Mercurial > hg > index.cgi
comparison lwasm/input.c @ 10:127e5b1e01c0
Removed use of asprintf() and added Makefile options for cross compiling; also a bugfix with sizeof{} in lwasm
author | lost@l-w.ca |
---|---|
date | Sat, 22 Jan 2011 10:37:53 -0700 |
parents | 7317fbe024af |
children | 1f77ae5c3590 |
comparison
equal
deleted
inserted
replaced
9:6eed14cccac9 | 10:127e5b1e01c0 |
---|---|
55 int type; | 55 int type; |
56 void *data; | 56 void *data; |
57 int data2; | 57 int data2; |
58 char *filespec; | 58 char *filespec; |
59 }; | 59 }; |
60 | |
61 static char *make_filename(char *p, char *f) | |
62 { | |
63 int l; | |
64 char *r; | |
65 l = strlen(p) + strlen(f) + 1; | |
66 r = lw_alloc(l + 1); | |
67 sprintf(r, "%s/%s", p, f); | |
68 return r; | |
69 } | |
60 | 70 |
61 #define IS ((struct input_stack *)(as -> input_data)) | 71 #define IS ((struct input_stack *)(as -> input_data)) |
62 | 72 |
63 void input_init(asmstate_t *as) | 73 void input_init(asmstate_t *as) |
64 { | 74 { |
177 return; | 187 return; |
178 } | 188 } |
179 | 189 |
180 /* relative path, check relative to "current file" directory */ | 190 /* relative path, check relative to "current file" directory */ |
181 p = lw_stack_top(as -> file_dir); | 191 p = lw_stack_top(as -> file_dir); |
182 (void)(0 == asprintf(&p2, "%s/%s", p, s)); | 192 p2 = make_filename(p, s); |
183 debug_message(as, 1, "Open: (cd) %s\n", p2); | 193 debug_message(as, 1, "Open: (cd) %s\n", p2); |
184 IS -> data = fopen(p2, "rb"); | 194 IS -> data = fopen(p2, "rb"); |
185 if (IS -> data) | 195 if (IS -> data) |
186 { | 196 { |
187 input_pushpath(as, p2); | 197 input_pushpath(as, p2); |
193 | 203 |
194 /* now check relative to entries in the search path */ | 204 /* now check relative to entries in the search path */ |
195 lw_stringlist_reset(as -> include_list); | 205 lw_stringlist_reset(as -> include_list); |
196 while ((p = lw_stringlist_current(as -> include_list))) | 206 while ((p = lw_stringlist_current(as -> include_list))) |
197 { | 207 { |
198 (void)(0 == asprintf(&p2, "%s/%s", p, s)); | 208 p2 = make_filename(p, s); |
199 debug_message(as, 1, "Open (sp): %s\n", p2); | 209 debug_message(as, 1, "Open (sp): %s\n", p2); |
200 IS -> data = fopen(p2, "rb"); | 210 IS -> data = fopen(p2, "rb"); |
201 if (IS -> data) | 211 if (IS -> data) |
202 { | 212 { |
203 input_pushpath(as, p2); | 213 input_pushpath(as, p2); |
245 return fp; | 255 return fp; |
246 } | 256 } |
247 | 257 |
248 /* relative path, check relative to "current file" directory */ | 258 /* relative path, check relative to "current file" directory */ |
249 p = lw_stack_top(as -> file_dir); | 259 p = lw_stack_top(as -> file_dir); |
250 (void)(0 == asprintf(&p2, "%s/%s", p, s)); | 260 p2 = make_filename(p, s); |
251 debug_message(as, 2, "Open file (st cd) %s", p2); | 261 debug_message(as, 2, "Open file (st cd) %s", p2); |
252 fp = fopen(p2, "rb"); | 262 fp = fopen(p2, "rb"); |
253 if (fp) | 263 if (fp) |
254 { | 264 { |
255 lw_free(p2); | 265 lw_free(p2); |
259 | 269 |
260 /* now check relative to entries in the search path */ | 270 /* now check relative to entries in the search path */ |
261 lw_stringlist_reset(as -> include_list); | 271 lw_stringlist_reset(as -> include_list); |
262 while ((p = lw_stringlist_current(as -> include_list))) | 272 while ((p = lw_stringlist_current(as -> include_list))) |
263 { | 273 { |
264 (void)(0 == asprintf(&p2, "%s/%s", p, s)); | 274 p2 = make_filename(p, s); |
265 debug_message(as, 2, "Open file (st ip) %s", p2); | 275 debug_message(as, 2, "Open file (st ip) %s", p2); |
266 fp = fopen(p2, "rb"); | 276 fp = fopen(p2, "rb"); |
267 if (fp) | 277 if (fp) |
268 { | 278 { |
269 lw_free(p2); | 279 lw_free(p2); |