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 #define LKDIRSEPSTR "/"
37 #define LKDIRSEPSTR "\\"
41 #define LKDIRSEPSTR "\\"
48 #define LKOBJEXT "rel"
53 * The module lklibr.c contains the functions which
54 * (1) specify the path(s) to library files [.LIB]
55 * (2) specify the library file(s) [.LIB] to search
56 * (3) search the library files for specific symbols
57 * and link the module containing this symbol
59 * lklibr.c contains the following functions:
71 typedef struct slibrarysymbol mlibrarysymbol;
72 typedef struct slibrarysymbol *pmlibrarysymbol;
74 struct slibrarysymbol {
75 char * name; /*Warning: allocate memory before using*/
79 typedef struct slibraryfile mlibraryfile;
80 typedef struct slibraryfile *pmlibraryfile;
85 char * relfil; /*Warning: allocate memory before using*/
86 char * filename; /*Warning: allocate memory before using*/
87 long offset; //if > 0, the embedded file offset in the library file libspc
88 pmlibrarysymbol symbols;
92 /* First entry in the library object symbol cache */
93 pmlibraryfile libr=NULL;
95 int buildlibraryindex();
96 void freelibraryindex (void);
99 /*)Function VOID addpath()
101 * The function addpath() creates a linked structure containing
102 * the paths to various object module library files.
105 * lbpath *lbph pointer to new path structure
106 * lbpath *lbp temporary pointer
109 * lbpath *lbphead The pointer to the first
113 * char getnb() lklex.c
114 * VOID * new() lksym.c
115 * int strlen() c_library
116 * char * strcpy() c_library
117 * VOID unget() lklex.c
120 * An lbpath structure may be created.
126 struct lbpath *lbph, *lbp;
128 lbph = (struct lbpath *) new (sizeof(struct lbpath));
129 if (lbphead == NULL) {
138 lbph->path = (char *) new (strlen(ip)+1);
139 strcpy(lbph->path, ip);
142 /*)Function VOID addlib()
144 * The function addlib() tests for the existance of a
145 * library path structure to determine the method of
146 * adding this library file to the library search structure.
148 * This function calls the function addfile() to actually
149 * add the library file to the search list.
152 * lbpath *lbph pointer to path structure
155 * lbpath *lbphead The pointer to the first
157 * ip a pointer to the library name
160 * VOID addfile() lklibr.c
161 * char getnb() lklex.c
162 * VOID unget() lklex.c
165 * The function addfile() may add the file to
166 * the library search list.
179 foundcount=addfile(NULL, ip);
183 for (lbph=lbphead; lbph; lbph=lbph->next)
185 foundcount+=addfile(lbph->path, ip);
190 fprintf(stderr, "?ASlink-Warning-Couldn't find library '%s'\n", ip);
194 /*)Function int addfile(path,libfil)
196 * char *path library path specification
197 * char *libfil library file specification
199 * The function addfile() searches for the library file
200 * by concatenating the path and libfil specifications.
201 * if the library is found, an lbname structure is created
202 * and linked to any previously defined structures. This
203 * linked list is used by the function fndsym() to attempt
204 * to find any undefined symbols.
206 * The function does not give report an error on invalid
207 * path / file specifications or if the file is not found.
210 * lbname *lbnh pointer to new name structure
211 * lbname *lbn temporary pointer
214 * lbname *lbnhead The pointer to the first
218 * char getnb() lklex.c
219 * VOID * new() lksym.c
220 * int strlen() c_library
221 * char * strcpy() c_library
222 * VOID unget() lklex.c
225 * An lbname structure may be created.
228 * 1: the library was found
229 * 0: the library was not found
232 int addfile(char * path, char * libfil)
236 struct lbname *lbnh, *lbn;
241 str = (char *) new (strlen(path) + strlen(libfil) + 6);
243 if (strlen(str) && (str[strlen(str)-1] != '/') && (str[strlen(str)-1] != '\\'))
245 strcat(str, LKDIRSEPSTR);
250 str = (char *) new (strlen(libfil) + 5);
253 if ((libfil[0] == '/') || (libfil[0] == '\\'))
261 if(strchr(libfil, FSEPX) == NULL)
263 sprintf(&str[strlen(str)], "%clib", FSEPX);
269 /*Ok, that didn't work. Try with the 'libfil' name only*/
270 if(libfilinc) libfil--;
271 fp=fopen(libfil, "r");
274 /*Bingo! 'libfil' is the absolute path of the library*/
276 path=NULL;/*This way 'libfil' and 'path' will be rebuilt from 'str'*/
282 /*'path' can not be null since it is needed to find the .rel/.o files associated with
283 the library. So, get 'path' from 'str' and then chop it off and recreate 'libfil'.
284 That way putting 'path' and 'libfil' together will result into the original filepath
285 as contained in 'str'.*/
287 path = (char *) new (strlen(str) + 1);
289 for(j=strlen(path)-1; j>=0; j--)
291 if((path[j] == '/') || (path[j] == '\\'))
293 strcpy(libfil, &path[j+1]);
304 lbnh = (struct lbname *) new (sizeof(struct lbname));
318 lbnh->libfil = (char *) new (strlen(libfil) + 1);
319 strcpy(lbnh->libfil, libfil);
330 /*)Function VOID search()
332 * The function search() looks through all the symbol tables
333 * at the end of pass 1. If any undefined symbols are found
334 * then the function fndsym() is called. Function fndsym()
335 * searches any specified library files to automagically
336 * import the object modules containing the needed symbol.
338 * After a symbol is found and imported by the function
339 * fndsym() the symbol tables are again searched. The
340 * symbol tables are search until no more symbols can be
341 * resolved within the library files. This ensures that
342 * back references from one library module to another are
346 * int i temporary counter
347 * sym *sp pointer to a symbol structure
348 * int symfnd found a symbol flag
351 * sym *symhash[] array of pointers to symbol tables
354 * int fndsym() lklibr.c
357 * If a symbol is found then the library object module
358 * containing the symbol will be imported and linked.
364 register struct sym *sp;
365 register int i, symfnd;
368 * Look for undefined symbols. Keep
369 * searching until no more symbols are resolved.
375 * Look through all the symbols
377 for (i=0; i<NHASH; ++i) {
380 /* If we find an undefined symbol
381 * (one where S_DEF is not set), then
382 * try looking for it. If we find it
383 * in any of the libraries then
384 * increment symfnd. This will force
385 * another pass of symbol searching and
386 * make sure that back references work.
388 if ((sp->s_type & S_DEF) == 0) {
389 if (fndsym(sp->s_id)) {
399 /*Load a .rel file embedded in a sdcclib file*/
400 void LoadRel(char * libfname, FILE * libfp, char * ModName)
405 while (fgets(str, NINPUT, libfp) != NULL)
407 str[NINPUT+1] = '\0';
412 if(EQ(str, "<FILE>"))
414 fgets(str, NINPUT, libfp);
415 str[NINPUT+1] = '\0';
417 if(EQ(str, ModName)) state=1;
420 fprintf(stderr, "?ASlink-Error-Bad offset in library file %s(%s)\n",
427 if(EQ(str, "<REL>")) state=2;
430 if(EQ(str, "</REL>")) return;
438 /*)Function VOID fndsym(name)
440 * char *name symbol name to find
442 * The function fndsym() searches through all combinations of the
443 * library path specifications (input by the -k option) and the
444 * library file specifications (input by the -l option) that
445 * lead to an existing file.
447 * The file specicifation may be formed in one of two ways:
449 * (1) If the library file contained an absolute
450 * path/file specification then this becomes filspc.
453 * (2) If the library file contains a relative path/file
454 * specification then the concatenation of the path
455 * and this file specification becomes filspc.
458 * The structure lbfile is created for the first library
459 * object file which contains the definition for the
460 * specified undefined symbol.
462 * If the library file [.LIB] contains file specifications for
463 * non existant files, no errors are returned.
466 * char buf[] [.REL] file input line
467 * char c [.REL] file input character
468 * FILE *fp file handle for object file
469 * lbfile *lbf temporary pointer
470 * lbfile *lbfh pointer to lbfile structure
471 * FILE *libfp file handle for library file
472 * lbname *lbnh pointer to lbname structure
473 * char *path file specification path
474 * char relfil[] [.REL] file specification
475 * char *str combined path and file specification
476 * char symname[] [.REL] file symbol string
479 * lbname *lbnhead The pointer to the first
481 * lbfile *lbfhead The pointer to the first
485 * int fclose() c_library
486 * int fgets() c_library
487 * FILE *fopen() c_library
488 * VOID free() c_library
489 * char getnb() lklex.c
490 * VOID lkexit() lkmain.c
491 * VOID loadfile() lklibr.c
492 * VOID * new() lksym.c
493 * char * sprintf() c_library
494 * int sscanf() c_library
495 * char * strcat() c_library
496 * char * strchr() c_library
497 * char * strcpy() c_library
498 * int strlen() c_library
499 * int strncmp() c_library
500 * VOID unget() lklex.c
503 * If the symbol is found then a new lbfile structure
504 * is created and added to the linked list of lbfile
505 * structures. The file containing the found symbol
511 int fndsym( char *name )
513 struct lbfile *lbfh, *lbf;
514 pmlibraryfile ThisLibr;
515 pmlibrarysymbol ThisSym = NULL;
517 pmlibraryfile FirstFound;
520 /* Build the index if this is the first call to fndsym */
521 if (libr==NULL) buildlibraryindex();
523 /* Iterate through all library object files */
525 FirstFound = libr; /*So gcc stops whining*/
528 /* Iterate through all symbols in an object file */
529 ThisSym = ThisLibr->symbols;
533 if (!strcmp(ThisSym->name, name))
535 if ((!ThisLibr->loaded) && (numfound==0))
537 /* Object file is not loaded - add it to the list */
538 lbfh = (struct lbfile *) new (sizeof(struct lbfile));
550 lbfh->libspc = ThisLibr->libspc;
551 lbfh->filspc = ThisLibr->filename;
552 lbfh->relfil = (char *) new (strlen(ThisLibr->relfil) + 1);
553 strcpy(lbfh->relfil, ThisLibr->relfil);
554 lbfh->offset = ThisLibr->offset;
556 { /*For an embedded object file in a library*/
557 void loadfile_SdccLib(char * libspc, char * module, long offset);
558 loadfile_SdccLib(lbfh->libspc, lbfh->relfil, lbfh->offset);
561 { /*For a stand alone object file*/
562 loadfile(lbfh->filspc);
574 char absPath1[PATH_MAX];
575 char absPath2[PATH_MAX];
576 #if defined(__BORLANDC__) || defined(_MSC_VER) || defined(__MINGW32__)
579 _fullpath(absPath1, FirstFound->libspc, PATH_MAX);
580 _fullpath(absPath2, ThisLibr->libspc, PATH_MAX);
581 for(j=0; absPath1[j]!=0; j++) absPath1[j]=tolower((unsigned char)absPath1[j]);
582 for(j=0; absPath2[j]!=0; j++) absPath2[j]=tolower((unsigned char)absPath2[j]);
584 realpath(FirstFound->libspc, absPath1);
585 realpath(ThisLibr->libspc, absPath2);
587 if( !( EQ(absPath1, absPath2) && EQ(FirstFound->relfil, ThisLibr->relfil) ) )
591 fprintf(stderr, "?Aslink-Warning-Definition of public symbol '%s'"
592 " found more than once:\n", name);
593 fprintf(stderr, " Library: '%s', Module: '%s'\n",
594 FirstFound->libspc, FirstFound->relfil);
596 fprintf(stderr, " Library: '%s', Module: '%s'\n",
597 ThisLibr->libspc, ThisLibr->relfil);
602 ThisSym=ThisSym->next; /* Next sym in library */
604 ThisLibr=ThisLibr->next; /* Next library in list */
609 pmlibraryfile buildlibraryindex_SdccLib(char * PathLib, FILE * libfp, char * DirLib, pmlibraryfile This)
611 char ModName[NCPS]="";
612 char FLine[MAXLINE+1];
615 long IndexOffset=0, FileOffset;
616 pmlibrarysymbol ThisSym = NULL;
621 fgets(FLine, MAXLINE, libfp);
627 if(EQ(FLine, "<INDEX>"))
629 /*The next line has the size of the index*/
631 fgets(FLine, MAXLINE, libfp);
633 IndexOffset=atol(FLine);
638 if(EQ(FLine, "<MODULE>"))
640 /*The next line has the name of the module and the offset
641 of the corresponding embedded file in the library*/
643 fgets(FLine, MAXLINE, libfp);
645 sscanf(FLine, "%s %ld", ModName, &FileOffset);
648 /*Create a new libraryfile object for this module*/
651 libr=This=(pmlibraryfile)new( sizeof( mlibraryfile ));
655 This->next=(pmlibraryfile)new( sizeof( mlibraryfile ));
660 This->offset=FileOffset+IndexOffset;
661 This->libspc=PathLib;
663 This->relfil=(char *)new(strlen(ModName)+1);
664 strcpy(This->relfil, ModName);
666 sprintf(buff, "%s%s%c%s", DirLib, ModName, FSEPX, LKOBJEXT);
667 This->filename=(char *)new(strlen(buff)+1);
668 strcpy(This->filename, buff);
670 This->symbols=ThisSym=NULL; /*Start a new linked list of symbols*/
672 else if(EQ(FLine, "</INDEX>"))
674 return This; /*Finish, get out of here*/
678 if(EQ(FLine, "</MODULE>"))
681 /*Create the index for the next module*/
687 if(ThisSym==NULL) /*First symbol of the current module*/
689 ThisSym=This->symbols=(pmlibrarysymbol)new(sizeof(mlibrarysymbol));
693 ThisSym->next = (pmlibrarysymbol)new(sizeof(mlibrarysymbol));
694 ThisSym=ThisSym->next;
697 ThisSym->name=(char *)new(strlen(FLine)+1);
698 strcpy(ThisSym->name, FLine);
703 return This; /*State machine should never reach this point, but just in case...*/
708 return This; /*State machine should never reach this point, but just in case...*/
712 /* buildlibraryindex - build an in-memory cache of the symbols contained in
715 int buildlibraryindex(void)
719 char relfil[NINPUT+2], str[PATH_MAX], *path;
720 char buf[NINPUT+2], c;
721 char symname[NINPUT+2];
722 pmlibraryfile This=NULL;
723 pmlibrarysymbol ThisSym;
726 * Search through every library in the linked list "lbnhead".
728 for (lbnh=lbnhead; lbnh; lbnh=lbnh->next)
730 if ((libfp = fopen(lbnh->libspc, "r")) == NULL)
732 fprintf(stderr, "?Aslink-Error-Cannot open library file %s\n",
739 * Read in a line from the library file.
740 * This is the relative file specification
741 * for a .REL file in this library.
744 while (fgets(relfil, NINPUT, libfp) != NULL)
746 relfil[NINPUT+1] = '\0';
752 if (strlen(str) && (str[strlen(str)-1] != '/') && (str[strlen(str)-1] != '\\'))
754 strcat(str, LKDIRSEPSTR);
763 if(strcmp(relfil, "<SDCCLIB>")==0)
765 /*Get the built in index of this library*/
766 This=buildlibraryindex_SdccLib(lbnh->libspc, libfp, str, This);
767 break; /*get the index for next library*/
770 /*From here down, build the index for the original library format*/
772 if ((relfil[0] == '/') || (relfil[0] == '\\'))
774 strcat(str, relfil+1);
781 if(strchr(relfil, FSEPX) == NULL)
783 sprintf(&str[strlen(str)], "%c%s", FSEPX, LKOBJEXT);
786 if ((fp = fopen(str, "r")) != NULL)
788 /* Opened OK - create a new libraryfile object for it */
791 libr=This=(pmlibraryfile)new( sizeof( mlibraryfile ));
795 This->next=(pmlibraryfile)new( sizeof( mlibraryfile ));
800 This->offset=-1; /*There should be a rel file*/
801 This->libspc = lbnh->libspc;
803 This->relfil=(char *)new(strlen(relfil)+1);
804 strcpy(This->relfil, relfil);
806 This->filename=(char *)new(strlen(str)+1);
807 strcpy(This->filename, str);
809 /*Start a new linked list of symbols for this module:*/
810 This->symbols = ThisSym = NULL;
813 * Read in the object file. Look for lines that
814 * begin with "S" and end with "D". These are
815 * symbol table definitions. If we find one, see
816 * if it is our symbol. Make sure we only read in
817 * our object file and don't go into the next one.
820 while (fgets(buf, NINPUT, fp) != NULL)
822 buf[NINPUT+1] = '\0';
823 buf[strlen(buf) - 1] = '\0';
826 * Skip everything that's not a symbol record.
828 if (buf[0] != 'S') continue;
831 * When a 'T line' is found terminate file scan.
832 * All 'S line's preceed 'T line's in .REL files.
834 if (buf[0] == 'T') break;
836 sscanf(buf, "S %s %c", symname, &c);
838 /* If it's an actual symbol, record it */
843 ThisSym=This->symbols=(pmlibrarysymbol)new(sizeof(mlibrarysymbol));
847 ThisSym->next=(pmlibrarysymbol)new(sizeof(mlibrarysymbol));
848 ThisSym=ThisSym->next;
852 ThisSym->name=(char *)new(strlen(symname)+1);
853 strcpy(ThisSym->name, symname);
855 } /* Closes while - read object file */
857 } /* Closes if object file opened OK */
860 fprintf(stderr, "?Aslink-Warning-Cannot open library module %s\n", str);
862 } /* Ends while - processing all in libr */
864 } /* Ends good open of libr file */
868 /*Release all memory allocated for the in-memory library index*/
869 void freelibraryindex (void)
871 pmlibraryfile ThisLibr, ThisLibr2Free;
872 pmlibrarysymbol ThisSym, ThisSym2Free;
878 ThisSym = ThisLibr->symbols;
883 ThisSym2Free=ThisSym;
884 ThisSym=ThisSym->next;
887 free(ThisLibr->filename);
888 free(ThisLibr->relfil);
889 ThisLibr2Free=ThisLibr;
890 ThisLibr=ThisLibr->next;
900 /*Check for a symbol in a SDCC library. If found, add the embedded .rel.
901 The library must be created with the SDCC librarian 'sdcclib' since the
902 linking process depends on the correct file offsets embedded in the library
905 int SdccLib(char * PathLib, FILE * libfp, char * DirLib, char * SymName)
907 struct lbfile *lbfh, *lbf;
908 char ModName[NCPS]="";
909 char FLine[MAXLINE+1];
911 long IndexOffset=0, FileOffset;
916 fgets(FLine, MAXLINE, libfp);
922 if(EQ(FLine, "<INDEX>"))
924 /*The next line has the size of the index*/
926 fgets(FLine, MAXLINE, libfp);
928 IndexOffset=atol(FLine);
933 if(EQ(FLine, "<MODULE>"))
935 /*The next line has the name of the module and the offset
936 of the corresponding embedded file in the library*/
938 fgets(FLine, MAXLINE, libfp);
940 sscanf(FLine, "%s %ld", ModName, &FileOffset);
943 else if(EQ(FLine, "</INDEX>"))
945 /*Reached the end of the index. The symbol is not in this library.*/
950 if(EQ(FLine, "</MODULE>"))
952 /*The symbol is not in this module, try the next one*/
957 /*Check if this is the symbol we are looking for.*/
958 if (strncmp(SymName, FLine, NCPS)==0)
960 /*The symbol is in this module.*/
962 /*As in the original library format, it is assumed that the .rel
963 files reside in the same directory as the lib files.*/
964 strcat(DirLib, ModName);
965 sprintf(&DirLib[strlen(DirLib)], "%c%s", FSEPX, LKOBJEXT);
967 /*If this module has been loaded already don't load it again.*/
971 if(EQ(DirLib, lbf->filspc)) return 1;/*Already loaded*/
975 /*Add the embedded file to the list of files to be loaded in
976 the second pass. That is performed latter by the function
978 lbfh = (struct lbfile *) new (sizeof(struct lbfile));
991 lbfh->libspc = PathLib;
992 lbfh->filspc = DirLib;
993 lbfh->relfil = (char *) new (strlen(ModName) + 1);
994 strcpy(lbfh->relfil, ModName);
995 /*Library embedded file, so lbfh->offset must be >=0*/
996 lbfh->offset = IndexOffset+FileOffset;
998 /*Jump to where the .rel begins and load it.*/
999 fseek(libfp, lbfh->offset, SEEK_SET);
1000 LoadRel(PathLib, libfp, ModName);
1002 return 1; /*Found the symbol, so success!*/
1008 return 0; /*It should never reach this point, but just in case...*/
1013 return 0; /*The symbol is not in this library*/
1016 /*)Function VOID fndsym(name)
1018 * char *name symbol name to find
1020 * The function fndsym() searches through all combinations of the
1021 * library path specifications (input by the -k option) and the
1022 * library file specifications (input by the -l option) that
1023 * lead to an existing file.
1025 * The file specicifation may be formed in one of two ways:
1027 * (1) If the library file contained an absolute
1028 * path/file specification then this becomes filspc.
1031 * (2) If the library file contains a relative path/file
1032 * specification then the concatenation of the path
1033 * and this file specification becomes filspc.
1036 * The structure lbfile is created for the first library
1037 * object file which contains the definition for the
1038 * specified undefined symbol.
1040 * If the library file [.LIB] contains file specifications for
1041 * non existant files, no errors are returned.
1044 * char buf[] [.REL] file input line
1045 * char c [.REL] file input character
1046 * FILE *fp file handle for object file
1047 * lbfile *lbf temporary pointer
1048 * lbfile *lbfh pointer to lbfile structure
1049 * FILE *libfp file handle for library file
1050 * lbname *lbnh pointer to lbname structure
1051 * char *path file specification path
1052 * char relfil[] [.REL] file specification
1053 * char *str combined path and file specification
1054 * char symname[] [.REL] file symbol string
1057 * lbname *lbnhead The pointer to the first
1059 * lbfile *lbfhead The pointer to the first
1063 * int fclose() c_library
1064 * int fgets() c_library
1065 * FILE *fopen() c_library
1066 * VOID free() c_library
1067 * char getnb() lklex.c
1068 * VOID lkexit() lkmain.c
1069 * VOID loadfile() lklibr.c
1070 * VOID * new() lksym.c
1071 * char * sprintf() c_library
1072 * int sscanf() c_library
1073 * char * strcat() c_library
1074 * char * strchr() c_library
1075 * char * strcpy() c_library
1076 * int strlen() c_library
1077 * int strncmp() c_library
1078 * VOID unget() lklex.c
1081 * If the symbol is found then a new lbfile structure
1082 * is created and added to the linked list of lbfile
1083 * structures. The file containing the found symbol
1092 struct lbname *lbnh;
1093 struct lbfile *lbfh, *lbf;
1094 char relfil[NINPUT+2];
1096 char symname[NINPUT];
1102 * Search through every library in the linked list "lbnhead".
1105 for (lbnh=lbnhead; lbnh; lbnh=lbnh->next)
1107 if ((libfp = fopen(lbnh->libspc, "r")) == NULL)
1109 fprintf(stderr, "?ASlink-Error-Cannot open library file %s\n",
1116 * Read in a line from the library file.
1117 * This is the relative file specification
1118 * for a .REL file in this library.
1121 while (fgets(relfil, NINPUT, libfp) != NULL)
1123 relfil[NINPUT+1] = '\0';
1127 str = (char *) new (strlen(path)+strlen(relfil)+6);
1130 if (strlen(str) && (str[strlen(str)-1] != '/') && (str[strlen(str)-1] != '\\'))
1146 str = (char *) new (strlen(relfil) + 5);
1149 /*See if this is a library with embedded files*/
1150 if(strcmp(relfil, "<SDCCLIB>")==0)
1152 result=SdccLib(lbnh->libspc, libfp, str, name);
1153 if(result) return(1); /*Found the symbol*/
1155 /*The symbol is not in the current library,
1156 check the next library in the list*/
1160 /*From here down is the support for libraries in the original format*/
1161 if ((relfil[0] == '/') || (relfil[0] == '\\'))
1163 strcat(str, relfil+1);
1167 strcat(str, relfil);
1170 if(strchr(relfil, FSEPX) == NULL)
1172 sprintf(&str[strlen(str)], "%c%s", FSEPX, LKOBJEXT);
1175 if ((fp = fopen(str, "r")) != NULL)
1178 * Read in the object file. Look for lines that
1179 * begin with "S" and end with "D". These are
1180 * symbol table definitions. If we find one, see
1181 * if it is our symbol. Make sure we only read in
1182 * our object file and don't go into the next one.
1185 while (fgets(buf, NINPUT, fp) != NULL)
1187 buf[NINPUT+1] = '\0';
1190 * Skip everything that's not a symbol record.
1196 * When a 'T line' is found terminate file scan.
1197 * All 'S line's preceed 'T line's in .REL files.
1202 sscanf(buf, "S %s %c", symname, &c);
1205 * If we find a symbol definition for the
1206 * symbol we're looking for, load in the
1207 * file and add it to lbfhead so it gets
1208 * loaded on pass number 2.
1210 if (strncmp(symname, name, NCPS) == 0 && c == 'D')
1212 lbfh = (struct lbfile *) new (sizeof(struct lbfile));
1213 if (lbfhead == NULL)
1225 lbfh->libspc = lbnh->libspc;
1227 lbfh->relfil = (char *) new (strlen(relfil) + 1);
1228 lbfh->offset = -1; /*Stand alone rel file*/
1229 strcpy(lbfh->relfil,relfil);
1245 #endif /* INDEXLIB */
1247 void loadfile_SdccLib(char * libspc, char * module, long offset)
1252 char posix_path[PATH_MAX];
1253 void cygwin_conv_to_full_posix_path(char * win_path, char * posix_path);
1254 cygwin_conv_to_full_posix_path(libspc, posix_path);
1255 fp = fopen(posix_path, "r");
1257 fp = fopen(libspc,"r");
1262 fseek(fp, offset, SEEK_SET);
1263 LoadRel(libspc, fp, module);
1268 fprintf(stderr, "?ASlink-Error-Opening library '%s'\n", libspc);
1273 /*)Function VOID library()
1275 * The function library() links all the library object files
1276 * contained in the lbfile structures.
1279 * lbfile *lbfh pointer to lbfile structure
1282 * lbfile *lbfhead pointer to first lbfile structure
1285 * VOID loadfile lklibr.c
1288 * Links all files contained in the lbfile structures.
1294 struct lbfile *lbfh;
1296 for (lbfh=lbfhead; lbfh; lbfh=lbfh->next)
1300 /*Stand alone rel file (original lib format)*/
1301 loadfile(lbfh->filspc);
1305 /*rel file embedded in lib (new lib format)*/
1306 loadfile_SdccLib(lbfh->libspc, lbfh->relfil, lbfh->offset);
1314 /*)Function VOID loadfile(filspc)
1316 * char *filspc library object file specification
1318 * The function loadfile() links the library object module.
1321 * FILE *fp file handle
1322 * int i input line length
1323 * char str[] file input line
1326 * char *ip pointer to linker input string
1329 * int fclose() c_library
1330 * int fgets() c_library
1331 * FILE * fopen() c_library
1332 * VOID link_main() lkmain.c
1333 * int strlen() c_library
1336 * If file exists it is linked.
1347 char posix_path[PATH_MAX];
1348 void cygwin_conv_to_full_posix_path(char * win_path, char * posix_path);
1349 cygwin_conv_to_full_posix_path(filspc, posix_path);
1350 fp = fopen(posix_path, "r");
1352 fp = fopen(filspc,"r");
1357 while (fgets(str, NINPUT, fp) != NULL)
1359 str[NINPUT+1] = '\0';
1368 fprintf(stderr, "?ASlink-Error-Opening library '%s'\n", filspc);