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 * The module lklibr.c contains the functions which
35 * (1) specify the path(s) to library files [.LIB]
36 * (2) specify the library file(s) [.LIB] to search
37 * (3) search the library files for specific symbols
38 * and link the module containing this symbol
40 * lklibr.c contains the following functions:
52 typedef struct slibrarysymbol mlibrarysymbol;
53 typedef struct slibrarysymbol *pmlibrarysymbol;
55 struct slibrarysymbol {
56 char * name; /*Warning: allocate memory before using*/
60 typedef struct slibraryfile mlibraryfile;
61 typedef struct slibraryfile *pmlibraryfile;
66 char * relfil; /*Warning: allocate memory before using*/
67 char * filename; /*Warning: allocate memory before using*/
68 long offset; //if > 0, the embedded file offset in the library file libspc
69 pmlibrarysymbol symbols;
73 /* First entry in the library object symbol cache */
74 pmlibraryfile libr=NULL;
76 int buildlibraryindex(void);
77 void freelibraryindex (void);
80 /*)Function VOID addpath()
82 * The function addpath() creates a linked structure containing
83 * the paths to various object module library files.
86 * lbpath *lbph pointer to new path structure
87 * lbpath *lbp temporary pointer
90 * lbpath *lbphead The pointer to the first
94 * char getnb() lklex.c
95 * VOID * new() lksym.c
96 * int strlen() c_library
97 * char * strcpy() c_library
98 * VOID unget() lklex.c
101 * An lbpath structure may be created.
107 struct lbpath *lbph, *lbp;
109 lbph = (struct lbpath *) new (sizeof(struct lbpath));
110 if (lbphead == NULL) {
121 lbph->path = (char *) new (strlen(ip)+1);
122 strcpy(lbph->path, ip);
125 /*)Function VOID addlib()
127 * The function addlib() tests for the existance of a
128 * library path structure to determine the method of
129 * adding this library file to the library search structure.
131 * This function calls the function addfile() to actually
132 * add the library file to the search list.
135 * lbpath *lbph pointer to path structure
138 * lbpath *lbphead The pointer to the first
140 * ip a pointer to the library name
143 * VOID addfile() lklibr.c
144 * char getnb() lklex.c
145 * VOID unget() lklex.c
148 * The function addfile() may add the file to
149 * the library search list.
162 foundcount=addfile(NULL, ip);
166 for (lbph=lbphead; lbph; lbph=lbph->next)
168 foundcount+=addfile(lbph->path, ip);
173 fprintf(stderr, "?ASlink-Warning-Couldn't find library '%s'\n", ip);
177 /*)Function int addfile(path,libfil)
179 * char *path library path specification
180 * char *libfil library file specification
182 * The function addfile() searches for the library file
183 * by concatenating the path and libfil specifications.
184 * if the library is found, an lbname structure is created
185 * and linked to any previously defined structures. This
186 * linked list is used by the function fndsym() to attempt
187 * to find any undefined symbols.
189 * The function does not give report an error on invalid
190 * path / file specifications or if the file is not found.
193 * lbname *lbnh pointer to new name structure
194 * lbname *lbn temporary pointer
197 * lbname *lbnhead The pointer to the first
201 * char getnb() lklex.c
202 * VOID * new() lksym.c
203 * int strlen() c_library
204 * char * strcpy() c_library
205 * VOID unget() lklex.c
208 * An lbname structure may be created.
211 * 1: the library was found
212 * 0: the library was not found
215 int addfile(char * path, char * libfil)
219 struct lbname *lbnh, *lbn;
226 str = (char *) new (strlen(path) + strlen(libfil) + 6);
229 if (strlen(str) && (str[strlen(str)-1] != '/') && (str[strlen(str)-1] != LKDIRSEP))
231 strcat(str, LKDIRSEPSTR);
237 str = (char *) new (strlen(libfil) + 5);
241 if ((libfil[0] == '/') || (libfil[0] == LKDIRSEP))
249 if(strchr(libfil, FSEPX) == NULL)
251 sprintf(&str[strlen(str)], "%clib", FSEPX);
257 /*Ok, that didn't work. Try with the 'libfil' name only*/
259 if(libfilinc) libfil--;
261 fp=fopen(libfil, "r");
264 /*Bingo! 'libfil' is the absolute path of the library*/
266 path=NULL;/*This way 'libfil' and 'path' will be rebuilt from 'str'*/
272 /*'path' can not be null since it is needed to find the object files associated with
273 the library. So, get 'path' from 'str' and then chop it off and recreate 'libfil'.
274 That way putting 'path' and 'libfil' together will result into the original filepath
275 as contained in 'str'.*/
277 path = (char *) new (strlen(str) + 1);
279 for(j=strlen(path)-1; j>=0; j--)
281 if((path[j] == '/') || (path[j] == LKDIRSEP))
283 strcpy(libfil, &path[j+1]);
294 lbnh = (struct lbname *) new (sizeof(struct lbname));
310 lbnh->libfil = (char *) new (strlen(libfil) + 1);
311 strcpy(lbnh->libfil, libfil);
322 /*)Function VOID search()
324 * The function search() looks through all the symbol tables
325 * at the end of pass 1. If any undefined symbols are found
326 * then the function fndsym() is called. Function fndsym()
327 * searches any specified library files to automagically
328 * import the object modules containing the needed symbol.
330 * After a symbol is found and imported by the function
331 * fndsym() the symbol tables are again searched. The
332 * symbol tables are search until no more symbols can be
333 * resolved within the library files. This ensures that
334 * back references from one library module to another are
338 * int i temporary counter
339 * sym *sp pointer to a symbol structure
340 * int symfnd found a symbol flag
343 * sym *symhash[] array of pointers to symbol tables
346 * int fndsym() lklibr.c
349 * If a symbol is found then the library object module
350 * containing the symbol will be imported and linked.
356 register struct sym *sp;
357 register int i, symfnd;
360 * Look for undefined symbols. Keep
361 * searching until no more symbols are resolved.
367 * Look through all the symbols
369 for (i=0; i<NHASH; ++i) {
372 /* If we find an undefined symbol
373 * (one where S_DEF is not set), then
374 * try looking for it. If we find it
375 * in any of the libraries then
376 * increment symfnd. This will force
377 * another pass of symbol searching and
378 * make sure that back references work.
380 if ((sp->s_type & S_DEF) == 0) {
381 if (fndsym(sp->s_id)) {
391 /*Load a .rel file embedded in a sdcclib file*/
392 void LoadRel(char * libfname, FILE * libfp, char * ModName)
398 while (fgets(str, NINPUT, libfp) != NULL)
400 str[NINPUT+1] = '\0';
405 if(EQ(str, "<FILE>"))
407 res = 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 /*Load an .adb file embedded in a sdcclib file. If there is
433 something between <ADB> and </ADB> returns 1, otherwise returns 0.
434 This way the aomf51 will not have useless empty modules. */
436 int LoadAdb(FILE * libfp)
442 while (fgets(str, MAXLINE, libfp) != NULL)
444 if (NINPUT < MAXLINE)
445 str[NINPUT+1] = '\0';
451 if(EQ(str, "<ADB>")) state=1;
454 if(EQ(str, "</ADB>")) return ToReturn;
455 fprintf(dfp, "%s\n", str);
463 /*Check for a symbol in a SDCC library. If found, add the embedded .rel and
464 .adb files from the library. The library must be created with the SDCC
465 librarian 'sdcclib' since the linking process depends on the correct file offsets
466 embedded in the library file.*/
468 int SdccLib(char * PathLib, FILE * libfp, char * DirLib, char * SymName)
470 struct lbfile *lbfh, *lbf;
471 char ModName[NCPS]="";
472 char FLine[MAXLINE+1];
474 long IndexOffset=0, FileOffset;
480 res = fgets(FLine, MAXLINE, libfp);
481 assert(res == FLine);
487 if(EQ(FLine, "<INDEX>"))
489 /*The next line has the size of the index*/
491 res = fgets(FLine, MAXLINE, libfp);
492 assert(res == FLine);
494 IndexOffset=atol(FLine);
499 if(EQ(FLine, "<MODULE>"))
501 /*The next line has the name of the module and the offset
502 of the corresponding embedded file in the library*/
504 res = fgets(FLine, MAXLINE, libfp);
505 assert(res == FLine);
507 sscanf(FLine, "%s %ld", ModName, &FileOffset);
510 else if(EQ(FLine, "</INDEX>"))
512 /*Reached the end of the index. The symbol is not in this library.*/
517 if(EQ(FLine, "</MODULE>"))
519 /*The symbol is not in this module, try the next one*/
524 /*Check if this is the symbol we are looking for.*/
525 if (strncmp(SymName, FLine, NCPS)==0)
527 /*The symbol is in this module.*/
529 /*As in the original library format, it is assumed that the .rel
530 files reside in the same directory as the lib files.*/
531 strcat(DirLib, ModName);
532 sprintf(&DirLib[strlen(DirLib)], "%c%s", FSEPX, LKOBJEXT);
534 /*If this module has been loaded already don't load it again.*/
538 if(EQ(DirLib, lbf->filspc)) return 1;/*Already loaded*/
542 /*Add the embedded file to the list of files to be loaded in
543 the second pass. That is performed latter by the function
545 lbfh = (struct lbfile *) new (sizeof(struct lbfile));
560 lbfh->libspc = PathLib;
561 lbfh->filspc = DirLib;
562 lbfh->relfil = (char *) new (strlen(ModName) + 1);
563 strcpy(lbfh->relfil, ModName);
564 /*Library embedded file, so lbfh->offset must be >=0*/
565 lbfh->offset = IndexOffset+FileOffset;
567 /*Jump to where the .rel begins and load it.*/
568 fseek(libfp, lbfh->offset, SEEK_SET);
569 LoadRel(PathLib, libfp, ModName);
571 /* if cdb information required & .adb file present */
575 SaveLinkedFilePath(DirLib);
577 return 1; /*Found the symbol, so success!*/
583 return 0; /*It should never reach this point, but just in case...*/
588 return 0; /*The symbol is not in this library*/
591 /*)Function VOID fndsym(name)
593 * char *name symbol name to find
595 * The function fndsym() searches through all combinations of the
596 * library path specifications (input by the -k option) and the
597 * library file specifications (input by the -l option) that
598 * lead to an existing file.
600 * The file specicifation may be formed in one of two ways:
602 * (1) If the library file contained an absolute
603 * path/file specification then this becomes filspc.
606 * (2) If the library file contains a relative path/file
607 * specification then the concatenation of the path
608 * and this file specification becomes filspc.
611 * The structure lbfile is created for the first library
612 * object file which contains the definition for the
613 * specified undefined symbol.
615 * If the library file [.LIB] contains file specifications for
616 * non existant files, no errors are returned.
619 * char buf[] [.REL] file input line
620 * char c [.REL] file input character
621 * FILE *fp file handle for object file
622 * lbfile *lbf temporary pointer
623 * lbfile *lbfh pointer to lbfile structure
624 * FILE *libfp file handle for library file
625 * lbname *lbnh pointer to lbname structure
626 * char *path file specification path
627 * char relfil[] [.REL] file specification
628 * char *str combined path and file specification
629 * char symname[] [.REL] file symbol string
632 * lbname *lbnhead The pointer to the first
634 * lbfile *lbfhead The pointer to the first
638 * int fclose() c_library
639 * int fgets() c_library
640 * FILE *fopen() c_library
641 * VOID free() c_library
642 * char getnb() lklex.c
643 * VOID lkexit() lkmain.c
644 * VOID loadfile() lklibr.c
645 * VOID * new() lksym.c
646 * char * sprintf() c_library
647 * int sscanf() c_library
648 * char * strcat() c_library
649 * char * strchr() c_library
650 * char * strcpy() c_library
651 * int strlen() c_library
652 * int strncmp() c_library
653 * VOID unget() lklex.c
656 * If the symbol is found then a new lbfile structure
657 * is created and added to the linked list of lbfile
658 * structures. The file containing the found symbol
664 int fndsym( char *name )
666 struct lbfile *lbfh, *lbf;
667 pmlibraryfile ThisLibr;
668 pmlibrarysymbol ThisSym = NULL;
670 pmlibraryfile FirstFound;
673 /* Build the index if this is the first call to fndsym */
674 if (libr==NULL) buildlibraryindex();
676 /* Iterate through all library object files */
678 FirstFound = libr; /*So gcc stops whining*/
681 /* Iterate through all symbols in an object file */
682 ThisSym = ThisLibr->symbols;
686 if (!strcmp(ThisSym->name, name))
688 if ((!ThisLibr->loaded) && (numfound==0))
690 /* Object file is not loaded - add it to the list */
691 lbfh = (struct lbfile *) new (sizeof(struct lbfile));
705 lbfh->libspc = ThisLibr->libspc;
706 lbfh->filspc = ThisLibr->filename;
707 lbfh->relfil = (char *) new (strlen(ThisLibr->relfil) + 1);
708 strcpy(lbfh->relfil, ThisLibr->relfil);
709 lbfh->offset = ThisLibr->offset;
711 { /*For an embedded object file in a library*/
712 void loadfile_SdccLib(char * libspc, char * module, long offset);
713 loadfile_SdccLib(lbfh->libspc, lbfh->relfil, lbfh->offset);
716 { /*For a stand alone object file*/
717 /* if cdb information required & adb file present */
720 FILE *xfp = afile(lbfh->filspc, "adb",0);
723 SaveLinkedFilePath(lbfh->filspc);
728 loadfile(lbfh->filspc);
740 char absPath1[PATH_MAX];
741 char absPath2[PATH_MAX];
742 #if defined(__BORLANDC__) || defined(_MSC_VER) || defined(__MINGW32__)
745 _fullpath(absPath1, FirstFound->libspc, PATH_MAX);
746 _fullpath(absPath2, ThisLibr->libspc, PATH_MAX);
747 for(j=0; absPath1[j]!=0; j++) absPath1[j]=tolower((unsigned char)absPath1[j]);
748 for(j=0; absPath2[j]!=0; j++) absPath2[j]=tolower((unsigned char)absPath2[j]);
751 res = realpath(FirstFound->libspc, absPath1);
752 assert(res == absPath1);
753 res = realpath(ThisLibr->libspc, absPath2);
754 assert(res == absPath2);
756 if( !( EQ(absPath1, absPath2) && EQ(FirstFound->relfil, ThisLibr->relfil) ) )
760 fprintf(stderr, "?ASlink-Warning-Definition of public symbol '%s'"
761 " found more than once:\n", name);
762 fprintf(stderr, " Library: '%s', Module: '%s'\n",
763 FirstFound->libspc, FirstFound->relfil);
765 fprintf(stderr, " Library: '%s', Module: '%s'\n",
766 ThisLibr->libspc, ThisLibr->relfil);
771 ThisSym=ThisSym->next; /* Next sym in library */
773 ThisLibr=ThisLibr->next; /* Next library in list */
778 pmlibraryfile buildlibraryindex_SdccLib(char * PathLib, FILE * libfp, char * DirLib, pmlibraryfile This)
780 char ModName[NCPS]="";
781 char FLine[MAXLINE+1];
784 long IndexOffset=0, FileOffset;
785 pmlibrarysymbol ThisSym = NULL;
791 res = fgets(FLine, MAXLINE, libfp);
792 assert(res == FLine);
798 if(EQ(FLine, "<INDEX>"))
800 /*The next line has the size of the index*/
802 res = fgets(FLine, MAXLINE, libfp);
803 assert(res == FLine);
805 IndexOffset=atol(FLine);
810 if(EQ(FLine, "<MODULE>"))
812 /*The next line has the name of the module and the offset
813 of the corresponding embedded file in the library*/
815 res = fgets(FLine, MAXLINE, libfp);
816 assert(res == FLine);
818 sscanf(FLine, "%s %ld", ModName, &FileOffset);
821 /*Create a new libraryfile object for this module*/
824 libr=This=(pmlibraryfile)new( sizeof( mlibraryfile ));
828 This->next=(pmlibraryfile)new( sizeof( mlibraryfile ));
833 This->offset=FileOffset+IndexOffset;
834 This->libspc=PathLib;
836 This->relfil=(char *)new(strlen(ModName)+1);
837 strcpy(This->relfil, ModName);
839 sprintf(buff, "%s%s%c%s", DirLib, ModName, FSEPX, LKOBJEXT);
840 This->filename=(char *)new(strlen(buff)+1);
841 strcpy(This->filename, buff);
843 This->symbols=ThisSym=NULL; /*Start a new linked list of symbols*/
845 else if(EQ(FLine, "</INDEX>"))
847 return This; /*Finish, get out of here*/
851 if(EQ(FLine, "</MODULE>"))
854 /*Create the index for the next module*/
860 if(ThisSym==NULL) /*First symbol of the current module*/
862 ThisSym=This->symbols=(pmlibrarysymbol)new(sizeof(mlibrarysymbol));
866 ThisSym->next = (pmlibrarysymbol)new(sizeof(mlibrarysymbol));
867 ThisSym=ThisSym->next;
870 ThisSym->name=(char *)new(strlen(FLine)+1);
871 strcpy(ThisSym->name, FLine);
876 return This; /*State machine should never reach this point, but just in case...*/
881 return This; /*State machine should never reach this point, but just in case...*/
885 /* buildlibraryindex - build an in-memory cache of the symbols contained in
888 int buildlibraryindex(void)
892 char relfil[NINPUT+2], str[PATH_MAX], *path;
893 char buf[NINPUT+2], c;
894 char symname[NINPUT+2];
895 pmlibraryfile This=NULL;
896 pmlibrarysymbol ThisSym;
899 * Search through every library in the linked list "lbnhead".
901 for (lbnh=lbnhead; lbnh; lbnh=lbnh->next)
903 if ((libfp = fopen(lbnh->libspc, "r")) == NULL)
905 fprintf(stderr, "?ASlink-Error-Cannot open library file %s\n",
912 * Read in a line from the library file.
913 * This is the relative file specification
914 * for a .REL file in this library.
917 while (fgets(relfil, NINPUT, libfp) != NULL)
919 relfil[NINPUT+1] = '\0';
925 if (strlen(str) && (str[strlen(str)-1] != '/') && (str[strlen(str)-1] != LKDIRSEP))
927 strcat(str, LKDIRSEPSTR);
936 if(strcmp(relfil, "<SDCCLIB>")==0)
938 /*Get the built in index of this library*/
939 This=buildlibraryindex_SdccLib(lbnh->libspc, libfp, str, This);
940 break; /*get the index for next library*/
943 /*From here down, build the index for the original library format*/
945 if ((relfil[0] == '/') || (relfil[0] == LKDIRSEP))
947 strcat(str, relfil+1);
954 if(strchr(relfil, FSEPX) == NULL)
956 sprintf(&str[strlen(str)], "%c%s", FSEPX, LKOBJEXT);
959 if ((fp = fopen(str, "r")) != NULL)
961 /* Opened OK - create a new libraryfile object for it */
964 libr=This=(pmlibraryfile)new( sizeof( mlibraryfile ));
968 This->next=(pmlibraryfile)new( sizeof( mlibraryfile ));
973 This->offset=-1; /*We have a stand alone .rel file*/
974 This->libspc = lbnh->libspc;
976 This->relfil=(char *)new(strlen(relfil)+1);
977 strcpy(This->relfil, relfil);
979 This->filename=(char *)new(strlen(str)+1);
980 strcpy(This->filename, str);
982 /*Start a new linked list of symbols for this module:*/
983 This->symbols = ThisSym = NULL;
986 * Read in the object file. Look for lines that
987 * begin with "S" and end with "D". These are
988 * symbol table definitions. If we find one, see
989 * if it is our symbol. Make sure we only read in
990 * our object file and don't go into the next one.
993 while (fgets(buf, NINPUT, fp) != NULL)
995 buf[NINPUT+1] = '\0';
996 buf[strlen(buf) - 1] = '\0';
999 * Skip everything that's not a symbol record.
1001 if (buf[0] != 'S') continue;
1004 * When a 'T line' is found terminate file scan.
1005 * All 'S line's preceed 'T line's in .REL files.
1007 if (buf[0] == 'T') break;
1009 sscanf(buf, "S %s %c", symname, &c);
1011 /* If it's an actual symbol, record it */
1016 ThisSym=This->symbols=(pmlibrarysymbol)new(sizeof(mlibrarysymbol));
1020 ThisSym->next=(pmlibrarysymbol)new(sizeof(mlibrarysymbol));
1021 ThisSym=ThisSym->next;
1025 ThisSym->name=(char *)new(strlen(symname)+1);
1026 strcpy(ThisSym->name, symname);
1028 } /* Closes while - read object file */
1030 } /* Closes if object file opened OK */
1033 fprintf(stderr, "?ASlink-Warning-Cannot open library module %s\n", str);
1035 } /* Ends while - processing all in libr */
1037 } /* Ends good open of libr file */
1041 /*Release all memory allocated for the in-memory library index*/
1042 void freelibraryindex (void)
1044 pmlibraryfile ThisLibr, ThisLibr2Free;
1045 pmlibrarysymbol ThisSym, ThisSym2Free;
1051 ThisSym = ThisLibr->symbols;
1055 free(ThisSym->name);
1056 ThisSym2Free=ThisSym;
1057 ThisSym=ThisSym->next;
1060 free(ThisLibr->filename);
1061 free(ThisLibr->relfil);
1062 ThisLibr2Free=ThisLibr;
1063 ThisLibr=ThisLibr->next;
1064 free(ThisLibr2Free);
1070 #else /* INDEXLIB */
1076 struct lbname *lbnh;
1077 struct lbfile *lbfh, *lbf;
1078 char relfil[NINPUT+2];
1080 char symname[NINPUT];
1086 * Search through every library in the linked list "lbnhead".
1089 for (lbnh=lbnhead; lbnh; lbnh=lbnh->next)
1091 if ((libfp = fopen(lbnh->libspc, "r")) == NULL)
1093 fprintf(stderr, "?ASlink-Error-Cannot open library file %s\n",
1100 * Read in a line from the library file.
1101 * This is the relative file specification
1102 * for a .REL file in this library.
1105 while (fgets(relfil, NINPUT, libfp) != NULL)
1107 relfil[NINPUT+1] = '\0';
1111 str = (char *) new (strlen(path)+strlen(relfil)+6);
1114 if (strlen(str) && (str[strlen(str)-1] != '/') && (str[strlen(str)-1] != LKDIRSEP))
1116 strcat(str, LKDIRSEPSTR);
1122 str = (char *) new (strlen(relfil) + 5);
1125 /*See if this is a library with embedded files*/
1126 if(strcmp(relfil, "<SDCCLIB>")==0)
1128 result=SdccLib(lbnh->libspc, libfp, str, name);
1129 if(result) return(1); /*Found the symbol*/
1131 /*The symbol is not in the current library,
1132 check the next library in the list*/
1136 /*From here down is the support for libraries in the original format*/
1137 if ((relfil[0] == '/') || (relfil[0] == LKDIRSEP))
1139 strcat(str, relfil+1);
1143 strcat(str, relfil);
1146 if(strchr(relfil, FSEPX) == NULL)
1148 sprintf(&str[strlen(str)], "%c%s", FSEPX, LKOBJEXT);
1151 if ((fp = fopen(str, "r")) != NULL)
1154 * Read in the object file. Look for lines that
1155 * begin with "S" and end with "D". These are
1156 * symbol table definitions. If we find one, see
1157 * if it is our symbol. Make sure we only read in
1158 * our object file and don't go into the next one.
1161 while (fgets(buf, NINPUT, fp) != NULL)
1163 buf[NINPUT+1] = '\0';
1166 * Skip everything that's not a symbol record.
1172 * When a 'T line' is found terminate file scan.
1173 * All 'S line's preceed 'T line's in .REL files.
1178 sscanf(buf, "S %s %c", symname, &c);
1181 * If we find a symbol definition for the
1182 * symbol we're looking for, load in the
1183 * file and add it to lbfhead so it gets
1184 * loaded on pass number 2.
1186 if (strncmp(symname, name, NCPS) == 0 && c == 'D')
1188 lbfh = (struct lbfile *) new (sizeof(struct lbfile));
1189 if (lbfhead == NULL)
1203 lbfh->libspc = lbnh->libspc;
1205 lbfh->relfil = (char *) new (strlen(relfil) + 1);
1206 lbfh->offset = -1; /*Stand alone rel file*/
1207 strcpy(lbfh->relfil,relfil);
1211 /* if cdb information required & adb file present */
1214 FILE *xfp = afile(str,"adb",0); //JCF: Nov 30, 2002
1217 SaveLinkedFilePath(str);
1225 } /* Closes while - read object file */
1227 } /* Closes if object file opened OK */
1230 fprintf(stderr, "?ASlink-Warning-Cannot open library module %s\n", str);
1233 } /* Ends while - processing all in libr */
1235 } /* Ends good open of libr file */
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.
1334 loadfile(char *filspc)
1340 char posix_path[PATH_MAX];
1341 void cygwin_conv_to_full_posix_path(char * win_path, char * posix_path);
1342 cygwin_conv_to_full_posix_path(filspc, posix_path);
1343 fp = fopen(posix_path, "r");
1345 fp = fopen(filspc,"r");
1350 while (fgets(str, NINPUT, fp) != NULL)
1352 str[NINPUT+1] = '\0';
1361 fprintf(stderr, "?ASlink-Error-Opening library '%s'\n", filspc);