diff options
author | João Valverde <joao.valverde@tecnico.ulisboa.pt> | 2017-11-23 02:42:05 +0000 |
---|---|---|
committer | João Valverde <j@v6e.pt> | 2017-11-23 12:09:55 +0000 |
commit | b6f5ee68f646715db094e55aa33b0810d0da1814 (patch) | |
tree | 7c3250fdd1cfd4f0716b047b34809e17dd3b04a8 | |
parent | db811a699d3238425a22f6b8b129c259e97262cf (diff) |
make-dissectors: Don't use stdout
This will prevent the file from being created with shell redirection
in case of error and allow printing informational messages to stdout
instead of stderr.
Also improve dissectorc.c Makefile recipe to abort on errors.
Change-Id: I64722927721887b57a7dbe69fd2625c2e4648ad4
Reviewed-on: https://code.wireshark.org/review/24545
Petri-Dish: João Valverde <j@v6e.pt>
Reviewed-by: João Valverde <j@v6e.pt>
-rw-r--r-- | epan/dissectors/CMakeLists.txt | 3 | ||||
-rw-r--r-- | epan/dissectors/Makefile.am | 8 | ||||
-rw-r--r-- | epan/dissectors/make-dissectors.c | 50 |
3 files changed, 44 insertions, 17 deletions
diff --git a/epan/dissectors/CMakeLists.txt b/epan/dissectors/CMakeLists.txt index 588484a6be..6ef31ee216 100644 --- a/epan/dissectors/CMakeLists.txt +++ b/epan/dissectors/CMakeLists.txt @@ -1873,8 +1873,7 @@ file(GENERATE ) add_custom_command( OUTPUT dissectors.c - COMMAND make-dissectors @dissectors.c.in - > dissectors.c + COMMAND make-dissectors dissectors.c @dissectors.c.in DEPENDS make-dissectors ${ALL_DISSECTOR_SRC} COMMENT "Making dissectors.c" ) diff --git a/epan/dissectors/Makefile.am b/epan/dissectors/Makefile.am index 5a4b231c10..f7d72c7b96 100644 --- a/epan/dissectors/Makefile.am +++ b/epan/dissectors/Makefile.am @@ -1942,9 +1942,11 @@ x11-dissector: $(top_srcdir)/tools/process-x11-fields.pl $(srcdir)/x11-fields $( # dissectors.c: make-dissectors $(ALL_DISSECTORS_SRC) @echo Making dissectors.c - @echo $(filter %.c,$^) > $@.in ; \ - $(builddir)/make-dissectors @$@.in > $@ ; \ - rm $@.in + @echo $(filter %.c,$^) > $@.in && \ + $(builddir)/make-dissectors $@ @$@.in + +MOSTLYCLEANFILES = \ + dissectors.c.in DISTCLEANFILES = \ $(NODIST_GENERATED_FILES) diff --git a/epan/dissectors/make-dissectors.c b/epan/dissectors/make-dissectors.c index 24e4864702..f8c4d51b85 100644 --- a/epan/dissectors/make-dissectors.c +++ b/epan/dissectors/make-dissectors.c @@ -11,6 +11,7 @@ #include <stdlib.h> #include <stdio.h> #include <string.h> +#include <errno.h> #include <glib.h> #define ARRAY_RESERVED_SIZE 2048 @@ -68,6 +69,12 @@ int main(int argc, char **argv) GPtrArray *protos = NULL, *handoffs = NULL; GError *err = NULL; guint i; + FILE *out; + + if (argc < 3) { + fprintf(stderr, "Usage: %s <outfile> <infiles...>\n", argv[0]); + exit(1); + } #if GLIB_CHECK_VERSION(2, 30, 0) protos = g_ptr_array_new_full(ARRAY_RESERVED_SIZE, g_free); @@ -92,7 +99,7 @@ int main(int argc, char **argv) exit(1); } - for (int arg = 1; arg < argc; arg++) { + for (int arg = 2; arg < argc; arg++) { if (argv[arg][0] == '@') { scan_list(&argv[arg][1], protos, handoffs); } @@ -101,10 +108,22 @@ int main(int argc, char **argv) } } + if (protos->len == 0) { + fprintf(stderr, "No protocol registrations found.\n"); + exit(1); + } + + out = fopen(argv[1], "w"); + if (out == NULL) { + fprintf(stderr, "Error opening file: %s: %s\n", argv[1], strerror(errno)); + exit(1); + } + g_ptr_array_sort(protos, compare_symbols); g_ptr_array_sort(handoffs, compare_symbols); - printf("/*\n" + fprintf(out, + "/*\n" " * Do not modify this file. Changes will be overwritten.\n" " *\n" " * Generated automatically by the \"dissectors.c\" target using\n" @@ -115,35 +134,42 @@ int main(int argc, char **argv) "#include <dissectors.h>\n" "\n"); - printf("const gulong dissector_reg_proto_count = %d;\n" + fprintf(out, + "const gulong dissector_reg_proto_count = %d;\n" "const gulong dissector_reg_handoff_count = %d;\n" "\n", protos->len, handoffs->len); for (i = 0; i < protos->len; i++) { - printf("void %s(void);\n", (char *)protos->pdata[i]); + fprintf(out, "void %s(void);\n", (char *)protos->pdata[i]); } - printf("\n" + fprintf(out, + "\n" "dissector_reg_t dissector_reg_proto[] = {\n"); for (i = 0; i < protos->len; i++) { - printf(" { \"%s\", %s },\n", (char *)protos->pdata[i], (char *)protos->pdata[i]); + fprintf(out, " { \"%s\", %s },\n", (char *)protos->pdata[i], (char *)protos->pdata[i]); } - printf(" { NULL, NULL }\n" + fprintf(out, + " { NULL, NULL }\n" "};\n" "\n"); for (i = 0; i < handoffs->len; i++) { - printf("void %s(void);\n", (char *)handoffs->pdata[i]); + fprintf(out, "void %s(void);\n", (char *)handoffs->pdata[i]); } - printf("\n" + fprintf(out, + "\n" "dissector_reg_t dissector_reg_handoff[] = {\n"); for (i = 0; i < handoffs->len; i++) { - printf(" { \"%s\", %s },\n", (char *)handoffs->pdata[i], (char *)handoffs->pdata[i]); + fprintf(out, " { \"%s\", %s },\n", (char *)handoffs->pdata[i], (char *)handoffs->pdata[i]); } - printf(" { NULL, NULL }\n" + fprintf(out, + " { NULL, NULL }\n" "};\n"); - fprintf(stderr, "Found %u registrations and %u handoffs.\n", protos->len, handoffs->len); + fclose(out); + + printf("Found %u registrations and %u handoffs.\n", protos->len, handoffs->len); g_regex_unref(protos_regex); g_regex_unref(handoffs_regex); |