Mercurial > hg > th-libs
diff th_args.c @ 453:efd33accdc81
Break backwards compatibility by renaming BOOL, TRUE and FALSE to lowercase.
Introduce optional but default use of stdbool.h.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 02 Jan 2018 22:56:03 +0200 |
parents | 2991e6b52d95 |
children | 347bfd3e017e |
line wrap: on
line diff
--- a/th_args.c Wed Oct 25 22:32:07 2017 +0300 +++ b/th_args.c Tue Jan 02 22:56:03 2018 +0200 @@ -23,15 +23,15 @@ * @param opts options list array * @param nopts number of elements in options list array * @param handle_option function pointer to callback that handles option arguments - * @param doProcess if TRUE, actually handle the argument, aka call the handle_option() function. if FALSE, only validity of options are checked. - * @param isLong TRUE if the option is a --long-format one + * @param doProcess if true, actually handle the argument, aka call the handle_option() function. if false, only validity of options are checked. + * @param isLong true if the option is a --long-format one */ -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 doProcess, BOOL isLong) + bool (*handle_option)(int id, char *, char *), + bool doProcess, bool isLong) { const th_optarg *opt = NULL; char *optArg = NULL; @@ -85,13 +85,13 @@ THERR("Option '%s%s' requires an argument.\n", isLong ? "--" : "-", currArg); - return FALSE; + return false; } } // Option was given succesfully, try to process it if (doProcess && !handle_option(opt->id, optArg, currArg)) - return FALSE; + return false; } else { @@ -100,10 +100,10 @@ isLong ? "--" : "-", currArg); - return FALSE; + return false; } - return TRUE; + return true; } @@ -118,15 +118,15 @@ * @param handle_option callback function * @param handle_other callback function * @param flags processing flags - * @return return TRUE if all is well + * @return return true if all is well */ -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 argIndex, handleFlags = flags & OPTH_ONLY_MASK; - BOOL optionsOK = TRUE, endOfOptions = FALSE; + bool optionsOK = true, endOfOptions = false; for (argIndex = 1; argIndex < argc; argIndex++) { @@ -134,8 +134,8 @@ if (*str == '-' && !endOfOptions) { // Should we process options? - BOOL doProcess = (handleFlags & OPTH_ONLY_OPTS) || handleFlags == 0; - BOOL isLong; + bool doProcess = (handleFlags & OPTH_ONLY_OPTS) || handleFlags == 0; + bool isLong; str++; if (*str == '-') @@ -144,19 +144,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, doProcess, isLong)) - optionsOK = FALSE; + optionsOK = false; } else if (handleFlags == OPTH_ONLY_OTHER || handleFlags == 0) @@ -166,13 +166,13 @@ (handle_other != NULL && !handle_other(str))) { THERR("Invalid argument '%s'\n", str); - optionsOK = FALSE; + optionsOK = false; } } // Check if we bail out on invalid argument if (!optionsOK && (flags & OPTH_BAILOUT)) - return FALSE; + return false; } return optionsOK;