4 * (C) Copyright 1989-1995
19 * The module lklex.c contains the general lexical analysis
20 * functions used to scan the text lines from the .rel files.
22 * lklex.c contains the fllowing functions:
34 * lklex.c contains no local variables.
37 /*)Function VOID getid(id,c)
39 * char * id a pointer to a string of
42 * >=0 this is first character to
43 * copy to the string buffer
46 * The function getid() scans the current input text line
47 * from the current position copying the next LETTER | DIGIT string
48 * into the external string buffer (id). The string ends when a non
49 * LETTER or DIGIT character is found. The maximum number of
50 * characters copied is NCPS. If the input string is larger than
51 * NCPS characters then the string is truncated, if the input string
52 * is shorter than NCPS characters then the string is NULL filled.
53 * If the mode argument (c) is >=0 then (c) is the first character
54 * copied to the string buffer, if (c) is <0 then intervening white
55 * space (SPACES and TABS) are skipped.
58 * char * p pointer to external string buffer
59 * int c current character value
62 * char ctype[] a character array which defines the
63 * type of character being processed.
64 * This index is the character
69 * char getnb() lklex.c
70 * VOID unget() lklex.c
73 * use of getnb(), get(), and unget() updates the
74 * global pointer ip the position in the current
92 } while (ctype[c=get()] & (LETTER|DIGIT));
98 /*)Function VOID getfid(fid,c)
100 * char * str a pointer to a string of
101 * maximum length FILSPC
102 * int c this is first character to
103 * copy to the string buffer
105 * The function getfid() scans the current input text line
106 * from the current position copying the next string
107 * into the external string buffer (str). The string ends when a
108 * non SPACE type character is found. The maximum number of
109 * characters copied is FILSPC. If the input string is larger than
110 * FILSPC characters then the string is truncated, if the input string
111 * is shorter than FILSPC characters then the string is NULL filled.
114 * char * p pointer to external string buffer
115 * int c current character value
118 * char ctype[] a character array which defines the
119 * type of character being processed.
120 * This index is the character
127 * use of get() updates the global pointer ip
128 * the position in the current input text line.
140 if (p < &str[FILSPC-1])
143 } while (c && (ctype[c] != SPACE));
144 while (p < &str[FILSPC])
148 /*)Function char getnb()
150 * The function getnb() scans the current input text
151 * line returning the first character not a SPACE or TAB.
154 * int c current character from input
163 * use of get() updates the global pointer ip, the position
164 * in the current input text line
172 while ((c=get())==' ' || c=='\t')
177 /*)Function VOID skip()
179 * The function skip() scans the input text skipping all
180 * letters and digits.
186 * char ctype[] array of character types, one per
191 * char getnb() lklex.c
192 * VOID unget() lklex.c
195 * Input letters and digits are skipped.
204 while (ctype[c=get()] & (LETTER|DIGIT)) { ; }
208 /*)Function char get()
210 * The function get() returns the next character in the
211 * input text line, at the end of the line a
212 * NULL character is returned.
215 * int c current character from
219 * char * ip pointer into the current
226 * updates ip to the next character position in the
227 * input text line. If ip is at the end of the
228 * line, ip is not updated.
241 /*)Function VOID unget(c)
243 * int c value of last character
244 * read from input text line
246 * If (c) is not a NULL character then the global pointer ip
247 * is updated to point to the preceeding character in the
250 * NOTE: This function does not push the character (c)
251 * back into the input text line, only
252 * the pointer ip is changed.
255 * int c last character read
256 * from input text line
259 * char * ip position into the current
266 * ip decremented by 1 character position
276 /*)Function int getmap(d)
278 * int d value to compare with the
279 * input text line character
281 * The function getmap() converts the 'C' style characters \b, \f,
282 * \n, \r, and \t to their equivalent ascii values and also
283 * converts 'C' style octal constants '\123' to their equivalent
284 * numeric values. If the first character is equivalent to (d) then
285 * a (-1) is returned, if the end of the line is detected then
286 * a 'q' error terminates the parse for this line, or if the first
287 * character is not a \ then the character value is returned.
290 * int c value of character
291 * from input text line
292 * int n looping counter
293 * int v current value of numeric conversion
300 * VOID unget() lklex.c
303 * use of get() updates the global pointer ip the position
304 * in the current input text line
310 register int c, n, v;
312 if ((c = get()) == '\0')
350 while (++n<=3 && c>='0' && c<='7') {
351 v = (v<<3) + c - '0';
362 /*)Function int getline()
364 * The function getline() reads a line of input text from a
365 * .rel source text file, a .lnk command file or from stdin.
366 * Lines of text are processed from a single .lnk file or
367 * multiple .rel files until all files have been read.
368 * The input text line is copied into the global string ib[]
369 * and converted to a NULL terminated string. The function
370 * getline() returns a (1) after succesfully reading a line
371 * or a (0) if all files have been read.
372 * This function also opens each input .lst file and output
373 * .rst file as each .rel file is processed.
376 * int i string length
377 * int ftype file type
378 * char * fid file name
381 * lfile *cfp The pointer *cfp points to the
382 * current lfile structure
383 * lfile *filep The pointer *filep points to the
384 * beginning of a linked list of
386 * int gline get a line from the LST file
387 * to translate for the RST file
388 * char ib[NINPUT] REL file text line
389 * int pass linker pass number
390 * int pflag print linker command file flag
391 * FILE *rfp The file handle to the current
393 * FILE *sfp The file handle sfp points to the
394 * currently open file
395 * FILE * stdin c_library
396 * FILE * stdout c_library
397 * FILE *tfp The file handle to the current
398 * LST file being scanned
399 * int uflag update listing flag
402 * FILE * afile() lkmain.c
403 * int fclose() c_library
404 * char * fgets() c_library
405 * int fprintf() c_library
406 * VOID lkulist() lklist.c
407 * VOID lkexit() lkmain.c
408 * int strlen() c_library
411 * The input stream is scanned. The .rel files will be
412 * opened and closed sequentially scanning each in turn.
421 loop: if (pflag && cfp && cfp->f_type == F_STD)
422 fprintf(stdout, "ASlink >> ");
424 if (sfp == NULL || fgets(ib, sizeof ib, sfp) == NULL) {
438 if (ftype == F_STD) {
441 if (ftype == F_LNK) {
442 sfp = afile(fid, "lnk", 0);
444 if (ftype == F_REL) {
445 sfp = afile(fid, "rel", 0);
446 /* if a .cdb file exists then copy it over */
447 if (dflag && sfp && dfp && pass == 0) {
448 FILE *xfp = afile(fid,"cdb",0);
454 if (uflag && pass != 0) {
455 if ((tfp = afile(fid, "lst", 0)) != NULL) {
456 if ((rfp = afile(fid, "rst", 1)) == NULL) {
464 fprintf(stderr, "Invalid file type\n");
480 /*)Function int more()
482 * The function more() scans the input text line
483 * skipping white space (SPACES and TABS) and returns a (0)
484 * if the end of the line or a comment delimeter (;) is found,
485 * or a (1) if their are additional characters in the line.
488 * int c next character from
489 * the input text line
495 * char getnb() lklex.c
496 * VOID unget() lklex.c
499 * use of getnb() and unget() updates the global pointer ip
500 * the position in the current input text line
510 return( (c == '\0' || c == ';') ? 0 : 1 );
513 /*)Function char endline()
515 * The function endline() scans the input text line
516 * skipping white space (SPACES and TABS) and returns the next
517 * character or a (0) if the end of the line is found or a
518 * comment delimiter (;) is found.
521 * int c next character from
522 * the input text line
528 * char getnb() lklex.c
531 * Use of getnb() updates the global pointer ip the
532 * position in the current input text line.
541 return( (c == '\0' || c == ';') ? 0 : c );
544 /*)Function VOID chop_crlf(str)
546 * char *str string to chop
548 * The function chop_crlf() removes trailing LF or CR/LF from
552 * int i string length
571 if (i >= 1 && str[i-1] == '\n') str[i-1] = 0;
572 if (i >= 2 && str[i-2] == '\r') str[i-2] = 0;