[hackers] [scc] [driver] add support for the combination of -c and -o || Quentin Rameau

From: <git_AT_suckless.org>
Date: Fri, 17 Jun 2016 21:45:13 +0200 (CEST)

commit 4bf6b4ce284606f33871caac9836f9a5a4b0a97f
Author: Quentin Rameau <quinq_AT_fifth.space>
AuthorDate: Thu Jun 16 10:47:41 2016 +0200
Commit: Quentin Rameau <quinq_AT_fifth.space>
CommitDate: Fri Jun 17 15:45:08 2016 +0200

    [driver] add support for the combination of -c and -o
    
    This is unspecified behaviour[1], but it seems that almost everybody out
    there relies on that, so.
    
    [1] “-o outfile: Use the pathname outfile, instead of the default a.out,
    for the executable file produced. If the -o option is present with -c or
    -E, the result is unspecified.”

diff --git a/driver/posix/scc.c b/driver/posix/scc.c
index 92a14b0..1b6cf5b 100644
--- a/driver/posix/scc.c
+++ b/driver/posix/scc.c
_AT_@ -52,7 +52,7 @@ struct objects {
 };
 
 char *argv0;
-static char *arch;
+static char *arch, *outfile;
 static struct objects objtmp, objout;
 static int Eflag, Sflag, cflag, kflag, sflag;
 
_AT_@ -144,8 +144,7 @@ inittool(int tool)
                 break;
         case LD:
                 addarg(tool, "-o");
- if (!t->outfile)
- t->outfile = xstrdup("a.out");
+ t->outfile = outfile ? outfile : xstrdup("a.out");
                 addarg(tool, t->outfile);
                 break;
         case AS:
_AT_@ -212,7 +211,7 @@ settool(int tool, char *infile, int nexttool)
                 addarg(tool, t->outfile);
                 break;
         case AS:
- t->outfile = outfilename(infile, "o");
+ t->outfile = outfile ? outfile : outfilename(infile, "o");
                 addarg(tool, t->outfile);
                 break;
         case LD:
_AT_@ -375,8 +374,15 @@ build(char *file)
 static void
 usage(void)
 {
- die("usage: %s [-E|-kS] [-w] [-m arch] [-c] [-o binout] [-s]\n"
- " [-D macro[=val]]... [-I dir]... file...", argv0);
+ die("usage: scc [-D def[=val]]... [-U def]... [-I dir]... "
+ "[-L dir]... [-l dir]...\n"
+ " [-ksw] [-m arch] [-E|-S] [-o outfile] file...\n"
+ " scc [-D def[=val]]... [-U def]... [-I dir]... "
+ "[-L dir]... [-l dir]...\n"
+ " [-ksw] [-m arch] [-E|-S] -c file...\n"
+ " scc [-D def[=val]]... [-U def]... [-I dir]... "
+ "[-L dir]... [-l dir]...\n"
+ " [-ksw] [-m arch] -c -o outfile file");
 }
 
 int
_AT_@ -424,7 +430,7 @@ main(int argc, char *argv[])
                 arch = EARGF(usage());
                 break;
         case 'o':
- tools[LD].outfile = xstrdup(EARGF(usage()));
+ outfile = xstrdup(EARGF(usage()));
                 break;
         case 's':
                 sflag = 1;
_AT_@ -440,7 +446,7 @@ main(int argc, char *argv[])
                 usage();
         } ARGEND
 
- if (Eflag && (Sflag || kflag))
+ if (Eflag && (Sflag || kflag) || argc > 1 && cflag && outfile)
                 usage();
 
         if (!argc)
Received on Fri Jun 17 2016 - 21:45:13 CEST

This archive was generated by hypermail 2.3.0 : Fri Jun 17 2016 - 21:48:19 CEST