[hackers] [scc] Add option -D option to cc1 || Roberto E. Vargas Caballero

From: <git_AT_suckless.org>
Date: Mon, 5 Oct 2015 22:38:38 +0200 (CEST)

commit bcc4c2b84232c42faead193fc05879867f7dc7f2
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Mon Oct 5 22:37:45 2015 +0200
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
CommitDate: Mon Oct 5 22:37:45 2015 +0200

    Add option -D option to cc1
    
    This option allows define a variable to the user.

diff --git a/cc1/cc1.h b/cc1/cc1.h
index 7da3ea7..e4ce5dd 100644
--- a/cc1/cc1.h
+++ b/cc1/cc1.h
_AT_@ -401,6 +401,7 @@ extern bool cpp(void);
 extern bool expand(char *begin, Symbol *sym);
 extern void incdir(char *dir);
 extern void outcpp(void);
+extern Symbol *defmacro(char *s);
 
 /*
  * Definition of global variables
diff --git a/cc1/cpp.c b/cc1/cpp.c
index ca4f47a..b20ba9a 100644
--- a/cc1/cpp.c
+++ b/cc1/cpp.c
_AT_@ -25,10 +25,17 @@ static char **dirinclude;
 unsigned cppctx;
 int disexpand;
 
-static Symbol *
+Symbol *
 defmacro(char *s)
 {
- return install(NS_CPP, lookup(NS_CPP, s));
+ char *p;
+ Symbol *sym;
+
+ if ((p = strchr(s, '=')) != NULL)
+ *p++='\0';
+ sym = install(NS_CPP, lookup(NS_CPP, s));
+ sym->u.s = p;
+ return sym;
 }
 
 void
diff --git a/cc1/main.c b/cc1/main.c
index 2ead794..ff2616b 100644
--- a/cc1/main.c
+++ b/cc1/main.c
_AT_@ -28,7 +28,7 @@ static void
 usage(void)
 {
         fprintf(stderr,
- "usage: %s [-E] [-Idir] [-w] [-d] [-o output] [input]\n",
+ "usage: %s [-E] [-Dmacro[=value]] [-Idir] [-w] [-d] [-o output] [input]\n",
                 arg0);
         exit(1);
 }
_AT_@ -43,6 +43,7 @@ main(int argc, char *argv[])
         arg0 = (cp = strrchr(*argv, '/')) ? cp+1 : *argv;
         if (!strcmp(arg0, "cpp"))
                 onlycpp = 1;
+
         for (;;) {
         nextiter:
                 --argc, ++argv;
_AT_@ -56,6 +57,9 @@ main(int argc, char *argv[])
                         case 'E':
                                 onlycpp = 1;
                                 break;
+ case 'D':
+ defmacro(cp+1);
+ goto nextiter;
                         case 'd':
                                 DBGON();
                                 break;
Received on Mon Oct 05 2015 - 22:38:38 CEST

This archive was generated by hypermail 2.3.0 : Mon Oct 05 2015 - 22:48:14 CEST