struct / union in initializer, RFE #901.
[sdcc.git] / sdcc / sdas / linksrc / lkrel.c
blob2210fec289cf98daf5da97588bc6b22f5711b6a1
1 /* lkrel.c - .rel object file handling
3 Copyright (C) 1989-1995 Alan R. Baldwin
4 721 Berkeley St., Kent, Ohio 44240
5 Copyright (C) 2008-2010 Borut Razem, borut dot razem at siol dot net
7 This program is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 3, or (at your option) any
10 later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21 * With contributions for the
22 * object libraries from
23 * Ken Hornstein
24 * kenh@cmf.nrl.navy.mil
29 * Extensions: P. Felber
32 #include <assert.h>
34 #include "lk_readnl.h"
35 #include "aslink.h"
36 #include "lkrel.h"
38 int
39 is_rel (FILE * libfp)
41 int c;
42 long pos = ftell (libfp);
43 int ret = 0;
45 /* [XDQ][HL][234] */
46 if (((c = getc (libfp)) == 'X' || c == 'D' || c == 'Q') && ((c = getc (libfp)) == 'H' || c == 'L'))
48 switch (getc (libfp))
50 case '2':
51 case '3':
52 case '4':
53 switch (getc (libfp))
55 case '\r':
56 if (getc (libfp) == '\n')
57 ret = 1;
58 break;
60 case '\n':
61 ret = 1;
63 break;
65 case '\r':
66 if (getc (libfp) == '\n')
67 ret = 1;
68 break;
70 case '\n':
71 ret = 1;
74 else if (c == ';')
76 char buf[6];
78 if (fread (buf, 1, sizeof (buf), libfp) == sizeof (buf) && memcmp (buf, "!FILE ", 6) == 0)
79 ret = 1;
81 fseek (libfp, pos, SEEK_SET);
82 return ret;
85 /* Load a standalone or embedded .rel */
86 int
87 load_rel (FILE * libfp, long size)
89 if (is_rel (libfp))
91 char str[NINPUT];
92 long end;
94 end = (size >= 0) ? ftell (libfp) + size : -1;
96 while ((end < 0 || ftell (libfp) < end) && lk_readnl (str, sizeof (str), libfp) != NULL)
98 if (0 == strcmp (str, "</REL>"))
99 return 1;
101 ip = str;
102 link_main ();
105 return 1;
107 else
108 return 0;
112 enum_symbols (FILE * fp, long size, int (*func) (const char *symvoid, void *param), void *param)
114 char buf[NINPUT];
115 long end = (size >= 0) ? ftell (fp) + size : -1;
117 assert (func != NULL);
120 * Read in the object file. Look for lines that
121 * begin with "S" and end with "D". These are
122 * symbol table definitions. If we find one, see
123 * if it is our symbol. Make sure we only read in
124 * our object file and don't go into the next one.
127 while ((end < 0 || ftell (fp) < end) && lk_readnl (buf, sizeof (buf), fp) != NULL)
129 char symname[NINPUT];
130 char c;
133 * When a 'T line' is found terminate file scan.
134 * All 'S line's preceed 'T line's in .REL files.
136 if (buf[0] == 'T')
137 break;
140 * Skip everything that's not a symbol record.
142 if (buf[0] != 'S')
143 continue;
145 sscanf (buf, "S %s %c", symname, &c);
147 /* If it's an actual symbol, record it */
148 if (c == 'D')
150 if ((*func) (symname, param))
151 return 1;
155 return 0;