Mercurial > hg-old > index.cgi
annotate lwlink/lwlink.c @ 211:51511cf1c9f8
Prepare for gnulib integration
author | lost |
---|---|
date | Fri, 24 Apr 2009 06:27:00 +0000 |
parents | 42df94f30d82 |
children | bae1e3ecdce1 |
rev | line source |
---|---|
112 | 1 /* |
2 lwlink.c | |
118 | 3 Copyright © 2009 William Astle |
112 | 4 |
5 This file is part of LWLINK. | |
6 | |
7 LWLINK is free software: you can redistribute it and/or modify it under the | |
8 terms of the GNU General Public License as published by the Free Software | |
9 Foundation, either version 3 of the License, or (at your option) any later | |
10 version. | |
11 | |
12 This program is distributed in the hope that it will be useful, but WITHOUT | |
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
15 more details. | |
16 | |
17 You should have received a copy of the GNU General Public License along with | |
18 this program. If not, see <http://www.gnu.org/licenses/>. | |
19 | |
20 | |
21 | |
22 */ | |
23 | |
24 #ifdef HAVE_CONFIG_H | |
25 #include "config.h" | |
26 #endif | |
27 | |
28 #define __lwlink_c_seen__ | |
29 | |
30 #include <argp.h> | |
31 #include <errno.h> | |
32 #include <stdio.h> | |
33 #include <stdlib.h> | |
171 | 34 #include <string.h> |
112 | 35 |
36 #include "lwlink.h" | |
114
c65fcec346cd
Handle input files on command line and add some memory management utility functions
lost
parents:
112
diff
changeset
|
37 #include "util.h" |
112 | 38 |
39 int debug_level = 0; | |
40 int outformat = OUTPUT_DECB; | |
41 char *outfile = NULL; | |
117 | 42 char *scriptfile = NULL; |
184
220a760ec654
Make lwlink display all undefined references instead of bailing after the first one
lost
parents:
180
diff
changeset
|
43 int symerr = 0; |
185 | 44 char *map_file = NULL; |
112 | 45 |
115 | 46 fileinfo_t **inputfiles = NULL; |
114
c65fcec346cd
Handle input files on command line and add some memory management utility functions
lost
parents:
112
diff
changeset
|
47 int ninputfiles = 0; |
c65fcec346cd
Handle input files on command line and add some memory management utility functions
lost
parents:
112
diff
changeset
|
48 |
180 | 49 int nlibdirs = 0; |
50 char **libdirs = NULL; | |
51 | |
52 int nscriptls = 0; | |
53 char **scriptls = NULL; | |
54 | |
114
c65fcec346cd
Handle input files on command line and add some memory management utility functions
lost
parents:
112
diff
changeset
|
55 void add_input_file(char *fn) |
c65fcec346cd
Handle input files on command line and add some memory management utility functions
lost
parents:
112
diff
changeset
|
56 { |
115 | 57 inputfiles = lw_realloc(inputfiles, sizeof(fileinfo_t *) * (ninputfiles + 1)); |
58 inputfiles[ninputfiles] = lw_malloc(sizeof(fileinfo_t)); | |
171 | 59 memset(inputfiles[ninputfiles], 0, sizeof(fileinfo_t)); |
205 | 60 inputfiles[ninputfiles] -> forced = 1; |
115 | 61 inputfiles[ninputfiles++] -> filename = lw_strdup(fn); |
114
c65fcec346cd
Handle input files on command line and add some memory management utility functions
lost
parents:
112
diff
changeset
|
62 } |
c65fcec346cd
Handle input files on command line and add some memory management utility functions
lost
parents:
112
diff
changeset
|
63 |
180 | 64 void add_input_library(char *libname) |
65 { | |
66 inputfiles = lw_realloc(inputfiles, sizeof(fileinfo_t *) * (ninputfiles + 1)); | |
67 inputfiles[ninputfiles] = lw_malloc(sizeof(fileinfo_t)); | |
68 memset(inputfiles[ninputfiles], 0, sizeof(fileinfo_t)); | |
69 inputfiles[ninputfiles] -> islib = 1; | |
205 | 70 inputfiles[ninputfiles] -> forced = 0; |
180 | 71 inputfiles[ninputfiles++] -> filename = lw_strdup(libname); |
72 } | |
73 | |
74 void add_library_search(char *libdir) | |
75 { | |
76 libdirs = lw_realloc(libdirs, sizeof(char*) * (nlibdirs + 1)); | |
77 libdirs[nlibdirs] = lw_strdup(libdir); | |
78 nlibdirs++; | |
79 } | |
80 | |
81 void add_section_base(char *sectspec) | |
82 { | |
83 char *base; | |
84 int baseaddr; | |
85 char *t; | |
86 int l; | |
87 | |
88 base = strchr(sectspec, '='); | |
89 if (!base) | |
90 { | |
91 l = strlen(sectspec); | |
92 baseaddr = 0; | |
93 } | |
94 else | |
95 { | |
96 baseaddr = strtol(base + 1, NULL, 16); | |
97 l = base - sectspec; | |
98 *base = '\0'; | |
99 } | |
100 baseaddr = baseaddr & 0xffff; | |
101 | |
102 t = lw_malloc(l + 25); | |
103 sprintf(t, "section %s load %04X", sectspec, baseaddr); | |
104 if (base) | |
105 *base = '='; | |
106 | |
107 scriptls = lw_realloc(scriptls, sizeof(char *) * (nscriptls + 1)); | |
108 scriptls[nscriptls++] = t; | |
109 } |