From abd393322d581d0b5ac387b3dcc409eed59a7460 Mon Sep 17 00:00:00 2001 From: huangxin Date: Fri, 2 Dec 2022 14:42:15 +0800 Subject: [PATCH] =?UTF-8?q?OCT=201.=20=E6=9B=B4=E6=96=B0=E6=A0=BC=E5=BC=8F?= =?UTF-8?q?=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .clang-format | 11 +- srcs/libs/CMakeLists.txt | 2 +- srcs/libs/args/argtable3.c | 826 ++-- srcs/libs/args/argtable3.h | 141 +- srcs/libs/cmdline/cmd_menu.c | 8 +- srcs/libs/configure/config_help.c | 2 +- srcs/libs/crypto/crypto.c | 8 +- srcs/libs/crypto/hash_digest.c | 7 +- srcs/libs/crypto/symmetric.c | 18 +- srcs/libs/database/sqlite3/config.h | 2 +- srcs/libs/include/config.h | 4 +- srcs/libs/include/crypto.h | 40 +- srcs/libs/include/inet_misc.h | 24 +- srcs/libs/include/misc.h | 7 +- srcs/libs/include/s2j/cJSON.h | 129 +- srcs/libs/include/s2j/s2jdef.h | 16 +- srcs/libs/include/sds/alloc.h | 12 +- srcs/libs/include/sds/sds.h | 191 +- srcs/libs/include/sds/sdsalloc.h | 4 +- srcs/libs/include/sqlite3/sqlite3.h | 2714 +++++++------ srcs/libs/include/sqlite3/sqlite3ext.h | 1119 +++--- srcs/libs/include/uthash/utarray.h | 30 +- srcs/libs/include/uthash/uthash.h | 18 +- srcs/libs/include/uthash/utstring.h | 25 +- srcs/libs/include/zvector/zvector.h | 80 +- srcs/libs/include/zvector/zvector_checks.h | 166 +- srcs/libs/include/zvector/zvector_config.h | 15 +- srcs/libs/json/cJSON.c | 1781 ++++----- srcs/libs/misc/misc.c | 7 +- srcs/libs/misc/sds.c | 1014 ++--- srcs/libs/misc/zvector.c | 4010 +++++++++++--------- srcs/libs/mq/mq_data.c | 6 +- srcs/libs/mq/msg_queue.c | 2 +- srcs/libs/network/http_svr.c | 2 +- srcs/libs/network/inet_misc.c | 42 +- 35 files changed, 6334 insertions(+), 6149 deletions(-) diff --git a/.clang-format b/.clang-format index 15d226d..42fe6c4 100644 --- a/.clang-format +++ b/.clang-format @@ -2,6 +2,7 @@ Language: Cpp AccessModifierOffset: -4 InsertBraces: true +AlignArrayOfStructures: Left AlignAfterOpenBracket: Align AlignConsecutiveMacros: Consecutive AlignConsecutiveAssignments: Consecutive @@ -26,8 +27,9 @@ AlwaysBreakBeforeMultilineStrings: true AlwaysBreakTemplateDeclarations: MultiLine AttributeMacros: - __capability + - __unused BinPackArguments: false -BinPackParameters: true +BinPackParameters: false BraceWrapping: AfterCaseLabel: false AfterClass: false @@ -57,7 +59,7 @@ BreakConstructorInitializersBeforeComma: false BreakConstructorInitializers: BeforeColon BreakAfterJavaFieldAnnotations: false BreakStringLiterals: true -ColumnLimit: 140 +ColumnLimit: 120 CommentPragmas: '^ IWYU pragma:' CompactNamespaces: true ConstructorInitializerAllOnOneLineOrOnePerLine: true @@ -174,7 +176,7 @@ SpaceAroundPointerQualifiers: Default SpaceBeforeRangeBasedForLoopColon: true SpaceInEmptyBlock: false SpaceInEmptyParentheses: false -SpacesBeforeTrailingComments: 0 +SpacesBeforeTrailingComments: 4 SpacesInAngles: false SpacesInConditionalStatement: false SpacesInContainerLiterals: false @@ -199,3 +201,6 @@ WhitespaceSensitiveMacros: - BOOST_PP_STRINGIZE - NS_SWIFT_NAME - CF_SWIFT_NAME +TypenameMacros: + - CONFIG_ITEM + - PCONFIG_ITEM diff --git a/srcs/libs/CMakeLists.txt b/srcs/libs/CMakeLists.txt index 2950bd6..901c174 100644 --- a/srcs/libs/CMakeLists.txt +++ b/srcs/libs/CMakeLists.txt @@ -47,7 +47,7 @@ IF (USED_SQLITE) -DSQLITE_HAVE_ZLIB=1 -DSQLITE_TEMP_STORE=2") ENDIF () -ADD_DEFINITIONS(-DBUILD_VERSION="${GIT_VERSION}" ${COMMON_DEFINE}) +ADD_DEFINITIONS(-DBUILD_VERSION= "${GIT_VERSION}" ${COMMON_DEFINE}) LINK_LIBRARIES(${COMMON_LIBS}) ADD_LIBRARY(${LIB_PROJECT_TARGET} ${C_SRC} ${C_HEADS}) diff --git a/srcs/libs/args/argtable3.c b/srcs/libs/args/argtable3.c index 30ebe31..2a82e9d 100644 --- a/srcs/libs/args/argtable3.c +++ b/srcs/libs/args/argtable3.c @@ -159,7 +159,8 @@ typedef struct arg_hashtable { * @param eqfn function for determining key equality * @return newly created hash table or NULL on failure */ -arg_hashtable_t *arg_hashtable_create(unsigned int minsize, unsigned int (*hashfn)(const void *), +arg_hashtable_t *arg_hashtable_create(unsigned int minsize, + unsigned int (*hashfn)(const void *), int (*eqfn)(const void *, const void *)); /** @@ -550,9 +551,9 @@ void arg_mgsort(void *data, int size, int esize, int i, int k, arg_comparefn *co * http://planetmath.org/encyclopedia/GoodHashTablePrimes.html */ static const unsigned int primes[] = {53, 97, 193, 389, 769, 1543, 3079, - 6151, 12289, 24593, 49157, 98317, 196613, 393241, - 786433, 1572869, 3145739, 6291469, 12582917, 25165843, 50331653, - 100663319, 201326611, 402653189, 805306457, 1610612741}; + 6151, 12289, 24593, 49157, 98317, 196613, 393241, + 786433, 1572869, 3145739, 6291469, 12582917, 25165843, 50331653, + 100663319, 201326611, 402653189, 805306457, 1610612741}; const unsigned int prime_table_length = sizeof(primes) / sizeof(primes[0]); const float max_load_factor = (float)0.65; @@ -573,15 +574,17 @@ static unsigned int index_for(unsigned int tablelength, unsigned int hashvalue) return (hashvalue % tablelength); } -arg_hashtable_t *arg_hashtable_create(unsigned int minsize, unsigned int (*hashfn)(const void *), +arg_hashtable_t *arg_hashtable_create(unsigned int minsize, + unsigned int (*hashfn)(const void *), int (*eqfn)(const void *, const void *)) { arg_hashtable_t *h; unsigned int pindex; unsigned int size = primes[0]; /* Check requested hash table isn't too large */ - if (minsize > (1u << 30)) + if (minsize > (1u << 30)) { return NULL; + } /* * Enforce size as prime. The reason is to avoid clustering of values @@ -616,8 +619,9 @@ static int arg_hashtable_expand(arg_hashtable_t *h) { unsigned int index; /* Check we're not hitting max capacity */ - if (h->primeindex == (prime_table_length - 1)) + if (h->primeindex == (prime_table_length - 1)) { return 0; + } newsize = primes[++(h->primeindex)]; newtable = (struct arg_hashtable_entry **)xmalloc(sizeof(struct arg_hashtable_entry *) * newsize); @@ -679,8 +683,9 @@ void *arg_hashtable_search(arg_hashtable_t *h, const void *k) { e = h->table[index]; while (e != NULL) { /* Check hash value to short circuit heavier comparison */ - if ((hashvalue == e->h) && (h->eqfn(k, e->k))) + if ((hashvalue == e->h) && (h->eqfn(k, e->k))) { return e->v; + } e = e->next; } return NULL; @@ -756,8 +761,9 @@ arg_hashtable_itr_t *arg_hashtable_itr_create(arg_hashtable_t *h) { itr->parent = NULL; tablelength = h->tablelength; itr->index = tablelength; - if (0 == h->entrycount) + if (0 == h->entrycount) { return itr; + } for (i = 0; i < tablelength; i++) { if (h->table[i] != NULL) { @@ -787,8 +793,9 @@ int arg_hashtable_itr_advance(arg_hashtable_itr_t *itr) { struct arg_hashtable_entry **table; struct arg_hashtable_entry *next; - if (itr->e == NULL) + if (itr->e == NULL) { return 0; /* stupidity check */ + } next = itr->e->next; if (NULL != next) { @@ -1008,8 +1015,9 @@ arg_dstr_t arg_dstr_create(void) { } void arg_dstr_destroy(arg_dstr_t ds) { - if (ds == NULL) + if (ds == NULL) { return; + } arg_dstr_reset(ds); xfree(ds); @@ -1115,15 +1123,17 @@ void arg_dstr_catf(arg_dstr_t ds, const char *fmt, ...) { int n, r; size_t slen; - if (fmt == NULL) + if (fmt == NULL) { return; + } /* Since the length is not determinable beforehand, a search is performed using the truncating "vsnprintf" call (to avoid buffer overflows) on increasing potential sizes for the output result. */ - if ((n = (int)(2 * strlen(fmt))) < START_VSNBUFF) + if ((n = (int)(2 * strlen(fmt))) < START_VSNBUFF) { n = START_VSNBUFF; + } buff = (char *)xmalloc((size_t)(n + 2)); memset(buff, 0, (size_t)(n + 2)); @@ -1134,13 +1144,15 @@ void arg_dstr_catf(arg_dstr_t ds, const char *fmt, ...) { va_end(arglist); slen = strlen(buff); - if (slen < (size_t)n) + if (slen < (size_t)n) { break; + } - if (r > n) + if (r > n) { n = r; - else + } else { n += n; + } xfree(buff); buff = (char *)xmalloc((size_t)(n + 2)); @@ -1520,10 +1532,11 @@ static void permute_args(int panonopt_start, int panonopt_end, int opt_end, char cstart = panonopt_end + i; pos = cstart; for (j = 0; j < cyclelen; j++) { - if (pos >= panonopt_end) + if (pos >= panonopt_end) { pos -= nnonopts; - else + } else { pos += nopts; + } swap = nargv[pos]; /* LINTED const cast */ ((char **)nargv)[pos] = nargv[cstart]; @@ -1538,8 +1551,12 @@ static void permute_args(int panonopt_start, int panonopt_end, int opt_end, char * Parse long options in argc/argv argument vector. * Returns -1 if short_too is set and the option does not match long_options. */ -static int parse_long_options(char *const *nargv, const char *options, const struct option *long_options, int *idx, - int short_too, int flags) { +static int parse_long_options(char *const *nargv, + const char *options, + const struct option *long_options, + int *idx, + int short_too, + int flags) { char *current_argv, *has_equal; #ifdef GNU_COMPATIBLE char *current_dash; @@ -1574,13 +1591,15 @@ static int parse_long_options(char *const *nargv, const char *options, const str /* argument found (--option=arg) */ current_argv_len = (size_t)(has_equal - current_argv); has_equal++; - } else + } else { current_argv_len = strlen(current_argv); + } for (i = 0; long_options[i].name; i++) { /* find matching long option */ - if (strncmp(current_argv, long_options[i].name, current_argv_len)) + if (strncmp(current_argv, long_options[i].name, current_argv_len)) { continue; + } if (strlen(long_options[i].name) == current_argv_len) { /* exact match */ @@ -1592,43 +1611,49 @@ static int parse_long_options(char *const *nargv, const char *options, const str * If this is a known short option, don't allow * a partial match of a single character. */ - if (short_too && current_argv_len == 1) + if (short_too && current_argv_len == 1) { continue; + } - if (match == -1) /* first partial match */ + if (match == -1) { /* first partial match */ match = i; - else if ((flags & FLAG_LONGONLY) || long_options[i].has_arg != long_options[match].has_arg - || long_options[i].flag != long_options[match].flag || long_options[i].val != long_options[match].val) + } else if ((flags & FLAG_LONGONLY) || long_options[i].has_arg != long_options[match].has_arg + || long_options[i].flag != long_options[match].flag + || long_options[i].val != long_options[match].val) { second_partial_match = 1; + } } if (!exact_match && second_partial_match) { /* ambiguous abbreviation */ - if (PRINT_ERROR) + if (PRINT_ERROR) { warnx(ambig, #ifdef GNU_COMPATIBLE current_dash, #endif (int)current_argv_len, current_argv); + } optopt = 0; return (BADCH); } if (match != -1) { /* option found */ if (long_options[match].has_arg == no_argument && has_equal) { - if (PRINT_ERROR) + if (PRINT_ERROR) { warnx(noarg, #ifdef GNU_COMPATIBLE current_dash, #endif (int)current_argv_len, current_argv); + } /* * XXX: GNU sets optopt to val regardless of flag */ - if (long_options[match].flag == NULL) + if (long_options[match].flag == NULL) { optopt = long_options[match].val; - else + } else { optopt = 0; + } #ifdef GNU_COMPATIBLE return (BADCH); #else @@ -1636,9 +1661,9 @@ static int parse_long_options(char *const *nargv, const char *options, const str #endif } if (long_options[match].has_arg == required_argument || long_options[match].has_arg == optional_argument) { - if (has_equal) + if (has_equal) { optarg = has_equal; - else if (long_options[match].has_arg == required_argument) { + } else if (long_options[match].has_arg == required_argument) { /* * optional argument doesn't use next nargv */ @@ -1650,19 +1675,21 @@ static int parse_long_options(char *const *nargv, const char *options, const str * Missing argument; leading ':' indicates no error * should be generated. */ - if (PRINT_ERROR) + if (PRINT_ERROR) { warnx(recargstring, #ifdef GNU_COMPATIBLE current_dash, #endif current_argv); + } /* * XXX: GNU sets optopt to val regardless of flag */ - if (long_options[match].flag == NULL) + if (long_options[match].flag == NULL) { optopt = long_options[match].val; - else + } else { optopt = 0; + } --optind; return (BADARG); } @@ -1671,43 +1698,52 @@ static int parse_long_options(char *const *nargv, const char *options, const str --optind; return (-1); } - if (PRINT_ERROR) + if (PRINT_ERROR) { warnx(illoptstring, #ifdef GNU_COMPATIBLE current_dash, #endif current_argv); + } optopt = 0; return (BADCH); } - if (idx) + if (idx) { *idx = match; + } if (long_options[match].flag) { *long_options[match].flag = long_options[match].val; return (0); - } else + } else { return (long_options[match].val); + } } /* * getopt_internal -- * Parse argc/argv argument vector. Called by user level routines. */ -static int getopt_internal(int nargc, char *const *nargv, const char *options, const struct option *long_options, - int *idx, int flags) { +static int getopt_internal(int nargc, + char *const *nargv, + const char *options, + const struct option *long_options, + int *idx, + int flags) { char *oli; /* option letter list index */ int optchar, short_too; static int posixly_correct = -1; - if (options == NULL) + if (options == NULL) { return (-1); + } /* * XXX Some GNU programs (like cvs) set optind to 0 instead of * XXX using optreset. Work around this braindamage. */ - if (optind == 0) + if (optind == 0) { optind = optreset = 1; + } /* * Disable GNU extensions if POSIXLY_CORRECT is set or options @@ -1725,16 +1761,19 @@ static int getopt_internal(int nargc, char *const *nargv, const char *options, c #endif } - if (*options == '-') + if (*options == '-') { flags |= FLAG_ALLARGS; - else if (posixly_correct || *options == '+') + } else if (posixly_correct || *options == '+') { flags &= ~FLAG_PERMUTE; - if (*options == '+' || *options == '-') + } + if (*options == '+' || *options == '-') { options++; + } optarg = NULL; - if (optreset) + if (optreset) { nonopt_start = nonopt_end = -1; + } start: if (optreset || !*place) { /* update scanning pointer */ optreset = 0; @@ -1777,9 +1816,9 @@ start: return (-1); } /* do permutation */ - if (nonopt_start == -1) + if (nonopt_start == -1) { nonopt_start = optind; - else if (nonopt_end != -1) { + } else if (nonopt_end != -1) { permute_args(nonopt_start, nonopt_end, optind, nargv); nonopt_start = optind - (nonopt_end - nonopt_start); nonopt_end = -1; @@ -1788,8 +1827,9 @@ start: /* process next argument */ goto start; } - if (nonopt_start != -1 && nonopt_end == -1) + if (nonopt_start != -1 && nonopt_end == -1) { nonopt_end = optind; + } /* * If we have "-" do nothing, if "--" we are done. @@ -1823,13 +1863,15 @@ start: #endif if (*place == '-') { place++; /* --foo long option */ - if (*place == '\0') + if (*place == '\0') { return (BADARG); /* malformed option */ + } #ifdef GNU_COMPATIBLE dash_prefix = DD_PREFIX; #endif - } else if (*place != ':' && strchr(options, *place) != NULL) + } else if (*place != ':' && strchr(options, *place) != NULL) { short_too = 1; /* could be short option too */ + } optchar = parse_long_options(nargv, options, long_options, idx, short_too, flags); if (optchar != -1) { @@ -1845,16 +1887,20 @@ start: * options, return -1 (non-option) as per POSIX. * Otherwise, it is an unknown option character (or ':'). */ - if (optchar == (int)'-' && *place == '\0') + if (optchar == (int)'-' && *place == '\0') { return (-1); - if (!*place) + } + if (!*place) { ++optind; + } #ifdef GNU_COMPATIBLE - if (PRINT_ERROR) + if (PRINT_ERROR) { warnx(posixly_correct ? illoptchar : gnuoptchar, optchar); + } #else - if (PRINT_ERROR) + if (PRINT_ERROR) { warnx(illoptchar, optchar); + } #endif optopt = optchar; return (BADCH); @@ -1865,12 +1911,14 @@ start: /* NOTHING */; else if (++optind >= nargc) { /* no arg */ place = EMSG; - if (PRINT_ERROR) + if (PRINT_ERROR) { warnx(recargchar, optchar); + } optopt = optchar; return (BADARG); - } else /* white space */ + } else { /* white space */ place = nargv[optind]; + } #ifdef GNU_COMPATIBLE dash_prefix = W_PREFIX; #endif @@ -1879,21 +1927,24 @@ start: return (optchar); } if (*++oli != ':') { /* doesn't take argument */ - if (!*place) + if (!*place) { ++optind; + } } else { /* takes (optional) argument */ optarg = NULL; - if (*place) /* no white space */ + if (*place) { /* no white space */ optarg = place; - else if (oli[1] != ':') { /* arg not optional */ + } else if (oli[1] != ':') { /* arg not optional */ if (++optind >= nargc) { /* no arg */ place = EMSG; - if (PRINT_ERROR) + if (PRINT_ERROR) { warnx(recargchar, optchar); + } optopt = optchar; return (BADARG); - } else + } else { optarg = nargv[optind]; + } } place = EMSG; ++optind; @@ -2002,10 +2053,11 @@ static int arg_date_scanfn(struct arg_date *parent, const char *argval) { /* parse the given argument value, store result in parent->tmval[] */ pend = arg_strptime(argval, parent->format, &tm); - if (pend && pend[0] == '\0') + if (pend && pend[0] == '\0') { parent->tmval[parent->count++] = tm; - else + } else { errorcode = ARG_ERR_BADDATE; + } } ARG_TRACE(("%s:scanfn(%p) returns %d\n", __FILE__, parent, errorcode)); @@ -2019,8 +2071,11 @@ static int arg_date_checkfn(struct arg_date *parent) { return errorcode; } -static void arg_date_errorfn(struct arg_date *parent, arg_dstr_t ds, int errorcode, const char *argval, - const char *progname) { +static void arg_date_errorfn(struct arg_date *parent, + arg_dstr_t ds, + int errorcode, + const char *argval, + const char *progname) { const char *shortopts = parent->hdr.shortopts; const char *longopts = parent->hdr.longopts; const char *datatype = parent->hdr.datatype; @@ -2054,18 +2109,29 @@ static void arg_date_errorfn(struct arg_date *parent, arg_dstr_t ds, int errorco } } -struct arg_date *arg_date0(const char *shortopts, const char *longopts, const char *format, const char *datatype, +struct arg_date *arg_date0(const char *shortopts, + const char *longopts, + const char *format, + const char *datatype, const char *glossary) { return arg_daten(shortopts, longopts, format, datatype, 0, 1, glossary); } -struct arg_date *arg_date1(const char *shortopts, const char *longopts, const char *format, const char *datatype, +struct arg_date *arg_date1(const char *shortopts, + const char *longopts, + const char *format, + const char *datatype, const char *glossary) { return arg_daten(shortopts, longopts, format, datatype, 1, 1, glossary); } -struct arg_date *arg_daten(const char *shortopts, const char *longopts, const char *format, const char *datatype, - int mincount, int maxcount, const char *glossary) { +struct arg_date *arg_daten(const char *shortopts, + const char *longopts, + const char *format, + const char *datatype, + int mincount, + int maxcount, + const char *glossary) { size_t nbytes; struct arg_date *result; @@ -2073,8 +2139,9 @@ struct arg_date *arg_daten(const char *shortopts, const char *longopts, const ch maxcount = (maxcount < mincount) ? mincount : maxcount; /* default time format is the national date format for the locale */ - if (!format) + if (!format) { format = "%x"; + } nbytes = sizeof(struct arg_date) /* storage for struct arg_date */ + (size_t)maxcount * sizeof(struct tm); /* storage for tmval[maxcount] array */ @@ -2180,9 +2247,11 @@ static const char *am_pm[2] = {"AM", "PM"}; static int arg_strcasecmp(const char *s1, const char *s2) { const unsigned char *us1 = (const unsigned char *)s1; const unsigned char *us2 = (const unsigned char *)s2; - while (tolower(*us1) == tolower(*us2++)) - if (*us1++ == '\0') + while (tolower(*us1) == tolower(*us2++)) { + if (*us1++ == '\0') { return 0; + } + } return tolower(*us1) - tolower(*--us2); } @@ -2192,11 +2261,13 @@ static int arg_strncasecmp(const char *s1, const char *s2, size_t n) { const unsigned char *us1 = (const unsigned char *)s1; const unsigned char *us2 = (const unsigned char *)s2; do { - if (tolower(*us1) != tolower(*us2++)) + if (tolower(*us1) != tolower(*us2++)) { return tolower(*us1) - tolower(*--us2); + } - if (*us1++ == '\0') + if (*us1++ == '\0') { break; + } } while (--n != 0); } @@ -2217,22 +2288,25 @@ char *arg_strptime(const char *buf, const char *fmt, struct tm *tm) { /* Eat up white-space. */ if (isspace(c)) { - while (isspace((int)(*bp))) + while (isspace((int)(*bp))) { bp++; + } fmt++; continue; } - if ((c = *fmt++) != '%') + if ((c = *fmt++) != '%') { goto literal; + } again: switch (c = *fmt++) { case '%': /* "%%" is converted to "%". */ literal: - if (c != *bp++) + if (c != *bp++) { return (0); + } break; /* @@ -2255,50 +2329,57 @@ char *arg_strptime(const char *buf, const char *fmt, struct tm *tm) { case 'c': /* Date and time, using the locale's format. */ LEGAL_ALT(ALT_E); bp = arg_strptime(bp, "%x %X", tm); - if (!bp) + if (!bp) { return (0); + } break; case 'D': /* The date as "%m/%d/%y". */ LEGAL_ALT(0); bp = arg_strptime(bp, "%m/%d/%y", tm); - if (!bp) + if (!bp) { return (0); + } break; case 'R': /* The time as "%H:%M". */ LEGAL_ALT(0); bp = arg_strptime(bp, "%H:%M", tm); - if (!bp) + if (!bp) { return (0); + } break; case 'r': /* The time in 12-hour clock representation. */ LEGAL_ALT(0); bp = arg_strptime(bp, "%I:%M:%S %p", tm); - if (!bp) + if (!bp) { return (0); + } break; case 'T': /* The time as "%H:%M:%S". */ LEGAL_ALT(0); bp = arg_strptime(bp, "%H:%M:%S", tm); - if (!bp) + if (!bp) { return (0); + } break; case 'X': /* The time, using the locale's format. */ LEGAL_ALT(ALT_E); bp = arg_strptime(bp, "%H:%M:%S", tm); - if (!bp) + if (!bp) { return (0); + } break; case 'x': /* The date, using the locale's format. */ LEGAL_ALT(ALT_E); bp = arg_strptime(bp, "%m/%d/%y", tm); - if (!bp) + if (!bp) { return (0); + } break; /* @@ -2310,18 +2391,21 @@ char *arg_strptime(const char *buf, const char *fmt, struct tm *tm) { for (i = 0; i < 7; i++) { /* Full name. */ len = strlen(day[i]); - if (arg_strncasecmp(day[i], bp, len) == 0) + if (arg_strncasecmp(day[i], bp, len) == 0) { break; + } /* Abbreviated name. */ len = strlen(abday[i]); - if (arg_strncasecmp(abday[i], bp, len) == 0) + if (arg_strncasecmp(abday[i], bp, len) == 0) { break; + } } /* Nothing matched. */ - if (i == 7) + if (i == 7) { return (0); + } tm->tm_wday = i; bp += len; @@ -2334,18 +2418,21 @@ char *arg_strptime(const char *buf, const char *fmt, struct tm *tm) { for (i = 0; i < 12; i++) { /* Full name. */ len = strlen(mon[i]); - if (arg_strncasecmp(mon[i], bp, len) == 0) + if (arg_strncasecmp(mon[i], bp, len) == 0) { break; + } /* Abbreviated name. */ len = strlen(abmon[i]); - if (arg_strncasecmp(abmon[i], bp, len) == 0) + if (arg_strncasecmp(abmon[i], bp, len) == 0) { break; + } } /* Nothing matched. */ - if (i == 12) + if (i == 12) { return (0); + } tm->tm_mon = i; bp += len; @@ -2353,8 +2440,9 @@ char *arg_strptime(const char *buf, const char *fmt, struct tm *tm) { case 'C': /* The century number. */ LEGAL_ALT(ALT_E); - if (!(conv_num(&bp, &i, 0, 99))) + if (!(conv_num(&bp, &i, 0, 99))) { return (0); + } if (split_year) { tm->tm_year = (tm->tm_year % 100) + (i * 100); @@ -2367,8 +2455,9 @@ char *arg_strptime(const char *buf, const char *fmt, struct tm *tm) { case 'd': /* The day of month. */ case 'e': LEGAL_ALT(ALT_O); - if (!(conv_num(&bp, &tm->tm_mday, 1, 31))) + if (!(conv_num(&bp, &tm->tm_mday, 1, 31))) { return (0); + } break; case 'k': /* The hour (24-hour clock representation). */ @@ -2376,8 +2465,9 @@ char *arg_strptime(const char *buf, const char *fmt, struct tm *tm) { /* FALLTHROUGH */ case 'H': LEGAL_ALT(ALT_O); - if (!(conv_num(&bp, &tm->tm_hour, 0, 23))) + if (!(conv_num(&bp, &tm->tm_hour, 0, 23))) { return (0); + } break; case 'l': /* The hour (12-hour clock representation). */ @@ -2385,29 +2475,34 @@ char *arg_strptime(const char *buf, const char *fmt, struct tm *tm) { /* FALLTHROUGH */ case 'I': LEGAL_ALT(ALT_O); - if (!(conv_num(&bp, &tm->tm_hour, 1, 12))) + if (!(conv_num(&bp, &tm->tm_hour, 1, 12))) { return (0); - if (tm->tm_hour == 12) + } + if (tm->tm_hour == 12) { tm->tm_hour = 0; + } break; case 'j': /* The day of year. */ LEGAL_ALT(0); - if (!(conv_num(&bp, &i, 1, 366))) + if (!(conv_num(&bp, &i, 1, 366))) { return (0); + } tm->tm_yday = i - 1; break; case 'M': /* The minute. */ LEGAL_ALT(ALT_O); - if (!(conv_num(&bp, &tm->tm_min, 0, 59))) + if (!(conv_num(&bp, &tm->tm_min, 0, 59))) { return (0); + } break; case 'm': /* The month. */ LEGAL_ALT(ALT_O); - if (!(conv_num(&bp, &i, 1, 12))) + if (!(conv_num(&bp, &i, 1, 12))) { return (0); + } tm->tm_mon = i - 1; break; @@ -2415,16 +2510,18 @@ char *arg_strptime(const char *buf, const char *fmt, struct tm *tm) { LEGAL_ALT(0); /* AM? */ if (arg_strcasecmp(am_pm[0], bp) == 0) { - if (tm->tm_hour > 11) + if (tm->tm_hour > 11) { return (0); + } bp += strlen(am_pm[0]); break; } /* PM? */ else if (arg_strcasecmp(am_pm[1], bp) == 0) { - if (tm->tm_hour > 11) + if (tm->tm_hour > 11) { return (0); + } tm->tm_hour += 12; bp += strlen(am_pm[1]); @@ -2436,8 +2533,9 @@ char *arg_strptime(const char *buf, const char *fmt, struct tm *tm) { case 'S': /* The seconds. */ LEGAL_ALT(ALT_O); - if (!(conv_num(&bp, &tm->tm_sec, 0, 61))) + if (!(conv_num(&bp, &tm->tm_sec, 0, 61))) { return (0); + } break; case 'U': /* The week of year, beginning on sunday. */ @@ -2449,38 +2547,43 @@ char *arg_strptime(const char *buf, const char *fmt, struct tm *tm) { * point to calculate a real value, so just check the * range for now. */ - if (!(conv_num(&bp, &i, 0, 53))) + if (!(conv_num(&bp, &i, 0, 53))) { return (0); + } break; case 'w': /* The day of week, beginning on sunday. */ LEGAL_ALT(ALT_O); - if (!(conv_num(&bp, &tm->tm_wday, 0, 6))) + if (!(conv_num(&bp, &tm->tm_wday, 0, 6))) { return (0); + } break; case 'Y': /* The year. */ LEGAL_ALT(ALT_E); - if (!(conv_num(&bp, &i, 0, 9999))) + if (!(conv_num(&bp, &i, 0, 9999))) { return (0); + } tm->tm_year = i - TM_YEAR_BASE; break; case 'y': /* The year within 100 years of the epoch. */ LEGAL_ALT(ALT_E | ALT_O); - if (!(conv_num(&bp, &i, 0, 99))) + if (!(conv_num(&bp, &i, 0, 99))) { return (0); + } if (split_year) { tm->tm_year = ((tm->tm_year / 100) * 100) + i; break; } split_year = 1; - if (i <= 68) + if (i <= 68) { tm->tm_year = i + 2000 - TM_YEAR_BASE; - else + } else { tm->tm_year = i + 1900 - TM_YEAR_BASE; + } break; /* @@ -2489,8 +2592,9 @@ char *arg_strptime(const char *buf, const char *fmt, struct tm *tm) { case 'n': /* Any kind of white-space. */ case 't': LEGAL_ALT(0); - while (isspace((int)(*bp))) + while (isspace((int)(*bp))) { bp++; + } break; default: /* Unknown/unsupported conversion. */ @@ -2508,8 +2612,9 @@ static int conv_num(const char **buf, int *dest, int llim, int ulim) { /* The limit also determines the number of valid digits. */ int rulim = ulim; - if (**buf < '0' || **buf > '9') + if (**buf < '0' || **buf > '9') { return (0); + } do { result *= 10; @@ -2517,8 +2622,9 @@ static int conv_num(const char **buf, int *dest, int llim, int ulim) { rulim /= 10; } while ((result * 10 <= ulim) && rulim && **buf >= '0' && **buf <= '9'); - if (result < llim || result > ulim) + if (result < llim || result > ulim) { return (0); + } *dest = result; return (1); @@ -2587,10 +2693,11 @@ static int arg_dbl_scanfn(struct arg_dbl *parent, const char *argval) { val = strtod(argval, &end); /* if success then store result in parent->dval[] array otherwise return error*/ - if (*end == 0) + if (*end == 0) { parent->dval[parent->count++] = val; - else + } else { errorcode = ARG_ERR_BADDOUBLE; + } } ARG_TRACE(("%s:scanfn(%p) returns %d\n", __FILE__, parent, errorcode)); @@ -2604,8 +2711,11 @@ static int arg_dbl_checkfn(struct arg_dbl *parent) { return errorcode; } -static void arg_dbl_errorfn(struct arg_dbl *parent, arg_dstr_t ds, int errorcode, const char *argval, - const char *progname) { +static void arg_dbl_errorfn(struct arg_dbl *parent, + arg_dstr_t ds, + int errorcode, + const char *argval, + const char *progname) { const char *shortopts = parent->hdr.shortopts; const char *longopts = parent->hdr.longopts; const char *datatype = parent->hdr.datatype; @@ -2640,7 +2750,11 @@ struct arg_dbl *arg_dbl1(const char *shortopts, const char *longopts, const char return arg_dbln(shortopts, longopts, datatype, 1, 1, glossary); } -struct arg_dbl *arg_dbln(const char *shortopts, const char *longopts, const char *datatype, int mincount, int maxcount, +struct arg_dbl *arg_dbln(const char *shortopts, + const char *longopts, + const char *datatype, + int mincount, + int maxcount, const char *glossary) { size_t nbytes; struct arg_dbl *result; @@ -2737,8 +2851,9 @@ static void arg_end_errorfn(void *parent, arg_dstr_t ds, int error, const char * progname = progname ? progname : ""; argval = argval ? argval : ""; - if (progname && strlen(progname) > 0) + if (progname && strlen(progname) > 0) { arg_dstr_catf(ds, "%s: ", progname); + } switch (error) { case ARG_ELIMIT: @@ -2806,8 +2921,9 @@ void arg_print_errors_ds(arg_dstr_t ds, struct arg_end *end, const char *prognam ARG_TRACE(("arg_errors()\n")); for (i = 0; i < end->count; i++) { struct arg_hdr *errorparent = (struct arg_hdr *)(end->parent[i]); - if (errorparent->errorfn) + if (errorparent->errorfn) { errorparent->errorfn(end->parent[i], ds, end->error[i], end->argval[i], progname); + } } } @@ -2881,18 +2997,22 @@ static const char *arg_basename(const char *filename) { result1 = (filename ? strrchr(filename, FILESEPARATOR1) : NULL); result2 = (filename ? strrchr(filename, FILESEPARATOR2) : NULL); - if (result2) + if (result2) { result = result2 + 1; /* using FILESEPARATOR2 (the alternative file separator) */ + } - if (result1) + if (result1) { result = result1 + 1; /* using FILESEPARATOR1 (the preferred file separator) */ + } - if (!result) + if (!result) { result = filename; /* neither file separator was found so basename is the whole filename */ + } /* special cases of "." and ".." are not considered basenames */ - if (result && (strcmp(".", result) == 0 || strcmp("..", result) == 0)) + if (result && (strcmp(".", result) == 0 || strcmp("..", result) == 0)) { result = filename + strlen(filename); + } return result; } @@ -2903,16 +3023,19 @@ static const char *arg_extension(const char *basename) { const char *result = (basename ? strrchr(basename, '.') : NULL); /* if no '.' was found then return pointer to end of basename */ - if (basename && !result) + if (basename && !result) { result = basename + strlen(basename); + } /* special case: basenames with a single leading dot (eg ".foo") are not considered as true extensions */ - if (basename && result == basename) + if (basename && result == basename) { result = basename + strlen(basename); + } /* special case: empty extensions (eg "foo.","foo..") are not considered as true extensions */ - if (basename && result && strlen(result) == 1) + if (basename && result && strlen(result) == 1) { result = basename + strlen(basename); + } return result; } @@ -2947,8 +3070,11 @@ static int arg_file_checkfn(struct arg_file *parent) { return errorcode; } -static void arg_file_errorfn(struct arg_file *parent, arg_dstr_t ds, int errorcode, const char *argval, - const char *progname) { +static void arg_file_errorfn(struct arg_file *parent, + arg_dstr_t ds, + int errorcode, + const char *argval, + const char *progname) { const char *shortopts = parent->hdr.shortopts; const char *longopts = parent->hdr.longopts; const char *datatype = parent->hdr.datatype; @@ -2956,8 +3082,9 @@ static void arg_file_errorfn(struct arg_file *parent, arg_dstr_t ds, int errorco /* make argval NULL safe */ argval = argval ? argval : ""; - if (progname && strlen(progname) > 0) + if (progname && strlen(progname) > 0) { arg_dstr_catf(ds, "%s: ", progname); + } switch (errorcode) { case ARG_ERR_MINCOUNT: @@ -2983,8 +3110,12 @@ struct arg_file *arg_file1(const char *shortopts, const char *longopts, const ch return arg_filen(shortopts, longopts, datatype, 1, 1, glossary); } -struct arg_file *arg_filen(const char *shortopts, const char *longopts, const char *datatype, int mincount, - int maxcount, const char *glossary) { +struct arg_file *arg_filen(const char *shortopts, + const char *longopts, + const char *datatype, + int mincount, + int maxcount, + const char *glossary) { size_t nbytes; struct arg_file *result; int i; @@ -3092,8 +3223,9 @@ static long int strtol0X(const char *str, const char **endptr, char X, int base) const char *ptr = str; /* ptr to current position in str */ /* skip leading whitespace */ - while (isspace((int)(*ptr))) + while (isspace((int)(*ptr))) { ptr++; + } /* printf("1) %s\n",ptr); */ /* scan optional sign character */ @@ -3146,8 +3278,9 @@ static int detectsuffix(const char *str, const char *suffix) { /* printf("'%c' '%c'\n", *str, *suffix); */ /* return 1 (success) if match persists until the string terminator */ - if (*str == '\0') + if (*str == '\0') { return 1; + } /* next chars */ str++; @@ -3156,12 +3289,14 @@ static int detectsuffix(const char *str, const char *suffix) { /* printf("'%c' '%c' mismatch\n", *str, *suffix); */ /* return 0 (fail) if the matching did not consume the entire suffix */ - if (*suffix != 0) + if (*suffix != 0) { return 0; /* failed to consume entire suffix */ + } /* skip any remaining whitespace in str */ - while (isspace((int)(*str))) + while (isspace((int)(*str))) { str++; + } /* return 1 (success) if we have reached end of str else return 0 (fail) */ return (*str == '\0') ? 1 : 0; @@ -3203,35 +3338,41 @@ static int arg_int_scanfn(struct arg_int *parent, const char *argval) { /* Safety check for integer overflow. WARNING: this check */ /* achieves nothing on machines where size(int)==size(long). */ - if (val > INT_MAX || val < INT_MIN) + if (val > INT_MAX || val < INT_MIN) { errorcode = ARG_ERR_OVERFLOW; + } /* Detect any suffixes (KB,MB,GB) and multiply argument value appropriately. */ /* We need to be mindful of integer overflows when using such big numbers. */ if (detectsuffix(end, "KB")) /* kilobytes */ { - if (val > (INT_MAX / 1024) || val < (INT_MIN / 1024)) + if (val > (INT_MAX / 1024) || val < (INT_MIN / 1024)) { errorcode = ARG_ERR_OVERFLOW; /* Overflow would occur if we proceed */ - else - val *= 1024; /* 1KB = 1024 */ + } else { + val *= 1024; /* 1KB = 1024 */ + } } else if (detectsuffix(end, "MB")) /* megabytes */ { - if (val > (INT_MAX / 1048576) || val < (INT_MIN / 1048576)) + if (val > (INT_MAX / 1048576) || val < (INT_MIN / 1048576)) { errorcode = ARG_ERR_OVERFLOW; /* Overflow would occur if we proceed */ - else - val *= 1048576; /* 1MB = 1024*1024 */ + } else { + val *= 1048576; /* 1MB = 1024*1024 */ + } } else if (detectsuffix(end, "GB")) /* gigabytes */ { - if (val > (INT_MAX / 1073741824) || val < (INT_MIN / 1073741824)) + if (val > (INT_MAX / 1073741824) || val < (INT_MIN / 1073741824)) { errorcode = ARG_ERR_OVERFLOW; /* Overflow would occur if we proceed */ - else + } else { val *= 1073741824; /* 1GB = 1024*1024*1024 */ - } else if (!detectsuffix(end, "")) + } + } else if (!detectsuffix(end, "")) { errorcode = ARG_ERR_BADINT; /* invalid suffix detected */ + } /* if success then store result in parent->ival[] array */ - if (errorcode == 0) + if (errorcode == 0) { parent->ival[parent->count++] = (int)val; + } } /* printf("%s:scanfn(%p,%p) returns %d\n",__FILE__,parent,argval,errorcode); */ @@ -3244,8 +3385,11 @@ static int arg_int_checkfn(struct arg_int *parent) { return errorcode; } -static void arg_int_errorfn(struct arg_int *parent, arg_dstr_t ds, int errorcode, const char *argval, - const char *progname) { +static void arg_int_errorfn(struct arg_int *parent, + arg_dstr_t ds, + int errorcode, + const char *argval, + const char *progname) { const char *shortopts = parent->hdr.shortopts; const char *longopts = parent->hdr.longopts; const char *datatype = parent->hdr.datatype; @@ -3286,7 +3430,11 @@ struct arg_int *arg_int1(const char *shortopts, const char *longopts, const char return arg_intn(shortopts, longopts, datatype, 1, 1, glossary); } -struct arg_int *arg_intn(const char *shortopts, const char *longopts, const char *datatype, int mincount, int maxcount, +struct arg_int *arg_intn(const char *shortopts, + const char *longopts, + const char *datatype, + int mincount, + int maxcount, const char *glossary) { size_t nbytes; struct arg_int *result; @@ -3367,10 +3515,11 @@ static void arg_lit_resetfn(struct arg_lit *parent) { static int arg_lit_scanfn(struct arg_lit *parent, const char *argval) { int errorcode = 0; - if (parent->count < parent->hdr.maxcount) + if (parent->count < parent->hdr.maxcount) { parent->count++; - else + } else { errorcode = ARG_ERR_MAXCOUNT; + } ARG_TRACE(("%s:scanfn(%p,%s) returns %d\n", __FILE__, parent, argval, errorcode)); return errorcode; @@ -3382,8 +3531,11 @@ static int arg_lit_checkfn(struct arg_lit *parent) { return errorcode; } -static void arg_lit_errorfn(struct arg_lit *parent, arg_dstr_t ds, int errorcode, const char *argval, - const char *progname) { +static void arg_lit_errorfn(struct arg_lit *parent, + arg_dstr_t ds, + int errorcode, + const char *argval, + const char *progname) { const char *shortopts = parent->hdr.shortopts; const char *longopts = parent->hdr.longopts; const char *datatype = parent->hdr.datatype; @@ -3412,7 +3564,10 @@ struct arg_lit *arg_lit1(const char *shortopts, const char *longopts, const char return arg_litn(shortopts, longopts, 1, 1, glossary); } -struct arg_lit *arg_litn(const char *shortopts, const char *longopts, int mincount, int maxcount, +struct arg_lit *arg_litn(const char *shortopts, + const char *longopts, + int mincount, + int maxcount, const char *glossary) { struct arg_lit *result; @@ -3606,8 +3761,11 @@ TREX_API TRex *trex_compile(const TRexChar *pattern, const TRexChar **error, int TREX_API void trex_free(TRex *exp); TREX_API TRexBool trex_match(TRex *exp, const TRexChar *text); TREX_API TRexBool trex_search(TRex *exp, const TRexChar *text, const TRexChar **out_begin, const TRexChar **out_end); -TREX_API TRexBool trex_searchrange(TRex *exp, const TRexChar *text_begin, const TRexChar *text_end, - const TRexChar **out_begin, const TRexChar **out_end); +TREX_API TRexBool trex_searchrange(TRex *exp, + const TRexChar *text_begin, + const TRexChar *text_end, + const TRexChar **out_begin, + const TRexChar **out_end); TREX_API int trex_getsubexpcount(TRex *exp); TREX_API TRexBool trex_getsubexp(TRex *exp, int n, TRexMatch *subexp); @@ -3649,10 +3807,11 @@ static int arg_rex_scanfn(struct arg_rex *parent, const char *argval) { rex = trex_compile(priv->pattern, &error, priv->flags); is_match = trex_match(rex, argval); - if (!is_match) + if (!is_match) { errorcode = ARG_ERR_REGNOMATCH; - else + } else { parent->sval[parent->count++] = argval; + } trex_free(rex); } @@ -3674,8 +3833,11 @@ static int arg_rex_checkfn(struct arg_rex *parent) { return errorcode; } -static void arg_rex_errorfn(struct arg_rex *parent, arg_dstr_t ds, int errorcode, const char *argval, - const char *progname) { +static void arg_rex_errorfn(struct arg_rex *parent, + arg_dstr_t ds, + int errorcode, + const char *argval, + const char *progname) { const char *shortopts = parent->hdr.shortopts; const char *longopts = parent->hdr.longopts; const char *datatype = parent->hdr.datatype; @@ -3710,18 +3872,32 @@ static void arg_rex_errorfn(struct arg_rex *parent, arg_dstr_t ds, int errorcode } } -struct arg_rex *arg_rex0(const char *shortopts, const char *longopts, const char *pattern, const char *datatype, - int flags, const char *glossary) { +struct arg_rex *arg_rex0(const char *shortopts, + const char *longopts, + const char *pattern, + const char *datatype, + int flags, + const char *glossary) { return arg_rexn(shortopts, longopts, pattern, datatype, 0, 1, flags, glossary); } -struct arg_rex *arg_rex1(const char *shortopts, const char *longopts, const char *pattern, const char *datatype, - int flags, const char *glossary) { +struct arg_rex *arg_rex1(const char *shortopts, + const char *longopts, + const char *pattern, + const char *datatype, + int flags, + const char *glossary) { return arg_rexn(shortopts, longopts, pattern, datatype, 1, 1, flags, glossary); } -struct arg_rex *arg_rexn(const char *shortopts, const char *longopts, const char *pattern, const char *datatype, - int mincount, int maxcount, int flags, const char *glossary) { +struct arg_rex *arg_rexn(const char *shortopts, + const char *longopts, + const char *pattern, + const char *datatype, + int mincount, + int maxcount, + int flags, + const char *glossary) { size_t nbytes; struct arg_rex *result; struct privhdr *priv; @@ -3768,8 +3944,9 @@ struct arg_rex *arg_rexn(const char *shortopts, const char *longopts, const char result->count = 0; /* foolproof the string pointers by initializing them to reference empty strings */ - for (i = 0; i < maxcount; i++) + for (i = 0; i < maxcount; i++) { result->sval[i] = ""; + } /* here we construct and destroy a regex representation of the regular * expression for no other reason than to force any regex errors to be @@ -3882,8 +4059,9 @@ static int trex_newnode(TRex *exp, TRexNodeType type) { int newid; n.type = type; n.next = n.right = n.left = -1; - if (type == OP_EXPR) + if (type == OP_EXPR) { n.right = exp->_nsubexpr++; + } if (exp->_nallocated < (exp->_nsize + 1)) { exp->_nallocated *= 2; exp->_nodes = (TRexNode *)xrealloc(exp->_nodes, (size_t)exp->_nallocated * sizeof(TRexNode)); @@ -3894,14 +4072,16 @@ static int trex_newnode(TRex *exp, TRexNodeType type) { } static void trex_error(TRex *exp, const TRexChar *error) { - if (exp->_error) + if (exp->_error) { *exp->_error = error; + } longjmp(*((jmp_buf *)exp->_jmpbuf), -1); } static void trex_expect(TRex *exp, int n) { - if ((*exp->_p) != n) + if ((*exp->_p) != n) { trex_error(exp, _SC("expected paren")); + } exp->_p++; } @@ -3927,8 +4107,9 @@ static TRexChar trex_escapechar(TRex *exp) { default: return (*exp->_p++); } - } else if (!scisprint((int)(*exp->_p))) + } else if (!scisprint((int)(*exp->_p))) { trex_error(exp, _SC("letter expected")); + } return (*exp->_p++); } @@ -4005,22 +4186,27 @@ static int trex_class(TRex *exp) { if (*exp->_p == TREX_SYMBOL_BEGINNING_OF_STRING) { ret = trex_newnode(exp, OP_NCLASS); exp->_p++; - } else + } else { ret = trex_newnode(exp, OP_CLASS); + } - if (*exp->_p == ']') + if (*exp->_p == ']') { trex_error(exp, _SC("empty class")); + } chain = ret; while (*exp->_p != ']' && exp->_p != exp->_eol) { if (*exp->_p == '-' && first != -1) { int r, t; - if (*exp->_p++ == ']') + if (*exp->_p++ == ']') { trex_error(exp, _SC("unfinished range")); + } r = trex_newnode(exp, OP_RANGE); - if (first > *exp->_p) + if (first > *exp->_p) { trex_error(exp, _SC("invalid range")); - if (exp->_nodes[first].type == OP_CCLASS) + } + if (exp->_nodes[first].type == OP_CCLASS) { trex_error(exp, _SC("cannot use character classes in ranges")); + } exp->_nodes[r].left = exp->_nodes[first].type; t = trex_escapechar(exp); exp->_nodes[r].right = t; @@ -4056,8 +4242,9 @@ static int trex_parsenumber(TRex *exp) { exp->_p++; while (isdigit((int)(*exp->_p))) { ret = ret * 10 + (*exp->_p++ - '0'); - if (positions == 1000000000) + if (positions == 1000000000) { trex_error(exp, _SC("overflow in numeric constant")); + } positions *= 10; }; return ret; @@ -4074,8 +4261,9 @@ static int trex_element(TRex *exp) { exp->_p++; trex_expect(exp, ':'); expr = trex_newnode(exp, OP_NOCAPEXPR); - } else + } else { expr = trex_newnode(exp, OP_EXPR); + } newn = trex_list(exp); exp->_nodes[expr].left = newn; ret = expr; @@ -4123,8 +4311,9 @@ static int trex_element(TRex *exp) { break; case '{': exp->_p++; - if (!isdigit((int)(*exp->_p))) + if (!isdigit((int)(*exp->_p))) { trex_error(exp, _SC("number expected")); + } p0 = (unsigned short)trex_parsenumber(exp); /*******************************/ switch (*exp->_p) { @@ -4172,8 +4361,9 @@ static int trex_list(TRex *exp) { e = trex_element(exp); if (ret != -1) { exp->_nodes[ret].next = e; - } else + } else { ret = e; + } if (*exp->_p == TREX_SYMBOL_BRANCH) { int temp, tright; @@ -4230,26 +4420,32 @@ static TRexBool trex_matchclass(TRex *exp, TRexNode *node, TRexChar c) { switch (node->type) { case OP_RANGE: if (exp->_flags & TREX_ICASE) { - if (c >= toupper(node->left) && c <= toupper(node->right)) + if (c >= toupper(node->left) && c <= toupper(node->right)) { return TRex_True; - if (c >= tolower(node->left) && c <= tolower(node->right)) + } + if (c >= tolower(node->left) && c <= tolower(node->right)) { return TRex_True; + } } else { - if (c >= node->left && c <= node->right) + if (c >= node->left && c <= node->right) { return TRex_True; + } } break; case OP_CCLASS: - if (trex_matchcclass(node->left, c)) + if (trex_matchcclass(node->left, c)) { return TRex_True; + } break; default: if (exp->_flags & TREX_ICASE) { - if (c == tolower(node->type) || c == toupper(node->type)) + if (c == tolower(node->type) || c == toupper(node->type)) { return TRex_True; + } } else { - if (c == node->type) + if (c == node->type) { return TRex_True; + } } } } while ((node->next != -1) && ((node = &exp->_nodes[node->next]) != NULL)); @@ -4273,8 +4469,9 @@ static const TRexChar *trex_matchnode(TRex *exp, TRexNode *node, const TRexChar while ((nmaches == 0xFFFF || nmaches < p1)) { const TRexChar *stop; - if ((s = trex_matchnode(exp, &exp->_nodes[node->left], s, greedystop)) == NULL) + if ((s = trex_matchnode(exp, &exp->_nodes[node->left], s, greedystop)) == NULL) { break; + } nmaches++; good = s; if (greedystop) { @@ -4291,43 +4488,48 @@ static const TRexChar *trex_matchnode(TRex *exp, TRexNode *node, const TRexChar stop = trex_matchnode(exp, greedystop, s, gnext); if (stop) { /* if satisfied stop it */ - if (p0 == p1 && p0 == nmaches) + if (p0 == p1 && p0 == nmaches) { break; - else if (nmaches >= p0 && p1 == 0xFFFF) + } else if (nmaches >= p0 && p1 == 0xFFFF) { break; - else if (nmaches >= p0 && nmaches <= p1) + } else if (nmaches >= p0 && nmaches <= p1) { break; + } } } } - if (s >= exp->_eol) + if (s >= exp->_eol) { break; + } } - if (p0 == p1 && p0 == nmaches) + if (p0 == p1 && p0 == nmaches) { return good; - else if (nmaches >= p0 && p1 == 0xFFFF) + } else if (nmaches >= p0 && p1 == 0xFFFF) { return good; - else if (nmaches >= p0 && nmaches <= p1) + } else if (nmaches >= p0 && nmaches <= p1) { return good; + } return NULL; } case OP_OR: { const TRexChar *asd = str; TRexNode *temp = &exp->_nodes[node->left]; while ((asd = trex_matchnode(exp, temp, asd, NULL)) != NULL) { - if (temp->next != -1) + if (temp->next != -1) { temp = &exp->_nodes[temp->next]; - else + } else { return asd; + } } asd = str; temp = &exp->_nodes[node->right]; while ((asd = trex_matchnode(exp, temp, asd, NULL)) != NULL) { - if (temp->next != -1) + if (temp->next != -1) { temp = &exp->_nodes[temp->next]; - else + } else { return asd; + } } return NULL; break; @@ -4359,8 +4561,9 @@ static const TRexChar *trex_matchnode(TRex *exp, TRexNode *node, const TRexChar } } while ((n->next != -1) && ((n = &exp->_nodes[n->next]) != NULL)); - if (capture != -1) + if (capture != -1) { exp->_matches[capture].len = (int)(cur - exp->_matches[capture].begin); + } return cur; } case OP_WB: @@ -4371,12 +4574,14 @@ static const TRexChar *trex_matchnode(TRex *exp, TRexNode *node, const TRexChar } return (node->left == 'b') ? NULL : str; case OP_BOL: - if (str == exp->_bol) + if (str == exp->_bol) { return str; + } return NULL; case OP_EOL: - if (str == exp->_eol) + if (str == exp->_eol) { return str; + } return NULL; case OP_DOT: { str++; @@ -4398,11 +4603,13 @@ static const TRexChar *trex_matchnode(TRex *exp, TRexNode *node, const TRexChar return NULL; default: /* char */ if (exp->_flags & TREX_ICASE) { - if (*str != tolower(node->type) && *str != toupper(node->type)) + if (*str != tolower(node->type) && *str != toupper(node->type)) { return NULL; + } } else { - if (*str != node->type) + if (*str != node->type) { return NULL; + } } str++; return str; @@ -4426,18 +4633,20 @@ TRex *trex_compile(const TRexChar *pattern, const TRexChar **error, int flags) { if (setjmp(*((jmp_buf *)exp->_jmpbuf)) == 0) { int res = trex_list(exp); exp->_nodes[exp->_first].left = res; - if (*exp->_p != '\0') + if (*exp->_p != '\0') { trex_error(exp, _SC("unexpected character")); + } #ifdef ARG_REX_DEBUG { int nsize, i; nsize = exp->_nsize; scprintf(_SC("\n")); for (i = 0; i < nsize; i++) { - if (exp->_nodes[i].type > MAX_CHAR) + if (exp->_nodes[i].type > MAX_CHAR) { scprintf(_SC("[%02d] %10s "), i, g_nnames[exp->_nodes[i].type - MAX_CHAR]); - else + } else { scprintf(_SC("[%02d] %10c "), i, exp->_nodes[i].type); + } scprintf(_SC("left %02d right %02d next %02d\n"), exp->_nodes[i].left, exp->_nodes[i].right, @@ -4470,17 +4679,22 @@ TRexBool trex_match(TRex *exp, const TRexChar *text) { exp->_eol = text + scstrlen(text); exp->_currsubexp = 0; res = trex_matchnode(exp, exp->_nodes, text, NULL); - if (res == NULL || res != exp->_eol) + if (res == NULL || res != exp->_eol) { return TRex_False; + } return TRex_True; } -TRexBool trex_searchrange(TRex *exp, const TRexChar *text_begin, const TRexChar *text_end, const TRexChar **out_begin, +TRexBool trex_searchrange(TRex *exp, + const TRexChar *text_begin, + const TRexChar *text_end, + const TRexChar **out_begin, const TRexChar **out_end) { const TRexChar *cur = NULL; int node = exp->_first; - if (text_begin >= text_end) + if (text_begin >= text_end) { return TRex_False; + } exp->_bol = text_begin; exp->_eol = text_end; do { @@ -4488,22 +4702,26 @@ TRexBool trex_searchrange(TRex *exp, const TRexChar *text_begin, const TRexChar while (node != -1) { exp->_currsubexp = 0; cur = trex_matchnode(exp, &exp->_nodes[node], cur, NULL); - if (!cur) + if (!cur) { break; + } node = exp->_nodes[node].next; } text_begin++; } while (cur == NULL && text_begin != text_end); - if (cur == NULL) + if (cur == NULL) { return TRex_False; + } --text_begin; - if (out_begin) + if (out_begin) { *out_begin = text_begin; - if (out_end) + } + if (out_end) { *out_end = cur; + } return TRex_True; } @@ -4516,8 +4734,9 @@ int trex_getsubexpcount(TRex *exp) { } TRexBool trex_getsubexp(TRex *exp, int n, TRexMatch *subexp) { - if (n < 0 || n >= exp->_nsubexpr) + if (n < 0 || n >= exp->_nsubexpr) { return TRex_False; + } *subexp = exp->_matches[n]; return TRex_True; } @@ -4597,8 +4816,11 @@ static int arg_str_checkfn(struct arg_str *parent) { return errorcode; } -static void arg_str_errorfn(struct arg_str *parent, arg_dstr_t ds, int errorcode, const char *argval, - const char *progname) { +static void arg_str_errorfn(struct arg_str *parent, + arg_dstr_t ds, + int errorcode, + const char *argval, + const char *progname) { const char *shortopts = parent->hdr.shortopts; const char *longopts = parent->hdr.longopts; const char *datatype = parent->hdr.datatype; @@ -4628,7 +4850,11 @@ struct arg_str *arg_str1(const char *shortopts, const char *longopts, const char return arg_strn(shortopts, longopts, datatype, 1, 1, glossary); } -struct arg_str *arg_strn(const char *shortopts, const char *longopts, const char *datatype, int mincount, int maxcount, +struct arg_str *arg_strn(const char *shortopts, + const char *longopts, + const char *datatype, + int mincount, + int maxcount, const char *glossary) { size_t nbytes; struct arg_str *result; @@ -4663,8 +4889,9 @@ struct arg_str *arg_strn(const char *shortopts, const char *longopts, const char result->count = 0; /* foolproof the string pointers by initializing them to reference empty strings */ - for (i = 0; i < maxcount; i++) + for (i = 0; i < maxcount; i++) { result->sval[i] = ""; + } ARG_TRACE(("arg_strn() returns %p\n", result)); return result; @@ -4783,8 +5010,9 @@ static unsigned int hash_key(const void *key) { int c; unsigned int hash = 5381; - while ((c = *str++) != 0) + while ((c = *str++) != 0) { hash = ((hash << 5) + hash) + (unsigned int)c; /* hash * 33 + c */ + } return hash; } @@ -4894,15 +5122,17 @@ int arg_cmd_itr_search(arg_cmd_itr_t itr, void *k) { } static const char *module_name(void) { - if (s_module_name == NULL || strlen(s_module_name) == 0) + if (s_module_name == NULL || strlen(s_module_name) == 0) { return ""; + } return s_module_name; } static const char *module_version(void) { - if (s_mod_ver == NULL || strlen(s_mod_ver) == 0) + if (s_mod_ver == NULL || strlen(s_mod_ver) == 0) { return "0.0.0.0"; + } return s_mod_ver; } @@ -4935,8 +5165,13 @@ void arg_make_syntax_err_msg(arg_dstr_t ds, void **argtable, struct arg_end *end arg_dstr_cat(ds, "\n"); } -int arg_make_syntax_err_help_msg(arg_dstr_t ds, char *name, int help, int nerrors, void **argtable, struct arg_end *end, - int *exitcode) { +int arg_make_syntax_err_help_msg(arg_dstr_t ds, + char *name, + int help, + int nerrors, + void **argtable, + struct arg_end *end, + int *exitcode) { /* help handling * note: '-h|--help' takes precedence over error reporting */ @@ -5035,8 +5270,9 @@ static void arg_register_error(struct arg_end *end, void *parent, int error, con static int find_shortoption(struct arg_hdr **table, char shortopt) { int tabindex; for (tabindex = 0; !(table[tabindex]->flag & ARG_TERMINATOR); tabindex++) { - if (table[tabindex]->shortopts && strchr(table[tabindex]->shortopts, shortopt)) + if (table[tabindex]->shortopts && strchr(table[tabindex]->shortopts, shortopt)) { return tabindex; + } } return -1; } @@ -5113,22 +5349,25 @@ static struct longoptions *alloc_longoptions(struct arg_hdr **table) { char *storestart = store; /* copy progressive longopt strings into the store */ - while (*longopts != 0 && *longopts != ',') + while (*longopts != 0 && *longopts != ',') { *store++ = *longopts++; + } *store++ = 0; - if (*longopts == ',') + if (*longopts == ',') { longopts++; + } /*fprintf(stderr,"storestart=\"%s\"\n",storestart);*/ result->options[option_index].name = storestart; result->options[option_index].flag = &(result->getoptval); result->options[option_index].val = tabindex; - if (table[tabindex]->flag & ARG_HASOPTVALUE) + if (table[tabindex]->flag & ARG_HASOPTVALUE) { result->options[option_index].has_arg = 2; - else if (table[tabindex]->flag & ARG_HASVALUE) + } else if (table[tabindex]->flag & ARG_HASVALUE) { result->options[option_index].has_arg = 1; - else + } else { result->options[option_index].has_arg = 0; + } option_index++; } @@ -5168,10 +5407,12 @@ static char *alloc_shortoptions(struct arg_hdr **table) { const char *shortopts = hdr->shortopts; while (shortopts && *shortopts) { *res++ = *shortopts++; - if (hdr->flag & ARG_HASVALUE) + if (hdr->flag & ARG_HASVALUE) { *res++ = ':'; - if (hdr->flag & ARG_HASOPTVALUE) + } + if (hdr->flag & ARG_HASOPTVALUE) { *res++ = ':'; + } } } /* null terminate the string */ @@ -5184,8 +5425,9 @@ static char *alloc_shortoptions(struct arg_hdr **table) { /* return index of the table terminator entry */ static int arg_endindex(struct arg_hdr **table) { int tabindex = 0; - while (!(table[tabindex]->flag & ARG_TERMINATOR)) + while (!(table[tabindex]->flag & ARG_TERMINATOR)) { tabindex++; + } return tabindex; } @@ -5231,8 +5473,9 @@ static void arg_parse_tagged(int argc, char **argv, struct arg_hdr **table, stru } if (table[tabindex]->scanfn) { int errorcode = table[tabindex]->scanfn(parent, optarg); - if (errorcode != 0) + if (errorcode != 0) { arg_register_error(endtable, parent, errorcode, optarg); + } } } break; @@ -5274,8 +5517,9 @@ static void arg_parse_tagged(int argc, char **argv, struct arg_hdr **table, stru if (table[tabindex]->scanfn) { void *parent = table[tabindex]->parent; int errorcode = table[tabindex]->scanfn(parent, optarg); - if (errorcode != 0) + if (errorcode != 0) { arg_register_error(endtable, parent, errorcode, optarg); + } } } break; @@ -5365,8 +5609,9 @@ static void arg_parse_check(struct arg_hdr **table, struct arg_end *endtable) { if (table[tabindex]->checkfn) { void *parent = table[tabindex]->parent; int errorcode = table[tabindex]->checkfn(parent); - if (errorcode != 0) + if (errorcode != 0) { arg_register_error(endtable, parent, errorcode, NULL); + } } } while (!(table[tabindex++]->flag & ARG_TERMINATOR)); } @@ -5376,8 +5621,9 @@ static void arg_reset(void **argtable) { int tabindex = 0; /*printf("arg_reset(%p)\n",argtable);*/ do { - if (table[tabindex]->resetfn) + if (table[tabindex]->resetfn) { table[tabindex]->resetfn(table[tabindex]->parent); + } } while (!(table[tabindex++]->flag & ARG_TERMINATOR)); } @@ -5415,8 +5661,9 @@ int arg_parse(int argc, char **argv, void **argtable) { because getopt rearranges argv[] which adversely affects susbsequent parsing attempts. */ - for (i = 0; i < argc; i++) + for (i = 0; i < argc; i++) { argvcopy[i] = argv[i]; + } argvcopy[argc] = NULL; @@ -5427,8 +5674,9 @@ int arg_parse(int argc, char **argv, void **argtable) { arg_parse_untagged(argc, argvcopy, table, endtable); /* if no errors so far then perform post-parse checks otherwise dont bother */ - if (endtable->count == 0) + if (endtable->count == 0) { arg_parse_check(table, endtable); + } /* release the local copt of argv[] */ xfree(argvcopy); @@ -5461,12 +5709,14 @@ static void arg_cat(char **pdest, const char *src, size_t *pndest) { char *end = dest + *pndest; /*locate null terminator of dest string */ - while (dest < end && *dest != 0) + while (dest < end && *dest != 0) { dest++; + } /* concat src string to dest string */ - while (dest < end && *src != 0) + while (dest < end && *src != 0) { *dest++ = *src++; + } /* null terminate dest string */ *dest = 0; @@ -5476,8 +5726,12 @@ static void arg_cat(char **pdest, const char *src, size_t *pndest) { *pdest = dest; } -static void arg_cat_option(char *dest, size_t ndest, const char *shortopts, const char *longopts, const char *datatype, - int optvalue) { +static void arg_cat_option(char *dest, + size_t ndest, + const char *shortopts, + const char *longopts, + const char *datatype, + int optvalue) { if (shortopts) { char option[3]; @@ -5494,8 +5748,9 @@ static void arg_cat_option(char *dest, size_t ndest, const char *shortopts, cons arg_cat(&dest, "[", &ndest); arg_cat(&dest, datatype, &ndest); arg_cat(&dest, "]", &ndest); - } else + } else { arg_cat(&dest, datatype, &ndest); + } } } else if (longopts) { size_t ncspn; @@ -5518,21 +5773,28 @@ static void arg_cat_option(char *dest, size_t ndest, const char *shortopts, cons arg_cat(&dest, "[", &ndest); arg_cat(&dest, datatype, &ndest); arg_cat(&dest, "]", &ndest); - } else + } else { arg_cat(&dest, datatype, &ndest); + } } } else if (datatype) { if (optvalue) { arg_cat(&dest, "[", &ndest); arg_cat(&dest, datatype, &ndest); arg_cat(&dest, "]", &ndest); - } else + } else { arg_cat(&dest, datatype, &ndest); + } } } -static void arg_cat_optionv(char *dest, size_t ndest, const char *shortopts, const char *longopts, const char *datatype, - int optvalue, const char *separator) { +static void arg_cat_optionv(char *dest, + size_t ndest, + const char *shortopts, + const char *longopts, + const char *datatype, + int optvalue, + const char *separator) { separator = separator ? separator : ""; if (shortopts) { @@ -5548,14 +5810,16 @@ static void arg_cat_optionv(char *dest, size_t ndest, const char *shortopts, con shortopt[2] = 0; arg_cat(&dest, shortopt, &ndest); - if (*++c) + if (*++c) { arg_cat(&dest, separator, &ndest); + } } } /* put separator between long opts and short opts */ - if (shortopts && longopts) + if (shortopts && longopts) { arg_cat(&dest, separator, &ndest); + } if (longopts) { const char *c = longopts; @@ -5584,21 +5848,26 @@ static void arg_cat_optionv(char *dest, size_t ndest, const char *shortopts, con } if (datatype) { - if (longopts) + if (longopts) { arg_cat(&dest, "=", &ndest); - else if (shortopts) + } else if (shortopts) { arg_cat(&dest, " ", &ndest); + } if (optvalue) { arg_cat(&dest, "[", &ndest); arg_cat(&dest, datatype, &ndest); arg_cat(&dest, "]", &ndest); - } else + } else { arg_cat(&dest, datatype, &ndest); + } } } -void arg_print_option_ds(arg_dstr_t ds, const char *shortopts, const char *longopts, const char *datatype, +void arg_print_option_ds(arg_dstr_t ds, + const char *shortopts, + const char *longopts, + const char *datatype, const char *suffix) { char syntax[200] = ""; suffix = suffix ? suffix : ""; @@ -5632,19 +5901,23 @@ static void arg_print_gnuswitch_ds(arg_dstr_t ds, struct arg_hdr **table) { /* print all mandatory switches that are without argument values */ for (tabindex = 0; table[tabindex] && !(table[tabindex]->flag & ARG_TERMINATOR); tabindex++) { /* skip optional options */ - if (table[tabindex]->mincount < 1) + if (table[tabindex]->mincount < 1) { continue; + } /* skip non-short options */ - if (table[tabindex]->shortopts == NULL) + if (table[tabindex]->shortopts == NULL) { continue; + } /* skip options that take argument values */ - if (table[tabindex]->flag & ARG_HASVALUE) + if (table[tabindex]->flag & ARG_HASVALUE) { continue; + } - if (table[tabindex]->maxcount == ARG_MAX_FLAG) + if (table[tabindex]->maxcount == ARG_MAX_FLAG) { continue; + } /* print the short option (only the first short option char, ignore multiple choices)*/ arg_dstr_catf(ds, format1, table[tabindex]->shortopts[0]); @@ -5655,19 +5928,23 @@ static void arg_print_gnuswitch_ds(arg_dstr_t ds, struct arg_hdr **table) { /* print all optional switches that are without argument values */ for (tabindex = 0; table[tabindex] && !(table[tabindex]->flag & ARG_TERMINATOR); tabindex++) { /* skip mandatory args */ - if (table[tabindex]->mincount > 0) + if (table[tabindex]->mincount > 0) { continue; + } /* skip args without short options */ - if (table[tabindex]->shortopts == NULL) + if (table[tabindex]->shortopts == NULL) { continue; + } /* skip args with values */ - if (table[tabindex]->flag & ARG_HASVALUE) + if (table[tabindex]->flag & ARG_HASVALUE) { continue; + } - if (table[tabindex]->maxcount == ARG_MAX_FLAG) + if (table[tabindex]->maxcount == ARG_MAX_FLAG) { continue; + } /* print first short option */ arg_dstr_catf(ds, format2, table[tabindex]->shortopts[0]); @@ -5701,12 +5978,8 @@ void arg_print_syntax_ds(arg_dstr_t ds, void **argtable, const char *suffix) { shortopts = table[tabindex]->shortopts; longopts = table[tabindex]->longopts; datatype = table[tabindex]->datatype; - arg_cat_option(syntax, - sizeof(syntax) - 1, - shortopts, - longopts, - datatype, - table[tabindex]->flag & ARG_HASOPTVALUE); + arg_cat_option( + syntax, sizeof(syntax) - 1, shortopts, longopts, datatype, table[tabindex]->flag & ARG_HASOPTVALUE); if (strlen(syntax) > 0) { /* print mandatory instances of this option */ @@ -5765,13 +6038,8 @@ void arg_print_syntaxv_ds(arg_dstr_t ds, void **argtable, const char *suffix) { shortopts = table[tabindex]->shortopts; longopts = table[tabindex]->longopts; datatype = table[tabindex]->datatype; - arg_cat_optionv(syntax, - sizeof(syntax) - 1, - shortopts, - longopts, - datatype, - table[tabindex]->flag & ARG_HASOPTVALUE, - "|"); + arg_cat_optionv( + syntax, sizeof(syntax) - 1, shortopts, longopts, datatype, table[tabindex]->flag & ARG_HASOPTVALUE, "|"); /* print mandatory options */ for (i = 0; i < table[tabindex]->mincount; i++) { @@ -6003,14 +6271,16 @@ int arg_nullcheck(void **argtable) { int tabindex; /*printf("arg_nullcheck(%p)\n",argtable);*/ - if (!table) + if (!table) { return 1; + } tabindex = 0; do { /*printf("argtable[%d]=%p\n",tabindex,argtable[tabindex]);*/ - if (!table[tabindex]) + if (!table[tabindex]) { return 1; + } } while (!(table[tabindex++]->flag & ARG_TERMINATOR)); return 0; @@ -6039,8 +6309,9 @@ void arg_free(void **argtable) { an intermediate entry could be NULL with other non-NULL entries to follow. The subsequent argtable entries would then not be freed as they should. */ - if (table[tabindex] == NULL) + if (table[tabindex] == NULL) { break; + } flag = table[tabindex]->flag; xfree(table[tabindex]); @@ -6055,8 +6326,9 @@ void arg_freetable(void **argtable, size_t n) { size_t tabindex = 0; /*printf("arg_freetable(%p)\n",argtable);*/ for (tabindex = 0; tabindex < n; tabindex++) { - if (table[tabindex] == NULL) + if (table[tabindex] == NULL) { continue; + } xfree(table[tabindex]); table[tabindex] = NULL; diff --git a/srcs/libs/args/argtable3.h b/srcs/libs/args/argtable3.h index b364884..d31054b 100644 --- a/srcs/libs/args/argtable3.h +++ b/srcs/libs/args/argtable3.h @@ -188,50 +188,110 @@ ARG_EXTERN struct arg_rem *arg_rem(const char *datatype, const char *glossary); ARG_EXTERN struct arg_lit *arg_lit0(const char *shortopts, const char *longopts, const char *glossary); ARG_EXTERN struct arg_lit *arg_lit1(const char *shortopts, const char *longopts, const char *glossary); -ARG_EXTERN struct arg_lit *arg_litn(const char *shortopts, const char *longopts, int mincount, int maxcount, +ARG_EXTERN struct arg_lit *arg_litn(const char *shortopts, + const char *longopts, + int mincount, + int maxcount, const char *glossary); -ARG_EXTERN struct arg_int *arg_int0(const char *shortopts, const char *longopts, const char *datatype, +ARG_EXTERN struct arg_int *arg_int0(const char *shortopts, + const char *longopts, + const char *datatype, const char *glossary); -ARG_EXTERN struct arg_int *arg_int1(const char *shortopts, const char *longopts, const char *datatype, +ARG_EXTERN struct arg_int *arg_int1(const char *shortopts, + const char *longopts, + const char *datatype, + const char *glossary); +ARG_EXTERN struct arg_int *arg_intn(const char *shortopts, + const char *longopts, + const char *datatype, + int mincount, + int maxcount, const char *glossary); -ARG_EXTERN struct arg_int *arg_intn(const char *shortopts, const char *longopts, const char *datatype, int mincount, - int maxcount, const char *glossary); -ARG_EXTERN struct arg_dbl *arg_dbl0(const char *shortopts, const char *longopts, const char *datatype, +ARG_EXTERN struct arg_dbl *arg_dbl0(const char *shortopts, + const char *longopts, + const char *datatype, const char *glossary); -ARG_EXTERN struct arg_dbl *arg_dbl1(const char *shortopts, const char *longopts, const char *datatype, +ARG_EXTERN struct arg_dbl *arg_dbl1(const char *shortopts, + const char *longopts, + const char *datatype, + const char *glossary); +ARG_EXTERN struct arg_dbl *arg_dbln(const char *shortopts, + const char *longopts, + const char *datatype, + int mincount, + int maxcount, const char *glossary); -ARG_EXTERN struct arg_dbl *arg_dbln(const char *shortopts, const char *longopts, const char *datatype, int mincount, - int maxcount, const char *glossary); -ARG_EXTERN struct arg_str *arg_str0(const char *shortopts, const char *longopts, const char *datatype, +ARG_EXTERN struct arg_str *arg_str0(const char *shortopts, + const char *longopts, + const char *datatype, const char *glossary); -ARG_EXTERN struct arg_str *arg_str1(const char *shortopts, const char *longopts, const char *datatype, +ARG_EXTERN struct arg_str *arg_str1(const char *shortopts, + const char *longopts, + const char *datatype, + const char *glossary); +ARG_EXTERN struct arg_str *arg_strn(const char *shortopts, + const char *longopts, + const char *datatype, + int mincount, + int maxcount, const char *glossary); -ARG_EXTERN struct arg_str *arg_strn(const char *shortopts, const char *longopts, const char *datatype, int mincount, - int maxcount, const char *glossary); -ARG_EXTERN struct arg_rex *arg_rex0(const char *shortopts, const char *longopts, const char *pattern, - const char *datatype, int flags, const char *glossary); -ARG_EXTERN struct arg_rex *arg_rex1(const char *shortopts, const char *longopts, const char *pattern, - const char *datatype, int flags, const char *glossary); -ARG_EXTERN struct arg_rex *arg_rexn(const char *shortopts, const char *longopts, const char *pattern, - const char *datatype, int mincount, int maxcount, int flags, const char *glossary); +ARG_EXTERN struct arg_rex *arg_rex0(const char *shortopts, + const char *longopts, + const char *pattern, + const char *datatype, + int flags, + const char *glossary); +ARG_EXTERN struct arg_rex *arg_rex1(const char *shortopts, + const char *longopts, + const char *pattern, + const char *datatype, + int flags, + const char *glossary); +ARG_EXTERN struct arg_rex *arg_rexn(const char *shortopts, + const char *longopts, + const char *pattern, + const char *datatype, + int mincount, + int maxcount, + int flags, + const char *glossary); -ARG_EXTERN struct arg_file *arg_file0(const char *shortopts, const char *longopts, const char *datatype, +ARG_EXTERN struct arg_file *arg_file0(const char *shortopts, + const char *longopts, + const char *datatype, const char *glossary); -ARG_EXTERN struct arg_file *arg_file1(const char *shortopts, const char *longopts, const char *datatype, +ARG_EXTERN struct arg_file *arg_file1(const char *shortopts, + const char *longopts, + const char *datatype, + const char *glossary); +ARG_EXTERN struct arg_file *arg_filen(const char *shortopts, + const char *longopts, + const char *datatype, + int mincount, + int maxcount, const char *glossary); -ARG_EXTERN struct arg_file *arg_filen(const char *shortopts, const char *longopts, const char *datatype, int mincount, - int maxcount, const char *glossary); -ARG_EXTERN struct arg_date *arg_date0(const char *shortopts, const char *longopts, const char *format, - const char *datatype, const char *glossary); -ARG_EXTERN struct arg_date *arg_date1(const char *shortopts, const char *longopts, const char *format, - const char *datatype, const char *glossary); -ARG_EXTERN struct arg_date *arg_daten(const char *shortopts, const char *longopts, const char *format, - const char *datatype, int mincount, int maxcount, const char *glossary); +ARG_EXTERN struct arg_date *arg_date0(const char *shortopts, + const char *longopts, + const char *format, + const char *datatype, + const char *glossary); +ARG_EXTERN struct arg_date *arg_date1(const char *shortopts, + const char *longopts, + const char *format, + const char *datatype, + const char *glossary); +ARG_EXTERN struct arg_date *arg_daten(const char *shortopts, + const char *longopts, + const char *format, + const char *datatype, + int mincount, + int maxcount, + const char *glossary); ARG_EXTERN struct arg_end *arg_end(int maxerrors); @@ -242,14 +302,20 @@ ARG_EXTERN struct arg_end *arg_end(int maxerrors); /**** other functions *******************************************/ ARG_EXTERN int arg_nullcheck(void **argtable); ARG_EXTERN int arg_parse(int argc, char **argv, void **argtable); -ARG_EXTERN void arg_print_option(FILE *fp, const char *shortopts, const char *longopts, const char *datatype, +ARG_EXTERN void arg_print_option(FILE *fp, + const char *shortopts, + const char *longopts, + const char *datatype, const char *suffix); ARG_EXTERN void arg_print_syntax(FILE *fp, void **argtable, const char *suffix); ARG_EXTERN void arg_print_syntaxv(FILE *fp, void **argtable, const char *suffix); ARG_EXTERN void arg_print_glossary(FILE *fp, void **argtable, const char *format); ARG_EXTERN void arg_print_glossary_gnu(FILE *fp, void **argtable); ARG_EXTERN void arg_print_errors(FILE *fp, struct arg_end *end, const char *progname); -ARG_EXTERN void arg_print_option_ds(arg_dstr_t ds, const char *shortopts, const char *longopts, const char *datatype, +ARG_EXTERN void arg_print_option_ds(arg_dstr_t ds, + const char *shortopts, + const char *longopts, + const char *datatype, const char *suffix); ARG_EXTERN void arg_print_syntax_ds(arg_dstr_t ds, void **argtable, const char *suffix); ARG_EXTERN void arg_print_syntaxv_ds(arg_dstr_t ds, void **argtable, const char *suffix); @@ -285,10 +351,15 @@ ARG_EXTERN void arg_mgsort(void *data, int size, int esize, int i, in ARG_EXTERN void arg_make_get_help_msg(arg_dstr_t res); ARG_EXTERN void arg_make_help_msg(arg_dstr_t ds, char *cmd_name, void **argtable); ARG_EXTERN void arg_make_syntax_err_msg(arg_dstr_t ds, void **argtable, struct arg_end *end); -ARG_EXTERN int arg_make_syntax_err_help_msg(arg_dstr_t ds, char *name, int help, int nerrors, void **argtable, - struct arg_end *end, int *exitcode); -ARG_EXTERN void arg_set_module_name(const char *name); -ARG_EXTERN void arg_set_module_version(int major, int minor, int patch, const char *tag); +ARG_EXTERN int arg_make_syntax_err_help_msg(arg_dstr_t ds, + char *name, + int help, + int nerrors, + void **argtable, + struct arg_end *end, + int *exitcode); +ARG_EXTERN void arg_set_module_name(const char *name); +ARG_EXTERN void arg_set_module_version(int major, int minor, int patch, const char *tag); /**** deprecated functions, for back-compatibility only ********/ ARG_EXTERN void arg_free(void **argtable); diff --git a/srcs/libs/cmdline/cmd_menu.c b/srcs/libs/cmdline/cmd_menu.c index d73a6ea..efd65fa 100644 --- a/srcs/libs/cmdline/cmd_menu.c +++ b/srcs/libs/cmdline/cmd_menu.c @@ -38,8 +38,8 @@ typedef struct __ARG_TBL_INFO { static PARG_TBL_INFO g_pArgTbl = NULL; static unsigned int g_nArgTbl = 0; static const char *g_toolsKey[][2] = { - {"cfg_all", "get all configuration information"}, - {"mem_info", "show the memory alloc information"}, + {"cfg_all", "get all configuration information" }, + {"mem_info", "show the memory alloc information" }, {"sys_info", "show the system and hardware information"}, }; @@ -428,8 +428,8 @@ static int on_cmd7(void *pTbl[], const char *pName, void *pInfo) { #endif static int on_cmd_(void *pTbl[], const char *pName, void *pInfo) { - PARG_TBL_INFO pArg = (PARG_TBL_INFO)pInfo; - int help = get_help_cmd(pTbl, pArg)->count; + PARG_TBL_INFO pArg = (PARG_TBL_INFO)pInfo; + int help = get_help_cmd(pTbl, pArg)->count; //int version = ((arg_lit_t *)pTbl[0])->count; if (help > 0) { diff --git a/srcs/libs/configure/config_help.c b/srcs/libs/configure/config_help.c index cd84d89..4e00cc0 100644 --- a/srcs/libs/configure/config_help.c +++ b/srcs/libs/configure/config_help.c @@ -17,7 +17,7 @@ const vector config_get_dhcp_replication_svr() { } #endif -const char* config_get_http_server_addr() { +const char *config_get_http_server_addr() { return cfg_get_string_value(CFG_HTTP_SVR_ADDR); } diff --git a/srcs/libs/crypto/crypto.c b/srcs/libs/crypto/crypto.c index 119f720..d74ae17 100644 --- a/srcs/libs/crypto/crypto.c +++ b/srcs/libs/crypto/crypto.c @@ -77,8 +77,12 @@ static void onEVPWorkCb(uv_work_t *pWork) { } } -int evp_add_crypto_task(CRYPTO_TYPE type, unsigned char *pInBuf, unsigned int iSize, unsigned char *pOutBuf, char *pKey, - on_evp_crypto onEvpCryptCb) { +int evp_add_crypto_task(CRYPTO_TYPE type, + unsigned char *pInBuf, + unsigned int iSize, + unsigned char *pOutBuf, + char *pKey, + on_evp_crypto onEvpCryptCb) { uv_work_t *puvWork = NULL; PCRYPT_TASK_PARAMS pTask = NULL; diff --git a/srcs/libs/crypto/hash_digest.c b/srcs/libs/crypto/hash_digest.c index 77e9b8d..53be6f4 100644 --- a/srcs/libs/crypto/hash_digest.c +++ b/srcs/libs/crypto/hash_digest.c @@ -92,8 +92,11 @@ int hash_digest_file(HASH_TYPE hashType, const char *pFileName, char **pHashValu * @param pHashValue * @return */ -int hash_digest_mem(HASH_TYPE hashType, const unsigned char *pBuf, unsigned int iBufLen, unsigned char **pHashValue, - unsigned int *pOutSize) { +int hash_digest_mem(HASH_TYPE hashType, + const unsigned char *pBuf, + unsigned int iBufLen, + unsigned char **pHashValue, + unsigned int *pOutSize) { EVP_MD_CTX *pCtx; if (pHashValue == NULL || pBuf == NULL || pOutSize == NULL) { diff --git a/srcs/libs/crypto/symmetric.c b/srcs/libs/crypto/symmetric.c index 3e62912..95d87d8 100644 --- a/srcs/libs/crypto/symmetric.c +++ b/srcs/libs/crypto/symmetric.c @@ -66,7 +66,7 @@ static int sha1prng_for_aes_key(const char *pKey, unsigned char *pShaPrng16) { strncpy((char *)keyBuf, pKey, EVP_CIPHER_key_length(pCipher)); \ break; \ case AES128_ECB_PKCS7PADDING_SHA1PRNG: \ - if (sha1prng_for_aes_key(pKey, keyBuf) != ERR_SUCCESS) { \ + if (sha1prng_for_aes_key(pKey, keyBuf) != ERR_SUCCESS) { \ EVP_CIPHER_CTX_cleanup(pCtx); \ return -ERR_AES128_KEYGEN; \ } \ @@ -110,8 +110,12 @@ static int sha1prng_for_aes_key(const char *pKey, unsigned char *pShaPrng16) { } \ } while (0) -int symmetric_decrypto(AES_TYPE algorithmType, unsigned char *pInBuf, unsigned int inSize, unsigned char **pOutBuf, - int *pOutSize, const char *pKey) { +int symmetric_decrypto(AES_TYPE algorithmType, + unsigned char *pInBuf, + unsigned int inSize, + unsigned char **pOutBuf, + int *pOutSize, + const char *pKey) { int enBytes = 0; EVP_CIPHER_CTX *pCtx; unsigned char *pAesBuf; @@ -180,8 +184,12 @@ int symmetric_decrypto(AES_TYPE algorithmType, unsigned char *pInBuf, unsigned i return ERR_SUCCESS; } -int symmetric_encrypto(AES_TYPE algorithmType, unsigned char *pInBuf, unsigned int inSize, unsigned char **pOutBuf, - int *pOutSize, const char *pKey) { +int symmetric_encrypto(AES_TYPE algorithmType, + unsigned char *pInBuf, + unsigned int inSize, + unsigned char **pOutBuf, + int *pOutSize, + const char *pKey) { int enBytes = 0; unsigned char *pAesBuf; EVP_CIPHER_CTX *pCtx; diff --git a/srcs/libs/database/sqlite3/config.h b/srcs/libs/database/sqlite3/config.h index 4f2abca..5f14e8b 100644 --- a/srcs/libs/database/sqlite3/config.h +++ b/srcs/libs/database/sqlite3/config.h @@ -141,7 +141,7 @@ /* Enable large inode numbers on Mac OS X 10.5. */ #ifndef _DARWIN_USE_64_BIT_INODE -# define _DARWIN_USE_64_BIT_INODE 1 +#define _DARWIN_USE_64_BIT_INODE 1 #endif /* Number of bits in a file offset, on hosts where this is settable. */ diff --git a/srcs/libs/include/config.h b/srcs/libs/include/config.h index d10a468..485f296 100644 --- a/srcs/libs/include/config.h +++ b/srcs/libs/include/config.h @@ -111,7 +111,7 @@ int cfg_get_zero_mq_port(); const char *cfg_get_zero_mq_data_path(); const char *cfg_get_string_value(CONFIG_ITEM_ID id); -vector cfg_get_vector(CONFIG_ITEM_ID id); +vector cfg_get_vector(CONFIG_ITEM_ID id); long double cfg_get_float_value(CONFIG_ITEM_ID id); int cfg_get_bool_value(CONFIG_ITEM_ID id); long long cfg_get_integral_value(CONFIG_ITEM_ID id); @@ -137,4 +137,4 @@ const vector config_get_dhcp_replication_svr(); #ifdef __cplusplus } #endif -#endif//DAEMON_AGENT_INCLUDE_CONFIG_H +#endif //DAEMON_AGENT_INCLUDE_CONFIG_H diff --git a/srcs/libs/include/crypto.h b/srcs/libs/include/crypto.h index f8239dc..b32dec0 100644 --- a/srcs/libs/include/crypto.h +++ b/srcs/libs/include/crypto.h @@ -38,16 +38,27 @@ typedef enum { HASH_TYPE_SHA256 = 2, } HASH_TYPE; -typedef void (*on_evp_crypto)(CRYPTO_TYPE type, const unsigned char *pData, unsigned int iSize, - const unsigned char *pSrcData, int iError); +typedef void (*on_evp_crypto)(CRYPTO_TYPE type, + const unsigned char *pData, + unsigned int iSize, + const unsigned char *pSrcData, + int iError); //***************************************************** // AES //***************************************************** -int symmetric_encrypto(AES_TYPE algorithmType, unsigned char *pInBuf, unsigned int inSize, unsigned char **pOutBuf, - int *pOutSize, const char *pKey); -int symmetric_decrypto(AES_TYPE algorithmType, unsigned char *pInBuf, unsigned int inSize, unsigned char **pOutBuf, - int *pOutSize, const char *pKey); +int symmetric_encrypto(AES_TYPE algorithmType, + unsigned char *pInBuf, + unsigned int inSize, + unsigned char **pOutBuf, + int *pOutSize, + const char *pKey); +int symmetric_decrypto(AES_TYPE algorithmType, + unsigned char *pInBuf, + unsigned int inSize, + unsigned char **pOutBuf, + int *pOutSize, + const char *pKey); //***************************************************** // BASE64 //***************************************************** @@ -62,18 +73,25 @@ unsigned char *base64_decode(const char *pBase64, unsigned int *pOutSize); // MD5 //***************************************************** int hash_digest_file(HASH_TYPE hashType, const char *pFileName, char **pHashValue); -int hash_digest_mem(HASH_TYPE hashType, const unsigned char *pBuf, unsigned int iBufLen, unsigned char **pHashValue, - unsigned int *pOutSize); +int hash_digest_mem(HASH_TYPE hashType, + const unsigned char *pBuf, + unsigned int iBufLen, + unsigned char **pHashValue, + unsigned int *pOutSize); //***************************************************** // Async Engine //***************************************************** -int evp_add_crypto_task(CRYPTO_TYPE type, unsigned char *pInBuf, unsigned int iSize, unsigned char *pOutBuf, char *pKey, - on_evp_crypto onEvpCryptCb); +int evp_add_crypto_task(CRYPTO_TYPE type, + unsigned char *pInBuf, + unsigned int iSize, + unsigned char *pOutBuf, + char *pKey, + on_evp_crypto onEvpCryptCb); void evp_system_init(void); #ifdef __cplusplus } #endif -#endif//DAEMON_AGENT_CRYPTO_CRYPTO_H +#endif //DAEMON_AGENT_CRYPTO_CRYPTO_H diff --git a/srcs/libs/include/inet_misc.h b/srcs/libs/include/inet_misc.h index c0269f4..7a50532 100644 --- a/srcs/libs/include/inet_misc.h +++ b/srcs/libs/include/inet_misc.h @@ -10,15 +10,25 @@ extern "C" { int inet_api_init(void); -typedef void (*on_http_response)(void *pData, unsigned int size, const char *pReqUrl, const char *pDlPath, - const char *pTaskUuid, int iFinished, void *pUserData); -typedef void (*on_progress_changed)(const char *pReqUrl, const char *pTaskUuid, unsigned char uPercent, - void *pUserData); +typedef void (*on_http_response)(void *pData, + unsigned int size, + const char *pReqUrl, + const char *pDlPath, + const char *pTaskUuid, + int iFinished, + void *pUserData); +typedef void (*on_progress_changed)(const char *pReqUrl, + const char *pTaskUuid, + unsigned char uPercent, + void *pUserData); -const char *inet_download_file_async(const char *pURL, const char *pPath, on_http_response onRespCb, - on_progress_changed onProgressCb, void *pData); +const char *inet_download_file_async(const char *pURL, + const char *pPath, + on_http_response onRespCb, + on_progress_changed onProgressCb, + void *pData); #ifdef __cplusplus } #endif -#endif//DAEMON_AGENT_NETWORD_INET_MISC_H +#endif //DAEMON_AGENT_NETWORD_INET_MISC_H diff --git a/srcs/libs/include/misc.h b/srcs/libs/include/misc.h index 9f80ae3..994995a 100644 --- a/srcs/libs/include/misc.h +++ b/srcs/libs/include/misc.h @@ -50,10 +50,13 @@ int copy_file(const char *pSrc, const char *pDest); char *bin2hex(char *p, const unsigned char *cp, unsigned int count); int shell_with_output(const char *pCmd, char **pResult); int str_to_mac(const char *str, unsigned char mac[6]); -int get_nic_info(const char *pName, unsigned int *pIp, unsigned int *pNetmask, unsigned int *pGateway, +int get_nic_info(const char *pName, + unsigned int *pIp, + unsigned int *pNetmask, + unsigned int *pGateway, unsigned char *pMac); int str_to_ipaddr(const char *pIp, unsigned int *ipAddr); #ifdef __cplusplus } #endif -#endif//DAEMON_AGENT_MISC_MISC_H +#endif //DAEMON_AGENT_MISC_MISC_H diff --git a/srcs/libs/include/s2j/cJSON.h b/srcs/libs/include/s2j/cJSON.h index e97e5f4..5afcc02 100644 --- a/srcs/libs/include/s2j/cJSON.h +++ b/srcs/libs/include/s2j/cJSON.h @@ -24,8 +24,7 @@ #define cJSON__h #ifdef __cplusplus -extern "C" -{ +extern "C" { #endif #if !defined(__WINDOWS__) && (defined(WIN32) || defined(WIN64) || defined(_MSC_VER) || defined(_WIN32)) @@ -52,7 +51,7 @@ then using the CJSON_API_VISIBILITY flag to "export" the same symbols the way CJ */ -#define CJSON_CDECL __cdecl +#define CJSON_CDECL __cdecl #define CJSON_STDCALL __stdcall /* export symbols by default, this is necessary for copy pasting the C and header file */ @@ -61,18 +60,18 @@ then using the CJSON_API_VISIBILITY flag to "export" the same symbols the way CJ #endif #if defined(CJSON_HIDE_SYMBOLS) -#define CJSON_PUBLIC(type) type CJSON_STDCALL +#define CJSON_PUBLIC(type) type CJSON_STDCALL #elif defined(CJSON_EXPORT_SYMBOLS) -#define CJSON_PUBLIC(type) __declspec(dllexport) type CJSON_STDCALL +#define CJSON_PUBLIC(type) __declspec(dllexport) type CJSON_STDCALL #elif defined(CJSON_IMPORT_SYMBOLS) -#define CJSON_PUBLIC(type) __declspec(dllimport) type CJSON_STDCALL +#define CJSON_PUBLIC(type) __declspec(dllimport) type CJSON_STDCALL #endif #else /* !__WINDOWS__ */ #define CJSON_CDECL #define CJSON_STDCALL -#if (defined(__GNUC__) || defined(__SUNPRO_CC) || defined (__SUNPRO_C)) && defined(CJSON_API_VISIBILITY) -#define CJSON_PUBLIC(type) __attribute__((visibility("default"))) type +#if (defined(__GNUC__) || defined(__SUNPRO_CC) || defined(__SUNPRO_C)) && defined(CJSON_API_VISIBILITY) +#define CJSON_PUBLIC(type) __attribute__((visibility("default"))) type #else #define CJSON_PUBLIC(type) type #endif @@ -87,21 +86,20 @@ then using the CJSON_API_VISIBILITY flag to "export" the same symbols the way CJ /* cJSON Types: */ #define cJSON_Invalid (0) -#define cJSON_False (1 << 0) -#define cJSON_True (1 << 1) -#define cJSON_NULL (1 << 2) -#define cJSON_Number (1 << 3) -#define cJSON_String (1 << 4) -#define cJSON_Array (1 << 5) -#define cJSON_Object (1 << 6) -#define cJSON_Raw (1 << 7) /* raw json */ +#define cJSON_False (1 << 0) +#define cJSON_True (1 << 1) +#define cJSON_NULL (1 << 2) +#define cJSON_Number (1 << 3) +#define cJSON_String (1 << 4) +#define cJSON_Array (1 << 5) +#define cJSON_Object (1 << 6) +#define cJSON_Raw (1 << 7) /* raw json */ -#define cJSON_IsReference 256 +#define cJSON_IsReference 256 #define cJSON_StringIsConst 512 /* The cJSON structure: */ -typedef struct cJSON -{ +typedef struct cJSON { /* next/prev allow you to walk array/object chains. Alternatively, use GetArraySize/GetArrayItem/GetObjectItem */ struct cJSON *next; struct cJSON *prev; @@ -122,11 +120,10 @@ typedef struct cJSON char *string; } cJSON; -typedef struct cJSON_Hooks -{ - /* malloc/free are CDECL on Windows regardless of the default calling convention of the compiler, so ensure the hooks allow passing those functions directly. */ - void *(CJSON_CDECL *malloc_fn)(size_t sz); - void (CJSON_CDECL *free_fn)(void *ptr); +typedef struct cJSON_Hooks { + /* malloc/free are CDECL on Windows regardless of the default calling convention of the compiler, so ensure the hooks allow passing those functions directly. */ + void *(CJSON_CDECL *malloc_fn)(size_t sz); + void(CJSON_CDECL *free_fn)(void *ptr); } cJSON_Hooks; typedef int cJSON_bool; @@ -138,10 +135,10 @@ typedef int cJSON_bool; #endif /* returns the version of cJSON as a string */ -CJSON_PUBLIC(const char*) cJSON_Version(void); +CJSON_PUBLIC(const char *) cJSON_Version(void); /* Supply malloc, realloc and free functions to cJSON */ -CJSON_PUBLIC(void) cJSON_InitHooks(cJSON_Hooks* hooks); +CJSON_PUBLIC(void) cJSON_InitHooks(cJSON_Hooks *hooks); /* Memory Management: the caller is always responsible to free the results from all variants of cJSON_Parse (with cJSON_Delete) and cJSON_Print (with stdlib free, cJSON_Hooks.free_fn, or cJSON_free as appropriate). The exception is cJSON_PrintPreallocated, where the caller has full responsibility of the buffer. */ /* Supply a block of JSON, and this returns a cJSON object you can interrogate. */ @@ -149,8 +146,13 @@ CJSON_PUBLIC(cJSON *) cJSON_Parse(const char *value); CJSON_PUBLIC(cJSON *) cJSON_ParseWithLength(const char *value, size_t buffer_length); /* ParseWithOpts allows you to require (and check) that the JSON is null terminated, and to retrieve the pointer to the final byte parsed. */ /* If you supply a ptr in return_parse_end and parsing fails, then return_parse_end will contain a pointer to the error so will match cJSON_GetErrorPtr(). */ -CJSON_PUBLIC(cJSON *) cJSON_ParseWithOpts(const char *value, const char **return_parse_end, cJSON_bool require_null_terminated); -CJSON_PUBLIC(cJSON *) cJSON_ParseWithLengthOpts(const char *value, size_t buffer_length, const char **return_parse_end, cJSON_bool require_null_terminated); +CJSON_PUBLIC(cJSON *) +cJSON_ParseWithOpts(const char *value, const char **return_parse_end, cJSON_bool require_null_terminated); +CJSON_PUBLIC(cJSON *) +cJSON_ParseWithLengthOpts(const char *value, + size_t buffer_length, + const char **return_parse_end, + cJSON_bool require_null_terminated); /* Render a cJSON entity to text for transfer/storage. */ CJSON_PUBLIC(char *) cJSON_Print(const cJSON *item); @@ -160,7 +162,8 @@ CJSON_PUBLIC(char *) cJSON_PrintUnformatted(const cJSON *item); CJSON_PUBLIC(char *) cJSON_PrintBuffered(const cJSON *item, int prebuffer, cJSON_bool fmt); /* Render a cJSON entity to text using a buffer already allocated in memory with given length. Returns 1 on success and 0 on failure. */ /* NOTE: cJSON is not always 100% accurate in estimating how much memory it will use, so to be safe allocate 5 bytes more than you actually need */ -CJSON_PUBLIC(cJSON_bool) cJSON_PrintPreallocated(cJSON *item, char *buffer, const int length, const cJSON_bool format); +CJSON_PUBLIC(cJSON_bool) +cJSON_PrintPreallocated(cJSON *item, char *buffer, const int length, const cJSON_bool format); /* Delete a cJSON entity and all subentities. */ CJSON_PUBLIC(void) cJSON_Delete(cJSON *item); @@ -169,27 +172,27 @@ CJSON_PUBLIC(int) cJSON_GetArraySize(const cJSON *array); /* Retrieve item number "index" from array "array". Returns NULL if unsuccessful. */ CJSON_PUBLIC(cJSON *) cJSON_GetArrayItem(const cJSON *array, int index); /* Get item "string" from object. Case insensitive. */ -CJSON_PUBLIC(cJSON *) cJSON_GetObjectItem(const cJSON * const object, const char * const string); -CJSON_PUBLIC(cJSON *) cJSON_GetObjectItemCaseSensitive(const cJSON * const object, const char * const string); +CJSON_PUBLIC(cJSON *) cJSON_GetObjectItem(const cJSON *const object, const char *const string); +CJSON_PUBLIC(cJSON *) cJSON_GetObjectItemCaseSensitive(const cJSON *const object, const char *const string); CJSON_PUBLIC(cJSON_bool) cJSON_HasObjectItem(const cJSON *object, const char *string); /* For analysing failed parses. This returns a pointer to the parse error. You'll probably need to look a few chars back to make sense of it. Defined when cJSON_Parse() returns 0. 0 when cJSON_Parse() succeeds. */ CJSON_PUBLIC(const char *) cJSON_GetErrorPtr(void); /* Check item type and return its value */ -CJSON_PUBLIC(char *) cJSON_GetStringValue(const cJSON * const item); -CJSON_PUBLIC(double) cJSON_GetNumberValue(const cJSON * const item); +CJSON_PUBLIC(char *) cJSON_GetStringValue(const cJSON *const item); +CJSON_PUBLIC(double) cJSON_GetNumberValue(const cJSON *const item); /* These functions check the type of an item */ -CJSON_PUBLIC(cJSON_bool) cJSON_IsInvalid(const cJSON * const item); -CJSON_PUBLIC(cJSON_bool) cJSON_IsFalse(const cJSON * const item); -CJSON_PUBLIC(cJSON_bool) cJSON_IsTrue(const cJSON * const item); -CJSON_PUBLIC(cJSON_bool) cJSON_IsBool(const cJSON * const item); -CJSON_PUBLIC(cJSON_bool) cJSON_IsNull(const cJSON * const item); -CJSON_PUBLIC(cJSON_bool) cJSON_IsNumber(const cJSON * const item); -CJSON_PUBLIC(cJSON_bool) cJSON_IsString(const cJSON * const item); -CJSON_PUBLIC(cJSON_bool) cJSON_IsArray(const cJSON * const item); -CJSON_PUBLIC(cJSON_bool) cJSON_IsObject(const cJSON * const item); -CJSON_PUBLIC(cJSON_bool) cJSON_IsRaw(const cJSON * const item); +CJSON_PUBLIC(cJSON_bool) cJSON_IsInvalid(const cJSON *const item); +CJSON_PUBLIC(cJSON_bool) cJSON_IsFalse(const cJSON *const item); +CJSON_PUBLIC(cJSON_bool) cJSON_IsTrue(const cJSON *const item); +CJSON_PUBLIC(cJSON_bool) cJSON_IsBool(const cJSON *const item); +CJSON_PUBLIC(cJSON_bool) cJSON_IsNull(const cJSON *const item); +CJSON_PUBLIC(cJSON_bool) cJSON_IsNumber(const cJSON *const item); +CJSON_PUBLIC(cJSON_bool) cJSON_IsString(const cJSON *const item); +CJSON_PUBLIC(cJSON_bool) cJSON_IsArray(const cJSON *const item); +CJSON_PUBLIC(cJSON_bool) cJSON_IsObject(const cJSON *const item); +CJSON_PUBLIC(cJSON_bool) cJSON_IsRaw(const cJSON *const item); /* These calls create a cJSON item of the appropriate type. */ CJSON_PUBLIC(cJSON *) cJSON_CreateNull(void); @@ -230,7 +233,7 @@ CJSON_PUBLIC(cJSON_bool) cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item CJSON_PUBLIC(cJSON_bool) cJSON_AddItemReferenceToObject(cJSON *object, const char *string, cJSON *item); /* Remove/Detach items from Arrays/Objects. */ -CJSON_PUBLIC(cJSON *) cJSON_DetachItemViaPointer(cJSON *parent, cJSON * const item); +CJSON_PUBLIC(cJSON *) cJSON_DetachItemViaPointer(cJSON *parent, cJSON *const item); CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromArray(cJSON *array, int which); CJSON_PUBLIC(void) cJSON_DeleteItemFromArray(cJSON *array, int which); CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromObject(cJSON *object, const char *string); @@ -239,11 +242,12 @@ CJSON_PUBLIC(void) cJSON_DeleteItemFromObject(cJSON *object, const char *string) CJSON_PUBLIC(void) cJSON_DeleteItemFromObjectCaseSensitive(cJSON *object, const char *string); /* Update array items. */ -CJSON_PUBLIC(cJSON_bool) cJSON_InsertItemInArray(cJSON *array, int which, cJSON *newitem); /* Shifts pre-existing items to the right. */ -CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemViaPointer(cJSON * const parent, cJSON * const item, cJSON * replacement); +CJSON_PUBLIC(cJSON_bool) +cJSON_InsertItemInArray(cJSON *array, int which, cJSON *newitem); /* Shifts pre-existing items to the right. */ +CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemViaPointer(cJSON *const parent, cJSON *const item, cJSON *replacement); CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInArray(cJSON *array, int which, cJSON *newitem); -CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInObject(cJSON *object,const char *string,cJSON *newitem); -CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInObjectCaseSensitive(cJSON *object,const char *string,cJSON *newitem); +CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInObject(cJSON *object, const char *string, cJSON *newitem); +CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInObjectCaseSensitive(cJSON *object, const char *string, cJSON *newitem); /* Duplicate a cJSON item */ CJSON_PUBLIC(cJSON *) cJSON_Duplicate(const cJSON *item, cJSON_bool recurse); @@ -252,7 +256,7 @@ CJSON_PUBLIC(cJSON *) cJSON_Duplicate(const cJSON *item, cJSON_bool recurse); * The item->next and ->prev pointers are always zero on return from Duplicate. */ /* Recursively compare two cJSON items for equality. If either a or b is NULL or invalid, they will be considered unequal. * case_sensitive determines if object keys are treated case sensitive (1) or case insensitive (0) */ -CJSON_PUBLIC(cJSON_bool) cJSON_Compare(const cJSON * const a, const cJSON * const b, const cJSON_bool case_sensitive); +CJSON_PUBLIC(cJSON_bool) cJSON_Compare(const cJSON *const a, const cJSON *const b, const cJSON_bool case_sensitive); /* Minify a strings, remove blank characters(such as ' ', '\t', '\r', '\n') from strings. * The input pointer json cannot point to a read-only address area, such as a string constant, @@ -261,26 +265,29 @@ CJSON_PUBLIC(void) cJSON_Minify(char *json); /* Helper functions for creating and adding items to an object at the same time. * They return the added item or NULL on failure. */ -CJSON_PUBLIC(cJSON*) cJSON_AddNullToObject(cJSON * const object, const char * const name); -CJSON_PUBLIC(cJSON*) cJSON_AddTrueToObject(cJSON * const object, const char * const name); -CJSON_PUBLIC(cJSON*) cJSON_AddFalseToObject(cJSON * const object, const char * const name); -CJSON_PUBLIC(cJSON*) cJSON_AddBoolToObject(cJSON * const object, const char * const name, const cJSON_bool boolean); -CJSON_PUBLIC(cJSON*) cJSON_AddNumberToObject(cJSON * const object, const char * const name, const double number); -CJSON_PUBLIC(cJSON*) cJSON_AddStringToObject(cJSON * const object, const char * const name, const char * const string); -CJSON_PUBLIC(cJSON*) cJSON_AddRawToObject(cJSON * const object, const char * const name, const char * const raw); -CJSON_PUBLIC(cJSON*) cJSON_AddObjectToObject(cJSON * const object, const char * const name); -CJSON_PUBLIC(cJSON*) cJSON_AddArrayToObject(cJSON * const object, const char * const name); +CJSON_PUBLIC(cJSON *) cJSON_AddNullToObject(cJSON *const object, const char *const name); +CJSON_PUBLIC(cJSON *) cJSON_AddTrueToObject(cJSON *const object, const char *const name); +CJSON_PUBLIC(cJSON *) cJSON_AddFalseToObject(cJSON *const object, const char *const name); +CJSON_PUBLIC(cJSON *) cJSON_AddBoolToObject(cJSON *const object, const char *const name, const cJSON_bool boolean); +CJSON_PUBLIC(cJSON *) cJSON_AddNumberToObject(cJSON *const object, const char *const name, const double number); +CJSON_PUBLIC(cJSON *) +cJSON_AddStringToObject(cJSON *const object, const char *const name, const char *const string); +CJSON_PUBLIC(cJSON *) cJSON_AddRawToObject(cJSON *const object, const char *const name, const char *const raw); +CJSON_PUBLIC(cJSON *) cJSON_AddObjectToObject(cJSON *const object, const char *const name); +CJSON_PUBLIC(cJSON *) cJSON_AddArrayToObject(cJSON *const object, const char *const name); /* When assigning an integer value, it needs to be propagated to valuedouble too. */ #define cJSON_SetIntValue(object, number) ((object) ? (object)->valueint = (object)->valuedouble = (number) : (number)) /* helper for the cJSON_SetNumberValue macro */ CJSON_PUBLIC(double) cJSON_SetNumberHelper(cJSON *object, double number); -#define cJSON_SetNumberValue(object, number) ((object != NULL) ? cJSON_SetNumberHelper(object, (double)number) : (number)) +#define cJSON_SetNumberValue(object, number) \ + ((object != NULL) ? cJSON_SetNumberHelper(object, (double)number) : (number)) /* Change the valuestring of a cJSON_String object, only takes effect when type of object is cJSON_String */ -CJSON_PUBLIC(char*) cJSON_SetValuestring(cJSON *object, const char *valuestring); +CJSON_PUBLIC(char *) cJSON_SetValuestring(cJSON *object, const char *valuestring); /* Macro for iterating over an array or object */ -#define cJSON_ArrayForEach(element, array) for(element = (array != NULL) ? (array)->child : NULL; element != NULL; element = element->next) +#define cJSON_ArrayForEach(element, array) \ + for (element = (array != NULL) ? (array)->child : NULL; element != NULL; element = element->next) /* malloc/free objects using the malloc/free functions that have been set with cJSON_InitHooks */ CJSON_PUBLIC(void *) cJSON_malloc(size_t size); diff --git a/srcs/libs/include/s2j/s2jdef.h b/srcs/libs/include/s2j/s2jdef.h index a8532f8..8f1f958 100644 --- a/srcs/libs/include/s2j/s2jdef.h +++ b/srcs/libs/include/s2j/s2jdef.h @@ -220,22 +220,14 @@ typedef struct { for (; index_##_element < realsize_##_element && index_##_element < size; index_##_element++) { \ array_item_##_element = cJSON_GetArrayItem(array_##_element, index_##_element); \ if (array_item_##_element) { \ - S2J_STRUCT_ARRAY_GET_ELEMENT_EX(to_struct, \ - array_item_##_element, \ - type, \ - _element, \ - index_##_element, \ - _defval); \ + S2J_STRUCT_ARRAY_GET_ELEMENT_EX( \ + to_struct, array_item_##_element, type, _element, index_##_element, _defval); \ } \ } \ } else { \ for (; index_##_element < realsize_##_element && index_##_element < size; index_##_element++) { \ - S2J_STRUCT_ARRAY_GET_ELEMENT_EX(to_struct, \ - array_##_element, \ - type, \ - _element, \ - index_##_element, \ - _defval); \ + S2J_STRUCT_ARRAY_GET_ELEMENT_EX( \ + to_struct, array_##_element, type, _element, index_##_element, _defval); \ } \ } \ } else { \ diff --git a/srcs/libs/include/sds/alloc.h b/srcs/libs/include/sds/alloc.h index 34a05f4..7b8bd13 100644 --- a/srcs/libs/include/sds/alloc.h +++ b/srcs/libs/include/sds/alloc.h @@ -40,14 +40,14 @@ extern "C" { /* Structure pointing to our actually configured allocators */ typedef struct hiredisAllocFuncs { void *(*mallocFn)(size_t); - void *(*callocFn)(size_t,size_t); - void *(*reallocFn)(void*,size_t); - char *(*strdupFn)(const char*); - void (*freeFn)(void*); + void *(*callocFn)(size_t, size_t); + void *(*reallocFn)(void *, size_t); + char *(*strdupFn)(const char *); + void (*freeFn)(void *); } hiredisAllocFuncs; hiredisAllocFuncs hiredisSetAllocators(hiredisAllocFuncs *ha); -void hiredisResetAllocators(void); +void hiredisResetAllocators(void); #ifndef _WIN32 @@ -80,7 +80,7 @@ void *hi_malloc(size_t size); void *hi_calloc(size_t nmemb, size_t size); void *hi_realloc(void *ptr, size_t size); char *hi_strdup(const char *str); -void hi_free(void *ptr); +void hi_free(void *ptr); #endif diff --git a/srcs/libs/include/sds/sds.h b/srcs/libs/include/sds/sds.h index eda8833..cdd8c63 100644 --- a/srcs/libs/include/sds/sds.h +++ b/srcs/libs/include/sds/sds.h @@ -33,7 +33,7 @@ #ifndef __SDS_H #define __SDS_H -#define SDS_MAX_PREALLOC (1024*1024) +#define SDS_MAX_PREALLOC (1024 * 1024) #ifdef _MSC_VER #define __attribute__(x) typedef long long ssize_t; @@ -48,83 +48,83 @@ typedef char *sds; /* Note: sdshdr5 is never used, we just access the flags byte directly. * However is here to document the layout of type 5 SDS strings. */ -struct __attribute__ ((__packed__)) sdshdr5 { +struct __attribute__((__packed__)) sdshdr5 { unsigned char flags; /* 3 lsb of type, and 5 msb of string length */ - char buf[]; + char buf[]; }; -struct __attribute__ ((__packed__)) sdshdr8 { - uint8_t len; /* used */ - uint8_t alloc; /* excluding the header and null terminator */ +struct __attribute__((__packed__)) sdshdr8 { + uint8_t len; /* used */ + uint8_t alloc; /* excluding the header and null terminator */ unsigned char flags; /* 3 lsb of type, 5 unused bits */ - char buf[]; + char buf[]; }; -struct __attribute__ ((__packed__)) sdshdr16 { - uint16_t len; /* used */ - uint16_t alloc; /* excluding the header and null terminator */ +struct __attribute__((__packed__)) sdshdr16 { + uint16_t len; /* used */ + uint16_t alloc; /* excluding the header and null terminator */ unsigned char flags; /* 3 lsb of type, 5 unused bits */ - char buf[]; + char buf[]; }; -struct __attribute__ ((__packed__)) sdshdr32 { - uint32_t len; /* used */ - uint32_t alloc; /* excluding the header and null terminator */ +struct __attribute__((__packed__)) sdshdr32 { + uint32_t len; /* used */ + uint32_t alloc; /* excluding the header and null terminator */ unsigned char flags; /* 3 lsb of type, 5 unused bits */ - char buf[]; + char buf[]; }; -struct __attribute__ ((__packed__)) sdshdr64 { - uint64_t len; /* used */ - uint64_t alloc; /* excluding the header and null terminator */ +struct __attribute__((__packed__)) sdshdr64 { + uint64_t len; /* used */ + uint64_t alloc; /* excluding the header and null terminator */ unsigned char flags; /* 3 lsb of type, 5 unused bits */ - char buf[]; + char buf[]; }; -#define SDS_TYPE_5 0 -#define SDS_TYPE_8 1 -#define SDS_TYPE_16 2 -#define SDS_TYPE_32 3 -#define SDS_TYPE_64 4 -#define SDS_TYPE_MASK 7 -#define SDS_TYPE_BITS 3 -#define SDS_HDR_VAR(T,s) struct sdshdr##T *sh = (struct sdshdr##T *)((s)-(sizeof(struct sdshdr##T))); -#define SDS_HDR(T,s) ((struct sdshdr##T *)((s)-(sizeof(struct sdshdr##T)))) -#define SDS_TYPE_5_LEN(f) ((f)>>SDS_TYPE_BITS) +#define SDS_TYPE_5 0 +#define SDS_TYPE_8 1 +#define SDS_TYPE_16 2 +#define SDS_TYPE_32 3 +#define SDS_TYPE_64 4 +#define SDS_TYPE_MASK 7 +#define SDS_TYPE_BITS 3 +#define SDS_HDR_VAR(T, s) struct sdshdr##T *sh = (struct sdshdr##T *)((s) - (sizeof(struct sdshdr##T))); +#define SDS_HDR(T, s) ((struct sdshdr##T *)((s) - (sizeof(struct sdshdr##T)))) +#define SDS_TYPE_5_LEN(f) ((f) >> SDS_TYPE_BITS) static inline size_t sdslen(const sds s) { unsigned char flags = s[-1]; - switch(flags&SDS_TYPE_MASK) { + switch (flags & SDS_TYPE_MASK) { case SDS_TYPE_5: return SDS_TYPE_5_LEN(flags); case SDS_TYPE_8: - return SDS_HDR(8,s)->len; + return SDS_HDR(8, s)->len; case SDS_TYPE_16: - return SDS_HDR(16,s)->len; + return SDS_HDR(16, s)->len; case SDS_TYPE_32: - return SDS_HDR(32,s)->len; + return SDS_HDR(32, s)->len; case SDS_TYPE_64: - return SDS_HDR(64,s)->len; + return SDS_HDR(64, s)->len; } return 0; } static inline size_t sdsavail(const sds s) { unsigned char flags = s[-1]; - switch(flags&SDS_TYPE_MASK) { + switch (flags & SDS_TYPE_MASK) { case SDS_TYPE_5: { return 0; } case SDS_TYPE_8: { - SDS_HDR_VAR(8,s); + SDS_HDR_VAR(8, s); return sh->alloc - sh->len; } case SDS_TYPE_16: { - SDS_HDR_VAR(16,s); + SDS_HDR_VAR(16, s); return sh->alloc - sh->len; } case SDS_TYPE_32: { - SDS_HDR_VAR(32,s); + SDS_HDR_VAR(32, s); return sh->alloc - sh->len; } case SDS_TYPE_64: { - SDS_HDR_VAR(64,s); + SDS_HDR_VAR(64, s); return sh->alloc - sh->len; } } @@ -133,49 +133,45 @@ static inline size_t sdsavail(const sds s) { static inline void sdssetlen(sds s, size_t newlen) { unsigned char flags = s[-1]; - switch(flags&SDS_TYPE_MASK) { - case SDS_TYPE_5: - { - unsigned char *fp = ((unsigned char*)s)-1; - *fp = (unsigned char)(SDS_TYPE_5 | (newlen << SDS_TYPE_BITS)); - } - break; + switch (flags & SDS_TYPE_MASK) { + case SDS_TYPE_5: { + unsigned char *fp = ((unsigned char *)s) - 1; + *fp = (unsigned char)(SDS_TYPE_5 | (newlen << SDS_TYPE_BITS)); + } break; case SDS_TYPE_8: - SDS_HDR(8,s)->len = (uint8_t)newlen; + SDS_HDR(8, s)->len = (uint8_t)newlen; break; case SDS_TYPE_16: - SDS_HDR(16,s)->len = (uint16_t)newlen; + SDS_HDR(16, s)->len = (uint16_t)newlen; break; case SDS_TYPE_32: - SDS_HDR(32,s)->len = (uint32_t)newlen; + SDS_HDR(32, s)->len = (uint32_t)newlen; break; case SDS_TYPE_64: - SDS_HDR(64,s)->len = (uint64_t)newlen; + SDS_HDR(64, s)->len = (uint64_t)newlen; break; } } static inline void sdsinclen(sds s, size_t inc) { unsigned char flags = s[-1]; - switch(flags&SDS_TYPE_MASK) { - case SDS_TYPE_5: - { - unsigned char *fp = ((unsigned char*)s)-1; - unsigned char newlen = SDS_TYPE_5_LEN(flags)+(unsigned char)inc; - *fp = SDS_TYPE_5 | (newlen << SDS_TYPE_BITS); - } - break; + switch (flags & SDS_TYPE_MASK) { + case SDS_TYPE_5: { + unsigned char *fp = ((unsigned char *)s) - 1; + unsigned char newlen = SDS_TYPE_5_LEN(flags) + (unsigned char)inc; + *fp = SDS_TYPE_5 | (newlen << SDS_TYPE_BITS); + } break; case SDS_TYPE_8: - SDS_HDR(8,s)->len += (uint8_t)inc; + SDS_HDR(8, s)->len += (uint8_t)inc; break; case SDS_TYPE_16: - SDS_HDR(16,s)->len += (uint16_t)inc; + SDS_HDR(16, s)->len += (uint16_t)inc; break; case SDS_TYPE_32: - SDS_HDR(32,s)->len += (uint32_t)inc; + SDS_HDR(32, s)->len += (uint32_t)inc; break; case SDS_TYPE_64: - SDS_HDR(64,s)->len += (uint64_t)inc; + SDS_HDR(64, s)->len += (uint64_t)inc; break; } } @@ -183,85 +179,84 @@ static inline void sdsinclen(sds s, size_t inc) { /* sdsalloc() = sdsavail() + sdslen() */ static inline size_t sdsalloc(const sds s) { unsigned char flags = s[-1]; - switch(flags&SDS_TYPE_MASK) { + switch (flags & SDS_TYPE_MASK) { case SDS_TYPE_5: return SDS_TYPE_5_LEN(flags); case SDS_TYPE_8: - return SDS_HDR(8,s)->alloc; + return SDS_HDR(8, s)->alloc; case SDS_TYPE_16: - return SDS_HDR(16,s)->alloc; + return SDS_HDR(16, s)->alloc; case SDS_TYPE_32: - return SDS_HDR(32,s)->alloc; + return SDS_HDR(32, s)->alloc; case SDS_TYPE_64: - return SDS_HDR(64,s)->alloc; + return SDS_HDR(64, s)->alloc; } return 0; } static inline void sdssetalloc(sds s, size_t newlen) { unsigned char flags = s[-1]; - switch(flags&SDS_TYPE_MASK) { + switch (flags & SDS_TYPE_MASK) { case SDS_TYPE_5: /* Nothing to do, this type has no total allocation info. */ break; case SDS_TYPE_8: - SDS_HDR(8,s)->alloc = (uint8_t)newlen; + SDS_HDR(8, s)->alloc = (uint8_t)newlen; break; case SDS_TYPE_16: - SDS_HDR(16,s)->alloc = (uint16_t)newlen; + SDS_HDR(16, s)->alloc = (uint16_t)newlen; break; case SDS_TYPE_32: - SDS_HDR(32,s)->alloc = (uint32_t)newlen; + SDS_HDR(32, s)->alloc = (uint32_t)newlen; break; case SDS_TYPE_64: - SDS_HDR(64,s)->alloc = (uint64_t)newlen; + SDS_HDR(64, s)->alloc = (uint64_t)newlen; break; } } -sds sdsnewlen(const void *init, size_t initlen); -sds sdsnew(const char *init); -sds sdsempty(void); -sds sdsdup(const sds s); +sds sdsnewlen(const void *init, size_t initlen); +sds sdsnew(const char *init); +sds sdsempty(void); +sds sdsdup(const sds s); void sdsfree(sds s); -sds sdsgrowzero(sds s, size_t len); -sds sdscatlen(sds s, const void *t, size_t len); -sds sdscat(sds s, const char *t); -sds sdscatsds(sds s, const sds t); -sds sdscpylen(sds s, const char *t, size_t len); -sds sdscpy(sds s, const char *t); +sds sdsgrowzero(sds s, size_t len); +sds sdscatlen(sds s, const void *t, size_t len); +sds sdscat(sds s, const char *t); +sds sdscatsds(sds s, const sds t); +sds sdscpylen(sds s, const char *t, size_t len); +sds sdscpy(sds s, const char *t); sds sdscatvprintf(sds s, const char *fmt, va_list ap); #ifdef __GNUC__ -sds sdscatprintf(sds s, const char *fmt, ...) - __attribute__((format(printf, 2, 3))); +sds sdscatprintf(sds s, const char *fmt, ...) __attribute__((format(printf, 2, 3))); #else sds sdscatprintf(sds s, const char *fmt, ...); #endif -sds sdscatfmt(sds s, char const *fmt, ...); -sds sdstrim(sds s, const char *cset); -int sdsrange(sds s, ssize_t start, ssize_t end); +sds sdscatfmt(sds s, char const *fmt, ...); +sds sdstrim(sds s, const char *cset); +int sdsrange(sds s, ssize_t start, ssize_t end); void sdsupdatelen(sds s); void sdsclear(sds s); -int sdscmp(const sds s1, const sds s2); +int sdscmp(const sds s1, const sds s2); sds *sdssplitlen(const char *s, int len, const char *sep, int seplen, int *count); void sdsfreesplitres(sds *tokens, int count); void sdstolower(sds s); void sdstoupper(sds s); -sds sdsfromlonglong(long long value); -sds sdscatrepr(sds s, const char *p, size_t len); +sds sdsfromlonglong(long long value); +sds sdscatrepr(sds s, const char *p, size_t len); sds *sdssplitargs(const char *line, int *argc); -sds sdsmapchars(sds s, const char *from, const char *to, size_t setlen); -sds sdsjoin(char **argv, int argc, char *sep); -sds sdsjoinsds(sds *argv, int argc, const char *sep, size_t seplen); +sds sdsmapchars(sds s, const char *from, const char *to, size_t setlen); +sds sdsjoin(char **argv, int argc, char *sep); +sds sdsjoinsds(sds *argv, int argc, const char *sep, size_t seplen); /* Low level functions exposed to the user API */ -sds sdsMakeRoomFor(sds s, size_t addlen); -void sdsIncrLen(sds s, int incr); -sds sdsRemoveFreeSpace(sds s); +sds sdsMakeRoomFor(sds s, size_t addlen); +void sdsIncrLen(sds s, int incr); +sds sdsRemoveFreeSpace(sds s); size_t sdsAllocSize(sds s); -void *sdsAllocPtr(sds s); +void *sdsAllocPtr(sds s); /* Export the allocator used by SDS to the program using SDS. * Sometimes the program SDS is linked to, may use a different set of @@ -269,7 +264,7 @@ void *sdsAllocPtr(sds s); * respectively free or allocate. */ void *sds_malloc(size_t size); void *sds_realloc(void *ptr, size_t size); -void sds_free(void *ptr); +void sds_free(void *ptr); #ifdef REDIS_TEST int sdsTest(int argc, char *argv[]); diff --git a/srcs/libs/include/sds/sdsalloc.h b/srcs/libs/include/sds/sdsalloc.h index 5538dd9..53467c2 100644 --- a/srcs/libs/include/sds/sdsalloc.h +++ b/srcs/libs/include/sds/sdsalloc.h @@ -39,6 +39,6 @@ #include "alloc.h" -#define s_malloc hi_malloc +#define s_malloc hi_malloc #define s_realloc hi_realloc -#define s_free hi_free +#define s_free hi_free diff --git a/srcs/libs/include/sqlite3/sqlite3.h b/srcs/libs/include/sqlite3/sqlite3.h index cf1af62..54f7525 100644 --- a/srcs/libs/include/sqlite3/sqlite3.h +++ b/srcs/libs/include/sqlite3/sqlite3.h @@ -32,7 +32,7 @@ */ #ifndef SQLITE3_H #define SQLITE3_H -#include /* Needed for the definition of va_list */ +#include /* Needed for the definition of va_list */ /* ** Make sure we can call this stuff from C++. @@ -41,7 +41,6 @@ extern "C" { #endif - /* ** Facilitate override of interface linkage and calling conventions. ** Be aware that these macros may not be used within this particular @@ -69,25 +68,25 @@ extern "C" { ** that require non-default calling conventions. */ #ifndef SQLITE_EXTERN -# define SQLITE_EXTERN extern +#define SQLITE_EXTERN extern #endif #ifndef SQLITE_API -# define SQLITE_API +#define SQLITE_API #endif #ifndef SQLITE_CDECL -# define SQLITE_CDECL +#define SQLITE_CDECL #endif #ifndef SQLITE_APICALL -# define SQLITE_APICALL +#define SQLITE_APICALL #endif #ifndef SQLITE_STDCALL -# define SQLITE_STDCALL SQLITE_APICALL +#define SQLITE_STDCALL SQLITE_APICALL #endif #ifndef SQLITE_CALLBACK -# define SQLITE_CALLBACK +#define SQLITE_CALLBACK #endif #ifndef SQLITE_SYSAPI -# define SQLITE_SYSAPI +#define SQLITE_SYSAPI #endif /* @@ -110,10 +109,10 @@ extern "C" { ** Ensure these symbols were not defined by some previous header file. */ #ifdef SQLITE_VERSION -# undef SQLITE_VERSION +#undef SQLITE_VERSION #endif #ifdef SQLITE_VERSION_NUMBER -# undef SQLITE_VERSION_NUMBER +#undef SQLITE_VERSION_NUMBER #endif /* @@ -183,9 +182,9 @@ extern "C" { ** See also: [sqlite_version()] and [sqlite_source_id()]. */ SQLITE_API SQLITE_EXTERN const char sqlite3_version[]; -SQLITE_API const char *sqlite3_libversion(void); -SQLITE_API const char *sqlite3_sourceid(void); -SQLITE_API int sqlite3_libversion_number(void); +SQLITE_API const char *sqlite3_libversion(void); +SQLITE_API const char *sqlite3_sourceid(void); +SQLITE_API int sqlite3_libversion_number(void); /* ** CAPI3REF: Run-Time Library Compilation Options Diagnostics @@ -210,11 +209,11 @@ SQLITE_API int sqlite3_libversion_number(void); ** [sqlite_compileoption_get()] and the [compile_options pragma]. */ #ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS -SQLITE_API int sqlite3_compileoption_used(const char *zOptName); +SQLITE_API int sqlite3_compileoption_used(const char *zOptName); SQLITE_API const char *sqlite3_compileoption_get(int N); #else -# define sqlite3_compileoption_used(X) 0 -# define sqlite3_compileoption_get(X) ((void*)0) +#define sqlite3_compileoption_used(X) 0 +#define sqlite3_compileoption_get(X) ((void *)0) #endif /* @@ -288,20 +287,20 @@ typedef struct sqlite3 sqlite3; ** between 0 and +18446744073709551615 inclusive. */ #ifdef SQLITE_INT64_TYPE - typedef SQLITE_INT64_TYPE sqlite_int64; -# ifdef SQLITE_UINT64_TYPE - typedef SQLITE_UINT64_TYPE sqlite_uint64; -# else - typedef unsigned SQLITE_INT64_TYPE sqlite_uint64; -# endif -#elif defined(_MSC_VER) || defined(__BORLANDC__) - typedef __int64 sqlite_int64; - typedef unsigned __int64 sqlite_uint64; +typedef SQLITE_INT64_TYPE sqlite_int64; +#ifdef SQLITE_UINT64_TYPE +typedef SQLITE_UINT64_TYPE sqlite_uint64; #else - typedef long long int sqlite_int64; - typedef unsigned long long int sqlite_uint64; +typedef unsigned SQLITE_INT64_TYPE sqlite_uint64; #endif -typedef sqlite_int64 sqlite3_int64; +#elif defined(_MSC_VER) || defined(__BORLANDC__) +typedef __int64 sqlite_int64; +typedef unsigned __int64 sqlite_uint64; +#else +typedef long long int sqlite_int64; +typedef unsigned long long int sqlite_uint64; +#endif +typedef sqlite_int64 sqlite3_int64; typedef sqlite_uint64 sqlite3_uint64; /* @@ -309,7 +308,7 @@ typedef sqlite_uint64 sqlite3_uint64; ** substitute integer for floating-point. */ #ifdef SQLITE_OMIT_FLOATING_POINT -# define double sqlite3_int64 +#define double sqlite3_int64 #endif /* @@ -350,15 +349,15 @@ typedef sqlite_uint64 sqlite3_uint64; ** ^Calling sqlite3_close() or sqlite3_close_v2() with a NULL pointer ** argument is a harmless no-op. */ -SQLITE_API int sqlite3_close(sqlite3*); -SQLITE_API int sqlite3_close_v2(sqlite3*); +SQLITE_API int sqlite3_close(sqlite3 *); +SQLITE_API int sqlite3_close_v2(sqlite3 *); /* ** The type for a callback function. ** This is legacy and deprecated. It is included for historical ** compatibility and is not documented. */ -typedef int (*sqlite3_callback)(void*,int,char**, char**); +typedef int (*sqlite3_callback)(void *, int, char **, char **); /* ** CAPI3REF: One-Step Query Execution Interface @@ -422,12 +421,11 @@ typedef int (*sqlite3_callback)(void*,int,char**, char**); ** the 2nd parameter of sqlite3_exec() while sqlite3_exec() is running. ** */ -SQLITE_API int sqlite3_exec( - sqlite3*, /* An open sqlitecipher */ - const char *sql, /* SQL to be evaluated */ - int (*callback)(void*,int,char**,char**), /* Callback function */ - void *, /* 1st argument to callback */ - char **errmsg /* Error msg written here */ +SQLITE_API int sqlite3_exec(sqlite3 *, /* An open sqlitecipher */ + const char *sql, /* SQL to be evaluated */ + int (*callback)(void *, int, char **, char **), /* Callback function */ + void *, /* 1st argument to callback */ + char **errmsg /* Error msg written here */ ); /* @@ -441,38 +439,38 @@ SQLITE_API int sqlite3_exec( ** ** See also: [extended result code definitions] */ -#define SQLITE_OK 0 /* Successful result */ +#define SQLITE_OK 0 /* Successful result */ /* beginning-of-error-codes */ -#define SQLITE_ERROR 1 /* Generic error */ -#define SQLITE_INTERNAL 2 /* Internal logic error in SQLite */ -#define SQLITE_PERM 3 /* Access permission denied */ -#define SQLITE_ABORT 4 /* Callback routine requested an abort */ -#define SQLITE_BUSY 5 /* The sqlitecipher file is locked */ -#define SQLITE_LOCKED 6 /* A table in the sqlitecipher is locked */ -#define SQLITE_NOMEM 7 /* A malloc() failed */ -#define SQLITE_READONLY 8 /* Attempt to write a readonly sqlitecipher */ -#define SQLITE_INTERRUPT 9 /* Operation terminated by sqlite3_interrupt()*/ -#define SQLITE_IOERR 10 /* Some kind of disk I/O error occurred */ -#define SQLITE_CORRUPT 11 /* The sqlitecipher disk image is malformed */ -#define SQLITE_NOTFOUND 12 /* Unknown opcode in sqlite3_file_control() */ -#define SQLITE_FULL 13 /* Insertion failed because sqlitecipher is full */ -#define SQLITE_CANTOPEN 14 /* Unable to open the sqlitecipher file */ -#define SQLITE_PROTOCOL 15 /* Database lock protocol error */ -#define SQLITE_EMPTY 16 /* Internal use only */ -#define SQLITE_SCHEMA 17 /* The sqlitecipher schema changed */ -#define SQLITE_TOOBIG 18 /* String or BLOB exceeds size limit */ -#define SQLITE_CONSTRAINT 19 /* Abort due to constraint violation */ -#define SQLITE_MISMATCH 20 /* Data type mismatch */ -#define SQLITE_MISUSE 21 /* Library used incorrectly */ -#define SQLITE_NOLFS 22 /* Uses OS features not supported on host */ -#define SQLITE_AUTH 23 /* Authorization denied */ -#define SQLITE_FORMAT 24 /* Not used */ -#define SQLITE_RANGE 25 /* 2nd parameter to sqlite3_bind out of range */ -#define SQLITE_NOTADB 26 /* File opened that is not a sqlitecipher file */ -#define SQLITE_NOTICE 27 /* Notifications from sqlite3_log() */ -#define SQLITE_WARNING 28 /* Warnings from sqlite3_log() */ -#define SQLITE_ROW 100 /* sqlite3_step() has another row ready */ -#define SQLITE_DONE 101 /* sqlite3_step() has finished executing */ +#define SQLITE_ERROR 1 /* Generic error */ +#define SQLITE_INTERNAL 2 /* Internal logic error in SQLite */ +#define SQLITE_PERM 3 /* Access permission denied */ +#define SQLITE_ABORT 4 /* Callback routine requested an abort */ +#define SQLITE_BUSY 5 /* The sqlitecipher file is locked */ +#define SQLITE_LOCKED 6 /* A table in the sqlitecipher is locked */ +#define SQLITE_NOMEM 7 /* A malloc() failed */ +#define SQLITE_READONLY 8 /* Attempt to write a readonly sqlitecipher */ +#define SQLITE_INTERRUPT 9 /* Operation terminated by sqlite3_interrupt()*/ +#define SQLITE_IOERR 10 /* Some kind of disk I/O error occurred */ +#define SQLITE_CORRUPT 11 /* The sqlitecipher disk image is malformed */ +#define SQLITE_NOTFOUND 12 /* Unknown opcode in sqlite3_file_control() */ +#define SQLITE_FULL 13 /* Insertion failed because sqlitecipher is full */ +#define SQLITE_CANTOPEN 14 /* Unable to open the sqlitecipher file */ +#define SQLITE_PROTOCOL 15 /* Database lock protocol error */ +#define SQLITE_EMPTY 16 /* Internal use only */ +#define SQLITE_SCHEMA 17 /* The sqlitecipher schema changed */ +#define SQLITE_TOOBIG 18 /* String or BLOB exceeds size limit */ +#define SQLITE_CONSTRAINT 19 /* Abort due to constraint violation */ +#define SQLITE_MISMATCH 20 /* Data type mismatch */ +#define SQLITE_MISUSE 21 /* Library used incorrectly */ +#define SQLITE_NOLFS 22 /* Uses OS features not supported on host */ +#define SQLITE_AUTH 23 /* Authorization denied */ +#define SQLITE_FORMAT 24 /* Not used */ +#define SQLITE_RANGE 25 /* 2nd parameter to sqlite3_bind out of range */ +#define SQLITE_NOTADB 26 /* File opened that is not a sqlitecipher file */ +#define SQLITE_NOTICE 27 /* Notifications from sqlite3_log() */ +#define SQLITE_WARNING 28 /* Warnings from sqlite3_log() */ +#define SQLITE_ROW 100 /* sqlite3_step() has another row ready */ +#define SQLITE_DONE 101 /* sqlite3_step() has finished executing */ /* end-of-error-codes */ /* @@ -492,81 +490,81 @@ SQLITE_API int sqlite3_exec( ** the most recent error can be obtained using ** [sqlite3_extended_errcode()]. */ -#define SQLITE_ERROR_MISSING_COLLSEQ (SQLITE_ERROR | (1<<8)) -#define SQLITE_ERROR_RETRY (SQLITE_ERROR | (2<<8)) -#define SQLITE_ERROR_SNAPSHOT (SQLITE_ERROR | (3<<8)) -#define SQLITE_IOERR_READ (SQLITE_IOERR | (1<<8)) -#define SQLITE_IOERR_SHORT_READ (SQLITE_IOERR | (2<<8)) -#define SQLITE_IOERR_WRITE (SQLITE_IOERR | (3<<8)) -#define SQLITE_IOERR_FSYNC (SQLITE_IOERR | (4<<8)) -#define SQLITE_IOERR_DIR_FSYNC (SQLITE_IOERR | (5<<8)) -#define SQLITE_IOERR_TRUNCATE (SQLITE_IOERR | (6<<8)) -#define SQLITE_IOERR_FSTAT (SQLITE_IOERR | (7<<8)) -#define SQLITE_IOERR_UNLOCK (SQLITE_IOERR | (8<<8)) -#define SQLITE_IOERR_RDLOCK (SQLITE_IOERR | (9<<8)) -#define SQLITE_IOERR_DELETE (SQLITE_IOERR | (10<<8)) -#define SQLITE_IOERR_BLOCKED (SQLITE_IOERR | (11<<8)) -#define SQLITE_IOERR_NOMEM (SQLITE_IOERR | (12<<8)) -#define SQLITE_IOERR_ACCESS (SQLITE_IOERR | (13<<8)) -#define SQLITE_IOERR_CHECKRESERVEDLOCK (SQLITE_IOERR | (14<<8)) -#define SQLITE_IOERR_LOCK (SQLITE_IOERR | (15<<8)) -#define SQLITE_IOERR_CLOSE (SQLITE_IOERR | (16<<8)) -#define SQLITE_IOERR_DIR_CLOSE (SQLITE_IOERR | (17<<8)) -#define SQLITE_IOERR_SHMOPEN (SQLITE_IOERR | (18<<8)) -#define SQLITE_IOERR_SHMSIZE (SQLITE_IOERR | (19<<8)) -#define SQLITE_IOERR_SHMLOCK (SQLITE_IOERR | (20<<8)) -#define SQLITE_IOERR_SHMMAP (SQLITE_IOERR | (21<<8)) -#define SQLITE_IOERR_SEEK (SQLITE_IOERR | (22<<8)) -#define SQLITE_IOERR_DELETE_NOENT (SQLITE_IOERR | (23<<8)) -#define SQLITE_IOERR_MMAP (SQLITE_IOERR | (24<<8)) -#define SQLITE_IOERR_GETTEMPPATH (SQLITE_IOERR | (25<<8)) -#define SQLITE_IOERR_CONVPATH (SQLITE_IOERR | (26<<8)) -#define SQLITE_IOERR_VNODE (SQLITE_IOERR | (27<<8)) -#define SQLITE_IOERR_AUTH (SQLITE_IOERR | (28<<8)) -#define SQLITE_IOERR_BEGIN_ATOMIC (SQLITE_IOERR | (29<<8)) -#define SQLITE_IOERR_COMMIT_ATOMIC (SQLITE_IOERR | (30<<8)) -#define SQLITE_IOERR_ROLLBACK_ATOMIC (SQLITE_IOERR | (31<<8)) -#define SQLITE_IOERR_DATA (SQLITE_IOERR | (32<<8)) -#define SQLITE_IOERR_CORRUPTFS (SQLITE_IOERR | (33<<8)) -#define SQLITE_LOCKED_SHAREDCACHE (SQLITE_LOCKED | (1<<8)) -#define SQLITE_LOCKED_VTAB (SQLITE_LOCKED | (2<<8)) -#define SQLITE_BUSY_RECOVERY (SQLITE_BUSY | (1<<8)) -#define SQLITE_BUSY_SNAPSHOT (SQLITE_BUSY | (2<<8)) -#define SQLITE_BUSY_TIMEOUT (SQLITE_BUSY | (3<<8)) -#define SQLITE_CANTOPEN_NOTEMPDIR (SQLITE_CANTOPEN | (1<<8)) -#define SQLITE_CANTOPEN_ISDIR (SQLITE_CANTOPEN | (2<<8)) -#define SQLITE_CANTOPEN_FULLPATH (SQLITE_CANTOPEN | (3<<8)) -#define SQLITE_CANTOPEN_CONVPATH (SQLITE_CANTOPEN | (4<<8)) -#define SQLITE_CANTOPEN_DIRTYWAL (SQLITE_CANTOPEN | (5<<8)) /* Not Used */ -#define SQLITE_CANTOPEN_SYMLINK (SQLITE_CANTOPEN | (6<<8)) -#define SQLITE_CORRUPT_VTAB (SQLITE_CORRUPT | (1<<8)) -#define SQLITE_CORRUPT_SEQUENCE (SQLITE_CORRUPT | (2<<8)) -#define SQLITE_CORRUPT_INDEX (SQLITE_CORRUPT | (3<<8)) -#define SQLITE_READONLY_RECOVERY (SQLITE_READONLY | (1<<8)) -#define SQLITE_READONLY_CANTLOCK (SQLITE_READONLY | (2<<8)) -#define SQLITE_READONLY_ROLLBACK (SQLITE_READONLY | (3<<8)) -#define SQLITE_READONLY_DBMOVED (SQLITE_READONLY | (4<<8)) -#define SQLITE_READONLY_CANTINIT (SQLITE_READONLY | (5<<8)) -#define SQLITE_READONLY_DIRECTORY (SQLITE_READONLY | (6<<8)) -#define SQLITE_ABORT_ROLLBACK (SQLITE_ABORT | (2<<8)) -#define SQLITE_CONSTRAINT_CHECK (SQLITE_CONSTRAINT | (1<<8)) -#define SQLITE_CONSTRAINT_COMMITHOOK (SQLITE_CONSTRAINT | (2<<8)) -#define SQLITE_CONSTRAINT_FOREIGNKEY (SQLITE_CONSTRAINT | (3<<8)) -#define SQLITE_CONSTRAINT_FUNCTION (SQLITE_CONSTRAINT | (4<<8)) -#define SQLITE_CONSTRAINT_NOTNULL (SQLITE_CONSTRAINT | (5<<8)) -#define SQLITE_CONSTRAINT_PRIMARYKEY (SQLITE_CONSTRAINT | (6<<8)) -#define SQLITE_CONSTRAINT_TRIGGER (SQLITE_CONSTRAINT | (7<<8)) -#define SQLITE_CONSTRAINT_UNIQUE (SQLITE_CONSTRAINT | (8<<8)) -#define SQLITE_CONSTRAINT_VTAB (SQLITE_CONSTRAINT | (9<<8)) -#define SQLITE_CONSTRAINT_ROWID (SQLITE_CONSTRAINT |(10<<8)) -#define SQLITE_CONSTRAINT_PINNED (SQLITE_CONSTRAINT |(11<<8)) -#define SQLITE_CONSTRAINT_DATATYPE (SQLITE_CONSTRAINT |(12<<8)) -#define SQLITE_NOTICE_RECOVER_WAL (SQLITE_NOTICE | (1<<8)) -#define SQLITE_NOTICE_RECOVER_ROLLBACK (SQLITE_NOTICE | (2<<8)) -#define SQLITE_WARNING_AUTOINDEX (SQLITE_WARNING | (1<<8)) -#define SQLITE_AUTH_USER (SQLITE_AUTH | (1<<8)) -#define SQLITE_OK_LOAD_PERMANENTLY (SQLITE_OK | (1<<8)) -#define SQLITE_OK_SYMLINK (SQLITE_OK | (2<<8)) /* internal use only */ +#define SQLITE_ERROR_MISSING_COLLSEQ (SQLITE_ERROR | (1 << 8)) +#define SQLITE_ERROR_RETRY (SQLITE_ERROR | (2 << 8)) +#define SQLITE_ERROR_SNAPSHOT (SQLITE_ERROR | (3 << 8)) +#define SQLITE_IOERR_READ (SQLITE_IOERR | (1 << 8)) +#define SQLITE_IOERR_SHORT_READ (SQLITE_IOERR | (2 << 8)) +#define SQLITE_IOERR_WRITE (SQLITE_IOERR | (3 << 8)) +#define SQLITE_IOERR_FSYNC (SQLITE_IOERR | (4 << 8)) +#define SQLITE_IOERR_DIR_FSYNC (SQLITE_IOERR | (5 << 8)) +#define SQLITE_IOERR_TRUNCATE (SQLITE_IOERR | (6 << 8)) +#define SQLITE_IOERR_FSTAT (SQLITE_IOERR | (7 << 8)) +#define SQLITE_IOERR_UNLOCK (SQLITE_IOERR | (8 << 8)) +#define SQLITE_IOERR_RDLOCK (SQLITE_IOERR | (9 << 8)) +#define SQLITE_IOERR_DELETE (SQLITE_IOERR | (10 << 8)) +#define SQLITE_IOERR_BLOCKED (SQLITE_IOERR | (11 << 8)) +#define SQLITE_IOERR_NOMEM (SQLITE_IOERR | (12 << 8)) +#define SQLITE_IOERR_ACCESS (SQLITE_IOERR | (13 << 8)) +#define SQLITE_IOERR_CHECKRESERVEDLOCK (SQLITE_IOERR | (14 << 8)) +#define SQLITE_IOERR_LOCK (SQLITE_IOERR | (15 << 8)) +#define SQLITE_IOERR_CLOSE (SQLITE_IOERR | (16 << 8)) +#define SQLITE_IOERR_DIR_CLOSE (SQLITE_IOERR | (17 << 8)) +#define SQLITE_IOERR_SHMOPEN (SQLITE_IOERR | (18 << 8)) +#define SQLITE_IOERR_SHMSIZE (SQLITE_IOERR | (19 << 8)) +#define SQLITE_IOERR_SHMLOCK (SQLITE_IOERR | (20 << 8)) +#define SQLITE_IOERR_SHMMAP (SQLITE_IOERR | (21 << 8)) +#define SQLITE_IOERR_SEEK (SQLITE_IOERR | (22 << 8)) +#define SQLITE_IOERR_DELETE_NOENT (SQLITE_IOERR | (23 << 8)) +#define SQLITE_IOERR_MMAP (SQLITE_IOERR | (24 << 8)) +#define SQLITE_IOERR_GETTEMPPATH (SQLITE_IOERR | (25 << 8)) +#define SQLITE_IOERR_CONVPATH (SQLITE_IOERR | (26 << 8)) +#define SQLITE_IOERR_VNODE (SQLITE_IOERR | (27 << 8)) +#define SQLITE_IOERR_AUTH (SQLITE_IOERR | (28 << 8)) +#define SQLITE_IOERR_BEGIN_ATOMIC (SQLITE_IOERR | (29 << 8)) +#define SQLITE_IOERR_COMMIT_ATOMIC (SQLITE_IOERR | (30 << 8)) +#define SQLITE_IOERR_ROLLBACK_ATOMIC (SQLITE_IOERR | (31 << 8)) +#define SQLITE_IOERR_DATA (SQLITE_IOERR | (32 << 8)) +#define SQLITE_IOERR_CORRUPTFS (SQLITE_IOERR | (33 << 8)) +#define SQLITE_LOCKED_SHAREDCACHE (SQLITE_LOCKED | (1 << 8)) +#define SQLITE_LOCKED_VTAB (SQLITE_LOCKED | (2 << 8)) +#define SQLITE_BUSY_RECOVERY (SQLITE_BUSY | (1 << 8)) +#define SQLITE_BUSY_SNAPSHOT (SQLITE_BUSY | (2 << 8)) +#define SQLITE_BUSY_TIMEOUT (SQLITE_BUSY | (3 << 8)) +#define SQLITE_CANTOPEN_NOTEMPDIR (SQLITE_CANTOPEN | (1 << 8)) +#define SQLITE_CANTOPEN_ISDIR (SQLITE_CANTOPEN | (2 << 8)) +#define SQLITE_CANTOPEN_FULLPATH (SQLITE_CANTOPEN | (3 << 8)) +#define SQLITE_CANTOPEN_CONVPATH (SQLITE_CANTOPEN | (4 << 8)) +#define SQLITE_CANTOPEN_DIRTYWAL (SQLITE_CANTOPEN | (5 << 8)) /* Not Used */ +#define SQLITE_CANTOPEN_SYMLINK (SQLITE_CANTOPEN | (6 << 8)) +#define SQLITE_CORRUPT_VTAB (SQLITE_CORRUPT | (1 << 8)) +#define SQLITE_CORRUPT_SEQUENCE (SQLITE_CORRUPT | (2 << 8)) +#define SQLITE_CORRUPT_INDEX (SQLITE_CORRUPT | (3 << 8)) +#define SQLITE_READONLY_RECOVERY (SQLITE_READONLY | (1 << 8)) +#define SQLITE_READONLY_CANTLOCK (SQLITE_READONLY | (2 << 8)) +#define SQLITE_READONLY_ROLLBACK (SQLITE_READONLY | (3 << 8)) +#define SQLITE_READONLY_DBMOVED (SQLITE_READONLY | (4 << 8)) +#define SQLITE_READONLY_CANTINIT (SQLITE_READONLY | (5 << 8)) +#define SQLITE_READONLY_DIRECTORY (SQLITE_READONLY | (6 << 8)) +#define SQLITE_ABORT_ROLLBACK (SQLITE_ABORT | (2 << 8)) +#define SQLITE_CONSTRAINT_CHECK (SQLITE_CONSTRAINT | (1 << 8)) +#define SQLITE_CONSTRAINT_COMMITHOOK (SQLITE_CONSTRAINT | (2 << 8)) +#define SQLITE_CONSTRAINT_FOREIGNKEY (SQLITE_CONSTRAINT | (3 << 8)) +#define SQLITE_CONSTRAINT_FUNCTION (SQLITE_CONSTRAINT | (4 << 8)) +#define SQLITE_CONSTRAINT_NOTNULL (SQLITE_CONSTRAINT | (5 << 8)) +#define SQLITE_CONSTRAINT_PRIMARYKEY (SQLITE_CONSTRAINT | (6 << 8)) +#define SQLITE_CONSTRAINT_TRIGGER (SQLITE_CONSTRAINT | (7 << 8)) +#define SQLITE_CONSTRAINT_UNIQUE (SQLITE_CONSTRAINT | (8 << 8)) +#define SQLITE_CONSTRAINT_VTAB (SQLITE_CONSTRAINT | (9 << 8)) +#define SQLITE_CONSTRAINT_ROWID (SQLITE_CONSTRAINT | (10 << 8)) +#define SQLITE_CONSTRAINT_PINNED (SQLITE_CONSTRAINT | (11 << 8)) +#define SQLITE_CONSTRAINT_DATATYPE (SQLITE_CONSTRAINT | (12 << 8)) +#define SQLITE_NOTICE_RECOVER_WAL (SQLITE_NOTICE | (1 << 8)) +#define SQLITE_NOTICE_RECOVER_ROLLBACK (SQLITE_NOTICE | (2 << 8)) +#define SQLITE_WARNING_AUTOINDEX (SQLITE_WARNING | (1 << 8)) +#define SQLITE_AUTH_USER (SQLITE_AUTH | (1 << 8)) +#define SQLITE_OK_LOAD_PERMANENTLY (SQLITE_OK | (1 << 8)) +#define SQLITE_OK_SYMLINK (SQLITE_OK | (2 << 8)) /* internal use only */ /* ** CAPI3REF: Flags For File Open Operations @@ -588,33 +586,32 @@ SQLITE_API int sqlite3_exec( ** [sqlite3_open_v2()] has historically be a no-op and might become an ** error in future versions of SQLite. */ -#define SQLITE_OPEN_READONLY 0x00000001 /* Ok for sqlite3_open_v2() */ -#define SQLITE_OPEN_READWRITE 0x00000002 /* Ok for sqlite3_open_v2() */ -#define SQLITE_OPEN_CREATE 0x00000004 /* Ok for sqlite3_open_v2() */ -#define SQLITE_OPEN_DELETEONCLOSE 0x00000008 /* VFS only */ -#define SQLITE_OPEN_EXCLUSIVE 0x00000010 /* VFS only */ -#define SQLITE_OPEN_AUTOPROXY 0x00000020 /* VFS only */ -#define SQLITE_OPEN_URI 0x00000040 /* Ok for sqlite3_open_v2() */ -#define SQLITE_OPEN_MEMORY 0x00000080 /* Ok for sqlite3_open_v2() */ -#define SQLITE_OPEN_MAIN_DB 0x00000100 /* VFS only */ -#define SQLITE_OPEN_TEMP_DB 0x00000200 /* VFS only */ -#define SQLITE_OPEN_TRANSIENT_DB 0x00000400 /* VFS only */ -#define SQLITE_OPEN_MAIN_JOURNAL 0x00000800 /* VFS only */ -#define SQLITE_OPEN_TEMP_JOURNAL 0x00001000 /* VFS only */ -#define SQLITE_OPEN_SUBJOURNAL 0x00002000 /* VFS only */ -#define SQLITE_OPEN_SUPER_JOURNAL 0x00004000 /* VFS only */ -#define SQLITE_OPEN_NOMUTEX 0x00008000 /* Ok for sqlite3_open_v2() */ -#define SQLITE_OPEN_FULLMUTEX 0x00010000 /* Ok for sqlite3_open_v2() */ -#define SQLITE_OPEN_SHAREDCACHE 0x00020000 /* Ok for sqlite3_open_v2() */ -#define SQLITE_OPEN_PRIVATECACHE 0x00040000 /* Ok for sqlite3_open_v2() */ -#define SQLITE_OPEN_WAL 0x00080000 /* VFS only */ -#define SQLITE_OPEN_NOFOLLOW 0x01000000 /* Ok for sqlite3_open_v2() */ -#define SQLITE_OPEN_EXRESCODE 0x02000000 /* Extended result codes */ +#define SQLITE_OPEN_READONLY 0x00000001 /* Ok for sqlite3_open_v2() */ +#define SQLITE_OPEN_READWRITE 0x00000002 /* Ok for sqlite3_open_v2() */ +#define SQLITE_OPEN_CREATE 0x00000004 /* Ok for sqlite3_open_v2() */ +#define SQLITE_OPEN_DELETEONCLOSE 0x00000008 /* VFS only */ +#define SQLITE_OPEN_EXCLUSIVE 0x00000010 /* VFS only */ +#define SQLITE_OPEN_AUTOPROXY 0x00000020 /* VFS only */ +#define SQLITE_OPEN_URI 0x00000040 /* Ok for sqlite3_open_v2() */ +#define SQLITE_OPEN_MEMORY 0x00000080 /* Ok for sqlite3_open_v2() */ +#define SQLITE_OPEN_MAIN_DB 0x00000100 /* VFS only */ +#define SQLITE_OPEN_TEMP_DB 0x00000200 /* VFS only */ +#define SQLITE_OPEN_TRANSIENT_DB 0x00000400 /* VFS only */ +#define SQLITE_OPEN_MAIN_JOURNAL 0x00000800 /* VFS only */ +#define SQLITE_OPEN_TEMP_JOURNAL 0x00001000 /* VFS only */ +#define SQLITE_OPEN_SUBJOURNAL 0x00002000 /* VFS only */ +#define SQLITE_OPEN_SUPER_JOURNAL 0x00004000 /* VFS only */ +#define SQLITE_OPEN_NOMUTEX 0x00008000 /* Ok for sqlite3_open_v2() */ +#define SQLITE_OPEN_FULLMUTEX 0x00010000 /* Ok for sqlite3_open_v2() */ +#define SQLITE_OPEN_SHAREDCACHE 0x00020000 /* Ok for sqlite3_open_v2() */ +#define SQLITE_OPEN_PRIVATECACHE 0x00040000 /* Ok for sqlite3_open_v2() */ +#define SQLITE_OPEN_WAL 0x00080000 /* VFS only */ +#define SQLITE_OPEN_NOFOLLOW 0x01000000 /* Ok for sqlite3_open_v2() */ +#define SQLITE_OPEN_EXRESCODE 0x02000000 /* Extended result codes */ /* Reserved: 0x00F00000 */ /* Legacy compatibility: */ -#define SQLITE_OPEN_MASTER_JOURNAL 0x00004000 /* VFS only */ - +#define SQLITE_OPEN_MASTER_JOURNAL 0x00004000 /* VFS only */ /* ** CAPI3REF: Device Characteristics @@ -649,21 +646,21 @@ SQLITE_API int sqlite3_exec( ** write operations are bracketed by [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE] and ** [SQLITE_FCNTL_COMMIT_ATOMIC_WRITE]. */ -#define SQLITE_IOCAP_ATOMIC 0x00000001 -#define SQLITE_IOCAP_ATOMIC512 0x00000002 -#define SQLITE_IOCAP_ATOMIC1K 0x00000004 -#define SQLITE_IOCAP_ATOMIC2K 0x00000008 -#define SQLITE_IOCAP_ATOMIC4K 0x00000010 -#define SQLITE_IOCAP_ATOMIC8K 0x00000020 -#define SQLITE_IOCAP_ATOMIC16K 0x00000040 -#define SQLITE_IOCAP_ATOMIC32K 0x00000080 -#define SQLITE_IOCAP_ATOMIC64K 0x00000100 -#define SQLITE_IOCAP_SAFE_APPEND 0x00000200 -#define SQLITE_IOCAP_SEQUENTIAL 0x00000400 -#define SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN 0x00000800 -#define SQLITE_IOCAP_POWERSAFE_OVERWRITE 0x00001000 -#define SQLITE_IOCAP_IMMUTABLE 0x00002000 -#define SQLITE_IOCAP_BATCH_ATOMIC 0x00004000 +#define SQLITE_IOCAP_ATOMIC 0x00000001 +#define SQLITE_IOCAP_ATOMIC512 0x00000002 +#define SQLITE_IOCAP_ATOMIC1K 0x00000004 +#define SQLITE_IOCAP_ATOMIC2K 0x00000008 +#define SQLITE_IOCAP_ATOMIC4K 0x00000010 +#define SQLITE_IOCAP_ATOMIC8K 0x00000020 +#define SQLITE_IOCAP_ATOMIC16K 0x00000040 +#define SQLITE_IOCAP_ATOMIC32K 0x00000080 +#define SQLITE_IOCAP_ATOMIC64K 0x00000100 +#define SQLITE_IOCAP_SAFE_APPEND 0x00000200 +#define SQLITE_IOCAP_SEQUENTIAL 0x00000400 +#define SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN 0x00000800 +#define SQLITE_IOCAP_POWERSAFE_OVERWRITE 0x00001000 +#define SQLITE_IOCAP_IMMUTABLE 0x00002000 +#define SQLITE_IOCAP_BATCH_ATOMIC 0x00004000 /* ** CAPI3REF: File Locking Levels @@ -672,11 +669,11 @@ SQLITE_API int sqlite3_exec( ** argument to calls it makes to the xLock() and xUnlock() methods ** of an [sqlite3_io_methods] object. */ -#define SQLITE_LOCK_NONE 0 -#define SQLITE_LOCK_SHARED 1 -#define SQLITE_LOCK_RESERVED 2 -#define SQLITE_LOCK_PENDING 3 -#define SQLITE_LOCK_EXCLUSIVE 4 +#define SQLITE_LOCK_NONE 0 +#define SQLITE_LOCK_SHARED 1 +#define SQLITE_LOCK_RESERVED 2 +#define SQLITE_LOCK_PENDING 3 +#define SQLITE_LOCK_EXCLUSIVE 4 /* ** CAPI3REF: Synchronization Type Flags @@ -704,9 +701,9 @@ SQLITE_API int sqlite3_exec( ** operating systems natively supported by SQLite, only Mac OSX ** cares about the difference.) */ -#define SQLITE_SYNC_NORMAL 0x00002 -#define SQLITE_SYNC_FULL 0x00003 -#define SQLITE_SYNC_DATAONLY 0x00010 +#define SQLITE_SYNC_NORMAL 0x00002 +#define SQLITE_SYNC_FULL 0x00003 +#define SQLITE_SYNC_DATAONLY 0x00010 /* ** CAPI3REF: OS Interface Open File Handle @@ -721,7 +718,7 @@ SQLITE_API int sqlite3_exec( */ typedef struct sqlite3_file sqlite3_file; struct sqlite3_file { - const struct sqlite3_io_methods *pMethods; /* Methods for an open file */ + const struct sqlite3_io_methods *pMethods; /* Methods for an open file */ }; /* @@ -820,29 +817,29 @@ struct sqlite3_file { */ typedef struct sqlite3_io_methods sqlite3_io_methods; struct sqlite3_io_methods { - int iVersion; - int (*xClose)(sqlite3_file*); - int (*xRead)(sqlite3_file*, void*, int iAmt, sqlite3_int64 iOfst); - int (*xWrite)(sqlite3_file*, const void*, int iAmt, sqlite3_int64 iOfst); - int (*xTruncate)(sqlite3_file*, sqlite3_int64 size); - int (*xSync)(sqlite3_file*, int flags); - int (*xFileSize)(sqlite3_file*, sqlite3_int64 *pSize); - int (*xLock)(sqlite3_file*, int); - int (*xUnlock)(sqlite3_file*, int); - int (*xCheckReservedLock)(sqlite3_file*, int *pResOut); - int (*xFileControl)(sqlite3_file*, int op, void *pArg); - int (*xSectorSize)(sqlite3_file*); - int (*xDeviceCharacteristics)(sqlite3_file*); - /* Methods above are valid for version 1 */ - int (*xShmMap)(sqlite3_file*, int iPg, int pgsz, int, void volatile**); - int (*xShmLock)(sqlite3_file*, int offset, int n, int flags); - void (*xShmBarrier)(sqlite3_file*); - int (*xShmUnmap)(sqlite3_file*, int deleteFlag); - /* Methods above are valid for version 2 */ - int (*xFetch)(sqlite3_file*, sqlite3_int64 iOfst, int iAmt, void **pp); - int (*xUnfetch)(sqlite3_file*, sqlite3_int64 iOfst, void *p); - /* Methods above are valid for version 3 */ - /* Additional methods may be added in future releases */ + int iVersion; + int (*xClose)(sqlite3_file *); + int (*xRead)(sqlite3_file *, void *, int iAmt, sqlite3_int64 iOfst); + int (*xWrite)(sqlite3_file *, const void *, int iAmt, sqlite3_int64 iOfst); + int (*xTruncate)(sqlite3_file *, sqlite3_int64 size); + int (*xSync)(sqlite3_file *, int flags); + int (*xFileSize)(sqlite3_file *, sqlite3_int64 *pSize); + int (*xLock)(sqlite3_file *, int); + int (*xUnlock)(sqlite3_file *, int); + int (*xCheckReservedLock)(sqlite3_file *, int *pResOut); + int (*xFileControl)(sqlite3_file *, int op, void *pArg); + int (*xSectorSize)(sqlite3_file *); + int (*xDeviceCharacteristics)(sqlite3_file *); + /* Methods above are valid for version 1 */ + int (*xShmMap)(sqlite3_file *, int iPg, int pgsz, int, void volatile **); + int (*xShmLock)(sqlite3_file *, int offset, int n, int flags); + void (*xShmBarrier)(sqlite3_file *); + int (*xShmUnmap)(sqlite3_file *, int deleteFlag); + /* Methods above are valid for version 2 */ + int (*xFetch)(sqlite3_file *, sqlite3_int64 iOfst, int iAmt, void **pp); + int (*xUnfetch)(sqlite3_file *, sqlite3_int64 iOfst, void *p); + /* Methods above are valid for version 3 */ + /* Additional methods may be added in future releases */ }; /* @@ -1184,52 +1181,51 @@ struct sqlite3_io_methods { ** Used by the cksmvfs VFS module only. ** */ -#define SQLITE_FCNTL_LOCKSTATE 1 -#define SQLITE_FCNTL_GET_LOCKPROXYFILE 2 -#define SQLITE_FCNTL_SET_LOCKPROXYFILE 3 -#define SQLITE_FCNTL_LAST_ERRNO 4 -#define SQLITE_FCNTL_SIZE_HINT 5 -#define SQLITE_FCNTL_CHUNK_SIZE 6 -#define SQLITE_FCNTL_FILE_POINTER 7 -#define SQLITE_FCNTL_SYNC_OMITTED 8 -#define SQLITE_FCNTL_WIN32_AV_RETRY 9 -#define SQLITE_FCNTL_PERSIST_WAL 10 -#define SQLITE_FCNTL_OVERWRITE 11 -#define SQLITE_FCNTL_VFSNAME 12 -#define SQLITE_FCNTL_POWERSAFE_OVERWRITE 13 -#define SQLITE_FCNTL_PRAGMA 14 -#define SQLITE_FCNTL_BUSYHANDLER 15 -#define SQLITE_FCNTL_TEMPFILENAME 16 -#define SQLITE_FCNTL_MMAP_SIZE 18 -#define SQLITE_FCNTL_TRACE 19 -#define SQLITE_FCNTL_HAS_MOVED 20 -#define SQLITE_FCNTL_SYNC 21 -#define SQLITE_FCNTL_COMMIT_PHASETWO 22 -#define SQLITE_FCNTL_WIN32_SET_HANDLE 23 -#define SQLITE_FCNTL_WAL_BLOCK 24 -#define SQLITE_FCNTL_ZIPVFS 25 -#define SQLITE_FCNTL_RBU 26 -#define SQLITE_FCNTL_VFS_POINTER 27 -#define SQLITE_FCNTL_JOURNAL_POINTER 28 -#define SQLITE_FCNTL_WIN32_GET_HANDLE 29 -#define SQLITE_FCNTL_PDB 30 -#define SQLITE_FCNTL_BEGIN_ATOMIC_WRITE 31 -#define SQLITE_FCNTL_COMMIT_ATOMIC_WRITE 32 -#define SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE 33 -#define SQLITE_FCNTL_LOCK_TIMEOUT 34 -#define SQLITE_FCNTL_DATA_VERSION 35 -#define SQLITE_FCNTL_SIZE_LIMIT 36 -#define SQLITE_FCNTL_CKPT_DONE 37 -#define SQLITE_FCNTL_RESERVE_BYTES 38 -#define SQLITE_FCNTL_CKPT_START 39 -#define SQLITE_FCNTL_EXTERNAL_READER 40 -#define SQLITE_FCNTL_CKSM_FILE 41 +#define SQLITE_FCNTL_LOCKSTATE 1 +#define SQLITE_FCNTL_GET_LOCKPROXYFILE 2 +#define SQLITE_FCNTL_SET_LOCKPROXYFILE 3 +#define SQLITE_FCNTL_LAST_ERRNO 4 +#define SQLITE_FCNTL_SIZE_HINT 5 +#define SQLITE_FCNTL_CHUNK_SIZE 6 +#define SQLITE_FCNTL_FILE_POINTER 7 +#define SQLITE_FCNTL_SYNC_OMITTED 8 +#define SQLITE_FCNTL_WIN32_AV_RETRY 9 +#define SQLITE_FCNTL_PERSIST_WAL 10 +#define SQLITE_FCNTL_OVERWRITE 11 +#define SQLITE_FCNTL_VFSNAME 12 +#define SQLITE_FCNTL_POWERSAFE_OVERWRITE 13 +#define SQLITE_FCNTL_PRAGMA 14 +#define SQLITE_FCNTL_BUSYHANDLER 15 +#define SQLITE_FCNTL_TEMPFILENAME 16 +#define SQLITE_FCNTL_MMAP_SIZE 18 +#define SQLITE_FCNTL_TRACE 19 +#define SQLITE_FCNTL_HAS_MOVED 20 +#define SQLITE_FCNTL_SYNC 21 +#define SQLITE_FCNTL_COMMIT_PHASETWO 22 +#define SQLITE_FCNTL_WIN32_SET_HANDLE 23 +#define SQLITE_FCNTL_WAL_BLOCK 24 +#define SQLITE_FCNTL_ZIPVFS 25 +#define SQLITE_FCNTL_RBU 26 +#define SQLITE_FCNTL_VFS_POINTER 27 +#define SQLITE_FCNTL_JOURNAL_POINTER 28 +#define SQLITE_FCNTL_WIN32_GET_HANDLE 29 +#define SQLITE_FCNTL_PDB 30 +#define SQLITE_FCNTL_BEGIN_ATOMIC_WRITE 31 +#define SQLITE_FCNTL_COMMIT_ATOMIC_WRITE 32 +#define SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE 33 +#define SQLITE_FCNTL_LOCK_TIMEOUT 34 +#define SQLITE_FCNTL_DATA_VERSION 35 +#define SQLITE_FCNTL_SIZE_LIMIT 36 +#define SQLITE_FCNTL_CKPT_DONE 37 +#define SQLITE_FCNTL_RESERVE_BYTES 38 +#define SQLITE_FCNTL_CKPT_START 39 +#define SQLITE_FCNTL_EXTERNAL_READER 40 +#define SQLITE_FCNTL_CKSM_FILE 41 /* deprecated names */ -#define SQLITE_GET_LOCKPROXYFILE SQLITE_FCNTL_GET_LOCKPROXYFILE -#define SQLITE_SET_LOCKPROXYFILE SQLITE_FCNTL_SET_LOCKPROXYFILE -#define SQLITE_LAST_ERRNO SQLITE_FCNTL_LAST_ERRNO - +#define SQLITE_GET_LOCKPROXYFILE SQLITE_FCNTL_GET_LOCKPROXYFILE +#define SQLITE_SET_LOCKPROXYFILE SQLITE_FCNTL_SET_LOCKPROXYFILE +#define SQLITE_LAST_ERRNO SQLITE_FCNTL_LAST_ERRNO /* ** CAPI3REF: Mutex Handle @@ -1425,38 +1421,37 @@ typedef struct sqlite3_api_routines sqlite3_api_routines; typedef struct sqlite3_vfs sqlite3_vfs; typedef void (*sqlite3_syscall_ptr)(void); struct sqlite3_vfs { - int iVersion; /* Structure version number (currently 3) */ - int szOsFile; /* Size of subclassed sqlite3_file */ - int mxPathname; /* Maximum file pathname length */ - sqlite3_vfs *pNext; /* Next registered VFS */ - const char *zName; /* Name of this virtual file system */ - void *pAppData; /* Pointer to application-specific data */ - int (*xOpen)(sqlite3_vfs*, const char *zName, sqlite3_file*, - int flags, int *pOutFlags); - int (*xDelete)(sqlite3_vfs*, const char *zName, int syncDir); - int (*xAccess)(sqlite3_vfs*, const char *zName, int flags, int *pResOut); - int (*xFullPathname)(sqlite3_vfs*, const char *zName, int nOut, char *zOut); - void *(*xDlOpen)(sqlite3_vfs*, const char *zFilename); - void (*xDlError)(sqlite3_vfs*, int nByte, char *zErrMsg); - void (*(*xDlSym)(sqlite3_vfs*,void*, const char *zSymbol))(void); - void (*xDlClose)(sqlite3_vfs*, void*); - int (*xRandomness)(sqlite3_vfs*, int nByte, char *zOut); - int (*xSleep)(sqlite3_vfs*, int microseconds); - int (*xCurrentTime)(sqlite3_vfs*, double*); - int (*xGetLastError)(sqlite3_vfs*, int, char *); - /* + int iVersion; /* Structure version number (currently 3) */ + int szOsFile; /* Size of subclassed sqlite3_file */ + int mxPathname; /* Maximum file pathname length */ + sqlite3_vfs *pNext; /* Next registered VFS */ + const char *zName; /* Name of this virtual file system */ + void *pAppData; /* Pointer to application-specific data */ + int (*xOpen)(sqlite3_vfs *, const char *zName, sqlite3_file *, int flags, int *pOutFlags); + int (*xDelete)(sqlite3_vfs *, const char *zName, int syncDir); + int (*xAccess)(sqlite3_vfs *, const char *zName, int flags, int *pResOut); + int (*xFullPathname)(sqlite3_vfs *, const char *zName, int nOut, char *zOut); + void *(*xDlOpen)(sqlite3_vfs *, const char *zFilename); + void (*xDlError)(sqlite3_vfs *, int nByte, char *zErrMsg); + void (*(*xDlSym)(sqlite3_vfs *, void *, const char *zSymbol))(void); + void (*xDlClose)(sqlite3_vfs *, void *); + int (*xRandomness)(sqlite3_vfs *, int nByte, char *zOut); + int (*xSleep)(sqlite3_vfs *, int microseconds); + int (*xCurrentTime)(sqlite3_vfs *, double *); + int (*xGetLastError)(sqlite3_vfs *, int, char *); + /* ** The methods above are in version 1 of the sqlite_vfs object ** definition. Those that follow are added in version 2 or later */ - int (*xCurrentTimeInt64)(sqlite3_vfs*, sqlite3_int64*); - /* + int (*xCurrentTimeInt64)(sqlite3_vfs *, sqlite3_int64 *); + /* ** The methods above are in versions 1 and 2 of the sqlite_vfs object. ** Those below are for version 3 and greater. */ - int (*xSetSystemCall)(sqlite3_vfs*, const char *zName, sqlite3_syscall_ptr); - sqlite3_syscall_ptr (*xGetSystemCall)(sqlite3_vfs*, const char *zName); - const char *(*xNextSystemCall)(sqlite3_vfs*, const char *zName); - /* + int (*xSetSystemCall)(sqlite3_vfs *, const char *zName, sqlite3_syscall_ptr); + sqlite3_syscall_ptr (*xGetSystemCall)(sqlite3_vfs *, const char *zName); + const char *(*xNextSystemCall)(sqlite3_vfs *, const char *zName); + /* ** The methods above are in versions 1 through 3 of the sqlite_vfs object. ** New fields may be appended in future versions. The iVersion ** value will increment whenever this happens. @@ -1484,8 +1479,8 @@ struct sqlite3_vfs { ** SQLite. */ #define SQLITE_ACCESS_EXISTS 0 -#define SQLITE_ACCESS_READWRITE 1 /* Used by PRAGMA temp_store_directory */ -#define SQLITE_ACCESS_READ 2 /* Unused */ +#define SQLITE_ACCESS_READWRITE 1 /* Used by PRAGMA temp_store_directory */ +#define SQLITE_ACCESS_READ 2 /* Unused */ /* ** CAPI3REF: Flags for the xShmLock VFS method @@ -1509,10 +1504,10 @@ struct sqlite3_vfs { ** between unlocked and EXCLUSIVE. It cannot transition between SHARED ** and EXCLUSIVE. */ -#define SQLITE_SHM_UNLOCK 1 -#define SQLITE_SHM_LOCK 2 -#define SQLITE_SHM_SHARED 4 -#define SQLITE_SHM_EXCLUSIVE 8 +#define SQLITE_SHM_UNLOCK 1 +#define SQLITE_SHM_LOCK 2 +#define SQLITE_SHM_SHARED 4 +#define SQLITE_SHM_EXCLUSIVE 8 /* ** CAPI3REF: Maximum xShmLock index @@ -1522,8 +1517,7 @@ struct sqlite3_vfs { ** The SQLite core will never attempt to acquire or release a ** lock outside of this range */ -#define SQLITE_SHM_NLOCK 8 - +#define SQLITE_SHM_NLOCK 8 /* ** CAPI3REF: Initialize The SQLite Library @@ -1655,7 +1649,7 @@ SQLITE_API int sqlite3_config(int, ...); ** ^Calls to sqlite3_db_config() return SQLITE_OK if and only if ** the call is considered successful. */ -SQLITE_API int sqlite3_db_config(sqlite3*, int op, ...); +SQLITE_API int sqlite3_db_config(sqlite3 *, int op, ...); /* ** CAPI3REF: Memory Allocation Routines @@ -1722,14 +1716,14 @@ SQLITE_API int sqlite3_db_config(sqlite3*, int op, ...); */ typedef struct sqlite3_mem_methods sqlite3_mem_methods; struct sqlite3_mem_methods { - void *(*xMalloc)(int); /* Memory allocation function */ - void (*xFree)(void*); /* Free a prior allocation */ - void *(*xRealloc)(void*,int); /* Resize an allocation */ - int (*xSize)(void*); /* Return the size of an allocation */ - int (*xRoundup)(int); /* Round up request size to allocation size */ - int (*xInit)(void*); /* Initialize the memory allocator */ - void (*xShutdown)(void*); /* Deinitialize the memory allocator */ - void *pAppData; /* Argument to xInit() and xShutdown() */ + void *(*xMalloc)(int); /* Memory allocation function */ + void (*xFree)(void *); /* Free a prior allocation */ + void *(*xRealloc)(void *, int); /* Resize an allocation */ + int (*xSize)(void *); /* Return the size of an allocation */ + int (*xRoundup)(int); /* Round up request size to allocation size */ + int (*xInit)(void *); /* Initialize the memory allocator */ + void (*xShutdown)(void *); /* Deinitialize the memory allocator */ + void *pAppData; /* Argument to xInit() and xShutdown() */ }; /* @@ -2085,35 +2079,35 @@ struct sqlite3_mem_methods { ** compile-time option is not set, then the default maximum is 1073741824. ** */ -#define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */ -#define SQLITE_CONFIG_MULTITHREAD 2 /* nil */ -#define SQLITE_CONFIG_SERIALIZED 3 /* nil */ -#define SQLITE_CONFIG_MALLOC 4 /* sqlite3_mem_methods* */ -#define SQLITE_CONFIG_GETMALLOC 5 /* sqlite3_mem_methods* */ -#define SQLITE_CONFIG_SCRATCH 6 /* No longer used */ -#define SQLITE_CONFIG_PAGECACHE 7 /* void*, int sz, int N */ -#define SQLITE_CONFIG_HEAP 8 /* void*, int nByte, int min */ -#define SQLITE_CONFIG_MEMSTATUS 9 /* boolean */ -#define SQLITE_CONFIG_MUTEX 10 /* sqlite3_mutex_methods* */ -#define SQLITE_CONFIG_GETMUTEX 11 /* sqlite3_mutex_methods* */ +#define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */ +#define SQLITE_CONFIG_MULTITHREAD 2 /* nil */ +#define SQLITE_CONFIG_SERIALIZED 3 /* nil */ +#define SQLITE_CONFIG_MALLOC 4 /* sqlite3_mem_methods* */ +#define SQLITE_CONFIG_GETMALLOC 5 /* sqlite3_mem_methods* */ +#define SQLITE_CONFIG_SCRATCH 6 /* No longer used */ +#define SQLITE_CONFIG_PAGECACHE 7 /* void*, int sz, int N */ +#define SQLITE_CONFIG_HEAP 8 /* void*, int nByte, int min */ +#define SQLITE_CONFIG_MEMSTATUS 9 /* boolean */ +#define SQLITE_CONFIG_MUTEX 10 /* sqlite3_mutex_methods* */ +#define SQLITE_CONFIG_GETMUTEX 11 /* sqlite3_mutex_methods* */ /* previously SQLITE_CONFIG_CHUNKALLOC 12 which is now unused. */ -#define SQLITE_CONFIG_LOOKASIDE 13 /* int int */ -#define SQLITE_CONFIG_PCACHE 14 /* no-op */ -#define SQLITE_CONFIG_GETPCACHE 15 /* no-op */ -#define SQLITE_CONFIG_LOG 16 /* xFunc, void* */ -#define SQLITE_CONFIG_URI 17 /* int */ -#define SQLITE_CONFIG_PCACHE2 18 /* sqlite3_pcache_methods2* */ -#define SQLITE_CONFIG_GETPCACHE2 19 /* sqlite3_pcache_methods2* */ -#define SQLITE_CONFIG_COVERING_INDEX_SCAN 20 /* int */ -#define SQLITE_CONFIG_SQLLOG 21 /* xSqllog, void* */ -#define SQLITE_CONFIG_MMAP_SIZE 22 /* sqlite3_int64, sqlite3_int64 */ -#define SQLITE_CONFIG_WIN32_HEAPSIZE 23 /* int nByte */ -#define SQLITE_CONFIG_PCACHE_HDRSZ 24 /* int *psz */ -#define SQLITE_CONFIG_PMASZ 25 /* unsigned int szPma */ -#define SQLITE_CONFIG_STMTJRNL_SPILL 26 /* int nByte */ -#define SQLITE_CONFIG_SMALL_MALLOC 27 /* boolean */ -#define SQLITE_CONFIG_SORTERREF_SIZE 28 /* int nByte */ -#define SQLITE_CONFIG_MEMDB_MAXSIZE 29 /* sqlite3_int64 */ +#define SQLITE_CONFIG_LOOKASIDE 13 /* int int */ +#define SQLITE_CONFIG_PCACHE 14 /* no-op */ +#define SQLITE_CONFIG_GETPCACHE 15 /* no-op */ +#define SQLITE_CONFIG_LOG 16 /* xFunc, void* */ +#define SQLITE_CONFIG_URI 17 /* int */ +#define SQLITE_CONFIG_PCACHE2 18 /* sqlite3_pcache_methods2* */ +#define SQLITE_CONFIG_GETPCACHE2 19 /* sqlite3_pcache_methods2* */ +#define SQLITE_CONFIG_COVERING_INDEX_SCAN 20 /* int */ +#define SQLITE_CONFIG_SQLLOG 21 /* xSqllog, void* */ +#define SQLITE_CONFIG_MMAP_SIZE 22 /* sqlite3_int64, sqlite3_int64 */ +#define SQLITE_CONFIG_WIN32_HEAPSIZE 23 /* int nByte */ +#define SQLITE_CONFIG_PCACHE_HDRSZ 24 /* int *psz */ +#define SQLITE_CONFIG_PMASZ 25 /* unsigned int szPma */ +#define SQLITE_CONFIG_STMTJRNL_SPILL 26 /* int nByte */ +#define SQLITE_CONFIG_SMALL_MALLOC 27 /* boolean */ +#define SQLITE_CONFIG_SORTERREF_SIZE 28 /* int nByte */ +#define SQLITE_CONFIG_MEMDB_MAXSIZE 29 /* sqlite3_int64 */ /* ** CAPI3REF: Database Connection Configuration Options @@ -2424,7 +2418,7 @@ struct sqlite3_mem_methods { ** [extended result codes] feature of SQLite. ^The extended result ** codes are disabled by default for historical compatibility. */ -SQLITE_API int sqlite3_extended_result_codes(sqlite3*, int onoff); +SQLITE_API int sqlite3_extended_result_codes(sqlite3 *, int onoff); /* ** CAPI3REF: Last Insert Rowid @@ -2486,7 +2480,7 @@ SQLITE_API int sqlite3_extended_result_codes(sqlite3*, int onoff); ** unpredictable and might not equal either the old or the new ** last insert [rowid]. */ -SQLITE_API sqlite3_int64 sqlite3_last_insert_rowid(sqlite3*); +SQLITE_API sqlite3_int64 sqlite3_last_insert_rowid(sqlite3 *); /* ** CAPI3REF: Set the Last Insert Rowid value. @@ -2496,7 +2490,7 @@ SQLITE_API sqlite3_int64 sqlite3_last_insert_rowid(sqlite3*); ** set the value returned by calling sqlite3_last_insert_rowid(D) to R ** without inserting a row into the sqlitecipher. */ -SQLITE_API void sqlite3_set_last_insert_rowid(sqlite3*,sqlite3_int64); +SQLITE_API void sqlite3_set_last_insert_rowid(sqlite3 *, sqlite3_int64); /* ** CAPI3REF: Count The Number Of Rows Modified @@ -2557,8 +2551,8 @@ SQLITE_API void sqlite3_set_last_insert_rowid(sqlite3*,sqlite3_int64); **
  • the [data_version pragma] ** */ -SQLITE_API int sqlite3_changes(sqlite3*); -SQLITE_API sqlite3_int64 sqlite3_changes64(sqlite3*); +SQLITE_API int sqlite3_changes(sqlite3 *); +SQLITE_API sqlite3_int64 sqlite3_changes64(sqlite3 *); /* ** CAPI3REF: Total Number Of Rows Modified @@ -2599,8 +2593,8 @@ SQLITE_API sqlite3_int64 sqlite3_changes64(sqlite3*); **
  • the [SQLITE_FCNTL_DATA_VERSION] [file control] ** */ -SQLITE_API int sqlite3_total_changes(sqlite3*); -SQLITE_API sqlite3_int64 sqlite3_total_changes64(sqlite3*); +SQLITE_API int sqlite3_total_changes(sqlite3 *); +SQLITE_API sqlite3_int64 sqlite3_total_changes64(sqlite3 *); /* ** CAPI3REF: Interrupt A Long-Running Query @@ -2637,7 +2631,7 @@ SQLITE_API sqlite3_int64 sqlite3_total_changes64(sqlite3*); ** SQL statements is a no-op and has no effect on SQL statements ** that are started after the sqlite3_interrupt() call returns. */ -SQLITE_API void sqlite3_interrupt(sqlite3*); +SQLITE_API void sqlite3_interrupt(sqlite3 *); /* ** CAPI3REF: Determine If An SQL Statement Is Complete @@ -2734,7 +2728,7 @@ SQLITE_API int sqlite3_complete16(const void *sql); ** A busy handler must not close the sqlitecipher connection ** or [prepared statement] that invoked the busy handler. */ -SQLITE_API int sqlite3_busy_handler(sqlite3*,int(*)(void*,int),void*); +SQLITE_API int sqlite3_busy_handler(sqlite3 *, int (*)(void *, int), void *); /* ** CAPI3REF: Set A Busy Timeout @@ -2757,7 +2751,7 @@ SQLITE_API int sqlite3_busy_handler(sqlite3*,int(*)(void*,int),void*); ** ** See also: [PRAGMA busy_timeout] */ -SQLITE_API int sqlite3_busy_timeout(sqlite3*, int ms); +SQLITE_API int sqlite3_busy_timeout(sqlite3 *, int ms); /* ** CAPI3REF: Convenience Routines For Running Queries @@ -2832,14 +2826,13 @@ SQLITE_API int sqlite3_busy_timeout(sqlite3*, int ms); ** reflected in subsequent calls to [sqlite3_errcode()] or ** [sqlite3_errmsg()]. */ -SQLITE_API int sqlite3_get_table( - sqlite3 *db, /* An open sqlitecipher */ - const char *zSql, /* SQL to be evaluated */ - char ***pazResult, /* Results of the query */ - int *pnRow, /* Number of result rows written here */ - int *pnColumn, /* Number of result columns written here */ - char **pzErrmsg /* Error msg written here */ -); +SQLITE_API int sqlite3_get_table(sqlite3 *db, /* An open sqlitecipher */ + const char *zSql, /* SQL to be evaluated */ + char ***pazResult, /* Results of the query */ + int *pnRow, /* Number of result rows written here */ + int *pnColumn, /* Number of result columns written here */ + char **pzErrmsg /* Error msg written here */ + ); SQLITE_API void sqlite3_free_table(char **result); /* @@ -2882,10 +2875,10 @@ SQLITE_API void sqlite3_free_table(char **result); ** ** See also: [built-in printf()], [printf() SQL function] */ -SQLITE_API char *sqlite3_mprintf(const char*,...); -SQLITE_API char *sqlite3_vmprintf(const char*, va_list); -SQLITE_API char *sqlite3_snprintf(int,char*,const char*, ...); -SQLITE_API char *sqlite3_vsnprintf(int,char*,const char*, va_list); +SQLITE_API char *sqlite3_mprintf(const char *, ...); +SQLITE_API char *sqlite3_vmprintf(const char *, va_list); +SQLITE_API char *sqlite3_snprintf(int, char *, const char *, ...); +SQLITE_API char *sqlite3_vsnprintf(int, char *, const char *, va_list); /* ** CAPI3REF: Memory Allocation Subsystem @@ -2962,12 +2955,12 @@ SQLITE_API char *sqlite3_vsnprintf(int,char*,const char*, va_list); ** a block of memory after it has been released using ** [sqlite3_free()] or [sqlite3_realloc()]. */ -SQLITE_API void *sqlite3_malloc(int); -SQLITE_API void *sqlite3_malloc64(sqlite3_uint64); -SQLITE_API void *sqlite3_realloc(void*, int); -SQLITE_API void *sqlite3_realloc64(void*, sqlite3_uint64); -SQLITE_API void sqlite3_free(void*); -SQLITE_API sqlite3_uint64 sqlite3_msize(void*); +SQLITE_API void *sqlite3_malloc(int); +SQLITE_API void *sqlite3_malloc64(sqlite3_uint64); +SQLITE_API void *sqlite3_realloc(void *, int); +SQLITE_API void *sqlite3_realloc64(void *, sqlite3_uint64); +SQLITE_API void sqlite3_free(void *); +SQLITE_API sqlite3_uint64 sqlite3_msize(void *); /* ** CAPI3REF: Memory Allocator Statistics @@ -3107,11 +3100,9 @@ SQLITE_API void sqlite3_randomness(int N, void *P); ** as stated in the previous paragraph, sqlite3_step() invokes ** sqlite3_prepare_v2() to reprepare a statement after a schema change. */ -SQLITE_API int sqlite3_set_authorizer( - sqlite3*, - int (*xAuth)(void*,int,const char*,const char*,const char*,const char*), - void *pUserData -); +SQLITE_API int sqlite3_set_authorizer(sqlite3 *, + int (*xAuth)(void *, int, const char *, const char *, const char *, const char *), + void *pUserData); /* ** CAPI3REF: Authorizer Return Codes @@ -3125,8 +3116,8 @@ SQLITE_API int sqlite3_set_authorizer( ** Note that SQLITE_IGNORE is also used as a [conflict resolution mode] ** returned from the [sqlite3_vtab_on_conflict()] interface. */ -#define SQLITE_DENY 1 /* Abort the SQL statement with an error */ -#define SQLITE_IGNORE 2 /* Don't allow access, but don't generate an error */ +#define SQLITE_DENY 1 /* Abort the SQL statement with an error */ +#define SQLITE_IGNORE 2 /* Don't allow access, but don't generate an error */ /* ** CAPI3REF: Authorizer Action Codes @@ -3148,40 +3139,40 @@ SQLITE_API int sqlite3_set_authorizer( ** top-level SQL code. */ /******************************************* 3rd ************ 4th ***********/ -#define SQLITE_CREATE_INDEX 1 /* Index Name Table Name */ -#define SQLITE_CREATE_TABLE 2 /* Table Name NULL */ -#define SQLITE_CREATE_TEMP_INDEX 3 /* Index Name Table Name */ -#define SQLITE_CREATE_TEMP_TABLE 4 /* Table Name NULL */ -#define SQLITE_CREATE_TEMP_TRIGGER 5 /* Trigger Name Table Name */ -#define SQLITE_CREATE_TEMP_VIEW 6 /* View Name NULL */ -#define SQLITE_CREATE_TRIGGER 7 /* Trigger Name Table Name */ -#define SQLITE_CREATE_VIEW 8 /* View Name NULL */ -#define SQLITE_DELETE 9 /* Table Name NULL */ -#define SQLITE_DROP_INDEX 10 /* Index Name Table Name */ -#define SQLITE_DROP_TABLE 11 /* Table Name NULL */ -#define SQLITE_DROP_TEMP_INDEX 12 /* Index Name Table Name */ -#define SQLITE_DROP_TEMP_TABLE 13 /* Table Name NULL */ -#define SQLITE_DROP_TEMP_TRIGGER 14 /* Trigger Name Table Name */ -#define SQLITE_DROP_TEMP_VIEW 15 /* View Name NULL */ -#define SQLITE_DROP_TRIGGER 16 /* Trigger Name Table Name */ -#define SQLITE_DROP_VIEW 17 /* View Name NULL */ -#define SQLITE_INSERT 18 /* Table Name NULL */ -#define SQLITE_PRAGMA 19 /* Pragma Name 1st arg or NULL */ -#define SQLITE_READ 20 /* Table Name Column Name */ -#define SQLITE_SELECT 21 /* NULL NULL */ -#define SQLITE_TRANSACTION 22 /* Operation NULL */ -#define SQLITE_UPDATE 23 /* Table Name Column Name */ -#define SQLITE_ATTACH 24 /* Filename NULL */ -#define SQLITE_DETACH 25 /* Database Name NULL */ -#define SQLITE_ALTER_TABLE 26 /* Database Name Table Name */ -#define SQLITE_REINDEX 27 /* Index Name NULL */ -#define SQLITE_ANALYZE 28 /* Table Name NULL */ -#define SQLITE_CREATE_VTABLE 29 /* Table Name Module Name */ -#define SQLITE_DROP_VTABLE 30 /* Table Name Module Name */ -#define SQLITE_FUNCTION 31 /* NULL Function Name */ -#define SQLITE_SAVEPOINT 32 /* Operation Savepoint Name */ -#define SQLITE_COPY 0 /* No longer used */ -#define SQLITE_RECURSIVE 33 /* NULL NULL */ +#define SQLITE_CREATE_INDEX 1 /* Index Name Table Name */ +#define SQLITE_CREATE_TABLE 2 /* Table Name NULL */ +#define SQLITE_CREATE_TEMP_INDEX 3 /* Index Name Table Name */ +#define SQLITE_CREATE_TEMP_TABLE 4 /* Table Name NULL */ +#define SQLITE_CREATE_TEMP_TRIGGER 5 /* Trigger Name Table Name */ +#define SQLITE_CREATE_TEMP_VIEW 6 /* View Name NULL */ +#define SQLITE_CREATE_TRIGGER 7 /* Trigger Name Table Name */ +#define SQLITE_CREATE_VIEW 8 /* View Name NULL */ +#define SQLITE_DELETE 9 /* Table Name NULL */ +#define SQLITE_DROP_INDEX 10 /* Index Name Table Name */ +#define SQLITE_DROP_TABLE 11 /* Table Name NULL */ +#define SQLITE_DROP_TEMP_INDEX 12 /* Index Name Table Name */ +#define SQLITE_DROP_TEMP_TABLE 13 /* Table Name NULL */ +#define SQLITE_DROP_TEMP_TRIGGER 14 /* Trigger Name Table Name */ +#define SQLITE_DROP_TEMP_VIEW 15 /* View Name NULL */ +#define SQLITE_DROP_TRIGGER 16 /* Trigger Name Table Name */ +#define SQLITE_DROP_VIEW 17 /* View Name NULL */ +#define SQLITE_INSERT 18 /* Table Name NULL */ +#define SQLITE_PRAGMA 19 /* Pragma Name 1st arg or NULL */ +#define SQLITE_READ 20 /* Table Name Column Name */ +#define SQLITE_SELECT 21 /* NULL NULL */ +#define SQLITE_TRANSACTION 22 /* Operation NULL */ +#define SQLITE_UPDATE 23 /* Table Name Column Name */ +#define SQLITE_ATTACH 24 /* Filename NULL */ +#define SQLITE_DETACH 25 /* Database Name NULL */ +#define SQLITE_ALTER_TABLE 26 /* Database Name Table Name */ +#define SQLITE_REINDEX 27 /* Index Name NULL */ +#define SQLITE_ANALYZE 28 /* Table Name NULL */ +#define SQLITE_CREATE_VTABLE 29 /* Table Name Module Name */ +#define SQLITE_DROP_VTABLE 30 /* Table Name Module Name */ +#define SQLITE_FUNCTION 31 /* NULL Function Name */ +#define SQLITE_SAVEPOINT 32 /* Operation Savepoint Name */ +#define SQLITE_COPY 0 /* No longer used */ +#define SQLITE_RECURSIVE 33 /* NULL NULL */ /* ** CAPI3REF: Tracing And Profiling Functions @@ -3215,10 +3206,10 @@ SQLITE_API int sqlite3_set_authorizer( ** either [sqlite3_trace()] or [sqlite3_trace_v2()] will cancel the ** profile callback. */ -SQLITE_API SQLITE_DEPRECATED void *sqlite3_trace(sqlite3*, - void(*xTrace)(void*,const char*), void*); -SQLITE_API SQLITE_DEPRECATED void *sqlite3_profile(sqlite3*, - void(*xProfile)(void*,const char*,sqlite3_uint64), void*); +SQLITE_API SQLITE_DEPRECATED void *sqlite3_trace(sqlite3 *, void (*xTrace)(void *, const char *), void *); +SQLITE_API SQLITE_DEPRECATED void *sqlite3_profile(sqlite3 *, + void (*xProfile)(void *, const char *, sqlite3_uint64), + void *); /* ** CAPI3REF: SQL Trace Event Codes @@ -3272,10 +3263,10 @@ SQLITE_API SQLITE_DEPRECATED void *sqlite3_profile(sqlite3*, ** and the X argument is unused. ** */ -#define SQLITE_TRACE_STMT 0x01 -#define SQLITE_TRACE_PROFILE 0x02 -#define SQLITE_TRACE_ROW 0x04 -#define SQLITE_TRACE_CLOSE 0x08 +#define SQLITE_TRACE_STMT 0x01 +#define SQLITE_TRACE_PROFILE 0x02 +#define SQLITE_TRACE_ROW 0x04 +#define SQLITE_TRACE_CLOSE 0x08 /* ** CAPI3REF: SQL Trace Hook @@ -3306,12 +3297,10 @@ SQLITE_API SQLITE_DEPRECATED void *sqlite3_profile(sqlite3*, ** interfaces [sqlite3_trace()] and [sqlite3_profile()], both of which ** are deprecated. */ -SQLITE_API int sqlite3_trace_v2( - sqlite3*, - unsigned uMask, - int(*xCallback)(unsigned,void*,void*,void*), - void *pCtx -); +SQLITE_API int sqlite3_trace_v2(sqlite3 *, + unsigned uMask, + int (*xCallback)(unsigned, void *, void *, void *), + void *pCtx); /* ** CAPI3REF: Query Progress Callbacks @@ -3345,7 +3334,7 @@ SQLITE_API int sqlite3_trace_v2( ** sqlitecipher connections for the meaning of "modify" in this paragraph. ** */ -SQLITE_API void sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*); +SQLITE_API void sqlite3_progress_handler(sqlite3 *, int, int (*)(void *), void *); /* ** CAPI3REF: Opening A New Database Connection @@ -3617,19 +3606,16 @@ SQLITE_API void sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*); ** ** See also: [sqlite3_temp_directory] */ -SQLITE_API int sqlite3_open( - const char *filename, /* Database filename (UTF-8) */ - sqlite3 **ppDb /* OUT: SQLite db handle */ +SQLITE_API int sqlite3_open(const char *filename, /* Database filename (UTF-8) */ + sqlite3 **ppDb /* OUT: SQLite db handle */ ); -SQLITE_API int sqlite3_open16( - const void *filename, /* Database filename (UTF-16) */ - sqlite3 **ppDb /* OUT: SQLite db handle */ +SQLITE_API int sqlite3_open16(const void *filename, /* Database filename (UTF-16) */ + sqlite3 **ppDb /* OUT: SQLite db handle */ ); -SQLITE_API int sqlite3_open_v2( - const char *filename, /* Database filename (UTF-8) */ - sqlite3 **ppDb, /* OUT: SQLite db handle */ - int flags, /* Flags */ - const char *zVfs /* Name of VFS module to use */ +SQLITE_API int sqlite3_open_v2(const char *filename, /* Database filename (UTF-8) */ + sqlite3 **ppDb, /* OUT: SQLite db handle */ + int flags, /* Flags */ + const char *zVfs /* Name of VFS module to use */ ); /* @@ -3698,10 +3684,10 @@ SQLITE_API int sqlite3_open_v2( ** ** See the [URI filename] documentation for additional information. */ -SQLITE_API const char *sqlite3_uri_parameter(const char *zFilename, const char *zParam); -SQLITE_API int sqlite3_uri_boolean(const char *zFile, const char *zParam, int bDefault); -SQLITE_API sqlite3_int64 sqlite3_uri_int64(const char*, const char*, sqlite3_int64); -SQLITE_API const char *sqlite3_uri_key(const char *zFilename, int N); +SQLITE_API const char *sqlite3_uri_parameter(const char *zFilename, const char *zParam); +SQLITE_API int sqlite3_uri_boolean(const char *zFile, const char *zParam, int bDefault); +SQLITE_API sqlite3_int64 sqlite3_uri_int64(const char *, const char *, sqlite3_int64); +SQLITE_API const char *sqlite3_uri_key(const char *zFilename, int N); /* ** CAPI3REF: Translate filenames @@ -3730,9 +3716,9 @@ SQLITE_API const char *sqlite3_uri_key(const char *zFilename, int N); ** return value from [sqlite3_db_filename()], then the result is ** undefined and is likely a memory access violation. */ -SQLITE_API const char *sqlite3_filename_database(const char*); -SQLITE_API const char *sqlite3_filename_journal(const char*); -SQLITE_API const char *sqlite3_filename_wal(const char*); +SQLITE_API const char *sqlite3_filename_database(const char *); +SQLITE_API const char *sqlite3_filename_journal(const char *); +SQLITE_API const char *sqlite3_filename_wal(const char *); /* ** CAPI3REF: Database File Corresponding To A Journal @@ -3751,7 +3737,7 @@ SQLITE_API const char *sqlite3_filename_wal(const char*); ** of this routine results in undefined and probably undesirable ** behavior. */ -SQLITE_API sqlite3_file *sqlite3_database_file_object(const char*); +SQLITE_API sqlite3_file *sqlite3_database_file_object(const char *); /* ** CAPI3REF: Create and Destroy VFS Filenames @@ -3798,14 +3784,12 @@ SQLITE_API sqlite3_file *sqlite3_database_file_object(const char*); ** then the corresponding [sqlite3_module.xClose() method should also be ** invoked prior to calling sqlite3_free_filename(Y). */ -SQLITE_API char *sqlite3_create_filename( - const char *zDatabase, - const char *zJournal, - const char *zWal, - int nParam, - const char **azParam -); -SQLITE_API void sqlite3_free_filename(char*); +SQLITE_API char *sqlite3_create_filename(const char *zDatabase, + const char *zJournal, + const char *zWal, + int nParam, + const char **azParam); +SQLITE_API void sqlite3_free_filename(char *); /* ** CAPI3REF: Error Codes And Messages @@ -3867,12 +3851,12 @@ SQLITE_API void sqlite3_free_filename(char*); ** was invoked incorrectly by the application. In that case, the ** error code and message may or may not be set. */ -SQLITE_API int sqlite3_errcode(sqlite3 *db); -SQLITE_API int sqlite3_extended_errcode(sqlite3 *db); -SQLITE_API const char *sqlite3_errmsg(sqlite3*); -SQLITE_API const void *sqlite3_errmsg16(sqlite3*); +SQLITE_API int sqlite3_errcode(sqlite3 *db); +SQLITE_API int sqlite3_extended_errcode(sqlite3 *db); +SQLITE_API const char *sqlite3_errmsg(sqlite3 *); +SQLITE_API const void *sqlite3_errmsg16(sqlite3 *); SQLITE_API const char *sqlite3_errstr(int); -SQLITE_API int sqlite3_error_offset(sqlite3 *db); +SQLITE_API int sqlite3_error_offset(sqlite3 *db); /* ** CAPI3REF: Prepared Statement Object @@ -3940,7 +3924,7 @@ typedef struct sqlite3_stmt sqlite3_stmt; ** ** New run-time limit categories may be added in future releases. */ -SQLITE_API int sqlite3_limit(sqlite3*, int id, int newVal); +SQLITE_API int sqlite3_limit(sqlite3 *, int id, int newVal); /* ** CAPI3REF: Run-Time Limit Categories @@ -3998,18 +3982,18 @@ SQLITE_API int sqlite3_limit(sqlite3*, int id, int newVal); ** [prepared statement] may start.)^ ** */ -#define SQLITE_LIMIT_LENGTH 0 -#define SQLITE_LIMIT_SQL_LENGTH 1 -#define SQLITE_LIMIT_COLUMN 2 -#define SQLITE_LIMIT_EXPR_DEPTH 3 -#define SQLITE_LIMIT_COMPOUND_SELECT 4 -#define SQLITE_LIMIT_VDBE_OP 5 -#define SQLITE_LIMIT_FUNCTION_ARG 6 -#define SQLITE_LIMIT_ATTACHED 7 -#define SQLITE_LIMIT_LIKE_PATTERN_LENGTH 8 -#define SQLITE_LIMIT_VARIABLE_NUMBER 9 -#define SQLITE_LIMIT_TRIGGER_DEPTH 10 -#define SQLITE_LIMIT_WORKER_THREADS 11 +#define SQLITE_LIMIT_LENGTH 0 +#define SQLITE_LIMIT_SQL_LENGTH 1 +#define SQLITE_LIMIT_COLUMN 2 +#define SQLITE_LIMIT_EXPR_DEPTH 3 +#define SQLITE_LIMIT_COMPOUND_SELECT 4 +#define SQLITE_LIMIT_VDBE_OP 5 +#define SQLITE_LIMIT_FUNCTION_ARG 6 +#define SQLITE_LIMIT_ATTACHED 7 +#define SQLITE_LIMIT_LIKE_PATTERN_LENGTH 8 +#define SQLITE_LIMIT_VARIABLE_NUMBER 9 +#define SQLITE_LIMIT_TRIGGER_DEPTH 10 +#define SQLITE_LIMIT_WORKER_THREADS 11 /* ** CAPI3REF: Prepare Flags @@ -4046,9 +4030,9 @@ SQLITE_API int sqlite3_limit(sqlite3*, int id, int newVal); ** any virtual tables. ** */ -#define SQLITE_PREPARE_PERSISTENT 0x01 -#define SQLITE_PREPARE_NORMALIZE 0x02 -#define SQLITE_PREPARE_NO_VTAB 0x04 +#define SQLITE_PREPARE_PERSISTENT 0x01 +#define SQLITE_PREPARE_NORMALIZE 0x02 +#define SQLITE_PREPARE_NO_VTAB 0x04 /* ** CAPI3REF: Compiling An SQL Statement @@ -4150,49 +4134,43 @@ SQLITE_API int sqlite3_limit(sqlite3*, int id, int newVal); ** sqlite3_prepare_v2() interface works exactly the same as ** sqlite3_prepare_v3() with a zero prepFlags parameter. */ -SQLITE_API int sqlite3_prepare( - sqlite3 *db, /* Database handle */ - const char *zSql, /* SQL statement, UTF-8 encoded */ - int nByte, /* Maximum length of zSql in bytes. */ - sqlite3_stmt **ppStmt, /* OUT: Statement handle */ - const char **pzTail /* OUT: Pointer to unused portion of zSql */ +SQLITE_API int sqlite3_prepare(sqlite3 *db, /* Database handle */ + const char *zSql, /* SQL statement, UTF-8 encoded */ + int nByte, /* Maximum length of zSql in bytes. */ + sqlite3_stmt **ppStmt, /* OUT: Statement handle */ + const char **pzTail /* OUT: Pointer to unused portion of zSql */ ); -SQLITE_API int sqlite3_prepare_v2( - sqlite3 *db, /* Database handle */ - const char *zSql, /* SQL statement, UTF-8 encoded */ - int nByte, /* Maximum length of zSql in bytes. */ - sqlite3_stmt **ppStmt, /* OUT: Statement handle */ - const char **pzTail /* OUT: Pointer to unused portion of zSql */ +SQLITE_API int sqlite3_prepare_v2(sqlite3 *db, /* Database handle */ + const char *zSql, /* SQL statement, UTF-8 encoded */ + int nByte, /* Maximum length of zSql in bytes. */ + sqlite3_stmt **ppStmt, /* OUT: Statement handle */ + const char **pzTail /* OUT: Pointer to unused portion of zSql */ ); -SQLITE_API int sqlite3_prepare_v3( - sqlite3 *db, /* Database handle */ - const char *zSql, /* SQL statement, UTF-8 encoded */ - int nByte, /* Maximum length of zSql in bytes. */ - unsigned int prepFlags, /* Zero or more SQLITE_PREPARE_ flags */ - sqlite3_stmt **ppStmt, /* OUT: Statement handle */ - const char **pzTail /* OUT: Pointer to unused portion of zSql */ +SQLITE_API int sqlite3_prepare_v3(sqlite3 *db, /* Database handle */ + const char *zSql, /* SQL statement, UTF-8 encoded */ + int nByte, /* Maximum length of zSql in bytes. */ + unsigned int prepFlags, /* Zero or more SQLITE_PREPARE_ flags */ + sqlite3_stmt **ppStmt, /* OUT: Statement handle */ + const char **pzTail /* OUT: Pointer to unused portion of zSql */ ); -SQLITE_API int sqlite3_prepare16( - sqlite3 *db, /* Database handle */ - const void *zSql, /* SQL statement, UTF-16 encoded */ - int nByte, /* Maximum length of zSql in bytes. */ - sqlite3_stmt **ppStmt, /* OUT: Statement handle */ - const void **pzTail /* OUT: Pointer to unused portion of zSql */ +SQLITE_API int sqlite3_prepare16(sqlite3 *db, /* Database handle */ + const void *zSql, /* SQL statement, UTF-16 encoded */ + int nByte, /* Maximum length of zSql in bytes. */ + sqlite3_stmt **ppStmt, /* OUT: Statement handle */ + const void **pzTail /* OUT: Pointer to unused portion of zSql */ ); -SQLITE_API int sqlite3_prepare16_v2( - sqlite3 *db, /* Database handle */ - const void *zSql, /* SQL statement, UTF-16 encoded */ - int nByte, /* Maximum length of zSql in bytes. */ - sqlite3_stmt **ppStmt, /* OUT: Statement handle */ - const void **pzTail /* OUT: Pointer to unused portion of zSql */ +SQLITE_API int sqlite3_prepare16_v2(sqlite3 *db, /* Database handle */ + const void *zSql, /* SQL statement, UTF-16 encoded */ + int nByte, /* Maximum length of zSql in bytes. */ + sqlite3_stmt **ppStmt, /* OUT: Statement handle */ + const void **pzTail /* OUT: Pointer to unused portion of zSql */ ); -SQLITE_API int sqlite3_prepare16_v3( - sqlite3 *db, /* Database handle */ - const void *zSql, /* SQL statement, UTF-16 encoded */ - int nByte, /* Maximum length of zSql in bytes. */ - unsigned int prepFlags, /* Zero or more SQLITE_PREPARE_ flags */ - sqlite3_stmt **ppStmt, /* OUT: Statement handle */ - const void **pzTail /* OUT: Pointer to unused portion of zSql */ +SQLITE_API int sqlite3_prepare16_v3(sqlite3 *db, /* Database handle */ + const void *zSql, /* SQL statement, UTF-16 encoded */ + int nByte, /* Maximum length of zSql in bytes. */ + unsigned int prepFlags, /* Zero or more SQLITE_PREPARE_ flags */ + sqlite3_stmt **ppStmt, /* OUT: Statement handle */ + const void **pzTail /* OUT: Pointer to unused portion of zSql */ ); /* @@ -4237,7 +4215,7 @@ SQLITE_API int sqlite3_prepare16_v3( ** the [SQLITE_ENABLE_NORMALIZE] compile-time option is defined. */ SQLITE_API const char *sqlite3_sql(sqlite3_stmt *pStmt); -SQLITE_API char *sqlite3_expanded_sql(sqlite3_stmt *pStmt); +SQLITE_API char *sqlite3_expanded_sql(sqlite3_stmt *pStmt); #ifdef SQLITE_ENABLE_NORMALIZE SQLITE_API const char *sqlite3_normalized_sql(sqlite3_stmt *pStmt); #endif @@ -4322,7 +4300,7 @@ SQLITE_API int sqlite3_stmt_isexplain(sqlite3_stmt *pStmt); ** for example, in diagnostic routines to search for prepared ** statements that are holding a transaction open. */ -SQLITE_API int sqlite3_stmt_busy(sqlite3_stmt*); +SQLITE_API int sqlite3_stmt_busy(sqlite3_stmt *); /* ** CAPI3REF: Dynamically Typed Value Object @@ -4522,21 +4500,24 @@ typedef struct sqlite3_context sqlite3_context; ** See also: [sqlite3_bind_parameter_count()], ** [sqlite3_bind_parameter_name()], and [sqlite3_bind_parameter_index()]. */ -SQLITE_API int sqlite3_bind_blob(sqlite3_stmt*, int, const void*, int n, void(*)(void*)); -SQLITE_API int sqlite3_bind_blob64(sqlite3_stmt*, int, const void*, sqlite3_uint64, - void(*)(void*)); -SQLITE_API int sqlite3_bind_double(sqlite3_stmt*, int, double); -SQLITE_API int sqlite3_bind_int(sqlite3_stmt*, int, int); -SQLITE_API int sqlite3_bind_int64(sqlite3_stmt*, int, sqlite3_int64); -SQLITE_API int sqlite3_bind_null(sqlite3_stmt*, int); -SQLITE_API int sqlite3_bind_text(sqlite3_stmt*,int,const char*,int,void(*)(void*)); -SQLITE_API int sqlite3_bind_text16(sqlite3_stmt*, int, const void*, int, void(*)(void*)); -SQLITE_API int sqlite3_bind_text64(sqlite3_stmt*, int, const char*, sqlite3_uint64, - void(*)(void*), unsigned char encoding); -SQLITE_API int sqlite3_bind_value(sqlite3_stmt*, int, const sqlite3_value*); -SQLITE_API int sqlite3_bind_pointer(sqlite3_stmt*, int, void*, const char*,void(*)(void*)); -SQLITE_API int sqlite3_bind_zeroblob(sqlite3_stmt*, int, int n); -SQLITE_API int sqlite3_bind_zeroblob64(sqlite3_stmt*, int, sqlite3_uint64); +SQLITE_API int sqlite3_bind_blob(sqlite3_stmt *, int, const void *, int n, void (*)(void *)); +SQLITE_API int sqlite3_bind_blob64(sqlite3_stmt *, int, const void *, sqlite3_uint64, void (*)(void *)); +SQLITE_API int sqlite3_bind_double(sqlite3_stmt *, int, double); +SQLITE_API int sqlite3_bind_int(sqlite3_stmt *, int, int); +SQLITE_API int sqlite3_bind_int64(sqlite3_stmt *, int, sqlite3_int64); +SQLITE_API int sqlite3_bind_null(sqlite3_stmt *, int); +SQLITE_API int sqlite3_bind_text(sqlite3_stmt *, int, const char *, int, void (*)(void *)); +SQLITE_API int sqlite3_bind_text16(sqlite3_stmt *, int, const void *, int, void (*)(void *)); +SQLITE_API int sqlite3_bind_text64(sqlite3_stmt *, + int, + const char *, + sqlite3_uint64, + void (*)(void *), + unsigned char encoding); +SQLITE_API int sqlite3_bind_value(sqlite3_stmt *, int, const sqlite3_value *); +SQLITE_API int sqlite3_bind_pointer(sqlite3_stmt *, int, void *, const char *, void (*)(void *)); +SQLITE_API int sqlite3_bind_zeroblob(sqlite3_stmt *, int, int n); +SQLITE_API int sqlite3_bind_zeroblob64(sqlite3_stmt *, int, sqlite3_uint64); /* ** CAPI3REF: Number Of SQL Parameters @@ -4557,7 +4538,7 @@ SQLITE_API int sqlite3_bind_zeroblob64(sqlite3_stmt*, int, sqlite3_uint64); ** [sqlite3_bind_parameter_name()], and ** [sqlite3_bind_parameter_index()]. */ -SQLITE_API int sqlite3_bind_parameter_count(sqlite3_stmt*); +SQLITE_API int sqlite3_bind_parameter_count(sqlite3_stmt *); /* ** CAPI3REF: Name Of A Host Parameter @@ -4585,7 +4566,7 @@ SQLITE_API int sqlite3_bind_parameter_count(sqlite3_stmt*); ** [sqlite3_bind_parameter_count()], and ** [sqlite3_bind_parameter_index()]. */ -SQLITE_API const char *sqlite3_bind_parameter_name(sqlite3_stmt*, int); +SQLITE_API const char *sqlite3_bind_parameter_name(sqlite3_stmt *, int); /* ** CAPI3REF: Index Of A Parameter With A Given Name @@ -4603,7 +4584,7 @@ SQLITE_API const char *sqlite3_bind_parameter_name(sqlite3_stmt*, int); ** [sqlite3_bind_parameter_count()], and ** [sqlite3_bind_parameter_name()]. */ -SQLITE_API int sqlite3_bind_parameter_index(sqlite3_stmt*, const char *zName); +SQLITE_API int sqlite3_bind_parameter_index(sqlite3_stmt *, const char *zName); /* ** CAPI3REF: Reset All Bindings On A Prepared Statement @@ -4613,7 +4594,7 @@ SQLITE_API int sqlite3_bind_parameter_index(sqlite3_stmt*, const char *zName); ** the [sqlite3_bind_blob | bindings] on a [prepared statement]. ** ^Use this routine to reset all host parameters to NULL. */ -SQLITE_API int sqlite3_clear_bindings(sqlite3_stmt*); +SQLITE_API int sqlite3_clear_bindings(sqlite3_stmt *); /* ** CAPI3REF: Number Of Columns In A Result Set @@ -4658,8 +4639,8 @@ SQLITE_API int sqlite3_column_count(sqlite3_stmt *pStmt); ** then the name of the column is unspecified and may change from ** one release of SQLite to the next. */ -SQLITE_API const char *sqlite3_column_name(sqlite3_stmt*, int N); -SQLITE_API const void *sqlite3_column_name16(sqlite3_stmt*, int N); +SQLITE_API const char *sqlite3_column_name(sqlite3_stmt *, int N); +SQLITE_API const void *sqlite3_column_name16(sqlite3_stmt *, int N); /* ** CAPI3REF: Source Of Data In A Query Result @@ -4703,12 +4684,12 @@ SQLITE_API const void *sqlite3_column_name16(sqlite3_stmt*, int N); ** for the same [prepared statement] and result column ** at the same time then the results are undefined. */ -SQLITE_API const char *sqlite3_column_database_name(sqlite3_stmt*,int); -SQLITE_API const void *sqlite3_column_database_name16(sqlite3_stmt*,int); -SQLITE_API const char *sqlite3_column_table_name(sqlite3_stmt*,int); -SQLITE_API const void *sqlite3_column_table_name16(sqlite3_stmt*,int); -SQLITE_API const char *sqlite3_column_origin_name(sqlite3_stmt*,int); -SQLITE_API const void *sqlite3_column_origin_name16(sqlite3_stmt*,int); +SQLITE_API const char *sqlite3_column_database_name(sqlite3_stmt *, int); +SQLITE_API const void *sqlite3_column_database_name16(sqlite3_stmt *, int); +SQLITE_API const char *sqlite3_column_table_name(sqlite3_stmt *, int); +SQLITE_API const void *sqlite3_column_table_name16(sqlite3_stmt *, int); +SQLITE_API const char *sqlite3_column_origin_name(sqlite3_stmt *, int); +SQLITE_API const void *sqlite3_column_origin_name16(sqlite3_stmt *, int); /* ** CAPI3REF: Declared Datatype Of A Query Result @@ -4740,8 +4721,8 @@ SQLITE_API const void *sqlite3_column_origin_name16(sqlite3_stmt*,int); ** is associated with individual values, not with the containers ** used to hold those values. */ -SQLITE_API const char *sqlite3_column_decltype(sqlite3_stmt*,int); -SQLITE_API const void *sqlite3_column_decltype16(sqlite3_stmt*,int); +SQLITE_API const char *sqlite3_column_decltype(sqlite3_stmt *, int); +SQLITE_API const void *sqlite3_column_decltype16(sqlite3_stmt *, int); /* ** CAPI3REF: Evaluate An SQL Statement @@ -4825,7 +4806,7 @@ SQLITE_API const void *sqlite3_column_decltype16(sqlite3_stmt*,int); ** then the more specific [error codes] are returned directly ** by sqlite3_step(). The use of the "vX" interfaces is recommended. */ -SQLITE_API int sqlite3_step(sqlite3_stmt*); +SQLITE_API int sqlite3_step(sqlite3_stmt *); /* ** CAPI3REF: Number of columns in a result set @@ -4869,16 +4850,16 @@ SQLITE_API int sqlite3_data_count(sqlite3_stmt *pStmt); ** SQLite version 2 and SQLite version 3 should use SQLITE3_TEXT, not ** SQLITE_TEXT. */ -#define SQLITE_INTEGER 1 -#define SQLITE_FLOAT 2 -#define SQLITE_BLOB 4 -#define SQLITE_NULL 5 +#define SQLITE_INTEGER 1 +#define SQLITE_FLOAT 2 +#define SQLITE_BLOB 4 +#define SQLITE_NULL 5 #ifdef SQLITE_TEXT -# undef SQLITE_TEXT +#undef SQLITE_TEXT #else -# define SQLITE_TEXT 3 +#define SQLITE_TEXT 3 #endif -#define SQLITE3_TEXT 3 +#define SQLITE3_TEXT 3 /* ** CAPI3REF: Result Values From A Query @@ -5093,16 +5074,16 @@ SQLITE_API int sqlite3_data_count(sqlite3_stmt *pStmt); ** return value is obtained and before any ** other SQLite interface is called on the same [sqlitecipher connection]. */ -SQLITE_API const void *sqlite3_column_blob(sqlite3_stmt*, int iCol); -SQLITE_API double sqlite3_column_double(sqlite3_stmt*, int iCol); -SQLITE_API int sqlite3_column_int(sqlite3_stmt*, int iCol); -SQLITE_API sqlite3_int64 sqlite3_column_int64(sqlite3_stmt*, int iCol); -SQLITE_API const unsigned char *sqlite3_column_text(sqlite3_stmt*, int iCol); -SQLITE_API const void *sqlite3_column_text16(sqlite3_stmt*, int iCol); -SQLITE_API sqlite3_value *sqlite3_column_value(sqlite3_stmt*, int iCol); -SQLITE_API int sqlite3_column_bytes(sqlite3_stmt*, int iCol); -SQLITE_API int sqlite3_column_bytes16(sqlite3_stmt*, int iCol); -SQLITE_API int sqlite3_column_type(sqlite3_stmt*, int iCol); +SQLITE_API const void *sqlite3_column_blob(sqlite3_stmt *, int iCol); +SQLITE_API double sqlite3_column_double(sqlite3_stmt *, int iCol); +SQLITE_API int sqlite3_column_int(sqlite3_stmt *, int iCol); +SQLITE_API sqlite3_int64 sqlite3_column_int64(sqlite3_stmt *, int iCol); +SQLITE_API const unsigned char *sqlite3_column_text(sqlite3_stmt *, int iCol); +SQLITE_API const void *sqlite3_column_text16(sqlite3_stmt *, int iCol); +SQLITE_API sqlite3_value *sqlite3_column_value(sqlite3_stmt *, int iCol); +SQLITE_API int sqlite3_column_bytes(sqlite3_stmt *, int iCol); +SQLITE_API int sqlite3_column_bytes16(sqlite3_stmt *, int iCol); +SQLITE_API int sqlite3_column_type(sqlite3_stmt *, int iCol); /* ** CAPI3REF: Destroy A Prepared Statement Object @@ -5282,49 +5263,41 @@ SQLITE_API int sqlite3_reset(sqlite3_stmt *pStmt); ** close the sqlitecipher connection nor finalize or reset the prepared ** statement in which the function is running. */ -SQLITE_API int sqlite3_create_function( - sqlite3 *db, - const char *zFunctionName, - int nArg, - int eTextRep, - void *pApp, - void (*xFunc)(sqlite3_context*,int,sqlite3_value**), - void (*xStep)(sqlite3_context*,int,sqlite3_value**), - void (*xFinal)(sqlite3_context*) -); -SQLITE_API int sqlite3_create_function16( - sqlite3 *db, - const void *zFunctionName, - int nArg, - int eTextRep, - void *pApp, - void (*xFunc)(sqlite3_context*,int,sqlite3_value**), - void (*xStep)(sqlite3_context*,int,sqlite3_value**), - void (*xFinal)(sqlite3_context*) -); -SQLITE_API int sqlite3_create_function_v2( - sqlite3 *db, - const char *zFunctionName, - int nArg, - int eTextRep, - void *pApp, - void (*xFunc)(sqlite3_context*,int,sqlite3_value**), - void (*xStep)(sqlite3_context*,int,sqlite3_value**), - void (*xFinal)(sqlite3_context*), - void(*xDestroy)(void*) -); -SQLITE_API int sqlite3_create_window_function( - sqlite3 *db, - const char *zFunctionName, - int nArg, - int eTextRep, - void *pApp, - void (*xStep)(sqlite3_context*,int,sqlite3_value**), - void (*xFinal)(sqlite3_context*), - void (*xValue)(sqlite3_context*), - void (*xInverse)(sqlite3_context*,int,sqlite3_value**), - void(*xDestroy)(void*) -); +SQLITE_API int sqlite3_create_function(sqlite3 *db, + const char *zFunctionName, + int nArg, + int eTextRep, + void *pApp, + void (*xFunc)(sqlite3_context *, int, sqlite3_value **), + void (*xStep)(sqlite3_context *, int, sqlite3_value **), + void (*xFinal)(sqlite3_context *)); +SQLITE_API int sqlite3_create_function16(sqlite3 *db, + const void *zFunctionName, + int nArg, + int eTextRep, + void *pApp, + void (*xFunc)(sqlite3_context *, int, sqlite3_value **), + void (*xStep)(sqlite3_context *, int, sqlite3_value **), + void (*xFinal)(sqlite3_context *)); +SQLITE_API int sqlite3_create_function_v2(sqlite3 *db, + const char *zFunctionName, + int nArg, + int eTextRep, + void *pApp, + void (*xFunc)(sqlite3_context *, int, sqlite3_value **), + void (*xStep)(sqlite3_context *, int, sqlite3_value **), + void (*xFinal)(sqlite3_context *), + void (*xDestroy)(void *)); +SQLITE_API int sqlite3_create_window_function(sqlite3 *db, + const char *zFunctionName, + int nArg, + int eTextRep, + void *pApp, + void (*xStep)(sqlite3_context *, int, sqlite3_value **), + void (*xFinal)(sqlite3_context *), + void (*xValue)(sqlite3_context *), + void (*xInverse)(sqlite3_context *, int, sqlite3_value **), + void (*xDestroy)(void *)); /* ** CAPI3REF: Text Encodings @@ -5332,12 +5305,12 @@ SQLITE_API int sqlite3_create_window_function( ** These constant define integer codes that represent the various ** text encodings supported by SQLite. */ -#define SQLITE_UTF8 1 /* IMP: R-37514-35566 */ -#define SQLITE_UTF16LE 2 /* IMP: R-03371-37637 */ -#define SQLITE_UTF16BE 3 /* IMP: R-51971-34154 */ -#define SQLITE_UTF16 4 /* Use native byte order */ -#define SQLITE_ANY 5 /* Deprecated */ -#define SQLITE_UTF16_ALIGNED 8 /* sqlite3_create_collation only */ +#define SQLITE_UTF8 1 /* IMP: R-37514-35566 */ +#define SQLITE_UTF16LE 2 /* IMP: R-03371-37637 */ +#define SQLITE_UTF16BE 3 /* IMP: R-51971-34154 */ +#define SQLITE_UTF16 4 /* Use native byte order */ +#define SQLITE_ANY 5 /* Deprecated */ +#define SQLITE_UTF16_ALIGNED 8 /* sqlite3_create_collation only */ /* ** CAPI3REF: Function Flags @@ -5404,10 +5377,10 @@ SQLITE_API int sqlite3_create_window_function( ** ** */ -#define SQLITE_DETERMINISTIC 0x000000800 -#define SQLITE_DIRECTONLY 0x000080000 -#define SQLITE_SUBTYPE 0x000100000 -#define SQLITE_INNOCUOUS 0x000200000 +#define SQLITE_DETERMINISTIC 0x000000800 +#define SQLITE_DIRECTONLY 0x000080000 +#define SQLITE_SUBTYPE 0x000100000 +#define SQLITE_INNOCUOUS 0x000200000 /* ** CAPI3REF: Deprecated Functions @@ -5420,13 +5393,12 @@ SQLITE_API int sqlite3_create_window_function( ** these functions, we will not explain what they do. */ #ifndef SQLITE_OMIT_DEPRECATED -SQLITE_API SQLITE_DEPRECATED int sqlite3_aggregate_count(sqlite3_context*); -SQLITE_API SQLITE_DEPRECATED int sqlite3_expired(sqlite3_stmt*); -SQLITE_API SQLITE_DEPRECATED int sqlite3_transfer_bindings(sqlite3_stmt*, sqlite3_stmt*); -SQLITE_API SQLITE_DEPRECATED int sqlite3_global_recover(void); +SQLITE_API SQLITE_DEPRECATED int sqlite3_aggregate_count(sqlite3_context *); +SQLITE_API SQLITE_DEPRECATED int sqlite3_expired(sqlite3_stmt *); +SQLITE_API SQLITE_DEPRECATED int sqlite3_transfer_bindings(sqlite3_stmt *, sqlite3_stmt *); +SQLITE_API SQLITE_DEPRECATED int sqlite3_global_recover(void); SQLITE_API SQLITE_DEPRECATED void sqlite3_thread_cleanup(void); -SQLITE_API SQLITE_DEPRECATED int sqlite3_memory_alarm(void(*)(void*,sqlite3_int64,int), - void*,sqlite3_int64); +SQLITE_API SQLITE_DEPRECATED int sqlite3_memory_alarm(void (*)(void *, sqlite3_int64, int), void *, sqlite3_int64); #endif /* @@ -5557,21 +5529,21 @@ SQLITE_API SQLITE_DEPRECATED int sqlite3_memory_alarm(void(*)(void*,sqlite3_int6 ** return value is obtained and before any ** other SQLite interface is called on the same [sqlitecipher connection]. */ -SQLITE_API const void *sqlite3_value_blob(sqlite3_value*); -SQLITE_API double sqlite3_value_double(sqlite3_value*); -SQLITE_API int sqlite3_value_int(sqlite3_value*); -SQLITE_API sqlite3_int64 sqlite3_value_int64(sqlite3_value*); -SQLITE_API void *sqlite3_value_pointer(sqlite3_value*, const char*); -SQLITE_API const unsigned char *sqlite3_value_text(sqlite3_value*); -SQLITE_API const void *sqlite3_value_text16(sqlite3_value*); -SQLITE_API const void *sqlite3_value_text16le(sqlite3_value*); -SQLITE_API const void *sqlite3_value_text16be(sqlite3_value*); -SQLITE_API int sqlite3_value_bytes(sqlite3_value*); -SQLITE_API int sqlite3_value_bytes16(sqlite3_value*); -SQLITE_API int sqlite3_value_type(sqlite3_value*); -SQLITE_API int sqlite3_value_numeric_type(sqlite3_value*); -SQLITE_API int sqlite3_value_nochange(sqlite3_value*); -SQLITE_API int sqlite3_value_frombind(sqlite3_value*); +SQLITE_API const void *sqlite3_value_blob(sqlite3_value *); +SQLITE_API double sqlite3_value_double(sqlite3_value *); +SQLITE_API int sqlite3_value_int(sqlite3_value *); +SQLITE_API sqlite3_int64 sqlite3_value_int64(sqlite3_value *); +SQLITE_API void *sqlite3_value_pointer(sqlite3_value *, const char *); +SQLITE_API const unsigned char *sqlite3_value_text(sqlite3_value *); +SQLITE_API const void *sqlite3_value_text16(sqlite3_value *); +SQLITE_API const void *sqlite3_value_text16le(sqlite3_value *); +SQLITE_API const void *sqlite3_value_text16be(sqlite3_value *); +SQLITE_API int sqlite3_value_bytes(sqlite3_value *); +SQLITE_API int sqlite3_value_bytes16(sqlite3_value *); +SQLITE_API int sqlite3_value_type(sqlite3_value *); +SQLITE_API int sqlite3_value_numeric_type(sqlite3_value *); +SQLITE_API int sqlite3_value_nochange(sqlite3_value *); +SQLITE_API int sqlite3_value_frombind(sqlite3_value *); /* ** CAPI3REF: Finding The Subtype Of SQL Values @@ -5583,7 +5555,7 @@ SQLITE_API int sqlite3_value_frombind(sqlite3_value*); ** one SQL function to another. Use the [sqlite3_result_subtype()] ** routine to set the subtype for the return value of an SQL function. */ -SQLITE_API unsigned int sqlite3_value_subtype(sqlite3_value*); +SQLITE_API unsigned int sqlite3_value_subtype(sqlite3_value *); /* ** CAPI3REF: Copy And Free SQL Values @@ -5600,8 +5572,8 @@ SQLITE_API unsigned int sqlite3_value_subtype(sqlite3_value*); ** previously obtained from [sqlite3_value_dup()]. ^If V is a NULL pointer ** then sqlite3_value_free(V) is a harmless no-op. */ -SQLITE_API sqlite3_value *sqlite3_value_dup(const sqlite3_value*); -SQLITE_API void sqlite3_value_free(sqlite3_value*); +SQLITE_API sqlite3_value *sqlite3_value_dup(const sqlite3_value *); +SQLITE_API void sqlite3_value_free(sqlite3_value *); /* ** CAPI3REF: Obtain Aggregate Function Context @@ -5646,7 +5618,7 @@ SQLITE_API void sqlite3_value_free(sqlite3_value*); ** This routine must be called from the same thread in which ** the aggregate SQL function is running. */ -SQLITE_API void *sqlite3_aggregate_context(sqlite3_context*, int nBytes); +SQLITE_API void *sqlite3_aggregate_context(sqlite3_context *, int nBytes); /* ** CAPI3REF: User Data For Functions @@ -5661,7 +5633,7 @@ SQLITE_API void *sqlite3_aggregate_context(sqlite3_context*, int nBytes); ** This routine must be called from the same thread in which ** the application-defined function is running. */ -SQLITE_API void *sqlite3_user_data(sqlite3_context*); +SQLITE_API void *sqlite3_user_data(sqlite3_context *); /* ** CAPI3REF: Database Connection For Functions @@ -5673,7 +5645,7 @@ SQLITE_API void *sqlite3_user_data(sqlite3_context*); ** and [sqlite3_create_function16()] routines that originally ** registered the application defined function. */ -SQLITE_API sqlite3 *sqlite3_context_db_handle(sqlite3_context*); +SQLITE_API sqlite3 *sqlite3_context_db_handle(sqlite3_context *); /* ** CAPI3REF: Function Auxiliary Data @@ -5732,9 +5704,8 @@ SQLITE_API sqlite3 *sqlite3_context_db_handle(sqlite3_context*); ** These routines must be called from the same thread in which ** the SQL function is running. */ -SQLITE_API void *sqlite3_get_auxdata(sqlite3_context*, int N); -SQLITE_API void sqlite3_set_auxdata(sqlite3_context*, int N, void*, void (*)(void*)); - +SQLITE_API void *sqlite3_get_auxdata(sqlite3_context *, int N); +SQLITE_API void sqlite3_set_auxdata(sqlite3_context *, int N, void *, void (*)(void *)); /* ** CAPI3REF: Constants Defining Special Destructor Behavior @@ -5750,9 +5721,9 @@ SQLITE_API void sqlite3_set_auxdata(sqlite3_context*, int N, void*, void (*)(voi ** The typedef is necessary to work around problems in certain ** C++ compilers. */ -typedef void (*sqlite3_destructor_type)(void*); -#define SQLITE_STATIC ((sqlite3_destructor_type)0) -#define SQLITE_TRANSIENT ((sqlite3_destructor_type)-1) +typedef void (*sqlite3_destructor_type)(void *); +#define SQLITE_STATIC ((sqlite3_destructor_type)0) +#define SQLITE_TRANSIENT ((sqlite3_destructor_type)-1) /* ** CAPI3REF: Setting The Result Of An SQL Function @@ -5900,29 +5871,30 @@ typedef void (*sqlite3_destructor_type)(void*); ** than the one containing the application-defined function that received ** the [sqlite3_context] pointer, the results are undefined. */ -SQLITE_API void sqlite3_result_blob(sqlite3_context*, const void*, int, void(*)(void*)); -SQLITE_API void sqlite3_result_blob64(sqlite3_context*,const void*, - sqlite3_uint64,void(*)(void*)); -SQLITE_API void sqlite3_result_double(sqlite3_context*, double); -SQLITE_API void sqlite3_result_error(sqlite3_context*, const char*, int); -SQLITE_API void sqlite3_result_error16(sqlite3_context*, const void*, int); -SQLITE_API void sqlite3_result_error_toobig(sqlite3_context*); -SQLITE_API void sqlite3_result_error_nomem(sqlite3_context*); -SQLITE_API void sqlite3_result_error_code(sqlite3_context*, int); -SQLITE_API void sqlite3_result_int(sqlite3_context*, int); -SQLITE_API void sqlite3_result_int64(sqlite3_context*, sqlite3_int64); -SQLITE_API void sqlite3_result_null(sqlite3_context*); -SQLITE_API void sqlite3_result_text(sqlite3_context*, const char*, int, void(*)(void*)); -SQLITE_API void sqlite3_result_text64(sqlite3_context*, const char*,sqlite3_uint64, - void(*)(void*), unsigned char encoding); -SQLITE_API void sqlite3_result_text16(sqlite3_context*, const void*, int, void(*)(void*)); -SQLITE_API void sqlite3_result_text16le(sqlite3_context*, const void*, int,void(*)(void*)); -SQLITE_API void sqlite3_result_text16be(sqlite3_context*, const void*, int,void(*)(void*)); -SQLITE_API void sqlite3_result_value(sqlite3_context*, sqlite3_value*); -SQLITE_API void sqlite3_result_pointer(sqlite3_context*, void*,const char*,void(*)(void*)); -SQLITE_API void sqlite3_result_zeroblob(sqlite3_context*, int n); -SQLITE_API int sqlite3_result_zeroblob64(sqlite3_context*, sqlite3_uint64 n); - +SQLITE_API void sqlite3_result_blob(sqlite3_context *, const void *, int, void (*)(void *)); +SQLITE_API void sqlite3_result_blob64(sqlite3_context *, const void *, sqlite3_uint64, void (*)(void *)); +SQLITE_API void sqlite3_result_double(sqlite3_context *, double); +SQLITE_API void sqlite3_result_error(sqlite3_context *, const char *, int); +SQLITE_API void sqlite3_result_error16(sqlite3_context *, const void *, int); +SQLITE_API void sqlite3_result_error_toobig(sqlite3_context *); +SQLITE_API void sqlite3_result_error_nomem(sqlite3_context *); +SQLITE_API void sqlite3_result_error_code(sqlite3_context *, int); +SQLITE_API void sqlite3_result_int(sqlite3_context *, int); +SQLITE_API void sqlite3_result_int64(sqlite3_context *, sqlite3_int64); +SQLITE_API void sqlite3_result_null(sqlite3_context *); +SQLITE_API void sqlite3_result_text(sqlite3_context *, const char *, int, void (*)(void *)); +SQLITE_API void sqlite3_result_text64(sqlite3_context *, + const char *, + sqlite3_uint64, + void (*)(void *), + unsigned char encoding); +SQLITE_API void sqlite3_result_text16(sqlite3_context *, const void *, int, void (*)(void *)); +SQLITE_API void sqlite3_result_text16le(sqlite3_context *, const void *, int, void (*)(void *)); +SQLITE_API void sqlite3_result_text16be(sqlite3_context *, const void *, int, void (*)(void *)); +SQLITE_API void sqlite3_result_value(sqlite3_context *, sqlite3_value *); +SQLITE_API void sqlite3_result_pointer(sqlite3_context *, void *, const char *, void (*)(void *)); +SQLITE_API void sqlite3_result_zeroblob(sqlite3_context *, int n); +SQLITE_API int sqlite3_result_zeroblob64(sqlite3_context *, sqlite3_uint64 n); /* ** CAPI3REF: Setting The Subtype Of An SQL Function @@ -5936,7 +5908,7 @@ SQLITE_API int sqlite3_result_zeroblob64(sqlite3_context*, sqlite3_uint64 n); ** The number of subtype bytes preserved by SQLite might increase ** in future releases of SQLite. */ -SQLITE_API void sqlite3_result_subtype(sqlite3_context*,unsigned int); +SQLITE_API void sqlite3_result_subtype(sqlite3_context *, unsigned int); /* ** CAPI3REF: Define New Collating Sequences @@ -6019,28 +5991,22 @@ SQLITE_API void sqlite3_result_subtype(sqlite3_context*,unsigned int); ** ** See also: [sqlite3_collation_needed()] and [sqlite3_collation_needed16()]. */ -SQLITE_API int sqlite3_create_collation( - sqlite3*, - const char *zName, - int eTextRep, - void *pArg, - int(*xCompare)(void*,int,const void*,int,const void*) -); -SQLITE_API int sqlite3_create_collation_v2( - sqlite3*, - const char *zName, - int eTextRep, - void *pArg, - int(*xCompare)(void*,int,const void*,int,const void*), - void(*xDestroy)(void*) -); -SQLITE_API int sqlite3_create_collation16( - sqlite3*, - const void *zName, - int eTextRep, - void *pArg, - int(*xCompare)(void*,int,const void*,int,const void*) -); +SQLITE_API int sqlite3_create_collation(sqlite3 *, + const char *zName, + int eTextRep, + void *pArg, + int (*xCompare)(void *, int, const void *, int, const void *)); +SQLITE_API int sqlite3_create_collation_v2(sqlite3 *, + const char *zName, + int eTextRep, + void *pArg, + int (*xCompare)(void *, int, const void *, int, const void *), + void (*xDestroy)(void *)); +SQLITE_API int sqlite3_create_collation16(sqlite3 *, + const void *zName, + int eTextRep, + void *pArg, + int (*xCompare)(void *, int, const void *, int, const void *)); /* ** CAPI3REF: Collation Needed Callbacks @@ -6069,16 +6035,8 @@ SQLITE_API int sqlite3_create_collation16( ** [sqlite3_create_collation()], [sqlite3_create_collation16()], or ** [sqlite3_create_collation_v2()]. */ -SQLITE_API int sqlite3_collation_needed( - sqlite3*, - void*, - void(*)(void*,sqlite3*,int eTextRep,const char*) -); -SQLITE_API int sqlite3_collation_needed16( - sqlite3*, - void*, - void(*)(void*,sqlite3*,int eTextRep,const void*) -); +SQLITE_API int sqlite3_collation_needed(sqlite3 *, void *, void (*)(void *, sqlite3 *, int eTextRep, const char *)); +SQLITE_API int sqlite3_collation_needed16(sqlite3 *, void *, void (*)(void *, sqlite3 *, int eTextRep, const void *)); /* BEGIN SQLCIPHER */ #ifdef SQLITE_HAS_CODEC @@ -6089,14 +6047,14 @@ SQLITE_API int sqlite3_collation_needed16( ** The code to implement this API is not available in the public release ** of SQLite. */ -SQLITE_API int sqlite3_key( - sqlite3 *db, /* Database to be rekeyed */ - const void *pKey, int nKey /* The key */ +SQLITE_API int sqlite3_key(sqlite3 *db, /* Database to be rekeyed */ + const void *pKey, + int nKey /* The key */ ); -SQLITE_API int sqlite3_key_v2( - sqlite3 *db, /* Database to be rekeyed */ - const char *zDbName, /* Name of the sqlitecipher */ - const void *pKey, int nKey /* The key */ +SQLITE_API int sqlite3_key_v2(sqlite3 *db, /* Database to be rekeyed */ + const char *zDbName, /* Name of the sqlitecipher */ + const void *pKey, + int nKey /* The key */ ); /* @@ -6120,22 +6078,21 @@ SQLITE_API int sqlite3_key_v2( use an ATTACHed sqlitecipher and the sqlcipher_export() convenience function as per the SQLCipher Documentation. */ -SQLITE_API int sqlite3_rekey( - sqlite3 *db, /* Database to be rekeyed */ - const void *pKey, int nKey /* The new key */ +SQLITE_API int sqlite3_rekey(sqlite3 *db, /* Database to be rekeyed */ + const void *pKey, + int nKey /* The new key */ ); -SQLITE_API int sqlite3_rekey_v2( - sqlite3 *db, /* Database to be rekeyed */ - const char *zDbName, /* Name of the sqlitecipher */ - const void *pKey, int nKey /* The new key */ +SQLITE_API int sqlite3_rekey_v2(sqlite3 *db, /* Database to be rekeyed */ + const char *zDbName, /* Name of the sqlitecipher */ + const void *pKey, + int nKey /* The new key */ ); /* ** Specify the activation key for a SEE sqlitecipher. Unless ** activated, none of the SEE routines will work. */ -SQLITE_API void sqlite3_activate_see( - const char *zPassPhrase /* Activation phrase */ +SQLITE_API void sqlite3_activate_see(const char *zPassPhrase /* Activation phrase */ ); #endif /* END SQLCIPHER */ @@ -6145,8 +6102,7 @@ SQLITE_API void sqlite3_activate_see( ** Specify the activation key for a CEROD sqlitecipher. Unless ** activated, none of the CEROD routines will work. */ -SQLITE_API void sqlite3_activate_cerod( - const char *zPassPhrase /* Activation phrase */ +SQLITE_API void sqlite3_activate_cerod(const char *zPassPhrase /* Activation phrase */ ); #endif @@ -6283,9 +6239,8 @@ SQLITE_API SQLITE_EXTERN char *sqlite3_data_directory; ** sqlite3_win32_set_directory interface except the string parameter must be ** UTF-8 or UTF-16, respectively. */ -SQLITE_API int sqlite3_win32_set_directory( - unsigned long type, /* Identifier for directory being set or reset */ - void *zValue /* New value for directory being set or reset */ +SQLITE_API int sqlite3_win32_set_directory(unsigned long type, /* Identifier for directory being set or reset */ + void *zValue /* New value for directory being set or reset */ ); SQLITE_API int sqlite3_win32_set_directory8(unsigned long type, const char *zValue); SQLITE_API int sqlite3_win32_set_directory16(unsigned long type, const void *zValue); @@ -6296,8 +6251,8 @@ SQLITE_API int sqlite3_win32_set_directory16(unsigned long type, const void *zVa ** These macros are only available on Windows. They define the allowed values ** for the type argument to the [sqlite3_win32_set_directory] interface. */ -#define SQLITE_WIN32_DATA_DIRECTORY_TYPE 1 -#define SQLITE_WIN32_TEMP_DIRECTORY_TYPE 2 +#define SQLITE_WIN32_DATA_DIRECTORY_TYPE 1 +#define SQLITE_WIN32_TEMP_DIRECTORY_TYPE 2 /* ** CAPI3REF: Test For Auto-Commit Mode @@ -6321,7 +6276,7 @@ SQLITE_API int sqlite3_win32_set_directory16(unsigned long type, const void *zVa ** connection while this routine is running, then the return value ** is undefined. */ -SQLITE_API int sqlite3_get_autocommit(sqlite3*); +SQLITE_API int sqlite3_get_autocommit(sqlite3 *); /* ** CAPI3REF: Find The Database Handle Of A Prepared Statement @@ -6334,7 +6289,7 @@ SQLITE_API int sqlite3_get_autocommit(sqlite3*); ** to the [sqlite3_prepare_v2()] call (or its variants) that was used to ** create the statement in the first place. */ -SQLITE_API sqlite3 *sqlite3_db_handle(sqlite3_stmt*); +SQLITE_API sqlite3 *sqlite3_db_handle(sqlite3_stmt *); /* ** CAPI3REF: Return The Schema Name For A Database Connection @@ -6416,7 +6371,7 @@ SQLITE_API int sqlite3_db_readonly(sqlite3 *db, const char *zDbName); ** ^If the S argument to sqlite3_txn_state(D,S) is not the name of ** a valid schema, then -1 is returned. */ -SQLITE_API int sqlite3_txn_state(sqlite3*,const char *zSchema); +SQLITE_API int sqlite3_txn_state(sqlite3 *, const char *zSchema); /* ** CAPI3REF: Allowed return values from [sqlite3_txn_state()] @@ -6514,8 +6469,8 @@ SQLITE_API sqlite3_stmt *sqlite3_next_stmt(sqlite3 *pDb, sqlite3_stmt *pStmt); ** ** See also the [sqlite3_update_hook()] interface. */ -SQLITE_API void *sqlite3_commit_hook(sqlite3*, int(*)(void*), void*); -SQLITE_API void *sqlite3_rollback_hook(sqlite3*, void(*)(void *), void*); +SQLITE_API void *sqlite3_commit_hook(sqlite3 *, int (*)(void *), void *); +SQLITE_API void *sqlite3_rollback_hook(sqlite3 *, void (*)(void *), void *); /* ** CAPI3REF: Autovacuum Compaction Amount Callback @@ -6576,12 +6531,10 @@ SQLITE_API void *sqlite3_rollback_hook(sqlite3*, void(*)(void *), void*); ** */ SQLITE_API int sqlite3_autovacuum_pages( - sqlite3 *db, - unsigned int(*)(void*,const char*,unsigned int,unsigned int,unsigned int), - void*, - void(*)(void*) -); - + sqlite3 *db, + unsigned int (*)(void *, const char *, unsigned int, unsigned int, unsigned int), + void *, + void (*)(void *)); /* ** CAPI3REF: Data Change Notification Callbacks @@ -6632,11 +6585,9 @@ SQLITE_API int sqlite3_autovacuum_pages( ** See also the [sqlite3_commit_hook()], [sqlite3_rollback_hook()], ** and [sqlite3_preupdate_hook()] interfaces. */ -SQLITE_API void *sqlite3_update_hook( - sqlite3*, - void(*)(void *,int ,char const *,char const *,sqlite3_int64), - void* -); +SQLITE_API void *sqlite3_update_hook(sqlite3 *, + void (*)(void *, int, char const *, char const *, sqlite3_int64), + void *); /* ** CAPI3REF: Enable Or Disable Shared Pager Cache @@ -6707,7 +6658,7 @@ SQLITE_API int sqlite3_release_memory(int); ** ** See also: [sqlite3_release_memory()] */ -SQLITE_API int sqlite3_db_release_memory(sqlite3*); +SQLITE_API int sqlite3_db_release_memory(sqlite3 *); /* ** CAPI3REF: Impose A Limit On Heap Size @@ -6787,7 +6738,6 @@ SQLITE_API sqlite3_int64 sqlite3_hard_heap_limit64(sqlite3_int64 N); */ SQLITE_API SQLITE_DEPRECATED void sqlite3_soft_heap_limit(int N); - /* ** CAPI3REF: Extract Metadata About A Column Of A Table ** METHOD: sqlite3 @@ -6857,16 +6807,15 @@ SQLITE_API SQLITE_DEPRECATED void sqlite3_soft_heap_limit(int N); ** parsed, if that has not already been done, and returns an error if ** any errors are encountered while loading the schema. */ -SQLITE_API int sqlite3_table_column_metadata( - sqlite3 *db, /* Connection handle */ - const char *zDbName, /* Database name or NULL */ - const char *zTableName, /* Table name */ - const char *zColumnName, /* Column name */ - char const **pzDataType, /* OUTPUT: Declared data type */ - char const **pzCollSeq, /* OUTPUT: Collation sequence name */ - int *pNotNull, /* OUTPUT: True if NOT NULL constraint exists */ - int *pPrimaryKey, /* OUTPUT: True if column part of PK */ - int *pAutoinc /* OUTPUT: True if column is auto-increment */ +SQLITE_API int sqlite3_table_column_metadata(sqlite3 *db, /* Connection handle */ + const char *zDbName, /* Database name or NULL */ + const char *zTableName, /* Table name */ + const char *zColumnName, /* Column name */ + char const **pzDataType, /* OUTPUT: Declared data type */ + char const **pzCollSeq, /* OUTPUT: Collation sequence name */ + int *pNotNull, /* OUTPUT: True if NOT NULL constraint exists */ + int *pPrimaryKey, /* OUTPUT: True if column part of PK */ + int *pAutoinc /* OUTPUT: True if column is auto-increment */ ); /* @@ -6913,11 +6862,10 @@ SQLITE_API int sqlite3_table_column_metadata( ** ** See also the [load_extension() SQL function]. */ -SQLITE_API int sqlite3_load_extension( - sqlite3 *db, /* Load the extension into this sqlitecipher connection */ - const char *zFile, /* Name of the shared library containing extension */ - const char *zProc, /* Entry point. Derived from zFile if 0 */ - char **pzErrMsg /* Put error message here if not 0 */ +SQLITE_API int sqlite3_load_extension(sqlite3 *db, /* Load the extension into this sqlitecipher connection */ + const char *zFile, /* Name of the shared library containing extension */ + const char *zProc, /* Entry point. Derived from zFile if 0 */ + char **pzErrMsg /* Put error message here if not 0 */ ); /* @@ -6983,7 +6931,7 @@ SQLITE_API int sqlite3_enable_load_extension(sqlite3 *db, int onoff); ** See also: [sqlite3_reset_auto_extension()] ** and [sqlite3_cancel_auto_extension()] */ -SQLITE_API int sqlite3_auto_extension(void(*xEntryPoint)(void)); +SQLITE_API int sqlite3_auto_extension(void (*xEntryPoint)(void)); /* ** CAPI3REF: Cancel Automatic Extension Loading @@ -6995,7 +6943,7 @@ SQLITE_API int sqlite3_auto_extension(void(*xEntryPoint)(void)); ** unregistered and it returns 0 if X was not on the list of initialization ** routines. */ -SQLITE_API int sqlite3_cancel_auto_extension(void(*xEntryPoint)(void)); +SQLITE_API int sqlite3_cancel_auto_extension(void (*xEntryPoint)(void)); /* ** CAPI3REF: Reset Automatic Extension Loading @@ -7017,10 +6965,10 @@ SQLITE_API void sqlite3_reset_auto_extension(void); /* ** Structures used by the virtual table interface */ -typedef struct sqlite3_vtab sqlite3_vtab; -typedef struct sqlite3_index_info sqlite3_index_info; +typedef struct sqlite3_vtab sqlite3_vtab; +typedef struct sqlite3_index_info sqlite3_index_info; typedef struct sqlite3_vtab_cursor sqlite3_vtab_cursor; -typedef struct sqlite3_module sqlite3_module; +typedef struct sqlite3_module sqlite3_module; /* ** CAPI3REF: Virtual Table Object @@ -7039,41 +6987,38 @@ typedef struct sqlite3_module sqlite3_module; ** any sqlitecipher connection. */ struct sqlite3_module { - int iVersion; - int (*xCreate)(sqlite3*, void *pAux, - int argc, const char *const*argv, - sqlite3_vtab **ppVTab, char**); - int (*xConnect)(sqlite3*, void *pAux, - int argc, const char *const*argv, - sqlite3_vtab **ppVTab, char**); - int (*xBestIndex)(sqlite3_vtab *pVTab, sqlite3_index_info*); - int (*xDisconnect)(sqlite3_vtab *pVTab); - int (*xDestroy)(sqlite3_vtab *pVTab); - int (*xOpen)(sqlite3_vtab *pVTab, sqlite3_vtab_cursor **ppCursor); - int (*xClose)(sqlite3_vtab_cursor*); - int (*xFilter)(sqlite3_vtab_cursor*, int idxNum, const char *idxStr, - int argc, sqlite3_value **argv); - int (*xNext)(sqlite3_vtab_cursor*); - int (*xEof)(sqlite3_vtab_cursor*); - int (*xColumn)(sqlite3_vtab_cursor*, sqlite3_context*, int); - int (*xRowid)(sqlite3_vtab_cursor*, sqlite3_int64 *pRowid); - int (*xUpdate)(sqlite3_vtab *, int, sqlite3_value **, sqlite3_int64 *); - int (*xBegin)(sqlite3_vtab *pVTab); - int (*xSync)(sqlite3_vtab *pVTab); - int (*xCommit)(sqlite3_vtab *pVTab); - int (*xRollback)(sqlite3_vtab *pVTab); - int (*xFindFunction)(sqlite3_vtab *pVtab, int nArg, const char *zName, - void (**pxFunc)(sqlite3_context*,int,sqlite3_value**), - void **ppArg); - int (*xRename)(sqlite3_vtab *pVtab, const char *zNew); - /* The methods above are in version 1 of the sqlite_module object. Those + int iVersion; + int (*xCreate)(sqlite3 *, void *pAux, int argc, const char *const *argv, sqlite3_vtab **ppVTab, char **); + int (*xConnect)(sqlite3 *, void *pAux, int argc, const char *const *argv, sqlite3_vtab **ppVTab, char **); + int (*xBestIndex)(sqlite3_vtab *pVTab, sqlite3_index_info *); + int (*xDisconnect)(sqlite3_vtab *pVTab); + int (*xDestroy)(sqlite3_vtab *pVTab); + int (*xOpen)(sqlite3_vtab *pVTab, sqlite3_vtab_cursor **ppCursor); + int (*xClose)(sqlite3_vtab_cursor *); + int (*xFilter)(sqlite3_vtab_cursor *, int idxNum, const char *idxStr, int argc, sqlite3_value **argv); + int (*xNext)(sqlite3_vtab_cursor *); + int (*xEof)(sqlite3_vtab_cursor *); + int (*xColumn)(sqlite3_vtab_cursor *, sqlite3_context *, int); + int (*xRowid)(sqlite3_vtab_cursor *, sqlite3_int64 *pRowid); + int (*xUpdate)(sqlite3_vtab *, int, sqlite3_value **, sqlite3_int64 *); + int (*xBegin)(sqlite3_vtab *pVTab); + int (*xSync)(sqlite3_vtab *pVTab); + int (*xCommit)(sqlite3_vtab *pVTab); + int (*xRollback)(sqlite3_vtab *pVTab); + int (*xFindFunction)(sqlite3_vtab *pVtab, + int nArg, + const char *zName, + void (**pxFunc)(sqlite3_context *, int, sqlite3_value **), + void **ppArg); + int (*xRename)(sqlite3_vtab *pVtab, const char *zNew); + /* The methods above are in version 1 of the sqlite_module object. Those ** below are for version 2 and greater. */ - int (*xSavepoint)(sqlite3_vtab *pVTab, int); - int (*xRelease)(sqlite3_vtab *pVTab, int); - int (*xRollbackTo)(sqlite3_vtab *pVTab, int); - /* The methods above are in versions 1 and 2 of the sqlite_module object. + int (*xSavepoint)(sqlite3_vtab *pVTab, int); + int (*xRelease)(sqlite3_vtab *pVTab, int); + int (*xRollbackTo)(sqlite3_vtab *pVTab, int); + /* The methods above are in versions 1 and 2 of the sqlite_module object. ** Those below are for version 3 and greater. */ - int (*xShadowName)(const char*); + int (*xShadowName)(const char *); }; /* @@ -7179,35 +7124,35 @@ struct sqlite3_module { ** 3009000. */ struct sqlite3_index_info { - /* Inputs */ - int nConstraint; /* Number of entries in aConstraint */ - struct sqlite3_index_constraint { - int iColumn; /* Column constrained. -1 for ROWID */ - unsigned char op; /* Constraint operator */ - unsigned char usable; /* True if this constraint is usable */ - int iTermOffset; /* Used internally - xBestIndex should ignore */ - } *aConstraint; /* Table of WHERE clause constraints */ - int nOrderBy; /* Number of terms in the ORDER BY clause */ - struct sqlite3_index_orderby { - int iColumn; /* Column number */ - unsigned char desc; /* True for DESC. False for ASC. */ - } *aOrderBy; /* The ORDER BY clause */ - /* Outputs */ - struct sqlite3_index_constraint_usage { - int argvIndex; /* if >0, constraint is part of argv to xFilter */ - unsigned char omit; /* Do not code a test for this constraint */ - } *aConstraintUsage; - int idxNum; /* Number used to identify the index */ - char *idxStr; /* String, possibly obtained from sqlite3_malloc */ - int needToFreeIdxStr; /* Free idxStr using sqlite3_free() if true */ - int orderByConsumed; /* True if output is already ordered */ - double estimatedCost; /* Estimated cost of using this index */ - /* Fields below are only available in SQLite 3.8.2 and later */ - sqlite3_int64 estimatedRows; /* Estimated number of rows returned */ - /* Fields below are only available in SQLite 3.9.0 and later */ - int idxFlags; /* Mask of SQLITE_INDEX_SCAN_* flags */ - /* Fields below are only available in SQLite 3.10.0 and later */ - sqlite3_uint64 colUsed; /* Input: Mask of columns used by statement */ + /* Inputs */ + int nConstraint; /* Number of entries in aConstraint */ + struct sqlite3_index_constraint { + int iColumn; /* Column constrained. -1 for ROWID */ + unsigned char op; /* Constraint operator */ + unsigned char usable; /* True if this constraint is usable */ + int iTermOffset; /* Used internally - xBestIndex should ignore */ + } *aConstraint; /* Table of WHERE clause constraints */ + int nOrderBy; /* Number of terms in the ORDER BY clause */ + struct sqlite3_index_orderby { + int iColumn; /* Column number */ + unsigned char desc; /* True for DESC. False for ASC. */ + } *aOrderBy; /* The ORDER BY clause */ + /* Outputs */ + struct sqlite3_index_constraint_usage { + int argvIndex; /* if >0, constraint is part of argv to xFilter */ + unsigned char omit; /* Do not code a test for this constraint */ + } *aConstraintUsage; + int idxNum; /* Number used to identify the index */ + char *idxStr; /* String, possibly obtained from sqlite3_malloc */ + int needToFreeIdxStr; /* Free idxStr using sqlite3_free() if true */ + int orderByConsumed; /* True if output is already ordered */ + double estimatedCost; /* Estimated cost of using this index */ + /* Fields below are only available in SQLite 3.8.2 and later */ + sqlite3_int64 estimatedRows; /* Estimated number of rows returned */ + /* Fields below are only available in SQLite 3.9.0 and later */ + int idxFlags; /* Mask of SQLITE_INDEX_SCAN_* flags */ + /* Fields below are only available in SQLite 3.10.0 and later */ + sqlite3_uint64 colUsed; /* Input: Mask of columns used by statement */ }; /* @@ -7217,7 +7162,7 @@ struct sqlite3_index_info { ** [sqlite3_index_info].idxFlags field to some combination of ** these bits. */ -#define SQLITE_INDEX_SCAN_UNIQUE 1 /* Scan visits at most 1 row */ +#define SQLITE_INDEX_SCAN_UNIQUE 1 /* Scan visits at most 1 row */ /* ** CAPI3REF: Virtual Table Constraint Operator Codes @@ -7257,22 +7202,22 @@ struct sqlite3_index_info { ** because the constraints are numeric) and so the sqlite3_vtab_collation() ** interface is no commonly needed. */ -#define SQLITE_INDEX_CONSTRAINT_EQ 2 -#define SQLITE_INDEX_CONSTRAINT_GT 4 -#define SQLITE_INDEX_CONSTRAINT_LE 8 -#define SQLITE_INDEX_CONSTRAINT_LT 16 -#define SQLITE_INDEX_CONSTRAINT_GE 32 -#define SQLITE_INDEX_CONSTRAINT_MATCH 64 -#define SQLITE_INDEX_CONSTRAINT_LIKE 65 -#define SQLITE_INDEX_CONSTRAINT_GLOB 66 -#define SQLITE_INDEX_CONSTRAINT_REGEXP 67 -#define SQLITE_INDEX_CONSTRAINT_NE 68 -#define SQLITE_INDEX_CONSTRAINT_ISNOT 69 -#define SQLITE_INDEX_CONSTRAINT_ISNOTNULL 70 -#define SQLITE_INDEX_CONSTRAINT_ISNULL 71 -#define SQLITE_INDEX_CONSTRAINT_IS 72 -#define SQLITE_INDEX_CONSTRAINT_LIMIT 73 -#define SQLITE_INDEX_CONSTRAINT_OFFSET 74 +#define SQLITE_INDEX_CONSTRAINT_EQ 2 +#define SQLITE_INDEX_CONSTRAINT_GT 4 +#define SQLITE_INDEX_CONSTRAINT_LE 8 +#define SQLITE_INDEX_CONSTRAINT_LT 16 +#define SQLITE_INDEX_CONSTRAINT_GE 32 +#define SQLITE_INDEX_CONSTRAINT_MATCH 64 +#define SQLITE_INDEX_CONSTRAINT_LIKE 65 +#define SQLITE_INDEX_CONSTRAINT_GLOB 66 +#define SQLITE_INDEX_CONSTRAINT_REGEXP 67 +#define SQLITE_INDEX_CONSTRAINT_NE 68 +#define SQLITE_INDEX_CONSTRAINT_ISNOT 69 +#define SQLITE_INDEX_CONSTRAINT_ISNOTNULL 70 +#define SQLITE_INDEX_CONSTRAINT_ISNULL 71 +#define SQLITE_INDEX_CONSTRAINT_IS 72 +#define SQLITE_INDEX_CONSTRAINT_LIMIT 73 +#define SQLITE_INDEX_CONSTRAINT_OFFSET 74 #define SQLITE_INDEX_CONSTRAINT_FUNCTION 150 /* @@ -7307,18 +7252,16 @@ struct sqlite3_index_info { ** ** See also: [sqlite3_drop_modules()] */ -SQLITE_API int sqlite3_create_module( - sqlite3 *db, /* SQLite connection to register module with */ - const char *zName, /* Name of the module */ - const sqlite3_module *p, /* Methods for the module */ - void *pClientData /* Client data for xCreate/xConnect */ +SQLITE_API int sqlite3_create_module(sqlite3 *db, /* SQLite connection to register module with */ + const char *zName, /* Name of the module */ + const sqlite3_module *p, /* Methods for the module */ + void *pClientData /* Client data for xCreate/xConnect */ ); -SQLITE_API int sqlite3_create_module_v2( - sqlite3 *db, /* SQLite connection to register module with */ - const char *zName, /* Name of the module */ - const sqlite3_module *p, /* Methods for the module */ - void *pClientData, /* Client data for xCreate/xConnect */ - void(*xDestroy)(void*) /* Module destructor function */ +SQLITE_API int sqlite3_create_module_v2(sqlite3 *db, /* SQLite connection to register module with */ + const char *zName, /* Name of the module */ + const sqlite3_module *p, /* Methods for the module */ + void *pClientData, /* Client data for xCreate/xConnect */ + void (*xDestroy)(void *) /* Module destructor function */ ); /* @@ -7333,9 +7276,8 @@ SQLITE_API int sqlite3_create_module_v2( ** ** See also: [sqlite3_create_module()] */ -SQLITE_API int sqlite3_drop_modules( - sqlite3 *db, /* Remove modules from this connection */ - const char **azKeep /* Except, do not remove the ones named here */ +SQLITE_API int sqlite3_drop_modules(sqlite3 *db, /* Remove modules from this connection */ + const char **azKeep /* Except, do not remove the ones named here */ ); /* @@ -7357,10 +7299,10 @@ SQLITE_API int sqlite3_drop_modules( ** freed by sqlite3_free() and the zErrMsg field will be zeroed. */ struct sqlite3_vtab { - const sqlite3_module *pModule; /* The module for this virtual table */ - int nRef; /* Number of open cursors */ - char *zErrMsg; /* Error message from sqlite3_mprintf() */ - /* Virtual table implementations will typically add additional fields */ + const sqlite3_module *pModule; /* The module for this virtual table */ + int nRef; /* Number of open cursors */ + char *zErrMsg; /* Error message from sqlite3_mprintf() */ + /* Virtual table implementations will typically add additional fields */ }; /* @@ -7381,8 +7323,8 @@ struct sqlite3_vtab { ** are common to all implementations. */ struct sqlite3_vtab_cursor { - sqlite3_vtab *pVtab; /* Virtual table of this cursor */ - /* Virtual table implementations will typically add additional fields */ + sqlite3_vtab *pVtab; /* Virtual table of this cursor */ + /* Virtual table implementations will typically add additional fields */ }; /* @@ -7393,7 +7335,7 @@ struct sqlite3_vtab_cursor { ** to declare the format (the names and datatypes of the columns) of ** the virtual tables they implement. */ -SQLITE_API int sqlite3_declare_vtab(sqlite3*, const char *zSQL); +SQLITE_API int sqlite3_declare_vtab(sqlite3 *, const char *zSQL); /* ** CAPI3REF: Overload A Function For A Virtual Table @@ -7412,7 +7354,7 @@ SQLITE_API int sqlite3_declare_vtab(sqlite3*, const char *zSQL); ** purpose is to be a placeholder function that can be overloaded ** by a [virtual table]. */ -SQLITE_API int sqlite3_overload_function(sqlite3*, const char *zFuncName, int nArg); +SQLITE_API int sqlite3_overload_function(sqlite3 *, const char *zFuncName, int nArg); /* ** The interface to the virtual-table mechanism defined above (back up @@ -7521,15 +7463,13 @@ typedef struct sqlite3_blob sqlite3_blob; ** [sqlite3_blob_reopen()], [sqlite3_blob_read()], ** [sqlite3_blob_bytes()], [sqlite3_blob_write()]. */ -SQLITE_API int sqlite3_blob_open( - sqlite3*, - const char *zDb, - const char *zTable, - const char *zColumn, - sqlite3_int64 iRow, - int flags, - sqlite3_blob **ppBlob -); +SQLITE_API int sqlite3_blob_open(sqlite3 *, + const char *zDb, + const char *zTable, + const char *zColumn, + sqlite3_int64 iRow, + int flags, + sqlite3_blob **ppBlob); /* ** CAPI3REF: Move a BLOB Handle to a New Row @@ -7696,8 +7636,8 @@ SQLITE_API int sqlite3_blob_write(sqlite3_blob *, const void *z, int n, int iOff ** the default. The choice for the new VFS is arbitrary.)^ */ SQLITE_API sqlite3_vfs *sqlite3_vfs_find(const char *zVfsName); -SQLITE_API int sqlite3_vfs_register(sqlite3_vfs*, int makeDflt); -SQLITE_API int sqlite3_vfs_unregister(sqlite3_vfs*); +SQLITE_API int sqlite3_vfs_register(sqlite3_vfs *, int makeDflt); +SQLITE_API int sqlite3_vfs_unregister(sqlite3_vfs *); /* ** CAPI3REF: Mutexes @@ -7814,10 +7754,10 @@ SQLITE_API int sqlite3_vfs_unregister(sqlite3_vfs*); ** See also: [sqlite3_mutex_held()] and [sqlite3_mutex_notheld()]. */ SQLITE_API sqlite3_mutex *sqlite3_mutex_alloc(int); -SQLITE_API void sqlite3_mutex_free(sqlite3_mutex*); -SQLITE_API void sqlite3_mutex_enter(sqlite3_mutex*); -SQLITE_API int sqlite3_mutex_try(sqlite3_mutex*); -SQLITE_API void sqlite3_mutex_leave(sqlite3_mutex*); +SQLITE_API void sqlite3_mutex_free(sqlite3_mutex *); +SQLITE_API void sqlite3_mutex_enter(sqlite3_mutex *); +SQLITE_API int sqlite3_mutex_try(sqlite3_mutex *); +SQLITE_API void sqlite3_mutex_leave(sqlite3_mutex *); /* ** CAPI3REF: Mutex Methods Object @@ -7886,15 +7826,15 @@ SQLITE_API void sqlite3_mutex_leave(sqlite3_mutex*); */ typedef struct sqlite3_mutex_methods sqlite3_mutex_methods; struct sqlite3_mutex_methods { - int (*xMutexInit)(void); - int (*xMutexEnd)(void); - sqlite3_mutex *(*xMutexAlloc)(int); - void (*xMutexFree)(sqlite3_mutex *); - void (*xMutexEnter)(sqlite3_mutex *); - int (*xMutexTry)(sqlite3_mutex *); - void (*xMutexLeave)(sqlite3_mutex *); - int (*xMutexHeld)(sqlite3_mutex *); - int (*xMutexNotheld)(sqlite3_mutex *); + int (*xMutexInit)(void); + int (*xMutexEnd)(void); + sqlite3_mutex *(*xMutexAlloc)(int); + void (*xMutexFree)(sqlite3_mutex *); + void (*xMutexEnter)(sqlite3_mutex *); + int (*xMutexTry)(sqlite3_mutex *); + void (*xMutexLeave)(sqlite3_mutex *); + int (*xMutexHeld)(sqlite3_mutex *); + int (*xMutexNotheld)(sqlite3_mutex *); }; /* @@ -7927,8 +7867,8 @@ struct sqlite3_mutex_methods { ** interface should also return 1 when given a NULL pointer. */ #ifndef NDEBUG -SQLITE_API int sqlite3_mutex_held(sqlite3_mutex*); -SQLITE_API int sqlite3_mutex_notheld(sqlite3_mutex*); +SQLITE_API int sqlite3_mutex_held(sqlite3_mutex *); +SQLITE_API int sqlite3_mutex_notheld(sqlite3_mutex *); #endif /* @@ -7941,26 +7881,25 @@ SQLITE_API int sqlite3_mutex_notheld(sqlite3_mutex*); ** next. Applications that override the built-in mutex logic must be ** prepared to accommodate additional static mutexes. */ -#define SQLITE_MUTEX_FAST 0 -#define SQLITE_MUTEX_RECURSIVE 1 -#define SQLITE_MUTEX_STATIC_MAIN 2 -#define SQLITE_MUTEX_STATIC_MEM 3 /* sqlite3_malloc() */ -#define SQLITE_MUTEX_STATIC_MEM2 4 /* NOT USED */ -#define SQLITE_MUTEX_STATIC_OPEN 4 /* sqlite3BtreeOpen() */ -#define SQLITE_MUTEX_STATIC_PRNG 5 /* sqlite3_randomness() */ -#define SQLITE_MUTEX_STATIC_LRU 6 /* lru page list */ -#define SQLITE_MUTEX_STATIC_LRU2 7 /* NOT USED */ -#define SQLITE_MUTEX_STATIC_PMEM 7 /* sqlite3PageMalloc() */ -#define SQLITE_MUTEX_STATIC_APP1 8 /* For use by application */ -#define SQLITE_MUTEX_STATIC_APP2 9 /* For use by application */ -#define SQLITE_MUTEX_STATIC_APP3 10 /* For use by application */ -#define SQLITE_MUTEX_STATIC_VFS1 11 /* For use by built-in VFS */ -#define SQLITE_MUTEX_STATIC_VFS2 12 /* For use by extension VFS */ -#define SQLITE_MUTEX_STATIC_VFS3 13 /* For use by application VFS */ +#define SQLITE_MUTEX_FAST 0 +#define SQLITE_MUTEX_RECURSIVE 1 +#define SQLITE_MUTEX_STATIC_MAIN 2 +#define SQLITE_MUTEX_STATIC_MEM 3 /* sqlite3_malloc() */ +#define SQLITE_MUTEX_STATIC_MEM2 4 /* NOT USED */ +#define SQLITE_MUTEX_STATIC_OPEN 4 /* sqlite3BtreeOpen() */ +#define SQLITE_MUTEX_STATIC_PRNG 5 /* sqlite3_randomness() */ +#define SQLITE_MUTEX_STATIC_LRU 6 /* lru page list */ +#define SQLITE_MUTEX_STATIC_LRU2 7 /* NOT USED */ +#define SQLITE_MUTEX_STATIC_PMEM 7 /* sqlite3PageMalloc() */ +#define SQLITE_MUTEX_STATIC_APP1 8 /* For use by application */ +#define SQLITE_MUTEX_STATIC_APP2 9 /* For use by application */ +#define SQLITE_MUTEX_STATIC_APP3 10 /* For use by application */ +#define SQLITE_MUTEX_STATIC_VFS1 11 /* For use by built-in VFS */ +#define SQLITE_MUTEX_STATIC_VFS2 12 /* For use by extension VFS */ +#define SQLITE_MUTEX_STATIC_VFS3 13 /* For use by application VFS */ /* Legacy compatibility: */ -#define SQLITE_MUTEX_STATIC_MASTER 2 - +#define SQLITE_MUTEX_STATIC_MASTER 2 /* ** CAPI3REF: Retrieve the mutex for a sqlitecipher connection @@ -7972,7 +7911,7 @@ SQLITE_API int sqlite3_mutex_notheld(sqlite3_mutex*); ** ^If the [threading mode] is Single-thread or Multi-thread then this ** routine returns a NULL pointer. */ -SQLITE_API sqlite3_mutex *sqlite3_db_mutex(sqlite3*); +SQLITE_API sqlite3_mutex *sqlite3_db_mutex(sqlite3 *); /* ** CAPI3REF: Low-Level Control Of Database Files @@ -8015,7 +7954,7 @@ SQLITE_API sqlite3_mutex *sqlite3_db_mutex(sqlite3*); ** ** See also: [file control opcodes] */ -SQLITE_API int sqlite3_file_control(sqlite3*, const char *zDbName, int op, void*); +SQLITE_API int sqlite3_file_control(sqlite3 *, const char *zDbName, int op, void *); /* ** CAPI3REF: Testing Interface @@ -8047,39 +7986,39 @@ SQLITE_API int sqlite3_test_control(int op, ...); ** Applications should not use any of these parameters or the ** [sqlite3_test_control()] interface. */ -#define SQLITE_TESTCTRL_FIRST 5 -#define SQLITE_TESTCTRL_PRNG_SAVE 5 -#define SQLITE_TESTCTRL_PRNG_RESTORE 6 -#define SQLITE_TESTCTRL_PRNG_RESET 7 /* NOT USED */ -#define SQLITE_TESTCTRL_BITVEC_TEST 8 -#define SQLITE_TESTCTRL_FAULT_INSTALL 9 -#define SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS 10 -#define SQLITE_TESTCTRL_PENDING_BYTE 11 -#define SQLITE_TESTCTRL_ASSERT 12 -#define SQLITE_TESTCTRL_ALWAYS 13 -#define SQLITE_TESTCTRL_RESERVE 14 /* NOT USED */ -#define SQLITE_TESTCTRL_OPTIMIZATIONS 15 -#define SQLITE_TESTCTRL_ISKEYWORD 16 /* NOT USED */ -#define SQLITE_TESTCTRL_SCRATCHMALLOC 17 /* NOT USED */ -#define SQLITE_TESTCTRL_INTERNAL_FUNCTIONS 17 -#define SQLITE_TESTCTRL_LOCALTIME_FAULT 18 -#define SQLITE_TESTCTRL_EXPLAIN_STMT 19 /* NOT USED */ -#define SQLITE_TESTCTRL_ONCE_RESET_THRESHOLD 19 -#define SQLITE_TESTCTRL_NEVER_CORRUPT 20 -#define SQLITE_TESTCTRL_VDBE_COVERAGE 21 -#define SQLITE_TESTCTRL_BYTEORDER 22 -#define SQLITE_TESTCTRL_ISINIT 23 -#define SQLITE_TESTCTRL_SORTER_MMAP 24 -#define SQLITE_TESTCTRL_IMPOSTER 25 -#define SQLITE_TESTCTRL_PARSER_COVERAGE 26 -#define SQLITE_TESTCTRL_RESULT_INTREAL 27 -#define SQLITE_TESTCTRL_PRNG_SEED 28 -#define SQLITE_TESTCTRL_EXTRA_SCHEMA_CHECKS 29 -#define SQLITE_TESTCTRL_SEEK_COUNT 30 -#define SQLITE_TESTCTRL_TRACEFLAGS 31 -#define SQLITE_TESTCTRL_TUNE 32 -#define SQLITE_TESTCTRL_LOGEST 33 -#define SQLITE_TESTCTRL_LAST 33 /* Largest TESTCTRL */ +#define SQLITE_TESTCTRL_FIRST 5 +#define SQLITE_TESTCTRL_PRNG_SAVE 5 +#define SQLITE_TESTCTRL_PRNG_RESTORE 6 +#define SQLITE_TESTCTRL_PRNG_RESET 7 /* NOT USED */ +#define SQLITE_TESTCTRL_BITVEC_TEST 8 +#define SQLITE_TESTCTRL_FAULT_INSTALL 9 +#define SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS 10 +#define SQLITE_TESTCTRL_PENDING_BYTE 11 +#define SQLITE_TESTCTRL_ASSERT 12 +#define SQLITE_TESTCTRL_ALWAYS 13 +#define SQLITE_TESTCTRL_RESERVE 14 /* NOT USED */ +#define SQLITE_TESTCTRL_OPTIMIZATIONS 15 +#define SQLITE_TESTCTRL_ISKEYWORD 16 /* NOT USED */ +#define SQLITE_TESTCTRL_SCRATCHMALLOC 17 /* NOT USED */ +#define SQLITE_TESTCTRL_INTERNAL_FUNCTIONS 17 +#define SQLITE_TESTCTRL_LOCALTIME_FAULT 18 +#define SQLITE_TESTCTRL_EXPLAIN_STMT 19 /* NOT USED */ +#define SQLITE_TESTCTRL_ONCE_RESET_THRESHOLD 19 +#define SQLITE_TESTCTRL_NEVER_CORRUPT 20 +#define SQLITE_TESTCTRL_VDBE_COVERAGE 21 +#define SQLITE_TESTCTRL_BYTEORDER 22 +#define SQLITE_TESTCTRL_ISINIT 23 +#define SQLITE_TESTCTRL_SORTER_MMAP 24 +#define SQLITE_TESTCTRL_IMPOSTER 25 +#define SQLITE_TESTCTRL_PARSER_COVERAGE 26 +#define SQLITE_TESTCTRL_RESULT_INTREAL 27 +#define SQLITE_TESTCTRL_PRNG_SEED 28 +#define SQLITE_TESTCTRL_EXTRA_SCHEMA_CHECKS 29 +#define SQLITE_TESTCTRL_SEEK_COUNT 30 +#define SQLITE_TESTCTRL_TRACEFLAGS 31 +#define SQLITE_TESTCTRL_TUNE 32 +#define SQLITE_TESTCTRL_LOGEST 33 +#define SQLITE_TESTCTRL_LAST 33 /* Largest TESTCTRL */ /* ** CAPI3REF: SQL Keyword Checking @@ -8129,8 +8068,8 @@ SQLITE_API int sqlite3_test_control(int op, ...); ** new keywords may be added to future releases of SQLite. */ SQLITE_API int sqlite3_keyword_count(void); -SQLITE_API int sqlite3_keyword_name(int,const char**,int*); -SQLITE_API int sqlite3_keyword_check(const char*,int); +SQLITE_API int sqlite3_keyword_name(int, const char **, int *); +SQLITE_API int sqlite3_keyword_check(const char *, int); /* ** CAPI3REF: Dynamic String Object @@ -8175,7 +8114,7 @@ typedef struct sqlite3_str sqlite3_str; ** the value set for [sqlite3_limit](D,[SQLITE_LIMIT_LENGTH]) instead ** of [SQLITE_MAX_LENGTH]. */ -SQLITE_API sqlite3_str *sqlite3_str_new(sqlite3*); +SQLITE_API sqlite3_str *sqlite3_str_new(sqlite3 *); /* ** CAPI3REF: Finalize A Dynamic String @@ -8190,7 +8129,7 @@ SQLITE_API sqlite3_str *sqlite3_str_new(sqlite3*); ** [sqlite3_str_finish(X)] interface will also return a NULL pointer if the ** string in [sqlite3_str] object X is zero bytes long. */ -SQLITE_API char *sqlite3_str_finish(sqlite3_str*); +SQLITE_API char *sqlite3_str_finish(sqlite3_str *); /* ** CAPI3REF: Add Content To A Dynamic String @@ -8224,12 +8163,12 @@ SQLITE_API char *sqlite3_str_finish(sqlite3_str*); ** is recorded in the [sqlite3_str] object and can be recovered by a ** subsequent call to [sqlite3_str_errcode(X)]. */ -SQLITE_API void sqlite3_str_appendf(sqlite3_str*, const char *zFormat, ...); -SQLITE_API void sqlite3_str_vappendf(sqlite3_str*, const char *zFormat, va_list); -SQLITE_API void sqlite3_str_append(sqlite3_str*, const char *zIn, int N); -SQLITE_API void sqlite3_str_appendall(sqlite3_str*, const char *zIn); -SQLITE_API void sqlite3_str_appendchar(sqlite3_str*, int N, char C); -SQLITE_API void sqlite3_str_reset(sqlite3_str*); +SQLITE_API void sqlite3_str_appendf(sqlite3_str *, const char *zFormat, ...); +SQLITE_API void sqlite3_str_vappendf(sqlite3_str *, const char *zFormat, va_list); +SQLITE_API void sqlite3_str_append(sqlite3_str *, const char *zIn, int N); +SQLITE_API void sqlite3_str_appendall(sqlite3_str *, const char *zIn); +SQLITE_API void sqlite3_str_appendchar(sqlite3_str *, int N, char C); +SQLITE_API void sqlite3_str_reset(sqlite3_str *); /* ** CAPI3REF: Status Of A Dynamic String @@ -8260,9 +8199,9 @@ SQLITE_API void sqlite3_str_reset(sqlite3_str*); ** outside the range of 0 to [sqlite3_str_length(X)] and do not read or ** write any byte after any subsequent sqlite3_str method call. */ -SQLITE_API int sqlite3_str_errcode(sqlite3_str*); -SQLITE_API int sqlite3_str_length(sqlite3_str*); -SQLITE_API char *sqlite3_str_value(sqlite3_str*); +SQLITE_API int sqlite3_str_errcode(sqlite3_str *); +SQLITE_API int sqlite3_str_length(sqlite3_str *); +SQLITE_API char *sqlite3_str_value(sqlite3_str *); /* ** CAPI3REF: SQLite Runtime Status @@ -8291,13 +8230,7 @@ SQLITE_API char *sqlite3_str_value(sqlite3_str*); ** See also: [sqlite3_db_status()] */ SQLITE_API int sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetFlag); -SQLITE_API int sqlite3_status64( - int op, - sqlite3_int64 *pCurrent, - sqlite3_int64 *pHighwater, - int resetFlag -); - +SQLITE_API int sqlite3_status64(int op, sqlite3_int64 *pCurrent, sqlite3_int64 *pHighwater, int resetFlag); /* ** CAPI3REF: Status Parameters @@ -8366,16 +8299,16 @@ SQLITE_API int sqlite3_status64( ** ** New status parameters may be added from time to time. */ -#define SQLITE_STATUS_MEMORY_USED 0 -#define SQLITE_STATUS_PAGECACHE_USED 1 -#define SQLITE_STATUS_PAGECACHE_OVERFLOW 2 -#define SQLITE_STATUS_SCRATCH_USED 3 /* NOT USED */ -#define SQLITE_STATUS_SCRATCH_OVERFLOW 4 /* NOT USED */ -#define SQLITE_STATUS_MALLOC_SIZE 5 -#define SQLITE_STATUS_PARSER_STACK 6 -#define SQLITE_STATUS_PAGECACHE_SIZE 7 -#define SQLITE_STATUS_SCRATCH_SIZE 8 /* NOT USED */ -#define SQLITE_STATUS_MALLOC_COUNT 9 +#define SQLITE_STATUS_MEMORY_USED 0 +#define SQLITE_STATUS_PAGECACHE_USED 1 +#define SQLITE_STATUS_PAGECACHE_OVERFLOW 2 +#define SQLITE_STATUS_SCRATCH_USED 3 /* NOT USED */ +#define SQLITE_STATUS_SCRATCH_OVERFLOW 4 /* NOT USED */ +#define SQLITE_STATUS_MALLOC_SIZE 5 +#define SQLITE_STATUS_PARSER_STACK 6 +#define SQLITE_STATUS_PAGECACHE_SIZE 7 +#define SQLITE_STATUS_SCRATCH_SIZE 8 /* NOT USED */ +#define SQLITE_STATUS_MALLOC_COUNT 9 /* ** CAPI3REF: Database Connection Status @@ -8400,7 +8333,7 @@ SQLITE_API int sqlite3_status64( ** ** See also: [sqlite3_status()] and [sqlite3_stmt_status()]. */ -SQLITE_API int sqlite3_db_status(sqlite3*, int op, int *pCur, int *pHiwtr, int resetFlg); +SQLITE_API int sqlite3_db_status(sqlite3 *, int op, int *pCur, int *pHiwtr, int resetFlg); /* ** CAPI3REF: Status Parameters for sqlitecipher connections @@ -8513,21 +8446,20 @@ SQLITE_API int sqlite3_db_status(sqlite3*, int op, int *pCur, int *pHiwtr, int r ** ** */ -#define SQLITE_DBSTATUS_LOOKASIDE_USED 0 -#define SQLITE_DBSTATUS_CACHE_USED 1 -#define SQLITE_DBSTATUS_SCHEMA_USED 2 -#define SQLITE_DBSTATUS_STMT_USED 3 -#define SQLITE_DBSTATUS_LOOKASIDE_HIT 4 -#define SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE 5 -#define SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL 6 -#define SQLITE_DBSTATUS_CACHE_HIT 7 -#define SQLITE_DBSTATUS_CACHE_MISS 8 -#define SQLITE_DBSTATUS_CACHE_WRITE 9 +#define SQLITE_DBSTATUS_LOOKASIDE_USED 0 +#define SQLITE_DBSTATUS_CACHE_USED 1 +#define SQLITE_DBSTATUS_SCHEMA_USED 2 +#define SQLITE_DBSTATUS_STMT_USED 3 +#define SQLITE_DBSTATUS_LOOKASIDE_HIT 4 +#define SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE 5 +#define SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL 6 +#define SQLITE_DBSTATUS_CACHE_HIT 7 +#define SQLITE_DBSTATUS_CACHE_MISS 8 +#define SQLITE_DBSTATUS_CACHE_WRITE 9 #define SQLITE_DBSTATUS_DEFERRED_FKS 10 #define SQLITE_DBSTATUS_CACHE_USED_SHARED 11 #define SQLITE_DBSTATUS_CACHE_SPILL 12 -#define SQLITE_DBSTATUS_MAX 12 /* Largest defined DBSTATUS */ - +#define SQLITE_DBSTATUS_MAX 12 /* Largest defined DBSTATUS */ /* ** CAPI3REF: Prepared Statement Status @@ -8553,7 +8485,7 @@ SQLITE_API int sqlite3_db_status(sqlite3*, int op, int *pCur, int *pHiwtr, int r ** ** See also: [sqlite3_status()] and [sqlite3_db_status()]. */ -SQLITE_API int sqlite3_stmt_status(sqlite3_stmt*, int op,int resetFlg); +SQLITE_API int sqlite3_stmt_status(sqlite3_stmt *, int op, int resetFlg); /* ** CAPI3REF: Status Parameters for prepared statements @@ -8620,15 +8552,15 @@ SQLITE_API int sqlite3_stmt_status(sqlite3_stmt*, int op,int resetFlg); ** ** */ -#define SQLITE_STMTSTATUS_FULLSCAN_STEP 1 -#define SQLITE_STMTSTATUS_SORT 2 -#define SQLITE_STMTSTATUS_AUTOINDEX 3 -#define SQLITE_STMTSTATUS_VM_STEP 4 -#define SQLITE_STMTSTATUS_REPREPARE 5 -#define SQLITE_STMTSTATUS_RUN 6 -#define SQLITE_STMTSTATUS_FILTER_MISS 7 -#define SQLITE_STMTSTATUS_FILTER_HIT 8 -#define SQLITE_STMTSTATUS_MEMUSED 99 +#define SQLITE_STMTSTATUS_FULLSCAN_STEP 1 +#define SQLITE_STMTSTATUS_SORT 2 +#define SQLITE_STMTSTATUS_AUTOINDEX 3 +#define SQLITE_STMTSTATUS_VM_STEP 4 +#define SQLITE_STMTSTATUS_REPREPARE 5 +#define SQLITE_STMTSTATUS_RUN 6 +#define SQLITE_STMTSTATUS_FILTER_MISS 7 +#define SQLITE_STMTSTATUS_FILTER_HIT 8 +#define SQLITE_STMTSTATUS_MEMUSED 99 /* ** CAPI3REF: Custom Page Cache Object @@ -8655,8 +8587,8 @@ typedef struct sqlite3_pcache sqlite3_pcache; */ typedef struct sqlite3_pcache_page sqlite3_pcache_page; struct sqlite3_pcache_page { - void *pBuf; /* The content of the page */ - void *pExtra; /* Extra information associated with the page */ + void *pBuf; /* The content of the page */ + void *pExtra; /* Extra information associated with the page */ }; /* @@ -8820,20 +8752,19 @@ struct sqlite3_pcache_page { */ typedef struct sqlite3_pcache_methods2 sqlite3_pcache_methods2; struct sqlite3_pcache_methods2 { - int iVersion; - void *pArg; - int (*xInit)(void*); - void (*xShutdown)(void*); - sqlite3_pcache *(*xCreate)(int szPage, int szExtra, int bPurgeable); - void (*xCachesize)(sqlite3_pcache*, int nCachesize); - int (*xPagecount)(sqlite3_pcache*); - sqlite3_pcache_page *(*xFetch)(sqlite3_pcache*, unsigned key, int createFlag); - void (*xUnpin)(sqlite3_pcache*, sqlite3_pcache_page*, int discard); - void (*xRekey)(sqlite3_pcache*, sqlite3_pcache_page*, - unsigned oldKey, unsigned newKey); - void (*xTruncate)(sqlite3_pcache*, unsigned iLimit); - void (*xDestroy)(sqlite3_pcache*); - void (*xShrink)(sqlite3_pcache*); + int iVersion; + void *pArg; + int (*xInit)(void *); + void (*xShutdown)(void *); + sqlite3_pcache *(*xCreate)(int szPage, int szExtra, int bPurgeable); + void (*xCachesize)(sqlite3_pcache *, int nCachesize); + int (*xPagecount)(sqlite3_pcache *); + sqlite3_pcache_page *(*xFetch)(sqlite3_pcache *, unsigned key, int createFlag); + void (*xUnpin)(sqlite3_pcache *, sqlite3_pcache_page *, int discard); + void (*xRekey)(sqlite3_pcache *, sqlite3_pcache_page *, unsigned oldKey, unsigned newKey); + void (*xTruncate)(sqlite3_pcache *, unsigned iLimit); + void (*xDestroy)(sqlite3_pcache *); + void (*xShrink)(sqlite3_pcache *); }; /* @@ -8843,20 +8774,19 @@ struct sqlite3_pcache_methods2 { */ typedef struct sqlite3_pcache_methods sqlite3_pcache_methods; struct sqlite3_pcache_methods { - void *pArg; - int (*xInit)(void*); - void (*xShutdown)(void*); - sqlite3_pcache *(*xCreate)(int szPage, int bPurgeable); - void (*xCachesize)(sqlite3_pcache*, int nCachesize); - int (*xPagecount)(sqlite3_pcache*); - void *(*xFetch)(sqlite3_pcache*, unsigned key, int createFlag); - void (*xUnpin)(sqlite3_pcache*, void*, int discard); - void (*xRekey)(sqlite3_pcache*, void*, unsigned oldKey, unsigned newKey); - void (*xTruncate)(sqlite3_pcache*, unsigned iLimit); - void (*xDestroy)(sqlite3_pcache*); + void *pArg; + int (*xInit)(void *); + void (*xShutdown)(void *); + sqlite3_pcache *(*xCreate)(int szPage, int bPurgeable); + void (*xCachesize)(sqlite3_pcache *, int nCachesize); + int (*xPagecount)(sqlite3_pcache *); + void *(*xFetch)(sqlite3_pcache *, unsigned key, int createFlag); + void (*xUnpin)(sqlite3_pcache *, void *, int discard); + void (*xRekey)(sqlite3_pcache *, void *, unsigned oldKey, unsigned newKey); + void (*xTruncate)(sqlite3_pcache *, unsigned iLimit); + void (*xDestroy)(sqlite3_pcache *); }; - /* ** CAPI3REF: Online Backup Object ** @@ -9055,16 +8985,15 @@ typedef struct sqlite3_backup sqlite3_backup; ** same time as another thread is invoking sqlite3_backup_step() it is ** possible that they return invalid values. */ -SQLITE_API sqlite3_backup *sqlite3_backup_init( - sqlite3 *pDest, /* Destination sqlitecipher handle */ - const char *zDestName, /* Destination sqlitecipher name */ - sqlite3 *pSource, /* Source sqlitecipher handle */ - const char *zSourceName /* Source sqlitecipher name */ +SQLITE_API sqlite3_backup *sqlite3_backup_init(sqlite3 *pDest, /* Destination sqlitecipher handle */ + const char *zDestName, /* Destination sqlitecipher name */ + sqlite3 *pSource, /* Source sqlitecipher handle */ + const char *zSourceName /* Source sqlitecipher name */ ); -SQLITE_API int sqlite3_backup_step(sqlite3_backup *p, int nPage); -SQLITE_API int sqlite3_backup_finish(sqlite3_backup *p); -SQLITE_API int sqlite3_backup_remaining(sqlite3_backup *p); -SQLITE_API int sqlite3_backup_pagecount(sqlite3_backup *p); +SQLITE_API int sqlite3_backup_step(sqlite3_backup *p, int nPage); +SQLITE_API int sqlite3_backup_finish(sqlite3_backup *p); +SQLITE_API int sqlite3_backup_remaining(sqlite3_backup *p); +SQLITE_API int sqlite3_backup_pagecount(sqlite3_backup *p); /* ** CAPI3REF: Unlock Notification @@ -9181,13 +9110,11 @@ SQLITE_API int sqlite3_backup_pagecount(sqlite3_backup *p); ** the special "DROP TABLE/INDEX" case, the extended error code is just ** SQLITE_LOCKED.)^ */ -SQLITE_API int sqlite3_unlock_notify( - sqlite3 *pBlocked, /* Waiting connection */ - void (*xNotify)(void **apArg, int nArg), /* Callback function to invoke */ - void *pNotifyArg /* Argument to pass to xNotify */ +SQLITE_API int sqlite3_unlock_notify(sqlite3 *pBlocked, /* Waiting connection */ + void (*xNotify)(void **apArg, int nArg), /* Callback function to invoke */ + void *pNotifyArg /* Argument to pass to xNotify */ ); - /* ** CAPI3REF: String Comparison ** @@ -9297,11 +9224,7 @@ SQLITE_API void sqlite3_log(int iErrCode, const char *zFormat, ...); ** [wal_autocheckpoint pragma] both invoke [sqlite3_wal_hook()] and will ** overwrite any prior [sqlite3_wal_hook()] settings. */ -SQLITE_API void *sqlite3_wal_hook( - sqlite3*, - int(*)(void *,sqlite3*,const char*,int), - void* -); +SQLITE_API void *sqlite3_wal_hook(sqlite3 *, int (*)(void *, sqlite3 *, const char *, int), void *); /* ** CAPI3REF: Configure an auto-checkpoint @@ -9448,12 +9371,11 @@ SQLITE_API int sqlite3_wal_checkpoint(sqlite3 *db, const char *zDb); ** ^The [PRAGMA wal_checkpoint] command can be used to invoke this interface ** from SQL. */ -SQLITE_API int sqlite3_wal_checkpoint_v2( - sqlite3 *db, /* Database handle */ - const char *zDb, /* Name of attached sqlitecipher (or NULL) */ - int eMode, /* SQLITE_CHECKPOINT_* value */ - int *pnLog, /* OUT: Size of WAL log in frames */ - int *pnCkpt /* OUT: Total number of frames checkpointed */ +SQLITE_API int sqlite3_wal_checkpoint_v2(sqlite3 *db, /* Database handle */ + const char *zDb, /* Name of attached sqlitecipher (or NULL) */ + int eMode, /* SQLITE_CHECKPOINT_* value */ + int *pnLog, /* OUT: Size of WAL log in frames */ + int *pnCkpt /* OUT: Total number of frames checkpointed */ ); /* @@ -9465,10 +9387,10 @@ SQLITE_API int sqlite3_wal_checkpoint_v2( ** See the [sqlite3_wal_checkpoint_v2()] documentation for details on the ** meaning of each of these checkpoint modes. */ -#define SQLITE_CHECKPOINT_PASSIVE 0 /* Do as much as possible w/o blocking */ -#define SQLITE_CHECKPOINT_FULL 1 /* Wait for writers, then checkpoint */ -#define SQLITE_CHECKPOINT_RESTART 2 /* Like FULL but wait for for readers */ -#define SQLITE_CHECKPOINT_TRUNCATE 3 /* Like RESTART but also truncate WAL */ +#define SQLITE_CHECKPOINT_PASSIVE 0 /* Do as much as possible w/o blocking */ +#define SQLITE_CHECKPOINT_FULL 1 /* Wait for writers, then checkpoint */ +#define SQLITE_CHECKPOINT_RESTART 2 /* Like FULL but wait for for readers */ +#define SQLITE_CHECKPOINT_TRUNCATE 3 /* Like RESTART but also truncate WAL */ /* ** CAPI3REF: Virtual Table Interface Configuration @@ -9488,7 +9410,7 @@ SQLITE_API int sqlite3_wal_checkpoint_v2( ** of parameters after C depend on which [virtual table configuration option] ** is used. */ -SQLITE_API int sqlite3_vtab_config(sqlite3*, int op, ...); +SQLITE_API int sqlite3_vtab_config(sqlite3 *, int op, ...); /* ** CAPI3REF: Virtual Table Configuration Options @@ -9592,7 +9514,7 @@ SQLITE_API int sqlite3_vtab_on_conflict(sqlite3 *); ** current implementation, the sqlite3_vtab_nochange() interface does always ** returns false for the enhanced [UPDATE FROM] statement. */ -SQLITE_API int sqlite3_vtab_nochange(sqlite3_context*); +SQLITE_API int sqlite3_vtab_nochange(sqlite3_context *); /* ** CAPI3REF: Determine The Collation For a Virtual Table Constraint @@ -9627,7 +9549,7 @@ SQLITE_API int sqlite3_vtab_nochange(sqlite3_context*); **
  • Otherwise, "BINARY" is returned. ** */ -SQLITE_API SQLITE_EXPERIMENTAL const char *sqlite3_vtab_collation(sqlite3_index_info*,int); +SQLITE_API SQLITE_EXPERIMENTAL const char *sqlite3_vtab_collation(sqlite3_index_info *, int); /* ** CAPI3REF: Determine if a virtual table query is DISTINCT @@ -9700,7 +9622,7 @@ SQLITE_API SQLITE_EXPERIMENTAL const char *sqlite3_vtab_collation(sqlite3_index_ ** valid to do so, on the other hand, might cause SQLite to return incorrect ** results. */ -SQLITE_API int sqlite3_vtab_distinct(sqlite3_index_info*); +SQLITE_API int sqlite3_vtab_distinct(sqlite3_index_info *); /* ** CAPI3REF: Identify and handle IN constraints in xBestIndex @@ -9773,7 +9695,7 @@ SQLITE_API int sqlite3_vtab_distinct(sqlite3_index_info*); ** [sqlite3_vtab_in_next()] to find all values on the right-hand side ** of the IN constraint. */ -SQLITE_API int sqlite3_vtab_in(sqlite3_index_info*, int iCons, int bHandle); +SQLITE_API int sqlite3_vtab_in(sqlite3_index_info *, int iCons, int bHandle); /* ** CAPI3REF: Find all elements on the right-hand side of an IN constraint. @@ -9864,7 +9786,7 @@ SQLITE_API int sqlite3_vtab_in_next(sqlite3_value *pVal, sqlite3_value **ppOut); ** The "_rhs_" in the name of this routine is an abbreviation for ** "Right-Hand Side". */ -SQLITE_API int sqlite3_vtab_rhs_value(sqlite3_index_info*, int, sqlite3_value **ppVal); +SQLITE_API int sqlite3_vtab_rhs_value(sqlite3_index_info *, int, sqlite3_value **ppVal); /* ** CAPI3REF: Conflict resolution modes @@ -9880,9 +9802,9 @@ SQLITE_API int sqlite3_vtab_rhs_value(sqlite3_index_info*, int, sqlite3_value ** */ #define SQLITE_ROLLBACK 1 /* #define SQLITE_IGNORE 2 // Also used by sqlite3_authorizer() callback */ -#define SQLITE_FAIL 3 +#define SQLITE_FAIL 3 /* #define SQLITE_ABORT 4 // Also an error code */ -#define SQLITE_REPLACE 5 +#define SQLITE_REPLACE 5 /* ** CAPI3REF: Prepared Statement Scan Status Opcodes @@ -9969,11 +9891,10 @@ SQLITE_API int sqlite3_vtab_rhs_value(sqlite3_index_info*, int, sqlite3_value ** ** ** See also: [sqlite3_stmt_scanstatus_reset()] */ -SQLITE_API int sqlite3_stmt_scanstatus( - sqlite3_stmt *pStmt, /* Prepared statement for which info desired */ - int idx, /* Index of loop to report on */ - int iScanStatusOp, /* Information desired. SQLITE_SCANSTAT_* */ - void *pOut /* Result written here */ +SQLITE_API int sqlite3_stmt_scanstatus(sqlite3_stmt *pStmt, /* Prepared statement for which info desired */ + int idx, /* Index of loop to report on */ + int iScanStatusOp, /* Information desired. SQLITE_SCANSTAT_* */ + void *pOut /* Result written here */ ); /* @@ -9985,7 +9906,7 @@ SQLITE_API int sqlite3_stmt_scanstatus( ** This API is only available if the library is built with pre-processor ** symbol [SQLITE_ENABLE_STMT_SCANSTATUS] defined. */ -SQLITE_API void sqlite3_stmt_scanstatus_reset(sqlite3_stmt*); +SQLITE_API void sqlite3_stmt_scanstatus_reset(sqlite3_stmt *); /* ** CAPI3REF: Flush caches to disk mid-transaction @@ -10018,7 +9939,7 @@ SQLITE_API void sqlite3_stmt_scanstatus_reset(sqlite3_stmt*); ** ^This function does not set the sqlitecipher handle error code or message ** returned by the [sqlite3_errcode()] and [sqlite3_errmsg()] functions. */ -SQLITE_API int sqlite3_db_cacheflush(sqlite3*); +SQLITE_API int sqlite3_db_cacheflush(sqlite3 *); /* ** CAPI3REF: The pre-update hook. @@ -10114,18 +10035,16 @@ SQLITE_API int sqlite3_db_cacheflush(sqlite3*); */ #if defined(SQLITE_ENABLE_PREUPDATE_HOOK) SQLITE_API void *sqlite3_preupdate_hook( - sqlite3 *db, - void(*xPreUpdate)( - void *pCtx, /* Copy of third arg to preupdate_hook() */ - sqlite3 *db, /* Database handle */ - int op, /* SQLITE_UPDATE, DELETE or INSERT */ - char const *zDb, /* Database name */ - char const *zName, /* Table name */ - sqlite3_int64 iKey1, /* Rowid of row about to be deleted/updated */ - sqlite3_int64 iKey2 /* New rowid value (for a rowid UPDATE) */ - ), - void* -); + sqlite3 *db, + void (*xPreUpdate)(void *pCtx, /* Copy of third arg to preupdate_hook() */ + sqlite3 *db, /* Database handle */ + int op, /* SQLITE_UPDATE, DELETE or INSERT */ + char const *zDb, /* Database name */ + char const *zName, /* Table name */ + sqlite3_int64 iKey1, /* Rowid of row about to be deleted/updated */ + sqlite3_int64 iKey2 /* New rowid value (for a rowid UPDATE) */ + ), + void *); SQLITE_API int sqlite3_preupdate_old(sqlite3 *, int, sqlite3_value **); SQLITE_API int sqlite3_preupdate_count(sqlite3 *); SQLITE_API int sqlite3_preupdate_depth(sqlite3 *); @@ -10144,7 +10063,7 @@ SQLITE_API int sqlite3_preupdate_blobwrite(sqlite3 *); ** called to get back the underlying "errno" that caused the problem, such ** as ENOSPC, EAUTH, EISDIR, and so forth. */ -SQLITE_API int sqlite3_system_errno(sqlite3*); +SQLITE_API int sqlite3_system_errno(sqlite3 *); /* ** CAPI3REF: Database Snapshot @@ -10167,7 +10086,7 @@ SQLITE_API int sqlite3_system_errno(sqlite3*); ** the most recent version. */ typedef struct sqlite3_snapshot { - unsigned char hidden[48]; + unsigned char hidden[48]; } sqlite3_snapshot; /* @@ -10213,11 +10132,9 @@ typedef struct sqlite3_snapshot { ** The [sqlite3_snapshot_get()] interface is only available when the ** [SQLITE_ENABLE_SNAPSHOT] compile-time option is used. */ -SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_snapshot_get( - sqlite3 *db, - const char *zSchema, - sqlite3_snapshot **ppSnapshot -); +SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_snapshot_get(sqlite3 *db, + const char *zSchema, + sqlite3_snapshot **ppSnapshot); /* ** CAPI3REF: Start a read transaction on an historical snapshot @@ -10262,11 +10179,7 @@ SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_snapshot_get( ** The [sqlite3_snapshot_open()] interface is only available when the ** [SQLITE_ENABLE_SNAPSHOT] compile-time option is used. */ -SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_snapshot_open( - sqlite3 *db, - const char *zSchema, - sqlite3_snapshot *pSnapshot -); +SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_snapshot_open(sqlite3 *db, const char *zSchema, sqlite3_snapshot *pSnapshot); /* ** CAPI3REF: Destroy a snapshot @@ -10279,7 +10192,7 @@ SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_snapshot_open( ** The [sqlite3_snapshot_free()] interface is only available when the ** [SQLITE_ENABLE_SNAPSHOT] compile-time option is used. */ -SQLITE_API SQLITE_EXPERIMENTAL void sqlite3_snapshot_free(sqlite3_snapshot*); +SQLITE_API SQLITE_EXPERIMENTAL void sqlite3_snapshot_free(sqlite3_snapshot *); /* ** CAPI3REF: Compare the ages of two snapshot handles. @@ -10306,10 +10219,7 @@ SQLITE_API SQLITE_EXPERIMENTAL void sqlite3_snapshot_free(sqlite3_snapshot*); ** This interface is only available if SQLite is compiled with the ** [SQLITE_ENABLE_SNAPSHOT] option. */ -SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_snapshot_cmp( - sqlite3_snapshot *p1, - sqlite3_snapshot *p2 -); +SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_snapshot_cmp(sqlite3_snapshot *p1, sqlite3_snapshot *p2); /* ** CAPI3REF: Recover snapshots from a wal file @@ -10372,11 +10282,10 @@ SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_snapshot_recover(sqlite3 *db, const c ** This interface is omitted if SQLite is compiled with the ** [SQLITE_OMIT_DESERIALIZE] option. */ -SQLITE_API unsigned char *sqlite3_serialize( - sqlite3 *db, /* The sqlitecipher connection */ - const char *zSchema, /* Which DB to serialize. ex: "main", "temp", ... */ - sqlite3_int64 *piSize, /* Write size of the DB here, if not NULL */ - unsigned int mFlags /* Zero or more SQLITE_SERIALIZE_* flags */ +SQLITE_API unsigned char *sqlite3_serialize(sqlite3 *db, /* The sqlitecipher connection */ + const char *zSchema, /* Which DB to serialize. ex: "main", "temp", ... */ + sqlite3_int64 *piSize, /* Write size of the DB here, if not NULL */ + unsigned int mFlags /* Zero or more SQLITE_SERIALIZE_* flags */ ); /* @@ -10393,7 +10302,7 @@ SQLITE_API unsigned char *sqlite3_serialize( ** using a contiguous in-memory sqlitecipher if it has been initialized by a ** prior call to [sqlite3_deserialize()]. */ -#define SQLITE_SERIALIZE_NOCOPY 0x001 /* Do no memory allocations */ +#define SQLITE_SERIALIZE_NOCOPY 0x001 /* Do no memory allocations */ /* ** CAPI3REF: Deserialize a sqlitecipher @@ -10428,13 +10337,12 @@ SQLITE_API unsigned char *sqlite3_serialize( ** This interface is omitted if SQLite is compiled with the ** [SQLITE_OMIT_DESERIALIZE] option. */ -SQLITE_API int sqlite3_deserialize( - sqlite3 *db, /* The sqlitecipher connection */ - const char *zSchema, /* Which DB to reopen with the deserialization */ - unsigned char *pData, /* The serialized sqlitecipher content */ - sqlite3_int64 szDb, /* Number bytes in the deserialization */ - sqlite3_int64 szBuf, /* Total size of buffer pData[] */ - unsigned mFlags /* Zero or more SQLITE_DESERIALIZE_* flags */ +SQLITE_API int sqlite3_deserialize(sqlite3 *db, /* The sqlitecipher connection */ + const char *zSchema, /* Which DB to reopen with the deserialization */ + unsigned char *pData, /* The serialized sqlitecipher content */ + sqlite3_int64 szDb, /* Number bytes in the deserialization */ + sqlite3_int64 szBuf, /* Total size of buffer pData[] */ + unsigned mFlags /* Zero or more SQLITE_DESERIALIZE_* flags */ ); /* @@ -10467,11 +10375,11 @@ SQLITE_API int sqlite3_deserialize( ** builds on processors without floating point support. */ #ifdef SQLITE_OMIT_FLOATING_POINT -# undef double +#undef double #endif #ifdef __cplusplus -} /* End of the 'extern "C"' block */ +} /* End of the 'extern "C"' block */ #endif #endif /* SQLITE3_H */ @@ -10492,21 +10400,20 @@ SQLITE_API int sqlite3_deserialize( #ifndef _SQLITE3RTREE_H_ #define _SQLITE3RTREE_H_ - #ifdef __cplusplus extern "C" { #endif -typedef struct sqlite3_rtree_geometry sqlite3_rtree_geometry; +typedef struct sqlite3_rtree_geometry sqlite3_rtree_geometry; typedef struct sqlite3_rtree_query_info sqlite3_rtree_query_info; /* The double-precision datatype used by RTree depends on the ** SQLITE_RTREE_INT_ONLY compile-time option. */ #ifdef SQLITE_RTREE_INT_ONLY - typedef sqlite3_int64 sqlite3_rtree_dbl; +typedef sqlite3_int64 sqlite3_rtree_dbl; #else - typedef double sqlite3_rtree_dbl; +typedef double sqlite3_rtree_dbl; #endif /* @@ -10515,24 +10422,21 @@ typedef struct sqlite3_rtree_query_info sqlite3_rtree_query_info; ** ** SELECT ... FROM WHERE MATCH $zGeom(... params ...) */ -SQLITE_API int sqlite3_rtree_geometry_callback( - sqlite3 *db, - const char *zGeom, - int (*xGeom)(sqlite3_rtree_geometry*, int, sqlite3_rtree_dbl*,int*), - void *pContext -); - +SQLITE_API int sqlite3_rtree_geometry_callback(sqlite3 *db, + const char *zGeom, + int (*xGeom)(sqlite3_rtree_geometry *, int, sqlite3_rtree_dbl *, int *), + void *pContext); /* ** A pointer to a structure of the following type is passed as the first ** argument to callbacks registered using rtree_geometry_callback(). */ struct sqlite3_rtree_geometry { - void *pContext; /* Copy of pContext passed to s_r_g_c() */ - int nParam; /* Size of array aParam[] */ - sqlite3_rtree_dbl *aParam; /* Parameters passed to SQL geom function */ - void *pUser; /* Callback implementation user data */ - void (*xDelUser)(void *); /* Called by SQLite to clean up pUser */ + void *pContext; /* Copy of pContext passed to s_r_g_c() */ + int nParam; /* Size of array aParam[] */ + sqlite3_rtree_dbl *aParam; /* Parameters passed to SQL geom function */ + void *pUser; /* Callback implementation user data */ + void (*xDelUser)(void *); /* Called by SQLite to clean up pUser */ }; /* @@ -10541,14 +10445,11 @@ struct sqlite3_rtree_geometry { ** ** SELECT ... FROM WHERE MATCH $zQueryFunc(... params ...) */ -SQLITE_API int sqlite3_rtree_query_callback( - sqlite3 *db, - const char *zQueryFunc, - int (*xQueryFunc)(sqlite3_rtree_query_info*), - void *pContext, - void (*xDestructor)(void*) -); - +SQLITE_API int sqlite3_rtree_query_callback(sqlite3 *db, + const char *zQueryFunc, + int (*xQueryFunc)(sqlite3_rtree_query_info *), + void *pContext, + void (*xDestructor)(void *)); /* ** A pointer to a structure of the following type is passed as the @@ -10560,38 +10461,37 @@ SQLITE_API int sqlite3_rtree_query_callback( ** sqlite3_rtree_geometry. */ struct sqlite3_rtree_query_info { - void *pContext; /* pContext from when function registered */ - int nParam; /* Number of function parameters */ - sqlite3_rtree_dbl *aParam; /* value of function parameters */ - void *pUser; /* callback can use this, if desired */ - void (*xDelUser)(void*); /* function to free pUser */ - sqlite3_rtree_dbl *aCoord; /* Coordinates of node or entry to check */ - unsigned int *anQueue; /* Number of pending entries in the queue */ - int nCoord; /* Number of coordinates */ - int iLevel; /* Level of current node or entry */ - int mxLevel; /* The largest iLevel value in the tree */ - sqlite3_int64 iRowid; /* Rowid for current entry */ - sqlite3_rtree_dbl rParentScore; /* Score of parent node */ - int eParentWithin; /* Visibility of parent node */ - int eWithin; /* OUT: Visibility */ - sqlite3_rtree_dbl rScore; /* OUT: Write the score here */ - /* The following fields are only available in 3.8.11 and later */ - sqlite3_value **apSqlParam; /* Original SQL values of parameters */ + void *pContext; /* pContext from when function registered */ + int nParam; /* Number of function parameters */ + sqlite3_rtree_dbl *aParam; /* value of function parameters */ + void *pUser; /* callback can use this, if desired */ + void (*xDelUser)(void *); /* function to free pUser */ + sqlite3_rtree_dbl *aCoord; /* Coordinates of node or entry to check */ + unsigned int *anQueue; /* Number of pending entries in the queue */ + int nCoord; /* Number of coordinates */ + int iLevel; /* Level of current node or entry */ + int mxLevel; /* The largest iLevel value in the tree */ + sqlite3_int64 iRowid; /* Rowid for current entry */ + sqlite3_rtree_dbl rParentScore; /* Score of parent node */ + int eParentWithin; /* Visibility of parent node */ + int eWithin; /* OUT: Visibility */ + sqlite3_rtree_dbl rScore; /* OUT: Write the score here */ + /* The following fields are only available in 3.8.11 and later */ + sqlite3_value **apSqlParam; /* Original SQL values of parameters */ }; /* ** Allowed values for sqlite3_rtree_query.eWithin and .eParentWithin. */ -#define NOT_WITHIN 0 /* Object completely outside of query region */ -#define PARTLY_WITHIN 1 /* Object partially overlaps query region */ -#define FULLY_WITHIN 2 /* Object fully contained within query region */ - +#define NOT_WITHIN 0 /* Object completely outside of query region */ +#define PARTLY_WITHIN 1 /* Object partially overlaps query region */ +#define FULLY_WITHIN 2 /* Object fully contained within query region */ #ifdef __cplusplus -} /* end of the 'extern "C"' block */ +} /* end of the 'extern "C"' block */ #endif -#endif /* ifndef _SQLITE3RTREE_H_ */ +#endif /* ifndef _SQLITE3RTREE_H_ */ /******** End of sqlite3rtree.h *********/ /******** Begin file sqlite3session.h *********/ @@ -10606,7 +10506,6 @@ struct sqlite3_rtree_query_info { extern "C" { #endif - /* ** CAPI3REF: Session Object Handle ** @@ -10654,10 +10553,9 @@ typedef struct sqlite3_changeset_iter sqlite3_changeset_iter; ** attached sqlitecipher. It is not an error if sqlitecipher zDb is not attached ** to the sqlitecipher when the session object is created. */ -SQLITE_API int sqlite3session_create( - sqlite3 *db, /* Database handle */ - const char *zDb, /* Name of db (e.g. "main") */ - sqlite3_session **ppSession /* OUT: New session object */ +SQLITE_API int sqlite3session_create(sqlite3 *db, /* Database handle */ + const char *zDb, /* Name of db (e.g. "main") */ + sqlite3_session **ppSession /* OUT: New session object */ ); /* @@ -10702,7 +10600,7 @@ SQLITE_API void sqlite3session_delete(sqlite3_session *pSession); ** It is an error (SQLITE_MISUSE) to attempt to modify this setting after ** the first table has been attached to the session object. */ -SQLITE_API int sqlite3session_object_config(sqlite3_session*, int op, void *pArg); +SQLITE_API int sqlite3session_object_config(sqlite3_session *, int op, void *pArg); /* */ @@ -10816,9 +10714,8 @@ SQLITE_API int sqlite3session_indirect(sqlite3_session *pSession, int bIndirect) ** sqlite3changeset_apply() function silently ignore any modifications to the ** sqlite_stat1 table that are part of a changeset or patchset. */ -SQLITE_API int sqlite3session_attach( - sqlite3_session *pSession, /* Session object */ - const char *zTab /* Table name */ +SQLITE_API int sqlite3session_attach(sqlite3_session *pSession, /* Session object */ + const char *zTab /* Table name */ ); /* @@ -10831,13 +10728,11 @@ SQLITE_API int sqlite3session_attach( ** If xFilter returns 0, changes are not tracked. Note that once a table is ** attached, xFilter will not be called again. */ -SQLITE_API void sqlite3session_table_filter( - sqlite3_session *pSession, /* Session object */ - int(*xFilter)( - void *pCtx, /* Copy of third arg to _filter_table() */ - const char *zTab /* Table name */ - ), - void *pCtx /* First argument passed to xFilter */ +SQLITE_API void sqlite3session_table_filter(sqlite3_session *pSession, /* Session object */ + int (*xFilter)(void *pCtx, /* Copy of third arg to _filter_table() */ + const char *zTab /* Table name */ + ), + void *pCtx /* First argument passed to xFilter */ ); /* @@ -10945,10 +10840,9 @@ SQLITE_API void sqlite3session_table_filter( ** another field of the same row is updated while the session is enabled, the ** resulting changeset will contain an UPDATE change that updates both fields. */ -SQLITE_API int sqlite3session_changeset( - sqlite3_session *pSession, /* Session object */ - int *pnChangeset, /* OUT: Size of buffer at *ppChangeset */ - void **ppChangeset /* OUT: Buffer containing changeset */ +SQLITE_API int sqlite3session_changeset(sqlite3_session *pSession, /* Session object */ + int *pnChangeset, /* OUT: Size of buffer at *ppChangeset */ + void **ppChangeset /* OUT: Buffer containing changeset */ ); /* @@ -11024,13 +10918,7 @@ SQLITE_API sqlite3_int64 sqlite3session_changeset_size(sqlite3_session *pSession ** message. It is the responsibility of the caller to free this buffer using ** sqlite3_free(). */ -SQLITE_API int sqlite3session_diff( - sqlite3_session *pSession, - const char *zFromDb, - const char *zTbl, - char **pzErrMsg -); - +SQLITE_API int sqlite3session_diff(sqlite3_session *pSession, const char *zFromDb, const char *zTbl, char **pzErrMsg); /* ** CAPI3REF: Generate A Patchset From A Session Object @@ -11061,10 +10949,9 @@ SQLITE_API int sqlite3session_diff( ** a single table are grouped together, tables appear in the order in which ** they were attached to the session object). */ -SQLITE_API int sqlite3session_patchset( - sqlite3_session *pSession, /* Session object */ - int *pnPatchset, /* OUT: Size of buffer at *ppPatchset */ - void **ppPatchset /* OUT: Buffer containing patchset */ +SQLITE_API int sqlite3session_patchset(sqlite3_session *pSession, /* Session object */ + int *pnPatchset, /* OUT: Size of buffer at *ppPatchset */ + void **ppPatchset /* OUT: Buffer containing patchset */ ); /* @@ -11133,16 +11020,14 @@ SQLITE_API sqlite3_int64 sqlite3session_memory_used(sqlite3_session *pSession); ** Note that the sqlite3changeset_start_v2() API is still experimental ** and therefore subject to change. */ -SQLITE_API int sqlite3changeset_start( - sqlite3_changeset_iter **pp, /* OUT: New changeset iterator handle */ - int nChangeset, /* Size of changeset blob in bytes */ - void *pChangeset /* Pointer to blob containing changeset */ +SQLITE_API int sqlite3changeset_start(sqlite3_changeset_iter **pp, /* OUT: New changeset iterator handle */ + int nChangeset, /* Size of changeset blob in bytes */ + void *pChangeset /* Pointer to blob containing changeset */ ); -SQLITE_API int sqlite3changeset_start_v2( - sqlite3_changeset_iter **pp, /* OUT: New changeset iterator handle */ - int nChangeset, /* Size of changeset blob in bytes */ - void *pChangeset, /* Pointer to blob containing changeset */ - int flags /* SESSION_CHANGESETSTART_* flags */ +SQLITE_API int sqlite3changeset_start_v2(sqlite3_changeset_iter **pp, /* OUT: New changeset iterator handle */ + int nChangeset, /* Size of changeset blob in bytes */ + void *pChangeset, /* Pointer to blob containing changeset */ + int flags /* SESSION_CHANGESETSTART_* flags */ ); /* @@ -11156,8 +11041,7 @@ SQLITE_API int sqlite3changeset_start_v2( ** inverting a changeset using sqlite3changeset_invert() before applying it. ** It is an error to specify this flag with a patchset. */ -#define SQLITE_CHANGESETSTART_INVERT 0x0002 - +#define SQLITE_CHANGESETSTART_INVERT 0x0002 /* ** CAPI3REF: Advance A Changeset Iterator @@ -11216,12 +11100,11 @@ SQLITE_API int sqlite3changeset_next(sqlite3_changeset_iter *pIter); ** SQLite error code is returned. The values of the output variables may not ** be trusted in this case. */ -SQLITE_API int sqlite3changeset_op( - sqlite3_changeset_iter *pIter, /* Iterator object */ - const char **pzTab, /* OUT: Pointer to table name */ - int *pnCol, /* OUT: Number of columns in table */ - int *pOp, /* OUT: SQLITE_INSERT, DELETE or UPDATE */ - int *pbIndirect /* OUT: True for an 'indirect' change */ +SQLITE_API int sqlite3changeset_op(sqlite3_changeset_iter *pIter, /* Iterator object */ + const char **pzTab, /* OUT: Pointer to table name */ + int *pnCol, /* OUT: Number of columns in table */ + int *pOp, /* OUT: SQLITE_INSERT, DELETE or UPDATE */ + int *pbIndirect /* OUT: True for an 'indirect' change */ ); /* @@ -11250,10 +11133,9 @@ SQLITE_API int sqlite3changeset_op( ** SQLITE_OK is returned and the output variables populated as described ** above. */ -SQLITE_API int sqlite3changeset_pk( - sqlite3_changeset_iter *pIter, /* Iterator object */ - unsigned char **pabPK, /* OUT: Array of boolean - true for PK cols */ - int *pnCol /* OUT: Number of entries in output array */ +SQLITE_API int sqlite3changeset_pk(sqlite3_changeset_iter *pIter, /* Iterator object */ + unsigned char **pabPK, /* OUT: Array of boolean - true for PK cols */ + int *pnCol /* OUT: Number of entries in output array */ ); /* @@ -11281,10 +11163,9 @@ SQLITE_API int sqlite3changeset_pk( ** If some other error occurs (e.g. an OOM condition), an SQLite error code ** is returned and *ppValue is set to NULL. */ -SQLITE_API int sqlite3changeset_old( - sqlite3_changeset_iter *pIter, /* Changeset iterator */ - int iVal, /* Column number */ - sqlite3_value **ppValue /* OUT: Old value (or NULL pointer) */ +SQLITE_API int sqlite3changeset_old(sqlite3_changeset_iter *pIter, /* Changeset iterator */ + int iVal, /* Column number */ + sqlite3_value **ppValue /* OUT: Old value (or NULL pointer) */ ); /* @@ -11315,10 +11196,9 @@ SQLITE_API int sqlite3changeset_old( ** If some other error occurs (e.g. an OOM condition), an SQLite error code ** is returned and *ppValue is set to NULL. */ -SQLITE_API int sqlite3changeset_new( - sqlite3_changeset_iter *pIter, /* Changeset iterator */ - int iVal, /* Column number */ - sqlite3_value **ppValue /* OUT: New value (or NULL pointer) */ +SQLITE_API int sqlite3changeset_new(sqlite3_changeset_iter *pIter, /* Changeset iterator */ + int iVal, /* Column number */ + sqlite3_value **ppValue /* OUT: New value (or NULL pointer) */ ); /* @@ -11343,10 +11223,9 @@ SQLITE_API int sqlite3changeset_new( ** If some other error occurs (e.g. an OOM condition), an SQLite error code ** is returned and *ppValue is set to NULL. */ -SQLITE_API int sqlite3changeset_conflict( - sqlite3_changeset_iter *pIter, /* Changeset iterator */ - int iVal, /* Column number */ - sqlite3_value **ppValue /* OUT: Value from conflicting row */ +SQLITE_API int sqlite3changeset_conflict(sqlite3_changeset_iter *pIter, /* Changeset iterator */ + int iVal, /* Column number */ + sqlite3_value **ppValue /* OUT: Value from conflicting row */ ); /* @@ -11360,12 +11239,10 @@ SQLITE_API int sqlite3changeset_conflict( ** ** In all other cases this function returns SQLITE_MISUSE. */ -SQLITE_API int sqlite3changeset_fk_conflicts( - sqlite3_changeset_iter *pIter, /* Changeset iterator */ - int *pnOut /* OUT: Number of FK violations */ +SQLITE_API int sqlite3changeset_fk_conflicts(sqlite3_changeset_iter *pIter, /* Changeset iterator */ + int *pnOut /* OUT: Number of FK violations */ ); - /* ** CAPI3REF: Finalize A Changeset Iterator ** METHOD: sqlite3_changeset_iter @@ -11426,9 +11303,10 @@ SQLITE_API int sqlite3changeset_finalize(sqlite3_changeset_iter *pIter); ** WARNING/TODO: This function currently assumes that the input is a valid ** changeset. If it is not, the results are undefined. */ -SQLITE_API int sqlite3changeset_invert( - int nIn, const void *pIn, /* Input changeset */ - int *pnOut, void **ppOut /* OUT: Inverse of input */ +SQLITE_API int sqlite3changeset_invert(int nIn, + const void *pIn, /* Input changeset */ + int *pnOut, + void **ppOut /* OUT: Inverse of input */ ); /* @@ -11457,16 +11335,14 @@ SQLITE_API int sqlite3changeset_invert( ** ** Refer to the sqlite3_changegroup documentation below for details. */ -SQLITE_API int sqlite3changeset_concat( - int nA, /* Number of bytes in buffer pA */ - void *pA, /* Pointer to buffer containing changeset A */ - int nB, /* Number of bytes in buffer pB */ - void *pB, /* Pointer to buffer containing changeset B */ - int *pnOut, /* OUT: Number of bytes in output changeset */ - void **ppOut /* OUT: Buffer containing output changeset */ +SQLITE_API int sqlite3changeset_concat(int nA, /* Number of bytes in buffer pA */ + void *pA, /* Pointer to buffer containing changeset A */ + int nB, /* Number of bytes in buffer pB */ + void *pB, /* Pointer to buffer containing changeset B */ + int *pnOut, /* OUT: Number of bytes in output changeset */ + void **ppOut /* OUT: Buffer containing output changeset */ ); - /* ** CAPI3REF: Changegroup Handle ** @@ -11589,7 +11465,7 @@ SQLITE_API int sqlite3changegroup_new(sqlite3_changegroup **pp); ** ** If no error occurs, SQLITE_OK is returned. */ -SQLITE_API int sqlite3changegroup_add(sqlite3_changegroup*, int nData, void *pData); +SQLITE_API int sqlite3changegroup_add(sqlite3_changegroup *, int nData, void *pData); /* ** CAPI3REF: Obtain A Composite Changeset From A Changegroup @@ -11616,17 +11492,16 @@ SQLITE_API int sqlite3changegroup_add(sqlite3_changegroup*, int nData, void *pDa ** responsibility of the caller to eventually free the buffer using a ** call to sqlite3_free(). */ -SQLITE_API int sqlite3changegroup_output( - sqlite3_changegroup*, - int *pnData, /* OUT: Size of output buffer in bytes */ - void **ppData /* OUT: Pointer to output buffer */ +SQLITE_API int sqlite3changegroup_output(sqlite3_changegroup *, + int *pnData, /* OUT: Size of output buffer in bytes */ + void **ppData /* OUT: Pointer to output buffer */ ); /* ** CAPI3REF: Delete A Changegroup Object ** DESTRUCTOR: sqlite3_changegroup */ -SQLITE_API void sqlite3changegroup_delete(sqlite3_changegroup*); +SQLITE_API void sqlite3changegroup_delete(sqlite3_changegroup *); /* ** CAPI3REF: Apply A Changeset To A Database @@ -11787,36 +11662,33 @@ SQLITE_API void sqlite3changegroup_delete(sqlite3_changegroup*); ** and therefore subject to change. */ SQLITE_API int sqlite3changeset_apply( - sqlite3 *db, /* Apply change to "main" db of this handle */ - int nChangeset, /* Size of changeset in bytes */ - void *pChangeset, /* Changeset blob */ - int(*xFilter)( - void *pCtx, /* Copy of sixth arg to _apply() */ - const char *zTab /* Table name */ - ), - int(*xConflict)( - void *pCtx, /* Copy of sixth arg to _apply() */ - int eConflict, /* DATA, MISSING, CONFLICT, CONSTRAINT */ - sqlite3_changeset_iter *p /* Handle describing change and conflict */ - ), - void *pCtx /* First argument passed to xConflict */ + sqlite3 *db, /* Apply change to "main" db of this handle */ + int nChangeset, /* Size of changeset in bytes */ + void *pChangeset, /* Changeset blob */ + int (*xFilter)(void *pCtx, /* Copy of sixth arg to _apply() */ + const char *zTab /* Table name */ + ), + int (*xConflict)(void *pCtx, /* Copy of sixth arg to _apply() */ + int eConflict, /* DATA, MISSING, CONFLICT, CONSTRAINT */ + sqlite3_changeset_iter *p /* Handle describing change and conflict */ + ), + void *pCtx /* First argument passed to xConflict */ ); SQLITE_API int sqlite3changeset_apply_v2( - sqlite3 *db, /* Apply change to "main" db of this handle */ - int nChangeset, /* Size of changeset in bytes */ - void *pChangeset, /* Changeset blob */ - int(*xFilter)( - void *pCtx, /* Copy of sixth arg to _apply() */ - const char *zTab /* Table name */ - ), - int(*xConflict)( - void *pCtx, /* Copy of sixth arg to _apply() */ - int eConflict, /* DATA, MISSING, CONFLICT, CONSTRAINT */ - sqlite3_changeset_iter *p /* Handle describing change and conflict */ - ), - void *pCtx, /* First argument passed to xConflict */ - void **ppRebase, int *pnRebase, /* OUT: Rebase data */ - int flags /* SESSION_CHANGESETAPPLY_* flags */ + sqlite3 *db, /* Apply change to "main" db of this handle */ + int nChangeset, /* Size of changeset in bytes */ + void *pChangeset, /* Changeset blob */ + int (*xFilter)(void *pCtx, /* Copy of sixth arg to _apply() */ + const char *zTab /* Table name */ + ), + int (*xConflict)(void *pCtx, /* Copy of sixth arg to _apply() */ + int eConflict, /* DATA, MISSING, CONFLICT, CONSTRAINT */ + sqlite3_changeset_iter *p /* Handle describing change and conflict */ + ), + void *pCtx, /* First argument passed to xConflict */ + void **ppRebase, + int *pnRebase, /* OUT: Rebase data */ + int flags /* SESSION_CHANGESETAPPLY_* flags */ ); /* @@ -11840,8 +11712,8 @@ SQLITE_API int sqlite3changeset_apply_v2( ** a changeset using sqlite3changeset_invert() before applying it. It is ** an error to specify this flag with a patchset. */ -#define SQLITE_CHANGESETAPPLY_NOSAVEPOINT 0x0001 -#define SQLITE_CHANGESETAPPLY_INVERT 0x0002 +#define SQLITE_CHANGESETAPPLY_NOSAVEPOINT 0x0001 +#define SQLITE_CHANGESETAPPLY_INVERT 0x0002 /* ** CAPI3REF: Constants Passed To The Conflict Handler @@ -11935,9 +11807,9 @@ SQLITE_API int sqlite3changeset_apply_v2( ** and the call to sqlite3changeset_apply() returns SQLITE_ABORT. ** */ -#define SQLITE_CHANGESET_OMIT 0 -#define SQLITE_CHANGESET_REPLACE 1 -#define SQLITE_CHANGESET_ABORT 2 +#define SQLITE_CHANGESET_OMIT 0 +#define SQLITE_CHANGESET_REPLACE 1 +#define SQLITE_CHANGESET_ABORT 2 /* ** CAPI3REF: Rebasing changesets @@ -12059,10 +11931,7 @@ SQLITE_API int sqlite3rebaser_create(sqlite3_rebaser **ppNew); ** bytes), which must have been obtained from a previous call to ** sqlite3changeset_apply_v2(). */ -SQLITE_API int sqlite3rebaser_configure( - sqlite3_rebaser*, - int nRebase, const void *pRebase -); +SQLITE_API int sqlite3rebaser_configure(sqlite3_rebaser *, int nRebase, const void *pRebase); /* ** CAPI3REF: Rebase a changeset @@ -12078,11 +11947,7 @@ SQLITE_API int sqlite3rebaser_configure( ** sqlite3_free(). Otherwise, if an error occurs, (*ppOut) and (*pnOut) ** are set to zero and an SQLite error code returned. */ -SQLITE_API int sqlite3rebaser_rebase( - sqlite3_rebaser*, - int nIn, const void *pIn, - int *pnOut, void **ppOut -); +SQLITE_API int sqlite3rebaser_rebase(sqlite3_rebaser *, int nIn, const void *pIn, int *pnOut, void **ppOut); /* ** CAPI3REF: Delete a changeset rebaser object. @@ -12185,87 +12050,67 @@ SQLITE_API void sqlite3rebaser_delete(sqlite3_rebaser *p); ** no guarantees are made as to the size of the chunks of data returned. */ SQLITE_API int sqlite3changeset_apply_strm( - sqlite3 *db, /* Apply change to "main" db of this handle */ - int (*xInput)(void *pIn, void *pData, int *pnData), /* Input function */ - void *pIn, /* First arg for xInput */ - int(*xFilter)( - void *pCtx, /* Copy of sixth arg to _apply() */ - const char *zTab /* Table name */ - ), - int(*xConflict)( - void *pCtx, /* Copy of sixth arg to _apply() */ - int eConflict, /* DATA, MISSING, CONFLICT, CONSTRAINT */ - sqlite3_changeset_iter *p /* Handle describing change and conflict */ - ), - void *pCtx /* First argument passed to xConflict */ + sqlite3 *db, /* Apply change to "main" db of this handle */ + int (*xInput)(void *pIn, void *pData, int *pnData), /* Input function */ + void *pIn, /* First arg for xInput */ + int (*xFilter)(void *pCtx, /* Copy of sixth arg to _apply() */ + const char *zTab /* Table name */ + ), + int (*xConflict)(void *pCtx, /* Copy of sixth arg to _apply() */ + int eConflict, /* DATA, MISSING, CONFLICT, CONSTRAINT */ + sqlite3_changeset_iter *p /* Handle describing change and conflict */ + ), + void *pCtx /* First argument passed to xConflict */ ); SQLITE_API int sqlite3changeset_apply_v2_strm( - sqlite3 *db, /* Apply change to "main" db of this handle */ - int (*xInput)(void *pIn, void *pData, int *pnData), /* Input function */ - void *pIn, /* First arg for xInput */ - int(*xFilter)( - void *pCtx, /* Copy of sixth arg to _apply() */ - const char *zTab /* Table name */ - ), - int(*xConflict)( - void *pCtx, /* Copy of sixth arg to _apply() */ - int eConflict, /* DATA, MISSING, CONFLICT, CONSTRAINT */ - sqlite3_changeset_iter *p /* Handle describing change and conflict */ - ), - void *pCtx, /* First argument passed to xConflict */ - void **ppRebase, int *pnRebase, - int flags -); -SQLITE_API int sqlite3changeset_concat_strm( - int (*xInputA)(void *pIn, void *pData, int *pnData), - void *pInA, - int (*xInputB)(void *pIn, void *pData, int *pnData), - void *pInB, - int (*xOutput)(void *pOut, const void *pData, int nData), - void *pOut -); -SQLITE_API int sqlite3changeset_invert_strm( - int (*xInput)(void *pIn, void *pData, int *pnData), - void *pIn, - int (*xOutput)(void *pOut, const void *pData, int nData), - void *pOut -); -SQLITE_API int sqlite3changeset_start_strm( - sqlite3_changeset_iter **pp, - int (*xInput)(void *pIn, void *pData, int *pnData), - void *pIn -); -SQLITE_API int sqlite3changeset_start_v2_strm( - sqlite3_changeset_iter **pp, - int (*xInput)(void *pIn, void *pData, int *pnData), - void *pIn, - int flags -); -SQLITE_API int sqlite3session_changeset_strm( - sqlite3_session *pSession, - int (*xOutput)(void *pOut, const void *pData, int nData), - void *pOut -); -SQLITE_API int sqlite3session_patchset_strm( - sqlite3_session *pSession, - int (*xOutput)(void *pOut, const void *pData, int nData), - void *pOut -); -SQLITE_API int sqlite3changegroup_add_strm(sqlite3_changegroup*, - int (*xInput)(void *pIn, void *pData, int *pnData), - void *pIn -); -SQLITE_API int sqlite3changegroup_output_strm(sqlite3_changegroup*, - int (*xOutput)(void *pOut, const void *pData, int nData), - void *pOut -); -SQLITE_API int sqlite3rebaser_rebase_strm( - sqlite3_rebaser *pRebaser, - int (*xInput)(void *pIn, void *pData, int *pnData), - void *pIn, - int (*xOutput)(void *pOut, const void *pData, int nData), - void *pOut -); + sqlite3 *db, /* Apply change to "main" db of this handle */ + int (*xInput)(void *pIn, void *pData, int *pnData), /* Input function */ + void *pIn, /* First arg for xInput */ + int (*xFilter)(void *pCtx, /* Copy of sixth arg to _apply() */ + const char *zTab /* Table name */ + ), + int (*xConflict)(void *pCtx, /* Copy of sixth arg to _apply() */ + int eConflict, /* DATA, MISSING, CONFLICT, CONSTRAINT */ + sqlite3_changeset_iter *p /* Handle describing change and conflict */ + ), + void *pCtx, /* First argument passed to xConflict */ + void **ppRebase, + int *pnRebase, + int flags); +SQLITE_API int sqlite3changeset_concat_strm(int (*xInputA)(void *pIn, void *pData, int *pnData), + void *pInA, + int (*xInputB)(void *pIn, void *pData, int *pnData), + void *pInB, + int (*xOutput)(void *pOut, const void *pData, int nData), + void *pOut); +SQLITE_API int sqlite3changeset_invert_strm(int (*xInput)(void *pIn, void *pData, int *pnData), + void *pIn, + int (*xOutput)(void *pOut, const void *pData, int nData), + void *pOut); +SQLITE_API int sqlite3changeset_start_strm(sqlite3_changeset_iter **pp, + int (*xInput)(void *pIn, void *pData, int *pnData), + void *pIn); +SQLITE_API int sqlite3changeset_start_v2_strm(sqlite3_changeset_iter **pp, + int (*xInput)(void *pIn, void *pData, int *pnData), + void *pIn, + int flags); +SQLITE_API int sqlite3session_changeset_strm(sqlite3_session *pSession, + int (*xOutput)(void *pOut, const void *pData, int nData), + void *pOut); +SQLITE_API int sqlite3session_patchset_strm(sqlite3_session *pSession, + int (*xOutput)(void *pOut, const void *pData, int nData), + void *pOut); +SQLITE_API int sqlite3changegroup_add_strm(sqlite3_changegroup *, + int (*xInput)(void *pIn, void *pData, int *pnData), + void *pIn); +SQLITE_API int sqlite3changegroup_output_strm(sqlite3_changegroup *, + int (*xOutput)(void *pOut, const void *pData, int nData), + void *pOut); +SQLITE_API int sqlite3rebaser_rebase_strm(sqlite3_rebaser *pRebaser, + int (*xInput)(void *pIn, void *pData, int *pnData), + void *pIn, + int (*xOutput)(void *pOut, const void *pData, int nData), + void *pOut); /* ** CAPI3REF: Configure global parameters @@ -12314,7 +12159,7 @@ SQLITE_API int sqlite3session_config(int op, void *pArg); } #endif -#endif /* !defined(__SQLITESESSION_H_) && defined(SQLITE_ENABLE_SESSION) */ +#endif /* !defined(__SQLITESESSION_H_) && defined(SQLITE_ENABLE_SESSION) */ /******** End of sqlite3session.h *********/ /******** Begin file fts5.h *********/ @@ -12337,11 +12182,9 @@ SQLITE_API int sqlite3session_config(int op, void *pArg); ** * custom auxiliary functions. */ - #ifndef _FTS5_H #define _FTS5_H - #ifdef __cplusplus extern "C" { #endif @@ -12354,20 +12197,19 @@ extern "C" { */ typedef struct Fts5ExtensionApi Fts5ExtensionApi; -typedef struct Fts5Context Fts5Context; -typedef struct Fts5PhraseIter Fts5PhraseIter; +typedef struct Fts5Context Fts5Context; +typedef struct Fts5PhraseIter Fts5PhraseIter; -typedef void (*fts5_extension_function)( - const Fts5ExtensionApi *pApi, /* API offered by current FTS version */ - Fts5Context *pFts, /* First arg to pass to pApi functions */ - sqlite3_context *pCtx, /* Context for returning result/error */ - int nVal, /* Number of values in apVal[] array */ - sqlite3_value **apVal /* Array of trailing arguments */ +typedef void (*fts5_extension_function)(const Fts5ExtensionApi *pApi, /* API offered by current FTS version */ + Fts5Context *pFts, /* First arg to pass to pApi functions */ + sqlite3_context *pCtx, /* Context for returning result/error */ + int nVal, /* Number of values in apVal[] array */ + sqlite3_value **apVal /* Array of trailing arguments */ ); struct Fts5PhraseIter { - const unsigned char *a; - const unsigned char *b; + const unsigned char *a; + const unsigned char *b; }; /* @@ -12582,41 +12424,43 @@ struct Fts5PhraseIter { ** See xPhraseFirstColumn above. */ struct Fts5ExtensionApi { - int iVersion; /* Currently always set to 3 */ + int iVersion; /* Currently always set to 3 */ - void *(*xUserData)(Fts5Context*); + void *(*xUserData)(Fts5Context *); - int (*xColumnCount)(Fts5Context*); - int (*xRowCount)(Fts5Context*, sqlite3_int64 *pnRow); - int (*xColumnTotalSize)(Fts5Context*, int iCol, sqlite3_int64 *pnToken); + int (*xColumnCount)(Fts5Context *); + int (*xRowCount)(Fts5Context *, sqlite3_int64 *pnRow); + int (*xColumnTotalSize)(Fts5Context *, int iCol, sqlite3_int64 *pnToken); - int (*xTokenize)(Fts5Context*, - const char *pText, int nText, /* Text to tokenize */ - void *pCtx, /* Context passed to xToken() */ - int (*xToken)(void*, int, const char*, int, int, int) /* Callback */ - ); + int (*xTokenize)(Fts5Context *, + const char *pText, + int nText, /* Text to tokenize */ + void *pCtx, /* Context passed to xToken() */ + int (*xToken)(void *, int, const char *, int, int, int) /* Callback */ + ); - int (*xPhraseCount)(Fts5Context*); - int (*xPhraseSize)(Fts5Context*, int iPhrase); + int (*xPhraseCount)(Fts5Context *); + int (*xPhraseSize)(Fts5Context *, int iPhrase); - int (*xInstCount)(Fts5Context*, int *pnInst); - int (*xInst)(Fts5Context*, int iIdx, int *piPhrase, int *piCol, int *piOff); + int (*xInstCount)(Fts5Context *, int *pnInst); + int (*xInst)(Fts5Context *, int iIdx, int *piPhrase, int *piCol, int *piOff); - sqlite3_int64 (*xRowid)(Fts5Context*); - int (*xColumnText)(Fts5Context*, int iCol, const char **pz, int *pn); - int (*xColumnSize)(Fts5Context*, int iCol, int *pnToken); + sqlite3_int64 (*xRowid)(Fts5Context *); + int (*xColumnText)(Fts5Context *, int iCol, const char **pz, int *pn); + int (*xColumnSize)(Fts5Context *, int iCol, int *pnToken); - int (*xQueryPhrase)(Fts5Context*, int iPhrase, void *pUserData, - int(*)(const Fts5ExtensionApi*,Fts5Context*,void*) - ); - int (*xSetAuxdata)(Fts5Context*, void *pAux, void(*xDelete)(void*)); - void *(*xGetAuxdata)(Fts5Context*, int bClear); + int (*xQueryPhrase)(Fts5Context *, + int iPhrase, + void *pUserData, + int (*)(const Fts5ExtensionApi *, Fts5Context *, void *)); + int (*xSetAuxdata)(Fts5Context *, void *pAux, void (*xDelete)(void *)); + void *(*xGetAuxdata)(Fts5Context *, int bClear); - int (*xPhraseFirst)(Fts5Context*, int iPhrase, Fts5PhraseIter*, int*, int*); - void (*xPhraseNext)(Fts5Context*, Fts5PhraseIter*, int *piCol, int *piOff); + int (*xPhraseFirst)(Fts5Context *, int iPhrase, Fts5PhraseIter *, int *, int *); + void (*xPhraseNext)(Fts5Context *, Fts5PhraseIter *, int *piCol, int *piOff); - int (*xPhraseFirstColumn)(Fts5Context*, int iPhrase, Fts5PhraseIter*, int*); - void (*xPhraseNextColumn)(Fts5Context*, Fts5PhraseIter*, int *piCol); + int (*xPhraseFirstColumn)(Fts5Context *, int iPhrase, Fts5PhraseIter *, int *); + void (*xPhraseNextColumn)(Fts5Context *, Fts5PhraseIter *, int *piCol); }; /* @@ -12815,35 +12659,34 @@ struct Fts5ExtensionApi { ** text (method (3)), not both. Doing so will not cause any errors, but is ** inefficient. */ -typedef struct Fts5Tokenizer Fts5Tokenizer; +typedef struct Fts5Tokenizer Fts5Tokenizer; typedef struct fts5_tokenizer fts5_tokenizer; struct fts5_tokenizer { - int (*xCreate)(void*, const char **azArg, int nArg, Fts5Tokenizer **ppOut); - void (*xDelete)(Fts5Tokenizer*); - int (*xTokenize)(Fts5Tokenizer*, - void *pCtx, - int flags, /* Mask of FTS5_TOKENIZE_* flags */ - const char *pText, int nText, - int (*xToken)( - void *pCtx, /* Copy of 2nd argument to xTokenize() */ - int tflags, /* Mask of FTS5_TOKEN_* flags */ - const char *pToken, /* Pointer to buffer containing token */ - int nToken, /* Size of token in bytes */ - int iStart, /* Byte offset of token within input text */ - int iEnd /* Byte offset of end of token within input text */ - ) - ); + int (*xCreate)(void *, const char **azArg, int nArg, Fts5Tokenizer **ppOut); + void (*xDelete)(Fts5Tokenizer *); + int (*xTokenize)(Fts5Tokenizer *, + void *pCtx, + int flags, /* Mask of FTS5_TOKENIZE_* flags */ + const char *pText, + int nText, + int (*xToken)(void *pCtx, /* Copy of 2nd argument to xTokenize() */ + int tflags, /* Mask of FTS5_TOKEN_* flags */ + const char *pToken, /* Pointer to buffer containing token */ + int nToken, /* Size of token in bytes */ + int iStart, /* Byte offset of token within input text */ + int iEnd /* Byte offset of end of token within input text */ + )); }; /* Flags that may be passed as the third argument to xTokenize() */ -#define FTS5_TOKENIZE_QUERY 0x0001 -#define FTS5_TOKENIZE_PREFIX 0x0002 -#define FTS5_TOKENIZE_DOCUMENT 0x0004 -#define FTS5_TOKENIZE_AUX 0x0008 +#define FTS5_TOKENIZE_QUERY 0x0001 +#define FTS5_TOKENIZE_PREFIX 0x0002 +#define FTS5_TOKENIZE_DOCUMENT 0x0004 +#define FTS5_TOKENIZE_AUX 0x0008 /* Flags that may be passed by the tokenizer implementation back to FTS5 ** as the third argument to the supplied xToken callback. */ -#define FTS5_TOKEN_COLOCATED 0x0001 /* Same position as prev. token */ +#define FTS5_TOKEN_COLOCATED 0x0001 /* Same position as prev. token */ /* ** END OF CUSTOM TOKENIZERS @@ -12854,33 +12697,24 @@ struct fts5_tokenizer { */ typedef struct fts5_api fts5_api; struct fts5_api { - int iVersion; /* Currently always set to 2 */ + int iVersion; /* Currently always set to 2 */ - /* Create a new tokenizer */ - int (*xCreateTokenizer)( - fts5_api *pApi, - const char *zName, - void *pContext, - fts5_tokenizer *pTokenizer, - void (*xDestroy)(void*) - ); + /* Create a new tokenizer */ + int (*xCreateTokenizer)(fts5_api *pApi, + const char *zName, + void *pContext, + fts5_tokenizer *pTokenizer, + void (*xDestroy)(void *)); - /* Find an existing tokenizer */ - int (*xFindTokenizer)( - fts5_api *pApi, - const char *zName, - void **ppContext, - fts5_tokenizer *pTokenizer - ); + /* Find an existing tokenizer */ + int (*xFindTokenizer)(fts5_api *pApi, const char *zName, void **ppContext, fts5_tokenizer *pTokenizer); - /* Create a new auxiliary function */ - int (*xCreateFunction)( - fts5_api *pApi, - const char *zName, - void *pContext, - fts5_extension_function xFunction, - void (*xDestroy)(void*) - ); + /* Create a new auxiliary function */ + int (*xCreateFunction)(fts5_api *pApi, + const char *zName, + void *pContext, + fts5_extension_function xFunction, + void (*xDestroy)(void *)); }; /* @@ -12888,7 +12722,7 @@ struct fts5_api { *************************************************************************/ #ifdef __cplusplus -} /* end of the 'extern "C"' block */ +} /* end of the 'extern "C"' block */ #endif #endif /* _FTS5_H */ diff --git a/srcs/libs/include/sqlite3/sqlite3ext.h b/srcs/libs/include/sqlite3/sqlite3ext.h index 5b2fc3c..664b291 100644 --- a/srcs/libs/include/sqlite3/sqlite3ext.h +++ b/srcs/libs/include/sqlite3/sqlite3ext.h @@ -30,343 +30,359 @@ ** libraries! */ struct sqlite3_api_routines { - void * (*aggregate_context)(sqlite3_context*,int nBytes); - int (*aggregate_count)(sqlite3_context*); - int (*bind_blob)(sqlite3_stmt*,int,const void*,int n,void(*)(void*)); - int (*bind_double)(sqlite3_stmt*,int,double); - int (*bind_int)(sqlite3_stmt*,int,int); - int (*bind_int64)(sqlite3_stmt*,int,sqlite_int64); - int (*bind_null)(sqlite3_stmt*,int); - int (*bind_parameter_count)(sqlite3_stmt*); - int (*bind_parameter_index)(sqlite3_stmt*,const char*zName); - const char * (*bind_parameter_name)(sqlite3_stmt*,int); - int (*bind_text)(sqlite3_stmt*,int,const char*,int n,void(*)(void*)); - int (*bind_text16)(sqlite3_stmt*,int,const void*,int,void(*)(void*)); - int (*bind_value)(sqlite3_stmt*,int,const sqlite3_value*); - int (*busy_handler)(sqlite3*,int(*)(void*,int),void*); - int (*busy_timeout)(sqlite3*,int ms); - int (*changes)(sqlite3*); - int (*close)(sqlite3*); - int (*collation_needed)(sqlite3*,void*,void(*)(void*,sqlite3*, - int eTextRep,const char*)); - int (*collation_needed16)(sqlite3*,void*,void(*)(void*,sqlite3*, - int eTextRep,const void*)); - const void * (*column_blob)(sqlite3_stmt*,int iCol); - int (*column_bytes)(sqlite3_stmt*,int iCol); - int (*column_bytes16)(sqlite3_stmt*,int iCol); - int (*column_count)(sqlite3_stmt*pStmt); - const char * (*column_database_name)(sqlite3_stmt*,int); - const void * (*column_database_name16)(sqlite3_stmt*,int); - const char * (*column_decltype)(sqlite3_stmt*,int i); - const void * (*column_decltype16)(sqlite3_stmt*,int); - double (*column_double)(sqlite3_stmt*,int iCol); - int (*column_int)(sqlite3_stmt*,int iCol); - sqlite_int64 (*column_int64)(sqlite3_stmt*,int iCol); - const char * (*column_name)(sqlite3_stmt*,int); - const void * (*column_name16)(sqlite3_stmt*,int); - const char * (*column_origin_name)(sqlite3_stmt*,int); - const void * (*column_origin_name16)(sqlite3_stmt*,int); - const char * (*column_table_name)(sqlite3_stmt*,int); - const void * (*column_table_name16)(sqlite3_stmt*,int); - const unsigned char * (*column_text)(sqlite3_stmt*,int iCol); - const void * (*column_text16)(sqlite3_stmt*,int iCol); - int (*column_type)(sqlite3_stmt*,int iCol); - sqlite3_value* (*column_value)(sqlite3_stmt*,int iCol); - void * (*commit_hook)(sqlite3*,int(*)(void*),void*); - int (*complete)(const char*sql); - int (*complete16)(const void*sql); - int (*create_collation)(sqlite3*,const char*,int,void*, - int(*)(void*,int,const void*,int,const void*)); - int (*create_collation16)(sqlite3*,const void*,int,void*, - int(*)(void*,int,const void*,int,const void*)); - int (*create_function)(sqlite3*,const char*,int,int,void*, - void (*xFunc)(sqlite3_context*,int,sqlite3_value**), - void (*xStep)(sqlite3_context*,int,sqlite3_value**), - void (*xFinal)(sqlite3_context*)); - int (*create_function16)(sqlite3*,const void*,int,int,void*, - void (*xFunc)(sqlite3_context*,int,sqlite3_value**), - void (*xStep)(sqlite3_context*,int,sqlite3_value**), - void (*xFinal)(sqlite3_context*)); - int (*create_module)(sqlite3*,const char*,const sqlite3_module*,void*); - int (*data_count)(sqlite3_stmt*pStmt); - sqlite3 * (*db_handle)(sqlite3_stmt*); - int (*declare_vtab)(sqlite3*,const char*); - int (*enable_shared_cache)(int); - int (*errcode)(sqlite3*db); - const char * (*errmsg)(sqlite3*); - const void * (*errmsg16)(sqlite3*); - int (*exec)(sqlite3*,const char*,sqlite3_callback,void*,char**); - int (*expired)(sqlite3_stmt*); - int (*finalize)(sqlite3_stmt*pStmt); - void (*free)(void*); - void (*free_table)(char**result); - int (*get_autocommit)(sqlite3*); - void * (*get_auxdata)(sqlite3_context*,int); - int (*get_table)(sqlite3*,const char*,char***,int*,int*,char**); - int (*global_recover)(void); - void (*interruptx)(sqlite3*); - sqlite_int64 (*last_insert_rowid)(sqlite3*); - const char * (*libversion)(void); - int (*libversion_number)(void); - void *(*malloc)(int); - char * (*mprintf)(const char*,...); - int (*open)(const char*,sqlite3**); - int (*open16)(const void*,sqlite3**); - int (*prepare)(sqlite3*,const char*,int,sqlite3_stmt**,const char**); - int (*prepare16)(sqlite3*,const void*,int,sqlite3_stmt**,const void**); - void * (*profile)(sqlite3*,void(*)(void*,const char*,sqlite_uint64),void*); - void (*progress_handler)(sqlite3*,int,int(*)(void*),void*); - void *(*realloc)(void*,int); - int (*reset)(sqlite3_stmt*pStmt); - void (*result_blob)(sqlite3_context*,const void*,int,void(*)(void*)); - void (*result_double)(sqlite3_context*,double); - void (*result_error)(sqlite3_context*,const char*,int); - void (*result_error16)(sqlite3_context*,const void*,int); - void (*result_int)(sqlite3_context*,int); - void (*result_int64)(sqlite3_context*,sqlite_int64); - void (*result_null)(sqlite3_context*); - void (*result_text)(sqlite3_context*,const char*,int,void(*)(void*)); - void (*result_text16)(sqlite3_context*,const void*,int,void(*)(void*)); - void (*result_text16be)(sqlite3_context*,const void*,int,void(*)(void*)); - void (*result_text16le)(sqlite3_context*,const void*,int,void(*)(void*)); - void (*result_value)(sqlite3_context*,sqlite3_value*); - void * (*rollback_hook)(sqlite3*,void(*)(void*),void*); - int (*set_authorizer)(sqlite3*,int(*)(void*,int,const char*,const char*, - const char*,const char*),void*); - void (*set_auxdata)(sqlite3_context*,int,void*,void (*)(void*)); - char * (*xsnprintf)(int,char*,const char*,...); - int (*step)(sqlite3_stmt*); - int (*table_column_metadata)(sqlite3*,const char*,const char*,const char*, - char const**,char const**,int*,int*,int*); - void (*thread_cleanup)(void); - int (*total_changes)(sqlite3*); - void * (*trace)(sqlite3*,void(*xTrace)(void*,const char*),void*); - int (*transfer_bindings)(sqlite3_stmt*,sqlite3_stmt*); - void * (*update_hook)(sqlite3*,void(*)(void*,int ,char const*,char const*, - sqlite_int64),void*); - void * (*user_data)(sqlite3_context*); - const void * (*value_blob)(sqlite3_value*); - int (*value_bytes)(sqlite3_value*); - int (*value_bytes16)(sqlite3_value*); - double (*value_double)(sqlite3_value*); - int (*value_int)(sqlite3_value*); - sqlite_int64 (*value_int64)(sqlite3_value*); - int (*value_numeric_type)(sqlite3_value*); - const unsigned char * (*value_text)(sqlite3_value*); - const void * (*value_text16)(sqlite3_value*); - const void * (*value_text16be)(sqlite3_value*); - const void * (*value_text16le)(sqlite3_value*); - int (*value_type)(sqlite3_value*); - char *(*vmprintf)(const char*,va_list); - /* Added ??? */ - int (*overload_function)(sqlite3*, const char *zFuncName, int nArg); - /* Added by 3.3.13 */ - int (*prepare_v2)(sqlite3*,const char*,int,sqlite3_stmt**,const char**); - int (*prepare16_v2)(sqlite3*,const void*,int,sqlite3_stmt**,const void**); - int (*clear_bindings)(sqlite3_stmt*); - /* Added by 3.4.1 */ - int (*create_module_v2)(sqlite3*,const char*,const sqlite3_module*,void*, - void (*xDestroy)(void *)); - /* Added by 3.5.0 */ - int (*bind_zeroblob)(sqlite3_stmt*,int,int); - int (*blob_bytes)(sqlite3_blob*); - int (*blob_close)(sqlite3_blob*); - int (*blob_open)(sqlite3*,const char*,const char*,const char*,sqlite3_int64, - int,sqlite3_blob**); - int (*blob_read)(sqlite3_blob*,void*,int,int); - int (*blob_write)(sqlite3_blob*,const void*,int,int); - int (*create_collation_v2)(sqlite3*,const char*,int,void*, - int(*)(void*,int,const void*,int,const void*), - void(*)(void*)); - int (*file_control)(sqlite3*,const char*,int,void*); - sqlite3_int64 (*memory_highwater)(int); - sqlite3_int64 (*memory_used)(void); - sqlite3_mutex *(*mutex_alloc)(int); - void (*mutex_enter)(sqlite3_mutex*); - void (*mutex_free)(sqlite3_mutex*); - void (*mutex_leave)(sqlite3_mutex*); - int (*mutex_try)(sqlite3_mutex*); - int (*open_v2)(const char*,sqlite3**,int,const char*); - int (*release_memory)(int); - void (*result_error_nomem)(sqlite3_context*); - void (*result_error_toobig)(sqlite3_context*); - int (*sleep)(int); - void (*soft_heap_limit)(int); - sqlite3_vfs *(*vfs_find)(const char*); - int (*vfs_register)(sqlite3_vfs*,int); - int (*vfs_unregister)(sqlite3_vfs*); - int (*xthreadsafe)(void); - void (*result_zeroblob)(sqlite3_context*,int); - void (*result_error_code)(sqlite3_context*,int); - int (*test_control)(int, ...); - void (*randomness)(int,void*); - sqlite3 *(*context_db_handle)(sqlite3_context*); - int (*extended_result_codes)(sqlite3*,int); - int (*limit)(sqlite3*,int,int); - sqlite3_stmt *(*next_stmt)(sqlite3*,sqlite3_stmt*); - const char *(*sql)(sqlite3_stmt*); - int (*status)(int,int*,int*,int); - int (*backup_finish)(sqlite3_backup*); - sqlite3_backup *(*backup_init)(sqlite3*,const char*,sqlite3*,const char*); - int (*backup_pagecount)(sqlite3_backup*); - int (*backup_remaining)(sqlite3_backup*); - int (*backup_step)(sqlite3_backup*,int); - const char *(*compileoption_get)(int); - int (*compileoption_used)(const char*); - int (*create_function_v2)(sqlite3*,const char*,int,int,void*, - void (*xFunc)(sqlite3_context*,int,sqlite3_value**), - void (*xStep)(sqlite3_context*,int,sqlite3_value**), - void (*xFinal)(sqlite3_context*), - void(*xDestroy)(void*)); - int (*db_config)(sqlite3*,int,...); - sqlite3_mutex *(*db_mutex)(sqlite3*); - int (*db_status)(sqlite3*,int,int*,int*,int); - int (*extended_errcode)(sqlite3*); - void (*log)(int,const char*,...); - sqlite3_int64 (*soft_heap_limit64)(sqlite3_int64); - const char *(*sourceid)(void); - int (*stmt_status)(sqlite3_stmt*,int,int); - int (*strnicmp)(const char*,const char*,int); - int (*unlock_notify)(sqlite3*,void(*)(void**,int),void*); - int (*wal_autocheckpoint)(sqlite3*,int); - int (*wal_checkpoint)(sqlite3*,const char*); - void *(*wal_hook)(sqlite3*,int(*)(void*,sqlite3*,const char*,int),void*); - int (*blob_reopen)(sqlite3_blob*,sqlite3_int64); - int (*vtab_config)(sqlite3*,int op,...); - int (*vtab_on_conflict)(sqlite3*); - /* Version 3.7.16 and later */ - int (*close_v2)(sqlite3*); - const char *(*db_filename)(sqlite3*,const char*); - int (*db_readonly)(sqlite3*,const char*); - int (*db_release_memory)(sqlite3*); - const char *(*errstr)(int); - int (*stmt_busy)(sqlite3_stmt*); - int (*stmt_readonly)(sqlite3_stmt*); - int (*stricmp)(const char*,const char*); - int (*uri_boolean)(const char*,const char*,int); - sqlite3_int64 (*uri_int64)(const char*,const char*,sqlite3_int64); - const char *(*uri_parameter)(const char*,const char*); - char *(*xvsnprintf)(int,char*,const char*,va_list); - int (*wal_checkpoint_v2)(sqlite3*,const char*,int,int*,int*); - /* Version 3.8.7 and later */ - int (*auto_extension)(void(*)(void)); - int (*bind_blob64)(sqlite3_stmt*,int,const void*,sqlite3_uint64, - void(*)(void*)); - int (*bind_text64)(sqlite3_stmt*,int,const char*,sqlite3_uint64, - void(*)(void*),unsigned char); - int (*cancel_auto_extension)(void(*)(void)); - int (*load_extension)(sqlite3*,const char*,const char*,char**); - void *(*malloc64)(sqlite3_uint64); - sqlite3_uint64 (*msize)(void*); - void *(*realloc64)(void*,sqlite3_uint64); - void (*reset_auto_extension)(void); - void (*result_blob64)(sqlite3_context*,const void*,sqlite3_uint64, - void(*)(void*)); - void (*result_text64)(sqlite3_context*,const char*,sqlite3_uint64, - void(*)(void*), unsigned char); - int (*strglob)(const char*,const char*); - /* Version 3.8.11 and later */ - sqlite3_value *(*value_dup)(const sqlite3_value*); - void (*value_free)(sqlite3_value*); - int (*result_zeroblob64)(sqlite3_context*,sqlite3_uint64); - int (*bind_zeroblob64)(sqlite3_stmt*, int, sqlite3_uint64); - /* Version 3.9.0 and later */ - unsigned int (*value_subtype)(sqlite3_value*); - void (*result_subtype)(sqlite3_context*,unsigned int); - /* Version 3.10.0 and later */ - int (*status64)(int,sqlite3_int64*,sqlite3_int64*,int); - int (*strlike)(const char*,const char*,unsigned int); - int (*db_cacheflush)(sqlite3*); - /* Version 3.12.0 and later */ - int (*system_errno)(sqlite3*); - /* Version 3.14.0 and later */ - int (*trace_v2)(sqlite3*,unsigned,int(*)(unsigned,void*,void*,void*),void*); - char *(*expanded_sql)(sqlite3_stmt*); - /* Version 3.18.0 and later */ - void (*set_last_insert_rowid)(sqlite3*,sqlite3_int64); - /* Version 3.20.0 and later */ - int (*prepare_v3)(sqlite3*,const char*,int,unsigned int, - sqlite3_stmt**,const char**); - int (*prepare16_v3)(sqlite3*,const void*,int,unsigned int, - sqlite3_stmt**,const void**); - int (*bind_pointer)(sqlite3_stmt*,int,void*,const char*,void(*)(void*)); - void (*result_pointer)(sqlite3_context*,void*,const char*,void(*)(void*)); - void *(*value_pointer)(sqlite3_value*,const char*); - int (*vtab_nochange)(sqlite3_context*); - int (*value_nochange)(sqlite3_value*); - const char *(*vtab_collation)(sqlite3_index_info*,int); - /* Version 3.24.0 and later */ - int (*keyword_count)(void); - int (*keyword_name)(int,const char**,int*); - int (*keyword_check)(const char*,int); - sqlite3_str *(*str_new)(sqlite3*); - char *(*str_finish)(sqlite3_str*); - void (*str_appendf)(sqlite3_str*, const char *zFormat, ...); - void (*str_vappendf)(sqlite3_str*, const char *zFormat, va_list); - void (*str_append)(sqlite3_str*, const char *zIn, int N); - void (*str_appendall)(sqlite3_str*, const char *zIn); - void (*str_appendchar)(sqlite3_str*, int N, char C); - void (*str_reset)(sqlite3_str*); - int (*str_errcode)(sqlite3_str*); - int (*str_length)(sqlite3_str*); - char *(*str_value)(sqlite3_str*); - /* Version 3.25.0 and later */ - int (*create_window_function)(sqlite3*,const char*,int,int,void*, - void (*xStep)(sqlite3_context*,int,sqlite3_value**), - void (*xFinal)(sqlite3_context*), - void (*xValue)(sqlite3_context*), - void (*xInv)(sqlite3_context*,int,sqlite3_value**), - void(*xDestroy)(void*)); - /* Version 3.26.0 and later */ - const char *(*normalized_sql)(sqlite3_stmt*); - /* Version 3.28.0 and later */ - int (*stmt_isexplain)(sqlite3_stmt*); - int (*value_frombind)(sqlite3_value*); - /* Version 3.30.0 and later */ - int (*drop_modules)(sqlite3*,const char**); - /* Version 3.31.0 and later */ - sqlite3_int64 (*hard_heap_limit64)(sqlite3_int64); - const char *(*uri_key)(const char*,int); - const char *(*filename_database)(const char*); - const char *(*filename_journal)(const char*); - const char *(*filename_wal)(const char*); - /* Version 3.32.0 and later */ - char *(*create_filename)(const char*,const char*,const char*, - int,const char**); - void (*free_filename)(char*); - sqlite3_file *(*database_file_object)(const char*); - /* Version 3.34.0 and later */ - int (*txn_state)(sqlite3*,const char*); - /* Version 3.36.1 and later */ - sqlite3_int64 (*changes64)(sqlite3*); - sqlite3_int64 (*total_changes64)(sqlite3*); - /* Version 3.37.0 and later */ - int (*autovacuum_pages)(sqlite3*, - unsigned int(*)(void*,const char*,unsigned int,unsigned int,unsigned int), - void*, void(*)(void*)); - /* Version 3.38.0 and later */ - int (*error_offset)(sqlite3*); - int (*vtab_rhs_value)(sqlite3_index_info*,int,sqlite3_value**); - int (*vtab_distinct)(sqlite3_index_info*); - int (*vtab_in)(sqlite3_index_info*,int,int); - int (*vtab_in_first)(sqlite3_value*,sqlite3_value**); - int (*vtab_in_next)(sqlite3_value*,sqlite3_value**); - /* Version 3.39.0 and later */ - int (*deserialize)(sqlite3*,const char*,unsigned char*, - sqlite3_int64,sqlite3_int64,unsigned); - unsigned char *(*serialize)(sqlite3*,const char *,sqlite3_int64*, - unsigned int); - const char *(*db_name)(sqlite3*,int); + void *(*aggregate_context)(sqlite3_context *, int nBytes); + int (*aggregate_count)(sqlite3_context *); + int (*bind_blob)(sqlite3_stmt *, int, const void *, int n, void (*)(void *)); + int (*bind_double)(sqlite3_stmt *, int, double); + int (*bind_int)(sqlite3_stmt *, int, int); + int (*bind_int64)(sqlite3_stmt *, int, sqlite_int64); + int (*bind_null)(sqlite3_stmt *, int); + int (*bind_parameter_count)(sqlite3_stmt *); + int (*bind_parameter_index)(sqlite3_stmt *, const char *zName); + const char *(*bind_parameter_name)(sqlite3_stmt *, int); + int (*bind_text)(sqlite3_stmt *, int, const char *, int n, void (*)(void *)); + int (*bind_text16)(sqlite3_stmt *, int, const void *, int, void (*)(void *)); + int (*bind_value)(sqlite3_stmt *, int, const sqlite3_value *); + int (*busy_handler)(sqlite3 *, int (*)(void *, int), void *); + int (*busy_timeout)(sqlite3 *, int ms); + int (*changes)(sqlite3 *); + int (*close)(sqlite3 *); + int (*collation_needed)(sqlite3 *, void *, void (*)(void *, sqlite3 *, int eTextRep, const char *)); + int (*collation_needed16)(sqlite3 *, void *, void (*)(void *, sqlite3 *, int eTextRep, const void *)); + const void *(*column_blob)(sqlite3_stmt *, int iCol); + int (*column_bytes)(sqlite3_stmt *, int iCol); + int (*column_bytes16)(sqlite3_stmt *, int iCol); + int (*column_count)(sqlite3_stmt *pStmt); + const char *(*column_database_name)(sqlite3_stmt *, int); + const void *(*column_database_name16)(sqlite3_stmt *, int); + const char *(*column_decltype)(sqlite3_stmt *, int i); + const void *(*column_decltype16)(sqlite3_stmt *, int); + double (*column_double)(sqlite3_stmt *, int iCol); + int (*column_int)(sqlite3_stmt *, int iCol); + sqlite_int64 (*column_int64)(sqlite3_stmt *, int iCol); + const char *(*column_name)(sqlite3_stmt *, int); + const void *(*column_name16)(sqlite3_stmt *, int); + const char *(*column_origin_name)(sqlite3_stmt *, int); + const void *(*column_origin_name16)(sqlite3_stmt *, int); + const char *(*column_table_name)(sqlite3_stmt *, int); + const void *(*column_table_name16)(sqlite3_stmt *, int); + const unsigned char *(*column_text)(sqlite3_stmt *, int iCol); + const void *(*column_text16)(sqlite3_stmt *, int iCol); + int (*column_type)(sqlite3_stmt *, int iCol); + sqlite3_value *(*column_value)(sqlite3_stmt *, int iCol); + void *(*commit_hook)(sqlite3 *, int (*)(void *), void *); + int (*complete)(const char *sql); + int (*complete16)(const void *sql); + int ( + *create_collation)(sqlite3 *, const char *, int, void *, int (*)(void *, int, const void *, int, const void *)); + int (*create_collation16)(sqlite3 *, + const void *, + int, + void *, + int (*)(void *, int, const void *, int, const void *)); + int (*create_function)(sqlite3 *, + const char *, + int, + int, + void *, + void (*xFunc)(sqlite3_context *, int, sqlite3_value **), + void (*xStep)(sqlite3_context *, int, sqlite3_value **), + void (*xFinal)(sqlite3_context *)); + int (*create_function16)(sqlite3 *, + const void *, + int, + int, + void *, + void (*xFunc)(sqlite3_context *, int, sqlite3_value **), + void (*xStep)(sqlite3_context *, int, sqlite3_value **), + void (*xFinal)(sqlite3_context *)); + int (*create_module)(sqlite3 *, const char *, const sqlite3_module *, void *); + int (*data_count)(sqlite3_stmt *pStmt); + sqlite3 *(*db_handle)(sqlite3_stmt *); + int (*declare_vtab)(sqlite3 *, const char *); + int (*enable_shared_cache)(int); + int (*errcode)(sqlite3 *db); + const char *(*errmsg)(sqlite3 *); + const void *(*errmsg16)(sqlite3 *); + int (*exec)(sqlite3 *, const char *, sqlite3_callback, void *, char **); + int (*expired)(sqlite3_stmt *); + int (*finalize)(sqlite3_stmt *pStmt); + void (*free)(void *); + void (*free_table)(char **result); + int (*get_autocommit)(sqlite3 *); + void *(*get_auxdata)(sqlite3_context *, int); + int (*get_table)(sqlite3 *, const char *, char ***, int *, int *, char **); + int (*global_recover)(void); + void (*interruptx)(sqlite3 *); + sqlite_int64 (*last_insert_rowid)(sqlite3 *); + const char *(*libversion)(void); + int (*libversion_number)(void); + void *(*malloc)(int); + char *(*mprintf)(const char *, ...); + int (*open)(const char *, sqlite3 **); + int (*open16)(const void *, sqlite3 **); + int (*prepare)(sqlite3 *, const char *, int, sqlite3_stmt **, const char **); + int (*prepare16)(sqlite3 *, const void *, int, sqlite3_stmt **, const void **); + void *(*profile)(sqlite3 *, void (*)(void *, const char *, sqlite_uint64), void *); + void (*progress_handler)(sqlite3 *, int, int (*)(void *), void *); + void *(*realloc)(void *, int); + int (*reset)(sqlite3_stmt *pStmt); + void (*result_blob)(sqlite3_context *, const void *, int, void (*)(void *)); + void (*result_double)(sqlite3_context *, double); + void (*result_error)(sqlite3_context *, const char *, int); + void (*result_error16)(sqlite3_context *, const void *, int); + void (*result_int)(sqlite3_context *, int); + void (*result_int64)(sqlite3_context *, sqlite_int64); + void (*result_null)(sqlite3_context *); + void (*result_text)(sqlite3_context *, const char *, int, void (*)(void *)); + void (*result_text16)(sqlite3_context *, const void *, int, void (*)(void *)); + void (*result_text16be)(sqlite3_context *, const void *, int, void (*)(void *)); + void (*result_text16le)(sqlite3_context *, const void *, int, void (*)(void *)); + void (*result_value)(sqlite3_context *, sqlite3_value *); + void *(*rollback_hook)(sqlite3 *, void (*)(void *), void *); + int (*set_authorizer)(sqlite3 *, + int (*)(void *, int, const char *, const char *, const char *, const char *), + void *); + void (*set_auxdata)(sqlite3_context *, int, void *, void (*)(void *)); + char *(*xsnprintf)(int, char *, const char *, ...); + int (*step)(sqlite3_stmt *); + int (*table_column_metadata)(sqlite3 *, + const char *, + const char *, + const char *, + char const **, + char const **, + int *, + int *, + int *); + void (*thread_cleanup)(void); + int (*total_changes)(sqlite3 *); + void *(*trace)(sqlite3 *, void (*xTrace)(void *, const char *), void *); + int (*transfer_bindings)(sqlite3_stmt *, sqlite3_stmt *); + void *(*update_hook)(sqlite3 *, void (*)(void *, int, char const *, char const *, sqlite_int64), void *); + void *(*user_data)(sqlite3_context *); + const void *(*value_blob)(sqlite3_value *); + int (*value_bytes)(sqlite3_value *); + int (*value_bytes16)(sqlite3_value *); + double (*value_double)(sqlite3_value *); + int (*value_int)(sqlite3_value *); + sqlite_int64 (*value_int64)(sqlite3_value *); + int (*value_numeric_type)(sqlite3_value *); + const unsigned char *(*value_text)(sqlite3_value *); + const void *(*value_text16)(sqlite3_value *); + const void *(*value_text16be)(sqlite3_value *); + const void *(*value_text16le)(sqlite3_value *); + int (*value_type)(sqlite3_value *); + char *(*vmprintf)(const char *, va_list); + /* Added ??? */ + int (*overload_function)(sqlite3 *, const char *zFuncName, int nArg); + /* Added by 3.3.13 */ + int (*prepare_v2)(sqlite3 *, const char *, int, sqlite3_stmt **, const char **); + int (*prepare16_v2)(sqlite3 *, const void *, int, sqlite3_stmt **, const void **); + int (*clear_bindings)(sqlite3_stmt *); + /* Added by 3.4.1 */ + int (*create_module_v2)(sqlite3 *, const char *, const sqlite3_module *, void *, void (*xDestroy)(void *)); + /* Added by 3.5.0 */ + int (*bind_zeroblob)(sqlite3_stmt *, int, int); + int (*blob_bytes)(sqlite3_blob *); + int (*blob_close)(sqlite3_blob *); + int (*blob_open)(sqlite3 *, const char *, const char *, const char *, sqlite3_int64, int, sqlite3_blob **); + int (*blob_read)(sqlite3_blob *, void *, int, int); + int (*blob_write)(sqlite3_blob *, const void *, int, int); + int (*create_collation_v2)(sqlite3 *, + const char *, + int, + void *, + int (*)(void *, int, const void *, int, const void *), + void (*)(void *)); + int (*file_control)(sqlite3 *, const char *, int, void *); + sqlite3_int64 (*memory_highwater)(int); + sqlite3_int64 (*memory_used)(void); + sqlite3_mutex *(*mutex_alloc)(int); + void (*mutex_enter)(sqlite3_mutex *); + void (*mutex_free)(sqlite3_mutex *); + void (*mutex_leave)(sqlite3_mutex *); + int (*mutex_try)(sqlite3_mutex *); + int (*open_v2)(const char *, sqlite3 **, int, const char *); + int (*release_memory)(int); + void (*result_error_nomem)(sqlite3_context *); + void (*result_error_toobig)(sqlite3_context *); + int (*sleep)(int); + void (*soft_heap_limit)(int); + sqlite3_vfs *(*vfs_find)(const char *); + int (*vfs_register)(sqlite3_vfs *, int); + int (*vfs_unregister)(sqlite3_vfs *); + int (*xthreadsafe)(void); + void (*result_zeroblob)(sqlite3_context *, int); + void (*result_error_code)(sqlite3_context *, int); + int (*test_control)(int, ...); + void (*randomness)(int, void *); + sqlite3 *(*context_db_handle)(sqlite3_context *); + int (*extended_result_codes)(sqlite3 *, int); + int (*limit)(sqlite3 *, int, int); + sqlite3_stmt *(*next_stmt)(sqlite3 *, sqlite3_stmt *); + const char *(*sql)(sqlite3_stmt *); + int (*status)(int, int *, int *, int); + int (*backup_finish)(sqlite3_backup *); + sqlite3_backup *(*backup_init)(sqlite3 *, const char *, sqlite3 *, const char *); + int (*backup_pagecount)(sqlite3_backup *); + int (*backup_remaining)(sqlite3_backup *); + int (*backup_step)(sqlite3_backup *, int); + const char *(*compileoption_get)(int); + int (*compileoption_used)(const char *); + int (*create_function_v2)(sqlite3 *, + const char *, + int, + int, + void *, + void (*xFunc)(sqlite3_context *, int, sqlite3_value **), + void (*xStep)(sqlite3_context *, int, sqlite3_value **), + void (*xFinal)(sqlite3_context *), + void (*xDestroy)(void *)); + int (*db_config)(sqlite3 *, int, ...); + sqlite3_mutex *(*db_mutex)(sqlite3 *); + int (*db_status)(sqlite3 *, int, int *, int *, int); + int (*extended_errcode)(sqlite3 *); + void (*log)(int, const char *, ...); + sqlite3_int64 (*soft_heap_limit64)(sqlite3_int64); + const char *(*sourceid)(void); + int (*stmt_status)(sqlite3_stmt *, int, int); + int (*strnicmp)(const char *, const char *, int); + int (*unlock_notify)(sqlite3 *, void (*)(void **, int), void *); + int (*wal_autocheckpoint)(sqlite3 *, int); + int (*wal_checkpoint)(sqlite3 *, const char *); + void *(*wal_hook)(sqlite3 *, int (*)(void *, sqlite3 *, const char *, int), void *); + int (*blob_reopen)(sqlite3_blob *, sqlite3_int64); + int (*vtab_config)(sqlite3 *, int op, ...); + int (*vtab_on_conflict)(sqlite3 *); + /* Version 3.7.16 and later */ + int (*close_v2)(sqlite3 *); + const char *(*db_filename)(sqlite3 *, const char *); + int (*db_readonly)(sqlite3 *, const char *); + int (*db_release_memory)(sqlite3 *); + const char *(*errstr)(int); + int (*stmt_busy)(sqlite3_stmt *); + int (*stmt_readonly)(sqlite3_stmt *); + int (*stricmp)(const char *, const char *); + int (*uri_boolean)(const char *, const char *, int); + sqlite3_int64 (*uri_int64)(const char *, const char *, sqlite3_int64); + const char *(*uri_parameter)(const char *, const char *); + char *(*xvsnprintf)(int, char *, const char *, va_list); + int (*wal_checkpoint_v2)(sqlite3 *, const char *, int, int *, int *); + /* Version 3.8.7 and later */ + int (*auto_extension)(void (*)(void)); + int (*bind_blob64)(sqlite3_stmt *, int, const void *, sqlite3_uint64, void (*)(void *)); + int (*bind_text64)(sqlite3_stmt *, int, const char *, sqlite3_uint64, void (*)(void *), unsigned char); + int (*cancel_auto_extension)(void (*)(void)); + int (*load_extension)(sqlite3 *, const char *, const char *, char **); + void *(*malloc64)(sqlite3_uint64); + sqlite3_uint64 (*msize)(void *); + void *(*realloc64)(void *, sqlite3_uint64); + void (*reset_auto_extension)(void); + void (*result_blob64)(sqlite3_context *, const void *, sqlite3_uint64, void (*)(void *)); + void (*result_text64)(sqlite3_context *, const char *, sqlite3_uint64, void (*)(void *), unsigned char); + int (*strglob)(const char *, const char *); + /* Version 3.8.11 and later */ + sqlite3_value *(*value_dup)(const sqlite3_value *); + void (*value_free)(sqlite3_value *); + int (*result_zeroblob64)(sqlite3_context *, sqlite3_uint64); + int (*bind_zeroblob64)(sqlite3_stmt *, int, sqlite3_uint64); + /* Version 3.9.0 and later */ + unsigned int (*value_subtype)(sqlite3_value *); + void (*result_subtype)(sqlite3_context *, unsigned int); + /* Version 3.10.0 and later */ + int (*status64)(int, sqlite3_int64 *, sqlite3_int64 *, int); + int (*strlike)(const char *, const char *, unsigned int); + int (*db_cacheflush)(sqlite3 *); + /* Version 3.12.0 and later */ + int (*system_errno)(sqlite3 *); + /* Version 3.14.0 and later */ + int (*trace_v2)(sqlite3 *, unsigned, int (*)(unsigned, void *, void *, void *), void *); + char *(*expanded_sql)(sqlite3_stmt *); + /* Version 3.18.0 and later */ + void (*set_last_insert_rowid)(sqlite3 *, sqlite3_int64); + /* Version 3.20.0 and later */ + int (*prepare_v3)(sqlite3 *, const char *, int, unsigned int, sqlite3_stmt **, const char **); + int (*prepare16_v3)(sqlite3 *, const void *, int, unsigned int, sqlite3_stmt **, const void **); + int (*bind_pointer)(sqlite3_stmt *, int, void *, const char *, void (*)(void *)); + void (*result_pointer)(sqlite3_context *, void *, const char *, void (*)(void *)); + void *(*value_pointer)(sqlite3_value *, const char *); + int (*vtab_nochange)(sqlite3_context *); + int (*value_nochange)(sqlite3_value *); + const char *(*vtab_collation)(sqlite3_index_info *, int); + /* Version 3.24.0 and later */ + int (*keyword_count)(void); + int (*keyword_name)(int, const char **, int *); + int (*keyword_check)(const char *, int); + sqlite3_str *(*str_new)(sqlite3 *); + char *(*str_finish)(sqlite3_str *); + void (*str_appendf)(sqlite3_str *, const char *zFormat, ...); + void (*str_vappendf)(sqlite3_str *, const char *zFormat, va_list); + void (*str_append)(sqlite3_str *, const char *zIn, int N); + void (*str_appendall)(sqlite3_str *, const char *zIn); + void (*str_appendchar)(sqlite3_str *, int N, char C); + void (*str_reset)(sqlite3_str *); + int (*str_errcode)(sqlite3_str *); + int (*str_length)(sqlite3_str *); + char *(*str_value)(sqlite3_str *); + /* Version 3.25.0 and later */ + int (*create_window_function)(sqlite3 *, + const char *, + int, + int, + void *, + void (*xStep)(sqlite3_context *, int, sqlite3_value **), + void (*xFinal)(sqlite3_context *), + void (*xValue)(sqlite3_context *), + void (*xInv)(sqlite3_context *, int, sqlite3_value **), + void (*xDestroy)(void *)); + /* Version 3.26.0 and later */ + const char *(*normalized_sql)(sqlite3_stmt *); + /* Version 3.28.0 and later */ + int (*stmt_isexplain)(sqlite3_stmt *); + int (*value_frombind)(sqlite3_value *); + /* Version 3.30.0 and later */ + int (*drop_modules)(sqlite3 *, const char **); + /* Version 3.31.0 and later */ + sqlite3_int64 (*hard_heap_limit64)(sqlite3_int64); + const char *(*uri_key)(const char *, int); + const char *(*filename_database)(const char *); + const char *(*filename_journal)(const char *); + const char *(*filename_wal)(const char *); + /* Version 3.32.0 and later */ + char *(*create_filename)(const char *, const char *, const char *, int, const char **); + void (*free_filename)(char *); + sqlite3_file *(*database_file_object)(const char *); + /* Version 3.34.0 and later */ + int (*txn_state)(sqlite3 *, const char *); + /* Version 3.36.1 and later */ + sqlite3_int64 (*changes64)(sqlite3 *); + sqlite3_int64 (*total_changes64)(sqlite3 *); + /* Version 3.37.0 and later */ + int (*autovacuum_pages)(sqlite3 *, + unsigned int (*)(void *, const char *, unsigned int, unsigned int, unsigned int), + void *, + void (*)(void *)); + /* Version 3.38.0 and later */ + int (*error_offset)(sqlite3 *); + int (*vtab_rhs_value)(sqlite3_index_info *, int, sqlite3_value **); + int (*vtab_distinct)(sqlite3_index_info *); + int (*vtab_in)(sqlite3_index_info *, int, int); + int (*vtab_in_first)(sqlite3_value *, sqlite3_value **); + int (*vtab_in_next)(sqlite3_value *, sqlite3_value **); + /* Version 3.39.0 and later */ + int (*deserialize)(sqlite3 *, const char *, unsigned char *, sqlite3_int64, sqlite3_int64, unsigned); + unsigned char *(*serialize)(sqlite3 *, const char *, sqlite3_int64 *, unsigned int); + const char *(*db_name)(sqlite3 *, int); }; /* ** This is the function signature used for all extension entry points. It ** is also defined in the file "loadext.c". */ -typedef int (*sqlite3_loadext_entry)( - sqlite3 *db, /* Handle to the sqlitecipher. */ - char **pzErrMsg, /* Used to set error string on failure. */ - const sqlite3_api_routines *pThunk /* Extension API function pointers. */ +typedef int (*sqlite3_loadext_entry)(sqlite3 *db, /* Handle to the sqlitecipher. */ + char **pzErrMsg, /* Used to set error string on failure. */ + const sqlite3_api_routines *pThunk /* Extension API function pointers. */ ); /* @@ -381,9 +397,9 @@ typedef int (*sqlite3_loadext_entry)( ** SQLITE_CORE macros is undefined. */ #if !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) -#define sqlite3_aggregate_context sqlite3_api->aggregate_context +#define sqlite3_aggregate_context sqlite3_api->aggregate_context #ifndef SQLITE_OMIT_DEPRECATED -#define sqlite3_aggregate_count sqlite3_api->aggregate_count +#define sqlite3_aggregate_count sqlite3_api->aggregate_count #endif #define sqlite3_bind_blob sqlite3_api->bind_blob #define sqlite3_bind_double sqlite3_api->bind_double @@ -441,261 +457,260 @@ typedef int (*sqlite3_loadext_entry)( #define sqlite3_errmsg16 sqlite3_api->errmsg16 #define sqlite3_exec sqlite3_api->exec #ifndef SQLITE_OMIT_DEPRECATED -#define sqlite3_expired sqlite3_api->expired +#define sqlite3_expired sqlite3_api->expired #endif -#define sqlite3_finalize sqlite3_api->finalize -#define sqlite3_free sqlite3_api->free -#define sqlite3_free_table sqlite3_api->free_table -#define sqlite3_get_autocommit sqlite3_api->get_autocommit -#define sqlite3_get_auxdata sqlite3_api->get_auxdata -#define sqlite3_get_table sqlite3_api->get_table +#define sqlite3_finalize sqlite3_api->finalize +#define sqlite3_free sqlite3_api->free +#define sqlite3_free_table sqlite3_api->free_table +#define sqlite3_get_autocommit sqlite3_api->get_autocommit +#define sqlite3_get_auxdata sqlite3_api->get_auxdata +#define sqlite3_get_table sqlite3_api->get_table #ifndef SQLITE_OMIT_DEPRECATED -#define sqlite3_global_recover sqlite3_api->global_recover +#define sqlite3_global_recover sqlite3_api->global_recover #endif -#define sqlite3_interrupt sqlite3_api->interruptx -#define sqlite3_last_insert_rowid sqlite3_api->last_insert_rowid -#define sqlite3_libversion sqlite3_api->libversion -#define sqlite3_libversion_number sqlite3_api->libversion_number -#define sqlite3_malloc sqlite3_api->malloc -#define sqlite3_mprintf sqlite3_api->mprintf -#define sqlite3_open sqlite3_api->open -#define sqlite3_open16 sqlite3_api->open16 -#define sqlite3_prepare sqlite3_api->prepare -#define sqlite3_prepare16 sqlite3_api->prepare16 -#define sqlite3_prepare_v2 sqlite3_api->prepare_v2 -#define sqlite3_prepare16_v2 sqlite3_api->prepare16_v2 -#define sqlite3_profile sqlite3_api->profile -#define sqlite3_progress_handler sqlite3_api->progress_handler -#define sqlite3_realloc sqlite3_api->realloc -#define sqlite3_reset sqlite3_api->reset -#define sqlite3_result_blob sqlite3_api->result_blob -#define sqlite3_result_double sqlite3_api->result_double -#define sqlite3_result_error sqlite3_api->result_error -#define sqlite3_result_error16 sqlite3_api->result_error16 -#define sqlite3_result_int sqlite3_api->result_int -#define sqlite3_result_int64 sqlite3_api->result_int64 -#define sqlite3_result_null sqlite3_api->result_null -#define sqlite3_result_text sqlite3_api->result_text -#define sqlite3_result_text16 sqlite3_api->result_text16 -#define sqlite3_result_text16be sqlite3_api->result_text16be -#define sqlite3_result_text16le sqlite3_api->result_text16le -#define sqlite3_result_value sqlite3_api->result_value -#define sqlite3_rollback_hook sqlite3_api->rollback_hook -#define sqlite3_set_authorizer sqlite3_api->set_authorizer -#define sqlite3_set_auxdata sqlite3_api->set_auxdata -#define sqlite3_snprintf sqlite3_api->xsnprintf -#define sqlite3_step sqlite3_api->step -#define sqlite3_table_column_metadata sqlite3_api->table_column_metadata -#define sqlite3_thread_cleanup sqlite3_api->thread_cleanup -#define sqlite3_total_changes sqlite3_api->total_changes -#define sqlite3_trace sqlite3_api->trace +#define sqlite3_interrupt sqlite3_api->interruptx +#define sqlite3_last_insert_rowid sqlite3_api->last_insert_rowid +#define sqlite3_libversion sqlite3_api->libversion +#define sqlite3_libversion_number sqlite3_api->libversion_number +#define sqlite3_malloc sqlite3_api->malloc +#define sqlite3_mprintf sqlite3_api->mprintf +#define sqlite3_open sqlite3_api->open +#define sqlite3_open16 sqlite3_api->open16 +#define sqlite3_prepare sqlite3_api->prepare +#define sqlite3_prepare16 sqlite3_api->prepare16 +#define sqlite3_prepare_v2 sqlite3_api->prepare_v2 +#define sqlite3_prepare16_v2 sqlite3_api->prepare16_v2 +#define sqlite3_profile sqlite3_api->profile +#define sqlite3_progress_handler sqlite3_api->progress_handler +#define sqlite3_realloc sqlite3_api->realloc +#define sqlite3_reset sqlite3_api->reset +#define sqlite3_result_blob sqlite3_api->result_blob +#define sqlite3_result_double sqlite3_api->result_double +#define sqlite3_result_error sqlite3_api->result_error +#define sqlite3_result_error16 sqlite3_api->result_error16 +#define sqlite3_result_int sqlite3_api->result_int +#define sqlite3_result_int64 sqlite3_api->result_int64 +#define sqlite3_result_null sqlite3_api->result_null +#define sqlite3_result_text sqlite3_api->result_text +#define sqlite3_result_text16 sqlite3_api->result_text16 +#define sqlite3_result_text16be sqlite3_api->result_text16be +#define sqlite3_result_text16le sqlite3_api->result_text16le +#define sqlite3_result_value sqlite3_api->result_value +#define sqlite3_rollback_hook sqlite3_api->rollback_hook +#define sqlite3_set_authorizer sqlite3_api->set_authorizer +#define sqlite3_set_auxdata sqlite3_api->set_auxdata +#define sqlite3_snprintf sqlite3_api->xsnprintf +#define sqlite3_step sqlite3_api->step +#define sqlite3_table_column_metadata sqlite3_api->table_column_metadata +#define sqlite3_thread_cleanup sqlite3_api->thread_cleanup +#define sqlite3_total_changes sqlite3_api->total_changes +#define sqlite3_trace sqlite3_api->trace #ifndef SQLITE_OMIT_DEPRECATED -#define sqlite3_transfer_bindings sqlite3_api->transfer_bindings +#define sqlite3_transfer_bindings sqlite3_api->transfer_bindings #endif -#define sqlite3_update_hook sqlite3_api->update_hook -#define sqlite3_user_data sqlite3_api->user_data -#define sqlite3_value_blob sqlite3_api->value_blob -#define sqlite3_value_bytes sqlite3_api->value_bytes -#define sqlite3_value_bytes16 sqlite3_api->value_bytes16 -#define sqlite3_value_double sqlite3_api->value_double -#define sqlite3_value_int sqlite3_api->value_int -#define sqlite3_value_int64 sqlite3_api->value_int64 -#define sqlite3_value_numeric_type sqlite3_api->value_numeric_type -#define sqlite3_value_text sqlite3_api->value_text -#define sqlite3_value_text16 sqlite3_api->value_text16 -#define sqlite3_value_text16be sqlite3_api->value_text16be -#define sqlite3_value_text16le sqlite3_api->value_text16le -#define sqlite3_value_type sqlite3_api->value_type -#define sqlite3_vmprintf sqlite3_api->vmprintf -#define sqlite3_vsnprintf sqlite3_api->xvsnprintf -#define sqlite3_overload_function sqlite3_api->overload_function -#define sqlite3_prepare_v2 sqlite3_api->prepare_v2 -#define sqlite3_prepare16_v2 sqlite3_api->prepare16_v2 -#define sqlite3_clear_bindings sqlite3_api->clear_bindings -#define sqlite3_bind_zeroblob sqlite3_api->bind_zeroblob -#define sqlite3_blob_bytes sqlite3_api->blob_bytes -#define sqlite3_blob_close sqlite3_api->blob_close -#define sqlite3_blob_open sqlite3_api->blob_open -#define sqlite3_blob_read sqlite3_api->blob_read -#define sqlite3_blob_write sqlite3_api->blob_write -#define sqlite3_create_collation_v2 sqlite3_api->create_collation_v2 -#define sqlite3_file_control sqlite3_api->file_control -#define sqlite3_memory_highwater sqlite3_api->memory_highwater -#define sqlite3_memory_used sqlite3_api->memory_used -#define sqlite3_mutex_alloc sqlite3_api->mutex_alloc -#define sqlite3_mutex_enter sqlite3_api->mutex_enter -#define sqlite3_mutex_free sqlite3_api->mutex_free -#define sqlite3_mutex_leave sqlite3_api->mutex_leave -#define sqlite3_mutex_try sqlite3_api->mutex_try -#define sqlite3_open_v2 sqlite3_api->open_v2 -#define sqlite3_release_memory sqlite3_api->release_memory -#define sqlite3_result_error_nomem sqlite3_api->result_error_nomem -#define sqlite3_result_error_toobig sqlite3_api->result_error_toobig -#define sqlite3_sleep sqlite3_api->sleep -#define sqlite3_soft_heap_limit sqlite3_api->soft_heap_limit -#define sqlite3_vfs_find sqlite3_api->vfs_find -#define sqlite3_vfs_register sqlite3_api->vfs_register -#define sqlite3_vfs_unregister sqlite3_api->vfs_unregister -#define sqlite3_threadsafe sqlite3_api->xthreadsafe -#define sqlite3_result_zeroblob sqlite3_api->result_zeroblob -#define sqlite3_result_error_code sqlite3_api->result_error_code -#define sqlite3_test_control sqlite3_api->test_control -#define sqlite3_randomness sqlite3_api->randomness -#define sqlite3_context_db_handle sqlite3_api->context_db_handle -#define sqlite3_extended_result_codes sqlite3_api->extended_result_codes -#define sqlite3_limit sqlite3_api->limit -#define sqlite3_next_stmt sqlite3_api->next_stmt -#define sqlite3_sql sqlite3_api->sql -#define sqlite3_status sqlite3_api->status -#define sqlite3_backup_finish sqlite3_api->backup_finish -#define sqlite3_backup_init sqlite3_api->backup_init -#define sqlite3_backup_pagecount sqlite3_api->backup_pagecount -#define sqlite3_backup_remaining sqlite3_api->backup_remaining -#define sqlite3_backup_step sqlite3_api->backup_step -#define sqlite3_compileoption_get sqlite3_api->compileoption_get -#define sqlite3_compileoption_used sqlite3_api->compileoption_used -#define sqlite3_create_function_v2 sqlite3_api->create_function_v2 -#define sqlite3_db_config sqlite3_api->db_config -#define sqlite3_db_mutex sqlite3_api->db_mutex -#define sqlite3_db_status sqlite3_api->db_status -#define sqlite3_extended_errcode sqlite3_api->extended_errcode -#define sqlite3_log sqlite3_api->log -#define sqlite3_soft_heap_limit64 sqlite3_api->soft_heap_limit64 -#define sqlite3_sourceid sqlite3_api->sourceid -#define sqlite3_stmt_status sqlite3_api->stmt_status -#define sqlite3_strnicmp sqlite3_api->strnicmp -#define sqlite3_unlock_notify sqlite3_api->unlock_notify -#define sqlite3_wal_autocheckpoint sqlite3_api->wal_autocheckpoint -#define sqlite3_wal_checkpoint sqlite3_api->wal_checkpoint -#define sqlite3_wal_hook sqlite3_api->wal_hook -#define sqlite3_blob_reopen sqlite3_api->blob_reopen -#define sqlite3_vtab_config sqlite3_api->vtab_config -#define sqlite3_vtab_on_conflict sqlite3_api->vtab_on_conflict +#define sqlite3_update_hook sqlite3_api->update_hook +#define sqlite3_user_data sqlite3_api->user_data +#define sqlite3_value_blob sqlite3_api->value_blob +#define sqlite3_value_bytes sqlite3_api->value_bytes +#define sqlite3_value_bytes16 sqlite3_api->value_bytes16 +#define sqlite3_value_double sqlite3_api->value_double +#define sqlite3_value_int sqlite3_api->value_int +#define sqlite3_value_int64 sqlite3_api->value_int64 +#define sqlite3_value_numeric_type sqlite3_api->value_numeric_type +#define sqlite3_value_text sqlite3_api->value_text +#define sqlite3_value_text16 sqlite3_api->value_text16 +#define sqlite3_value_text16be sqlite3_api->value_text16be +#define sqlite3_value_text16le sqlite3_api->value_text16le +#define sqlite3_value_type sqlite3_api->value_type +#define sqlite3_vmprintf sqlite3_api->vmprintf +#define sqlite3_vsnprintf sqlite3_api->xvsnprintf +#define sqlite3_overload_function sqlite3_api->overload_function +#define sqlite3_prepare_v2 sqlite3_api->prepare_v2 +#define sqlite3_prepare16_v2 sqlite3_api->prepare16_v2 +#define sqlite3_clear_bindings sqlite3_api->clear_bindings +#define sqlite3_bind_zeroblob sqlite3_api->bind_zeroblob +#define sqlite3_blob_bytes sqlite3_api->blob_bytes +#define sqlite3_blob_close sqlite3_api->blob_close +#define sqlite3_blob_open sqlite3_api->blob_open +#define sqlite3_blob_read sqlite3_api->blob_read +#define sqlite3_blob_write sqlite3_api->blob_write +#define sqlite3_create_collation_v2 sqlite3_api->create_collation_v2 +#define sqlite3_file_control sqlite3_api->file_control +#define sqlite3_memory_highwater sqlite3_api->memory_highwater +#define sqlite3_memory_used sqlite3_api->memory_used +#define sqlite3_mutex_alloc sqlite3_api->mutex_alloc +#define sqlite3_mutex_enter sqlite3_api->mutex_enter +#define sqlite3_mutex_free sqlite3_api->mutex_free +#define sqlite3_mutex_leave sqlite3_api->mutex_leave +#define sqlite3_mutex_try sqlite3_api->mutex_try +#define sqlite3_open_v2 sqlite3_api->open_v2 +#define sqlite3_release_memory sqlite3_api->release_memory +#define sqlite3_result_error_nomem sqlite3_api->result_error_nomem +#define sqlite3_result_error_toobig sqlite3_api->result_error_toobig +#define sqlite3_sleep sqlite3_api->sleep +#define sqlite3_soft_heap_limit sqlite3_api->soft_heap_limit +#define sqlite3_vfs_find sqlite3_api->vfs_find +#define sqlite3_vfs_register sqlite3_api->vfs_register +#define sqlite3_vfs_unregister sqlite3_api->vfs_unregister +#define sqlite3_threadsafe sqlite3_api->xthreadsafe +#define sqlite3_result_zeroblob sqlite3_api->result_zeroblob +#define sqlite3_result_error_code sqlite3_api->result_error_code +#define sqlite3_test_control sqlite3_api->test_control +#define sqlite3_randomness sqlite3_api->randomness +#define sqlite3_context_db_handle sqlite3_api->context_db_handle +#define sqlite3_extended_result_codes sqlite3_api->extended_result_codes +#define sqlite3_limit sqlite3_api->limit +#define sqlite3_next_stmt sqlite3_api->next_stmt +#define sqlite3_sql sqlite3_api->sql +#define sqlite3_status sqlite3_api->status +#define sqlite3_backup_finish sqlite3_api->backup_finish +#define sqlite3_backup_init sqlite3_api->backup_init +#define sqlite3_backup_pagecount sqlite3_api->backup_pagecount +#define sqlite3_backup_remaining sqlite3_api->backup_remaining +#define sqlite3_backup_step sqlite3_api->backup_step +#define sqlite3_compileoption_get sqlite3_api->compileoption_get +#define sqlite3_compileoption_used sqlite3_api->compileoption_used +#define sqlite3_create_function_v2 sqlite3_api->create_function_v2 +#define sqlite3_db_config sqlite3_api->db_config +#define sqlite3_db_mutex sqlite3_api->db_mutex +#define sqlite3_db_status sqlite3_api->db_status +#define sqlite3_extended_errcode sqlite3_api->extended_errcode +#define sqlite3_log sqlite3_api->log +#define sqlite3_soft_heap_limit64 sqlite3_api->soft_heap_limit64 +#define sqlite3_sourceid sqlite3_api->sourceid +#define sqlite3_stmt_status sqlite3_api->stmt_status +#define sqlite3_strnicmp sqlite3_api->strnicmp +#define sqlite3_unlock_notify sqlite3_api->unlock_notify +#define sqlite3_wal_autocheckpoint sqlite3_api->wal_autocheckpoint +#define sqlite3_wal_checkpoint sqlite3_api->wal_checkpoint +#define sqlite3_wal_hook sqlite3_api->wal_hook +#define sqlite3_blob_reopen sqlite3_api->blob_reopen +#define sqlite3_vtab_config sqlite3_api->vtab_config +#define sqlite3_vtab_on_conflict sqlite3_api->vtab_on_conflict /* Version 3.7.16 and later */ -#define sqlite3_close_v2 sqlite3_api->close_v2 -#define sqlite3_db_filename sqlite3_api->db_filename -#define sqlite3_db_readonly sqlite3_api->db_readonly -#define sqlite3_db_release_memory sqlite3_api->db_release_memory -#define sqlite3_errstr sqlite3_api->errstr -#define sqlite3_stmt_busy sqlite3_api->stmt_busy -#define sqlite3_stmt_readonly sqlite3_api->stmt_readonly -#define sqlite3_stricmp sqlite3_api->stricmp -#define sqlite3_uri_boolean sqlite3_api->uri_boolean -#define sqlite3_uri_int64 sqlite3_api->uri_int64 -#define sqlite3_uri_parameter sqlite3_api->uri_parameter -#define sqlite3_uri_vsnprintf sqlite3_api->xvsnprintf -#define sqlite3_wal_checkpoint_v2 sqlite3_api->wal_checkpoint_v2 +#define sqlite3_close_v2 sqlite3_api->close_v2 +#define sqlite3_db_filename sqlite3_api->db_filename +#define sqlite3_db_readonly sqlite3_api->db_readonly +#define sqlite3_db_release_memory sqlite3_api->db_release_memory +#define sqlite3_errstr sqlite3_api->errstr +#define sqlite3_stmt_busy sqlite3_api->stmt_busy +#define sqlite3_stmt_readonly sqlite3_api->stmt_readonly +#define sqlite3_stricmp sqlite3_api->stricmp +#define sqlite3_uri_boolean sqlite3_api->uri_boolean +#define sqlite3_uri_int64 sqlite3_api->uri_int64 +#define sqlite3_uri_parameter sqlite3_api->uri_parameter +#define sqlite3_uri_vsnprintf sqlite3_api->xvsnprintf +#define sqlite3_wal_checkpoint_v2 sqlite3_api->wal_checkpoint_v2 /* Version 3.8.7 and later */ -#define sqlite3_auto_extension sqlite3_api->auto_extension -#define sqlite3_bind_blob64 sqlite3_api->bind_blob64 -#define sqlite3_bind_text64 sqlite3_api->bind_text64 -#define sqlite3_cancel_auto_extension sqlite3_api->cancel_auto_extension -#define sqlite3_load_extension sqlite3_api->load_extension -#define sqlite3_malloc64 sqlite3_api->malloc64 -#define sqlite3_msize sqlite3_api->msize -#define sqlite3_realloc64 sqlite3_api->realloc64 -#define sqlite3_reset_auto_extension sqlite3_api->reset_auto_extension -#define sqlite3_result_blob64 sqlite3_api->result_blob64 -#define sqlite3_result_text64 sqlite3_api->result_text64 -#define sqlite3_strglob sqlite3_api->strglob +#define sqlite3_auto_extension sqlite3_api->auto_extension +#define sqlite3_bind_blob64 sqlite3_api->bind_blob64 +#define sqlite3_bind_text64 sqlite3_api->bind_text64 +#define sqlite3_cancel_auto_extension sqlite3_api->cancel_auto_extension +#define sqlite3_load_extension sqlite3_api->load_extension +#define sqlite3_malloc64 sqlite3_api->malloc64 +#define sqlite3_msize sqlite3_api->msize +#define sqlite3_realloc64 sqlite3_api->realloc64 +#define sqlite3_reset_auto_extension sqlite3_api->reset_auto_extension +#define sqlite3_result_blob64 sqlite3_api->result_blob64 +#define sqlite3_result_text64 sqlite3_api->result_text64 +#define sqlite3_strglob sqlite3_api->strglob /* Version 3.8.11 and later */ -#define sqlite3_value_dup sqlite3_api->value_dup -#define sqlite3_value_free sqlite3_api->value_free -#define sqlite3_result_zeroblob64 sqlite3_api->result_zeroblob64 -#define sqlite3_bind_zeroblob64 sqlite3_api->bind_zeroblob64 +#define sqlite3_value_dup sqlite3_api->value_dup +#define sqlite3_value_free sqlite3_api->value_free +#define sqlite3_result_zeroblob64 sqlite3_api->result_zeroblob64 +#define sqlite3_bind_zeroblob64 sqlite3_api->bind_zeroblob64 /* Version 3.9.0 and later */ -#define sqlite3_value_subtype sqlite3_api->value_subtype -#define sqlite3_result_subtype sqlite3_api->result_subtype +#define sqlite3_value_subtype sqlite3_api->value_subtype +#define sqlite3_result_subtype sqlite3_api->result_subtype /* Version 3.10.0 and later */ -#define sqlite3_status64 sqlite3_api->status64 -#define sqlite3_strlike sqlite3_api->strlike -#define sqlite3_db_cacheflush sqlite3_api->db_cacheflush +#define sqlite3_status64 sqlite3_api->status64 +#define sqlite3_strlike sqlite3_api->strlike +#define sqlite3_db_cacheflush sqlite3_api->db_cacheflush /* Version 3.12.0 and later */ -#define sqlite3_system_errno sqlite3_api->system_errno +#define sqlite3_system_errno sqlite3_api->system_errno /* Version 3.14.0 and later */ -#define sqlite3_trace_v2 sqlite3_api->trace_v2 -#define sqlite3_expanded_sql sqlite3_api->expanded_sql +#define sqlite3_trace_v2 sqlite3_api->trace_v2 +#define sqlite3_expanded_sql sqlite3_api->expanded_sql /* Version 3.18.0 and later */ -#define sqlite3_set_last_insert_rowid sqlite3_api->set_last_insert_rowid +#define sqlite3_set_last_insert_rowid sqlite3_api->set_last_insert_rowid /* Version 3.20.0 and later */ -#define sqlite3_prepare_v3 sqlite3_api->prepare_v3 -#define sqlite3_prepare16_v3 sqlite3_api->prepare16_v3 -#define sqlite3_bind_pointer sqlite3_api->bind_pointer -#define sqlite3_result_pointer sqlite3_api->result_pointer -#define sqlite3_value_pointer sqlite3_api->value_pointer +#define sqlite3_prepare_v3 sqlite3_api->prepare_v3 +#define sqlite3_prepare16_v3 sqlite3_api->prepare16_v3 +#define sqlite3_bind_pointer sqlite3_api->bind_pointer +#define sqlite3_result_pointer sqlite3_api->result_pointer +#define sqlite3_value_pointer sqlite3_api->value_pointer /* Version 3.22.0 and later */ -#define sqlite3_vtab_nochange sqlite3_api->vtab_nochange -#define sqlite3_value_nochange sqlite3_api->value_nochange -#define sqlite3_vtab_collation sqlite3_api->vtab_collation +#define sqlite3_vtab_nochange sqlite3_api->vtab_nochange +#define sqlite3_value_nochange sqlite3_api->value_nochange +#define sqlite3_vtab_collation sqlite3_api->vtab_collation /* Version 3.24.0 and later */ -#define sqlite3_keyword_count sqlite3_api->keyword_count -#define sqlite3_keyword_name sqlite3_api->keyword_name -#define sqlite3_keyword_check sqlite3_api->keyword_check -#define sqlite3_str_new sqlite3_api->str_new -#define sqlite3_str_finish sqlite3_api->str_finish -#define sqlite3_str_appendf sqlite3_api->str_appendf -#define sqlite3_str_vappendf sqlite3_api->str_vappendf -#define sqlite3_str_append sqlite3_api->str_append -#define sqlite3_str_appendall sqlite3_api->str_appendall -#define sqlite3_str_appendchar sqlite3_api->str_appendchar -#define sqlite3_str_reset sqlite3_api->str_reset -#define sqlite3_str_errcode sqlite3_api->str_errcode -#define sqlite3_str_length sqlite3_api->str_length -#define sqlite3_str_value sqlite3_api->str_value +#define sqlite3_keyword_count sqlite3_api->keyword_count +#define sqlite3_keyword_name sqlite3_api->keyword_name +#define sqlite3_keyword_check sqlite3_api->keyword_check +#define sqlite3_str_new sqlite3_api->str_new +#define sqlite3_str_finish sqlite3_api->str_finish +#define sqlite3_str_appendf sqlite3_api->str_appendf +#define sqlite3_str_vappendf sqlite3_api->str_vappendf +#define sqlite3_str_append sqlite3_api->str_append +#define sqlite3_str_appendall sqlite3_api->str_appendall +#define sqlite3_str_appendchar sqlite3_api->str_appendchar +#define sqlite3_str_reset sqlite3_api->str_reset +#define sqlite3_str_errcode sqlite3_api->str_errcode +#define sqlite3_str_length sqlite3_api->str_length +#define sqlite3_str_value sqlite3_api->str_value /* Version 3.25.0 and later */ #define sqlite3_create_window_function sqlite3_api->create_window_function /* Version 3.26.0 and later */ -#define sqlite3_normalized_sql sqlite3_api->normalized_sql +#define sqlite3_normalized_sql sqlite3_api->normalized_sql /* Version 3.28.0 and later */ -#define sqlite3_stmt_isexplain sqlite3_api->stmt_isexplain -#define sqlite3_value_frombind sqlite3_api->value_frombind +#define sqlite3_stmt_isexplain sqlite3_api->stmt_isexplain +#define sqlite3_value_frombind sqlite3_api->value_frombind /* Version 3.30.0 and later */ -#define sqlite3_drop_modules sqlite3_api->drop_modules +#define sqlite3_drop_modules sqlite3_api->drop_modules /* Version 3.31.0 and later */ -#define sqlite3_hard_heap_limit64 sqlite3_api->hard_heap_limit64 -#define sqlite3_uri_key sqlite3_api->uri_key -#define sqlite3_filename_database sqlite3_api->filename_database -#define sqlite3_filename_journal sqlite3_api->filename_journal -#define sqlite3_filename_wal sqlite3_api->filename_wal +#define sqlite3_hard_heap_limit64 sqlite3_api->hard_heap_limit64 +#define sqlite3_uri_key sqlite3_api->uri_key +#define sqlite3_filename_database sqlite3_api->filename_database +#define sqlite3_filename_journal sqlite3_api->filename_journal +#define sqlite3_filename_wal sqlite3_api->filename_wal /* Version 3.32.0 and later */ -#define sqlite3_create_filename sqlite3_api->create_filename -#define sqlite3_free_filename sqlite3_api->free_filename -#define sqlite3_database_file_object sqlite3_api->database_file_object +#define sqlite3_create_filename sqlite3_api->create_filename +#define sqlite3_free_filename sqlite3_api->free_filename +#define sqlite3_database_file_object sqlite3_api->database_file_object /* Version 3.34.0 and later */ -#define sqlite3_txn_state sqlite3_api->txn_state +#define sqlite3_txn_state sqlite3_api->txn_state /* Version 3.36.1 and later */ -#define sqlite3_changes64 sqlite3_api->changes64 -#define sqlite3_total_changes64 sqlite3_api->total_changes64 +#define sqlite3_changes64 sqlite3_api->changes64 +#define sqlite3_total_changes64 sqlite3_api->total_changes64 /* Version 3.37.0 and later */ -#define sqlite3_autovacuum_pages sqlite3_api->autovacuum_pages +#define sqlite3_autovacuum_pages sqlite3_api->autovacuum_pages /* Version 3.38.0 and later */ -#define sqlite3_error_offset sqlite3_api->error_offset -#define sqlite3_vtab_rhs_value sqlite3_api->vtab_rhs_value -#define sqlite3_vtab_distinct sqlite3_api->vtab_distinct -#define sqlite3_vtab_in sqlite3_api->vtab_in -#define sqlite3_vtab_in_first sqlite3_api->vtab_in_first -#define sqlite3_vtab_in_next sqlite3_api->vtab_in_next +#define sqlite3_error_offset sqlite3_api->error_offset +#define sqlite3_vtab_rhs_value sqlite3_api->vtab_rhs_value +#define sqlite3_vtab_distinct sqlite3_api->vtab_distinct +#define sqlite3_vtab_in sqlite3_api->vtab_in +#define sqlite3_vtab_in_first sqlite3_api->vtab_in_first +#define sqlite3_vtab_in_next sqlite3_api->vtab_in_next /* Version 3.39.0 and later */ #ifndef SQLITE_OMIT_DESERIALIZE -#define sqlite3_deserialize sqlite3_api->deserialize -#define sqlite3_serialize sqlite3_api->serialize +#define sqlite3_deserialize sqlite3_api->deserialize +#define sqlite3_serialize sqlite3_api->serialize #endif -#define sqlite3_db_name sqlite3_api->db_name +#define sqlite3_db_name sqlite3_api->db_name #endif /* !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) */ #if !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) - /* This case when the file really is being compiled as a loadable +/* This case when the file really is being compiled as a loadable ** extension */ -# define SQLITE_EXTENSION_INIT1 const sqlite3_api_routines *sqlite3_api=0; -# define SQLITE_EXTENSION_INIT2(v) sqlite3_api=v; -# define SQLITE_EXTENSION_INIT3 \ - extern const sqlite3_api_routines *sqlite3_api; +#define SQLITE_EXTENSION_INIT1 const sqlite3_api_routines *sqlite3_api = 0; +#define SQLITE_EXTENSION_INIT2(v) sqlite3_api = v; +#define SQLITE_EXTENSION_INIT3 extern const sqlite3_api_routines *sqlite3_api; #else - /* This case when the file is being statically linked into the +/* This case when the file is being statically linked into the ** application */ -# define SQLITE_EXTENSION_INIT1 /*no-op*/ -# define SQLITE_EXTENSION_INIT2(v) (void)v; /* unused parameter */ -# define SQLITE_EXTENSION_INIT3 /*no-op*/ +#define SQLITE_EXTENSION_INIT1 /*no-op*/ +#define SQLITE_EXTENSION_INIT2(v) (void)v; /* unused parameter */ +#define SQLITE_EXTENSION_INIT3 /*no-op*/ #endif #endif /* SQLITE3EXT_H */ diff --git a/srcs/libs/include/uthash/utarray.h b/srcs/libs/include/uthash/utarray.h index 3885ae5..9730464 100644 --- a/srcs/libs/include/uthash/utarray.h +++ b/srcs/libs/include/uthash/utarray.h @@ -212,20 +212,19 @@ typedef struct { utarray_inserta(dst, src, utarray_len(dst)); \ } while (0) -#define utarray_erase(a, pos, len) \ - do { \ - if ((a)->icd.dtor) { \ - unsigned _ut_i; \ - for (_ut_i = 0; _ut_i < (len); _ut_i++) { \ - (a)->icd.dtor(utarray_eltptr(a, (pos) + _ut_i)); \ - } \ - } \ - if ((a)->i > ((pos) + (len))) { \ - memmove(_utarray_eltptr(a, pos), \ - _utarray_eltptr(a, (pos) + (len)), \ - ((a)->i - ((pos) + (len))) * (a)->icd.sz); \ - } \ - (a)->i -= (len); \ +#define utarray_erase(a, pos, len) \ + do { \ + if ((a)->icd.dtor) { \ + unsigned _ut_i; \ + for (_ut_i = 0; _ut_i < (len); _ut_i++) { \ + (a)->icd.dtor(utarray_eltptr(a, (pos) + _ut_i)); \ + } \ + } \ + if ((a)->i > ((pos) + (len))) { \ + memmove( \ + _utarray_eltptr(a, pos), _utarray_eltptr(a, (pos) + (len)), ((a)->i - ((pos) + (len))) * (a)->icd.sz); \ + } \ + (a)->i -= (len); \ } while (0) #define utarray_renew(a, u) \ @@ -274,8 +273,9 @@ static void utarray_str_cpy(void *dst, const void *src) { } static void utarray_str_dtor(void *elt) { char **eltc = (char **)elt; - if (*eltc != NULL) + if (*eltc != NULL) { free(*eltc); + } } static const UT_icd ut_str_icd UTARRAY_UNUSED = {sizeof(char *), NULL, utarray_str_cpy, utarray_str_dtor}; static const UT_icd ut_int_icd UTARRAY_UNUSED = {sizeof(int), NULL, NULL, NULL}; diff --git a/srcs/libs/include/uthash/uthash.h b/srcs/libs/include/uthash/uthash.h index 3f8cb7c..1328cdc 100644 --- a/srcs/libs/include/uthash/uthash.h +++ b/srcs/libs/include/uthash/uthash.h @@ -226,9 +226,9 @@ typedef unsigned char uint8_t; (head)->hh.tbl->num_buckets = HASH_INITIAL_NUM_BUCKETS; \ (head)->hh.tbl->log2_num_buckets = HASH_INITIAL_NUM_BUCKETS_LOG2; \ (head)->hh.tbl->hho = (char *)(&(head)->hh) - (char *)(head); \ - (head)->hh.tbl->buckets = \ - (UT_hash_bucket *)uthash_malloc(HASH_INITIAL_NUM_BUCKETS * sizeof(struct UT_hash_bucket)); \ - (head)->hh.tbl->signature = HASH_SIGNATURE; \ + (head)->hh.tbl->buckets = (UT_hash_bucket *)uthash_malloc(HASH_INITIAL_NUM_BUCKETS \ + * sizeof(struct UT_hash_bucket)); \ + (head)->hh.tbl->signature = HASH_SIGNATURE; \ if (!(head)->hh.tbl->buckets) { \ HASH_RECORD_OOM(oomed); \ uthash_free((head)->hh.tbl, sizeof(UT_hash_table)); \ @@ -523,10 +523,8 @@ typedef unsigned char uint8_t; _prev = NULL; \ while (_thh) { \ if (_prev != (char *)(_thh->hh_prev)) { \ - HASH_OOPS("%s: invalid hh_prev %p, actual %p\n", \ - (where), \ - (void *)_thh->hh_prev, \ - (void *)_prev); \ + HASH_OOPS( \ + "%s: invalid hh_prev %p, actual %p\n", (where), (void *)_thh->hh_prev, (void *)_prev); \ } \ _bkt_count++; \ _prev = (char *)(_thh); \ @@ -887,9 +885,9 @@ typedef unsigned char uint8_t; uthash_free((tbl)->buckets, (tbl)->num_buckets * sizeof(struct UT_hash_bucket)); \ (tbl)->num_buckets *= 2U; \ (tbl)->log2_num_buckets++; \ - (tbl)->buckets = _he_new_buckets; \ - (tbl)->ineff_expands = \ - ((tbl)->nonideal_items > ((tbl)->num_items >> 1)) ? ((tbl)->ineff_expands + 1U) : 0U; \ + (tbl)->buckets = _he_new_buckets; \ + (tbl)->ineff_expands = ((tbl)->nonideal_items > ((tbl)->num_items >> 1)) ? ((tbl)->ineff_expands + 1U) \ + : 0U; \ if ((tbl)->ineff_expands > 1U) { \ (tbl)->noexpand = 1; \ uthash_noexpand_fyi(tbl); \ diff --git a/srcs/libs/include/uthash/utstring.h b/srcs/libs/include/uthash/utstring.h index b465eab..f91f856 100644 --- a/srcs/libs/include/uthash/utstring.h +++ b/srcs/libs/include/uthash/utstring.h @@ -152,10 +152,11 @@ UTSTRING_UNUSED static void utstring_printf_va(UT_string *s, const char *fmt, va } /* Else try again with more space. */ - if (n > -1) + if (n > -1) { utstring_reserve(s, n + 1); /* exact */ - else + } else { utstring_reserve(s, (s->n) * 2); /* 2x */ + } } } #ifdef __GNUC__ @@ -227,8 +228,11 @@ UTSTRING_UNUSED static void _utstring_BuildTableR(const char *P_Needle, size_t P } /* Search data from left to right. ( Multiple search mode. ) */ -UTSTRING_UNUSED static long _utstring_find(const char *P_Haystack, size_t P_HaystackLen, const char *P_Needle, - size_t P_NeedleLen, long *P_KMP_Table) { +UTSTRING_UNUSED static long _utstring_find(const char *P_Haystack, + size_t P_HaystackLen, + const char *P_Needle, + size_t P_NeedleLen, + long *P_KMP_Table) { long i, j; long V_FindPosition = -1; @@ -251,8 +255,11 @@ UTSTRING_UNUSED static long _utstring_find(const char *P_Haystack, size_t P_Hays } /* Search data from right to left. ( Multiple search mode. ) */ -UTSTRING_UNUSED static long _utstring_findR(const char *P_Haystack, size_t P_HaystackLen, const char *P_Needle, - size_t P_NeedleLen, long *P_KMP_Table) { +UTSTRING_UNUSED static long _utstring_findR(const char *P_Haystack, + size_t P_HaystackLen, + const char *P_Needle, + size_t P_NeedleLen, + long *P_KMP_Table) { long i, j; long V_FindPosition = -1; @@ -278,7 +285,8 @@ UTSTRING_UNUSED static long _utstring_findR(const char *P_Haystack, size_t P_Hay /* Search data from left to right. ( One time search mode. ) */ UTSTRING_UNUSED static long utstring_find(UT_string *s, long P_StartPosition, /* Start from 0. -1 means last position. */ - const char *P_Needle, size_t P_NeedleLen) { + const char *P_Needle, + size_t P_NeedleLen) { long V_StartPosition; long V_HaystackLen; long *V_KMP_Table; @@ -310,7 +318,8 @@ UTSTRING_UNUSED static long utstring_find(UT_string *s, /* Search data from right to left. ( One time search mode. ) */ UTSTRING_UNUSED static long utstring_findR(UT_string *s, long P_StartPosition, /* Start from 0. -1 means last position. */ - const char *P_Needle, size_t P_NeedleLen) { + const char *P_Needle, + size_t P_NeedleLen) { long V_StartPosition; long V_HaystackLen; long *V_KMP_Table; diff --git a/srcs/libs/include/zvector/zvector.h b/srcs/libs/include/zvector/zvector.h index 9c2578f..ffabc09 100644 --- a/srcs/libs/include/zvector/zvector.h +++ b/srcs/libs/include/zvector/zvector.h @@ -12,11 +12,11 @@ #define SRC_ZVECTOR_H_ #if defined(_MSC_VER) && (_MSC_VER >= 1020) -# pragma once +#pragma once #endif #ifdef __cplusplus -extern "C"{ +extern "C" { #endif // Requires standard C libraries: @@ -32,7 +32,7 @@ extern "C"{ #include "zvector_config.h" // Declare required structs: -typedef struct p_vector * vector; +typedef struct p_vector *vector; // Declare required enums: @@ -52,23 +52,24 @@ typedef struct p_vector * vector; * its reference will also be fully zeroed out before freeing it. */ enum ZVECT_PROPERTIES { - ZV_NONE = 0, // Sets or Resets all vector's properties to 0. - ZV_SEC_WIPE = 1 << 0, // Sets the vector for automatic Secure Wipe of items. - ZV_BYREF = 1 << 1, // Sets the vector to store items by reference instead of copying them as per default. - ZV_CIRCULAR = 1 << 2, // Sets the vector to be a circular vector (so it will not grow in capacity automatically). Elements will be overwritten as in typical circular buffers! - ZV_NOLOCKING = 1 << 3, // This Property means the vector will not use mutexes, be careful using it! + ZV_NONE = 0, // Sets or Resets all vector's properties to 0. + ZV_SEC_WIPE = 1 << 0, // Sets the vector for automatic Secure Wipe of items. + ZV_BYREF = 1 << 1, // Sets the vector to store items by reference instead of copying them as per default. + ZV_CIRCULAR = 1 + << 2, // Sets the vector to be a circular vector (so it will not grow in capacity automatically). Elements will be overwritten as in typical circular buffers! + ZV_NOLOCKING = 1 << 3, // This Property means the vector will not use mutexes, be careful using it! }; enum ZVECT_ERR { - ZVERR_VECTUNDEF = -1, - ZVERR_IDXOUTOFBOUND = -2, - ZVERR_OUTOFMEM = -3, - ZVERR_VECTCORRUPTED = -4, - ZVERR_RACECOND = -5, - ZVERR_VECTTOOSMALL = -6, - ZVERR_VECTDATASIZE = -7, - ZVERR_VECTEMPTY = -8, - ZVERR_OPNOTALLOWED = -9 + ZVERR_VECTUNDEF = -1, + ZVERR_IDXOUTOFBOUND = -2, + ZVERR_OUTOFMEM = -3, + ZVERR_VECTCORRUPTED = -4, + ZVERR_RACECOND = -5, + ZVERR_VECTTOOSMALL = -6, + ZVERR_VECTDATASIZE = -7, + ZVERR_VECTEMPTY = -8, + ZVERR_OPNOTALLOWED = -9 }; /***************************** @@ -137,7 +138,7 @@ bool vect_set_status(const vector v, zvect_index flag_id); bool vect_clear_status(const vector v, zvect_index flag_id); -#if ( ZVECT_THREAD_SAFE == 1 ) +#if (ZVECT_THREAD_SAFE == 1) // Vector Thread Safe functions: /* @@ -201,10 +202,11 @@ zvect_retval vect_unlock(vector const v); * zvect_retval vect_lock_after_signal(const vector v); */ -zvect_retval vect_move_on_signal(vector const v1, vector v2, - const zvect_index s2, - const zvect_index e2, - zvect_retval (*f2)(void *, void *)); +zvect_retval vect_move_on_signal(vector const v1, + vector v2, + const zvect_index s2, + const zvect_index e2, + zvect_retval (*f2)(void *, void *)); zvect_retval vect_send_signal(const vector v); @@ -214,7 +216,7 @@ zvect_retval vect_sem_wait(const vector v); zvect_retval vect_sem_post(const vector v); -#endif // ( ZVECT_THREAD_SAFE == 1 ) +#endif // ( ZVECT_THREAD_SAFE == 1 ) ///////////////////////////////////////////////////// // Vector Data Storage functions: @@ -229,7 +231,7 @@ zvect_retval vect_sem_post(const vector v); * corresponds to the top of a * Stack. */ - void vect_push(vector const v, const void *item); +void vect_push(vector const v, const void *item); /* * vect_pop(v) "pops" (returns) the element @@ -290,7 +292,7 @@ void vect_add_front(vector const v, const void *item); * vect_pop(v)). */ void *vect_get(vector const v); -#define vect_back(v) vect_get(v) +#define vect_back(v) vect_get(v) /* * @@ -298,14 +300,14 @@ void *vect_get(vector const v); * 3 in the vector v. */ void *vect_get_at(vector const v, const zvect_index i); -#define vect_at(v, x) vect_get_at(v, x) +#define vect_at(v, x) vect_get_at(v, x) /* * vect_get_front(v) will return the first element in * the vector v. */ void *vect_get_front(vector const v); -#define vect_front(v) vect_get_front(v) +#define vect_front(v) vect_get_front(v) /* *vect_put allows you to REPLACE an item @@ -458,7 +460,7 @@ void vect_rotate_right(vector const v, const zvect_index i); * pointers to your datastructures stored in the vector. * */ -void vect_qsort(vector const v, int (*compare_func)(const void *, const void*)); +void vect_qsort(vector const v, int (*compare_func)(const void *, const void *)); /* * vect_bsearch is a function that allows to perform @@ -479,11 +481,11 @@ void vect_qsort(vector const v, int (*compare_func)(const void *, const void*)); * vect_bsearch(v, &i, my_compare); */ #ifdef __cplusplus - extern "C"{ +extern "C" { #endif - bool vect_bsearch(vector const v, const void *key, int (*f1)(const void *, const void *), zvect_index *item_index); +bool vect_bsearch(vector const v, const void *key, int (*f1)(const void *, const void *), zvect_index *item_index); #ifdef __cplusplus - } +} #endif /* * vect_add_ordered allows the insertion of new items in @@ -504,7 +506,7 @@ void vect_qsort(vector const v, int (*compare_func)(const void *, const void*)); */ void vect_add_ordered(vector const v, const void *value, int (*f1)(const void *, const void *)); -#endif // ZVECT_DMF_EXTENSIONS +#endif // ZVECT_DMF_EXTENSIONS #ifdef ZVECT_SFMD_EXTENSIONS // Single Function Multiple Data extensions: @@ -591,8 +593,7 @@ void vect_copy(vector const v1, vector const v2, zvect_index start, zvect_index * you'll have such items "inserted" * inside v1. */ -void vect_insert(vector const v1, vector const v2, const zvect_index s2, - const zvect_index e2, const zvect_index s1); +void vect_insert(vector const v1, vector const v2, const zvect_index s2, const zvect_index e2, const zvect_index s1); /* * vect_move is a function that allows to move a specified @@ -623,8 +624,11 @@ void vect_move(vector const v1, vector const v2, zvect_index start, zvect_index * the end of v1 if check_data returns * true. */ -zvect_retval vect_move_if(vector const v1, vector v2, const zvect_index s2, - const zvect_index e2, zvect_retval (*f2)(void *, void *)); +zvect_retval vect_move_if(vector const v1, + vector v2, + const zvect_index s2, + const zvect_index e2, + zvect_retval (*f2)(void *, void *)); /* * vect_merge is a function that merges together 2 vectors of @@ -638,10 +642,10 @@ zvect_retval vect_move_if(vector const v1, vector v2, const zvect_index s2, */ void vect_merge(vector const v1, vector v2); -#endif // ZVECT_SFMD_EXTENSIONS +#endif // ZVECT_SFMD_EXTENSIONS #ifdef __cplusplus } #endif -#endif // SRC_ZVECTOR_H_ +#endif // SRC_ZVECTOR_H_ diff --git a/srcs/libs/include/zvector/zvector_checks.h b/srcs/libs/include/zvector/zvector_checks.h index 2479b57..4c8a25d 100644 --- a/srcs/libs/include/zvector/zvector_checks.h +++ b/srcs/libs/include/zvector/zvector_checks.h @@ -17,128 +17,122 @@ // Try to determine the Operating System being used: #if defined(__APPLE__) && defined(__MACH__) -# define macOS +#define macOS #endif -#if ( defined(__GNU__) || defined(__gnu_linux__) || \ - defined(__linux__) || defined(macOS) ) -# define OS_TYPE 1 -#elif ( defined(__WIN32__) || defined(WIN32) || defined(_WIN32) ) -# define OS_TYPE 2 +#if (defined(__GNU__) || defined(__gnu_linux__) || defined(__linux__) || defined(macOS)) +#define OS_TYPE 1 +#elif (defined(__WIN32__) || defined(WIN32) || defined(_WIN32)) +#define OS_TYPE 2 #else -# define OS_TYPE 0 +#define OS_TYPE 0 #endif // Try to determine compiler being used: #if defined(__GNUC__) -# define compiler gcc -# define ZVECT_COMPTYPE 1 -# define COMP_MAJRELEASE (__GNUC__) -# define COMP_MINRELEASE (__GNUC_MINOR__) -# define COMP_PATRELEASE (__GNUC_PATCHLEVEL__) +#define compiler gcc +#define ZVECT_COMPTYPE 1 +#define COMP_MAJRELEASE (__GNUC__) +#define COMP_MINRELEASE (__GNUC_MINOR__) +#define COMP_PATRELEASE (__GNUC_PATCHLEVEL__) #elif defined(_MSC_VER) -# define compiler msc -# define ZVECT_COMPTYPE 2 -# define COMP_MAJRELEASE (_MSC_VER) -# define COMP_MINRELEASE 0 -# define COMP_PATRELEASE 0 +#define compiler msc +#define ZVECT_COMPTYPE 2 +#define COMP_MAJRELEASE (_MSC_VER) +#define COMP_MINRELEASE 0 +#define COMP_PATRELEASE 0 #elif defined(__clang__) -# define compiler clang -# define ZVECT_COMPTYPE 3 -# define COMP_MAJRELEASE (__clang_major__) -# define COMP_MINRELEASE (__clang_minor__) -# define COMP_PATRELEASE (__clang_patchlevel__) -#elif defined(__INTEL_COMPILER) || defined(__ICC) || \ - defined(__ECC) || defined(__ICL) +#define compiler clang +#define ZVECT_COMPTYPE 3 +#define COMP_MAJRELEASE (__clang_major__) +#define COMP_MINRELEASE (__clang_minor__) +#define COMP_PATRELEASE (__clang_patchlevel__) +#elif defined(__INTEL_COMPILER) || defined(__ICC) || defined(__ECC) || defined(__ICL) // For intel c compiler please remember to specify: // /Qstd=c99 (on Windows) // -std=c99 on Linux and/or macOS -# define compiler intelc -# define ZVECT_COMPTYPE 4 -# define COMP_MAJRELEASE (__INTEL_COMPILER) -# define COMP_MINRELEASE 0 -# define COMP_PATRELEASE 0 -#elif defined (__LCC__) -# define compiler lcc -# define ZVECT_COMPTYPE 5 -# define COMP_MAJRELEASE (__LCC) -# define COMP_MINRELEASE 0 -# define COMP_PATRELEASE 0 -#elif defined(__NORCROFT_C__) || defined(__CC_NORCROFT) || \ - defined(__ARMCC_VERSION) +#define compiler intelc +#define ZVECT_COMPTYPE 4 +#define COMP_MAJRELEASE (__INTEL_COMPILER) +#define COMP_MINRELEASE 0 +#define COMP_PATRELEASE 0 +#elif defined(__LCC__) +#define compiler lcc +#define ZVECT_COMPTYPE 5 +#define COMP_MAJRELEASE (__LCC) +#define COMP_MINRELEASE 0 +#define COMP_PATRELEASE 0 +#elif defined(__NORCROFT_C__) || defined(__CC_NORCROFT) || defined(__ARMCC_VERSION) // For Norcroft C please remember to specify: // -c99 -# define compiler norcroftc -# define ZVECT_COMPTYPE 6 -# define COMP_MAJRELEASE (__ARMCC_VERSION) +#define compiler norcroftc +#define ZVECT_COMPTYPE 6 +#define COMP_MAJRELEASE (__ARMCC_VERSION) #elif defined(_CRAYC) // For Cray C please remember to specify: // -hc99 -# define compiler crayc -# define ZVECT_COMPTYPE 10 -# define COMP_MAJRELEASE (_RELEASE) -# define COMP_MINRELEASE (_RELEASE_MINOR) -# define COMP_PATRELEASE 0 +#define compiler crayc +#define ZVECT_COMPTYPE 10 +#define COMP_MAJRELEASE (_RELEASE) +#define COMP_MINRELEASE (_RELEASE_MINOR) +#define COMP_PATRELEASE 0 #elif defined(__HP_cc) // For HP CC please remember to specify: // -ansi -std=c99 -# define compiler hpc -# define ZVECT_COMPTYPE 11 -# define COMP_MAJRELEASE 1 -# define COMP_MINRELEASE 21 -# define COMP_PATRELEASE 0 +#define compiler hpc +#define ZVECT_COMPTYPE 11 +#define COMP_MAJRELEASE 1 +#define COMP_MINRELEASE 21 +#define COMP_PATRELEASE 0 #elif defined(__IBMC__) // For IBM C please remember to specify: // C99 flags -# define compiler ibmc -# define ZVECT_COMPTYPE 12 +#define compiler ibmc +#define ZVECT_COMPTYPE 12 #elif defined(__TINYC__) -# define compiler tinyc -# define ZVECT_COMPTYPE 6 -# define COMP_MAJRELEASE 0 -# define COMP_MINRELEASE 0 -# define COMP_PATRELEASE 0 +#define compiler tinyc +#define ZVECT_COMPTYPE 6 +#define COMP_MAJRELEASE 0 +#define COMP_MINRELEASE 0 +#define COMP_PATRELEASE 0 #else -# define compiler unknown -# define ZVECT_COMPTYPE 0 +#define compiler unknown +#define ZVECT_COMPTYPE 0 #endif // Try to determine CPU Architecture: #if defined(__aarch64__) -# define CPU_TYPE ARM64 -# define Arch64 +#define CPU_TYPE ARM64 +#define Arch64 #elif defined(__aarch32__) -# define CPU_TYPE ARM32 -# define Arch32 -#elif defined(__amd64__) || defined(__x86_64__) || \ - defined(__ia64__) || defined(_M_IA64) || \ - defined(_M_AMD64) || defined(_M_X64) -# define CPU_TYPE x86_64 -# define Arch64 +#define CPU_TYPE ARM32 +#define Arch32 +#elif defined(__amd64__) || defined(__x86_64__) || defined(__ia64__) || defined(_M_IA64) || defined(_M_AMD64) \ + || defined(_M_X64) +#define CPU_TYPE x86_64 +#define Arch64 #else -# define CPU_TYPE unknown -# define Arch32 +#define CPU_TYPE unknown +#define Arch32 #endif // Start setting up macros based on the platform we detected // above. -#if ( OS_TYPE == 1 ) - // We are on a Unix-like OS so we can use pthreads! -# define MUTEX_TYPE 1 -# elif ( OS_TYPE == 2 ) && ( defined(__CYGWIN__) || \ - defined(__MINGW32__) || defined(__MINGW64__) ) - // We are on MS Windows using CIGWIN so we can use pthreads! -# define MUTEX_TYPE 1 -# elif ( OS_TYPE == 2 ) && ( !defined(__CYGWIN__) && \ - !defined(__MINGW32__) && !defined(__MINGW64__) ) - // We are on MS Windows, so we need to use - // Windows stuff: -# define MUTEX_TYPE 2 +#if (OS_TYPE == 1) +// We are on a Unix-like OS so we can use pthreads! +#define MUTEX_TYPE 1 +#elif (OS_TYPE == 2) && (defined(__CYGWIN__) || defined(__MINGW32__) || defined(__MINGW64__)) +// We are on MS Windows using CIGWIN so we can use pthreads! +#define MUTEX_TYPE 1 +#elif (OS_TYPE == 2) && (!defined(__CYGWIN__) && !defined(__MINGW32__) && !defined(__MINGW64__)) +// We are on MS Windows, so we need to use +// Windows stuff: +#define MUTEX_TYPE 2 #else - // I have no idea on which platform are we, - // hence I have to use fake mutexes and go with the flow! -# define MUTEX_TYPE 0 +// I have no idea on which platform are we, +// hence I have to use fake mutexes and go with the flow! +#define MUTEX_TYPE 0 #endif -#endif // SRC_ZVECTOR_CHECKS_H_ +#endif // SRC_ZVECTOR_CHECKS_H_ diff --git a/srcs/libs/include/zvector/zvector_config.h b/srcs/libs/include/zvector/zvector_config.h index b458bb1..4e94bcf 100644 --- a/srcs/libs/include/zvector/zvector_config.h +++ b/srcs/libs/include/zvector/zvector_config.h @@ -19,10 +19,10 @@ #include // Data alignment configuration -#if ( ZVECT_COMPTYPE == 1 ) -#define ZVECT_DATAALIGN __attribute__((aligned)) -#define ZVECT_PACKING __attribute__((__packed__)) -#define ZVECT_ALWAYSINLINE __attribute__ ((__always_inline__)) +#if (ZVECT_COMPTYPE == 1) +#define ZVECT_DATAALIGN __attribute__((aligned)) +#define ZVECT_PACKING __attribute__((__packed__)) +#define ZVECT_ALWAYSINLINE __attribute__((__always_inline__)) #else #define ZVECT_DATAALIGN #define ZVECT_PACKING @@ -36,8 +36,9 @@ // If you want a larger index you can // change it to, for example, uint64_t typedef uint32_t zvect_index; -#define zvect_index_max 4294967295 // If you change zvect_index type make sure you update this value - // it's the maximum number that can be stored in a zvect_index. +#define zvect_index_max \ + 4294967295 // If you change zvect_index type make sure you update this value \ + // it's the maximum number that can be stored in a zvect_index. // Default vector return type for // error codes. @@ -81,4 +82,4 @@ typedef int32_t zvect_retval; // Enable/Disable SFMD Extensions: #define ZVECT_SFMD_EXTENSIONS 1 -#endif // SRC_ZVECTOR_CONFIG_H_ +#endif // SRC_ZVECTOR_CONFIG_H_ diff --git a/srcs/libs/json/cJSON.c b/srcs/libs/json/cJSON.c index a6b3811..28d515c 100644 --- a/srcs/libs/json/cJSON.c +++ b/srcs/libs/json/cJSON.c @@ -32,9 +32,9 @@ #pragma GCC visibility push(default) #endif #if defined(_MSC_VER) -#pragma warning (push) +#pragma warning(push) /* disable warning about single line comments in system headers */ -#pragma warning (disable : 4001) +#pragma warning(disable : 4001) #endif #include @@ -50,7 +50,7 @@ #endif #if defined(_MSC_VER) -#pragma warning (pop) +#pragma warning(pop) #endif #ifdef __GNUC__ #pragma GCC visibility pop @@ -78,35 +78,30 @@ #endif #ifndef NAN -#define NAN 0.0/0.0 +#define NAN 0.0 / 0.0 #endif typedef struct { const unsigned char *json; - size_t position; + size_t position; } error; -static error global_error = { NULL, 0 }; +static error global_error = {NULL, 0}; -CJSON_PUBLIC(const char *) cJSON_GetErrorPtr(void) -{ - return (const char*) (global_error.json + global_error.position); +CJSON_PUBLIC(const char *) cJSON_GetErrorPtr(void) { + return (const char *)(global_error.json + global_error.position); } -CJSON_PUBLIC(char *) cJSON_GetStringValue(const cJSON * const item) -{ - if (!cJSON_IsString(item)) - { +CJSON_PUBLIC(char *) cJSON_GetStringValue(const cJSON *const item) { + if (!cJSON_IsString(item)) { return NULL; } return item->valuestring; } -CJSON_PUBLIC(double) cJSON_GetNumberValue(const cJSON * const item) -{ - if (!cJSON_IsNumber(item)) - { - return (double) NAN; +CJSON_PUBLIC(double) cJSON_GetNumberValue(const cJSON *const item) { + if (!cJSON_IsNumber(item)) { + return (double)NAN; } return item->valuedouble; @@ -114,11 +109,10 @@ CJSON_PUBLIC(double) cJSON_GetNumberValue(const cJSON * const item) /* This is a safeguard to prevent copy-pasters from using incompatible C and header files */ #if (CJSON_VERSION_MAJOR != 1) || (CJSON_VERSION_MINOR != 7) || (CJSON_VERSION_PATCH != 14) - #error cJSON.h and cJSON.c have different versions. Make sure that both have the same. +#error cJSON.h and cJSON.c have different versions. Make sure that both have the same. #endif -CJSON_PUBLIC(const char*) cJSON_Version(void) -{ +CJSON_PUBLIC(const char *) cJSON_Version(void) { static char version[15]; sprintf(version, "%i.%i.%i", CJSON_VERSION_MAJOR, CJSON_VERSION_MINOR, CJSON_VERSION_PATCH); @@ -126,22 +120,17 @@ CJSON_PUBLIC(const char*) cJSON_Version(void) } /* Case insensitive string comparison, doesn't consider two NULL pointers equal though */ -static int case_insensitive_strcmp(const unsigned char *string1, const unsigned char *string2) -{ - if ((string1 == NULL) || (string2 == NULL)) - { +static int case_insensitive_strcmp(const unsigned char *string1, const unsigned char *string2) { + if ((string1 == NULL) || (string2 == NULL)) { return 1; } - if (string1 == string2) - { + if (string1 == string2) { return 0; } - for(; tolower(*string1) == tolower(*string2); (void)string1++, string2++) - { - if (*string1 == '\0') - { + for (; tolower(*string1) == tolower(*string2); (void)string1++, string2++) { + if (*string1 == '\0') { return 0; } } @@ -149,52 +138,45 @@ static int case_insensitive_strcmp(const unsigned char *string1, const unsigned return tolower(*string1) - tolower(*string2); } -typedef struct internal_hooks -{ +typedef struct internal_hooks { void *(CJSON_CDECL *allocate)(size_t size); - void (CJSON_CDECL *deallocate)(void *pointer); + void(CJSON_CDECL *deallocate)(void *pointer); void *(CJSON_CDECL *reallocate)(void *pointer, size_t size); } internal_hooks; #if defined(_MSC_VER) /* work around MSVC error C2322: '...' address of dllimport '...' is not static */ -static void * CJSON_CDECL internal_malloc(size_t size) -{ +static void *CJSON_CDECL internal_malloc(size_t size) { return malloc(size); } -static void CJSON_CDECL internal_free(void *pointer) -{ +static void CJSON_CDECL internal_free(void *pointer) { free(pointer); } -static void * CJSON_CDECL internal_realloc(void *pointer, size_t size) -{ +static void *CJSON_CDECL internal_realloc(void *pointer, size_t size) { return realloc(pointer, size); } #else -#define internal_malloc malloc -#define internal_free free +#define internal_malloc malloc +#define internal_free free #define internal_realloc realloc #endif /* strlen of character literals resolved at compile time */ #define static_strlen(string_literal) (sizeof(string_literal) - sizeof("")) -static internal_hooks global_hooks = { internal_malloc, internal_free, internal_realloc }; +static internal_hooks global_hooks = {internal_malloc, internal_free, internal_realloc}; -static unsigned char* cJSON_strdup(const unsigned char* string, const internal_hooks * const hooks) -{ - size_t length = 0; - unsigned char *copy = NULL; +static unsigned char *cJSON_strdup(const unsigned char *string, const internal_hooks *const hooks) { + size_t length = 0; + unsigned char *copy = NULL; - if (string == NULL) - { + if (string == NULL) { return NULL; } - length = strlen((const char*)string) + sizeof(""); - copy = (unsigned char*)hooks->allocate(length); - if (copy == NULL) - { + length = strlen((const char *)string) + sizeof(""); + copy = (unsigned char *)hooks->allocate(length); + if (copy == NULL) { return NULL; } memcpy(copy, string, length); @@ -202,43 +184,36 @@ static unsigned char* cJSON_strdup(const unsigned char* string, const internal_h return copy; } -CJSON_PUBLIC(void) cJSON_InitHooks(cJSON_Hooks* hooks) -{ - if (hooks == NULL) - { +CJSON_PUBLIC(void) cJSON_InitHooks(cJSON_Hooks *hooks) { + if (hooks == NULL) { /* Reset hooks */ - global_hooks.allocate = malloc; + global_hooks.allocate = malloc; global_hooks.deallocate = free; global_hooks.reallocate = realloc; return; } global_hooks.allocate = malloc; - if (hooks->malloc_fn != NULL) - { + if (hooks->malloc_fn != NULL) { global_hooks.allocate = hooks->malloc_fn; } global_hooks.deallocate = free; - if (hooks->free_fn != NULL) - { + if (hooks->free_fn != NULL) { global_hooks.deallocate = hooks->free_fn; } /* use realloc only if both free and malloc are used */ global_hooks.reallocate = NULL; - if ((global_hooks.allocate == malloc) && (global_hooks.deallocate == free)) - { + if ((global_hooks.allocate == malloc) && (global_hooks.deallocate == free)) { global_hooks.reallocate = realloc; } } /* Internal constructor. */ -static cJSON *cJSON_New_Item(const internal_hooks * const hooks) -{ - cJSON* node = (cJSON*)hooks->allocate(sizeof(cJSON)); - if (node) - { +static cJSON *cJSON_New_Item(const internal_hooks *const hooks) { + cJSON *node = (cJSON *)hooks->allocate(sizeof(cJSON)); + if (node) { memset(node, '\0', sizeof(cJSON)); } @@ -246,22 +221,17 @@ static cJSON *cJSON_New_Item(const internal_hooks * const hooks) } /* Delete a cJSON structure. */ -CJSON_PUBLIC(void) cJSON_Delete(cJSON *item) -{ +CJSON_PUBLIC(void) cJSON_Delete(cJSON *item) { cJSON *next = NULL; - while (item != NULL) - { + while (item != NULL) { next = item->next; - if (!(item->type & cJSON_IsReference) && (item->child != NULL)) - { + if (!(item->type & cJSON_IsReference) && (item->child != NULL)) { cJSON_Delete(item->child); } - if (!(item->type & cJSON_IsReference) && (item->valuestring != NULL)) - { + if (!(item->type & cJSON_IsReference) && (item->valuestring != NULL)) { global_hooks.deallocate(item->valuestring); } - if (!(item->type & cJSON_StringIsConst) && (item->string != NULL)) - { + if (!(item->type & cJSON_StringIsConst) && (item->string != NULL)) { global_hooks.deallocate(item->string); } global_hooks.deallocate(item); @@ -270,54 +240,48 @@ CJSON_PUBLIC(void) cJSON_Delete(cJSON *item) } /* get the decimal point character of the current locale */ -static unsigned char get_decimal_point(void) -{ +static unsigned char get_decimal_point(void) { #ifdef ENABLE_LOCALES struct lconv *lconv = localeconv(); - return (unsigned char) lconv->decimal_point[0]; + return (unsigned char)lconv->decimal_point[0]; #else return '.'; #endif } -typedef struct -{ +typedef struct { const unsigned char *content; - size_t length; - size_t offset; - size_t depth; /* How deeply nested (in arrays/objects) is the input at the current offset. */ - internal_hooks hooks; + size_t length; + size_t offset; + size_t depth; /* How deeply nested (in arrays/objects) is the input at the current offset. */ + internal_hooks hooks; } parse_buffer; /* check if the given size is left to read in a given parse buffer (starting with 1) */ #define can_read(buffer, size) ((buffer != NULL) && (((buffer)->offset + size) <= (buffer)->length)) /* check if the buffer can be accessed at the given index (starting with 0) */ -#define can_access_at_index(buffer, index) ((buffer != NULL) && (((buffer)->offset + index) < (buffer)->length)) +#define can_access_at_index(buffer, index) ((buffer != NULL) && (((buffer)->offset + index) < (buffer)->length)) #define cannot_access_at_index(buffer, index) (!can_access_at_index(buffer, index)) /* get a pointer to the buffer at the position */ #define buffer_at_offset(buffer) ((buffer)->content + (buffer)->offset) /* Parse the input text to generate a number, and populate the result into item. */ -static cJSON_bool parse_number(cJSON * const item, parse_buffer * const input_buffer) -{ - double number = 0; +static cJSON_bool parse_number(cJSON *const item, parse_buffer *const input_buffer) { + double number = 0; unsigned char *after_end = NULL; - unsigned char number_c_string[64]; - unsigned char decimal_point = get_decimal_point(); - size_t i = 0; + unsigned char number_c_string[64]; + unsigned char decimal_point = get_decimal_point(); + size_t i = 0; - if ((input_buffer == NULL) || (input_buffer->content == NULL)) - { + if ((input_buffer == NULL) || (input_buffer->content == NULL)) { return false; } /* copy the number into a temporary buffer and replace '.' with the decimal point * of the current locale (for strtod) * This also takes care of '\0' not necessarily being available for marking the end of the input */ - for (i = 0; (i < (sizeof(number_c_string) - 1)) && can_access_at_index(input_buffer, i); i++) - { - switch (buffer_at_offset(input_buffer)[i]) - { + for (i = 0; (i < (sizeof(number_c_string) - 1)) && can_access_at_index(input_buffer, i); i++) { + switch (buffer_at_offset(input_buffer)[i]) { case '0': case '1': case '2': @@ -346,25 +310,19 @@ static cJSON_bool parse_number(cJSON * const item, parse_buffer * const input_bu loop_end: number_c_string[i] = '\0'; - number = strtod((const char*)number_c_string, (char**)&after_end); - if (number_c_string == after_end) - { + number = strtod((const char *)number_c_string, (char **)&after_end); + if (number_c_string == after_end) { return false; /* parse_error */ } item->valuedouble = number; /* use saturation in case of overflow */ - if (number >= INT_MAX) - { + if (number >= INT_MAX) { item->valueint = INT_MAX; - } - else if (number <= (double)INT_MIN) - { + } else if (number <= (double)INT_MIN) { item->valueint = INT_MIN; - } - else - { + } else { item->valueint = (int)number; } @@ -375,44 +333,33 @@ loop_end: } /* don't ask me, but the original cJSON_SetNumberValue returns an integer or double */ -CJSON_PUBLIC(double) cJSON_SetNumberHelper(cJSON *object, double number) -{ - if (number >= INT_MAX) - { +CJSON_PUBLIC(double) cJSON_SetNumberHelper(cJSON *object, double number) { + if (number >= INT_MAX) { object->valueint = INT_MAX; - } - else if (number <= (double)INT_MIN) - { + } else if (number <= (double)INT_MIN) { object->valueint = INT_MIN; - } - else - { + } else { object->valueint = (int)number; } return object->valuedouble = number; } -CJSON_PUBLIC(char*) cJSON_SetValuestring(cJSON *object, const char *valuestring) -{ +CJSON_PUBLIC(char *) cJSON_SetValuestring(cJSON *object, const char *valuestring) { char *copy = NULL; /* if object's type is not cJSON_String or is cJSON_IsReference, it should not set valuestring */ - if (!(object->type & cJSON_String) || (object->type & cJSON_IsReference)) - { + if (!(object->type & cJSON_String) || (object->type & cJSON_IsReference)) { return NULL; } - if (strlen(valuestring) <= strlen(object->valuestring)) - { + if (strlen(valuestring) <= strlen(object->valuestring)) { strcpy(object->valuestring, valuestring); return object->valuestring; } - copy = (char*) cJSON_strdup((const unsigned char*)valuestring, &global_hooks); - if (copy == NULL) - { + copy = (char *)cJSON_strdup((const unsigned char *)valuestring, &global_hooks); + if (copy == NULL) { return NULL; } - if (object->valuestring != NULL) - { + if (object->valuestring != NULL) { cJSON_free(object->valuestring); } object->valuestring = copy; @@ -420,43 +367,37 @@ CJSON_PUBLIC(char*) cJSON_SetValuestring(cJSON *object, const char *valuestring) return copy; } -typedef struct -{ +typedef struct { unsigned char *buffer; - size_t length; - size_t offset; - size_t depth; /* current nesting depth (for formatted printing) */ - cJSON_bool noalloc; - cJSON_bool format; /* is this print a formatted print */ + size_t length; + size_t offset; + size_t depth; /* current nesting depth (for formatted printing) */ + cJSON_bool noalloc; + cJSON_bool format; /* is this print a formatted print */ internal_hooks hooks; } printbuffer; /* realloc printbuffer if necessary to have at least "needed" bytes more */ -static unsigned char* ensure(printbuffer * const p, size_t needed) -{ +static unsigned char *ensure(printbuffer *const p, size_t needed) { unsigned char *newbuffer = NULL; - size_t newsize = 0; + size_t newsize = 0; - if ((p == NULL) || (p->buffer == NULL)) - { + if ((p == NULL) || (p->buffer == NULL)) { return NULL; } - if ((p->length > 0) && (p->offset >= p->length)) - { + if ((p->length > 0) && (p->offset >= p->length)) { /* make sure that offset is valid */ return NULL; } - if (needed > INT_MAX) - { + if (needed > INT_MAX) { /* sizes bigger than INT_MAX are currently not supported */ return NULL; } needed += p->offset + 1; - if (needed <= p->length) - { + if (needed <= p->length) { return p->buffer + p->offset; } @@ -465,50 +406,38 @@ static unsigned char* ensure(printbuffer * const p, size_t needed) } /* calculate new buffer size */ - if (needed > (INT_MAX / 2)) - { + if (needed > (INT_MAX / 2)) { /* overflow of int, use INT_MAX if possible */ - if (needed <= INT_MAX) - { + if (needed <= INT_MAX) { newsize = INT_MAX; - } - else - { + } else { return NULL; } - } - else - { + } else { newsize = needed * 2; } - if (p->hooks.reallocate != NULL) - { + if (p->hooks.reallocate != NULL) { /* reallocate with realloc if available */ - newbuffer = (unsigned char*)p->hooks.reallocate(p->buffer, newsize); - if (newbuffer == NULL) - { + newbuffer = (unsigned char *)p->hooks.reallocate(p->buffer, newsize); + if (newbuffer == NULL) { p->hooks.deallocate(p->buffer); p->length = 0; p->buffer = NULL; return NULL; } - } - else - { + } else { /* otherwise reallocate manually */ - newbuffer = (unsigned char*)p->hooks.allocate(newsize); - if (!newbuffer) - { + newbuffer = (unsigned char *)p->hooks.allocate(newsize); + if (!newbuffer) { p->hooks.deallocate(p->buffer); p->length = 0; p->buffer = NULL; return NULL; } - if (newbuffer) - { + if (newbuffer) { memcpy(newbuffer, p->buffer, p->offset + 1); } p->hooks.deallocate(p->buffer); @@ -520,78 +449,65 @@ static unsigned char* ensure(printbuffer * const p, size_t needed) } /* calculate the new length of the string in a printbuffer and update the offset */ -static void update_offset(printbuffer * const buffer) -{ +static void update_offset(printbuffer *const buffer) { const unsigned char *buffer_pointer = NULL; - if ((buffer == NULL) || (buffer->buffer == NULL)) - { + if ((buffer == NULL) || (buffer->buffer == NULL)) { return; } buffer_pointer = buffer->buffer + buffer->offset; - buffer->offset += strlen((const char*)buffer_pointer); + buffer->offset += strlen((const char *)buffer_pointer); } /* securely comparison of floating-point variables */ -static cJSON_bool compare_double(double a, double b) -{ +static cJSON_bool compare_double(double a, double b) { double maxVal = fabs(a) > fabs(b) ? fabs(a) : fabs(b); return (fabs(a - b) <= maxVal * DBL_EPSILON); } /* Render the number nicely from the given item into a string. */ -static cJSON_bool print_number(const cJSON * const item, printbuffer * const output_buffer) -{ - unsigned char *output_pointer = NULL; - double d = item->valuedouble; - int length = 0; - size_t i = 0; - unsigned char number_buffer[26] = {0}; /* temporary buffer to print the number into */ - unsigned char decimal_point = get_decimal_point(); - double test = 0.0; +static cJSON_bool print_number(const cJSON *const item, printbuffer *const output_buffer) { + unsigned char *output_pointer = NULL; + double d = item->valuedouble; + int length = 0; + size_t i = 0; + unsigned char number_buffer[26] = {0}; /* temporary buffer to print the number into */ + unsigned char decimal_point = get_decimal_point(); + double test = 0.0; - if (output_buffer == NULL) - { + if (output_buffer == NULL) { return false; } /* This checks for NaN and Infinity */ - if (isnan(d) || isinf(d)) - { - length = sprintf((char*)number_buffer, "null"); - } - else - { + if (isnan(d) || isinf(d)) { + length = sprintf((char *)number_buffer, "null"); + } else { /* Try 15 decimal places of precision to avoid nonsignificant nonzero digits */ - length = sprintf((char*)number_buffer, "%1.15g", d); + length = sprintf((char *)number_buffer, "%1.15g", d); /* Check whether the original double can be recovered */ - if ((sscanf((char*)number_buffer, "%lg", &test) != 1) || !compare_double((double)test, d)) - { + if ((sscanf((char *)number_buffer, "%lg", &test) != 1) || !compare_double((double)test, d)) { /* If not, print with 17 decimal places of precision */ - length = sprintf((char*)number_buffer, "%1.17g", d); + length = sprintf((char *)number_buffer, "%1.17g", d); } } /* sprintf failed or buffer overrun occurred */ - if ((length < 0) || (length > (int)(sizeof(number_buffer) - 1))) - { + if ((length < 0) || (length > (int)(sizeof(number_buffer) - 1))) { return false; } /* reserve appropriate space in the output */ output_pointer = ensure(output_buffer, (size_t)length + sizeof("")); - if (output_pointer == NULL) - { + if (output_pointer == NULL) { return false; } /* copy the printed number to the output and replace locale * dependent decimal point with '.' */ - for (i = 0; i < ((size_t)length); i++) - { - if (number_buffer[i] == decimal_point) - { + for (i = 0; i < ((size_t)length); i++) { + if (number_buffer[i] == decimal_point) { output_pointer[i] = '.'; continue; } @@ -606,33 +522,24 @@ static cJSON_bool print_number(const cJSON * const item, printbuffer * const out } /* parse 4 digit hexadecimal number */ -static unsigned parse_hex4(const unsigned char * const input) -{ +static unsigned parse_hex4(const unsigned char *const input) { unsigned int h = 0; - size_t i = 0; + size_t i = 0; - for (i = 0; i < 4; i++) - { + for (i = 0; i < 4; i++) { /* parse digit */ - if ((input[i] >= '0') && (input[i] <= '9')) - { - h += (unsigned int) input[i] - '0'; - } - else if ((input[i] >= 'A') && (input[i] <= 'F')) - { - h += (unsigned int) 10 + input[i] - 'A'; - } - else if ((input[i] >= 'a') && (input[i] <= 'f')) - { - h += (unsigned int) 10 + input[i] - 'a'; - } - else /* invalid */ + if ((input[i] >= '0') && (input[i] <= '9')) { + h += (unsigned int)input[i] - '0'; + } else if ((input[i] >= 'A') && (input[i] <= 'F')) { + h += (unsigned int)10 + input[i] - 'A'; + } else if ((input[i] >= 'a') && (input[i] <= 'f')) { + h += (unsigned int)10 + input[i] - 'a'; + } else /* invalid */ { return 0; } - if (i < 3) - { + if (i < 3) { /* shift left to make place for the next nibble */ h = h << 4; } @@ -643,18 +550,18 @@ static unsigned parse_hex4(const unsigned char * const input) /* converts a UTF-16 literal to UTF-8 * A literal can be one or two sequences of the form \uXXXX */ -static unsigned char utf16_literal_to_utf8(const unsigned char * const input_pointer, const unsigned char * const input_end, unsigned char **output_pointer) -{ - long unsigned int codepoint = 0; - unsigned int first_code = 0; - const unsigned char *first_sequence = input_pointer; - unsigned char utf8_length = 0; - unsigned char utf8_position = 0; - unsigned char sequence_length = 0; - unsigned char first_byte_mark = 0; +static unsigned char utf16_literal_to_utf8(const unsigned char *const input_pointer, + const unsigned char *const input_end, + unsigned char **output_pointer) { + long unsigned int codepoint = 0; + unsigned int first_code = 0; + const unsigned char *first_sequence = input_pointer; + unsigned char utf8_length = 0; + unsigned char utf8_position = 0; + unsigned char sequence_length = 0; + unsigned char first_byte_mark = 0; - if ((input_end - first_sequence) < 6) - { + if ((input_end - first_sequence) < 6) { /* input ends unexpectedly */ goto fail; } @@ -663,26 +570,22 @@ static unsigned char utf16_literal_to_utf8(const unsigned char * const input_poi first_code = parse_hex4(first_sequence + 2); /* check that the code is valid */ - if (((first_code >= 0xDC00) && (first_code <= 0xDFFF))) - { + if (((first_code >= 0xDC00) && (first_code <= 0xDFFF))) { goto fail; } /* UTF16 surrogate pair */ - if ((first_code >= 0xD800) && (first_code <= 0xDBFF)) - { + if ((first_code >= 0xD800) && (first_code <= 0xDBFF)) { const unsigned char *second_sequence = first_sequence + 6; - unsigned int second_code = 0; - sequence_length = 12; /* \uXXXX\uXXXX */ + unsigned int second_code = 0; + sequence_length = 12; /* \uXXXX\uXXXX */ - if ((input_end - second_sequence) < 6) - { + if ((input_end - second_sequence) < 6) { /* input ends unexpectedly */ goto fail; } - if ((second_sequence[0] != '\\') || (second_sequence[1] != 'u')) - { + if ((second_sequence[0] != '\\') || (second_sequence[1] != 'u')) { /* missing second half of the surrogate pair */ goto fail; } @@ -690,68 +593,51 @@ static unsigned char utf16_literal_to_utf8(const unsigned char * const input_poi /* get the second utf16 sequence */ second_code = parse_hex4(second_sequence + 2); /* check that the code is valid */ - if ((second_code < 0xDC00) || (second_code > 0xDFFF)) - { + if ((second_code < 0xDC00) || (second_code > 0xDFFF)) { /* invalid second half of the surrogate pair */ goto fail; } - /* calculate the unicode codepoint from the surrogate pair */ codepoint = 0x10000 + (((first_code & 0x3FF) << 10) | (second_code & 0x3FF)); - } - else - { + } else { sequence_length = 6; /* \uXXXX */ - codepoint = first_code; + codepoint = first_code; } /* encode as UTF-8 * takes at maximum 4 bytes to encode: * 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx */ - if (codepoint < 0x80) - { + if (codepoint < 0x80) { /* normal ascii, encoding 0xxxxxxx */ utf8_length = 1; - } - else if (codepoint < 0x800) - { + } else if (codepoint < 0x800) { /* two bytes, encoding 110xxxxx 10xxxxxx */ - utf8_length = 2; + utf8_length = 2; first_byte_mark = 0xC0; /* 11000000 */ - } - else if (codepoint < 0x10000) - { + } else if (codepoint < 0x10000) { /* three bytes, encoding 1110xxxx 10xxxxxx 10xxxxxx */ - utf8_length = 3; + utf8_length = 3; first_byte_mark = 0xE0; /* 11100000 */ - } - else if (codepoint <= 0x10FFFF) - { + } else if (codepoint <= 0x10FFFF) { /* four bytes, encoding 1110xxxx 10xxxxxx 10xxxxxx 10xxxxxx */ - utf8_length = 4; + utf8_length = 4; first_byte_mark = 0xF0; /* 11110000 */ - } - else - { + } else { /* invalid unicode codepoint */ goto fail; } /* encode as utf8 */ - for (utf8_position = (unsigned char)(utf8_length - 1); utf8_position > 0; utf8_position--) - { + for (utf8_position = (unsigned char)(utf8_length - 1); utf8_position > 0; utf8_position--) { /* 10xxxxxx */ (*output_pointer)[utf8_position] = (unsigned char)((codepoint | 0x80) & 0xBF); codepoint >>= 6; } /* encode first byte */ - if (utf8_length > 1) - { + if (utf8_length > 1) { (*output_pointer)[0] = (unsigned char)((codepoint | first_byte_mark) & 0xFF); - } - else - { + } else { (*output_pointer)[0] = (unsigned char)(codepoint & 0x7F); } @@ -764,30 +650,25 @@ fail: } /* Parse the input text into an unescaped cinput, and populate item. */ -static cJSON_bool parse_string(cJSON * const item, parse_buffer * const input_buffer) -{ - const unsigned char *input_pointer = buffer_at_offset(input_buffer) + 1; - const unsigned char *input_end = buffer_at_offset(input_buffer) + 1; - unsigned char *output_pointer = NULL; - unsigned char *output = NULL; +static cJSON_bool parse_string(cJSON *const item, parse_buffer *const input_buffer) { + const unsigned char *input_pointer = buffer_at_offset(input_buffer) + 1; + const unsigned char *input_end = buffer_at_offset(input_buffer) + 1; + unsigned char *output_pointer = NULL; + unsigned char *output = NULL; /* not a string */ - if (buffer_at_offset(input_buffer)[0] != '\"') - { + if (buffer_at_offset(input_buffer)[0] != '\"') { goto fail; } { /* calculate approximate size of the output (overestimate) */ size_t allocation_length = 0; - size_t skipped_bytes = 0; - while (((size_t)(input_end - input_buffer->content) < input_buffer->length) && (*input_end != '\"')) - { + size_t skipped_bytes = 0; + while (((size_t)(input_end - input_buffer->content) < input_buffer->length) && (*input_end != '\"')) { /* is escape sequence */ - if (input_end[0] == '\\') - { - if ((size_t)(input_end + 1 - input_buffer->content) >= input_buffer->length) - { + if (input_end[0] == '\\') { + if ((size_t)(input_end + 1 - input_buffer->content) >= input_buffer->length) { /* prevent buffer overflow when last input character is a backslash */ goto fail; } @@ -796,39 +677,32 @@ static cJSON_bool parse_string(cJSON * const item, parse_buffer * const input_bu } input_end++; } - if (((size_t)(input_end - input_buffer->content) >= input_buffer->length) || (*input_end != '\"')) - { + if (((size_t)(input_end - input_buffer->content) >= input_buffer->length) || (*input_end != '\"')) { goto fail; /* string ended unexpectedly */ } /* This is at most how much we need for the output */ - allocation_length = (size_t) (input_end - buffer_at_offset(input_buffer)) - skipped_bytes; - output = (unsigned char*)input_buffer->hooks.allocate(allocation_length + sizeof("")); - if (output == NULL) - { + allocation_length = (size_t)(input_end - buffer_at_offset(input_buffer)) - skipped_bytes; + output = (unsigned char *)input_buffer->hooks.allocate(allocation_length + sizeof("")); + if (output == NULL) { goto fail; /* allocation failure */ } } output_pointer = output; /* loop through the string literal */ - while (input_pointer < input_end) - { - if (*input_pointer != '\\') - { + while (input_pointer < input_end) { + if (*input_pointer != '\\') { *output_pointer++ = *input_pointer++; } /* escape sequence */ - else - { + else { unsigned char sequence_length = 2; - if ((input_end - input_pointer) < 1) - { + if ((input_end - input_pointer) < 1) { goto fail; } - switch (input_pointer[1]) - { + switch (input_pointer[1]) { case 'b': *output_pointer++ = '\b'; break; @@ -853,8 +727,7 @@ static cJSON_bool parse_string(cJSON * const item, parse_buffer * const input_bu /* UTF-16 literal */ case 'u': sequence_length = utf16_literal_to_utf8(input_pointer, input_end, &output_pointer); - if (sequence_length == 0) - { + if (sequence_length == 0) { /* failed to convert UTF16-literal to UTF-8 */ goto fail; } @@ -870,22 +743,20 @@ static cJSON_bool parse_string(cJSON * const item, parse_buffer * const input_bu /* zero terminate the output */ *output_pointer = '\0'; - item->type = cJSON_String; - item->valuestring = (char*)output; + item->type = cJSON_String; + item->valuestring = (char *)output; - input_buffer->offset = (size_t) (input_end - input_buffer->content); + input_buffer->offset = (size_t)(input_end - input_buffer->content); input_buffer->offset++; return true; fail: - if (output != NULL) - { + if (output != NULL) { input_buffer->hooks.deallocate(output); } - if (input_pointer != NULL) - { + if (input_pointer != NULL) { input_buffer->offset = (size_t)(input_pointer - input_buffer->content); } @@ -893,38 +764,32 @@ fail: } /* Render the cstring provided to an escaped version that can be printed. */ -static cJSON_bool print_string_ptr(const unsigned char * const input, printbuffer * const output_buffer) -{ - const unsigned char *input_pointer = NULL; - unsigned char *output = NULL; - unsigned char *output_pointer = NULL; - size_t output_length = 0; +static cJSON_bool print_string_ptr(const unsigned char *const input, printbuffer *const output_buffer) { + const unsigned char *input_pointer = NULL; + unsigned char *output = NULL; + unsigned char *output_pointer = NULL; + size_t output_length = 0; /* numbers of additional characters needed for escaping */ size_t escape_characters = 0; - if (output_buffer == NULL) - { + if (output_buffer == NULL) { return false; } /* empty string */ - if (input == NULL) - { + if (input == NULL) { output = ensure(output_buffer, sizeof("\"\"")); - if (output == NULL) - { + if (output == NULL) { return false; } - strcpy((char*)output, "\"\""); + strcpy((char *)output, "\"\""); return true; } /* set "flag" to 1 if something needs to be escaped */ - for (input_pointer = input; *input_pointer; input_pointer++) - { - switch (*input_pointer) - { + for (input_pointer = input; *input_pointer; input_pointer++) { + switch (*input_pointer) { case '\"': case '\\': case '\b': @@ -936,8 +801,7 @@ static cJSON_bool print_string_ptr(const unsigned char * const input, printbuffe escape_characters++; break; default: - if (*input_pointer < 32) - { + if (*input_pointer < 32) { /* UTF-16 escape sequence uXXXX */ escape_characters += 5; } @@ -947,14 +811,12 @@ static cJSON_bool print_string_ptr(const unsigned char * const input, printbuffe output_length = (size_t)(input_pointer - input) + escape_characters; output = ensure(output_buffer, output_length + sizeof("\"\"")); - if (output == NULL) - { + if (output == NULL) { return false; } /* no characters have to be escaped */ - if (escape_characters == 0) - { + if (escape_characters == 0) { output[0] = '\"'; memcpy(output + 1, input, output_length); output[output_length + 1] = '\"'; @@ -963,22 +825,17 @@ static cJSON_bool print_string_ptr(const unsigned char * const input, printbuffe return true; } - output[0] = '\"'; + output[0] = '\"'; output_pointer = output + 1; /* copy the string */ - for (input_pointer = input; *input_pointer != '\0'; (void)input_pointer++, output_pointer++) - { - if ((*input_pointer > 31) && (*input_pointer != '\"') && (*input_pointer != '\\')) - { + for (input_pointer = input; *input_pointer != '\0'; (void)input_pointer++, output_pointer++) { + if ((*input_pointer > 31) && (*input_pointer != '\"') && (*input_pointer != '\\')) { /* normal character, copy */ *output_pointer = *input_pointer; - } - else - { + } else { /* character needs to be escaped */ *output_pointer++ = '\\'; - switch (*input_pointer) - { + switch (*input_pointer) { case '\\': *output_pointer = '\\'; break; @@ -1002,7 +859,7 @@ static cJSON_bool print_string_ptr(const unsigned char * const input, printbuffe break; default: /* escape and print as unicode codepoint */ - sprintf((char*)output_pointer, "u%04x", *input_pointer); + sprintf((char *)output_pointer, "u%04x", *input_pointer); output_pointer += 4; break; } @@ -1015,39 +872,33 @@ static cJSON_bool print_string_ptr(const unsigned char * const input, printbuffe } /* Invoke print_string_ptr (which is useful) on an item. */ -static cJSON_bool print_string(const cJSON * const item, printbuffer * const p) -{ - return print_string_ptr((unsigned char*)item->valuestring, p); +static cJSON_bool print_string(const cJSON *const item, printbuffer *const p) { + return print_string_ptr((unsigned char *)item->valuestring, p); } /* Predeclare these prototypes. */ -static cJSON_bool parse_value(cJSON * const item, parse_buffer * const input_buffer); -static cJSON_bool print_value(const cJSON * const item, printbuffer * const output_buffer); -static cJSON_bool parse_array(cJSON * const item, parse_buffer * const input_buffer); -static cJSON_bool print_array(const cJSON * const item, printbuffer * const output_buffer); -static cJSON_bool parse_object(cJSON * const item, parse_buffer * const input_buffer); -static cJSON_bool print_object(const cJSON * const item, printbuffer * const output_buffer); +static cJSON_bool parse_value(cJSON *const item, parse_buffer *const input_buffer); +static cJSON_bool print_value(const cJSON *const item, printbuffer *const output_buffer); +static cJSON_bool parse_array(cJSON *const item, parse_buffer *const input_buffer); +static cJSON_bool print_array(const cJSON *const item, printbuffer *const output_buffer); +static cJSON_bool parse_object(cJSON *const item, parse_buffer *const input_buffer); +static cJSON_bool print_object(const cJSON *const item, printbuffer *const output_buffer); /* Utility to jump whitespace and cr/lf */ -static parse_buffer *buffer_skip_whitespace(parse_buffer * const buffer) -{ - if ((buffer == NULL) || (buffer->content == NULL)) - { +static parse_buffer *buffer_skip_whitespace(parse_buffer *const buffer) { + if ((buffer == NULL) || (buffer->content == NULL)) { return NULL; } - if (cannot_access_at_index(buffer, 0)) - { + if (cannot_access_at_index(buffer, 0)) { return buffer; } - while (can_access_at_index(buffer, 0) && (buffer_at_offset(buffer)[0] <= 32)) - { - buffer->offset++; + while (can_access_at_index(buffer, 0) && (buffer_at_offset(buffer)[0] <= 32)) { + buffer->offset++; } - if (buffer->offset == buffer->length) - { + if (buffer->offset == buffer->length) { buffer->offset--; } @@ -1055,27 +906,23 @@ static parse_buffer *buffer_skip_whitespace(parse_buffer * const buffer) } /* skip the UTF-8 BOM (byte order mark) if it is at the beginning of a buffer */ -static parse_buffer *skip_utf8_bom(parse_buffer * const buffer) -{ - if ((buffer == NULL) || (buffer->content == NULL) || (buffer->offset != 0)) - { +static parse_buffer *skip_utf8_bom(parse_buffer *const buffer) { + if ((buffer == NULL) || (buffer->content == NULL) || (buffer->offset != 0)) { return NULL; } - if (can_access_at_index(buffer, 4) && (strncmp((const char*)buffer_at_offset(buffer), "\xEF\xBB\xBF", 3) == 0)) - { + if (can_access_at_index(buffer, 4) && (strncmp((const char *)buffer_at_offset(buffer), "\xEF\xBB\xBF", 3) == 0)) { buffer->offset += 3; } return buffer; } -CJSON_PUBLIC(cJSON *) cJSON_ParseWithOpts(const char *value, const char **return_parse_end, cJSON_bool require_null_terminated) -{ +CJSON_PUBLIC(cJSON *) +cJSON_ParseWithOpts(const char *value, const char **return_parse_end, cJSON_bool require_null_terminated) { size_t buffer_length; - if (NULL == value) - { + if (NULL == value) { return NULL; } @@ -1086,24 +933,28 @@ CJSON_PUBLIC(cJSON *) cJSON_ParseWithOpts(const char *value, const char **return } /* Parse an object - create a new root, and populate. */ -CJSON_PUBLIC(cJSON *) cJSON_ParseWithLengthOpts(const char *value, size_t buffer_length, const char **return_parse_end, cJSON_bool require_null_terminated) -{ - parse_buffer buffer = { 0, 0, 0, 0, { 0, 0, 0 } }; +CJSON_PUBLIC(cJSON *) +cJSON_ParseWithLengthOpts(const char *value, + size_t buffer_length, + const char **return_parse_end, + cJSON_bool require_null_terminated) { + parse_buffer buffer = { + 0, 0, 0, 0, {0, 0, 0} + }; cJSON *item = NULL; /* reset error position */ - global_error.json = NULL; + global_error.json = NULL; global_error.position = 0; - if (value == NULL || 0 == buffer_length) - { + if (value == NULL || 0 == buffer_length) { goto fail; } - buffer.content = (const unsigned char*)value; - buffer.length = buffer_length; - buffer.offset = 0; - buffer.hooks = global_hooks; + buffer.content = (const unsigned char *)value; + buffer.length = buffer_length; + buffer.offset = 0; + buffer.hooks = global_hooks; item = cJSON_New_Item(&global_hooks); if (item == NULL) /* memory fail */ @@ -1111,52 +962,42 @@ CJSON_PUBLIC(cJSON *) cJSON_ParseWithLengthOpts(const char *value, size_t buffer goto fail; } - if (!parse_value(item, buffer_skip_whitespace(skip_utf8_bom(&buffer)))) - { + if (!parse_value(item, buffer_skip_whitespace(skip_utf8_bom(&buffer)))) { /* parse failure. ep is set. */ goto fail; } /* if we require null-terminated JSON without appended garbage, skip and then check for a null terminator */ - if (require_null_terminated) - { + if (require_null_terminated) { buffer_skip_whitespace(&buffer); - if ((buffer.offset >= buffer.length) || buffer_at_offset(&buffer)[0] != '\0') - { + if ((buffer.offset >= buffer.length) || buffer_at_offset(&buffer)[0] != '\0') { goto fail; } } - if (return_parse_end) - { - *return_parse_end = (const char*)buffer_at_offset(&buffer); + if (return_parse_end) { + *return_parse_end = (const char *)buffer_at_offset(&buffer); } return item; fail: - if (item != NULL) - { + if (item != NULL) { cJSON_Delete(item); } - if (value != NULL) - { + if (value != NULL) { error local_error; - local_error.json = (const unsigned char*)value; + local_error.json = (const unsigned char *)value; local_error.position = 0; - if (buffer.offset < buffer.length) - { + if (buffer.offset < buffer.length) { local_error.position = buffer.offset; - } - else if (buffer.length > 0) - { + } else if (buffer.length > 0) { local_error.position = buffer.length - 1; } - if (return_parse_end != NULL) - { - *return_parse_end = (const char*)local_error.json + local_error.position; + if (return_parse_end != NULL) { + *return_parse_end = (const char *)local_error.json + local_error.position; } global_error = local_error; @@ -1166,57 +1007,49 @@ fail: } /* Default options for cJSON_Parse */ -CJSON_PUBLIC(cJSON *) cJSON_Parse(const char *value) -{ +CJSON_PUBLIC(cJSON *) cJSON_Parse(const char *value) { return cJSON_ParseWithOpts(value, 0, 0); } -CJSON_PUBLIC(cJSON *) cJSON_ParseWithLength(const char *value, size_t buffer_length) -{ +CJSON_PUBLIC(cJSON *) cJSON_ParseWithLength(const char *value, size_t buffer_length) { return cJSON_ParseWithLengthOpts(value, buffer_length, 0, 0); } #define cjson_min(a, b) (((a) < (b)) ? (a) : (b)) -static unsigned char *print(const cJSON * const item, cJSON_bool format, const internal_hooks * const hooks) -{ +static unsigned char *print(const cJSON *const item, cJSON_bool format, const internal_hooks *const hooks) { static const size_t default_buffer_size = 256; - printbuffer buffer[1]; - unsigned char *printed = NULL; + printbuffer buffer[1]; + unsigned char *printed = NULL; memset(buffer, 0, sizeof(buffer)); /* create buffer */ - buffer->buffer = (unsigned char*) hooks->allocate(default_buffer_size); + buffer->buffer = (unsigned char *)hooks->allocate(default_buffer_size); buffer->length = default_buffer_size; buffer->format = format; - buffer->hooks = *hooks; - if (buffer->buffer == NULL) - { + buffer->hooks = *hooks; + if (buffer->buffer == NULL) { goto fail; } /* print the value */ - if (!print_value(item, buffer)) - { + if (!print_value(item, buffer)) { goto fail; } update_offset(buffer); /* check if reallocate is available */ - if (hooks->reallocate != NULL) - { - printed = (unsigned char*) hooks->reallocate(buffer->buffer, buffer->offset + 1); + if (hooks->reallocate != NULL) { + printed = (unsigned char *)hooks->reallocate(buffer->buffer, buffer->offset + 1); if (printed == NULL) { goto fail; } buffer->buffer = NULL; - } - else /* otherwise copy the JSON over to a new buffer */ + } else /* otherwise copy the JSON over to a new buffer */ { - printed = (unsigned char*) hooks->allocate(buffer->offset + 1); - if (printed == NULL) - { + printed = (unsigned char *)hooks->allocate(buffer->offset + 1); + if (printed == NULL) { goto fail; } memcpy(printed, buffer->buffer, cjson_min(buffer->length, buffer->offset + 1)); @@ -1229,13 +1062,11 @@ static unsigned char *print(const cJSON * const item, cJSON_bool format, const i return printed; fail: - if (buffer->buffer != NULL) - { + if (buffer->buffer != NULL) { hooks->deallocate(buffer->buffer); } - if (printed != NULL) - { + if (printed != NULL) { hooks->deallocate(printed); } @@ -1243,114 +1074,103 @@ fail: } /* Render a cJSON item/entity/structure to text. */ -CJSON_PUBLIC(char *) cJSON_Print(const cJSON *item) -{ - return (char*)print(item, true, &global_hooks); +CJSON_PUBLIC(char *) cJSON_Print(const cJSON *item) { + return (char *)print(item, true, &global_hooks); } -CJSON_PUBLIC(char *) cJSON_PrintUnformatted(const cJSON *item) -{ - return (char*)print(item, false, &global_hooks); +CJSON_PUBLIC(char *) cJSON_PrintUnformatted(const cJSON *item) { + return (char *)print(item, false, &global_hooks); } -CJSON_PUBLIC(char *) cJSON_PrintBuffered(const cJSON *item, int prebuffer, cJSON_bool fmt) -{ - printbuffer p = { 0, 0, 0, 0, 0, 0, { 0, 0, 0 } }; +CJSON_PUBLIC(char *) cJSON_PrintBuffered(const cJSON *item, int prebuffer, cJSON_bool fmt) { + printbuffer p = { + 0, 0, 0, 0, 0, 0, {0, 0, 0} + }; - if (prebuffer < 0) - { + if (prebuffer < 0) { return NULL; } - p.buffer = (unsigned char*)global_hooks.allocate((size_t)prebuffer); - if (!p.buffer) - { + p.buffer = (unsigned char *)global_hooks.allocate((size_t)prebuffer); + if (!p.buffer) { return NULL; } - p.length = (size_t)prebuffer; - p.offset = 0; + p.length = (size_t)prebuffer; + p.offset = 0; p.noalloc = false; - p.format = fmt; - p.hooks = global_hooks; + p.format = fmt; + p.hooks = global_hooks; - if (!print_value(item, &p)) - { + if (!print_value(item, &p)) { global_hooks.deallocate(p.buffer); return NULL; } - return (char*)p.buffer; + return (char *)p.buffer; } -CJSON_PUBLIC(cJSON_bool) cJSON_PrintPreallocated(cJSON *item, char *buffer, const int length, const cJSON_bool format) -{ - printbuffer p = { 0, 0, 0, 0, 0, 0, { 0, 0, 0 } }; +CJSON_PUBLIC(cJSON_bool) cJSON_PrintPreallocated(cJSON *item, char *buffer, const int length, const cJSON_bool format) { + printbuffer p = { + 0, 0, 0, 0, 0, 0, {0, 0, 0} + }; - if ((length < 0) || (buffer == NULL)) - { + if ((length < 0) || (buffer == NULL)) { return false; } - p.buffer = (unsigned char*)buffer; - p.length = (size_t)length; - p.offset = 0; + p.buffer = (unsigned char *)buffer; + p.length = (size_t)length; + p.offset = 0; p.noalloc = true; - p.format = format; - p.hooks = global_hooks; + p.format = format; + p.hooks = global_hooks; return print_value(item, &p); } /* Parser core - when encountering text, process appropriately. */ -static cJSON_bool parse_value(cJSON * const item, parse_buffer * const input_buffer) -{ - if ((input_buffer == NULL) || (input_buffer->content == NULL)) - { +static cJSON_bool parse_value(cJSON *const item, parse_buffer *const input_buffer) { + if ((input_buffer == NULL) || (input_buffer->content == NULL)) { return false; /* no input */ } /* parse the different types of values */ /* null */ - if (can_read(input_buffer, 4) && (strncmp((const char*)buffer_at_offset(input_buffer), "null", 4) == 0)) - { + if (can_read(input_buffer, 4) && (strncmp((const char *)buffer_at_offset(input_buffer), "null", 4) == 0)) { item->type = cJSON_NULL; input_buffer->offset += 4; return true; } /* false */ - if (can_read(input_buffer, 5) && (strncmp((const char*)buffer_at_offset(input_buffer), "false", 5) == 0)) - { + if (can_read(input_buffer, 5) && (strncmp((const char *)buffer_at_offset(input_buffer), "false", 5) == 0)) { item->type = cJSON_False; input_buffer->offset += 5; return true; } /* true */ - if (can_read(input_buffer, 4) && (strncmp((const char*)buffer_at_offset(input_buffer), "true", 4) == 0)) - { - item->type = cJSON_True; + if (can_read(input_buffer, 4) && (strncmp((const char *)buffer_at_offset(input_buffer), "true", 4) == 0)) { + item->type = cJSON_True; item->valueint = 1; input_buffer->offset += 4; return true; } /* string */ - if (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == '\"')) - { + if (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == '\"')) { return parse_string(item, input_buffer); } /* number */ - if (can_access_at_index(input_buffer, 0) && ((buffer_at_offset(input_buffer)[0] == '-') || ((buffer_at_offset(input_buffer)[0] >= '0') && (buffer_at_offset(input_buffer)[0] <= '9')))) - { + if (can_access_at_index(input_buffer, 0) + && ((buffer_at_offset(input_buffer)[0] == '-') + || ((buffer_at_offset(input_buffer)[0] >= '0') && (buffer_at_offset(input_buffer)[0] <= '9')))) { return parse_number(item, input_buffer); } /* array */ - if (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == '[')) - { + if (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == '[')) { return parse_array(item, input_buffer); } /* object */ - if (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == '{')) - { + if (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == '{')) { return parse_object(item, input_buffer); } @@ -1358,59 +1178,50 @@ static cJSON_bool parse_value(cJSON * const item, parse_buffer * const input_buf } /* Render a value to text. */ -static cJSON_bool print_value(const cJSON * const item, printbuffer * const output_buffer) -{ +static cJSON_bool print_value(const cJSON *const item, printbuffer *const output_buffer) { unsigned char *output = NULL; - if ((item == NULL) || (output_buffer == NULL)) - { + if ((item == NULL) || (output_buffer == NULL)) { return false; } - switch ((item->type) & 0xFF) - { + switch ((item->type) & 0xFF) { case cJSON_NULL: output = ensure(output_buffer, 5); - if (output == NULL) - { + if (output == NULL) { return false; } - strcpy((char*)output, "null"); + strcpy((char *)output, "null"); return true; case cJSON_False: output = ensure(output_buffer, 6); - if (output == NULL) - { + if (output == NULL) { return false; } - strcpy((char*)output, "false"); + strcpy((char *)output, "false"); return true; case cJSON_True: output = ensure(output_buffer, 5); - if (output == NULL) - { + if (output == NULL) { return false; } - strcpy((char*)output, "true"); + strcpy((char *)output, "true"); return true; case cJSON_Number: return print_number(item, output_buffer); - case cJSON_Raw: - { + case cJSON_Raw: { size_t raw_length = 0; - if (item->valuestring == NULL) - { + if (item->valuestring == NULL) { return false; } raw_length = strlen(item->valuestring) + sizeof(""); - output = ensure(output_buffer, raw_length); - if (output == NULL) - { + output = ensure(output_buffer, raw_length); + if (output == NULL) { return false; } memcpy(output, item->valuestring, raw_length); @@ -1432,34 +1243,29 @@ static cJSON_bool print_value(const cJSON * const item, printbuffer * const outp } /* Build an array from input text. */ -static cJSON_bool parse_array(cJSON * const item, parse_buffer * const input_buffer) -{ - cJSON *head = NULL; /* head of the linked list */ +static cJSON_bool parse_array(cJSON *const item, parse_buffer *const input_buffer) { + cJSON *head = NULL; /* head of the linked list */ cJSON *current_item = NULL; - if (input_buffer->depth >= CJSON_NESTING_LIMIT) - { + if (input_buffer->depth >= CJSON_NESTING_LIMIT) { return false; /* to deeply nested */ } input_buffer->depth++; - if (buffer_at_offset(input_buffer)[0] != '[') - { + if (buffer_at_offset(input_buffer)[0] != '[') { /* not an array */ goto fail; } input_buffer->offset++; buffer_skip_whitespace(input_buffer); - if (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == ']')) - { + if (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == ']')) { /* empty array */ goto success; } /* check if we skipped to the end of the buffer */ - if (cannot_access_at_index(input_buffer, 0)) - { + if (cannot_access_at_index(input_buffer, 0)) { input_buffer->offset--; goto fail; } @@ -1467,42 +1273,34 @@ static cJSON_bool parse_array(cJSON * const item, parse_buffer * const input_buf /* step back to character in front of the first element */ input_buffer->offset--; /* loop through the comma separated array elements */ - do - { + do { /* allocate next item */ cJSON *new_item = cJSON_New_Item(&(input_buffer->hooks)); - if (new_item == NULL) - { + if (new_item == NULL) { goto fail; /* allocation failure */ } /* attach next item to list */ - if (head == NULL) - { + if (head == NULL) { /* start the linked list */ current_item = head = new_item; - } - else - { + } else { /* add to the end and advance */ current_item->next = new_item; - new_item->prev = current_item; - current_item = new_item; + new_item->prev = current_item; + current_item = new_item; } /* parse next value */ input_buffer->offset++; buffer_skip_whitespace(input_buffer); - if (!parse_value(current_item, input_buffer)) - { + if (!parse_value(current_item, input_buffer)) { goto fail; /* failed to parse value */ } buffer_skip_whitespace(input_buffer); - } - while (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == ',')); + } while (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == ',')); - if (cannot_access_at_index(input_buffer, 0) || buffer_at_offset(input_buffer)[0] != ']') - { + if (cannot_access_at_index(input_buffer, 0) || buffer_at_offset(input_buffer)[0] != ']') { goto fail; /* expected end of array */ } @@ -1513,7 +1311,7 @@ success: head->prev = current_item; } - item->type = cJSON_Array; + item->type = cJSON_Array; item->child = head; input_buffer->offset++; @@ -1521,8 +1319,7 @@ success: return true; fail: - if (head != NULL) - { + if (head != NULL) { cJSON_Delete(head); } @@ -1530,22 +1327,19 @@ fail: } /* Render an array to text */ -static cJSON_bool print_array(const cJSON * const item, printbuffer * const output_buffer) -{ - unsigned char *output_pointer = NULL; - size_t length = 0; - cJSON *current_element = item->child; +static cJSON_bool print_array(const cJSON *const item, printbuffer *const output_buffer) { + unsigned char *output_pointer = NULL; + size_t length = 0; + cJSON *current_element = item->child; - if (output_buffer == NULL) - { + if (output_buffer == NULL) { return false; } /* Compose the output array. */ /* opening square bracket */ output_pointer = ensure(output_buffer, 1); - if (output_pointer == NULL) - { + if (output_pointer == NULL) { return false; } @@ -1553,24 +1347,19 @@ static cJSON_bool print_array(const cJSON * const item, printbuffer * const outp output_buffer->offset++; output_buffer->depth++; - while (current_element != NULL) - { - if (!print_value(current_element, output_buffer)) - { + while (current_element != NULL) { + if (!print_value(current_element, output_buffer)) { return false; } update_offset(output_buffer); - if (current_element->next) - { - length = (size_t) (output_buffer->format ? 2 : 1); + if (current_element->next) { + length = (size_t)(output_buffer->format ? 2 : 1); output_pointer = ensure(output_buffer, length + 1); - if (output_pointer == NULL) - { + if (output_pointer == NULL) { return false; } *output_pointer++ = ','; - if(output_buffer->format) - { + if (output_buffer->format) { *output_pointer++ = ' '; } *output_pointer = '\0'; @@ -1580,44 +1369,38 @@ static cJSON_bool print_array(const cJSON * const item, printbuffer * const outp } output_pointer = ensure(output_buffer, 2); - if (output_pointer == NULL) - { + if (output_pointer == NULL) { return false; } *output_pointer++ = ']'; - *output_pointer = '\0'; + *output_pointer = '\0'; output_buffer->depth--; return true; } /* Build an object from the text. */ -static cJSON_bool parse_object(cJSON * const item, parse_buffer * const input_buffer) -{ - cJSON *head = NULL; /* linked list head */ +static cJSON_bool parse_object(cJSON *const item, parse_buffer *const input_buffer) { + cJSON *head = NULL; /* linked list head */ cJSON *current_item = NULL; - if (input_buffer->depth >= CJSON_NESTING_LIMIT) - { + if (input_buffer->depth >= CJSON_NESTING_LIMIT) { return false; /* to deeply nested */ } input_buffer->depth++; - if (cannot_access_at_index(input_buffer, 0) || (buffer_at_offset(input_buffer)[0] != '{')) - { + if (cannot_access_at_index(input_buffer, 0) || (buffer_at_offset(input_buffer)[0] != '{')) { goto fail; /* not an object */ } input_buffer->offset++; buffer_skip_whitespace(input_buffer); - if (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == '}')) - { + if (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == '}')) { goto success; /* empty object */ } /* check if we skipped to the end of the buffer */ - if (cannot_access_at_index(input_buffer, 0)) - { + if (cannot_access_at_index(input_buffer, 0)) { input_buffer->offset--; goto fail; } @@ -1625,60 +1408,50 @@ static cJSON_bool parse_object(cJSON * const item, parse_buffer * const input_bu /* step back to character in front of the first element */ input_buffer->offset--; /* loop through the comma separated array elements */ - do - { + do { /* allocate next item */ cJSON *new_item = cJSON_New_Item(&(input_buffer->hooks)); - if (new_item == NULL) - { + if (new_item == NULL) { goto fail; /* allocation failure */ } /* attach next item to list */ - if (head == NULL) - { + if (head == NULL) { /* start the linked list */ current_item = head = new_item; - } - else - { + } else { /* add to the end and advance */ current_item->next = new_item; - new_item->prev = current_item; - current_item = new_item; + new_item->prev = current_item; + current_item = new_item; } /* parse the name of the child */ input_buffer->offset++; buffer_skip_whitespace(input_buffer); - if (!parse_string(current_item, input_buffer)) - { + if (!parse_string(current_item, input_buffer)) { goto fail; /* failed to parse name */ } buffer_skip_whitespace(input_buffer); /* swap valuestring and string, because we parsed the name */ - current_item->string = current_item->valuestring; + current_item->string = current_item->valuestring; current_item->valuestring = NULL; - if (cannot_access_at_index(input_buffer, 0) || (buffer_at_offset(input_buffer)[0] != ':')) - { + if (cannot_access_at_index(input_buffer, 0) || (buffer_at_offset(input_buffer)[0] != ':')) { goto fail; /* invalid object */ } /* parse the value */ input_buffer->offset++; buffer_skip_whitespace(input_buffer); - if (!parse_value(current_item, input_buffer)) - { + if (!parse_value(current_item, input_buffer)) { goto fail; /* failed to parse value */ } buffer_skip_whitespace(input_buffer); - } - while (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == ',')); + } while (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == ',')); - if (cannot_access_at_index(input_buffer, 0) || (buffer_at_offset(input_buffer)[0] != '}')) - { + if (cannot_access_at_index(input_buffer, 0) || (buffer_at_offset(input_buffer)[0] != '}')) { goto fail; /* expected end of object */ } @@ -1689,15 +1462,14 @@ success: head->prev = current_item; } - item->type = cJSON_Object; + item->type = cJSON_Object; item->child = head; input_buffer->offset++; return true; fail: - if (head != NULL) - { + if (head != NULL) { cJSON_Delete(head); } @@ -1705,91 +1477,76 @@ fail: } /* Render an object to text. */ -static cJSON_bool print_object(const cJSON * const item, printbuffer * const output_buffer) -{ +static cJSON_bool print_object(const cJSON *const item, printbuffer *const output_buffer) { unsigned char *output_pointer = NULL; - size_t length = 0; - cJSON *current_item = item->child; + size_t length = 0; + cJSON *current_item = item->child; - if (output_buffer == NULL) - { + if (output_buffer == NULL) { return false; } /* Compose the output: */ - length = (size_t) (output_buffer->format ? 2 : 1); /* fmt: {\n */ + length = (size_t)(output_buffer->format ? 2 : 1); /* fmt: {\n */ output_pointer = ensure(output_buffer, length + 1); - if (output_pointer == NULL) - { + if (output_pointer == NULL) { return false; } *output_pointer++ = '{'; output_buffer->depth++; - if (output_buffer->format) - { + if (output_buffer->format) { *output_pointer++ = '\n'; } output_buffer->offset += length; - while (current_item) - { - if (output_buffer->format) - { + while (current_item) { + if (output_buffer->format) { size_t i; output_pointer = ensure(output_buffer, output_buffer->depth); - if (output_pointer == NULL) - { + if (output_pointer == NULL) { return false; } - for (i = 0; i < output_buffer->depth; i++) - { + for (i = 0; i < output_buffer->depth; i++) { *output_pointer++ = '\t'; } output_buffer->offset += output_buffer->depth; } /* print key */ - if (!print_string_ptr((unsigned char*)current_item->string, output_buffer)) - { + if (!print_string_ptr((unsigned char *)current_item->string, output_buffer)) { return false; } update_offset(output_buffer); - length = (size_t) (output_buffer->format ? 2 : 1); + length = (size_t)(output_buffer->format ? 2 : 1); output_pointer = ensure(output_buffer, length); - if (output_pointer == NULL) - { + if (output_pointer == NULL) { return false; } *output_pointer++ = ':'; - if (output_buffer->format) - { + if (output_buffer->format) { *output_pointer++ = '\t'; } output_buffer->offset += length; /* print value */ - if (!print_value(current_item, output_buffer)) - { + if (!print_value(current_item, output_buffer)) { return false; } update_offset(output_buffer); /* print comma if not last */ - length = ((size_t)(output_buffer->format ? 1 : 0) + (size_t)(current_item->next ? 1 : 0)); + length = ((size_t)(output_buffer->format ? 1 : 0) + (size_t)(current_item->next ? 1 : 0)); output_pointer = ensure(output_buffer, length + 1); - if (output_pointer == NULL) - { + if (output_pointer == NULL) { return false; } - if (current_item->next) - { + if (current_item->next) { *output_pointer++ = ','; } - if (output_buffer->format) - { + if (output_buffer->format) { *output_pointer++ = '\n'; } *output_pointer = '\0'; @@ -1799,40 +1556,34 @@ static cJSON_bool print_object(const cJSON * const item, printbuffer * const out } output_pointer = ensure(output_buffer, output_buffer->format ? (output_buffer->depth + 1) : 2); - if (output_pointer == NULL) - { + if (output_pointer == NULL) { return false; } - if (output_buffer->format) - { + if (output_buffer->format) { size_t i; - for (i = 0; i < (output_buffer->depth - 1); i++) - { + for (i = 0; i < (output_buffer->depth - 1); i++) { *output_pointer++ = '\t'; } } *output_pointer++ = '}'; - *output_pointer = '\0'; + *output_pointer = '\0'; output_buffer->depth--; return true; } /* Get Array size/item / object item. */ -CJSON_PUBLIC(int) cJSON_GetArraySize(const cJSON *array) -{ +CJSON_PUBLIC(int) cJSON_GetArraySize(const cJSON *array) { cJSON *child = NULL; - size_t size = 0; + size_t size = 0; - if (array == NULL) - { + if (array == NULL) { return 0; } child = array->child; - while(child != NULL) - { + while (child != NULL) { size++; child = child->next; } @@ -1842,18 +1593,15 @@ CJSON_PUBLIC(int) cJSON_GetArraySize(const cJSON *array) return (int)size; } -static cJSON* get_array_item(const cJSON *array, size_t index) -{ +static cJSON *get_array_item(const cJSON *array, size_t index) { cJSON *current_child = NULL; - if (array == NULL) - { + if (array == NULL) { return NULL; } current_child = array->child; - while ((current_child != NULL) && (index > 0)) - { + while ((current_child != NULL) && (index > 0)) { index--; current_child = current_child->next; } @@ -1861,37 +1609,32 @@ static cJSON* get_array_item(const cJSON *array, size_t index) return current_child; } -CJSON_PUBLIC(cJSON *) cJSON_GetArrayItem(const cJSON *array, int index) -{ - if (index < 0) - { +CJSON_PUBLIC(cJSON *) cJSON_GetArrayItem(const cJSON *array, int index) { + if (index < 0) { return NULL; } return get_array_item(array, (size_t)index); } -static cJSON *get_object_item(const cJSON * const object, const char * const name, const cJSON_bool case_sensitive) -{ +static cJSON *get_object_item(const cJSON *const object, const char *const name, const cJSON_bool case_sensitive) { cJSON *current_element = NULL; - if ((object == NULL) || (name == NULL)) - { + if ((object == NULL) || (name == NULL)) { return NULL; } current_element = object->child; - if (case_sensitive) - { - while ((current_element != NULL) && (current_element->string != NULL) && (strcmp(name, current_element->string) != 0)) - { + if (case_sensitive) { + while ((current_element != NULL) && (current_element->string != NULL) + && (strcmp(name, current_element->string) != 0)) { current_element = current_element->next; } - } - else - { - while ((current_element != NULL) && (case_insensitive_strcmp((const unsigned char*)name, (const unsigned char*)(current_element->string)) != 0)) - { + } else { + while ( + (current_element != NULL) + && (case_insensitive_strcmp((const unsigned char *)name, (const unsigned char *)(current_element->string)) + != 0)) { current_element = current_element->next; } } @@ -1903,40 +1646,33 @@ static cJSON *get_object_item(const cJSON * const object, const char * const nam return current_element; } -CJSON_PUBLIC(cJSON *) cJSON_GetObjectItem(const cJSON * const object, const char * const string) -{ +CJSON_PUBLIC(cJSON *) cJSON_GetObjectItem(const cJSON *const object, const char *const string) { return get_object_item(object, string, false); } -CJSON_PUBLIC(cJSON *) cJSON_GetObjectItemCaseSensitive(const cJSON * const object, const char * const string) -{ +CJSON_PUBLIC(cJSON *) cJSON_GetObjectItemCaseSensitive(const cJSON *const object, const char *const string) { return get_object_item(object, string, true); } -CJSON_PUBLIC(cJSON_bool) cJSON_HasObjectItem(const cJSON *object, const char *string) -{ +CJSON_PUBLIC(cJSON_bool) cJSON_HasObjectItem(const cJSON *object, const char *string) { return cJSON_GetObjectItem(object, string) ? 1 : 0; } /* Utility for array list handling. */ -static void suffix_object(cJSON *prev, cJSON *item) -{ +static void suffix_object(cJSON *prev, cJSON *item) { prev->next = item; item->prev = prev; } /* Utility for handling references. */ -static cJSON *create_reference(const cJSON *item, const internal_hooks * const hooks) -{ +static cJSON *create_reference(const cJSON *item, const internal_hooks *const hooks) { cJSON *reference = NULL; - if (item == NULL) - { + if (item == NULL) { return NULL; } reference = cJSON_New_Item(hooks); - if (reference == NULL) - { + if (reference == NULL) { return NULL; } @@ -1947,12 +1683,10 @@ static cJSON *create_reference(const cJSON *item, const internal_hooks * const h return reference; } -static cJSON_bool add_item_to_array(cJSON *array, cJSON *item) -{ +static cJSON_bool add_item_to_array(cJSON *array, cJSON *item) { cJSON *child = NULL; - if ((item == NULL) || (array == NULL) || (array == item)) - { + if ((item == NULL) || (array == NULL) || (array == item)) { return false; } @@ -1960,18 +1694,14 @@ static cJSON_bool add_item_to_array(cJSON *array, cJSON *item) /* * To find the last item in array quickly, we use prev in array */ - if (child == NULL) - { + if (child == NULL) { /* list is empty, start new one */ array->child = item; - item->prev = item; - item->next = NULL; - } - else - { + item->prev = item; + item->next = NULL; + } else { /* append to the end */ - if (child->prev) - { + if (child->prev) { suffix_object(child->prev, item); array->child->prev = item; } @@ -1981,100 +1711,86 @@ static cJSON_bool add_item_to_array(cJSON *array, cJSON *item) } /* Add item to array/object. */ -CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToArray(cJSON *array, cJSON *item) -{ +CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToArray(cJSON *array, cJSON *item) { return add_item_to_array(array, item); } -#if defined(__clang__) || (defined(__GNUC__) && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ > 5)))) - #pragma GCC diagnostic push +#if defined(__clang__) || (defined(__GNUC__) && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ > 5)))) +#pragma GCC diagnostic push #endif #ifdef __GNUC__ #pragma GCC diagnostic ignored "-Wcast-qual" #endif /* helper function to cast away const */ -static void* cast_away_const(const void* string) -{ - return (void*)string; +static void *cast_away_const(const void *string) { + return (void *)string; } -#if defined(__clang__) || (defined(__GNUC__) && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ > 5)))) - #pragma GCC diagnostic pop +#if defined(__clang__) || (defined(__GNUC__) && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ > 5)))) +#pragma GCC diagnostic pop #endif +static cJSON_bool add_item_to_object(cJSON *const object, + const char *const string, + cJSON *const item, + const internal_hooks *const hooks, + const cJSON_bool constant_key) { + char *new_key = NULL; + int new_type = cJSON_Invalid; -static cJSON_bool add_item_to_object(cJSON * const object, const char * const string, cJSON * const item, const internal_hooks * const hooks, const cJSON_bool constant_key) -{ - char *new_key = NULL; - int new_type = cJSON_Invalid; - - if ((object == NULL) || (string == NULL) || (item == NULL) || (object == item)) - { + if ((object == NULL) || (string == NULL) || (item == NULL) || (object == item)) { return false; } - if (constant_key) - { - new_key = (char*)cast_away_const(string); + if (constant_key) { + new_key = (char *)cast_away_const(string); new_type = item->type | cJSON_StringIsConst; - } - else - { - new_key = (char*)cJSON_strdup((const unsigned char*)string, hooks); - if (new_key == NULL) - { + } else { + new_key = (char *)cJSON_strdup((const unsigned char *)string, hooks); + if (new_key == NULL) { return false; } new_type = item->type & ~cJSON_StringIsConst; } - if (!(item->type & cJSON_StringIsConst) && (item->string != NULL)) - { + if (!(item->type & cJSON_StringIsConst) && (item->string != NULL)) { hooks->deallocate(item->string); } item->string = new_key; - item->type = new_type; + item->type = new_type; return add_item_to_array(object, item); } -CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToObject(cJSON *object, const char *string, cJSON *item) -{ +CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToObject(cJSON *object, const char *string, cJSON *item) { return add_item_to_object(object, string, item, &global_hooks, false); } /* Add an item to an object with constant string as key */ -CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToObjectCS(cJSON *object, const char *string, cJSON *item) -{ +CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToObjectCS(cJSON *object, const char *string, cJSON *item) { return add_item_to_object(object, string, item, &global_hooks, true); } -CJSON_PUBLIC(cJSON_bool) cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item) -{ - if (array == NULL) - { +CJSON_PUBLIC(cJSON_bool) cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item) { + if (array == NULL) { return false; } return add_item_to_array(array, create_reference(item, &global_hooks)); } -CJSON_PUBLIC(cJSON_bool) cJSON_AddItemReferenceToObject(cJSON *object, const char *string, cJSON *item) -{ - if ((object == NULL) || (string == NULL)) - { +CJSON_PUBLIC(cJSON_bool) cJSON_AddItemReferenceToObject(cJSON *object, const char *string, cJSON *item) { + if ((object == NULL) || (string == NULL)) { return false; } return add_item_to_object(object, string, create_reference(item, &global_hooks), &global_hooks, false); } -CJSON_PUBLIC(cJSON*) cJSON_AddNullToObject(cJSON * const object, const char * const name) -{ +CJSON_PUBLIC(cJSON *) cJSON_AddNullToObject(cJSON *const object, const char *const name) { cJSON *null = cJSON_CreateNull(); - if (add_item_to_object(object, name, null, &global_hooks, false)) - { + if (add_item_to_object(object, name, null, &global_hooks, false)) { return null; } @@ -2082,11 +1798,9 @@ CJSON_PUBLIC(cJSON*) cJSON_AddNullToObject(cJSON * const object, const char * co return NULL; } -CJSON_PUBLIC(cJSON*) cJSON_AddTrueToObject(cJSON * const object, const char * const name) -{ +CJSON_PUBLIC(cJSON *) cJSON_AddTrueToObject(cJSON *const object, const char *const name) { cJSON *true_item = cJSON_CreateTrue(); - if (add_item_to_object(object, name, true_item, &global_hooks, false)) - { + if (add_item_to_object(object, name, true_item, &global_hooks, false)) { return true_item; } @@ -2094,11 +1808,9 @@ CJSON_PUBLIC(cJSON*) cJSON_AddTrueToObject(cJSON * const object, const char * co return NULL; } -CJSON_PUBLIC(cJSON*) cJSON_AddFalseToObject(cJSON * const object, const char * const name) -{ +CJSON_PUBLIC(cJSON *) cJSON_AddFalseToObject(cJSON *const object, const char *const name) { cJSON *false_item = cJSON_CreateFalse(); - if (add_item_to_object(object, name, false_item, &global_hooks, false)) - { + if (add_item_to_object(object, name, false_item, &global_hooks, false)) { return false_item; } @@ -2106,11 +1818,9 @@ CJSON_PUBLIC(cJSON*) cJSON_AddFalseToObject(cJSON * const object, const char * c return NULL; } -CJSON_PUBLIC(cJSON*) cJSON_AddBoolToObject(cJSON * const object, const char * const name, const cJSON_bool boolean) -{ +CJSON_PUBLIC(cJSON *) cJSON_AddBoolToObject(cJSON *const object, const char *const name, const cJSON_bool boolean) { cJSON *bool_item = cJSON_CreateBool(boolean); - if (add_item_to_object(object, name, bool_item, &global_hooks, false)) - { + if (add_item_to_object(object, name, bool_item, &global_hooks, false)) { return bool_item; } @@ -2118,11 +1828,9 @@ CJSON_PUBLIC(cJSON*) cJSON_AddBoolToObject(cJSON * const object, const char * co return NULL; } -CJSON_PUBLIC(cJSON*) cJSON_AddNumberToObject(cJSON * const object, const char * const name, const double number) -{ +CJSON_PUBLIC(cJSON *) cJSON_AddNumberToObject(cJSON *const object, const char *const name, const double number) { cJSON *number_item = cJSON_CreateNumber(number); - if (add_item_to_object(object, name, number_item, &global_hooks, false)) - { + if (add_item_to_object(object, name, number_item, &global_hooks, false)) { return number_item; } @@ -2130,11 +1838,9 @@ CJSON_PUBLIC(cJSON*) cJSON_AddNumberToObject(cJSON * const object, const char * return NULL; } -CJSON_PUBLIC(cJSON*) cJSON_AddStringToObject(cJSON * const object, const char * const name, const char * const string) -{ +CJSON_PUBLIC(cJSON *) cJSON_AddStringToObject(cJSON *const object, const char *const name, const char *const string) { cJSON *string_item = cJSON_CreateString(string); - if (add_item_to_object(object, name, string_item, &global_hooks, false)) - { + if (add_item_to_object(object, name, string_item, &global_hooks, false)) { return string_item; } @@ -2142,11 +1848,9 @@ CJSON_PUBLIC(cJSON*) cJSON_AddStringToObject(cJSON * const object, const char * return NULL; } -CJSON_PUBLIC(cJSON*) cJSON_AddRawToObject(cJSON * const object, const char * const name, const char * const raw) -{ +CJSON_PUBLIC(cJSON *) cJSON_AddRawToObject(cJSON *const object, const char *const name, const char *const raw) { cJSON *raw_item = cJSON_CreateRaw(raw); - if (add_item_to_object(object, name, raw_item, &global_hooks, false)) - { + if (add_item_to_object(object, name, raw_item, &global_hooks, false)) { return raw_item; } @@ -2154,11 +1858,9 @@ CJSON_PUBLIC(cJSON*) cJSON_AddRawToObject(cJSON * const object, const char * con return NULL; } -CJSON_PUBLIC(cJSON*) cJSON_AddObjectToObject(cJSON * const object, const char * const name) -{ +CJSON_PUBLIC(cJSON *) cJSON_AddObjectToObject(cJSON *const object, const char *const name) { cJSON *object_item = cJSON_CreateObject(); - if (add_item_to_object(object, name, object_item, &global_hooks, false)) - { + if (add_item_to_object(object, name, object_item, &global_hooks, false)) { return object_item; } @@ -2166,11 +1868,9 @@ CJSON_PUBLIC(cJSON*) cJSON_AddObjectToObject(cJSON * const object, const char * return NULL; } -CJSON_PUBLIC(cJSON*) cJSON_AddArrayToObject(cJSON * const object, const char * const name) -{ +CJSON_PUBLIC(cJSON *) cJSON_AddArrayToObject(cJSON *const object, const char *const name) { cJSON *array = cJSON_CreateArray(); - if (add_item_to_object(object, name, array, &global_hooks, false)) - { + if (add_item_to_object(object, name, array, &global_hooks, false)) { return array; } @@ -2178,31 +1878,24 @@ CJSON_PUBLIC(cJSON*) cJSON_AddArrayToObject(cJSON * const object, const char * c return NULL; } -CJSON_PUBLIC(cJSON *) cJSON_DetachItemViaPointer(cJSON *parent, cJSON * const item) -{ - if ((parent == NULL) || (item == NULL)) - { +CJSON_PUBLIC(cJSON *) cJSON_DetachItemViaPointer(cJSON *parent, cJSON *const item) { + if ((parent == NULL) || (item == NULL)) { return NULL; } - if (item != parent->child) - { + if (item != parent->child) { /* not the first element */ item->prev->next = item->next; } - if (item->next != NULL) - { + if (item->next != NULL) { /* not the last element */ item->next->prev = item->prev; } - if (item == parent->child) - { + if (item == parent->child) { /* first element */ parent->child = item->next; - } - else if (item->next == NULL) - { + } else if (item->next == NULL) { /* last element */ parent->child->prev = item->prev; } @@ -2214,113 +1907,90 @@ CJSON_PUBLIC(cJSON *) cJSON_DetachItemViaPointer(cJSON *parent, cJSON * const it return item; } -CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromArray(cJSON *array, int which) -{ - if (which < 0) - { +CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromArray(cJSON *array, int which) { + if (which < 0) { return NULL; } return cJSON_DetachItemViaPointer(array, get_array_item(array, (size_t)which)); } -CJSON_PUBLIC(void) cJSON_DeleteItemFromArray(cJSON *array, int which) -{ +CJSON_PUBLIC(void) cJSON_DeleteItemFromArray(cJSON *array, int which) { cJSON_Delete(cJSON_DetachItemFromArray(array, which)); } -CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromObject(cJSON *object, const char *string) -{ +CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromObject(cJSON *object, const char *string) { cJSON *to_detach = cJSON_GetObjectItem(object, string); return cJSON_DetachItemViaPointer(object, to_detach); } -CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromObjectCaseSensitive(cJSON *object, const char *string) -{ +CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromObjectCaseSensitive(cJSON *object, const char *string) { cJSON *to_detach = cJSON_GetObjectItemCaseSensitive(object, string); return cJSON_DetachItemViaPointer(object, to_detach); } -CJSON_PUBLIC(void) cJSON_DeleteItemFromObject(cJSON *object, const char *string) -{ +CJSON_PUBLIC(void) cJSON_DeleteItemFromObject(cJSON *object, const char *string) { cJSON_Delete(cJSON_DetachItemFromObject(object, string)); } -CJSON_PUBLIC(void) cJSON_DeleteItemFromObjectCaseSensitive(cJSON *object, const char *string) -{ +CJSON_PUBLIC(void) cJSON_DeleteItemFromObjectCaseSensitive(cJSON *object, const char *string) { cJSON_Delete(cJSON_DetachItemFromObjectCaseSensitive(object, string)); } /* Replace array/object items with new ones. */ -CJSON_PUBLIC(cJSON_bool) cJSON_InsertItemInArray(cJSON *array, int which, cJSON *newitem) -{ +CJSON_PUBLIC(cJSON_bool) cJSON_InsertItemInArray(cJSON *array, int which, cJSON *newitem) { cJSON *after_inserted = NULL; - if (which < 0) - { + if (which < 0) { return false; } after_inserted = get_array_item(array, (size_t)which); - if (after_inserted == NULL) - { + if (after_inserted == NULL) { return add_item_to_array(array, newitem); } - newitem->next = after_inserted; - newitem->prev = after_inserted->prev; + newitem->next = after_inserted; + newitem->prev = after_inserted->prev; after_inserted->prev = newitem; - if (after_inserted == array->child) - { + if (after_inserted == array->child) { array->child = newitem; - } - else - { + } else { newitem->prev->next = newitem; } return true; } -CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemViaPointer(cJSON * const parent, cJSON * const item, cJSON * replacement) -{ - if ((parent == NULL) || (replacement == NULL) || (item == NULL)) - { +CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemViaPointer(cJSON *const parent, cJSON *const item, cJSON *replacement) { + if ((parent == NULL) || (replacement == NULL) || (item == NULL)) { return false; } - if (replacement == item) - { + if (replacement == item) { return true; } replacement->next = item->next; replacement->prev = item->prev; - if (replacement->next != NULL) - { + if (replacement->next != NULL) { replacement->next->prev = replacement; } - if (parent->child == item) - { - if (parent->child->prev == parent->child) - { + if (parent->child == item) { + if (parent->child->prev == parent->child) { replacement->prev = replacement; } parent->child = replacement; - } - else - { /* + } else { /* * To find the last item in array quickly, we use prev in array. * We can't modify the last item's next pointer where this item was the parent's child */ - if (replacement->prev != NULL) - { + if (replacement->prev != NULL) { replacement->prev->next = replacement; } - if (replacement->next == NULL) - { + if (replacement->next == NULL) { parent->child->prev = replacement; } } @@ -2332,108 +2002,89 @@ CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemViaPointer(cJSON * const parent, cJSON return true; } -CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInArray(cJSON *array, int which, cJSON *newitem) -{ - if (which < 0) - { +CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInArray(cJSON *array, int which, cJSON *newitem) { + if (which < 0) { return false; } return cJSON_ReplaceItemViaPointer(array, get_array_item(array, (size_t)which), newitem); } -static cJSON_bool replace_item_in_object(cJSON *object, const char *string, cJSON *replacement, cJSON_bool case_sensitive) -{ - if ((replacement == NULL) || (string == NULL)) - { +static cJSON_bool replace_item_in_object(cJSON *object, + const char *string, + cJSON *replacement, + cJSON_bool case_sensitive) { + if ((replacement == NULL) || (string == NULL)) { return false; } /* replace the name in the replacement */ - if (!(replacement->type & cJSON_StringIsConst) && (replacement->string != NULL)) - { + if (!(replacement->type & cJSON_StringIsConst) && (replacement->string != NULL)) { cJSON_free(replacement->string); } - replacement->string = (char*)cJSON_strdup((const unsigned char*)string, &global_hooks); + replacement->string = (char *)cJSON_strdup((const unsigned char *)string, &global_hooks); replacement->type &= ~cJSON_StringIsConst; return cJSON_ReplaceItemViaPointer(object, get_object_item(object, string, case_sensitive), replacement); } -CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInObject(cJSON *object, const char *string, cJSON *newitem) -{ +CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInObject(cJSON *object, const char *string, cJSON *newitem) { return replace_item_in_object(object, string, newitem, false); } -CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInObjectCaseSensitive(cJSON *object, const char *string, cJSON *newitem) -{ +CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInObjectCaseSensitive(cJSON *object, const char *string, cJSON *newitem) { return replace_item_in_object(object, string, newitem, true); } /* Create basic types: */ -CJSON_PUBLIC(cJSON *) cJSON_CreateNull(void) -{ +CJSON_PUBLIC(cJSON *) cJSON_CreateNull(void) { cJSON *item = cJSON_New_Item(&global_hooks); - if(item) - { + if (item) { item->type = cJSON_NULL; } return item; } -CJSON_PUBLIC(cJSON *) cJSON_CreateTrue(void) -{ +CJSON_PUBLIC(cJSON *) cJSON_CreateTrue(void) { cJSON *item = cJSON_New_Item(&global_hooks); - if(item) - { + if (item) { item->type = cJSON_True; } return item; } -CJSON_PUBLIC(cJSON *) cJSON_CreateFalse(void) -{ +CJSON_PUBLIC(cJSON *) cJSON_CreateFalse(void) { cJSON *item = cJSON_New_Item(&global_hooks); - if(item) - { + if (item) { item->type = cJSON_False; } return item; } -CJSON_PUBLIC(cJSON *) cJSON_CreateBool(cJSON_bool boolean) -{ +CJSON_PUBLIC(cJSON *) cJSON_CreateBool(cJSON_bool boolean) { cJSON *item = cJSON_New_Item(&global_hooks); - if(item) - { + if (item) { item->type = boolean ? cJSON_True : cJSON_False; } return item; } -CJSON_PUBLIC(cJSON *) cJSON_CreateNumber(double num) -{ +CJSON_PUBLIC(cJSON *) cJSON_CreateNumber(double num) { cJSON *item = cJSON_New_Item(&global_hooks); - if(item) - { - item->type = cJSON_Number; + if (item) { + item->type = cJSON_Number; item->valuedouble = num; /* use saturation in case of overflow */ - if (num >= INT_MAX) - { + if (num >= INT_MAX) { item->valueint = INT_MAX; - } - else if (num <= (double)INT_MIN) - { + } else if (num <= (double)INT_MIN) { item->valueint = INT_MIN; - } - else - { + } else { item->valueint = (int)num; } } @@ -2441,15 +2092,12 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateNumber(double num) return item; } -CJSON_PUBLIC(cJSON *) cJSON_CreateString(const char *string) -{ +CJSON_PUBLIC(cJSON *) cJSON_CreateString(const char *string) { cJSON *item = cJSON_New_Item(&global_hooks); - if(item) - { - item->type = cJSON_String; - item->valuestring = (char*)cJSON_strdup((const unsigned char*)string, &global_hooks); - if(!item->valuestring) - { + if (item) { + item->type = cJSON_String; + item->valuestring = (char *)cJSON_strdup((const unsigned char *)string, &global_hooks); + if (!item->valuestring) { cJSON_Delete(item); return NULL; } @@ -2458,24 +2106,21 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateString(const char *string) return item; } -CJSON_PUBLIC(cJSON *) cJSON_CreateStringReference(const char *string) -{ +CJSON_PUBLIC(cJSON *) cJSON_CreateStringReference(const char *string) { cJSON *item = cJSON_New_Item(&global_hooks); - if (item != NULL) - { - item->type = cJSON_String | cJSON_IsReference; - item->valuestring = (char*)cast_away_const(string); + if (item != NULL) { + item->type = cJSON_String | cJSON_IsReference; + item->valuestring = (char *)cast_away_const(string); } return item; } -CJSON_PUBLIC(cJSON *) cJSON_CreateObjectReference(const cJSON *child) -{ +CJSON_PUBLIC(cJSON *) cJSON_CreateObjectReference(const cJSON *child) { cJSON *item = cJSON_New_Item(&global_hooks); if (item != NULL) { - item->type = cJSON_Object | cJSON_IsReference; - item->child = (cJSON*)cast_away_const(child); + item->type = cJSON_Object | cJSON_IsReference; + item->child = (cJSON *)cast_away_const(child); } return item; @@ -2484,22 +2129,19 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateObjectReference(const cJSON *child) CJSON_PUBLIC(cJSON *) cJSON_CreateArrayReference(const cJSON *child) { cJSON *item = cJSON_New_Item(&global_hooks); if (item != NULL) { - item->type = cJSON_Array | cJSON_IsReference; - item->child = (cJSON*)cast_away_const(child); + item->type = cJSON_Array | cJSON_IsReference; + item->child = (cJSON *)cast_away_const(child); } return item; } -CJSON_PUBLIC(cJSON *) cJSON_CreateRaw(const char *raw) -{ +CJSON_PUBLIC(cJSON *) cJSON_CreateRaw(const char *raw) { cJSON *item = cJSON_New_Item(&global_hooks); - if(item) - { - item->type = cJSON_Raw; - item->valuestring = (char*)cJSON_strdup((const unsigned char*)raw, &global_hooks); - if(!item->valuestring) - { + if (item) { + item->type = cJSON_Raw; + item->valuestring = (char *)cJSON_strdup((const unsigned char *)raw, &global_hooks); + if (!item->valuestring) { cJSON_Delete(item); return NULL; } @@ -2508,22 +2150,18 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateRaw(const char *raw) return item; } -CJSON_PUBLIC(cJSON *) cJSON_CreateArray(void) -{ +CJSON_PUBLIC(cJSON *) cJSON_CreateArray(void) { cJSON *item = cJSON_New_Item(&global_hooks); - if(item) - { - item->type=cJSON_Array; + if (item) { + item->type = cJSON_Array; } return item; } -CJSON_PUBLIC(cJSON *) cJSON_CreateObject(void) -{ +CJSON_PUBLIC(cJSON *) cJSON_CreateObject(void) { cJSON *item = cJSON_New_Item(&global_hooks); - if (item) - { + if (item) { item->type = cJSON_Object; } @@ -2531,33 +2169,26 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateObject(void) } /* Create Arrays: */ -CJSON_PUBLIC(cJSON *) cJSON_CreateIntArray(const int *numbers, int count) -{ +CJSON_PUBLIC(cJSON *) cJSON_CreateIntArray(const int *numbers, int count) { size_t i = 0; cJSON *n = NULL; cJSON *p = NULL; cJSON *a = NULL; - if ((count < 0) || (numbers == NULL)) - { + if ((count < 0) || (numbers == NULL)) { return NULL; } a = cJSON_CreateArray(); - for(i = 0; a && (i < (size_t)count); i++) - { + for (i = 0; a && (i < (size_t)count); i++) { n = cJSON_CreateNumber(numbers[i]); - if (!n) - { + if (!n) { cJSON_Delete(a); return NULL; } - if(!i) - { + if (!i) { a->child = n; - } - else - { + } else { suffix_object(p, n); } p = n; @@ -2567,34 +2198,27 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateIntArray(const int *numbers, int count) return a; } -CJSON_PUBLIC(cJSON *) cJSON_CreateFloatArray(const float *numbers, int count) -{ +CJSON_PUBLIC(cJSON *) cJSON_CreateFloatArray(const float *numbers, int count) { size_t i = 0; cJSON *n = NULL; cJSON *p = NULL; cJSON *a = NULL; - if ((count < 0) || (numbers == NULL)) - { + if ((count < 0) || (numbers == NULL)) { return NULL; } a = cJSON_CreateArray(); - for(i = 0; a && (i < (size_t)count); i++) - { + for (i = 0; a && (i < (size_t)count); i++) { n = cJSON_CreateNumber((double)numbers[i]); - if(!n) - { + if (!n) { cJSON_Delete(a); return NULL; } - if(!i) - { + if (!i) { a->child = n; - } - else - { + } else { suffix_object(p, n); } p = n; @@ -2604,34 +2228,27 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateFloatArray(const float *numbers, int count) return a; } -CJSON_PUBLIC(cJSON *) cJSON_CreateDoubleArray(const double *numbers, int count) -{ +CJSON_PUBLIC(cJSON *) cJSON_CreateDoubleArray(const double *numbers, int count) { size_t i = 0; cJSON *n = NULL; cJSON *p = NULL; cJSON *a = NULL; - if ((count < 0) || (numbers == NULL)) - { + if ((count < 0) || (numbers == NULL)) { return NULL; } a = cJSON_CreateArray(); - for(i = 0;a && (i < (size_t)count); i++) - { + for (i = 0; a && (i < (size_t)count); i++) { n = cJSON_CreateNumber(numbers[i]); - if(!n) - { + if (!n) { cJSON_Delete(a); return NULL; } - if(!i) - { + if (!i) { a->child = n; - } - else - { + } else { suffix_object(p, n); } p = n; @@ -2641,35 +2258,28 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateDoubleArray(const double *numbers, int count) return a; } -CJSON_PUBLIC(cJSON *) cJSON_CreateStringArray(const char *const *strings, int count) -{ +CJSON_PUBLIC(cJSON *) cJSON_CreateStringArray(const char *const *strings, int count) { size_t i = 0; cJSON *n = NULL; cJSON *p = NULL; cJSON *a = NULL; - if ((count < 0) || (strings == NULL)) - { + if ((count < 0) || (strings == NULL)) { return NULL; } a = cJSON_CreateArray(); - for (i = 0; a && (i < (size_t)count); i++) - { + for (i = 0; a && (i < (size_t)count); i++) { n = cJSON_CreateString(strings[i]); - if(!n) - { + if (!n) { cJSON_Delete(a); return NULL; } - if(!i) - { + if (!i) { a->child = n; - } - else - { - suffix_object(p,n); + } else { + suffix_object(p, n); } p = n; } @@ -2679,95 +2289,80 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateStringArray(const char *const *strings, int co } /* Duplication */ -CJSON_PUBLIC(cJSON *) cJSON_Duplicate(const cJSON *item, cJSON_bool recurse) -{ - cJSON *newitem = NULL; - cJSON *child = NULL; - cJSON *next = NULL; +CJSON_PUBLIC(cJSON *) cJSON_Duplicate(const cJSON *item, cJSON_bool recurse) { + cJSON *newitem = NULL; + cJSON *child = NULL; + cJSON *next = NULL; cJSON *newchild = NULL; /* Bail on bad ptr */ - if (!item) - { + if (!item) { goto fail; } /* Create new item */ newitem = cJSON_New_Item(&global_hooks); - if (!newitem) - { + if (!newitem) { goto fail; } /* Copy over all vars */ - newitem->type = item->type & (~cJSON_IsReference); - newitem->valueint = item->valueint; + newitem->type = item->type & (~cJSON_IsReference); + newitem->valueint = item->valueint; newitem->valuedouble = item->valuedouble; - if (item->valuestring) - { - newitem->valuestring = (char*)cJSON_strdup((unsigned char*)item->valuestring, &global_hooks); - if (!newitem->valuestring) - { + if (item->valuestring) { + newitem->valuestring = (char *)cJSON_strdup((unsigned char *)item->valuestring, &global_hooks); + if (!newitem->valuestring) { goto fail; } } - if (item->string) - { - newitem->string = (item->type&cJSON_StringIsConst) ? item->string : (char*)cJSON_strdup((unsigned char*)item->string, &global_hooks); - if (!newitem->string) - { + if (item->string) { + newitem->string = (item->type & cJSON_StringIsConst) + ? item->string + : (char *)cJSON_strdup((unsigned char *)item->string, &global_hooks); + if (!newitem->string) { goto fail; } } /* If non-recursive, then we're done! */ - if (!recurse) - { + if (!recurse) { return newitem; } /* Walk the ->next chain for the child. */ child = item->child; - while (child != NULL) - { + while (child != NULL) { newchild = cJSON_Duplicate(child, true); /* Duplicate (with recurse) each item in the ->next chain */ - if (!newchild) - { + if (!newchild) { goto fail; } - if (next != NULL) - { + if (next != NULL) { /* If newitem->child already set, then crosswire ->prev and ->next and move on */ - next->next = newchild; + next->next = newchild; newchild->prev = next; - next = newchild; - } - else - { + next = newchild; + } else { /* Set newitem->child and move to it */ newitem->child = newchild; - next = newchild; + next = newchild; } child = child->next; } - if (newitem && newitem->child) - { + if (newitem && newitem->child) { newitem->child->prev = newchild; } return newitem; fail: - if (newitem != NULL) - { + if (newitem != NULL) { cJSON_Delete(newitem); } return NULL; } -static void skip_oneline_comment(char **input) -{ +static void skip_oneline_comment(char **input) { *input += static_strlen("//"); - for (; (*input)[0] != '\0'; ++(*input)) - { + for (; (*input)[0] != '\0'; ++(*input)) { if ((*input)[0] == '\n') { *input += static_strlen("\n"); return; @@ -2775,14 +2370,11 @@ static void skip_oneline_comment(char **input) } } -static void skip_multiline_comment(char **input) -{ +static void skip_multiline_comment(char **input) { *input += static_strlen("/*"); - for (; (*input)[0] != '\0'; ++(*input)) - { - if (((*input)[0] == '*') && ((*input)[1] == '/')) - { + for (; (*input)[0] != '\0'; ++(*input)) { + if (((*input)[0] == '*') && ((*input)[1] == '/')) { *input += static_strlen("*/"); return; } @@ -2794,7 +2386,6 @@ static void minify_string(char **input, char **output) { *input += static_strlen("\""); *output += static_strlen("\""); - for (; (*input)[0] != '\0'; (void)++(*input), ++(*output)) { (*output)[0] = (*input)[0]; @@ -2811,19 +2402,15 @@ static void minify_string(char **input, char **output) { } } -CJSON_PUBLIC(void) cJSON_Minify(char *json) -{ +CJSON_PUBLIC(void) cJSON_Minify(char *json) { char *into = json; - if (json == NULL) - { + if (json == NULL) { return; } - while (json[0] != '\0') - { - switch (json[0]) - { + while (json[0] != '\0') { + switch (json[0]) { case ' ': case '\t': case '\r': @@ -2832,12 +2419,9 @@ CJSON_PUBLIC(void) cJSON_Minify(char *json) break; case '/': - if (json[1] == '/') - { + if (json[1] == '/') { skip_oneline_comment(&json); - } - else if (json[1] == '*') - { + } else if (json[1] == '*') { skip_multiline_comment(&json); } else { json++; @@ -2845,7 +2429,7 @@ CJSON_PUBLIC(void) cJSON_Minify(char *json) break; case '\"': - minify_string(&json, (char**)&into); + minify_string(&json, (char **)&into); break; default: @@ -2859,116 +2443,92 @@ CJSON_PUBLIC(void) cJSON_Minify(char *json) *into = '\0'; } -CJSON_PUBLIC(cJSON_bool) cJSON_IsInvalid(const cJSON * const item) -{ - if (item == NULL) - { +CJSON_PUBLIC(cJSON_bool) cJSON_IsInvalid(const cJSON *const item) { + if (item == NULL) { return false; } return (item->type & 0xFF) == cJSON_Invalid; } -CJSON_PUBLIC(cJSON_bool) cJSON_IsFalse(const cJSON * const item) -{ - if (item == NULL) - { +CJSON_PUBLIC(cJSON_bool) cJSON_IsFalse(const cJSON *const item) { + if (item == NULL) { return false; } return (item->type & 0xFF) == cJSON_False; } -CJSON_PUBLIC(cJSON_bool) cJSON_IsTrue(const cJSON * const item) -{ - if (item == NULL) - { +CJSON_PUBLIC(cJSON_bool) cJSON_IsTrue(const cJSON *const item) { + if (item == NULL) { return false; } return (item->type & 0xff) == cJSON_True; } - -CJSON_PUBLIC(cJSON_bool) cJSON_IsBool(const cJSON * const item) -{ - if (item == NULL) - { +CJSON_PUBLIC(cJSON_bool) cJSON_IsBool(const cJSON *const item) { + if (item == NULL) { return false; } return (item->type & (cJSON_True | cJSON_False)) != 0; } -CJSON_PUBLIC(cJSON_bool) cJSON_IsNull(const cJSON * const item) -{ - if (item == NULL) - { +CJSON_PUBLIC(cJSON_bool) cJSON_IsNull(const cJSON *const item) { + if (item == NULL) { return false; } return (item->type & 0xFF) == cJSON_NULL; } -CJSON_PUBLIC(cJSON_bool) cJSON_IsNumber(const cJSON * const item) -{ - if (item == NULL) - { +CJSON_PUBLIC(cJSON_bool) cJSON_IsNumber(const cJSON *const item) { + if (item == NULL) { return false; } return (item->type & 0xFF) == cJSON_Number; } -CJSON_PUBLIC(cJSON_bool) cJSON_IsString(const cJSON * const item) -{ - if (item == NULL) - { +CJSON_PUBLIC(cJSON_bool) cJSON_IsString(const cJSON *const item) { + if (item == NULL) { return false; } return (item->type & 0xFF) == cJSON_String; } -CJSON_PUBLIC(cJSON_bool) cJSON_IsArray(const cJSON * const item) -{ - if (item == NULL) - { +CJSON_PUBLIC(cJSON_bool) cJSON_IsArray(const cJSON *const item) { + if (item == NULL) { return false; } return (item->type & 0xFF) == cJSON_Array; } -CJSON_PUBLIC(cJSON_bool) cJSON_IsObject(const cJSON * const item) -{ - if (item == NULL) - { +CJSON_PUBLIC(cJSON_bool) cJSON_IsObject(const cJSON *const item) { + if (item == NULL) { return false; } return (item->type & 0xFF) == cJSON_Object; } -CJSON_PUBLIC(cJSON_bool) cJSON_IsRaw(const cJSON * const item) -{ - if (item == NULL) - { +CJSON_PUBLIC(cJSON_bool) cJSON_IsRaw(const cJSON *const item) { + if (item == NULL) { return false; } return (item->type & 0xFF) == cJSON_Raw; } -CJSON_PUBLIC(cJSON_bool) cJSON_Compare(const cJSON * const a, const cJSON * const b, const cJSON_bool case_sensitive) -{ - if ((a == NULL) || (b == NULL) || ((a->type & 0xFF) != (b->type & 0xFF)) || cJSON_IsInvalid(a)) - { +CJSON_PUBLIC(cJSON_bool) cJSON_Compare(const cJSON *const a, const cJSON *const b, const cJSON_bool case_sensitive) { + if ((a == NULL) || (b == NULL) || ((a->type & 0xFF) != (b->type & 0xFF)) || cJSON_IsInvalid(a)) { return false; } /* check if type is valid */ - switch (a->type & 0xFF) - { + switch (a->type & 0xFF) { case cJSON_False: case cJSON_True: case cJSON_NULL: @@ -2984,13 +2544,11 @@ CJSON_PUBLIC(cJSON_bool) cJSON_Compare(const cJSON * const a, const cJSON * cons } /* identical objects are equal */ - if (a == b) - { + if (a == b) { return true; } - switch (a->type & 0xFF) - { + switch (a->type & 0xFF) { /* in these cases and equal type is enough */ case cJSON_False: case cJSON_True: @@ -2998,34 +2556,28 @@ CJSON_PUBLIC(cJSON_bool) cJSON_Compare(const cJSON * const a, const cJSON * cons return true; case cJSON_Number: - if (compare_double(a->valuedouble, b->valuedouble)) - { + if (compare_double(a->valuedouble, b->valuedouble)) { return true; } return false; case cJSON_String: case cJSON_Raw: - if ((a->valuestring == NULL) || (b->valuestring == NULL)) - { + if ((a->valuestring == NULL) || (b->valuestring == NULL)) { return false; } - if (strcmp(a->valuestring, b->valuestring) == 0) - { + if (strcmp(a->valuestring, b->valuestring) == 0) { return true; } return false; - case cJSON_Array: - { + case cJSON_Array: { cJSON *a_element = a->child; cJSON *b_element = b->child; - for (; (a_element != NULL) && (b_element != NULL);) - { - if (!cJSON_Compare(a_element, b_element, case_sensitive)) - { + for (; (a_element != NULL) && (b_element != NULL);) { + if (!cJSON_Compare(a_element, b_element, case_sensitive)) { return false; } @@ -3041,37 +2593,30 @@ CJSON_PUBLIC(cJSON_bool) cJSON_Compare(const cJSON * const a, const cJSON * cons return true; } - case cJSON_Object: - { + case cJSON_Object: { cJSON *a_element = NULL; cJSON *b_element = NULL; - cJSON_ArrayForEach(a_element, a) - { + cJSON_ArrayForEach(a_element, a) { /* TODO This has O(n^2) runtime, which is horrible! */ b_element = get_object_item(b, a_element->string, case_sensitive); - if (b_element == NULL) - { + if (b_element == NULL) { return false; } - if (!cJSON_Compare(a_element, b_element, case_sensitive)) - { + if (!cJSON_Compare(a_element, b_element, case_sensitive)) { return false; } } /* doing this twice, once on a and b to prevent true comparison if a subset of b * TODO: Do this the proper way, this is just a fix for now */ - cJSON_ArrayForEach(b_element, b) - { + cJSON_ArrayForEach(b_element, b) { a_element = get_object_item(a, b_element->string, case_sensitive); - if (a_element == NULL) - { + if (a_element == NULL) { return false; } - if (!cJSON_Compare(b_element, a_element, case_sensitive)) - { + if (!cJSON_Compare(b_element, a_element, case_sensitive)) { return false; } } @@ -3084,12 +2629,10 @@ CJSON_PUBLIC(cJSON_bool) cJSON_Compare(const cJSON * const a, const cJSON * cons } } -CJSON_PUBLIC(void *) cJSON_malloc(size_t size) -{ +CJSON_PUBLIC(void *) cJSON_malloc(size_t size) { return global_hooks.allocate(size); } -CJSON_PUBLIC(void) cJSON_free(void *object) -{ +CJSON_PUBLIC(void) cJSON_free(void *object) { global_hooks.deallocate(object); } diff --git a/srcs/libs/misc/misc.c b/srcs/libs/misc/misc.c index bf2ee09..56fb0c8 100644 --- a/srcs/libs/misc/misc.c +++ b/srcs/libs/misc/misc.c @@ -183,7 +183,10 @@ int str_to_ipaddr(const char *pIp, unsigned int *ipAddr) { return ret; } -int get_nic_info(const char *pName, unsigned int *pIp, unsigned int *pNetmask, unsigned int *pGateway, +int get_nic_info(const char *pName, + unsigned int *pIp, + unsigned int *pNetmask, + unsigned int *pGateway, unsigned char *pMac) { int sock; struct ifreq ifr; @@ -234,7 +237,7 @@ int get_nic_info(const char *pName, unsigned int *pIp, unsigned int *pNetmask, u return err; } -const char*get_cur_process_name() { +const char *get_cur_process_name() { static char g_exeName[1024]; memset(g_exeName, 0, 1024); diff --git a/srcs/libs/misc/sds.c b/srcs/libs/misc/sds.c index fe5c04a..d3d9ace 100644 --- a/srcs/libs/misc/sds.c +++ b/srcs/libs/misc/sds.c @@ -40,11 +40,11 @@ #include hiredisAllocFuncs hiredisAllocFns = { - .mallocFn = malloc, - .callocFn = calloc, + .mallocFn = malloc, + .callocFn = calloc, .reallocFn = realloc, - .strdupFn = strdup, - .freeFn = free, + .strdupFn = strdup, + .freeFn = free, }; /* Override hiredis' allocators with ones supplied by the user */ @@ -59,16 +59,16 @@ hiredisAllocFuncs hiredisSetAllocators(hiredisAllocFuncs *override) { /* Reset allocators to use libc defaults */ void hiredisResetAllocators(void) { hiredisAllocFns = (hiredisAllocFuncs) { - .mallocFn = malloc, - .callocFn = calloc, + .mallocFn = malloc, + .callocFn = calloc, .reallocFn = realloc, - .strdupFn = strdup, - .freeFn = free, + .strdupFn = strdup, + .freeFn = free, }; } static inline int sdsHdrSize(char type) { - switch(type&SDS_TYPE_MASK) { + switch (type & SDS_TYPE_MASK) { case SDS_TYPE_5: return sizeof(struct sdshdr5); case SDS_TYPE_8: @@ -84,14 +84,18 @@ static inline int sdsHdrSize(char type) { } static inline char sdsReqType(size_t string_size) { - if (string_size < 32) + if (string_size < 32) { return SDS_TYPE_5; - if (string_size < 0xff) + } + if (string_size < 0xff) { return SDS_TYPE_8; - if (string_size < 0xffff) + } + if (string_size < 0xffff) { return SDS_TYPE_16; - if (string_size < 0xffffffff) + } + if (string_size < 0xffffffff) { return SDS_TYPE_32; + } return SDS_TYPE_64; } @@ -109,56 +113,62 @@ static inline char sdsReqType(size_t string_size) { * \0 characters in the middle, as the length is stored in the sds header. */ sds sdsnewlen(const void *init, size_t initlen) { void *sh; - sds s; - char type = sdsReqType(initlen); + sds s; + char type = sdsReqType(initlen); /* Empty strings are usually created in order to append. Use type 8 * since type 5 is not good at this. */ - if (type == SDS_TYPE_5 && initlen == 0) type = SDS_TYPE_8; - int hdrlen = sdsHdrSize(type); + if (type == SDS_TYPE_5 && initlen == 0) { + type = SDS_TYPE_8; + } + int hdrlen = sdsHdrSize(type); unsigned char *fp; /* flags pointer. */ - sh = s_malloc(hdrlen+initlen+1); - if (sh == NULL) return NULL; - if (!init) - memset(sh, 0, hdrlen+initlen+1); - s = (char*)sh+hdrlen; - fp = ((unsigned char*)s)-1; - switch(type) { + sh = s_malloc(hdrlen + initlen + 1); + if (sh == NULL) { + return NULL; + } + if (!init) { + memset(sh, 0, hdrlen + initlen + 1); + } + s = (char *)sh + hdrlen; + fp = ((unsigned char *)s) - 1; + switch (type) { case SDS_TYPE_5: { *fp = type | (initlen << SDS_TYPE_BITS); break; } case SDS_TYPE_8: { - SDS_HDR_VAR(8,s); - sh->len = initlen; + SDS_HDR_VAR(8, s); + sh->len = initlen; sh->alloc = initlen; - *fp = type; + *fp = type; break; } case SDS_TYPE_16: { - SDS_HDR_VAR(16,s); - sh->len = initlen; + SDS_HDR_VAR(16, s); + sh->len = initlen; sh->alloc = initlen; - *fp = type; + *fp = type; break; } case SDS_TYPE_32: { - SDS_HDR_VAR(32,s); - sh->len = initlen; + SDS_HDR_VAR(32, s); + sh->len = initlen; sh->alloc = initlen; - *fp = type; + *fp = type; break; } case SDS_TYPE_64: { - SDS_HDR_VAR(64,s); - sh->len = initlen; + SDS_HDR_VAR(64, s); + sh->len = initlen; sh->alloc = initlen; - *fp = type; + *fp = type; break; } } - if (initlen && init) + if (initlen && init) { memcpy(s, init, initlen); + } s[initlen] = '\0'; return s; } @@ -166,7 +176,7 @@ sds sdsnewlen(const void *init, size_t initlen) { /* Create an empty (zero length) sds string. Even in this case the string * always has an implicit null term. */ sds sdsempty(void) { - return sdsnewlen("",0); + return sdsnewlen("", 0); } /* Create a new sds string starting from a null terminated C string. */ @@ -182,8 +192,10 @@ sds sdsdup(const sds s) { /* Free an sds string. No operation is performed if 's' is NULL. */ void sdsfree(sds s) { - if (s == NULL) return; - s_free((char*)s-sdsHdrSize(s[-1])); + if (s == NULL) { + return; + } + s_free((char *)s - sdsHdrSize(s[-1])); } /* Set the sds string length to the length as obtained with strlen(), so @@ -221,43 +233,52 @@ void sdsclear(sds s) { * Note: this does not change the *length* of the sds string as returned * by sdslen(), but only the free buffer space we have. */ sds sdsMakeRoomFor(sds s, size_t addlen) { - void *sh, *newsh; + void *sh, *newsh; size_t avail = sdsavail(s); size_t len, newlen; - char type, oldtype = s[-1] & SDS_TYPE_MASK; - int hdrlen; + char type, oldtype = s[-1] & SDS_TYPE_MASK; + int hdrlen; /* Return ASAP if there is enough space left. */ - if (avail >= addlen) return s; + if (avail >= addlen) { + return s; + } - len = sdslen(s); - sh = (char*)s-sdsHdrSize(oldtype); - newlen = (len+addlen); - if (newlen < SDS_MAX_PREALLOC) + len = sdslen(s); + sh = (char *)s - sdsHdrSize(oldtype); + newlen = (len + addlen); + if (newlen < SDS_MAX_PREALLOC) { newlen *= 2; - else + } else { newlen += SDS_MAX_PREALLOC; + } type = sdsReqType(newlen); /* Don't use type 5: the user is appending to the string and type 5 is * not able to remember empty space, so sdsMakeRoomFor() must be called * at every appending operation. */ - if (type == SDS_TYPE_5) type = SDS_TYPE_8; + if (type == SDS_TYPE_5) { + type = SDS_TYPE_8; + } hdrlen = sdsHdrSize(type); - if (oldtype==type) { - newsh = s_realloc(sh, hdrlen+newlen+1); - if (newsh == NULL) return NULL; - s = (char*)newsh+hdrlen; + if (oldtype == type) { + newsh = s_realloc(sh, hdrlen + newlen + 1); + if (newsh == NULL) { + return NULL; + } + s = (char *)newsh + hdrlen; } else { /* Since the header size changes, need to move the string forward, * and can't use realloc */ - newsh = s_malloc(hdrlen+newlen+1); - if (newsh == NULL) return NULL; - memcpy((char*)newsh+hdrlen, s, len+1); + newsh = s_malloc(hdrlen + newlen + 1); + if (newsh == NULL) { + return NULL; + } + memcpy((char *)newsh + hdrlen, s, len + 1); s_free(sh); - s = (char*)newsh+hdrlen; + s = (char *)newsh + hdrlen; s[-1] = type; sdssetlen(s, len); } @@ -272,24 +293,28 @@ sds sdsMakeRoomFor(sds s, size_t addlen) { * After the call, the passed sds string is no longer valid and all the * references must be substituted with the new pointer returned by the call. */ sds sdsRemoveFreeSpace(sds s) { - void *sh, *newsh; - char type, oldtype = s[-1] & SDS_TYPE_MASK; - int hdrlen; + void *sh, *newsh; + char type, oldtype = s[-1] & SDS_TYPE_MASK; + int hdrlen; size_t len = sdslen(s); - sh = (char*)s-sdsHdrSize(oldtype); + sh = (char *)s - sdsHdrSize(oldtype); - type = sdsReqType(len); + type = sdsReqType(len); hdrlen = sdsHdrSize(type); - if (oldtype==type) { - newsh = s_realloc(sh, hdrlen+len+1); - if (newsh == NULL) return NULL; - s = (char*)newsh+hdrlen; + if (oldtype == type) { + newsh = s_realloc(sh, hdrlen + len + 1); + if (newsh == NULL) { + return NULL; + } + s = (char *)newsh + hdrlen; } else { - newsh = s_malloc(hdrlen+len+1); - if (newsh == NULL) return NULL; - memcpy((char*)newsh+hdrlen, s, len+1); + newsh = s_malloc(hdrlen + len + 1); + if (newsh == NULL) { + return NULL; + } + memcpy((char *)newsh + hdrlen, s, len + 1); s_free(sh); - s = (char*)newsh+hdrlen; + s = (char *)newsh + hdrlen; s[-1] = type; sdssetlen(s, len); } @@ -306,13 +331,13 @@ sds sdsRemoveFreeSpace(sds s) { */ size_t sdsAllocSize(sds s) { size_t alloc = sdsalloc(s); - return sdsHdrSize(s[-1])+alloc+1; + return sdsHdrSize(s[-1]) + alloc + 1; } /* Return the pointer of the actual SDS allocation (normally SDS strings * are referenced by the start of the string buffer). */ void *sdsAllocPtr(sds s) { - return (void*) (s-sdsHdrSize(s[-1])); + return (void *)(s - sdsHdrSize(s[-1])); } /* Increment the sds length and decrements the left free space at the @@ -340,41 +365,43 @@ void *sdsAllocPtr(sds s) { */ void sdsIncrLen(sds s, int incr) { unsigned char flags = s[-1]; - size_t len; - switch(flags&SDS_TYPE_MASK) { + size_t len; + switch (flags & SDS_TYPE_MASK) { case SDS_TYPE_5: { - unsigned char *fp = ((unsigned char*)s)-1; - unsigned char oldlen = SDS_TYPE_5_LEN(flags); - assert((incr > 0 && oldlen+incr < 32) || (incr < 0 && oldlen >= (unsigned int)(-incr))); - *fp = SDS_TYPE_5 | ((oldlen+incr) << SDS_TYPE_BITS); - len = oldlen+incr; + unsigned char *fp = ((unsigned char *)s) - 1; + unsigned char oldlen = SDS_TYPE_5_LEN(flags); + assert((incr > 0 && oldlen + incr < 32) || (incr < 0 && oldlen >= (unsigned int)(-incr))); + *fp = SDS_TYPE_5 | ((oldlen + incr) << SDS_TYPE_BITS); + len = oldlen + incr; break; } case SDS_TYPE_8: { - SDS_HDR_VAR(8,s); - assert((incr >= 0 && sh->alloc-sh->len >= incr) || (incr < 0 && sh->len >= (unsigned int)(-incr))); + SDS_HDR_VAR(8, s); + assert((incr >= 0 && sh->alloc - sh->len >= incr) || (incr < 0 && sh->len >= (unsigned int)(-incr))); len = (sh->len += incr); break; } case SDS_TYPE_16: { - SDS_HDR_VAR(16,s); - assert((incr >= 0 && sh->alloc-sh->len >= incr) || (incr < 0 && sh->len >= (unsigned int)(-incr))); + SDS_HDR_VAR(16, s); + assert((incr >= 0 && sh->alloc - sh->len >= incr) || (incr < 0 && sh->len >= (unsigned int)(-incr))); len = (sh->len += incr); break; } case SDS_TYPE_32: { - SDS_HDR_VAR(32,s); - assert((incr >= 0 && sh->alloc-sh->len >= (unsigned int)incr) || (incr < 0 && sh->len >= (unsigned int)(-incr))); + SDS_HDR_VAR(32, s); + assert((incr >= 0 && sh->alloc - sh->len >= (unsigned int)incr) + || (incr < 0 && sh->len >= (unsigned int)(-incr))); len = (sh->len += incr); break; } case SDS_TYPE_64: { - SDS_HDR_VAR(64,s); - assert((incr >= 0 && sh->alloc-sh->len >= (uint64_t)incr) || (incr < 0 && sh->len >= (uint64_t)(-incr))); + SDS_HDR_VAR(64, s); + assert((incr >= 0 && sh->alloc - sh->len >= (uint64_t)incr) || (incr < 0 && sh->len >= (uint64_t)(-incr))); len = (sh->len += incr); break; } - default: len = 0; /* Just to avoid compilation warnings. */ + default: + len = 0; /* Just to avoid compilation warnings. */ } s[len] = '\0'; } @@ -387,12 +414,16 @@ void sdsIncrLen(sds s, int incr) { sds sdsgrowzero(sds s, size_t len) { size_t curlen = sdslen(s); - if (len <= curlen) return s; - s = sdsMakeRoomFor(s,len-curlen); - if (s == NULL) return NULL; + if (len <= curlen) { + return s; + } + s = sdsMakeRoomFor(s, len - curlen); + if (s == NULL) { + return NULL; + } /* Make sure added region doesn't contain garbage */ - memset(s+curlen,0,(len-curlen+1)); /* also set trailing \0 byte */ + memset(s + curlen, 0, (len - curlen + 1)); /* also set trailing \0 byte */ sdssetlen(s, len); return s; } @@ -405,11 +436,13 @@ sds sdsgrowzero(sds s, size_t len) { sds sdscatlen(sds s, const void *t, size_t len) { size_t curlen = sdslen(s); - s = sdsMakeRoomFor(s,len); - if (s == NULL) return NULL; - memcpy(s+curlen, t, len); - sdssetlen(s, curlen+len); - s[curlen+len] = '\0'; + s = sdsMakeRoomFor(s, len); + if (s == NULL) { + return NULL; + } + memcpy(s + curlen, t, len); + sdssetlen(s, curlen + len); + s[curlen + len] = '\0'; return s; } @@ -433,8 +466,10 @@ sds sdscatsds(sds s, const sds t) { * safe string pointed by 't' of length 'len' bytes. */ sds sdscpylen(sds s, const char *t, size_t len) { if (sdsalloc(s) < len) { - s = sdsMakeRoomFor(s,len-sdslen(s)); - if (s == NULL) return NULL; + s = sdsMakeRoomFor(s, len - sdslen(s)); + if (s == NULL) { + return NULL; + } } memcpy(s, t, len); s[len] = '\0'; @@ -456,30 +491,32 @@ sds sdscpy(sds s, const char *t) { * representation stored at 's'. */ #define SDS_LLSTR_SIZE 21 int sdsll2str(char *s, long long value) { - char *p, aux; + char *p, aux; unsigned long long v; - size_t l; + size_t l; /* Generate the string representation, this method produces * an reversed string. */ v = (value < 0) ? -value : value; p = s; do { - *p++ = '0'+(v%10); + *p++ = '0' + (v % 10); v /= 10; - } while(v); - if (value < 0) *p++ = '-'; + } while (v); + if (value < 0) { + *p++ = '-'; + } /* Compute length and add null term. */ - l = p-s; + l = p - s; *p = '\0'; /* Reverse the string. */ p--; - while(s < p) { + while (s < p) { aux = *s; - *s = *p; - *p = aux; + *s = *p; + *p = aux; s++; p--; } @@ -488,27 +525,27 @@ int sdsll2str(char *s, long long value) { /* Identical sdsll2str(), but for unsigned long long type. */ int sdsull2str(char *s, unsigned long long v) { - char *p, aux; + char *p, aux; size_t l; /* Generate the string representation, this method produces * an reversed string. */ p = s; do { - *p++ = '0'+(v%10); + *p++ = '0' + (v % 10); v /= 10; - } while(v); + } while (v); /* Compute length and add null term. */ - l = p-s; + l = p - s; *p = '\0'; /* Reverse the string. */ p--; - while(s < p) { + while (s < p) { aux = *s; - *s = *p; - *p = aux; + *s = *p; + *p = aux; s++; p--; } @@ -521,38 +558,44 @@ int sdsull2str(char *s, unsigned long long v) { */ sds sdsfromlonglong(long long value) { char buf[SDS_LLSTR_SIZE]; - int len = sdsll2str(buf,value); + int len = sdsll2str(buf, value); - return sdsnewlen(buf,len); + return sdsnewlen(buf, len); } /* Like sdscatprintf() but gets va_list instead of being variadic. */ sds sdscatvprintf(sds s, const char *fmt, va_list ap) { va_list cpy; - char staticbuf[1024], *buf = staticbuf, *t; - size_t buflen = strlen(fmt)*2; + char staticbuf[1024], *buf = staticbuf, *t; + size_t buflen = strlen(fmt) * 2; /* We try to start using a static buffer for speed. * If not possible we revert to heap allocation. */ if (buflen > sizeof(staticbuf)) { buf = s_malloc(buflen); - if (buf == NULL) return NULL; + if (buf == NULL) { + return NULL; + } } else { buflen = sizeof(staticbuf); } /* Try with buffers two times bigger every time we fail to * fit the string in the current buffer size. */ - while(1) { - buf[buflen-2] = '\0'; - va_copy(cpy,ap); + while (1) { + buf[buflen - 2] = '\0'; + va_copy(cpy, ap); vsnprintf(buf, buflen, fmt, cpy); va_end(cpy); - if (buf[buflen-2] != '\0') { - if (buf != staticbuf) s_free(buf); + if (buf[buflen - 2] != '\0') { + if (buf != staticbuf) { + s_free(buf); + } buflen *= 2; buf = s_malloc(buflen); - if (buf == NULL) return NULL; + if (buf == NULL) { + return NULL; + } continue; } break; @@ -560,7 +603,9 @@ sds sdscatvprintf(sds s, const char *fmt, va_list ap) { /* Finally concat the obtained string to the SDS string and return it. */ t = sdscat(s, buf); - if (buf != staticbuf) s_free(buf); + if (buf != staticbuf) { + s_free(buf); + } return t; } @@ -582,9 +627,9 @@ sds sdscatvprintf(sds s, const char *fmt, va_list ap) { */ sds sdscatprintf(sds s, const char *fmt, ...) { va_list ap; - char *t; + char *t; va_start(ap, fmt); - t = sdscatvprintf(s,fmt,ap); + t = sdscatvprintf(s, fmt, ap); va_end(ap); return t; } @@ -607,86 +652,96 @@ sds sdscatprintf(sds s, const char *fmt, ...) { */ sds sdscatfmt(sds s, char const *fmt, ...) { const char *f = fmt; - int i; - va_list ap; + int i; + va_list ap; - va_start(ap,fmt); + va_start(ap, fmt); i = sdslen(s); /* Position of the next byte to write to dest str. */ - while(*f) { - char next, *str; - size_t l; - long long num; + while (*f) { + char next, *str; + size_t l; + long long num; unsigned long long unum; /* Make sure there is always space for at least 1 char. */ - if (sdsavail(s)==0) { - s = sdsMakeRoomFor(s,1); - if (s == NULL) goto fmt_error; + if (sdsavail(s) == 0) { + s = sdsMakeRoomFor(s, 1); + if (s == NULL) { + goto fmt_error; + } } - switch(*f) { - case '%': - next = *(f+1); - f++; - switch(next) { - case 's': - case 'S': - str = va_arg(ap,char*); - l = (next == 's') ? strlen(str) : sdslen(str); - if (sdsavail(s) < l) { - s = sdsMakeRoomFor(s,l); - if (s == NULL) goto fmt_error; - } - memcpy(s+i,str,l); - sdsinclen(s,l); - i += l; - break; - case 'i': - case 'I': - if (next == 'i') - num = va_arg(ap,int); - else - num = va_arg(ap,long long); - { - char buf[SDS_LLSTR_SIZE]; - l = sdsll2str(buf,num); - if (sdsavail(s) < l) { - s = sdsMakeRoomFor(s,l); - if (s == NULL) goto fmt_error; - } - memcpy(s+i,buf,l); - sdsinclen(s,l); - i += l; + switch (*f) { + case '%': + next = *(f + 1); + f++; + switch (next) { + case 's': + case 'S': + str = va_arg(ap, char *); + l = (next == 's') ? strlen(str) : sdslen(str); + if (sdsavail(s) < l) { + s = sdsMakeRoomFor(s, l); + if (s == NULL) { + goto fmt_error; + } + } + memcpy(s + i, str, l); + sdsinclen(s, l); + i += l; + break; + case 'i': + case 'I': + if (next == 'i') { + num = va_arg(ap, int); + } else { + num = va_arg(ap, long long); + } + { + char buf[SDS_LLSTR_SIZE]; + l = sdsll2str(buf, num); + if (sdsavail(s) < l) { + s = sdsMakeRoomFor(s, l); + if (s == NULL) { + goto fmt_error; + } + } + memcpy(s + i, buf, l); + sdsinclen(s, l); + i += l; + } + break; + case 'u': + case 'U': + if (next == 'u') { + unum = va_arg(ap, unsigned int); + } else { + unum = va_arg(ap, unsigned long long); + } + { + char buf[SDS_LLSTR_SIZE]; + l = sdsull2str(buf, unum); + if (sdsavail(s) < l) { + s = sdsMakeRoomFor(s, l); + if (s == NULL) { + goto fmt_error; + } + } + memcpy(s + i, buf, l); + sdsinclen(s, l); + i += l; + } + break; + default: /* Handle %% and generally %. */ + s[i++] = next; + sdsinclen(s, 1); + break; } break; - case 'u': - case 'U': - if (next == 'u') - unum = va_arg(ap,unsigned int); - else - unum = va_arg(ap,unsigned long long); - { - char buf[SDS_LLSTR_SIZE]; - l = sdsull2str(buf,unum); - if (sdsavail(s) < l) { - s = sdsMakeRoomFor(s,l); - if (s == NULL) goto fmt_error; - } - memcpy(s+i,buf,l); - sdsinclen(s,l); - i += l; - } + default: + s[i++] = *f; + sdsinclen(s, 1); break; - default: /* Handle %% and generally %. */ - s[i++] = next; - sdsinclen(s,1); - break; - } - break; - default: - s[i++] = *f; - sdsinclen(s,1); - break; } f++; } @@ -716,17 +771,23 @@ fmt_error: * Output will be just "Hello World". */ sds sdstrim(sds s, const char *cset) { - char *start, *end, *sp, *ep; + char *start, *end, *sp, *ep; size_t len; sp = start = s; - ep = end = s+sdslen(s)-1; - while(sp <= end && strchr(cset, *sp)) sp++; - while(ep > sp && strchr(cset, *ep)) ep--; - len = (sp > ep) ? 0 : ((ep-sp)+1); - if (s != sp) memmove(s, sp, len); + ep = end = s + sdslen(s) - 1; + while (sp <= end && strchr(cset, *sp)) { + sp++; + } + while (ep > sp && strchr(cset, *ep)) { + ep--; + } + len = (sp > ep) ? 0 : ((ep - sp) + 1); + if (s != sp) { + memmove(s, sp, len); + } s[len] = '\0'; - sdssetlen(s,len); + sdssetlen(s, len); return s; } @@ -752,31 +813,41 @@ sds sdstrim(sds s, const char *cset) { */ int sdsrange(sds s, ssize_t start, ssize_t end) { size_t newlen, len = sdslen(s); - if (len > SSIZE_MAX) return -1; + if (len > SSIZE_MAX) { + return -1; + } - if (len == 0) return 0; + if (len == 0) { + return 0; + } if (start < 0) { - start = len+start; - if (start < 0) start = 0; + start = len + start; + if (start < 0) { + start = 0; + } } if (end < 0) { - end = len+end; - if (end < 0) end = 0; + end = len + end; + if (end < 0) { + end = 0; + } } - newlen = (start > end) ? 0 : (end-start)+1; + newlen = (start > end) ? 0 : (end - start) + 1; if (newlen != 0) { if (start >= (ssize_t)len) { newlen = 0; } else if (end >= (ssize_t)len) { - end = len-1; - newlen = (start > end) ? 0 : (end-start)+1; + end = len - 1; + newlen = (start > end) ? 0 : (end - start) + 1; } } else { start = 0; } - if (start && newlen) memmove(s, s+start, newlen); + if (start && newlen) { + memmove(s, s + start, newlen); + } s[newlen] = 0; - sdssetlen(s,newlen); + sdssetlen(s, newlen); return 0; } @@ -784,14 +855,18 @@ int sdsrange(sds s, ssize_t start, ssize_t end) { void sdstolower(sds s) { int len = sdslen(s), j; - for (j = 0; j < len; j++) s[j] = tolower(s[j]); + for (j = 0; j < len; j++) { + s[j] = tolower(s[j]); + } } /* Apply toupper() to every character of the sds string 's'. */ void sdstoupper(sds s) { int len = sdslen(s), j; - for (j = 0; j < len; j++) s[j] = toupper(s[j]); + for (j = 0; j < len; j++) { + s[j] = toupper(s[j]); + } } /* Compare two sds strings s1 and s2 with memcmp(). @@ -807,13 +882,15 @@ void sdstoupper(sds s) { * the smaller one. */ int sdscmp(const sds s1, const sds s2) { size_t l1, l2, minlen; - int cmp; + int cmp; - l1 = sdslen(s1); - l2 = sdslen(s2); + l1 = sdslen(s1); + l2 = sdslen(s2); minlen = (l1 < l2) ? l1 : l2; - cmp = memcmp(s1,s2,minlen); - if (cmp == 0) return l1-l2; + cmp = memcmp(s1, s2, minlen); + if (cmp == 0) { + return l1 - l2; + } return cmp; } @@ -834,59 +911,73 @@ int sdscmp(const sds s1, const sds s2) { * same function but for zero-terminated strings. */ sds *sdssplitlen(const char *s, int len, const char *sep, int seplen, int *count) { - int elements = 0, slots = 5, start = 0, j; + int elements = 0, slots = 5, start = 0, j; sds *tokens; - if (seplen < 1 || len < 0) return NULL; + if (seplen < 1 || len < 0) { + return NULL; + } - tokens = s_malloc(sizeof(sds)*slots); - if (tokens == NULL) return NULL; + tokens = s_malloc(sizeof(sds) * slots); + if (tokens == NULL) { + return NULL; + } if (len == 0) { *count = 0; return tokens; } - for (j = 0; j < (len-(seplen-1)); j++) { + for (j = 0; j < (len - (seplen - 1)); j++) { /* make sure there is room for the next element and the final one */ - if (slots < elements+2) { + if (slots < elements + 2) { sds *newtokens; slots *= 2; - newtokens = s_realloc(tokens,sizeof(sds)*slots); - if (newtokens == NULL) goto cleanup; + newtokens = s_realloc(tokens, sizeof(sds) * slots); + if (newtokens == NULL) { + goto cleanup; + } tokens = newtokens; } /* search the separator */ - if ((seplen == 1 && *(s+j) == sep[0]) || (memcmp(s+j,sep,seplen) == 0)) { - tokens[elements] = sdsnewlen(s+start,j-start); - if (tokens[elements] == NULL) goto cleanup; + if ((seplen == 1 && *(s + j) == sep[0]) || (memcmp(s + j, sep, seplen) == 0)) { + tokens[elements] = sdsnewlen(s + start, j - start); + if (tokens[elements] == NULL) { + goto cleanup; + } elements++; - start = j+seplen; - j = j+seplen-1; /* skip the separator */ + start = j + seplen; + j = j + seplen - 1; /* skip the separator */ } } /* Add the final element. We are sure there is room in the tokens array. */ - tokens[elements] = sdsnewlen(s+start,len-start); - if (tokens[elements] == NULL) goto cleanup; + tokens[elements] = sdsnewlen(s + start, len - start); + if (tokens[elements] == NULL) { + goto cleanup; + } elements++; *count = elements; return tokens; -cleanup: - { - int i; - for (i = 0; i < elements; i++) sdsfree(tokens[i]); - s_free(tokens); - *count = 0; - return NULL; +cleanup : { + int i; + for (i = 0; i < elements; i++) { + sdsfree(tokens[i]); } + s_free(tokens); + *count = 0; + return NULL; +} } /* Free the result returned by sdssplitlen(), or do nothing if 'tokens' is NULL. */ void sdsfreesplitres(sds *tokens, int count) { - if (!tokens) return; - while(count--) + if (!tokens) { + return; + } + while (count--) { sdsfree(tokens[count]); + } s_free(tokens); } @@ -897,51 +988,85 @@ void sdsfreesplitres(sds *tokens, int count) { * After the call, the modified sds string is no longer valid and all the * references must be substituted with the new pointer returned by the call. */ sds sdscatrepr(sds s, const char *p, size_t len) { - s = sdscatlen(s,"\"",1); - while(len--) { - switch(*p) { - case '\\': - case '"': - s = sdscatprintf(s,"\\%c",*p); - break; - case '\n': s = sdscatlen(s,"\\n",2); break; - case '\r': s = sdscatlen(s,"\\r",2); break; - case '\t': s = sdscatlen(s,"\\t",2); break; - case '\a': s = sdscatlen(s,"\\a",2); break; - case '\b': s = sdscatlen(s,"\\b",2); break; - default: - if (isprint(*p)) - s = sdscatprintf(s,"%c",*p); - else - s = sdscatprintf(s,"\\x%02x",(unsigned char)*p); - break; + s = sdscatlen(s, "\"", 1); + while (len--) { + switch (*p) { + case '\\': + case '"': + s = sdscatprintf(s, "\\%c", *p); + break; + case '\n': + s = sdscatlen(s, "\\n", 2); + break; + case '\r': + s = sdscatlen(s, "\\r", 2); + break; + case '\t': + s = sdscatlen(s, "\\t", 2); + break; + case '\a': + s = sdscatlen(s, "\\a", 2); + break; + case '\b': + s = sdscatlen(s, "\\b", 2); + break; + default: + if (isprint(*p)) { + s = sdscatprintf(s, "%c", *p); + } else { + s = sdscatprintf(s, "\\x%02x", (unsigned char)*p); + } + break; } p++; } - return sdscatlen(s,"\"",1); + return sdscatlen(s, "\"", 1); } /* Helper function for sdssplitargs() that converts a hex digit into an * integer from 0 to 15 */ int hex_digit_to_int(char c) { - switch(c) { - case '0': return 0; - case '1': return 1; - case '2': return 2; - case '3': return 3; - case '4': return 4; - case '5': return 5; - case '6': return 6; - case '7': return 7; - case '8': return 8; - case '9': return 9; - case 'a': case 'A': return 10; - case 'b': case 'B': return 11; - case 'c': case 'C': return 12; - case 'd': case 'D': return 13; - case 'e': case 'E': return 14; - case 'f': case 'F': return 15; - default: return 0; + switch (c) { + case '0': + return 0; + case '1': + return 1; + case '2': + return 2; + case '3': + return 3; + case '4': + return 4; + case '5': + return 5; + case '6': + return 6; + case '7': + return 7; + case '8': + return 8; + case '9': + return 9; + case 'a': + case 'A': + return 10; + case 'b': + case 'B': + return 11; + case 'c': + case 'C': + return 12; + case 'd': + case 'D': + return 13; + case 'e': + case 'E': + return 14; + case 'f': + case 'F': + return 15; + default: + return 0; } } @@ -965,119 +1090,142 @@ int hex_digit_to_int(char c) { * as in: "foo"bar or "foo' */ sds *sdssplitargs(const char *line, int *argc) { - const char *p = line; - char *current = NULL; - char **vector = NULL; + const char *p = line; + char *current = NULL; + char **vector = NULL; *argc = 0; - while(1) { + while (1) { /* skip blanks */ - while(*p && isspace(*p)) p++; + while (*p && isspace(*p)) { + p++; + } if (*p) { /* get a token */ - int inq=0; /* set to 1 if we are in "quotes" */ - int insq=0; /* set to 1 if we are in 'single quotes' */ - int done=0; + int inq = 0; /* set to 1 if we are in "quotes" */ + int insq = 0; /* set to 1 if we are in 'single quotes' */ + int done = 0; - if (current == NULL) current = sdsempty(); - while(!done) { + if (current == NULL) { + current = sdsempty(); + } + while (!done) { if (inq) { - if (*p == '\\' && *(p+1) == 'x' && - isxdigit(*(p+2)) && - isxdigit(*(p+3))) - { + if (*p == '\\' && *(p + 1) == 'x' && isxdigit(*(p + 2)) && isxdigit(*(p + 3))) { unsigned char byte; - byte = (hex_digit_to_int(*(p+2))*16)+ - hex_digit_to_int(*(p+3)); - current = sdscatlen(current,(char*)&byte,1); + byte = (hex_digit_to_int(*(p + 2)) * 16) + hex_digit_to_int(*(p + 3)); + current = sdscatlen(current, (char *)&byte, 1); p += 3; - } else if (*p == '\\' && *(p+1)) { + } else if (*p == '\\' && *(p + 1)) { char c; p++; - switch(*p) { - case 'n': c = '\n'; break; - case 'r': c = '\r'; break; - case 't': c = '\t'; break; - case 'b': c = '\b'; break; - case 'a': c = '\a'; break; - default: c = *p; break; + switch (*p) { + case 'n': + c = '\n'; + break; + case 'r': + c = '\r'; + break; + case 't': + c = '\t'; + break; + case 'b': + c = '\b'; + break; + case 'a': + c = '\a'; + break; + default: + c = *p; + break; } - current = sdscatlen(current,&c,1); + current = sdscatlen(current, &c, 1); } else if (*p == '"') { /* closing quote must be followed by a space or * nothing at all. */ - if (*(p+1) && !isspace(*(p+1))) goto err; - done=1; + if (*(p + 1) && !isspace(*(p + 1))) { + goto err; + } + done = 1; } else if (!*p) { /* unterminated quotes */ goto err; } else { - current = sdscatlen(current,p,1); + current = sdscatlen(current, p, 1); } } else if (insq) { - if (*p == '\\' && *(p+1) == '\'') { + if (*p == '\\' && *(p + 1) == '\'') { p++; - current = sdscatlen(current,"'",1); + current = sdscatlen(current, "'", 1); } else if (*p == '\'') { /* closing quote must be followed by a space or * nothing at all. */ - if (*(p+1) && !isspace(*(p+1))) goto err; - done=1; + if (*(p + 1) && !isspace(*(p + 1))) { + goto err; + } + done = 1; } else if (!*p) { /* unterminated quotes */ goto err; } else { - current = sdscatlen(current,p,1); + current = sdscatlen(current, p, 1); } } else { - switch(*p) { - case ' ': - case '\n': - case '\r': - case '\t': - case '\0': - done=1; - break; - case '"': - inq=1; - break; - case '\'': - insq=1; - break; - default: - current = sdscatlen(current,p,1); - break; + switch (*p) { + case ' ': + case '\n': + case '\r': + case '\t': + case '\0': + done = 1; + break; + case '"': + inq = 1; + break; + case '\'': + insq = 1; + break; + default: + current = sdscatlen(current, p, 1); + break; } } - if (*p) p++; + if (*p) { + p++; + } } /* add the token to the vector */ { - char **new_vector = s_realloc(vector,((*argc)+1)*sizeof(char*)); + char **new_vector = s_realloc(vector, ((*argc) + 1) * sizeof(char *)); if (new_vector == NULL) { s_free(vector); return NULL; } - vector = new_vector; + vector = new_vector; vector[*argc] = current; (*argc)++; current = NULL; } } else { /* Even on empty input string return something not NULL. */ - if (vector == NULL) vector = s_malloc(sizeof(void*)); + if (vector == NULL) { + vector = s_malloc(sizeof(void *)); + } return vector; } } err: - while((*argc)--) + while ((*argc)--) { sdsfree(vector[*argc]); + } s_free(vector); - if (current) sdsfree(current); + if (current) { + sdsfree(current); + } *argc = 0; return NULL; } @@ -1113,7 +1261,9 @@ sds sdsjoin(char **argv, int argc, char *sep) { for (j = 0; j < argc; j++) { join = sdscat(join, argv[j]); - if (j != argc-1) join = sdscat(join,sep); + if (j != argc - 1) { + join = sdscat(join, sep); + } } return join; } @@ -1125,7 +1275,9 @@ sds sdsjoinsds(sds *argv, int argc, const char *sep, size_t seplen) { for (j = 0; j < argc; j++) { join = sdscatsds(join, argv[j]); - if (j != argc-1) join = sdscatlen(join,sep,seplen); + if (j != argc - 1) { + join = sdscatlen(join, sep, seplen); + } } return join; } @@ -1135,9 +1287,15 @@ sds sdsjoinsds(sds *argv, int argc, const char *sep, size_t seplen) { * the overhead of function calls. Here we define these wrappers only for * the programs SDS is linked to, if they want to touch the SDS internals * even if they use a different allocator. */ -void *sds_malloc(size_t size) { return s_malloc(size); } -void *sds_realloc(void *ptr, size_t size) { return s_realloc(ptr,size); } -void sds_free(void *ptr) { s_free(ptr); } +void *sds_malloc(size_t size) { + return s_malloc(size); +} +void *sds_realloc(void *ptr, size_t size) { + return s_realloc(ptr, size); +} +void sds_free(void *ptr) { + s_free(ptr); +} #if defined(SDS_TEST_MAIN) #include @@ -1149,130 +1307,115 @@ int sdsTest(void) { { sds x = sdsnew("foo"), y; - test_cond("Create a string and obtain the length", - sdslen(x) == 3 && memcmp(x,"foo\0",4) == 0) + test_cond("Create a string and obtain the length", sdslen(x) == 3 && memcmp(x, "foo\0", 4) == 0) - sdsfree(x); - x = sdsnewlen("foo",2); - test_cond("Create a string with specified length", - sdslen(x) == 2 && memcmp(x,"fo\0",3) == 0) + sdsfree(x); + x = sdsnewlen("foo", 2); + test_cond("Create a string with specified length", sdslen(x) == 2 && memcmp(x, "fo\0", 3) == 0) - x = sdscat(x,"bar"); - test_cond("Strings concatenation", - sdslen(x) == 5 && memcmp(x,"fobar\0",6) == 0); + x = sdscat(x, "bar"); + test_cond("Strings concatenation", sdslen(x) == 5 && memcmp(x, "fobar\0", 6) == 0); - x = sdscpy(x,"a"); - test_cond("sdscpy() against an originally longer string", - sdslen(x) == 1 && memcmp(x,"a\0",2) == 0) + x = sdscpy(x, "a"); + test_cond("sdscpy() against an originally longer string", sdslen(x) == 1 && memcmp(x, "a\0", 2) == 0) - x = sdscpy(x,"xyzxxxxxxxxxxyyyyyyyyyykkkkkkkkkk"); + x = sdscpy(x, "xyzxxxxxxxxxxyyyyyyyyyykkkkkkkkkk"); test_cond("sdscpy() against an originally shorter string", - sdslen(x) == 33 && - memcmp(x,"xyzxxxxxxxxxxyyyyyyyyyykkkkkkkkkk\0",33) == 0) + sdslen(x) == 33 && memcmp(x, "xyzxxxxxxxxxxyyyyyyyyyykkkkkkkkkk\0", 33) == 0) - sdsfree(x); - x = sdscatprintf(sdsempty(),"%d",123); - test_cond("sdscatprintf() seems working in the base case", - sdslen(x) == 3 && memcmp(x,"123\0",4) == 0) + sdsfree(x); + x = sdscatprintf(sdsempty(), "%d", 123); + test_cond("sdscatprintf() seems working in the base case", sdslen(x) == 3 && memcmp(x, "123\0", 4) == 0) - sdsfree(x); + sdsfree(x); x = sdsnew("--"); - x = sdscatfmt(x, "Hello %s World %I,%I--", "Hi!", LLONG_MIN,LLONG_MAX); + x = sdscatfmt(x, "Hello %s World %I,%I--", "Hi!", LLONG_MIN, LLONG_MAX); test_cond("sdscatfmt() seems working in the base case", - sdslen(x) == 60 && - memcmp(x,"--Hello Hi! World -9223372036854775808," - "9223372036854775807--",60) == 0) - printf("[%s]\n",x); + sdslen(x) == 60 + && memcmp(x, + "--Hello Hi! World -9223372036854775808," + "9223372036854775807--", + 60) + == 0) printf("[%s]\n", x); sdsfree(x); x = sdsnew("--"); x = sdscatfmt(x, "%u,%U--", UINT_MAX, ULLONG_MAX); test_cond("sdscatfmt() seems working with unsigned numbers", - sdslen(x) == 35 && - memcmp(x,"--4294967295,18446744073709551615--",35) == 0) + sdslen(x) == 35 && memcmp(x, "--4294967295,18446744073709551615--", 35) == 0) - sdsfree(x); + sdsfree(x); x = sdsnew(" x "); - sdstrim(x," x"); - test_cond("sdstrim() works when all chars match", - sdslen(x) == 0) + sdstrim(x, " x"); + test_cond("sdstrim() works when all chars match", sdslen(x) == 0) - sdsfree(x); + sdsfree(x); x = sdsnew(" x "); - sdstrim(x," "); - test_cond("sdstrim() works when a single char remains", - sdslen(x) == 1 && x[0] == 'x') + sdstrim(x, " "); + test_cond("sdstrim() works when a single char remains", sdslen(x) == 1 && x[0] == 'x') - sdsfree(x); + sdsfree(x); x = sdsnew("xxciaoyyy"); - sdstrim(x,"xy"); - test_cond("sdstrim() correctly trims characters", - sdslen(x) == 4 && memcmp(x,"ciao\0",5) == 0) + sdstrim(x, "xy"); + test_cond("sdstrim() correctly trims characters", sdslen(x) == 4 && memcmp(x, "ciao\0", 5) == 0) + y = sdsdup(x); + sdsrange(y, 1, 1); + test_cond("sdsrange(...,1,1)", sdslen(y) == 1 && memcmp(y, "i\0", 2) == 0) + + sdsfree(y); y = sdsdup(x); - sdsrange(y,1,1); - test_cond("sdsrange(...,1,1)", - sdslen(y) == 1 && memcmp(y,"i\0",2) == 0) + sdsrange(y, 1, -1); + test_cond("sdsrange(...,1,-1)", sdslen(y) == 3 && memcmp(y, "iao\0", 4) == 0) - sdsfree(y); + sdsfree(y); y = sdsdup(x); - sdsrange(y,1,-1); - test_cond("sdsrange(...,1,-1)", - sdslen(y) == 3 && memcmp(y,"iao\0",4) == 0) + sdsrange(y, -2, -1); + test_cond("sdsrange(...,-2,-1)", sdslen(y) == 2 && memcmp(y, "ao\0", 3) == 0) - sdsfree(y); + sdsfree(y); y = sdsdup(x); - sdsrange(y,-2,-1); - test_cond("sdsrange(...,-2,-1)", - sdslen(y) == 2 && memcmp(y,"ao\0",3) == 0) + sdsrange(y, 2, 1); + test_cond("sdsrange(...,2,1)", sdslen(y) == 0 && memcmp(y, "\0", 1) == 0) - sdsfree(y); + sdsfree(y); y = sdsdup(x); - sdsrange(y,2,1); - test_cond("sdsrange(...,2,1)", - sdslen(y) == 0 && memcmp(y,"\0",1) == 0) + sdsrange(y, 1, 100); + test_cond("sdsrange(...,1,100)", sdslen(y) == 3 && memcmp(y, "iao\0", 4) == 0) - sdsfree(y); + sdsfree(y); y = sdsdup(x); - sdsrange(y,1,100); - test_cond("sdsrange(...,1,100)", - sdslen(y) == 3 && memcmp(y,"iao\0",4) == 0) + sdsrange(y, 100, 100); + test_cond("sdsrange(...,100,100)", sdslen(y) == 0 && memcmp(y, "\0", 1) == 0) - sdsfree(y); - y = sdsdup(x); - sdsrange(y,100,100); - test_cond("sdsrange(...,100,100)", - sdslen(y) == 0 && memcmp(y,"\0",1) == 0) - - sdsfree(y); + sdsfree(y); sdsfree(x); x = sdsnew("foo"); y = sdsnew("foa"); - test_cond("sdscmp(foo,foa)", sdscmp(x,y) > 0) + test_cond("sdscmp(foo,foa)", sdscmp(x, y) > 0) - sdsfree(y); + sdsfree(y); sdsfree(x); x = sdsnew("bar"); y = sdsnew("bar"); - test_cond("sdscmp(bar,bar)", sdscmp(x,y) == 0) + test_cond("sdscmp(bar,bar)", sdscmp(x, y) == 0) - sdsfree(y); + sdsfree(y); sdsfree(x); x = sdsnew("aar"); y = sdsnew("bar"); - test_cond("sdscmp(bar,bar)", sdscmp(x,y) < 0) + test_cond("sdscmp(bar,bar)", sdscmp(x, y) < 0) - sdsfree(y); + sdsfree(y); sdsfree(x); - x = sdsnewlen("\a\n\0foo\r",7); - y = sdscatrepr(sdsempty(),x,sdslen(x)); - test_cond("sdscatrepr(...data...)", - memcmp(y,"\"\\a\\n\\x00foo\\r\"",15) == 0) + x = sdsnewlen("\a\n\0foo\r", 7); + y = sdscatrepr(sdsempty(), x, sdslen(x)); + test_cond("sdscatrepr(...data...)", memcmp(y, "\"\\a\\n\\x00foo\\r\"", 15) == 0) { unsigned int oldfree; - char *p; - int step = 10, j, i; + char *p; + int step = 10, j, i; sdsfree(x); sdsfree(y); @@ -1283,29 +1426,32 @@ int sdsTest(void) { * SDS header types. */ for (i = 0; i < 10; i++) { int oldlen = sdslen(x); - x = sdsMakeRoomFor(x,step); - int type = x[-1]&SDS_TYPE_MASK; + x = sdsMakeRoomFor(x, step); + int type = x[-1] & SDS_TYPE_MASK; test_cond("sdsMakeRoomFor() len", sdslen(x) == oldlen); if (type != SDS_TYPE_5) { test_cond("sdsMakeRoomFor() free", sdsavail(x) >= step); oldfree = sdsavail(x); } - p = x+oldlen; + p = x + oldlen; for (j = 0; j < step; j++) { - p[j] = 'A'+j; + p[j] = 'A' + j; } - sdsIncrLen(x,step); + sdsIncrLen(x, step); } test_cond("sdsMakeRoomFor() content", - memcmp("0ABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJ",x,101) == 0); - test_cond("sdsMakeRoomFor() final length",sdslen(x)==101); + memcmp("0ABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGH" + "IJABCDEFGHIJ", + x, + 101) + == 0); + test_cond("sdsMakeRoomFor() final length", sdslen(x) == 101); sdsfree(x); } } - test_report() - return 0; + test_report() return 0; } #endif diff --git a/srcs/libs/misc/zvector.c b/srcs/libs/misc/zvector.c index bdd9d12..be5c3e6 100644 --- a/srcs/libs/misc/zvector.c +++ b/srcs/libs/misc/zvector.c @@ -31,76 +31,75 @@ #include "zvector/zvector.h" #if (OS_TYPE == 1) -# if (!defined(macOS)) +#if (!defined(macOS)) /* Improve PThreads on Linux. * macOS seems to be handling pthreads * in a slightly different way than * Linux, so, avoid using the same trick * on macOS. */ -# ifndef _POSIX_C_SOURCE -# define _POSIX_C_SOURCE 200112L -# endif // _POSIX_C_SOURCE -# define __USE_UNIX98 -# endif // macOS -#endif // OS_TYPE +#ifndef _POSIX_C_SOURCE +#define _POSIX_C_SOURCE 200112L +#endif // _POSIX_C_SOURCE +#define __USE_UNIX98 +#endif // macOS +#endif // OS_TYPE // Include non-ANSI Libraries // only if the user has requested // special extensions: #if (OS_TYPE == 1) -# if ( !defined(macOS) ) -# include -# endif -# if (CPU_TYPE == x86_64) +#if (!defined(macOS)) +#include +#endif +#if (CPU_TYPE == x86_64) //# include -# endif -#endif // OS_TYPE +#endif +#endif // OS_TYPE #if (ZVECT_THREAD_SAFE == 1) -# if MUTEX_TYPE == 1 -# if ( !defined(macOS) ) -# include -# else -# include -# endif -# include -# elif MUTEX_TYPE == 2 -# include -# include -# endif // MUTEX_TYPE -#endif // ZVECT_THREAD_SAFE +#if MUTEX_TYPE == 1 +#if (!defined(macOS)) +#include +#else +#include +#endif +#include +#elif MUTEX_TYPE == 2 +#include +#include +#endif // MUTEX_TYPE +#endif // ZVECT_THREAD_SAFE // Local Defines/Macros: // Declare Vector status flags: enum { - ZVS_NONE = 0, // - Set or Reset vector's status - // register. - ZVS_CUST_WIPE_ON = 1 << 0, // - Set the bit to indicate a custom - // secure wipe - // function has been set. - ZVS_USR1_FLAG = 1 << 1, // - This is a "user" available flag, - // a user code can set it to 1 or - // 0 for its own need. - // Can be useful when signaling - // between threads. - ZVS_USR2_FLAG = 1 << 2 - + ZVS_NONE = 0, // - Set or Reset vector's status + // register. + ZVS_CUST_WIPE_ON = 1 << 0, // - Set the bit to indicate a custom + // secure wipe + // function has been set. + ZVS_USR1_FLAG = 1 << 1, // - This is a "user" available flag, + // a user code can set it to 1 or + // 0 for its own need. + // Can be useful when signaling + // between threads. + ZVS_USR2_FLAG = 1 << 2 }; #ifndef ZVECT_MEMX_METHOD -# define ZVECT_MEMX_METHOD 1 +#define ZVECT_MEMX_METHOD 1 #endif #if defined(Arch32) -# define ADDR_TYPE1 uint32_t -# define ADDR_TYPE2 uint32_t -# define ADDR_TYPE3 uint16_t +#define ADDR_TYPE1 uint32_t +#define ADDR_TYPE2 uint32_t +#define ADDR_TYPE3 uint16_t #else -# define ADDR_TYPE1 uint64_t -# define ADDR_TYPE2 uint64_t -# define ADDR_TYPE3 uint32_t -#endif // Arch32 +#define ADDR_TYPE1 uint64_t +#define ADDR_TYPE2 uint64_t +#define ADDR_TYPE3 uint32_t +#endif // Arch32 /*---------------------------------------------------------------------------*/ // Useful macros @@ -117,77 +116,77 @@ enum { // Please note: fields order is based on "most used fields" to help a bit with cache struct ZVECT_PACKING p_vector { - zvect_index cap_left; // - Max capacity allocated on the - // left. - zvect_index cap_right; // - Max capacity allocated on the - // right. - zvect_index begin; // - First vector's Element Pointer - zvect_index end; // - Current Array size. size - 1 gives - // us the pointer to the last element - // in the vector. - uint32_t flags; // - This flag set is used to store all - // Vector's properties. - // It contains bits that set Secure - // Wipe, Auto Shrink, Pass Items By - // Ref etc. - size_t data_size; // - User DataType size. - // This should be 2 bytes size on a - // 16-bit system, 4 bytes on a 32 - // bit, 8 bytes on a 64 bit. But - // check your compiler for the - // actual size, it's implementation - // dependent. + zvect_index cap_left; // - Max capacity allocated on the + // left. + zvect_index cap_right; // - Max capacity allocated on the + // right. + zvect_index begin; // - First vector's Element Pointer + zvect_index end; // - Current Array size. size - 1 gives + // us the pointer to the last element + // in the vector. + uint32_t flags; // - This flag set is used to store all + // Vector's properties. + // It contains bits that set Secure + // Wipe, Auto Shrink, Pass Items By + // Ref etc. + size_t data_size; // - User DataType size. + // This should be 2 bytes size on a + // 16-bit system, 4 bytes on a 32 + // bit, 8 bytes on a 64 bit. But + // check your compiler for the + // actual size, it's implementation + // dependent. #if (ZVECT_THREAD_SAFE == 1) -# if MUTEX_TYPE == 0 - void *lock ZVECT_DATAALIGN; // - Vector's mutex for thread safe - // micro-transactions or user locks. - // This should be 2 bytes size on a - // 16 bit machine, 4 bytes on a 32 - // bit 4 bytes on a 64 bit. - void *cond; // - Vector's mutex condition variable -# elif MUTEX_TYPE == 1 - pthread_mutex_t lock ZVECT_DATAALIGN; - // - Vector's mutex for thread safe - // micro-transactions or user locks. - // This should be 24 bytes on a 32bit - // machine and 40 bytes on a 64bit. - pthread_cond_t cond; // - Vector's mutex condition variable +#if MUTEX_TYPE == 0 + void *lock ZVECT_DATAALIGN; // - Vector's mutex for thread safe + // micro-transactions or user locks. + // This should be 2 bytes size on a + // 16 bit machine, 4 bytes on a 32 + // bit 4 bytes on a 64 bit. + void *cond; // - Vector's mutex condition variable +#elif MUTEX_TYPE == 1 + pthread_mutex_t lock ZVECT_DATAALIGN; + // - Vector's mutex for thread safe + // micro-transactions or user locks. + // This should be 24 bytes on a 32bit + // machine and 40 bytes on a 64bit. + pthread_cond_t cond; // - Vector's mutex condition variable -# elif MUTEX_TYPE == 2 - CRITICAL_SECTION lock ZVECT_DATAALIGN; - // - Vector's mutex for thread safe - // micro-transactions or user locks. - // Check your WINNT.H to calculate - // the size of this one. - CONDITION_VARIABLE cond; // - Vector's mutex condition variable -# endif // MUTEX_TYPE -#endif // ZVECT_THREAD_SAFE - void **data ZVECT_DATAALIGN; // - Vector's storage. - zvect_index init_capacity; // - Initial Capacity (this is set at - // creation time). - // For the size of zvect_index check - // zvector_config.h. - void (*SfWpFunc)(const void *item, size_t size); - // - Pointer to a CUSTOM Safe Wipe - // function (optional) needed only - // for Secure Wiping special - // structures. +#elif MUTEX_TYPE == 2 + CRITICAL_SECTION lock ZVECT_DATAALIGN; + // - Vector's mutex for thread safe + // micro-transactions or user locks. + // Check your WINNT.H to calculate + // the size of this one. + CONDITION_VARIABLE cond; // - Vector's mutex condition variable +#endif // MUTEX_TYPE +#endif // ZVECT_THREAD_SAFE + void **data ZVECT_DATAALIGN; // - Vector's storage. + zvect_index init_capacity; // - Initial Capacity (this is set at + // creation time). + // For the size of zvect_index check + // zvector_config.h. + void (*SfWpFunc)(const void *item, size_t size); + // - Pointer to a CUSTOM Safe Wipe + // function (optional) needed only + // for Secure Wiping special + // structures. #ifdef ZVECT_DMF_EXTENSIONS - zvect_index balance; // - Used by the Adaptive Binary Search - // to improve performance. - zvect_index bottom; // - Used to optimise Adaptive Binary - // Search. -#endif // ZVECT_DMF_EXTENSIONS - volatile uint32_t status; // - Internal vector Status Flags + zvect_index balance; // - Used by the Adaptive Binary Search + // to improve performance. + zvect_index bottom; // - Used to optimise Adaptive Binary + // Search. +#endif // ZVECT_DMF_EXTENSIONS + volatile uint32_t status; // - Internal vector Status Flags #if (ZVECT_THREAD_SAFE == 1) -# if ( !defined(macOS) ) - sem_t semaphore; // - Vector semaphore -# else - dispatch_semaphore_t semaphore; // - Vector semaphore -# endif - volatile int32_t lock_type; // - This field contains the lock type - // used for this Vector. -#endif // ZVECT_THREAD_SAFE +#if (!defined(macOS)) + sem_t semaphore; // - Vector semaphore +#else + dispatch_semaphore_t semaphore; // - Vector semaphore +#endif + volatile int32_t lock_type; // - This field contains the lock type + // used for this Vector. +#endif // ZVECT_THREAD_SAFE } ZVECT_DATAALIGN; // Initialisation state: @@ -203,136 +202,133 @@ static uint32_t p_init_state = 0; // Errors and messages handling: enum ZVECT_LOGPRIORITY { - ZVLP_NONE = 0, // No priority - ZVLP_INFO = 1 << 0, // This is an informational priority - // message. - ZVLP_LOW = 1 << 1, // " low " - ZVLP_MEDIUM = 1 << 2, // " medium " - ZVLP_HIGH = 1 << 3, // " high " - ZVLP_ERROR = 1 << 4 // This is an error message. + ZVLP_NONE = 0, // No priority + ZVLP_INFO = 1 << 0, // This is an informational priority + // message. + ZVLP_LOW = 1 << 1, // " low " + ZVLP_MEDIUM = 1 << 2, // " medium " + ZVLP_HIGH = 1 << 3, // " high " + ZVLP_ERROR = 1 << 4 // This is an error message. }; // Set the message priority at which we log it: #ifdef DEBUG -unsigned int LOG_PRIORITY = (ZVLP_ERROR | ZVLP_HIGH | ZVLP_MEDIUM | - ZVLP_LOW | ZVLP_INFO); +unsigned int LOG_PRIORITY = (ZVLP_ERROR | ZVLP_HIGH | ZVLP_MEDIUM | ZVLP_LOW | ZVLP_INFO); #endif #ifndef DEBUG unsigned int LOG_PRIORITY = (ZVLP_ERROR | ZVLP_HIGH | ZVLP_MEDIUM); #endif // This is a vprintf wrapper nothing special: -static void log_msg(int const priority, const char * const format, ...) -{ - va_list args; - va_start(args, format); +static void log_msg(int const priority, const char *const format, ...) { + va_list args; + va_start(args, format); - if ( priority & LOG_PRIORITY ) - vprintf(format, args); + if (priority & LOG_PRIORITY) { + vprintf(format, args); + } #ifdef DEBUG - fflush(stdout); + fflush(stdout); #endif #ifndef DEBUG - if (priority & (ZVLP_ERROR | ZVLP_HIGH)) - fflush(stdout); + if (priority & (ZVLP_ERROR | ZVLP_HIGH)) { + fflush(stdout); + } #endif - va_end(args); + va_end(args); } -static size_t safe_strlen(const char *str, size_t max_len) -{ +static size_t safe_strlen(const char *str, size_t max_len) { const char *end = (const char *)memchr(str, '\0', max_len); - if (end == NULL) + if (end == NULL) { return max_len; - else + } else { return end - str; + } } -static void *safe_strncpy(const char * const str_src, - size_t max_len) -{ - void *str_dst = NULL; - char tmp_dst[max_len]; - tmp_dst[sizeof(tmp_dst) - 1] = 0; +static void *safe_strncpy(const char *const str_src, size_t max_len) { + void *str_dst = NULL; + char tmp_dst[max_len]; + tmp_dst[sizeof(tmp_dst) - 1] = 0; - strncpy(tmp_dst, str_src, sizeof(tmp_dst)); + strncpy(tmp_dst, str_src, sizeof(tmp_dst)); - if ( tmp_dst[sizeof(tmp_dst) - 1] != 0 ) - { - tmp_dst[sizeof(tmp_dst) - 1] = 0; - } + if (tmp_dst[sizeof(tmp_dst) - 1] != 0) { + tmp_dst[sizeof(tmp_dst) - 1] = 0; + } - str_dst = (void *)malloc(sizeof(char *) * (sizeof(tmp_dst) + 1)); - if ( str_dst == NULL ) - { - log_msg(ZVLP_ERROR, "Error: %*i, %s\n", 8, -1000, "Out of memory!"); - } else { - strncpy((char *)str_dst, tmp_dst, sizeof(char) * max_len); - } - return str_dst; + str_dst = (void *)malloc(sizeof(char *) * (sizeof(tmp_dst) + 1)); + if (str_dst == NULL) { + log_msg(ZVLP_ERROR, "Error: %*i, %s\n", 8, -1000, "Out of memory!"); + } else { + strncpy((char *)str_dst, tmp_dst, sizeof(char) * max_len); + } + return str_dst; } #if (ZVECT_COMPTYPE == 1) || (ZVECT_COMPTYPE == 3) __attribute__((noreturn)) #endif -static void p_throw_error(const zvect_retval error_code, - const char *error_message) { - int32_t locally_allocated = 0; - char *message = NULL; - unsigned long msg_len = 0; +static void +p_throw_error(const zvect_retval error_code, const char *error_message) { + int32_t locally_allocated = 0; + char *message = NULL; + unsigned long msg_len = 0; - if ( error_message == NULL ) - { - msg_len = sizeof(char *) * 255; - locally_allocated=-1; - } else { - msg_len = safe_strlen(error_message, 255); - } + if (error_message == NULL) { + msg_len = sizeof(char *) * 255; + locally_allocated = -1; + } else { + msg_len = safe_strlen(error_message, 255); + } - if ( locally_allocated ) { - switch (error_code) - { - case ZVERR_VECTUNDEF: - message=(char *)safe_strncpy("Undefined or uninitialized vector.\n\0", msg_len); - break; - case ZVERR_IDXOUTOFBOUND: - message=(char *)safe_strncpy("Index out of bound.\n\0", msg_len); - break; - case ZVERR_OUTOFMEM: - message=(char *)safe_strncpy("Not enough memory to allocate space for the vector.\n\0", msg_len); - break; - case ZVERR_VECTCORRUPTED: - message=(char *)safe_strncpy("Vector corrupted.\n\0", msg_len); - break; - case ZVERR_RACECOND: - message=(char *)safe_strncpy("Race condition detected, cannot continue.\n\0", msg_len); - break; - case ZVERR_VECTTOOSMALL: - message=(char *)safe_strncpy("Destination vector is smaller than source.\n\0", msg_len); - break; - case ZVERR_VECTDATASIZE: - message=(char *)safe_strncpy("This operation requires two (or more vectors) with the same data size.\n\0", msg_len); - break; - case ZVERR_VECTEMPTY: - message=(char *)safe_strncpy("Vector is empty.\n\0", msg_len); - break; - case ZVERR_OPNOTALLOWED: - message=(char *)safe_strncpy("Operation not allowed.\n\0", msg_len); - break; - default: - message=(char *)safe_strncpy("Unknown error.\n\0", msg_len); - break; - } - } else - message=(char *)safe_strncpy(error_message, msg_len); + if (locally_allocated) { + switch (error_code) { + case ZVERR_VECTUNDEF: + message = (char *)safe_strncpy("Undefined or uninitialized vector.\n\0", msg_len); + break; + case ZVERR_IDXOUTOFBOUND: + message = (char *)safe_strncpy("Index out of bound.\n\0", msg_len); + break; + case ZVERR_OUTOFMEM: + message = (char *)safe_strncpy("Not enough memory to allocate space for the vector.\n\0", msg_len); + break; + case ZVERR_VECTCORRUPTED: + message = (char *)safe_strncpy("Vector corrupted.\n\0", msg_len); + break; + case ZVERR_RACECOND: + message = (char *)safe_strncpy("Race condition detected, cannot continue.\n\0", msg_len); + break; + case ZVERR_VECTTOOSMALL: + message = (char *)safe_strncpy("Destination vector is smaller than source.\n\0", msg_len); + break; + case ZVERR_VECTDATASIZE: + message = (char *)safe_strncpy( + "This operation requires two (or more vectors) with the same data size.\n\0", msg_len); + break; + case ZVERR_VECTEMPTY: + message = (char *)safe_strncpy("Vector is empty.\n\0", msg_len); + break; + case ZVERR_OPNOTALLOWED: + message = (char *)safe_strncpy("Operation not allowed.\n\0", msg_len); + break; + default: + message = (char *)safe_strncpy("Unknown error.\n\0", msg_len); + break; + } + } else { + message = (char *)safe_strncpy(error_message, msg_len); + } - log_msg(ZVLP_ERROR, "Error: %*i, %s\n", 8, error_code, message); - if (locally_allocated) - free((void *)message); + log_msg(ZVLP_ERROR, "Error: %*i, %s\n", 8, error_code, message); + if (locally_allocated) { + free((void *)message); + } - exit(error_code); + exit(error_code); } /*---------------------------------------------------------------------------*/ @@ -343,46 +339,45 @@ static void p_throw_error(const zvect_retval error_code, #if (ZVECT_MEMX_METHOD == 0) ZVECT_ALWAYSINLINE static inline -#endif // ZVECT_MEMX_METHOD -void *p_vect_memcpy(const void *__restrict dst, const void *__restrict src, size_t size) { +#endif // ZVECT_MEMX_METHOD + void * + p_vect_memcpy(const void *__restrict dst, const void *__restrict src, size_t size) { #if (ZVECT_MEMX_METHOD == 0) - // Using regular memcpy - // If you are using ZVector on Linux/macOS/BSD/Windows - // you should stick to this one! - return memcpy((void *)dst, src, size); + // Using regular memcpy + // If you are using ZVector on Linux/macOS/BSD/Windows + // you should stick to this one! + return memcpy((void *)dst, src, size); #elif (ZVECT_MEMX_METHOD == 1) - // Using improved memcpy (where improved means for - // embedded systems only!): - if (size > 0) { - if (((uintptr_t)dst % sizeof(ADDR_TYPE1) == 0) && - ((uintptr_t)src % sizeof(ADDR_TYPE1) == 0) && - (size % sizeof(ADDR_TYPE1) == 0)) { - ADDR_TYPE1 *pExDst = (ADDR_TYPE1 *)dst; - ADDR_TYPE1 const *pExSrc = (ADDR_TYPE1 const *)src; - size_t end = size / sizeof(ADDR_TYPE1); - for (register size_t i = 0; i < end; i++) { - // The following should be compiled as: (-O2 on x86_64) - // mov rdi, QWORD PTR [rsi+rcx] - // mov QWORD PTR [rax+rcx], rdi - *pExDst++ = *pExSrc++; - } - } else { - return memcpy(dst, src, size); - } - } - return dst; -#endif // ZVECT_MEMX_METHOD + // Using improved memcpy (where improved means for + // embedded systems only!): + if (size > 0) { + if (((uintptr_t)dst % sizeof(ADDR_TYPE1) == 0) && ((uintptr_t)src % sizeof(ADDR_TYPE1) == 0) + && (size % sizeof(ADDR_TYPE1) == 0)) { + ADDR_TYPE1 *pExDst = (ADDR_TYPE1 *)dst; + ADDR_TYPE1 const *pExSrc = (ADDR_TYPE1 const *)src; + size_t end = size / sizeof(ADDR_TYPE1); + for (register size_t i = 0; i < end; i++) { + // The following should be compiled as: (-O2 on x86_64) + // mov rdi, QWORD PTR [rsi+rcx] + // mov QWORD PTR [rax+rcx], rdi + *pExDst++ = *pExSrc++; + } + } else { + return memcpy(dst, src, size); + } + } + return dst; +#endif // ZVECT_MEMX_METHOD } ZVECT_ALWAYSINLINE -static inline void *p_vect_memmove(const void *__restrict dst, - const void *__restrict src, size_t size) { +static inline void *p_vect_memmove(const void *__restrict dst, const void *__restrict src, size_t size) { #ifdef DEBUG - log_msg(ZVLP_INFO, "p_vect_memmove: dst %*p\n", 14, dst); - log_msg(ZVLP_INFO, "p_vect_memmove: src %*p\n", 14, src); - log_msg(ZVLP_INFO, "p_vect_memmove: size %*u\n", 14, size); + log_msg(ZVLP_INFO, "p_vect_memmove: dst %*p\n", 14, dst); + log_msg(ZVLP_INFO, "p_vect_memmove: src %*p\n", 14, src); + log_msg(ZVLP_INFO, "p_vect_memmove: size %*u\n", 14, size); #endif - return memmove((void *)dst, src, size); + return memmove((void *)dst, src, size); } /*---------------------------------------------------------------------------*/ @@ -392,95 +387,95 @@ static inline void *p_vect_memmove(const void *__restrict dst, #if (ZVECT_THREAD_SAFE == 1) static volatile bool locking_disabled = false; -# if MUTEX_TYPE == 0 -# define ZVECT_THREAD_SAFE 0 -# elif MUTEX_TYPE == 1 +#if MUTEX_TYPE == 0 +#define ZVECT_THREAD_SAFE 0 +#elif MUTEX_TYPE == 1 ZVECT_ALWAYSINLINE static inline int mutex_lock(pthread_mutex_t *lock) { - return pthread_mutex_lock(lock); + return pthread_mutex_lock(lock); } ZVECT_ALWAYSINLINE static inline int mutex_trylock(pthread_mutex_t *lock) { - return pthread_mutex_trylock(lock); + return pthread_mutex_trylock(lock); } ZVECT_ALWAYSINLINE static inline int mutex_unlock(pthread_mutex_t *lock) { - return pthread_mutex_unlock(lock); + return pthread_mutex_unlock(lock); } static inline void mutex_init(pthread_mutex_t *lock) { -# if (!defined(macOS)) - pthread_mutexattr_t Attr; - pthread_mutexattr_init(&Attr); - pthread_mutexattr_settype(&Attr, PTHREAD_MUTEX_RECURSIVE_NP); - pthread_mutexattr_setpshared(&Attr, PTHREAD_PROCESS_PRIVATE); - pthread_mutexattr_setprotocol(&Attr, PTHREAD_PRIO_INHERIT); - pthread_mutex_init(lock, &Attr); -# else - pthread_mutex_init(lock, NULL); -# endif // macOS +#if (!defined(macOS)) + pthread_mutexattr_t Attr; + pthread_mutexattr_init(&Attr); + pthread_mutexattr_settype(&Attr, PTHREAD_MUTEX_RECURSIVE_NP); + pthread_mutexattr_setpshared(&Attr, PTHREAD_PROCESS_PRIVATE); + pthread_mutexattr_setprotocol(&Attr, PTHREAD_PRIO_INHERIT); + pthread_mutex_init(lock, &Attr); +#else + pthread_mutex_init(lock, NULL); +#endif // macOS } static inline void mutex_cond_init(pthread_cond_t *cond) { -# if (!defined(macOS)) - pthread_condattr_t Attr; - pthread_condattr_init(&Attr); - pthread_condattr_setpshared(&Attr, PTHREAD_PROCESS_PRIVATE); - pthread_cond_init(cond, &Attr); -# else - pthread_cond_init(cond, NULL); -# endif // macOS +#if (!defined(macOS)) + pthread_condattr_t Attr; + pthread_condattr_init(&Attr); + pthread_condattr_setpshared(&Attr, PTHREAD_PROCESS_PRIVATE); + pthread_cond_init(cond, &Attr); +#else + pthread_cond_init(cond, NULL); +#endif // macOS } static inline void mutex_destroy(pthread_mutex_t *lock) { - pthread_mutex_destroy(lock); + pthread_mutex_destroy(lock); } static inline int semaphore_init -# if !defined(macOS) - (sem_t *sem, int value) { - return sem_init(sem, 0, value); -# else - (dispatch_semaphore_t *sem, int value) { - *sem = dispatch_semaphore_create(value); - return 0; -# endif +#if !defined(macOS) + (sem_t *sem, int value) { + return sem_init(sem, 0, value); +#else + (dispatch_semaphore_t *sem, int value) { + *sem = dispatch_semaphore_create(value); + return 0; +#endif } static inline int semaphore_destroy -# if !defined(macOS) - (sem_t *sem) { - return sem_destroy(sem); -# else - (dispatch_semaphore_t *sem) { - return 0; // dispatch_semaphore_destroy(sem); - (void)sem; -# endif +#if !defined(macOS) + (sem_t *sem) { + return sem_destroy(sem); +#else + (dispatch_semaphore_t *sem) { + return 0; // dispatch_semaphore_destroy(sem); + (void)sem; +#endif } -# elif MUTEX_TYPE == 2 +#elif MUTEX_TYPE == 2 static inline void mutex_lock(CRITICAL_SECTION *lock) { - EnterCriticalSection(lock); + EnterCriticalSection(lock); } static inline void mutex_unlock(CRITICAL_SECTION *lock) { - LeaveCriticalSection(lock); + LeaveCriticalSection(lock); } static inline void mutex_alloc(CRITICAL_SECTION *lock) { - // InitializeCriticalSection(lock); - InitializeCriticalSectionAndSpinCount(lock, 32); + // InitializeCriticalSection(lock); + InitializeCriticalSectionAndSpinCount(lock, 32); } static inline void mutex_destroy(CRITICAL_SECTION *lock) { - DeleteCriticalSection(lock); + DeleteCriticalSection(lock); } -# endif // MUTEX_TYPE -#endif // ZVECT_THREAD_SAFE +#endif // MUTEX_TYPE +#endif // ZVECT_THREAD_SAFE #if (ZVECT_THREAD_SAFE == 1) // The following two functions are generic locking functions @@ -497,34 +492,34 @@ static inline void mutex_destroy(CRITICAL_SECTION *lock) { * level 3 is the priority of the User's locks. */ static inline zvect_retval get_mutex_lock(const vector v, const int32_t lock_type) { - if (lock_type >= v->lock_type) { - mutex_lock(&(v->lock)); - v->lock_type = lock_type; - return 1; - } - return 0; + if (lock_type >= v->lock_type) { + mutex_lock(&(v->lock)); + v->lock_type = lock_type; + return 1; + } + return 0; } static inline zvect_retval check_mutex_trylock(const vector v, const int32_t lock_type) { - if ((lock_type >= v->lock_type) && (!mutex_trylock(&(v->lock)))) { - v->lock_type = lock_type; - return 1; - } - return 0; + if ((lock_type >= v->lock_type) && (!mutex_trylock(&(v->lock)))) { + v->lock_type = lock_type; + return 1; + } + return 0; } static inline zvect_retval lock_after_signal(const vector v, const int32_t lock_type) { - if (lock_type >= v->lock_type) { - //if (!mutex_trylock(&(v->lock))) { - while (!pthread_cond_wait(&(v->cond), &(v->lock))) { - // wait until we get a signal - } - //mutex_lock(&(v->lock)); - v->lock_type = lock_type; - return 1; - //} - } - return 0; + if (lock_type >= v->lock_type) { + //if (!mutex_trylock(&(v->lock))) { + while (!pthread_cond_wait(&(v->cond), &(v->lock))) { + // wait until we get a signal + } + //mutex_lock(&(v->lock)); + v->lock_type = lock_type; + return 1; + //} + } + return 0; } /* @@ -545,22 +540,22 @@ static inline zvect_retval wait_for_signal(const vector v, const int32_t lock_ty */ static inline zvect_retval send_signal(const vector v, const int32_t lock_type) { - return (lock_type >= v->lock_type) ? pthread_cond_signal(&(v->cond)) : 0; + return (lock_type >= v->lock_type) ? pthread_cond_signal(&(v->cond)) : 0; } static inline zvect_retval broadcast_signal(const vector v, const int32_t lock_type) { - return (lock_type >= v->lock_type) ? pthread_cond_broadcast(&(v->cond)) : 0; + return (lock_type >= v->lock_type) ? pthread_cond_broadcast(&(v->cond)) : 0; } static inline zvect_retval get_mutex_unlock(const vector v, const int32_t lock_type) { - if (lock_type == v->lock_type) { - v->lock_type = 0; - mutex_unlock(&(v->lock)); - return 1; - } - return 0; + if (lock_type == v->lock_type) { + v->lock_type = 0; + mutex_unlock(&(v->lock)); + return 1; + } + return 0; } -#endif // ZVECT_THREAD_SAFE +#endif // ZVECT_THREAD_SAFE /*---------------------------------------------------------------------------*/ /***************************************************************************** @@ -572,14 +567,14 @@ static inline zvect_retval get_mutex_unlock(const vector v, const int32_t lock_t void p_init_zvect(void) { #if (OS_TYPE == 1) -# if ( !defined(macOS) ) - //mallopt(M_MXFAST, 196*sizeof(size_t)/4); -# endif -#endif // OS_TYPE == 1 +#if (!defined(macOS)) + //mallopt(M_MXFAST, 196*sizeof(size_t)/4); +#endif +#endif // OS_TYPE == 1 - // We are done initialising ZVector so set the following - // to one, so this function will no longer be called: - p_init_state = 1; + // We are done initialising ZVector so set the following + // to one, so this function will no longer be called: + p_init_state = 1; } /*---------------------------------------------------------------------------*/ @@ -589,92 +584,96 @@ void p_init_zvect(void) { ZVECT_ALWAYSINLINE static inline zvect_retval p_vect_check(const vector x) { - return (x == NULL) ? ZVERR_VECTUNDEF : 0; + return (x == NULL) ? ZVERR_VECTUNDEF : 0; } ZVECT_ALWAYSINLINE static inline zvect_index p_vect_capacity(const vector v) { - return ( v->cap_left + v->cap_right ); + return (v->cap_left + v->cap_right); } ZVECT_ALWAYSINLINE static inline zvect_index p_vect_size(const vector v) { - return ( v->end > v->begin ) ? ( v->end - v->begin ) : ( v->begin - v->end ); + return (v->end > v->begin) ? (v->end - v->begin) : (v->begin - v->end); } static inline void p_item_safewipe(vector const v, void *const item) { - if (item != NULL) { - if (!(v->status & ZVS_CUST_WIPE_ON)) { - memset(item, 0, v->data_size); - } else { - (*(v->SfWpFunc))(item, v->data_size); - } - } + if (item != NULL) { + if (!(v->status & ZVS_CUST_WIPE_ON)) { + memset(item, 0, v->data_size); + } else { + (*(v->SfWpFunc))(item, v->data_size); + } + } } ZVECT_ALWAYSINLINE -static inline zvect_retval p_usr_status(zvect_index flag_id) -{ - switch (flag_id) { - case 1: return 0; - break; - default: return 1; - } +static inline zvect_retval p_usr_status(zvect_index flag_id) { + switch (flag_id) { + case 1: + return 0; + break; + default: + return 1; + } } -bool vect_check_status(const vector v, zvect_index flag_id) -{ - return (v->status >> flag_id) & 1U; +bool vect_check_status(const vector v, zvect_index flag_id) { + return (v->status >> flag_id) & 1U; } -bool vect_set_status(const vector v, zvect_index flag_id) -{ - zvect_retval rval = p_usr_status(flag_id); +bool vect_set_status(const vector v, zvect_index flag_id) { + zvect_retval rval = p_usr_status(flag_id); - if (!rval) - v->status |= 1UL << flag_id; + if (!rval) { + v->status |= 1UL << flag_id; + } - return (bool)rval; + return (bool)rval; } -bool vect_clear_status(const vector v, zvect_index flag_id) -{ - zvect_retval rval = p_usr_status(flag_id); +bool vect_clear_status(const vector v, zvect_index flag_id) { + zvect_retval rval = p_usr_status(flag_id); - if (!rval) - v->status &= ~(1UL << flag_id); + if (!rval) { + v->status &= ~(1UL << flag_id); + } - return (bool)rval; + return (bool)rval; } -bool vect_toggle_status(const vector v, zvect_index flag_id) -{ - zvect_retval rval = p_usr_status(flag_id); +bool vect_toggle_status(const vector v, zvect_index flag_id) { + zvect_retval rval = p_usr_status(flag_id); - if (!rval) - v->status ^= (1UL << flag_id); + if (!rval) { + v->status ^= (1UL << flag_id); + } - return rval; + return rval; } static void p_free_items(vector const v, zvect_index first, zvect_index offset) { - if (p_vect_size(v) == 0) - return; + if (p_vect_size(v) == 0) { + return; + } - for (register zvect_index j = (first + offset); j >= first; j--) { - if (v->data[v->begin + j] != NULL) { - if (v->flags & ZV_SEC_WIPE) - p_item_safewipe(v, v->data[v->begin + j]); - if (!(v->flags & ZV_BYREF)) - free(v->data[v->begin + j]); - } - if (j == first) - break; // this is required if we are using - // uint and the first element is element - // 0, because on GCC an uint will fail - // then check in the for loop if j >= first - // in this particular case! - } + for (register zvect_index j = (first + offset); j >= first; j--) { + if (v->data[v->begin + j] != NULL) { + if (v->flags & ZV_SEC_WIPE) { + p_item_safewipe(v, v->data[v->begin + j]); + } + if (!(v->flags & ZV_BYREF)) { + free(v->data[v->begin + j]); + } + } + if (j == first) { + break; // this is required if we are using + // uint and the first element is element + // 0, because on GCC an uint will fail + // then check in the for loop if j >= first + // in this particular case! + } + } } /*---------------------------------------------------------------------------*/ @@ -685,155 +684,159 @@ static void p_free_items(vector const v, zvect_index first, zvect_index offset) /* * Set vector capacity to a specific new_capacity value */ -static zvect_retval p_vect_set_capacity(vector const v, const zvect_index direction, const zvect_index new_capacity_) -{ - zvect_index new_capacity = new_capacity_; +static zvect_retval p_vect_set_capacity(vector const v, const zvect_index direction, const zvect_index new_capacity_) { + zvect_index new_capacity = new_capacity_; - if ( new_capacity <= v->init_capacity ) - new_capacity = v->init_capacity; + if (new_capacity <= v->init_capacity) { + new_capacity = v->init_capacity; + } - void **new_data = NULL; - if (!direction) - { + void **new_data = NULL; + if (!direction) { - // Set capacity on the left side of the vector to new_capacity: - new_data = (void **)malloc(sizeof(void *) * (new_capacity + v->cap_right)); - if (new_data == NULL) - return ZVERR_OUTOFMEM; + // Set capacity on the left side of the vector to new_capacity: + new_data = (void **)malloc(sizeof(void *) * (new_capacity + v->cap_right)); + if (new_data == NULL) { + return ZVERR_OUTOFMEM; + } - zvect_index nb; - zvect_index ne; - nb = v->cap_left; - ne = ( nb + (v->end - v->begin) ); - if (v->end != v->begin) - p_vect_memcpy(new_data + nb, v->data + v->begin, sizeof(void *) * (v->end - v->begin) ); + zvect_index nb; + zvect_index ne; + nb = v->cap_left; + ne = (nb + (v->end - v->begin)); + if (v->end != v->begin) { + p_vect_memcpy(new_data + nb, v->data + v->begin, sizeof(void *) * (v->end - v->begin)); + } - // Reconfigure vector: - v->cap_left = new_capacity; - v->end = ne; - v->begin = nb; - free(v->data); + // Reconfigure vector: + v->cap_left = new_capacity; + v->end = ne; + v->begin = nb; + free(v->data); - } else { + } else { - // Set capacity on the right side of the vector to new_capacity: - new_data = (void **)realloc(v->data, sizeof(void *) * (v->cap_left + new_capacity)); - if (new_data == NULL) - return ZVERR_OUTOFMEM; + // Set capacity on the right side of the vector to new_capacity: + new_data = (void **)realloc(v->data, sizeof(void *) * (v->cap_left + new_capacity)); + if (new_data == NULL) { + return ZVERR_OUTOFMEM; + } - // Reconfigure Vector: - v->cap_right = new_capacity; - } + // Reconfigure Vector: + v->cap_right = new_capacity; + } - // Apply changes - v->data = new_data; + // Apply changes + v->data = new_data; - // done - return 0; + // done + return 0; } /* * This function increase the CAPACITY of a vector. */ static zvect_retval p_vect_increase_capacity(vector const v, const zvect_index direction) { - zvect_index new_capacity; + zvect_index new_capacity; - if (!direction) - { + if (!direction) { - // Increase capacity on the left side of the vector: + // Increase capacity on the left side of the vector: - // Get actual left capacity and double it - // Note: "<< 1" is the same as "* 2" - // this is an optimisation for old - // compilers. - new_capacity = v->cap_left << 1; + // Get actual left capacity and double it + // Note: "<< 1" is the same as "* 2" + // this is an optimisation for old + // compilers. + new_capacity = v->cap_left << 1; - } else { + } else { - // Increase capacity on the right side of the vector: + // Increase capacity on the right side of the vector: - // Get actual left capacity and double it - // Note: "<< 1" is the same as "* 2" - // this is an optimisation for old - // compilers. - new_capacity = v->cap_right << 1; + // Get actual left capacity and double it + // Note: "<< 1" is the same as "* 2" + // this is an optimisation for old + // compilers. + new_capacity = v->cap_right << 1; + } - } + zvect_retval rval = p_vect_set_capacity(v, direction, new_capacity); - zvect_retval rval = p_vect_set_capacity(v, direction, new_capacity); - - // done - return rval; + // done + return rval; } /* * This function decrease the CAPACITY of a vector. */ static zvect_retval p_vect_decrease_capacity(vector const v, const zvect_index direction) { - // Check if new capacity is smaller than initial capacity - if ( p_vect_capacity(v) <= v->init_capacity) - return 0; + // Check if new capacity is smaller than initial capacity + if (p_vect_capacity(v) <= v->init_capacity) { + return 0; + } - zvect_index new_capacity; + zvect_index new_capacity; - void **new_data = NULL; - if (!direction) - { - // Decreasing on the left: + void **new_data = NULL; + if (!direction) { + // Decreasing on the left: - // Note: ">> 1" is the same as "/ 2" - // this is an optimisation for old - // compilers. - new_capacity = v->cap_left >> 1; + // Note: ">> 1" is the same as "/ 2" + // this is an optimisation for old + // compilers. + new_capacity = v->cap_left >> 1; - if (new_capacity < ( v->init_capacity >> 1 )) - new_capacity = v->init_capacity >> 1; + if (new_capacity < (v->init_capacity >> 1)) { + new_capacity = v->init_capacity >> 1; + } - new_capacity = max( (p_vect_size(v) >> 1), new_capacity); + new_capacity = max((p_vect_size(v) >> 1), new_capacity); - new_data = (void **)malloc(sizeof(void *) * (new_capacity + v->cap_right)); - if (new_data == NULL) - return ZVERR_OUTOFMEM; + new_data = (void **)malloc(sizeof(void *) * (new_capacity + v->cap_right)); + if (new_data == NULL) { + return ZVERR_OUTOFMEM; + } - zvect_index nb; - zvect_index ne; - nb = ( new_capacity >> 1); - ne = ( nb + (v->end - v->begin) ); - p_vect_memcpy(new_data + nb, v->data + v->begin, sizeof(void *) * (v->end - v->begin) ); + zvect_index nb; + zvect_index ne; + nb = (new_capacity >> 1); + ne = (nb + (v->end - v->begin)); + p_vect_memcpy(new_data + nb, v->data + v->begin, sizeof(void *) * (v->end - v->begin)); - // Reconfigure Vector: - v->cap_left = new_capacity; - v->end = ne; - v->begin = nb; - free(v->data); + // Reconfigure Vector: + v->cap_left = new_capacity; + v->end = ne; + v->begin = nb; + free(v->data); - } else { + } else { - // Decreasing on the right: - // Note: ">> 1" is the same as "/ 2" - // this is an optimisation for old - // compilers. - new_capacity = v->cap_right >> 1; + // Decreasing on the right: + // Note: ">> 1" is the same as "/ 2" + // this is an optimisation for old + // compilers. + new_capacity = v->cap_right >> 1; - if (new_capacity < ( v->init_capacity >> 1 )) - new_capacity = v->init_capacity >> 1; + if (new_capacity < (v->init_capacity >> 1)) { + new_capacity = v->init_capacity >> 1; + } - new_capacity = max( (p_vect_size(v) >> 1), new_capacity); + new_capacity = max((p_vect_size(v) >> 1), new_capacity); - new_data = (void **)realloc(v->data, sizeof(void *) * (v->cap_left + new_capacity)); - if (new_data == NULL) - return ZVERR_OUTOFMEM; + new_data = (void **)realloc(v->data, sizeof(void *) * (v->cap_left + new_capacity)); + if (new_data == NULL) { + return ZVERR_OUTOFMEM; + } - // Reconfigure vector: - v->cap_right = new_capacity; - } + // Reconfigure vector: + v->cap_right = new_capacity; + } - // Apply changes - v->data = new_data; + // Apply changes + v->data = new_data; - // done: - return 0; + // done: + return 0; } /* @@ -842,45 +845,49 @@ static zvect_retval p_vect_decrease_capacity(vector const v, const zvect_index d * need to remove items from it. */ static zvect_retval p_vect_shrink(vector const v) { - if (v->init_capacity < 2) - v->init_capacity = 2; + if (v->init_capacity < 2) { + v->init_capacity = 2; + } - if (p_vect_capacity(v) == v->init_capacity || p_vect_capacity(v) <= p_vect_size(v)) - return 0; + if (p_vect_capacity(v) == v->init_capacity || p_vect_capacity(v) <= p_vect_size(v)) { + return 0; + } - // Determine the correct shrunk size: - zvect_index new_capacity; - if (p_vect_size(v) < v->init_capacity) - new_capacity = v->init_capacity; - else - new_capacity = p_vect_size(v) + 2; + // Determine the correct shrunk size: + zvect_index new_capacity; + if (p_vect_size(v) < v->init_capacity) { + new_capacity = v->init_capacity; + } else { + new_capacity = p_vect_size(v) + 2; + } - // shrink the vector: - // Given that zvector supports vectors that can grow on the left and on the right - // I cannot use realloc here. - void **new_data = (void **)malloc(sizeof(void *) * new_capacity); - if (new_data == NULL) - return ZVERR_OUTOFMEM; + // shrink the vector: + // Given that zvector supports vectors that can grow on the left and on the right + // I cannot use realloc here. + void **new_data = (void **)malloc(sizeof(void *) * new_capacity); + if (new_data == NULL) { + return ZVERR_OUTOFMEM; + } - zvect_index ne; - zvect_index nb; - // Note: ">> 1" is the same as "/ 2" - // this is an optimisation for old - // compilers. - nb = ( new_capacity >> 1 ); - ne = ( nb + (v->end - v->begin) ); - p_vect_memcpy(new_data + nb, v->data + v->begin, sizeof(void *) * (v->end - v->begin) ); + zvect_index ne; + zvect_index nb; + // Note: ">> 1" is the same as "/ 2" + // this is an optimisation for old + // compilers. + nb = (new_capacity >> 1); + ne = (nb + (v->end - v->begin)); + p_vect_memcpy(new_data + nb, v->data + v->begin, sizeof(void *) * (v->end - v->begin)); - // Apply changes: - free(v->data); - v->data = new_data; - v->end = ne; - v->begin = nb; - v->cap_left = new_capacity >> 1; - v->cap_right = new_capacity >> 1; + // Apply changes: + free(v->data); + v->data = new_data; + v->end = ne; + v->begin = nb; + v->cap_left = new_capacity >> 1; + v->cap_right = new_capacity >> 1; - // done: - return 0; + // done: + return 0; } /*---------------------------------------------------------------------------*/ @@ -889,347 +896,365 @@ static zvect_retval p_vect_shrink(vector const v) { // Creation and destruction primitives: zvect_retval p_vect_clear(vector const v) { - // Clear the vector: - if (!vect_is_empty(v)) - p_free_items(v, 0, (p_vect_size(v) - 1)); + // Clear the vector: + if (!vect_is_empty(v)) { + p_free_items(v, 0, (p_vect_size(v) - 1)); + } - // Reset interested descriptors: - v->begin = v->end = 0; + // Reset interested descriptors: + v->begin = v->end = 0; - // Shrink Vector's capacity: - // p_vect_shrink(v); // commented this out to make vect_clear behave more like the clear method in C++ + // Shrink Vector's capacity: + // p_vect_shrink(v); // commented this out to make vect_clear behave more like the clear method in C++ - return 0; + return 0; } static zvect_retval p_vect_destroy(vector v, uint32_t flags) { - // p_destroy is an exception to the rule of handling - // locking from the public methods. This because - // p_destroy has to destroy the vector mutex too and - // so it needs to control the lock as well! + // p_destroy is an exception to the rule of handling + // locking from the public methods. This because + // p_destroy has to destroy the vector mutex too and + // so it needs to control the lock as well! #if (ZVECT_THREAD_SAFE == 1) - zvect_retval lock_owner = (locking_disabled || (v->flags & ZV_NOLOCKING)) ? 0 : get_mutex_lock(v, 1); - if (!lock_owner && (!locking_disabled) && !(v->flags & ZV_NOLOCKING)) - return ZVERR_RACECOND; + zvect_retval lock_owner = (locking_disabled || (v->flags & ZV_NOLOCKING)) ? 0 : get_mutex_lock(v, 1); + if (!lock_owner && (!locking_disabled) && !(v->flags & ZV_NOLOCKING)) { + return ZVERR_RACECOND; + } #endif - // Clear the vector (if LSB of flags is set to 1): - if ((p_vect_size(v) > 0) && (flags & 1)) { - // Clean the vector: - p_vect_clear(v); + // Clear the vector (if LSB of flags is set to 1): + if ((p_vect_size(v) > 0) && (flags & 1)) { + // Clean the vector: + p_vect_clear(v); - // Reset interested descriptors: - v->end = 0; - } + // Reset interested descriptors: + v->end = 0; + } - // Destroy the vector: - v->init_capacity = v->cap_left = v->cap_right = 0; + // Destroy the vector: + v->init_capacity = v->cap_left = v->cap_right = 0; - // Destroy it: - if (v->status & ZVS_CUST_WIPE_ON) - v->SfWpFunc = NULL; + // Destroy it: + if (v->status & ZVS_CUST_WIPE_ON) { + v->SfWpFunc = NULL; + } - if (v->data != NULL) { - free(v->data); - v->data = NULL; - } + if (v->data != NULL) { + free(v->data); + v->data = NULL; + } - // Clear vector status flags: - v->status = v->flags = v->begin = v->end = v->data_size = v->balance = v->bottom = 0; + // Clear vector status flags: + v->status = v->flags = v->begin = v->end = v->data_size = v->balance = v->bottom = 0; #if (ZVECT_THREAD_SAFE == 1) - if ( lock_owner ) - get_mutex_unlock(v, v->lock_type); - mutex_destroy(&(v->lock)); - semaphore_destroy(&(v->semaphore)); + if (lock_owner) { + get_mutex_unlock(v, v->lock_type); + } + mutex_destroy(&(v->lock)); + semaphore_destroy(&(v->semaphore)); #endif - // All done and freed, so we can safely - // free the vector itself: - free(v); + // All done and freed, so we can safely + // free the vector itself: + free(v); - return 0; + return 0; } /*---------------------------------------------------------------------------*/ - /*---------------------------------------------------------------------------*/ // Vector data storage primitives: // inline implementation for all put: -static inline zvect_retval p_vect_put_at(vector const v, const void *value, - const zvect_index i) { - // Check if the index passed is out of bounds: - zvect_index idx = i; - if (!(v->flags & ZV_CIRCULAR)) - { - if (idx >= p_vect_size(v)) - return ZVERR_IDXOUTOFBOUND; - } else { - if (idx >= p_vect_size(v)) - idx = i % v->init_capacity; - } +static inline zvect_retval p_vect_put_at(vector const v, const void *value, const zvect_index i) { + // Check if the index passed is out of bounds: + zvect_index idx = i; + if (!(v->flags & ZV_CIRCULAR)) { + if (idx >= p_vect_size(v)) { + return ZVERR_IDXOUTOFBOUND; + } + } else { + if (idx >= p_vect_size(v)) { + idx = i % v->init_capacity; + } + } - // Add value at the specified index, considering - // if the vector has ZV_BYREF property enabled: - if ( v->flags & ZV_BYREF ) { - void *temp = v->data[v->begin + idx]; - v->data[v->begin + idx] = (void *)value; - if ( v->flags & ZV_SEC_WIPE ) - memset((void *)temp, 0, v->data_size); - } else { - p_vect_memcpy(v->data[v->begin + idx], value, v->data_size); - } + // Add value at the specified index, considering + // if the vector has ZV_BYREF property enabled: + if (v->flags & ZV_BYREF) { + void *temp = v->data[v->begin + idx]; + v->data[v->begin + idx] = (void *)value; + if (v->flags & ZV_SEC_WIPE) { + memset((void *)temp, 0, v->data_size); + } + } else { + p_vect_memcpy(v->data[v->begin + idx], value, v->data_size); + } - // done - return 0; + // done + return 0; } // inline implementation for all add(s): -static inline zvect_retval p_vect_add_at(vector const v, const void *value, - const zvect_index i) { - zvect_index idx = i; +static inline zvect_retval p_vect_add_at(vector const v, const void *value, const zvect_index i) { + zvect_index idx = i; - // Get vector size: - zvect_index vsize = p_vect_size(v); + // Get vector size: + zvect_index vsize = p_vect_size(v); #if (ZVECT_FULL_REENTRANT == 1) - // If we are in FULL_REENTRANT MODE prepare for potential - // array copy: - void **new_data = NULL; - if (idx < vsize) { - new_data = (void **)malloc(sizeof(void *) * p_vect_capacity(v)); - if (new_data == NULL) - return ZVERR_OUTOFMEM; - } + // If we are in FULL_REENTRANT MODE prepare for potential + // array copy: + void **new_data = NULL; + if (idx < vsize) { + new_data = (void **)malloc(sizeof(void *) * p_vect_capacity(v)); + if (new_data == NULL) { + return ZVERR_OUTOFMEM; + } + } #endif - // Allocate memory for the new item: - zvect_index base = v->begin; - if (!idx) { - // Prepare left side of the vector: - if ( base ) - base--; - if (!(v->flags & ZV_BYREF)) { - v->data[base] = (void *)malloc(v->data_size); - if (v->data[base] == NULL) - return ZVERR_OUTOFMEM; - } - } else if (idx == vsize && !(v->flags & ZV_BYREF)) { - // Prepare right side of the vector: - v->data[base + vsize] = (void *)malloc(v->data_size); - if (v->data[base + vsize] == NULL) - return ZVERR_OUTOFMEM; - } + // Allocate memory for the new item: + zvect_index base = v->begin; + if (!idx) { + // Prepare left side of the vector: + if (base) { + base--; + } + if (!(v->flags & ZV_BYREF)) { + v->data[base] = (void *)malloc(v->data_size); + if (v->data[base] == NULL) { + return ZVERR_OUTOFMEM; + } + } + } else if (idx == vsize && !(v->flags & ZV_BYREF)) { + // Prepare right side of the vector: + v->data[base + vsize] = (void *)malloc(v->data_size); + if (v->data[base + vsize] == NULL) { + return ZVERR_OUTOFMEM; + } + } - // "Shift" right the array of one position to make space for the new item: - int16_t array_changed = 0; + // "Shift" right the array of one position to make space for the new item: + int16_t array_changed = 0; - if ((idx < vsize) && (idx != 0)) { - array_changed = 1; + if ((idx < vsize) && (idx != 0)) { + array_changed = 1; #if (ZVECT_FULL_REENTRANT == 1) - // Algorithm to try to copy an array of pointers as fast as possible: - if (idx > 0) - p_vect_memcpy(new_data + base, v->data + base, sizeof(void *) * idx); - p_vect_memcpy(new_data + base + (idx + 1), v->data + base + idx, - sizeof(void *) * (vsize - idx)); + // Algorithm to try to copy an array of pointers as fast as possible: + if (idx > 0) { + p_vect_memcpy(new_data + base, v->data + base, sizeof(void *) * idx); + } + p_vect_memcpy(new_data + base + (idx + 1), v->data + base + idx, sizeof(void *) * (vsize - idx)); #else - // We can't use the vect_memcpy when not in full reentrant code - // because it's not safe to use it on the same src and dst. - p_vect_memmove(v->data + base + (idx + 1), v->data + base + idx, - sizeof(void *) * (vsize - idx)); -#endif // (ZVECT_FULL_REENTRANT == 1) - } + // We can't use the vect_memcpy when not in full reentrant code + // because it's not safe to use it on the same src and dst. + p_vect_memmove(v->data + base + (idx + 1), v->data + base + idx, sizeof(void *) * (vsize - idx)); +#endif // (ZVECT_FULL_REENTRANT == 1) + } - // Add new value in (at the index i): + // Add new value in (at the index i): #if (ZVECT_FULL_REENTRANT == 1) - if (array_changed) { - if (v->flags & ZV_BYREF) { - new_data[base + idx] = (void *)value; - } else { - new_data[base + idx] = (void *)malloc(v->data_size); - if (new_data[base + idx] == NULL) - return ZVERR_OUTOFMEM; - p_vect_memcpy(new_data[base + idx], value, v->data_size); - } - } else { - if (v->flags & ZV_BYREF) - v->data[base + idx] = (void *)value; - else - p_vect_memcpy(v->data[base + idx], value, v->data_size); - } + if (array_changed) { + if (v->flags & ZV_BYREF) { + new_data[base + idx] = (void *)value; + } else { + new_data[base + idx] = (void *)malloc(v->data_size); + if (new_data[base + idx] == NULL) { + return ZVERR_OUTOFMEM; + } + p_vect_memcpy(new_data[base + idx], value, v->data_size); + } + } else { + if (v->flags & ZV_BYREF) { + v->data[base + idx] = (void *)value; + } else { + p_vect_memcpy(v->data[base + idx], value, v->data_size); + } + } #else - if (array_changed && !(v->flags & ZV_BYREF)) { - // We moved chunks of memory, so we need to - // allocate new memory for the item at position i: - v->data[base + idx] = malloc(v->data_size); - if (v->data[base + idx] == NULL) - return ZVERR_OUTOFMEM; - } - if (v->flags & ZV_BYREF) - v->data[base + idx] = (void *)value; - else - p_vect_memcpy(v->data[base + idx], value, v->data_size); -#endif // (ZVECT_FULL_REENTRANT == 1) + if (array_changed && !(v->flags & ZV_BYREF)) { + // We moved chunks of memory, so we need to + // allocate new memory for the item at position i: + v->data[base + idx] = malloc(v->data_size); + if (v->data[base + idx] == NULL) { + return ZVERR_OUTOFMEM; + } + } + if (v->flags & ZV_BYREF) { + v->data[base + idx] = (void *)value; + } else { + p_vect_memcpy(v->data[base + idx], value, v->data_size); + } +#endif // (ZVECT_FULL_REENTRANT == 1) - // Apply changes: + // Apply changes: #if (ZVECT_FULL_REENTRANT == 1) - if (array_changed) { - free(v->data); - v->data = new_data; - } + if (array_changed) { + free(v->data); + v->data = new_data; + } #endif - // Increment vector size - if (!idx) { - if (v->begin == base) - v->end++; - else - v->begin = base; - } else { - v->end++; - } + // Increment vector size + if (!idx) { + if (v->begin == base) { + v->end++; + } else { + v->begin = base; + } + } else { + v->end++; + } - // done - return 0; + // done + return 0; #if (ZVECT_FULL_REENTRANT == 1) - UNUSED(new_data); + UNUSED(new_data); #endif } // This is the inline implementation for all the remove and pop static inline zvect_retval p_vect_remove_at(vector const v, const zvect_index i, void **item) { - zvect_index idx = i; + zvect_index idx = i; - // Get the vector size: - zvect_index vsize = p_vect_size(v); + // Get the vector size: + zvect_index vsize = p_vect_size(v); - // Check if the index is out of bounds: - if (idx >= vsize) { - if (!(v->flags & ZV_CIRCULAR)) { - return ZVERR_IDXOUTOFBOUND; - } else { - idx = idx % vsize; - } - } + // Check if the index is out of bounds: + if (idx >= vsize) { + if (!(v->flags & ZV_CIRCULAR)) { + return ZVERR_IDXOUTOFBOUND; + } else { + idx = idx % vsize; + } + } - // Check if the vector got corrupted - if ((v->end != 0) && (v->begin > v->end)) - return ZVERR_VECTCORRUPTED; + // Check if the vector got corrupted + if ((v->end != 0) && (v->begin > v->end)) { + return ZVERR_VECTCORRUPTED; + } - // Start processing the vector: + // Start processing the vector: #if (ZVECT_FULL_REENTRANT == 1) - // Allocate memory for support Data Structure: - void **new_data = (void **)malloc(sizeof(void *) * p_vect_capacity(v)); - if (new_data == NULL) - return ZVERR_OUTOFMEM; + // Allocate memory for support Data Structure: + void **new_data = (void **)malloc(sizeof(void *) * p_vect_capacity(v)); + if (new_data == NULL) { + return ZVERR_OUTOFMEM; + } #endif - // Get the value we are about to remove: - // If the vector is set as ZV_BYREF, then just copy the pointer to the item - // If the vector is set as regular, then copy the item - zvect_index base = v->begin; - if (v->flags & ZV_BYREF) { - *item = v->data[base + idx]; - } else { - *item = (void **)malloc(v->data_size); - if ( v->data[base + idx] != NULL ) - { - p_vect_memcpy(*item, v->data[base + idx], v->data_size); + // Get the value we are about to remove: + // If the vector is set as ZV_BYREF, then just copy the pointer to the item + // If the vector is set as regular, then copy the item + zvect_index base = v->begin; + if (v->flags & ZV_BYREF) { + *item = v->data[base + idx]; + } else { + *item = (void **)malloc(v->data_size); + if (v->data[base + idx] != NULL) { + p_vect_memcpy(*item, v->data[base + idx], v->data_size); - // If the vector is set for secure wipe, and we copied the item - // then we need to wipe the old copy: - if (v->flags & ZV_SEC_WIPE) - p_item_safewipe(v, v->data[base + idx]); - } /* else { + // If the vector is set for secure wipe, and we copied the item + // then we need to wipe the old copy: + if (v->flags & ZV_SEC_WIPE) { + p_item_safewipe(v, v->data[base + idx]); + } + } /* else { memset(item, 0, v->data_size - 1); } */ - } + } - // "shift" left the array of one position: - uint16_t array_changed; - array_changed = 0; - if ( idx != 0 ) { - if ((idx < (vsize - 1)) && (vsize > 0)) { - array_changed = 1; - free(v->data[base + idx]); + // "shift" left the array of one position: + uint16_t array_changed; + array_changed = 0; + if (idx != 0) { + if ((idx < (vsize - 1)) && (vsize > 0)) { + array_changed = 1; + free(v->data[base + idx]); #if (ZVECT_FULL_REENTRANT == 1) - p_vect_memcpy(new_data + base, v->data + base, sizeof(void *) * idx); - p_vect_memcpy(new_data + base + idx, v->data + base + (idx + 1), - sizeof(void *) * (vsize - idx)); + p_vect_memcpy(new_data + base, v->data + base, sizeof(void *) * idx); + p_vect_memcpy(new_data + base + idx, v->data + base + (idx + 1), sizeof(void *) * (vsize - idx)); #else - // We can't use the vect_memcpy when not in full reentrant code - // because it's not safe to use it on the same src and dst. - p_vect_memmove(v->data + (base + idx), v->data + (base + (idx + 1)), - sizeof(void *) * (vsize - idx)); + // We can't use the vect_memcpy when not in full reentrant code + // because it's not safe to use it on the same src and dst. + p_vect_memmove(v->data + (base + idx), v->data + (base + (idx + 1)), sizeof(void *) * (vsize - idx)); - // Clear leftover item pointers: - memset(v->data[(v->begin + vsize) - 1], 0, 1); + // Clear leftover item pointers: + memset(v->data[(v->begin + vsize) - 1], 0, 1); #endif - } - } else { - if ( base < v->end ) { - array_changed = 1; - if (v->data[base] != NULL) - free(v->data[base]); - } - } + } + } else { + if (base < v->end) { + array_changed = 1; + if (v->data[base] != NULL) { + free(v->data[base]); + } + } + } - // Reduce vector size: + // Reduce vector size: #if (ZVECT_FULL_REENTRANT == 0) - if (!(v->flags & ZV_BYREF) && !array_changed) - p_free_items(v, vsize - 1, 0); + if (!(v->flags & ZV_BYREF) && !array_changed) { + p_free_items(v, vsize - 1, 0); + } #else - // Apply changes - if (array_changed) { - free(v->data); - v->data = new_data; - } + // Apply changes + if (array_changed) { + free(v->data); + v->data = new_data; + } #endif - if (!(v->flags & ZV_CIRCULAR)) { - if ( idx != 0 ) { - if (v->end > v->begin) { - v->end--; - } else { - v->end = v->begin; - } - } else { - if (v->begin < v->end) { - v->begin++; - } else { - v->begin = v->end; - } - } - // Check if we need to shrink vector's capacity: - if ((4 * vsize) < p_vect_capacity(v) ) - p_vect_decrease_capacity(v, idx); - } + if (!(v->flags & ZV_CIRCULAR)) { + if (idx != 0) { + if (v->end > v->begin) { + v->end--; + } else { + v->end = v->begin; + } + } else { + if (v->begin < v->end) { + v->begin++; + } else { + v->begin = v->end; + } + } + // Check if we need to shrink vector's capacity: + if ((4 * vsize) < p_vect_capacity(v)) { + p_vect_decrease_capacity(v, idx); + } + } - // All done, return control: - return 0; + // All done, return control: + return 0; } // This is the inline implementation for all the "delete" methods -static inline zvect_retval p_vect_delete_at(vector const v, const zvect_index start, - const zvect_index offset, uint32_t flags) { +static inline zvect_retval p_vect_delete_at(vector const v, + const zvect_index start, + const zvect_index offset, + uint32_t flags) { - zvect_index vsize = p_vect_size(v); + zvect_index vsize = p_vect_size(v); - // If the vector is empty just return - if (vsize == 0) - return ZVERR_VECTEMPTY; + // If the vector is empty just return + if (vsize == 0) { + return ZVERR_VECTEMPTY; + } - // Check if the index is out of bounds: - if ((start + offset) > vsize) - return ZVERR_IDXOUTOFBOUND; + // Check if the index is out of bounds: + if ((start + offset) > vsize) { + return ZVERR_IDXOUTOFBOUND; + } - uint16_t array_changed = 0; + uint16_t array_changed = 0; - // "shift" left the data of one position: - zvect_index tot_items = start + offset; + // "shift" left the data of one position: + zvect_index tot_items = start + offset; #ifdef DEBUG - /* + /* log_msg(ZVLP_INFO, "p_vect_delete_at: start %*u\n", 14, start); log_msg(ZVLP_INFO, "p_vect_delete_at: offset %*u\n", 14, offset); log_msg(ZVLP_INFO, "p_vect_delete_at: tot_items %*u\n", 14, tot_items); @@ -1239,67 +1264,69 @@ static inline zvect_retval p_vect_delete_at(vector const v, const zvect_index st log_msg(ZVLP_INFO, "p_vect_delete_at: data %*p\n", 14, v->data); */ #endif - if ( (vsize > 1) && (start < (vsize - 1)) && (tot_items < vsize) && (v->data != NULL) ) { - array_changed = 1; + if ((vsize > 1) && (start < (vsize - 1)) && (tot_items < vsize) && (v->data != NULL)) { + array_changed = 1; #ifdef DEBUG - /* for (zvect_index ptrID = start; ptrID < start + offset; ptrID++) + /* for (zvect_index ptrID = start; ptrID < start + offset; ptrID++) { log_msg(ZVLP_INFO, "p_vect_delete_at: data ptr %*p\n", 14, v->data + (v->begin + ptrID)); }*/ #endif - // Safe erase items? - if ( flags & 1 ) - p_free_items(v, start, offset); + // Safe erase items? + if (flags & 1) { + p_free_items(v, start, offset); + } - // Move remaining items pointers up: - if ( tot_items ) - p_vect_memmove(v->data + (v->begin + start), v->data + (v->begin + tot_items + 1), - sizeof(void *) * ((vsize - start) - offset)); + // Move remaining items pointers up: + if (tot_items) { + p_vect_memmove(v->data + (v->begin + start), + v->data + (v->begin + tot_items + 1), + sizeof(void *) * ((vsize - start) - offset)); + } - // Clear leftover item pointers: - if ( offset && !(flags & 1)) - memset(v->data + ((v->begin + vsize) - (offset + 1)), 0, offset); - } + // Clear leftover item pointers: + if (offset && !(flags & 1)) { + memset(v->data + ((v->begin + vsize) - (offset + 1)), 0, offset); + } + } - // Reduce vector size: - if (!(v->flags & ZV_BYREF) && (flags & 1) && !array_changed) - p_free_items(v, ((vsize - 1) - offset), offset); + // Reduce vector size: + if (!(v->flags & ZV_BYREF) && (flags & 1) && !array_changed) { + p_free_items(v, ((vsize - 1) - offset), offset); + } - // Check if we need to increment begin or decrement end - // depending on the direction of the "delete" (left or right) - if ( start != 0 || array_changed ) { - if ((v->end - (offset + 1)) > v->begin) { - v->end -= (offset + 1); - } else { - v->end = v->begin; - } - } else { - if ((v->begin + (offset + 1)) < v->end) { - v->begin += (offset + 1); - } else { - v->begin = v->end; - } - } + // Check if we need to increment begin or decrement end + // depending on the direction of the "delete" (left or right) + if (start != 0 || array_changed) { + if ((v->end - (offset + 1)) > v->begin) { + v->end -= (offset + 1); + } else { + v->end = v->begin; + } + } else { + if ((v->begin + (offset + 1)) < v->end) { + v->begin += (offset + 1); + } else { + v->begin = v->end; + } + } - if (v->begin == v->end) - { - v->begin = 0; - v->end = 0; - } + if (v->begin == v->end) { + v->begin = 0; + v->end = 0; + } - // Check if we need to shrink the vector: - if ((4 * vsize) < p_vect_capacity(v)) - p_vect_decrease_capacity(v, start); + // Check if we need to shrink the vector: + if ((4 * vsize) < p_vect_capacity(v)) { + p_vect_decrease_capacity(v, start); + } - // All done, return control: - return 0; + // All done, return control: + return 0; } /*---------------------------------------------------------------------------*/ - - - /***************************************************************************** ** ZVector API ** *****************************************************************************/ @@ -1313,17 +1340,19 @@ static inline zvect_retval p_vect_delete_at(vector const v, const zvect_index st */ void vect_shrink(vector const v) { #if (ZVECT_THREAD_SAFE == 1) - zvect_retval lock_owner = get_mutex_lock(v, 1); + zvect_retval lock_owner = get_mutex_lock(v, 1); #endif - zvect_retval rval = p_vect_shrink(v); + zvect_retval rval = p_vect_shrink(v); #if (ZVECT_THREAD_SAFE == 1) - if (lock_owner) - get_mutex_unlock(v, 1); + if (lock_owner) { + get_mutex_unlock(v, 1); + } #endif - if (rval) - p_throw_error(rval, NULL); + if (rval) { + p_throw_error(rval, NULL); + } } /*---------------------------------------------------------------------------*/ @@ -1332,23 +1361,23 @@ void vect_shrink(vector const v) { // Vector Structural Information report: bool vect_is_empty(vector const v) { - return !p_vect_check(v) ? (p_vect_size(v) == 0) : (bool)ZVERR_VECTUNDEF; + return !p_vect_check(v) ? (p_vect_size(v) == 0) : (bool)ZVERR_VECTUNDEF; } zvect_index vect_size(vector const v) { - return !p_vect_check(v) ? p_vect_size(v) : 0; + return !p_vect_check(v) ? p_vect_size(v) : 0; } zvect_index vect_max_size(vector const v) { - return !p_vect_check(v) ? zvect_index_max : 0; + return !p_vect_check(v) ? zvect_index_max : 0; } void *vect_begin(vector const v) { - return !p_vect_check(v) ? v->data[v->begin] : NULL; + return !p_vect_check(v) ? v->data[v->begin] : NULL; } void *vect_end(vector const v) { - return !p_vect_check(v) ? v->data[v->end] : NULL; + return !p_vect_check(v) ? v->data[v->end] : NULL; } /*---------------------------------------------------------------------------*/ @@ -1356,86 +1385,90 @@ void *vect_end(vector const v) { /*---------------------------------------------------------------------------*/ // Vector Creation and Destruction: -vector vect_create(const zvect_index init_capacity, const size_t item_size, - const uint32_t properties) { - // If ZVector has not been initialised yet, then initialise it - // when creating the first vector: - if (p_init_state == 0) - p_init_zvect(); +vector vect_create(const zvect_index init_capacity, const size_t item_size, const uint32_t properties) { + // If ZVector has not been initialised yet, then initialise it + // when creating the first vector: + if (p_init_state == 0) { + p_init_zvect(); + } - // Create the vector first: - vector v = (vector)malloc(sizeof(struct p_vector)); - if (v == NULL) - p_throw_error(ZVERR_OUTOFMEM, NULL); + // Create the vector first: + vector v = (vector)malloc(sizeof(struct p_vector)); + if (v == NULL) { + p_throw_error(ZVERR_OUTOFMEM, NULL); + } - // Initialize the vector: - v->end = 0; - if (item_size == 0) - v->data_size = ZVECT_DEFAULT_DATA_SIZE; - else - v->data_size = item_size; + // Initialize the vector: + v->end = 0; + if (item_size == 0) { + v->data_size = ZVECT_DEFAULT_DATA_SIZE; + } else { + v->data_size = item_size; + } - zvect_index capacity = init_capacity; - if (init_capacity == 0) - { - v->cap_left = ZVECT_INITIAL_CAPACITY / 2; - v->cap_right= ZVECT_INITIAL_CAPACITY / 2; - } else { - if (init_capacity <= 4) - capacity = 4; + zvect_index capacity = init_capacity; + if (init_capacity == 0) { + v->cap_left = ZVECT_INITIAL_CAPACITY / 2; + v->cap_right = ZVECT_INITIAL_CAPACITY / 2; + } else { + if (init_capacity <= 4) { + capacity = 4; + } - v->cap_left = capacity / 2; - v->cap_right= capacity / 2; - } - v->begin = v->end = 0; + v->cap_left = capacity / 2; + v->cap_right = capacity / 2; + } + v->begin = v->end = 0; - v->init_capacity = v->cap_left + v->cap_right; - v->flags = properties; - v->SfWpFunc = NULL; - v->status = 0; - if (v->flags & ZV_CIRCULAR) - { - // If the vector is circular then - // we need to pre-allocate all the elements - // the vector will not grow: - v->end = v->cap_right - 1; - v->begin = v->cap_left - 1; - } + v->init_capacity = v->cap_left + v->cap_right; + v->flags = properties; + v->SfWpFunc = NULL; + v->status = 0; + if (v->flags & ZV_CIRCULAR) { + // If the vector is circular then + // we need to pre-allocate all the elements + // the vector will not grow: + v->end = v->cap_right - 1; + v->begin = v->cap_left - 1; + } #ifdef ZVECT_DMF_EXTENSIONS - v->balance = v->bottom = 0; -#endif // ZVECT_DMF_EXTENSIONS + v->balance = v->bottom = 0; +#endif // ZVECT_DMF_EXTENSIONS - v->data = NULL; + v->data = NULL; #if (ZVECT_THREAD_SAFE == 1) - v->lock_type = 0; - mutex_init(&(v->lock)); - mutex_cond_init(&(v->cond)); - semaphore_init(&(v->semaphore), 0); + v->lock_type = 0; + mutex_init(&(v->lock)); + mutex_cond_init(&(v->cond)); + semaphore_init(&(v->semaphore), 0); #endif - // Allocate memory for the vector storage area - v->data = (void **)calloc(p_vect_capacity(v), sizeof(void *)); - if (v->data == NULL) - p_throw_error(ZVERR_OUTOFMEM, NULL); + // Allocate memory for the vector storage area + v->data = (void **)calloc(p_vect_capacity(v), sizeof(void *)); + if (v->data == NULL) { + p_throw_error(ZVERR_OUTOFMEM, NULL); + } - // Return the vector to the user: - return v; + // Return the vector to the user: + return v; } void vect_destroy(vector v) { - // Call p_vect_destroy with flags set to 1 - // to destroy data according to the vector - // properties: - zvect_retval rval = p_vect_check(v); - if (rval) - goto JOB_DONE; + // Call p_vect_destroy with flags set to 1 + // to destroy data according to the vector + // properties: + zvect_retval rval = p_vect_check(v); + if (rval) { + goto JOB_DONE; + } - rval = p_vect_destroy(v, 1); + rval = p_vect_destroy(v, 1); JOB_DONE: - if (rval) - p_throw_error(rval, NULL); + if (rval) { + p_throw_error(rval, NULL); + } } /*---------------------------------------------------------------------------*/ @@ -1445,51 +1478,51 @@ JOB_DONE: #if (ZVECT_THREAD_SAFE == 1) void vect_lock_enable(void) { - locking_disabled = false; + locking_disabled = false; } void vect_lock_disable(void) { - locking_disabled = true; + locking_disabled = true; } static inline zvect_retval p_vect_lock(vector const v) { - return (locking_disabled || (v->flags & ZV_NOLOCKING)) ? 0 : get_mutex_lock(v, 3); + return (locking_disabled || (v->flags & ZV_NOLOCKING)) ? 0 : get_mutex_lock(v, 3); } zvect_retval vect_lock(vector const v) { - return p_vect_lock(v); + return p_vect_lock(v); } static inline zvect_retval p_vect_unlock(vector const v) { - return (locking_disabled || (v->flags & ZV_NOLOCKING)) ? 0 : get_mutex_unlock(v, 3); + return (locking_disabled || (v->flags & ZV_NOLOCKING)) ? 0 : get_mutex_unlock(v, 3); } zvect_retval vect_unlock(vector const v) { - return p_vect_unlock(v); + return p_vect_unlock(v); } static inline zvect_retval p_vect_trylock(vector const v) { - return (locking_disabled || (v->flags & ZV_NOLOCKING)) ? 0 : check_mutex_trylock(v, 3); + return (locking_disabled || (v->flags & ZV_NOLOCKING)) ? 0 : check_mutex_trylock(v, 3); } zvect_retval vect_trylock(vector const v) { - return p_vect_trylock(v); + return p_vect_trylock(v); } zvect_retval vect_sem_wait(const vector v) { #if !defined(macOS) - return sem_wait(&(v->semaphore)); + return sem_wait(&(v->semaphore)); #else - return dispatch_semaphore_wait(v->semaphore, DISPATCH_TIME_FOREVER); + return dispatch_semaphore_wait(v->semaphore, DISPATCH_TIME_FOREVER); #endif } zvect_retval vect_sem_post(const vector v) { -# if !defined(macOS) - return sem_post(&(v->semaphore)); -# else - return dispatch_semaphore_signal(v->semaphore); -# endif +#if !defined(macOS) + return sem_post(&(v->semaphore)); +#else + return dispatch_semaphore_signal(v->semaphore); +#endif } /* @@ -1503,19 +1536,19 @@ inline zvect_retval vect_wait_for_signal(const vector v) { */ static inline zvect_retval p_vect_lock_after_signal(const vector v) { - return (locking_disabled || (v->flags & ZV_NOLOCKING)) ? 1 : lock_after_signal(v, 3); + return (locking_disabled || (v->flags & ZV_NOLOCKING)) ? 1 : lock_after_signal(v, 3); } zvect_retval vect_lock_after_signal(const vector v) { - return p_vect_lock_after_signal(v); + return p_vect_lock_after_signal(v); } zvect_retval vect_send_signal(const vector v) { - return send_signal(v, 3); + return send_signal(v, 3); } zvect_retval vect_broadcast_signal(const vector v) { - return broadcast_signal(v, 3); + return broadcast_signal(v, 3); } #endif @@ -1526,462 +1559,518 @@ zvect_retval vect_broadcast_signal(const vector v) { // Vector Data Storage functions: void vect_clear(vector const v) { - // check if the vector exists: - zvect_retval rval = p_vect_check(v); - if (rval) - goto JOB_DONE; + // check if the vector exists: + zvect_retval rval = p_vect_check(v); + if (rval) { + goto JOB_DONE; + } #if (ZVECT_THREAD_SAFE == 1) - zvect_retval lock_owner = (locking_disabled || (v->flags & ZV_NOLOCKING)) ? 0 : get_mutex_lock(v, 1); + zvect_retval lock_owner = (locking_disabled || (v->flags & ZV_NOLOCKING)) ? 0 : get_mutex_lock(v, 1); #endif - rval = p_vect_clear(v); + rval = p_vect_clear(v); //DONE_PROCESSING: #if (ZVECT_THREAD_SAFE == 1) - if (lock_owner) - get_mutex_unlock(v, 1); + if (lock_owner) { + get_mutex_unlock(v, 1); + } #endif JOB_DONE: - if (rval) - p_throw_error(rval, NULL); + if (rval) { + p_throw_error(rval, NULL); + } } void vect_set_wipefunct(const vector v, void (*f1)(const void *, size_t)) { - v->SfWpFunc = (void *)malloc(sizeof(void *)); - if (v->SfWpFunc == NULL) - p_throw_error(ZVERR_OUTOFMEM, NULL); + v->SfWpFunc = (void *)malloc(sizeof(void *)); + if (v->SfWpFunc == NULL) { + p_throw_error(ZVERR_OUTOFMEM, NULL); + } - // Set custom Safe Wipe function: - v->SfWpFunc = f1; - // p_vect_memcpy(v->SfWpFunc, f1, sizeof(void *)); - v->status |= ZVS_CUST_WIPE_ON; + // Set custom Safe Wipe function: + v->SfWpFunc = f1; + // p_vect_memcpy(v->SfWpFunc, f1, sizeof(void *)); + v->status |= ZVS_CUST_WIPE_ON; } // Add an item at the END (top) of the vector inline void vect_push(const vector v, const void *value) { - zvect_retval rval = p_vect_check(v); - if (rval) - goto JOB_DONE; + zvect_retval rval = p_vect_check(v); + if (rval) { + goto JOB_DONE; + } - // If the vector is circular then use vect_put_at - // instead: - if (v->flags & ZV_CIRCULAR) { - rval = p_vect_put_at(v, value, p_vect_size(v)); - goto JOB_DONE; - } + // If the vector is circular then use vect_put_at + // instead: + if (v->flags & ZV_CIRCULAR) { + rval = p_vect_put_at(v, value, p_vect_size(v)); + goto JOB_DONE; + } #if (ZVECT_THREAD_SAFE == 1) - zvect_retval lock_owner = (locking_disabled || (v->flags & ZV_NOLOCKING)) ? 0 : get_mutex_lock(v, 1); + zvect_retval lock_owner = (locking_disabled || (v->flags & ZV_NOLOCKING)) ? 0 : get_mutex_lock(v, 1); #endif - // The very first time we do a push, if the vector is - // declared very small, we may need to expand its - // capacity on the left. This because the very first - // push will use index 0 and the rule in ZVector is - // when we use index 0 we may need to expand on the - // left. So let's check if we do for this vector: - zvect_index vsize = p_vect_size(v); + // The very first time we do a push, if the vector is + // declared very small, we may need to expand its + // capacity on the left. This because the very first + // push will use index 0 and the rule in ZVector is + // when we use index 0 we may need to expand on the + // left. So let's check if we do for this vector: + zvect_index vsize = p_vect_size(v); - // Check if we need to expand on thr right side: - if ( (v->end >= v->cap_right) && ((rval = p_vect_increase_capacity(v, 1)) != 0) ) - goto DONE_PROCESSING; + // Check if we need to expand on thr right side: + if ((v->end >= v->cap_right) && ((rval = p_vect_increase_capacity(v, 1)) != 0)) { + goto DONE_PROCESSING; + } - rval = p_vect_add_at(v, value, vsize); + rval = p_vect_add_at(v, value, vsize); DONE_PROCESSING: #if (ZVECT_THREAD_SAFE == 1) - if (lock_owner) - get_mutex_unlock(v, 1); + if (lock_owner) { + get_mutex_unlock(v, 1); + } #endif JOB_DONE: - if (rval) - p_throw_error(rval, NULL); + if (rval) { + p_throw_error(rval, NULL); + } } // Add an item at the END of the vector void vect_add(const vector v, const void *value) { - vect_push(v, value); + vect_push(v, value); } // Add an item at position "i" of the vector void vect_add_at(const vector v, const void *value, const zvect_index i) { - zvect_retval rval = p_vect_check(v); - if (rval) - goto JOB_DONE; + zvect_retval rval = p_vect_check(v); + if (rval) { + goto JOB_DONE; + } - // If the vector is circular then use vect_put_at - // instead: - if (v->flags & ZV_CIRCULAR) { - rval = p_vect_put_at(v, value, i); - goto JOB_DONE; - } + // If the vector is circular then use vect_put_at + // instead: + if (v->flags & ZV_CIRCULAR) { + rval = p_vect_put_at(v, value, i); + goto JOB_DONE; + } #if (ZVECT_THREAD_SAFE == 1) - zvect_retval lock_owner = (locking_disabled || (v->flags & ZV_NOLOCKING)) ? 0 : get_mutex_lock(v, 1); + zvect_retval lock_owner = (locking_disabled || (v->flags & ZV_NOLOCKING)) ? 0 : get_mutex_lock(v, 1); #endif - // Check if the provided index is out of bounds: - if (i > p_vect_size(v)) - { - rval = ZVERR_IDXOUTOFBOUND; - goto DONE_PROCESSING; - } + // Check if the provided index is out of bounds: + if (i > p_vect_size(v)) { + rval = ZVERR_IDXOUTOFBOUND; + goto DONE_PROCESSING; + } - if (!i) { - // Check if we need to expand on the left side: - if ( (v->begin == 0 || v->cap_left <= 1) && ( (rval = p_vect_increase_capacity(v, 0)) != 0 ) ) - goto DONE_PROCESSING; - } else { - // Check if we need to expand on thr right side: - if ( (v->end >= v->cap_right ) && ( (rval = p_vect_increase_capacity(v, 1)) != 0 ) ) - goto DONE_PROCESSING; - } - rval = p_vect_add_at(v, value, i); + if (!i) { + // Check if we need to expand on the left side: + if ((v->begin == 0 || v->cap_left <= 1) && ((rval = p_vect_increase_capacity(v, 0)) != 0)) { + goto DONE_PROCESSING; + } + } else { + // Check if we need to expand on thr right side: + if ((v->end >= v->cap_right) && ((rval = p_vect_increase_capacity(v, 1)) != 0)) { + goto DONE_PROCESSING; + } + } + rval = p_vect_add_at(v, value, i); DONE_PROCESSING: #if (ZVECT_THREAD_SAFE == 1) - if (lock_owner) - get_mutex_unlock(v, 1); + if (lock_owner) { + get_mutex_unlock(v, 1); + } #endif JOB_DONE: - if (rval) - p_throw_error(rval, NULL); + if (rval) { + p_throw_error(rval, NULL); + } } // Add an item at the FRONT of the vector void vect_add_front(vector const v, const void *value) { - zvect_retval rval = p_vect_check(v); - if (rval) - goto JOB_DONE; + zvect_retval rval = p_vect_check(v); + if (rval) { + goto JOB_DONE; + } - // If the vector is circular then use vect_put_at - // instead: - if (v->flags & ZV_CIRCULAR) { - rval = p_vect_put_at(v, value, 0); - goto JOB_DONE; - } + // If the vector is circular then use vect_put_at + // instead: + if (v->flags & ZV_CIRCULAR) { + rval = p_vect_put_at(v, value, 0); + goto JOB_DONE; + } #if (ZVECT_THREAD_SAFE == 1) - zvect_retval lock_owner = (locking_disabled || (v->flags & ZV_NOLOCKING)) ? 0 : get_mutex_lock(v, 1); + zvect_retval lock_owner = (locking_disabled || (v->flags & ZV_NOLOCKING)) ? 0 : get_mutex_lock(v, 1); #endif - // Check if we need to expand on the left side: - if ( (v->begin == 0 || v->cap_left <= 1 ) && ( (rval = p_vect_increase_capacity(v, 0)) != 0 ) ) - goto DONE_PROCESSING; + // Check if we need to expand on the left side: + if ((v->begin == 0 || v->cap_left <= 1) && ((rval = p_vect_increase_capacity(v, 0)) != 0)) { + goto DONE_PROCESSING; + } - rval = p_vect_add_at(v, value, 0); + rval = p_vect_add_at(v, value, 0); DONE_PROCESSING: #if (ZVECT_THREAD_SAFE == 1) - if (lock_owner) - get_mutex_unlock(v, 1); + if (lock_owner) { + get_mutex_unlock(v, 1); + } #endif JOB_DONE: - if (rval) - p_throw_error(rval, NULL); + if (rval) { + p_throw_error(rval, NULL); + } } // inline implementation for all get(s): static inline void *p_vect_get_at(vector const v, const zvect_index i) { - // Check if passed index is out of bounds: - if (i >= p_vect_size(v)) - p_throw_error(ZVERR_IDXOUTOFBOUND, NULL); + // Check if passed index is out of bounds: + if (i >= p_vect_size(v)) { + p_throw_error(ZVERR_IDXOUTOFBOUND, NULL); + } - // Return found element: - return v->data[v->begin + i]; + // Return found element: + return v->data[v->begin + i]; } void *vect_get(vector const v) { - // check if the vector exists: - zvect_retval rval = p_vect_check(v); - if (!rval) - return p_vect_get_at(v, p_vect_size(v) - 1); - else - p_throw_error(rval, NULL); + // check if the vector exists: + zvect_retval rval = p_vect_check(v); + if (!rval) { + return p_vect_get_at(v, p_vect_size(v) - 1); + } else { + p_throw_error(rval, NULL); + } - return NULL; + return NULL; } void *vect_get_at(vector const v, const zvect_index i) { - // check if the vector exists: - zvect_retval rval = p_vect_check(v); - if (!rval) - return p_vect_get_at(v, i); - else - p_throw_error(rval, NULL); + // check if the vector exists: + zvect_retval rval = p_vect_check(v); + if (!rval) { + return p_vect_get_at(v, i); + } else { + p_throw_error(rval, NULL); + } - return NULL; + return NULL; } void *vect_get_front(vector const v) { - // check if the vector exists: - zvect_retval rval = p_vect_check(v); - if (!rval) - return p_vect_get_at(v, 0); - else - p_throw_error(rval, NULL); + // check if the vector exists: + zvect_retval rval = p_vect_check(v); + if (!rval) { + return p_vect_get_at(v, 0); + } else { + p_throw_error(rval, NULL); + } - return NULL; + return NULL; } void vect_put(vector const v, const void *value) { - zvect_retval rval = p_vect_check(v); - if (rval) - goto JOB_DONE; + zvect_retval rval = p_vect_check(v); + if (rval) { + goto JOB_DONE; + } #if (ZVECT_THREAD_SAFE == 1) - zvect_retval lock_owner = (locking_disabled || (v->flags & ZV_NOLOCKING)) ? 0 : get_mutex_lock(v, 1); + zvect_retval lock_owner = (locking_disabled || (v->flags & ZV_NOLOCKING)) ? 0 : get_mutex_lock(v, 1); #endif - rval = p_vect_put_at(v, value, p_vect_size(v) - 1); + rval = p_vect_put_at(v, value, p_vect_size(v) - 1); #if (ZVECT_THREAD_SAFE == 1) - if (lock_owner) - get_mutex_unlock(v, 1); + if (lock_owner) { + get_mutex_unlock(v, 1); + } #endif JOB_DONE: - if (rval) - p_throw_error(rval, NULL); + if (rval) { + p_throw_error(rval, NULL); + } } void vect_put_at(vector const v, const void *value, const zvect_index i) { - zvect_retval rval = p_vect_check(v); - if (rval) - goto JOB_DONE; + zvect_retval rval = p_vect_check(v); + if (rval) { + goto JOB_DONE; + } #if (ZVECT_THREAD_SAFE == 1) - zvect_retval lock_owner = (locking_disabled || (v->flags & ZV_NOLOCKING)) ? 0 : get_mutex_lock(v, 1); + zvect_retval lock_owner = (locking_disabled || (v->flags & ZV_NOLOCKING)) ? 0 : get_mutex_lock(v, 1); #endif - rval = p_vect_put_at(v, value, i); + rval = p_vect_put_at(v, value, i); #if (ZVECT_THREAD_SAFE == 1) - if (lock_owner) - get_mutex_unlock(v, 1); + if (lock_owner) { + get_mutex_unlock(v, 1); + } #endif JOB_DONE: - if (rval) - p_throw_error(rval, NULL); + if (rval) { + p_throw_error(rval, NULL); + } } void vect_put_front(vector const v, const void *value) { - zvect_retval rval = p_vect_check(v); - if (rval) - goto JOB_DONE; + zvect_retval rval = p_vect_check(v); + if (rval) { + goto JOB_DONE; + } #if (ZVECT_THREAD_SAFE == 1) - zvect_retval lock_owner = (locking_disabled || (v->flags & ZV_NOLOCKING)) ? 0 : get_mutex_lock(v, 1); + zvect_retval lock_owner = (locking_disabled || (v->flags & ZV_NOLOCKING)) ? 0 : get_mutex_lock(v, 1); #endif - rval = p_vect_put_at(v, value, 0); + rval = p_vect_put_at(v, value, 0); #if (ZVECT_THREAD_SAFE == 1) - if (lock_owner) - get_mutex_unlock(v, 1); + if (lock_owner) { + get_mutex_unlock(v, 1); + } #endif JOB_DONE: - if (rval) - p_throw_error(rval, NULL); + if (rval) { + p_throw_error(rval, NULL); + } } inline void *vect_pop(vector const v) { - void *item = NULL; - zvect_retval rval = p_vect_check(v); - if (rval) - goto JOB_DONE; + void *item = NULL; + zvect_retval rval = p_vect_check(v); + if (rval) { + goto JOB_DONE; + } #if (ZVECT_THREAD_SAFE == 1) - zvect_retval lock_owner = (locking_disabled || (v->flags & ZV_NOLOCKING)) ? 0 : get_mutex_lock(v, 1); + zvect_retval lock_owner = (locking_disabled || (v->flags & ZV_NOLOCKING)) ? 0 : get_mutex_lock(v, 1); #endif - zvect_index vsize = p_vect_size(v); - if (vsize != 0) - rval = p_vect_remove_at(v, vsize - 1, &item); + zvect_index vsize = p_vect_size(v); + if (vsize != 0) { + rval = p_vect_remove_at(v, vsize - 1, &item); + } #if (ZVECT_THREAD_SAFE == 1) - if (lock_owner) - get_mutex_unlock(v, 1); + if (lock_owner) { + get_mutex_unlock(v, 1); + } #endif JOB_DONE: - if (rval) - p_throw_error(rval, NULL); + if (rval) { + p_throw_error(rval, NULL); + } - return item; + return item; } void *vect_remove(vector const v) { - void *item = NULL; - zvect_retval rval = p_vect_check(v); - if (rval) - goto JOB_DONE; + void *item = NULL; + zvect_retval rval = p_vect_check(v); + if (rval) { + goto JOB_DONE; + } #if (ZVECT_THREAD_SAFE == 1) - zvect_retval lock_owner = (locking_disabled || (v->flags & ZV_NOLOCKING)) ? 0 : get_mutex_lock(v, 1); + zvect_retval lock_owner = (locking_disabled || (v->flags & ZV_NOLOCKING)) ? 0 : get_mutex_lock(v, 1); #endif - zvect_index vsize = p_vect_size(v); - if (vsize != 0) - rval = p_vect_remove_at(v, vsize - 1, &item); + zvect_index vsize = p_vect_size(v); + if (vsize != 0) { + rval = p_vect_remove_at(v, vsize - 1, &item); + } #if (ZVECT_THREAD_SAFE == 1) - if (lock_owner) - get_mutex_unlock(v, 1); + if (lock_owner) { + get_mutex_unlock(v, 1); + } #endif JOB_DONE: - if (rval) - p_throw_error(rval, NULL); + if (rval) { + p_throw_error(rval, NULL); + } - return item; + return item; } void *vect_remove_at(vector const v, const zvect_index i) { - void *item = NULL; - zvect_retval rval = p_vect_check(v); - if (rval) - goto JOB_DONE; + void *item = NULL; + zvect_retval rval = p_vect_check(v); + if (rval) { + goto JOB_DONE; + } #if (ZVECT_THREAD_SAFE == 1) - zvect_retval lock_owner = (locking_disabled || (v->flags & ZV_NOLOCKING)) ? 0 : get_mutex_lock(v, 1); + zvect_retval lock_owner = (locking_disabled || (v->flags & ZV_NOLOCKING)) ? 0 : get_mutex_lock(v, 1); #endif - if (p_vect_size(v) != 0) - rval = p_vect_remove_at(v, i, &item); + if (p_vect_size(v) != 0) { + rval = p_vect_remove_at(v, i, &item); + } #if (ZVECT_THREAD_SAFE == 1) - if (lock_owner) - get_mutex_unlock(v, 1); + if (lock_owner) { + get_mutex_unlock(v, 1); + } #endif JOB_DONE: - if (rval) - p_throw_error(rval, NULL); + if (rval) { + p_throw_error(rval, NULL); + } - return item; + return item; } void *vect_remove_front(vector const v) { - void *item = NULL; - zvect_retval rval = p_vect_check(v); - if (rval) - goto JOB_DONE; + void *item = NULL; + zvect_retval rval = p_vect_check(v); + if (rval) { + goto JOB_DONE; + } #if (ZVECT_THREAD_SAFE == 1) - zvect_retval lock_owner = (locking_disabled || (v->flags & ZV_NOLOCKING)) ? 0 : get_mutex_lock(v, 1); + zvect_retval lock_owner = (locking_disabled || (v->flags & ZV_NOLOCKING)) ? 0 : get_mutex_lock(v, 1); #endif - if (p_vect_size(v) != 0) - rval = p_vect_remove_at(v, 0, &item); + if (p_vect_size(v) != 0) { + rval = p_vect_remove_at(v, 0, &item); + } #if (ZVECT_THREAD_SAFE == 1) - if (lock_owner) - get_mutex_unlock(v, 1); + if (lock_owner) { + get_mutex_unlock(v, 1); + } #endif JOB_DONE: - if (rval) - p_throw_error(rval, NULL); + if (rval) { + p_throw_error(rval, NULL); + } - return item; + return item; } // Delete an item at the END of the vector void vect_delete(vector const v) { - zvect_retval rval = p_vect_check(v); - if (rval) - goto JOB_DONE; + zvect_retval rval = p_vect_check(v); + if (rval) { + goto JOB_DONE; + } #if (ZVECT_THREAD_SAFE == 1) - zvect_retval lock_owner = (locking_disabled || (v->flags & ZV_NOLOCKING)) ? 0 : get_mutex_lock(v, 1); + zvect_retval lock_owner = (locking_disabled || (v->flags & ZV_NOLOCKING)) ? 0 : get_mutex_lock(v, 1); #endif - rval = p_vect_delete_at(v, p_vect_size(v) - 1, 0, 1); + rval = p_vect_delete_at(v, p_vect_size(v) - 1, 0, 1); #if (ZVECT_THREAD_SAFE == 1) - if (lock_owner) - get_mutex_unlock(v, 1); + if (lock_owner) { + get_mutex_unlock(v, 1); + } #endif JOB_DONE: - if (rval) - p_throw_error(rval, NULL); + if (rval) { + p_throw_error(rval, NULL); + } } // Delete an item at position "i" on the vector void vect_delete_at(const vector v, const zvect_index i) { - zvect_retval rval = p_vect_check(v); - if (rval) - goto JOB_DONE; + zvect_retval rval = p_vect_check(v); + if (rval) { + goto JOB_DONE; + } #if (ZVECT_THREAD_SAFE == 1) - zvect_retval lock_owner = (locking_disabled || (v->flags & ZV_NOLOCKING)) ? 0 : get_mutex_lock(v, 1); + zvect_retval lock_owner = (locking_disabled || (v->flags & ZV_NOLOCKING)) ? 0 : get_mutex_lock(v, 1); #endif - rval = p_vect_delete_at(v, i, 0, 1); + rval = p_vect_delete_at(v, i, 0, 1); #if (ZVECT_THREAD_SAFE == 1) - if (lock_owner) - get_mutex_unlock(v, 1); + if (lock_owner) { + get_mutex_unlock(v, 1); + } #endif JOB_DONE: - if (rval) - p_throw_error(rval, NULL); + if (rval) { + p_throw_error(rval, NULL); + } } // Delete a range of items from "first_element" to "last_element" on the vector v -void vect_delete_range(vector const v, const zvect_index first_element, - const zvect_index last_element) { - zvect_retval rval = p_vect_check(v); - if (rval) - goto JOB_DONE; +void vect_delete_range(vector const v, const zvect_index first_element, const zvect_index last_element) { + zvect_retval rval = p_vect_check(v); + if (rval) { + goto JOB_DONE; + } #if (ZVECT_THREAD_SAFE == 1) - zvect_retval lock_owner = (locking_disabled || (v->flags & ZV_NOLOCKING)) ? 0 : get_mutex_lock(v, 1); + zvect_retval lock_owner = (locking_disabled || (v->flags & ZV_NOLOCKING)) ? 0 : get_mutex_lock(v, 1); #endif - zvect_index end = (last_element - first_element); - rval = p_vect_delete_at(v, first_element, end, 1); + zvect_index end = (last_element - first_element); + rval = p_vect_delete_at(v, first_element, end, 1); #if (ZVECT_THREAD_SAFE == 1) - if (lock_owner) - get_mutex_unlock(v, 1); + if (lock_owner) { + get_mutex_unlock(v, 1); + } #endif JOB_DONE: - if (rval) - p_throw_error(rval, NULL); + if (rval) { + p_throw_error(rval, NULL); + } } // Delete an item at the BEGINNING of a vector v void vect_delete_front(vector const v) { - zvect_retval rval = p_vect_check(v); - if (rval) - goto JOB_DONE; + zvect_retval rval = p_vect_check(v); + if (rval) { + goto JOB_DONE; + } #if (ZVECT_THREAD_SAFE == 1) - zvect_retval lock_owner = (locking_disabled || (v->flags & ZV_NOLOCKING)) ? 0 : get_mutex_lock(v, 1); + zvect_retval lock_owner = (locking_disabled || (v->flags & ZV_NOLOCKING)) ? 0 : get_mutex_lock(v, 1); #endif - rval = p_vect_delete_at(v, 0, 0, 1); + rval = p_vect_delete_at(v, 0, 0, 1); #if (ZVECT_THREAD_SAFE == 1) - if (lock_owner) - get_mutex_unlock(v, 1); + if (lock_owner) { + get_mutex_unlock(v, 1); + } #endif JOB_DONE: - if (rval) - p_throw_error(rval, NULL); + if (rval) { + p_throw_error(rval, NULL); + } } /*---------------------------------------------------------------------------*/ @@ -1991,341 +2080,375 @@ JOB_DONE: #ifdef ZVECT_DMF_EXTENSIONS void vect_swap(vector const v, const zvect_index i1, const zvect_index i2) { - // Check parameters: - if (i1 == i2) - return; + // Check parameters: + if (i1 == i2) { + return; + } - // check if the vector exists: - zvect_retval rval = p_vect_check(v); - if (rval) - goto JOB_DONE; + // check if the vector exists: + zvect_retval rval = p_vect_check(v); + if (rval) { + goto JOB_DONE; + } #if (ZVECT_THREAD_SAFE == 1) - zvect_retval lock_owner = (locking_disabled || (v->flags & ZV_NOLOCKING)) ? 0 : get_mutex_lock(v, 1); + zvect_retval lock_owner = (locking_disabled || (v->flags & ZV_NOLOCKING)) ? 0 : get_mutex_lock(v, 1); #endif - // Check parameters: - zvect_index vsize = p_vect_size(v); - if (i1 > vsize || i2 > vsize) { - rval = ZVERR_IDXOUTOFBOUND; - goto DONE_PROCESSING; - } + // Check parameters: + zvect_index vsize = p_vect_size(v); + if (i1 > vsize || i2 > vsize) { + rval = ZVERR_IDXOUTOFBOUND; + goto DONE_PROCESSING; + } - // Let's swap items: - void *temp = v->data[v->begin + i2]; - v->data[v->begin + i2] = v->data[v->begin + i1]; - v->data[v->begin + i1] = temp; + // Let's swap items: + void *temp = v->data[v->begin + i2]; + v->data[v->begin + i2] = v->data[v->begin + i1]; + v->data[v->begin + i1] = temp; DONE_PROCESSING: #if (ZVECT_THREAD_SAFE == 1) - if (lock_owner) - get_mutex_unlock(v, 1); + if (lock_owner) { + get_mutex_unlock(v, 1); + } #endif JOB_DONE: - if (rval) - p_throw_error(rval, NULL); + if (rval) { + p_throw_error(rval, NULL); + } } -void vect_swap_range(vector const v, const zvect_index s1, const zvect_index e1, - const zvect_index s2) { - // Check parameters: - if (s1 == s2) - return; +void vect_swap_range(vector const v, const zvect_index s1, const zvect_index e1, const zvect_index s2) { + // Check parameters: + if (s1 == s2) { + return; + } - zvect_index end = e1; - if (e1 != 0) - end = e1 - s1; + zvect_index end = e1; + if (e1 != 0) { + end = e1 - s1; + } - // check if the vector exists: - zvect_retval rval = p_vect_check(v); - if (rval) - goto JOB_DONE; + // check if the vector exists: + zvect_retval rval = p_vect_check(v); + if (rval) { + goto JOB_DONE; + } #if (ZVECT_THREAD_SAFE == 1) - zvect_retval lock_owner = (locking_disabled || (v->flags & ZV_NOLOCKING)) ? 0 : get_mutex_lock(v, 1); + zvect_retval lock_owner = (locking_disabled || (v->flags & ZV_NOLOCKING)) ? 0 : get_mutex_lock(v, 1); #endif - zvect_index vsize = p_vect_size(v); - if ((s1 + end) > vsize || (s2 + end) > vsize || s2 < (s1 + end)) { - rval = ZVERR_IDXOUTOFBOUND; - goto DONE_PROCESSING; - } + zvect_index vsize = p_vect_size(v); + if ((s1 + end) > vsize || (s2 + end) > vsize || s2 < (s1 + end)) { + rval = ZVERR_IDXOUTOFBOUND; + goto DONE_PROCESSING; + } - // Let's swap items: - register zvect_index i; - for (register zvect_index j = s1; j <= (s1 + end); j++) { - i = j - s1; - void *temp = v->data[v->begin + j]; - v->data[v->begin + j] = v->data[v->begin + (s2 + i)]; - v->data[v->begin + (s2 + i)] = temp; - } + // Let's swap items: + register zvect_index i; + for (register zvect_index j = s1; j <= (s1 + end); j++) { + i = j - s1; + void *temp = v->data[v->begin + j]; + v->data[v->begin + j] = v->data[v->begin + (s2 + i)]; + v->data[v->begin + (s2 + i)] = temp; + } DONE_PROCESSING: #if (ZVECT_THREAD_SAFE == 1) - if (lock_owner) - get_mutex_unlock(v, 1); + if (lock_owner) { + get_mutex_unlock(v, 1); + } #endif JOB_DONE: - if (rval) - p_throw_error(rval, NULL); + if (rval) { + p_throw_error(rval, NULL); + } } void vect_rotate_left(vector const v, const zvect_index i) { - // check if the vector exists: - zvect_retval rval = p_vect_check(v); - if (rval) - goto JOB_DONE; + // check if the vector exists: + zvect_retval rval = p_vect_check(v); + if (rval) { + goto JOB_DONE; + } #if (ZVECT_THREAD_SAFE == 1) - zvect_retval lock_owner = (locking_disabled || (v->flags & ZV_NOLOCKING)) ? 0 : get_mutex_lock(v, 1); + zvect_retval lock_owner = (locking_disabled || (v->flags & ZV_NOLOCKING)) ? 0 : get_mutex_lock(v, 1); #endif - // Check parameters: - zvect_index vsize = p_vect_size(v); - if (i == 0 || i == vsize) - goto DONE_PROCESSING; + // Check parameters: + zvect_index vsize = p_vect_size(v); + if (i == 0 || i == vsize) { + goto DONE_PROCESSING; + } - if (i > vsize) { - rval = ZVERR_IDXOUTOFBOUND; - goto DONE_PROCESSING; - } + if (i > vsize) { + rval = ZVERR_IDXOUTOFBOUND; + goto DONE_PROCESSING; + } - // Process the vector - if (i == 1) { - // Rotate left the vector of 1 position: - void *temp = v->data[0]; - p_vect_memmove(v->data, v->data + 1, sizeof(void *) * (vsize - 1)); - v->data[vsize - 1] = temp; - } else { - void **new_data = (void **)malloc(sizeof(void *) * p_vect_capacity(v)); - if (new_data == NULL) { - rval = ZVERR_OUTOFMEM; - goto DONE_PROCESSING; - } - // Rotate left the vector of "i" positions: - p_vect_memcpy(new_data + v->begin, v->data + v->begin, sizeof(void *) * i); - p_vect_memmove(v->data + v->begin, v->data + v->begin + i, sizeof(void *) * (vsize - i)); - p_vect_memcpy(v->data + v->begin + (vsize - i), new_data + v->begin, sizeof(void *) * i); + // Process the vector + if (i == 1) { + // Rotate left the vector of 1 position: + void *temp = v->data[0]; + p_vect_memmove(v->data, v->data + 1, sizeof(void *) * (vsize - 1)); + v->data[vsize - 1] = temp; + } else { + void **new_data = (void **)malloc(sizeof(void *) * p_vect_capacity(v)); + if (new_data == NULL) { + rval = ZVERR_OUTOFMEM; + goto DONE_PROCESSING; + } + // Rotate left the vector of "i" positions: + p_vect_memcpy(new_data + v->begin, v->data + v->begin, sizeof(void *) * i); + p_vect_memmove(v->data + v->begin, v->data + v->begin + i, sizeof(void *) * (vsize - i)); + p_vect_memcpy(v->data + v->begin + (vsize - i), new_data + v->begin, sizeof(void *) * i); - free(new_data); - } + free(new_data); + } DONE_PROCESSING: #if (ZVECT_THREAD_SAFE == 1) - if (lock_owner) - get_mutex_unlock(v, 1); + if (lock_owner) { + get_mutex_unlock(v, 1); + } #endif JOB_DONE: - if (rval) - p_throw_error(rval, NULL); + if (rval) { + p_throw_error(rval, NULL); + } } void vect_rotate_right(vector const v, const zvect_index i) { - // check if the vector exists: - zvect_retval rval = p_vect_check(v); - if (rval) - goto JOB_DONE; + // check if the vector exists: + zvect_retval rval = p_vect_check(v); + if (rval) { + goto JOB_DONE; + } #if (ZVECT_THREAD_SAFE == 1) - zvect_retval lock_owner = (locking_disabled || (v->flags & ZV_NOLOCKING)) ? 0 : get_mutex_lock(v, 1); + zvect_retval lock_owner = (locking_disabled || (v->flags & ZV_NOLOCKING)) ? 0 : get_mutex_lock(v, 1); #endif - // Check parameters: - zvect_index vsize = p_vect_size(v); - if (i == 0 || i == vsize) - goto DONE_PROCESSING; + // Check parameters: + zvect_index vsize = p_vect_size(v); + if (i == 0 || i == vsize) { + goto DONE_PROCESSING; + } - if (i > vsize) { - rval = ZVERR_IDXOUTOFBOUND; - goto DONE_PROCESSING; - } + if (i > vsize) { + rval = ZVERR_IDXOUTOFBOUND; + goto DONE_PROCESSING; + } - // Process the vector - if (i == 1) { - // Rotate right the vector of 1 position: - void *temp = v->data[v->begin + p_vect_size(v) - 1]; - p_vect_memmove(v->data + v->begin + 1, v->data + v->begin, sizeof(void *) * (vsize - 1)); - v->data[v->begin] = temp; - } else { - void **new_data = (void **)malloc(sizeof(void *) * p_vect_capacity(v)); - if (new_data == NULL) { - rval = ZVERR_OUTOFMEM; - goto DONE_PROCESSING; - } + // Process the vector + if (i == 1) { + // Rotate right the vector of 1 position: + void *temp = v->data[v->begin + p_vect_size(v) - 1]; + p_vect_memmove(v->data + v->begin + 1, v->data + v->begin, sizeof(void *) * (vsize - 1)); + v->data[v->begin] = temp; + } else { + void **new_data = (void **)malloc(sizeof(void *) * p_vect_capacity(v)); + if (new_data == NULL) { + rval = ZVERR_OUTOFMEM; + goto DONE_PROCESSING; + } - // Rotate right the vector of "i" positions: - p_vect_memcpy(new_data + v->begin, v->data + v->begin + (p_vect_size(v) - i), sizeof(void *) * i); - p_vect_memmove(v->data + v->begin + i, v->data + v->begin, sizeof(void *) * (vsize - i)); - p_vect_memcpy(v->data + v->begin, new_data + v->begin, sizeof(void *) * i); + // Rotate right the vector of "i" positions: + p_vect_memcpy(new_data + v->begin, v->data + v->begin + (p_vect_size(v) - i), sizeof(void *) * i); + p_vect_memmove(v->data + v->begin + i, v->data + v->begin, sizeof(void *) * (vsize - i)); + p_vect_memcpy(v->data + v->begin, new_data + v->begin, sizeof(void *) * i); - free(new_data); - } + free(new_data); + } DONE_PROCESSING: #if (ZVECT_THREAD_SAFE == 1) - if (lock_owner) - get_mutex_unlock(v, 1); + if (lock_owner) { + get_mutex_unlock(v, 1); + } #endif JOB_DONE: - if (rval) - p_throw_error(rval, NULL); + if (rval) { + p_throw_error(rval, NULL); + } } #ifdef TRADITIONAL_QSORT -static inline zvect_index -p_partition(vector v, zvect_index low, zvect_index high, - int (*compare_func)(const void *, const void *)) { - if (high >= p_vect_size(v)) - high = p_vect_size(v) - 1; +static inline zvect_index p_partition(vector v, + zvect_index low, + zvect_index high, + int (*compare_func)(const void *, const void *)) { + if (high >= p_vect_size(v)) { + high = p_vect_size(v) - 1; + } - void *pivot = v->data[v->begin + high]; - zvect_index i = (low - 1); + void *pivot = v->data[v->begin + high]; + zvect_index i = (low - 1); - for (register zvect_index j = low; j <= (high - 1); j++) { - // v->data[j] <= pivot - if ((*compare_func)(v->data[v->begin + j], pivot) <= 0) - vect_swap(v, ++i, j); - } + for (register zvect_index j = low; j <= (high - 1); j++) { + // v->data[j] <= pivot + if ((*compare_func)(v->data[v->begin + j], pivot) <= 0) { + vect_swap(v, ++i, j); + } + } - vect_swap(v, i + 1, high); - return (i + 1); + vect_swap(v, i + 1, high); + return (i + 1); } -static void p_vect_qsort(vector v, zvect_index low, zvect_index high, - int (*compare_func)(const void *, const void *)) { - if (low < high) { - zvect_index pi = p_partition(v, low, high, compare_func); - p_vect_qsort(v, low, pi - 1, compare_func); - p_vect_qsort(v, pi + 1, high, compare_func); - } +static void p_vect_qsort(vector v, zvect_index low, zvect_index high, int (*compare_func)(const void *, const void *)) { + if (low < high) { + zvect_index pi = p_partition(v, low, high, compare_func); + p_vect_qsort(v, low, pi - 1, compare_func); + p_vect_qsort(v, pi + 1, high, compare_func); + } } -#endif // TRADITIONAL_QSORT +#endif // TRADITIONAL_QSORT #ifndef TRADITIONAL_QSORT // This is my much faster implementation of a quicksort algorithm // it fundamentally uses the 3 ways partitioning adapted and improved // to deal with arrays of pointers together with having a custom // compare function: -static void p_vect_qsort(const vector v, zvect_index l, zvect_index r, - int (*compare_func)(const void *, const void *)) { - if (r <= l) - return; +static void p_vect_qsort(const vector v, + zvect_index l, + zvect_index r, + int (*compare_func)(const void *, const void *)) { + if (r <= l) { + return; + } - zvect_index i; - zvect_index p; - zvect_index j; - zvect_index q; - void *ref_val = NULL; + zvect_index i; + zvect_index p; + zvect_index j; + zvect_index q; + void *ref_val = NULL; - // l = left (also low) - if (l > 0) - i = l - 1; - else - i = l; - // r = right (also high) - j = r; - p = i; - q = r; - ref_val = v->data[v->begin + r]; + // l = left (also low) + if (l > 0) { + i = l - 1; + } else { + i = l; + } + // r = right (also high) + j = r; + p = i; + q = r; + ref_val = v->data[v->begin + r]; - for (;;) { - while ((*compare_func)(v->data[v->begin + i], ref_val) < 0) - i++; - while ((*compare_func)(ref_val, v->data[(--j) + v->begin]) < 0) - if (j == l) - break; - if (i >= j) - break; - vect_swap(v, i, j); - if ((*compare_func)(v->data[v->begin + i], ref_val) == 0) { - p++; - vect_swap(v, p, i); - } - if ((*compare_func)(ref_val, v->data[v->begin + j]) == 0) { - q--; - vect_swap(v, q, j); - } - } - vect_swap(v, i, r); - j = i - 1; - i = i + 1; - register zvect_index k; - for (k = l; k < p; k++, j--) - vect_swap(v, k, j); - for (k = r - 1; k > q; k--, i++) - vect_swap(v, k, i); - p_vect_qsort(v, l, j, compare_func); - p_vect_qsort(v, i, r, compare_func); + for (;;) { + while ((*compare_func)(v->data[v->begin + i], ref_val) < 0) { + i++; + } + while ((*compare_func)(ref_val, v->data[(--j) + v->begin]) < 0) { + if (j == l) { + break; + } + } + if (i >= j) { + break; + } + vect_swap(v, i, j); + if ((*compare_func)(v->data[v->begin + i], ref_val) == 0) { + p++; + vect_swap(v, p, i); + } + if ((*compare_func)(ref_val, v->data[v->begin + j]) == 0) { + q--; + vect_swap(v, q, j); + } + } + vect_swap(v, i, r); + j = i - 1; + i = i + 1; + register zvect_index k; + for (k = l; k < p; k++, j--) { + vect_swap(v, k, j); + } + for (k = r - 1; k > q; k--, i++) { + vect_swap(v, k, i); + } + p_vect_qsort(v, l, j, compare_func); + p_vect_qsort(v, i, r, compare_func); } -#endif // ! TRADITIONAL_QSORT +#endif // ! TRADITIONAL_QSORT void vect_qsort(const vector v, int (*compare_func)(const void *, const void *)) { - // Check parameters: - if ( compare_func == NULL ) - return; + // Check parameters: + if (compare_func == NULL) { + return; + } - zvect_retval rval = p_vect_check(v); - if (rval) - goto JOB_DONE; + zvect_retval rval = p_vect_check(v); + if (rval) { + goto JOB_DONE; + } #if (ZVECT_THREAD_SAFE == 1) - zvect_retval lock_owner = (locking_disabled || (v->flags & ZV_NOLOCKING)) ? 0 : get_mutex_lock(v, 1); + zvect_retval lock_owner = (locking_disabled || (v->flags & ZV_NOLOCKING)) ? 0 : get_mutex_lock(v, 1); #endif - zvect_index vsize = p_vect_size(v); - if (vsize <= 1) - goto DONE_PROCESSING; + zvect_index vsize = p_vect_size(v); + if (vsize <= 1) { + goto DONE_PROCESSING; + } - // Process the vector: - p_vect_qsort(v, 0, vsize - 1, compare_func); + // Process the vector: + p_vect_qsort(v, 0, vsize - 1, compare_func); DONE_PROCESSING: #if (ZVECT_THREAD_SAFE == 1) - if (lock_owner) - get_mutex_unlock(v, 1); + if (lock_owner) { + get_mutex_unlock(v, 1); + } #endif JOB_DONE: - if (rval) - p_throw_error(rval, NULL); + if (rval) { + p_throw_error(rval, NULL); + } } #ifdef TRADITIONAL_BINARY_SEARCH -static bool p_standard_binary_search(vector v, const void *key, - zvect_index *item_index, - int (*f1)(const void *, const void *)) { - zvect_index bot, top; +static bool p_standard_binary_search(vector v, + const void *key, + zvect_index *item_index, + int (*f1)(const void *, const void *)) { + zvect_index bot, top; - bot = 0; - top = p_vect_size(v) - 1; + bot = 0; + top = p_vect_size(v) - 1; - while (bot < top) { - zvect_index mid // mid-point - mid = top - (top - bot) / 2; + while (bot < top) { + zvect_index mid // mid-point + mid = top - (top - bot) / 2; - // key < array[mid] - if ((*f1)(key, v->data[v->begin + mid]) < 0) { - top = mid - 1; - } else { - bot = mid; - } - } + // key < array[mid] + if ((*f1)(key, v->data[v->begin + mid]) < 0) { + top = mid - 1; + } else { + bot = mid; + } + } - // key == array[top] - if ((*f1)(key, v->data[v->begin + top]) == 0) { - *item_index = top; - return true; - } + // key == array[top] + if ((*f1)(key, v->data[v->begin + top]) == 0) { + *item_index = top; + return true; + } - *item_index = top; - return false; + *item_index = top; + return false; } -#endif // TRADITIONAL_BINARY_SEARCH +#endif // TRADITIONAL_BINARY_SEARCH #ifndef TRADITIONAL_BINARY_SEARCH // This is my re-implementation of Igor van den Hoven's Adaptive @@ -2333,122 +2456,126 @@ static bool p_standard_binary_search(vector v, const void *key, // original design, most notably the use of custom compare // function that makes it suitable also to search through strings // and other types of vectors. -static bool p_adaptive_binary_search(vector const v, const void *key, - zvect_index *item_index, - int (*f1)(const void *, const void *)) { - zvect_index bot; - zvect_index top; - zvect_index mid; +static bool p_adaptive_binary_search(vector const v, + const void *key, + zvect_index *item_index, + int (*f1)(const void *, const void *)) { + zvect_index bot; + zvect_index top; + zvect_index mid; - if ((v->balance >= 32) || (p_vect_size(v) <= 64)) { - bot = 0; - top = p_vect_size(v); - goto MONOBOUND; - } - bot = v->bottom; - top = 32; + if ((v->balance >= 32) || (p_vect_size(v) <= 64)) { + bot = 0; + top = p_vect_size(v); + goto MONOBOUND; + } + bot = v->bottom; + top = 32; - // key >= array[bot] - if ((*f1)(key, v->data[v->begin + bot]) >= 0) { - while (1) { - if ((bot + top) >= p_vect_size(v)) { - top = p_vect_size(v) - bot; - break; - } - bot += top; + // key >= array[bot] + if ((*f1)(key, v->data[v->begin + bot]) >= 0) { + while (1) { + if ((bot + top) >= p_vect_size(v)) { + top = p_vect_size(v) - bot; + break; + } + bot += top; - // key < array[bot] - if ((*f1)(key, v->data[v->begin + bot]) < 0) { - bot -= top; - break; - } - top *= 2; - } - } else { - while (1) { - if (bot < top) { - top = bot; - bot = 0; - break; - } - bot -= top; + // key < array[bot] + if ((*f1)(key, v->data[v->begin + bot]) < 0) { + bot -= top; + break; + } + top *= 2; + } + } else { + while (1) { + if (bot < top) { + top = bot; + bot = 0; + break; + } + bot -= top; - // key >= array[bot] - if ((*f1)(key, v->data[v->begin + bot]) >= 0) - break; - top *= 2; - } - } + // key >= array[bot] + if ((*f1)(key, v->data[v->begin + bot]) >= 0) { + break; + } + top *= 2; + } + } - MONOBOUND: - while (top > 3) { - mid = top / 2; - // key >= array[bot + mid] - if ((*f1)(key, v->data[v->begin + (bot + mid)]) >= 0) - bot += mid; - top -= mid; - } +MONOBOUND: + while (top > 3) { + mid = top / 2; + // key >= array[bot + mid] + if ((*f1)(key, v->data[v->begin + (bot + mid)]) >= 0) { + bot += mid; + } + top -= mid; + } - v->balance = v->bottom > bot ? v->bottom - bot : bot - v->bottom; - v->bottom = bot; + v->balance = v->bottom > bot ? v->bottom - bot : bot - v->bottom; + v->bottom = bot; - while (top) { - // key == array[bot + --top] - int test = (*f1)(key, v->data[v->begin + (bot + (--top))]); - if (test == 0) { - *item_index = bot + top; - return true; - } else if (test > 0) { - *item_index = bot + (top + 1); - return false; - } - } + while (top) { + // key == array[bot + --top] + int test = (*f1)(key, v->data[v->begin + (bot + (--top))]); + if (test == 0) { + *item_index = bot + top; + return true; + } else if (test > 0) { + *item_index = bot + (top + 1); + return false; + } + } - *item_index = bot + top; - return false; + *item_index = bot + top; + return false; } -#endif // ! TRADITIONAL_BINARY_SEARCH +#endif // ! TRADITIONAL_BINARY_SEARCH -bool vect_bsearch(vector const v, const void *key, - int (*f1)(const void *, const void *), - zvect_index *item_index) { - // Check parameters: - if ((key == NULL) || (f1 == NULL) || (p_vect_size(v) == 0)) - return false; +bool vect_bsearch(vector const v, const void *key, int (*f1)(const void *, const void *), zvect_index *item_index) { + // Check parameters: + if ((key == NULL) || (f1 == NULL) || (p_vect_size(v) == 0)) { + return false; + } - *item_index = 0; - // check if the vector exists: - zvect_retval rval = p_vect_check(v); - if (rval) - goto JOB_DONE; + *item_index = 0; + // check if the vector exists: + zvect_retval rval = p_vect_check(v); + if (rval) { + goto JOB_DONE; + } - // TODO: Add mutex locking + // TODO: Add mutex locking #ifdef TRADITIONAL_BINARY_SEARCH - if (p_standard_binary_search(v, key, item_index, f1)) { - return true; - } else { - *item_index = 0; - return false; - } -#endif // TRADITIONAL_BINARY_SEARCH + if (p_standard_binary_search(v, key, item_index, f1)) { + return true; + } else { + *item_index = 0; + return false; + } +#endif // TRADITIONAL_BINARY_SEARCH #ifndef TRADITIONAL_BINARY_SEARCH - if (p_adaptive_binary_search(v, key, item_index, f1)) { - return true; - } else { - *item_index = 0; - return false; - } -#endif // ! TRADITIONAL_BINARY_SEARCH + if (p_adaptive_binary_search(v, key, item_index, f1)) { + return true; + } else { + *item_index = 0; + return false; + } +#endif // ! TRADITIONAL_BINARY_SEARCH -// DONE_PROCESSING: - // TODO: Add mutex unlock + // DONE_PROCESSING: + // TODO: Add mutex unlock JOB_DONE: - if (rval) - p_throw_error(rval, NULL); + if (rval) { + p_throw_error(rval, NULL); + } - return false; + return false; } /* @@ -2456,236 +2583,256 @@ JOB_DONE: * functions, the vect_add_ordered is an exception because it * requires vect_bserach and vect_qsort to be available. */ -void vect_add_ordered(vector const v, const void *value, - int (*f1)(const void *, const void *)) { - // Check parameters: - if (value == NULL) - return; +void vect_add_ordered(vector const v, const void *value, int (*f1)(const void *, const void *)) { + // Check parameters: + if (value == NULL) { + return; + } - // check if the vector exists: - zvect_retval rval = p_vect_check(v); - if (rval) - goto JOB_DONE; + // check if the vector exists: + zvect_retval rval = p_vect_check(v); + if (rval) { + goto JOB_DONE; + } #if (ZVECT_THREAD_SAFE == 1) - zvect_retval lock_owner = (locking_disabled || (v->flags & ZV_NOLOCKING)) ? 0 : get_mutex_lock(v, 2); + zvect_retval lock_owner = (locking_disabled || (v->flags & ZV_NOLOCKING)) ? 0 : get_mutex_lock(v, 2); #endif - // Few tricks to make it faster: - zvect_index vsize = p_vect_size(v); - if (vsize == 0) { - // If the vector is empty clearly we can just - // use vect_add and add the value normally! - vect_add(v, value); - goto DONE_PROCESSING; - } + // Few tricks to make it faster: + zvect_index vsize = p_vect_size(v); + if (vsize == 0) { + // If the vector is empty clearly we can just + // use vect_add and add the value normally! + vect_add(v, value); + goto DONE_PROCESSING; + } - if ((*f1)(value, v->data[v->begin + (vsize - 1)]) > 0) { - // If the compare function returns that - // the value passed should go after the - // last value in the vector, just do so! - vect_add(v, value); - goto DONE_PROCESSING; - } + if ((*f1)(value, v->data[v->begin + (vsize - 1)]) > 0) { + // If the compare function returns that + // the value passed should go after the + // last value in the vector, just do so! + vect_add(v, value); + goto DONE_PROCESSING; + } - // Ok previous checks didn't help us, so we need - // to get "heavy weapons" out and find where in - // the vector we should add "value": - zvect_index item_index = 0; + // Ok previous checks didn't help us, so we need + // to get "heavy weapons" out and find where in + // the vector we should add "value": + zvect_index item_index = 0; - // Here is another trick: - // I improved adaptive binary search to ALWAYS - // return an index (even when it doesn't find a - // searched item), this works for both: regular - // searches which will also use the bool to - // know if we actually found the item in that - // item_index or not and the vect_add_ordered - // which will use item_index (which will be the - // place where value should have been) to insert - // value as an ordered item :) - p_adaptive_binary_search(v, value, &item_index, f1); + // Here is another trick: + // I improved adaptive binary search to ALWAYS + // return an index (even when it doesn't find a + // searched item), this works for both: regular + // searches which will also use the bool to + // know if we actually found the item in that + // item_index or not and the vect_add_ordered + // which will use item_index (which will be the + // place where value should have been) to insert + // value as an ordered item :) + p_adaptive_binary_search(v, value, &item_index, f1); - vect_add_at(v, value, item_index); + vect_add_at(v, value, item_index); DONE_PROCESSING: #if (ZVECT_THREAD_SAFE == 1) - if (lock_owner) - get_mutex_unlock(v, 2); + if (lock_owner) { + get_mutex_unlock(v, 2); + } #endif JOB_DONE: - if(rval) - p_throw_error(rval, NULL); + if (rval) { + p_throw_error(rval, NULL); + } } -#endif // ZVECT_DMF_EXTENSIONS +#endif // ZVECT_DMF_EXTENSIONS #ifdef ZVECT_SFMD_EXTENSIONS // Single Function Call Multiple Data operations extensions: void vect_apply(vector const v, void (*f)(void *)) { - // Check Parameters: - if (f == NULL) - return; + // Check Parameters: + if (f == NULL) { + return; + } - zvect_retval rval = p_vect_check(v); - if (rval) - goto JOB_DONE; + zvect_retval rval = p_vect_check(v); + if (rval) { + goto JOB_DONE; + } #if (ZVECT_THREAD_SAFE == 1) - zvect_retval lock_owner = (locking_disabled || (v->flags & ZV_NOLOCKING)) ? 0 : get_mutex_lock(v, 1); + zvect_retval lock_owner = (locking_disabled || (v->flags & ZV_NOLOCKING)) ? 0 : get_mutex_lock(v, 1); #endif - // Process the vector: - for (register zvect_index i = p_vect_size(v); i--;) - (*f)(v->data[v->begin + i]); + // Process the vector: + for (register zvect_index i = p_vect_size(v); i--;) { + (*f)(v->data[v->begin + i]); + } //DONE_PROCESSING: #if (ZVECT_THREAD_SAFE == 1) - if (lock_owner) - get_mutex_unlock(v, 1); + if (lock_owner) { + get_mutex_unlock(v, 1); + } #endif JOB_DONE: - if(rval) - p_throw_error(rval, NULL); + if (rval) { + p_throw_error(rval, NULL); + } } -void vect_apply_range(vector const v, void (*f)(void *), const zvect_index x, - const zvect_index y) { - // Check parameters: - if ( f == NULL ) - return; +void vect_apply_range(vector const v, void (*f)(void *), const zvect_index x, const zvect_index y) { + // Check parameters: + if (f == NULL) { + return; + } - // check if the vector exists: - zvect_retval rval = p_vect_check(v); - if (rval) - goto JOB_DONE; + // check if the vector exists: + zvect_retval rval = p_vect_check(v); + if (rval) { + goto JOB_DONE; + } #if (ZVECT_THREAD_SAFE == 1) - zvect_retval lock_owner = (locking_disabled || (v->flags & ZV_NOLOCKING)) ? 0 : get_mutex_lock(v, 1); + zvect_retval lock_owner = (locking_disabled || (v->flags & ZV_NOLOCKING)) ? 0 : get_mutex_lock(v, 1); #endif - if (x > p_vect_size(v) || y > p_vect_size(v)) - { - rval = ZVERR_IDXOUTOFBOUND; - goto DONE_PROCESSING; - } + if (x > p_vect_size(v) || y > p_vect_size(v)) { + rval = ZVERR_IDXOUTOFBOUND; + goto DONE_PROCESSING; + } - zvect_index start; - zvect_index end; - if (x > y) { - start = x; - end = y; - } else { - start = y; - end = x; - } + zvect_index start; + zvect_index end; + if (x > y) { + start = x; + end = y; + } else { + start = y; + end = x; + } - // Process the vector: - for (register zvect_index i = start; i <= end; i++) - (*f)(v->data[v->begin + i]); + // Process the vector: + for (register zvect_index i = start; i <= end; i++) { + (*f)(v->data[v->begin + i]); + } DONE_PROCESSING: #if (ZVECT_THREAD_SAFE == 1) - if (lock_owner) - get_mutex_unlock(v, 1); + if (lock_owner) { + get_mutex_unlock(v, 1); + } #endif JOB_DONE: - if(rval) - p_throw_error(rval, NULL); + if (rval) { + p_throw_error(rval, NULL); + } } -void vect_apply_if(vector const v1, vector const v2, void (*f1)(void *), - bool (*f2)(void *, void *)) { - // Check parameters: - if (f1 == NULL || f2 == NULL) - return; +void vect_apply_if(vector const v1, vector const v2, void (*f1)(void *), bool (*f2)(void *, void *)) { + // Check parameters: + if (f1 == NULL || f2 == NULL) { + return; + } - // check if the vector exists: - zvect_retval rval = p_vect_check(v1) | p_vect_check(v2); - if (rval) - goto JOB_DONE; + // check if the vector exists: + zvect_retval rval = p_vect_check(v1) | p_vect_check(v2); + if (rval) { + goto JOB_DONE; + } #if (ZVECT_THREAD_SAFE == 1) - zvect_retval lock_owner = (locking_disabled || (v1->flags & ZV_NOLOCKING)) ? 0 : get_mutex_lock(v1, 1); + zvect_retval lock_owner = (locking_disabled || (v1->flags & ZV_NOLOCKING)) ? 0 : get_mutex_lock(v1, 1); #endif - // Check parameters: - if (p_vect_size(v1) > p_vect_size(v2)) { - rval = ZVERR_VECTTOOSMALL; - goto DONE_PROCESSING; - } + // Check parameters: + if (p_vect_size(v1) > p_vect_size(v2)) { + rval = ZVERR_VECTTOOSMALL; + goto DONE_PROCESSING; + } - // Process vectors: - for (register zvect_index i = p_vect_size(v1); i--;) - if ((*f2)(v1->data[v1->begin + i], v2->data[v2->begin + i])) - (*f1)(v1->data[v1->begin + i]); + // Process vectors: + for (register zvect_index i = p_vect_size(v1); i--;) { + if ((*f2)(v1->data[v1->begin + i], v2->data[v2->begin + i])) { + (*f1)(v1->data[v1->begin + i]); + } + } DONE_PROCESSING: #if (ZVECT_THREAD_SAFE == 1) - if (lock_owner) - get_mutex_unlock(v1, 1); + if (lock_owner) { + get_mutex_unlock(v1, 1); + } #endif JOB_DONE: - if(rval) - p_throw_error(rval, NULL); + if (rval) { + p_throw_error(rval, NULL); + } } -void vect_copy(vector const v1, vector const v2, const zvect_index s2, - const zvect_index e2) { - // check if the vectors v1 and v2 exist: - zvect_retval rval = p_vect_check(v1) | p_vect_check(v2); - if (rval) - goto JOB_DONE; +void vect_copy(vector const v1, vector const v2, const zvect_index s2, const zvect_index e2) { + // check if the vectors v1 and v2 exist: + zvect_retval rval = p_vect_check(v1) | p_vect_check(v2); + if (rval) { + goto JOB_DONE; + } #if (ZVECT_THREAD_SAFE == 1) - zvect_retval lock_owner = (locking_disabled || (v1->flags & ZV_NOLOCKING)) ? 0 : get_mutex_lock(v1, 2); + zvect_retval lock_owner = (locking_disabled || (v1->flags & ZV_NOLOCKING)) ? 0 : get_mutex_lock(v1, 2); #endif - // We can only copy vectors with the same data_size! - if (v1->data_size != v2->data_size) { - rval = ZVERR_VECTDATASIZE; - goto DONE_PROCESSING; - } + // We can only copy vectors with the same data_size! + if (v1->data_size != v2->data_size) { + rval = ZVERR_VECTDATASIZE; + goto DONE_PROCESSING; + } - // Let's check if the indexes provided are correct for - // v2: - if (e2 > p_vect_size(v2) || s2 > p_vect_size(v2)) { - rval = ZVERR_IDXOUTOFBOUND; - goto DONE_PROCESSING; - } + // Let's check if the indexes provided are correct for + // v2: + if (e2 > p_vect_size(v2) || s2 > p_vect_size(v2)) { + rval = ZVERR_IDXOUTOFBOUND; + goto DONE_PROCESSING; + } - // If the user specified 0 max_elements then - // copy the entire vector from start position - // till the last item in the vector 2: - zvect_index ee2; - if (e2 == 0) - ee2 = (p_vect_size(v2) - 1) - s2; - else - ee2 = e2; + // If the user specified 0 max_elements then + // copy the entire vector from start position + // till the last item in the vector 2: + zvect_index ee2; + if (e2 == 0) { + ee2 = (p_vect_size(v2) - 1) - s2; + } else { + ee2 = e2; + } - // Set the correct capacity for v1 to get the whole v2: - while ( p_vect_capacity(v1) <= (p_vect_size(v1) + ee2)) - p_vect_increase_capacity(v1, 1); + // Set the correct capacity for v1 to get the whole v2: + while (p_vect_capacity(v1) <= (p_vect_size(v1) + ee2)) { + p_vect_increase_capacity(v1, 1); + } - // Copy v2 (from s2) in v1 at the end of v1: - p_vect_memcpy(v1->data + v1->begin + p_vect_size(v1), v2->data + v2->begin + s2, sizeof(void *) * ee2); + // Copy v2 (from s2) in v1 at the end of v1: + p_vect_memcpy(v1->data + v1->begin + p_vect_size(v1), v2->data + v2->begin + s2, sizeof(void *) * ee2); - // Update v1 size: - v1->end += ee2; + // Update v1 size: + v1->end += ee2; DONE_PROCESSING: #if (ZVECT_THREAD_SAFE == 1) - if (lock_owner) - get_mutex_unlock(v1, 2); + if (lock_owner) { + get_mutex_unlock(v1, 2); + } #endif JOB_DONE: - if(rval) - p_throw_error(rval, NULL); + if (rval) { + p_throw_error(rval, NULL); + } } /* @@ -2694,93 +2841,96 @@ JOB_DONE: * position s1). * */ -void vect_insert(vector const v1, vector const v2, const zvect_index s2, - const zvect_index e2, const zvect_index s1) { - // check if the vectors v1 and v2 exist: - zvect_retval rval = p_vect_check(v1) | p_vect_check(v2); - if (rval) - goto JOB_DONE; +void vect_insert(vector const v1, vector const v2, const zvect_index s2, const zvect_index e2, const zvect_index s1) { + // check if the vectors v1 and v2 exist: + zvect_retval rval = p_vect_check(v1) | p_vect_check(v2); + if (rval) { + goto JOB_DONE; + } #if (ZVECT_THREAD_SAFE == 1) - zvect_retval lock_owner = (locking_disabled || (v1->flags & ZV_NOLOCKING)) ? 0 : get_mutex_lock(v1, 2); + zvect_retval lock_owner = (locking_disabled || (v1->flags & ZV_NOLOCKING)) ? 0 : get_mutex_lock(v1, 2); #endif - // We can only copy vectors with the same data_size! - if (v1->data_size != v2->data_size) { - rval = ZVERR_VECTDATASIZE; - goto DONE_PROCESSING; - } + // We can only copy vectors with the same data_size! + if (v1->data_size != v2->data_size) { + rval = ZVERR_VECTDATASIZE; + goto DONE_PROCESSING; + } - // Let's check if the indexes provided are correct for - // v2: - if ((e2 > p_vect_size(v2)) || (s2 > p_vect_size(v2))) { - rval = ZVERR_IDXOUTOFBOUND; - goto DONE_PROCESSING; - } + // Let's check if the indexes provided are correct for + // v2: + if ((e2 > p_vect_size(v2)) || (s2 > p_vect_size(v2))) { + rval = ZVERR_IDXOUTOFBOUND; + goto DONE_PROCESSING; + } - // If the user specified 0 max_elements then - // copy the entire vector from start position - // till the last item in the vector 2: - zvect_index ee2; - if (e2 == 0) - ee2 = (p_vect_size(v2) - 1) - s2; - else - ee2 = e2; + // If the user specified 0 max_elements then + // copy the entire vector from start position + // till the last item in the vector 2: + zvect_index ee2; + if (e2 == 0) { + ee2 = (p_vect_size(v2) - 1) - s2; + } else { + ee2 = e2; + } - // Process vectors: - if (ee2 > 1) - { - // Number of rows to insert is large, so let's use - // memmove: + // Process vectors: + if (ee2 > 1) { + // Number of rows to insert is large, so let's use + // memmove: - // Set the correct capacity for v1 to get data from v2: - if (p_vect_capacity(v1) <= (p_vect_size(v1) + ee2)) - p_vect_set_capacity(v1, 1, p_vect_capacity(v1) + ee2); + // Set the correct capacity for v1 to get data from v2: + if (p_vect_capacity(v1) <= (p_vect_size(v1) + ee2)) { + p_vect_set_capacity(v1, 1, p_vect_capacity(v1) + ee2); + } - const void *rptr = NULL; + const void *rptr = NULL; - // Reserve appropriate space in the destination vector - rptr = p_vect_memmove(v1->data + (v1->begin + s1 + ee2), v1->data + (v1->begin + s1), sizeof(void *) * (p_vect_size(v1) - s1)); + // Reserve appropriate space in the destination vector + rptr = p_vect_memmove( + v1->data + (v1->begin + s1 + ee2), v1->data + (v1->begin + s1), sizeof(void *) * (p_vect_size(v1) - s1)); - if (rptr == NULL) - { - rval = ZVERR_VECTCORRUPTED; - goto DONE_PROCESSING; - } + if (rptr == NULL) { + rval = ZVERR_VECTCORRUPTED; + goto DONE_PROCESSING; + } - // Copy items from v2 to v1 at location s1: - rptr = p_vect_memcpy(v1->data + (v1->begin + s1), v2->data + (v2->begin + s2), sizeof(void *) * ee2); + // Copy items from v2 to v1 at location s1: + rptr = p_vect_memcpy(v1->data + (v1->begin + s1), v2->data + (v2->begin + s2), sizeof(void *) * ee2); - if (rptr == NULL) - { - rval = ZVERR_VECTCORRUPTED; - goto DONE_PROCESSING; - } + if (rptr == NULL) { + rval = ZVERR_VECTCORRUPTED; + goto DONE_PROCESSING; + } - // Update v1 size: - v1->end += ee2; - } else { - // Number of rows to insert is small - // so let's use vect_Add_at: - register zvect_index j = 0; + // Update v1 size: + v1->end += ee2; + } else { + // Number of rows to insert is small + // so let's use vect_Add_at: + register zvect_index j = 0; - // Copy v2 items (from s2) in v1 (from s1): - for (register zvect_index i = s2; i <= s2 + ee2; i++, j++) - vect_add_at(v1, v2->data[v2->begin + i], s1 + j); + // Copy v2 items (from s2) in v1 (from s1): + for (register zvect_index i = s2; i <= s2 + ee2; i++, j++) { + vect_add_at(v1, v2->data[v2->begin + i], s1 + j); + } - goto DONE_PROCESSING; - } + goto DONE_PROCESSING; + } - rval = p_vect_delete_at(v2, s2, ee2 - 1, 0); + rval = p_vect_delete_at(v2, s2, ee2 - 1, 0); DONE_PROCESSING: #if (ZVECT_THREAD_SAFE == 1) - if (lock_owner) - get_mutex_unlock(v1, 2); + if (lock_owner) { + get_mutex_unlock(v1, 2); + } #endif JOB_DONE: - if(rval) - p_throw_error(rval, NULL); + if (rval) { + p_throw_error(rval, NULL); + } } /* @@ -2789,180 +2939,243 @@ JOB_DONE: * the end of it). * */ -static inline zvect_retval p_vect_move(vector const v1, vector v2, const zvect_index s2, - const zvect_index e2) { - zvect_retval rval = 0; +static inline zvect_retval p_vect_move(vector const v1, vector v2, const zvect_index s2, const zvect_index e2) { + zvect_retval rval = 0; #ifdef DEBUG - log_msg(ZVLP_INFO, "p_vect_move: move pointers set from v2 to v1\n"); + log_msg(ZVLP_INFO, "p_vect_move: move pointers set from v2 to v1\n"); #endif - // We can only copy vectors with the same data_size! - if (v1->data_size != v2->data_size) - return ZVERR_VECTDATASIZE; + // We can only copy vectors with the same data_size! + if (v1->data_size != v2->data_size) { + return ZVERR_VECTDATASIZE; + } - // Let's check if the indexes provided are correct for - // v2: - if ((e2 > p_vect_size(v2)) || (s2 > p_vect_size(v2))) - return ZVERR_IDXOUTOFBOUND; + // Let's check if the indexes provided are correct for + // v2: + if ((e2 > p_vect_size(v2)) || (s2 > p_vect_size(v2))) { + return ZVERR_IDXOUTOFBOUND; + } - // If the user specified 0 max_elements then - // move the entire vector from start position - // till the last item in the vector 2: - zvect_index ee2; - if (e2 == 0) - ee2 = (p_vect_size(v2) - 1) - s2; - else - ee2 = e2; + // If the user specified 0 max_elements then + // move the entire vector from start position + // till the last item in the vector 2: + zvect_index ee2; + if (e2 == 0) { + ee2 = (p_vect_size(v2) - 1) - s2; + } else { + ee2 = e2; + } #ifdef DEBUG - log_msg(ZVLP_INFO, "p_vect_move: v2 capacity = %*u, begin = %*u, end = %*u, size = %*u, s2 = %*u, ee2 = %*u\n", 10, p_vect_capacity(v2), 10, v2->begin, 10, v2->end, 10, p_vect_size(v2), 10, s2, 10, ee2); + log_msg(ZVLP_INFO, + "p_vect_move: v2 capacity = %*u, begin = %*u, end = %*u, size = %*u, s2 = %*u, ee2 = %*u\n", + 10, + p_vect_capacity(v2), + 10, + v2->begin, + 10, + v2->end, + 10, + p_vect_size(v2), + 10, + s2, + 10, + ee2); - log_msg(ZVLP_INFO, "p_vect_move: v1 capacity = %*u, begin = %*u, end = %*u, size = %*u\n", 10, p_vect_capacity(v1), 10, v1->begin, 10, v1->end, 10, p_vect_size(v1)); + log_msg(ZVLP_INFO, + "p_vect_move: v1 capacity = %*u, begin = %*u, end = %*u, size = %*u\n", + 10, + p_vect_capacity(v1), + 10, + v1->begin, + 10, + v1->end, + 10, + p_vect_size(v1)); #endif - // Set the correct capacity for v1 to get the whole v2: - if (p_vect_capacity(v1) <= (p_vect_size(v1) + ee2)) - p_vect_set_capacity(v1, 1, p_vect_capacity(v1)+ee2); + // Set the correct capacity for v1 to get the whole v2: + if (p_vect_capacity(v1) <= (p_vect_size(v1) + ee2)) { + p_vect_set_capacity(v1, 1, p_vect_capacity(v1) + ee2); + } #ifdef DEBUG - log_msg(ZVLP_INFO, "p_vect_move: v1 capacity = %*u, begin = %*u, end = %*u, size = %*u\n", 10, p_vect_capacity(v1), 10, v1->begin, 10, v1->end, 10, p_vect_size(v1)); + log_msg(ZVLP_INFO, + "p_vect_move: v1 capacity = %*u, begin = %*u, end = %*u, size = %*u\n", + 10, + p_vect_capacity(v1), + 10, + v1->begin, + 10, + v1->end, + 10, + p_vect_size(v1)); - log_msg(ZVLP_INFO, "p_vect_move: ready to copy pointers set\n"); + log_msg(ZVLP_INFO, "p_vect_move: ready to copy pointers set\n"); #endif - // Move v2 (from s2) in v1 at the end of v1: - const void *rptr = NULL; - if (v1 != v2) - rptr = p_vect_memcpy(v1->data + (v1->begin + p_vect_size(v1)), v2->data + (v2->begin + s2), sizeof(void *) * ee2); - else - rptr = p_vect_memmove(v1->data + (v1->begin + p_vect_size(v1)), v2->data + (v2->begin + s2), sizeof(void *) * ee2); + // Move v2 (from s2) in v1 at the end of v1: + const void *rptr = NULL; + if (v1 != v2) { + rptr = p_vect_memcpy( + v1->data + (v1->begin + p_vect_size(v1)), v2->data + (v2->begin + s2), sizeof(void *) * ee2); + } else { + rptr = p_vect_memmove( + v1->data + (v1->begin + p_vect_size(v1)), v2->data + (v2->begin + s2), sizeof(void *) * ee2); + } - if (rptr == NULL) - { - rval = ZVERR_VECTCORRUPTED; - goto DONE_PROCESSING; - } + if (rptr == NULL) { + rval = ZVERR_VECTCORRUPTED; + goto DONE_PROCESSING; + } - // Update v1 size: - v1->end += ee2; + // Update v1 size: + v1->end += ee2; #ifdef DEBUG - log_msg(ZVLP_INFO, "p_vect_move: done copy pointers set\n"); + log_msg(ZVLP_INFO, "p_vect_move: done copy pointers set\n"); #endif - // Clean up v2 memory slots that no longer belong to v2: - //rval = p_vect_delete_at(v2, s2, ee2 - 1, 0); + // Clean up v2 memory slots that no longer belong to v2: + //rval = p_vect_delete_at(v2, s2, ee2 - 1, 0); DONE_PROCESSING: #ifdef DEBUG - log_msg(ZVLP_INFO, "p_vect_move: v1 capacity = %*u, begin = %*u, end = %*u, size = %*u\n", 10, p_vect_capacity(v1), 10, v1->begin, 10, v1->end, 10, p_vect_size(v1)); - log_msg(ZVLP_INFO, "p_vect_move: v2 capacity = %*u, begin = %*u, end = %*u, size = %*u\n", 10, p_vect_capacity(v2), 10, v2->begin, 10, v2->end, 10, p_vect_size(v2)); + log_msg(ZVLP_INFO, + "p_vect_move: v1 capacity = %*u, begin = %*u, end = %*u, size = %*u\n", + 10, + p_vect_capacity(v1), + 10, + v1->begin, + 10, + v1->end, + 10, + p_vect_size(v1)); + log_msg(ZVLP_INFO, + "p_vect_move: v2 capacity = %*u, begin = %*u, end = %*u, size = %*u\n", + 10, + p_vect_capacity(v2), + 10, + v2->begin, + 10, + v2->end, + 10, + p_vect_size(v2)); #endif - return rval; + return rval; } // END of p_vect_move ////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////// // vect_move moves a portion of a vector (v2) into another (v1): -void vect_move(vector const v1, vector v2, const zvect_index s2, - const zvect_index e2) { - // check if the vectors v1 and v2 exist: - zvect_retval rval = p_vect_check(v1) | p_vect_check(v2); - if (rval) - goto JOB_DONE; +void vect_move(vector const v1, vector v2, const zvect_index s2, const zvect_index e2) { + // check if the vectors v1 and v2 exist: + zvect_retval rval = p_vect_check(v1) | p_vect_check(v2); + if (rval) { + goto JOB_DONE; + } #if (ZVECT_THREAD_SAFE == 1) - // vect_move modifies both vectors, so has to lock them both (if needed) - zvect_retval lock_owner2 = (locking_disabled || (v2->flags & ZV_NOLOCKING)) ? 0 : get_mutex_lock(v2, 1); - zvect_retval lock_owner1 = (locking_disabled || (v1->flags & ZV_NOLOCKING)) ? 0 : get_mutex_lock(v1, 1); + // vect_move modifies both vectors, so has to lock them both (if needed) + zvect_retval lock_owner2 = (locking_disabled || (v2->flags & ZV_NOLOCKING)) ? 0 : get_mutex_lock(v2, 1); + zvect_retval lock_owner1 = (locking_disabled || (v1->flags & ZV_NOLOCKING)) ? 0 : get_mutex_lock(v1, 1); #endif #ifdef DEBUG - log_msg(ZVLP_INFO, "vect_move: --- begin ---\n"); -# if (ZVECT_THREAD_SAFE == 1) - log_msg(ZVLP_INFO, "vect_move: lock_owner1 for vector v1: %*u\n",10,lock_owner1); - log_msg(ZVLP_INFO, "vect_move: lock_owner2 for vector v2: %*u\n",10,lock_owner2); -# endif // ZVECT_THREAD_SAFE + log_msg(ZVLP_INFO, "vect_move: --- begin ---\n"); +#if (ZVECT_THREAD_SAFE == 1) + log_msg(ZVLP_INFO, "vect_move: lock_owner1 for vector v1: %*u\n", 10, lock_owner1); + log_msg(ZVLP_INFO, "vect_move: lock_owner2 for vector v2: %*u\n", 10, lock_owner2); +#endif // ZVECT_THREAD_SAFE #endif - // We can only copy vectors with the same data_size! - if (v1->data_size != v2->data_size) { - rval = ZVERR_VECTDATASIZE; - goto DONE_PROCESSING; - } + // We can only copy vectors with the same data_size! + if (v1->data_size != v2->data_size) { + rval = ZVERR_VECTDATASIZE; + goto DONE_PROCESSING; + } - rval = p_vect_move(v1, v2, s2, e2); + rval = p_vect_move(v1, v2, s2, e2); DONE_PROCESSING: #if (ZVECT_THREAD_SAFE == 1) - if (lock_owner1) - get_mutex_unlock(v1, 1); + if (lock_owner1) { + get_mutex_unlock(v1, 1); + } - rval = p_vect_delete_at(v2, s2, e2 - 1, 0); + rval = p_vect_delete_at(v2, s2, e2 - 1, 0); - if (lock_owner2) - get_mutex_unlock(v2, 1); + if (lock_owner2) { + get_mutex_unlock(v2, 1); + } #endif #ifdef DEBUG - log_msg(ZVLP_INFO, "vect_move: --- end ---\n"); + log_msg(ZVLP_INFO, "vect_move: --- end ---\n"); #endif JOB_DONE: - if(rval) - p_throw_error(rval, NULL); + if (rval) { + p_throw_error(rval, NULL); + } } ///////////////////////////////////////////////////////////////// - ////////////////////////////////////////////////////////////////// // vect_move_if moves a portion of a vector (v2) into another (v1) if f2 is true: -zvect_retval vect_move_if(vector const v1, vector v2, const zvect_index s2, - const zvect_index e2, zvect_retval (*f2)(void *, void *)) { - // check if the vectors v1 and v2 exist: - zvect_retval rval = p_vect_check(v1) | p_vect_check(v2); - if (rval) - goto JOB_DONE; +zvect_retval vect_move_if(vector const v1, + vector v2, + const zvect_index s2, + const zvect_index e2, + zvect_retval (*f2)(void *, void *)) { + // check if the vectors v1 and v2 exist: + zvect_retval rval = p_vect_check(v1) | p_vect_check(v2); + if (rval) { + goto JOB_DONE; + } #if (ZVECT_THREAD_SAFE == 1) - // vect_move modifies both vectors, so has to lock them both (if needed) - zvect_retval lock_owner2 = (locking_disabled || (v2->flags & ZV_NOLOCKING)) ? 0 : get_mutex_lock(v2, 1); - zvect_retval lock_owner1 = (locking_disabled || (v1->flags & ZV_NOLOCKING)) ? 0 : get_mutex_lock(v1, 1); + // vect_move modifies both vectors, so has to lock them both (if needed) + zvect_retval lock_owner2 = (locking_disabled || (v2->flags & ZV_NOLOCKING)) ? 0 : get_mutex_lock(v2, 1); + zvect_retval lock_owner1 = (locking_disabled || (v1->flags & ZV_NOLOCKING)) ? 0 : get_mutex_lock(v1, 1); #endif #ifdef DEBUG - log_msg(ZVLP_INFO, "vect_move_if: --- begin ---\n"); -# if (ZVECT_THREAD_SAFE == 1) - log_msg(ZVLP_INFO, "vect_move_if: lock_owner1 for vector v1: %*u\n",10,lock_owner1); - log_msg(ZVLP_INFO, "vect_move_if: lock_owner2 for vector v2: %*u\n",10,lock_owner2); -# endif // ZVECT_THREAD_SAFE + log_msg(ZVLP_INFO, "vect_move_if: --- begin ---\n"); +#if (ZVECT_THREAD_SAFE == 1) + log_msg(ZVLP_INFO, "vect_move_if: lock_owner1 for vector v1: %*u\n", 10, lock_owner1); + log_msg(ZVLP_INFO, "vect_move_if: lock_owner2 for vector v2: %*u\n", 10, lock_owner2); +#endif // ZVECT_THREAD_SAFE #endif - // We can only move vectors with the same data_size! - if (v1->data_size != v2->data_size) { - rval = ZVERR_VECTDATASIZE; - goto DONE_PROCESSING; - } + // We can only move vectors with the same data_size! + if (v1->data_size != v2->data_size) { + rval = ZVERR_VECTDATASIZE; + goto DONE_PROCESSING; + } - rval = (*f2)(v1, v2) ? p_vect_move(v1, v2, s2, e2) : 1; + rval = (*f2)(v1, v2) ? p_vect_move(v1, v2, s2, e2) : 1; DONE_PROCESSING: #if (ZVECT_THREAD_SAFE == 1) - if (lock_owner1) - get_mutex_unlock(v1, 1); + if (lock_owner1) { + get_mutex_unlock(v1, 1); + } - rval = p_vect_delete_at(v2, s2, e2 - 1, 0); + rval = p_vect_delete_at(v2, s2, e2 - 1, 0); - if (lock_owner2) - get_mutex_unlock(v2, 1); + if (lock_owner2) { + get_mutex_unlock(v2, 1); + } #endif #ifdef DEBUG - log_msg(ZVLP_INFO, "vect_move_if: --- end ---\n"); + log_msg(ZVLP_INFO, "vect_move_if: --- end ---\n"); #endif JOB_DONE: - if(rval && (rval != 1)) - p_throw_error(rval, NULL); + if (rval && (rval != 1)) { + p_throw_error(rval, NULL); + } - return rval; + return rval; } ///////////////////////////////////////////////////////////////// @@ -2970,152 +3183,199 @@ JOB_DONE: ///////////////////////////////////////////////////////////////// // vect_move_on_signal -zvect_retval vect_move_on_signal(vector const v1, vector v2, const zvect_index s2, - const zvect_index e2, zvect_retval (*f2)(void *, void *)) -{ - // check if the vectors v1 and v2 exist: - zvect_retval rval = p_vect_check(v1) | p_vect_check(v2); - if (rval) - goto JOB_DONE; +zvect_retval vect_move_on_signal(vector const v1, + vector v2, + const zvect_index s2, + const zvect_index e2, + zvect_retval (*f2)(void *, void *)) { + // check if the vectors v1 and v2 exist: + zvect_retval rval = p_vect_check(v1) | p_vect_check(v2); + if (rval) { + goto JOB_DONE; + } - // vect_move modifies both vectors, so has to lock them both (if needed) - zvect_retval lock_owner2 = (locking_disabled || (v2->flags & ZV_NOLOCKING)) ? 0 : get_mutex_lock(v2, 1); + // vect_move modifies both vectors, so has to lock them both (if needed) + zvect_retval lock_owner2 = (locking_disabled || (v2->flags & ZV_NOLOCKING)) ? 0 : get_mutex_lock(v2, 1); - zvect_retval lock_owner1 = (locking_disabled || (v1->flags & ZV_NOLOCKING)) ? 0 : get_mutex_lock(v1, 1); + zvect_retval lock_owner1 = (locking_disabled || (v1->flags & ZV_NOLOCKING)) ? 0 : get_mutex_lock(v1, 1); #ifdef DEBUG - log_msg(ZVLP_MEDIUM, "vect_move_on_signal: --- start waiting ---\n"); + log_msg(ZVLP_MEDIUM, "vect_move_on_signal: --- start waiting ---\n"); #endif - // wait until we get a signal - while(!(*f2)(v1, v2) && !(v2->status && (bool)ZVS_USR1_FLAG)) { - pthread_cond_wait(&(v2->cond), &(v2->lock)); - } - v2->status &= ~(ZVS_USR1_FLAG); - //v2->status |= ZVS_USR_FLAG; + // wait until we get a signal + while (!(*f2)(v1, v2) && !(v2->status && (bool)ZVS_USR1_FLAG)) { + pthread_cond_wait(&(v2->cond), &(v2->lock)); + } + v2->status &= ~(ZVS_USR1_FLAG); + //v2->status |= ZVS_USR_FLAG; #ifdef DEBUG - log_msg(ZVLP_MEDIUM, "Set status flag: %*i\n", 10, vect_check_status(v2, 1)); + log_msg(ZVLP_MEDIUM, "Set status flag: %*i\n", 10, vect_check_status(v2, 1)); - log_msg(ZVLP_MEDIUM, "vect_move_on_signal: --- received signal ---\n"); + log_msg(ZVLP_MEDIUM, "vect_move_on_signal: --- received signal ---\n"); - log_msg(ZVLP_MEDIUM, "vect_move_on_signal: --- begin ---\n"); + log_msg(ZVLP_MEDIUM, "vect_move_on_signal: --- begin ---\n"); #endif - // Proceed with move items: - rval = p_vect_move(v1, v2, s2, e2); + // Proceed with move items: + rval = p_vect_move(v1, v2, s2, e2); #ifdef DEBUG - log_msg(ZVLP_MEDIUM, "vect_move_on_signal: --- end ---\n"); + log_msg(ZVLP_MEDIUM, "vect_move_on_signal: --- end ---\n"); #endif - v2->status &= ~(ZVS_USR1_FLAG); + v2->status &= ~(ZVS_USR1_FLAG); #ifdef DEBUG - log_msg(ZVLP_MEDIUM, "Reset status flag: %*i\n", 10, vect_check_status(v2, 1)); + log_msg(ZVLP_MEDIUM, "Reset status flag: %*i\n", 10, vect_check_status(v2, 1)); #endif //DONE_PROCESSING: #ifdef DEBUG - log_msg(ZVLP_MEDIUM, "v1 owner? %*i\n", 10, lock_owner1); + log_msg(ZVLP_MEDIUM, "v1 owner? %*i\n", 10, lock_owner1); #endif - if (lock_owner1) - get_mutex_unlock(v1, 1); + if (lock_owner1) { + get_mutex_unlock(v1, 1); + } #ifdef DEBUG - log_msg(ZVLP_MEDIUM, "v2 owner? %*i\n", 10, lock_owner2); + log_msg(ZVLP_MEDIUM, "v2 owner? %*i\n", 10, lock_owner2); #endif - rval = p_vect_delete_at(v2, s2, e2 - 1, 0); - if (lock_owner2) - get_mutex_unlock(v2, 1); + rval = p_vect_delete_at(v2, s2, e2 - 1, 0); + if (lock_owner2) { + get_mutex_unlock(v2, 1); + } JOB_DONE: - if(rval && (rval != 1)) - p_throw_error(rval, NULL); + if (rval && (rval != 1)) { + p_throw_error(rval, NULL); + } - return rval; + return rval; } -#endif // (ZVECT_THREAD_SAFE == 1) +#endif // (ZVECT_THREAD_SAFE == 1) ///////////////////////////////////////////////////////////////// - ///////////////////////////////////////////////////////////////// // vect_merge merges a vector (v2) into another (v1) void vect_merge(vector const v1, vector v2) { - // check if the vector v1 exists: - zvect_retval rval = p_vect_check(v1) | p_vect_check(v2); - if (rval) - goto JOB_DONE; + // check if the vector v1 exists: + zvect_retval rval = p_vect_check(v1) | p_vect_check(v2); + if (rval) { + goto JOB_DONE; + } #if (ZVECT_THREAD_SAFE == 1) - zvect_retval lock_owner1 = (locking_disabled || (v1->flags & ZV_NOLOCKING)) ? 0 : get_mutex_lock(v1, 1); - zvect_retval lock_owner2 = (locking_disabled || (v2->flags & ZV_NOLOCKING)) ? 0 : get_mutex_lock(v2, 1); + zvect_retval lock_owner1 = (locking_disabled || (v1->flags & ZV_NOLOCKING)) ? 0 : get_mutex_lock(v1, 1); + zvect_retval lock_owner2 = (locking_disabled || (v2->flags & ZV_NOLOCKING)) ? 0 : get_mutex_lock(v2, 1); #endif #ifdef DEBUG - log_msg(ZVLP_INFO, "vect_merge: --- begin ---\n"); -# if (ZVECT_THREAD_SAFE == 1) - log_msg(ZVLP_INFO, "vect_merge: lock_owner1 for vector v1: %*u\n",10,lock_owner1); - log_msg(ZVLP_INFO, "vect_merge: lock_owner2 for vector v2: %*u\n",10,lock_owner2); -# endif // ZVECT_THREAD_SAFE -#endif // DEBUG + log_msg(ZVLP_INFO, "vect_merge: --- begin ---\n"); +#if (ZVECT_THREAD_SAFE == 1) + log_msg(ZVLP_INFO, "vect_merge: lock_owner1 for vector v1: %*u\n", 10, lock_owner1); + log_msg(ZVLP_INFO, "vect_merge: lock_owner2 for vector v2: %*u\n", 10, lock_owner2); +#endif // ZVECT_THREAD_SAFE +#endif // DEBUG - // We can only copy vectors with the same data_size! - if (v1->data_size != v2->data_size) { - rval = ZVERR_VECTDATASIZE; - goto DONE_PROCESSING; - } + // We can only copy vectors with the same data_size! + if (v1->data_size != v2->data_size) { + rval = ZVERR_VECTDATASIZE; + goto DONE_PROCESSING; + } - // Check if the user is trying to merge a vector to itself: - if (v1 == v2) { - rval = ZVERR_OPNOTALLOWED; - goto DONE_PROCESSING; - } + // Check if the user is trying to merge a vector to itself: + if (v1 == v2) { + rval = ZVERR_OPNOTALLOWED; + goto DONE_PROCESSING; + } #ifdef DEBUG - log_msg(ZVLP_INFO, "vect_merge: v2 capacity = %*u, begin = %*u, end: %*u, size = %*u\n", 10, p_vect_capacity(v2), 10, v2->begin, 10, v2->end, 10, p_vect_size(v2)); - log_msg(ZVLP_INFO, "vect_merge: v1 capacity = %*u, begin = %*u, end: %*u, size = %*u\n", 10, p_vect_capacity(v1), 10, v1->begin, 10, v1->end, 10, p_vect_size(v1)); + log_msg(ZVLP_INFO, + "vect_merge: v2 capacity = %*u, begin = %*u, end: %*u, size = %*u\n", + 10, + p_vect_capacity(v2), + 10, + v2->begin, + 10, + v2->end, + 10, + p_vect_size(v2)); + log_msg(ZVLP_INFO, + "vect_merge: v1 capacity = %*u, begin = %*u, end: %*u, size = %*u\n", + 10, + p_vect_capacity(v1), + 10, + v1->begin, + 10, + v1->end, + 10, + p_vect_size(v1)); #endif - // Set the correct capacity for v1 to get the whole v2: - if (p_vect_capacity(v1) <= (p_vect_size(v1) + p_vect_size(v2))) - p_vect_set_capacity(v1, 1, p_vect_capacity(v1) + p_vect_size(v2)); + // Set the correct capacity for v1 to get the whole v2: + if (p_vect_capacity(v1) <= (p_vect_size(v1) + p_vect_size(v2))) { + p_vect_set_capacity(v1, 1, p_vect_capacity(v1) + p_vect_size(v2)); + } #ifdef DEBUG - log_msg(ZVLP_INFO, "vect_merge: v1 capacity = %*u, begin = %*u, end: %*u, size = %*u\n", 10, p_vect_capacity(v1), 10, v1->begin, 10, v1->end, 10, p_vect_size(v1)); + log_msg(ZVLP_INFO, + "vect_merge: v1 capacity = %*u, begin = %*u, end: %*u, size = %*u\n", + 10, + p_vect_capacity(v1), + 10, + v1->begin, + 10, + v1->end, + 10, + p_vect_size(v1)); #endif - // Copy the whole v2 in v1 at the end of v1: - p_vect_memcpy(v1->data + (v1->begin + p_vect_size(v1)), v2->data + v2->begin, sizeof(void *) * p_vect_size(v2)); + // Copy the whole v2 in v1 at the end of v1: + p_vect_memcpy(v1->data + (v1->begin + p_vect_size(v1)), v2->data + v2->begin, sizeof(void *) * p_vect_size(v2)); - // Update v1 size: - v1->end += p_vect_size(v2); + // Update v1 size: + v1->end += p_vect_size(v2); #ifdef DEBUG - log_msg(ZVLP_INFO, "vect_merge: v1 capacity = %*u, begin = %*u, end: %*u, size = %*u\n", 10, p_vect_capacity(v1), 10, v1->begin, 10, v1->end, 10, p_vect_size(v1)); + log_msg(ZVLP_INFO, + "vect_merge: v1 capacity = %*u, begin = %*u, end: %*u, size = %*u\n", + 10, + p_vect_capacity(v1), + 10, + v1->begin, + 10, + v1->end, + 10, + p_vect_size(v1)); #endif DONE_PROCESSING: #if (ZVECT_THREAD_SAFE == 1) - if (lock_owner2) - get_mutex_unlock(v2, 1); + if (lock_owner2) { + get_mutex_unlock(v2, 1); + } - if (!rval) - rval = p_vect_destroy(v2, 0); + if (!rval) { + rval = p_vect_destroy(v2, 0); + } - if (lock_owner1) - get_mutex_unlock(v1, 1); + if (lock_owner1) { + get_mutex_unlock(v1, 1); + } #else - rval = p_vect_destroy(v2, 0); - // ^ Because we are merging two vectors in one - // after merged v2 to v1 there is no need for - // v2 to still exists, so let's destroy it to - // free memory correctly. + rval = p_vect_destroy(v2, 0); + // ^ Because we are merging two vectors in one + // after merged v2 to v1 there is no need for + // v2 to still exists, so let's destroy it to + // free memory correctly. #endif #ifdef DEBUG - log_msg(ZVLP_INFO, "vect_merge: --- end ---\n"); + log_msg(ZVLP_INFO, "vect_merge: --- end ---\n"); #endif JOB_DONE: - if(rval) - p_throw_error(rval, NULL); + if (rval) { + p_throw_error(rval, NULL); + } } // END of vect_merge diff --git a/srcs/libs/mq/mq_data.c b/srcs/libs/mq/mq_data.c index 2a3c0b2..37e44d4 100644 --- a/srcs/libs/mq/mq_data.c +++ b/srcs/libs/mq/mq_data.c @@ -229,9 +229,9 @@ PMQ_DATA_ADD_USER decode_add_user_msg(const char *pStrJson, PMQ_DATA_ADD_USER *p int j; memset(pCurrent->pUser, 0, sizeof(ADD_USER_USER) * nUser); for (j = 0; j < nUser; j++) { - PADD_USER_USER p = &pCurrent->pUser[j]; - cJSON *pJsonU = cJSON_GetArrayItem(puser, j); - PADD_USER_USER pTmp = j2s_add_user(pJsonU); + PADD_USER_USER p = &pCurrent->pUser[j]; + cJSON *pJsonU = cJSON_GetArrayItem(puser, j); + PADD_USER_USER pTmp = j2s_add_user(pJsonU); if (pTmp) { memcpy(p, pTmp, sizeof(ADD_USER_USER)); diff --git a/srcs/libs/mq/msg_queue.c b/srcs/libs/mq/msg_queue.c index 3bbe607..b5b6bd7 100644 --- a/srcs/libs/mq/msg_queue.c +++ b/srcs/libs/mq/msg_queue.c @@ -105,7 +105,7 @@ int mq_init(void) { return ERR_SUCCESS; } -void* get_mq_context() { +void *get_mq_context() { return g_pContext; } diff --git a/srcs/libs/network/http_svr.c b/srcs/libs/network/http_svr.c index b90419e..531e032 100644 --- a/srcs/libs/network/http_svr.c +++ b/srcs/libs/network/http_svr.c @@ -8,7 +8,7 @@ int http_svr_init() { configuration config; - config.http_listen_address = (char*)config_get_http_server_addr(); + config.http_listen_address = (char *)config_get_http_server_addr(); config.http_listen_port = config_get_http_server_port(); config.thread_count = 0; config.parser = "http_parser"; diff --git a/srcs/libs/network/inet_misc.c b/srcs/libs/network/inet_misc.c index 741037c..66586ed 100644 --- a/srcs/libs/network/inet_misc.c +++ b/srcs/libs/network/inet_misc.c @@ -54,7 +54,7 @@ typedef struct { unsigned int uRetryTimes; PHTTP_REQ_PARAMS pCurlItem; - UT_hash_handle hh;///< UT Hash handle + UT_hash_handle hh; ///< UT Hash handle } CURL_HANDLE_TBL, *PCURL_HANDLE_TBL; static uv_timer_t g_uvCurlTm; @@ -229,10 +229,8 @@ static void checkMultiInfo(void) { pReq->errCode = 0; } - uv_fs_fdatasync(get_task_manager(), - &pReq->uvFsDataSync, - (uv_file)pReq->uvFsOpen.result, - uvFsDataSyncCb); + uv_fs_fdatasync( + get_task_manager(), &pReq->uvFsDataSync, (uv_file)pReq->uvFsOpen.result, uvFsDataSyncCb); } else if (pReq->type == INET_HTTP_WEBSERVICE_POST) { if (pMsg->data.result != CURLE_OK) { if (pReq->onRspCb && pReq->isCancel == FALSE) { @@ -402,13 +400,8 @@ static size_t writeDataCb(void *pData, size_t size, size_t nmemb, void *pParams) pReq->uvFsBuf = uv_buf_init(pData, iMemSize); - wr = uv_fs_write(get_task_manager(), - &pReq->uvFsWrite, - (uv_file)pReq->uvFsOpen.result, - &pReq->uvFsBuf, - 1, - -1, - NULL); + wr = uv_fs_write( + get_task_manager(), &pReq->uvFsWrite, (uv_file)pReq->uvFsOpen.result, &pReq->uvFsBuf, 1, -1, NULL); if (wr > 0) { pReq->dlSize += wr; @@ -440,10 +433,8 @@ static int progressCb(void *pData, double total, double now, double UNUSED(ulTot if (pParams->onPrgCb) { if (pParams->type == INET_HTTP_DOWNLOAD_FILE) { - pParams->onPrgCb(pParams->pReqUrl, - pParams->pTaskUuid, - (unsigned char)(now * 100.0 / total), - pParams->pData); + pParams->onPrgCb( + pParams->pReqUrl, pParams->pTaskUuid, (unsigned char)(now * 100.0 / total), pParams->pData); } } @@ -554,8 +545,11 @@ static void onDlTimeoutCb(uv_timer_t *UNUSED(pufTimer)) { } } -const char *inet_download_file_async(const char *pURL, const char *pPath, on_http_response onRespCb, - on_progress_changed onProgressCb, void *pData) { +const char *inet_download_file_async(const char *pURL, + const char *pPath, + on_http_response onRespCb, + on_progress_changed onProgressCb, + void *pData) { CURLMcode ret; uuid_t msgId; char strMsgId[64]; @@ -614,12 +608,8 @@ const char *inet_download_file_async(const char *pURL, const char *pPath, on_htt dzlog_debug("[%s]: File %s used temp path %s\n", pParams->pTaskUuid, pParams->sPath, pParams->sDlPath); - uv_fs_open(get_task_manager(), - &pParams->uvFsOpen, - pParams->sDlPath, - O_RDWR | O_CREAT | O_TRUNC, - S_IRUSR | S_IWUSR, - NULL); + uv_fs_open( + get_task_manager(), &pParams->uvFsOpen, pParams->sDlPath, O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR, NULL); curl_easy_setopt(pCurl, CURLOPT_WRITEFUNCTION, writeDataCb); curl_easy_setopt(pCurl, CURLOPT_WRITEDATA, pParams); @@ -631,8 +621,8 @@ const char *inet_download_file_async(const char *pURL, const char *pPath, on_htt curl_easy_setopt(pCurl, CURLOPT_PROGRESSDATA, pParams); //curl_easy_setopt(pCurl, CURLOPT_TIMEOUT, 1800L); // Max download times (30 minutes)1800s - curl_easy_setopt(pCurl, CURLOPT_LOW_SPEED_LIMIT, 10000L);// 10K bytes - curl_easy_setopt(pCurl, CURLOPT_LOW_SPEED_TIME, 10L); // 30 seconds + curl_easy_setopt(pCurl, CURLOPT_LOW_SPEED_LIMIT, 10000L); // 10K bytes + curl_easy_setopt(pCurl, CURLOPT_LOW_SPEED_TIME, 10L); // 30 seconds curl_easy_setopt(pCurl, CURLOPT_CONNECTTIMEOUT, 10L); //curl_easy_setopt(pCurl, CURLOPT_CONNECTTIMEOUT_MS, 10L);