4 * (C) Copyright 1989-1995
13 * Extensions: P. Felber, M. Hope
22 * The module lklex.c contains the general lexical analysis
23 * functions used to scan the text lines from the .rel files.
25 * 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 getSid (char *id)
104 * char * id a pointer to a string of
105 * maximum length NCPS
107 * getSid is derived from getid. It is called from newsym()
108 * in lksym.c, when an S-record has to be scanned. getSid accepts
109 * much more characters than getid, which is necessary for SDCC.
111 * The function getSid() scans the current input text line
112 * from the current position copying the next string
113 * into the external string buffer (id). The string ends when a space
114 * character (space, tab, \0) is found. The maximum number of
115 * characters copied is NCPS. If the input string is larger than
116 * NCPS characters then the string is truncated, if the input string
117 * is shorter than NCPS characters then the string is NULL filled.
118 * Intervening white space (SPACES and TABS) are skipped.
121 * char * p pointer to external string buffer
122 * int c current character value
125 * char ctype[] a character array which defines the
126 * type of character being processed.
127 * This index is the character
132 * char getnb() lklex.c
133 * VOID unget() lklex.c
136 * use of getnb(), get(), and unget() updates the
137 * global pointer ip the position in the current
153 } while (c != '\0' && c != ' ' && c != '\t');
155 while (p < &id[NCPS])
159 /*)Function VOID getfid(fid,c)
161 * char * str a pointer to a string of
162 * maximum length PATH_MAX
163 * int c this is first character to
164 * copy to the string buffer
166 * The function getfid() scans the current input text line
167 * from the current position copying the next string
168 * into the external string buffer (str). The string ends when a
169 * non SPACE type character is found. The maximum number of
170 * characters copied is FILSPC. If the input string is larger than
171 * PATH_MAX characters then the string is truncated, if the input string
172 * is shorter than FILSPC characters then the string is NULL filled.
175 * char * p pointer to external string buffer
176 * int c current character value
179 * char ctype[] a character array which defines the
180 * type of character being processed.
181 * This index is the character
188 * use of get() updates the global pointer ip
189 * the position in the current input text line.
202 if (p < &str[PATH_MAX-1])
211 } while (c && (ctype[c] != SPACE));
213 while (p < &str[PATH_MAX])
217 /*)Function char getnb()
219 * The function getnb() scans the current input text
220 * line returning the first character not a SPACE or TAB.
223 * int c current character from input
232 * use of get() updates the global pointer ip, the position
233 * in the current input text line
241 while ((c=get())==' ' || c=='\t')
246 /*)Function VOID skip()
248 * The function skip() scans the input text skipping all
249 * letters and digits.
255 * char ctype[] array of character types, one per
260 * char getnb() lklex.c
261 * VOID unget() lklex.c
264 * Input letters and digits are skipped.
273 while (ctype[c=get()] & (LETTER|DIGIT)) { ; }
277 /*)Function char get()
279 * The function get() returns the next character in the
280 * input text line, at the end of the line a
281 * NULL character is returned.
284 * int c current character from
288 * char * ip pointer into the current
295 * updates ip to the next character position in the
296 * input text line. If ip is at the end of the
297 * line, ip is not updated.
310 /*)Function VOID unget(c)
312 * int c value of last character
313 * read from input text line
315 * If (c) is not a NULL character then the global pointer ip
316 * is updated to point to the preceeding character in the
319 * NOTE: This function does not push the character (c)
320 * back into the input text line, only
321 * the pointer ip is changed.
324 * int c last character read
325 * from input text line
328 * char * ip position into the current
335 * ip decremented by 1 character position
345 /*)Function int getmap(d)
347 * int d value to compare with the
348 * input text line character
350 * The function getmap() converts the 'C' style characters \b, \f,
351 * \n, \r, and \t to their equivalent ascii values and also
352 * converts 'C' style octal constants '\123' to their equivalent
353 * numeric values. If the first character is equivalent to (d) then
354 * a (-1) is returned, if the end of the line is detected then
355 * a 'q' error terminates the parse for this line, or if the first
356 * character is not a \ then the character value is returned.
359 * int c value of character
360 * from input text line
361 * int n looping counter
362 * int v current value of numeric conversion
369 * VOID unget() lklex.c
372 * use of get() updates the global pointer ip the position
373 * in the current input text line
379 register int c, n, v;
381 if ((c = get()) == '\0')
419 while (++n<=3 && c>='0' && c<='7') {
420 v = (v<<3) + c - '0';
431 /*)Function int lk_getline()
433 * The function lk_getline() reads a line of input text from a
434 * .rel source text file, a .lnk command file or from stdin.
435 * Lines of text are processed from a single .lnk file or
436 * multiple .rel files until all files have been read.
437 * The input text line is copied into the global string ib[]
438 * and converted to a NULL terminated string. The function
439 * lk_getline() returns a (1) after succesfully reading a line
440 * or a (0) if all files have been read.
441 * This function also opens each input .lst file and output
442 * .rst file as each .rel file is processed.
445 * int i string length
446 * int ftype file type
447 * char * fid file name
450 * lfile *cfp The pointer *cfp points to the
451 * current lfile structure
452 * lfile *filep The pointer *filep points to the
453 * beginning of a linked list of
455 * int gline get a line from the LST file
456 * to translate for the RST file
457 * char ib[NINPUT] REL file text line
458 * int pass linker pass number
459 * int pflag print linker command file flag
460 * FILE *rfp The file handle to the current
462 * FILE *sfp The file handle sfp points to the
463 * currently open file
464 * FILE * stdin c_library
465 * FILE * stdout c_library
466 * FILE *tfp The file handle to the current
467 * LST file being scanned
468 * int uflag update listing flag
471 * FILE * afile() lkmain.c
472 * int fclose() c_library
473 * char * fgets() c_library
474 * int fprintf() c_library
475 * VOID lkulist() lklist.c
476 * VOID lkexit() lkmain.c
477 * int strlen() c_library
480 * The input stream is scanned. The .rel files will be
481 * opened and closed sequentially scanning each in turn.
490 loop: if (pflag && cfp && cfp->f_type == F_STD)
491 fprintf(stdout, "ASlink >> ");
494 if(cfp == NULL && filep != NULL && filep->f_type == F_CMD) {
495 char **argv = (char **)filep->f_idp;
496 if(argv[0] != NULL && strlen(argv[0]) < sizeof ib) {
498 filep->f_idp = (char *)&argv[1];
505 if (sfp == NULL || fgets(ib, sizeof ib, sfp) == NULL) {
521 if (ftype == F_STD) {
524 if (ftype == F_LNK) {
526 sfp = afile(fid, "lnk", 0);
528 sfp = afile(fid, "LNK", 0);
531 if (ftype == F_REL) {
533 sfp = afile(fid, "", 0);
534 if (uflag && pass != 0) {
535 if ((tfp = afile(fid, "lst", 0)) != NULL) {
536 if ((rfp = afile(fid, "rst", 1)) == NULL) {
538 sfp = afile(fid, "REL", 0);
539 if (uflag && pass != 0) {
540 if ((tfp = afile(fid, "LST", 0)) != NULL) {
541 if ((rfp = afile(fid, "RST", 1)) == NULL) {
550 fprintf(stderr, "Invalid file type\n");
566 /*)Function int more()
568 * The function more() scans the input text line
569 * skipping white space (SPACES and TABS) and returns a (0)
570 * if the end of the line or a comment delimeter (;) is found,
571 * or a (1) if their are additional characters in the line.
574 * int c next character from
575 * the input text line
581 * char getnb() lklex.c
582 * VOID unget() lklex.c
585 * use of getnb() and unget() updates the global pointer ip
586 * the position in the current input text line
596 return( (c == '\0' || c == ';') ? 0 : 1 );
599 /*)Function char endline()
601 * The function endline() scans the input text line
602 * skipping white space (SPACES and TABS) and returns the next
603 * character or a (0) if the end of the line is found or a
604 * comment delimiter (;) is found.
607 * int c next character from
608 * the input text line
614 * char getnb() lklex.c
617 * Use of getnb() updates the global pointer ip the
618 * position in the current input text line.
627 return( (c == '\0' || c == ';') ? 0 : c );
630 /*)Function VOID chop_crlf(str)
632 * char *str string to chop
634 * The function chop_crlf() removes trailing LF or CR/LF from
638 * int i string length
657 if (i >= 1 && str[i-1] == '\n') str[i-1] = 0;
658 if (i >= 2 && str[i-2] == '\r') str[i-2] = 0;