Fixed gcc warning
[fw/sdcc] / as / mcs51 / lkmain.c
index 86e3357d81febf15eeb3f73192488ed3905eb974..548a44fdf53ba6e222c337bba8c1681192fff450 100644 (file)
 #include <string.h>
 #include "aslink.h"
 
+#ifdef WIN32T
+#include <time.h>
+
+void Timer(int action, char * message)
+{
+       static double start, end, total=0.0;
+    static const double secs_per_tick = 1.0 / CLOCKS_PER_SEC;
+
+    if(action==0) start=clock()*secs_per_tick;
+    else if(action==1)
+    {
+       end=clock() * secs_per_tick;
+               printf("%s \t%f seconds.\n", message, (end-start));
+               total+=end-start;
+    }
+    else
+    {
+               printf("Total time: \t%f seconds.\n", total);
+               total=0.0;
+    }
+}
+#endif
+
 /* yuck - but including unistd.h causes problems on Cygwin by redefining
  * Addr_T.
  */
@@ -176,6 +199,10 @@ char *argv[];
        register char *p;
        register int c, i;
 
+#ifdef WIN32T
+    Timer(0, "");
+#endif
+
        startp = (struct lfile *) new (sizeof (struct lfile));
 
        pflag = 1;
@@ -344,6 +371,10 @@ char *argv[];
        //JCF:
        CreateAOMF51();
 
+#ifdef WIN32T
+    Timer(1, "Linker execution time");
+#endif
+
        lkexit(lkerr);
        return 0;
 }
@@ -434,6 +465,29 @@ link_main()
        if ((c=endline()) == 0) { return; }
        switch (c) {
 
+    case 'O': /*For some important sdcc options*/
+        if (pass == 0)
+        {
+            if(strlen(sdccopt)==0)
+            {
+                strcpy(sdccopt, &ip[1]);
+                strcpy(sdccopt_module, curr_module);
+            }
+            else
+            {
+                if(strcmp(sdccopt, &ip[1])!=0)
+                {
+                                   fprintf(stderr,
+                                   "?ASlink-Warning-Conflicting sdcc options:\n"
+                    "   \"%s\" in module \"%s\" and\n"
+                    "   \"%s\" in module \"%s\".\n",
+                    sdccopt, sdccopt_module, &ip[1], curr_module);
+                                   lkerr++;
+                }
+            }
+        }
+               break;
+
        case 'X':
                radix = 16;
                break;
@@ -459,12 +513,14 @@ link_main()
                sdp.s_area = NULL;
                sdp.s_areax = NULL;
                sdp.s_addr = 0;
-               // jwk lastExtendedAddress = -1;
                break;
 
        case 'M':
                if (pass == 0)
+        {
+            strcpy(curr_module, &ip[1]);
                        module();
+        }
                break;
 
        case 'A':
@@ -1077,12 +1133,8 @@ setgbl()
  *     the assembler on an open error.
  *
  *     local variables:
- *             int     c               character value
  *             char    fb[]            constructed file specification string
  *             FILE *  fp              filehandle for opened file
- *             char *  p1              pointer to filespec string fn
- *             char *  p2              pointer to filespec string fb
- *             char *  p3              pointer to filetype string ft
  *
  *     global variables:
  *             int     lkerr           error flag
@@ -1100,36 +1152,35 @@ afile(fn, ft, wf)
 char *fn;
 char *ft;
 {
-       register char *p1, *p2, *p3;
-       register int c;
        FILE *fp;
        char fb[PATH_MAX];
        char *omode = (wf ? (wf == 2 ? "a" : "w") : "r");
+       int i;
 
-       p1 = fn;
-       p2 = fb;
-       p3 = ft;
-       while ((c = *p1++) != 0 && c != FSEPX) {
-               if (p2 < &fb[PATH_MAX-4])
-                       *p2++ = c;
-       }
-       *p2++ = FSEPX;
-       if (*p3 == 0) {
-               if (c == FSEPX) {
-                       p3 = p1;
-               } else {
-                       p3 = "rel";
-               }
+       /*Look backward the name path and get rid of the extension, if any*/
+       i=strlen(fn);
+       for(; (fn[i]!='.')&&(fn[i]!='\\')&&(fn[i]!='/')&&(i>=0); i--);
+       if( (fn[i]=='.') && strcmp(ft, "lnk") )
+       {
+               strncpy(fb, fn, i);
+               fb[i]=0;
        }
-       while ((c = *p3++) != 0) {
-               if (p2 < &fb[PATH_MAX-1])
-                       *p2++ = c;
+       else
+       {
+               strcpy(fb, fn);
        }
-       *p2++ = 0;      
-       if ((fp = fopen(fb, omode)) == NULL) {
-           if (strcmp(ft,"adb")) {
-               fprintf(stderr, "%s: cannot %s.\n", fb, wf?"create":"open");
-               lkerr++;
+
+       /*Add the extension*/
+       strcat(fb, ".");
+       strcat(fb, strlen(ft)?ft:"rel");
+       
+       fp = fopen(fb, omode);
+       if (fp==NULL)
+       {
+           if (strcmp(ft,"adb"))/*Do not complaint for optional adb files*/
+               {
+                       fprintf(stderr, "%s: cannot %s.\n", fb, wf?"create":"open");
+                       lkerr++;
            }
        }
        return (fp);