]> git.sur5r.net Git - cc65/blob - src/ld65/scanner.h
More debug file output
[cc65] / src / ld65 / scanner.h
1 /*****************************************************************************/
2 /*                                                                           */
3 /*                                 scanner.h                                 */
4 /*                                                                           */
5 /*              Configuration file scanner for the ld65 linker               */
6 /*                                                                           */
7 /*                                                                           */
8 /*                                                                           */
9 /* (C) 1998-2003 Ullrich von Bassewitz                                       */
10 /*               Römerstrasse 52                                             */
11 /*               D-70794 Filderstadt                                         */
12 /* EMail:        uz@cc65.org                                                 */
13 /*                                                                           */
14 /*                                                                           */
15 /* This software is provided 'as-is', without any expressed or implied       */
16 /* warranty.  In no event will the authors be held liable for any damages    */
17 /* arising from the use of this software.                                    */
18 /*                                                                           */
19 /* Permission is granted to anyone to use this software for any purpose,     */
20 /* including commercial applications, and to alter it and redistribute it    */
21 /* freely, subject to the following restrictions:                            */
22 /*                                                                           */
23 /* 1. The origin of this software must not be misrepresented; you must not   */
24 /*    claim that you wrote the original software. If you use this software   */
25 /*    in a product, an acknowledgment in the product documentation would be  */
26 /*    appreciated but is not required.                                       */
27 /* 2. Altered source versions must be plainly marked as such, and must not   */
28 /*    be misrepresented as being the original software.                      */
29 /* 3. This notice may not be removed or altered from any source              */
30 /*    distribution.                                                          */
31 /*                                                                           */
32 /*****************************************************************************/
33
34
35
36 #ifndef SCANNER_H
37 #define SCANNER_H
38
39
40
41 /*****************************************************************************/
42 /*                                   Data                                    */
43 /*****************************************************************************/
44
45
46
47 /* Config file tokens */
48 typedef enum {
49     CFGTOK_NONE,
50     CFGTOK_INTCON,
51     CFGTOK_STRCON,
52     CFGTOK_IDENT,
53     CFGTOK_LCURLY,
54     CFGTOK_RCURLY,
55     CFGTOK_SEMI,
56     CFGTOK_COMMA,
57     CFGTOK_EQ,
58     CFGTOK_COLON,
59     CFGTOK_DOT,
60     CFGTOK_EOF,
61
62     /* Special identifiers */
63     CFGTOK_MEMORY,
64     CFGTOK_FILES,
65     CFGTOK_SEGMENTS,
66     CFGTOK_FORMATS,
67     CFGTOK_FEATURES,
68     CFGTOK_SYMBOLS,
69
70     CFGTOK_START,
71     CFGTOK_SIZE,
72     CFGTOK_TYPE,
73     CFGTOK_FILE,
74     CFGTOK_DEFINE,
75     CFGTOK_FILL,
76     CFGTOK_FILLVAL,
77     CFGTOK_EXPORT,
78     CFGTOK_IMPORT,
79     CFGTOK_OS,
80     CFGTOK_ID,
81     CFGTOK_VERSION,
82     CFGTOK_FORMAT,
83
84     CFGTOK_LOAD,
85     CFGTOK_RUN,
86     CFGTOK_ALIGN,
87     CFGTOK_OFFSET,
88     CFGTOK_OPTIONAL,
89
90     CFGTOK_RO,
91     CFGTOK_RW,
92     CFGTOK_BSS,
93     CFGTOK_ZP,
94
95     CFGTOK_O65,
96     CFGTOK_BIN,
97
98     CFGTOK_SMALL,
99     CFGTOK_LARGE,
100
101     CFGTOK_TRUE,
102     CFGTOK_FALSE,
103
104     CFGTOK_LUNIX,
105     CFGTOK_OSA65,
106     CFGTOK_CC65,
107
108     CFGTOK_CONDES,
109     CFGTOK_STARTADDRESS,
110
111     CFGTOK_SEGMENT,
112     CFGTOK_LABEL,
113     CFGTOK_COUNT,
114     CFGTOK_ORDER,
115
116     CFGTOK_CONSTRUCTOR,
117     CFGTOK_DESTRUCTOR,
118
119     CFGTOK_DECREASING,
120     CFGTOK_INCREASING,
121
122     CFGTOK_DEFAULT
123
124 } cfgtok_t;
125
126
127
128 /* Mapping table entry, special identifier --> token */
129 typedef struct IdentTok IdentTok;
130 struct IdentTok {
131     const char* Ident;          /* Identifier */
132     cfgtok_t    Tok;            /* Token for identifier */
133 };
134 #define ENTRY_COUNT(s)  (sizeof (s) / sizeof (s [0]))
135
136
137
138 /* Current token and attributes */
139 #define CFG_MAX_IDENT_LEN  255
140 extern cfgtok_t         CfgTok;
141 extern char             CfgSVal [CFG_MAX_IDENT_LEN+1];
142 extern unsigned long    CfgIVal;
143
144 /* Error location */
145 extern unsigned         CfgErrorLine;
146 extern unsigned         CfgErrorCol;
147
148
149
150 /*****************************************************************************/
151 /*                                   Code                                    */
152 /*****************************************************************************/
153
154
155
156 void CfgWarning (const char* Format, ...) attribute((format(printf,1,2)));
157 /* Print a warning message adding file name and line number of the config file */
158
159 void CfgError (const char* Format, ...) attribute((format(printf,1,2)));
160 /* Print an error message adding file name and line number of the config file */
161
162 void CfgNextTok (void);
163 /* Read the next token from the input stream */
164
165 void CfgConsume (cfgtok_t T, const char* Msg);
166 /* Skip a token, print an error message if not found */
167
168 void CfgConsumeSemi (void);
169 /* Consume a semicolon */
170
171 void CfgConsumeColon (void);
172 /* Consume a colon */
173
174 void CfgOptionalComma (void);
175 /* Consume a comma if there is one */
176
177 void CfgOptionalAssign (void);
178 /* Consume an equal sign if there is one */
179
180 void CfgAssureInt (void);
181 /* Make sure the next token is an integer */
182
183 void CfgAssureStr (void);
184 /* Make sure the next token is a string constant */
185
186 void CfgAssureIdent (void);
187 /* Make sure the next token is an identifier */
188
189 void CfgRangeCheck (unsigned long Lo, unsigned long Hi);
190 /* Check the range of CfgIVal */
191
192 void CfgSpecialToken (const IdentTok* Table, unsigned Size, const char* Name);
193 /* Map an identifier to one of the special tokens in the table */
194
195 void CfgBoolToken (void);
196 /* Map an identifier or integer to a boolean token */
197
198 void CfgSetName (const char* Name);
199 /* Set a name for a config file */
200
201 const char* CfgGetName (void);
202 /* Get the name of the config file */
203
204 void CfgSetBuf (const char* Buf);
205 /* Set a memory buffer for the config */
206
207 int CfgAvail (void);
208 /* Return true if we have a configuration available */
209
210 void CfgOpenInput (void);
211 /* Open the input file if we have one */
212
213 void CfgCloseInput (void);
214 /* Close the input file if we have one */
215
216
217
218 /* End of scanner.h */
219 #endif
220
221
222
223