4 * (C) Copyright 1989-1995
11 * 28-Oct-97 JLH bug in getst(): sign extend on ~(SPACE|ILL)
12 * causes infinite loop
18 //#if !defined(_MSC_VER)
25 * The module aslex.c includes the general lexical
26 * analysis routines for the assembler.
28 * aslex.c contains the following functions:
39 * aslex.c contains no local/static variables
42 /*)Function VOID getid(id,c)
44 * char * id a pointer to a string of
47 * >=0 this is first character to
48 * copy to the string buffer
49 * <0 skip white space, first
50 * character must be a LETTER
52 * The function getid() scans the current assembler-source text line
53 * from the current position copying the next LETTER | DIGIT string
54 * into the external string buffer (id). The string ends when a non
55 * LETTER or DIGIT character is found. The maximum number of
56 * characters copied is NCPS. If the input string is larger than
57 * NCPS characters then the string is truncated, if the input string
58 * is shorter than NCPS characters then the string is NULL filled.
59 * If the mode argument (c) is >=0 then (c) is the first character
60 * copied to the string buffer, if (c) is <0 then intervening white
61 * space (SPACES and TABS) are skipped and the first character found
62 * must be a LETTER else a 'q' error terminates the parse of this
63 * assembler-source text line.
66 * char * p pointer to external string buffer
67 * int c current character value
70 * char ctype[] a character array which defines the
71 * type of character being processed.
72 * This index is the character
77 * char getnb() aslex.c
78 * VOID unget() aslex.c
81 * use of getnb(), get(), and unget() updates the
82 * global pointer ip, the position in the current
83 * assembler-source text line.
95 if ((ctype[c] & LETTER) == 0)
102 } while (ctype[c=get()] & (LETTER|DIGIT));
104 while (p < &id[NCPS])
108 /*)Function VOID getst(id,c)
110 * char * id a pointer to a string of
111 * maximum length NCPS
113 * >=0 this is first character to
114 * copy to the string buffer
115 * <0 skip white space, first
116 * character must be a LETTER
118 * The function getnbid() scans the current assembler-source text line
119 * from the current position copying the next character string into
120 * the external string buffer (id). The string ends when a SPACE or
121 * ILL character is found. The maximum number of
122 * characters copied is NCPS. If the input string is larger than
123 * NCPS characters then the string is truncated, if the input string
124 * is shorter than NCPS characters then the string is NULL filled.
125 * If the mode argument (c) is >=0 then (c) is the first character
126 * copied to the string buffer, if (c) is <0 then intervening white
127 * space (SPACES and TABS) are skipped and the first character found
128 * must be a LETTER else a 'q' error terminates the parse of this
129 * assembler-source text line.
132 * char * p pointer to external string buffer
133 * int c current character value
136 * char ctype[] a character array which defines the
137 * type of character being processed.
138 * This index is the character
143 * char getnb() aslex.c
144 * VOID unget() aslex.c
147 * use of getnb(), get(), and unget() updates the
148 * global pointer ip, the position in the current
149 * assembler-source text line.
161 if ((ctype[c] & LETTER) == 0)
168 } while (ctype[c=get()] & (0xFF - (SPACE|ILL)));
170 while (p < &id[NCPS])
174 /*)Function char getnb()
176 * The function getnb() scans the current assembler-source
177 * text line returning the first character not a SPACE or TAB.
180 * int c current character from
181 * assembler-source text line
190 * use of get() updates the global pointer ip, the position
191 * in the current assembler-source text line
199 while ((c=get()) == ' ' || c == '\t')
204 /*)Function char get()
206 * The function get() returns the next character in the
207 * assembler-source text line, at the end of the line a
208 * NULL character is returned.
211 * int c current character from
212 * assembler-source text line
215 * char * ip pointer into the current
216 * assembler-source text line
222 * updates ip to the next character position in the
223 * assembler-source text line. If ip is at the end of the
224 * line, ip is not updated.
237 /*)Function VOID unget(c)
239 * int c value of last character read from
240 * assembler-source text line
242 * If (c) is not a NULL character then the global pointer ip
243 * is updated to point to the preceeding character in the
244 * assembler-source text line.
246 * NOTE: This function does not push the character (c)
247 * back into the assembler-source text line, only
248 * the pointer ip is changed.
251 * int c last character read from
252 * assembler-source text line
255 * char * ip position into the current
256 * assembler-source text line
262 * ip decremented by 1 character position
273 /*)Function int getmap(d)
275 * int d value to compare with the
276 * assembler-source text line character
278 * The function getmap() converts the 'C' style characters \b, \f,
279 * \n, \r, and \t to their equivalent ascii values and also
280 * converts 'C' style octal constants '\123' to their equivalent
281 * numeric values. If the first character is equivalent to (d) then
282 * a (-1) is returned, if the end of the line is detected then
283 * a 'q' error terminates the parse for this line, or if the first
284 * character is not a \ then the character value is returned.
287 * int c value of character from the
288 * assembler-source text line
289 * int n looping counter
290 * int v current value of numeric conversion
299 * use of get() updates the global pointer ip the position
300 * in the current assembler-source text line
306 register int c, n, v;
308 if ((c=get()) == '\0')
346 while (++n<=3 && c>='0' && c<='7') {
347 v = (v<<3) + c - '0';
358 /*)Function int getline()
360 * The function getline() reads a line of assembler-source text
361 * from an assembly source text file or an include file.
362 * Lines of text are processed from assembler-source files until
363 * all files have been read. If an include file is opened then
364 * lines of text are read from the include file (or nested
365 * include file) until the end of the include file is found.
366 * The input text line is copied into the global string ib[]
367 * and converted to a NULL terminated string. The function
368 * getline() returns a (1) after succesfully reading a line
369 * or a (0) if all files have been read.
372 * int i string length
375 * char ib[] string buffer containing
376 * assembler-source text line
377 * char ifp[] array of file handles for
379 * int incfil index for ifp[] specifies
380 * active include file
381 * int incline[] array of include file
383 * char sfp[] array of file handles for
384 * assembler source files
385 * int cfile index for sfp[] specifies
387 * int srcline[] array of source file
389 * int inpfil maximum input file index
392 * int fclose() c-library
393 * char * fgets() c-library
394 * int strlen() c-library
397 * include file will be closed at detection of end of file.
398 * the next sequential source file may be selected.
399 * the global file indexes incfil or cfile may be changed.
400 * The respective source line or include line counter
407 loop: if (incfil >= 0) {
408 if (fgets(ib, sizeof ib, ifp[incfil]) == NULL) {
409 fclose(ifp[incfil--]);
416 if (fgets(ib, sizeof ib, sfp[cfile]) == NULL) {
417 if (++cfile <= inpfil) {
430 /*)Function int more()
432 * The function more() scans the assembler-source text line
433 * skipping white space (SPACES and TABS) and returns a (0)
434 * if the end of the line or a comment delimeter (;) is found,
435 * or a (1) if their are additional characters in the line.
438 * int c next character from the
439 * assembler-source text line
445 * char getnb() aslex.c
446 * VOID unget() aslex.c
449 * use of getnb() and unget() updates the global pointer ip
450 * the position in the current assembler-source text line
460 return( (c == '\0' || c == ';') ? 0 : 1 );
463 /*)Function char endline()
465 * The function endline() scans the assembler-source text line
466 * skipping white space (SPACES and TABS) and returns the next
467 * character or a (0) if the end of the line is found or a
468 * comment delimiter (;) is found.
471 * int c next character from the
472 * assembler-source text line
478 * char getnb() aslex.c
481 * use of getnb() updates the global pointer ip the
482 * position in the current assembler-source text line
491 return( (c == '\0' || c == ';') ? 0 : c );
494 /*)Function VOID chop_crlf(str)
496 * char *str string to chop
498 * The function chop_crlf() removes trailing LF or CR/LF from
502 * int i string length
521 if (i >= 1 && str[i-1] == '\n') str[i-1] = 0;
522 if (i >= 2 && str[i-2] == '\r') str[i-2] = 0;