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*/
33 * The module lklibr.c contains the functions which
34 * (1) specify the path(s) to library files [.LIB]
35 * (2) specify the library file(s) [.LIB] to search
36 * (3) search the library files for specific symbols
37 * and link the module containing this symbol
39 * lklibr.c contains the following functions:
51 typedef struct slibrarysymbol mlibrarysymbol;
52 typedef struct slibrarysymbol *pmlibrarysymbol;
54 struct slibrarysymbol {
55 char * name; /*Warning: allocate memory before using*/
59 typedef struct slibraryfile mlibraryfile;
60 typedef struct slibraryfile *pmlibraryfile;
65 char * relfil; /*Warning: allocate memory before using*/
66 char * filename; /*Warning: allocate memory before using*/
67 long offset; //if > 0, the embedded file offset in the library file libspc
68 pmlibrarysymbol symbols;
72 /* First entry in the library object symbol cache */
73 pmlibraryfile libr=NULL;
75 int buildlibraryindex(void);
76 void freelibraryindex (void);
79 /*)Function VOID addpath()
81 * The function addpath() creates a linked structure containing
82 * the paths to various object module library files.
85 * lbpath *lbph pointer to new path structure
86 * lbpath *lbp temporary pointer
89 * lbpath *lbphead The pointer to the first
93 * char getnb() lklex.c
94 * VOID * new() lksym.c
95 * int strlen() c_library
96 * char * strcpy() c_library
97 * VOID unget() lklex.c
100 * An lbpath structure may be created.
106 struct lbpath *lbph, *lbp;
108 lbph = (struct lbpath *) new (sizeof(struct lbpath));
109 if (lbphead == NULL) {
120 lbph->path = (char *) new (strlen(ip)+1);
121 strcpy(lbph->path, ip);
124 /*)Function VOID addlib()
126 * The function addlib() tests for the existance of a
127 * library path structure to determine the method of
128 * adding this library file to the library search structure.
130 * This function calls the function addfile() to actually
131 * add the library file to the search list.
134 * lbpath *lbph pointer to path structure
137 * lbpath *lbphead The pointer to the first
139 * ip a pointer to the library name
142 * VOID addfile() lklibr.c
143 * char getnb() lklex.c
144 * VOID unget() lklex.c
147 * The function addfile() may add the file to
148 * the library search list.
161 foundcount=addfile(NULL, ip);
165 for (lbph=lbphead; lbph; lbph=lbph->next)
167 foundcount+=addfile(lbph->path, ip);
172 fprintf(stderr, "?ASlink-Warning-Couldn't find library '%s'\n", ip);
176 /*)Function int addfile(path,libfil)
178 * char *path library path specification
179 * char *libfil library file specification
181 * The function addfile() searches for the library file
182 * by concatenating the path and libfil specifications.
183 * if the library is found, an lbname structure is created
184 * and linked to any previously defined structures. This
185 * linked list is used by the function fndsym() to attempt
186 * to find any undefined symbols.
188 * The function does not give report an error on invalid
189 * path / file specifications or if the file is not found.
192 * lbname *lbnh pointer to new name structure
193 * lbname *lbn temporary pointer
196 * lbname *lbnhead The pointer to the first
200 * char getnb() lklex.c
201 * VOID * new() lksym.c
202 * int strlen() c_library
203 * char * strcpy() c_library
204 * VOID unget() lklex.c
207 * An lbname structure may be created.
210 * 1: the library was found
211 * 0: the library was not found
214 int addfile(char * path, char * libfil)
218 struct lbname *lbnh, *lbn;
225 str = (char *) new (strlen(path) + strlen(libfil) + 6);
228 if (strlen(str) && (str[strlen(str)-1] != '/') && (str[strlen(str)-1] != LKDIRSEP))
230 strcat(str, LKDIRSEPSTR);
236 str = (char *) new (strlen(libfil) + 5);
240 if ((libfil[0] == '/') || (libfil[0] == LKDIRSEP))
248 if(strchr(libfil, FSEPX) == NULL)
250 sprintf(&str[strlen(str)], "%clib", FSEPX);
256 /*Ok, that didn't work. Try with the 'libfil' name only*/
258 if(libfilinc) libfil--;
260 fp=fopen(libfil, "r");
263 /*Bingo! 'libfil' is the absolute path of the library*/
265 path=NULL;/*This way 'libfil' and 'path' will be rebuilt from 'str'*/
271 /*'path' can not be null since it is needed to find the object files associated with
272 the library. So, get 'path' from 'str' and then chop it off and recreate 'libfil'.
273 That way putting 'path' and 'libfil' together will result into the original filepath
274 as contained in 'str'.*/
276 path = (char *) new (strlen(str) + 1);
278 for(j=strlen(path)-1; j>=0; j--)
280 if((path[j] == '/') || (path[j] == LKDIRSEP))
282 strcpy(libfil, &path[j+1]);
293 lbnh = (struct lbname *) new (sizeof(struct lbname));
309 lbnh->libfil = (char *) new (strlen(libfil) + 1);
310 strcpy(lbnh->libfil, libfil);
321 /*)Function VOID search()
323 * The function search() looks through all the symbol tables
324 * at the end of pass 1. If any undefined symbols are found
325 * then the function fndsym() is called. Function fndsym()
326 * searches any specified library files to automagically
327 * import the object modules containing the needed symbol.
329 * After a symbol is found and imported by the function
330 * fndsym() the symbol tables are again searched. The
331 * symbol tables are search until no more symbols can be
332 * resolved within the library files. This ensures that
333 * back references from one library module to another are
337 * int i temporary counter
338 * sym *sp pointer to a symbol structure
339 * int symfnd found a symbol flag
342 * sym *symhash[] array of pointers to symbol tables
345 * int fndsym() lklibr.c
348 * If a symbol is found then the library object module
349 * containing the symbol will be imported and linked.
355 register struct sym *sp;
356 register int i, symfnd;
359 * Look for undefined symbols. Keep
360 * searching until no more symbols are resolved.
366 * Look through all the symbols
368 for (i=0; i<NHASH; ++i) {
371 /* If we find an undefined symbol
372 * (one where S_DEF is not set), then
373 * try looking for it. If we find it
374 * in any of the libraries then
375 * increment symfnd. This will force
376 * another pass of symbol searching and
377 * make sure that back references work.
379 if ((sp->s_type & S_DEF) == 0) {
380 if (fndsym(sp->s_id)) {
390 /*Load a .rel file embedded in a sdcclib file*/
391 void LoadRel(char * libfname, FILE * libfp, char * ModName)
396 while (fgets(str, NINPUT, libfp) != NULL)
398 str[NINPUT+1] = '\0';
403 if(EQ(str, "<FILE>"))
405 fgets(str, NINPUT, libfp);
406 str[NINPUT+1] = '\0';
408 if(EQ(str, ModName)) state=1;
411 fprintf(stderr, "?ASlink-Error-Bad offset in library file %s(%s)\n",
418 if(EQ(str, "<REL>")) state=2;
421 if(EQ(str, "</REL>")) return;
429 /*Load an .adb file embedded in a sdcclib file. If there is
430 something between <ADB> and </ADB> returns 1, otherwise returns 0.
431 This way the aomf51 will not have useless empty modules. */
433 int LoadAdb(FILE * libfp)
439 while (fgets(str, MAXLINE, libfp) != NULL)
441 str[NINPUT+1] = '\0';
446 if(EQ(str, "<ADB>")) state=1;
449 if(EQ(str, "</ADB>")) return ToReturn;
450 fprintf(dfp, "%s\n", str);
458 /*Check for a symbol in a SDCC library. If found, add the embedded .rel and
459 .adb files from the library. The library must be created with the SDCC
460 librarian 'sdcclib' since the linking process depends on the correct file offsets
461 embedded in the library file.*/
463 int SdccLib(char * PathLib, FILE * libfp, char * DirLib, char * SymName)
465 struct lbfile *lbfh, *lbf;
466 char ModName[NCPS]="";
467 char FLine[MAXLINE+1];
469 long IndexOffset=0, FileOffset;
474 fgets(FLine, MAXLINE, libfp);
480 if(EQ(FLine, "<INDEX>"))
482 /*The next line has the size of the index*/
484 fgets(FLine, MAXLINE, libfp);
486 IndexOffset=atol(FLine);
491 if(EQ(FLine, "<MODULE>"))
493 /*The next line has the name of the module and the offset
494 of the corresponding embedded file in the library*/
496 fgets(FLine, MAXLINE, libfp);
498 sscanf(FLine, "%s %ld", ModName, &FileOffset);
501 else if(EQ(FLine, "</INDEX>"))
503 /*Reached the end of the index. The symbol is not in this library.*/
508 if(EQ(FLine, "</MODULE>"))
510 /*The symbol is not in this module, try the next one*/
515 /*Check if this is the symbol we are looking for.*/
516 if (strncmp(SymName, FLine, NCPS)==0)
518 /*The symbol is in this module.*/
520 /*As in the original library format, it is assumed that the .rel
521 files reside in the same directory as the lib files.*/
522 strcat(DirLib, ModName);
523 sprintf(&DirLib[strlen(DirLib)], "%c%s", FSEPX, LKOBJEXT);
525 /*If this module has been loaded already don't load it again.*/
529 if(EQ(DirLib, lbf->filspc)) return 1;/*Already loaded*/
533 /*Add the embedded file to the list of files to be loaded in
534 the second pass. That is performed latter by the function
536 lbfh = (struct lbfile *) new (sizeof(struct lbfile));
551 lbfh->libspc = PathLib;
552 lbfh->filspc = DirLib;
553 lbfh->relfil = (char *) new (strlen(ModName) + 1);
554 strcpy(lbfh->relfil, ModName);
555 /*Library embedded file, so lbfh->offset must be >=0*/
556 lbfh->offset = IndexOffset+FileOffset;
558 /*Jump to where the .rel begins and load it.*/
559 fseek(libfp, lbfh->offset, SEEK_SET);
560 LoadRel(PathLib, libfp, ModName);
562 return 1; /*Found the symbol, so success!*/
568 return 0; /*It should never reach this point, but just in case...*/
573 return 0; /*The symbol is not in this library*/
576 /*)Function VOID fndsym(name)
578 * char *name symbol name to find
580 * The function fndsym() searches through all combinations of the
581 * library path specifications (input by the -k option) and the
582 * library file specifications (input by the -l option) that
583 * lead to an existing file.
585 * The file specicifation may be formed in one of two ways:
587 * (1) If the library file contained an absolute
588 * path/file specification then this becomes filspc.
591 * (2) If the library file contains a relative path/file
592 * specification then the concatenation of the path
593 * and this file specification becomes filspc.
596 * The structure lbfile is created for the first library
597 * object file which contains the definition for the
598 * specified undefined symbol.
600 * If the library file [.LIB] contains file specifications for
601 * non existant files, no errors are returned.
604 * char buf[] [.REL] file input line
605 * char c [.REL] file input character
606 * FILE *fp file handle for object file
607 * lbfile *lbf temporary pointer
608 * lbfile *lbfh pointer to lbfile structure
609 * FILE *libfp file handle for library file
610 * lbname *lbnh pointer to lbname structure
611 * char *path file specification path
612 * char relfil[] [.REL] file specification
613 * char *str combined path and file specification
614 * char symname[] [.REL] file symbol string
617 * lbname *lbnhead The pointer to the first
619 * lbfile *lbfhead The pointer to the first
623 * int fclose() c_library
624 * int fgets() c_library
625 * FILE *fopen() c_library
626 * VOID free() c_library
627 * char getnb() lklex.c
628 * VOID lkexit() lkmain.c
629 * VOID loadfile() lklibr.c
630 * VOID * new() lksym.c
631 * char * sprintf() c_library
632 * int sscanf() c_library
633 * char * strcat() c_library
634 * char * strchr() c_library
635 * char * strcpy() c_library
636 * int strlen() c_library
637 * int strncmp() c_library
638 * VOID unget() lklex.c
641 * If the symbol is found then a new lbfile structure
642 * is created and added to the linked list of lbfile
643 * structures. The file containing the found symbol
649 int fndsym( char *name )
651 struct lbfile *lbfh, *lbf;
652 pmlibraryfile ThisLibr;
653 pmlibrarysymbol ThisSym = NULL;
655 pmlibraryfile FirstFound;
658 /* Build the index if this is the first call to fndsym */
659 if (libr==NULL) buildlibraryindex();
661 /* Iterate through all library object files */
663 FirstFound = libr; /*So gcc stops whining*/
666 /* Iterate through all symbols in an object file */
667 ThisSym = ThisLibr->symbols;
671 if (!strcmp(ThisSym->name, name))
673 if ((!ThisLibr->loaded) && (numfound==0))
675 /* Object file is not loaded - add it to the list */
676 lbfh = (struct lbfile *) new (sizeof(struct lbfile));
690 lbfh->libspc = ThisLibr->libspc;
691 lbfh->filspc = ThisLibr->filename;
692 lbfh->relfil = (char *) new (strlen(ThisLibr->relfil) + 1);
693 strcpy(lbfh->relfil, ThisLibr->relfil);
694 lbfh->offset = ThisLibr->offset;
696 { /*For an embedded object file in a library*/
697 void loadfile_SdccLib(char * libspc, char * module, long offset);
698 loadfile_SdccLib(lbfh->libspc, lbfh->relfil, lbfh->offset);
701 { /*For a stand alone object file*/
702 loadfile(lbfh->filspc);
714 char absPath1[PATH_MAX];
715 char absPath2[PATH_MAX];
716 #if defined(__BORLANDC__) || defined(_MSC_VER) || defined(__MINGW32__)
719 _fullpath(absPath1, FirstFound->libspc, PATH_MAX);
720 _fullpath(absPath2, ThisLibr->libspc, PATH_MAX);
721 for(j=0; absPath1[j]!=0; j++) absPath1[j]=tolower((unsigned char)absPath1[j]);
722 for(j=0; absPath2[j]!=0; j++) absPath2[j]=tolower((unsigned char)absPath2[j]);
724 realpath(FirstFound->libspc, absPath1);
725 realpath(ThisLibr->libspc, absPath2);
727 if( !( EQ(absPath1, absPath2) && EQ(FirstFound->relfil, ThisLibr->relfil) ) )
731 fprintf(stderr, "?ASlink-Warning-Definition of public symbol '%s'"
732 " found more than once:\n", name);
733 fprintf(stderr, " Library: '%s', Module: '%s'\n",
734 FirstFound->libspc, FirstFound->relfil);
736 fprintf(stderr, " Library: '%s', Module: '%s'\n",
737 ThisLibr->libspc, ThisLibr->relfil);
742 ThisSym=ThisSym->next; /* Next sym in library */
744 ThisLibr=ThisLibr->next; /* Next library in list */
749 pmlibraryfile buildlibraryindex_SdccLib(char * PathLib, FILE * libfp, char * DirLib, pmlibraryfile This)
751 char ModName[NCPS]="";
752 char FLine[MAXLINE+1];
755 long IndexOffset=0, FileOffset;
756 pmlibrarysymbol ThisSym = NULL;
761 fgets(FLine, MAXLINE, libfp);
767 if(EQ(FLine, "<INDEX>"))
769 /*The next line has the size of the index*/
771 fgets(FLine, MAXLINE, libfp);
773 IndexOffset=atol(FLine);
778 if(EQ(FLine, "<MODULE>"))
780 /*The next line has the name of the module and the offset
781 of the corresponding embedded file in the library*/
783 fgets(FLine, MAXLINE, libfp);
785 sscanf(FLine, "%s %ld", ModName, &FileOffset);
788 /*Create a new libraryfile object for this module*/
791 libr=This=(pmlibraryfile)new( sizeof( mlibraryfile ));
795 This->next=(pmlibraryfile)new( sizeof( mlibraryfile ));
800 This->offset=FileOffset+IndexOffset;
801 This->libspc=PathLib;
803 This->relfil=(char *)new(strlen(ModName)+1);
804 strcpy(This->relfil, ModName);
806 sprintf(buff, "%s%s%c%s", DirLib, ModName, FSEPX, LKOBJEXT);
807 This->filename=(char *)new(strlen(buff)+1);
808 strcpy(This->filename, buff);
810 This->symbols=ThisSym=NULL; /*Start a new linked list of symbols*/
812 else if(EQ(FLine, "</INDEX>"))
814 return This; /*Finish, get out of here*/
818 if(EQ(FLine, "</MODULE>"))
821 /*Create the index for the next module*/
827 if(ThisSym==NULL) /*First symbol of the current module*/
829 ThisSym=This->symbols=(pmlibrarysymbol)new(sizeof(mlibrarysymbol));
833 ThisSym->next = (pmlibrarysymbol)new(sizeof(mlibrarysymbol));
834 ThisSym=ThisSym->next;
837 ThisSym->name=(char *)new(strlen(FLine)+1);
838 strcpy(ThisSym->name, FLine);
843 return This; /*State machine should never reach this point, but just in case...*/
848 return This; /*State machine should never reach this point, but just in case...*/
852 /* buildlibraryindex - build an in-memory cache of the symbols contained in
855 int buildlibraryindex(void)
859 char relfil[NINPUT+2], str[PATH_MAX], *path;
860 char buf[NINPUT+2], c;
861 char symname[NINPUT+2];
862 pmlibraryfile This=NULL;
863 pmlibrarysymbol ThisSym;
866 * Search through every library in the linked list "lbnhead".
868 for (lbnh=lbnhead; lbnh; lbnh=lbnh->next)
870 if ((libfp = fopen(lbnh->libspc, "r")) == NULL)
872 fprintf(stderr, "?ASlink-Error-Cannot open library file %s\n",
879 * Read in a line from the library file.
880 * This is the relative file specification
881 * for a .REL file in this library.
884 while (fgets(relfil, NINPUT, libfp) != NULL)
886 relfil[NINPUT+1] = '\0';
892 if (strlen(str) && (str[strlen(str)-1] != '/') && (str[strlen(str)-1] != LKDIRSEP))
894 strcat(str, LKDIRSEPSTR);
903 if(strcmp(relfil, "<SDCCLIB>")==0)
905 /*Get the built in index of this library*/
906 This=buildlibraryindex_SdccLib(lbnh->libspc, libfp, str, This);
907 break; /*get the index for next library*/
910 /*From here down, build the index for the original library format*/
912 if ((relfil[0] == '/') || (relfil[0] == LKDIRSEP))
914 strcat(str, relfil+1);
921 if(strchr(relfil, FSEPX) == NULL)
923 sprintf(&str[strlen(str)], "%c%s", FSEPX, LKOBJEXT);
926 if ((fp = fopen(str, "r")) != NULL)
928 /* Opened OK - create a new libraryfile object for it */
931 libr=This=(pmlibraryfile)new( sizeof( mlibraryfile ));
935 This->next=(pmlibraryfile)new( sizeof( mlibraryfile ));
940 This->offset=-1; /*There should be a rel file*/
941 This->libspc = lbnh->libspc;
943 This->relfil=(char *)new(strlen(relfil)+1);
944 strcpy(This->relfil, relfil);
946 This->filename=(char *)new(strlen(str)+1);
947 strcpy(This->filename, str);
949 /*Start a new linked list of symbols for this module:*/
950 This->symbols = ThisSym = NULL;
953 * Read in the object file. Look for lines that
954 * begin with "S" and end with "D". These are
955 * symbol table definitions. If we find one, see
956 * if it is our symbol. Make sure we only read in
957 * our object file and don't go into the next one.
960 while (fgets(buf, NINPUT, fp) != NULL)
962 buf[NINPUT+1] = '\0';
963 buf[strlen(buf) - 1] = '\0';
966 * Skip everything that's not a symbol record.
968 if (buf[0] != 'S') continue;
971 * When a 'T line' is found terminate file scan.
972 * All 'S line's preceed 'T line's in .REL files.
974 if (buf[0] == 'T') break;
976 sscanf(buf, "S %s %c", symname, &c);
978 /* If it's an actual symbol, record it */
983 ThisSym=This->symbols=(pmlibrarysymbol)new(sizeof(mlibrarysymbol));
987 ThisSym->next=(pmlibrarysymbol)new(sizeof(mlibrarysymbol));
988 ThisSym=ThisSym->next;
992 ThisSym->name=(char *)new(strlen(symname)+1);
993 strcpy(ThisSym->name, symname);
995 } /* Closes while - read object file */
997 } /* Closes if object file opened OK */
1000 fprintf(stderr, "?ASlink-Warning-Cannot open library module %s\n", str);
1002 } /* Ends while - processing all in libr */
1004 } /* Ends good open of libr file */
1008 /*Release all memory allocated for the in-memory library index*/
1009 void freelibraryindex (void)
1011 pmlibraryfile ThisLibr, ThisLibr2Free;
1012 pmlibrarysymbol ThisSym, ThisSym2Free;
1018 ThisSym = ThisLibr->symbols;
1022 free(ThisSym->name);
1023 ThisSym2Free=ThisSym;
1024 ThisSym=ThisSym->next;
1027 free(ThisLibr->filename);
1028 free(ThisLibr->relfil);
1029 ThisLibr2Free=ThisLibr;
1030 ThisLibr=ThisLibr->next;
1031 free(ThisLibr2Free);
1037 #else /* INDEXLIB */
1043 struct lbname *lbnh;
1044 struct lbfile *lbfh, *lbf;
1045 char relfil[NINPUT+2];
1047 char symname[NINPUT];
1053 * Search through every library in the linked list "lbnhead".
1056 for (lbnh=lbnhead; lbnh; lbnh=lbnh->next)
1058 if ((libfp = fopen(lbnh->libspc, "r")) == NULL)
1060 fprintf(stderr, "?ASlink-Error-Cannot open library file %s\n",
1067 * Read in a line from the library file.
1068 * This is the relative file specification
1069 * for a .REL file in this library.
1072 while (fgets(relfil, NINPUT, libfp) != NULL)
1074 relfil[NINPUT+1] = '\0';
1078 str = (char *) new (strlen(path)+strlen(relfil)+6);
1081 if (strlen(str) && (str[strlen(str)-1] != '/') && (str[strlen(str)-1] != LKDIRSEP))
1083 strcat(str, LKDIRSEPSTR);
1089 str = (char *) new (strlen(relfil) + 5);
1092 /*See if this is a library with embedded files*/
1093 if(strcmp(relfil, "<SDCCLIB>")==0)
1095 result=SdccLib(lbnh->libspc, libfp, str, name);
1096 if(result) return(1); /*Found the symbol*/
1098 /*The symbol is not in the current library,
1099 check the next library in the list*/
1103 /*From here down is the support for libraries in the original format*/
1104 if ((relfil[0] == '/') || (relfil[0] == LKDIRSEP))
1106 strcat(str, relfil+1);
1110 strcat(str, relfil);
1113 if(strchr(relfil, FSEPX) == NULL)
1115 sprintf(&str[strlen(str)], "%c%s", FSEPX, LKOBJEXT);
1118 if ((fp = fopen(str, "r")) != NULL)
1121 * Read in the object file. Look for lines that
1122 * begin with "S" and end with "D". These are
1123 * symbol table definitions. If we find one, see
1124 * if it is our symbol. Make sure we only read in
1125 * our object file and don't go into the next one.
1128 while (fgets(buf, NINPUT, fp) != NULL)
1130 buf[NINPUT+1] = '\0';
1133 * Skip everything that's not a symbol record.
1139 * When a 'T line' is found terminate file scan.
1140 * All 'S line's preceed 'T line's in .REL files.
1145 sscanf(buf, "S %s %c", symname, &c);
1148 * If we find a symbol definition for the
1149 * symbol we're looking for, load in the
1150 * file and add it to lbfhead so it gets
1151 * loaded on pass number 2.
1153 if (strncmp(symname, name, NCPS) == 0 && c == 'D')
1155 lbfh = (struct lbfile *) new (sizeof(struct lbfile));
1156 if (lbfhead == NULL)
1170 lbfh->libspc = lbnh->libspc;
1172 lbfh->relfil = (char *) new (strlen(relfil) + 1);
1173 lbfh->offset = -1; /*Stand alone rel file*/
1174 strcpy(lbfh->relfil,relfil);
1180 } /* Closes while - read object file */
1182 } /* Closes if object file opened OK */
1185 fprintf(stderr, "?ASlink-Warning-Cannot open library module %s\n", str);
1188 } /* Ends while - processing all in libr */
1190 } /* Ends good open of libr file */
1194 #endif /* INDEXLIB */
1196 void loadfile_SdccLib(char * libspc, char * module, long offset)
1201 char posix_path[PATH_MAX];
1202 void cygwin_conv_to_full_posix_path(char * win_path, char * posix_path);
1203 cygwin_conv_to_full_posix_path(libspc, posix_path);
1204 fp = fopen(posix_path, "r");
1206 fp = fopen(libspc,"r");
1211 fseek(fp, offset, SEEK_SET);
1212 LoadRel(libspc, fp, module);
1217 fprintf(stderr, "?ASlink-Error-Opening library '%s'\n", libspc);
1222 /*)Function VOID library()
1224 * The function library() links all the library object files
1225 * contained in the lbfile structures.
1228 * lbfile *lbfh pointer to lbfile structure
1231 * lbfile *lbfhead pointer to first lbfile structure
1234 * VOID loadfile lklibr.c
1237 * Links all files contained in the lbfile structures.
1243 struct lbfile *lbfh;
1245 for (lbfh=lbfhead; lbfh; lbfh=lbfh->next)
1249 /*Stand alone rel file (original lib format)*/
1250 loadfile(lbfh->filspc);
1254 /*rel file embedded in lib (new lib format)*/
1255 loadfile_SdccLib(lbfh->libspc, lbfh->relfil, lbfh->offset);
1263 /*)Function VOID loadfile(filspc)
1265 * char *filspc library object file specification
1267 * The function loadfile() links the library object module.
1270 * FILE *fp file handle
1271 * int i input line length
1272 * char str[] file input line
1275 * char *ip pointer to linker input string
1278 * int fclose() c_library
1279 * int fgets() c_library
1280 * FILE * fopen() c_library
1281 * VOID link_main() lkmain.c
1282 * int strlen() c_library
1285 * If file exists it is linked.
1289 loadfile(char *filspc)
1295 char posix_path[PATH_MAX];
1296 void cygwin_conv_to_full_posix_path(char * win_path, char * posix_path);
1297 cygwin_conv_to_full_posix_path(filspc, posix_path);
1298 fp = fopen(posix_path, "r");
1300 fp = fopen(filspc,"r");
1305 while (fgets(str, NINPUT, fp) != NULL)
1307 str[NINPUT+1] = '\0';
1316 fprintf(stderr, "?ASlink-Error-Opening library '%s'\n", filspc);