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:
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 getSid (char *id)
100 * char * id a pointer to a string of
101 * maximum length NCPS
103 * getSid is derived from getid. It is called from newsym()
104 * in lksym.c, when an S-record has to be scanned. getSid accepts
105 * much more characters than getid, which is necessary for SDCC.
107 * The function getSid() scans the current input text line
108 * from the current position copying the next string
109 * into the external string buffer (id). The string ends when a space
110 * character (space, tab, \0) is found. The maximum number of
111 * characters copied is NCPS. If the input string is larger than
112 * NCPS characters then the string is truncated, if the input string
113 * is shorter than NCPS characters then the string is NULL filled.
114 * Intervening white space (SPACES and TABS) are skipped.
117 * char * p pointer to external string buffer
118 * int c current character value
121 * char ctype[] a character array which defines the
122 * type of character being processed.
123 * This index is the character
128 * char getnb() lklex.c
129 * VOID unget() lklex.c
132 * use of getnb(), get(), and unget() updates the
133 * global pointer ip the position in the current
150 } while (c != '\0' && c != ' ' && c != '\t');
152 while (p < &id[NCPS])
156 /*)Function VOID getfid(fid,c)
158 * char * str a pointer to a string of
159 * maximum length PATH_MAX
160 * int c this is first character to
161 * copy to the string buffer
163 * The function getfid() scans the current input text line
164 * from the current position copying the next string
165 * into the external string buffer (str). The string ends when a
166 * non SPACE type character is found. The maximum number of
167 * characters copied is PATH_MAX. If the input string is larger than
168 * PATH_MAX characters then the string is truncated, if the input string
169 * is shorter than PATH_MAX characters then the string is NULL filled.
172 * char * p pointer to external string buffer
173 * int c current character value
176 * char ctype[] a character array which defines the
177 * type of character being processed.
178 * This index is the character
185 * use of get() updates the global pointer ip
186 * the position in the current input text line.
198 if (p < &str[PATH_MAX-1])
201 } while (c && ((ctype[c] != SPACE)||(c == ':')||(c == '\\')));
202 while (p < &str[PATH_MAX])
206 /*)Function char getnb()
208 * The function getnb() scans the current input text
209 * line returning the first character not a SPACE or TAB.
212 * int c current character from input
221 * use of get() updates the global pointer ip, the position
222 * in the current input text line
230 while ((c=get())==' ' || c=='\t')
235 /*)Function VOID skip()
237 * The function skip() scans the input text skipping all
238 * letters and digits.
244 * char ctype[] array of character types, one per
249 * char getnb() lklex.c
250 * VOID unget() lklex.c
253 * Input letters and digits are skipped.
262 while (ctype[c=get()] & (LETTER|DIGIT)) { ; }
266 /*)Function char get()
268 * The function get() returns the next character in the
269 * input text line, at the end of the line a
270 * NULL character is returned.
273 * int c current character from
277 * char * ip pointer into the current
284 * updates ip to the next character position in the
285 * input text line. If ip is at the end of the
286 * line, ip is not updated.
299 /*)Function VOID unget(c)
301 * int c value of last character
302 * read from input text line
304 * If (c) is not a NULL character then the global pointer ip
305 * is updated to point to the preceeding character in the
308 * NOTE: This function does not push the character (c)
309 * back into the input text line, only
310 * the pointer ip is changed.
313 * int c last character read
314 * from input text line
317 * char * ip position into the current
324 * ip decremented by 1 character position
334 /*)Function int getmap(d)
336 * int d value to compare with the
337 * input text line character
339 * The function getmap() converts the 'C' style characters \b, \f,
340 * \n, \r, and \t to their equivalent ascii values and also
341 * converts 'C' style octal constants '\123' to their equivalent
342 * numeric values. If the first character is equivalent to (d) then
343 * a (-1) is returned, if the end of the line is detected then
344 * a 'q' error terminates the parse for this line, or if the first
345 * character is not a \ then the character value is returned.
348 * int c value of character
349 * from input text line
350 * int n looping counter
351 * int v current value of numeric conversion
358 * VOID unget() lklex.c
361 * use of get() updates the global pointer ip the position
362 * in the current input text line
368 register int c, n, v;
370 if ((c = get()) == '\0')
408 while (++n<=3 && c>='0' && c<='7') {
409 v = (v<<3) + c - '0';
420 /*)Function int getline()
422 * The function getline() reads a line of input text from a
423 * .rel source text file, a .lnk command file or from stdin.
424 * Lines of text are processed from a single .lnk file or
425 * multiple .rel files until all files have been read.
426 * The input text line is copied into the global string ib[]
427 * and converted to a NULL terminated string. The function
428 * getline() returns a (1) after succesfully reading a line
429 * or a (0) if all files have been read.
430 * This function also opens each input .lst file and output
431 * .rst file as each .rel file is processed.
434 * int i string length
435 * int ftype file type
436 * char * fid file name
439 * lfile *cfp The pointer *cfp points to the
440 * current lfile structure
441 * lfile *filep The pointer *filep points to the
442 * beginning of a linked list of
444 * int gline get a line from the LST file
445 * to translate for the RST file
446 * char ib[NINPUT] REL file text line
447 * int pass linker pass number
448 * int pflag print linker command file flag
449 * FILE *rfp The file handle to the current
451 * FILE *sfp The file handle sfp points to the
452 * currently open file
453 * FILE * stdin c_library
454 * FILE * stdout c_library
455 * FILE *tfp The file handle to the current
456 * LST file being scanned
457 * int uflag update listing flag
460 * FILE * afile() lkmain.c
461 * int fclose() c_library
462 * char * fgets() c_library
463 * int fprintf() c_library
464 * VOID lkulist() lklist.c
465 * VOID lkexit() lkmain.c
466 * int strlen() c_library
469 * The input stream is scanned. The .rel files will be
470 * opened and closed sequentially scanning each in turn.
479 loop: if (pflag && cfp && cfp->f_type == F_STD)
480 fprintf(stdout, "ASlink >> ");
482 if (sfp == NULL || fgets(ib, sizeof ib, sfp) == NULL) {
496 if (ftype == F_STD) {
499 if (ftype == F_LNK) {
500 sfp = afile(fid, "lnk", 0);
502 if (ftype == F_REL) {
503 sfp = afile(fid, "rel", 0);
504 /* if a .cdb file exists then copy it over */
505 if (dflag && sfp && dfp && pass == 0) {
506 FILE *xfp = afile(fid,"adb",0); //JCF: Nov 30, 2002
512 if (uflag && pass != 0) {
513 SaveLinkedFilePath(fid); //Save the linked path for aomf51
514 if ((tfp = afile(fid, "lst", 0)) != NULL) {
515 if ((rfp = afile(fid, "rst", 1)) == NULL) {
523 fprintf(stderr, "Invalid file type\n");
539 /*)Function int more()
541 * The function more() scans the input text line
542 * skipping white space (SPACES and TABS) and returns a (0)
543 * if the end of the line or a comment delimeter (;) is found,
544 * or a (1) if their are additional characters in the line.
547 * int c next character from
548 * the input text line
554 * char getnb() lklex.c
555 * VOID unget() lklex.c
558 * use of getnb() and unget() updates the global pointer ip
559 * the position in the current input text line
569 return( (c == '\0' || c == ';') ? 0 : 1 );
572 /*)Function char endline()
574 * The function endline() scans the input text line
575 * skipping white space (SPACES and TABS) and returns the next
576 * character or a (0) if the end of the line is found or a
577 * comment delimiter (;) is found.
580 * int c next character from
581 * the input text line
587 * char getnb() lklex.c
590 * Use of getnb() updates the global pointer ip the
591 * position in the current input text line.
600 return( (c == '\0' || c == ';') ? 0 : c );
603 /*)Function VOID chop_crlf(str)
605 * char *str string to chop
607 * The function chop_crlf() removes trailing LF or CR/LF from
611 * int i string length
630 if (i >= 1 && str[i-1] == '\n') str[i-1] = 0;
631 if (i >= 2 && str[i-2] == '\r') str[i-2] = 0;