comparison lwasm/input.c @ 386:af5f2c51db76

Bugfixing on includes
author lost@starbug
date Sun, 16 May 2010 13:03:17 -0600
parents 38b50ce6967a
children e3567a9f0d54
comparison
equal deleted inserted replaced
385:cf8c92d70eb1 386:af5f2c51db76
166 /* first check for absolute path and if so, skip path */ 166 /* first check for absolute path and if so, skip path */
167 if (*s == '/') 167 if (*s == '/')
168 { 168 {
169 /* absolute path */ 169 /* absolute path */
170 IS -> data = fopen(s, "rb"); 170 IS -> data = fopen(s, "rb");
171 debug_message(as, 1, "Opening (abs) %s", s);
171 if (!IS -> data) 172 if (!IS -> data)
172 { 173 {
173 lw_error("Cannot open file '%s': %s", s, strerror(errno)); 174 lw_error("Cannot open file '%s': %s", s, strerror(errno));
174 } 175 }
175 input_pushpath(as, s); 176 input_pushpath(as, s);
177 } 178 }
178 179
179 /* relative path, check relative to "current file" directory */ 180 /* relative path, check relative to "current file" directory */
180 p = lw_stack_top(as -> file_dir); 181 p = lw_stack_top(as -> file_dir);
181 0 == asprintf(&p2, "%s/%s", p, s); 182 0 == asprintf(&p2, "%s/%s", p, s);
183 debug_message(as, 1, "Open: (cd) %s\n", p2);
182 IS -> data = fopen(p2, "rb"); 184 IS -> data = fopen(p2, "rb");
183 if (IS -> data) 185 if (IS -> data)
184 { 186 {
185 input_pushpath(as, p2); 187 input_pushpath(as, p2);
186 lw_free(p2); 188 lw_free(p2);
191 /* now check relative to entries in the search path */ 193 /* now check relative to entries in the search path */
192 lw_stringlist_reset(as -> include_list); 194 lw_stringlist_reset(as -> include_list);
193 while (p = lw_stringlist_current(as -> include_list)) 195 while (p = lw_stringlist_current(as -> include_list))
194 { 196 {
195 0 == asprintf(&p2, "%s/%s", p, s); 197 0 == asprintf(&p2, "%s/%s", p, s);
198 debug_message(as, 1, "Open (sp): %s\n", p2);
196 IS -> data = fopen(p2, "rb"); 199 IS -> data = fopen(p2, "rb");
197 if (IS -> data) 200 if (IS -> data)
198 { 201 {
199 input_pushpath(as, p2); 202 input_pushpath(as, p2);
200 lw_free(p2); 203 lw_free(p2);
204 lw_stringlist_next(as -> include_list); 207 lw_stringlist_next(as -> include_list);
205 } 208 }
206 lw_error("Cannot open include file '%s': %s", s, strerror(errno)); 209 lw_error("Cannot open include file '%s': %s", s, strerror(errno));
207 210
208 case input_type_file: 211 case input_type_file:
212 debug_message(as, 1, "Opening (reg): %s\n", s);
209 IS -> data = fopen(s, "rb"); 213 IS -> data = fopen(s, "rb");
210 214
211 if (!IS -> data) 215 if (!IS -> data)
212 { 216 {
213 lw_error("Cannot open file '%s': %s", s, strerror(errno)); 217 lw_error("Cannot open file '%s': %s", s, strerror(errno));
227 231
228 /* first check for absolute path and if so, skip path */ 232 /* first check for absolute path and if so, skip path */
229 if (*s == '/') 233 if (*s == '/')
230 { 234 {
231 /* absolute path */ 235 /* absolute path */
236 debug_message(as, 2, "Open file (st abs) %s", s);
232 fp = fopen(s, "rb"); 237 fp = fopen(s, "rb");
233 if (!fp) 238 if (!fp)
234 { 239 {
235 return NULL; 240 return NULL;
236 } 241 }
238 } 243 }
239 244
240 /* relative path, check relative to "current file" directory */ 245 /* relative path, check relative to "current file" directory */
241 p = lw_stack_top(as -> file_dir); 246 p = lw_stack_top(as -> file_dir);
242 0 == asprintf(&p2, "%s/%s", p, s); 247 0 == asprintf(&p2, "%s/%s", p, s);
248 debug_message(as, 2, "Open file (st cd) %s", p2);
243 fp = fopen(p2, "rb"); 249 fp = fopen(p2, "rb");
244 if (fp) 250 if (fp)
245 { 251 {
246 lw_free(p2); 252 lw_free(p2);
247 return fp; 253 return fp;
251 /* now check relative to entries in the search path */ 257 /* now check relative to entries in the search path */
252 lw_stringlist_reset(as -> include_list); 258 lw_stringlist_reset(as -> include_list);
253 while (p = lw_stringlist_current(as -> include_list)) 259 while (p = lw_stringlist_current(as -> include_list))
254 { 260 {
255 0 == asprintf(&p2, "%s/%s", p, s); 261 0 == asprintf(&p2, "%s/%s", p, s);
262 debug_message(as, 2, "Open file (st ip) %s", p2);
256 fp = fopen(p2, "rb"); 263 fp = fopen(p2, "rb");
257 if (fp) 264 if (fp)
258 { 265 {
259 lw_free(p2); 266 lw_free(p2);
260 return fp; 267 return fp;