* link/z80/lkmain.c (afile): allow periods in directory names
[fw/sdcc] / link / z80 / lkmain.c
index 745504b8495c52eac4e17914b8c009e08610c404..624d4a793a0ff9ca4cc355eb85748e3b37c5ceb6 100644 (file)
 #define TARGET_STRING          "gbz80"
 #endif
 
+#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
+
 /*)Module      lkmain.c
  *
  *     The module lkmain.c contains the functions which
@@ -165,6 +188,10 @@ char *argv[];
        register char *p;
        register int c, i;
 
+#ifdef WIN32T
+    Timer(0, "");
+#endif
+
 #ifdef GAMEBOY
        nb_rom_banks = 2;
        nb_ram_banks = 0;
@@ -376,6 +403,9 @@ char *argv[];
                        reloc('E');
                }
        }
+#ifdef WIN32T
+    Timer(1, "Linker time");
+#endif
        lkexit(lkerr);
 
         /* Never get here. */
@@ -458,6 +488,29 @@ link()
        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;
@@ -487,7 +540,10 @@ link()
 
        case 'M':
                if (pass == 0)
+        {
+            strcpy(curr_module, &ip[1]);
                        module();
+        }
                break;
 
        case 'A':
@@ -855,6 +911,8 @@ parse()
        char fid[NINPUT];
 
        while ((c = getnb()) != 0) {
+               if (c == ';')
+                       return(0);
                if ( c == '-') {
                        while (ctype[c=get()] & LETTER) {
                                switch(c) {
@@ -984,6 +1042,8 @@ parse()
                                        lkexit(1);
                                }
                        }
+                       if (c == ';')
+                               return(0);
                } else
                if (ctype[c] != ILL) {
                        if (linkp == NULL) {
@@ -1279,11 +1339,16 @@ afile(fn, ft, wf)
 char *fn;
 char *ft;
 {
+#if 0
        register char *p1, *p2, *p3;
        register int c;
+#else
+       int i;
+#endif 
        FILE *fp;
        char fb[FILSPC];
 
+#if 0  
        p1 = fn;
        p2 = fb;
        p3 = ft;
@@ -1308,6 +1373,32 @@ char *ft;
                        *p2++ = c;
        }
        *p2++ = 0;
+#else
+       /*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]=='.') && *ft && strcmp(ft, "lnk") )
+       {
+               strncpy(fb, fn, i);
+               fb[i]=0;
+       }
+       else
+       {
+               strcpy(fb, fn);
+       }
+
+       /*Add the extension*/
+       if (fb[i] != '.')
+       {
+               strcat(fb, ".");
+#ifdef SDK
+               strcat(fb, strlen(ft)?ft:"rel");
+#else
+               strcat(fb, strlen(ft)?ft:"REL");
+#endif
+       }
+#endif
+
 #ifdef SDK
        if ((fp = fopen(fb, wf?(binary?"wb":"w"):(binary?"rb":"r"))) == NULL) {
 #else /* SDK */