From a71dd334fac0c4e41a05a894979ae02f9b0ce786 Mon Sep 17 00:00:00 2001 From: Olof hagsand Date: Wed, 31 Jan 2024 17:11:40 +0100 Subject: [PATCH] style: removed trailing spaces and added extra CR after each doc title --- CHANGELOG.md | 2 + cligen.h | 12 +- cligen_buf.c | 49 ++-- cligen_buf.h | 8 +- cligen_buf_internal.h | 10 +- cligen_callback.c | 16 +- cligen_callback.h | 4 +- cligen_custom.h | 6 +- cligen_cv.c | 512 +++++++++++++++++++------------------- cligen_cv.h | 18 +- cligen_cv_internal.h | 10 +- cligen_cvec.c | 22 +- cligen_cvec.h | 6 +- cligen_cvec_internal.h | 8 +- cligen_expand.c | 192 ++++++++------ cligen_expand.h | 15 +- cligen_file.c | 40 +-- cligen_getline.c | 178 +++++++------ cligen_getline.h | 5 +- cligen_handle.c | 168 ++++++++----- cligen_handle.h | 10 +- cligen_handle_internal.h | 17 +- cligen_hello.c | 8 +- cligen_history.c | 51 ++-- cligen_history.h | 8 +- cligen_history_internal.h | 12 +- cligen_io.c | 63 ++--- cligen_io.h | 8 +- cligen_match.c | 168 +++++++------ cligen_match.h | 12 +- cligen_object.c | 120 ++++----- cligen_object.h | 40 +-- cligen_parse.h | 10 +- cligen_parse.l | 35 +-- cligen_parse.y | 252 ++++++++++--------- cligen_parsetree.c | 58 ++--- cligen_parsetree.h | 9 +- cligen_print.c | 47 ++-- cligen_print.h | 4 +- cligen_pt_head.c | 53 ++-- cligen_pt_head.h | 4 +- cligen_read.c | 138 +++++----- cligen_read.h | 4 +- cligen_regex.c | 47 ++-- cligen_regex.h | 4 +- cligen_result.c | 19 +- cligen_result.h | 6 +- cligen_syntax.c | 55 ++-- cligen_syntax.h | 14 +- cligen_tutorial.c | 35 +-- cligen_util.c | 13 +- cligen_util.h | 4 +- 52 files changed, 1389 insertions(+), 1220 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 55487c4..b25140c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,8 @@ Expected: February 2024 ### Minor items +* Made coverity analysis and fixed most of them + * Some were ignored being for generated code (eg lex) or not applicable * Added vcprintf ## 6.5.0 diff --git a/cligen.h b/cligen.h index 0cf1ffa..51aec94 100644 --- a/cligen.h +++ b/cligen.h @@ -1,8 +1,8 @@ /* - CLIgen is a CLI generator. + CLIgen is a CLI generator. ***** BEGIN LICENSE BLOCK ***** - + Copyright (C) 2001-2022 Olof Hagsand This file is part of CLIgen. @@ -25,7 +25,7 @@ of those above. If you wish to allow use of your version of this file only under the terms of the GPL, and not to allow others to use your version of this file under the terms of Apache License version 2, indicate - your decision by deleting the provisions above and replace them with the + your decision by deleting the provisions above and replace them with the notice and other provisions required by the GPL. If you do not delete the provisions above, a recipient may use your version of this file under the terms of any one of the Apache License version 2 or the GPL. @@ -34,9 +34,9 @@ */ -/* +/* You include cligen.h which includes the other cligen include files for you. - All cligen include files are placed in the sub-directory cligen/cligen*.h. + All cligen include files are placed in the sub-directory cligen/cligen*.h. */ #include #include @@ -54,7 +54,7 @@ typedef void *cligen_handle; /* API */ #ifdef __cplusplus extern "C" { #endif - + #include #include #include diff --git a/cligen_buf.c b/cligen_buf.c index 773be56..5fa66a1 100644 --- a/cligen_buf.c +++ b/cligen_buf.c @@ -1,6 +1,6 @@ /* ***** BEGIN LICENSE BLOCK ***** - + Copyright (C) 2001-2022 Olof Hagsand This file is part of CLIgen. @@ -23,14 +23,14 @@ of those above. If you wish to allow use of your version of this file only under the terms of the GPL, and not to allow others to use your version of this file under the terms of Apache License version 2, indicate - your decision by deleting the provisions above and replace them with the + your decision by deleting the provisions above and replace them with the notice and other provisions required by the GPL. If you do not delete the provisions above, a recipient may use your version of this file under the terms of any one of the Apache License version 2 or the GPL. ***** END LICENSE BLOCK ***** - * CLIgen dynamic buffers + * CLIgen dynamic buffers * @code * cbuf *cb; * if ((cb = cbuf_new()) == NULL) @@ -46,7 +46,7 @@ * Constants */ /* Initial alloc mem length of a cbuf, then grows exponentially, with 2*, 4*, etc - * 1K could be a bit much for large syntaxes and small entries + * 1K could be a bit much for large syntaxes and small entries * @see cbuf_alloc_set */ #define CBUFLEN_START 1024 @@ -59,13 +59,13 @@ #include #include "cligen_buf.h" /* External API */ -#include "cligen_buf_internal.h" +#include "cligen_buf_internal.h" /* * Variables */ -/* This is how large an initial cbuf is after calling cbuf_new. Note that the cbuf - * may grow after calls to cprintf or cbuf_alloc +/* This is how large an initial cbuf is after calling cbuf_new. Note that the cbuf + * may grow after calls to cprintf or cbuf_alloc */ static size_t cbuflen_start = CBUFLEN_START; @@ -75,7 +75,8 @@ static size_t cbuflen_start = CBUFLEN_START; static size_t cbuflen_threshold = CBUFLEN_THRESHOLD; /*! Get global cbuf initial memory allocation size - * This is how large a cbuf is after calling cbuf_new. Note that the cbuf + * + * This is how large a cbuf is after calling cbuf_new. Note that the cbuf * may grow after calls to cprintf or cbuf_alloc * @param[out] default Initial default cbuf size * @param[out] threshold Threshold where cbuf grows linearly instead of exponentially @@ -90,7 +91,8 @@ cbuf_alloc_get(size_t *start, } /*! Set global cbuf initial memory allocation size - * This is how large a cbuf is after calling cbuf_new. Note that the cbuf + * + * This is how large a cbuf is after calling cbuf_new. Note that the cbuf * may grow after calls to cprintf or cbuf_alloc * If 0 continue with exponential growth */ @@ -104,6 +106,7 @@ cbuf_alloc_set(size_t start, } /*! Allocate cligen buffer. Returned handle can be used in sprintf calls + * * which dynamically print a string. * The handle should be freed by cbuf_free() * @param[in] How much buffer space for initial allocation @@ -130,6 +133,7 @@ cbuf_new_alloc(size_t sz) } /*! Allocate cligen buffer with auto buffer allocation. Returned handle can be used in sprintf calls + * * which dynamically print a string. * The handle should be freed by cbuf_free() * @retval cb The allocated objecyt handle on success. @@ -143,6 +147,7 @@ cbuf_new(void) } /*! Free cligen buffer previously allocated with cbuf_new + * * @param[in] cb Cligen buffer */ void @@ -156,6 +161,7 @@ cbuf_free(cbuf *cb) } /*! Return actual byte buffer of cligen buffer + * * @param[in] cb Cligen buffer */ char* @@ -165,6 +171,7 @@ cbuf_get(cbuf *cb) } /*! Return length of string in cligen buffer (not buffer length itself) + * * @param[in] cb Cligen buffer * @see cbuf_buflen */ @@ -175,6 +182,7 @@ cbuf_len(cbuf *cb) } /*! Return length of buffer itself, ie allocated bytes + * * @param[in] cb Cligen buffer * @see cbuf_len */ @@ -185,16 +193,18 @@ cbuf_buflen(cbuf *cb) } /*! Reset a cligen buffer. That is, restart it from scratch. + * * @param[in] cb Cligen buffer */ void cbuf_reset(cbuf *cb) { - cb->cb_strlen = 0; - cb->cb_buffer[0] = '\0'; + cb->cb_strlen = 0; + cb->cb_buffer[0] = '\0'; } /*! Internal buffer reallocator, Ensure buffer is large enough + * * use quadratic expansion (2* size) * @param[in] cb CLIgen buffer * @param[in] len Extra length added @@ -205,7 +215,7 @@ cbuf_realloc(cbuf *cb, { int retval = -1; int diff; - + diff = cb->cb_buflen - (cb->cb_strlen + sz + 1); if (diff <= 0){ while (diff <= 0){ @@ -224,7 +234,7 @@ cbuf_realloc(cbuf *cb, } /*! Append a cligen buf by printf like semantics - * + * * @param [in] cb cligen buffer allocated by cbuf_new(), may be reallocated. * @param [in] format arguments uses printf syntax. * @retval See printf @@ -232,7 +242,7 @@ cbuf_realloc(cbuf *cb, * @note cprintf assume null-terminated string as %s, use cbuf_memcp for a raw interface */ int -cprintf(cbuf *cb, +cprintf(cbuf *cb, const char *format, ...) { int retval = -1; @@ -271,7 +281,7 @@ vcprintf(cbuf *cb, int len; int ret; va_list ap1; - + va_copy(ap1, ap); if (cb == NULL) goto ok; @@ -373,10 +383,11 @@ cbuf_append_buf(cbuf *cb, } /*! Truncate cligen buf to a shorther length - * @param [in] cb cligen buffer allocated by cbuf_new(), may be reallocated. - * @param [in] i Truncate string to this length - * @retval 0 OK - * @retval -1 Error + * + * @param [in] cb cligen buffer allocated by cbuf_new(), may be reallocated. + * @param [in] i Truncate string to this length + * @retval 0 OK + * @retval -1 Error */ int cbuf_trunc(cbuf *cb, diff --git a/cligen_buf.h b/cligen_buf.h index 18bcee8..f922ea0 100644 --- a/cligen_buf.h +++ b/cligen_buf.h @@ -1,6 +1,6 @@ /* ***** BEGIN LICENSE BLOCK ***** - + Copyright (C) 2001-2022 Olof Hagsand This file is part of CLIgen. @@ -23,7 +23,7 @@ of those above. If you wish to allow use of your version of this file only under the terms of the GPL, and not to allow others to use your version of this file under the terms of Apache License version 2, indicate - your decision by deleting the provisions above and replace them with the + your decision by deleting the provisions above and replace them with the notice and other provisions required by the GPL. If you do not delete the provisions above, a recipient may use your version of this file under the terms of any one of the Apache License version 2 or the GPL. @@ -32,7 +32,7 @@ * * - * CLIgen dynamic buffers + * CLIgen dynamic buffers * @code * cbuf *cb; * if ((cb = cbuf_new()) == NULL) @@ -47,7 +47,7 @@ #ifndef _CLIGEN_BUF_H #define _CLIGEN_BUF_H -#include +#include /* * Types diff --git a/cligen_buf_internal.h b/cligen_buf_internal.h index 70acd9f..3ef2da5 100644 --- a/cligen_buf_internal.h +++ b/cligen_buf_internal.h @@ -1,6 +1,6 @@ /* ***** BEGIN LICENSE BLOCK ***** - + Copyright (C) 2001-2022 Olof Hagsand This file is part of CLIgen. @@ -23,15 +23,15 @@ of those above. If you wish to allow use of your version of this file only under the terms of the GPL, and not to allow others to use your version of this file under the terms of Apache License version 2, indicate - your decision by deleting the provisions above and replace them with the + your decision by deleting the provisions above and replace them with the notice and other provisions required by the GPL. If you do not delete the provisions above, a recipient may use your version of this file under the terms of any one of the Apache License version 2 or the GPL. ***** END LICENSE BLOCK ***** * - * This is an internal CLIgen header file - * Do not use these struct for external use, the internal structure may change. + * This is an internal CLIgen header file + * Do not use these struct for external use, the internal structure may change. * @see cligen_buf.h for external API use */ @@ -41,7 +41,7 @@ /* * Types */ -/*! Internal CLIgen buffer. +/*! Internal CLIgen buffer. */ struct cbuf { char *cb_buffer; /* pointer to buffer */ diff --git a/cligen_callback.c b/cligen_callback.c index bef3270..121908a 100644 --- a/cligen_callback.c +++ b/cligen_callback.c @@ -1,6 +1,6 @@ /* ***** BEGIN LICENSE BLOCK ***** - + Copyright (C) 2001-2022 Olof Hagsand This file is part of CLIgen. @@ -23,7 +23,7 @@ of those above. If you wish to allow use of your version of this file only under the terms of the GPL, and not to allow others to use your version of this file under the terms of Apache License version 2, indicate - your decision by deleting the provisions above and replace them with the + your decision by deleting the provisions above and replace them with the notice and other provisions required by the GPL. If you do not delete the provisions above, a recipient may use your version of this file under the terms of any one of the Apache License version 2 or the GPL. @@ -66,7 +66,7 @@ co_callback_next(cg_callback *cc) /*! Copy a linked list of cg_obj callback objects * - * Copy a linked list of cg_obj callback objects, including function pointer, + * Copy a linked list of cg_obj callback objects, including function pointer, * function name, * * @param[in] cc0 The object to copy from @@ -75,7 +75,7 @@ co_callback_next(cg_callback *cc) * @retval -1 Error */ int -co_callback_copy(cg_callback *cc0, +co_callback_copy(cg_callback *cc0, cg_callback **ccn) { int retval = -1; @@ -113,9 +113,9 @@ co_callback_copy(cg_callback *cc0, static int co_callback_one_free(cg_callback *cc) { - if (cc->cc_cvec) + if (cc->cc_cvec) cvec_free(cc->cc_cvec); - if (cc->cc_fn_str) + if (cc->cc_fn_str) free(cc->cc_fn_str); free(cc); return 0; @@ -129,7 +129,7 @@ int co_callbacks_free(cg_callback **ccp) { cg_callback *cc; - + while ((cc = *ccp) != NULL){ *ccp = co_callback_next(cc); co_callback_one_free(cc); @@ -145,7 +145,7 @@ co_callback2cbuf(cbuf *cb, { int i; cg_var *cv; - + if (cc->cc_fn_str){ cprintf(cb, ", %s(", cc->cc_fn_str); if (cc->cc_cvec){ diff --git a/cligen_callback.h b/cligen_callback.h index 0fb1484..92b74db 100644 --- a/cligen_callback.h +++ b/cligen_callback.h @@ -1,6 +1,6 @@ /* ***** BEGIN LICENSE BLOCK ***** - + Copyright (C) 2001-2022 Olof Hagsand This file is part of CLIgen. @@ -23,7 +23,7 @@ of those above. If you wish to allow use of your version of this file only under the terms of the GPL, and not to allow others to use your version of this file under the terms of Apache License version 2, indicate - your decision by deleting the provisions above and replace them with the + your decision by deleting the provisions above and replace them with the notice and other provisions required by the GPL. If you do not delete the provisions above, a recipient may use your version of this file under the terms of any one of the Apache License version 2 or the GPL. diff --git a/cligen_custom.h b/cligen_custom.h index 47769d8..c35c769 100644 --- a/cligen_custom.h +++ b/cligen_custom.h @@ -1,6 +1,6 @@ /* ***** BEGIN LICENSE BLOCK ***** - + Copyright (C) 2001-2022 Olof Hagsand This file is part of CLIgen. @@ -23,7 +23,7 @@ of those above. If you wish to allow use of your version of this file only under the terms of the GPL, and not to allow others to use your version of this file under the terms of Apache License version 2, indicate - your decision by deleting the provisions above and replace them with the + your decision by deleting the provisions above and replace them with the notice and other provisions required by the GPL. If you do not delete the provisions above, a recipient may use your version of this file under the terms of any one of the Apache License version 2 or the GPL. @@ -31,7 +31,7 @@ ***** END LICENSE BLOCK ***** - Custom file as boilerplate appended by cligen_config.h + Custom file as boilerplate appended by cligen_config.h */ #if 1 /* SANITY CHECK */ diff --git a/cligen_cv.c b/cligen_cv.c index efb19f4..ec57a68 100644 --- a/cligen_cv.c +++ b/cligen_cv.c @@ -1,6 +1,5 @@ /* ***** BEGIN LICENSE BLOCK ***** - Copyright (C) 2001-2022 Olof Hagsand This file is part of CLIgen. @@ -23,7 +22,7 @@ of those above. If you wish to allow use of your version of this file only under the terms of the GPL, and not to allow others to use your version of this file under the terms of Apache License version 2, indicate - your decision by deleting the provisions above and replace them with the + your decision by deleting the provisions above and replace them with the notice and other provisions required by the GPL. If you do not delete the provisions above, a recipient may use your version of this file under the terms of any one of the Apache License version 2 or the GPL. @@ -32,7 +31,7 @@ CLIgen variables - cgv - cgv:s are created when parsing an input string as instances of cg_obj variable + cgv:s are created when parsing an input string as instances of cg_obj variable when matching. Note that a cg_obj is a syntax object and contains a part that specifies cgv:s called cov */ @@ -90,12 +89,12 @@ static char *cg_urlprotostr[] = { char * cv_name_get(cg_var *cv) { - if (cv == NULL) + if (cv == NULL) return 0; return cv->var_name; } -/*! Set new CLIgen varable name. +/*! Set new CLIgen varable name. * * Free previous string if existing. * @param[in] cv CLIgen variable @@ -104,14 +103,13 @@ cv_name_get(cg_var *cv) * @retval NULL Error */ char * -cv_name_set(cg_var *cv, - const char *s0) +cv_name_set(cg_var *cv, + const char *s0) { char *s1 = NULL; - if (cv == NULL) + if (cv == NULL) return 0; - /* Duplicate s0. Must be done before a free, in case s0 is part of the original */ if (s0){ if ((s1 = strdup(s0)) == NULL) @@ -120,7 +118,7 @@ cv_name_set(cg_var *cv, if (cv->var_name != NULL) free(cv->var_name); cv->var_name = s1; - return s1; + return s1; } /*! Get cv type @@ -131,22 +129,22 @@ cv_name_set(cg_var *cv, enum cv_type cv_type_get(cg_var *cv) { - if (cv == NULL) + if (cv == NULL) return 0; return cv->var_type; } -/*! Set new CLIgen type. +/*! Set new CLIgen type. * * @param[in] cv CLIgen variable * @param[in] t New type * @retval t New type */ enum cv_type -cv_type_set(cg_var *cv, +cv_type_set(cg_var *cv, enum cv_type x) { - if (cv == NULL) + if (cv == NULL) return 0; return (cv->var_type = x); } @@ -159,19 +157,19 @@ cv_type_set(cg_var *cv, char cv_const_get(cg_var *cv) { - if (cv == NULL) + if (cv == NULL) return 0; return cv->var_const; } -/*! Set CLIgen const flag. +/*! Set CLIgen const flag. * * @param[in] cv CLIgen variable * @param[in] t New type * @retval t New type */ char -cv_const_set(cg_var *cv, +cv_const_set(cg_var *cv, int c) { if (cv == NULL) @@ -185,7 +183,7 @@ cv_const_set(cg_var *cv, * @see cv_flag_set */ char -cv_flag(cg_var *cv, +cv_flag(cg_var *cv, char mask) { if (cv == NULL) @@ -193,12 +191,12 @@ cv_flag(cg_var *cv, return cv->var_flag & mask; } -/*! Clear application-specific cv flag +/*! Clear application-specific cv flag * * @param[in] cv CLIgen variable */ char -cv_flag_clr(cg_var *cv, +cv_flag_clr(cg_var *cv, char mask) { if (cv == NULL) @@ -206,16 +204,16 @@ cv_flag_clr(cg_var *cv, return cv->var_flag ^= mask; } -/*! Set application-specific cv flag +/*! Set application-specific cv flag * * @param[in] cv CLIgen variable * @see cv_flag */ char -cv_flag_set(cg_var *cv, +cv_flag_set(cg_var *cv, char mask) { - if (cv == NULL) + if (cv == NULL) return 0; return cv->var_flag |= mask; } @@ -227,7 +225,7 @@ cv_flag_set(cg_var *cv, char cv_bool_get(cg_var *cv) { - if (cv == NULL) + if (cv == NULL) return 0; return ((cv)->u.varu_bool); } @@ -237,10 +235,10 @@ cv_bool_get(cg_var *cv) * @param[in] cv CLIgen variable */ char -cv_bool_set(cg_var *cv, +cv_bool_set(cg_var *cv, char x) { - if (cv == NULL) + if (cv == NULL) return 0; return (cv->u.varu_bool = x); } @@ -252,7 +250,7 @@ cv_bool_set(cg_var *cv, int8_t cv_int8_get(cg_var *cv) { - if (cv == NULL) + if (cv == NULL) return 0; return ((cv)->u.varu_int8); } @@ -262,10 +260,10 @@ cv_int8_get(cg_var *cv) * @param[in] cv CLIgen variable */ int8_t -cv_int8_set(cg_var *cv, +cv_int8_set(cg_var *cv, int8_t x) { - if (cv == NULL) + if (cv == NULL) return 0; return (cv->u.varu_int8 = x); } @@ -277,7 +275,7 @@ cv_int8_set(cg_var *cv, int16_t cv_int16_get(cg_var *cv) { - if (cv == NULL) + if (cv == NULL) return 0; return ((cv)->u.varu_int16); } @@ -287,10 +285,10 @@ cv_int16_get(cg_var *cv) * @param[in] cv CLIgen variable */ int16_t -cv_int16_set(cg_var *cv, +cv_int16_set(cg_var *cv, int16_t x) { - if (cv == NULL) + if (cv == NULL) return 0; return (cv->u.varu_int16 = x); } @@ -302,7 +300,7 @@ cv_int16_set(cg_var *cv, int32_t cv_int32_get(cg_var *cv) { - if (cv == NULL) + if (cv == NULL) return 0; return ((cv)->u.varu_int32); } @@ -312,10 +310,10 @@ cv_int32_get(cg_var *cv) * @param[in] cv CLIgen variable */ int32_t -cv_int32_set(cg_var *cv, +cv_int32_set(cg_var *cv, int32_t x) { - if (cv == NULL) + if (cv == NULL) return 0; return (cv->u.varu_int32 = x); } @@ -327,7 +325,7 @@ cv_int32_set(cg_var *cv, int64_t cv_int64_get(cg_var *cv) { - if (cv == NULL) + if (cv == NULL) return 0; return ((cv)->u.varu_int64); } @@ -337,10 +335,10 @@ cv_int64_get(cg_var *cv) * @param[in] cv CLIgen variable */ int64_t -cv_int64_set(cg_var *cv, +cv_int64_set(cg_var *cv, int64_t x) { - if (cv == NULL) + if (cv == NULL) return 0; return (cv->u.varu_int64 = x); } @@ -352,7 +350,7 @@ cv_int64_set(cg_var *cv, uint8_t cv_uint8_get(cg_var *cv) { - if (cv == NULL) + if (cv == NULL) return 0; return ((cv)->u.varu_uint8); } @@ -365,7 +363,7 @@ uint8_t cv_uint8_set(cg_var *cv, uint8_t x) { - if (cv == NULL) + if (cv == NULL) return 0; return (cv->u.varu_uint8 = x); } @@ -377,7 +375,7 @@ cv_uint8_set(cg_var *cv, uint16_t cv_uint16_get(cg_var *cv) { - if (cv == NULL) + if (cv == NULL) return 0; return ((cv)->u.varu_uint16); } @@ -387,7 +385,7 @@ cv_uint16_get(cg_var *cv) * @param[in] cv CLIgen variable */ uint16_t -cv_uint16_set(cg_var *cv, +cv_uint16_set(cg_var *cv, uint16_t x) { return (cv->u.varu_uint16 = x); @@ -400,7 +398,7 @@ cv_uint16_set(cg_var *cv, uint32_t cv_uint32_get(cg_var *cv) { - if (cv == NULL) + if (cv == NULL) return 0; return ((cv)->u.varu_uint32); } @@ -410,10 +408,10 @@ cv_uint32_get(cg_var *cv) * @param[in] cv CLIgen variable */ uint32_t -cv_uint32_set(cg_var *cv, +cv_uint32_set(cg_var *cv, uint32_t x) { - if (cv == NULL) + if (cv == NULL) return 0; return (cv->u.varu_uint32 = x); } @@ -425,7 +423,7 @@ cv_uint32_set(cg_var *cv, uint64_t cv_uint64_get(cg_var *cv) { - if (cv == NULL) + if (cv == NULL) return 0; return ((cv)->u.varu_uint64); } @@ -435,10 +433,10 @@ cv_uint64_get(cg_var *cv) * @param[in] cv CLIgen variable */ uint64_t -cv_uint64_set(cg_var *cv, +cv_uint64_set(cg_var *cv, uint64_t x) { - if (cv == NULL) + if (cv == NULL) return 0; return (cv->u.varu_uint64 = x); } @@ -447,10 +445,10 @@ cv_uint64_set(cg_var *cv, * * @param[in] cv CLIgen variable */ -uint8_t +uint8_t cv_dec64_n_get(cg_var *cv) { - if (cv == NULL) + if (cv == NULL) return 0; return ((cv)->var_dec64_n); } @@ -458,13 +456,13 @@ cv_dec64_n_get(cg_var *cv) /*! Set n-value of decimal-64 of cv (eg exponent) * * @param[in] cv CLIgen variable - * XXX range check? 1..18 + * XXX range check? 1..18 */ -uint8_t -cv_dec64_n_set(cg_var *cv, +uint8_t +cv_dec64_n_set(cg_var *cv, uint8_t x) { - if (cv == NULL) + if (cv == NULL) return 0; return (cv->var_dec64_n = x); } @@ -473,10 +471,10 @@ cv_dec64_n_set(cg_var *cv, * * @param[in] cv CLIgen variable */ -int64_t +int64_t cv_dec64_i_get(cg_var *cv) { - if (cv == NULL) + if (cv == NULL) return 0; return ((cv)->var_dec64_i); } @@ -485,16 +483,16 @@ cv_dec64_i_get(cg_var *cv) * * @param[in] cv CLIgen variable */ -int64_t -cv_dec64_i_set(cg_var *cv, +int64_t +cv_dec64_i_set(cg_var *cv, int64_t x) { - if (cv == NULL) + if (cv == NULL) return 0; return (cv->var_dec64_i = x); } -/*! Get pointer to cv string. +/*! Get pointer to cv string. * * @param[in] cv CLIgen variable * String can be modified in-line but must call _set function to reallocate. @@ -502,12 +500,12 @@ cv_dec64_i_set(cg_var *cv, char * cv_string_get(cg_var *cv) { - if (cv == NULL) + if (cv == NULL) return 0; return ((cv)->u.varu_string); } -/*! Allocate new string from original NULL-terminated string. Malloc new string and free previous +/*! Allocate new string from original NULL-terminated string. Malloc new string and free previous * * @param[in] cv CLIgen variable * @param[in] s0 String to copy from @@ -515,7 +513,7 @@ cv_string_get(cg_var *cv) * @retval NULL Error */ char * -cv_string_set(cg_var *cv, +cv_string_set(cg_var *cv, const char *s0) { char *s1 = NULL; @@ -534,10 +532,10 @@ cv_string_set(cg_var *cv, if (cv->u.varu_string != NULL) free(cv->u.varu_string); cv->u.varu_string = s1; - return s1; + return s1; } -/*! Set new string without malloc +/*! Set new string without malloc * * @param[in] cv CLIgen variable * @param[in] s String to directly assign (must have been alloced) @@ -545,7 +543,7 @@ cv_string_set(cg_var *cv, * @retval -1 Error */ int -cv_string_set_direct(cg_var *cv, +cv_string_set_direct(cg_var *cv, char *s) { if (cv == NULL){ @@ -559,7 +557,7 @@ cv_string_set_direct(cg_var *cv, if (cv->u.varu_string != NULL) free(cv->u.varu_string); cv->u.varu_string = s; - return 0; + return 0; } /*! Allocate new string from original by copying using strncpy @@ -571,7 +569,7 @@ cv_string_set_direct(cg_var *cv, * @retval NULL Error */ char * -cv_strncpy(cg_var *cv, +cv_strncpy(cg_var *cv, char *s0, size_t n) { @@ -593,7 +591,7 @@ cv_strncpy(cg_var *cv, if (cv->u.varu_string != NULL) free(cv->u.varu_string); cv->u.varu_string = s1; - return s1; + return s1; } /*! Get ipv4addr, pointer returned, can be used to set value. @@ -603,7 +601,7 @@ cv_strncpy(cg_var *cv, struct in_addr * cv_ipv4addr_get(cg_var *cv) { - if (cv == NULL) + if (cv == NULL) return 0; return &cv->u.varu_ipv4addr.varipv4_ipv4addr; } @@ -617,7 +615,7 @@ struct in_addr * cv_ipv4addr_set(cg_var *cv, struct in_addr *addr) { - if (cv && addr) + if (cv && addr) cv->var_ipv4addr = *addr; return addr; } @@ -629,7 +627,7 @@ cv_ipv4addr_set(cg_var *cv, uint8_t cv_ipv4masklen_get(cg_var *cv) { - if (cv == NULL) + if (cv == NULL) return 0; return cv->u.varu_ipv4addr.varipv4_masklen; } @@ -642,7 +640,7 @@ cv_ipv4masklen_get(cg_var *cv) uint8_t cv_ipv4masklen_set(cg_var *cv, uint8_t masklen) { - if (cv == NULL) + if (cv == NULL) return 0; cv->u.varu_ipv4addr.varipv4_masklen = masklen; return masklen; @@ -655,7 +653,7 @@ cv_ipv4masklen_set(cg_var *cv, uint8_t masklen) struct in6_addr * cv_ipv6addr_get(cg_var *cv) { - if (cv == NULL) + if (cv == NULL) return 0; return &cv->u.varu_ipv6addr.varipv6_ipv6addr; } @@ -667,12 +665,12 @@ cv_ipv6addr_get(cg_var *cv) uint8_t cv_ipv6masklen_get(cg_var *cv) { - if (cv == NULL) + if (cv == NULL) return 0; return cv->u.varu_ipv6addr.varipv6_masklen; } -/*! Returns a pointer to 6-byte mac-address array. +/*! Returns a pointer to 6-byte mac-address array. * * @param[in] cv CLIgen variable * This can be used to set the address too @@ -680,20 +678,20 @@ cv_ipv6masklen_get(cg_var *cv) char * cv_mac_get(cg_var *cv) { - if (cv == NULL) + if (cv == NULL) return 0; return cv->u.varu_macaddr; } -/*! Returns a pointer to uuid byte array. - * +/*! Returns a pointer to uuid byte array. + * * @param[in] cv CLIgen variable * This can be used to set the uuid too. */ unsigned char * cv_uuid_get(cg_var *cv) { - if (cv == NULL) + if (cv == NULL) return 0; return cv->u.varu_uuid; } @@ -703,10 +701,10 @@ cv_uuid_get(cg_var *cv) * @param[in] cv CLIgen variable */ unsigned char * -cv_uuid_set(cg_var *cv, +cv_uuid_set(cg_var *cv, unsigned char *u) { - if (cv == NULL) + if (cv == NULL) return 0; memcpy((char*)&cv->u.varu_uuid, u, 16); return cv->u.varu_uuid; @@ -732,7 +730,7 @@ cv_time_get(cg_var *cv) * Returns a struct timeval by value. */ struct timeval -cv_time_set(cg_var *cv, +cv_time_set(cg_var *cv, struct timeval t) { if (cv == NULL) { @@ -760,7 +758,7 @@ cv_void_get(cg_var *cv) * @param[in] cv CLIgen variable */ int -cv_void_set(cg_var *cv, +cv_void_set(cg_var *cv, void *p) { if (cv) @@ -768,7 +766,7 @@ cv_void_set(cg_var *cv, return 0; } -/*! Get pointer to URL proto string. +/*! Get pointer to URL proto string. * * @param[in] cv CLIgen variable * String can be modified in-line but must call _set function to reallocate. @@ -776,7 +774,7 @@ cv_void_set(cg_var *cv, char * cv_urlproto_get(cg_var *cv) { - if (cv == NULL) + if (cv == NULL) return 0; return (cv)->u.varu_url.varurl_proto; } @@ -787,7 +785,7 @@ cv_urlproto_get(cg_var *cv) * @param[in] cv CLIgen variable */ char * -cv_urlproto_set(cg_var *cv, +cv_urlproto_set(cg_var *cv, const char *s0) { char *s1 = NULL; @@ -803,10 +801,10 @@ cv_urlproto_set(cg_var *cv, if (cv->u.varu_url.varurl_proto != NULL) free(cv->u.varu_url.varurl_proto); cv->u.varu_url.varurl_proto = s1; - return s1; + return s1; } -/*! Get pointer to URL address string. +/*! Get pointer to URL address string. * * @param[in] cv CLIgen variable * String can be modified in-line but must call _set function to reallocate. @@ -827,7 +825,7 @@ cv_urladdr_get(cg_var *cv) * malloc new string from original. Free previous string if existing. */ char * -cv_urladdr_set(cg_var *cv, +cv_urladdr_set(cg_var *cv, const char *s0) { char *s1 = NULL; @@ -844,10 +842,10 @@ cv_urladdr_set(cg_var *cv, if (cv->u.varu_url.varurl_addr != NULL) free(cv->u.varu_url.varurl_addr); cv->u.varu_url.varurl_addr = s1; - return s1; + return s1; } -/*! Get pointer to URL path string. +/*! Get pointer to URL path string. * * @param[in] cv CLIgen variable * String can be modified in-line but must call _set function to reallocate. @@ -868,7 +866,7 @@ cv_urlpath_get(cg_var *cv) * malloc new string from original. Free previous string if existing. */ char * -cv_urlpath_set(cg_var *cv, +cv_urlpath_set(cg_var *cv, const char *s0) { char *s1 = NULL; @@ -884,10 +882,10 @@ cv_urlpath_set(cg_var *cv, if (cv->u.varu_url.varurl_path != NULL) free(cv->u.varu_url.varurl_path); cv->u.varu_url.varurl_path = s1; - return s1; + return s1; } -/*! Get pointer to URL user string. +/*! Get pointer to URL user string. * * @param[in] cv CLIgen variable * String can be modified in-line but must call _set function to reallocate. @@ -908,7 +906,7 @@ cv_urluser_get(cg_var *cv) * @param[in] cv CLIgen variable */ char * -cv_urluser_set(cg_var *cv, +cv_urluser_set(cg_var *cv, const char *s0) { char *s1 = NULL; @@ -924,10 +922,10 @@ cv_urluser_set(cg_var *cv, if (cv->u.varu_url.varurl_user != NULL) free(cv->u.varu_url.varurl_user); cv->u.varu_url.varurl_user = s1; - return s1; + return s1; } -/*! Get pointer to URL passwd string. +/*! Get pointer to URL passwd string. * * @param[in] cv CLIgen variable * String can be modified in-line but must call _set function to reallocate. @@ -948,7 +946,7 @@ cv_urlpasswd_get(cg_var *cv) * malloc new string from original. Free previous string if existing. */ char * -cv_urlpasswd_set(cg_var *cv, +cv_urlpasswd_set(cg_var *cv, const char *s0) { char *s1 = NULL; @@ -964,7 +962,7 @@ cv_urlpasswd_set(cg_var *cv, if (cv->u.varu_url.varurl_passwd != NULL) free(cv->u.varu_url.varurl_passwd); cv->u.varu_url.varurl_passwd = s1; - return s1; + return s1; } /*! Parse an int64 number with explicit base and check for errors @@ -974,7 +972,7 @@ cv_urlpasswd_set(cg_var *cv, * the number will be read in base 16; otherwise, a zero base * is taken as 10 (decimal) unless the next character is '0', * in which case it is taken as 8 (octal). - * @param[in] imin Min range (set INT64_MIN for default) + * @param[in] imin Min range (set INT64_MIN for default) * @param[in] imax Max range (set INT64_MAX for default) * @param[out] val Value on success * @param[out] reason Error string on failure @@ -983,10 +981,10 @@ cv_urlpasswd_set(cg_var *cv, * @retval -1 Error (fatal), with errno set to indicate error */ static int -parse_int64_base(char *str, +parse_int64_base(char *str, int base, int64_t imin, - int64_t imax, + int64_t imax, int64_t *val, char **reason) { @@ -1006,7 +1004,7 @@ parse_int64_base(char *str, goto done; } if (errno != 0){ - if ((i == INT64_MIN || i == INT64_MAX) && errno == ERANGE){ + if ((i == INT64_MIN || i == INT64_MAX) && errno == ERANGE){ errno = 0; if (reason != NULL) if ((*reason = cligen_reason("Number %s out of range: %" PRId64 " - %" PRId64, str, imin, imax)) == NULL){ @@ -1050,13 +1048,13 @@ parse_int64_base(char *str, * @retval -1 Error (fatal), with errno set to indicate error */ int -parse_int8(char *str, +parse_int8(char *str, int8_t *val, char **reason) { int64_t i; int retval; - + if ((retval = parse_int64_base(str, 0, -128, 127, &i, reason)) != 1) goto done; *val = (int8_t)i; @@ -1074,13 +1072,13 @@ parse_int8(char *str, * @retval -1 Error (fatal), with errno set to indicate error */ int -parse_int16(char *str, - int16_t *val, +parse_int16(char *str, + int16_t *val, char **reason) { int64_t i; int retval; - + if ((retval = parse_int64_base(str, 0, -32768, 32767, &i, reason)) != 1) goto done; *val = (int16_t)i; @@ -1098,13 +1096,13 @@ parse_int16(char *str, * @retval -1 Error (fatal), with errno set to indicate error */ int -parse_int32(char *str, - int32_t *val, +parse_int32(char *str, + int32_t *val, char **reason) { int64_t i; int retval; - + if ((retval = parse_int64_base(str, 0, INT_MIN, INT_MAX, &i, reason)) != 1) goto done; *val = (int32_t)i; @@ -1122,7 +1120,7 @@ parse_int32(char *str, * @retval -1 Error (fatal), with errno set to indicate error */ int -parse_int64(char *str, +parse_int64(char *str, int64_t *val, char **reason) { @@ -1136,7 +1134,7 @@ parse_int64(char *str, * the number will be read in base 16; otherwise, a zero base * is taken as 10 (decimal) unless the next character is '0', * in which case it is taken as 8 (octal). - * @param[in] umin Min range (set UINT64_MIN for default) + * @param[in] umin Min range (set UINT64_MIN for default) * @param[in] umax Max range (set UINT64_MAX for default) * @param[out] val Value on success * @param[out] reason Error string on failure (if given) @@ -1146,11 +1144,11 @@ parse_int64(char *str, * @note: we have to detect a minus sign ourselves,.... */ static int -parse_uint64_base(char *str, +parse_uint64_base(char *str, int base, uint64_t umin, - uint64_t umax, - uint64_t *val, + uint64_t umax, + uint64_t *val, char **reason) { uint64_t i; @@ -1169,7 +1167,7 @@ parse_uint64_base(char *str, goto done; } if (errno != 0){ - if (i == UINT64_MAX && errno == ERANGE){ + if (i == UINT64_MAX && errno == ERANGE){ if (reason != NULL) if ((*reason = cligen_reason("Number %s out of range: 0 - %" PRIu64, str, umax)) == NULL){ retval = -1; /* malloc */ @@ -1222,13 +1220,13 @@ parse_uint64_base(char *str, * @retval -1 Error (fatal), with errno set to indicate error */ int -parse_uint8(char *str, - uint8_t *val, +parse_uint8(char *str, + uint8_t *val, char **reason) { uint64_t i; int retval; - + if ((retval = parse_uint64_base(str, 0, 0, 255, &i, reason)) != 1) goto done; *val = (uint8_t)i; @@ -1246,13 +1244,13 @@ parse_uint8(char *str, * @retval -1 Error (fatal), with errno set to indicate error */ int -parse_uint16(char *str, - uint16_t *val, +parse_uint16(char *str, + uint16_t *val, char **reason) { uint64_t i; int retval; - + if ((retval = parse_uint64_base(str, 0, 0, 65535, &i, reason)) != 1) goto done; *val = (uint16_t)i; @@ -1270,13 +1268,13 @@ parse_uint16(char *str, * @retval -1 Error (fatal), with errno set to indicate error */ int -parse_uint32(char *str, - uint32_t *val, +parse_uint32(char *str, + uint32_t *val, char **reason) { uint64_t i; int retval; - + if ((retval = parse_uint64_base(str, 0, 0, UINT_MAX, &i, reason)) != 1) goto done; *val = (uint32_t)i; @@ -1295,7 +1293,7 @@ parse_uint32(char *str, * @note: we have to detect a minus sign ourselves,.... */ int -parse_uint64(char *str, +parse_uint64(char *str, uint64_t *val, char **reason) { @@ -1313,9 +1311,9 @@ parse_uint64(char *str, * @retval -1 fatal error */ int -parse_dec64(char *str, - uint8_t n, - int64_t *dec64_i, +parse_dec64(char *str, + uint8_t n, + int64_t *dec64_i, char **reason) { int retval = 1; @@ -1373,9 +1371,9 @@ parse_dec64(char *str, retval = 0; goto done; } - memcpy(ss+len1, s2, len2); + memcpy(ss+len1, s2, len2); } - /* Fill out with trailing zeroes if any + /* Fill out with trailing zeroes if any | s1 | s2 | */ for (i=len1+len2; i://[[:]@][/]. May + * @param[in] url Syntax: ://[[:]@][/]. May * be changed destructively * @param[in] cv CLIgen variable * @param[out] reason if given, malloced err string (retval=0), needs freeing - * URL syntax: Syntax: ://[[:]@][/]. + * URL syntax: Syntax: ://[[:]@][/]. * @note The syntax is not complete: it is recommended to use regexps */ static int -parse_url(char *url, - cg_var *cv, +parse_url(char *url, + cg_var *cv, char **reason) { char *str0 = NULL; @@ -1622,7 +1620,7 @@ parse_url(char *url, goto warn; *tmp = '\0'; cv->var_urlproto = strdup(str); - str = tmp+3; + str = tmp+3; if ((tmp = strchr(str, '@')) != NULL){ /* user field */ *tmp = '\0'; @@ -1664,7 +1662,7 @@ parse_url(char *url, /*! Translate url protocol string to enum * - * @param[in] str + * @param[in] str */ int str2urlproto(const char *str) @@ -1683,36 +1681,36 @@ str2urlproto(const char *str) /*! Translate uuid binary data structure to uuid ascii string * * @param[in] u UUID as binary data structure - * @param[out] fmt Format string. + * @param[out] fmt Format string. * @param[in] len Length of fmt needs to be at 37. * @retval 0 OK * @retval -1 Error */ int -uuid2str(uuid_t u, - char *fmt, +uuid2str(uuid_t u, + char *fmt, int len) { - snprintf(fmt, len, - "%02x%02x%02x%02x-" "%02x%02x-" "%02x%02x-" "%02x%02x-" - "%02x%02x%02x%02x%02x%02x", + snprintf(fmt, len, + "%02x%02x%02x%02x-" "%02x%02x-" "%02x%02x-" "%02x%02x-" + "%02x%02x%02x%02x%02x%02x", u[0]&0xff, u[1]&0xff, u[2]&0xff, u[3]&0xff, - u[4]&0xff, u[5]&0xff, u[6]&0xff, u[7]&0xff, - u[8]&0xff, u[9]&0xff, u[10]&0xff, u[11]&0xff, + u[4]&0xff, u[5]&0xff, u[6]&0xff, u[7]&0xff, + u[8]&0xff, u[9]&0xff, u[10]&0xff, u[11]&0xff, u[12]&0xff, u[13]&0xff, u[14]&0xff, u[15]&0xff); return 0; } /*! Given a single hex character, return its number as int */ -static int +static int toint(char c) { - if (c >= '0' && c <= '9') + if (c >= '0' && c <= '9') return c - '0'; - if (c >= 'A' && c <= 'F') + if (c >= 'A' && c <= 'F') return 10 + c - 'A'; - if (c >= 'a' && c <= 'f') + if (c >= 'a' && c <= 'f') return 10 + c - 'a'; return -1; } @@ -1726,7 +1724,7 @@ toint(char c) * @retval -1 Error */ int -str2uuid(const char *in, +str2uuid(const char *in, uuid_t u) { int i = 0, j = 0, k; @@ -1736,11 +1734,11 @@ str2uuid(const char *in, if (strlen(in) != 36) return -1; for (k=0; k<4; k++){ - a = toint(in[j++]); + a = toint(in[j++]); b = toint(in[j++]); if (a < 0 || b < 0) goto done; - u[i++] = (a << 4) | b; + u[i++] = (a << 4) | b; } if (in[j++] != '-') goto done; @@ -1748,7 +1746,7 @@ str2uuid(const char *in, a = toint(in[j++]); b = toint(in[j++]); if (a < 0 || b < 0) goto done; - u[i++] = (a << 4) | b; + u[i++] = (a << 4) | b; } if (in[j++] != '-') goto done; @@ -1756,7 +1754,7 @@ str2uuid(const char *in, a = toint(in[j++]); b = toint(in[j++]); if (a < 0 || b < 0) goto done; - u[i++] = (a << 4) | b; + u[i++] = (a << 4) | b; } if (in[j++] != '-') goto done; @@ -1764,7 +1762,7 @@ str2uuid(const char *in, a = toint(in[j++]); b = toint(in[j++]); if (a < 0 || b < 0) goto done; - u[i++] = (a << 4) | b; + u[i++] = (a << 4) | b; } if (in[j++] != '-') goto done; @@ -1772,7 +1770,7 @@ str2uuid(const char *in, a = toint(in[j++]); b = toint(in[j++]); if (a < 0 || b < 0) goto done; - u[i++] = (a << 4) | b; + u[i++] = (a << 4) | b; } if (in[j] != '\0') goto done; @@ -1783,10 +1781,10 @@ str2uuid(const char *in, /*! Given a single digit character, return its number as int */ -static int +static int todig(char c) { - if (c >= '0' && c <= '9') + if (c >= '0' && c <= '9') return c - '0'; return -1; } @@ -1801,7 +1799,7 @@ todig(char c) * @note works for positive numbers and up to 2^31 */ int -cligen_tonum(int n, +cligen_tonum(int n, const char *s) { int i; @@ -1829,7 +1827,7 @@ cligen_tonum(int n, * @retval -1 Error * T can be space. * in-string is upto 26 bytes + null termination (27 bytes in total). - * out timestamp is a 4+4 integer struct timeval + * out timestamp is a 4+4 integer struct timeval * returns 0 if OK parses. -1 if not correct. * usec can be 1-6 digits. That is, .3 means 300000 usec. * @note : string coming in is expected to be UTC and we parse that into a tm struct and @@ -1843,7 +1841,7 @@ cligen_tonum(int n, * @see time2str */ int -str2time(const char *in, +str2time(const char *in, struct timeval *tv) { int retval = -1; @@ -1938,7 +1936,7 @@ str2time(const char *in, case 'Z': /* does not parse zone*/ i++; break; - case '+': + case '+': case '-': /* not parsed */ goto mkdate; case '\0': @@ -1959,11 +1957,11 @@ str2time(const char *in, tm->tm_hour = hour; tm->tm_min = min; tm->tm_sec = sec; - if ((t = mktime(tm)) < 0) + if ((t = mktime(tm)) < 0) goto done; #if 0 /* If I enable this, I get 1h extra when loading from file in summer. When parsing a timestamp such as 2013-04-03T10:50:36 from file to cv - (and db). So that when it is printed again it is 2013-04-03T11:50:36 + (and db). So that when it is printed again it is 2013-04-03T11:50:36 I dont know why I enabled it in the first place. That is why I make this note. */ @@ -1972,16 +1970,16 @@ str2time(const char *in, #endif /* Must adjust with timezone, since mktime() assumes tm i local but it is UTC! */ #ifdef linux - t = t - timezone; + t = t - timezone; #else { struct timeval tv; struct timezone tz; gettimeofday(&tv, &tz); - t = t - tz.tz_minuteswest*60; + t = t - tz.tz_minuteswest*60; } #endif - tv->tv_sec = t; + tv->tv_sec = t; tv->tv_usec = usec; retval = 0; done: @@ -1994,7 +1992,7 @@ str2time(const char *in, * * from timeval to ISO 8601 date+time on the form 2008-09-21T18:57:21.003456Z * @param[in] tv Timeval - * @param[out] fmt Format string. + * @param[out] fmt Format string. * @param[in] len Length of format string. Must be at least 28 bytes. * @retval 0 OK * @retval -1 Error @@ -2143,7 +2141,7 @@ cv_type2str(enum cv_type type) str="ipv4prefix"; break; case CGV_IPV6ADDR: - str="ipv6addr"; + str="ipv6addr"; break; case CGV_IPV6PFX: str="ipv6prefix"; @@ -2220,10 +2218,10 @@ cv_len(cg_var *cv) case CGV_REST: len = (cv->var_rest ? strlen(cv->var_rest) : 0) + 1; break; - case CGV_STRING: + case CGV_STRING: len = (cv->var_string ? strlen(cv->var_string) : 0) + 1; break; - case CGV_INTERFACE: + case CGV_INTERFACE: len = (cv->var_interface ? strlen(cv->var_interface) : 0) + 1; break; case CGV_IPV4ADDR: @@ -2266,17 +2264,17 @@ cv_len(cg_var *cv) return len; } -/*! Print a dec64 cv to a string +/*! Print a dec64 cv to a string * * @param[in] cv A cligen variable of type CGV_DEC64 to print * @param[out] s0 A string that will hold the dec64 * @param[inout] len A string that holds available free space in s0 * @retval 0 OK - * @retval -1 Error with error msg on stderr. + * @retval -1 Error with error msg on stderr. */ static int -cv_dec64_print(cg_var *cv, - char *s0, +cv_dec64_print(cg_var *cv, + char *s0, int *s0len) { int i; @@ -2292,15 +2290,15 @@ cv_dec64_print(cg_var *cv, len = snprintf(s0, *s0len, "%0*" PRId64, n+1, di); assert(len>=n); *s0len -= len; - /* Shift fraction digits right, including null character. - * eg: xyz --> x.yz (if n==2) + /* Shift fraction digits right, including null character. + * eg: xyz --> x.yz (if n==2) */ - for (i=len; i>=len-n; i--) + for (i=len; i>=len-n; i--) s0[i+1] = s0[i]; (*s0len)--; s0[len-n] = '.'; - /* prepend a '-' if the number is negative*/ - if (cv_dec64_i_get(cv)<0){ + /* prepend a '-' if the number is negative*/ + if (cv_dec64_i_get(cv)<0){ for (i=len+1; i>=0; i--) s0[i+1] = s0[i]; s0[0] = '-'; @@ -2312,7 +2310,7 @@ cv_dec64_print(cg_var *cv, /*! Print value of CLIgen variable to CLIgen buf using printf style formats. * * @param[in] cv CLIgen variable - * @param[out] cb Value printed + * @param[out] cb Value printed * The params shuld be switched cb<->cv */ int @@ -2363,17 +2361,17 @@ cv2cbuf(cg_var *cv, case CGV_REST: cprintf(cb, "%s", cv->var_rest); break; - case CGV_STRING: + case CGV_STRING: cprintf(cb, "%s", cv->var_string); break; - case CGV_INTERFACE: + case CGV_INTERFACE: cprintf(cb, "%s", cv->var_interface); break; case CGV_IPV4ADDR: cprintf(cb, "%s", inet_ntoa(cv->var_ipv4addr)); break; case CGV_IPV4PFX: - cprintf(cb, "%s/%u", + cprintf(cb, "%s/%u", inet_ntoa(cv->var_ipv4addr), cv->var_ipv4masklen); break; @@ -2392,7 +2390,7 @@ cv2cbuf(cg_var *cv, cprintf(cb, "%s/%u", straddr, cv->var_ipv6masklen); break; case CGV_MACADDR: - cprintf(cb, "%02x:%02x:%02x:%02x:%02x:%02x", + cprintf(cb, "%02x:%02x:%02x:%02x:%02x:%02x", (uint8_t)cv->var_macaddr[0], (uint8_t)cv->var_macaddr[1], (uint8_t)cv->var_macaddr[2], @@ -2401,7 +2399,7 @@ cv2cbuf(cg_var *cv, (uint8_t)cv->var_macaddr[5]); break; case CGV_URL: /* ://[[:]@][/] */ - cprintf(cb, "%s://%s%s%s%s%s/%s", + cprintf(cb, "%s://%s%s%s%s%s/%s", cv->var_urlproto, cv->var_urluser, strlen(cv->var_urlpasswd)?":":"", @@ -2419,10 +2417,10 @@ cv2cbuf(cg_var *cv, time2str(&cv->var_time, timestr, sizeof(timestr)); cprintf(cb, "%s", timestr); break; - case CGV_VOID: + case CGV_VOID: cprintf(cb, "%p", cv->var_void); break; - case CGV_EMPTY: + case CGV_EMPTY: break; default: break; @@ -2447,8 +2445,8 @@ cv2cbuf(cg_var *cv, * @see cv_print which also prints a CV but to a file */ int -cv2str(cg_var *cv, - char *str, +cv2str(cg_var *cv, + char *str, size_t size) { int len = 0; @@ -2458,7 +2456,7 @@ cv2str(cg_var *cv, char uuidstr[37]; char timestr[28]; - if (cv == NULL) + if (cv == NULL) return 0; switch (cv->var_type){ case CGV_INT8: @@ -2498,17 +2496,17 @@ cv2str(cg_var *cv, case CGV_REST: len = snprintf(str, size, "%s", cv->var_rest); break; - case CGV_STRING: + case CGV_STRING: len = snprintf(str, size, "%s", cv->var_string); break; - case CGV_INTERFACE: + case CGV_INTERFACE: len = snprintf(str, size, "%s", cv->var_interface); break; case CGV_IPV4ADDR: len = snprintf(str, size, "%s", inet_ntoa(cv->var_ipv4addr)); break; case CGV_IPV4PFX: - len = snprintf(str, size, "%s/%u", + len = snprintf(str, size, "%s/%u", inet_ntoa (cv->var_ipv4addr), cv->var_ipv4masklen); break; @@ -2527,7 +2525,7 @@ cv2str(cg_var *cv, len = snprintf(str, size, "%s/%u", straddr, cv->var_ipv6masklen); break; case CGV_MACADDR: - len = snprintf(str, size, "%02x:%02x:%02x:%02x:%02x:%02x", + len = snprintf(str, size, "%02x:%02x:%02x:%02x:%02x:%02x", (uint8_t)cv->var_macaddr[0], (uint8_t)cv->var_macaddr[1], (uint8_t)cv->var_macaddr[2], @@ -2537,7 +2535,7 @@ cv2str(cg_var *cv, break; case CGV_URL: /* ://[[:]@][/] */ - len = snprintf(str, size, "%s://%s%s%s%s%s/%s", + len = snprintf(str, size, "%s://%s%s%s%s%s/%s", cv->var_urlproto, cv->var_urluser, strlen(cv->var_urlpasswd)?":":"", @@ -2578,7 +2576,7 @@ cv2str_dup(cg_var *cv) int len; char *str; - if (cv == NULL) + if (cv == NULL) return NULL; if ((len = cv2str(cv, NULL, 0)) < 0) return NULL; @@ -2597,7 +2595,7 @@ cv2str_dup(cg_var *cv) * @see cv2str which also prints a CV but to a string */ int -cv_print(FILE *f, +cv_print(FILE *f, cg_var *cv) { int len = 0; @@ -2646,11 +2644,11 @@ cv_print(FILE *f, if (cv->var_rest) fprintf(f, "%s", cv->var_rest); break; - case CGV_STRING: + case CGV_STRING: if (cv->var_string) fprintf(f, "\"%s\"", cv->var_string); break; - case CGV_INTERFACE: + case CGV_INTERFACE: fprintf(f, "\"%s\"", cv->var_interface); break; case CGV_IPV4ADDR: @@ -2674,7 +2672,7 @@ cv_print(FILE *f, fprintf(f, "%s/%d", straddr, cv->var_ipv4masklen); break; case CGV_MACADDR: - fprintf(f, "%02x:%02x:%02x:%02x:%02x:%02x", + fprintf(f, "%02x:%02x:%02x:%02x:%02x:%02x", cv->var_macaddr[0], cv->var_macaddr[1], cv->var_macaddr[2], @@ -2684,7 +2682,7 @@ cv_print(FILE *f, break; case CGV_URL: /* ://[[:]@][/] */ - fprintf(f, "%s://%s%s%s%s%s/%s", + fprintf(f, "%s://%s%s%s%s%s/%s", cv->var_urlproto, cv->var_urluser, strlen(cv->var_urlpasswd)?":":"", @@ -2726,8 +2724,8 @@ cv_print(FILE *f, * @see cv_max_set */ int -cvtype_max2str(enum cv_type type, - char *str, +cvtype_max2str(enum cv_type type, + char *str, size_t size) { int len = 0; @@ -2907,10 +2905,10 @@ string_remove_backslash(char *str) return 0; } -/*! Parse cv from string. +/*! Parse cv from string. * * This function expects an initialized cv as created by cv_new() or - * prepared by cv_reset(). + * prepared by cv_reset(). * The following is required of a cv before calling this function: * - A type field. So that the parser knows how to parse the string * - For decimal64 the fraction_digits (n) must be known. @@ -2936,14 +2934,14 @@ string_remove_backslash(char *str) */ int cv_parse1(const char *str0, - cg_var *cv, + cg_var *cv, char **reason) { int retval = -1; char *str; char *mask; int masklen = 0; - + if (reason && (*reason != NULL)){ fprintf(stderr, "reason must be NULL on calling\n"); return -1; @@ -3011,7 +3009,7 @@ cv_parse1(const char *str0, goto done; retval = 1; break; - case CGV_IPV4ADDR: + case CGV_IPV4ADDR: cv->var_ipv4masklen = 32; retval = parse_ipv4addr(str, &cv->var_ipv4addr, reason); break; @@ -3022,7 +3020,7 @@ cv_parse1(const char *str0, case CGV_IPV4PFX: if ((mask = strchr (str, '/')) == NULL){ retval = 0; - if (reason) + if (reason) if ((*reason = cligen_reason("Mask-length missing")) == NULL) retval = -1; goto done; @@ -3043,7 +3041,7 @@ cv_parse1(const char *str0, case CGV_IPV6PFX: if ((mask = strchr (str, '/')) == NULL){ retval = 0; - if (reason) + if (reason) if ((*reason = cligen_reason("Mask-length missing")) == NULL) retval = -1; goto done; @@ -3064,7 +3062,7 @@ cv_parse1(const char *str0, case CGV_MACADDR: retval = parse_macaddr(str, cv->var_macaddr, reason); break; - case CGV_URL: + case CGV_URL: retval = parse_url(str, cv, reason); break; case CGV_UUID: @@ -3091,7 +3089,7 @@ cv_parse1(const char *str0, case CGV_EMPTY: case CGV_ERR: retval = 0; - if (reason) + if (reason) *reason = cligen_reason("Invalid variable"); break; } /* switch */ @@ -3103,10 +3101,10 @@ cv_parse1(const char *str0, return retval; } -/*! Parse cv from string. +/*! Parse cv from string. * * This function expects an initialized cv as created by cv_new() or - * prepared by cv_reset(). + * prepared by cv_reset(). * @note The following is required of a cv before calling this function: * - A type field. So that the parser knows how to parse the string * - For decimal64 the fraction_digits (n) must be known (cv_dec64_n_set()) @@ -3127,7 +3125,7 @@ cv_parse1(const char *str0, * @endcode */ int -cv_parse(const char *str, +cv_parse(const char *str, cg_var *cv) { int retval; @@ -3145,6 +3143,7 @@ cv_parse(const char *str, } /*! Range interval check if a number is in an interval + * * @param[in] i The number to check if it is in an interval * @param[in] cvlow cv containing lower bound * @param[in] cvupp cv containing upper bound @@ -3239,8 +3238,8 @@ outoflength(uint64_t u64, */ int cv_validate(cligen_handle h, - cg_var *cv, - cg_varspec *cs, + cg_var *cv, + cg_varspec *cs, char *cmd, char **reason) { @@ -3254,7 +3253,7 @@ cv_validate(cligen_handle h, int j; cg_var *cv1; cg_var *cv2; - + switch (cs->cgs_vtype){ case CGV_INT8: if (!cs->cgs_rangelen) @@ -3463,15 +3462,15 @@ cv_validate(cligen_handle h, break; case CGV_BOOL: case CGV_INTERFACE: - case CGV_IPV4ADDR: - case CGV_IPV6ADDR: - case CGV_IPV4PFX: - case CGV_IPV6PFX: + case CGV_IPV4ADDR: + case CGV_IPV6ADDR: + case CGV_IPV4PFX: + case CGV_IPV6PFX: case CGV_MACADDR: - case CGV_URL: - case CGV_UUID: - case CGV_TIME: - case CGV_EMPTY: + case CGV_URL: + case CGV_UUID: + case CGV_TIME: + case CGV_EMPTY: break; } if (reason && *reason) @@ -3487,10 +3486,10 @@ cv_validate(cligen_handle h, * @retval 0 equal * @retval <0 cv1 is less than cv2 * @retval >0 cv1 is greater than cv2 - * XXX assume dec64_n are equal + * XXX assume dec64_n are equal */ -int -cv_cmp(cg_var *cv1, +int +cv_cmp(cg_var *cv1, cg_var *cv2) { int n; @@ -3525,7 +3524,7 @@ cv_cmp(cg_var *cv1, case CGV_BOOL: return (cv1->var_bool - cv2->var_bool); case CGV_REST: - case CGV_STRING: + case CGV_STRING: case CGV_INTERFACE: /* All strings have the same address */ return strcmp(cv1->var_string, cv2->var_string); case CGV_IPV4ADDR: @@ -3547,7 +3546,6 @@ cv_cmp(cg_var *cv1, case CGV_MACADDR: return memcmp(&cv1->var_macaddr, &cv2->var_macaddr, sizeof(cv1->var_macaddr)); - case CGV_URL: if ((n = strcmp(cv1->var_urlproto, cv2->var_urlproto))) return n; @@ -3575,16 +3573,16 @@ cv_cmp(cg_var *cv1, * The new cv should have been be initialized, such as after cv_new() or * after cv_reset(). * The new cv may involve duplicating strings, etc. - * @retval 0 0n success, + * @retval 0 0n success, * @retval -1 On error with errno set (strdup errors) */ int -cv_cp(cg_var *new, +cv_cp(cg_var *new, cg_var *old) { int retval = -1; - memcpy(new, old, sizeof(*old)); + memcpy(new, old, sizeof(*old)); if (old->var_name) if ((new->var_name = strdup(old->var_name)) == NULL) goto done; @@ -3606,10 +3604,10 @@ cv_cp(cg_var *new, case CGV_BOOL: break; case CGV_REST: - case CGV_STRING: + case CGV_STRING: case CGV_INTERFACE: /* All strings have the same address */ if (old->var_string) - if ((new->var_string = strdup(old->var_string)) == NULL) + if ((new->var_string = strdup(old->var_string)) == NULL) goto done; break; case CGV_IPV4ADDR: @@ -3650,7 +3648,7 @@ cv_cp(cg_var *new, return retval; } -/*! Create a new cgv and copy the contents from the original. +/*! Create a new cgv and copy the contents from the original. * * This may involve duplicating strings, etc. * The new cv needs to be freed by cv_free(). @@ -3669,7 +3667,7 @@ cv_dup(cg_var *old) return new; } -/*! Create new cligen variable. +/*! Create new cligen variable. * * @retval NULL on error, error printed on stder * @retval cv on success the malloc:ed cligen variable. Needs to be freed w cv_free() @@ -3694,7 +3692,7 @@ cv_new(enum cv_type type) /*! Free pointers and resets a single CLIgen variable cv * - * But does not free the cgv itself! + * But does not free the cgv itself! * the type is maintained after reset. */ int @@ -3727,7 +3725,7 @@ cv_reset(cg_var *cv) break; case CGV_VOID: /* XXX: freeit ? */ break; - case CGV_EMPTY: + case CGV_EMPTY: break; default: break; diff --git a/cligen_cv.h b/cligen_cv.h index b9edfbf..a8e6573 100644 --- a/cligen_cv.h +++ b/cligen_cv.h @@ -1,6 +1,6 @@ /* ***** BEGIN LICENSE BLOCK ***** - + Copyright (C) 2001-2022 Olof Hagsand This file is part of CLIgen. @@ -23,7 +23,7 @@ of those above. If you wish to allow use of your version of this file only under the terms of the GPL, and not to allow others to use your version of this file under the terms of Apache License version 2, indicate - your decision by deleting the provisions above and replace them with the + your decision by deleting the provisions above and replace them with the notice and other provisions required by the GPL. If you do not delete the provisions above, a recipient may use your version of this file under the terms of any one of the Apache License version 2 or the GPL. @@ -32,7 +32,7 @@ CLIgen variables - cgv - cgv:s are created when parsing an input string as instances of cg_obj variable + cgv:s are created when parsing an input string as instances of cg_obj variable when matching. Note that a cg_obj is a syntax object and contains a part that specifies cgv:s called cov */ @@ -55,7 +55,7 @@ typedef unsigned char uuid_t[16]; * First, built in types, * Some types have their values in-line (eg in the cgv struct), others * have pointers to the value. - * Cgvs with pointers are: string, interface, rest, choice, + * Cgvs with pointers are: string, interface, rest, choice, * expand. */ enum cv_type{ @@ -81,7 +81,7 @@ enum cv_type{ CGV_URL, /* ://[[:]@][/] */ CGV_UUID, /* Universally Unique Identifier: 550e8400-e29b-41d4-a716-446655440000 */ CGV_TIME, /* ISO 8601 date+timestamp: 2008-09-21T18:57:21.003 (extended format) */ - CGV_VOID, /* Pointer to external data. Notes: not freed on cv_free; + CGV_VOID, /* Pointer to external data. Notes: not freed on cv_free; not null-terminated string, cv_cp/dup will retain pointer */ CGV_EMPTY, /* A type without a value */ }; @@ -104,7 +104,7 @@ enum cv_type{ #define cv_isstring(t)((t)==CGV_STRING||(t)==CGV_REST|| \ (t)==CGV_INTERFACE) -#define cv_typemax(t) +#define cv_typemax(t) /* * Cligen Variable structure @@ -112,8 +112,8 @@ enum cv_type{ * A cg_var is a variable instantiation, ie it has a name and a value and is typed. * The type determines how the values are stored. Some values are stored in-line * using a union structure (such as int) while others uses pointers (eg string). - * It is different from cg_obj of type CO_VARIABLE in that the cg_obj is a - * specification. + * It is different from cg_obj of type CO_VARIABLE in that the cg_obj is a + * specification. */ typedef struct cg_var cg_var; @@ -223,7 +223,7 @@ int cv_min_set(cg_var *cv); int cv_cmp(cg_var *cgv1, cg_var *cgv2); int cv_cp(cg_var *n, cg_var *old); cg_var *cv_dup(cg_var *old); -int cv_parse(const char *str, cg_var *cgv); +int cv_parse(const char *str, cg_var *cgv); int cv_parse1(const char *str, cg_var *cgv, char **reason); /* better err-handling */ int cv_validate(cligen_handle h, cg_var *cv, struct cg_varspec *cs, char *cmd, char **reason); diff --git a/cligen_cv_internal.h b/cligen_cv_internal.h index 3d1b05a..786419d 100644 --- a/cligen_cv_internal.h +++ b/cligen_cv_internal.h @@ -1,6 +1,6 @@ /* ***** BEGIN LICENSE BLOCK ***** - + Copyright (C) 2001-2022 Olof Hagsand This file is part of CLIgen. @@ -23,15 +23,15 @@ of those above. If you wish to allow use of your version of this file only under the terms of the GPL, and not to allow others to use your version of this file under the terms of Apache License version 2, indicate - your decision by deleting the provisions above and replace them with the + your decision by deleting the provisions above and replace them with the notice and other provisions required by the GPL. If you do not delete the provisions above, a recipient may use your version of this file under the terms of any one of the Apache License version 2 or the GPL. ***** END LICENSE BLOCK ***** - * This is an internal CLIgen header file - * Do not use these struct for external use, the internal structure may change. + * This is an internal CLIgen header file + * Do not use these struct for external use, the internal structure may change. * @see cligen_cv.h for external API use */ @@ -88,7 +88,7 @@ struct cg_var { char varu_macaddr[6]; struct { char *varurl_proto; - char *varurl_addr; + char *varurl_addr; char *varurl_path; char *varurl_user; char *varurl_passwd; diff --git a/cligen_cvec.c b/cligen_cvec.c index 7bcd113..455d4fd 100644 --- a/cligen_cvec.c +++ b/cligen_cvec.c @@ -372,7 +372,7 @@ cvec_i_str(cvec *cvv, int i) { cg_var *cv; - + if ((cv = cvec_i(cvv, i)) == NULL) return NULL; return cv_string_get(cv); @@ -692,7 +692,7 @@ cligen_txt2cvv(char *str, cg_var *cv = NULL; int whitespace = 1; size_t len; - + if ((cvv = cvec_new(0)) == NULL) goto done; len = strlen(str); @@ -733,7 +733,7 @@ cligen_txt2cvv(char *str, return retval; } -/*! Given a string (s0), return the next token. +/*! Given a string (s0), return the next token. * * The string is modified to return * the remainder of the string after the identified token. @@ -751,9 +751,9 @@ cligen_txt2cvv(char *str, * results in token="foo", leading=1 */ static int -next_token(char **s0, +next_token(char **s0, char **token0, - char **rest0, + char **rest0, int *leading0) { char *s; @@ -834,8 +834,8 @@ next_token(char **s0, /*! Split a CLIgen command string into a cligen variable vector using delimeters and escape quotes * * @param[in] string String to split - * @param[out] cvtp CLIgen variable vector, containing all tokens. - * @param[out] cvrp CLIgen variable vector, containing the remaining strings. + * @param[out] cvtp CLIgen variable vector, containing all tokens. + * @param[out] cvrp CLIgen variable vector, containing the remaining strings. * @retval 0 OK * @retval -1 Error * @code @@ -853,7 +853,7 @@ next_token(char **s0, * @note both out cvv:s should be freed with cvec_free() */ int -cligen_str2cvv(char *string, +cligen_str2cvv(char *string, cvec **cvtp, cvec **cvrp) { @@ -880,7 +880,7 @@ cligen_str2cvv(char *string, t = NULL; if (next_token(&s, &t, &sr, &trail) < 0) goto done; - /* If there is no token, stop, + /* If there is no token, stop, * unless it is the intial token (empty string) OR there are trailing whitespace * In these cases insert an empty "" token. */ @@ -935,7 +935,7 @@ cvec_expand_first(cvec *cvv) cbuf *cb = NULL; cg_var *cv; int i; - + if ((cb = cbuf_new()) == NULL) goto done; for (i=1; i [0 1..n] [0 1..m] <-- ptn @@ -175,7 +175,7 @@ co_expand_sub(cg_obj *co0, * @param[in] helptext Helptext of command, can be NULL already malloced is consumed */ static int -transform_var_to_cmd(cg_obj *co, +transform_var_to_cmd(cg_obj *co, char *cmd, char *helptext) { @@ -230,7 +230,7 @@ transform_var_to_cmd(cg_obj *co, /*! Look up treeref from @ and return expanded parse-tree * * @param[in] h Cligen handle - * @param[in] co Cligen treeref object + * @param[in] co Cligen treeref object * @param[in] cvt Tokenized string: vector of tokens * @param[out] ptrefp Treeref Parse-tree result * @retval 1 OK @@ -251,7 +251,7 @@ tree_resolve(cligen_handle h, cligen_tree_resolve_wrapper_fn *fn = NULL; void *arg = NULL; int ret; - + treename = coref->co_command; cligen_tree_resolve_wrapper_get(h, &fn, &arg); if (fn){ @@ -278,7 +278,7 @@ tree_resolve(cligen_handle h, if ((cow = cligen_ph_workpoint_get(ph)) != NULL) *ptrefp = co_pt_get(cow); else - *ptrefp = cligen_ph_parsetree_get(ph); + *ptrefp = cligen_ph_parsetree_get(ph); ok: retval = 0; done: @@ -287,8 +287,11 @@ tree_resolve(cligen_handle h, return retval; } -/*! Find filter labels defined as "filter:@remove: