Mercurial > hg > index.cgi
comparison lwlink/script.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 | 554831f03338 |
comparison
equal
deleted
inserted
replaced
7:917b608b8c66 | 8:fdc11ef4115b |
---|---|
25 #include <errno.h> | 25 #include <errno.h> |
26 #include <stdio.h> | 26 #include <stdio.h> |
27 #include <stdlib.h> | 27 #include <stdlib.h> |
28 #include <string.h> | 28 #include <string.h> |
29 | 29 |
30 #include <lw_alloc.h> | |
31 #include <lw_string.h> | |
32 | |
30 #include "lwlink.h" | 33 #include "lwlink.h" |
31 #include "util.h" | |
32 | 34 |
33 // the built-in DECB target linker script | 35 // the built-in DECB target linker script |
34 static char *decb_script = | 36 static char *decb_script = |
35 "section init load 2000\n" | 37 "section init load 2000\n" |
36 "section code\n" | 38 "section code\n" |
85 } | 87 } |
86 fseek(f, 0, SEEK_END); | 88 fseek(f, 0, SEEK_END); |
87 size = ftell(f); | 89 size = ftell(f); |
88 rewind(f); | 90 rewind(f); |
89 | 91 |
90 script = lw_malloc(size + 2); | 92 script = lw_alloc(size + 2); |
91 | 93 |
92 bread = fread(script, 1, size, f); | 94 bread = fread(script, 1, size, f); |
93 if (bread < size) | 95 if (bread < size) |
94 { | 96 { |
95 fprintf(stderr, "Short read on file %s (%ld/%ld):", scriptfile, bread, size); | 97 fprintf(stderr, "Short read on file %s (%ld/%ld):", scriptfile, bread, size); |
130 int i; | 132 int i; |
131 // prepend the "extra" script lines | 133 // prepend the "extra" script lines |
132 for (i = 0; i < nscriptls; i++) | 134 for (i = 0; i < nscriptls; i++) |
133 size += strlen(scriptls[i]) + 1; | 135 size += strlen(scriptls[i]) + 1; |
134 | 136 |
135 rscript = lw_malloc(size + 1); | 137 rscript = lw_alloc(size + 1); |
136 oscript = rscript; | 138 oscript = rscript; |
137 for (i = 0; i < nscriptls; i++) | 139 for (i = 0; i < nscriptls; i++) |
138 { | 140 { |
139 oscript += sprintf(oscript, "%s\n", scriptls[i]); | 141 oscript += sprintf(oscript, "%s\n", scriptls[i]); |
140 } | 142 } |
153 char *ptr, *ptr2, *line; | 155 char *ptr, *ptr2, *line; |
154 | 156 |
155 for (ptr = script; *ptr && *ptr != '\n' && *ptr != '\r'; ptr++) | 157 for (ptr = script; *ptr && *ptr != '\n' && *ptr != '\r'; ptr++) |
156 /* do nothing */ ; | 158 /* do nothing */ ; |
157 | 159 |
158 line = lw_malloc(ptr - script + 1); | 160 line = lw_alloc(ptr - script + 1); |
159 memcpy(line, script, ptr - script); | 161 memcpy(line, script, ptr - script); |
160 line[ptr - script] = '\0'; | 162 line[ptr - script] = '\0'; |
161 | 163 |
162 // skip line terms | 164 // skip line terms |
163 for (script = ptr + 1; *script == '\n' || *script == '\r'; script++) | 165 for (script = ptr + 1; *script == '\n' || *script == '\r'; script++) |