4 * (C) Copyright 1989-1995
11 * 28-Oct-97 JLH bug in getst(): sign extend on ~(SPACE|ILL)
12 * causes infinite loop
16 * Extensions: P. Felber, M. Hope
22 #include "dbuf_string.h"
27 * The module aslex.c includes the general lexical
28 * analysis routines for the assembler.
30 * aslex.c contains the following functions:
41 * aslex.c contains no local/static variables
44 /*)Function VOID getid(id,c)
46 * char * id a pointer to a string of
49 * >=0 this is first character to
50 * copy to the string buffer
51 * <0 skip white space, first
52 * character must be a LETTER
54 * The function getid() scans the current assembler-source text line
55 * from the current position copying the next LETTER | DIGIT string
56 * into the external string buffer (id). The string ends when a non
57 * LETTER or DIGIT character is found. The maximum number of
58 * characters copied is NCPS. If the input string is larger than
59 * NCPS characters then the string is truncated, if the input string
60 * is shorter than NCPS characters then the string is NULL filled.
61 * If the mode argument (c) is >=0 then (c) is the first character
62 * copied to the string buffer, if (c) is <0 then intervening white
63 * space (SPACES and TABS) are skipped and the first character found
64 * must be a LETTER else a 'q' error terminates the parse of this
65 * assembler-source text line.
68 * char * p pointer to external string buffer
69 * int c current character value
72 * char ctype[] a character array which defines the
73 * type of character being processed.
74 * This index is the character
79 * char getnb() aslex.c
80 * VOID unget() aslex.c
83 * use of getnb(), get(), and unget() updates the
84 * global pointer ip, the position in the current
85 * assembler-source text line.
97 if ((ctype[c] & LETTER) == 0)
104 } while (ctype[c=get()] & (LETTER|DIGIT));
106 while (p < &id[NCPS])
110 /*)Function VOID getst(id,c)
112 * char * id a pointer to a string of
113 * maximum length NCPS
115 * >=0 this is first character to
116 * copy to the string buffer
117 * <0 skip white space, first
118 * character must be a LETTER
120 * The function getnbid() scans the current assembler-source text line
121 * from the current position copying the next character string into
122 * the external string buffer (id). The string ends when a SPACE or
123 * ILL character is found. The maximum number of
124 * characters copied is NCPS. If the input string is larger than
125 * NCPS characters then the string is truncated, if the input string
126 * is shorter than NCPS characters then the string is NULL filled.
127 * If the mode argument (c) is >=0 then (c) is the first character
128 * copied to the string buffer, if (c) is <0 then intervening white
129 * space (SPACES and TABS) are skipped and the first character found
130 * must be a LETTER else a 'q' error terminates the parse of this
131 * assembler-source text line.
134 * char * p pointer to external string buffer
135 * int c current character value
138 * char ctype[] a character array which defines the
139 * type of character being processed.
140 * This index is the character
145 * char getnb() aslex.c
146 * VOID unget() aslex.c
149 * use of getnb(), get(), and unget() updates the
150 * global pointer ip, the position in the current
151 * assembler-source text line.
163 if ((ctype[c] & LETTER) == 0)
170 } while (ctype[c=get()] & (0xFF - (SPACE|ILL)));
172 while (p < &id[NCPS])
176 /*)Function char getnb()
178 * The function getnb() scans the current assembler-source
179 * text line returning the first character not a SPACE or TAB.
182 * int c current character from
183 * assembler-source text line
192 * use of get() updates the global pointer ip, the position
193 * in the current assembler-source text line
201 while ((c=get()) == ' ' || c == '\t')
206 /*)Function char get()
208 * The function get() returns the next character in the
209 * assembler-source text line, at the end of the line a
210 * NULL character is returned.
213 * int c current character from
214 * assembler-source text line
217 * char * ip pointer into the current
218 * assembler-source text line
224 * updates ip to the next character position in the
225 * assembler-source text line. If ip is at the end of the
226 * line, ip is not updated.
239 /*)Function VOID unget(c)
241 * int c value of last character read from
242 * assembler-source text line
244 * If (c) is not a NULL character then the global pointer ip
245 * is updated to point to the preceeding character in the
246 * assembler-source text line.
248 * NOTE: This function does not push the character (c)
249 * back into the assembler-source text line, only
250 * the pointer ip is changed.
253 * int c last character read from
254 * assembler-source text line
257 * char * ip position into the current
258 * assembler-source text line
264 * ip decremented by 1 character position
275 /*)Function int getmap(d)
277 * int d value to compare with the
278 * assembler-source text line character
280 * The function getmap() converts the 'C' style characters \b, \f,
281 * \n, \r, and \t to their equivalent ascii values and also
282 * converts 'C' style octal constants '\123' to their equivalent
283 * numeric values. If the first character is equivalent to (d) then
284 * a (-1) is returned, if the end of the line is detected then
285 * a 'q' error terminates the parse for this line, or if the first
286 * character is not a \ then the character value is returned.
289 * int c value of character from the
290 * assembler-source text line
291 * int n looping counter
292 * int v current value of numeric conversion
301 * use of get() updates the global pointer ip the position
302 * in the current assembler-source text line
308 register int c, n, v;
310 if ((c=get()) == '\0')
348 while (++n<=3 && c>='0' && c<='7') {
349 v = (v<<3) + c - '0';
360 /*)Function int as_getline()
362 * The function as_getline() reads a line of assembler-source text
363 * from an assembly source text file or an include file.
364 * Lines of text are processed from assembler-source files until
365 * all files have been read. If an include file is opened then
366 * lines of text are read from the include file (or nested
367 * include file) until the end of the include file is found.
368 * The input text line is copied into the global string ib[]
369 * and converted to a NULL terminated string. The function
370 * as_getline() returns a (1) after succesfully reading a line
371 * or a (0) if all files have been read.
374 * int i string length
377 * const char ib[] string buffer containing
378 * assembler-source text line
379 * char ifp[] array of file handles for
381 * int incfil index for ifp[] specifies
382 * active include file
383 * int incline[] array of include file
385 * char sfp[] array of file handles for
386 * assembler source files
387 * int cfile index for sfp[] specifies
389 * int srcline[] array of source file
391 * int inpfil maximum input file index
395 * int dbuf_set_length()
397 * const char * dbuf_c_str()
398 * int fclose() c-library
399 * char * fgets() c-library
400 * int strlen() c-library
403 * include file will be closed at detection of end of file.
404 * the next sequential source file may be selected.
405 * the global file indexes incfil or cfile may be changed.
406 * The respective source line or include line counter
413 static struct dbuf_s dbuf;
414 static char dbufInitialized = 0;
417 if (!dbufInitialized)
419 dbuf_init (&dbuf, 1024);
423 dbuf_set_length (&dbuf, 0);
428 if ((len = dbuf_getline (&dbuf, ifp[incfil])) == 0)
430 fclose (ifp[incfil]);
431 ifp[incfil--] = NULL;
442 if ((len = dbuf_getline (&dbuf, sfp[cfile])) == 0)
444 if (++cfile <= inpfil)
456 ib = dbuf_c_str (&dbuf);
458 /* remove the trailing NL */
459 if (len > 0 && '\n' == ib[len - 1])
462 if (len > 0 && '\r' == ib[len - 1])
464 dbuf_set_length (&dbuf, len);
465 ib = dbuf_c_str (&dbuf);
471 /*)Function int more()
473 * The function more() scans the assembler-source text line
474 * skipping white space (SPACES and TABS) and returns a (0)
475 * if the end of the line or a comment delimeter (;) is found,
476 * or a (1) if their are additional characters in the line.
479 * int c next character from the
480 * assembler-source text line
486 * char getnb() aslex.c
487 * VOID unget() aslex.c
490 * use of getnb() and unget() updates the global pointer ip
491 * the position in the current assembler-source text line
501 return( (c == '\0' || c == ';') ? 0 : 1 );
504 /*)Function char endline()
506 * The function endline() scans the assembler-source text line
507 * skipping white space (SPACES and TABS) and returns the next
508 * character or a (0) if the end of the line is found or a
509 * comment delimiter (;) is found.
512 * int c next character from the
513 * assembler-source text line
519 * char getnb() aslex.c
522 * use of getnb() updates the global pointer ip the
523 * position in the current assembler-source text line
532 return( (c == '\0' || c == ';') ? 0 : c );