summaryrefslogtreecommitdiff
path: root/legacy/evil
diff options
context:
space:
mode:
authorVincent Torri <vincent.torri@gmail.com>2010-12-13 05:20:56 +0000
committerVincent Torri <vincent.torri@gmail.com>2010-12-13 05:20:56 +0000
commit0fe21742f61cac9256daf9774d1eb815ede058e9 (patch)
treea3c96a9a4fc1e0f32d4ae256a3a7e4005dc50444 /legacy/evil
parentb493685f897fd8821dcb83baa7669c0eaa2732dc (diff)
add dirname() function
SVN revision: 55530
Diffstat (limited to 'legacy/evil')
-rw-r--r--legacy/evil/ChangeLog6
-rw-r--r--legacy/evil/src/lib/evil_libgen.c83
-rw-r--r--legacy/evil/src/lib/evil_libgen.h4
3 files changed, 86 insertions, 7 deletions
diff --git a/legacy/evil/ChangeLog b/legacy/evil/ChangeLog
index a4176f80bf..483fda5f77 100644
--- a/legacy/evil/ChangeLog
+++ b/legacy/evil/ChangeLog
@@ -1,5 +1,11 @@
12010-12-12 Vincent Torri <doursse at users dot sf dot net> 12010-12-12 Vincent Torri <doursse at users dot sf dot net>
2 2
3 * src/lib/evil_libgen.c:
4 * src/lib/evil_libgen.h:
5 add dirname() function
6
72010-12-12 Vincent Torri <doursse at users dot sf dot net>
8
3 * src/lib/evil_unistd.c: 9 * src/lib/evil_unistd.c:
4 * src/lib/evil_unistd.h: 10 * src/lib/evil_unistd.h:
5 add usleep() for vc++ 11 add usleep() for vc++
diff --git a/legacy/evil/src/lib/evil_libgen.c b/legacy/evil/src/lib/evil_libgen.c
index dd43d46e61..089bdb5f8f 100644
--- a/legacy/evil/src/lib/evil_libgen.c
+++ b/legacy/evil/src/lib/evil_libgen.c
@@ -7,6 +7,7 @@
7#include "Evil.h" 7#include "Evil.h"
8 8
9char _evil_basename_buf[PATH_MAX]; 9char _evil_basename_buf[PATH_MAX];
10char _evil_dirname_buf[PATH_MAX];
10 11
11char * 12char *
12evil_basename(char *path) 13evil_basename(char *path)
@@ -15,28 +16,96 @@ evil_basename(char *path)
15 char *p2; 16 char *p2;
16 size_t length; 17 size_t length;
17 18
18 if (!path || !*path) 19 /* path must begin by "?:\" or "?:/" */
20 if ((!path) ||
21 (strlen(path) <= 3) ||
22 ((path[0] < 'a' || path[0] > 'z') && (path[0] < 'A' || path[0] > 'Z')) ||
23 (path[1] != ':') ||
24 ((path[2] != '/') && (path[2] != '\\')))
19 { 25 {
20 memcpy(_evil_basename_buf, ".", 2); 26 memcpy(_evil_basename_buf, "C:\\", 4);
21 return _evil_basename_buf; 27 return _evil_basename_buf;
22 } 28 }
23 29
30 /* '/' --> '\\' */
24 length = strlen(path); 31 length = strlen(path);
25 p1 = strdup(path); 32 p1 = strdup(path);
26 if (!p1) return NULL; 33 if (!p1)
34 {
35 memcpy(_evil_basename_buf, "C:\\", 4);
36 return _evil_basename_buf;
37 }
27 p2 = p1; 38 p2 = p1;
28 while (p2) 39 while (p2)
29 { 40 {
30 if (*p2 == '/') *p2 = '\\'; 41 if (*p2 == '/') *p2 = '\\';
31 p2++; 42 p2++;
32 } 43 }
33 if (p1[length - 1] =='\\') p1[--length] = '\0'; 44
45 /* remove trailing backslashes */
46 p2 = p1 + (length - 1);
47 if (*p2 == '\\')
48 {
49 while (*p2 == '\\')
50 p2--;
51 }
52 *(p2 + 1) = '\0';
34 53
35 p2 = strrchr(p1, '\\'); 54 p2 = strrchr(p1, '\\');
36 if (!p2) memcpy(_evil_basename_buf, p1, length + 1); 55 memcpy(_evil_basename_buf, p2 + 1, (p1 + length + 1) - p2);
37 else memcpy(_evil_basename_buf, p2 + 1, (p1 + length + 1) - p2);
38 56
39 free(p1); 57 free(p1);
40 58
41 return _evil_basename_buf; 59 return _evil_basename_buf;
42} 60}
61
62char *
63evil_dirname(char *path)
64{
65 char *p1;
66 char *p2;
67 size_t length;
68
69 /* path must begin by "?:\" or "?:/" */
70 if ((!path) ||
71 (strlen(path) <= 3) ||
72 ((path[0] < 'a' || path[0] > 'z') && (path[0] < 'A' || path[0] > 'Z')) ||
73 (path[1] != ':') ||
74 ((path[2] != '/') && (path[2] != '\\')))
75 {
76 memcpy(_evil_dirname_buf, "C:\\", 4);
77 return _evil_dirname_buf;
78 }
79
80 /* '/' --> '\\' */
81 length = strlen(path);
82 p1 = strdup(path);
83 if (!p1)
84 {
85 memcpy(_evil_dirname_buf, "C:\\", 4);
86 return _evil_dirname_buf;
87 }
88 p2 = p1;
89 while (p2)
90 {
91 if (*p2 == '/') *p2 = '\\';
92 p2++;
93 }
94
95 /* remove trailing backslashes */
96 p2 = p1 + (length - 1);
97 if (*p2 == '\\')
98 {
99 while (*p2 == '\\')
100 p2--;
101 }
102 *(p2 + 1) = '\0';
103
104 p2 = strrchr(p1, '\\');
105 *p2 = '\0';
106 memcpy(_evil_dirname_buf, p1, strlen(p1) + 1);
107
108 free(p1);
109
110 return _evil_dirname_buf;
111}
diff --git a/legacy/evil/src/lib/evil_libgen.h b/legacy/evil/src/lib/evil_libgen.h
index c252b2fa3e..48a3d82693 100644
--- a/legacy/evil/src/lib/evil_libgen.h
+++ b/legacy/evil/src/lib/evil_libgen.h
@@ -16,6 +16,10 @@ EAPI char *evil_basename(char *path);
16 16
17#define basename(p) evil_basename(p) 17#define basename(p) evil_basename(p)
18 18
19EAPI char *evil_dirname(char *path);
20
21#define dirname(p) evil_dirname(p)
22
19 23
20/** 24/**
21 * @} 25 * @}