4 * (C) Copyright 1989-1995
14 //#if !defined(_MSC_VER)
21 * The module lklex.c contains the general lexical analysis
22 * functions used to scan the text lines from the .rel files.
24 * lklex.c contains the fllowing functions:
36 * lklex.c contains no local variables.
39 /*)Function VOID getid(id,c)
41 * char * id a pointer to a string of
44 * >=0 this is first character to
45 * copy to the string buffer
48 * The function getid() scans the current input text line
49 * from the current position copying the next LETTER | DIGIT string
50 * into the external string buffer (id). The string ends when a non
51 * LETTER or DIGIT character is found. The maximum number of
52 * characters copied is NCPS. If the input string is larger than
53 * NCPS characters then the string is truncated, if the input string
54 * is shorter than NCPS characters then the string is NULL filled.
55 * If the mode argument (c) is >=0 then (c) is the first character
56 * copied to the string buffer, if (c) is <0 then intervening white
57 * space (SPACES and TABS) are skipped.
60 * char * p pointer to external string buffer
61 * int c current character value
64 * char ctype[] a character array which defines the
65 * type of character being processed.
66 * This index is the character
71 * char getnb() lklex.c
72 * VOID unget() lklex.c
75 * use of getnb(), get(), and unget() updates the
76 * global pointer ip the position in the current
94 } while (ctype[c=get()] & (LETTER|DIGIT));
100 /*)Function VOID getfid(fid,c)
102 * char * str a pointer to a string of
103 * maximum length FILSPC
104 * int c this is first character to
105 * copy to the string buffer
107 * The function getfid() scans the current input text line
108 * from the current position copying the next string
109 * into the external string buffer (str). The string ends when a
110 * non SPACE type character is found. The maximum number of
111 * characters copied is FILSPC. If the input string is larger than
112 * FILSPC characters then the string is truncated, if the input string
113 * is shorter than FILSPC characters then the string is NULL filled.
116 * char * p pointer to external string buffer
117 * int c current character value
120 * char ctype[] a character array which defines the
121 * type of character being processed.
122 * This index is the character
129 * use of get() updates the global pointer ip
130 * the position in the current input text line.
142 if (p < &str[FILSPC-1])
145 } while (c && ((ctype[c] != SPACE)||(c == ':')||(c == '\\')));
146 while (p < &str[FILSPC])
150 /*)Function char getnb()
152 * The function getnb() scans the current input text
153 * line returning the first character not a SPACE or TAB.
156 * int c current character from input
165 * use of get() updates the global pointer ip, the position
166 * in the current input text line
174 while ((c=get())==' ' || c=='\t')
179 /*)Function VOID skip()
181 * The function skip() scans the input text skipping all
182 * letters and digits.
188 * char ctype[] array of character types, one per
193 * char getnb() lklex.c
194 * VOID unget() lklex.c
197 * Input letters and digits are skipped.
206 while (ctype[c=get()] & (LETTER|DIGIT)) { ; }
210 /*)Function char get()
212 * The function get() returns the next character in the
213 * input text line, at the end of the line a
214 * NULL character is returned.
217 * int c current character from
221 * char * ip pointer into the current
228 * updates ip to the next character position in the
229 * input text line. If ip is at the end of the
230 * line, ip is not updated.
243 /*)Function VOID unget(c)
245 * int c value of last character
246 * read from input text line
248 * If (c) is not a NULL character then the global pointer ip
249 * is updated to point to the preceeding character in the
252 * NOTE: This function does not push the character (c)
253 * back into the input text line, only
254 * the pointer ip is changed.
257 * int c last character read
258 * from input text line
261 * char * ip position into the current
268 * ip decremented by 1 character position
278 /*)Function int getmap(d)
280 * int d value to compare with the
281 * input text line character
283 * The function getmap() converts the 'C' style characters \b, \f,
284 * \n, \r, and \t to their equivalent ascii values and also
285 * converts 'C' style octal constants '\123' to their equivalent
286 * numeric values. If the first character is equivalent to (d) then
287 * a (-1) is returned, if the end of the line is detected then
288 * a 'q' error terminates the parse for this line, or if the first
289 * character is not a \ then the character value is returned.
292 * int c value of character
293 * from input text line
294 * int n looping counter
295 * int v current value of numeric conversion
302 * VOID unget() lklex.c
305 * use of get() updates the global pointer ip the position
306 * in the current input text line
312 register int c, n, v;
314 if ((c = get()) == '\0')
352 while (++n<=3 && c>='0' && c<='7') {
353 v = (v<<3) + c - '0';
364 /*)Function int getline()
366 * The function getline() reads a line of input text from a
367 * .rel source text file, a .lnk command file or from stdin.
368 * Lines of text are processed from a single .lnk file or
369 * multiple .rel files until all files have been read.
370 * The input text line is copied into the global string ib[]
371 * and converted to a NULL terminated string. The function
372 * getline() returns a (1) after succesfully reading a line
373 * or a (0) if all files have been read.
374 * This function also opens each input .lst file and output
375 * .rst file as each .rel file is processed.
378 * int i string length
379 * int ftype file type
380 * char * fid file name
383 * lfile *cfp The pointer *cfp points to the
384 * current lfile structure
385 * lfile *filep The pointer *filep points to the
386 * beginning of a linked list of
388 * int gline get a line from the LST file
389 * to translate for the RST file
390 * char ib[NINPUT] REL file text line
391 * int pass linker pass number
392 * int pflag print linker command file flag
393 * FILE *rfp The file handle to the current
395 * FILE *sfp The file handle sfp points to the
396 * currently open file
397 * FILE * stdin c_library
398 * FILE * stdout c_library
399 * FILE *tfp The file handle to the current
400 * LST file being scanned
401 * int uflag update listing flag
404 * FILE * afile() lkmain.c
405 * int fclose() c_library
406 * char * fgets() c_library
407 * int fprintf() c_library
408 * VOID lkulist() lklist.c
409 * VOID lkexit() lkmain.c
410 * int strlen() c_library
413 * The input stream is scanned. The .rel files will be
414 * opened and closed sequentially scanning each in turn.
423 loop: if (pflag && cfp && cfp->f_type == F_STD)
424 fprintf(stdout, "ASlink >> ");
426 if (sfp == NULL || fgets(ib, sizeof ib, sfp) == NULL) {
440 if (ftype == F_STD) {
443 if (ftype == F_LNK) {
444 sfp = afile(fid, "lnk", 0);
446 if (ftype == F_REL) {
447 sfp = afile(fid, "rel", 0);
448 /* if a .cdb file exists then copy it over */
449 if (dflag && sfp && dfp && pass == 0) {
450 FILE *xfp = afile(fid,"cdb",0);
456 if (uflag && pass != 0) {
457 if ((tfp = afile(fid, "lst", 0)) != NULL) {
458 if ((rfp = afile(fid, "rst", 1)) == NULL) {
466 fprintf(stderr, "Invalid file type\n");
482 /*)Function int more()
484 * The function more() scans the input text line
485 * skipping white space (SPACES and TABS) and returns a (0)
486 * if the end of the line or a comment delimeter (;) is found,
487 * or a (1) if their are additional characters in the line.
490 * int c next character from
491 * the input text line
497 * char getnb() lklex.c
498 * VOID unget() lklex.c
501 * use of getnb() and unget() updates the global pointer ip
502 * the position in the current input text line
512 return( (c == '\0' || c == ';') ? 0 : 1 );
515 /*)Function char endline()
517 * The function endline() scans the input text line
518 * skipping white space (SPACES and TABS) and returns the next
519 * character or a (0) if the end of the line is found or a
520 * comment delimiter (;) is found.
523 * int c next character from
524 * the input text line
530 * char getnb() lklex.c
533 * Use of getnb() updates the global pointer ip the
534 * position in the current input text line.
543 return( (c == '\0' || c == ';') ? 0 : c );
546 /*)Function VOID chop_crlf(str)
548 * char *str string to chop
550 * The function chop_crlf() removes trailing LF or CR/LF from
554 * int i string length
573 if (i >= 1 && str[i-1] == '\n') str[i-1] = 0;
574 if (i >= 2 && str[i-2] == '\r') str[i-2] = 0;