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*/
35 #define LKDIRSEPSTR "/"
38 #define LKDIRSEPSTR "\\"
42 #define LKDIRSEPSTR "\\"
48 * The module lklibr.c contains the functions which
49 * (1) specify the path(s) to library files [.LIB]
50 * (2) specify the library file(s) [.LIB] to search
51 * (3) search the library files for specific symbols
52 * and link the module containing this symbol
54 * lklibr.c contains the following functions:
66 typedef struct slibrarysymbol mlibrarysymbol;
67 typedef struct slibrarysymbol *pmlibrarysymbol;
69 struct slibrarysymbol {
70 char * name; /*Warning: allocate memory before using*/
74 typedef struct slibraryfile mlibraryfile;
75 typedef struct slibraryfile *pmlibraryfile;
80 char * relfil; /*Warning: allocate memory before using*/
81 char * filename; /*Warning: allocate memory before using*/
82 long offset; //if > 0, the embedded file offset in the library file libspc
83 pmlibrarysymbol symbols;
87 /* First entry in the library object symbol cache */
88 pmlibraryfile libr=NULL;
90 int buildlibraryindex();
91 void freelibraryindex (void);
94 /*)Function VOID addpath()
96 * The function addpath() creates a linked structure containing
97 * the paths to various object module library files.
100 * lbpath *lbph pointer to new path structure
101 * lbpath *lbp temporary pointer
104 * lbpath *lbphead The pointer to the first
108 * char getnb() lklex.c
109 * VOID * new() lksym.c
110 * int strlen() c_library
111 * char * strcpy() c_library
112 * VOID unget() lklex.c
115 * An lbpath structure may be created.
121 struct lbpath *lbph, *lbp;
123 lbph = (struct lbpath *) new (sizeof(struct lbpath));
124 if (lbphead == NULL) {
133 lbph->path = (char *) new (strlen(ip)+1);
134 strcpy(lbph->path, ip);
137 /*)Function VOID addlib()
139 * The function addlib() tests for the existance of a
140 * library path structure to determine the method of
141 * adding this library file to the library search structure.
143 * This function calls the function addfile() to actually
144 * add the library file to the search list.
147 * lbpath *lbph pointer to path structure
150 * lbpath *lbphead The pointer to the first
152 * ip a pointer to the library name
155 * VOID addfile() lklibr.c
156 * char getnb() lklex.c
157 * VOID unget() lklex.c
160 * The function addfile() may add the file to
161 * the library search list.
174 foundcount=addfile(NULL, ip);
178 for (lbph=lbphead; lbph; lbph=lbph->next)
180 foundcount+=addfile(lbph->path, ip);
185 fprintf(stderr, "?ASlink-Warning-Couldn't find library '%s'\n", ip);
189 /*)Function int addfile(path,libfil)
191 * char *path library path specification
192 * char *libfil library file specification
194 * The function addfile() searches for the library file
195 * by concatenating the path and libfil specifications.
196 * if the library is found, an lbname structure is created
197 * and linked to any previously defined structures. This
198 * linked list is used by the function fndsym() to attempt
199 * to find any undefined symbols.
201 * The function does not give report an error on invalid
202 * path / file specifications or if the file is not found.
205 * lbname *lbnh pointer to new name structure
206 * lbname *lbn temporary pointer
209 * lbname *lbnhead The pointer to the first
213 * char getnb() lklex.c
214 * VOID * new() lksym.c
215 * int strlen() c_library
216 * char * strcpy() c_library
217 * VOID unget() lklex.c
220 * An lbname structure may be created.
223 * 1: the library was found
224 * 0: the library was not found
227 int addfile(char * path, char * libfil)
231 struct lbname *lbnh, *lbn;
236 str = (char *) new (strlen(path) + strlen(libfil) + 6);
238 if (strlen(str) && (str[strlen(str)-1] != '/') && (str[strlen(str)-1] != '\\'))
240 strcat(str, LKDIRSEPSTR);
245 str = (char *) new (strlen(libfil) + 5);
248 if ((libfil[0] == '/') || (libfil[0] == '\\'))
256 if(strchr(libfil, FSEPX) == NULL)
258 sprintf(&str[strlen(str)], "%clib", FSEPX);
264 /*Ok, that didn't work. Try with the 'libfil' name only*/
265 if(libfilinc) libfil--;
266 fp=fopen(libfil, "r");
269 /*Bingo! 'libfil' is the absolute path of the library*/
271 path=NULL;/*This way 'libfil' and 'path' will be rebuilt from 'str'*/
277 /*'path' can not be null since it is needed to find the .rel/.o files associated with
278 the library. So, get 'path' from 'str' and then chop it off and recreate 'libfil'.
279 That way putting 'path' and 'libfil' together will result into the original filepath
280 as contained in 'str'.*/
282 path = (char *) new (strlen(str) + 1);
284 for(j=strlen(path)-1; j>=0; j--)
286 if((path[j] == '/') || (path[j] == '\\'))
288 strcpy(libfil, &path[j+1]);
299 lbnh = (struct lbname *) new (sizeof(struct lbname));
313 lbnh->libfil = (char *) new (strlen(libfil) + 1);
314 strcpy(lbnh->libfil, libfil);
325 /*)Function VOID search()
327 * The function search() looks through all the symbol tables
328 * at the end of pass 1. If any undefined symbols are found
329 * then the function fndsym() is called. Function fndsym()
330 * searches any specified library files to automagically
331 * import the object modules containing the needed symbol.
333 * After a symbol is found and imported by the function
334 * fndsym() the symbol tables are again searched. The
335 * symbol tables are search until no more symbols can be
336 * resolved within the library files. This ensures that
337 * back references from one library module to another are
341 * int i temporary counter
342 * sym *sp pointer to a symbol structure
343 * int symfnd found a symbol flag
346 * sym *symhash[] array of pointers to symbol tables
349 * int fndsym() lklibr.c
352 * If a symbol is found then the library object module
353 * containing the symbol will be imported and linked.
359 register struct sym *sp;
360 register int i, symfnd;
363 * Look for undefined symbols. Keep
364 * searching until no more symbols are resolved.
370 * Look through all the symbols
372 for (i=0; i<NHASH; ++i) {
375 /* If we find an undefined symbol
376 * (one where S_DEF is not set), then
377 * try looking for it. If we find it
378 * in any of the libraries then
379 * increment symfnd. This will force
380 * another pass of symbol searching and
381 * make sure that back references work.
383 if ((sp->s_type & S_DEF) == 0) {
384 if (fndsym(sp->s_id)) {
394 /*Load a .rel file embedded in a sdcclib file*/
395 void LoadRel(char * libfname, FILE * libfp, char * ModName)
400 while (fgets(str, NINPUT, libfp) != NULL)
402 str[NINPUT+1] = '\0';
407 if(EQ(str, "<FILE>"))
409 fgets(str, NINPUT, libfp);
410 str[NINPUT+1] = '\0';
412 if(EQ(str, ModName)) state=1;
415 fprintf(stderr, "?ASlink-Error-Bad offset in library file %s(%s)\n",
422 if(EQ(str, "<REL>")) state=2;
425 if(EQ(str, "</REL>")) return;
433 /*)Function VOID fndsym(name)
435 * char *name symbol name to find
437 * The function fndsym() searches through all combinations of the
438 * library path specifications (input by the -k option) and the
439 * library file specifications (input by the -l option) that
440 * lead to an existing file.
442 * The file specicifation may be formed in one of two ways:
444 * (1) If the library file contained an absolute
445 * path/file specification then this becomes filspc.
448 * (2) If the library file contains a relative path/file
449 * specification then the concatenation of the path
450 * and this file specification becomes filspc.
453 * The structure lbfile is created for the first library
454 * object file which contains the definition for the
455 * specified undefined symbol.
457 * If the library file [.LIB] contains file specifications for
458 * non existant files, no errors are returned.
461 * char buf[] [.REL] file input line
462 * char c [.REL] file input character
463 * FILE *fp file handle for object file
464 * lbfile *lbf temporary pointer
465 * lbfile *lbfh pointer to lbfile structure
466 * FILE *libfp file handle for library file
467 * lbname *lbnh pointer to lbname structure
468 * char *path file specification path
469 * char relfil[] [.REL] file specification
470 * char *str combined path and file specification
471 * char symname[] [.REL] file symbol string
474 * lbname *lbnhead The pointer to the first
476 * lbfile *lbfhead The pointer to the first
480 * int fclose() c_library
481 * int fgets() c_library
482 * FILE *fopen() c_library
483 * VOID free() c_library
484 * char getnb() lklex.c
485 * VOID lkexit() lkmain.c
486 * VOID loadfile() lklibr.c
487 * VOID * new() lksym.c
488 * char * sprintf() c_library
489 * int sscanf() c_library
490 * char * strcat() c_library
491 * char * strchr() c_library
492 * char * strcpy() c_library
493 * int strlen() c_library
494 * int strncmp() c_library
495 * VOID unget() lklex.c
498 * If the symbol is found then a new lbfile structure
499 * is created and added to the linked list of lbfile
500 * structures. The file containing the found symbol
506 int fndsym( char *name )
508 struct lbfile *lbfh, *lbf;
509 pmlibraryfile ThisLibr;
510 pmlibrarysymbol ThisSym = NULL;
512 pmlibraryfile FirstFound;
515 /* Build the index if this is the first call to fndsym */
516 if (libr==NULL) buildlibraryindex();
518 /* Iterate through all library object files */
520 FirstFound = libr; /*So gcc stops whining*/
523 /* Iterate through all symbols in an object file */
524 ThisSym = ThisLibr->symbols;
528 if (!strcmp(ThisSym->name, name))
530 if ((!ThisLibr->loaded) && (numfound==0))
532 /* Object file is not loaded - add it to the list */
533 lbfh = (struct lbfile *) new (sizeof(struct lbfile));
545 lbfh->libspc = ThisLibr->libspc;
546 lbfh->filspc = ThisLibr->filename;
547 lbfh->relfil = (char *) new (strlen(ThisLibr->relfil) + 1);
548 strcpy(lbfh->relfil, ThisLibr->relfil);
549 lbfh->offset = ThisLibr->offset;
551 { /*For an embedded object file in a library*/
552 void loadfile_SdccLib(char * libspc, char * module, long offset);
553 loadfile_SdccLib(lbfh->libspc, lbfh->relfil, lbfh->offset);
556 { /*For a stand alone object file*/
557 loadfile(lbfh->filspc);
569 char absPath1[PATH_MAX];
570 char absPath2[PATH_MAX];
571 #if defined(__BORLANDC__) || defined(_MSC_VER) || defined(__MINGW32__)
574 _fullpath(absPath1, FirstFound->libspc, PATH_MAX);
575 _fullpath(absPath2, ThisLibr->libspc, PATH_MAX);
576 for(j=0; absPath1[j]!=0; j++) absPath1[j]=tolower((unsigned char)absPath1[j]);
577 for(j=0; absPath2[j]!=0; j++) absPath2[j]=tolower((unsigned char)absPath2[j]);
579 realpath(FirstFound->libspc, absPath1);
580 realpath(ThisLibr->libspc, absPath2);
582 if( !( EQ(absPath1, absPath2) && EQ(FirstFound->relfil, ThisLibr->relfil) ) )
586 fprintf(stderr, "?Aslink-Warning-Definition of public symbol '%s'"
587 " found more than once:\n", name);
588 fprintf(stderr, " Library: '%s', Module: '%s'\n",
589 FirstFound->libspc, FirstFound->relfil);
591 fprintf(stderr, " Library: '%s', Module: '%s'\n",
592 ThisLibr->libspc, ThisLibr->relfil);
597 ThisSym=ThisSym->next; /* Next sym in library */
599 ThisLibr=ThisLibr->next; /* Next library in list */
604 pmlibraryfile buildlibraryindex_SdccLib(char * PathLib, FILE * libfp, char * DirLib, pmlibraryfile This)
606 char ModName[NCPS]="";
607 char FLine[MAXLINE+1];
610 long IndexOffset=0, FileOffset;
611 pmlibrarysymbol ThisSym = NULL;
616 fgets(FLine, MAXLINE, libfp);
622 if(EQ(FLine, "<INDEX>"))
624 /*The next line has the size of the index*/
626 fgets(FLine, MAXLINE, libfp);
628 IndexOffset=atol(FLine);
633 if(EQ(FLine, "<MODULE>"))
635 /*The next line has the name of the module and the offset
636 of the corresponding embedded file in the library*/
638 fgets(FLine, MAXLINE, libfp);
640 sscanf(FLine, "%s %ld", ModName, &FileOffset);
643 /*Create a new libraryfile object for this module*/
646 libr=This=(pmlibraryfile)new( sizeof( mlibraryfile ));
650 This->next=(pmlibraryfile)new( sizeof( mlibraryfile ));
655 This->offset=FileOffset+IndexOffset;
656 This->libspc=PathLib;
658 This->relfil=(char *)new(strlen(ModName)+1);
659 strcpy(This->relfil, ModName);
661 sprintf(buff, "%s%s%c%s", DirLib, ModName, FSEPX, LKOBJEXT);
662 This->filename=(char *)new(strlen(buff)+1);
663 strcpy(This->filename, buff);
665 This->symbols=ThisSym=NULL; /*Start a new linked list of symbols*/
667 else if(EQ(FLine, "</INDEX>"))
669 return This; /*Finish, get out of here*/
673 if(EQ(FLine, "</MODULE>"))
676 /*Create the index for the next module*/
682 if(ThisSym==NULL) /*First symbol of the current module*/
684 ThisSym=This->symbols=(pmlibrarysymbol)new(sizeof(mlibrarysymbol));
688 ThisSym->next = (pmlibrarysymbol)new(sizeof(mlibrarysymbol));
689 ThisSym=ThisSym->next;
692 ThisSym->name=(char *)new(strlen(FLine)+1);
693 strcpy(ThisSym->name, FLine);
698 return This; /*State machine should never reach this point, but just in case...*/
703 return This; /*State machine should never reach this point, but just in case...*/
707 /* buildlibraryindex - build an in-memory cache of the symbols contained in
710 int buildlibraryindex(void)
714 char relfil[NINPUT+2], str[PATH_MAX], *path;
715 char buf[NINPUT+2], c;
716 char symname[NINPUT+2];
717 pmlibraryfile This=NULL;
718 pmlibrarysymbol ThisSym;
721 * Search through every library in the linked list "lbnhead".
723 for (lbnh=lbnhead; lbnh; lbnh=lbnh->next)
725 if ((libfp = fopen(lbnh->libspc, "r")) == NULL)
727 fprintf(stderr, "?Aslink-Error-Cannot open library file %s\n",
734 * Read in a line from the library file.
735 * This is the relative file specification
736 * for a .REL file in this library.
739 while (fgets(relfil, NINPUT, libfp) != NULL)
741 relfil[NINPUT+1] = '\0';
747 if (strlen(str) && (str[strlen(str)-1] != '/') && (str[strlen(str)-1] != '\\'))
749 strcat(str, LKDIRSEPSTR);
758 if(strcmp(relfil, "<SDCCLIB>")==0)
760 /*Get the built in index of this library*/
761 This=buildlibraryindex_SdccLib(lbnh->libspc, libfp, str, This);
762 break; /*get the index for next library*/
765 /*From here down, build the index for the original library format*/
767 if ((relfil[0] == '/') || (relfil[0] == '\\'))
769 strcat(str, relfil+1);
776 if(strchr(relfil, FSEPX) == NULL)
778 sprintf(&str[strlen(str)], "%c%s", FSEPX, LKOBJEXT);
781 if ((fp = fopen(str, "r")) != NULL)
783 /* Opened OK - create a new libraryfile object for it */
786 libr=This=(pmlibraryfile)new( sizeof( mlibraryfile ));
790 This->next=(pmlibraryfile)new( sizeof( mlibraryfile ));
795 This->offset=-1; /*There should be a rel file*/
796 This->libspc = lbnh->libspc;
798 This->relfil=(char *)new(strlen(relfil)+1);
799 strcpy(This->relfil, relfil);
801 This->filename=(char *)new(strlen(str)+1);
802 strcpy(This->filename, str);
804 /*Start a new linked list of symbols for this module:*/
805 This->symbols = ThisSym = NULL;
808 * Read in the object file. Look for lines that
809 * begin with "S" and end with "D". These are
810 * symbol table definitions. If we find one, see
811 * if it is our symbol. Make sure we only read in
812 * our object file and don't go into the next one.
815 while (fgets(buf, NINPUT, fp) != NULL)
817 buf[NINPUT+1] = '\0';
818 buf[strlen(buf) - 1] = '\0';
821 * Skip everything that's not a symbol record.
823 if (buf[0] != 'S') continue;
826 * When a 'T line' is found terminate file scan.
827 * All 'S line's preceed 'T line's in .REL files.
829 if (buf[0] == 'T') break;
831 sscanf(buf, "S %s %c", symname, &c);
833 /* If it's an actual symbol, record it */
838 ThisSym=This->symbols=(pmlibrarysymbol)new(sizeof(mlibrarysymbol));
842 ThisSym->next=(pmlibrarysymbol)new(sizeof(mlibrarysymbol));
843 ThisSym=ThisSym->next;
847 ThisSym->name=(char *)new(strlen(symname)+1);
848 strcpy(ThisSym->name, symname);
850 } /* Closes while - read object file */
852 } /* Closes if object file opened OK */
855 fprintf(stderr, "?Aslink-Warning-Cannot open library module %s\n", str);
857 } /* Ends while - processing all in libr */
859 } /* Ends good open of libr file */
863 /*Release all memory allocated for the in-memory library index*/
864 void freelibraryindex (void)
866 pmlibraryfile ThisLibr, ThisLibr2Free;
867 pmlibrarysymbol ThisSym, ThisSym2Free;
873 ThisSym = ThisLibr->symbols;
878 ThisSym2Free=ThisSym;
879 ThisSym=ThisSym->next;
882 free(ThisLibr->filename);
883 free(ThisLibr->relfil);
884 ThisLibr2Free=ThisLibr;
885 ThisLibr=ThisLibr->next;
895 /*Check for a symbol in a SDCC library. If found, add the embedded .rel.
896 The library must be created with the SDCC librarian 'sdcclib' since the
897 linking process depends on the correct file offsets embedded in the library
900 int SdccLib(char * PathLib, FILE * libfp, char * DirLib, char * SymName)
902 struct lbfile *lbfh, *lbf;
903 char ModName[NCPS]="";
904 char FLine[MAXLINE+1];
906 long IndexOffset=0, FileOffset;
911 fgets(FLine, MAXLINE, libfp);
917 if(EQ(FLine, "<INDEX>"))
919 /*The next line has the size of the index*/
921 fgets(FLine, MAXLINE, libfp);
923 IndexOffset=atol(FLine);
928 if(EQ(FLine, "<MODULE>"))
930 /*The next line has the name of the module and the offset
931 of the corresponding embedded file in the library*/
933 fgets(FLine, MAXLINE, libfp);
935 sscanf(FLine, "%s %ld", ModName, &FileOffset);
938 else if(EQ(FLine, "</INDEX>"))
940 /*Reached the end of the index. The symbol is not in this library.*/
945 if(EQ(FLine, "</MODULE>"))
947 /*The symbol is not in this module, try the next one*/
952 /*Check if this is the symbol we are looking for.*/
953 if (strncmp(SymName, FLine, NCPS)==0)
955 /*The symbol is in this module.*/
957 /*As in the original library format, it is assumed that the .rel
958 files reside in the same directory as the lib files.*/
959 strcat(DirLib, ModName);
960 sprintf(&DirLib[strlen(DirLib)], "%c%s", FSEPX, LKOBJEXT);
962 /*If this module has been loaded already don't load it again.*/
966 if(EQ(DirLib, lbf->filspc)) return 1;/*Already loaded*/
970 /*Add the embedded file to the list of files to be loaded in
971 the second pass. That is performed latter by the function
973 lbfh = (struct lbfile *) new (sizeof(struct lbfile));
986 lbfh->libspc = PathLib;
987 lbfh->filspc = DirLib;
988 lbfh->relfil = (char *) new (strlen(ModName) + 1);
989 strcpy(lbfh->relfil, ModName);
990 /*Library embedded file, so lbfh->offset must be >=0*/
991 lbfh->offset = IndexOffset+FileOffset;
993 /*Jump to where the .rel begins and load it.*/
994 fseek(libfp, lbfh->offset, SEEK_SET);
995 LoadRel(PathLib, libfp, ModName);
997 return 1; /*Found the symbol, so success!*/
1003 return 0; /*It should never reach this point, but just in case...*/
1008 return 0; /*The symbol is not in this library*/
1011 /*)Function VOID fndsym(name)
1013 * char *name symbol name to find
1015 * The function fndsym() searches through all combinations of the
1016 * library path specifications (input by the -k option) and the
1017 * library file specifications (input by the -l option) that
1018 * lead to an existing file.
1020 * The file specicifation may be formed in one of two ways:
1022 * (1) If the library file contained an absolute
1023 * path/file specification then this becomes filspc.
1026 * (2) If the library file contains a relative path/file
1027 * specification then the concatenation of the path
1028 * and this file specification becomes filspc.
1031 * The structure lbfile is created for the first library
1032 * object file which contains the definition for the
1033 * specified undefined symbol.
1035 * If the library file [.LIB] contains file specifications for
1036 * non existant files, no errors are returned.
1039 * char buf[] [.REL] file input line
1040 * char c [.REL] file input character
1041 * FILE *fp file handle for object file
1042 * lbfile *lbf temporary pointer
1043 * lbfile *lbfh pointer to lbfile structure
1044 * FILE *libfp file handle for library file
1045 * lbname *lbnh pointer to lbname structure
1046 * char *path file specification path
1047 * char relfil[] [.REL] file specification
1048 * char *str combined path and file specification
1049 * char symname[] [.REL] file symbol string
1052 * lbname *lbnhead The pointer to the first
1054 * lbfile *lbfhead The pointer to the first
1058 * int fclose() c_library
1059 * int fgets() c_library
1060 * FILE *fopen() c_library
1061 * VOID free() c_library
1062 * char getnb() lklex.c
1063 * VOID lkexit() lkmain.c
1064 * VOID loadfile() lklibr.c
1065 * VOID * new() lksym.c
1066 * char * sprintf() c_library
1067 * int sscanf() c_library
1068 * char * strcat() c_library
1069 * char * strchr() c_library
1070 * char * strcpy() c_library
1071 * int strlen() c_library
1072 * int strncmp() c_library
1073 * VOID unget() lklex.c
1076 * If the symbol is found then a new lbfile structure
1077 * is created and added to the linked list of lbfile
1078 * structures. The file containing the found symbol
1087 struct lbname *lbnh;
1088 struct lbfile *lbfh, *lbf;
1089 char relfil[NINPUT+2];
1091 char symname[NINPUT];
1097 * Search through every library in the linked list "lbnhead".
1100 for (lbnh=lbnhead; lbnh; lbnh=lbnh->next)
1102 if ((libfp = fopen(lbnh->libspc, "r")) == NULL)
1104 fprintf(stderr, "?ASlink-Error-Cannot open library file %s\n",
1111 * Read in a line from the library file.
1112 * This is the relative file specification
1113 * for a .REL file in this library.
1116 while (fgets(relfil, NINPUT, libfp) != NULL)
1118 relfil[NINPUT+1] = '\0';
1122 str = (char *) new (strlen(path)+strlen(relfil)+6);
1125 if (strlen(str) && (str[strlen(str)-1] != '/') && (str[strlen(str)-1] != '\\'))
1141 str = (char *) new (strlen(relfil) + 5);
1144 /*See if this is a library with embedded files*/
1145 if(strcmp(relfil, "<SDCCLIB>")==0)
1147 result=SdccLib(lbnh->libspc, libfp, str, name);
1148 if(result) return(1); /*Found the symbol*/
1150 /*The symbol is not in the current library,
1151 check the next library in the list*/
1155 /*From here down is the support for libraries in the original format*/
1156 if ((relfil[0] == '/') || (relfil[0] == '\\'))
1158 strcat(str, relfil+1);
1162 strcat(str, relfil);
1165 if(strchr(relfil, FSEPX) == NULL)
1167 sprintf(&str[strlen(str)], "%c%s", FSEPX, LKOBJEXT);
1170 if ((fp = fopen(str, "r")) != NULL)
1173 * Read in the object file. Look for lines that
1174 * begin with "S" and end with "D". These are
1175 * symbol table definitions. If we find one, see
1176 * if it is our symbol. Make sure we only read in
1177 * our object file and don't go into the next one.
1180 while (fgets(buf, NINPUT, fp) != NULL)
1182 buf[NINPUT+1] = '\0';
1185 * Skip everything that's not a symbol record.
1191 * When a 'T line' is found terminate file scan.
1192 * All 'S line's preceed 'T line's in .REL files.
1197 sscanf(buf, "S %s %c", symname, &c);
1200 * If we find a symbol definition for the
1201 * symbol we're looking for, load in the
1202 * file and add it to lbfhead so it gets
1203 * loaded on pass number 2.
1205 if (strncmp(symname, name, NCPS) == 0 && c == 'D')
1207 lbfh = (struct lbfile *) new (sizeof(struct lbfile));
1208 if (lbfhead == NULL)
1220 lbfh->libspc = lbnh->libspc;
1222 lbfh->relfil = (char *) new (strlen(relfil) + 1);
1223 lbfh->offset = -1; /*Stand alone rel file*/
1224 strcpy(lbfh->relfil,relfil);
1240 #endif /* INDEXLIB */
1242 void loadfile_SdccLib(char * libspc, char * module, long offset)
1247 char posix_path[PATH_MAX];
1248 void cygwin_conv_to_full_posix_path(char * win_path, char * posix_path);
1249 cygwin_conv_to_full_posix_path(libspc, posix_path);
1250 fp = fopen(posix_path, "r");
1252 fp = fopen(libspc,"r");
1257 fseek(fp, offset, SEEK_SET);
1258 LoadRel(libspc, fp, module);
1263 fprintf(stderr, "?ASlink-Error-Opening library '%s'\n", libspc);
1268 /*)Function VOID library()
1270 * The function library() links all the library object files
1271 * contained in the lbfile structures.
1274 * lbfile *lbfh pointer to lbfile structure
1277 * lbfile *lbfhead pointer to first lbfile structure
1280 * VOID loadfile lklibr.c
1283 * Links all files contained in the lbfile structures.
1289 struct lbfile *lbfh;
1291 for (lbfh=lbfhead; lbfh; lbfh=lbfh->next)
1295 /*Stand alone rel file (original lib format)*/
1296 loadfile(lbfh->filspc);
1300 /*rel file embedded in lib (new lib format)*/
1301 loadfile_SdccLib(lbfh->libspc, lbfh->relfil, lbfh->offset);
1309 /*)Function VOID loadfile(filspc)
1311 * char *filspc library object file specification
1313 * The function loadfile() links the library object module.
1316 * FILE *fp file handle
1317 * int i input line length
1318 * char str[] file input line
1321 * char *ip pointer to linker input string
1324 * int fclose() c_library
1325 * int fgets() c_library
1326 * FILE * fopen() c_library
1327 * VOID link_main() lkmain.c
1328 * int strlen() c_library
1331 * If file exists it is linked.
1342 char posix_path[PATH_MAX];
1343 void cygwin_conv_to_full_posix_path(char * win_path, char * posix_path);
1344 cygwin_conv_to_full_posix_path(filspc, posix_path);
1345 fp = fopen(posix_path, "r");
1347 fp = fopen(filspc,"r");
1352 while (fgets(str, NINPUT, fp) != NULL)
1354 str[NINPUT+1] = '\0';
1363 fprintf(stderr, "?ASlink-Error-Opening library '%s'\n", filspc);