Mercurial > hg > dmlib
diff src/dmargs.c @ 2586:9807ae37ad69
Require stdbool.h, we require C11 now.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Thu, 08 Dec 2022 15:59:22 +0200 |
parents | c6ee41fd98dd |
children | 70b589a22495 |
line wrap: on
line diff
--- a/src/dmargs.c Thu Dec 08 15:56:36 2022 +0200 +++ b/src/dmargs.c Thu Dec 08 15:59:22 2022 +0200 @@ -19,15 +19,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 process 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 process 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 dmArgsProcessOpt( +static bool dmArgsProcessOpt( char *currArg, int *argIndex, int argc, char *argv[], const DMOptArg 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 DMOptArg *opt = NULL; char *optArg = NULL; @@ -80,13 +80,13 @@ dmErrorMsg("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 { @@ -95,10 +95,10 @@ isLong ? "--" : "-", currArg); - return FALSE; + return false; } - return TRUE; + return true; } @@ -113,15 +113,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 dmArgsProcess(int argc, char *argv[], +bool dmArgsProcess(int argc, char *argv[], const DMOptArg *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++) { @@ -129,8 +129,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 == '-') @@ -139,19 +139,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 (!dmArgsProcessOpt(str, &argIndex, argc, argv, opts, nopts, handle_option, process, isLong)) - optionsOK = FALSE; + optionsOK = false; } else if (handleFlags == OPTH_ONLY_OTHER || handleFlags == 0) @@ -160,13 +160,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; @@ -193,14 +193,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; dmPrintPad(fh, first ? 0 : rpad, ' '); - first = FALSE; + first = false; // Skip whitespace at line start while (isspace(str[pos]) || str[pos] == '\n') @@ -254,12 +254,12 @@ static void dmArgsPrintHelpPrintItem(FILE *fh, const DMOptArg *opt, int *optWidth, const int maxOptWidth, const int termWidth, - const BOOL doPrint) + const bool doPrint) { const char *arg = dmArgsGetOptArg(opt); char fmtBuf[32]; int padWidth; - BOOL hasLongOpt = opt->o_long != NULL; + bool hasLongOpt = opt->o_long != NULL; if (opt->o_short != 0) { @@ -343,7 +343,7 @@ for (index = 0; index < nopts; index++) { int optWidth = 0; - dmArgsPrintHelpPrintItem(NULL, &opts[index], &optWidth, 0, width, FALSE); + dmArgsPrintHelpPrintItem(NULL, &opts[index], &optWidth, 0, width, false); if (optWidth > maxOptWidth) maxOptWidth = optWidth; } @@ -354,6 +354,6 @@ for (index = 0; index < nopts; index++) { int optWidth; - dmArgsPrintHelpPrintItem(fh, &opts[index], &optWidth, maxOptWidth, width, TRUE); + dmArgsPrintHelpPrintItem(fh, &opts[index], &optWidth, maxOptWidth, width, true); } }