]> git.sur5r.net Git - cc65/blob - src/ld65/scanner.h
2c0a5ac392675b48092692dccd8d33c9c9dfd630
[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     Ullrich von Bassewitz                                        */
10 /*              Wacholderweg 14                                              */
11 /*              D-70597 Stuttgart                                            */
12 /* EMail:       uz@musoftware.de                                             */
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 #define CFGTOK_NONE             0
49 #define CFGTOK_INTCON           1
50 #define CFGTOK_STRCON           2
51 #define CFGTOK_IDENT            3
52 #define CFGTOK_LCURLY           4
53 #define CFGTOK_RCURLY           5
54 #define CFGTOK_SEMI             6
55 #define CFGTOK_COMMA            7
56 #define CFGTOK_EQ               8
57 #define CFGTOK_COLON            9
58 #define CFGTOK_DOT              10
59 #define CFGTOK_EOF              11
60
61 /* Special identifiers */
62 #define CFGTOK_MEMORY           20
63 #define CFGTOK_FILES            21
64 #define CFGTOK_SEGMENTS         22
65 #define CFGTOK_FORMATS          23
66
67 #define CFGTOK_START            30
68 #define CFGTOK_SIZE             31
69 #define CFGTOK_TYPE             32
70 #define CFGTOK_FILE             33
71 #define CFGTOK_DEFINE           34
72 #define CFGTOK_FILL             35
73 #define CFGTOK_FILLVAL          36
74 #define CFGTOK_EXPORT           37
75 #define CFGTOK_IMPORT           38
76 #define CFGTOK_OS               39
77 #define CFGTOK_FORMAT           40
78
79 #define CFGTOK_LOAD             50
80 #define CFGTOK_RUN              51
81 #define CFGTOK_ALIGN            52
82 #define CFGTOK_OFFSET           53
83
84 #define CFGTOK_RO               60
85 #define CFGTOK_RW               61
86 #define CFGTOK_BSS              62
87 #define CFGTOK_ZP               63
88 #define CFGTOK_WPROT            64
89
90 #define CFGTOK_O65              70
91 #define CFGTOK_BIN              71
92
93 #define CFGTOK_SMALL            80
94 #define CFGTOK_LARGE            81
95
96 #define CFGTOK_TRUE             90
97 #define CFGTOK_FALSE            91
98
99 #define CFGTOK_LUNIX            100
100 #define CFGTOK_OSA65            101
101
102
103
104 /* Mapping table entry, special identifier --> token */
105 typedef struct IdentTok_ IdentTok;
106 struct IdentTok_ {
107     const char*         Ident;          /* Identifier */
108     unsigned            Tok;            /* Token for identifier */
109 };
110 #define ENTRY_COUNT(s)  (sizeof (s) / sizeof (s [0]))
111
112
113
114 /* Current token and attributes */
115 #define CFG_MAX_IDENT_LEN  255
116 extern unsigned         CfgTok;
117 extern char             CfgSVal [CFG_MAX_IDENT_LEN+1];
118 extern unsigned long    CfgIVal;
119
120 /* Error location */
121 extern unsigned         CfgErrorLine;
122 extern unsigned         CfgErrorCol;
123
124
125
126 /*****************************************************************************/
127 /*                                   Code                                    */
128 /*****************************************************************************/
129
130
131
132 void CfgWarning (const char* Format, ...);
133 /* Print a warning message adding file name and line number of the config file */
134
135 void CfgError (const char* Format, ...);
136 /* Print an error message adding file name and line number of the config file */
137
138 void CfgNextTok (void);
139 /* Read the next token from the input stream */
140
141 void CfgConsume (unsigned T, const char* Msg);
142 /* Skip a token, print an error message if not found */
143
144 void CfgConsumeSemi (void);
145 /* Consume a semicolon */
146
147 void CfgConsumeColon (void);
148 /* Consume a colon */
149
150 void CfgOptionalComma (void);
151 /* Consume a comma if there is one */
152
153 void CfgOptionalAssign (void);
154 /* Consume an equal sign if there is one */
155
156 void CfgAssureInt (void);
157 /* Make sure the next token is an integer */
158
159 void CfgAssureStr (void);
160 /* Make sure the next token is a string constant */
161
162 void CfgAssureIdent (void);
163 /* Make sure the next token is an identifier */
164
165 void CfgRangeCheck (unsigned long Lo, unsigned long Hi);
166 /* Check the range of CfgIVal */
167
168 void CfgSpecialToken (const IdentTok* Table, unsigned Size, const char* Name);
169 /* Map an identifier to one of the special tokens in the table */
170
171 void CfgBoolToken (void);
172 /* Map an identifier or integer to a boolean token */
173
174 void CfgSetName (const char* Name);
175 /* Set a name for a config file */
176
177 const char* CfgGetName (void);
178 /* Get the name of the config file */
179
180 void CfgSetBuf (const char* Buf);
181 /* Set a memory buffer for the config */
182
183 int CfgAvail (void);
184 /* Return true if we have a configuration available */
185
186 void CfgOpenInput (void);
187 /* Open the input file if we have one */
188
189 void CfgCloseInput (void);
190 /* Close the input file if we have one */
191
192
193
194 /* End of scanner.h */
195 #endif
196
197
198