lucy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mar...@apache.org
Subject [4/5] git commit: Finish switch over to CLI.
Date Wed, 15 Oct 2014 02:28:34 GMT
Finish switch over to CLI.


Project: http://git-wip-us.apache.org/repos/asf/lucy-charmonizer/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy-charmonizer/commit/28b930e1
Tree: http://git-wip-us.apache.org/repos/asf/lucy-charmonizer/tree/28b930e1
Diff: http://git-wip-us.apache.org/repos/asf/lucy-charmonizer/diff/28b930e1

Branch: refs/heads/generic_cli
Commit: 28b930e1b992c774e49e968b4347ae415f272075
Parents: 9311f42
Author: Marvin Humphrey <marvin@rectangular.com>
Authored: Thu Oct 9 18:46:15 2014 -0700
Committer: Marvin Humphrey <marvin@rectangular.com>
Committed: Tue Oct 14 17:48:58 2014 -0700

----------------------------------------------------------------------
 charmonize.c            | 82 ++++----------------------------------------
 src/Charmonizer/Probe.c | 36 ++++---------------
 src/Charmonizer/Probe.h | 19 ++--------
 3 files changed, 17 insertions(+), 120 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy-charmonizer/blob/28b930e1/charmonize.c
----------------------------------------------------------------------
diff --git a/charmonize.c b/charmonize.c
index 6c44c53..a602fea 100644
--- a/charmonize.c
+++ b/charmonize.c
@@ -34,91 +34,23 @@
 #include "Charmonizer/Probe/UnusedVars.h"
 #include "Charmonizer/Probe/VariadicMacros.h"
 #include "Charmonizer/Core/HeaderChecker.h"
+#include "Charmonizer/Core/CLI.h"
 #include "Charmonizer/Core/ConfWriter.h"
 #include "Charmonizer/Core/ConfWriterC.h"
 #include "Charmonizer/Core/ConfWriterPerl.h"
 #include "Charmonizer/Core/ConfWriterRuby.h"
 
