Generate a warning when a library file is not found.
authorjesusc <jesusc@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Mon, 28 Jul 2003 21:14:12 +0000 (21:14 +0000)
committerjesusc <jesusc@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Mon, 28 Jul 2003 21:14:12 +0000 (21:14 +0000)
git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@2782 4a8a32a2-be11-0410-ad9d-d568d2c75423

ChangeLog
as/mcs51/aslink.h
as/mcs51/lklibr.c
link/z80/aslink.h
link/z80/lklibr.c

index 870fa9d6989d0e5e397559ad2dfe3ce83134f3de..d854ebd692c1c939adbd9e90e90645f33b05d282 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2003-07-28  Jesus Calvino-Fraga <jesusc@ece.ubc.ca>
+
+    *link/z80/aslink.h, link/z80/lklibr.c, as/mcs51/aslink.h,
+    as/mcs51/lklibr.c: Generate a warning when a library is not found.
+
 2003-07-28  Bernhard Held <bernhard@bernhardheld.de>
 
        * src/z80/mappings.i: fix _mul[us][int,long] entries
index 01988e13223cb58d8a07f22ad57d94c74c6b35a6..fa4f1d1f5558ab01979ef8626394dedb4d99d801 100644 (file)
@@ -741,7 +741,7 @@ extern      VOID            prntval();
 extern  int            lastExtendedAddress;
 
 /* lklibr.c */
-extern VOID            addfile();
+extern int             addfile();
 extern VOID            addlib();
 extern VOID            addpath();
 extern int             fndsym();
index 204449534c0b63a929199200628aa05022c8e777..e880d7a6e23e164dbbdb7f74a902fef80ab16d0a 100644 (file)
@@ -106,6 +106,7 @@ addpath()
  *     global variables:
  *             lbpath  *lbphead        The pointer to the first
  *                                     path structure
+ *      ip a pointer to the library name
  *
  *      functions called:
  *             VOID    addfile()       lklibr.c
@@ -121,6 +122,7 @@ VOID
 addlib()
 {
        struct lbpath *lbph;
+    int foundcount=0;
 
        unget(getnb());
 
@@ -129,11 +131,15 @@ addlib()
                return;
        }       
        for (lbph=lbphead; lbph; lbph=lbph->next) {
-               addfile(lbph->path,ip);
+               foundcount+=addfile(lbph->path,ip);
        }
+    if(foundcount==0)
+    {
+        printf("?ASlink-Warning-Couldn't find library '%s'\n", ip);
+    }
 }
 
-/*)Function    VOID    addfile(path,libfil)
+/*)Function    int     addfile(path,libfil)
  *
  *             char    *path           library path specification
  *             char    *libfil         library file specification
@@ -165,54 +171,114 @@ addlib()
  *
  *     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;
+#ifdef OTHERSYSTEM
+    int libfilinc=0;
+#endif
 
-       if ((path != NULL) && (strchr(libfil,':') == NULL)){
+       if (path != NULL)
+    {
                str = (char *) new (strlen(path) + strlen(libfil) + 6);
                strcpy(str,path);
 #ifdef OTHERSYSTEM
-               if (str[strlen(str)-1] != '/') {
+               if (str[strlen(str)-1] != '/')
+        {
                        strcat(str,"/");
                }
 #endif
-       } else {
+       }
+    else
+    {
                str = (char *) new (strlen(libfil) + 5);
        }
+
 #ifdef OTHERSYSTEM
-       if (libfil[0] == '/') { libfil++; }
+       if (libfil[0] == '/')
+    {
+        libfil++;
+        libfilinc=1;
+    }
 #endif
-       strcat(str,libfil);
-       if(strchr(libfil,FSEPX) == NULL) {
+       
+    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*/
+#ifdef OTHERSYSTEM
+        if(libfilinc) libfil--;
+#endif
+        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);
                lbnh->libspc = str;
-       } else {
+        return 1;
+       } 
+    else 
+    {
                free(str);
+        return 0;
        }
 }
 
index 747c904e57cf634ccffba1c6621c55cd82ae01de..0e3cd39c75b059ece026cec8e29c376262abce50 100644 (file)
@@ -711,7 +711,7 @@ extern      VOID            erpdmp();
 extern VOID            prntval();
 
 /* lklibr.c */
-extern VOID            addfile();
+extern int             addfile();
 extern VOID            addlib();
 extern VOID            addpath();
 extern int             fndsym();
index 47f499f3c09abe79a3370b6548c69366682636c5..94b54da551ddc6a8508b7f3b529d6c1ba30c8e09 100644 (file)
 #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)
 {
@@ -140,6 +155,7 @@ addpath()
  *     global variables:
  *             lbpath  *lbphead        The pointer to the first
  *                                     path structure
+ *      ip a pointer to the library name
  *
  *      functions called:
  *             VOID    addfile()       lklibr.c
@@ -155,6 +171,7 @@ VOID
 addlib()
 {
        struct lbpath *lbph;
+    int foundcount=0;
 
        unget(getnb());
 
@@ -163,11 +180,15 @@ addlib()
                return;
        }       
        for (lbph=lbphead; lbph; lbph=lbph->next) {
-               addfile(lbph->path,ip);
+               foundcount+=addfile(lbph->path,ip);
        }
+    if(foundcount==0)
+    {
+        printf("?ASlink-Warning-Couldn't find library '%s'\n", ip);
+    }
 }
 
-/*)Function    VOID    addfile(path,libfil)
+/*)Function    int     addfile(path,libfil)
  *
  *             char    *path           library path specification
  *             char    *libfil         library file specification
@@ -199,72 +220,108 @@ addlib()
  *
  *     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;
        }
 }