diff options
author | pgen <p.gen.progs@gmail.com> | 2023-09-10 00:35:48 +0200 |
---|---|---|
committer | pgen <p.gen.progs@gmail.com> | 2023-09-11 14:15:32 +0200 |
commit | 36881ac8835674bf5ce0112f1c5bfa7d1b1e3f27 (patch) | |
tree | 97e706c87e9189c1896b5117578f112f8ce7484d | |
parent | b4e826f3ce669758eb2847d5d7eb65ee2c4755d0 (diff) |
Reformatting source code
-rw-r--r-- | .clang-format | 27 | ||||
-rw-r--r-- | ctxopt.c | 1144 | ||||
-rw-r--r-- | ctxopt.h | 48 | ||||
-rw-r--r-- | fgetc.c | 4 | ||||
-rw-r--r-- | fgetc.h | 4 | ||||
-rw-r--r-- | index.c | 62 | ||||
-rw-r--r-- | index.h | 32 | ||||
-rw-r--r-- | list.c | 44 | ||||
-rw-r--r-- | list.h | 21 | ||||
-rw-r--r-- | safe.c | 9 | ||||
-rw-r--r-- | safe.h | 7 | ||||
-rw-r--r-- | smenu.c | 3708 | ||||
-rw-r--r-- | smenu.h | 341 | ||||
-rw-r--r-- | utf8.c | 61 | ||||
-rw-r--r-- | utf8.h | 20 | ||||
-rw-r--r-- | utils.c | 54 | ||||
-rw-r--r-- | utils.h | 26 | ||||
-rw-r--r-- | xmalloc.c | 26 | ||||
-rw-r--r-- | xmalloc.h | 8 |
19 files changed, 3626 insertions, 2020 deletions
diff --git a/.clang-format b/.clang-format index b957a81..442a2f6 100644 --- a/.clang-format +++ b/.clang-format @@ -1,13 +1,11 @@ -SortIncludes: 'false' -BasedOnStyle: Mozilla AlignAfterOpenBracket: 'true' AlignConsecutiveAssignments: 'true' AlignConsecutiveDeclarations: 'true' -AlignOperands: 'true' AlignEscapedNewlinesLeft: 'true' AlignOperands: 'true' +AlignOperands: 'true' AlignTrailingComments: 'true' -ReflowComments: 'false' +AllowAllArgumentsOnNextLine: 'false' AllowAllParametersOfDeclarationOnNextLine: 'false' AllowShortBlocksOnASingleLine: 'false' AllowShortCaseLabelsOnASingleLine: 'false' @@ -15,10 +13,11 @@ AllowShortFunctionsOnASingleLine: None AllowShortIfStatementsOnASingleLine: 'false' AllowShortLoopsOnASingleLine: 'false' AlwaysBreakBeforeMultilineStrings: 'false' -BinPackArguments: 'true' -BinPackParameters: 'true' -BreakBeforeBraces: Allman +BasedOnStyle: Mozilla +BinPackArguments: 'false' +BinPackParameters: 'false' BreakBeforeBinaryOperators: NonAssignment +BreakBeforeBraces: Allman BreakBeforeTernaryOperators: 'true' BreakConstructorInitializersBeforeComma: 'false' ColumnLimit: '80' @@ -29,11 +28,19 @@ IndentWidth: '2' KeepEmptyLinesAtTheStartOfBlocks: 'true' Language: Cpp MaxEmptyLinesToKeep: '1' -PointerAlignment: Middle +PenaltyBreakAssignment: '150' +PenaltyBreakBeforeFirstCallParameter: '100' +PointerAlignment: Right +ReflowComments: 'false' +SeparateDefinitionBlocks: 'Always' +SortIncludes: 'false' SpaceAfterCStyleCast: 'false' +SpaceAroundPointerQualifiers: 'Before' SpaceBeforeAssignmentOperators: 'true' -SpaceBeforeParens: Never SpaceBeforeParens: ControlStatements +SpaceBeforeCaseColon: 'false' +SpaceInEmptyBlock: 'false' +SpacesInSquareBrackets: 'false' SpaceInEmptyParentheses: 'false' SpacesBeforeTrailingComments: '1' SpacesInCStyleCastParentheses: 'false' @@ -41,5 +48,3 @@ SpacesInParentheses: 'false' SpacesInSquareBrackets: 'false' TabWidth: '2' UseTab: Never -PenaltyBreakBeforeFirstCallParameter: '100' -PenaltyBreakAssignment: '150' @@ -22,10 +22,10 @@ /* Static global variables. */ /* ************************ */ -static void * contexts_bst; -static void * options_bst; +static void *contexts_bst; +static void *options_bst; -state_t * cur_state; +state_t *cur_state; /* Prototypes */ @@ -33,19 +33,19 @@ state_t * cur_state; /* Fatal messages prototypes. */ /* ************************** */ -static void (**err_functions)(errors e, state_t * state); +static void (**err_functions)(errors e, state_t *state); static void -fatal_internal(const char * format, ...); +fatal_internal(const char *format, ...); static void -fatal(errors e, char * errmsg); +fatal(errors e, char *errmsg); -static int user_rc; /* Used by various callback functions. */ -static int user_value; /* Used by various callback functions. */ -static char * user_string; /* Used by various callback functions. */ -static char * user_string2; /* Used by various callback functions. */ -static void * user_object; /* Used by various callback functions. */ +static int user_rc; /* Used by various callback functions. */ +static int user_value; /* Used by various callback functions. */ +static char *user_string; /* Used by various callback functions. */ +static char *user_string2; /* Used by various callback functions. */ +static void *user_object; /* Used by various callback functions. */ /* ************************************ */ /* Memory management static prototypes. */ @@ -58,13 +58,13 @@ static void * xcalloc(size_t num, size_t size); static void * -xrealloc(void * ptr, size_t size); +xrealloc(void *ptr, size_t size); static char * -xstrdup(const char * p); +xstrdup(const char *p); static char * -xstrndup(const char * str, size_t len); +xstrndup(const char *str, size_t len); /* ********************** */ /* BST static prototypes. */ @@ -87,22 +87,25 @@ bst_delete(const void * vkey, void ** vrootp, #endif static void -bst_destroy(void * vrootp, void (*clean)(void *)); +bst_destroy(void *vrootp, void (*clean)(void *)); static void * -bst_find(const void * vkey, void * const * vrootp, +bst_find(const void *vkey, + void * const *vrootp, int (*compar)(const void *, const void *)); static void * -bst_search(void * vkey, void ** vrootp, +bst_search(void *vkey, + void **vrootp, int (*compar)(const void *, const void *)); static void -bst_walk_recurse(const bst_t * root, - void (*action)(const void *, walk_order_e, int), int level); +bst_walk_recurse(const bst_t *root, + void (*action)(const void *, walk_order_e, int), + int level); static void -bst_walk(const void * vroot, void (*action)(const void *, walk_order_e, int)); +bst_walk(const void *vroot, void (*action)(const void *, walk_order_e, int)); /* ****************************** */ /* Linked list static prototypes. */ @@ -118,16 +121,16 @@ static void ll_prepend(ll_t * const list, void * const data); static void -ll_insert_after(ll_t * const list, ll_node_t * node, void * const data); +ll_insert_after(ll_t * const list, ll_node_t *node, void * const data); static void -ll_insert_before(ll_t * const list, ll_node_t * node, void * const data); +ll_insert_before(ll_t * const list, ll_node_t *node, void * const data); static int -ll_delete(ll_t * const list, ll_node_t * node); +ll_delete(ll_t * const list, ll_node_t *node); static void -ll_init(ll_t * list); +ll_init(ll_t *list); static ll_node_t * ll_new_node(void); @@ -142,35 +145,35 @@ static void ll_destroy(ll_t * const list, void (*)(void *)); static int -ll_strarray(ll_t * list, ll_node_t * start_node, int * count, char *** array); +ll_strarray(ll_t *list, ll_node_t *start_node, int *count, char ***array); /* ************************** */ /* Various static prototypes. */ /* ************************** */ static void -ltrim(char * str, const char * trim_str); +ltrim(char *str, const char *trim_str); static void -rtrim(char * str, const char * trim_str, size_t min); +rtrim(char *str, const char *trim_str, size_t min); static int -strchrcount(char * str, char c); +strchrcount(char *str, char c); static int -strpref(char * s1, char * s2); +strpref(char *s1, char *s2); static int -stricmp(const char * s1, const char * s2); +stricmp(const char *s1, const char *s2); static char * -xstrtok_r(char * str, const char * delim, char ** end); +xstrtok_r(char *str, const char *delim, char **end); static int -eval_yes(char * value, int * invalid); +eval_yes(char *value, int *invalid); static char * -get_word(char * str, char * buf, size_t len); +get_word(char *str, char *buf, size_t len); /* ************************* */ /* ctxopt static prototypes. */ @@ -187,104 +190,112 @@ typedef struct seen_opt_s seen_opt_t; typedef struct req_s req_t; static char * -strtoken(char * s, char * token, size_t tok_len, char * pattern, int * pos); +strtoken(char *s, char *token, size_t tok_len, char *pattern, int *pos); static int -ctx_compare(const void * c1, const void * c2); +ctx_compare(const void *c1, const void *c2); static void -ctx_free(void * o); +ctx_free(void *o); static void -ctx_inst_free(void * ci); +ctx_inst_free(void *ci); static void -opt_inst_free(void * oi); +opt_inst_free(void *oi); static int -seen_opt_compare(const void * so1, const void * so2); +seen_opt_compare(const void *so1, const void *so2); static void -incomp_bst_free(void * b); +incomp_bst_free(void *b); static void -req_free(void * r); +req_free(void *r); static void -seen_opt_free(void * seen_opt); +seen_opt_free(void *seen_opt); static int -opt_compare(const void * o1, const void * o2); +opt_compare(const void *o1, const void *o2); static void -opt_free(void * o); +opt_free(void *o); static int -par_compare(const void * a1, const void * a2); +par_compare(const void *a1, const void *a2); static void -par_free(void * p); +par_free(void *p); static void -constraint_free(void * cstr); +constraint_free(void *cstr); static ctx_t * -locate_ctx(char * name); +locate_ctx(char *name); static opt_t * -locate_opt(char * name); +locate_opt(char *name); static par_t * -locate_par(char * name, ctx_t * ctx); +locate_par(char *name, ctx_t *ctx); static void -print_before_constraints(ll_t * list); +print_before_constraints(ll_t *list); static void -print_options(ll_t * list, int * has_optional, int * has_ellipsis, - int * has_rule, int * has_generic_arg, int * has_ctx_change, - int * has_early_eval); +print_options(ll_t *list, + int *has_optional, + int *has_ellipsis, + int *has_rule, + int *has_generic_arg, + int *has_ctx_change, + int *has_early_eval); static void -print_explanations(int has_early_eval, int has_ctx_change, int has_generic_arg, - int has_optional, int has_ellipsis, int has_rule); +print_explanations(int has_early_eval, + int has_ctx_change, + int has_generic_arg, + int has_optional, + int has_ellipsis, + int has_rule); static void -bst_seen_opt_cb(const void * node, walk_order_e kind, int level); +bst_seen_opt_cb(const void *node, walk_order_e kind, int level); static void -bst_seen_opt_seen_cb(const void * node, walk_order_e kind, int level); +bst_seen_opt_seen_cb(const void *node, walk_order_e kind, int level); static void -bst_print_ctx_cb(const void * node, walk_order_e kind, int level); +bst_print_ctx_cb(const void *node, walk_order_e kind, int level); static void -bst_check_opt_cb(const void * node, walk_order_e kind, int level); +bst_check_opt_cb(const void *node, walk_order_e kind, int level); static void -bst_match_par_cb(const void * node, walk_order_e kind, int level); +bst_match_par_cb(const void *node, walk_order_e kind, int level); static void -match_prefix_cb(const void * node, walk_order_e kind, int level); +match_prefix_cb(const void *node, walk_order_e kind, int level); static int -has_unseen_mandatory_opt(ctx_inst_t * ctx_inst, char ** missing); +has_unseen_mandatory_opt(ctx_inst_t *ctx_inst, char **missing); static int -opt_parse(char * s, opt_t ** opt); +opt_parse(char *s, opt_t **opt); static int -init_opts(char * spec, ctx_t * ctx); +init_opts(char *spec, ctx_t *ctx); static int -ctxopt_build_cmdline_list(int nb_words, char ** words); +ctxopt_build_cmdline_list(int nb_words, char **words); static int -opt_set_parms(char * opt_name, char * par_str); +opt_set_parms(char *opt_name, char *par_str); static ctx_inst_t * -new_ctx_inst(ctx_t * ctx, ctx_inst_t * prev_ctx_inst); +new_ctx_inst(ctx_t *ctx, ctx_inst_t *prev_ctx_inst); static void -evaluate_ctx_inst(ctx_inst_t * ctx_inst); +evaluate_ctx_inst(ctx_inst_t *ctx_inst); /* ****************************** */ /* Fatal messages implementation. */ @@ -298,7 +309,7 @@ evaluate_ctx_inst(ctx_inst_t * ctx_inst); /* ... : remaining arguments interpreted using the format argument. */ /* =================================================================== */ static void -fatal_internal(const char * format, ...) +fatal_internal(const char *format, ...) { va_list args; @@ -337,7 +348,7 @@ fatal_internal(const char * format, ...) /* CTXOPTCTGARG Arguments: too many occurrences. */ /* ====================================================================== */ static void -fatal(errors e, char * errmsg) +fatal(errors e, char *errmsg) { if (err_functions[e] != NULL) err_functions[e](e, cur_state); @@ -353,7 +364,8 @@ fatal(errors e, char * errmsg) fprintf(stderr, "the mandatory parameter(s) %s are missing in the context " "introduced by %s.\n", - errmsg, cur_state->ctx_par_name); + errmsg, + cur_state->ctx_par_name); else fprintf(stderr, "The mandatory parameter(s) %s are missing " @@ -364,7 +376,9 @@ fatal(errors e, char * errmsg) break; case CTXOPTREQPAR: - fprintf(stderr, errmsg, cur_state->req_opt_par_needed, + fprintf(stderr, + errmsg, + cur_state->req_opt_par_needed, cur_state->req_opt_par); break; @@ -378,10 +392,12 @@ fatal(errors e, char * errmsg) case CTXOPTMISARG: if (cur_state->pre_opt_par_name != NULL) - fprintf(stderr, "%s requires argument(s).\n", + fprintf(stderr, + "%s requires argument(s).\n", cur_state->pre_opt_par_name); else - fprintf(stderr, "%s requires argument(s).\n", + fprintf(stderr, + "%s requires argument(s).\n", cur_state->cur_opt_par_name); break; @@ -390,7 +406,8 @@ fatal(errors e, char * errmsg) fprintf(stderr, "The parameter %s can only appear once in the context " "introduced by %s.\n", - cur_state->cur_opt_params, cur_state->ctx_par_name); + cur_state->cur_opt_params, + cur_state->ctx_par_name); else fprintf(stderr, "The parameter %s can only appear once " @@ -399,13 +416,17 @@ fatal(errors e, char * errmsg) break; case CTXOPTUNKPAR: - fprintf(stderr, "Unknown parameter %s.\n%s", - cur_state->cur_opt_par_name, errmsg); + fprintf(stderr, + "Unknown parameter %s.\n%s", + cur_state->cur_opt_par_name, + errmsg); break; case CTXOPTINCOPT: - fprintf(stderr, "The parameter %s is incompatible with %s.\n", - cur_state->cur_opt_par_name, errmsg); + fprintf(stderr, + "The parameter %s is incompatible with %s.\n", + cur_state->cur_opt_par_name, + errmsg); break; case CTXOPTCTEOPT: @@ -413,13 +434,15 @@ fatal(errors e, char * errmsg) fprintf(stderr, "The parameter %s must appear exactly %d times " "in the context introduced by %s.\n", - cur_state->cur_opt_params, cur_state->opts_count, + cur_state->cur_opt_params, + cur_state->opts_count, cur_state->ctx_par_name); else fprintf(stderr, "The parameter %s must appear exactly %d times " "in the main context.\n", - cur_state->cur_opt_params, cur_state->opts_count); + cur_state->cur_opt_params, + cur_state->opts_count); break; case CTXOPTCTLOPT: @@ -427,13 +450,15 @@ fatal(errors e, char * errmsg) fprintf(stderr, "The parameter %s must appear less than %d times " "in the context introduced by %s.\n", - cur_state->cur_opt_params, cur_state->opts_count, + cur_state->cur_opt_params, + cur_state->opts_count, cur_state->ctx_par_name); else fprintf(stderr, "The parameter %s must appear less than %d times " "in the main context.\n", - cur_state->cur_opt_params, cur_state->opts_count); + cur_state->cur_opt_params, + cur_state->opts_count); break; case CTXOPTCTGOPT: @@ -441,28 +466,36 @@ fatal(errors e, char * errmsg) fprintf(stderr, "The parameter %s must appear more than %d times " "in the context introduced by %s.\n", - cur_state->cur_opt_params, cur_state->opts_count, + cur_state->cur_opt_params, + cur_state->opts_count, cur_state->ctx_par_name); else fprintf(stderr, "The parameter %s must appear more than %d times " "in the main context.\n", - cur_state->cur_opt_params, cur_state->opts_count); + cur_state->cur_opt_params, + cur_state->opts_count); break; case CTXOPTCTEARG: - fprintf(stderr, "The parameter %s must have exactly %d arguments.\n", - cur_state->cur_opt_par_name, cur_state->opt_args_count); + fprintf(stderr, + "The parameter %s must have exactly %d arguments.\n", + cur_state->cur_opt_par_name, + cur_state->opt_args_count); break; case CTXOPTCTLARG: - fprintf(stderr, "The parameter %s must have less than %d arguments.\n", - cur_state->cur_opt_par_name, cur_state->opt_args_count); + fprintf(stderr, + "The parameter %s must have less than %d arguments.\n", + cur_state->cur_opt_par_name, + cur_state->opt_args_count); break; case CTXOPTCTGARG: - fprintf(stderr, "The parameter %s must have more than %d arguments.\n", - cur_state->cur_opt_par_name, cur_state->opt_args_count); + fprintf(stderr, + "The parameter %s must have more than %d arguments.\n", + cur_state->cur_opt_par_name, + cur_state->opt_args_count); break; case CTXOPTERRSIZ: @@ -493,7 +526,7 @@ fatal(errors e, char * errmsg) static void * xmalloc(size_t size) { - void * allocated; + void *allocated; size_t real_size; real_size = (size > 0) ? size : 1; @@ -511,7 +544,7 @@ xmalloc(size_t size) static void * xcalloc(size_t n, size_t size) { - void * allocated; + void *allocated; n = (n > 0) ? n : 1; size = (size > 0) ? size : 1; @@ -527,9 +560,9 @@ xcalloc(size_t n, size_t size) /* Customized realloc. */ /* =================== */ static void * -xrealloc(void * p, size_t size) +xrealloc(void *p, size_t size) { - void * allocated; + void *allocated; allocated = realloc(p, size); if (allocated == NULL && size > 0) @@ -543,9 +576,9 @@ xrealloc(void * p, size_t size) /* strdup implementation using xmalloc. */ /* ==================================== */ static char * -xstrdup(const char * p) +xstrdup(const char *p) { - char * allocated; + char *allocated; allocated = xmalloc(strlen(p) + 1); strcpy(allocated, p); @@ -558,9 +591,9 @@ xstrdup(const char * p) /* This version guarantees that there is a final '\0'. */ /* =================================================== */ static char * -xstrndup(const char * str, size_t len) +xstrndup(const char *str, size_t len) { - char * p; + char *p; p = memchr(str, '\0', len); @@ -582,18 +615,18 @@ xstrndup(const char * str, size_t len) /* """"""""""""""""""""""""""" */ struct ll_node_s { - void * data; - struct ll_node_s * next; - struct ll_node_s * prev; + void *data; + struct ll_node_s *next; + struct ll_node_s *prev; }; /* Linked List structure. */ /* """""""""""""""""""""" */ struct ll_s { - ll_node_t * head; - ll_node_t * tail; - long len; + ll_node_t *head; + ll_node_t *tail; + long len; }; /* ========================= */ @@ -602,7 +635,7 @@ struct ll_s static ll_t * ll_new(void) { - ll_t * ret = xmalloc(sizeof(ll_t)); + ll_t *ret = xmalloc(sizeof(ll_t)); ll_init(ret); return ret; @@ -616,7 +649,7 @@ ll_new(void) static void ll_free(ll_t * const list, void (*clean)(void *)) { - ll_node_t * node; + ll_node_t *node; if (list) { @@ -640,7 +673,7 @@ ll_free(ll_t * const list, void (*clean)(void *)) /* Destroy a list and all its elements. */ /* ==================================== */ static void -ll_destroy(ll_t * list, void (*clean)(void *)) +ll_destroy(ll_t *list, void (*clean)(void *)) { if (list) { @@ -653,7 +686,7 @@ ll_destroy(ll_t * list, void (*clean)(void *)) /* Initialize a linked list. */ /* ========================= */ static void -ll_init(ll_t * list) +ll_init(ll_t *list) { list->head = NULL; list->tail = NULL; @@ -666,7 +699,7 @@ ll_init(ll_t * list) static ll_node_t * ll_new_node(void) { - ll_node_t * ret = xmalloc(sizeof(ll_node_t)); + ll_node_t *ret = xmalloc(sizeof(ll_node_t)); return ret; } @@ -678,7 +711,7 @@ ll_new_node(void) static void ll_append(ll_t * const list, void * const data) { - ll_node_t * node; + ll_node_t *node; node = ll_new_node(); /* ll_new_node cannot return NULL because it * | uses xmalloc which does not return if there * @@ -706,7 +739,7 @@ ll_append(ll_t * const list, void * const data) static void ll_prepend(ll_t * const list, void * const data) { - ll_node_t * node; + ll_node_t *node; node = ll_new_node(); /* ll_new_node cannot return NULL because it * | uses xmalloc which does not return if there * @@ -730,9 +763,9 @@ ll_prepend(ll_t * const list, void * const data) /* Insert a new node before the specified node in the list. */ /* ======================================================== */ static void -ll_insert_before(ll_t * const list, ll_node_t * node, void * const data) +ll_insert_before(ll_t * const list, ll_node_t *node, void * const data) { - ll_node_t * new_node; + ll_node_t *new_node; if (node->prev == NULL) ll_prepend(list, data); @@ -757,9 +790,9 @@ ll_insert_before(ll_t * const list, ll_node_t * node, void * const data) /* Insert a new node after the specified node in the list. */ /* ======================================================= */ static void -ll_insert_after(ll_t * const list, ll_node_t * node, void * const data) +ll_insert_after(ll_t * const list, ll_node_t *node, void * const data) { - ll_node_t * new_node; + ll_node_t *new_node; if (node->next == NULL) ll_append(list, data); @@ -785,7 +818,7 @@ ll_insert_after(ll_t * const list, ll_node_t * node, void * const data) /* The memory taken by the deleted node must be freed by the caller. */ /* ================================================================= */ static int -ll_delete(ll_t * const list, ll_node_t * node) +ll_delete(ll_t * const list, ll_node_t *node) { if (list->head == list->tail) { @@ -840,10 +873,10 @@ ll_delete(ll_t * const list, ll_node_t * node) /* RC : : The number of elements of the resulting array. */ /* ==================================================================== */ static int -ll_strarray(ll_t * list, ll_node_t * start_node, int * count, char *** array) +ll_strarray(ll_t *list, ll_node_t *start_node, int *count, char ***array) { - int n = 0; - ll_node_t * node; + int n = 0; + ll_node_t *node; *count = 0; @@ -883,9 +916,9 @@ ll_strarray(ll_t * list, ll_node_t * start_node, int * count, char *** array) struct bst_s { - void * key; - struct bst_s * llink; - struct bst_s * rlink; + void *key; + struct bst_s *llink; + struct bst_s *rlink; }; #if 0 /* Unused yet. */ @@ -943,9 +976,9 @@ bst_delete(const void * vkey, void ** vrootp, /* is not freed. */ /* ===================================================================== */ static void -bst_destroy(void * vrootp, void (*clean)(void *)) +bst_destroy(void *vrootp, void (*clean)(void *)) { - bst_t * root = (bst_t *)vrootp; + bst_t *root = (bst_t *)vrootp; if (root == NULL) return; @@ -963,10 +996,11 @@ bst_destroy(void * vrootp, void (*clean)(void *)) /* Find a node, or return 0. */ /* ========================= */ static void * -bst_find(const void * vkey, void * const * vrootp, +bst_find(const void *vkey, + void * const *vrootp, int (*compar)(const void *, const void *)) { - bst_t * const * rootp = (bst_t * const *)vrootp; + bst_t * const *rootp = (bst_t * const *)vrootp; if (rootp == NULL) return NULL; @@ -987,11 +1021,10 @@ bst_find(const void * vkey, void * const * vrootp, /* Find or inserts datum into search tree. */ /* ======================================= */ static void * -bst_search(void * vkey, void ** vrootp, - int (*compar)(const void *, const void *)) +bst_search(void *vkey, void **vrootp, int (*compar)(const void *, const void *)) { - bst_t * q; - bst_t ** rootp = (bst_t **)vrootp; + bst_t *q; + bst_t **rootp = (bst_t **)vrootp; if (rootp == NULL) return NULL; @@ -1021,8 +1054,9 @@ bst_search(void * vkey, void ** vrootp, /* Walk the nodes of a tree. */ /* ========================= */ static void -bst_walk_recurse(const bst_t * root, - void (*action)(const void *, walk_order_e, int), int level) +bst_walk_recurse(const bst_t *root, + void (*action)(const void *, walk_order_e, int), + int level) { if (root->llink == NULL && root->rlink == NULL) (*action)(root, leaf, level); @@ -1039,7 +1073,7 @@ bst_walk_recurse(const bst_t * root, } static void -bst_walk(const void * vroot, void (*action)(const void *, walk_order_e, int)) +bst_walk(const void *vroot, void (*action)(const void *, walk_order_e, int)) { if (vroot != NULL && action != NULL) bst_walk_recurse(vroot, action, 0); @@ -1053,7 +1087,7 @@ bst_walk(const void * vroot, void (*action)(const void *, walk_order_e, int)) /* Trim leading characters. */ /* ======================== */ static void -ltrim(char * str, const char * trim_str) +ltrim(char *str, const char *trim_str) { size_t len = strlen(str); size_t begin = strspn(str, trim_str); @@ -1070,7 +1104,7 @@ ltrim(char * str, const char * trim_str) /* even if trailing spaces remain. */ /* ================================================= */ static void -rtrim(char * str, const char * trim_str, size_t min) +rtrim(char *str, const char *trim_str, size_t min) { size_t len = strlen(str); while (len > min && strchr(trim_str, str[len - 1])) @@ -1083,7 +1117,7 @@ rtrim(char * str, const char * trim_str, size_t min) /* The str pointer is assumed to be not NULL. */ /* ================================================== */ static int -strchrcount(char * str, char c) +strchrcount(char *str, char c) { int count = 0; @@ -1098,7 +1132,7 @@ strchrcount(char * str, char c) /* Is the string str2 a prefix of the string str1? */ /* =============================================== */ static int -strpref(char * str1, char * str2) +strpref(char *str1, char *str2) { while (*str1 != '\0' && *str1 == *str2) { @@ -1113,7 +1147,7 @@ strpref(char * str1, char * str2) /* Like strcmp ignoring case. */ /* ========================== */ static int -stricmp(const char * s1, const char * s2) +stricmp(const char *s1, const char *s2) { while (tolower((unsigned char)*s1) == tolower((unsigned char)*s2)) { @@ -1139,11 +1173,11 @@ stricmp(const char * s1, const char * s2) /* string. */ /* ====================================================================== */ static char * -strappend(char * str, ...) +strappend(char *str, ...) { size_t l; va_list args; - char * s; + char *s; l = 1 + strlen(str); va_start(args, str); @@ -1186,9 +1220,9 @@ strappend(char * str, ...) /* *end == NULL. */ /* ====================================================================== */ static char * -xstrtok_r(char * str, const char * delim, char ** end) +xstrtok_r(char *str, const char *delim, char **end) { - char * ret; + char *ret; if (str == NULL) str = *end; @@ -1221,9 +1255,9 @@ xstrtok_r(char * str, const char * delim, char ** end) /* trimmed before the call. */ /* ===================================================================== */ char * -get_word(char * str, char * buf, size_t len) +get_word(char *str, char *buf, size_t len) { - char * s = str; + char *s = str; /* Skip spaces. */ /* """""""""""" */ @@ -1252,7 +1286,7 @@ get_word(char * str, char * buf, size_t len) /* invalid is set to 0 in all the other cases. */ /* ==================================================================== */ static int -eval_yes(char * value, int * invalid) +eval_yes(char *value, int *invalid) { *invalid = 0; @@ -1273,7 +1307,7 @@ eval_yes(char * value, int * invalid) /* return: the number of words (<=max). */ /* =========================================================== */ static int -str2argv(char * str, char ** args, int max) +str2argv(char *str, char **args, int max) { int nb_args = 0; @@ -1319,19 +1353,22 @@ static flags_t flags = { 0, 1, 1 }; /* """""""""""""""""" */ struct ctx_s { - char * name; - ll_t * opt_list; /* list of options allowed in this context. */ - ll_t * incomp_list; /* list of strings containing incompatible names * - | of options separated by spaces or tabs. */ - ll_t * req_list; /* list of strings containing an option name and * - | all the option names where at least one of * - | them is required to be also present. */ - - int (*action)(char * name, int type, char * new_ctx, int ctx_nb_data, - void ** ctx_data); - void * par_bst; - int nb_data; - void ** data; + char *name; + ll_t *opt_list; /* list of options allowed in this context. */ + ll_t *incomp_list; /* list of strings containing incompatible names * + | of options separated by spaces or tabs. */ + ll_t *req_list; /* list of strings containing an option name and * + | all the option names where at least one of * + | them is required to be also present. */ + + int (*action)(char *name, + int type, + char *new_ctx, + int ctx_nb_data, + void **ctx_data); + void *par_bst; + int nb_data; + void **data; }; /* https://textik.com/#488ce3649b6c60f5 */ @@ -1360,27 +1397,27 @@ struct ctx_s /* """"""""""""""""" */ struct opt_s { - char * name; /* option name. */ - char * next_ctx; /* new context this option may lead to */ - ll_t * ctx_list; /* list of contexts allowing this option. */ - char * params; /* string containing all the parameters of * - | the option. */ - - void (*action)( /* The option associated action. */ - char * ctx_name, /* context name. */ - char * opt_name, /* option name. */ - char * par, /* option parameter. */ - int nb_args, /* number of arguments. */ - char ** args, /* option arguments. */ - int nb_opt_data, /* number of option data pointers. */ - |