[hackers] [scc] [cc1] update usage, reorder flags and arguments checks || Quentin Rameau

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

commit cbd198b38bee47a2b58541ff413f847d78db4b67
Author: Quentin Rameau <quinq_AT_fifth.space>
AuthorDate: Thu Jun 16 14:41:27 2016 +0200
Commit: Quentin Rameau <quinq_AT_fifth.space>
CommitDate: Fri Jun 17 21:41:09 2016 +0200

    [cc1] update usage, reorder flags and arguments checks

diff --git a/cc1/main.c b/cc1/main.c
index db8b455..91974a9 100644
--- a/cc1/main.c
+++ b/cc1/main.c
_AT_@ -15,7 +15,7 @@ char *argv0;
 int warnings;
 jmp_buf recover;
 
-static char *output;
+static char *base, *output;
 int onlycpp;
 
 extern int failure;
_AT_@ -30,8 +30,11 @@ clean(void)
 static void
 usage(void)
 {
- die("usage: %s [-E] [-D macro[=value]] ... [-I dir] [-w] [-d]"
- "[-o output] [input]", argv0);
+ die(!strcmp(base, "cpp") ?
+ "usage: cpp [-wd] [-D def[=val]]... [-U def]... [-I dir]... "
+ "[input]" :
+ "usage: cc1 [-Ewd] [-D def[=val]]... [-U def]... [-I dir]... "
+ "[-o output] [input]");
 }
 
 int
_AT_@ -43,15 +46,21 @@ main(int argc, char *argv[])
         atexit(clean);
         icpp();
 
+ /* if run as cpp, only run the preprocessor */
+ if ((base = strrchr(argv0, '/')))
+ ++base;
+ else
+ base = argv0;
+
         ARGBEGIN {
- case 'w':
- warnings = 1;
+ case 'D':
+ defmacro(EARGF(usage()));
                 break;
         case 'E':
                 onlycpp = 1;
                 break;
- case 'D':
- defmacro(EARGF(usage()));
+ case 'I':
+ incdir(EARGF(usage()));
                 break;
         case 'U':
                 if (umacro == &uvec[NR_USWITCHES])
_AT_@ -61,32 +70,27 @@ main(int argc, char *argv[])
         case 'd':
                 DBGON();
                 break;
- case 'I':
- incdir(EARGF(usage()));
- break;
         case 'o':
                 output = EARGF(usage());
                 break;
+ case 'w':
+ warnings = 1;
+ break;
         default:
                 usage();
         } ARGEND
 
- for (umacro = uvec; *umacro; umacro++)
- undefmacro(*umacro);
-
         if (argc > 1)
                 usage();
 
- /* if run as cpp, only run the preprocessor */
- if ((base = strrchr(argv0, '/')))
- ++base;
- else
- base = argv0;
+ if (output && !freopen(output, "w", stdout))
+ die("error opening output: %s", strerror(errno));
+
         if (!strcmp(base, "cpp"))
                 onlycpp = 1;
 
- if (output && !freopen(output, "w", stdout))
- die("error opening output: %s", strerror(errno));
+ for (umacro = uvec; *umacro; umacro++)
+ undefmacro(*umacro);
 
         ilex(*argv);
         if (onlycpp) {
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:31 CEST