[hackers] [scc] [cc1] Implement -M flag || Roberto E. Vargas Caballero

From: <git_AT_suckless.org>
Date: Wed, 25 Jan 2017 15:57:34 +0100 (CET)

commit 399b69db4783a278f4e69a560b5bbc1b325761ee
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Wed Jan 25 15:13:57 2017 +0100
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
CommitDate: Wed Jan 25 15:53:55 2017 +0100

    [cc1] Implement -M flag
    
    This flag enables the inclusion mode where cc1 only prints
    the inclusion dependencies of the input file.

diff --git a/cc1/cc1.h b/cc1/cc1.h
index 13c6d44..1a9e3c5 100644
--- a/cc1/cc1.h
+++ b/cc1/cc1.h
_AT_@ -453,9 +453,11 @@ extern unsigned short yylen;
 extern int disexpand;
 extern unsigned cppctx;
 extern Input *input;
-extern int lexmode, namespace, onlycpp;
+extern int lexmode, namespace;
+extern int onlycpp, onlyheader;
 extern unsigned curctx;
 extern Symbol *curfun, *zero, *one;
+extern char *infile, *outfile;
 
 extern Type *voidtype, *pvoidtype, *booltype,
             *uchartype, *chartype, *schartype,
diff --git a/cc1/code.c b/cc1/code.c
index 38a5f0e..f4ef599 100644
--- a/cc1/code.c
+++ b/cc1/code.c
_AT_@ -159,7 +159,7 @@ emit(unsigned op, void *arg)
 {
         extern int failure;
 
- if (failure || onlycpp)
+ if (failure || onlycpp || onlyheader)
                 return;
         (*opcode[op])(op, arg);
 }
