# HG changeset patch # User Matti Hamalainen # Date 1456845538 -7200 # Node ID f4e182720870cb81395e081faf9e5e77c2a6dc5a # Parent 5391cd55748372a013d4fd1ba30585da0fe7801a Rename some function arguments and option argument structure members. diff -r 5391cd557483 -r f4e182720870 th_args.c --- a/th_args.c Tue Mar 01 00:17:53 2016 +0200 +++ b/th_args.c Tue Mar 01 17:18:58 2016 +0200 @@ -17,28 +17,28 @@ static BOOL th_args_process_opt( char *currArg, int *argIndex, int argc, char *argv[], - const th_optarg_t opts[], int numOpts, - BOOL (*handleOptionCB)(int, char *, char *), + const th_optarg_t opts[], int nopts, + BOOL (*handle_option)(int id, char *, char *), BOOL doProcess, BOOL isLong) { const th_optarg_t *opt = NULL; char *optArg = NULL; int optIndex; - for (optIndex = 0; optIndex < numOpts; optIndex++) + for (optIndex = 0; optIndex < nopts; optIndex++) { const th_optarg_t *node = &opts[optIndex]; - if (isLong && node->optLong != NULL) + if (isLong && node->o_long != NULL) { - if (strcmp(currArg, node->optLong) == 0) + if (strcmp(currArg, node->o_long) == 0) { opt = node; optArg = NULL; break; } - size_t len = strlen(node->optLong); - if (strncmp(currArg, node->optLong, len) == 0 && + size_t len = strlen(node->o_long); + if (strncmp(currArg, node->o_long, len) == 0 && currArg[len] == '=') { opt = node; @@ -47,9 +47,9 @@ } } else - if (!isLong && node->optShort != 0) + if (!isLong && node->o_short != 0) { - if (*currArg == node->optShort) + if (*currArg == node->o_short) { opt = node; optArg = (currArg[1] != 0) ? &currArg[1] : NULL; @@ -78,7 +78,7 @@ } // Option was given succesfully, try to process it - if (doProcess && !handleOptionCB(opt->id, optArg, currArg)) + if (doProcess && !handle_option(opt->id, optArg, currArg)) return FALSE; } else @@ -99,9 +99,9 @@ * calling the given callback functions. */ BOOL th_args_process(int argc, char *argv[], - const th_optarg_t *opts, const int numOpts, - BOOL(*handleOptionCB) (int, char *, char *), - BOOL(*handleOther) (char *), const int flags) + const th_optarg_t *opts, const int nopts, + 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; @@ -133,15 +133,15 @@ isLong = FALSE; if (!th_args_process_opt(str, &argIndex, argc, argv, - opts, numOpts, handleOptionCB, doProcess, isLong)) + opts, nopts, handle_option, doProcess, isLong)) optionsOK = FALSE; } else if (handleFlags == OPTH_ONLY_OTHER || handleFlags == 0) { // Was not option argument - if (handleOther == NULL || - (handleOther != NULL && !handleOther(str))) + if (handle_other == NULL || + (handle_other != NULL && !handle_other(str))) { THERR("Invalid argument '%s'\n", str); optionsOK = FALSE; @@ -160,23 +160,23 @@ /* Print help for commandline arguments/options */ void th_args_help(FILE *fh, - const th_optarg_t *opts, const int numOpts, + const th_optarg_t *opts, const int nopts, const int flags) { int index; (void) flags; // Print out option list - for (index = 0; index < numOpts; index++) + for (index = 0; index < nopts; index++) { const th_optarg_t *opt = &opts[index]; char tmpStr[128]; // Print short option - if (opt->optShort != 0) + if (opt->o_short != 0) { snprintf(tmpStr, sizeof(tmpStr), - "-%c,", opt->optShort); + "-%c,", opt->o_short); } else tmpStr[0] = 0; @@ -184,10 +184,10 @@ fprintf(fh, " %-5s", tmpStr); // Print long option - if (opt->optLong != NULL) + if (opt->o_long != NULL) { snprintf(tmpStr, sizeof(tmpStr), "--%s%s", - opt->optLong, + opt->o_long, (opt->flags & OPT_ARGREQ) ? "=ARG" : ""); } else diff -r 5391cd557483 -r f4e182720870 th_args.h --- a/th_args.h Tue Mar 01 00:17:53 2016 +0200 +++ b/th_args.h Tue Mar 01 17:18:58 2016 +0200 @@ -1,7 +1,7 @@ /* * Simple commandline argument processing function * Programmed and designed by Matti 'ccr' Hamalainen - * (C) Copyright 2002-2015 Tecnic Software productions (TNSP) + * (C) Copyright 2002-2016 Tecnic Software productions (TNSP) * * Please read file 'COPYING' for information on license and distribution. */ @@ -32,8 +32,8 @@ typedef struct { int id; - char optShort; - char *optLong; + char o_hort; + char *o_long; char *desc; int flags; } th_optarg_t; @@ -41,8 +41,8 @@ BOOL th_args_process(int argc, char *argv[], const th_optarg_t *opts, const int nopts, - BOOL (*handleOption)(int, char *, char *), - BOOL (*handleOther)(char *), const int flags); + BOOL (*handle_option)(int id, char *, char *), + BOOL (*handle_other)(char *), const int flags); void th_args_help(FILE *, const th_optarg_t *opts, const int nopts, const int flags);