4 * (C) Copyright 1989-1995
18 * The module lklex.c contains the general lexical analysis
19 * functions used to scan the text lines from the .rel files.
21 * lklex.c contains the fllowing functions:
33 * lklex.c contains no local variables.
36 /*)Function VOID getid(id,c)
38 * char * id a pointer to a string of
41 * >=0 this is first character to
42 * copy to the string buffer
45 * The function getid() scans the current input text line
46 * from the current position copying the next LETTER | DIGIT string
47 * into the external string buffer (id). The string ends when a non
48 * LETTER or DIGIT character is found. The maximum number of
49 * characters copied is NCPS. If the input string is larger than
50 * NCPS characters then the string is truncated, if the input string
51 * is shorter than NCPS characters then the string is NULL filled.
52 * If the mode argument (c) is >=0 then (c) is the first character
53 * copied to the string buffer, if (c) is <0 then intervening white
54 * space (SPACES and TABS) are skipped.
57 * char * p pointer to external string buffer
58 * int c current character value
61 * char ctype[] a character array which defines the
62 * type of character being processed.
63 * This index is the character
68 * char getnb() lklex.c
69 * VOID unget() lklex.c
72 * use of getnb(), get(), and unget() updates the
73 * global pointer ip the position in the current
91 } while (ctype[c=get()] & (LETTER|DIGIT));
97 /*)Function VOID getfid(fid,c)
99 * char * str a pointer to a string of
100 * maximum length FILSPC
101 * int c this is first character to
102 * copy to the string buffer
104 * The function getfid() scans the current input text line
105 * from the current position copying the next string
106 * into the external string buffer (str). The string ends when a
107 * non SPACE type character is found. The maximum number of
108 * characters copied is FILSPC. If the input string is larger than
109 * FILSPC characters then the string is truncated, if the input string
110 * is shorter than FILSPC characters then the string is NULL filled.
113 * char * p pointer to external string buffer
114 * int c current character value
117 * char ctype[] a character array which defines the
118 * type of character being processed.
119 * This index is the character
126 * use of get() updates the global pointer ip
127 * the position in the current input text line.
139 if (p < &str[FILSPC-1])
142 } while (c && ((ctype[c] != SPACE)||(c == ':')||(c == '\\')));
143 while (p < &str[FILSPC])
147 /*)Function char getnb()
149 * The function getnb() scans the current input text
150 * line returning the first character not a SPACE or TAB.
153 * int c current character from input
162 * use of get() updates the global pointer ip, the position
163 * in the current input text line
171 while ((c=get())==' ' || c=='\t')
176 /*)Function VOID skip()
178 * The function skip() scans the input text skipping all
179 * letters and digits.
185 * char ctype[] array of character types, one per
190 * char getnb() lklex.c
191 * VOID unget() lklex.c
194 * Input letters and digits are skipped.
203 while (ctype[c=get()] & (LETTER|DIGIT)) { ; }
207 /*)Function char get()
209 * The function get() returns the next character in the
210 * input text line, at the end of the line a
211 * NULL character is returned.
214 * int c current character from
218 * char * ip pointer into the current
225 * updates ip to the next character position in the
226 * input text line. If ip is at the end of the
227 * line, ip is not updated.
240 /*)Function VOID unget(c)
242 * int c value of last character
243 * read from input text line
245 * If (c) is not a NULL character then the global pointer ip
246 * is updated to point to the preceeding character in the
249 * NOTE: This function does not push the character (c)
250 * back into the input text line, only
251 * the pointer ip is changed.
254 * int c last character read
255 * from input text line
258 * char * ip position into the current
265 * ip decremented by 1 character position
275 /*)Function int getmap(d)
277 * int d value to compare with the
278 * input 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
290 * from input text line
291 * int n looping counter
292 * int v current value of numeric conversion
299 * VOID unget() lklex.c
302 * use of get() updates the global pointer ip the position
303 * in the current input text line
309 register int c, n, v;
311 if ((c = get()) == '\0')
349 while (++n<=3 && c>='0' && c<='7') {
350 v = (v<<3) + c - '0';
361 /*)Function int getline()
363 * The function getline() reads a line of input text from a
364 * .rel source text file, a .lnk command file or from stdin.
365 * Lines of text are processed from a single .lnk file or
366 * multiple .rel files until all files have been read.
367 * The input text line is copied into the global string ib[]
368 * and converted to a NULL terminated string. The function
369 * getline() returns a (1) after succesfully reading a line
370 * or a (0) if all files have been read.
371 * This function also opens each input .lst file and output
372 * .rst file as each .rel file is processed.
375 * int i string length
376 * int ftype file type
377 * char * fid file name
380 * lfile *cfp The pointer *cfp points to the
381 * current lfile structure
382 * lfile *filep The pointer *filep points to the
383 * beginning of a linked list of
385 * int gline get a line from the LST file
386 * to translate for the RST file
387 * char ib[NINPUT] REL file text line
388 * int pass linker pass number
389 * int pflag print linker command file flag
390 * FILE *rfp The file handle to the current
392 * FILE *sfp The file handle sfp points to the
393 * currently open file
394 * FILE * stdin c_library
395 * FILE * stdout c_library
396 * FILE *tfp The file handle to the current
397 * LST file being scanned
398 * int uflag update listing flag
401 * FILE * afile() lkmain.c
402 * int fclose() c_library
403 * char * fgets() c_library
404 * int fprintf() c_library
405 * VOID lkulist() lklist.c
406 * VOID lkexit() lkmain.c
407 * int strlen() c_library
410 * The input stream is scanned. The .rel files will be
411 * opened and closed sequentially scanning each in turn.
420 loop: if (pflag && cfp && cfp->f_type == F_STD)
421 fprintf(stdout, "ASlink >> ");
423 if (sfp == NULL || fgets(ib, sizeof ib, sfp) == NULL) {
437 if (ftype == F_STD) {
440 if (ftype == F_LNK) {
441 sfp = afile(fid, "lnk", 0);
443 if (ftype == F_REL) {
444 sfp = afile(fid, "rel", 0);
445 /* if a .cdb file exists then copy it over */
446 if (dflag && sfp && dfp && pass == 0) {
447 FILE *xfp = afile(fid,"cdb",0);
453 if (uflag && pass != 0) {
454 if ((tfp = afile(fid, "lst", 0)) != NULL) {
455 if ((rfp = afile(fid, "rst", 1)) == NULL) {
463 fprintf(stderr, "Invalid file type\n");
479 /*)Function int more()
481 * The function more() scans the input text line
482 * skipping white space (SPACES and TABS) and returns a (0)
483 * if the end of the line or a comment delimeter (;) is found,
484 * or a (1) if their are additional characters in the line.
487 * int c next character from
488 * the input text line
494 * char getnb() lklex.c
495 * VOID unget() lklex.c
498 * use of getnb() and unget() updates the global pointer ip
499 * the position in the current input text line
509 return( (c == '\0' || c == ';') ? 0 : 1 );
512 /*)Function char endline()
514 * The function endline() scans the input text line
515 * skipping white space (SPACES and TABS) and returns the next
516 * character or a (0) if the end of the line is found or a
517 * comment delimiter (;) is found.
520 * int c next character from
521 * the input text line
527 * char getnb() lklex.c
530 * Use of getnb() updates the global pointer ip the
531 * position in the current input text line.
540 return( (c == '\0' || c == ';') ? 0 : c );
543 /*)Function VOID chop_crlf(str)
545 * char *str string to chop
547 * The function chop_crlf() removes trailing LF or CR/LF from
551 * int i string length
570 if (i >= 1 && str[i-1] == '\n') str[i-1] = 0;
571 if (i >= 2 && str[i-2] == '\r') str[i-2] = 0;