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 /* if cdb information required & .adb file present */
566 SaveLinkedFilePath(DirLib);
568 return 1; /*Found the symbol, so success!*/
574 return 0; /*It should never reach this point, but just in case...*/
579 return 0; /*The symbol is not in this library*/
582 /*)Function VOID fndsym(name)
584 * char *name symbol name to find
586 * The function fndsym() searches through all combinations of the
587 * library path specifications (input by the -k option) and the
588 * library file specifications (input by the -l option) that
589 * lead to an existing file.
591 * The file specicifation may be formed in one of two ways:
593 * (1) If the library file contained an absolute
594 * path/file specification then this becomes filspc.
597 * (2) If the library file contains a relative path/file
598 * specification then the concatenation of the path
599 * and this file specification becomes filspc.
602 * The structure lbfile is created for the first library
603 * object file which contains the definition for the
604 * specified undefined symbol.
606 * If the library file [.LIB] contains file specifications for
607 * non existant files, no errors are returned.
610 * char buf[] [.REL] file input line
611 * char c [.REL] file input character
612 * FILE *fp file handle for object file
613 * lbfile *lbf temporary pointer
614 * lbfile *lbfh pointer to lbfile structure
615 * FILE *libfp file handle for library file
616 * lbname *lbnh pointer to lbname structure
617 * char *path file specification path
618 * char relfil[] [.REL] file specification
619 * char *str combined path and file specification
620 * char symname[] [.REL] file symbol string
623 * lbname *lbnhead The pointer to the first
625 * lbfile *lbfhead The pointer to the first
629 * int fclose() c_library
630 * int fgets() c_library
631 * FILE *fopen() c_library
632 * VOID free() c_library
633 * char getnb() lklex.c
634 * VOID lkexit() lkmain.c
635 * VOID loadfile() lklibr.c
636 * VOID * new() lksym.c
637 * char * sprintf() c_library
638 * int sscanf() c_library
639 * char * strcat() c_library
640 * char * strchr() c_library
641 * char * strcpy() c_library
642 * int strlen() c_library
643 * int strncmp() c_library
644 * VOID unget() lklex.c
647 * If the symbol is found then a new lbfile structure
648 * is created and added to the linked list of lbfile
649 * structures. The file containing the found symbol
655 int fndsym( char *name )
657 struct lbfile *lbfh, *lbf;
658 pmlibraryfile ThisLibr;
659 pmlibrarysymbol ThisSym = NULL;
661 pmlibraryfile FirstFound;
664 /* Build the index if this is the first call to fndsym */
665 if (libr==NULL) buildlibraryindex();
667 /* Iterate through all library object files */
669 FirstFound = libr; /*So gcc stops whining*/
672 /* Iterate through all symbols in an object file */
673 ThisSym = ThisLibr->symbols;
677 if (!strcmp(ThisSym->name, name))
679 if ((!ThisLibr->loaded) && (numfound==0))
681 /* Object file is not loaded - add it to the list */
682 lbfh = (struct lbfile *) new (sizeof(struct lbfile));
696 lbfh->libspc = ThisLibr->libspc;
697 lbfh->filspc = ThisLibr->filename;
698 lbfh->relfil = (char *) new (strlen(ThisLibr->relfil) + 1);
699 strcpy(lbfh->relfil, ThisLibr->relfil);
700 lbfh->offset = ThisLibr->offset;
702 { /*For an embedded object file in a library*/
703 void loadfile_SdccLib(char * libspc, char * module, long offset);
704 loadfile_SdccLib(lbfh->libspc, lbfh->relfil, lbfh->offset);
707 { /*For a stand alone object file*/
708 /* if cdb information required & adb file present */
711 FILE *xfp = afile(lbfh->filspc, "adb",0);
714 SaveLinkedFilePath(lbfh->filspc);
719 loadfile(lbfh->filspc);
731 char absPath1[PATH_MAX];
732 char absPath2[PATH_MAX];
733 #if defined(__BORLANDC__) || defined(_MSC_VER) || defined(__MINGW32__)
736 _fullpath(absPath1, FirstFound->libspc, PATH_MAX);
737 _fullpath(absPath2, ThisLibr->libspc, PATH_MAX);
738 for(j=0; absPath1[j]!=0; j++) absPath1[j]=tolower((unsigned char)absPath1[j]);
739 for(j=0; absPath2[j]!=0; j++) absPath2[j]=tolower((unsigned char)absPath2[j]);
741 realpath(FirstFound->libspc, absPath1);
742 realpath(ThisLibr->libspc, absPath2);
744 if( !( EQ(absPath1, absPath2) && EQ(FirstFound->relfil, ThisLibr->relfil) ) )
748 fprintf(stderr, "?ASlink-Warning-Definition of public symbol '%s'"
749 " found more than once:\n", name);
750 fprintf(stderr, " Library: '%s', Module: '%s'\n",
751 FirstFound->libspc, FirstFound->relfil);
753 fprintf(stderr, " Library: '%s', Module: '%s'\n",
754 ThisLibr->libspc, ThisLibr->relfil);
759 ThisSym=ThisSym->next; /* Next sym in library */
761 ThisLibr=ThisLibr->next; /* Next library in list */
766 pmlibraryfile buildlibraryindex_SdccLib(char * PathLib, FILE * libfp, char * DirLib, pmlibraryfile This)
768 char ModName[NCPS]="";
769 char FLine[MAXLINE+1];
772 long IndexOffset=0, FileOffset;
773 pmlibrarysymbol ThisSym = NULL;
778 fgets(FLine, MAXLINE, libfp);
784 if(EQ(FLine, "<INDEX>"))
786 /*The next line has the size of the index*/
788 fgets(FLine, MAXLINE, libfp);
790 IndexOffset=atol(FLine);
795 if(EQ(FLine, "<MODULE>"))
797 /*The next line has the name of the module and the offset
798 of the corresponding embedded file in the library*/
800 fgets(FLine, MAXLINE, libfp);
802 sscanf(FLine, "%s %ld", ModName, &FileOffset);
805 /*Create a new libraryfile object for this module*/
808 libr=This=(pmlibraryfile)new( sizeof( mlibraryfile ));
812 This->next=(pmlibraryfile)new( sizeof( mlibraryfile ));
817 This->offset=FileOffset+IndexOffset;
818 This->libspc=PathLib;
820 This->relfil=(char *)new(strlen(ModName)+1);
821 strcpy(This->relfil, ModName);
823 sprintf(buff, "%s%s%c%s", DirLib, ModName, FSEPX, LKOBJEXT);
824 This->filename=(char *)new(strlen(buff)+1);
825 strcpy(This->filename, buff);
827 This->symbols=ThisSym=NULL; /*Start a new linked list of symbols*/
829 else if(EQ(FLine, "</INDEX>"))
831 return This; /*Finish, get out of here*/
835 if(EQ(FLine, "</MODULE>"))
838 /*Create the index for the next module*/
844 if(ThisSym==NULL) /*First symbol of the current module*/
846 ThisSym=This->symbols=(pmlibrarysymbol)new(sizeof(mlibrarysymbol));
850 ThisSym->next = (pmlibrarysymbol)new(sizeof(mlibrarysymbol));
851 ThisSym=ThisSym->next;
854 ThisSym->name=(char *)new(strlen(FLine)+1);
855 strcpy(ThisSym->name, FLine);
860 return This; /*State machine should never reach this point, but just in case...*/
865 return This; /*State machine should never reach this point, but just in case...*/
869 /* buildlibraryindex - build an in-memory cache of the symbols contained in
872 int buildlibraryindex(void)
876 char relfil[NINPUT+2], str[PATH_MAX], *path;
877 char buf[NINPUT+2], c;
878 char symname[NINPUT+2];
879 pmlibraryfile This=NULL;
880 pmlibrarysymbol ThisSym;
883 * Search through every library in the linked list "lbnhead".
885 for (lbnh=lbnhead; lbnh; lbnh=lbnh->next)
887 if ((libfp = fopen(lbnh->libspc, "r")) == NULL)
889 fprintf(stderr, "?ASlink-Error-Cannot open library file %s\n",
896 * Read in a line from the library file.
897 * This is the relative file specification
898 * for a .REL file in this library.
901 while (fgets(relfil, NINPUT, libfp) != NULL)
903 relfil[NINPUT+1] = '\0';
909 if (strlen(str) && (str[strlen(str)-1] != '/') && (str[strlen(str)-1] != LKDIRSEP))
911 strcat(str, LKDIRSEPSTR);
920 if(strcmp(relfil, "<SDCCLIB>")==0)
922 /*Get the built in index of this library*/
923 This=buildlibraryindex_SdccLib(lbnh->libspc, libfp, str, This);
924 break; /*get the index for next library*/
927 /*From here down, build the index for the original library format*/
929 if ((relfil[0] == '/') || (relfil[0] == LKDIRSEP))
931 strcat(str, relfil+1);
938 if(strchr(relfil, FSEPX) == NULL)
940 sprintf(&str[strlen(str)], "%c%s", FSEPX, LKOBJEXT);
943 if ((fp = fopen(str, "r")) != NULL)
945 /* Opened OK - create a new libraryfile object for it */
948 libr=This=(pmlibraryfile)new( sizeof( mlibraryfile ));
952 This->next=(pmlibraryfile)new( sizeof( mlibraryfile ));
957 This->offset=-1; /*We have a stand alone .rel file*/
958 This->libspc = lbnh->libspc;
960 This->relfil=(char *)new(strlen(relfil)+1);
961 strcpy(This->relfil, relfil);
963 This->filename=(char *)new(strlen(str)+1);
964 strcpy(This->filename, str);
966 /*Start a new linked list of symbols for this module:*/
967 This->symbols = ThisSym = NULL;
970 * Read in the object file. Look for lines that
971 * begin with "S" and end with "D". These are
972 * symbol table definitions. If we find one, see
973 * if it is our symbol. Make sure we only read in
974 * our object file and don't go into the next one.
977 while (fgets(buf, NINPUT, fp) != NULL)
979 buf[NINPUT+1] = '\0';
980 buf[strlen(buf) - 1] = '\0';
983 * Skip everything that's not a symbol record.
985 if (buf[0] != 'S') continue;
988 * When a 'T line' is found terminate file scan.
989 * All 'S line's preceed 'T line's in .REL files.
991 if (buf[0] == 'T') break;
993 sscanf(buf, "S %s %c", symname, &c);
995 /* If it's an actual symbol, record it */
1000 ThisSym=This->symbols=(pmlibrarysymbol)new(sizeof(mlibrarysymbol));
1004 ThisSym->next=(pmlibrarysymbol)new(sizeof(mlibrarysymbol));
1005 ThisSym=ThisSym->next;
1009 ThisSym->name=(char *)new(strlen(symname)+1);
1010 strcpy(ThisSym->name, symname);
1012 } /* Closes while - read object file */
1014 } /* Closes if object file opened OK */
1017 fprintf(stderr, "?ASlink-Warning-Cannot open library module %s\n", str);
1019 } /* Ends while - processing all in libr */
1021 } /* Ends good open of libr file */
1025 /*Release all memory allocated for the in-memory library index*/
1026 void freelibraryindex (void)
1028 pmlibraryfile ThisLibr, ThisLibr2Free;
1029 pmlibrarysymbol ThisSym, ThisSym2Free;
1035 ThisSym = ThisLibr->symbols;
1039 free(ThisSym->name);
1040 ThisSym2Free=ThisSym;
1041 ThisSym=ThisSym->next;
1044 free(ThisLibr->filename);
1045 free(ThisLibr->relfil);
1046 ThisLibr2Free=ThisLibr;
1047 ThisLibr=ThisLibr->next;
1048 free(ThisLibr2Free);
1054 #else /* INDEXLIB */
1060 struct lbname *lbnh;
1061 struct lbfile *lbfh, *lbf;
1062 char relfil[NINPUT+2];
1064 char symname[NINPUT];
1070 * Search through every library in the linked list "lbnhead".
1073 for (lbnh=lbnhead; lbnh; lbnh=lbnh->next)
1075 if ((libfp = fopen(lbnh->libspc, "r")) == NULL)
1077 fprintf(stderr, "?ASlink-Error-Cannot open library file %s\n",
1084 * Read in a line from the library file.
1085 * This is the relative file specification
1086 * for a .REL file in this library.
1089 while (fgets(relfil, NINPUT, libfp) != NULL)
1091 relfil[NINPUT+1] = '\0';
1095 str = (char *) new (strlen(path)+strlen(relfil)+6);
1098 if (strlen(str) && (str[strlen(str)-1] != '/') && (str[strlen(str)-1] != LKDIRSEP))
1100 strcat(str, LKDIRSEPSTR);
1106 str = (char *) new (strlen(relfil) + 5);
1109 /*See if this is a library with embedded files*/
1110 if(strcmp(relfil, "<SDCCLIB>")==0)
1112 result=SdccLib(lbnh->libspc, libfp, str, name);
1113 if(result) return(1); /*Found the symbol*/
1115 /*The symbol is not in the current library,
1116 check the next library in the list*/
1120 /*From here down is the support for libraries in the original format*/
1121 if ((relfil[0] == '/') || (relfil[0] == LKDIRSEP))
1123 strcat(str, relfil+1);
1127 strcat(str, relfil);
1130 if(strchr(relfil, FSEPX) == NULL)
1132 sprintf(&str[strlen(str)], "%c%s", FSEPX, LKOBJEXT);
1135 if ((fp = fopen(str, "r")) != NULL)
1138 * Read in the object file. Look for lines that
1139 * begin with "S" and end with "D". These are
1140 * symbol table definitions. If we find one, see
1141 * if it is our symbol. Make sure we only read in
1142 * our object file and don't go into the next one.
1145 while (fgets(buf, NINPUT, fp) != NULL)
1147 buf[NINPUT+1] = '\0';
1150 * Skip everything that's not a symbol record.
1156 * When a 'T line' is found terminate file scan.
1157 * All 'S line's preceed 'T line's in .REL files.
1162 sscanf(buf, "S %s %c", symname, &c);
1165 * If we find a symbol definition for the
1166 * symbol we're looking for, load in the
1167 * file and add it to lbfhead so it gets
1168 * loaded on pass number 2.
1170 if (strncmp(symname, name, NCPS) == 0 && c == 'D')
1172 lbfh = (struct lbfile *) new (sizeof(struct lbfile));
1173 if (lbfhead == NULL)
1187 lbfh->libspc = lbnh->libspc;
1189 lbfh->relfil = (char *) new (strlen(relfil) + 1);
1190 lbfh->offset = -1; /*Stand alone rel file*/
1191 strcpy(lbfh->relfil,relfil);
1195 /* if cdb information required & adb file present */
1198 FILE *xfp = afile(str,"adb",0); //JCF: Nov 30, 2002
1201 SaveLinkedFilePath(str);
1209 } /* Closes while - read object file */
1211 } /* Closes if object file opened OK */
1214 fprintf(stderr, "?ASlink-Warning-Cannot open library module %s\n", str);
1217 } /* Ends while - processing all in libr */
1219 } /* Ends good open of libr file */
1223 #endif /* INDEXLIB */
1225 void loadfile_SdccLib(char * libspc, char * module, long offset)
1230 char posix_path[PATH_MAX];
1231 void cygwin_conv_to_full_posix_path(char * win_path, char * posix_path);
1232 cygwin_conv_to_full_posix_path(libspc, posix_path);
1233 fp = fopen(posix_path, "r");
1235 fp = fopen(libspc,"r");
1240 fseek(fp, offset, SEEK_SET);
1241 LoadRel(libspc, fp, module);
1246 fprintf(stderr, "?ASlink-Error-Opening library '%s'\n", libspc);
1251 /*)Function VOID library()
1253 * The function library() links all the library object files
1254 * contained in the lbfile structures.
1257 * lbfile *lbfh pointer to lbfile structure
1260 * lbfile *lbfhead pointer to first lbfile structure
1263 * VOID loadfile lklibr.c
1266 * Links all files contained in the lbfile structures.
1272 struct lbfile *lbfh;
1274 for (lbfh=lbfhead; lbfh; lbfh=lbfh->next)
1278 /*Stand alone rel file (original lib format)*/
1279 loadfile(lbfh->filspc);
1283 /*rel file embedded in lib (new lib format)*/
1284 loadfile_SdccLib(lbfh->libspc, lbfh->relfil, lbfh->offset);
1292 /*)Function VOID loadfile(filspc)
1294 * char *filspc library object file specification
1296 * The function loadfile() links the library object module.
1299 * FILE *fp file handle
1300 * int i input line length
1301 * char str[] file input line
1304 * char *ip pointer to linker input string
1307 * int fclose() c_library
1308 * int fgets() c_library
1309 * FILE * fopen() c_library
1310 * VOID link_main() lkmain.c
1311 * int strlen() c_library
1314 * If file exists it is linked.
1318 loadfile(char *filspc)
1324 char posix_path[PATH_MAX];
1325 void cygwin_conv_to_full_posix_path(char * win_path, char * posix_path);
1326 cygwin_conv_to_full_posix_path(filspc, posix_path);
1327 fp = fopen(posix_path, "r");
1329 fp = fopen(filspc,"r");
1334 while (fgets(str, NINPUT, fp) != NULL)
1336 str[NINPUT+1] = '\0';
1345 fprintf(stderr, "?ASlink-Error-Opening library '%s'\n", filspc);