4 * (C) Copyright 1989-1995
11 * 28-Oct-97 JLH bug in getst(): sign extend on ~(SPACE|ILL)
12 * causes infinite loop
22 * The module aslex.c includes the general lexical
23 * analysis routines for the assembler.
25 * aslex.c contains the following functions:
36 * aslex.c contains no local/static variables
39 /*)Function VOID getid(id,c)
41 * char * id a pointer to a string of
44 * >=0 this is first character to
45 * copy to the string buffer
46 * <0 skip white space, first
47 * character must be a LETTER
49 * The function getid() scans the current assembler-source text line
50 * from the current position copying the next LETTER | DIGIT string
51 * into the external string buffer (id). The string ends when a non
52 * LETTER or DIGIT character is found. The maximum number of
53 * characters copied is NCPS. If the input string is larger than
54 * NCPS characters then the string is truncated, if the input string
55 * is shorter than NCPS characters then the string is NULL filled.
56 * If the mode argument (c) is >=0 then (c) is the first character
57 * copied to the string buffer, if (c) is <0 then intervening white
58 * space (SPACES and TABS) are skipped and the first character found
59 * must be a LETTER else a 'q' error terminates the parse of this
60 * assembler-source text line.
63 * char * p pointer to external string buffer
64 * int c current character value
67 * char ctype[] a character array which defines the
68 * type of character being processed.
69 * This index is the character
74 * char getnb() aslex.c
75 * VOID unget() aslex.c
78 * use of getnb(), get(), and unget() updates the
79 * global pointer ip, the position in the current
80 * assembler-source text line.
92 if ((ctype[c] & LETTER) == 0)
99 } while (ctype[c=get()] & (LETTER|DIGIT));
101 while (p < &id[NCPS])
105 /*)Function VOID getst(id,c)
107 * char * id a pointer to a string of
108 * maximum length NCPS
110 * >=0 this is first character to
111 * copy to the string buffer
112 * <0 skip white space, first
113 * character must be a LETTER
115 * The function getnbid() scans the current assembler-source text line
116 * from the current position copying the next character string into
117 * the external string buffer (id). The string ends when a SPACE or
118 * ILL character is found. The maximum number of
119 * characters copied is NCPS. If the input string is larger than
120 * NCPS characters then the string is truncated, if the input string
121 * is shorter than NCPS characters then the string is NULL filled.
122 * If the mode argument (c) is >=0 then (c) is the first character
123 * copied to the string buffer, if (c) is <0 then intervening white
124 * space (SPACES and TABS) are skipped and the first character found
125 * must be a LETTER else a 'q' error terminates the parse of this
126 * assembler-source text line.
129 * char * p pointer to external string buffer
130 * int c current character value
133 * char ctype[] a character array which defines the
134 * type of character being processed.
135 * This index is the character
140 * char getnb() aslex.c
141 * VOID unget() aslex.c
144 * use of getnb(), get(), and unget() updates the
145 * global pointer ip, the position in the current
146 * assembler-source text line.
158 if ((ctype[c] & LETTER) == 0)
165 } while (ctype[c=get()] & (0xFF - (SPACE|ILL)));
167 while (p < &id[NCPS])
171 /*)Function char getnb()
173 * The function getnb() scans the current assembler-source
174 * text line returning the first character not a SPACE or TAB.
177 * int c current character from
178 * assembler-source text line
187 * use of get() updates the global pointer ip, the position
188 * in the current assembler-source text line
196 while ((c=get()) == ' ' || c == '\t')
201 /*)Function char get()
203 * The function get() returns the next character in the
204 * assembler-source text line, at the end of the line a
205 * NULL character is returned.
208 * int c current character from
209 * assembler-source text line
212 * char * ip pointer into the current
213 * assembler-source text line
219 * updates ip to the next character position in the
220 * assembler-source text line. If ip is at the end of the
221 * line, ip is not updated.
234 /*)Function VOID unget(c)
236 * int c value of last character read from
237 * assembler-source text line
239 * If (c) is not a NULL character then the global pointer ip
240 * is updated to point to the preceeding character in the
241 * assembler-source text line.
243 * NOTE: This function does not push the character (c)
244 * back into the assembler-source text line, only
245 * the pointer ip is changed.
248 * int c last character read from
249 * assembler-source text line
252 * char * ip position into the current
253 * assembler-source text line
259 * ip decremented by 1 character position
270 /*)Function int getmap(d)
272 * int d value to compare with the
273 * assembler-source text line character
275 * The function getmap() converts the 'C' style characters \b, \f,
276 * \n, \r, and \t to their equivalent ascii values and also
277 * converts 'C' style octal constants '\123' to their equivalent
278 * numeric values. If the first character is equivalent to (d) then
279 * a (-1) is returned, if the end of the line is detected then
280 * a 'q' error terminates the parse for this line, or if the first
281 * character is not a \ then the character value is returned.
284 * int c value of character from the
285 * assembler-source text line
286 * int n looping counter
287 * int v current value of numeric conversion
296 * use of get() updates the global pointer ip the position
297 * in the current assembler-source text line
303 register int c, n, v;
305 if ((c=get()) == '\0')
343 while (++n<=3 && c>='0' && c<='7') {
344 v = (v<<3) + c - '0';
355 /*)Function int getline()
357 * The function getline() reads a line of assembler-source text
358 * from an assembly source text file or an include file.
359 * Lines of text are processed from assembler-source files until
360 * all files have been read. If an include file is opened then
361 * lines of text are read from the include file (or nested
362 * include file) until the end of the include file is found.
363 * The input text line is copied into the global string ib[]
364 * and converted to a NULL terminated string. The function
365 * getline() returns a (1) after succesfully reading a line
366 * or a (0) if all files have been read.
369 * int i string length
372 * char ib[] string buffer containing
373 * assembler-source text line
374 * char ifp[] array of file handles for
376 * int incfil index for ifp[] specifies
377 * active include file
378 * int incline[] array of include file
380 * char sfp[] array of file handles for
381 * assembler source files
382 * int cfile index for sfp[] specifies
384 * int srcline[] array of source file
386 * int inpfil maximum input file index
389 * int fclose() c-library
390 * char * fgets() c-library
391 * int strlen() c-library
394 * include file will be closed at detection of end of file.
395 * the next sequential source file may be selected.
396 * the global file indexes incfil or cfile may be changed.
397 * The respective source line or include line counter
404 loop: if (incfil >= 0) {
405 if (fgets(ib, sizeof ib, ifp[incfil]) == NULL) {
406 fclose(ifp[incfil--]);
413 if (fgets(ib, sizeof ib, sfp[cfile]) == NULL) {
414 if (++cfile <= inpfil) {
427 /*)Function int more()
429 * The function more() scans the assembler-source text line
430 * skipping white space (SPACES and TABS) and returns a (0)
431 * if the end of the line or a comment delimeter (;) is found,
432 * or a (1) if their are additional characters in the line.
435 * int c next character from the
436 * assembler-source text line
442 * char getnb() aslex.c
443 * VOID unget() aslex.c
446 * use of getnb() and unget() updates the global pointer ip
447 * the position in the current assembler-source text line
457 return( (c == '\0' || c == ';') ? 0 : 1 );
460 /*)Function char endline()
462 * The function endline() scans the assembler-source text line
463 * skipping white space (SPACES and TABS) and returns the next
464 * character or a (0) if the end of the line is found or a
465 * comment delimiter (;) is found.
468 * int c next character from the
469 * assembler-source text line
475 * char getnb() aslex.c
478 * use of getnb() updates the global pointer ip the
479 * position in the current assembler-source text line
488 return( (c == '\0' || c == ';') ? 0 : c );
491 /*)Function VOID chop_crlf(str)
493 * char *str string to chop
495 * The function chop_crlf() removes trailing LF or CR/LF from
499 * int i string length
518 if (i >= 1 && str[i-1] == '\n') str[i-1] = 0;
519 if (i >= 2 && str[i-2] == '\r') str[i-2] = 0;