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])
150 } while (c && (ctype[c] != SPACE));
152 while (p < &str[FILSPC])
156 /*)Function char getnb()
158 * The function getnb() scans the current input text
159 * line returning the first character not a SPACE or TAB.
162 * int c current character from input
171 * use of get() updates the global pointer ip, the position
172 * in the current input text line
180 while ((c=get())==' ' || c=='\t')
185 /*)Function VOID skip()
187 * The function skip() scans the input text skipping all
188 * letters and digits.
194 * char ctype[] array of character types, one per
199 * char getnb() lklex.c
200 * VOID unget() lklex.c
203 * Input letters and digits are skipped.
212 while (ctype[c=get()] & (LETTER|DIGIT)) { ; }
216 /*)Function char get()
218 * The function get() returns the next character in the
219 * input text line, at the end of the line a
220 * NULL character is returned.
223 * int c current character from
227 * char * ip pointer into the current
234 * updates ip to the next character position in the
235 * input text line. If ip is at the end of the
236 * line, ip is not updated.
249 /*)Function VOID unget(c)
251 * int c value of last character
252 * read from input text line
254 * If (c) is not a NULL character then the global pointer ip
255 * is updated to point to the preceeding character in the
258 * NOTE: This function does not push the character (c)
259 * back into the input text line, only
260 * the pointer ip is changed.
263 * int c last character read
264 * from input text line
267 * char * ip position into the current
274 * ip decremented by 1 character position
284 /*)Function int getmap(d)
286 * int d value to compare with the
287 * input text line character
289 * The function getmap() converts the 'C' style characters \b, \f,
290 * \n, \r, and \t to their equivalent ascii values and also
291 * converts 'C' style octal constants '\123' to their equivalent
292 * numeric values. If the first character is equivalent to (d) then
293 * a (-1) is returned, if the end of the line is detected then
294 * a 'q' error terminates the parse for this line, or if the first
295 * character is not a \ then the character value is returned.
298 * int c value of character
299 * from input text line
300 * int n looping counter
301 * int v current value of numeric conversion
308 * VOID unget() lklex.c
311 * use of get() updates the global pointer ip the position
312 * in the current input text line
318 register int c, n, v;
320 if ((c = get()) == '\0')
358 while (++n<=3 && c>='0' && c<='7') {
359 v = (v<<3) + c - '0';
370 /*)Function int getline()
372 * The function getline() reads a line of input text from a
373 * .rel source text file, a .lnk command file or from stdin.
374 * Lines of text are processed from a single .lnk file or
375 * multiple .rel files until all files have been read.
376 * The input text line is copied into the global string ib[]
377 * and converted to a NULL terminated string. The function
378 * getline() returns a (1) after succesfully reading a line
379 * or a (0) if all files have been read.
380 * This function also opens each input .lst file and output
381 * .rst file as each .rel file is processed.
384 * int i string length
385 * int ftype file type
386 * char * fid file name
389 * lfile *cfp The pointer *cfp points to the
390 * current lfile structure
391 * lfile *filep The pointer *filep points to the
392 * beginning of a linked list of
394 * int gline get a line from the LST file
395 * to translate for the RST file
396 * char ib[NINPUT] REL file text line
397 * int pass linker pass number
398 * int pflag print linker command file flag
399 * FILE *rfp The file handle to the current
401 * FILE *sfp The file handle sfp points to the
402 * currently open file
403 * FILE * stdin c_library
404 * FILE * stdout c_library
405 * FILE *tfp The file handle to the current
406 * LST file being scanned
407 * int uflag update listing flag
410 * FILE * afile() lkmain.c
411 * int fclose() c_library
412 * char * fgets() c_library
413 * int fprintf() c_library
414 * VOID lkulist() lklist.c
415 * VOID lkexit() lkmain.c
416 * int strlen() c_library
419 * The input stream is scanned. The .rel files will be
420 * opened and closed sequentially scanning each in turn.
426 register int i, ftype;
429 loop: if (pflag && cfp && cfp->f_type == F_STD)
430 fprintf(stdout, "ASlink >> ");
433 if(cfp == NULL && filep != NULL && filep->f_type == F_CMD) {
434 char **argv = (char **)filep->f_idp;
435 if(argv[0] != NULL && strlen(argv[0]) < sizeof ib) {
437 filep->f_idp = (char *)&argv[1];
444 if (sfp == NULL || fgets(ib, sizeof ib, sfp) == NULL) {
460 if (ftype == F_STD) {
463 if (ftype == F_LNK) {
465 sfp = afile(fid, "lnk", 0);
467 sfp = afile(fid, "LNK", 0);
470 if (ftype == F_REL) {
472 sfp = afile(fid, "", 0);
473 if (uflag && pass != 0) {
474 if ((tfp = afile(fid, "lst", 0)) != NULL) {
475 if ((rfp = afile(fid, "rst", 1)) == NULL) {
477 sfp = afile(fid, "REL", 0);
478 if (uflag && pass != 0) {
479 if ((tfp = afile(fid, "LST", 0)) != NULL) {
480 if ((rfp = afile(fid, "RST", 1)) == NULL) {
489 fprintf(stderr, "Invalid file type\n");
507 /*)Function int more()
509 * The function more() scans the input text line
510 * skipping white space (SPACES and TABS) and returns a (0)
511 * if the end of the line or a comment delimeter (;) is found,
512 * or a (1) if their are additional characters in the line.
515 * int c next character from
516 * the input text line
522 * char getnb() lklex.c
523 * VOID unget() lklex.c
526 * use of getnb() and unget() updates the global pointer ip
527 * the position in the current input text line
537 return( (c == '\0' || c == ';') ? 0 : 1 );
540 /*)Function char endline()
542 * The function endline() scans the input text line
543 * skipping white space (SPACES and TABS) and returns the next
544 * character or a (0) if the end of the line is found or a
545 * comment delimiter (;) is found.
548 * int c next character from
549 * the input text line
555 * char getnb() lklex.c
558 * Use of getnb() updates the global pointer ip the
559 * position in the current input text line.
568 return( (c == '\0' || c == ';') ? 0 : c );
571 /*)Function VOID chop_crlf(str)
573 * char *str string to chop
575 * The function chop_crlf() removes trailing LF or CR/LF from
579 * int i string length
598 if (i >= 1 && str[i-1] == '\n') str[i-1] = 0;
599 if (i >= 2 && str[i-2] == '\r') str[i-2] = 0;