XRA: added upstream channel id, sid and iuc to burstinfo dissect
[metze/wireshark/wip.git] / captype.c
index 1d83f573ef882c34d031ff7379f855c82cdcaa1e..b47a66ef2a9191f75722a70a5d0d51ff0ec350f8 100644 (file)
--- a/captype.c
+++ b/captype.c
@@ -8,19 +8,7 @@
  * By Gerald Combs <gerald@wireshark.org>
  * Copyright 1998 Gerald Combs
  *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ * SPDX-License-Identifier: GPL-2.0-or-later
  */
 
 #include <config.h>
 
 #include <wiretap/wtap.h>
 
+#include <wsutil/cmdarg_err.h>
 #include <wsutil/crash_info.h>
 #include <wsutil/file_util.h>
 #include <wsutil/filesystem.h>
 #include <wsutil/privileges.h>
-#include <ws_version_info.h>
+#include <version_info.h>
 
 #ifdef HAVE_PLUGINS
 #include <wsutil/plugins.h>
 #endif
 
-#include <wsutil/report_err.h>
+#include <wsutil/report_message.h>
 #include <wsutil/str_util.h>
 
 #ifdef _WIN32
@@ -61,6 +50,8 @@
 #include "wsutil/wsgetopt.h"
 #endif
 
+#include "ui/failure_message.h"
+
 static void
 print_usage(FILE *output)
 {
@@ -68,18 +59,27 @@ print_usage(FILE *output)
   fprintf(output, "Usage: captype <infile> ...\n");
 }
 
-#ifdef HAVE_PLUGINS
 /*
- * General errors are reported with an console message in captype.
+ * General errors and warnings are reported with an console message
+ * in captype.
  */
 static void
-failure_message(const char *msg_format, va_list ap)
+failure_warning_message(const char *msg_format, va_list ap)
 {
   fprintf(stderr, "captype: ");
   vfprintf(stderr, msg_format, ap);
   fprintf(stderr, "\n");
 }
-#endif
+
+/*
+ * Report additional information for an error in command-line arguments.
+ */
+static void
+failure_message_cont(const char *msg_format, va_list ap)
+{
+  vfprintf(stderr, msg_format, ap);
+  fprintf(stderr, "\n");
+}
 
 int
 main(int argc, char *argv[])
@@ -102,6 +102,8 @@ main(int argc, char *argv[])
   /* Set the C-language locale to the native environment. */
   setlocale(LC_ALL, "");
 
+  cmdarg_err_init(failure_warning_message, failure_message_cont);
+
   /* Get the compile-time version information string */
   comp_info_str = get_compiled_version_info(NULL, NULL);
 
@@ -140,22 +142,10 @@ main(int argc, char *argv[])
     g_free(init_progfile_dir_error);
   }
 
-  wtap_init();
+  init_report_message(failure_warning_message, failure_warning_message,
+                      NULL, NULL, NULL);
 
-#ifdef HAVE_PLUGINS
-  init_report_err(failure_message,NULL,NULL,NULL);
-
-  /* Scan for plugins.  This does *not* call their registration routines;
-     that's done later.
-
-     Don't report failures to load plugins because most (non-wiretap)
-     plugins *should* fail to load (because we're not linked against
-     libwireshark and dissector plugins need libwireshark). */
-  scan_plugins(DONT_REPORT_LOAD_FAILURE);
-
-  /* Register all libwiretap plugin modules. */
-  register_all_wiretap_modules();
-#endif
+  wtap_init(TRUE);
 
   /* Process the options */
   while ((opt = getopt_long(argc, argv, "hv", long_options, NULL)) !=-1) {
@@ -204,18 +194,15 @@ main(int argc, char *argv[])
       if (err == WTAP_ERR_FILE_UNKNOWN_FORMAT)
         printf("%s: unknown\n", argv[i]);
       else {
-        fprintf(stderr, "captype: Can't open %s: %s\n", argv[i],
-                wtap_strerror(err));
-        if (err_info != NULL) {
-          fprintf(stderr, "(%s)\n", err_info);
-          g_free(err_info);
-        }
+        cfile_open_failure_message("captype", argv[i], err, err_info);
         overall_error_status = 2; /* remember that an error has occurred */
       }
     }
 
   }
 
+  wtap_cleanup();
+  free_progdirs();
   return overall_error_status;
 }