forked from osmocom/wireshark
dftest: Add -0 option (no optimization)
This commit is contained in:
parent
ff7bab1730
commit
9d7b461a16
42
dftest.c
42
dftest.c
|
@ -46,6 +46,7 @@ static int opt_flex = 0;
|
|||
static int opt_lemon = 0;
|
||||
static int opt_syntax_tree = 0;
|
||||
static int opt_timer = 0;
|
||||
static long opt_optimize = 1;
|
||||
|
||||
static gdouble elapsed_expand = 0;
|
||||
static gdouble elapsed_compile = 0;
|
||||
|
@ -85,10 +86,11 @@ putloc(FILE *fp, df_loc_t loc)
|
|||
fputc('\n', fp);
|
||||
}
|
||||
|
||||
static void
|
||||
print_usage(void)
|
||||
WS_NORETURN static void
|
||||
print_usage(int status)
|
||||
{
|
||||
FILE *fp = stdout;
|
||||
fprintf(fp, "\n");
|
||||
fprintf(fp, "Usage: dftest [OPTIONS] -- EXPRESSION\n");
|
||||
fprintf(fp, "Options:\n");
|
||||
fprintf(fp, " -V, --verbose enable verbose mode\n");
|
||||
|
@ -97,8 +99,10 @@ print_usage(void)
|
|||
fprintf(fp, " -l, --lemon enable Lemon debug trace\n");
|
||||
fprintf(fp, " -s, --syntax print syntax tree\n");
|
||||
fprintf(fp, " -t, --timer print elapsed compilation time\n");
|
||||
fprintf(fp, " -0, --optimize=0 do not optimize (check syntax)\n");
|
||||
fprintf(fp, " -h, --help display this help and exit\n");
|
||||
fprintf(fp, " -v, --version print version\n");
|
||||
exit(status);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -166,7 +170,8 @@ compile_filter(const char *text, dfilter_t **dfp, GTimer *timer)
|
|||
gboolean ok;
|
||||
df_error_t *df_err = NULL;
|
||||
|
||||
df_flags |= DF_OPTIMIZE;
|
||||
if (opt_optimize > 0)
|
||||
df_flags |= DF_OPTIMIZE;
|
||||
if (opt_syntax_tree)
|
||||
df_flags |= DF_SAVE_TREE;
|
||||
if (opt_flex)
|
||||
|
@ -222,7 +227,7 @@ main(int argc, char **argv)
|
|||
|
||||
ws_init_version_info("DFTest", NULL, NULL);
|
||||
|
||||
const char *optstring = "hvdflsVt";
|
||||
const char *optstring = "hvdflstV0";
|
||||
static struct ws_option long_options[] = {
|
||||
{ "help", ws_no_argument, 0, 'h' },
|
||||
{ "version", ws_no_argument, 0, 'v' },
|
||||
|
@ -232,6 +237,7 @@ main(int argc, char **argv)
|
|||
{ "syntax", ws_no_argument, 0, 's' },
|
||||
{ "timer", ws_no_argument, 0, 't' },
|
||||
{ "verbose", ws_no_argument, 0, 'V' },
|
||||
{ "optimize", ws_required_argument, 0, 1000 },
|
||||
{ NULL, 0, 0, 0 }
|
||||
};
|
||||
int opt;
|
||||
|
@ -260,20 +266,31 @@ main(int argc, char **argv)
|
|||
case 't':
|
||||
opt_timer = 1;
|
||||
break;
|
||||
case '0':
|
||||
opt_optimize = 0;
|
||||
break;
|
||||
case 1000:
|
||||
if (strlen(ws_optarg) > 1 || !g_ascii_isdigit(*ws_optarg)) {
|
||||
printf("Error: \"%s\" is not a valid number 0-9\n", ws_optarg);
|
||||
print_usage(EXIT_FAILURE);
|
||||
}
|
||||
errno = 0;
|
||||
opt_optimize = strtol(ws_optarg, NULL, 10);
|
||||
if (errno) {
|
||||
printf("Error: %s\n", g_strerror(errno));
|
||||
print_usage(EXIT_FAILURE);
|
||||
}
|
||||
break;
|
||||
case 'v':
|
||||
show_help_header(NULL);
|
||||
exit(EXIT_SUCCESS);
|
||||
break;
|
||||
case 'h':
|
||||
show_help_header(NULL);
|
||||
printf("\n");
|
||||
print_usage();
|
||||
exit(EXIT_SUCCESS);
|
||||
print_usage(EXIT_SUCCESS);
|
||||
break;
|
||||
case '?':
|
||||
printf("\n");
|
||||
print_usage();
|
||||
exit(EXIT_FAILURE);
|
||||
print_usage(EXIT_FAILURE);
|
||||
default:
|
||||
ws_assert_not_reached();
|
||||
}
|
||||
|
@ -281,9 +298,8 @@ main(int argc, char **argv)
|
|||
|
||||
/* Check for filter on command line */
|
||||
if (argv[ws_optind] == NULL) {
|
||||
printf("Error: Missing argument.\n\n");
|
||||
print_usage();
|
||||
exit(EXIT_FAILURE);
|
||||
printf("Error: Missing argument.\n");
|
||||
print_usage(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (opt_noisy)
|
||||
|
|
Loading…
Reference in New Issue