aboutsummaryrefslogtreecommitdiffstats
path: root/wsutil
diff options
context:
space:
mode:
authorJoão Valverde <j@v6e.pt>2023-02-06 22:46:45 +0000
committerJoão Valverde <j@v6e.pt>2023-02-10 20:59:22 +0000
commit0cea64a632167e497a8a56757b1e4a70e9202e3b (patch)
tree22d1f11cc9422269dcb60f7e2435e510510f33bf /wsutil
parentd117e4767385b178445dc3bdd4742b066742cac9 (diff)
Move ui/cmdarg_err.[ch] to wsutil
Diffstat (limited to 'wsutil')
-rw-r--r--wsutil/CMakeLists.txt2
-rw-r--r--wsutil/cmdarg_err.c59
-rw-r--r--wsutil/cmdarg_err.h51
3 files changed, 112 insertions, 0 deletions
diff --git a/wsutil/CMakeLists.txt b/wsutil/CMakeLists.txt
index 0935fcaba7..b72bbb54df 100644
--- a/wsutil/CMakeLists.txt
+++ b/wsutil/CMakeLists.txt
@@ -32,6 +32,7 @@ set(WSUTIL_PUBLIC_HEADERS
bits_ctz.h
bitswap.h
buffer.h
+ cmdarg_err.h
codecs.h
color.h
cpu_info.h
@@ -103,6 +104,7 @@ set(WSUTIL_COMMON_FILES
base32.c
bitswap.c
buffer.c
+ cmdarg_err.c
codecs.c
crash_info.c
crc10.c
diff --git a/wsutil/cmdarg_err.c b/wsutil/cmdarg_err.c
new file mode 100644
index 0000000000..85a4d8d45c
--- /dev/null
+++ b/wsutil/cmdarg_err.c
@@ -0,0 +1,59 @@
+/* cmdarg_err.c
+ * Routines to report command-line argument errors.
+ *
+ * Wireshark - Network traffic analyzer
+ * By Gerald Combs <gerald@wireshark.org>
+ * Copyright 1998 Gerald Combs
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "config.h"
+
+#include "cmdarg_err.h"
+
+static void (*print_err)(const char *, va_list ap);
+static void (*print_err_cont)(const char *, va_list ap);
+
+/*
+ * Set the reporting functions for error messages.
+ */
+void
+cmdarg_err_init(void (*err)(const char *, va_list),
+ void (*err_cont)(const char *, va_list))
+{
+ print_err = err;
+ print_err_cont = err_cont;
+}
+
+/*
+ * Report an error in command-line arguments.
+ */
+void
+vcmdarg_err(const char *fmt, va_list ap)
+{
+ print_err(fmt, ap);
+}
+
+void
+cmdarg_err(const char *fmt, ...)
+{
+ va_list ap;
+
+ va_start(ap, fmt);
+ print_err(fmt, ap);
+ va_end(ap);
+}
+
+/*
+ * Report additional information for an error in command-line arguments.
+ */
+void
+cmdarg_err_cont(const char *fmt, ...)
+{
+ va_list ap;
+
+ va_start(ap, fmt);
+ print_err_cont(fmt, ap);
+ va_end(ap);
+}
diff --git a/wsutil/cmdarg_err.h b/wsutil/cmdarg_err.h
new file mode 100644
index 0000000000..daa50524e7
--- /dev/null
+++ b/wsutil/cmdarg_err.h
@@ -0,0 +1,51 @@
+/** @file
+ *
+ * Declarations of routines to report command-line argument errors.
+ *
+ * Wireshark - Network traffic analyzer
+ * By Gerald Combs <gerald@wireshark.org>
+ * Copyright 1998 Gerald Combs
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#ifndef __CMDARG_ERR_H__
+#define __CMDARG_ERR_H__
+
+#include <wireshark.h>
+#include <stdarg.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+/*
+ * Set the reporting functions for error messages.
+ */
+WS_DLL_PUBLIC void
+cmdarg_err_init(void (*err)(const char *, va_list),
+ void (*err_cont)(const char *, va_list));
+
+/*
+ * Report an error in command-line arguments.
+ */
+WS_DLL_PUBLIC void
+vcmdarg_err(const char *fmt, va_list ap)
+ G_GNUC_PRINTF(1, 0);
+
+WS_DLL_PUBLIC void
+cmdarg_err(const char *fmt, ...)
+ G_GNUC_PRINTF(1, 2);
+
+/*
+ * Report additional information for an error in command-line arguments.
+ */
+WS_DLL_PUBLIC void
+cmdarg_err_cont(const char *fmt, ...)
+ G_GNUC_PRINTF(1, 2);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* __CMDARG_ERR_H__ */