-
-/*Check for a symbol in a SDCC library. If found, add the embedded .rel.
-The library must be created with the SDCC librarian 'sdcclib' since the
-linking process depends on the correct file offsets embedded in the library
-file.*/
-
-int SdccLib(char * PathLib, FILE * libfp, char * DirLib, char * SymName)
-{
- struct lbfile *lbfh, *lbf;
- char ModName[NCPS]="";
- char FLine[MAXLINE+1];
- int state=0;
- long IndexOffset=0, FileOffset;
-
- while(!feof(libfp))
- {
- FLine[0]=0;
- fgets(FLine, MAXLINE, libfp);
- chop_crlf(FLine);
-
- switch(state)
- {
- case 0:
- if(EQ(FLine, "<INDEX>"))
- {
- /*The next line has the size of the index*/
- FLine[0]=0;
- fgets(FLine, MAXLINE, libfp);
- chop_crlf(FLine);
- IndexOffset=atol(FLine);
- state=1;
- }
- break;
- case 1:
- if(EQ(FLine, "<MODULE>"))
- {
- /*The next line has the name of the module and the offset
- of the corresponding embedded file in the library*/
- FLine[0]=0;
- fgets(FLine, MAXLINE, libfp);
- chop_crlf(FLine);
- sscanf(FLine, "%s %ld", ModName, &FileOffset);
- state=2;
- }
- else if(EQ(FLine, "</INDEX>"))
- {
- /*Reached the end of the index. The symbol is not in this library.*/
- return 0;
- }
- break;
- case 2:
- if(EQ(FLine, "</MODULE>"))
- {
- /*The symbol is not in this module, try the next one*/
- state=1;
- }
- else
- {
- /*Check if this is the symbol we are looking for.*/
- if (strncmp(SymName, FLine, NCPS)==0)
- {
- /*The symbol is in this module.*/
-
- /*As in the original library format, it is assumed that the .rel
- files reside in the same directory as the lib files.*/
- strcat(DirLib, ModName);
- sprintf(&DirLib[strlen(DirLib)], "%c%s", FSEPX, LKOBJEXT);
-
- /*If this module has been loaded already don't load it again.*/
- lbf = lbfhead;
- while (lbf)
- {
- if(EQ(DirLib, lbf->filspc)) return 1;/*Already loaded*/
- lbf=lbf->next;
- }
-
- /*Add the embedded file to the list of files to be loaded in
- the second pass. That is performed latter by the function
- library() below.*/
- lbfh = (struct lbfile *) new (sizeof(struct lbfile));
- if (lbfhead == NULL)
- {
- lbfhead = lbfh;
- }
- else
- {
- lbf = lbfhead;
- while (lbf->next)
- lbf = lbf->next;
- lbf->next = lbfh;
- }
-
- lbfh->libspc = PathLib;
- lbfh->filspc = DirLib;
- lbfh->relfil = (char *) new (strlen(ModName) + 1);
- strcpy(lbfh->relfil, ModName);
- /*Library embedded file, so lbfh->offset must be >=0*/
- lbfh->offset = IndexOffset+FileOffset;
-
- /*Jump to where the .rel begins and load it.*/
- fseek(libfp, lbfh->offset, SEEK_SET);
- LoadRel(PathLib, libfp, ModName);
-
- return 1; /*Found the symbol, so success!*/
- }
- }
- break;
-
- default:
- return 0; /*It should never reach this point, but just in case...*/
- break;
- }
- }
-
- return 0; /*The symbol is not in this library*/
-}
-
-/*)Function VOID fndsym(name)
- *
- * char *name symbol name to find
- *
- * The function fndsym() searches through all combinations of the
- * library path specifications (input by the -k option) and the
- * library file specifications (input by the -l option) that
- * lead to an existing file.
- *
- * The file specicifation may be formed in one of two ways:
- *
- * (1) If the library file contained an absolute
- * path/file specification then this becomes filspc.
- * (i.e. C:\...)
- *
- * (2) If the library file contains a relative path/file
- * specification then the concatenation of the path
- * and this file specification becomes filspc.
- * (i.e. \...)
- *
- * The structure lbfile is created for the first library
- * object file which contains the definition for the
- * specified undefined symbol.
- *
- * If the library file [.LIB] contains file specifications for
- * non existant files, no errors are returned.
- *
- * local variables:
- * char buf[] [.REL] file input line
- * char c [.REL] file input character
- * FILE *fp file handle for object file
- * lbfile *lbf temporary pointer
- * lbfile *lbfh pointer to lbfile structure
- * FILE *libfp file handle for library file
- * lbname *lbnh pointer to lbname structure
- * char *path file specification path
- * char relfil[] [.REL] file specification
- * char *str combined path and file specification
- * char symname[] [.REL] file symbol string
- *
- * global variables:
- * lbname *lbnhead The pointer to the first
- * name structure
- * lbfile *lbfhead The pointer to the first
- * file structure
- *
- * functions called:
- * int fclose() c_library
- * int fgets() c_library
- * FILE *fopen() c_library
- * VOID free() c_library
- * char getnb() lklex.c
- * VOID lkexit() lkmain.c
- * VOID loadfile() lklibr.c
- * VOID * new() lksym.c
- * char * sprintf() c_library
- * int sscanf() c_library
- * char * strcat() c_library
- * char * strchr() c_library
- * char * strcpy() c_library
- * int strlen() c_library
- * int strncmp() c_library
- * VOID unget() lklex.c
- *
- * side effects:
- * If the symbol is found then a new lbfile structure
- * is created and added to the linked list of lbfile
- * structures. The file containing the found symbol
- * is linked.
- */
-