Mercurial > hg > th-libs
diff th_args.c @ 735:31bc1ed07cf5
Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Wed, 07 Dec 2022 12:14:39 +0200 |
parents | 29e44a58bc73 |
children | 56594b498180 |
line wrap: on
line diff
--- a/th_args.c Wed Dec 07 11:58:54 2022 +0200 +++ b/th_args.c Wed Dec 07 12:14:39 2022 +0200 @@ -19,16 +19,16 @@ * @param[in] opts options list array * @param[in] nopts number of elements in options list array * @param[in] handle_option function pointer to callback that handles option arguments - * @param[in] process if TRUE, actually handle the argument, aka call the handle_option() function. if FALSE, only validity of options are checked. - * @param[in] isLong TRUE if the option is a --long-format one - * @returns returns @c TRUE if option processing was successful + * @param[in] process if true, actually handle the argument, aka call the handle_option() function. if false, only validity of options are checked. + * @param[in] isLong true if the option is a --long-format one + * @returns returns @c true if option processing was successful */ -static BOOL th_args_process_opt( +static bool th_args_process_opt( char *currArg, int *argIndex, int argc, char *argv[], const th_optarg opts[], int nopts, - BOOL (*handle_option)(int id, char *, char *), - BOOL process, BOOL isLong) + bool (*handle_option)(int id, char *, char *), + bool process, bool isLong) { const th_optarg *opt = NULL; char *optArg = NULL; @@ -81,13 +81,13 @@ THERR("Option '%s%s' requires an argument.\n", isLong ? "--" : "-", currArg); - return FALSE; + return false; } } // Option was given succesfully, try to process it if (process && !handle_option(opt->id, optArg, currArg)) - return FALSE; + return false; } else { @@ -96,10 +96,10 @@ isLong ? "--" : "-", currArg); - return FALSE; + return false; } - return TRUE; + return true; } @@ -114,15 +114,15 @@ * @param[in] handle_option callback function * @param[in] handle_other callback function * @param[in] flags processing flags - * @return returns @c TRUE if arguments were processed successfully + * @return returns @c true if arguments were processed successfully */ -BOOL th_args_process(int argc, char *argv[], +bool th_args_process(int argc, char *argv[], const th_optarg *opts, const int nopts, - BOOL(*handle_option)(int id, char *, char *), - BOOL(*handle_other)(char *), const int flags) + bool(*handle_option)(int id, char *, char *), + bool(*handle_other)(char *), const int flags) { int handleFlags = flags & OPTH_ONLY_MASK; - BOOL optionsOK = TRUE, endOfOptions = FALSE; + bool optionsOK = true, endOfOptions = false; for (int argIndex = 1; argIndex < argc; argIndex++) { @@ -130,8 +130,8 @@ if (*str == '-' && !endOfOptions) { // Should we process options? - BOOL process = (handleFlags & OPTH_ONLY_OPTS) || handleFlags == 0; - BOOL isLong; + bool process = (handleFlags & OPTH_ONLY_OPTS) || handleFlags == 0; + bool isLong; str++; if (*str == '-') @@ -140,19 +140,19 @@ str++; if (*str == 0) { - endOfOptions = TRUE; + endOfOptions = true; continue; } // We have a long option - isLong = TRUE; + isLong = true; } else - isLong = FALSE; + isLong = false; if (!th_args_process_opt(str, &argIndex, argc, argv, opts, nopts, handle_option, process, isLong)) - optionsOK = FALSE; + optionsOK = false; } else if (handleFlags == OPTH_ONLY_OTHER || handleFlags == 0) @@ -161,13 +161,13 @@ if (handle_other == NULL || (handle_other != NULL && !handle_other(str))) { - optionsOK = FALSE; + optionsOK = false; } } // Check if we bail out on invalid argument if (!optionsOK && (flags & OPTH_BAILOUT)) - return FALSE; + return false; } return optionsOK; @@ -194,14 +194,14 @@ const int width, const char *str) { size_t pos = 0; - BOOL first = TRUE; + bool first = true; while (str[pos]) { // Pre-pad line int linelen = first ? spad : rpad; th_print_pad(fh, first ? 0 : rpad, ' '); - first = FALSE; + first = false; // Skip whitespace at line start while (th_isspace(str[pos]) || str[pos] == '\n') @@ -255,12 +255,12 @@ static void th_args_help_print_item(FILE *fh, const th_optarg *opt, int *optWidth, const int maxOptWidth, const int termWidth, - const BOOL doPrint) + const bool doPrint) { const char *arg = th_args_get_optarg(opt); char fmtBuf[32]; int padWidth; - BOOL hasLongOpt = opt->o_long != NULL; + bool hasLongOpt = opt->o_long != NULL; if (opt->o_short != 0) { @@ -347,7 +347,7 @@ for (index = 0; index < nopts; index++) { int optWidth = 0; - th_args_help_print_item(NULL, &opts[index], &optWidth, 0, width, FALSE); + th_args_help_print_item(NULL, &opts[index], &optWidth, 0, width, false); if (optWidth > maxOptWidth) maxOptWidth = optWidth; } @@ -358,6 +358,6 @@ for (index = 0; index < nopts; index++) { int optWidth; - th_args_help_print_item(fh, &opts[index], &optWidth, maxOptWidth, width, TRUE); + th_args_help_print_item(fh, &opts[index], &optWidth, maxOptWidth, width, true); } }