-#define MAX_CC_LEN 128
-#define MAX_FLAGS_LEN 2048
-
-struct CLIArgs {
-    char cc_command[MAX_CC_LEN + 1];
-    char cc_flags[MAX_FLAGS_LEN + 1];
-    int  enable_c;
-    int  enable_perl;
-    int  enable_ruby;
-};
-
-/* Parse command line arguments. */
-static void
-S_parse_arguments(int argc, char **argv, struct CLIArgs *args) {
-    int i;
-    int output_enabled = 0;
-
-    /* Parse most args. */
-    for (i = 1; i < argc; i++) {
-        char *arg = argv[i];
-        if (strcmp(arg, "--") == 0) {
-            /* From here on out, everything will be a compiler flag. */
-            i++;
-            break;
-        }
-        if (strcmp(arg, "--enable-c") == 0) {
-            args->enable_c = 1;
-            output_enabled = 1;
-        }
-        else if (strcmp(arg, "--enable-perl") == 0) {
-            args->enable_perl = 1;
-            output_enabled = 1;
-        }
-        else if (strcmp(arg, "--enable-ruby") == 0) {
-            args->enable_ruby = 1;
-            output_enabled = 1;
-        }
-        else if (memcmp(arg, "--cc=", 5) == 0) {
-            if (strlen(arg) > MAX_CC_LEN - 5) {
-                fprintf(stderr, "Exceeded max length for compiler command");
-                exit(1);
-            }
-            strcpy(args->cc_command, arg + 5);
-        }
-    }
-
-    /* Accumulate compiler flags. */
-    for (; i < argc; i++) {
-        char *arg = argv[i];
-        if (strlen(arg) + strlen(args->cc_flags) + 2 >= MAX_FLAGS_LEN) {
-            fprintf(stderr, "Exceeded max length for compiler flags");
-            exit(1);
-        }
-        strcat(args->cc_flags, " ");
-        strcat(args->cc_flags, arg);
-
-    }
-
-    /* Validate. */
-    if (!args->cc_command
-        || !strlen(args->cc_command)
-        || !output_enabled
-       ) {
-        fprintf(stderr,
-                "Usage: ./charmonize --cc=CC_COMMAND [--enable-c] "
-                "[--enable-perl] [--enable-ruby] -- CC_FLAGS\n");
-        exit(1);
-    }
-
-}
-
 int main(int argc, const char **argv) {
     /* Initialize. */
     {
-        struct chaz_CLIArgs args;
-        int result = chaz_Probe_parse_cli_args(argc, argv, &args);
+        chaz_CLI *cli = chaz_CLI_new(argv[0], NULL);
+        int result = chaz_Probe_parse_cli_args(argc, argv, cli);
         if (!result) {
-            chaz_Probe_die_usage();
+            fprintf(stderr, chaz_CLI_help(cli));
+            exit(1);
         }
-        chaz_Probe_init(&args);
+        chaz_Probe_init(cli);
+        chaz_CLI_destroy(cli);
     }
 
     /* Run probe modules. */

http://git-wip-us.apache.org/repos/asf/lucy-charmonizer/blob/28b930e1/src/Charmonizer/Probe.c
----------------------------------------------------------------------
diff --git a/src/Charmonizer/Probe.c b/src/Charmonizer/Probe.c
index 93b744c..cdd8042 100644
--- a/src/Charmonizer/Probe.c
+++ b/src/Charmonizer/Probe.c
@@ -32,13 +32,9 @@
 #include "Charmonizer/Core/OperatingSystem.h"
 
 int
-chaz_Probe_parse_cli_args(int argc, const char *argv[],
-                          struct chaz_CLIArgs *args) {
+chaz_Probe_parse_cli_args(int argc, const char *argv[], chaz_CLI *cli) {
     int i;
     int output_enabled = 0;
-    chaz_CLI *cli
-        = chaz_CLI_new(argv[0], "charmonizer: Probe C compiler environment");
-    chaz_CLI_set_usage(cli, "Usage: charmonizer [OPTIONS] [-- [CFLAGS]]");
 
     /* Register Charmonizer-specific options. */
     chaz_CLI_register(cli, "enable-c", "generate charmony.h", CHAZ_CLI_NO_ARG);
@@ -127,24 +123,6 @@ chaz_Probe_parse_cli_args(int argc, const char *argv[],
         return false;
     }
 
-    /* Zero out args struct. */
-    memset(args, 0, sizeof(struct chaz_CLIArgs));
-
-    /* Copy to CLIArgs struct.  TODO: This code will be going away shortly. */
-    args->charmony_h     = chaz_CLI_defined(cli, "enable-c");
-    args->charmony_pm    = chaz_CLI_defined(cli, "enable-perl");
-    args->charmony_py    = chaz_CLI_defined(cli, "enable-python");
-    args->charmony_rb    = chaz_CLI_defined(cli, "enable-ruby");
-    args->write_makefile = chaz_CLI_defined(cli, "enable-makefile");
-    args->code_coverage  = chaz_CLI_defined(cli, "enable-coverage");
-    if (chaz_CLI_defined(cli, "cc")) {
-        strcpy(args->cc, chaz_CLI_strval(cli, "cc"));
-    }
-    if (chaz_CLI_defined(cli, "verbosity")) {
-        args->verbosity = (int)chaz_CLI_longval(cli, "verbosity");
-    }
-
-    chaz_CLI_destroy(cli);
     return true;
 }
 
@@ -157,7 +135,7 @@ chaz_Probe_die_usage(void) {
 }
 
 void
-chaz_Probe_init(struct chaz_CLIArgs *args) {
+chaz_Probe_init(struct chaz_CLI *cli) {
     int output_enabled = 0;
 
     {
@@ -170,25 +148,25 @@ chaz_Probe_init(struct chaz_CLIArgs *args) {
 
     /* Dispatch other initializers. */
     chaz_OS_init();
-    chaz_CC_init(args->cc, args->cflags);
+    chaz_CC_init(chaz_CLI_strval(cli, "cc"), chaz_CLI_strval(cli, "cflags"));
     chaz_ConfWriter_init();
     chaz_HeadCheck_init();
     chaz_Make_init();
 
     /* Enable output. */
-    if (args->charmony_h) {
+    if (chaz_CLI_defined(cli, "enable-c")) {
         chaz_ConfWriterC_enable();
         output_enabled = true;
     }
-    if (args->charmony_pm) {
+    if (chaz_CLI_defined(cli, "enable-perl")) {
         chaz_ConfWriterPerl_enable();
         output_enabled = true;
     }
-    if (args->charmony_py) {
+    if (chaz_CLI_defined(cli, "enable-python")) {
         chaz_ConfWriterPython_enable();
         output_enabled = true;
     }
-    if (args->charmony_rb) {
+    if (chaz_CLI_defined(cli, "enable-ruby")) {
         chaz_ConfWriterRuby_enable();
         output_enabled = true;
     }

http://git-wip-us.apache.org/repos/asf/lucy-charmonizer/blob/28b930e1/src/Charmonizer/Probe.h
----------------------------------------------------------------------
diff --git a/src/Charmonizer/Probe.h b/src/Charmonizer/Probe.h
index 6323503..3ce92d0 100644
--- a/src/Charmonizer/Probe.h
+++ b/src/Charmonizer/Probe.h
@@ -24,20 +24,7 @@ extern "C" {
 #include <stddef.h>
 #include <stdio.h>
 
-#define CHAZ_PROBE_MAX_CC_LEN 100
-#define CHAZ_PROBE_MAX_CFLAGS_LEN 2000
-
-struct chaz_CLIArgs {
-    char cc[CHAZ_PROBE_MAX_CC_LEN + 1];
-    char cflags[CHAZ_PROBE_MAX_CFLAGS_LEN + 1];
-    int  charmony_h;
-    int  charmony_pm;
-    int  charmony_py;
-    int  charmony_rb;
-    int  verbosity;
-    int  write_makefile;
-    int  code_coverage;
-};
+struct chaz_CLI;
 
 /* Parse command line arguments, initializing and filling in the supplied
  * `args` struct.
@@ -54,7 +41,7 @@ struct chaz_CLIArgs {
  */
 int
 chaz_Probe_parse_cli_args(int argc, const char *argv[],
-                          struct chaz_CLIArgs *args);
+                          struct chaz_CLI *cli);
 
 /* Exit after printing usage instructions to stderr.
  */
@@ -71,7 +58,7 @@ chaz_Probe_die_usage(void);
  *      2 - debugging
  */
 void
-chaz_Probe_init(struct chaz_CLIArgs *args);
+chaz_Probe_init(struct chaz_CLI *cli);
 
 /* Clean up the Charmonizer environment -- deleting tempfiles, etc.  This
  * should be called only after everything else finishes.


Mime
View raw message