libsheepy

C lib for handling text files, strings and json like data structure with an object oriented system
git clone https://spartatek.se/git/libsheepy.git
Log | Files | Refs | README | LICENSE

libsheepyObject.c (114372B)


      1 // MIT License
      2 //
      3 // Copyright (c) 2026 Remy Noulin
      4 //
      5 // Permission is hereby granted, free of charge, to any person obtaining a copy
      6 // of this software and associated documentation files (the "Software"), to deal
      7 // in the Software without restriction, including without limitation the rights
      8 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
      9 // copies of the Software, and to permit persons to whom the Software is
     10 // furnished to do so, subject to the following conditions:
     11 //
     12 // The above copyright notice and this permission notice shall be included in all
     13 // copies or substantial portions of the Software.
     14 //
     15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     16 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     17 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
     18 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
     19 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
     20 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
     21 // SOFTWARE.
     22 
     23 #include "../libsheepyObject.h"
     24 #if (!defined(__OpenBSD__))
     25 // pthread.h is already included in tpool.h for pthread_mutex_t in OpenBSD with GCC 4.9.4
     26 #include "pthread.h"
     27 #endif
     28 #if (!(__APPLE__ || __FreeBSD__ || __TERMUX__ || __OpenBSD__ || __DragonFly__ || MUSL_LIBC || __sun__))
     29 //register_printf_specifier
     30 #include "printf.h"
     31 #endif
     32 #if (!(__APPLE__ || __FreeBSD__ || __OpenBSD__ || __DragonFly__ || __HAIKU__))
     33 // sysinfo
     34 #include "sys/sysinfo.h"
     35 #endif
     36 
     37 #define internal static
     38 
     39 #include <sys/stat.h>
     40 #include <ctype.h>
     41 #include <unistd.h>
     42 #include <stdio.h>
     43 #include <dirent.h>
     44 #include <stdarg.h>
     45 #if (!(__OpenBSD__ || __HAIKU__))
     46 #include <wordexp.h>
     47 #endif
     48 #include <stdbool.h>
     49 #include <string.h>
     50 #include <stdlib.h>
     51 #include <libgen.h>
     52 #include <stdint.h>
     53 
     54 #if (!defined(__OpenBSD__))
     55 #endif
     56 #if (!(__APPLE__ || __FreeBSD__ || __TERMUX__ || __OpenBSD__ || __DragonFly__ || MUSL_LIBC || __sun__))
     57 #endif
     58 #if (!(__APPLE__ || __FreeBSD__ || __OpenBSD__ || __DragonFly__ || __HAIKU__))
     59 #endif
     60 #if (__APPLE__ || __FreeBSD__ || __OpenBSD__ || __DragonFly__ || __sun__ || __HAIKU__)
     61 smallDictt *shSysinfo(void);
     62 smallDictt *shSysinfo(void);
     63 #endif
     64 void cleanUpBaseTerminateG(baset **val);
     65 void cleanUpBaseFreeG(baset **val);
     66 void cleanUpBaseFinishG(baset **val);
     67 void cleanUpBaseSmashG(baset **val);
     68 baset *duplicateBaseG(baset *self);
     69 void freeManyOF(void *paramType, ...);
     70 void terminateManyOF(void *paramType, ...);
     71 void smashManyOF(void *paramType, ...);
     72 void finishManyOF(void *paramType, ...);
     73 smallJsont *getProgPathJO(void);
     74 smallStringt *getProgPathO(void);
     75 smallJsont *getRealProgPathJO(void);
     76 smallStringt *getRealProgPathO(void);
     77 int systemJO(smallJsont *command);
     78 int systemO(smallStringt *command);
     79 int systemNFreeJOF(smallJsont *command, int line, const char *thisFunc, const char *thisFileName);
     80 int systemNFreeOF(smallStringt *command, int line, const char *thisFunc, const char *thisFileName);
     81 #if (!(__APPLE__ || __FreeBSD__ || __TERMUX__ || __OpenBSD__ || __DragonFly__ || MUSL_LIBC || __sun__ || __HAIKU__))
     82 int print_m(FILE *stream, const struct printf_info *info, const void *const *args);
     83 int print_m_arginfo(const struct printf_info *info UNUSED, size_t n, int *argtypes, int* size);
     84 #endif
     85 void putsOF(baset* object);
     86 void putsUndefinedGF(undefinedt* object);
     87 void putsBoolGF(bool object);
     88 void putsBoolPGF(bool* object);
     89 void putsDoubleGF(double object);
     90 void putsDoublePGF(double* object);
     91 void putsIntGF(int64_t object);
     92 void putsIntPGF(int64_t* object);
     93 void putsInt32GF(int32_t object);
     94 void putsInt32PGF(int32_t* object);
     95 void putsUintGF(uint64_t object);
     96 void putsUintPGF(uint64_t* object);
     97 void putsUint32GF(uint32_t object);
     98 void putsUint32PGF(uint32_t* object);
     99 void putsSGF(const char* object);
    100 void putsListSGF(char** object);
    101 void putsListCSGF(const char** object);
    102 void putsDictGF(smallDictt* object);
    103 void putsJsonGF(smallJsont* object);
    104 void putsArrayGF(smallArrayt* object);
    105 void putsSmallBoolGF(smallBoolt* object);
    106 void putsSmallBytesGF(smallBytest* object);
    107 void putsSmallDoubleGF(smallDoublet* object);
    108 void putsSmallIntGF(smallIntt* object);
    109 void putsSmallStringGF(smallStringt* object);
    110 void putsVoidGF(void* object);
    111 void putsSmallContainerGF(smallContainert* object);
    112 char *toStringOF(baset* object);
    113 char *toStringUndefinedGF(undefinedt* object);
    114 char *toStringBoolGF(bool object);
    115 char *toStringBoolPGF(bool* object);
    116 char *toStringFloatGF(float object);
    117 char *toStringFloatPGF(float* object);
    118 char *toStringDoubleGF(double object);
    119 char *toStringDoublePGF(double* object);
    120 char *toStringIntGF(int64_t object);
    121 char *toStringIntPGF(int64_t* object);
    122 char *toStringInt32GF(int32_t object);
    123 char *toStringInt32PGF(int32_t* object);
    124 char *toStringInt16GF(int16_t object);
    125 char *toStringInt16PGF(int16_t* object);
    126 char *toStringUintGF(uint64_t object);
    127 char *toStringUintPGF(uint64_t* object);
    128 char *toStringUint32GF(uint32_t object);
    129 char *toStringUint32PGF(uint32_t* object);
    130 char *toStringUint16GF(uint16_t object);
    131 char *toStringUint16PGF(uint16_t* object);
    132 char *toStringUint8GF(uint8_t object);
    133 char *toStringUint8PGF(uint8_t* object);
    134 char *toStringCharGF(char object);
    135 char *toStringSGF(const char* object);
    136 char *toStringListSGF(char** object);
    137 char *toStringListCSGF(const char** object);
    138 char *toStringDictGF(smallDictt* object);
    139 char *toStringArrayGF(smallArrayt* object);
    140 char *toStringSmallBoolGF(smallBoolt* object);
    141 char *toStringSmallBytesGF(smallBytest* object);
    142 char *toStringSmallDoubleGF(smallDoublet* object);
    143 char *toStringSmallIntGF(smallIntt* object);
    144 char *toStringSmallStringGF(smallStringt* object);
    145 char *toStringVoidGF(void* object);
    146 char *toStringSmallContainerGF(smallContainert* object);
    147 char *toStringSmallJsonGF(smallJsont* object);
    148 char *otos(void *basetObj);
    149 smallStringt *formatO(const char *fmt, ...);
    150 int execO(const char *cmd, smallArrayt *out, smallArrayt *err UNUSED);
    151 int execSmallJsonO(smallJsont *cmd, smallArrayt *out, smallArrayt *err);
    152 int execSmallStringO(smallStringt *cmd, smallArrayt *out, smallArrayt *err);
    153 smallArrayt* walkDirO(const char* dirPath);
    154 smallArrayt *walkDirSmallJsonO(smallJsont* dirPath);
    155 smallArrayt *walkDirSmallStringO(smallStringt* dirPath);
    156 internal void walkADir(const char *dirPath, smallArrayt *list);
    157 smallArrayt* walkDirDirO(const char* dirPath);
    158 smallArrayt *walkDirDirSmallJsonO(smallJsont* dirPath);
    159 smallArrayt *walkDirDirSmallStringO(smallStringt* dirPath);
    160 internal void walkADirDir(const char *dirPath, smallArrayt *list);
    161 smallArrayt *readDirO(const char *dirPath);
    162 smallArrayt *readDirSmallJsonO(smallJsont *dirPath);
    163 smallArrayt *readDirSmallStringO(smallStringt *dirPath);
    164 smallArrayt *readDirDirO(const char *dirPath);
    165 smallArrayt *readDirDirSmallJsonO(smallJsont *dirPath);
    166 smallArrayt *readDirDirSmallStringO(smallStringt *dirPath);
    167 smallArrayt *walkDirAllO(const char* dirPath);
    168 smallArrayt *walkDirAllSmallJsonO(smallJsont* dirPath);
    169 smallArrayt *walkDirAllSmallStringO(smallStringt* dirPath);
    170 internal void walkADirAll(const char *dirPath, smallArrayt *list);
    171 smallArrayt *readDirAllO(const char *dirPath);
    172 smallArrayt *readDirAllSmallJsonO(smallJsont *dirPath);
    173 smallArrayt *readDirAllSmallStringO(smallStringt *dirPath);
    174 time_t getModificationTimeJO(smallJsont *path);
    175 time_t getModificationTimeO(smallStringt *path);
    176 int setModificationTimeJO(smallJsont *path, time_t mtime);
    177 int setModificationTimeO(smallStringt *path, time_t mtime);
    178 bool equalModificationTimesJO(smallJsont *path1, smallJsont *path2);
    179 bool equalModificationTimesSJO(const char *path1, smallJsont *path2);
    180 bool equalModificationTimesJOS(smallJsont *path1, const char *path2);
    181 bool equalModificationTimesJOO(smallJsont *path1, smallStringt *path2);
    182 bool equalModificationTimesOJO(smallStringt *path1, smallJsont *path2);
    183 bool equalModificationTimesO(smallStringt *path1, smallStringt *path2);
    184 bool equalModificationTimesSO(const char *path1, smallStringt *path2);
    185 bool equalModificationTimesOS(smallStringt *path1, const char *path2);
    186 smallJsont *timeToJO(const time_t t);
    187 smallStringt *timeToSO(const time_t t);
    188 smallJsont *shDirnameJO(smallJsont *path);
    189 smallStringt *shDirnameO(smallStringt *path);
    190 smallJsont *expandHomeJO(smallJsont *path);
    191 #if (__OpenBSD__ || __HAIKU__)
    192 smallStringt *expandHomeO(smallStringt *path);
    193 #else
    194 smallStringt *expandHomeO(smallStringt *path);
    195 #endif
    196 smallJsont *normalizePathJO(smallJsont *path);
    197 smallStringt *normalizePathO(smallStringt *path);
    198 smallJsont *getCwdJO(void);
    199 smallStringt *getCwdO(void);
    200 int chDirJO(smallJsont *path);
    201 int chDirO(smallStringt *path);
    202 bool isDirJO(smallJsont *path);
    203 bool isDirO(smallStringt *path);
    204 bool isLinkJO(smallJsont *path);
    205 bool isLinkO(smallStringt *path);
    206 bool fileExistsJO(smallJsont *filePath);
    207 bool fileExistsO(smallStringt *filePath);
    208 bool fileChmodJO(smallJsont *filePath, mode_t mode);
    209 bool fileChmodO(smallStringt *filePath, mode_t mode);
    210 ssize_t fileSizeJO(smallJsont *filePath);
    211 ssize_t fileSizeO(smallStringt *filePath);
    212 void *readFileToNewG(void *none UNUSED, const char *filePath);
    213 void *readStreamToNewG(void *none UNUSED, FILE *fp);
    214 char *readFileToG(char **string, const char *filePath);
    215 char *readStreamToG(char **string, FILE *fp);
    216 void readTextSmallJsonNotSupported(char ***self UNUSED, smallJsont *path UNUSED);
    217 void readTextSmallStringNotSupported(char ***self UNUSED, smallStringt *path UNUSED);
    218 void readToFileSmallJsonNotSupported(void *self UNUSED, smallJsont *path UNUSED);
    219 void readToFileSmallStringNotSupported(void *self UNUSED, smallStringt *path UNUSED);
    220 int writeFileFromG(const char *string, const char *filePath);
    221 int writeStreamFromG(const char *string, FILE *fp);
    222 int writeTextSmallJsonNotSupported(char **self UNUSED, smallJsont *path UNUSED);
    223 int writeTextSmallStringNotSupported(char **self UNUSED, smallStringt *path UNUSED);
    224 int writeTextCCSmallJsonNotSupported(const char **self UNUSED, smallJsont *path UNUSED);
    225 int writeTextCCSmallStringNotSupported(const char **self UNUSED, smallStringt *path UNUSED);
    226 char **readTextSG(char ***list, const char *filePath);
    227 char **readTextStreamG(char ***list, FILE *fp);
    228 bool writeTextSG(char **list, const char *filePath);
    229 bool writeTextStreamG(char **list, FILE *fp);
    230 bool writeTextCG(const char **list, const char *filePath);
    231 bool writeTextStreamCG(const char **list, FILE *fp);
    232 bool appendFileSG(const char *string, const char *filePath);
    233 bool appendTextSG(char **list, const char *filePath);
    234 bool appendTextCG(const char **list, const char *filePath);
    235 int mkdirParentsSmallJsonO(smallJsont* path);
    236 int mkdirParentsO(smallStringt* path);
    237 int rmAllSmallJsonO(smallJsont* path);
    238 int rmAllO(smallStringt* path);
    239 int copyO(smallStringt* src, smallStringt* dst);
    240 int copySSmallJsonO(const char* src, smallJsont* dst);
    241 int copySO(const char* src, smallStringt* dst);
    242 int copySmallJsonOS(smallJsont* src, const char* dst);
    243 int copySmallJsonSmallJson(smallJsont* src, smallJsont* dst);
    244 int copySmallJsonO(smallJsont* src, smallStringt* dst);
    245 int copyOS(smallStringt* src, const char* dst);
    246 int copyOSmallJson(smallStringt* src, smallJsont* dst);
    247 int renameSmallJsonO(smallJsont* src, smallStringt* dst);
    248 int renameSmallJsonSmallJson(smallJsont* src, smallJsont* dst);
    249 int renameSmallJsonOS(smallJsont* src, const char* dst);
    250 int renameO(smallStringt* src, smallStringt* dst);
    251 int renameOSmallJson(smallStringt* src, smallJsont* dst);
    252 int renameSSmallJsonO(const char* src, smallJsont* dst);
    253 int renameSO(const char* src, smallStringt* dst);
    254 int renameOS(smallStringt* src, const char* dst);
    255 int moveSmallJsonO(smallJsont* src, smallStringt* dst);
    256 int moveSmallJsonSmallJson(smallJsont* src, smallJsont* dst);
    257 int moveSmallJsonOS(smallJsont* src, const char* dst);
    258 int moveO(smallStringt* src, smallStringt* dst);
    259 int moveOSmallJson(smallStringt* src, smallJsont* dst);
    260 int moveSSmallJsonO(const char* src, smallJsont* dst);
    261 int moveSO(const char* src, smallStringt* dst);
    262 int moveOS(smallStringt* src, const char* dst);
    263 smallJsont *randomSmallJsonO(uint64_t length);
    264 smallStringt *randomSO(uint64_t length);
    265 smallJsont *randomAlphaNumSmallJsonO(uint64_t length);
    266 smallStringt *randomAlphaNumSO(uint64_t length);
    267 smallJsont *readSmallJsonO(void);
    268 smallStringt *readO(void);
    269 smallJsont *readLineSmallJsonO(FILE *fp);
    270 smallStringt *readLineO(FILE *fp);
    271 char *intToSG(char *retType UNUSED, int64_t n);
    272 char *doubleToSG(char *retType UNUSED, double n);
    273 char **iListUniqG(char ***list, int dum UNUSED);
    274 char **iicListUniqG(char ***list, int dum UNUSED);
    275 char **listFromArrayG(char **retType UNUSED, char **array, size_t size);
    276 char **listFromCArrayG(char **retType UNUSED, const char **array, size_t size);
    277 char getSG(const char *string, int retType UNUSED, int64_t index);
    278 char *listGetG(char **list, int retType UNUSED, int64_t index);
    279 char *listGetCG(const char **list, int retType UNUSED, int64_t index);
    280 char *iListGetG(char **list, int retType UNUSED, int64_t index);
    281 const char *iListGetCG(const char **list, int retType UNUSED, int64_t index);
    282 char *listPopG(char ***list, int retType UNUSED);
    283 char *listDequeueG(char ***list, int retType UNUSED);
    284 char **listDupCG(const char **list);
    285 bool listEqCG(char **list1, const char **list2);
    286 bool listEqC1G(const char **list1, char **list2);
    287 bool listEqCCG(const char **list1, const char **list2);
    288 bool icListEqCG(char **list1, const char **list2);
    289 bool icListEqC1G(const char **list1, char **list2);
    290 bool icListEqCCG(const char **list1, const char **list2);
    291 size_t listLengthCG(const char **list);
    292 ssize_t listIndexOfCG(const char **list, const char *string);
    293 ssize_t listIndexOfCharCG(const char **list, char c);
    294 ssize_t icListIndexOfCG(const char **list, const char *string);
    295 ssize_t icListIndexOfCharCG(const char **list, char c);
    296 bool listHasCharCG(const char **list, char c);
    297 bool listHasCG(const char **list, const char *string);
    298 bool icListHasCG(const char **list, const char *string);
    299 bool icListHasCharCG(const char **list, char c);
    300 char *joinCG(const char **list, const char* delim);
    301 char *joinCharCG(const char **list, char delim);
    302 char **listAddCG(char **list1, const char **list2);
    303 int listPrintCG(const char **list);
    304 bool eqCharChar(char c, char value);
    305 bool equalChaOG(char c, baset* value);
    306 bool equalChaBoolG(char c UNUSED, bool value UNUSED);
    307 bool equalChaDoubleG(char c, double value);
    308 bool equalChaInt64G(char c, int64_t value);
    309 bool equalChaInt32G(char c, int32_t value);
    310 bool equalChaUint32G(char c, uint32_t value);
    311 bool equalChaUint64G(char c, uint64_t value);
    312 bool equalChaSmallBytesG(char c, smallBytest* value);
    313 bool equalChaSmallDoubleG(char c, smallDoublet* value);
    314 bool equalChaSmallIntG(char c, smallIntt* value);
    315 bool equalChaSmallJsonG(char c, smallJsont* value);
    316 bool equalChaSmallStringG(char c, smallStringt* value);
    317 bool equalCharOG(const char *s, baset* value);
    318 bool equalCharBoolG(const char *s, bool value);
    319 bool equalCharDoubleG(const char *s, double value);
    320 bool equalCharInt64G(const char *s, int64_t value);
    321 bool equalCharInt32G(const char *s, int32_t value);
    322 bool equalCharUint32G(const char *s, uint32_t value);
    323 bool equalCharUint64G(const char *s, uint64_t value);
    324 bool equalCharSmallBoolG(const char *s, smallBoolt* value);
    325 bool equalCharSmallBytesG(const char *s, smallBytest* value);
    326 bool equalCharSmallDoubleG(const char *s, smallDoublet* value);
    327 bool equalCharSmallIntG(const char *s, smallIntt* value);
    328 bool equalCharPSmallJsonG(const char *s, smallJsont* value);
    329 bool equalCharPSmallStringG(const char *s, smallStringt* value);
    330 bool equalArrayOG(char ** p1, baset* p2);
    331 bool equalCArrayOG(const char ** p1, baset* p2);
    332 bool equalArraySmallJsonG(char ** p1, smallJsont* p2);
    333 bool equalArraySmallArrayG(char ** p1, smallArrayt* p2);
    334 bool equalCArraySmallJsonG(const char ** p1, smallJsont* p2);
    335 bool equalCArraySmallArrayG(const char ** p1, smallArrayt* p2);
    336 bool equalOCharG(baset* p1, const char * p2);
    337 bool equalOChaG(baset* p1, char p2);
    338 bool equalOArrayG(baset* p1, char ** p2);
    339 bool equalOCArrayG(baset* p1, const char ** p2);
    340 bool equalOOG(baset* p1, baset* p2);
    341 bool equalOBoolG(baset* p1, bool p2);
    342 bool equalODoubleG(baset* p1, double p2);
    343 bool equalOInt64G(baset* p1, int64_t p2);
    344 bool equalOInt32G(baset* p1, int32_t p2);
    345 bool equalOUint32G(baset* p1, uint32_t p2);
    346 bool equalOUint64G(baset* p1, uint64_t p2);
    347 bool equalOSmallArrayG(baset* p1, smallArrayt* p2);
    348 bool equalOSmallBoolG(baset* p1, smallBoolt* p2);
    349 bool equalOSmallBytesG(baset* p1, smallBytest* p2);
    350 bool equalOSmallDoubleG(baset* p1, smallDoublet* p2);
    351 bool equalOSmallDictG(baset* p1, smallDictt* p2);
    352 bool equalOSmallIntG(baset* p1, smallIntt* p2);
    353 bool equalOSmallJsonG(baset* p1, smallJsont* p2);
    354 bool equalOSmallStringG(baset* p1, smallStringt* p2);
    355 bool equalBoolChaG(bool p1 UNUSED, char p2 UNUSED);
    356 bool equalBoolCharG(bool p1, const char * p2);
    357 bool equalBoolOG(bool p1, baset* p2);
    358 bool equalBoolFG(bool p1, bool p2);
    359 bool equalBoolDoubleG(bool p1, double p2);
    360 bool equalBoolInt64G(bool p1, int64_t p2);
    361 bool equalBoolInt32G(bool p1, int32_t p2);
    362 bool equalBoolUint32G(bool p1, uint32_t p2);
    363 bool equalBoolUint64G(bool p1, uint64_t p2);
    364 bool equalBoolSmallBoolG(bool p1, smallBoolt* p2);
    365 bool equalBoolSmallBytesG(bool p1, smallBytest* p2);
    366 bool equalBoolSmallDoubleG(bool p1, smallDoublet* p2);
    367 bool equalBoolSmallIntG(bool p1, smallIntt* p2);
    368 bool equalBoolSmallJsonG(bool p1, smallJsont* p2);
    369 bool equalBoolSmallStringG(bool p1, smallStringt* p2);
    370 bool equalDoubleChaG(double p1, char p2);
    371 bool equalDoubleCharG(double p1, const char * p2);
    372 bool equalDoubleBaseG(double p1, baset* p2);
    373 bool equalDoubleBoolG(double p1, bool p2);
    374 bool equalDoubleFG(double p1, double p2);
    375 bool equalDoubleInt64G(double p1, int64_t p2);
    376 bool equalDoubleInt32G(double p1, int32_t p2);
    377 bool equalDoubleUint32G(double p1, uint32_t p2);
    378 bool equalDoubleUint64G(double p1, uint64_t p2);
    379 bool equalDoubleSmallBoolG(double p1, smallBoolt* p2);
    380 bool equalDoubleSmallBytesG(double p1, smallBytest* p2);
    381 bool equalDoubleSmallDoubleG(double p1, smallDoublet* p2);
    382 bool equalDoubleSmallIntG(double p1, smallIntt* p2);
    383 bool equalDoubleSmallJsonG(double p1, smallJsont* p2);
    384 bool equalDoubleSmallStringG(double p1, smallStringt* p2);
    385 bool equalInt64ChaG(int64_t p1, char p2);
    386 bool equalInt64CharG(int64_t p1, const char * p2);
    387 bool equalInt64BaseG(int64_t p1, baset* p2);
    388 bool equalInt64BoolG(int64_t p1, bool p2);
    389 bool equalInt64DoubleG(int64_t p1, double p2);
    390 bool equalInt64FG(int64_t p1, int64_t p2);
    391 bool equalInt64Int32G(int64_t p1, int32_t p2);
    392 bool equalInt64Uint32G(int64_t p1, uint32_t p2);
    393 bool equalInt64Uint64G(int64_t p1, uint64_t p2);
    394 bool equalInt64SmallBoolG(int64_t p1, smallBoolt* p2);
    395 bool equalInt64SmallBytesG(int64_t p1, smallBytest* p2);
    396 bool equalInt64SmallDoubleG(int64_t p1, smallDoublet* p2);
    397 bool equalInt64SmallIntG(int64_t p1, smallIntt* p2);
    398 bool equalInt64SmallJsonG(int64_t p1, smallJsont* p2);
    399 bool equalInt64SmallStringG(int64_t p1, smallStringt* p2);
    400 bool equalInt32ChaG(int32_t p1, char p2);
    401 bool equalInt32CharG(int32_t p1, const char * p2);
    402 bool equalInt32BaseG(int32_t p1, baset* p2);
    403 bool equalInt32BoolG(int32_t p1, bool p2);
    404 bool equalInt32DoubleG(int32_t p1, double p2);
    405 bool equalInt32Int64G(int32_t p1, int64_t p2);
    406 bool equalInt32FG(int32_t p1, int32_t p2);
    407 bool equalInt32Uint32G(int32_t p1, uint32_t p2);
    408 bool equalInt32Uint64G(int32_t p1, uint64_t p2);
    409 bool equalInt32SmallBoolG(int32_t p1, smallBoolt* p2);
    410 bool equalInt32SmallBytesG(int32_t p1, smallBytest* p2);
    411 bool equalInt32SmallDoubleG(int32_t p1, smallDoublet* p2);
    412 bool equalInt32SmallIntG(int32_t p1, smallIntt* p2);
    413 bool equalInt32SmallJsonG(int32_t p1, smallJsont* p2);
    414 bool equalInt32SmallStringG(int32_t p1, smallStringt* p2);
    415 bool equalUint32ChaG(uint32_t p1, char p2);
    416 bool equalUint32CharG(uint32_t p1, const char * p2);
    417 bool equalUint32BaseG(uint32_t p1, baset* p2);
    418 bool equalUint32BoolG(uint32_t p1, bool p2);
    419 bool equalUint32DoubleG(uint32_t p1, double p2);
    420 bool equalUint32Int64G(uint32_t p1, int64_t p2);
    421 bool equalUint32Int32G(uint32_t p1, int32_t p2);
    422 bool equalUint32FG(uint32_t p1, uint32_t p2);
    423 bool equalUint32Uint64G(uint32_t p1, uint64_t p2);
    424 bool equalUint32SmallBoolG(uint32_t p1, smallBoolt* p2);
    425 bool equalUint32SmallBytesG(uint32_t p1, smallBytest* p2);
    426 bool equalUint32SmallDoubleG(uint32_t p1, smallDoublet* p2);
    427 bool equalUint32SmallIntG(uint32_t p1, smallIntt* p2);
    428 bool equalUint32SmallJsonG(uint32_t p1, smallJsont* p2);
    429 bool equalUint32SmallStringG(uint32_t p1, smallStringt* p2);
    430 bool equalUint64ChaG(uint64_t p1, char p2);
    431 bool equalUint64CharG(uint64_t p1, const char * p2);
    432 bool equalUint64BaseG(uint64_t p1, baset* p2);
    433 bool equalUint64BoolG(uint64_t p1, bool p2);
    434 bool equalUint64DoubleG(uint64_t p1, double p2);
    435 bool equalUint64Int64G(uint64_t p1, int64_t p2);
    436 bool equalUint64Int32G(uint64_t p1, int32_t p2);
    437 bool equalUint64Uint32G(uint64_t p1, uint32_t p2);
    438 bool equalUint64FG(uint64_t p1, uint64_t p2);
    439 bool equalUint64SmallBoolG(uint64_t p1, smallBoolt* p2);
    440 bool equalUint64SmallBytesG(uint64_t p1, smallBytest* p2);
    441 bool equalUint64SmallDoubleG(uint64_t p1, smallDoublet* p2);
    442 bool equalUint64SmallIntG(uint64_t p1, smallIntt* p2);
    443 bool equalUint64SmallJsonG(uint64_t p1, smallJsont* p2);
    444 bool equalUint64SmallStringG(uint64_t p1, smallStringt* p2);
    445 bool notEqualCharG(char c UNUSED, void *value UNUSED);
    446 bool notEqualOCharG(void *a UNUSED, char c UNUSED);
    447 bool notEqualOG(void *a UNUSED, void *b UNUSED);
    448 bool notEqualCCOG(const char *a UNUSED, void *b UNUSED);
    449 bool notEqualBoolOG(bool p1 UNUSED, void *p2 UNUSED);
    450 bool notEqualDoubleOG(double p1 UNUSED, void *p2 UNUSED);
    451 bool notEqualInt64OG(int64_t p1 UNUSED, void *p2 UNUSED);
    452 bool notEqualInt32OG(int32_t p1 UNUSED, void *p2 UNUSED);
    453 bool notEqualUint32OG(uint32_t p1 UNUSED, void *p2 UNUSED);
    454 bool notEqualUint64OG(uint64_t p1 UNUSED, void *p2 UNUSED);
    455 bool notEqualOBoolG(void *p1 UNUSED, bool p2 UNUSED);
    456 bool notEqualDoubleG(void *p1 UNUSED, double p2 UNUSED);
    457 bool notEqualOInt64G(void *p1 UNUSED, int64_t p2 UNUSED);
    458 bool notEqualOInt32G(void *p1 UNUSED, int32_t p2 UNUSED);
    459 bool notEqualOUint32G(void *p1 UNUSED, uint32_t p2 UNUSED);
    460 bool notEqualOUint64G(void *p1 UNUSED, uint64_t p2 UNUSED);
    461 bool icEqCharChar(char c, char value);
    462 bool icEqualChaOG(char c, baset* value);
    463 bool icEqualChaSmallJsonG(char c, smallJsont* value);
    464 bool icEqualChaSmallStringG(char c, smallStringt* value);
    465 bool icEqualCharOG(const char *s, baset* value);
    466 bool icEqualCharPSmallJsonG(const char *s, smallJsont* value);
    467 bool icEqualCharPSmallStringG(const char *s, smallStringt* value);
    468 bool icEqualArrayOG(char ** p1, baset* p2);
    469 bool icEqualCArrayOG(const char ** p1, baset* p2);
    470 bool icEqualArraySmallJsonG(char ** p1, smallJsont* p2);
    471 bool icEqualCArraySmallJsonG(const char ** p1, smallJsont* p2);
    472 bool icEqualArraySmallArrayG(char ** p1, smallArrayt* p2);
    473 bool icEqualCArraySmallArrayG(const char ** p1, smallArrayt* p2);
    474 bool icEqualOCharG(baset* p1, const char * p2);
    475 bool icEqualOChaG(baset* p1, char p2);
    476 bool icEqualOArrayG(baset* p1, char ** p2);
    477 bool icEqualOCArrayG(baset* p1, const char ** p2);
    478 bool icEqualOOG(baset* p1, baset* p2);
    479 bool icEqualOSmallArrayG(baset* p1, smallArrayt* p2);
    480 bool icEqualOSmallDictG(baset* p1, smallDictt* p2);
    481 bool icEqualOSmallJsonG(baset* p1, smallJsont* p2);
    482 bool icEqualOSmallStringG(baset* p1, smallStringt* p2);
    483 void freeBasetInContainer(void *baseo);
    484 smallt *toSmallt(baset *obj);
    485 baset *toBaset(smallt *obj);
    486 int cpuCount(void);
    487 unsigned registerFinalizeRecycleContainersInThreadPool(recycleContainersFt f);
    488 void finalizeLibsheepyRecycleContainers(void *arg UNUSED);
    489 void finalizeLibsheepyAtExit(void);
    490 #if (__APPLE__ || __FreeBSD__ || __TERMUX__ || __OpenBSD__ || __DragonFly__ || MUSL_LIBC || __sun__ || __HAIKU__)
    491 void initLibsheepyObject(void);
    492 void initLibsheepyObject(void);
    493 void initLibsheepyObjectWithoutTpool(void);
    494 #endif
    495 
    496 /** \file
    497  * This file implements the libsheepyObject support functions
    498  *
    499  * These functions are similar to the ones in libsheepy.h but take and return baset objects
    500  *
    501  * For more information, the documentation is located at http://spartatek.se/libsheepy/
    502  */
    503 
    504 #if (__APPLE__ || __FreeBSD__ || __OpenBSD__ || __DragonFly__ || __sun__ || __HAIKU__)
    505 smallDictt *shSysinfo(void) {
    506 
    507   // TODO macos
    508   // https://stackoverflow.com/questions/12523704/mac-os-x-equivalent-header-file-for-sysinfo-h-in-linux
    509   //
    510   createAllocateSmallDict(r);
    511   if (!r) {
    512     return(NULL);
    513   }
    514 
    515   setIntO(r, "uptime", 0);
    516   setIntO(r, "loads", 0);
    517   setIntO(r, "totalram", 0);
    518   setIntO(r, "freeram", 0);
    519   setIntO(r, "sharedram", 0);
    520   setIntO(r, "bufferram", 0);
    521   setIntO(r, "totalswap", 0);
    522   setIntO(r, "freeswap", 0);
    523   setIntO(r, "procs", 0);
    524   return(r);
    525 }
    526 #else // #if (__APPLE__ || __FreeBSD__ || __OpenBSD__ || __DragonFly__ || __sun__ || __HAIKU__)
    527 smallDictt *shSysinfo(void) {
    528 
    529   createAllocateSmallDict(r);
    530   if (!r) {
    531     return(NULL);
    532   }
    533 
    534   struct sysinfo info;
    535 
    536   if (sysinfo(&info) == -1) {
    537     pFuncError
    538     terminateO(r);
    539     return(NULL);
    540   }
    541 
    542   setIntO(r, "uptime", info.uptime);
    543   setIntO(r, "loads", (int64_t)info.loads[0]);
    544   setIntO(r, "totalram", (int64_t)info.totalram);
    545   setIntO(r, "freeram", (int64_t)info.freeram);
    546   setIntO(r, "sharedram", (int64_t)info.sharedram);
    547   setIntO(r, "bufferram", (int64_t)info.bufferram);
    548   setIntO(r, "totalswap", (int64_t)info.totalswap);
    549   setIntO(r, "freeswap", (int64_t)info.freeswap);
    550   setIntO(r, "procs", info.procs);
    551   return(r);
    552 }
    553 #endif
    554 // #if __APPLE__ || __FreeBSD__ || __OpenBSD__ || __DragonFly__ || __sun__ || __HAIKU__
    555 
    556 void cleanUpBaseTerminateG(baset **val) {
    557 
    558   terminateO(*val);
    559 }
    560 
    561 void cleanUpBaseFreeG(baset **val) {
    562 
    563   freeO(*val);
    564 }
    565 
    566 void cleanUpBaseFinishG(baset **val) {
    567 
    568   finishO(*val);
    569 }
    570 
    571 void cleanUpBaseSmashG(baset **val) {
    572 
    573   smashO(*val);
    574 }
    575 
    576 baset *duplicateBaseG(baset *self) {
    577 
    578   return(self->f->duplicate(self));
    579 }
    580 
    581 void freeManyOF(void *paramType, ...) {
    582   va_list pl;
    583 
    584   freeO((baset*)paramType);
    585 
    586   // add arguments to a list
    587   va_start(pl, paramType);
    588   paramType = va_arg(pl, baset *);
    589   while (paramType) {
    590     freeO((baset*)paramType);
    591     paramType = va_arg(pl, baset *);
    592   }
    593   va_end(pl);
    594 }
    595 
    596 void terminateManyOF(void *paramType, ...) {
    597   va_list pl;
    598   baset *obj = NULL;
    599 
    600   obj = (baset*)paramType;
    601   terminateO(obj);
    602 
    603   // add arguments to a list
    604   va_start(pl, paramType);
    605   paramType = va_arg(pl, baset *);
    606   while (paramType) {
    607     obj = (baset*)paramType;
    608     terminateO(obj);
    609     paramType = va_arg(pl, baset *);
    610   }
    611   va_end(pl);
    612 }
    613 
    614 void smashManyOF(void *paramType, ...) {
    615   va_list pl;
    616   baset *obj = NULL;
    617 
    618   obj = (baset*)paramType;
    619   smashO(obj);
    620 
    621   // add arguments to a list
    622   va_start(pl, paramType);
    623   paramType = va_arg(pl, baset *);
    624   while (paramType) {
    625     obj = (baset*)paramType;
    626     smashO(obj);
    627     paramType = va_arg(pl, baset *);
    628   }
    629   va_end(pl);
    630 }
    631 
    632 void finishManyOF(void *paramType, ...) {
    633   va_list pl;
    634   baset *obj = NULL;
    635 
    636   obj = (baset*)paramType;
    637   finishO(obj);
    638 
    639   // add arguments to a list
    640   va_start(pl, paramType);
    641   paramType = va_arg(pl, baset *);
    642   while (paramType) {
    643     obj = (baset*)paramType;
    644     finishO(obj);
    645     paramType = va_arg(pl, baset *);
    646   }
    647   va_end(pl);
    648 }
    649 
    650 smallJsont *getProgPathJO(void) {
    651 
    652   createAllocateSmallJson(r);
    653   if (!r) {
    654     return(NULL);
    655   }
    656   setTopStringO(r, getProgPath());
    657   return(r);
    658 }
    659 
    660 smallStringt *getProgPathO(void) {
    661 
    662   return(allocSmallString(getProgPath()));
    663 }
    664 
    665 smallJsont *getRealProgPathJO(void) {
    666 
    667   createAllocateSmallJson(r);
    668   if (!r) {
    669     return(NULL);
    670   }
    671   setTopStringO(r, getRealProgPath());
    672   return(r);
    673 }
    674 
    675 smallStringt *getRealProgPathO(void) {
    676 
    677   return(allocSmallString(getRealProgPath()));
    678 }
    679 
    680 int systemJO(smallJsont *command) {
    681 
    682   if (!command) {
    683     return(-1);
    684   }
    685 
    686   const char *type = getTopTypeO(command);
    687 
    688   if (!eqS(type,"string")) {
    689     return(-1);
    690   }
    691 
    692   return(system(getTopSO(command)));
    693 }
    694 
    695 int systemO(smallStringt *command) {
    696 
    697   if (!command) {
    698     return(-1);
    699   }
    700 
    701   return(system(ssGet(command)));
    702 }
    703 
    704 int systemNFreeJOF(smallJsont *command, int line, const char *thisFunc, const char *thisFileName) {
    705   int r;
    706 
    707   if (!command) {
    708     return(-1);
    709   }
    710 
    711   const char *type = getTopTypeO(command);
    712 
    713   if (!eqS(type,"string")) {
    714     return(-1);
    715   }
    716 
    717   char *cmd = getTopSO(command);;
    718 
    719   r = system(cmd);
    720   if (r) {
    721     printf("\nSystem Error at %d, %s, %s. The command was: \"%s\"\n", line, thisFunc, thisFileName, cmd);
    722     printf("\n");
    723   }
    724   terminateO(command);
    725   return(r);
    726 }
    727 
    728 int systemNFreeOF(smallStringt *command, int line, const char *thisFunc, const char *thisFileName) {
    729   int r;
    730 
    731   if (!command) {
    732     return(-1);
    733   }
    734 
    735   char *cmd = ssGet(command);;
    736 
    737   r = system(cmd);
    738   if (r) {
    739     printf("\nSystem Error at %d, %s, %s. The command was: \"%s\"\n", line, thisFunc, thisFileName, cmd);
    740     printf("\n");
    741   }
    742   terminateO(command);
    743   return(r);
    744 }
    745 
    746 #if (!(__APPLE__ || __FreeBSD__ || __TERMUX__ || __OpenBSD__ || __DragonFly__ || MUSL_LIBC || __sun__ || __HAIKU__))
    747 /**
    748  * %m printf type specifier to print baset objects
    749  */
    750 int print_m(FILE *stream, const struct printf_info *info, const void *const *args) {
    751   const baset *o = NULL;
    752   char *b = NULL;
    753   int len;
    754 
    755   o = *((baset*const*) args[0]);
    756   // warning OK: toString discards const qualifier -Wdiscarded-qualifiers
    757   _Pragma ("GCC diagnostic push")
    758   _Pragma ("GCC diagnostic ignored \"-Wdiscarded-qualifiers\"") {
    759   //#pragma GCC diagnostic push
    760   //bug in cg_c - #pragma GCC diagnostic ignored "-Wdiscarded-qualifiers"
    761   b = toStringO(o);
    762   _Pragma ("GCC diagnostic pop")
    763   //#pragma GCC diagnostic pop
    764 
    765   /* Pad to the minimum field width and print to the stream. */
    766   //len = fprintf(stream, "%*s", (info->left ? -info->width : info->width), b)
    767   sheepyRGBFP;
    768   free(b);
    769   return(len);
    770 }
    771   }
    772 
    773 /**
    774  * procress printf argument
    775  */
    776 int print_m_arginfo(const struct printf_info *info UNUSED, size_t n, int *argtypes, int* size) {
    777 
    778   if (n > 0) {
    779     argtypes[0] = PA_POINTER;
    780     size[0]     = sizeof(baset*);
    781   }
    782   return(1);
    783 }
    784 
    785 #endif
    786 // #if __APPLE__ || __FreeBSD_ || __TERMUX__ || __OpenBSD__ || __DragonFly__ || MUSL_LIBC || __sun__ || __HAIKU__
    787 
    788 void putsOF(baset* object) {
    789   char *s = NULL;
    790 
    791   if (!object) {
    792     return;
    793   }
    794   s = toStringO(object);
    795   puts(s);
    796   free(s);
    797 }
    798 
    799 void putsUndefinedGF(undefinedt* object) {
    800   char *s = NULL;
    801 
    802   if (!object) {
    803     return;
    804   }
    805   s = toStringO((baset *)object);
    806   puts(s);
    807   free(s);
    808 }
    809 
    810 void putsBoolGF(bool object) {
    811 
    812   if (object) {
    813     puts("true");
    814   }
    815   else {
    816     puts("false");
    817 }
    818   }
    819 
    820 void putsBoolPGF(bool* object) {
    821 
    822   if (!object) {
    823     return;
    824   }
    825   if (*object) {
    826     puts("true");
    827   }
    828   else {
    829     puts("false");
    830 }
    831   }
    832 
    833 void putsDoubleGF(double object) {
    834   char *s = NULL;
    835 
    836   isError(s, malloc(256*sizeof(char))) {
    837     return;
    838   }
    839   snprintf(s,256, "%e", object);
    840   puts(s);
    841   free(s);
    842 }
    843 
    844 void putsDoublePGF(double* object) {
    845   char *s = NULL;
    846 
    847   if (!object) {
    848     return;
    849   }
    850   isError(s, malloc(256*sizeof(char))) {
    851     return;
    852   }
    853   snprintf(s,256, "%e", *object);
    854   puts(s);
    855   free(s);
    856 }
    857 
    858 void putsIntGF(int64_t object) {
    859   char *s = NULL;
    860 
    861   s = intToS(object);
    862   if (s) {
    863     puts(s);
    864   }
    865   free(s);
    866 }
    867 
    868 void putsIntPGF(int64_t* object) {
    869   char *s = NULL;
    870 
    871   if (!object) {
    872     return;
    873   }
    874   s = intToS(*object);
    875   if (s) {
    876     puts(s);
    877   }
    878   free(s);
    879 }
    880 
    881 void putsInt32GF(int32_t object) {
    882   char *s = NULL;
    883 
    884   s = intToS(object);
    885   if (s) {
    886     puts(s);
    887   }
    888   free(s);
    889 }
    890 
    891 void putsInt32PGF(int32_t* object) {
    892   char *s = NULL;
    893 
    894   if (!object) {
    895     return;
    896   }
    897   s = intToS(*object);
    898   if (s) {
    899     puts(s);
    900   }
    901   free(s);
    902 }
    903 
    904 void putsUintGF(uint64_t object) {
    905   char *s = NULL;
    906 
    907   // TODO create uintToS
    908   s = intToS((int64_t)object);
    909   if (s) {
    910     puts(s);
    911   }
    912   free(s);
    913 }
    914 
    915 void putsUintPGF(uint64_t* object) {
    916   char *s = NULL;
    917 
    918   if (!object) {
    919     return;
    920   }
    921   // TODO create uintToS
    922   s = intToS((int64_t)*object);
    923   if (s) {
    924     puts(s);
    925   }
    926   free(s);
    927 }
    928 
    929 void putsUint32GF(uint32_t object) {
    930   char *s = NULL;
    931 
    932   s = intToS(object);
    933   if (s) {
    934     puts(s);
    935   }
    936   free(s);
    937 }
    938 
    939 void putsUint32PGF(uint32_t* object) {
    940   char *s = NULL;
    941 
    942   if (!object) {
    943     return;
    944   }
    945   s = intToS(*object);
    946   if (s) {
    947     puts(s);
    948   }
    949   free(s);
    950 }
    951 
    952 void putsSGF(const char* object) {
    953 
    954   if (!object) {
    955     return;
    956   }
    957   puts(object);
    958 }
    959 
    960 void putsListSGF(char** object) {
    961 
    962   pError0(listPrintS(object));
    963 }
    964 
    965 void putsListCSGF(const char** object) {
    966 
    967   pError0(listPrintCS(object));
    968 }
    969 
    970 void putsDictGF(smallDictt* object) {
    971   char *s = NULL;
    972 
    973   if (!object) {
    974     return;
    975   }
    976   s = toStringO((baset *)object);
    977   if (s) {
    978     puts(s);
    979   }
    980   free(s);
    981 }
    982 
    983 void putsJsonGF(smallJsont* object) {
    984   char *s = NULL;
    985 
    986   if (!object) {
    987     return;
    988   }
    989   s = toStringO((baset *)object);
    990   if (s) {
    991     puts(s);
    992   }
    993   free(s);
    994 }
    995 
    996 void putsArrayGF(smallArrayt* object) {
    997   char *s = NULL;
    998 
    999   if (!object) {
   1000     return;
   1001   }
   1002   s = toStringO((baset *)object);
   1003   if (s) {
   1004     puts(s);
   1005   }
   1006   free(s);
   1007 }
   1008 
   1009 void putsSmallBoolGF(smallBoolt* object) {
   1010   char *s = NULL;
   1011 
   1012   if (!object) {
   1013     return;
   1014   }
   1015   s = toStringO((baset *)object);
   1016   if (s) {
   1017     puts(s);
   1018   }
   1019   free(s);
   1020 }
   1021 
   1022 void putsSmallBytesGF(smallBytest* object) {
   1023   char *s = NULL;
   1024 
   1025   if (!object) {
   1026     return;
   1027   }
   1028   s = toStringO((baset *)object);
   1029   if (s) {
   1030     puts(s);
   1031   }
   1032   free(s);
   1033 }
   1034 
   1035 void putsSmallDoubleGF(smallDoublet* object) {
   1036   char *s = NULL;
   1037 
   1038   if (!object) {
   1039     return;
   1040   }
   1041   s = toStringO((baset *)object);
   1042   if (s) {
   1043     puts(s);
   1044   }
   1045   free(s);
   1046 }
   1047 
   1048 void putsSmallIntGF(smallIntt* object) {
   1049   char *s = NULL;
   1050 
   1051   if (!object) {
   1052     return;
   1053   }
   1054   s = toStringO((baset *)object);
   1055   if (s) {
   1056     puts(s);
   1057   }
   1058   free(s);
   1059 }
   1060 
   1061 void putsSmallStringGF(smallStringt* object) {
   1062   char *s = NULL;
   1063 
   1064   if (!object) {
   1065     return;
   1066   }
   1067   s = toStringO((baset *)object);
   1068   if (s) {
   1069     puts(s);
   1070   }
   1071   free(s);
   1072 }
   1073 
   1074 void putsVoidGF(void* object) {
   1075 
   1076   if (!object) {
   1077     return;
   1078   }
   1079   puts("Unsupported putsG type or void pointer");
   1080 }
   1081 
   1082 void putsSmallContainerGF(smallContainert* object) {
   1083   char *s = NULL;
   1084 
   1085   if (!object) {
   1086     return;
   1087   }
   1088   s = toStringO((baset *)object);
   1089   if (s) {
   1090     puts(s);
   1091   }
   1092   free(s);
   1093 }
   1094 
   1095 
   1096 char *toStringOF(baset* object) {
   1097 
   1098   if (!object) {
   1099     return(NULL);
   1100   }
   1101   return(toStringO(object));
   1102 }
   1103 
   1104 char *toStringUndefinedGF(undefinedt* object) {
   1105 
   1106   if (!object) {
   1107     return(NULL);
   1108   }
   1109   return(toStringO((baset *)object));
   1110 }
   1111 
   1112 char *toStringBoolGF(bool object) {
   1113 
   1114   if (object) {
   1115     return(strdup("true"));
   1116   }
   1117   else {
   1118     return(strdup("false"));
   1119 }
   1120   }
   1121 
   1122 char *toStringBoolPGF(bool* object) {
   1123 
   1124   if (!object) {
   1125     return(NULL);
   1126   }
   1127   if (*object) {
   1128     return(strdup("true"));
   1129   }
   1130   else {
   1131     return(strdup("false"));
   1132 }
   1133   }
   1134 
   1135 char *toStringFloatGF(float object) {
   1136   char *s = NULL;
   1137 
   1138   isError(s, malloc(256*sizeof(char))) return(NULL);
   1139   snprintf(s,256, "%f", (double)object);
   1140   return(s);
   1141 }
   1142 
   1143 char *toStringFloatPGF(float* object) {
   1144   char *s = NULL;
   1145 
   1146   if (!object) {
   1147     return(NULL);
   1148   }
   1149   isError(s, malloc(256*sizeof(char))) return(NULL);
   1150   snprintf(s,256, "%f", (double)*object);
   1151   return(s);
   1152 }
   1153 
   1154 char *toStringDoubleGF(double object) {
   1155   char *s = NULL;
   1156 
   1157   isError(s, malloc(256*sizeof(char))) return(NULL);
   1158   snprintf(s,256, "%e", object);
   1159   return(s);
   1160 }
   1161 
   1162 char *toStringDoublePGF(double* object) {
   1163   char *s = NULL;
   1164 
   1165   if (!object) {
   1166     return(NULL);
   1167   }
   1168   isError(s, malloc(256*sizeof(char))) return(NULL);
   1169   snprintf(s,256, "%e", *object);
   1170   return(s);
   1171 }
   1172 
   1173 char *toStringIntGF(int64_t object) {
   1174 
   1175   return(intToS(object));
   1176 }
   1177 
   1178 char *toStringIntPGF(int64_t* object) {
   1179 
   1180   if (!object) {
   1181     return(NULL);
   1182   }
   1183   return(intToS(*object));
   1184 }
   1185 
   1186 char *toStringInt32GF(int32_t object) {
   1187 
   1188   return(intToS(object));
   1189 }
   1190 
   1191 char *toStringInt32PGF(int32_t* object) {
   1192 
   1193   if (!object) {
   1194     return(NULL);
   1195   }
   1196   return(intToS(*object));
   1197 }
   1198 
   1199 char *toStringInt16GF(int16_t object) {
   1200 
   1201   return(intToS(object));
   1202 }
   1203 
   1204 char *toStringInt16PGF(int16_t* object) {
   1205 
   1206   if (!object) {
   1207     return(NULL);
   1208   }
   1209   return(intToS(*object));
   1210 }
   1211 
   1212 char *toStringUintGF(uint64_t object) {
   1213 
   1214   // TODO create uintToS
   1215   return(intToS((int64_t)object));
   1216 }
   1217 
   1218 char *toStringUintPGF(uint64_t* object) {
   1219 
   1220   if (!object) {
   1221     return(NULL);
   1222   }
   1223   // TODO create uintToS
   1224   return(intToS((int64_t)*object));
   1225 }
   1226 
   1227 char *toStringUint32GF(uint32_t object) {
   1228 
   1229   return(intToS(object));
   1230 }
   1231 
   1232 char *toStringUint32PGF(uint32_t* object) {
   1233 
   1234   if (!object) {
   1235     return(NULL);
   1236   }
   1237   return(intToS(*object));
   1238 }
   1239 
   1240 char *toStringUint16GF(uint16_t object) {
   1241 
   1242   return(intToS(object));
   1243 }
   1244 
   1245 char *toStringUint16PGF(uint16_t* object) {
   1246 
   1247   if (!object) {
   1248     return(NULL);
   1249   }
   1250   return(intToS(*object));
   1251 }
   1252 
   1253 char *toStringUint8GF(uint8_t object) {
   1254 
   1255   return(intToS(object));
   1256 }
   1257 
   1258 char *toStringUint8PGF(uint8_t* object) {
   1259 
   1260   if (!object) {
   1261     return(NULL);
   1262   }
   1263   return(intToS(*object));
   1264 }
   1265 
   1266 char *toStringCharGF(char object) {
   1267   char r[2];;
   1268 
   1269   r[0] = object;
   1270   r[1] = 0;
   1271 
   1272   return(strdup(r));
   1273 }
   1274 
   1275 char *toStringSGF(const char* object) {
   1276 
   1277   return(dupS(object));
   1278 }
   1279 
   1280 char *toStringListSGF(char** object) {
   1281 
   1282   if (!object) {
   1283     return(NULL);
   1284   }
   1285   char *s = join(object, "\",\"");
   1286   if (!s) {
   1287     // empty list
   1288     return(strdup("[]"));
   1289   }
   1290   char *r = catS("[\"", s, "\"]");;
   1291   free(s);
   1292   return(r);
   1293 }
   1294 
   1295 char *toStringListCSGF(const char** object) {
   1296 
   1297   if (!object) {
   1298     return(NULL);
   1299   }
   1300   char *s = joinCS(object, "\",\"");
   1301   if (!s) {
   1302     // empty list
   1303     return(strdup("[]"));
   1304   }
   1305   char *r = catS("[\"", s, "\"]");;
   1306   free(s);
   1307   return(r);
   1308 }
   1309 
   1310 char *toStringDictGF(smallDictt* object) {
   1311 
   1312   if (!object) {
   1313     return(NULL);
   1314   }
   1315   return(toStringO((baset *)object));
   1316 }
   1317 
   1318 char *toStringArrayGF(smallArrayt* object) {
   1319 
   1320   if (!object) {
   1321     return(NULL);
   1322   }
   1323   return(toStringO((baset *)object));
   1324 }
   1325 
   1326 char *toStringSmallBoolGF(smallBoolt* object) {
   1327 
   1328   if (!object) {
   1329     return(NULL);
   1330   }
   1331   return(toStringO((baset *)object));
   1332 }
   1333 
   1334 char *toStringSmallBytesGF(smallBytest* object) {
   1335 
   1336   if (!object) {
   1337     return(NULL);
   1338   }
   1339   return(toStringO((baset *)object));
   1340 }
   1341 
   1342 char *toStringSmallDoubleGF(smallDoublet* object) {
   1343 
   1344   if (!object) {
   1345     return(NULL);
   1346   }
   1347   return(toStringO((baset *)object));
   1348 }
   1349 
   1350 char *toStringSmallIntGF(smallIntt* object) {
   1351 
   1352   if (!object) {
   1353     return(NULL);
   1354   }
   1355   return(toStringO((baset *)object));
   1356 }
   1357 
   1358 char *toStringSmallStringGF(smallStringt* object) {
   1359 
   1360   if (!object) {
   1361     return(NULL);
   1362   }
   1363   return(toStringO((baset *)object));
   1364 }
   1365 
   1366 char *toStringVoidGF(void* object) {
   1367 
   1368   if (!object) {
   1369     return(NULL);
   1370   }
   1371   return(strdup("Unsupported toStringG type or void pointer"));
   1372 }
   1373 
   1374 char *toStringSmallContainerGF(smallContainert* object) {
   1375 
   1376   if (!object) {
   1377     return(NULL);
   1378   }
   1379   return(toStringO((baset *)object));
   1380 }
   1381 
   1382 char *toStringSmallJsonGF(smallJsont* object) {
   1383 
   1384   if (!object) {
   1385     return(NULL);
   1386   }
   1387   return(toStringO((baset *)object));
   1388 }
   1389 
   1390 char *otos(void *basetObj) {
   1391 
   1392   cast(baset*, obj, basetObj);
   1393   return(toStringO(obj));
   1394 }
   1395 
   1396 smallStringt *formatO(const char *fmt, ...) {
   1397   char *r = NULL;
   1398   va_list pl;
   1399 
   1400   if (!fmt) {
   1401     return(NULL);
   1402   }
   1403   va_start(pl, fmt);
   1404   if (vasprintf(&r, fmt, pl) == -1) {
   1405     va_end(pl);
   1406     return(NULL);
   1407   }
   1408   va_end(pl);
   1409 
   1410   smallStringt *R = allocSmallString(r);
   1411   free(r);
   1412   if (!R) {
   1413     return(NULL);
   1414   }
   1415   return(R);
   1416 }
   1417 
   1418 
   1419 int execO(const char *cmd, smallArrayt *out, smallArrayt *err UNUSED) {
   1420   FILE* fp = NULL;
   1421   char **list = NULL;
   1422 
   1423   // sanity checks
   1424   if (!cmd) {
   1425     return(0);
   1426   }
   1427 
   1428   if (!out) {
   1429     return(0);
   1430   }
   1431 
   1432   fp = popen(cmd, "r");
   1433   if (!fp) {
   1434     pFuncError
   1435     shEPrintfS("The command was: \"%s\"\n", cmd);
   1436     return(0);//LCOV_EXCL_LINE
   1437   }
   1438 
   1439   list = readStream(fp);
   1440 
   1441   pclose(fp);
   1442   out->f->fromArrayNFree(out, list, 0);
   1443   return(1);
   1444 }
   1445 
   1446 int execSmallJsonO(smallJsont *cmd, smallArrayt *out, smallArrayt *err) {
   1447 
   1448   if (!cmd) {
   1449     return(0);
   1450   }
   1451 
   1452   const char *type = getTopTypeO(cmd);
   1453 
   1454   if (!eqS(type,"string")) {
   1455     return(0);
   1456   }
   1457 
   1458   return(execO(sjGet(cmd), out, err));
   1459 }
   1460 
   1461 int execSmallStringO(smallStringt *cmd, smallArrayt *out, smallArrayt *err) {
   1462 
   1463   if (!cmd) {
   1464     return(0);
   1465   }
   1466   return(execO(ssGet(cmd), out, err));
   1467 }
   1468 
   1469 smallArrayt* walkDirO(const char* dirPath) {
   1470 
   1471   // sanity checks
   1472   if (!dirPath || isBlankS(dirPath)) {
   1473     return(NULL);
   1474   }
   1475 
   1476   createAllocateSmallArray(list);
   1477   if (!list) {
   1478     return(NULL);
   1479   }
   1480   walkADir(dirPath, list);
   1481 
   1482   list->f->sort(list);
   1483 
   1484   return(list);
   1485 }
   1486 
   1487 smallArrayt *walkDirSmallJsonO(smallJsont* dirPath) {
   1488 
   1489   if (!dirPath) {
   1490     return(NULL);
   1491   }
   1492 
   1493   const char *type = getTopTypeO(dirPath);
   1494 
   1495   if (!eqS(type,"string")) {
   1496     return(NULL);
   1497   }
   1498 
   1499   return(walkDirO(getTopSO(dirPath)));
   1500 }
   1501 
   1502 smallArrayt *walkDirSmallStringO(smallStringt* dirPath) {
   1503 
   1504   if (!dirPath) {
   1505     return(NULL);
   1506   }
   1507   return(walkDirO(ssGet(dirPath)));
   1508 }
   1509 
   1510 internal void walkADir(const char *dirPath, smallArrayt *list) {
   1511   DIR *d = NULL;
   1512   struct dirent *dp = NULL;
   1513   char *sPath = NULL;
   1514 
   1515   d = opendir(dirPath);
   1516   if (!d) {
   1517     pFuncError
   1518     shEPrintfS("The path was: \"%s\"\n", dirPath);
   1519     return;
   1520   }
   1521 
   1522   dp = readdir(d);
   1523   while (dp) {
   1524     if (eqS(dp->d_name, ".") || eqS(dp->d_name, "..")) {
   1525       dp = readdir(d);
   1526       continue;
   1527     }
   1528 
   1529     sPath = catS(dirPath, "/", dp->d_name);
   1530 
   1531     if (isDir(sPath)) {
   1532       if (!isLink(sPath)) {
   1533         walkADir(sPath, list);
   1534     }
   1535       }
   1536     else {
   1537       list->f->pushS(list, sPath);
   1538     }
   1539     free(sPath);
   1540     dp = readdir(d);
   1541   }
   1542 
   1543   closedir(d);
   1544 }
   1545 
   1546 smallArrayt* walkDirDirO(const char* dirPath) {
   1547 
   1548   // sanity checks
   1549   if (!dirPath || isBlankS(dirPath)) {
   1550     return(NULL);
   1551   }
   1552 
   1553   createAllocateSmallArray(list);
   1554   if (!list) {
   1555     return(NULL);
   1556   }
   1557   walkADirDir(dirPath, list);
   1558 
   1559   list->f->sort(list);
   1560 
   1561   return(list);
   1562 }
   1563 
   1564 smallArrayt *walkDirDirSmallJsonO(smallJsont* dirPath) {
   1565 
   1566   if (!dirPath) {
   1567     return(NULL);
   1568   }
   1569 
   1570   const char *type = getTopTypeO(dirPath);
   1571 
   1572   if (!eqS(type,"string")) {
   1573     return(NULL);
   1574   }
   1575 
   1576   return(walkDirDirO(getTopSO(dirPath)));
   1577 }
   1578 
   1579 smallArrayt *walkDirDirSmallStringO(smallStringt* dirPath) {
   1580 
   1581   if (!dirPath) {
   1582     return(NULL);
   1583   }
   1584   return(walkDirDirO(ssGet(dirPath)));
   1585 }
   1586 
   1587 internal void walkADirDir(const char *dirPath, smallArrayt *list) {
   1588   DIR *d = NULL;
   1589   struct dirent *dp = NULL;
   1590   char *sPath = NULL;
   1591 
   1592   d = opendir(dirPath);
   1593   if (!d) {
   1594     pFuncError
   1595     shEPrintfS("The path was: \"%s\"\n", dirPath);
   1596     return;
   1597   }
   1598 
   1599   dp = readdir(d);
   1600   while (dp) {
   1601     if (eqS(dp->d_name, ".") || eqS(dp->d_name, "..")) {
   1602       dp = readdir(d);
   1603       continue;
   1604     }
   1605 
   1606     sPath = catS(dirPath, "/", dp->d_name);
   1607 
   1608     if (isDir(sPath)) {
   1609       list->f->pushS(list, sPath);
   1610       if (!isLink(sPath)) {
   1611         walkADirDir(sPath, list);
   1612     }
   1613       }
   1614     free(sPath);
   1615     dp = readdir(d);
   1616   }
   1617 
   1618   closedir(d);
   1619 }
   1620 
   1621 smallArrayt *readDirO(const char *dirPath) {
   1622   DIR *d = NULL;
   1623   struct dirent *dp = NULL;
   1624 
   1625   // sanity checks
   1626   if (!dirPath || isBlankS(dirPath)) {
   1627     return(NULL);
   1628   }
   1629 
   1630   createAllocateSmallArray(list);
   1631   if (!list) {
   1632     return(NULL);
   1633   }
   1634 
   1635   d = opendir(dirPath);
   1636   if (!d) {
   1637     pFuncError
   1638     shEPrintfS("The path was: \"%s\"\n", dirPath);
   1639     return(list);
   1640   }
   1641 
   1642   dp = readdir(d);
   1643   while (dp) {
   1644     if (eqS(dp->d_name, ".") || eqS(dp->d_name, "..")) {
   1645       dp = readdir(d);
   1646       continue;
   1647     }
   1648 
   1649     char *sPath = catS(dirPath, "/", dp->d_name);
   1650 
   1651     if (!isDir(sPath)) {
   1652       list->f->pushS(list, dp->d_name);
   1653     }
   1654     free(sPath);
   1655     dp = readdir(d);
   1656   }
   1657 
   1658   closedir(d);
   1659 
   1660   list->f->sort(list);
   1661 
   1662   return(list);
   1663 }
   1664 
   1665 smallArrayt *readDirSmallJsonO(smallJsont *dirPath) {
   1666 
   1667   if (!dirPath) {
   1668     return(NULL);
   1669   }
   1670 
   1671   const char *type = getTopTypeO(dirPath);
   1672 
   1673   if (!eqS(type,"string")) {
   1674     return(NULL);
   1675   }
   1676 
   1677   return(readDirO(getTopSO(dirPath)));
   1678 }
   1679 
   1680 smallArrayt *readDirSmallStringO(smallStringt *dirPath) {
   1681 
   1682   if (!dirPath) {
   1683     return(NULL);
   1684   }
   1685   return(readDirO(ssGet(dirPath)));
   1686 }
   1687 
   1688 smallArrayt *readDirDirO(const char *dirPath) {
   1689   DIR *d = NULL;
   1690   struct dirent *dp = NULL;
   1691 
   1692   // sanity checks
   1693   if (!dirPath || isBlankS(dirPath)) {
   1694     return(NULL);
   1695   }
   1696 
   1697   createAllocateSmallArray(list);
   1698   if (!list) {
   1699     return(NULL);
   1700   }
   1701 
   1702   d = opendir(dirPath);
   1703   if (!d) {
   1704     pFuncError
   1705     shEPrintfS("The path was: \"%s\"\n", dirPath);
   1706     return(list);
   1707   }
   1708 
   1709   dp = readdir(d);
   1710   while (dp) {
   1711     if (eqS(dp->d_name, ".") || eqS(dp->d_name, "..")) {
   1712       dp = readdir(d);
   1713       continue;
   1714     }
   1715 
   1716     char *sPath = catS(dirPath, "/", dp->d_name);
   1717 
   1718     if (isDir(sPath)) {
   1719       list->f->pushS(list, dp->d_name);
   1720     }
   1721     free(sPath);
   1722     dp = readdir(d);
   1723   }
   1724 
   1725   closedir(d);
   1726 
   1727   list->f->sort(list);
   1728 
   1729   return(list);
   1730 }
   1731 
   1732 smallArrayt *readDirDirSmallJsonO(smallJsont *dirPath) {
   1733 
   1734   if (!dirPath) {
   1735     return(NULL);
   1736   }
   1737 
   1738   const char *type = getTopTypeO(dirPath);
   1739 
   1740   if (!eqS(type,"string")) {
   1741     return(NULL);
   1742   }
   1743 
   1744   return(readDirDirO(getTopSO(dirPath)));
   1745 }
   1746 
   1747 smallArrayt *readDirDirSmallStringO(smallStringt *dirPath) {
   1748 
   1749   if (!dirPath) {
   1750     return(NULL);
   1751   }
   1752   return(readDirDirO(ssGet(dirPath)));
   1753 }
   1754 
   1755 smallArrayt *walkDirAllO(const char* dirPath) {
   1756 
   1757   // sanity checks
   1758   if (!dirPath || isBlankS(dirPath)) {
   1759     return(NULL);
   1760   }
   1761 
   1762   createAllocateSmallArray(list);
   1763   if (!list) {
   1764     return(NULL);
   1765   }
   1766   walkADirAll(dirPath, list);
   1767 
   1768   list->f->sort(list);
   1769 
   1770   return(list);
   1771 }
   1772 
   1773 smallArrayt *walkDirAllSmallJsonO(smallJsont* dirPath) {
   1774 
   1775   if (!dirPath) {
   1776     return(NULL);
   1777   }
   1778 
   1779   const char *type = getTopTypeO(dirPath);
   1780 
   1781   if (!eqS(type,"string")) {
   1782     return(NULL);
   1783   }
   1784 
   1785   return(walkDirAllO(getTopSO(dirPath)));
   1786 }
   1787 
   1788 smallArrayt *walkDirAllSmallStringO(smallStringt* dirPath) {
   1789 
   1790   if (!dirPath) {
   1791     return(NULL);
   1792   }
   1793   return(walkDirAllO(ssGet(dirPath)));
   1794 }
   1795 
   1796 internal void walkADirAll(const char *dirPath, smallArrayt *list) {
   1797   DIR *d = NULL;
   1798   struct dirent *dp = NULL;
   1799   char *sPath = NULL;
   1800 
   1801   d = opendir(dirPath);
   1802   if (!d) {
   1803     pFuncError
   1804     shEPrintfS("The path was: \"%s\"\n", dirPath);
   1805     return;
   1806   }
   1807 
   1808   dp = readdir(d);
   1809   while (dp) {
   1810     if (eqS(dp->d_name, ".") || eqS(dp->d_name, "..")) {
   1811       dp = readdir(d);
   1812       continue;
   1813     }
   1814 
   1815     sPath = catS(dirPath, "/", dp->d_name);
   1816 
   1817     list->f->pushS(list, sPath);
   1818 
   1819     if (isDir(sPath)) {
   1820       if (!isLink(sPath)) {
   1821         walkADirAll(sPath, list);
   1822     }
   1823       }
   1824     dp = readdir(d);
   1825     free(sPath);
   1826   }
   1827 
   1828   closedir(d);
   1829 }
   1830 
   1831 smallArrayt *readDirAllO(const char *dirPath) {
   1832   DIR *d = NULL;
   1833   struct dirent *dp = NULL;
   1834 
   1835   // sanity checks
   1836   if (!dirPath || isBlankS(dirPath)) {
   1837     return(NULL);
   1838   }
   1839 
   1840   createAllocateSmallArray(list);
   1841   if (!list) {
   1842     return(NULL);
   1843   }
   1844 
   1845   d = opendir(dirPath);
   1846   if (!d) {
   1847     pFuncError
   1848     shEPrintfS("The path was: \"%s\"\n", dirPath);
   1849     return(list);
   1850   }
   1851 
   1852   dp = readdir(d);
   1853   while (dp) {
   1854     if (eqS(dp->d_name, ".") || eqS(dp->d_name, "..")) {
   1855       dp = readdir(d);
   1856       continue;
   1857     }
   1858 
   1859     char *sPath = catS(dirPath, "/", dp->d_name);
   1860 
   1861     list->f->pushS(list, dp->d_name);
   1862     free(sPath);
   1863     dp = readdir(d);
   1864   }
   1865 
   1866   closedir(d);
   1867 
   1868   list->f->sort(list);
   1869 
   1870   return(list);
   1871 }
   1872 
   1873 smallArrayt *readDirAllSmallJsonO(smallJsont *dirPath) {
   1874 
   1875   if (!dirPath) {
   1876     return(NULL);
   1877   }
   1878 
   1879   const char *type = getTopTypeO(dirPath);
   1880 
   1881   if (!eqS(type,"string")) {
   1882     return(NULL);
   1883   }
   1884 
   1885   return(readDirAllO(getTopSO(dirPath)));
   1886 }
   1887 
   1888 smallArrayt *readDirAllSmallStringO(smallStringt *dirPath) {
   1889 
   1890   if (!dirPath) {
   1891     return(NULL);
   1892   }
   1893   return(readDirAllO(ssGet(dirPath)));
   1894 }
   1895 
   1896 time_t getModificationTimeJO(smallJsont *path) {
   1897 
   1898   if (!path) {
   1899     return(0);
   1900   }
   1901 
   1902   const char *type = getTopTypeO(path);
   1903 
   1904   if (!eqS(type,"string")) {
   1905     return(0);
   1906   }
   1907 
   1908   return(getModificationTime(getTopSO(path))); {
   1909   // bug cg_c IF
   1910 }
   1911   }
   1912 
   1913 time_t getModificationTimeO(smallStringt *path) {
   1914 
   1915   if (!path || !path->data) {
   1916     return(0);
   1917   }
   1918 
   1919   return(getModificationTime(ssGet(path))); {
   1920   // bug cg_c IF
   1921 }
   1922   }
   1923 
   1924 
   1925 int setModificationTimeJO(smallJsont *path, time_t mtime) {
   1926 
   1927   if (!path) {
   1928     return(0);
   1929   }
   1930 
   1931   const char *type = getTopTypeO(path);
   1932 
   1933   if (!eqS(type,"string")) {
   1934     return(0);
   1935   }
   1936 
   1937   return(setModificationTime(getTopSO(path), mtime)); {
   1938   // bug cg_c IF
   1939 }
   1940   }
   1941 
   1942 int setModificationTimeO(smallStringt *path, time_t mtime) {
   1943 
   1944   if (!path || !path->data) {
   1945     return(0);
   1946   }
   1947 
   1948   return(setModificationTime(ssGet(path), mtime)); {
   1949   // bug cg_c IF
   1950 }
   1951   }
   1952 
   1953 
   1954 bool equalModificationTimesJO(smallJsont *path1, smallJsont *path2) {
   1955 
   1956   if (!path1 || !path2) {
   1957     return(false);
   1958   }
   1959 
   1960   const char *type = getTopTypeO(path1);
   1961 
   1962   if (!eqS(type,"string")) {
   1963     return(false);
   1964   }
   1965 
   1966   type = getTopTypeO(path2);
   1967 
   1968   if (!eqS(type,"string")) {
   1969     return(false);
   1970   }
   1971 
   1972   return(equalModificationTimes(getTopSO(path1), getTopSO(path2))); {
   1973   // bug cg_c IF
   1974 }
   1975   }
   1976 
   1977 bool equalModificationTimesSJO(const char *path1, smallJsont *path2) {
   1978 
   1979   if (!path1 || !path2) {
   1980     return(false);
   1981   }
   1982 
   1983   const char *type = getTopTypeO(path2);
   1984 
   1985   if (!eqS(type,"string")) {
   1986     return(false);
   1987   }
   1988 
   1989   return(equalModificationTimes(path1, getTopSO(path2))); {
   1990   // bug cg_c IF
   1991 }
   1992   }
   1993 
   1994 bool equalModificationTimesJOS(smallJsont *path1, const char *path2) {
   1995 
   1996   if (!path1 || !path2) {
   1997     return(false);
   1998   }
   1999 
   2000   const char *type = getTopTypeO(path1);
   2001 
   2002   if (!eqS(type,"string")) {
   2003     return(false);
   2004   }
   2005 
   2006   return(equalModificationTimes(getTopSO(path1), path2)); {
   2007   // bug cg_c IF
   2008 }
   2009   }
   2010 
   2011 bool equalModificationTimesJOO(smallJsont *path1, smallStringt *path2) {
   2012 
   2013   if (!path1 || !path2 || !path2->data) {
   2014     return(false);
   2015   }
   2016 
   2017   const char *type = getTopTypeO(path1);
   2018 
   2019   if (!eqS(type,"string")) {
   2020     return(false);
   2021   }
   2022 
   2023   return(equalModificationTimes(getTopSO(path1), ssGet(path2))); {
   2024   // bug cg_c IF
   2025 }
   2026   }
   2027 
   2028 bool equalModificationTimesOJO(smallStringt *path1, smallJsont *path2) {
   2029 
   2030   if (!path1 || !path2 || !path1->data) {
   2031     return(false);
   2032   }
   2033 
   2034   const char *type = getTopTypeO(path2);
   2035 
   2036   if (!eqS(type,"string")) {
   2037     return(false);
   2038   }
   2039 
   2040   return(equalModificationTimes(ssGet(path1), getTopSO(path2))); {
   2041   // bug cg_c IF
   2042 }
   2043   }
   2044 
   2045 bool equalModificationTimesO(smallStringt *path1, smallStringt *path2) {
   2046 
   2047   if (!path1 || !path2 || !path1->data || !path2->data) {
   2048     return(false);
   2049   }
   2050 
   2051   time_t t1 = getModificationTimeO(path1); {
   2052   time_t t2 = getModificationTimeO(path2); {
   2053 
   2054   if (!t1 || !t2) {
   2055     return(false);
   2056   }
   2057   return(t1 == t2);;
   2058 }
   2059   }
   2060   }
   2061 
   2062 bool equalModificationTimesSO(const char *path1, smallStringt *path2) {
   2063 
   2064   if (!path2) {
   2065     return(false);
   2066   }
   2067   return(equalModificationTimes(path1, ssGet(path2))); {
   2068   // cg_c bug
   2069 }
   2070   }
   2071 
   2072 bool equalModificationTimesOS(smallStringt *path1, const char *path2) {
   2073 
   2074   if (!path1) {
   2075     return(false);
   2076   }
   2077   return(equalModificationTimes(ssGet(path1), path2)); {
   2078   // cg_c bug
   2079 }
   2080   }
   2081 
   2082 smallJsont *timeToJO(const time_t t) {
   2083 
   2084   char *s         = timeToS(t);
   2085   createAllocateSmallJson(r);
   2086   if (!r) {
   2087     free(s);
   2088     return(NULL);
   2089   }
   2090   setTopStringO(r, s);
   2091   free(s);
   2092   return(r);
   2093 }
   2094 
   2095 smallStringt *timeToSO(const time_t t) {
   2096 
   2097   char *s         = timeToS(t);
   2098   smallStringt *r = allocSmallString(s);
   2099   free(s);
   2100   if (!r) {
   2101     return(NULL);
   2102   }
   2103   return(r);
   2104 }
   2105 
   2106 smallJsont *shDirnameJO(smallJsont *path) {
   2107 
   2108   if (!path) {
   2109     return(NULL);
   2110   }
   2111 
   2112   const char *type = getTopTypeO(path);
   2113 
   2114   if (!eqS(type,"string")) {
   2115     return(NULL);
   2116   }
   2117 
   2118   createAllocateSmallJson(r);
   2119   if (!r) {
   2120     return(NULL);
   2121   }
   2122   setTopNFreeStringO(r, shDirname(getTopSO(path)));
   2123   return(r);
   2124 }
   2125 
   2126 smallStringt *shDirnameO(smallStringt *path) {
   2127   char *dir = NULL;
   2128   smallStringt *r = NULL;
   2129 
   2130   if (!path || !path->data) {
   2131     return(NULL);
   2132   }
   2133 
   2134   if (isBlankO(path)) {
   2135     return(allocSmallString("./"));
   2136   }
   2137 
   2138   dir = strdup(ssGet(path));
   2139   dirname(dir);
   2140 
   2141   // is dirname empty?
   2142   if (strEq(dir, ssGet(path))) {
   2143     // set dir to pwd when dirname is empty
   2144     free(dir);
   2145     dir = strdup("./");
   2146   }
   2147   r = allocSmallString(dir);
   2148   free(dir);
   2149   if (!r) {
   2150     return(NULL);
   2151   }
   2152   return(r);
   2153 }
   2154 
   2155 
   2156 smallJsont *expandHomeJO(smallJsont *path) {
   2157 
   2158   // sanity checks
   2159   if (!path) {
   2160     return(NULL);
   2161   }
   2162 
   2163   const char *type = getTopTypeO(path);
   2164 
   2165   if (!eqS(type,"string")) {
   2166     return(NULL);
   2167   }
   2168 
   2169   char *r = expandHome(getTopSO(path));
   2170   freeO(path);
   2171   setTopNFreeStringO(path, r);
   2172   return(path);
   2173 }
   2174 
   2175 #if (__OpenBSD__ || __HAIKU__)
   2176 smallStringt *expandHomeO(smallStringt *path) {
   2177 
   2178   // sanity checks
   2179   if (!path || !path->data) {
   2180     return(NULL);
   2181   }
   2182 
   2183   char *r = expandHome(ssGet(path));
   2184   path->f->set(path, r);
   2185   free(r);
   2186   return(path);
   2187 }
   2188 
   2189 #else
   2190 smallStringt *expandHomeO(smallStringt *path) {
   2191   wordexp_t exp_result;
   2192 
   2193   // sanity checks
   2194   // duplicate path to be able to realloc (impossible when path is static)
   2195   // expand ~/ or ~USER
   2196 
   2197   // sanity checks
   2198   if (!path || !path->data) {
   2199     return(NULL);
   2200   }
   2201 
   2202   #if (!__TERMUX__)
   2203   // expand ~/
   2204   int status = wordexp(path->f->get(path), &exp_result, 0);;
   2205   switch (status) {
   2206     case WRDE_BADCHAR:
   2207       shEPrintfS("expandHomeO error: unquoted invalid character\n");
   2208       shEPrintfS("The path was: \"%s\"\n", ssGet(path));
   2209       return(NULL);
   2210     case WRDE_BADVAL:
   2211       shEPrintfS("expandHomeO error: undefined shell variable\n");
   2212       shEPrintfS("The path was: \"%s\"\n", ssGet(path));
   2213       return(NULL);
   2214     case WRDE_NOSPACE:
   2215       shEPrintfS("expandHomeO error: out of memory\n");
   2216       shEPrintfS("The path was: \"%s\"\n", ssGet(path));
   2217       return(NULL);
   2218     case WRDE_SYNTAX:
   2219       shEPrintfS("expandHomeO error: syntax error\n");
   2220       shEPrintfS("The path was: \"%s\"\n", ssGet(path));
   2221       return(NULL);
   2222     default:
   2223       break;
   2224   }
   2225 
   2226   path->f->set(path, exp_result.we_wordv[0]);
   2227   wordfree(&exp_result);
   2228   #else
   2229   path->f->replace(path, "~", "/data/data/com.termux/files/home", 1);
   2230   #endif
   2231   return(path);
   2232 }
   2233 
   2234 #endif
   2235 // #if __OpenBSD__ || __HAIKU__
   2236 
   2237 smallJsont *normalizePathJO(smallJsont *path) {
   2238 
   2239   if (!path) {
   2240     return(NULL);
   2241   }
   2242 
   2243   const char *type = getTopTypeO(path);
   2244 
   2245   if (!eqS(type,"string")) {
   2246     return(NULL);
   2247   }
   2248 
   2249   char *r = normalizePath(getTopSO(path));
   2250   freeO(path);
   2251   setTopNFreeStringO(path, r);
   2252   return(path);
   2253 }
   2254 
   2255 smallStringt *normalizePathO(smallStringt *path) {
   2256 
   2257   // sanity checks
   2258   if (!path || !path->data) {
   2259     return(NULL);
   2260   }
   2261 
   2262   if (isEmptyO(path)) {
   2263     return(path);
   2264   }
   2265 
   2266   // list path elements
   2267   char **pathL = splitSO(path, "/");
   2268 
   2269   // remove empty elements
   2270   pErrorNULL(iListCompactS(&pathL));
   2271 
   2272   if (listIsEmptyS(pathL)) {
   2273     listFreeS(pathL);
   2274     // keep leading /
   2275     path->f->set(path, "/");
   2276     return(path);
   2277   }
   2278 
   2279   // new path elements
   2280   char **list = NULL;
   2281 
   2282   // detect leading double dots
   2283   bool onlyLeadingDoubleDots = true;
   2284 
   2285   // add elements to list
   2286   forEachCharP(pathL, level) {
   2287     if (strEq(*level, "..")) {
   2288       if (onlyLeadingDoubleDots) {
   2289         // keep leading ..
   2290         pErrorNULL(listPushS(&list, ".."));
   2291       }
   2292       else {
   2293         // remove .. in path
   2294         char *s = listPopS(&list);
   2295         free(s);
   2296     }
   2297       }
   2298     else if (!strEq(*level, ".")) {
   2299       // remove . and add elements
   2300       pErrorNULL(listPushS(&list, *level));
   2301       // an element is pushed, so this is the end of leading double dots
   2302       onlyLeadingDoubleDots = false;
   2303   }
   2304     }
   2305 
   2306   if (listLengthS(list) == 1 && strEq(list[0], "..") && path->f->getAt(path, 0) == '/') {
   2307     // handle ../ .. /.. /../
   2308     list[0][0] = 0;
   2309   }
   2310 
   2311   // handle /.: add empty string
   2312   if (path->f->equalS(path, "/.")) {
   2313     pErrorNULL(listPushS(&list, ""));
   2314   }
   2315 
   2316   // keep leading /
   2317   if (path->f->getAt(path, 0) == '/') {
   2318     if (listIsEmptyS(list)) {
   2319       // .. cancelled path: /a/b/../..
   2320       listFreeManyS(pathL, list);
   2321       path->f->set(path, "/");
   2322       return(path);
   2323     }
   2324     pErrorNULL(listPrependS(&list, ""));
   2325   }
   2326 
   2327   // create new path
   2328   char *r = join(list, "/");;
   2329   // keep order pathL, list because list can be NULL
   2330   // if it is first listFreeManyS stops early
   2331   listFreeManyS(pathL, list);
   2332   if (!r) {
   2333     path->f->set(path, "");
   2334     return(path);
   2335   }
   2336   path->f->setNFree(path, r);
   2337   return(path);
   2338 }
   2339 
   2340 
   2341 smallJsont *getCwdJO(void) {
   2342 
   2343   char *s = getCwd();
   2344 
   2345   if (!s) {
   2346     return(NULL);
   2347   }
   2348 
   2349   createAllocateSmallJson(r);
   2350   if (!r) {
   2351     free(s);
   2352     return(NULL);
   2353   }
   2354   setTopNFreeStringO(r, s);
   2355   return(r);
   2356 }
   2357 
   2358 smallStringt *getCwdO(void) {
   2359   char *r = NULL;
   2360 
   2361   r = getcwd(NULL, 0);
   2362   if (!r) {
   2363     pFuncError
   2364     return(NULL);
   2365   }
   2366   createAllocateSmallString(s);
   2367   if (!s) {
   2368     free(r);
   2369     return(NULL);
   2370   }
   2371   s->f->setNFree(s, r);
   2372   return(s);
   2373 }
   2374 
   2375 int chDirJO(smallJsont *path) {
   2376 
   2377   if (!path) {
   2378     return(0);
   2379   }
   2380 
   2381   const char *type = getTopTypeO(path);
   2382 
   2383   if (!eqS(type,"string")) {
   2384     return(0);
   2385   }
   2386 
   2387   return(chDir(getTopSO(path)));
   2388 }
   2389 
   2390 int chDirO(smallStringt *path) {
   2391 
   2392   if (!path) {
   2393     return(0);
   2394   }
   2395 
   2396   int r = chdir(ssGet(path));
   2397   if (r) {
   2398     pFuncError
   2399     shEPrintfS("The path was: \"%s\"\n", ssGet(path));
   2400     return(0);
   2401   }
   2402   return(1);
   2403 }
   2404 
   2405 bool isDirJO(smallJsont *path) {
   2406 
   2407   if (!path) {
   2408     return(false);
   2409   }
   2410 
   2411   const char *type = getTopTypeO(path);
   2412 
   2413   if (!eqS(type,"string")) {
   2414     return(false);
   2415   }
   2416 
   2417   return(isDir(getTopSO(path)));
   2418 }
   2419 
   2420 bool isDirO(smallStringt *path) {
   2421   struct stat st;
   2422 
   2423   // sanity checks
   2424   if (!path || isBlankO(path)) {
   2425     return(false);
   2426   }
   2427 
   2428   if (stat(ssGet(path), &st) == -1) {
   2429     return(false);
   2430   }
   2431 
   2432   if (!S_ISDIR(st.st_mode)) {
   2433     return(false);
   2434   }
   2435   return(true);
   2436 }
   2437 
   2438 bool isLinkJO(smallJsont *path) {
   2439 
   2440   if (!path) {
   2441     return(false);
   2442   }
   2443 
   2444   const char *type = getTopTypeO(path);
   2445 
   2446   if (!eqS(type,"string")) {
   2447     return(false);
   2448   }
   2449 
   2450   return(isLink(getTopSO(path)));
   2451 }
   2452 
   2453 bool isLinkO(smallStringt *path) {
   2454   struct stat st;
   2455 
   2456   // sanity checks
   2457   if (!path || isBlankO(path)) {
   2458     return(false);
   2459   }
   2460 
   2461   if (lstat(ssGet(path), &st) == -1) {
   2462     return(false);
   2463   }
   2464 
   2465   if (!S_ISLNK(st.st_mode)) {
   2466     return(false);
   2467   }
   2468   return(true);
   2469 }
   2470 
   2471 bool fileExistsJO(smallJsont *filePath) {
   2472 
   2473   if (!filePath) {
   2474     return(false);
   2475   }
   2476 
   2477   const char *type = getTopTypeO(filePath);
   2478 
   2479   if (!eqS(type,"string")) {
   2480     return(false);
   2481   }
   2482 
   2483   return(fileExists(getTopSO(filePath)));
   2484 }
   2485 
   2486 bool fileExistsO(smallStringt *filePath) {
   2487 
   2488   // sanity checks
   2489   if (!filePath || filePath->f->isBlank(filePath)) {
   2490     return(false);
   2491   }
   2492 
   2493   int r = access(filePath->f->get(filePath), F_OK);
   2494   //if r
   2495   //  perror("fileExists error");
   2496   // dont print error because this is a test
   2497   return(r != -1);;
   2498 }
   2499 
   2500 bool fileChmodJO(smallJsont *filePath, mode_t mode) {
   2501 
   2502   if (!filePath) {
   2503     return(false);
   2504   }
   2505 
   2506   const char *type = getTopTypeO(filePath);
   2507 
   2508   if (!eqS(type,"string")) {
   2509     return(false);
   2510   }
   2511 
   2512   return(fileChmod(getTopSO(filePath), mode));
   2513 }
   2514 
   2515 bool fileChmodO(smallStringt *filePath, mode_t mode) {
   2516 
   2517   // sanity checks
   2518   if (!filePath || isBlankO(filePath)) {
   2519     return(false);
   2520   }
   2521 
   2522   int r = chmod(ssGet(filePath), mode);
   2523   if (r) {
   2524     pFuncError
   2525     shEPrintfS("The path was: \"%s\"\n", ssGet(filePath));
   2526   }
   2527   return(r == 0);;
   2528 }
   2529 
   2530 ssize_t fileSizeJO(smallJsont *filePath) {
   2531 
   2532   if (!filePath) {
   2533     return(-1);
   2534   }
   2535 
   2536   const char *type = getTopTypeO(filePath);
   2537 
   2538   if (!eqS(type,"string")) {
   2539     return(-1);
   2540   }
   2541 
   2542   return(fileSize(getTopSO(filePath)));
   2543 }
   2544 
   2545 ssize_t fileSizeO(smallStringt *filePath) {
   2546   struct stat st;
   2547 
   2548   // sanity checks
   2549   if (!filePath || isBlankO(filePath)) {
   2550     return(-1);
   2551   }
   2552 
   2553   int r = stat(ssGet(filePath), &st);;
   2554   if (r) {
   2555     pFuncError
   2556     shEPrintfS("The path was: \"%s\"\n", ssGet(filePath));
   2557     return(-1);
   2558   }
   2559 
   2560   // macOS returns a varying number a number above the constant below
   2561   // when the file doesnt exists
   2562   if ((uint64_t)(st.st_size) > 140734000000000) {
   2563     return(-1);//LCOV_EXCL_LINE
   2564   }
   2565   return(st.st_size);
   2566 }
   2567 
   2568 void *readFileToNewG(void *none UNUSED, const char *filePath) {
   2569 
   2570   return(readFileToS(filePath));
   2571 }
   2572 
   2573 void *readStreamToNewG(void *none UNUSED, FILE *fp) {
   2574 
   2575   return(readStreamToS(fp));
   2576 }
   2577 
   2578 char *readFileToG(char **string, const char *filePath) {
   2579 
   2580   if (!string) {
   2581     return(NULL);
   2582   }
   2583   *string = readFileToS(filePath);
   2584   return(*string);
   2585 }
   2586 
   2587 char *readStreamToG(char **string, FILE *fp) {
   2588 
   2589   if (!string) {
   2590     return(NULL);
   2591   }
   2592   *string = readStreamToS(fp);
   2593   return(*string);
   2594 }
   2595 
   2596 void readTextSmallJsonNotSupported(char ***self UNUSED, smallJsont *path UNUSED) {
   2597 
   2598   // TODO
   2599   shPrintError;
   2600   logI("readFile smallJsont path not supported");
   2601 }
   2602 
   2603 void readTextSmallStringNotSupported(char ***self UNUSED, smallStringt *path UNUSED) {
   2604 
   2605   // TODO
   2606   shPrintError;
   2607   logI("readFile smallStringt path not supported");
   2608 }
   2609 
   2610 void readToFileSmallJsonNotSupported(void *self UNUSED, smallJsont *path UNUSED) {
   2611 
   2612   // TODO
   2613   shPrintError;
   2614   logI("readFile smallJsont path not supported");
   2615 }
   2616 
   2617 void readToFileSmallStringNotSupported(void *self UNUSED, smallStringt *path UNUSED) {
   2618 
   2619   // TODO
   2620   shPrintError;
   2621   logI("readFile smallStringt path not supported");
   2622 }
   2623 
   2624 int writeFileFromG(const char *string, const char *filePath) {
   2625 
   2626   return(writeFileS(filePath, string));
   2627 }
   2628 
   2629 int writeStreamFromG(const char *string, FILE *fp) {
   2630 
   2631   return(writeStreamS(fp, string));
   2632 }
   2633 
   2634 int writeTextSmallJsonNotSupported(char **self UNUSED, smallJsont *path UNUSED) {
   2635 
   2636   // TODO
   2637   shPrintError;
   2638   logI("writeFile smallJsont path not supported");
   2639   return(0);
   2640 }
   2641 
   2642 int writeTextSmallStringNotSupported(char **self UNUSED, smallStringt *path UNUSED) {
   2643 
   2644   // TODO
   2645   shPrintError;
   2646   logI("writeFile smallStringt path not supported");
   2647   return(0);
   2648 }
   2649 
   2650 int writeTextCCSmallJsonNotSupported(const char **self UNUSED, smallJsont *path UNUSED) {
   2651 
   2652   // TODO
   2653   shPrintError;
   2654   logI("writeFile smallJsont path not supported");
   2655   return(0);
   2656 }
   2657 
   2658 int writeTextCCSmallStringNotSupported(const char **self UNUSED, smallStringt *path UNUSED) {
   2659 
   2660   // TODO
   2661   shPrintError;
   2662   logI("writeFile smallStringt path not supported");
   2663   return(0);
   2664 }
   2665 
   2666 char **readTextSG(char ***list, const char *filePath) {
   2667 
   2668   if (!list) {
   2669     return(NULL);
   2670   }
   2671   *list = readText(filePath);
   2672   return(*list);
   2673 }
   2674 
   2675 char **readTextStreamG(char ***list, FILE *fp) {
   2676 
   2677   if (!list) {
   2678     return(NULL);
   2679   }
   2680   *list = readStream(fp);
   2681   return(*list);
   2682 }
   2683 
   2684 bool writeTextSG(char **list, const char *filePath) {
   2685 
   2686   return(writeText(filePath, list));
   2687 }
   2688 
   2689 bool writeTextStreamG(char **list, FILE *fp) {
   2690 
   2691   return(writeStream(fp, list));
   2692 }
   2693 
   2694 bool writeTextCG(const char **list, const char *filePath) {
   2695 
   2696   return(writeCText(filePath, list));
   2697 }
   2698 
   2699 bool writeTextStreamCG(const char **list, FILE *fp) {
   2700 
   2701   return(writeCStream(fp, list));
   2702 }
   2703 
   2704 bool appendFileSG(const char *string, const char *filePath) {
   2705 
   2706   return(appendFileS(filePath, string));
   2707 }
   2708 
   2709 bool appendTextSG(char **list, const char *filePath) {
   2710 
   2711   return(appendText(filePath, list));
   2712 }
   2713 
   2714 bool appendTextCG(const char **list, const char *filePath) {
   2715 
   2716   return(appendCText(filePath, list));
   2717 }
   2718 
   2719 int mkdirParentsSmallJsonO(smallJsont* path) {
   2720 
   2721   if (!path) {
   2722     return(0);
   2723   }
   2724 
   2725   const char *type = getTopTypeO(path);
   2726 
   2727   if (!eqS(type,"string")) {
   2728     return(0);
   2729   }
   2730 
   2731   return(mkdirParents(getTopSO(path)));
   2732 }
   2733 
   2734 int mkdirParentsO(smallStringt* path) {
   2735 
   2736   // sanity checks
   2737   if (!path || path->f->isBlank(path)) {
   2738     return(0);
   2739   }
   2740 
   2741   return(mkdirParents(ssGet(path)));
   2742 }
   2743 
   2744 int rmAllSmallJsonO(smallJsont* path) {
   2745 
   2746   if (!path) {
   2747     return(0);
   2748   }
   2749 
   2750   const char *type = getTopTypeO(path);
   2751 
   2752   if (!eqS(type,"string")) {
   2753     return(0);
   2754   }
   2755 
   2756   return(rmAll(getTopSO(path)));
   2757 }
   2758 
   2759 int rmAllO(smallStringt* path) {
   2760 
   2761   // sanity checks
   2762   if (!path || path->f->isBlank(path)) {
   2763     return(0);
   2764   }
   2765 
   2766   return(rmAll(ssGet(path)));
   2767 }
   2768 
   2769 int copyO(smallStringt* src, smallStringt* dst) {
   2770 
   2771   // sanity checks
   2772   if (!src || !dst || src->f->isBlank(src) || dst->f->isBlank(dst)) {
   2773     return(0);
   2774   }
   2775 
   2776   return(copy(ssGet(src), ssGet(dst)));
   2777 }
   2778 
   2779 int copySSmallJsonO(const char* src, smallJsont* dst) {
   2780 
   2781   if (!src || !dst || isBlankS(src)) {
   2782     return(0);
   2783   }
   2784 
   2785   if (checkObjectTypes && !isOSmallJson(dst)) {
   2786     return(0);
   2787   }
   2788 
   2789   const char *type = getTopTypeO(dst);
   2790 
   2791   if (!eqS(type,"string")) {
   2792     return(0);
   2793   }
   2794 
   2795   if (isBlankO(dst)) {
   2796     return(0);
   2797   }
   2798 
   2799   return(copy(src, getTopSO(dst)));
   2800 }
   2801 
   2802 int copySO(const char* src, smallStringt* dst) {
   2803 
   2804   // sanity checks
   2805   if (!src || !dst || isBlankS(src) || dst->f->isBlank(dst)) {
   2806     return(0);
   2807   }
   2808 
   2809   return(copy(src, ssGet(dst)));
   2810 }
   2811 
   2812 int copySmallJsonOS(smallJsont* src, const char* dst) {
   2813 
   2814   if (!src || !dst || isBlankS(dst)) {
   2815     return(0);
   2816   }
   2817 
   2818   if (checkObjectTypes && !isOSmallJson(src)) {
   2819     return(0);
   2820   }
   2821 
   2822   const char *type = getTopTypeO(src);
   2823 
   2824   if (!eqS(type,"string")) {
   2825     return(0);
   2826   }
   2827 
   2828   if (isBlankO(src)) {
   2829     return(0);
   2830   }
   2831 
   2832   return(copy(getTopSO(src), dst));
   2833 }
   2834 
   2835 int copySmallJsonSmallJson(smallJsont* src, smallJsont* dst) {
   2836 
   2837   if (!src || !dst) {
   2838     return(0);
   2839   }
   2840 
   2841   if (checkObjectTypes && !isOSmallJson(src)) {
   2842     return(0);
   2843   }
   2844 
   2845   if (checkObjectTypes && !isOSmallJson(dst)) {
   2846     return(0);
   2847   }
   2848 
   2849   const char *type = getTopTypeO(src);
   2850 
   2851   if (!eqS(type,"string")) {
   2852     return(0);
   2853   }
   2854 
   2855   type = getTopTypeO(dst);
   2856 
   2857   if (!eqS(type,"string")) {
   2858     return(0);
   2859   }
   2860 
   2861   if (isBlankO(src) || isBlankO(dst)) {
   2862     return(0);
   2863   }
   2864 
   2865   return(copy(getTopSO(src), getTopSO(dst)));
   2866 }
   2867 
   2868 int copySmallJsonO(smallJsont* src, smallStringt* dst) {
   2869 
   2870   if (!src || !dst) {
   2871     return(0);
   2872   }
   2873 
   2874   if (checkObjectTypes && !isOSmallJson(src)) {
   2875     return(0);
   2876   }
   2877 
   2878   if (checkObjectTypes && !isOSmallString(dst)) {
   2879     return(0);
   2880   }
   2881 
   2882   const char *type = getTopTypeO(src);
   2883 
   2884   if (!eqS(type,"string")) {
   2885     return(0);
   2886   }
   2887 
   2888   if (isBlankO(src) || isBlankO(dst)) {
   2889     return(0);
   2890   }
   2891 
   2892   return(copy(getTopSO(src), ssGet(dst)));
   2893 }
   2894 
   2895 int copyOS(smallStringt* src, const char* dst) {
   2896 
   2897   // sanity checks
   2898   if (!src || !dst || src->f->isBlank(src) || isBlankS(dst)) {
   2899     return(0);
   2900   }
   2901 
   2902   return(copy(ssGet(src), dst));
   2903 }
   2904 
   2905 int copyOSmallJson(smallStringt* src, smallJsont* dst) {
   2906 
   2907   if (!src || !dst) {
   2908     return(0);
   2909   }
   2910 
   2911   if (checkObjectTypes && !isOSmallString(src)) {
   2912     return(0);
   2913   }
   2914 
   2915   if (checkObjectTypes && !isOSmallJson(dst)) {
   2916     return(0);
   2917   }
   2918 
   2919   const char *type = getTopTypeO(dst);
   2920 
   2921   if (!eqS(type,"string")) {
   2922     return(0);
   2923   }
   2924 
   2925   if (isBlankO(src) || isBlankO(dst)) {
   2926     return(0);
   2927   }
   2928 
   2929   return(copy(ssGet(src), getTopSO(dst)));
   2930 }
   2931 
   2932 int renameSmallJsonO(smallJsont* src, smallStringt* dst) {
   2933 
   2934   if (!src || !dst) {
   2935     return(0);
   2936   }
   2937 
   2938   if (checkObjectTypes && !isOSmallJson(src)) {
   2939     return(0);
   2940   }
   2941 
   2942   if (checkObjectTypes && !isOSmallString(dst)) {
   2943     return(0);
   2944   }
   2945 
   2946   const char *type = getTopTypeO(src);
   2947 
   2948   if (!eqS(type,"string")) {
   2949     return(0);
   2950   }
   2951 
   2952   if (isBlankO(src) || isBlankO(dst)) {
   2953     return(0);
   2954   }
   2955 
   2956   return(shRename(getTopSO(src), ssGet(dst)));
   2957 }
   2958 
   2959 int renameSmallJsonSmallJson(smallJsont* src, smallJsont* dst) {
   2960 
   2961   if (!src || !dst) {
   2962     return(0);
   2963   }
   2964 
   2965   if (checkObjectTypes && !isOSmallJson(src)) {
   2966     return(0);
   2967   }
   2968 
   2969   if (checkObjectTypes && !isOSmallJson(dst)) {
   2970     return(0);
   2971   }
   2972 
   2973   const char *type = getTopTypeO(src);
   2974 
   2975   if (!eqS(type,"string")) {
   2976     return(0);
   2977   }
   2978 
   2979   type = getTopTypeO(dst);
   2980 
   2981   if (!eqS(type,"string")) {
   2982     return(0);
   2983   }
   2984 
   2985   if (isBlankO(src) || isBlankO(dst)) {
   2986     return(0);
   2987   }
   2988 
   2989   return(shRename(getTopSO(src), getTopSO(dst)));
   2990 }
   2991 
   2992 int renameSmallJsonOS(smallJsont* src, const char* dst) {
   2993 
   2994   if (!src || !dst || isBlankS(dst)) {
   2995     return(0);
   2996   }
   2997 
   2998   if (checkObjectTypes && !isOSmallJson(src)) {
   2999     return(0);
   3000   }
   3001 
   3002   const char *type = getTopTypeO(src);
   3003 
   3004   if (!eqS(type,"string")) {
   3005     return(0);
   3006   }
   3007 
   3008   if (isBlankO(src)) {
   3009     return(0);
   3010   }
   3011 
   3012   return(shRename(getTopSO(src), dst));
   3013 }
   3014 
   3015 int renameO(smallStringt* src, smallStringt* dst) {
   3016 
   3017   // sanity checks
   3018   if (!src || !dst || src->f->isBlank(src) || dst->f->isBlank(dst)) {
   3019     return(0);
   3020   }
   3021 
   3022   return(shRename(ssGet(src), ssGet(dst)));
   3023 }
   3024 
   3025 int renameOSmallJson(smallStringt* src, smallJsont* dst) {
   3026 
   3027   if (!src || !dst) {
   3028     return(0);
   3029   }
   3030 
   3031   if (checkObjectTypes && !isOSmallString(src)) {
   3032     return(0);
   3033   }
   3034 
   3035   if (checkObjectTypes && !isOSmallJson(dst)) {
   3036     return(0);
   3037   }
   3038 
   3039   const char *type = getTopTypeO(dst);
   3040 
   3041   if (!eqS(type,"string")) {
   3042     return(0);
   3043   }
   3044 
   3045   if (isBlankO(src) || isBlankO(dst)) {
   3046     return(0);
   3047   }
   3048 
   3049   return(shRename(ssGet(src), getTopSO(dst)));
   3050 }
   3051 
   3052 int renameSSmallJsonO(const char* src, smallJsont* dst) {
   3053 
   3054   if (!dst) {
   3055     return(0);
   3056   }
   3057 
   3058   if (checkObjectTypes && !isOSmallJson(dst)) {
   3059     return(0);
   3060   }
   3061 
   3062   const char *type = getTopTypeO(dst);
   3063 
   3064   if (!eqS(type,"string")) {
   3065     return(0);
   3066   }
   3067 
   3068   if (isBlankS(src) || isBlankO(dst)) {
   3069     return(0);
   3070   }
   3071 
   3072   return(shRename(src, sjGet(dst)));
   3073 }
   3074 
   3075 int renameSO(const char* src, smallStringt* dst) {
   3076 
   3077   if (!dst) {
   3078     return(0);
   3079   }
   3080   return(shRename(src, ssGet(dst)));
   3081 }
   3082 
   3083 int renameOS(smallStringt* src, const char* dst) {
   3084 
   3085   if (!src) {
   3086     return(0);
   3087   }
   3088   return(shRename(ssGet(src), dst));
   3089 }
   3090 
   3091 int moveSmallJsonO(smallJsont* src, smallStringt* dst) {
   3092 
   3093   if (!src || !dst) {
   3094     return(0);
   3095   }
   3096 
   3097   if (checkObjectTypes && !isOSmallJson(src)) {
   3098     return(0);
   3099   }
   3100 
   3101   if (checkObjectTypes && !isOSmallString(dst)) {
   3102     return(0);
   3103   }
   3104 
   3105   const char *type = getTopTypeO(src);
   3106 
   3107   if (!eqS(type,"string")) {
   3108     return(0);
   3109   }
   3110 
   3111   if (isBlankO(src) || isBlankO(dst)) {
   3112     return(0);
   3113   }
   3114 
   3115   return(shMove(getTopSO(src), ssGet(dst)));
   3116 }
   3117 
   3118 int moveSmallJsonSmallJson(smallJsont* src, smallJsont* dst) {
   3119 
   3120   if (!src || !dst) {
   3121     return(0);
   3122   }
   3123 
   3124   if (checkObjectTypes && !isOSmallJson(src)) {
   3125     return(0);
   3126   }
   3127 
   3128   if (checkObjectTypes && !isOSmallJson(dst)) {
   3129     return(0);
   3130   }
   3131 
   3132   const char *type = getTopTypeO(src);
   3133 
   3134   if (!eqS(type,"string")) {
   3135     return(0);
   3136   }
   3137 
   3138   type = getTopTypeO(dst);
   3139 
   3140   if (!eqS(type,"string")) {
   3141     return(0);
   3142   }
   3143 
   3144   if (isBlankO(src) || isBlankO(dst)) {
   3145     return(0);
   3146   }
   3147 
   3148   return(shMove(getTopSO(src), getTopSO(dst)));
   3149 }
   3150 
   3151 int moveSmallJsonOS(smallJsont* src, const char* dst) {
   3152 
   3153   if (!src || !dst || isBlankS(dst)) {
   3154     return(0);
   3155   }
   3156 
   3157   if (checkObjectTypes && !isOSmallJson(src)) {
   3158     return(0);
   3159   }
   3160 
   3161   const char *type = getTopTypeO(src);
   3162 
   3163   if (!eqS(type,"string")) {
   3164     return(0);
   3165   }
   3166 
   3167   if (isBlankO(src)) {
   3168     return(0);
   3169   }
   3170 
   3171   return(shMove(getTopSO(src), dst));
   3172 }
   3173 
   3174 int moveO(smallStringt* src, smallStringt* dst) {
   3175 
   3176   // sanity checks
   3177   if (!src || !dst || src->f->isBlank(src) || dst->f->isBlank(dst)) {
   3178     return(0);
   3179   }
   3180 
   3181   return(shMove(ssGet(src), ssGet(dst)));
   3182 }
   3183 
   3184 int moveOSmallJson(smallStringt* src, smallJsont* dst) {
   3185 
   3186   if (!src || !dst) {
   3187     return(0);
   3188   }
   3189 
   3190   if (checkObjectTypes && !isOSmallString(src)) {
   3191     return(0);
   3192   }
   3193 
   3194   if (checkObjectTypes && !isOSmallJson(dst)) {
   3195     return(0);
   3196   }
   3197 
   3198   const char *type = getTopTypeO(dst);
   3199 
   3200   if (!eqS(type,"string")) {
   3201     return(0);
   3202   }
   3203 
   3204   if (isBlankO(src) || isBlankO(dst)) {
   3205     return(0);
   3206   }
   3207 
   3208   return(shMove(ssGet(src), getTopSO(dst)));
   3209 }
   3210 
   3211 int moveSSmallJsonO(const char* src, smallJsont* dst) {
   3212 
   3213   if (!dst) {
   3214     return(0);
   3215   }
   3216 
   3217   if (checkObjectTypes && !isOSmallJson(dst)) {
   3218     return(0);
   3219   }
   3220 
   3221   const char *type = getTopTypeO(dst);
   3222 
   3223   if (!eqS(type,"string")) {
   3224     return(0);
   3225   }
   3226 
   3227   if (isBlankS(src) || isBlankO(dst)) {
   3228     return(0);
   3229   }
   3230 
   3231   return(shMove(src, sjGet(dst)));
   3232 }
   3233 
   3234 int moveSO(const char* src, smallStringt* dst) {
   3235 
   3236   if (!dst) {
   3237     return(0);
   3238   }
   3239   return(shMove(src, ssGet(dst)));
   3240 }
   3241 
   3242 int moveOS(smallStringt* src, const char* dst) {
   3243 
   3244   if (!src) {
   3245     return(0);
   3246   }
   3247   return(shMove(ssGet(src), dst));
   3248 }
   3249 
   3250 smallJsont *randomSmallJsonO(uint64_t length) {
   3251   char *s = NULL;
   3252 
   3253   s = randomS(length);
   3254   if (!s) {
   3255     return(NULL);
   3256   }
   3257   createAllocateSmallJson(r);
   3258   if (!r) {
   3259     free(s);
   3260     return(NULL);
   3261   }
   3262   setTopNFreeStringO(r, s);
   3263   return(r);
   3264 }
   3265 
   3266 smallStringt *randomSO(uint64_t length) {
   3267   char *s = NULL;
   3268 
   3269   s = randomS(length);
   3270   if (!s) {
   3271     return(NULL);
   3272   }
   3273   createAllocateSmallString(r);
   3274   if (!r) {
   3275     free(s);
   3276     return(NULL);
   3277   }
   3278   r->f->setNFree(r, s);
   3279   return(r);
   3280 }
   3281 
   3282 smallJsont *randomAlphaNumSmallJsonO(uint64_t length) {
   3283   char *s = NULL;
   3284 
   3285   s = randomAlphaNumS(length);
   3286   if (!s) {
   3287     return(NULL);
   3288   }
   3289   createAllocateSmallJson(r);
   3290   if (!r) {
   3291     free(s);
   3292     return(NULL);
   3293   }
   3294   setTopNFreeStringO(r, s);
   3295   return(r);
   3296 }
   3297 
   3298 smallStringt *randomAlphaNumSO(uint64_t length) {
   3299   char *s = NULL;
   3300 
   3301   s = randomAlphaNumS(length);
   3302   if (!s) {
   3303     return(NULL);
   3304   }
   3305   createAllocateSmallString(r);
   3306   if (!r) {
   3307     free(s);
   3308     return(NULL);
   3309   }
   3310   r->f->setNFree(r, s);
   3311   return(r);
   3312 }
   3313 
   3314 smallJsont *readSmallJsonO(void) {
   3315 
   3316   char *s = readS();
   3317   if (!s) {
   3318     return(NULL);
   3319   }
   3320   createAllocateSmallJson(r);
   3321   if (!r) {
   3322     free(s);
   3323     return(NULL);
   3324   }
   3325   setTopNFreeStringO(r, s);
   3326   return(r);
   3327 }
   3328 
   3329 #define startMax   20
   3330 
   3331 smallStringt *readO(void) {
   3332   size_t max = startMax;;
   3333 
   3334   char *s = malloc(max);
   3335   if (!s) {
   3336     return(NULL);
   3337   }
   3338 
   3339   size_t i = 0;
   3340   while (1) {
   3341     #ifndef unitTest
   3342     int c = getchar();
   3343     #else
   3344     int c;
   3345     if (i < startMax) {
   3346       c = 'a';
   3347     }
   3348     else {
   3349       c = '\n';
   3350     }
   3351     #endif
   3352     if (c == '\n') {
   3353       s[i] = 0;
   3354       break;
   3355     }
   3356     s[i] = (char)c;
   3357     if (i == max-1) {
   3358       // buffer full
   3359       max += max;
   3360       char *tmp = realloc(s, max);
   3361       if (!tmp) {
   3362         free(s);
   3363         return(NULL);
   3364       }
   3365       s = tmp;
   3366     }
   3367     i++;
   3368   }
   3369   createAllocateSmallString(r);
   3370   if (!r) {
   3371     free(s);
   3372     return(NULL);
   3373   }
   3374   r->f->setNFree(r, s);
   3375   return(r);
   3376 }
   3377 
   3378 smallJsont *readLineSmallJsonO(FILE *fp) {
   3379 
   3380   char *s = readLine(fp);
   3381   if (!s) {
   3382     return(NULL);
   3383   }
   3384   createAllocateSmallJson(r);
   3385   if (!r) {
   3386     free(s);
   3387     return(NULL);
   3388   }
   3389   setTopNFreeStringO(r, s);
   3390   return(r);
   3391 }
   3392 
   3393 smallStringt *readLineO(FILE *fp) {
   3394   char *s = NULL;
   3395 
   3396   // sanity checks
   3397   if (!fp) {
   3398     return(NULL);
   3399   }
   3400 
   3401   s = readLine(fp);
   3402   if (!s) {
   3403     return(NULL);
   3404   }
   3405   createAllocateSmallString(r);
   3406   if (!r) {
   3407     free(s);
   3408     return(NULL);
   3409   }
   3410   r->f->setNFree(r, s);
   3411   return(r);
   3412 }
   3413 
   3414 char *intToSG(char *retType UNUSED, int64_t n) {
   3415 
   3416   return(intToS(n));
   3417 }
   3418 
   3419 char *doubleToSG(char *retType UNUSED, double n) {
   3420 
   3421   return(doubleToS(n));
   3422 }
   3423 
   3424 char **iListUniqG(char ***list, int dum UNUSED) {
   3425 
   3426   return(iListUniqS(list));
   3427 }
   3428 
   3429 char **iicListUniqG(char ***list, int dum UNUSED) {
   3430 
   3431   return(iicListUniqS(list));
   3432 }
   3433 
   3434 char **listFromArrayG(char **retType UNUSED, char **array, size_t size) {
   3435 
   3436   return(listFromArrayS(array, size));
   3437 }
   3438 
   3439 char **listFromCArrayG(char **retType UNUSED, const char **array, size_t size) {
   3440 
   3441   return(listFromCArrayS(array, size));
   3442 }
   3443 
   3444 char getSG(const char *string, int retType UNUSED, int64_t index) {
   3445 
   3446   return(getS(string, index));
   3447 }
   3448 
   3449 char *listGetG(char **list, int retType UNUSED, int64_t index) {
   3450 
   3451   return(listGetS(list, index));
   3452 }
   3453 
   3454 char *listGetCG(const char **list, int retType UNUSED, int64_t index) {
   3455 
   3456   return(listGetCS(list, index));
   3457 }
   3458 
   3459 char *iListGetG(char **list, int retType UNUSED, int64_t index) {
   3460 
   3461   return(iListGetS(list, index));
   3462 }
   3463 
   3464 const char *iListGetCG(const char **list, int retType UNUSED, int64_t index) {
   3465 
   3466   return(iListGetCS(list, index));
   3467 }
   3468 
   3469 char *listPopG(char ***list, int retType UNUSED) {
   3470 
   3471   return(listPopS(list));
   3472 }
   3473 
   3474 char *listDequeueG(char ***list, int retType UNUSED) {
   3475 
   3476   return(listDequeueS(list));
   3477 }
   3478 
   3479 char **listDupCG(const char **list) {
   3480 
   3481   return(listDupCS(list));
   3482 }
   3483 
   3484 bool listEqCG(char **list1, const char **list2) {
   3485 
   3486   return(listEqCS(list1, list2));
   3487 }
   3488 
   3489 bool listEqC1G(const char **list1, char **list2) {
   3490 
   3491   return(listEqC1S(list1, list2));
   3492 }
   3493 
   3494 bool listEqCCG(const char **list1, const char **list2) {
   3495 
   3496   return(listEqCCS(list1, list2));
   3497 }
   3498 
   3499 bool icListEqCG(char **list1, const char **list2) {
   3500 
   3501   return(icListEqCS(list1, list2));
   3502 }
   3503 
   3504 bool icListEqC1G(const char **list1, char **list2) {
   3505 
   3506   return(icListEqC1S(list1, list2));
   3507 }
   3508 
   3509 bool icListEqCCG(const char **list1, const char **list2) {
   3510 
   3511   return(icListEqCCS(list1, list2));
   3512 }
   3513 
   3514 size_t listLengthCG(const char **list) {
   3515 
   3516   return(listLengthCS(list));
   3517 }
   3518 
   3519 ssize_t listIndexOfCG(const char **list, const char *string) {
   3520 
   3521   return(listIndexOfCS(list, string));
   3522 }
   3523 
   3524 ssize_t listIndexOfCharCG(const char **list, char c) {
   3525 
   3526   return(listIndexOfCharCS(list, c));
   3527 }
   3528 
   3529 ssize_t icListIndexOfCG(const char **list, const char *string) {
   3530 
   3531   return(icListIndexOfCS(list, string));
   3532 }
   3533 
   3534 ssize_t icListIndexOfCharCG(const char **list, char c) {
   3535 
   3536   return(icListIndexOfCharCS(list, c));
   3537 }
   3538 
   3539 bool listHasCharCG(const char **list, char c) {
   3540 
   3541   return(listHasCharCS(list, c));
   3542 }
   3543 
   3544 bool listHasCG(const char **list, const char *string) {
   3545 
   3546   return(listHasCS(list, string));
   3547 }
   3548 
   3549 bool icListHasCG(const char **list, const char *string) {
   3550 
   3551   return(icListHasCS(list, string));
   3552 }
   3553 
   3554 bool icListHasCharCG(const char **list, char c) {
   3555 
   3556   return(icListHasCharCS(list, c));
   3557 }
   3558 
   3559 char *joinCG(const char **list, const char* delim) {
   3560 
   3561   return(joinCS(list, delim));
   3562 }
   3563 
   3564 char *joinCharCG(const char **list, char delim) {
   3565 
   3566   charToS(s, delim);
   3567   return(joinCS(list, s));
   3568 }
   3569 
   3570 char **listAddCG(char **list1, const char **list2) {
   3571 
   3572   return(listAddCS(list1, list2));
   3573 }
   3574 
   3575 int listPrintCG(const char **list) {
   3576 
   3577   return(listPrintCS(list));
   3578 }
   3579 
   3580 bool eqCharChar(char c, char value) {
   3581 
   3582   return(c == value);;
   3583 }
   3584 
   3585 bool equalChaOG(char c, baset* value) {
   3586 
   3587   charToS(s, c);
   3588   return(equalCharOG(s, value));
   3589 }
   3590 
   3591 bool equalChaBoolG(char c UNUSED, bool value UNUSED) {
   3592 
   3593   return(false);
   3594 }
   3595 
   3596 bool equalChaDoubleG(char c, double value) {
   3597 
   3598   charToS(s, c);
   3599   return(equalDoubleCharG(value, s));
   3600 }
   3601 
   3602 bool equalChaInt64G(char c, int64_t value) {
   3603 
   3604   charToS(s, c);
   3605   return(equalInt64CharG(value, s));
   3606 }
   3607 
   3608 bool equalChaInt32G(char c, int32_t value) {
   3609 
   3610   charToS(s, c);
   3611   return(equalInt32CharG(value, s));
   3612 }
   3613 
   3614 bool equalChaUint32G(char c, uint32_t value) {
   3615 
   3616   charToS(s, c);
   3617   return(equalUint32CharG(value, s));
   3618 }
   3619 
   3620 bool equalChaUint64G(char c, uint64_t value) {
   3621 
   3622   charToS(s, c);
   3623   return(equalUint64CharG(value, s));
   3624 }
   3625 
   3626 bool equalChaSmallBytesG(char c, smallBytest* value) {
   3627 
   3628   if (!value || !value->B) {
   3629     return(false);
   3630   }
   3631 
   3632   charToS(s, c);
   3633 
   3634   return(equalSO(value, s));
   3635 }
   3636 
   3637 bool equalChaSmallDoubleG(char c, smallDoublet* value) {
   3638 
   3639   charToS(s, c);
   3640 
   3641   if (!value) {
   3642     return(false);
   3643   }
   3644   return(value->f->equalChar(value, s));
   3645 }
   3646 
   3647 bool equalChaSmallIntG(char c, smallIntt* value) {
   3648 
   3649   charToS(s, c);
   3650 
   3651   if (!value) {
   3652     return(false);
   3653   }
   3654   return(value->f->equalChar(value, s));
   3655 }
   3656 
   3657 bool equalChaSmallJsonG(char c, smallJsont* value) {
   3658 
   3659   if (!value) {
   3660     return(false);
   3661   }
   3662 
   3663   if (checkObjectTypes && !isOSmallJson(value)) {
   3664     return(0);
   3665   }
   3666 
   3667   const char *type = getTopTypeO(value);
   3668 
   3669   if (!eqS(type,"string")) {
   3670     return(0);
   3671   }
   3672 
   3673   charToS(s, c);
   3674   return(eqS(getTopSO(value), s));
   3675 }
   3676 
   3677 bool equalChaSmallStringG(char c, smallStringt* value) {
   3678 
   3679   if (!value || !value->data) {
   3680     return(false);
   3681   }
   3682 
   3683   charToS(s, c);
   3684   return(equalSO(value, s));
   3685 }
   3686 
   3687 
   3688 bool equalCharOG(const char *s, baset* value) {
   3689 
   3690   if (!s || !value) {
   3691     return(false);
   3692   }
   3693 
   3694   char *v = toStringO(value);
   3695   bool r  = strEq(s, v);
   3696   free(v);
   3697   return(r);
   3698 }
   3699 
   3700 bool equalCharBoolG(const char *s, bool value) {
   3701 
   3702   return(equalBoolCharG(value, s));
   3703 }
   3704 
   3705 bool equalCharDoubleG(const char *s, double value) {
   3706 
   3707   return(equalDoubleCharG(value, s));
   3708 }
   3709 
   3710 bool equalCharInt64G(const char *s, int64_t value) {
   3711 
   3712   return(equalInt64CharG(value, s));
   3713 }
   3714 
   3715 bool equalCharInt32G(const char *s, int32_t value) {
   3716 
   3717   return(equalInt32CharG(value, s));
   3718 }
   3719 
   3720 bool equalCharUint32G(const char *s, uint32_t value) {
   3721 
   3722   return(equalUint32CharG(value, s));
   3723 }
   3724 
   3725 bool equalCharUint64G(const char *s, uint64_t value) {
   3726 
   3727   return(equalUint64CharG(value, s));
   3728 }
   3729 
   3730 bool equalCharSmallBoolG(const char *s, smallBoolt* value) {
   3731 
   3732   if (!value) {
   3733     return(false);
   3734   }
   3735   return(value->f->equalChar(value, s));
   3736 }
   3737 
   3738 bool equalCharSmallBytesG(const char *s, smallBytest* value) {
   3739 
   3740   if (!value) {
   3741     return(false);
   3742   }
   3743   return(value->f->equalS(value, s));
   3744 }
   3745 
   3746 bool equalCharSmallDoubleG(const char *s, smallDoublet* value) {
   3747 
   3748   if (!value) {
   3749     return(false);
   3750   }
   3751   return(value->f->equalChar(value, s));
   3752 }
   3753 
   3754 bool equalCharSmallIntG(const char *s, smallIntt* value) {
   3755 
   3756   if (!value) {
   3757     return(false);
   3758   }
   3759   return(value->f->equalChar(value, s));
   3760 }
   3761 
   3762 bool equalCharPSmallJsonG(const char *s, smallJsont* value) {
   3763 
   3764   if (!value) {
   3765     return(false);
   3766   }
   3767 
   3768   if (checkObjectTypes && !isOSmallJson(value)) {
   3769     return(false);
   3770   }
   3771 
   3772   const char *type = getTopTypeO(value);
   3773 
   3774   if (!eqS(type,"string")) {
   3775     return(false);
   3776   }
   3777 
   3778   return(eqS(getTopSO(value), s));
   3779 }
   3780 
   3781 bool equalCharPSmallStringG(const char *s, smallStringt* value) {
   3782 
   3783   if (!value) {
   3784     return(false);
   3785   }
   3786   return(equalSO(value, s));
   3787 }
   3788 
   3789 
   3790 bool equalArrayOG(char ** p1, baset* p2) {
   3791 
   3792   if (!p1 || !p2) {
   3793     return(false);
   3794   }
   3795 
   3796   if (!isOType(p2, "smallArray")) {
   3797     return(false);
   3798   }
   3799 
   3800   cast(smallArrayt *, arr, p2);
   3801 
   3802   if (!listLengthS(p1) || !lenO(arr)) {
   3803     return(false);
   3804   }
   3805 
   3806   // compare elements
   3807   // TODO compare any types of element, not only strings
   3808   enumerateSArray(arr->a, e, i) {
   3809     if (not e) {
   3810       return(false);
   3811     }
   3812     if (!strEq(sStringGetTiny((sStringt*)e), p1[i])) {
   3813       return(false);
   3814   }
   3815     }
   3816 
   3817   return(true);
   3818 }
   3819 
   3820 bool equalCArrayOG(const char ** p1, baset* p2) {
   3821 
   3822   if (!p1 || !p2) {
   3823     return(false);
   3824   }
   3825 
   3826   if (!isOType(p2, "smallArray")) {
   3827     return(false);
   3828   }
   3829 
   3830   cast(smallArrayt *, arr, p2);
   3831 
   3832   if (!listLengthCS(p1) || !lenO(arr)) {
   3833     return(false);
   3834   }
   3835 
   3836   // compare elements
   3837   // TODO compare any types of element, not only strings
   3838   enumerateSArray(arr->a, e, i) {
   3839     if (not e) {
   3840       return(false);
   3841     }
   3842     if (!strEq(sStringGetTiny((sStringt*)e), p1[i])) {
   3843       return(false);
   3844   }
   3845     }
   3846 
   3847   return(true);
   3848 }
   3849 
   3850 bool equalArraySmallJsonG(char ** p1, smallJsont* p2) {
   3851 
   3852   if (!p1 || !p2) {
   3853     return(false);
   3854   }
   3855 
   3856   if (checkObjectTypes && !isOSmallJson(p2)) {
   3857     return(false);
   3858   }
   3859 
   3860   const char *type = getTopTypeO(p2);
   3861 
   3862   if (!eqS(type,"array")) {
   3863     return(false);
   3864   }
   3865 
   3866   return(p2->f->equalArray(p2, p1));
   3867 }
   3868 
   3869 bool equalArraySmallArrayG(char ** p1, smallArrayt* p2) {
   3870 
   3871   if (!p2) {
   3872     return(false);
   3873   }
   3874 
   3875   if (checkObjectTypes && !isOSmallArray(p2)) {
   3876     return(false);
   3877   }
   3878 
   3879   return(p2->f->equalArray(p2, p1));
   3880 }
   3881 
   3882 bool equalCArraySmallJsonG(const char ** p1, smallJsont* p2) {
   3883 
   3884   if (!p1 || !p2) {
   3885     return(false);
   3886   }
   3887 
   3888   if (checkObjectTypes && !isOSmallJson(p2)) {
   3889     return(false);
   3890   }
   3891 
   3892   const char *type = getTopTypeO(p2);
   3893 
   3894   if (!eqS(type,"array")) {
   3895     return(false);
   3896   }
   3897 
   3898   return(p2->f->equalCArray(p2, p1));
   3899 }
   3900 
   3901 bool equalCArraySmallArrayG(const char ** p1, smallArrayt* p2) {
   3902 
   3903   if (!p2) {
   3904     return(false);
   3905   }
   3906 
   3907   if (checkObjectTypes && !isOSmallArray(p2)) {
   3908     return(false);
   3909   }
   3910 
   3911   return(p2->f->equalCArray(p2, p1));
   3912 }
   3913 
   3914 bool equalOCharG(baset* p1, const char * p2) {
   3915 
   3916   return(equalCharOG(p2, p1));
   3917 }
   3918 
   3919 bool equalOChaG(baset* p1, char p2) {
   3920 
   3921   return(equalChaOG(p2, p1));
   3922 }
   3923 
   3924 bool equalOArrayG(baset* p1, char ** p2) {
   3925 
   3926   return(equalArrayOG(p2, p1));
   3927 }
   3928 
   3929 bool equalOCArrayG(baset* p1, const char ** p2) {
   3930 
   3931   return(equalCArrayOG(p2, p1));
   3932 }
   3933 
   3934 bool equalOOG(baset* p1, baset* p2) {
   3935 
   3936   if (!p1 || !p2) {
   3937     return(false);
   3938   }
   3939 
   3940   char *s = toStringO(p1);
   3941   char *S = toStringO(p2);
   3942   bool r;
   3943   if (strEq(s, S)) {
   3944     r = true;
   3945   }
   3946   else {
   3947     r = false;
   3948   }
   3949   freeManyS(s, S);
   3950   return(r);
   3951 }
   3952 
   3953 bool equalOBoolG(baset* p1, bool p2) {
   3954 
   3955   return(equalBoolOG(p2, p1));
   3956 }
   3957 
   3958 bool equalODoubleG(baset* p1, double p2) {
   3959 
   3960   return(equalDoubleBaseG(p2, p1));
   3961 }
   3962 
   3963 bool equalOInt64G(baset* p1, int64_t p2) {
   3964 
   3965   return(equalInt64BaseG(p2, p1));
   3966 }
   3967 
   3968 bool equalOInt32G(baset* p1, int32_t p2) {
   3969 
   3970   return(equalInt32BaseG(p2, p1));
   3971 }
   3972 
   3973 bool equalOUint32G(baset* p1, uint32_t p2) {
   3974 
   3975   return(equalUint32BaseG(p2, p1));
   3976 }
   3977 
   3978 bool equalOUint64G(baset* p1, uint64_t p2) {
   3979 
   3980   return(equalUint64BaseG(p2, p1));
   3981 }
   3982 
   3983 bool equalOSmallArrayG(baset* p1, smallArrayt* p2) {
   3984 
   3985   if (!p2) {
   3986     return(false);
   3987   }
   3988 
   3989   if (checkObjectTypes && !isOSmallArray(p2)) {
   3990     return(false);
   3991   }
   3992 
   3993   return(p2->f->equalBase(p2, p1));
   3994 }
   3995 
   3996 bool equalOSmallBoolG(baset* p1, smallBoolt* p2) {
   3997 
   3998   if (!p2) {
   3999     return(false);
   4000   }
   4001 
   4002   if (checkObjectTypes && !isOSmallBool(p2)) {
   4003     return(false);
   4004   }
   4005 
   4006   return(p2->f->equalBase(p2, p1));
   4007 }
   4008 
   4009 bool equalOSmallBytesG(baset* p1, smallBytest* p2) {
   4010 
   4011   if (!p2) {
   4012     return(false);
   4013   }
   4014 
   4015   if (checkObjectTypes && !isOSmallBytes(p2)) {
   4016     return(false);
   4017   }
   4018 
   4019   return(p2->f->equalBase(p2, p1));
   4020 }
   4021 
   4022 bool equalOSmallDoubleG(baset* p1, smallDoublet* p2) {
   4023 
   4024   if (!p2) {
   4025     return(false);
   4026   }
   4027 
   4028   if (checkObjectTypes && !isOSmallDouble(p2)) {
   4029     return(false);
   4030   }
   4031 
   4032   return(p2->f->equalBase(p2, p1));
   4033 }
   4034 
   4035 bool equalOSmallDictG(baset* p1, smallDictt* p2) {
   4036 
   4037   if (!p2) {
   4038     return(false);
   4039   }
   4040 
   4041   if (checkObjectTypes && !isOSmallDict(p2)) {
   4042     return(false);
   4043   }
   4044 
   4045   return(p2->f->equalBase(p2, p1));
   4046 }
   4047 
   4048 bool equalOSmallIntG(baset* p1, smallIntt* p2) {
   4049 
   4050   if (!p2) {
   4051     return(false);
   4052   }
   4053 
   4054   if (checkObjectTypes && !isOSmallInt(p2)) {
   4055     return(false);
   4056   }
   4057 
   4058   return(p2->f->equalBase(p2, p1));
   4059 }
   4060 
   4061 bool equalOSmallJsonG(baset* p1, smallJsont* p2) {
   4062 
   4063   if (!p2) {
   4064     return(false);
   4065   }
   4066 
   4067   if (checkObjectTypes && !isOSmallJson(p2)) {
   4068     return(false);
   4069   }
   4070 
   4071   return(p2->f->equalBase(p2, p1));
   4072 }
   4073 
   4074 bool equalOSmallStringG(baset* p1, smallStringt* p2) {
   4075 
   4076   if (!p1 || !p2 || !p2->data) {
   4077     return(false);
   4078   }
   4079 
   4080   if (checkObjectTypes && !isOSmallString(p2)) {
   4081     return(false);
   4082   }
   4083 
   4084   char *s = toStringO(p1);
   4085 
   4086   bool r = equalSO(p2, s);
   4087   free(s);
   4088   return(r);
   4089 }
   4090 
   4091 bool equalBoolChaG(bool p1 UNUSED, char p2 UNUSED) {
   4092 
   4093   return(false);
   4094 }
   4095 
   4096 bool equalBoolCharG(bool p1, const char * p2) {
   4097 
   4098   if (!p2) {
   4099     return(false);
   4100   }
   4101 
   4102   if (strEq(p2, "true") || strEq(p2, "TRUE")) {
   4103     return(p1);
   4104   }
   4105   else if (strEq(p2, "false") || strEq(p2, "FALSE")) {
   4106     return(!p1);
   4107   }
   4108   return(false);
   4109 }
   4110 
   4111 bool equalBoolOG(bool p1, baset* p2) {
   4112 
   4113   if (!p2) {
   4114     return(false);
   4115   }
   4116 
   4117   char *s = toStringO(p2);
   4118 
   4119   if (strEq(s, "true") || strEq(s, "TRUE")) {
   4120     free(s);
   4121     return(p1);
   4122   }
   4123   else if (strEq(s, "false") || strEq(s, "FALSE")) {
   4124     free(s);
   4125     return(!p1);
   4126   }
   4127   free(s);
   4128   return(false);
   4129 }
   4130 
   4131 bool equalBoolFG(bool p1, bool p2) {
   4132 
   4133   return(p1 == p2);;
   4134 }
   4135 
   4136 bool equalBoolDoubleG(bool p1, double p2) {
   4137 
   4138   return(p1 == p2);;
   4139 }
   4140 
   4141 bool equalBoolInt64G(bool p1, int64_t p2) {
   4142 
   4143   return(p1 == p2);;
   4144 }
   4145 
   4146 bool equalBoolInt32G(bool p1, int32_t p2) {
   4147 
   4148   return(p1 == p2);;
   4149 }
   4150 
   4151 bool equalBoolUint32G(bool p1, uint32_t p2) {
   4152 
   4153   return(p1 == p2);;
   4154 }
   4155 
   4156 bool equalBoolUint64G(bool p1, uint64_t p2) {
   4157 
   4158   return(p1 == p2);;
   4159 }
   4160 
   4161 bool equalBoolSmallBoolG(bool p1, smallBoolt* p2) {
   4162 
   4163   if (!p2 || !p2->value) {
   4164     return(false);
   4165   }
   4166 
   4167   return(p2->value->value == p1);;
   4168 }
   4169 
   4170 bool equalBoolSmallBytesG(bool p1, smallBytest* p2) {
   4171 
   4172   if (!p2 || !p2->B) {
   4173     return(false);
   4174   }
   4175 
   4176   if (equalSO(p2, "true") || equalSO(p2, "TRUE")) {
   4177     return(p1);
   4178   }
   4179   else if (equalSO(p2, "false") || equalSO(p2, "FALSE")) {
   4180     return(!p1);
   4181   }
   4182   return(false);
   4183 }
   4184 
   4185 bool equalBoolSmallDoubleG(bool p1, smallDoublet* p2) {
   4186 
   4187   if (!p2 || !p2->value) {
   4188     return(false);
   4189   }
   4190 
   4191   return(p2->value->value == p1);;
   4192 }
   4193 
   4194 bool equalBoolSmallIntG(bool p1, smallIntt* p2) {
   4195 
   4196   if (!p2 || !p2->value) {
   4197     return(false);
   4198   }
   4199 
   4200   return(p2->value->value == p1);;
   4201 }
   4202 
   4203 bool equalBoolSmallJsonG(bool p1, smallJsont* p2) {
   4204 
   4205   if (!p2) {
   4206     return(false);
   4207   }
   4208 
   4209   if (checkObjectTypes && !isOSmallJson(p2)) {
   4210     return(false);
   4211   }
   4212 
   4213   return(equalBoolO(p2, p1));
   4214 }
   4215 
   4216 bool equalBoolSmallStringG(bool p1, smallStringt* p2) {
   4217 
   4218   if (!p2 || !p2->data) {
   4219     return(false);
   4220   }
   4221 
   4222   char *s = sStringGetTiny(p2->data);
   4223   if (strEq(s, "true") || strEq(s, "TRUE")) {
   4224     return(p1);
   4225   }
   4226   else if (strEq(s, "false") || strEq(s, "FALSE")) {
   4227     return(!p1);
   4228   }
   4229   return(false);
   4230 }
   4231 
   4232 bool equalDoubleChaG(double p1, char p2) {
   4233 
   4234   return(equalChaDoubleG(p2, p1));
   4235 }
   4236 
   4237 bool equalDoubleCharG(double p1, const char * p2) {
   4238 
   4239   if (!p2) {
   4240     return(false);
   4241   }
   4242 
   4243   if (isInt(p2) || !isNumber(p2)) {
   4244     return(false);
   4245   }
   4246 
   4247   double value = parseDouble(p2);
   4248 
   4249   return(p1 == value);;
   4250 }
   4251 
   4252 bool equalDoubleBaseG(double p1, baset* p2) {
   4253 
   4254   if (!p2) {
   4255     return(false);
   4256   }
   4257 
   4258   char *s = toStringO(p2);
   4259 
   4260   if (isInt(s) || !isNumber(s)) {
   4261     free(s);
   4262     return(false);
   4263   }
   4264 
   4265   double value = parseDouble(s);
   4266 
   4267   bool r;
   4268   if (p1 == value) {
   4269     r = true;
   4270   }
   4271   else {
   4272     r = false;
   4273   }
   4274   free(s);
   4275   return(r);
   4276 }
   4277 
   4278 bool equalDoubleBoolG(double p1, bool p2) {
   4279 
   4280   return(p1 == p2);;
   4281 }
   4282 
   4283 bool equalDoubleFG(double p1, double p2) {
   4284 
   4285   return(p1 == p2);;
   4286 }
   4287 
   4288 bool equalDoubleInt64G(double p1, int64_t p2) {
   4289 
   4290   return(p1 == p2);;
   4291 }
   4292 
   4293 bool equalDoubleInt32G(double p1, int32_t p2) {
   4294 
   4295   return(p1 == p2);;
   4296 }
   4297 
   4298 bool equalDoubleUint32G(double p1, uint32_t p2) {
   4299 
   4300   return(p1 == p2);;
   4301 }
   4302 
   4303 bool equalDoubleUint64G(double p1, uint64_t p2) {
   4304 
   4305   return(p1 == p2);;
   4306 }
   4307 
   4308 bool equalDoubleSmallBoolG(double p1, smallBoolt* p2) {
   4309 
   4310   if (!p2 || !p2->value) {
   4311     return(false);
   4312   }
   4313 
   4314   return(p2->value->value == p1);;
   4315 }
   4316 
   4317 bool equalDoubleSmallBytesG(double p1, smallBytest* p2) {
   4318 
   4319   if (!p2 || !p2->B) {
   4320     return(false);
   4321   }
   4322 
   4323   char *s = sBytesGet(p2->B);
   4324 
   4325   bool has0 = false;
   4326   rangeDown(i, p2->B->count) {
   4327     if (s[i] == 0) {
   4328       has0 = true;
   4329       break;
   4330     }
   4331   }
   4332 
   4333   if (!has0) {
   4334     return(false);
   4335   }
   4336 
   4337   if (isInt(s) || !isNumber(s)) {
   4338     return(false);
   4339   }
   4340 
   4341   double p2Value = parseDouble(s);
   4342 
   4343   return(p2Value == p1);;
   4344 }
   4345 
   4346 bool equalDoubleSmallDoubleG(double p1, smallDoublet* p2) {
   4347 
   4348   if (!p2 || !p2->value) {
   4349     return(false);
   4350   }
   4351 
   4352   return(p2->value->value == p1);;
   4353 }
   4354 
   4355 bool equalDoubleSmallIntG(double p1, smallIntt* p2) {
   4356 
   4357   if (!p2 || !p2->value) {
   4358     return(false);
   4359   }
   4360 
   4361   return(p2->value->value == p1);;
   4362 }
   4363 
   4364 bool equalDoubleSmallJsonG(double p1, smallJsont* p2) {
   4365 
   4366   if (!p2) {
   4367     return(false);
   4368   }
   4369 
   4370   if (checkObjectTypes && !isOSmallJson(p2)) {
   4371     return(false);
   4372   }
   4373 
   4374   return(equalDoubleO(p2, p1));
   4375 }
   4376 
   4377 bool equalDoubleSmallStringG(double p1, smallStringt* p2) {
   4378 
   4379   if (!p2 || !p2->data) {
   4380     return(false);
   4381   }
   4382 
   4383   char *s = sStringGetTiny(p2->data);
   4384 
   4385   if (isInt(s) || !isNumber(s)) {
   4386     return(false);
   4387   }
   4388 
   4389   double p2Value = parseDoubleO(p2);
   4390 
   4391   return(p2Value == p1);;
   4392 }
   4393 
   4394 bool equalInt64ChaG(int64_t p1, char p2) {
   4395 
   4396   return(equalChaInt64G(p2, p1));
   4397 }
   4398 
   4399 bool equalInt64CharG(int64_t p1, const char * p2) {
   4400 
   4401   if (!p2) {
   4402     return(false);
   4403   }
   4404 
   4405   if (!isInt(p2)) {
   4406     return(false);
   4407   }
   4408 
   4409   int64_t value = parseInt(p2);
   4410 
   4411   return(p1 == value);;
   4412 }
   4413 
   4414 bool equalInt64BaseG(int64_t p1, baset* p2) {
   4415 
   4416   if (!p2) {
   4417     return(false);
   4418   }
   4419 
   4420   char *s = toStringO(p2);
   4421 
   4422   if (!isInt(s)) {
   4423     free(s);
   4424     return(false);
   4425   }
   4426 
   4427   int64_t value = parseInt(s);
   4428 
   4429   bool r;
   4430   if (p1 == value) {
   4431     r = true;
   4432   }
   4433   else {
   4434     r = false;
   4435   }
   4436   free(s);
   4437   return(r);
   4438 }
   4439 
   4440 bool equalInt64BoolG(int64_t p1, bool p2) {
   4441 
   4442   return(p1 == p2);;
   4443 }
   4444 
   4445 bool equalInt64DoubleG(int64_t p1, double p2) {
   4446 
   4447   return(p1 == p2);;
   4448 }
   4449 
   4450 bool equalInt64FG(int64_t p1, int64_t p2) {
   4451 
   4452   return(p1 == p2);;
   4453 }
   4454 
   4455 bool equalInt64Int32G(int64_t p1, int32_t p2) {
   4456 
   4457   return(p1 == p2);;
   4458 }
   4459 
   4460 bool equalInt64Uint32G(int64_t p1, uint32_t p2) {
   4461 
   4462   return(p1 == p2);;
   4463 }
   4464 
   4465 bool equalInt64Uint64G(int64_t p1, uint64_t p2) {
   4466 
   4467   return((uint64_t)p1 == p2);;
   4468 }
   4469 
   4470 bool equalInt64SmallBoolG(int64_t p1, smallBoolt* p2) {
   4471 
   4472   if (!p2 || !p2->value) {
   4473     return(false);
   4474   }
   4475 
   4476   return(p2->value->value == p1);;
   4477 }
   4478 
   4479 bool equalInt64SmallBytesG(int64_t p1, smallBytest* p2) {
   4480 
   4481   if (!p2 || !p2->B) {
   4482     return(false);
   4483   }
   4484 
   4485   char *s = sBytesGet(p2->B);
   4486 
   4487   bool has0 = false;
   4488   rangeDown(i, p2->B->count) {
   4489     if (s[i] == 0) {
   4490       has0 = true;
   4491       break;
   4492     }
   4493   }
   4494 
   4495   if (!has0) {
   4496     return(false);
   4497   }
   4498 
   4499   if (!isInt(s)) {
   4500     return(false);
   4501   }
   4502 
   4503   int64_t p2Value = parseInt(s);
   4504 
   4505   return(p2Value == p1);;
   4506 }
   4507 
   4508 bool equalInt64SmallDoubleG(int64_t p1, smallDoublet* p2) {
   4509 
   4510   if (!p2 || !p2->value) {
   4511     return(false);
   4512   }
   4513 
   4514   return(p2->value->value == p1);;
   4515 }
   4516 
   4517 bool equalInt64SmallIntG(int64_t p1, smallIntt* p2) {
   4518 
   4519   if (!p2 || !p2->value) {
   4520     return(false);
   4521   }
   4522 
   4523   return(p2->value->value == p1);;
   4524 }
   4525 
   4526 bool equalInt64SmallJsonG(int64_t p1, smallJsont* p2) {
   4527 
   4528   if (!p2) {
   4529     return(false);
   4530   }
   4531 
   4532   if (checkObjectTypes && !isOSmallJson(p2)) {
   4533     return(false);
   4534   }
   4535 
   4536   return(equalInt64O(p2, p1));
   4537 }
   4538 
   4539 bool equalInt64SmallStringG(int64_t p1, smallStringt* p2) {
   4540 
   4541   if (!p2 || !p2->data) {
   4542     return(false);
   4543   }
   4544 
   4545   char *s = sStringGetTiny(p2->data);
   4546 
   4547   if (!isInt(s)) {
   4548     return(false);
   4549   }
   4550 
   4551   int64_t p2Value = parseIntO(p2);
   4552 
   4553   return(p2Value == p1);;
   4554 }
   4555 
   4556 bool equalInt32ChaG(int32_t p1, char p2) {
   4557 
   4558   return(equalChaInt32G(p2, p1));
   4559 }
   4560 
   4561 bool equalInt32CharG(int32_t p1, const char * p2) {
   4562 
   4563   if (!p2) {
   4564     return(false);
   4565   }
   4566 
   4567   if (!isInt(p2)) {
   4568     return(false);
   4569   }
   4570 
   4571   int32_t value = (int32_t)parseInt(p2);
   4572 
   4573   return(p1 == value);;
   4574 }
   4575 
   4576 bool equalInt32BaseG(int32_t p1, baset* p2) {
   4577 
   4578   if (!p2) {
   4579     return(false);
   4580   }
   4581 
   4582   char *s = toStringO(p2);
   4583 
   4584   if (!isInt(s)) {
   4585     free(s);
   4586     return(false);
   4587   }
   4588 
   4589   int32_t value = (int32_t)parseInt(s);
   4590 
   4591   bool r;
   4592   if (p1 == value) {
   4593     r = true;
   4594   }
   4595   else {
   4596     r = false;
   4597   }
   4598   free(s);
   4599   return(r);
   4600 }
   4601 
   4602 bool equalInt32BoolG(int32_t p1, bool p2) {
   4603 
   4604   return(p1 == p2);;
   4605 }
   4606 
   4607 bool equalInt32DoubleG(int32_t p1, double p2) {
   4608 
   4609   return(p1 == p2);;
   4610 }
   4611 
   4612 bool equalInt32Int64G(int32_t p1, int64_t p2) {
   4613 
   4614   return(p1 == p2);;
   4615 }
   4616 
   4617 bool equalInt32FG(int32_t p1, int32_t p2) {
   4618 
   4619   return(p1 == p2);;
   4620 }
   4621 
   4622 bool equalInt32Uint32G(int32_t p1, uint32_t p2) {
   4623 
   4624   return((uint32_t)p1 == p2);;
   4625 }
   4626 
   4627 bool equalInt32Uint64G(int32_t p1, uint64_t p2) {
   4628 
   4629   return((uint64_t)p1 == p2);;
   4630 }
   4631 
   4632 bool equalInt32SmallBoolG(int32_t p1, smallBoolt* p2) {
   4633 
   4634   if (!p2 || !p2->value) {
   4635     return(false);
   4636   }
   4637 
   4638   return(p2->value->value == p1);;
   4639 }
   4640 
   4641 bool equalInt32SmallBytesG(int32_t p1, smallBytest* p2) {
   4642 
   4643   if (!p2 || !p2->B) {
   4644     return(false);
   4645   }
   4646 
   4647   char *s = sBytesGet(p2->B);
   4648 
   4649   bool has0 = false;
   4650   rangeDown(i, p2->B->count) {
   4651     if (s[i] == 0) {
   4652       has0 = true;
   4653       break;
   4654     }
   4655   }
   4656 
   4657   if (!has0) {
   4658     return(false);
   4659   }
   4660 
   4661   if (!isInt(s)) {
   4662     return(false);
   4663   }
   4664 
   4665   int32_t p2Value = (int32_t)parseInt(s);
   4666 
   4667   return(p2Value == p1);;
   4668 }
   4669 
   4670 bool equalInt32SmallDoubleG(int32_t p1, smallDoublet* p2) {
   4671 
   4672   if (!p2 || !p2->value) {
   4673     return(false);
   4674   }
   4675 
   4676   return(p2->value->value == p1);;
   4677 }
   4678 
   4679 bool equalInt32SmallIntG(int32_t p1, smallIntt* p2) {
   4680 
   4681   if (!p2 || !p2->value) {
   4682     return(false);
   4683   }
   4684 
   4685   return(p2->value->value == p1);;
   4686 }
   4687 
   4688 bool equalInt32SmallJsonG(int32_t p1, smallJsont* p2) {
   4689 
   4690   if (!p2) {
   4691     return(false);
   4692   }
   4693 
   4694   if (checkObjectTypes && !isOSmallJson(p2)) {
   4695     return(false);
   4696   }
   4697 
   4698   return(equalInt32O(p2, p1));
   4699 }
   4700 
   4701 bool equalInt32SmallStringG(int32_t p1, smallStringt* p2) {
   4702 
   4703   if (!p2 || !p2->data) {
   4704     return(false);
   4705   }
   4706 
   4707   char *s = sStringGetTiny(p2->data);
   4708 
   4709   if (!isInt(s)) {
   4710     return(false);
   4711   }
   4712 
   4713   int32_t p2Value = (int32_t)parseIntO(p2);
   4714 
   4715   return(p2Value == p1);;
   4716 }
   4717 
   4718 bool equalUint32ChaG(uint32_t p1, char p2) {
   4719 
   4720   return(equalChaUint32G(p2, p1));
   4721 }
   4722 
   4723 bool equalUint32CharG(uint32_t p1, const char * p2) {
   4724 
   4725   if (!p2) {
   4726     return(false);
   4727   }
   4728 
   4729   if (!isInt(p2)) {
   4730     return(false);
   4731   }
   4732 
   4733   uint32_t value = (uint32_t)parseInt(p2);
   4734 
   4735   return(p1 == value);;
   4736 }
   4737 
   4738 bool equalUint32BaseG(uint32_t p1, baset* p2) {
   4739 
   4740   if (!p2) {
   4741     return(false);
   4742   }
   4743 
   4744   char *s = toStringO(p2);
   4745 
   4746   if (!isInt(s)) {
   4747     free(s);
   4748     return(false);
   4749   }
   4750 
   4751   uint32_t value = (uint32_t)parseInt(s);
   4752 
   4753   bool r;
   4754   if (p1 == value) {
   4755     r = true;
   4756   }
   4757   else {
   4758     r = false;
   4759   }
   4760   free(s);
   4761   return(r);
   4762 }
   4763 
   4764 bool equalUint32BoolG(uint32_t p1, bool p2) {
   4765 
   4766   return(p1 == p2);;
   4767 }
   4768 
   4769 bool equalUint32DoubleG(uint32_t p1, double p2) {
   4770 
   4771   return(p1 == p2);;
   4772 }
   4773 
   4774 bool equalUint32Int64G(uint32_t p1, int64_t p2) {
   4775 
   4776   return(p1 == p2);;
   4777 }
   4778 
   4779 bool equalUint32Int32G(uint32_t p1, int32_t p2) {
   4780 
   4781   return(p1 == (uint32_t)p2);;
   4782 }
   4783 
   4784 bool equalUint32FG(uint32_t p1, uint32_t p2) {
   4785 
   4786   return(p1 == p2);;
   4787 }
   4788 
   4789 bool equalUint32Uint64G(uint32_t p1, uint64_t p2) {
   4790 
   4791   return(p1 == p2);;
   4792 }
   4793 
   4794 bool equalUint32SmallBoolG(uint32_t p1, smallBoolt* p2) {
   4795 
   4796   if (!p2 || !p2->value) {
   4797     return(false);
   4798   }
   4799 
   4800   return(p2->value->value == p1);;
   4801 }
   4802 
   4803 bool equalUint32SmallBytesG(uint32_t p1, smallBytest* p2) {
   4804 
   4805   if (!p2 || !p2->B) {
   4806     return(false);
   4807   }
   4808 
   4809   char *s = sBytesGet(p2->B);
   4810 
   4811   bool has0 = false;
   4812   rangeDown(i, p2->B->count) {
   4813     if (s[i] == 0) {
   4814       has0 = true;
   4815       break;
   4816     }
   4817   }
   4818 
   4819   if (!has0) {
   4820     return(false);
   4821   }
   4822 
   4823   if (!isInt(s)) {
   4824     return(false);
   4825   }
   4826 
   4827   uint32_t p2Value = (uint32_t)parseInt(s);
   4828 
   4829   return(p2Value == p1);;
   4830 }
   4831 
   4832 bool equalUint32SmallDoubleG(uint32_t p1, smallDoublet* p2) {
   4833 
   4834   if (!p2 || !p2->value) {
   4835     return(false);
   4836   }
   4837 
   4838   return(p2->value->value == p1);;
   4839 }
   4840 
   4841 bool equalUint32SmallIntG(uint32_t p1, smallIntt* p2) {
   4842 
   4843   if (!p2 || !p2->value) {
   4844     return(false);
   4845   }
   4846 
   4847   return(p2->value->value == p1);;
   4848 }
   4849 
   4850 bool equalUint32SmallJsonG(uint32_t p1, smallJsont* p2) {
   4851 
   4852   if (!p2) {
   4853     return(false);
   4854   }
   4855 
   4856   if (checkObjectTypes && !isOSmallJson(p2)) {
   4857     return(false);
   4858   }
   4859 
   4860   return(equalUint32O(p2, p1));
   4861 }
   4862 
   4863 bool equalUint32SmallStringG(uint32_t p1, smallStringt* p2) {
   4864 
   4865   if (!p2 || !p2->data) {
   4866     return(false);
   4867   }
   4868 
   4869   char *s = sStringGetTiny(p2->data);
   4870 
   4871   if (!isInt(s)) {
   4872     return(false);
   4873   }
   4874 
   4875   uint32_t p2Value = (uint32_t)parseIntO(p2);
   4876 
   4877   return(p2Value == p1);;
   4878 }
   4879 
   4880 bool equalUint64ChaG(uint64_t p1, char p2) {
   4881 
   4882   return(equalChaUint64G(p2, p1));
   4883 }
   4884 
   4885 bool equalUint64CharG(uint64_t p1, const char * p2) {
   4886 
   4887   if (!p2) {
   4888     return(false);
   4889   }
   4890 
   4891   if (!isInt(p2)) {
   4892     return(false);
   4893   }
   4894 
   4895   uint64_t value = (uint64_t)parseInt(p2);
   4896 
   4897   return(p1 == value);;
   4898 }
   4899 
   4900 bool equalUint64BaseG(uint64_t p1, baset* p2) {
   4901 
   4902   if (!p2) {
   4903     return(false);
   4904   }
   4905 
   4906   char *s = toStringO(p2);
   4907 
   4908   if (!isInt(s)) {
   4909     free(s);
   4910     return(false);
   4911   }
   4912 
   4913   uint64_t value = (uint64_t)parseInt(s);
   4914 
   4915   bool r;
   4916   if (p1 == value) {
   4917     r = true;
   4918   }
   4919   else {
   4920     r = false;
   4921   }
   4922   free(s);
   4923   return(r);
   4924 }
   4925 
   4926 bool equalUint64BoolG(uint64_t p1, bool p2) {
   4927 
   4928   return(p1 == p2);;
   4929 }
   4930 
   4931 bool equalUint64DoubleG(uint64_t p1, double p2) {
   4932 
   4933   return(p1 == p2);;
   4934 }
   4935 
   4936 bool equalUint64Int64G(uint64_t p1, int64_t p2) {
   4937 
   4938   return(p1 == (uint64_t)p2);;
   4939 }
   4940 
   4941 bool equalUint64Int32G(uint64_t p1, int32_t p2) {
   4942 
   4943   return(p1 == (uint64_t)p2);;
   4944 }
   4945 
   4946 bool equalUint64Uint32G(uint64_t p1, uint32_t p2) {
   4947 
   4948   return(p1 == p2);;
   4949 }
   4950 
   4951 bool equalUint64FG(uint64_t p1, uint64_t p2) {
   4952 
   4953   return(p1 == p2);;
   4954 }
   4955 
   4956 bool equalUint64SmallBoolG(uint64_t p1, smallBoolt* p2) {
   4957 
   4958   if (!p2 || !p2->value) {
   4959     return(false);
   4960   }
   4961 
   4962   return(p2->value->value == p1);;
   4963 }
   4964 
   4965 bool equalUint64SmallBytesG(uint64_t p1, smallBytest* p2) {
   4966 
   4967   if (!p2 || !p2->B) {
   4968     return(false);
   4969   }
   4970 
   4971   char *s = sBytesGet(p2->B);
   4972 
   4973   bool has0 = false;
   4974   rangeDown(i, p2->B->count) {
   4975     if (s[i] == 0) {
   4976       has0 = true;
   4977       break;
   4978     }
   4979   }
   4980 
   4981   if (!has0) {
   4982     return(false);
   4983   }
   4984 
   4985   if (!isInt(s)) {
   4986     return(false);
   4987   }
   4988 
   4989   uint64_t p2Value = (uint64_t)parseInt(s);
   4990 
   4991   return(p2Value == p1);;
   4992 }
   4993 
   4994 bool equalUint64SmallDoubleG(uint64_t p1, smallDoublet* p2) {
   4995 
   4996   if (!p2 || !p2->value) {
   4997     return(false);
   4998   }
   4999 
   5000   return(p2->value->value == p1);;
   5001 }
   5002 
   5003 bool equalUint64SmallIntG(uint64_t p1, smallIntt* p2) {
   5004 
   5005   if (!p2 || !p2->value) {
   5006     return(false);
   5007   }
   5008 
   5009   return((uint64_t)p2->value->value == p1);;
   5010 }
   5011 
   5012 bool equalUint64SmallJsonG(uint64_t p1, smallJsont* p2) {
   5013 
   5014   if (!p2) {
   5015     return(false);
   5016   }
   5017 
   5018   if (checkObjectTypes && !isOSmallJson(p2)) {
   5019     return(false);
   5020   }
   5021 
   5022   return(equalUint64O(p2, p1));
   5023 }
   5024 
   5025 bool equalUint64SmallStringG(uint64_t p1, smallStringt* p2) {
   5026 
   5027   if (!p2 || !p2->data) {
   5028     return(false);
   5029   }
   5030 
   5031   char *s = sStringGetTiny(p2->data);
   5032 
   5033   if (!isInt(s)) {
   5034     return(false);
   5035   }
   5036 
   5037   uint64_t p2Value = (uint64_t)parseIntO(p2);
   5038 
   5039   return(p2Value == p1);;
   5040 }
   5041 
   5042 bool notEqualCharG(char c UNUSED, void *value UNUSED) {
   5043 
   5044   return(false);
   5045 }
   5046 
   5047 bool notEqualOCharG(void *a UNUSED, char c UNUSED) {
   5048 
   5049   return(false);
   5050 }
   5051 
   5052 bool notEqualOG(void *a UNUSED, void *b UNUSED) {
   5053 
   5054   return(false);
   5055 }
   5056 
   5057 bool notEqualCCOG(const char *a UNUSED, void *b UNUSED) {
   5058 
   5059   return(false);
   5060 }
   5061 
   5062 bool notEqualBoolOG(bool p1 UNUSED, void *p2 UNUSED) {
   5063 
   5064   return(false);
   5065 }
   5066 
   5067 bool notEqualDoubleOG(double p1 UNUSED, void *p2 UNUSED) {
   5068 
   5069   return(false);
   5070 }
   5071 
   5072 bool notEqualInt64OG(int64_t p1 UNUSED, void *p2 UNUSED) {
   5073 
   5074   return(false);
   5075 }
   5076 
   5077 bool notEqualInt32OG(int32_t p1 UNUSED, void *p2 UNUSED) {
   5078 
   5079   return(false);
   5080 }
   5081 
   5082 bool notEqualUint32OG(uint32_t p1 UNUSED, void *p2 UNUSED) {
   5083 
   5084   return(false);
   5085 }
   5086 
   5087 bool notEqualUint64OG(uint64_t p1 UNUSED, void *p2 UNUSED) {
   5088 
   5089   return(false);
   5090 }
   5091 
   5092 bool notEqualOBoolG(void *p1 UNUSED, bool p2 UNUSED) {
   5093 
   5094   return(false);
   5095 }
   5096 
   5097 bool notEqualDoubleG(void *p1 UNUSED, double p2 UNUSED) {
   5098 
   5099   return(false);
   5100 }
   5101 
   5102 bool notEqualOInt64G(void *p1 UNUSED, int64_t p2 UNUSED) {
   5103 
   5104   return(false);
   5105 }
   5106 
   5107 bool notEqualOInt32G(void *p1 UNUSED, int32_t p2 UNUSED) {
   5108 
   5109   return(false);
   5110 }
   5111 
   5112 bool notEqualOUint32G(void *p1 UNUSED, uint32_t p2 UNUSED) {
   5113 
   5114   return(false);
   5115 }
   5116 
   5117 bool notEqualOUint64G(void *p1 UNUSED, uint64_t p2 UNUSED) {
   5118 
   5119   return(false);
   5120 }
   5121 
   5122 
   5123 bool icEqCharChar(char c, char value) {
   5124 
   5125   return(tolower(c) == tolower(value));;
   5126 }
   5127 
   5128 bool icEqualChaOG(char c, baset* value) {
   5129 
   5130   charToS(s, c);
   5131   return(icEqualCharOG(s, value));
   5132 }
   5133 
   5134 bool icEqualChaSmallJsonG(char c, smallJsont* value) {
   5135 
   5136   // sanity checks
   5137   if (!value) {
   5138     return(false);
   5139   }
   5140 
   5141   if (checkObjectTypes && !isOSmallJson(value)) {
   5142     return(false);
   5143   }
   5144 
   5145   return(value->f->icEqualChar(value, c));
   5146 }
   5147 
   5148 bool icEqualChaSmallStringG(char c, smallStringt* value) {
   5149 
   5150   if (!value) {
   5151     return(false);
   5152   }
   5153   charToS(s, c);
   5154   return(icEqualSO(value, s));
   5155 }
   5156 
   5157 
   5158 bool icEqualCharOG(const char *s, baset* value) {
   5159 
   5160   if (!s || !value) {
   5161     return(false);
   5162   }
   5163 
   5164   char *v = toStringO(value);
   5165   bool r  = icEqS(s, v);
   5166   free(v);
   5167   return(r);
   5168 }
   5169 
   5170 bool icEqualCharPSmallJsonG(const char *s, smallJsont* value) {
   5171 
   5172   // sanity checks
   5173   if (!value) {
   5174     return(false);
   5175   }
   5176 
   5177   if (checkObjectTypes && !isOSmallJson(value)) {
   5178     return(false);
   5179   }
   5180 
   5181   return(value->f->icEqualS(value, s));
   5182 }
   5183 
   5184 bool icEqualCharPSmallStringG(const char *s, smallStringt* value) {
   5185 
   5186   if (!value) {
   5187     return(false);
   5188   }
   5189   return(icEqualSO(value, s));
   5190 }
   5191 
   5192 
   5193 bool icEqualArrayOG(char ** p1, baset* p2) {
   5194 
   5195   if (!p1 || !p2) {
   5196     return(false);
   5197   }
   5198 
   5199   if (!isOType(p2, "smallArray")) {
   5200     return(false);
   5201   }
   5202 
   5203   cast(smallArrayt *, arr, p2);
   5204 
   5205   if (!listLengthS(p1) || !lenO(arr)) {
   5206     return(false);
   5207   }
   5208 
   5209   // compare elements
   5210   // TODO compare any types of element, not only strings
   5211   enumerateSArray(arr->a, e, i) {
   5212     if (not e) {
   5213       return(false);
   5214     }
   5215     if (!icEqS(sStringGetTiny((sStringt*)e), p1[i])) {
   5216       return(false);
   5217   }
   5218     }
   5219 
   5220   return(true);
   5221 }
   5222 
   5223 bool icEqualCArrayOG(const char ** p1, baset* p2) {
   5224 
   5225   if (!p1 || !p2) {
   5226     return(false);
   5227   }
   5228 
   5229   if (!isOType(p2, "smallArray")) {
   5230     return(false);
   5231   }
   5232 
   5233   cast(smallArrayt *, arr, p2);
   5234 
   5235   if (!listLengthCS(p1) || !lenO(arr)) {
   5236     return(false);
   5237   }
   5238 
   5239   // compare elements
   5240   // TODO compare any types of element, not only strings
   5241   enumerateSArray(arr->a, e, i) {
   5242     if (not e) {
   5243       return(false);
   5244     }
   5245     if (!icEqS(sStringGetTiny((sStringt*)e), p1[i])) {
   5246       return(false);
   5247   }
   5248     }
   5249 
   5250   return(true);
   5251 }
   5252 
   5253 bool icEqualArraySmallJsonG(char ** p1, smallJsont* p2) {
   5254 
   5255   // sanity checks
   5256   if (!p2) {
   5257     return(false);
   5258   }
   5259 
   5260   if (checkObjectTypes && !isOSmallJson(p2)) {
   5261     return(false);
   5262   }
   5263 
   5264   const char *type = getTopTypeO(p2);
   5265 
   5266   if (!eqS(type,"array")) {
   5267     return(false);
   5268   }
   5269 
   5270   return(p2->f->icEqualArray(p2, p1));
   5271 }
   5272 
   5273 bool icEqualCArraySmallJsonG(const char ** p1, smallJsont* p2) {
   5274 
   5275   // sanity checks
   5276   if (!p2) {
   5277     return(false);
   5278   }
   5279 
   5280   if (checkObjectTypes && !isOSmallJson(p2)) {
   5281     return(false);
   5282   }
   5283 
   5284   const char *type = getTopTypeO(p2);
   5285 
   5286   if (!eqS(type,"array")) {
   5287     return(false);
   5288   }
   5289 
   5290   return(p2->f->icEqualCArray(p2, p1));
   5291 }
   5292 
   5293 bool icEqualArraySmallArrayG(char ** p1, smallArrayt* p2) {
   5294 
   5295   if (!p2) {
   5296     return(false);
   5297   }
   5298 
   5299   if (checkObjectTypes && !isOSmallArray(p2)) {
   5300     return(false);
   5301   }
   5302 
   5303   return(p2->f->icEqualArray(p2, p1));
   5304 }
   5305 
   5306 bool icEqualCArraySmallArrayG(const char ** p1, smallArrayt* p2) {
   5307 
   5308   if (!p2) {
   5309     return(false);
   5310   }
   5311 
   5312   if (checkObjectTypes && !isOSmallArray(p2)) {
   5313     return(false);
   5314   }
   5315 
   5316   return(p2->f->icEqualCArray(p2, p1));
   5317 }
   5318 
   5319 bool icEqualOCharG(baset* p1, const char * p2) {
   5320 
   5321   return(icEqualCharOG(p2, p1));
   5322 }
   5323 
   5324 bool icEqualOChaG(baset* p1, char p2) {
   5325 
   5326   return(icEqualChaOG(p2, p1));
   5327 }
   5328 
   5329 bool icEqualOArrayG(baset* p1, char ** p2) {
   5330 
   5331   return(icEqualArrayOG(p2, p1));
   5332 }
   5333 
   5334 bool icEqualOCArrayG(baset* p1, const char ** p2) {
   5335 
   5336   return(icEqualCArrayOG(p2, p1));
   5337 }
   5338 
   5339 bool icEqualOOG(baset* p1, baset* p2) {
   5340 
   5341   if (!p1 || !p2) {
   5342     return(false);
   5343   }
   5344 
   5345   char *s = toStringO(p1);
   5346   char *S = toStringO(p2);
   5347   bool r;
   5348   if (icEqS(s, S)) {
   5349     r = true;
   5350   }
   5351   else {
   5352     r = false;
   5353   }
   5354   freeManyS(s, S);
   5355   return(r);
   5356 }
   5357 
   5358 bool icEqualOSmallArrayG(baset* p1, smallArrayt* p2) {
   5359 
   5360   if (!p2) {
   5361     return(false);
   5362   }
   5363 
   5364   if (checkObjectTypes && !isOSmallArray(p2)) {
   5365     return(false);
   5366   }
   5367 
   5368   return(p2->f->icEqualBase(p2, p1));
   5369 }
   5370 
   5371 bool icEqualOSmallDictG(baset* p1, smallDictt* p2) {
   5372 
   5373   if (!p2) {
   5374     return(false);
   5375   }
   5376 
   5377   if (checkObjectTypes && !isOSmallDict(p2)) {
   5378     return(false);
   5379   }
   5380 
   5381   return(p2->f->icEqualBase(p2, p1));
   5382 }
   5383 
   5384 bool icEqualOSmallJsonG(baset* p1, smallJsont* p2) {
   5385 
   5386   // sanity checks
   5387   if (!p2) {
   5388     return(false);
   5389   }
   5390 
   5391   if (checkObjectTypes && !isOSmallJson(p2)) {
   5392     return(false);
   5393   }
   5394 
   5395   return(p2->f->icEqualBase(p2, p1));
   5396 }
   5397 
   5398 bool icEqualOSmallStringG(baset* p1, smallStringt* p2) {
   5399 
   5400   if (!p1 || !p2 || !p2->data) {
   5401     return(false);
   5402   }
   5403 
   5404   if (checkObjectTypes && !isOSmallString(p2)) {
   5405     return(false);
   5406   }
   5407 
   5408   char *s = toStringO(p1);
   5409 
   5410   bool r = icEqualSO(p2, s);
   5411   free(s);
   5412   return(r);
   5413 }
   5414 
   5415 
   5416 
   5417 // TODO format function, print objects, stderr print
   5418 
   5419 void freeBasetInContainer(void *baseo) {
   5420 
   5421   // Terminate baset object
   5422   cast(baset*,o,baseo);
   5423   terminateO(o);
   5424 }
   5425 
   5426 
   5427 smallt *toSmallt(baset *obj) {
   5428   smallt *r = NULL;
   5429 
   5430   if (!obj) {
   5431     return(NULL);
   5432   }
   5433 
   5434   if (isOType(obj, "undefined")) {
   5435     r      = (smallt *)allocSUndefined();
   5436   }
   5437   else if (isOType(obj, "smallArray")) {
   5438     if (!((smallArrayt *)obj)->a) {
   5439       ((smallArrayt *)obj)->a = allocSArray();
   5440     }
   5441     r = (smallt *)((smallArrayt *)obj)->a;
   5442   }
   5443   else if (isOType(obj, "smallDict")) {
   5444     if (!((smallDictt *)obj)->d) {
   5445       ((smallDictt *)obj)->d = allocSDict();
   5446     }
   5447     r = (smallt *)((smallDictt *)obj)->d;
   5448   }
   5449   else if (isOType(obj, "smallBool")) {
   5450     if (!((smallBoolt *)obj)->value) {
   5451       ((smallBoolt *)obj)->value = allocSBool(false);
   5452     }
   5453     r = (smallt *)((smallBoolt *)obj)->value;
   5454   }
   5455   else if (isOType(obj, "smallBytes")) {
   5456     if (!((smallBytest *)obj)->B) {
   5457       ((smallBytest *)obj)->B = allocSBytes();
   5458     }
   5459     r = (smallt *)((smallBytest *)obj)->B;
   5460   }
   5461   else if (isOType(obj, "smallContainer")) {
   5462     if (!((smallContainert *)obj)->data) {
   5463       ((smallContainert *)obj)->data = allocSContainer(NULL);
   5464     }
   5465     r = (smallt *)((smallContainert *)obj)->data;
   5466   }
   5467   else if (isOType(obj, "smallDouble")) {
   5468     if (!((smallDoublet *)obj)->value) {
   5469       ((smallDoublet *)obj)->value = allocSDouble(0);
   5470     }
   5471     r = (smallt *)((smallDoublet *)obj)->value;
   5472   }
   5473   else if (isOType(obj, "smallInt")) {
   5474     if (!((smallIntt *)obj)->value) {
   5475       ((smallIntt *)obj)->value = allocSInt(0);
   5476     }
   5477     r = (smallt *)((smallIntt *)obj)->value;
   5478   }
   5479   else if (isOType(obj, "smallString")) {
   5480     if (!((smallStringt *)obj)->data) {
   5481       ((smallStringt *)obj)->data = allocSStringTiny("");
   5482     }
   5483     r = (smallt *)((smallStringt *)obj)->data;
   5484   }
   5485   else {
   5486     // store other baset object in sContainers
   5487     sContainert *c = allocSContainer(obj);
   5488     if (!c) {
   5489       return(NULL);
   5490     }
   5491     c->dataType    = SH_DT_BASET;
   5492     c->free        = freeBasetInContainer;
   5493     r              = (smallt *) c;
   5494   }
   5495 
   5496   return(r);
   5497 }
   5498 
   5499 
   5500 baset *toBaset(smallt *obj) {
   5501   undefinedt *u = NULL;
   5502   smallBoolt *b = NULL;
   5503   smallBytest *B = NULL;
   5504   smallContainert *c = NULL;
   5505   smallDictt *d = NULL;
   5506   smallDoublet *D = NULL;
   5507   smallIntt *i = NULL;
   5508   smallStringt *s = NULL;
   5509   smallArrayt *a = NULL;
   5510   baset *r = NULL;
   5511 
   5512   if (!obj) {
   5513     return(NULL);
   5514   }
   5515 
   5516   switch(obj->type) {
   5517     case UNDEFINED:
   5518       initiateAllocateUndefined(&u);
   5519       r = (baset *)u;
   5520       break;
   5521     case BOOL:
   5522       initiateAllocateSmallBool(&b);
   5523       if (!b) {
   5524         return(NULL);
   5525       }
   5526       b->value = (sBoolt *)obj;
   5527       r = (baset *)b;
   5528       break;
   5529     case BYTES:
   5530       initiateAllocateSmallBytes(&B);
   5531       if (!B) {
   5532         return(NULL);
   5533       }
   5534       B->B = (sBytest *)obj;
   5535       r = (baset *)B;
   5536       break;
   5537     case CONTAINER:
   5538       ;cast(sContainert*, sc, obj);
   5539       if (sc->dataType == SH_DT_BASET) {
   5540         r = (baset *)sc->data;
   5541       }
   5542       else {
   5543         initiateAllocateSmallContainer(&c);
   5544         if (!c) {
   5545           return(NULL);
   5546         }
   5547         c->data = (sContainert *)obj;
   5548         r = (baset *)c;
   5549       }
   5550       break;
   5551     case DICT:
   5552       initiateAllocateSmallDict(&d);
   5553       if (!d) {
   5554         return(NULL);
   5555       }
   5556       d->d = (sDictt *)obj;
   5557       r = (baset *)d;
   5558       break;
   5559     case DOUBLE:
   5560       initiateAllocateSmallDouble(&D);
   5561       if (!D) {
   5562         return(NULL);
   5563       }
   5564       D->value = (sDoublet *)obj;
   5565       r = (baset *)D;
   5566       break;
   5567     case INT:
   5568       initiateAllocateSmallInt(&i);
   5569       if (!i) {
   5570         return(NULL);
   5571       }
   5572       i->value = (sIntt *)obj;
   5573       r = (baset *)i;
   5574       break;
   5575     case STRING:
   5576       initiateAllocateSmallString(&s);
   5577       if (!s) {
   5578         return(NULL);
   5579       }
   5580       s->data = (sStringt *)obj;
   5581       s->_len = strlen((char*)obj)-1;
   5582       r = (baset *)s;
   5583       break;
   5584     case ARRAY:
   5585       initiateAllocateSmallArray(&a);
   5586       if (!a) {
   5587         return(NULL);
   5588       }
   5589       a->a = (sArrayt *)obj;
   5590       r = (baset *)a;
   5591       break;
   5592     default:;
   5593       // return NULL
   5594   }
   5595   return(r);
   5596 }
   5597 
   5598 int cpuCount(void) {
   5599 
   5600   return((int)sysconf(_SC_NPROCESSORS_ONLN));
   5601 }
   5602 
   5603 dArrayT(finalizeRecycleContainersFuncst, recycleContainersFt);
   5604 
   5605 internal finalizeRecycleContainersFuncst finalizeRecycleContainersFuncs;
   5606 
   5607 unsigned registerFinalizeRecycleContainersInThreadPool(recycleContainersFt f) {
   5608 
   5609   dArrayAppend(&finalizeRecycleContainersFuncs, f);
   5610   return(1);
   5611 }
   5612 
   5613 void finalizeLibsheepyRecycleContainers(void *arg UNUSED) {
   5614 
   5615   // call finalizeRecycleSmall*
   5616   range(i, dArrayCount(&finalizeRecycleContainersFuncs)) {
   5617     dArrayAt(&finalizeRecycleContainersFuncs, i)(NULL);
   5618   }
   5619 }
   5620 
   5621 void finalizeLibsheepyAtExit(void) {
   5622 
   5623   tpoolKill;
   5624 
   5625   dArrayFree(&finalizeRecycleContainersFuncs);
   5626 
   5627   finalizeSmallDict();
   5628   finalizeSmallArray();
   5629   finalizeSmallJson();
   5630   finalizeUndefined();
   5631   finalizeSmallBytes();
   5632   finalizeSmallBool();
   5633   finalizeSmallContainer();
   5634   finalizeSmallDouble();
   5635   finalizeSmallInt();
   5636   finalizeSmallString();
   5637 }
   5638 
   5639 #if (__APPLE__ || __FreeBSD__ || __TERMUX__ || __OpenBSD__ || __DragonFly__ || MUSL_LIBC || __sun__ || __HAIKU__)
   5640 void initLibsheepyObject(void) {
   5641 
   5642   dArrayInit(&finalizeRecycleContainersFuncs);
   5643   registerFinalizeRecycleContainersInThreadPool(finalizeRecycleSmallArray);
   5644   registerFinalizeRecycleContainersInThreadPool(finalizeRecycleSmallBool);
   5645   registerFinalizeRecycleContainersInThreadPool(finalizeRecycleSmallBytes);
   5646   registerFinalizeRecycleContainersInThreadPool(finalizeRecycleSmallContainer);
   5647   registerFinalizeRecycleContainersInThreadPool(finalizeRecycleSmallDict);
   5648   registerFinalizeRecycleContainersInThreadPool(finalizeRecycleSmallDouble);
   5649   registerFinalizeRecycleContainersInThreadPool(finalizeRecycleSmallInt);
   5650   registerFinalizeRecycleContainersInThreadPool(finalizeRecycleSmallJson);
   5651   registerFinalizeRecycleContainersInThreadPool(finalizeRecycleSmallString);
   5652   registerFinalizeRecycleContainersInThreadPool(finalizeRecycleUndefined);
   5653 
   5654   int numberOfOnlineProcs = (int)sysconf(_SC_NPROCESSORS_ONLN);
   5655   tpool = tpool_init(numberOfOnlineProcs);
   5656 
   5657   pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
   5658   range(i, tpoolLockCount) {
   5659     tpoolLocks[i] = mutex;
   5660   }
   5661 
   5662   // register %m type specifiers in printf for baset objects
   5663   // not available in macos - register_printf_specifier('m', print_m, print_m_arginfo);
   5664 
   5665   // call finalizeLibsheepy when the program finishes
   5666   pErrorNot0(atexit(finalizeLibsheepyAtExit));
   5667 }
   5668 
   5669 #else // #if (__APPLE__ || __FreeBSD__ || __TERMUX__ || __OpenBSD__ || __DragonFly__ || MUSL_LIBC || __sun__ || __HAIKU__)
   5670 void initLibsheepyObject(void) {
   5671 
   5672   initLibsheepyObjectWithoutTpool();
   5673 
   5674   int numberOfOnlineProcs = (int)sysconf(_SC_NPROCESSORS_ONLN);
   5675   tpool = tpool_init(numberOfOnlineProcs);
   5676 
   5677   pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
   5678   range(i, tpoolLockCount) {
   5679     tpoolLocks[i] = mutex;
   5680   }
   5681 }
   5682 
   5683 void initLibsheepyObjectWithoutTpool(void) {
   5684 
   5685   dArrayInit(&finalizeRecycleContainersFuncs);
   5686   registerFinalizeRecycleContainersInThreadPool(finalizeRecycleSmallArray);
   5687   registerFinalizeRecycleContainersInThreadPool(finalizeRecycleSmallBool);
   5688   registerFinalizeRecycleContainersInThreadPool(finalizeRecycleSmallBytes);
   5689   registerFinalizeRecycleContainersInThreadPool(finalizeRecycleSmallContainer);
   5690   registerFinalizeRecycleContainersInThreadPool(finalizeRecycleSmallDict);
   5691   registerFinalizeRecycleContainersInThreadPool(finalizeRecycleSmallDouble);
   5692   registerFinalizeRecycleContainersInThreadPool(finalizeRecycleSmallInt);
   5693   registerFinalizeRecycleContainersInThreadPool(finalizeRecycleSmallJson);
   5694   registerFinalizeRecycleContainersInThreadPool(finalizeRecycleSmallString);
   5695   registerFinalizeRecycleContainersInThreadPool(finalizeRecycleUndefined);
   5696 
   5697   // register %m type specifiers in printf for baset objects
   5698   register_printf_specifier('m', print_m, print_m_arginfo); {
   5699 
   5700   // call finalizeLibsheepy when the program finishes
   5701   pErrorNot0(atexit(finalizeLibsheepyAtExit));
   5702 }
   5703   }
   5704 
   5705 #endif
   5706 // #if __APPLE__ || __FreeBSD__ || __TERMUX__ || __OpenBSD__ || __DragonFly__ || MUSL_LIBC || __sun__ || __HAIKU__
   5707 
   5708 /**
   5709  * undefined/null object for setting undefined/null in small data structures
   5710  * pushG(a, undefined);
   5711  */
   5712 undefinedt* undefined = NULL;
   5713 
   5714 /**
   5715  * Generic return types
   5716  * getG(dict, rtBool, "a");
   5717  */
   5718 baset* rtBaset                     = NULL;
   5719 undefinedt* rtUndefinedt           = NULL;
   5720 bool rtBool                        = false;
   5721 bool* rtBoolP                      = NULL;
   5722 double rtDouble                    = 0;
   5723 double* rtDoubleP                  = NULL;
   5724 int64_t rtInt64_t                  = 0;
   5725 int64_t* rtInt64_tP                = NULL;
   5726 int32_t rtInt32_t                  = 0;
   5727 int32_t* rtInt32_tP                = NULL;
   5728 uint64_t rtUint64_t                = 0;
   5729 uint64_t* rtUint64_tP              = NULL;
   5730 uint32_t rtUint32_t                = 0;
   5731 uint32_t* rtUint32_tP              = NULL;
   5732 float rtF32                        = 0;
   5733 double rtF64                       = 0;
   5734 double* rtF64P                     = NULL;
   5735 int64_t rtI64                      = 0;
   5736 int64_t* rtI64P                    = NULL;
   5737 int32_t rtI32                      = 0;
   5738 int32_t* rtI32P                    = NULL;
   5739 uint64_t rtU64                     = 0;
   5740 uint64_t* rtU64P                   = NULL;
   5741 uint32_t rtU32                     = 0;
   5742 uint32_t* rtU32P                   = NULL;
   5743 uint16_t rtU16                     = 0;
   5744 uint8_t rtU8                       = 0;
   5745 char* rtChar                       = NULL;
   5746 smallArrayt* rtSmallArrayt         = NULL;
   5747 smallBoolt* rtSmallBoolt           = NULL;
   5748 smallBytest* rtSmallBytest         = NULL;
   5749 smallDictt* rtSmallDictt           = NULL;
   5750 smallDoublet* rtSmallDoublet       = NULL;
   5751 smallIntt* rtSmallIntt             = NULL;
   5752 smallJsont* rtSmallJsont           = NULL;
   5753 smallStringt* rtSmallStringt       = NULL;
   5754 void* rtVoid                       = NULL;
   5755 smallContainert* rtSmallContainert = NULL;