forked from osmocom/wireshark
dftest: Add -h and improve output format
Experiment with removing the type from the instruction output. This information is also available with the -s option flag. Rename -t to -s.
This commit is contained in:
parent
e77d716411
commit
df30299aff
28
dftest.c
28
dftest.c
|
@ -38,6 +38,7 @@
|
|||
#include "ui/util.h"
|
||||
#include "ui/cmdarg_err.h"
|
||||
#include "ui/failure_message.h"
|
||||
#include "ui/version_info.h"
|
||||
|
||||
static void dftest_cmdarg_err(const char *fmt, va_list ap);
|
||||
static void dftest_cmdarg_err_cont(const char *fmt, va_list ap);
|
||||
|
@ -67,11 +68,12 @@ print_usage(void)
|
|||
{
|
||||
fprintf(stderr, "Usage: dftest [OPTIONS] -- <EXPR>\n");
|
||||
fprintf(stderr, "\nOptions:\n");
|
||||
fprintf(stderr, " -v Verbose mode\n");
|
||||
fprintf(stderr, " -d Enable verbose display filter logs\n");
|
||||
fprintf(stderr, " -f Enable Flex debug trace\n");
|
||||
fprintf(stderr, " -l Enable Lemon debug trace\n");
|
||||
fprintf(stderr, " -t Print syntax tree\n");
|
||||
fprintf(stderr, " -v verbose mode\n");
|
||||
fprintf(stderr, " -d enable noisy display filter logs\n");
|
||||
fprintf(stderr, " -f enable Flex debug trace\n");
|
||||
fprintf(stderr, " -l enable Lemon debug trace\n");
|
||||
fprintf(stderr, " -s print syntax tree\n");
|
||||
fprintf(stderr, " -h display this help and exit\n");
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -161,7 +163,9 @@ main(int argc, char **argv)
|
|||
setlocale(LC_ALL, "");
|
||||
#endif
|
||||
|
||||
while ((opt = ws_getopt(argc, argv, "vdflt")) != -1) {
|
||||
ws_init_version_info("DFTest", NULL, NULL);
|
||||
|
||||
while ((opt = ws_getopt(argc, argv, "vdflsh")) != -1) {
|
||||
switch (opt) {
|
||||
case 'v':
|
||||
opt_verbose = 1;
|
||||
|
@ -175,10 +179,14 @@ main(int argc, char **argv)
|
|||
case 'l':
|
||||
opt_lemon = 1;
|
||||
break;
|
||||
case 't':
|
||||
case 's':
|
||||
opt_syntax_tree = 1;
|
||||
break;
|
||||
case 'h':
|
||||
/* fall-through */
|
||||
default: /* '?' */
|
||||
show_help_header(NULL);
|
||||
printf("\n");
|
||||
print_usage();
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
@ -248,7 +256,7 @@ main(int argc, char **argv)
|
|||
/* Get filter text */
|
||||
text = get_args_as_string(argc, argv, ws_optind);
|
||||
|
||||
printf("Filter: %s\n\n", text);
|
||||
printf("Filter:\n %s\n\n", text);
|
||||
|
||||
timer = g_timer_new();
|
||||
|
||||
|
@ -265,11 +273,11 @@ main(int argc, char **argv)
|
|||
}
|
||||
|
||||
if (strcmp(text, expanded_text) != 0)
|
||||
printf("Filter after expansion: %s\n\n", expanded_text);
|
||||
printf("Filter (after expansion):\n %s\n\n", expanded_text);
|
||||
|
||||
/* Compile it */
|
||||
if (opt_syntax_tree)
|
||||
df_flags = DF_SAVE_TREE;
|
||||
df_flags |= DF_SAVE_TREE;
|
||||
if (opt_flex)
|
||||
df_flags |= DF_DEBUG_FLEX;
|
||||
if (opt_lemon)
|
||||
|
|
|
@ -210,26 +210,20 @@ dfvm_value_new_guint(guint num)
|
|||
static char *
|
||||
dfvm_value_tostr(dfvm_value_t *v)
|
||||
{
|
||||
char *s, *aux;
|
||||
char *s;
|
||||
|
||||
if (!v)
|
||||
return NULL;
|
||||
|
||||
switch (v->type) {
|
||||
case HFINFO:
|
||||
s = ws_strdup_printf("%s <%s>",
|
||||
v->value.hfinfo->abbrev,
|
||||
ftype_name(v->value.hfinfo->type));
|
||||
s = ws_strdup(v->value.hfinfo->abbrev);
|
||||
break;
|
||||
case RAW_HFINFO:
|
||||
s = ws_strdup_printf("@%s <FT_BYTES>",
|
||||
v->value.hfinfo->abbrev);
|
||||
s = ws_strdup_printf("@%s", v->value.hfinfo->abbrev);
|
||||
break;
|
||||
case FVALUE:
|
||||
aux = fvalue_to_debug_repr(NULL, v->value.fvalue);
|
||||
s = ws_strdup_printf("%s <%s>",
|
||||
aux, fvalue_type_name(v->value.fvalue));
|
||||
g_free(aux);
|
||||
s = fvalue_to_debug_repr(NULL, v->value.fvalue);
|
||||
break;
|
||||
case DRANGE:
|
||||
s = drange_tostr(v->value.drange);
|
||||
|
@ -238,7 +232,7 @@ dfvm_value_tostr(dfvm_value_t *v)
|
|||
s = ws_strdup(ws_regex_pattern(v->value.pcre));
|
||||
break;
|
||||
case REGISTER:
|
||||
s = ws_strdup_printf("reg#%"G_GUINT32_FORMAT, v->value.numeric);
|
||||
s = ws_strdup_printf("R%"G_GUINT32_FORMAT, v->value.numeric);
|
||||
break;
|
||||
case FUNCTION_DEF:
|
||||
s = ws_strdup(v->value.funcdef->name);
|
||||
|
@ -278,9 +272,9 @@ append_op(wmem_strbuf_t *buf, int id, dfvm_opcode_t opcode)
|
|||
{
|
||||
char *str;
|
||||
size_t len;
|
||||
#define INDENT_COLUMN 22
|
||||
#define INDENT_COLUMN 24
|
||||
|
||||
str = ws_strdup_printf("%04d %s ", id, dfvm_opcode_tostr(opcode));
|
||||
str = ws_strdup_printf(" %04d %s ", id, dfvm_opcode_tostr(opcode));
|
||||
wmem_strbuf_append(buf, str);
|
||||
len = strlen(str);
|
||||
g_free(str);
|
||||
|
@ -293,7 +287,7 @@ static void
|
|||
append_to_register(wmem_strbuf_t *buf, const char *reg)
|
||||
{
|
||||
if (reg != NULL) {
|
||||
wmem_strbuf_append(buf, " --> ");
|
||||
wmem_strbuf_append(buf, " -> ");
|
||||
wmem_strbuf_append(buf, reg);
|
||||
}
|
||||
wmem_strbuf_append_c(buf, '\n');
|
||||
|
|
|
@ -564,10 +564,11 @@ show_version(void)
|
|||
void
|
||||
show_help_header(const char *description)
|
||||
{
|
||||
printf("%s\n"
|
||||
"%s\n"
|
||||
"See https://www.wireshark.org for more information.\n",
|
||||
appname_with_version, description);
|
||||
printf("%s\n", appname_with_version);
|
||||
if (description) {
|
||||
printf("%s\n", description);
|
||||
printf("See https://www.wireshark.org for more information.\n");
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
Loading…
Reference in New Issue