Fixed gcc warning
[fw/sdcc] / link / z80 / lklibr.c
index 94b54da551ddc6a8508b7f3b529d6c1ba30c8e09..be82f7bca79900a644ea727df81020b37e680590 100644 (file)
@@ -175,16 +175,20 @@ addlib()
 
        unget(getnb());
 
-       if (lbphead == NULL) {
-               addfile(NULL,ip);
-               return;
-       }       
-       for (lbph=lbphead; lbph; lbph=lbph->next) {
-               foundcount+=addfile(lbph->path,ip);
+       if (lbphead == NULL)
+    {
+               foundcount=addfile(NULL, ip);
        }
-    if(foundcount==0)
+    else
+    {
+           for (lbph=lbphead; lbph; lbph=lbph->next)
+        {
+                   foundcount+=addfile(lbph->path, ip);
+           }
+    }
+    if(foundcount == 0)
     {
-        printf("?ASlink-Warning-Couldn't find library '%s'\n", ip);
+        printf("\n?ASlink-Warning-Couldn't find library '%s'", ip);
     }
 }
 
@@ -514,26 +518,36 @@ int fndsym( char *name )
        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) {
+               while (ThisSym)
+        {
             //printf("ThisSym->name=%s\n", ThisSym->name);
-                       if (!strcmp(ThisSym->name, name)) {
-                               if (!ThisLibr->loaded) {
+                       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;
@@ -555,13 +569,35 @@ int fndsym( char *name )
                     }
                                        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)