From 0cea64a632167e497a8a56757b1e4a70e9202e3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Valverde?= Date: Mon, 6 Feb 2023 22:46:45 +0000 Subject: Move ui/cmdarg_err.[ch] to wsutil --- wsutil/CMakeLists.txt | 2 ++ wsutil/cmdarg_err.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++ wsutil/cmdarg_err.h | 51 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 112 insertions(+) create mode 100644 wsutil/cmdarg_err.c create mode 100644 wsutil/cmdarg_err.h (limited to 'wsutil') 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 + * 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 + * Copyright 1998 Gerald Combs + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#ifndef __CMDARG_ERR_H__ +#define __CMDARG_ERR_H__ + +#include +#include + +#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__ */ -- cgit v1.2.3