# HG changeset patch # User Matti Hamalainen # Date 1672388660 -7200 # Node ID 70b589a2249551c0e924e170b9c6051bf14eeea1 # Parent b2c510f851dc44d2718e23d445ef45cbe33f1c34 Sync some changes from th-libs/th_args.c diff -r b2c510f851dc -r 70b589a22495 src/dmargs.c --- a/src/dmargs.c Sun Dec 25 02:37:11 2022 +0200 +++ b/src/dmargs.c Fri Dec 30 10:24:20 2022 +0200 @@ -1,7 +1,7 @@ /* * Simple commandline argument processing * Programmed and designed by Matti 'ccr' Hamalainen - * (C) Copyright 2002-2021 Tecnic Software productions (TNSP) + * (C) Copyright 2002-2022 Tecnic Software productions (TNSP) * * Please read file 'COPYING' for information on license and distribution. */ @@ -13,14 +13,15 @@ /** * Parse and optionally handle the given long or short option argument. * @param currArg current argument string - * @param argIndex pointer to index of current argument in argv[] + * @param[in,out] argIndex pointer to index of current argument in argv[] * @param argc number of arguments * @param argv argument string array - * @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[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 */ static bool dmArgsProcessOpt( char *currArg, int *argIndex, @@ -108,12 +109,12 @@ * * @param argc number of arguments * @param argv argument list - * @param opts supported option list array - * @param nopts number of elements in the option list array - * @param handle_option callback function - * @param handle_other callback function - * @param flags processing flags - * @return return true if all is well + * @param[in] opts supported option list array + * @param[in] nopts number of elements in the option list array + * @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 */ bool dmArgsProcess(int argc, char *argv[], const DMOptArg *opts, const int nopts, @@ -184,10 +185,10 @@ * Print given string indented in such a way that it is automatically * line-wrapped as necessary, taking hard linefeeds into account as well. * @param fh stdio file handle to output to - * @param spad starting pad/indent of the first line - * @param rpad how much to pad the other lines - * @param width total line width to wrap at - * @param str string to output + * @param[in] spad starting pad/indent of the first line + * @param[in] rpad how much to pad the other lines + * @param[in] width total line width to wrap at + * @param[in] str string to output */ void dmPrintWrap(FILE *fh, const int spad, int const rpad, const int width, const char *str) @@ -270,8 +271,9 @@ } else { - snprintf(fmtBuf, sizeof(fmtBuf), " -%c,", - opt->o_short); + snprintf(fmtBuf, sizeof(fmtBuf), " -%c%s", + opt->o_short, + hasLongOpt ? "," : ""); } *optWidth = strlen(fmtBuf); @@ -325,12 +327,15 @@ /** - * Print help for commandline arguments/options + * Print neatly formatted help for specified array of commandline options. + * The function will attempt to find the best indentation and formatting of + * the output using a simple fitting algorithm. Option descriptions will be + * automatically split over several lines if necessary. * @param fh stdio file handle to output to - * @param opts options list array - * @param nopts number of elements in options list array - * @param flags flags (currently unused) - * @param width width of the terminal or desired width of the print out + * @param[in] opts options list array + * @param[in] nopts number of elements in the options list array @p opts + * @param[in] flags (currently unused) + * @param[in] width width of the output terminal or the desired maximum width of the printout */ void dmArgsPrintHelp(FILE *fh, const DMOptArg *opts, const int nopts, const int flags, const int width)