diff --git a/cc1/cpp.c b/cc1/cpp.c
index 2fa22ed..30b59ea 100644
--- a/cc1/cpp.c
+++ b/cc1/cpp.c
_AT_@ -788,6 +788,8 @@ outcpp(void)
         char c, *s, *t;
 
         for (next(); yytoken != EOFTOK; next()) {
+ if (onlyheader)
+ continue;
                 if (yytoken != STRING) {
                         printf("%s ", yytext);
                         continue;
diff --git a/cc1/lex.c b/cc1/lex.c
index d2e7ef5..dc17712 100644
--- a/cc1/lex.c
+++ b/cc1/lex.c
_AT_@ -89,6 +89,8 @@ addinput(char *fname, Symbol *hide, char *buffer)
                 if ((fp = fopen(fname, "r")) == NULL)
                         return 0;
                 flags = IFILE;
+ if (input && onlyheader)
+ printf("%s: %s\n", infile, fname);
         } else {
                 /* reading from stdin */
                 fp = stdin;
diff --git a/cc1/main.c b/cc1/main.c
index 020d557..40e836e 100644
--- a/cc1/main.c
+++ b/cc1/main.c
_AT_@ -10,22 +10,22 @@ static char sccsid[] = "@(#) ./cc1/main.c";
 #include "../inc/cc.h"
 #include "cc1.h"
 
-char *argv0;
+char *argv0, *infile, *outfile;
 
 int warnings;
 jmp_buf recover;
 
-static char *output;
 static struct items uflags;
-int onlycpp;
+int onlycpp, onlyheader;
+
 
 extern int failure;
 
 static void
 clean(void)
 {
- if (failure && output)
- remove(output);
+ if (failure && outfile)
+ remove(outfile);
 }
 
 static void
_AT_@ -62,6 +62,9 @@ main(int argc, char *argv[])
         case 'D':
                 defmacro(EARGF(usage()));
                 break;
+ case 'M':
+ onlyheader = 1;
+ break;
         case 'E':
                 onlycpp = 1;
                 break;
_AT_@ -75,7 +78,7 @@ main(int argc, char *argv[])
                 DBGON();
                 break;
         case 'o':
- output = EARGF(usage());
+ outfile = EARGF(usage());
                 break;
         case 'w':
                 warnings = 1;
_AT_@ -87,17 +90,18 @@ main(int argc, char *argv[])
         if (argc > 1)
                 usage();
 
- if (output && !freopen(output, "w", stdout))
+ if (outfile && !freopen(outfile, "w", stdout))
                 die("error opening output: %s", strerror(errno));
 
         for (i = 0; i < uflags.n; ++i)
                 undefmacro(uflags.s[i]);
 
+ infile = (*argv) ? *argv : "<stdin>";
         if (!addinput(*argv, NULL, NULL)) {
                 die("error: failed to open input file '%s': %s",
                     *argv, strerror(errno));
         }
- if (onlycpp) {
+ if (onlycpp || onlyheader) {
                 outcpp();
         } else {
                 for (next(); yytoken != EOFTOK; decl())
diff --git a/driver/posix/scc.c b/driver/posix/scc.c
index 3baec99..5107a14 100644
--- a/driver/posix/scc.c
+++ b/driver/posix/scc.c
_AT_@ -54,7 +54,7 @@ static char *arch, *execpath, *objfile, *outfile;
 static char *tmpdir;
 static size_t tmpdirln;
 static struct items objtmp, objout;
-static int Eflag, Sflag, cflag, kflag, sflag;
+static int Mflag, Eflag, Sflag, cflag, kflag, sflag;
 
 extern int failure;
 
_AT_@ -326,7 +326,7 @@ buildfile(char *file, int tool)
         for (; tool < LAST_TOOL; tool = nexttool) {
                 switch (tool) {
                 case CC1:
- if (Eflag)
+ if (Eflag || Mflag)
                                 nexttool = LAST_TOOL;
                         else
                                 nexttool = kflag ? TEEIR : CC2;
_AT_@ -400,10 +400,10 @@ usage(void)
 {
         die("usage: scc [-D def[=val]]... [-U def]... [-I dir]... "
             "[-L dir]... [-l dir]...\n"
- " [-gksw] [-m arch] [-E|-S] [-o outfile] file...\n"
+ " [-gksw] [-m arch] [-M|-E|-S] [-o outfile] file...\n"
             " scc [-D def[=val]]... [-U def]... [-I dir]... "
             "[-L dir]... [-l dir]...\n"
- " [-gksw] [-m arch] [-E|-S] -c file...\n"
+ " [-gksw] [-m arch] [-M|-E|-S] -c file...\n"
             " scc [-D def[=val]]... [-U def]... [-I dir]... "
             "[-L dir]... [-l dir]...\n"
             " [-gksw] [-m arch] -c -o outfile file");
_AT_@ -427,6 +427,10 @@ main(int argc, char *argv[])
                 addarg(CC1, "-D");
                 addarg(CC1, EARGF(usage()));
                 break;
+ case 'M':
+ Mflag = 1;
+ addarg(CC1, "-M");
+ break;
         case 'E':
                 Eflag = 1;
                 addarg(CC1, "-E");
_AT_@ -486,7 +490,9 @@ operand:
         for (; *argv; --argc, ++argv)
                 goto operand;
 
- if (Eflag && (Sflag || kflag) || linkchain.n == 0 ||
+ if (Eflag && Mflag ||
+ (Eflag || Mflag) && (Sflag || kflag) ||
+ linkchain.n == 0 ||
             linkchain.n > 1 && cflag && outfile)
                 usage();
 
_AT_@ -494,7 +500,7 @@ operand:
                 tmpdir = ".";
         tmpdirln = strlen(tmpdir);
 
- build(&linkchain, (link = !(Eflag || Sflag || cflag)));
+ build(&linkchain, (link = !(Mflag || Eflag || Sflag || cflag)));
 
         if (!(link || cflag))
                 return failure;
Received on Wed Jan 25 2017 - 15:57:34 CET

This archive was generated by hypermail 2.3.0 : Wed Jan 25 2017 - 16:00:21 CET