4 * (C) Copyright 1989-1995
11 * With contributions for the
12 * object libraries from
14 * kenh@cmf.nrl.navy.mil
19 * Extensions: P. Felber
22 #define EQ(A,B) !strcmp((A),(B))
23 #define MAXLINE 254 /*when using fgets*/
34 #define LKDIRSEPSTR "/"
37 #define LKDIRSEPSTR "\\"
41 #define LKDIRSEPSTR "\\"
47 * The module lklibr.c contains the functions which
48 * (1) specify the path(s) to library files [.LIB]
49 * (2) specify the library file(s) [.LIB] to search
50 * (3) search the library files for specific symbols
51 * and link the module containing this symbol
53 * lklibr.c contains the following functions:
65 typedef struct slibrarysymbol mlibrarysymbol;
66 typedef struct slibrarysymbol *pmlibrarysymbol;
68 struct slibrarysymbol {
69 char * name; /*Warning: allocate memory before using*/
73 typedef struct slibraryfile mlibraryfile;
74 typedef struct slibraryfile *pmlibraryfile;
79 char * relfil; /*Warning: allocate memory before using*/
80 char * filename; /*Warning: allocate memory before using*/
81 long offset; //if > 0, the embedded file offset in the library file libspc
82 pmlibrarysymbol symbols;
86 /* First entry in the library object symbol cache */
87 pmlibraryfile libr=NULL;
89 int buildlibraryindex();
90 void freelibraryindex (void);
93 /*)Function VOID addpath()
95 * The function addpath() creates a linked structure containing
96 * the paths to various object module library files.
99 * lbpath *lbph pointer to new path structure
100 * lbpath *lbp temporary pointer
103 * lbpath *lbphead The pointer to the first
107 * char getnb() lklex.c
108 * VOID * new() lksym.c
109 * int strlen() c_library
110 * char * strcpy() c_library
111 * VOID unget() lklex.c
114 * An lbpath structure may be created.
120 struct lbpath *lbph, *lbp;
122 lbph = (struct lbpath *) new (sizeof(struct lbpath));
123 if (lbphead == NULL) {
132 lbph->path = (char *) new (strlen(ip)+1);
133 strcpy(lbph->path, ip);
136 /*)Function VOID addlib()
138 * The function addlib() tests for the existance of a
139 * library path structure to determine the method of
140 * adding this library file to the library search structure.
142 * This function calls the function addfile() to actually
143 * add the library file to the search list.
146 * lbpath *lbph pointer to path structure
149 * lbpath *lbphead The pointer to the first
151 * ip a pointer to the library name
154 * VOID addfile() lklibr.c
155 * char getnb() lklex.c
156 * VOID unget() lklex.c
159 * The function addfile() may add the file to
160 * the library search list.
173 foundcount=addfile(NULL, ip);
177 for (lbph=lbphead; lbph; lbph=lbph->next)
179 foundcount+=addfile(lbph->path, ip);
184 fprintf(stderr, "?ASlink-Warning-Couldn't find library '%s'\n", ip);
188 /*)Function int addfile(path,libfil)
190 * char *path library path specification
191 * char *libfil library file specification
193 * The function addfile() searches for the library file
194 * by concatenating the path and libfil specifications.
195 * if the library is found, an lbname structure is created
196 * and linked to any previously defined structures. This
197 * linked list is used by the function fndsym() to attempt
198 * to find any undefined symbols.
200 * The function does not give report an error on invalid
201 * path / file specifications or if the file is not found.
204 * lbname *lbnh pointer to new name structure
205 * lbname *lbn temporary pointer
208 * lbname *lbnhead The pointer to the first
212 * char getnb() lklex.c
213 * VOID * new() lksym.c
214 * int strlen() c_library
215 * char * strcpy() c_library
216 * VOID unget() lklex.c
219 * An lbname structure may be created.
222 * 1: the library was found
223 * 0: the library was not found
226 int addfile(char * path, char * libfil)
230 struct lbname *lbnh, *lbn;
235 str = (char *) new (strlen(path) + strlen(libfil) + 6);
237 if (strlen(str) && (str[strlen(str)-1] != '/') && (str[strlen(str)-1] != '\\'))
239 strcat(str, LKDIRSEPSTR);
244 str = (char *) new (strlen(libfil) + 5);
247 if ((libfil[0] == '/') || (libfil[0] == '\\'))
255 if(strchr(libfil, FSEPX) == NULL)
257 sprintf(&str[strlen(str)], "%clib", FSEPX);
263 /*Ok, that didn't work. Try with the 'libfil' name only*/
264 if(libfilinc) libfil--;
265 fp=fopen(libfil, "r");
268 /*Bingo! 'libfil' is the absolute path of the library*/
270 path=NULL;/*This way 'libfil' and 'path' will be rebuilt from 'str'*/
276 /*'path' can not be null since it is needed to find the .rel/.o files associated with
277 the library. So, get 'path' from 'str' and then chop it off and recreate 'libfil'.
278 That way putting 'path' and 'libfil' together will result into the original filepath
279 as contained in 'str'.*/
281 path = (char *) new (strlen(str) + 1);
283 for(j=strlen(path)-1; j>=0; j--)
285 if((path[j] == '/') || (path[j] == '\\'))
287 strcpy(libfil, &path[j+1]);
298 lbnh = (struct lbname *) new (sizeof(struct lbname));
312 lbnh->libfil = (char *) new (strlen(libfil) + 1);
313 strcpy(lbnh->libfil, libfil);
324 /*)Function VOID search()
326 * The function search() looks through all the symbol tables
327 * at the end of pass 1. If any undefined symbols are found
328 * then the function fndsym() is called. Function fndsym()
329 * searches any specified library files to automagically
330 * import the object modules containing the needed symbol.
332 * After a symbol is found and imported by the function
333 * fndsym() the symbol tables are again searched. The
334 * symbol tables are search until no more symbols can be
335 * resolved within the library files. This ensures that
336 * back references from one library module to another are
340 * int i temporary counter
341 * sym *sp pointer to a symbol structure
342 * int symfnd found a symbol flag
345 * sym *symhash[] array of pointers to symbol tables
348 * int fndsym() lklibr.c
351 * If a symbol is found then the library object module
352 * containing the symbol will be imported and linked.
358 register struct sym *sp;
359 register int i, symfnd;
362 * Look for undefined symbols. Keep
363 * searching until no more symbols are resolved.
369 * Look through all the symbols
371 for (i=0; i<NHASH; ++i) {
374 /* If we find an undefined symbol
375 * (one where S_DEF is not set), then
376 * try looking for it. If we find it
377 * in any of the libraries then
378 * increment symfnd. This will force
379 * another pass of symbol searching and
380 * make sure that back references work.
382 if ((sp->s_type & S_DEF) == 0) {
383 if (fndsym(sp->s_id)) {
393 /*Load a .rel file embedded in a sdcclib file*/
394 void LoadRel(char * libfname, FILE * libfp, char * ModName)
399 while (fgets(str, NINPUT, libfp) != NULL)
401 str[NINPUT+1] = '\0';
406 if(EQ(str, "<FILE>"))
408 fgets(str, NINPUT, libfp);
409 str[NINPUT+1] = '\0';
411 if(EQ(str, ModName)) state=1;
414 fprintf(stderr, "?ASlink-Error-Bad offset in library file %s(%s)\n",
421 if(EQ(str, "<REL>")) state=2;
424 if(EQ(str, "</REL>")) return;
432 /*)Function VOID fndsym(name)
434 * char *name symbol name to find
436 * The function fndsym() searches through all combinations of the
437 * library path specifications (input by the -k option) and the
438 * library file specifications (input by the -l option) that
439 * lead to an existing file.
441 * The file specicifation may be formed in one of two ways:
443 * (1) If the library file contained an absolute
444 * path/file specification then this becomes filspc.
447 * (2) If the library file contains a relative path/file
448 * specification then the concatenation of the path
449 * and this file specification becomes filspc.
452 * The structure lbfile is created for the first library
453 * object file which contains the definition for the
454 * specified undefined symbol.
456 * If the library file [.LIB] contains file specifications for
457 * non existant files, no errors are returned.
460 * char buf[] [.REL] file input line
461 * char c [.REL] file input character
462 * FILE *fp file handle for object file
463 * lbfile *lbf temporary pointer
464 * lbfile *lbfh pointer to lbfile structure
465 * FILE *libfp file handle for library file
466 * lbname *lbnh pointer to lbname structure
467 * char *path file specification path
468 * char relfil[] [.REL] file specification
469 * char *str combined path and file specification
470 * char symname[] [.REL] file symbol string
473 * lbname *lbnhead The pointer to the first
475 * lbfile *lbfhead The pointer to the first
479 * int fclose() c_library
480 * int fgets() c_library
481 * FILE *fopen() c_library
482 * VOID free() c_library
483 * char getnb() lklex.c
484 * VOID lkexit() lkmain.c
485 * VOID loadfile() lklibr.c
486 * VOID * new() lksym.c
487 * char * sprintf() c_library
488 * int sscanf() c_library
489 * char * strcat() c_library
490 * char * strchr() c_library
491 * char * strcpy() c_library
492 * int strlen() c_library
493 * int strncmp() c_library
494 * VOID unget() lklex.c
497 * If the symbol is found then a new lbfile structure
498 * is created and added to the linked list of lbfile
499 * structures. The file containing the found symbol
505 int fndsym( char *name )
507 struct lbfile *lbfh, *lbf;
508 pmlibraryfile ThisLibr;
509 pmlibrarysymbol ThisSym = NULL;
511 pmlibraryfile FirstFound;
514 /* Build the index if this is the first call to fndsym */
515 if (libr==NULL) buildlibraryindex();
517 /* Iterate through all library object files */
519 FirstFound = libr; /*So gcc stops whining*/
522 /* Iterate through all symbols in an object file */
523 ThisSym = ThisLibr->symbols;
527 if (!strcmp(ThisSym->name, name))
529 if ((!ThisLibr->loaded) && (numfound==0))
531 /* Object file is not loaded - add it to the list */
532 lbfh = (struct lbfile *) new (sizeof(struct lbfile));
544 lbfh->libspc = ThisLibr->libspc;
545 lbfh->filspc = ThisLibr->filename;
546 lbfh->relfil = (char *) new (strlen(ThisLibr->relfil) + 1);
547 strcpy(lbfh->relfil, ThisLibr->relfil);
548 lbfh->offset = ThisLibr->offset;
550 { /*For an embedded object file in a library*/
551 void loadfile_SdccLib(char * libspc, char * module, long offset);
552 loadfile_SdccLib(lbfh->libspc, lbfh->relfil, lbfh->offset);
555 { /*For a stand alone object file*/
556 loadfile(lbfh->filspc);
568 char absPath1[PATH_MAX];
569 char absPath2[PATH_MAX];
570 #if defined(__BORLANDC__) || defined(_MSC_VER) || defined(__MINGW32__)
573 _fullpath(absPath1, FirstFound->libspc, PATH_MAX);
574 _fullpath(absPath2, ThisLibr->libspc, PATH_MAX);
575 for(j=0; absPath1[j]!=0; j++) absPath1[j]=tolower((unsigned char)absPath1[j]);
576 for(j=0; absPath2[j]!=0; j++) absPath2[j]=tolower((unsigned char)absPath2[j]);
578 realpath(FirstFound->libspc, absPath1);
579 realpath(ThisLibr->libspc, absPath2);
581 if( !( EQ(absPath1, absPath2) && EQ(FirstFound->relfil, ThisLibr->relfil) ) )
585 fprintf(stderr, "?Aslink-Warning-Definition of public symbol '%s'"
586 " found more than once:\n", name);
587 fprintf(stderr, " Library: '%s', Module: '%s'\n",
588 FirstFound->libspc, FirstFound->relfil);
590 fprintf(stderr, " Library: '%s', Module: '%s'\n",
591 ThisLibr->libspc, ThisLibr->relfil);
596 ThisSym=ThisSym->next; /* Next sym in library */
598 ThisLibr=ThisLibr->next; /* Next library in list */
603 pmlibraryfile buildlibraryindex_SdccLib(char * PathLib, FILE * libfp, char * DirLib, pmlibraryfile This)
605 char ModName[NCPS]="";
606 char FLine[MAXLINE+1];
609 long IndexOffset=0, FileOffset;
610 pmlibrarysymbol ThisSym = NULL;
615 fgets(FLine, MAXLINE, libfp);
621 if(EQ(FLine, "<INDEX>"))
623 /*The next line has the size of the index*/
625 fgets(FLine, MAXLINE, libfp);
627 IndexOffset=atol(FLine);
632 if(EQ(FLine, "<MODULE>"))
634 /*The next line has the name of the module and the offset
635 of the corresponding embedded file in the library*/
637 fgets(FLine, MAXLINE, libfp);
639 sscanf(FLine, "%s %ld", ModName, &FileOffset);
642 /*Create a new libraryfile object for this module*/
645 libr=This=(pmlibraryfile)new( sizeof( mlibraryfile ));
649 This->next=(pmlibraryfile)new( sizeof( mlibraryfile ));
654 This->offset=FileOffset+IndexOffset;
655 This->libspc=PathLib;
657 This->relfil=(char *)new(strlen(ModName)+1);
658 strcpy(This->relfil, ModName);
660 sprintf(buff, "%s%s%c%s", DirLib, ModName, FSEPX, LKOBJEXT);
661 This->filename=(char *)new(strlen(buff)+1);
662 strcpy(This->filename, buff);
664 This->symbols=ThisSym=NULL; /*Start a new linked list of symbols*/
666 else if(EQ(FLine, "</INDEX>"))
668 return This; /*Finish, get out of here*/
672 if(EQ(FLine, "</MODULE>"))
675 /*Create the index for the next module*/
681 if(ThisSym==NULL) /*First symbol of the current module*/
683 ThisSym=This->symbols=(pmlibrarysymbol)new(sizeof(mlibrarysymbol));
687 ThisSym->next = (pmlibrarysymbol)new(sizeof(mlibrarysymbol));
688 ThisSym=ThisSym->next;
691 ThisSym->name=(char *)new(strlen(FLine)+1);
692 strcpy(ThisSym->name, FLine);
697 return This; /*State machine should never reach this point, but just in case...*/
702 return This; /*State machine should never reach this point, but just in case...*/
706 /* buildlibraryindex - build an in-memory cache of the symbols contained in
709 int buildlibraryindex(void)
713 char relfil[NINPUT+2], str[PATH_MAX], *path;
714 char buf[NINPUT+2], c;
715 char symname[NINPUT+2];
716 pmlibraryfile This=NULL;
717 pmlibrarysymbol ThisSym;
720 * Search through every library in the linked list "lbnhead".
722 for (lbnh=lbnhead; lbnh; lbnh=lbnh->next)
724 if ((libfp = fopen(lbnh->libspc, "r")) == NULL)
726 fprintf(stderr, "?Aslink-Error-Cannot open library file %s\n",
733 * Read in a line from the library file.
734 * This is the relative file specification
735 * for a .REL file in this library.
738 while (fgets(relfil, NINPUT, libfp) != NULL)
740 relfil[NINPUT+1] = '\0';
746 if (strlen(str) && (str[strlen(str)-1] != '/') && (str[strlen(str)-1] != '\\'))
748 strcat(str, LKDIRSEPSTR);
757 if(strcmp(relfil, "<SDCCLIB>")==0)
759 /*Get the built in index of this library*/
760 This=buildlibraryindex_SdccLib(lbnh->libspc, libfp, str, This);
761 break; /*get the index for next library*/
764 /*From here down, build the index for the original library format*/
766 if ((relfil[0] == '/') || (relfil[0] == '\\'))
768 strcat(str, relfil+1);
775 if(strchr(relfil, FSEPX) == NULL)
777 sprintf(&str[strlen(str)], "%c%s", FSEPX, LKOBJEXT);
780 if ((fp = fopen(str, "r")) != NULL)
782 /* Opened OK - create a new libraryfile object for it */
785 libr=This=(pmlibraryfile)new( sizeof( mlibraryfile ));
789 This->next=(pmlibraryfile)new( sizeof( mlibraryfile ));
794 This->offset=-1; /*There should be a rel file*/
795 This->libspc = lbnh->libspc;
797 This->relfil=(char *)new(strlen(relfil)+1);
798 strcpy(This->relfil, relfil);
800 This->filename=(char *)new(strlen(str)+1);
801 strcpy(This->filename, str);
803 /*Start a new linked list of symbols for this module:*/
804 This->symbols = ThisSym = NULL;
807 * Read in the object file. Look for lines that
808 * begin with "S" and end with "D". These are
809 * symbol table definitions. If we find one, see
810 * if it is our symbol. Make sure we only read in
811 * our object file and don't go into the next one.
814 while (fgets(buf, NINPUT, fp) != NULL)
816 buf[NINPUT+1] = '\0';
817 buf[strlen(buf) - 1] = '\0';
820 * Skip everything that's not a symbol record.
822 if (buf[0] != 'S') continue;
825 * When a 'T line' is found terminate file scan.
826 * All 'S line's preceed 'T line's in .REL files.
828 if (buf[0] == 'T') break;
830 sscanf(buf, "S %s %c", symname, &c);
832 /* If it's an actual symbol, record it */
837 ThisSym=This->symbols=(pmlibrarysymbol)new(sizeof(mlibrarysymbol));
841 ThisSym->next=(pmlibrarysymbol)new(sizeof(mlibrarysymbol));
842 ThisSym=ThisSym->next;
846 ThisSym->name=(char *)new(strlen(symname)+1);
847 strcpy(ThisSym->name, symname);
849 } /* Closes while - read object file */
851 } /* Closes if object file opened OK */
854 fprintf(stderr, "?Aslink-Warning-Cannot open library module %s\n", str);
856 } /* Ends while - processing all in libr */
858 } /* Ends good open of libr file */
862 /*Release all memory allocated for the in-memory library index*/
863 void freelibraryindex (void)
865 pmlibraryfile ThisLibr, ThisLibr2Free;
866 pmlibrarysymbol ThisSym, ThisSym2Free;
872 ThisSym = ThisLibr->symbols;
877 ThisSym2Free=ThisSym;
878 ThisSym=ThisSym->next;
881 free(ThisLibr->filename);
882 free(ThisLibr->relfil);
883 ThisLibr2Free=ThisLibr;
884 ThisLibr=ThisLibr->next;
894 /*Check for a symbol in a SDCC library. If found, add the embedded .rel.
895 The library must be created with the SDCC librarian 'sdcclib' since the
896 linking process depends on the correct file offsets embedded in the library
899 int SdccLib(char * PathLib, FILE * libfp, char * DirLib, char * SymName)
901 struct lbfile *lbfh, *lbf;
902 char ModName[NCPS]="";
903 char FLine[MAXLINE+1];
905 long IndexOffset=0, FileOffset;
910 fgets(FLine, MAXLINE, libfp);
916 if(EQ(FLine, "<INDEX>"))
918 /*The next line has the size of the index*/
920 fgets(FLine, MAXLINE, libfp);
922 IndexOffset=atol(FLine);
927 if(EQ(FLine, "<MODULE>"))
929 /*The next line has the name of the module and the offset
930 of the corresponding embedded file in the library*/
932 fgets(FLine, MAXLINE, libfp);
934 sscanf(FLine, "%s %ld", ModName, &FileOffset);
937 else if(EQ(FLine, "</INDEX>"))
939 /*Reached the end of the index. The symbol is not in this library.*/
944 if(EQ(FLine, "</MODULE>"))
946 /*The symbol is not in this module, try the next one*/
951 /*Check if this is the symbol we are looking for.*/
952 if (strncmp(SymName, FLine, NCPS)==0)
954 /*The symbol is in this module.*/
956 /*As in the original library format, it is assumed that the .rel
957 files reside in the same directory as the lib files.*/
958 strcat(DirLib, ModName);
959 sprintf(&DirLib[strlen(DirLib)], "%c%s", FSEPX, LKOBJEXT);
961 /*If this module has been loaded already don't load it again.*/
965 if(EQ(DirLib, lbf->filspc)) return 1;/*Already loaded*/
969 /*Add the embedded file to the list of files to be loaded in
970 the second pass. That is performed latter by the function
972 lbfh = (struct lbfile *) new (sizeof(struct lbfile));
985 lbfh->libspc = PathLib;
986 lbfh->filspc = DirLib;
987 lbfh->relfil = (char *) new (strlen(ModName) + 1);
988 strcpy(lbfh->relfil, ModName);
989 /*Library embedded file, so lbfh->offset must be >=0*/
990 lbfh->offset = IndexOffset+FileOffset;
992 /*Jump to where the .rel begins and load it.*/
993 fseek(libfp, lbfh->offset, SEEK_SET);
994 LoadRel(PathLib, libfp, ModName);
996 return 1; /*Found the symbol, so success!*/
1002 return 0; /*It should never reach this point, but just in case...*/
1007 return 0; /*The symbol is not in this library*/
1010 /*)Function VOID fndsym(name)
1012 * char *name symbol name to find
1014 * The function fndsym() searches through all combinations of the
1015 * library path specifications (input by the -k option) and the
1016 * library file specifications (input by the -l option) that
1017 * lead to an existing file.
1019 * The file specicifation may be formed in one of two ways:
1021 * (1) If the library file contained an absolute
1022 * path/file specification then this becomes filspc.
1025 * (2) If the library file contains a relative path/file
1026 * specification then the concatenation of the path
1027 * and this file specification becomes filspc.
1030 * The structure lbfile is created for the first library
1031 * object file which contains the definition for the
1032 * specified undefined symbol.
1034 * If the library file [.LIB] contains file specifications for
1035 * non existant files, no errors are returned.
1038 * char buf[] [.REL] file input line
1039 * char c [.REL] file input character
1040 * FILE *fp file handle for object file
1041 * lbfile *lbf temporary pointer
1042 * lbfile *lbfh pointer to lbfile structure
1043 * FILE *libfp file handle for library file
1044 * lbname *lbnh pointer to lbname structure
1045 * char *path file specification path
1046 * char relfil[] [.REL] file specification
1047 * char *str combined path and file specification
1048 * char symname[] [.REL] file symbol string
1051 * lbname *lbnhead The pointer to the first
1053 * lbfile *lbfhead The pointer to the first
1057 * int fclose() c_library
1058 * int fgets() c_library
1059 * FILE *fopen() c_library
1060 * VOID free() c_library
1061 * char getnb() lklex.c
1062 * VOID lkexit() lkmain.c
1063 * VOID loadfile() lklibr.c
1064 * VOID * new() lksym.c
1065 * char * sprintf() c_library
1066 * int sscanf() c_library
1067 * char * strcat() c_library
1068 * char * strchr() c_library
1069 * char * strcpy() c_library
1070 * int strlen() c_library
1071 * int strncmp() c_library
1072 * VOID unget() lklex.c
1075 * If the symbol is found then a new lbfile structure
1076 * is created and added to the linked list of lbfile
1077 * structures. The file containing the found symbol
1086 struct lbname *lbnh;
1087 struct lbfile *lbfh, *lbf;
1088 char relfil[NINPUT+2];
1090 char symname[NINPUT];
1096 * Search through every library in the linked list "lbnhead".
1099 for (lbnh=lbnhead; lbnh; lbnh=lbnh->next)
1101 if ((libfp = fopen(lbnh->libspc, "r")) == NULL)
1103 fprintf(stderr, "?ASlink-Error-Cannot open library file %s\n",
1110 * Read in a line from the library file.
1111 * This is the relative file specification
1112 * for a .REL file in this library.
1115 while (fgets(relfil, NINPUT, libfp) != NULL)
1117 relfil[NINPUT+1] = '\0';
1121 str = (char *) new (strlen(path)+strlen(relfil)+6);
1124 if (strlen(str) && (str[strlen(str)-1] != '/') && (str[strlen(str)-1] != '\\'))
1140 str = (char *) new (strlen(relfil) + 5);
1143 /*See if this is a library with embedded files*/
1144 if(strcmp(relfil, "<SDCCLIB>")==0)
1146 result=SdccLib(lbnh->libspc, libfp, str, name);
1147 if(result) return(1); /*Found the symbol*/
1149 /*The symbol is not in the current library,
1150 check the next library in the list*/
1154 /*From here down is the support for libraries in the original format*/
1155 if ((relfil[0] == '/') || (relfil[0] == '\\'))
1157 strcat(str, relfil+1);
1161 strcat(str, relfil);
1164 if(strchr(relfil, FSEPX) == NULL)
1166 sprintf(&str[strlen(str)], "%c%s", FSEPX, LKOBJEXT);
1169 if ((fp = fopen(str, "r")) != NULL)
1172 * Read in the object file. Look for lines that
1173 * begin with "S" and end with "D". These are
1174 * symbol table definitions. If we find one, see
1175 * if it is our symbol. Make sure we only read in
1176 * our object file and don't go into the next one.
1179 while (fgets(buf, NINPUT, fp) != NULL)
1181 buf[NINPUT+1] = '\0';
1184 * Skip everything that's not a symbol record.
1190 * When a 'T line' is found terminate file scan.
1191 * All 'S line's preceed 'T line's in .REL files.
1196 sscanf(buf, "S %s %c", symname, &c);
1199 * If we find a symbol definition for the
1200 * symbol we're looking for, load in the
1201 * file and add it to lbfhead so it gets
1202 * loaded on pass number 2.
1204 if (strncmp(symname, name, NCPS) == 0 && c == 'D')
1206 lbfh = (struct lbfile *) new (sizeof(struct lbfile));
1207 if (lbfhead == NULL)
1219 lbfh->libspc = lbnh->libspc;
1221 lbfh->relfil = (char *) new (strlen(relfil) + 1);
1222 lbfh->offset = -1; /*Stand alone rel file*/
1223 strcpy(lbfh->relfil,relfil);
1239 #endif /* INDEXLIB */
1241 void loadfile_SdccLib(char * libspc, char * module, long offset)
1246 char posix_path[PATH_MAX];
1247 void cygwin_conv_to_full_posix_path(char * win_path, char * posix_path);
1248 cygwin_conv_to_full_posix_path(libspc, posix_path);
1249 fp = fopen(posix_path, "r");
1251 fp = fopen(libspc,"r");
1256 fseek(fp, offset, SEEK_SET);
1257 LoadRel(libspc, fp, module);
1262 fprintf(stderr, "?ASlink-Error-Opening library '%s'\n", libspc);
1267 /*)Function VOID library()
1269 * The function library() links all the library object files
1270 * contained in the lbfile structures.
1273 * lbfile *lbfh pointer to lbfile structure
1276 * lbfile *lbfhead pointer to first lbfile structure
1279 * VOID loadfile lklibr.c
1282 * Links all files contained in the lbfile structures.
1288 struct lbfile *lbfh;
1290 for (lbfh=lbfhead; lbfh; lbfh=lbfh->next)
1294 /*Stand alone rel file (original lib format)*/
1295 loadfile(lbfh->filspc);
1299 /*rel file embedded in lib (new lib format)*/
1300 loadfile_SdccLib(lbfh->libspc, lbfh->relfil, lbfh->offset);
1308 /*)Function VOID loadfile(filspc)
1310 * char *filspc library object file specification
1312 * The function loadfile() links the library object module.
1315 * FILE *fp file handle
1316 * int i input line length
1317 * char str[] file input line
1320 * char *ip pointer to linker input string
1323 * int fclose() c_library
1324 * int fgets() c_library
1325 * FILE * fopen() c_library
1326 * VOID link_main() lkmain.c
1327 * int strlen() c_library
1330 * If file exists it is linked.
1341 char posix_path[PATH_MAX];
1342 void cygwin_conv_to_full_posix_path(char * win_path, char * posix_path);
1343 cygwin_conv_to_full_posix_path(filspc, posix_path);
1344 fp = fopen(posix_path, "r");
1346 fp = fopen(filspc,"r");
1351 while (fgets(str, NINPUT, fp) != NULL)
1353 str[NINPUT+1] = '\0';
1362 fprintf(stderr, "?ASlink-Error-Opening library '%s'\n", filspc);