Mercurial > hg > index.cgi
comparison lwlink/readfiles.c @ 8:fdc11ef4115b
Switched lwlink to lw_cmdline from argp and also brought in lw_alloc and lw_string to replace util.c
author | lost@l-w.ca |
---|---|
date | Sat, 22 Jan 2011 09:58:24 -0700 |
parents | 7317fbe024af |
children | fc8386b13399 |
comparison
equal
deleted
inserted
replaced
7:917b608b8c66 | 8:fdc11ef4115b |
---|---|
20 | 20 |
21 Reads input files | 21 Reads input files |
22 | 22 |
23 */ | 23 */ |
24 | 24 |
25 #include <argp.h> | |
26 #include <errno.h> | 25 #include <errno.h> |
27 #include <stdio.h> | 26 #include <stdio.h> |
28 #include <stdlib.h> | 27 #include <stdlib.h> |
29 #include <string.h> | 28 #include <string.h> |
30 | 29 |
30 #include <lw_alloc.h> | |
31 #include <lw_string.h> | |
32 | |
31 #include "lwlink.h" | 33 #include "lwlink.h" |
32 #include "util.h" | |
33 | 34 |
34 void read_lwobj16v0(fileinfo_t *fn); | 35 void read_lwobj16v0(fileinfo_t *fn); |
35 void read_lwar1v(fileinfo_t *fn); | 36 void read_lwar1v(fileinfo_t *fn); |
36 | 37 |
37 /* | 38 /* |
75 f = NULL; | 76 f = NULL; |
76 | 77 |
77 for (j = 0; j < nlibdirs; j++) | 78 for (j = 0; j < nlibdirs; j++) |
78 { | 79 { |
79 s = strlen(libdirs[j]) + 7 + strlen(inputfiles[i] -> filename); | 80 s = strlen(libdirs[j]) + 7 + strlen(inputfiles[i] -> filename); |
80 tf = lw_malloc(s + 1); | 81 tf = lw_alloc(s + 1); |
81 sprintf(tf, "%s/lib%s.a", libdirs[j], inputfiles[i] -> filename); | 82 sprintf(tf, "%s/lib%s.a", libdirs[j], inputfiles[i] -> filename); |
82 f = fopen(tf, "rb"); | 83 f = fopen(tf, "rb"); |
83 if (!f) | 84 if (!f) |
84 { | 85 { |
85 free(tf); | 86 free(tf); |
106 } | 107 } |
107 fseek(f, 0, SEEK_END); | 108 fseek(f, 0, SEEK_END); |
108 size = ftell(f); | 109 size = ftell(f); |
109 rewind(f); | 110 rewind(f); |
110 | 111 |
111 inputfiles[i] -> filedata = lw_malloc(size); | 112 inputfiles[i] -> filedata = lw_alloc(size); |
112 inputfiles[i] -> filesize = size; | 113 inputfiles[i] -> filesize = size; |
113 | 114 |
114 bread = fread(inputfiles[i] -> filedata, 1, size, f); | 115 bread = fread(inputfiles[i] -> filedata, 1, size, f); |
115 if (bread < size) | 116 if (bread < size) |
116 { | 117 { |
217 val |= (CURBYTE()); | 218 val |= (CURBYTE()); |
218 NEXTBYTE(); | 219 NEXTBYTE(); |
219 // val is now the symbol value | 220 // val is now the symbol value |
220 | 221 |
221 // create symbol table entry | 222 // create symbol table entry |
222 se = lw_malloc(sizeof(symtab_t)); | 223 se = lw_alloc(sizeof(symtab_t)); |
223 se -> next = s -> localsyms; | 224 se -> next = s -> localsyms; |
224 s -> localsyms = se; | 225 s -> localsyms = se; |
225 se -> sym = fp; | 226 se -> sym = fp; |
226 se -> offset = val; | 227 se -> offset = val; |
227 } | 228 } |
239 val |= (CURBYTE()); | 240 val |= (CURBYTE()); |
240 NEXTBYTE(); | 241 NEXTBYTE(); |
241 // val is now the symbol value | 242 // val is now the symbol value |
242 | 243 |
243 // create symbol table entry | 244 // create symbol table entry |
244 se = lw_malloc(sizeof(symtab_t)); | 245 se = lw_alloc(sizeof(symtab_t)); |
245 se -> next = s -> exportedsyms; | 246 se -> next = s -> exportedsyms; |
246 s -> exportedsyms = se; | 247 s -> exportedsyms = se; |
247 se -> sym = fp; | 248 se -> sym = fp; |
248 se -> offset = val; | 249 se -> offset = val; |
249 } | 250 } |
256 { | 257 { |
257 reloc_t *rp; | 258 reloc_t *rp; |
258 lw_expr_term_t *term; | 259 lw_expr_term_t *term; |
259 | 260 |
260 // we have a reference | 261 // we have a reference |
261 rp = lw_malloc(sizeof(reloc_t)); | 262 rp = lw_alloc(sizeof(reloc_t)); |
262 rp -> next = s -> incompletes; | 263 rp -> next = s -> incompletes; |
263 s -> incompletes = rp; | 264 s -> incompletes = rp; |
264 rp -> offset = 0; | 265 rp -> offset = 0; |
265 rp -> expr = lw_expr_stack_create(); | 266 rp -> expr = lw_expr_stack_create(); |
266 rp -> flags = RELOC_NORM; | 267 rp -> flags = RELOC_NORM; |
407 exit(1); | 408 exit(1); |
408 } | 409 } |
409 | 410 |
410 // add the "sub" input file | 411 // add the "sub" input file |
411 fn -> subs = lw_realloc(fn -> subs, sizeof(fileinfo_t *) * (fn -> nsubs + 1)); | 412 fn -> subs = lw_realloc(fn -> subs, sizeof(fileinfo_t *) * (fn -> nsubs + 1)); |
412 fn -> subs[fn -> nsubs] = lw_malloc(sizeof(fileinfo_t)); | 413 fn -> subs[fn -> nsubs] = lw_alloc(sizeof(fileinfo_t)); |
413 memset(fn -> subs[fn -> nsubs], 0, sizeof(fileinfo_t)); | 414 memset(fn -> subs[fn -> nsubs], 0, sizeof(fileinfo_t)); |
414 fn -> subs[fn -> nsubs] -> filedata = fn -> filedata + cc; | 415 fn -> subs[fn -> nsubs] -> filedata = fn -> filedata + cc; |
415 fn -> subs[fn -> nsubs] -> filesize = flen; | 416 fn -> subs[fn -> nsubs] -> filesize = flen; |
416 fn -> subs[fn -> nsubs] -> filename = lw_strdup((char *)(fn -> filedata + l)); | 417 fn -> subs[fn -> nsubs] -> filename = lw_strdup((char *)(fn -> filedata + l)); |
417 fn -> subs[fn -> nsubs] -> parent = fn; | 418 fn -> subs[fn -> nsubs] -> parent = fn; |