1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
|
--- a/main.cpp
+++ b/main.cpp
@@ -564,6 +564,11 @@ int main( int argc, const char **argv )
"\" is the same as the input file" << endp;
}
+ for (char* p = (char*)id.inputFileName; *p != 0; p++) {
+ if (*p == '\\')
+ *p = '/';
+ }
+
process( id );
return 0;
--- a/rlscan.cpp
+++ b/rlscan.cpp
@@ -45,12 +45,6 @@ enum InlineBlockType
SemiTerminated
};
-#ifdef _WIN32
-#define PATH_SEP '\\'
-#else
-#define PATH_SEP '/'
-#endif
-
/*
* The Scanner for Importing
@@ -811,12 +805,26 @@ void Scanner::endSection( )
bool isAbsolutePath( const char *path )
{
#ifdef _WIN32
- return isalpha( path[0] ) && path[1] == ':' && path[2] == '\\';
+ return isalpha( path[0] ) && path[1] == ':' && (path[2] == '\\' || path[2] == '/');
#else
return path[0] == '/';
#endif
}
+inline char* resolvePath(const char* rel, const char* abs) {
+ const size_t l1 = strlen(rel);
+ const size_t l2 = strlen(abs);
+ char* ret = new char[l1 + l2 + 1];
+
+ const char* p = strrchr(abs, '/') + 1;
+ const size_t l3 = p - abs;
+
+ memcpy(ret, abs, l3);
+ strcpy(ret + l3, rel);
+
+ return ret;
+}
+
char **Scanner::makeIncludePathChecks( const char *thisFileName,
const char *fileName, int fnlen )
{
@@ -836,17 +844,11 @@ char **Scanner::makeIncludePathChecks( const char *thisFileName,
checks = new char*[2 + id.includePaths.length()];
/* Search from the the location of the current file. */
- const char *lastSlash = strrchr( thisFileName, PATH_SEP );
+ const char *lastSlash = strrchr( thisFileName, '/' );
if ( lastSlash == 0 )
checks[nextCheck++] = data;
else {
- long givenPathLen = (lastSlash - thisFileName) + 1;
- long checklen = givenPathLen + length;
- char *check = new char[checklen+1];
- memcpy( check, thisFileName, givenPathLen );
- memcpy( check+givenPathLen, data, length );
- check[checklen] = 0;
- checks[nextCheck++] = check;
+ checks[nextCheck++] = resolvePath(data, thisFileName);
}
/* Search from the include paths given on the command line. */
@@ -855,7 +857,7 @@ char **Scanner::makeIncludePathChecks( const char *thisFileName,
long checkLen = pathLen + 1 + length;
char *check = new char[checkLen+1];
memcpy( check, *incp, pathLen );
- check[pathLen] = PATH_SEP;
+ check[pathLen] = '/';
memcpy( check+pathLen+1, data, length );
check[checkLen] = 0;
checks[nextCheck++] = check;
--- a/rlscan.rl
+++ b/rlscan.rl
@@ -43,12 +43,6 @@ enum InlineBlockType
SemiTerminated
};
-#ifdef _WIN32
-#define PATH_SEP '\\'
-#else
-#define PATH_SEP '/'
-#endif
-
/*
* The Scanner for Importing
@@ -548,12 +542,26 @@ void Scanner::endSection( )
bool isAbsolutePath( const char *path )
{
#ifdef _WIN32
- return isalpha( path[0] ) && path[1] == ':' && path[2] == '\\';
+ return isalpha( path[0] ) && path[1] == ':' && (path[2] == '\\' || path[2] == '/');
#else
return path[0] == '/';
#endif
}
+inline char* resolvePath(const char* rel, const char* abs) {
+ const size_t l1 = strlen(rel);
+ const size_t l2 = strlen(abs);
+ char* ret = new char[l1 + l2 + 1];
+
+ const char* p = strrchr(abs, '/') + 1;
+ const size_t l3 = p - abs;
+
+ memcpy(ret, abs, l3);
+ strcpy(ret + l3, rel);
+
+ return ret;
+}
+
char **Scanner::makeIncludePathChecks( const char *thisFileName,
const char *fileName, int fnlen )
{
@@ -573,17 +581,11 @@ char **Scanner::makeIncludePathChecks( const char *thisFileName,
checks = new char*[2 + id.includePaths.length()];
/* Search from the the location of the current file. */
- const char *lastSlash = strrchr( thisFileName, PATH_SEP );
+ const char *lastSlash = strrchr( thisFileName, '/' );
if ( lastSlash == 0 )
checks[nextCheck++] = data;
else {
- long givenPathLen = (lastSlash - thisFileName) + 1;
- long checklen = givenPathLen + length;
- char *check = new char[checklen+1];
- memcpy( check, thisFileName, givenPathLen );
- memcpy( check+givenPathLen, data, length );
- check[checklen] = 0;
- checks[nextCheck++] = check;
+ checks[nextCheck++] = resolvePath(data, thisFileName);
}
/* Search from the include paths given on the command line. */
@@ -592,7 +594,7 @@ char **Scanner::makeIncludePathChecks( const char *thisFileName,
long checkLen = pathLen + 1 + length;
char *check = new char[checkLen+1];
memcpy( check, *incp, pathLen );
- check[pathLen] = PATH_SEP;
+ check[pathLen] = '/';
memcpy( check+pathLen+1, data, length );
check[checkLen] = 0;
checks[nextCheck++] = check;
|