diff --git a/dftest.c b/dftest.c index 5ed088f87e..81090ecf6e 100644 --- a/dftest.c +++ b/dftest.c @@ -31,6 +31,7 @@ #include #include #include +#include #include @@ -45,14 +46,6 @@ static int debug_noisy = 0; static int debug_flex = 0; static int debug_lemon = 0; -static GOptionEntry entries[] = -{ - { "debug", 'd', 0, G_OPTION_ARG_NONE, &debug_noisy, "Enable verbose debug logs", NULL }, - { "debug-flex", 'f', 0, G_OPTION_ARG_NONE, &debug_flex, "Enable debugging for Flex", NULL }, - { "debug-lemon", 'l', 0, G_OPTION_ARG_NONE, &debug_lemon, "Enable debugging for Lemon", NULL }, - { NULL, 0, 0, G_OPTION_ARG_NONE, NULL, "", NULL } -}; - static void putloc(FILE *fp, df_loc_t loc) { @@ -67,6 +60,12 @@ putloc(FILE *fp, df_loc_t loc) fputc('\n', fp); } +static void +print_usage(void) +{ + fprintf(stderr, "Usage: dftest [OPTIONS] -- \n"); +} + int main(int argc, char **argv) { @@ -93,8 +92,7 @@ main(int argc, char **argv) gdouble elapsed_expand, elapsed_compile; gboolean ok; int exit_status = 0; - GError *error = NULL; - GOptionContext *context; + int opt; cmdarg_err_init(dftest_cmdarg_err, dftest_cmdarg_err_cont); @@ -116,12 +114,21 @@ main(int argc, char **argv) setlocale(LC_ALL, ""); #endif - context = g_option_context_new("EXPR"); - g_option_context_add_main_entries(context, entries, NULL); - if (!g_option_context_parse(context, &argc, &argv, &error)) { - printf("Error parsing arguments: %s\n", error->message); - g_error_free(error); - exit(1); + while ((opt = ws_getopt(argc, argv, "dfl")) != -1) { + switch (opt) { + case 'd': + debug_noisy = 1; + break; + case 'f': + debug_flex = 1; + break; + case 'l': + debug_lemon = 1; + break; + default: /* '?' */ + print_usage(); + exit(EXIT_FAILURE); + } } if (debug_noisy) @@ -171,17 +178,22 @@ main(int argc, char **argv) prefs_apply_all(); /* Check for filter on command line */ - if (argc <= 1) { - char *help = g_option_context_get_help(context, TRUE, NULL); - fprintf(stderr, "%s", help); - g_free(help); - goto out; + if (argv[ws_optind] == NULL) { + print_usage(); + exit(1); } - timer = g_timer_new(); + /* This is useful to prevent confusion with option parsing. + * Skips printing options and argv[0]. */ + for (int i = ws_optind; i < argc; i++) { + printf("argv[%d]: %s\n", i, argv[i]); + } + printf("\n"); /* Get filter text */ - text = get_args_as_string(argc, argv, 1); + text = get_args_as_string(argc, argv, ws_optind); + + timer = g_timer_new(); /* Expand macros. */ g_timer_start(timer); @@ -244,7 +256,6 @@ out: g_free(expanded_text); if (timer != NULL) g_timer_destroy(timer); - g_option_context_free(context); exit(exit_status); } diff --git a/test/suite_dfilter/dfiltertest.py b/test/suite_dfilter/dfiltertest.py index 9f65ef1b3a..ca2f9860be 100644 --- a/test/suite_dfilter/dfiltertest.py +++ b/test/suite_dfilter/dfiltertest.py @@ -67,7 +67,7 @@ def checkDFilterCountWithSelectedFrame(dfilter_cmd, base_env): def checkDFilterFail(cmd_dftest, base_env): def checkDFilterFail_real(dfilter, error_message): """Run a display filter and expect dftest to fail.""" - proc = subprocess.Popen([cmd_dftest, dfilter], + proc = subprocess.Popen([cmd_dftest, '--', dfilter], stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True, @@ -84,7 +84,7 @@ def checkDFilterFail(cmd_dftest, base_env): def checkDFilterSucceed(cmd_dftest, base_env): def checkDFilterSucceed_real(dfilter, expect_stdout=None): """Run a display filter and expect dftest to succeed.""" - proc = subprocess.Popen([cmd_dftest, dfilter], + proc = subprocess.Popen([cmd_dftest, '--', dfilter], stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True,