#include <stdlib.h>
#include "aslink.h"
+#ifdef OTHERSYSTEM
+#ifdef SDK
+#ifdef UNIX
+ #define LKDIRSEP '/'
+ #define LKDIRSEPSTR "/"
+#else /* UNIX */
+ #define LKDIRSEP '\\'
+ #define LKDIRSEPSTR "\\"
+#endif /* UNIX */
+#else /* SDK */
+ #define LKDIRSEP '\\'
+ #define LKDIRSEPSTR "\\"
+#endif /* SDK */
+#endif
+
+#ifdef __CYGWIN__
+void ToCygWin(char * filspc)
+{
+ char posix_path[PATH_MAX];
+ void cygwin_conv_to_full_posix_path(char * win_path, char * posix_path);
+ cygwin_conv_to_full_posix_path(filspc, posix_path);
+ strcpy(filspc, posix_path);
+}
+#endif
+
/*)Module lklibr.c
*
* The module lklibr.c contains the functions which
* global variables:
* lbpath *lbphead The pointer to the first
* path structure
+ * ip a pointer to the library name
*
* functions called:
* VOID addfile() lklibr.c
addlib()
{
struct lbpath *lbph;
+ int foundcount=0;
unget(getnb());
- if (lbphead == NULL) {
- addfile(NULL,ip);
- return;
- }
- for (lbph=lbphead; lbph; lbph=lbph->next) {
- addfile(lbph->path,ip);
+ if (lbphead == NULL)
+ {
+ foundcount=addfile(NULL, ip);
}
+ else
+ {
+ for (lbph=lbphead; lbph; lbph=lbph->next)
+ {
+ foundcount+=addfile(lbph->path, ip);
+ }
+ }
+ if(foundcount == 0)
+ {
+ printf("\n?ASlink-Warning-Couldn't find library '%s'", ip);
+ }
}
-/*)Function VOID addfile(path,libfil)
+/*)Function int addfile(path,libfil)
*
* char *path library path specification
* char *libfil library file specification
*
* side effects:
* An lbname structure may be created.
+ *
+ * return:
+ * 1: the library was found
+ * 0: the library was not found
*/
-VOID
-addfile(path,libfil)
-char *path;
-char *libfil;
+int addfile(char * path, char * libfil)
{
FILE *fp;
char *str;
struct lbname *lbnh, *lbn;
+ int libfilinc=0;
- if ((path != NULL) && (strchr(libfil,':') == NULL)){
+ if (path != NULL)
+ {
str = (char *) new (strlen(path) + strlen(libfil) + 6);
- strcpy(str,path);
-#ifdef OTHERSYSTEM
-#ifdef SDK
-#ifdef UNIX
- if (str[strlen(str)-1] != '/') {
- strcat(str,"/");
-#else /* UNIX */
- if (str[strlen(str)-1] != '\\') {
- strcat(str,"\\");
-#endif /* UNIX */
-#else /* SDK */
- if (str[strlen(str)-1] != '\\') {
- strcat(str,"\\");
-#endif /* SDK */
+ strcpy(str, path);
+
+ if (str[strlen(str)-1] != LKDIRSEP)
+ {
+ strcat(str, LKDIRSEPSTR);
}
-#endif
- } else {
+ }
+ else
+ {
str = (char *) new (strlen(libfil) + 5);
}
-#ifdef OTHERSYSTEM
-#ifdef SDK
-#ifdef UNIX
- if (libfil[0] == '/') { libfil++; }
-#else /* UNIX */
- if (libfil[0] == '\\') { libfil++; }
-#endif /* UNIX */
-#else /* SDK */
- if (libfil[0] == '\\') { libfil++; }
-#endif /* SDK */
-#endif
- strcat(str,libfil);
- if(strchr(libfil,FSEPX) == NULL) {
+
+ if (libfil[0] == LKDIRSEP)
+ {
+ libfil++;
+ libfilinc=1;
+ }
+
+ strcat(str, libfil);
+
+ if(strchr(libfil, FSEPX) == NULL)
+ {
sprintf(&str[strlen(str)], "%clib", FSEPX);
}
- if ((fp = fopen(str, "r")) != NULL) {
+
+ fp=fopen(str, "r");
+ if(fp == NULL)
+ {
+ /*Ok, that didn't work. Try with the 'libfil' name only*/
+ if(libfilinc) libfil--;
+ fp=fopen(libfil, "r");
+ if(fp != NULL)
+ {
+ /*Bingo! 'libfil' is the absolute path of the library*/
+ strcpy(str, libfil);
+ path=NULL;/*This way 'libfil' and 'path' will be rebuilt from 'str'*/
+ }
+ }
+
+ if(path==NULL)
+ {
+ /*'path' can not be null since it is needed to find the '.o' files associated with
+ the library. So, get 'path' from 'str' and then chop it off and recreate 'libfil'.
+ That way putting 'path' and 'libfil' together will result into the original filepath
+ as contained in 'str'.*/
+ int j;
+ path = (char *) new (strlen(str));
+ strcpy(path, str);
+ for(j=strlen(path)-1; j>=0; j--)
+ {
+ if((path[j]=='\\')||(path[j]=='/'))
+ {
+ strcpy(libfil, &path[j+1]);
+ path[j+1]=0;
+ break;
+ }
+ }
+ if(j<=0) path[0]=0;
+ }
+
+ if (fp != NULL)
+ {
fclose(fp);
lbnh = (struct lbname *) new (sizeof(struct lbname));
- if (lbnhead == NULL) {
+ if (lbnhead == NULL)
+ {
lbnhead = lbnh;
- } else {
+ }
+ else
+ {
lbn = lbnhead;
while (lbn->next)
lbn = lbn->next;
lbn->next = lbnh;
}
- if ((path != NULL) && (strchr(libfil,':') == NULL)){
- lbnh->path = path;
- }
+
+ lbnh->path = path;
lbnh->libfil = (char *) new (strlen(libfil) + 1);
- strcpy(lbnh->libfil,libfil);
+ strcpy(lbnh->libfil, libfil);
lbnh->libspc = str;
- } else {
+ return 1;
+ }
+ else
+ {
free(str);
+ return 0;
}
}
pmlibraryfile ThisLibr;
pmlibrarysymbol ThisSym = NULL;
+ pmlibraryfile FirstFound;
+ int numfound=0;
+
/* Build the index if this is the first call to fndsym */
if (libr.next==NULL)
buildlibraryindex();
/* Iterate through all library object files */
ThisLibr = libr.next;
- while (ThisLibr) {
-
+ FirstFound = libr.next; /*So gcc stops whining*/
+ while (ThisLibr)
+ {
/* Iterate through all symbols in an object file */
ThisSym = ThisLibr->symbols->next;
- while (ThisSym) {
- if (!strcmp(ThisSym->name, name)) {
- if (!ThisLibr->loaded) {
+ while (ThisSym)
+ {
+ //printf("ThisSym->name=%s\n", ThisSym->name);
+ if (!strcmp(ThisSym->name, name))
+ {
+ if ((!ThisLibr->loaded) && (numfound==0))
+ {
/* Object file is not loaded - add it to the list */
lbfh = (struct lbfile *) new (sizeof(struct lbfile));
- if (lbfhead == NULL) {
+ if (lbfhead == NULL)
+ {
lbfhead = lbfh;
- } else {
+ }
+ else
+ {
lbf = lbfhead;
while (lbf->next)
lbf = lbf->next;
}
ThisLibr->loaded=1;
}
- return (1); /* Found the symbol, return */
+
+ if(numfound==0)
+ {
+ numfound++;
+ FirstFound=ThisLibr;
+ }
+ else
+ {
+ if( !( EQ(FirstFound->libspc, ThisLibr->libspc) &&
+ EQ(FirstFound->relfil, ThisLibr->relfil) ) )
+ {
+ if(numfound==1)
+ {
+ printf("?Aslink-Warning-Definition of public symbol '%s'"
+ " found more than once:\n", name);
+ printf(" Library: '%s', Module: '%s'\n",
+ FirstFound->libspc, FirstFound->relfil);
+ }
+ printf(" Library: '%s', Module: '%s'\n",
+ ThisLibr->libspc, ThisLibr->relfil);
+ numfound++;
+ }
+ }
}
ThisSym=ThisSym->next; /* Next sym in library */
}
ThisLibr=ThisLibr->next; /* Next library in list */
}
- return 0; /* Failure - symbol not found in any library */
+ return numfound;
}
pmlibraryfile buildlibraryindex_SdccLib(char * PathLib, FILE * libfp, char * DirLib, pmlibraryfile This)
char FLine[MAXLINE+1];
int state=0;
long IndexOffset=0, FileOffset;
- pmlibrarysymbol ThisSym;
+ pmlibrarysymbol ThisSym = NULL;
while(!feof(libfp))
{
} else {
strcat(str,relfil);
}
- if(strchr(str,FSEPX) == NULL) {
+ if(strchr(relfil, FSEPX) == NULL) {
#ifdef SDK
sprintf(&str[strlen(str)], "%co", FSEPX);
#else /* SDK */
} else {
strcat(str,relfil);
}
- if(strchr(relfil,FSEPX) == NULL) {
+ if(strchr(relfil, FSEPX) == NULL) {
#ifdef SDK
sprintf(&str[strlen(str)], "%co", FSEPX);
#else /* SDK */
{
FILE *fp;
+#ifdef __CYGWIN__
+ ToCygWin(libspc);
+#endif
+
if ((fp = fopen(libspc,"r")) != NULL)
{
fseek(fp, offset, SEEK_SET);
char str[NINPUT+2];
int i;
+#ifdef __CYGWIN__
+ ToCygWin(filspc);
+#endif
+
if ((fp = fopen(filspc,"r")) != NULL) {
while (fgets(str, NINPUT, fp) != NULL) {
str[NINPUT+1] = '\0';
}
fclose(fp);
}
+ else
+ {
+ printf("Couldn't find file %s\n", filspc);
+ exit(-4);
+ }
}