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
149 } while (c != '\0' && c != ' ' && c != '\t');
151 while (p < &id[NCPS])
155 /*)Function VOID getfid(fid,c)
157 * char * str a pointer to a string of
158 * maximum length PATH_MAX
159 * int c this is first character to
160 * copy to the string buffer
162 * The function getfid() scans the current input text line from
163 * the current position copying the next string into the external
164 * string buffer (str). The string ends when end of line is found.
165 * Trailing spaces are removed. The maximum number of characters
166 * copied is PATH_MAX. If the input string is larger than PATH_MAX
167 * characters then the string is truncated. The string is NULL
171 * char * p pointer to external string buffer
172 * int c current character value
175 * char ctype[] a character array which defines the
176 * type of character being processed.
177 * This index is the character
184 * use of get() updates the global pointer ip
185 * the position in the current input text line.
189 getfid(char *str, register int c)
196 if (p < &str[PATH_MAX-1])
203 /* trim trailing spaces */
205 while (p >= str && ctype[(int)*p] == SPACE)
207 /* terminate the string */
211 /*)Function char getnb()
213 * The function getnb() scans the current input text
214 * line returning the first character not a SPACE or TAB.
217 * int c current character from input
226 * use of get() updates the global pointer ip, the position
227 * in the current input text line
235 while ((c=get())==' ' || c=='\t')
240 /*)Function VOID skip()
242 * The function skip() scans the input text skipping all
243 * letters and digits.
249 * char ctype[] array of character types, one per
254 * char getnb() lklex.c
255 * VOID unget() lklex.c
258 * Input letters and digits are skipped.
266 while (ctype[c=get()] & (LETTER|DIGIT)) { ; }
270 /*)Function char get()
272 * The function get() returns the next character in the
273 * input text line, at the end of the line a
274 * NULL character is returned.
277 * int c current character from
281 * char * ip pointer into the current
288 * updates ip to the next character position in the
289 * input text line. If ip is at the end of the
290 * line, ip is not updated.
303 /*)Function VOID unget(c)
305 * int c value of last character
306 * read from input text line
308 * If (c) is not a NULL character then the global pointer ip
309 * is updated to point to the preceeding character in the
312 * NOTE: This function does not push the character (c)
313 * back into the input text line, only
314 * the pointer ip is changed.
317 * int c last character read
318 * from input text line
321 * char * ip position into the current
328 * ip decremented by 1 character position
338 /*)Function int getmap(d)
340 * int d value to compare with the
341 * input text line character
343 * The function getmap() converts the 'C' style characters \b, \f,
344 * \n, \r, and \t to their equivalent ascii values and also
345 * converts 'C' style octal constants '\123' to their equivalent
346 * numeric values. If the first character is equivalent to (d) then
347 * a (-1) is returned, if the end of the line is detected then
348 * a 'q' error terminates the parse for this line, or if the first
349 * character is not a \ then the character value is returned.
352 * int c value of character
353 * from input text line
354 * int n looping counter
355 * int v current value of numeric conversion
362 * VOID unget() lklex.c
365 * use of get() updates the global pointer ip the position
366 * in the current input text line
372 register int c, n, v;
374 if ((c = get()) == '\0')
412 while (++n<=3 && c>='0' && c<='7') {
413 v = (v<<3) + c - '0';
424 /*)Function int lk_getline()
426 * The function lk_getline() reads a line of input text from a
427 * .rel source text file, a .lnk command file or from stdin.
428 * Lines of text are processed from a single .lnk file or
429 * multiple .rel files until all files have been read.
430 * The input text line is copied into the global string ib[]
431 * and converted to a NULL terminated string. The function
432 * lk_getline() returns a (1) after succesfully reading a line
433 * or a (0) if all files have been read.
434 * This function also opens each input .lst file and output
435 * .rst file as each .rel file is processed.
438 * int i string length
439 * int ftype file type
440 * char * fid file name
443 * lfile *cfp The pointer *cfp points to the
444 * current lfile structure
445 * lfile *filep The pointer *filep points to the
446 * beginning of a linked list of
448 * int gline get a line from the LST file
449 * to translate for the RST file
450 * char ib[NINPUT] REL file text line
451 * int pass linker pass number
452 * int pflag print linker command file flag
453 * FILE *rfp The file handle to the current
455 * FILE *sfp The file handle sfp points to the
456 * currently open file
457 * FILE * stdin c_library
458 * FILE * stdout c_library
459 * FILE *tfp The file handle to the current
460 * LST file being scanned
461 * int uflag update listing flag
464 * FILE * afile() lkmain.c
465 * int fclose() c_library
466 * char * fgets() c_library
467 * int fprintf() c_library
468 * VOID lkulist() lklist.c
469 * VOID lkexit() lkmain.c
470 * int strlen() c_library
473 * The input stream is scanned. The .rel files will be
474 * opened and closed sequentially scanning each in turn.
483 loop: if (pflag && cfp && cfp->f_type == F_STD)
484 fprintf(stdout, "ASlink >> ");
486 if (sfp == NULL || fgets(ib, sizeof ib, sfp) == NULL) {
500 if (ftype == F_STD) {
503 if (ftype == F_LNK) {
504 sfp = afile(fid, "lnk", 0);
506 if (ftype == F_REL) {
507 sfp = afile(fid, LKOBJEXT, 0);
508 /* if a .adb file exists then copy it over */
509 if (dflag && sfp && dfp && pass == 0) {
510 FILE *xfp = afile(fid,"adb",0); //JCF: Nov 30, 2002
516 if (uflag && pass != 0) {
517 SaveLinkedFilePath(fid); //Save the linked path for aomf51
518 if ((tfp = afile(fid, "lst", 0)) != NULL) {
519 if ((rfp = afile(fid, "rst", 1)) == NULL) {
527 fprintf(stderr, "Invalid file type\n");
543 /*)Function int more()
545 * The function more() scans the input text line
546 * skipping white space (SPACES and TABS) and returns a (0)
547 * if the end of the line or a comment delimeter (;) is found,
548 * or a (1) if their are additional characters in the line.
551 * int c next character from
552 * the input text line
558 * char getnb() lklex.c
559 * VOID unget() lklex.c
562 * use of getnb() and unget() updates the global pointer ip
563 * the position in the current input text line
573 return( (c == '\0' || c == ';') ? 0 : 1 );
576 /*)Function char endline()
578 * The function endline() scans the input text line
579 * skipping white space (SPACES and TABS) and returns the next
580 * character or a (0) if the end of the line is found or a
581 * comment delimiter (;) is found.
584 * int c next character from
585 * the input text line
591 * char getnb() lklex.c
594 * Use of getnb() updates the global pointer ip the
595 * position in the current input text line.
604 return( (c == '\0' || c == ';') ? 0 : c );
607 /*)Function VOID chop_crlf(str)
609 * char *str string to chop
611 * The function chop_crlf() removes trailing LF or CR/LF from
615 * int i string length
633 if (i >= 1 && str[i-1] == '\n') str[i-1] = 0;
634 if (i >= 2 && str[i-2] == '\r') str[i-2] = 0;