4 * (C) Copyright 1989-1995
11 * With contributions for the
12 * object libraries from
14 * kenh@cmf.nrl.navy.mil
18 #define EQ(A,B) !strcmp((A),(B))
19 #define MAXLINE 254 /*when using fgets*/
29 * The module lklibr.c contains the functions which
30 * (1) specify the path(s) to library files [.LIB]
31 * (2) specify the library file(s) [.LIB] to search
32 * (3) search the library files for specific symbols
33 * and link the module containing this symbol
35 * lklibr.c contains the following functions:
47 typedef struct slibrarysymbol mlibrarysymbol;
48 typedef struct slibrarysymbol *pmlibrarysymbol;
50 struct slibrarysymbol {
51 char * name; /*Warning: allocate memory before using*/
55 typedef struct slibraryfile mlibraryfile;
56 typedef struct slibraryfile *pmlibraryfile;
61 char * relfil; /*Warning: allocate memory before using*/
62 char * filename; /*Warning: allocate memory before using*/
63 long offset; //if > 0, the embedded file offset in the library file libspc
64 pmlibrarysymbol symbols;
68 /* First entry in the library object symbol cache */
69 pmlibraryfile libr=NULL;
71 int buildlibraryindex(void);
72 void freelibraryindex (void);
75 /*)Function VOID addpath()
77 * The function addpath() creates a linked structure containing
78 * the paths to various object module library files.
81 * lbpath *lbph pointer to new path structure
82 * lbpath *lbp temporary pointer
85 * lbpath *lbphead The pointer to the first
89 * char getnb() lklex.c
90 * VOID * new() lksym.c
91 * int strlen() c_library
92 * char * strcpy() c_library
93 * VOID unget() lklex.c
96 * An lbpath structure may be created.
102 struct lbpath *lbph, *lbp;
104 lbph = (struct lbpath *) new (sizeof(struct lbpath));
105 if (lbphead == NULL) {
116 lbph->path = (char *) new (strlen(ip)+1);
117 strcpy(lbph->path, ip);
120 /*)Function VOID addlib()
122 * The function addlib() tests for the existance of a
123 * library path structure to determine the method of
124 * adding this library file to the library search structure.
126 * This function calls the function addfile() to actually
127 * add the library file to the search list.
130 * lbpath *lbph pointer to path structure
133 * lbpath *lbphead The pointer to the first
135 * ip a pointer to the library name
138 * VOID addfile() lklibr.c
139 * char getnb() lklex.c
140 * VOID unget() lklex.c
143 * The function addfile() may add the file to
144 * the library search list.
157 foundcount=addfile(NULL, ip);
161 for (lbph=lbphead; lbph; lbph=lbph->next)
163 foundcount+=addfile(lbph->path, ip);
168 fprintf(stderr, "?ASlink-Warning-Couldn't find library '%s'\n", ip);
172 /*)Function int addfile(path,libfil)
174 * char *path library path specification
175 * char *libfil library file specification
177 * The function addfile() searches for the library file
178 * by concatenating the path and libfil specifications.
179 * if the library is found, an lbname structure is created
180 * and linked to any previously defined structures. This
181 * linked list is used by the function fndsym() to attempt
182 * to find any undefined symbols.
184 * The function does not give report an error on invalid
185 * path / file specifications or if the file is not found.
188 * lbname *lbnh pointer to new name structure
189 * lbname *lbn temporary pointer
192 * lbname *lbnhead The pointer to the first
196 * char getnb() lklex.c
197 * VOID * new() lksym.c
198 * int strlen() c_library
199 * char * strcpy() c_library
200 * VOID unget() lklex.c
203 * An lbname structure may be created.
206 * 1: the library was found
207 * 0: the library was not found
210 int addfile(char * path, char * libfil)
214 struct lbname *lbnh, *lbn;
221 str = (char *) new (strlen(path) + strlen(libfil) + 6);
224 if (strlen(str) && (str[strlen(str)-1] != '/') && (str[strlen(str)-1] != LKDIRSEP))
226 strcat(str, LKDIRSEPSTR);
232 str = (char *) new (strlen(libfil) + 5);
236 if ((libfil[0] == '/') || (libfil[0] == LKDIRSEP))
244 if(strchr(libfil, FSEPX) == NULL)
246 sprintf(&str[strlen(str)], "%clib", FSEPX);
252 /*Ok, that didn't work. Try with the 'libfil' name only*/
254 if(libfilinc) libfil--;
256 fp=fopen(libfil, "r");
259 /*Bingo! 'libfil' is the absolute path of the library*/
261 path=NULL;/*This way 'libfil' and 'path' will be rebuilt from 'str'*/
267 /*'path' can not be null since it is needed to find the object files associated with
268 the library. So, get 'path' from 'str' and then chop it off and recreate 'libfil'.
269 That way putting 'path' and 'libfil' together will result into the original filepath
270 as contained in 'str'.*/
272 path = (char *) new (strlen(str) + 1);
274 for(j=strlen(path)-1; j>=0; j--)
276 if((path[j] == '/') || (path[j] == LKDIRSEP))
278 strcpy(libfil, &path[j+1]);
289 lbnh = (struct lbname *) new (sizeof(struct lbname));
305 lbnh->libfil = (char *) new (strlen(libfil) + 1);
306 strcpy(lbnh->libfil, libfil);
317 /*)Function VOID search()
319 * The function search() looks through all the symbol tables
320 * at the end of pass 1. If any undefined symbols are found
321 * then the function fndsym() is called. Function fndsym()
322 * searches any specified library files to automagically
323 * import the object modules containing the needed symbol.
325 * After a symbol is found and imported by the function
326 * fndsym() the symbol tables are again searched. The
327 * symbol tables are search until no more symbols can be
328 * resolved within the library files. This ensures that
329 * back references from one library module to another are
333 * int i temporary counter
334 * sym *sp pointer to a symbol structure
335 * int symfnd found a symbol flag
338 * sym *symhash[] array of pointers to symbol tables
341 * int fndsym() lklibr.c
344 * If a symbol is found then the library object module
345 * containing the symbol will be imported and linked.
351 register struct sym *sp;
352 register int i, symfnd;
355 * Look for undefined symbols. Keep
356 * searching until no more symbols are resolved.
362 * Look through all the symbols
364 for (i=0; i<NHASH; ++i) {
367 /* If we find an undefined symbol
368 * (one where S_DEF is not set), then
369 * try looking for it. If we find it
370 * in any of the libraries then
371 * increment symfnd. This will force
372 * another pass of symbol searching and
373 * make sure that back references work.
375 if ((sp->s_type & S_DEF) == 0) {
376 if (fndsym(sp->s_id)) {
386 /*Load a .rel file embedded in a sdcclib file*/
387 void LoadRel(char * libfname, FILE * libfp, char * ModName)
392 while (fgets(str, NINPUT, libfp) != NULL)
394 str[NINPUT+1] = '\0';
399 if(EQ(str, "<FILE>"))
401 fgets(str, NINPUT, libfp);
402 str[NINPUT+1] = '\0';
404 if(EQ(str, ModName)) state=1;
407 fprintf(stderr, "?ASlink-Error-Bad offset in library file %s(%s)\n",
414 if(EQ(str, "<REL>")) state=2;
417 if(EQ(str, "</REL>")) return;
425 /*Load an .adb file embedded in a sdcclib file. If there is
426 something between <ADB> and </ADB> returns 1, otherwise returns 0.
427 This way the aomf51 will not have useless empty modules. */
429 int LoadAdb(FILE * libfp)
435 while (fgets(str, MAXLINE, libfp) != NULL)
437 str[NINPUT+1] = '\0';
442 if(EQ(str, "<ADB>")) state=1;
445 if(EQ(str, "</ADB>")) return ToReturn;
446 fprintf(dfp, "%s\n", str);
454 /*Check for a symbol in a SDCC library. If found, add the embedded .rel and
455 .adb files from the library. The library must be created with the SDCC
456 librarian 'sdcclib' since the linking process depends on the correct file offsets
457 embedded in the library file.*/
459 int SdccLib(char * PathLib, FILE * libfp, char * DirLib, char * SymName)
461 struct lbfile *lbfh, *lbf;
462 char ModName[NCPS]="";
463 char FLine[MAXLINE+1];
465 long IndexOffset=0, FileOffset;
470 fgets(FLine, MAXLINE, libfp);
476 if(EQ(FLine, "<INDEX>"))
478 /*The next line has the size of the index*/
480 fgets(FLine, MAXLINE, libfp);
482 IndexOffset=atol(FLine);
487 if(EQ(FLine, "<MODULE>"))
489 /*The next line has the name of the module and the offset
490 of the corresponding embedded file in the library*/
492 fgets(FLine, MAXLINE, libfp);
494 sscanf(FLine, "%s %ld", ModName, &FileOffset);
497 else if(EQ(FLine, "</INDEX>"))
499 /*Reached the end of the index. The symbol is not in this library.*/
504 if(EQ(FLine, "</MODULE>"))
506 /*The symbol is not in this module, try the next one*/
511 /*Check if this is the symbol we are looking for.*/
512 if (strncmp(SymName, FLine, NCPS)==0)
514 /*The symbol is in this module.*/
516 /*As in the original library format, it is assumed that the .rel
517 files reside in the same directory as the lib files.*/
518 strcat(DirLib, ModName);
519 sprintf(&DirLib[strlen(DirLib)], "%c%s", FSEPX, LKOBJEXT);
521 /*If this module has been loaded already don't load it again.*/
525 if(EQ(DirLib, lbf->filspc)) return 1;/*Already loaded*/
529 /*Add the embedded file to the list of files to be loaded in
530 the second pass. That is performed latter by the function
532 lbfh = (struct lbfile *) new (sizeof(struct lbfile));
547 lbfh->libspc = PathLib;
548 lbfh->filspc = DirLib;
549 lbfh->relfil = (char *) new (strlen(ModName) + 1);
550 strcpy(lbfh->relfil, ModName);
551 /*Library embedded file, so lbfh->offset must be >=0*/
552 lbfh->offset = IndexOffset+FileOffset;
554 /*Jump to where the .rel begins and load it.*/
555 fseek(libfp, lbfh->offset, SEEK_SET);
556 LoadRel(PathLib, libfp, ModName);
558 /* if cdb information required & .adb file present */
562 SaveLinkedFilePath(DirLib);
564 return 1; /*Found the symbol, so success!*/
570 return 0; /*It should never reach this point, but just in case...*/
575 return 0; /*The symbol is not in this library*/
578 /*)Function VOID fndsym(name)
580 * char *name symbol name to find
582 * The function fndsym() searches through all combinations of the
583 * library path specifications (input by the -k option) and the
584 * library file specifications (input by the -l option) that
585 * lead to an existing file.
587 * The file specicifation may be formed in one of two ways:
589 * (1) If the library file contained an absolute
590 * path/file specification then this becomes filspc.
593 * (2) If the library file contains a relative path/file
594 * specification then the concatenation of the path
595 * and this file specification becomes filspc.
598 * The structure lbfile is created for the first library
599 * object file which contains the definition for the
600 * specified undefined symbol.
602 * If the library file [.LIB] contains file specifications for
603 * non existant files, no errors are returned.
606 * char buf[] [.REL] file input line
607 * char c [.REL] file input character
608 * FILE *fp file handle for object file
609 * lbfile *lbf temporary pointer
610 * lbfile *lbfh pointer to lbfile structure
611 * FILE *libfp file handle for library file
612 * lbname *lbnh pointer to lbname structure
613 * char *path file specification path
614 * char relfil[] [.REL] file specification
615 * char *str combined path and file specification
616 * char symname[] [.REL] file symbol string
619 * lbname *lbnhead The pointer to the first
621 * lbfile *lbfhead The pointer to the first
625 * int fclose() c_library
626 * int fgets() c_library
627 * FILE *fopen() c_library
628 * VOID free() c_library
629 * char getnb() lklex.c
630 * VOID lkexit() lkmain.c
631 * VOID loadfile() lklibr.c
632 * VOID * new() lksym.c
633 * char * sprintf() c_library
634 * int sscanf() c_library
635 * char * strcat() c_library
636 * char * strchr() c_library
637 * char * strcpy() c_library
638 * int strlen() c_library
639 * int strncmp() c_library
640 * VOID unget() lklex.c
643 * If the symbol is found then a new lbfile structure
644 * is created and added to the linked list of lbfile
645 * structures. The file containing the found symbol
651 int fndsym( char *name )
653 struct lbfile *lbfh, *lbf;
654 pmlibraryfile ThisLibr;
655 pmlibrarysymbol ThisSym = NULL;
657 pmlibraryfile FirstFound;
660 /* Build the index if this is the first call to fndsym */
661 if (libr==NULL) buildlibraryindex();
663 /* Iterate through all library object files */
665 FirstFound = libr; /*So gcc stops whining*/
668 /* Iterate through all symbols in an object file */
669 ThisSym = ThisLibr->symbols;
673 if (!strcmp(ThisSym->name, name))
675 if ((!ThisLibr->loaded) && (numfound==0))
677 /* Object file is not loaded - add it to the list */
678 lbfh = (struct lbfile *) new (sizeof(struct lbfile));
692 lbfh->libspc = ThisLibr->libspc;
693 lbfh->filspc = ThisLibr->filename;
694 lbfh->relfil = (char *) new (strlen(ThisLibr->relfil) + 1);
695 strcpy(lbfh->relfil, ThisLibr->relfil);
696 lbfh->offset = ThisLibr->offset;
698 { /*For an embedded object file in a library*/
699 void loadfile_SdccLib(char * libspc, char * module, long offset);
700 loadfile_SdccLib(lbfh->libspc, lbfh->relfil, lbfh->offset);
703 { /*For a stand alone object file*/
704 /* if cdb information required & adb file present */
707 FILE *xfp = afile(lbfh->filspc, "adb",0);
710 SaveLinkedFilePath(lbfh->filspc);
715 loadfile(lbfh->filspc);
727 char absPath1[PATH_MAX];
728 char absPath2[PATH_MAX];
729 #if defined(__BORLANDC__) || defined(_MSC_VER) || defined(__MINGW32__)
732 _fullpath(absPath1, FirstFound->libspc, PATH_MAX);
733 _fullpath(absPath2, ThisLibr->libspc, PATH_MAX);
734 for(j=0; absPath1[j]!=0; j++) absPath1[j]=tolower((unsigned char)absPath1[j]);
735 for(j=0; absPath2[j]!=0; j++) absPath2[j]=tolower((unsigned char)absPath2[j]);
737 realpath(FirstFound->libspc, absPath1);
738 realpath(ThisLibr->libspc, absPath2);
740 if( !( EQ(absPath1, absPath2) && EQ(FirstFound->relfil, ThisLibr->relfil) ) )
744 fprintf(stderr, "?ASlink-Warning-Definition of public symbol '%s'"
745 " found more than once:\n", name);
746 fprintf(stderr, " Library: '%s', Module: '%s'\n",
747 FirstFound->libspc, FirstFound->relfil);
749 fprintf(stderr, " Library: '%s', Module: '%s'\n",
750 ThisLibr->libspc, ThisLibr->relfil);
755 ThisSym=ThisSym->next; /* Next sym in library */
757 ThisLibr=ThisLibr->next; /* Next library in list */
762 pmlibraryfile buildlibraryindex_SdccLib(char * PathLib, FILE * libfp, char * DirLib, pmlibraryfile This)
764 char ModName[NCPS]="";
765 char FLine[MAXLINE+1];
768 long IndexOffset=0, FileOffset;
769 pmlibrarysymbol ThisSym = NULL;
774 fgets(FLine, MAXLINE, libfp);
780 if(EQ(FLine, "<INDEX>"))
782 /*The next line has the size of the index*/
784 fgets(FLine, MAXLINE, libfp);
786 IndexOffset=atol(FLine);
791 if(EQ(FLine, "<MODULE>"))
793 /*The next line has the name of the module and the offset
794 of the corresponding embedded file in the library*/
796 fgets(FLine, MAXLINE, libfp);
798 sscanf(FLine, "%s %ld", ModName, &FileOffset);
801 /*Create a new libraryfile object for this module*/
804 libr=This=(pmlibraryfile)new( sizeof( mlibraryfile ));
808 This->next=(pmlibraryfile)new( sizeof( mlibraryfile ));
813 This->offset=FileOffset+IndexOffset;
814 This->libspc=PathLib;
816 This->relfil=(char *)new(strlen(ModName)+1);
817 strcpy(This->relfil, ModName);
819 sprintf(buff, "%s%s%c%s", DirLib, ModName, FSEPX, LKOBJEXT);
820 This->filename=(char *)new(strlen(buff)+1);
821 strcpy(This->filename, buff);
823 This->symbols=ThisSym=NULL; /*Start a new linked list of symbols*/
825 else if(EQ(FLine, "</INDEX>"))
827 return This; /*Finish, get out of here*/
831 if(EQ(FLine, "</MODULE>"))
834 /*Create the index for the next module*/
840 if(ThisSym==NULL) /*First symbol of the current module*/
842 ThisSym=This->symbols=(pmlibrarysymbol)new(sizeof(mlibrarysymbol));
846 ThisSym->next = (pmlibrarysymbol)new(sizeof(mlibrarysymbol));
847 ThisSym=ThisSym->next;
850 ThisSym->name=(char *)new(strlen(FLine)+1);
851 strcpy(ThisSym->name, FLine);
856 return This; /*State machine should never reach this point, but just in case...*/
861 return This; /*State machine should never reach this point, but just in case...*/
865 /* buildlibraryindex - build an in-memory cache of the symbols contained in
868 int buildlibraryindex(void)
872 char relfil[NINPUT+2], str[PATH_MAX], *path;
873 char buf[NINPUT+2], c;
874 char symname[NINPUT+2];
875 pmlibraryfile This=NULL;
876 pmlibrarysymbol ThisSym;
879 * Search through every library in the linked list "lbnhead".
881 for (lbnh=lbnhead; lbnh; lbnh=lbnh->next)
883 if ((libfp = fopen(lbnh->libspc, "r")) == NULL)
885 fprintf(stderr, "?ASlink-Error-Cannot open library file %s\n",
892 * Read in a line from the library file.
893 * This is the relative file specification
894 * for a .REL file in this library.
897 while (fgets(relfil, NINPUT, libfp) != NULL)
899 relfil[NINPUT+1] = '\0';
905 if (strlen(str) && (str[strlen(str)-1] != '/') && (str[strlen(str)-1] != LKDIRSEP))
907 strcat(str, LKDIRSEPSTR);
916 if(strcmp(relfil, "<SDCCLIB>")==0)
918 /*Get the built in index of this library*/
919 This=buildlibraryindex_SdccLib(lbnh->libspc, libfp, str, This);
920 break; /*get the index for next library*/
923 /*From here down, build the index for the original library format*/
925 if ((relfil[0] == '/') || (relfil[0] == LKDIRSEP))
927 strcat(str, relfil+1);
934 if(strchr(relfil, FSEPX) == NULL)
936 sprintf(&str[strlen(str)], "%c%s", FSEPX, LKOBJEXT);
939 if ((fp = fopen(str, "r")) != NULL)
941 /* Opened OK - create a new libraryfile object for it */
944 libr=This=(pmlibraryfile)new( sizeof( mlibraryfile ));
948 This->next=(pmlibraryfile)new( sizeof( mlibraryfile ));
953 This->offset=-1; /*We have a stand alone .rel file*/
954 This->libspc = lbnh->libspc;
956 This->relfil=(char *)new(strlen(relfil)+1);
957 strcpy(This->relfil, relfil);
959 This->filename=(char *)new(strlen(str)+1);
960 strcpy(This->filename, str);
962 /*Start a new linked list of symbols for this module:*/
963 This->symbols = ThisSym = NULL;
966 * Read in the object file. Look for lines that
967 * begin with "S" and end with "D". These are
968 * symbol table definitions. If we find one, see
969 * if it is our symbol. Make sure we only read in
970 * our object file and don't go into the next one.
973 while (fgets(buf, NINPUT, fp) != NULL)
975 buf[NINPUT+1] = '\0';
976 buf[strlen(buf) - 1] = '\0';
979 * Skip everything that's not a symbol record.
981 if (buf[0] != 'S') continue;
984 * When a 'T line' is found terminate file scan.
985 * All 'S line's preceed 'T line's in .REL files.
987 if (buf[0] == 'T') break;
989 sscanf(buf, "S %s %c", symname, &c);
991 /* If it's an actual symbol, record it */
996 ThisSym=This->symbols=(pmlibrarysymbol)new(sizeof(mlibrarysymbol));
1000 ThisSym->next=(pmlibrarysymbol)new(sizeof(mlibrarysymbol));
1001 ThisSym=ThisSym->next;
1005 ThisSym->name=(char *)new(strlen(symname)+1);
1006 strcpy(ThisSym->name, symname);
1008 } /* Closes while - read object file */
1010 } /* Closes if object file opened OK */
1013 fprintf(stderr, "?ASlink-Warning-Cannot open library module %s\n", str);
1015 } /* Ends while - processing all in libr */
1017 } /* Ends good open of libr file */
1021 /*Release all memory allocated for the in-memory library index*/
1022 void freelibraryindex (void)
1024 pmlibraryfile ThisLibr, ThisLibr2Free;
1025 pmlibrarysymbol ThisSym, ThisSym2Free;
1031 ThisSym = ThisLibr->symbols;
1035 free(ThisSym->name);
1036 ThisSym2Free=ThisSym;
1037 ThisSym=ThisSym->next;
1040 free(ThisLibr->filename);
1041 free(ThisLibr->relfil);
1042 ThisLibr2Free=ThisLibr;
1043 ThisLibr=ThisLibr->next;
1044 free(ThisLibr2Free);
1050 #else /* INDEXLIB */
1056 struct lbname *lbnh;
1057 struct lbfile *lbfh, *lbf;
1058 char relfil[NINPUT+2];
1060 char symname[NINPUT];
1066 * Search through every library in the linked list "lbnhead".
1069 for (lbnh=lbnhead; lbnh; lbnh=lbnh->next)
1071 if ((libfp = fopen(lbnh->libspc, "r")) == NULL)
1073 fprintf(stderr, "?ASlink-Error-Cannot open library file %s\n",
1080 * Read in a line from the library file.
1081 * This is the relative file specification
1082 * for a .REL file in this library.
1085 while (fgets(relfil, NINPUT, libfp) != NULL)
1087 relfil[NINPUT+1] = '\0';
1091 str = (char *) new (strlen(path)+strlen(relfil)+6);
1094 if (strlen(str) && (str[strlen(str)-1] != '/') && (str[strlen(str)-1] != LKDIRSEP))
1096 strcat(str, LKDIRSEPSTR);
1102 str = (char *) new (strlen(relfil) + 5);
1105 /*See if this is a library with embedded files*/
1106 if(strcmp(relfil, "<SDCCLIB>")==0)
1108 result=SdccLib(lbnh->libspc, libfp, str, name);
1109 if(result) return(1); /*Found the symbol*/
1111 /*The symbol is not in the current library,
1112 check the next library in the list*/
1116 /*From here down is the support for libraries in the original format*/
1117 if ((relfil[0] == '/') || (relfil[0] == LKDIRSEP))
1119 strcat(str, relfil+1);
1123 strcat(str, relfil);
1126 if(strchr(relfil, FSEPX) == NULL)
1128 sprintf(&str[strlen(str)], "%c%s", FSEPX, LKOBJEXT);
1131 if ((fp = fopen(str, "r")) != NULL)
1134 * Read in the object file. Look for lines that
1135 * begin with "S" and end with "D". These are
1136 * symbol table definitions. If we find one, see
1137 * if it is our symbol. Make sure we only read in
1138 * our object file and don't go into the next one.
1141 while (fgets(buf, NINPUT, fp) != NULL)
1143 buf[NINPUT+1] = '\0';
1146 * Skip everything that's not a symbol record.
1152 * When a 'T line' is found terminate file scan.
1153 * All 'S line's preceed 'T line's in .REL files.
1158 sscanf(buf, "S %s %c", symname, &c);
1161 * If we find a symbol definition for the
1162 * symbol we're looking for, load in the
1163 * file and add it to lbfhead so it gets
1164 * loaded on pass number 2.
1166 if (strncmp(symname, name, NCPS) == 0 && c == 'D')
1168 lbfh = (struct lbfile *) new (sizeof(struct lbfile));
1169 if (lbfhead == NULL)
1183 lbfh->libspc = lbnh->libspc;
1185 lbfh->relfil = (char *) new (strlen(relfil) + 1);
1186 lbfh->offset = -1; /*Stand alone rel file*/
1187 strcpy(lbfh->relfil,relfil);
1191 /* if cdb information required & adb file present */
1194 FILE *xfp = afile(str,"adb",0); //JCF: Nov 30, 2002
1197 SaveLinkedFilePath(str);
1205 } /* Closes while - read object file */
1207 } /* Closes if object file opened OK */
1210 fprintf(stderr, "?ASlink-Warning-Cannot open library module %s\n", str);
1213 } /* Ends while - processing all in libr */
1215 } /* Ends good open of libr file */
1219 #endif /* INDEXLIB */
1221 void loadfile_SdccLib(char * libspc, char * module, long offset)
1226 char posix_path[PATH_MAX];
1227 void cygwin_conv_to_full_posix_path(char * win_path, char * posix_path);
1228 cygwin_conv_to_full_posix_path(libspc, posix_path);
1229 fp = fopen(posix_path, "r");
1231 fp = fopen(libspc,"r");
1236 fseek(fp, offset, SEEK_SET);
1237 LoadRel(libspc, fp, module);
1242 fprintf(stderr, "?ASlink-Error-Opening library '%s'\n", libspc);
1247 /*)Function VOID library()
1249 * The function library() links all the library object files
1250 * contained in the lbfile structures.
1253 * lbfile *lbfh pointer to lbfile structure
1256 * lbfile *lbfhead pointer to first lbfile structure
1259 * VOID loadfile lklibr.c
1262 * Links all files contained in the lbfile structures.
1268 struct lbfile *lbfh;
1270 for (lbfh=lbfhead; lbfh; lbfh=lbfh->next)
1274 /*Stand alone rel file (original lib format)*/
1275 loadfile(lbfh->filspc);
1279 /*rel file embedded in lib (new lib format)*/
1280 loadfile_SdccLib(lbfh->libspc, lbfh->relfil, lbfh->offset);
1288 /*)Function VOID loadfile(filspc)
1290 * char *filspc library object file specification
1292 * The function loadfile() links the library object module.
1295 * FILE *fp file handle
1296 * int i input line length
1297 * char str[] file input line
1300 * char *ip pointer to linker input string
1303 * int fclose() c_library
1304 * int fgets() c_library
1305 * FILE * fopen() c_library
1306 * VOID link_main() lkmain.c
1307 * int strlen() c_library
1310 * If file exists it is linked.
1314 loadfile(char *filspc)
1320 char posix_path[PATH_MAX];
1321 void cygwin_conv_to_full_posix_path(char * win_path, char * posix_path);
1322 cygwin_conv_to_full_posix_path(filspc, posix_path);
1323 fp = fopen(posix_path, "r");
1325 fp = fopen(filspc,"r");
1330 while (fgets(str, NINPUT, fp) != NULL)
1332 str[NINPUT+1] = '\0';
1341 fprintf(stderr, "?ASlink-Error-Opening library '%s'\n", filspc);