4 * (C) Copyright 1989-1995
13 * Extensions: P. Felber, M. Hope
23 * The module lklex.c contains the general lexical analysis
24 * functions used to scan the text lines from the .rel files.
26 * lklex.c contains the fllowing functions:
38 * lklex.c contains no local variables.
41 /*)Function VOID getid(id,c)
43 * char * id a pointer to a string of
46 * >=0 this is first character to
47 * copy to the string buffer
50 * The function getid() scans the current input text line
51 * from the current position copying the next LETTER | DIGIT string
52 * into the external string buffer (id). The string ends when a non
53 * LETTER or DIGIT character is found. The maximum number of
54 * characters copied is NCPS. If the input string is larger than
55 * NCPS characters then the string is truncated, if the input string
56 * is shorter than NCPS characters then the string is NULL filled.
57 * If the mode argument (c) is >=0 then (c) is the first character
58 * copied to the string buffer, if (c) is <0 then intervening white
59 * space (SPACES and TABS) are skipped.
62 * char * p pointer to external string buffer
63 * int c current character value
66 * char ctype[] a character array which defines the
67 * type of character being processed.
68 * This index is the character
73 * char getnb() lklex.c
74 * VOID unget() lklex.c
77 * use of getnb(), get(), and unget() updates the
78 * global pointer ip the position in the current
96 } while (ctype[c=get()] & (LETTER|DIGIT));
102 /*)Function VOID getfid(fid,c)
104 * char * str a pointer to a string of
105 * maximum length FILSPC
106 * int c this is first character to
107 * copy to the string buffer
109 * The function getfid() scans the current input text line
110 * from the current position copying the next string
111 * into the external string buffer (str). The string ends when a
112 * non SPACE type character is found. The maximum number of
113 * characters copied is FILSPC. If the input string is larger than
114 * FILSPC characters then the string is truncated, if the input string
115 * is shorter than FILSPC characters then the string is NULL filled.
118 * char * p pointer to external string buffer
119 * int c current character value
122 * char ctype[] a character array which defines the
123 * type of character being processed.
124 * This index is the character
131 * use of get() updates the global pointer ip
132 * the position in the current input text line.
144 if (p < &str[FILSPC-1])
153 } while (c && (ctype[c] != SPACE));
155 while (p < &str[FILSPC])
159 /*)Function char getnb()
161 * The function getnb() scans the current input text
162 * line returning the first character not a SPACE or TAB.
165 * int c current character from input
174 * use of get() updates the global pointer ip, the position
175 * in the current input text line
183 while ((c=get())==' ' || c=='\t')
188 /*)Function VOID skip()
190 * The function skip() scans the input text skipping all
191 * letters and digits.
197 * char ctype[] array of character types, one per
202 * char getnb() lklex.c
203 * VOID unget() lklex.c
206 * Input letters and digits are skipped.
215 while (ctype[c=get()] & (LETTER|DIGIT)) { ; }
219 /*)Function char get()
221 * The function get() returns the next character in the
222 * input text line, at the end of the line a
223 * NULL character is returned.
226 * int c current character from
230 * char * ip pointer into the current
237 * updates ip to the next character position in the
238 * input text line. If ip is at the end of the
239 * line, ip is not updated.
252 /*)Function VOID unget(c)
254 * int c value of last character
255 * read from input text line
257 * If (c) is not a NULL character then the global pointer ip
258 * is updated to point to the preceeding character in the
261 * NOTE: This function does not push the character (c)
262 * back into the input text line, only
263 * the pointer ip is changed.
266 * int c last character read
267 * from input text line
270 * char * ip position into the current
277 * ip decremented by 1 character position
287 /*)Function int getmap(d)
289 * int d value to compare with the
290 * input text line character
292 * The function getmap() converts the 'C' style characters \b, \f,
293 * \n, \r, and \t to their equivalent ascii values and also
294 * converts 'C' style octal constants '\123' to their equivalent
295 * numeric values. If the first character is equivalent to (d) then
296 * a (-1) is returned, if the end of the line is detected then
297 * a 'q' error terminates the parse for this line, or if the first
298 * character is not a \ then the character value is returned.
301 * int c value of character
302 * from input text line
303 * int n looping counter
304 * int v current value of numeric conversion
311 * VOID unget() lklex.c
314 * use of get() updates the global pointer ip the position
315 * in the current input text line
321 register int c, n, v;
323 if ((c = get()) == '\0')
361 while (++n<=3 && c>='0' && c<='7') {
362 v = (v<<3) + c - '0';
373 /*)Function int lk_getline()
375 * The function lk_getline() reads a line of input text from a
376 * .rel source text file, a .lnk command file or from stdin.
377 * Lines of text are processed from a single .lnk file or
378 * multiple .rel files until all files have been read.
379 * The input text line is copied into the global string ib[]
380 * and converted to a NULL terminated string. The function
381 * lk_getline() returns a (1) after succesfully reading a line
382 * or a (0) if all files have been read.
383 * This function also opens each input .lst file and output
384 * .rst file as each .rel file is processed.
387 * int i string length
388 * int ftype file type
389 * char * fid file name
392 * lfile *cfp The pointer *cfp points to the
393 * current lfile structure
394 * lfile *filep The pointer *filep points to the
395 * beginning of a linked list of
397 * int gline get a line from the LST file
398 * to translate for the RST file
399 * char ib[NINPUT] REL file text line
400 * int pass linker pass number
401 * int pflag print linker command file flag
402 * FILE *rfp The file handle to the current
404 * FILE *sfp The file handle sfp points to the
405 * currently open file
406 * FILE * stdin c_library
407 * FILE * stdout c_library
408 * FILE *tfp The file handle to the current
409 * LST file being scanned
410 * int uflag update listing flag
413 * FILE * afile() lkmain.c
414 * int fclose() c_library
415 * char * fgets() c_library
416 * int fprintf() c_library
417 * VOID lkulist() lklist.c
418 * VOID lkexit() lkmain.c
419 * int strlen() c_library
422 * The input stream is scanned. The .rel files will be
423 * opened and closed sequentially scanning each in turn.
429 register int i, ftype;
432 loop: if (pflag && cfp && cfp->f_type == F_STD)
433 fprintf(stdout, "ASlink >> ");
436 if(cfp == NULL && filep != NULL && filep->f_type == F_CMD) {
437 char **argv = (char **)filep->f_idp;
438 if(argv[0] != NULL && strlen(argv[0]) < sizeof ib) {
440 filep->f_idp = (char *)&argv[1];
447 if (sfp == NULL || fgets(ib, sizeof ib, sfp) == NULL) {
463 if (ftype == F_STD) {
466 if (ftype == F_LNK) {
468 sfp = afile(fid, "lnk", 0);
470 sfp = afile(fid, "LNK", 0);
473 if (ftype == F_REL) {
475 sfp = afile(fid, "", 0);
476 if (uflag && pass != 0) {
477 if ((tfp = afile(fid, "lst", 0)) != NULL) {
478 if ((rfp = afile(fid, "rst", 1)) == NULL) {
480 sfp = afile(fid, "REL", 0);
481 if (uflag && pass != 0) {
482 if ((tfp = afile(fid, "LST", 0)) != NULL) {
483 if ((rfp = afile(fid, "RST", 1)) == NULL) {
492 fprintf(stderr, "Invalid file type\n");
510 /*)Function int more()
512 * The function more() scans the input text line
513 * skipping white space (SPACES and TABS) and returns a (0)
514 * if the end of the line or a comment delimeter (;) is found,
515 * or a (1) if their are additional characters in the line.
518 * int c next character from
519 * the input text line
525 * char getnb() lklex.c
526 * VOID unget() lklex.c
529 * use of getnb() and unget() updates the global pointer ip
530 * the position in the current input text line
540 return( (c == '\0' || c == ';') ? 0 : 1 );
543 /*)Function char endline()
545 * The function endline() scans the input text line
546 * skipping white space (SPACES and TABS) and returns the next
547 * character or a (0) if the end of the line is found or a
548 * comment delimiter (;) is found.
551 * int c next character from
552 * the input text line
558 * char getnb() lklex.c
561 * Use of getnb() updates the global pointer ip the
562 * position in the current input text line.
571 return( (c == '\0' || c == ';') ? 0 : c );
574 /*)Function VOID chop_crlf(str)
576 * char *str string to chop
578 * The function chop_crlf() removes trailing LF or CR/LF from
582 * int i string length
601 if (i >= 1 && str[i-1] == '\n') str[i-1] = 0;
602 if (i >= 2 && str[i-2] == '\r') str[i-2] = 0;