restored else branch for other ports
[fw/sdcc] / as / hc08 / lkmain.c
index 548a44fdf53ba6e222c337bba8c1681192fff450..401916a51b397764f6ac190720567f12edcb4d21 100644 (file)
@@ -116,7 +116,7 @@ void Areas51 (void)
  *
  *     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 as_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(),
@@ -170,7 +170,7 @@ void Areas51 (void)
  *             FILE *  afile()         lkmain.c
  *             int     fclose()        c_library
  *             int     fprintf()       c_library
- *             int     getline()       lklex.c
+ *             int     as_getline()    lklex.c
  *             VOID    library()       lklibr.c
  *             VOID    link_main()     lkmain.c
  *             VOID    lkexit()        lkmain.c
@@ -252,7 +252,7 @@ char *argv[];
        filep = startp;
        while (1) {
                ip = ib;
-               if (getline() == 0)
+               if (as_getline() == 0)
                        break;
                if (pflag && sfp != stdin)
                        fprintf(stdout, "%s\n", ip);
@@ -287,7 +287,7 @@ char *argv[];
                
                Areas51(); /*JCF: Create the default 8051 areas in the right order*/
 
-               while (getline()) {
+               while (as_getline()) {
                        ip = ib;
 
                         /* pass any "magic comments" to NoICE output */
@@ -359,6 +359,12 @@ char *argv[];
                                }
                                /* include NoICE command to load hex file */
                                if (jfp) fprintf( jfp, "LOAD %s.S19\n", linkp->f_idp );
+                       } else
+                       if (oflag == 3) {
+                               ofp = afile(linkp->f_idp, "elf", 4);
+                               if (ofp == NULL) {
+                                       lkexit(1);
+                               }
                        }
                } else {
                        /*
@@ -369,7 +375,7 @@ char *argv[];
                }
        }
        //JCF:
-       CreateAOMF51();
+       //CreateAOMF51();
 
 #ifdef WIN32T
     Timer(1, "Linker execution time");
@@ -756,6 +762,8 @@ parse()
        char fid[NINPUT];
 
        while ((c = getnb()) != 0) {
+               if ( c == ';')
+                       return(0);
                if ( c == '-') {
                        while (ctype[c=get()] & LETTER) {
                                switch(c) {
@@ -770,6 +778,11 @@ parse()
                                        oflag = 2;
                                        break;
 
+                               case 't':
+                               case 'T':
+                                       oflag = 3;
+                                       break;
+
                                case 'm':
                                case 'M':
                                        ++mflag;
@@ -866,6 +879,8 @@ parse()
                                        lkexit(1);
                                }
                        }
+                       if ( c == ';')
+                               return(0);
                } else
                if (ctype[c] & ILL) {
                        fprintf(stderr, "Invalid input");
@@ -1154,12 +1169,22 @@ char *ft;
 {
        FILE *fp;
        char fb[PATH_MAX];
-       char *omode = (wf ? (wf == 2 ? "a" : "w") : "r");
+       char *omode;
        int i;
+       
+       switch (wf) {
+               case 0: omode = "r"; break;
+               case 1: omode = "w"; break;
+               case 2: omode = "a"; break;
+               case 3: omode = "rb"; break;
+               case 4: omode = "wb"; break;
+               case 5: omode = "ab"; break;
+               default: omode = "r"; break;
+       }
 
        /*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--);
+       for(; (fn[i]!='.')&&(fn[i]!='\\')&&(fn[i]!='/')&&(i>0); i--);
        if( (fn[i]=='.') && strcmp(ft, "lnk") )
        {
                strncpy(fb, fn, i);
@@ -1171,9 +1196,12 @@ char *ft;
        }
 
        /*Add the extension*/
-       strcat(fb, ".");
-       strcat(fb, strlen(ft)?ft:"rel");
-       
+       if (fb[i] != '.')
+       {
+               strcat(fb, ".");
+               strcat(fb, strlen(ft)?ft:"rel");
+       }
+               
        fp = fopen(fb, omode);
        if (fp==NULL)
        {
@@ -1309,6 +1337,7 @@ char *usetxt[] = {
        "Output:",
        "  -i   Intel Hex as file[IHX]",
        "  -s   Motorola S19 as file[S19]",
+        "  -t   ELF executable as file[elf]",
        "  -j   Produce NoICE debug as file[NOI]",
        "  -z   Produce SDCdb debug as file[cdb]",
 /*     "List:", */