* src/SDCCast.c (decorateType): fix for RFE 1475742, optimize 'ifx (op == 0)' resp...
[fw/sdcc] / link / z80 / lkmain.c
index c6cc8b29fcded57a27a26c7237271560c386cdad..f2d071e253bddbf0bd7dabef4feb03260a66e2f9 100644 (file)
@@ -83,7 +83,7 @@ void Timer(int action, char * message)
  *
  *     The function main() evaluates the command line arguments to
  *     determine if the linker parameters are to input through 'stdin'
- *     or read from a command file.  The functiond getline() and parse()
+ *     or read from a command file.  The functiond lk_getline() and parse()
  *     are to input and evaluate the linker parameters.  The linking process
  *     proceeds by making the first pass through each .rel file in the order
  *     presented to the linker.  At the end of the first pass the setbase(),
@@ -137,7 +137,7 @@ void Timer(int action, char * message)
  *             FILE *  afile()         lkmain.c
  *             int     fclose()        c_library
  *             int     fprintf()       c_library
- *             int     getline()       lklex.c
+ *             int     lk_getline()    lklex.c
  *             VOID    library()       lklibr.c
  *             VOID    link()          lkmain.c
  *             VOID    lkexit()        lkmain.c
@@ -285,7 +285,7 @@ char *argv[];
        filep = startp;
        while (1) {
                ip = ib;                                        
-               if (getline() == 0)
+               if (lk_getline() == 0)
                        break;
                if (pflag && sfp != stdin)
                        fprintf(stdout, "%s\n", ip);
@@ -328,7 +328,7 @@ char *argv[];
                hp = NULL;
                radix = 10;
 
-               while (getline()) {
+               while (lk_getline()) {
                        ip = ib;
                        link();
                }
@@ -911,6 +911,8 @@ parse()
        char fid[NINPUT];
 
        while ((c = getnb()) != 0) {
+               if (c == ';')
+                       return(0);
                if ( c == '-') {
                        while (ctype[c=get()] & LETTER) {
                                switch(c) {
@@ -1040,6 +1042,8 @@ parse()
                                        lkexit(1);
                                }
                        }
+                       if (c == ';')
+                               return(0);
                } else
                if (ctype[c] != ILL) {
                        if (linkp == NULL) {
@@ -1335,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;
@@ -1364,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 */