Allow definition of macros on the command line
authorMichael Spang <mspang@csclub.uwaterloo.ca>
Fri, 11 Dec 2009 22:02:26 +0000 (17:02 -0500)
committerMichael Spang <mspang@csclub.uwaterloo.ca>
Tue, 22 Dec 2009 03:11:47 +0000 (22:11 -0500)
This allows you to run inapt -Dabc, similarly to gcc.

Signed-off-by: Michael Spang <mspang@csclub.uwaterloo.ca>
inapt.cc

index 444608b..08acf1d 100644 (file)
--- a/inapt.cc
+++ b/inapt.cc
@@ -4,6 +4,7 @@
 #include <iostream>
 #include <cstdio>
 #include <fstream>
+#include <set>
 #include <apt-pkg/pkgcache.h>
 #include <apt-pkg/cachefile.h>
 #include <apt-pkg/dpkgdb.h>
@@ -198,9 +199,17 @@ int main(int argc, char *argv[]) {
     int opt;
     char *filename = NULL;
 
+    set<string> defines;
+
     prog = xstrdup(basename(argv[0]));
-    while ((opt = getopt_long(argc, argv, "", opts, NULL)) != -1) {
+    while ((opt = getopt_long(argc, argv, "D:U:", opts, NULL)) != -1) {
         switch (opt) {
+            case 'D':
+                defines.insert(optarg);
+                break;
+            case 'U':
+                defines.erase(optarg);
+                break;
             case '?':
                 usage();
                 break;
@@ -214,6 +223,9 @@ int main(int argc, char *argv[]) {
     else if (argc - optind > 0)
         usage();
 
+    for (set<string>::iterator i = defines.begin(); i != defines.end(); i++)
+        fprintf(stderr, "D: %s\n", i->c_str());
+
     inapt_block context;
 
     pkgInitConfig(*_config);