Mercurial > hg > index.cgi
comparison lwasm/input.c @ 247:4b36eaaf80c3
First attempt at fixing the drive letter problem on Windows
Absolute paths in windows cannot be detected by simply checking for a
leading slash, even in MinGW. Instead, apply a heuristic that looks for
either a leading slash or a letter followed by a colon. This heuristic is
only activated on windows builds.
author | William Astle <lost@l-w.ca> |
---|---|
date | Thu, 24 Jan 2013 21:00:00 -0700 |
parents | 3864d96ee8c7 |
children | 891bab942b5a |
comparison
equal
deleted
inserted
replaced
246:b97460509c3d | 247:4b36eaaf80c3 |
---|---|
79 } | 79 } |
80 | 80 |
81 #define IS ((struct input_stack *)(as -> input_data)) | 81 #define IS ((struct input_stack *)(as -> input_data)) |
82 | 82 |
83 struct ifl *ifl_head = NULL; | 83 struct ifl *ifl_head = NULL; |
84 | |
85 static int input_isabsolute(const char *s) | |
86 { | |
87 #if defined(WIN32) || defined(WIN64) | |
88 // aiming for the root of the current drive - treat as absolute | |
89 if (s[0] == '/') | |
90 return 1; | |
91 // check for drive letter stuff | |
92 if (!s[0] || !s[1]) | |
93 return 0; | |
94 if (s[1] != ':') | |
95 return 0; | |
96 if (isalpha(s[0])) | |
97 return 1; | |
98 return 0; | |
99 #else | |
100 /* this is suitable for unix-like systems */ | |
101 if (s[0] == '/') | |
102 return 1; | |
103 return 0; | |
104 #endif | |
105 } | |
84 | 106 |
85 /* this adds real filenames that were opened to a list */ | 107 /* this adds real filenames that were opened to a list */ |
86 void input_add_to_resource_list(asmstate_t *as, const char *s) | 108 void input_add_to_resource_list(asmstate_t *as, const char *s) |
87 { | 109 { |
88 struct ifl *ifl; | 110 struct ifl *ifl; |
206 | 228 |
207 switch (IS -> type) | 229 switch (IS -> type) |
208 { | 230 { |
209 case input_type_include: | 231 case input_type_include: |
210 /* first check for absolute path and if so, skip path */ | 232 /* first check for absolute path and if so, skip path */ |
211 if (*s == '/') | 233 if (input_isabsolute(s)) |
212 { | 234 { |
213 /* absolute path */ | 235 /* absolute path */ |
214 IS -> data = fopen(s, "rb"); | 236 IS -> data = fopen(s, "rb"); |
215 debug_message(as, 1, "Opening (abs) %s", s); | 237 debug_message(as, 1, "Opening (abs) %s", s); |
216 if (!IS -> data && !IGNOREERROR) | 238 if (!IS -> data && !IGNOREERROR) |
290 FILE *fp; | 312 FILE *fp; |
291 char *p, *p2; | 313 char *p, *p2; |
292 | 314 |
293 debug_message(as, 2, "Open file (st) %s", s); | 315 debug_message(as, 2, "Open file (st) %s", s); |
294 /* first check for absolute path and if so, skip path */ | 316 /* first check for absolute path and if so, skip path */ |
295 if (*s == '/') | 317 if (input_isabsolute(s)) |
296 { | 318 { |
297 /* absolute path */ | 319 /* absolute path */ |
298 debug_message(as, 2, "Open file (st abs) %s", s); | 320 debug_message(as, 2, "Open file (st abs) %s", s); |
299 if (as -> flags & FLAG_DEPEND) | 321 if (as -> flags & FLAG_DEPEND) |
300 printf("%s\n", s); | 322 printf("%s\n", s); |