31 #include <sys/types.h> 39 #if !defined(__arm__) && !defined(__aarch64__) 40 #include <immintrin.h> 41 #endif // #if !defined(__arm__) && !defined(__aarch64__) 101 #define LIBSHEEPY_VERSION "2.2.12.1" 104 #define SH_PREFIX(NAME) NAME 110 #define internal static 116 #define var __auto_type 120 extern const bool TRUE;
123 extern const bool FALSE;
133 #define boolS(x) x ? "TRUE" : "FALSE" 138 #define XSUCCESS exit(EXIT_SUCCESS); 139 #define XSuccess XSUCCESS 144 #define XFAILURE exit(EXIT_FAILURE); 145 #define XFailure XFAILURE 152 #define logXSuccess(string) MACRO(\ 153 logP("Success: %s", string);\ 164 #define logXSuccessf(format, ...) MACRO(\ 165 logP(format, __VA_ARGS__);\ 174 #define logXFailure(string) MACRO(\ 175 logC("Failed: %s", string);\ 186 #define logXFailuref(format, ...) MACRO(\ 187 logC(format, __VA_ARGS__);\ 196 #define logExit(exitCode, string) MACRO (\ 197 logI("Exit: %s", string);\ 206 #define exitFailure(cond) \ 233 #define procbegin do{ 234 #define procend }while(0) 243 #define MACRO( STATEMENTS ) do { STATEMENTS } while(0) 253 #define FUNC( STATEMENTS) ({ STATEMENTS }) 282 #define stringifyExpr(expr) stringifyExpr1(expr) 284 #define stringifyExpr1(expr) #expr 291 #define libsheepyErrorMask 0x8000000000000000UL 293 #define disableLibsheepyErrorLogs do{logMask &= (~libsheepyErrorMask);}while(0) 295 #define shperror(string) procbegin\ 296 char *errstr = strerror(errno);\ 297 logE("%s: %s", string, errstr);\ 306 #define pFuncError do{ if ((libsheepyErrorMask) & logMask) { shperror(__func__);logEBtrace;} }while(0); 311 #define pStrError(str) do{ if ((libsheepyErrorMask) & logMask) { shperror(str);logEBtrace;} }while(0); 319 #define shPrintError do{ if ((libsheepyErrorMask) & logMask) { logE("Error line "stringifyExpr(__LINE__)", function %s, file "__FILE__"\n", __func__); logEBtrace;} }while(0); 324 #define pError(func) if (func == -1) shPrintError 329 #define pError0(func) if (func == 0) shPrintError 334 #define pErrorNot0(func) if (func != 0) shPrintError 339 #define pErrorNULL(func) if (func == NULL) shPrintError 344 #define pErrorValue(func, errorValue) if (func == errorValue) shPrintError 349 #define pTestError(test) if (test) shPrintError 354 #define pTestErrorCmd(test, cmd) if (test) { shPrintError cmd; } 359 #define pErrorCmd(func, test, cmd) if (func test) { shPrintError cmd; } 367 #define pErrorResult(result, func, test) if ((result = func) test) shPrintError 375 #define pErrorResultCmd(result, func, test, cmd) if ((result = func) test) { shPrintError cmd; } 386 #define isError(assigned, left) if (!(assigned = left)) 391 #define maxTryThrowCount 16 397 #define setJump(slot) setjmp(tryJumpBuffers[slot]) 414 #define try(slot) if (!setjmp(tryJumpBuffers[slot])) 419 #define throw(slot) longjmp(tryJumpBuffers[slot], 1) 428 #define tryV(result, slot) if (!(result = setjmp(tryJumpBuffers[slot]))) 433 #define throwV(slot, value) longjmp(tryJumpBuffers[slot], value) 436 #define goNLabel(go, label) goto go; label: 455 #define I8(value) (i8)(value) 456 #define I16(value) (i16)(value) 457 #define I32(value) (i32)(value) 458 #define I64(value) (i64)(value) 459 #define U8(value) (u8)(value) 460 #define U16(value) (u16)(value) 461 #define U32(value) (u32)(value) 462 #define U64(value) (u64)(value) 463 #define F32(value) (f32)(value) 464 #define F64(value) (f64)(value) 466 #define MAX(a, b) (((a) > (b)) ? (a) : (b)) 467 #define MIN(a, b) (((a) < (b)) ? (a) : (b)) 468 #define MIN3(a, b, c) MIN((typeof(a))MIN(a, b), c) 469 #define MAX3(a, b, c) MAX((typeof(a))MAX(a, b), c) 470 #define ABS(a) (((a) < 0) ? -(a) : (a)) 471 #define CLAMP(x, low, high) (((x) > (high)) ? (high) : (((x) < (low)) ? (low) : (x))) 472 #define COUNT_ELEMENTS(arr) (sizeof (arr) / sizeof ((arr)[0])) 473 #define ARRAY_SIZE COUNT_ELEMENTS 478 #define EXTRACT(x, msb, lsb) ((~(0xFFFFFFFFFFFFFFFEUL << (msb)) & (x)) >> (lsb)) 489 #define CMP(a, b) ({\ 490 var UNIQVAR(_a) = a;\ 491 var UNIQVAR(_b) = b;\ 492 UNIQVAR(_a) > UNIQVAR(_b) ? 1 : UNIQVAR(_a) < UNIQVAR(_b) ? -1 : 0;\ 506 #define ZEROVAR(name) zeroBuf(&(name), sizeof(name)) 519 #define BUCKETS(count, divider) ((count)/(divider) + (((count) % (divider)) ? 1 : 0)) 524 #define swapV(a, b) do{\ 525 var UNIQVAR(swaptmp) = a;\ 527 b = UNIQVAR(swaptmp);\ 531 #define setMax(result, a, b) do{\ 532 var UNIQVAR(_a) = a;\ 533 var UNIQVAR(_b) = b;\ 534 result = MAX(UNIQVAR(_a), UNIQVAR(_b));\ 538 #define setMin(result, a, b) do{\ 539 var UNIQVAR(_a) = a;\ 540 var UNIQVAR(_b) = b;\ 541 result = MIN(UNIQVAR(_a), UNIQVAR(_b));\ 545 #define maxV(a, b) ({\ 546 var UNIQVAR(_a) = a;\ 547 var UNIQVAR(_b) = b;\ 548 MAX(UNIQVAR(_a), UNIQVAR(_b));\ 552 #define minV(a, b) ({\ 553 var UNIQVAR(_a) = a;\ 554 var UNIQVAR(_b) = b;\ 555 MIN(UNIQVAR(_a), UNIQVAR(_b));\ 559 #define absV(a) ({var UNIQVAR(_a) = a; ((UNIQVAR(_a)) < 0) ? -(UNIQVAR(_a)) : (UNIQVAR(_a));}) 568 #define FIELD_SIZEOF(t, f) (sizeof(((t*)0)->f)) 571 #define isIntOdd(value) (value&1) 574 #define isIntEven(value) (!(value&1)) 599 #define unless(cond) if(not(cond)) 611 #define until(cond) while(not(cond)) 617 #define cast(type, casted, toCast) type casted = (type) (toCast); 622 #define freen(ptr) do {\ 642 #define EVA(var, func) (var = func, var) 661 #define loopBreakerInit\ 662 uint32_t libsheepyLoopCounter = 0;\ 663 bool didBreak = false; 668 #define loopBreakerReset\ 669 libsheepyLoopCounter = 0;\ 675 #define loopBreaker(breakCount)\ 676 libsheepyLoopCounter++;\ 677 if(libsheepyLoopCounter>breakCount){didBreak=true;break;} 684 #define FILE_LINE __FILE__":"stringifyExpr(__LINE__) 685 #define PFILE_LINE puts(FILE_LINE) 694 #define AT pLog(LOG_DEBUG, __FILE__", %s:"stringifyExpr(__LINE__)"\n",__func__); 699 #define TODO(message) logD(BLD MGT BGBLK"TODO"RST BLD MGT": "message RST) 703 #define TOKENPASTE2(a, b) a ## b 704 #define TOKENPASTE(a, b) TOKENPASTE2(a, b) 705 #define UNIQVAR(name) TOKENPASTE(name, __LINE__) 714 #define cleanCharP(name) char *name CLEANUP(cleanUpCharFree) 722 #define cleanListP(name) char **name CLEANUP(cleanUpListFree) 730 #define cleanFileP(name) FILE *name CLEANUP(cleanUpFileFree) 738 #define cleanFd(name) int name CLEANUP(cleanUpFd) 739 #define cleanFdInit(name) int name CLEANUP(cleanUpFd) = -1 748 #define logVar(var, format) logD("%s=%" format, stringifyExpr(var), var); 749 #define logMVar(mask, var, format) logMD(mask, "%s=%" format, stringifyExpr(var), var); 752 #define logBoolVar(var) logVar(var, "b"); 753 #define logMBoolVar(mask, var) logMVar(mask, var, "b"); 758 #define logPtr(pointer) logD("%s=%p", stringifyExpr(pointer), pointer); 759 #define logMPtr(mask, pointer) logMD(mask, "%s=%p", stringifyExpr(pointer), pointer); 763 #define RST "\x1B[0m" 765 #define BLD "\x1B[1m" 767 #define FNT "\x1B[2m" 769 #define ITL "\x1B[3m" 771 #define UDL "\x1B[4m" 773 #define BLI "\x1B[5m" 775 #define INV "\x1B[7m" 777 #define COC "\x1B[8m" 779 #define CRD "\x1B[9m" 783 #define BLK "\x1B[30m" 785 #define RED "\x1B[31m" 787 #define GRN "\x1B[32m" 789 #define YLW "\x1B[33m" 791 #define BLU "\x1B[34m" 793 #define MGT "\x1B[35m" 795 #define CYN "\x1B[36m" 797 #define WHT "\x1B[37m" 801 #define BGBLK "\x1B[40m" 803 #define BGRED "\x1B[41m" 805 #define BGGRN "\x1B[42m" 807 #define BGYLW "\x1B[43m" 809 #define BGBLU "\x1B[44m" 811 #define BGMGT "\x1B[45m" 813 #define BGCYN "\x1B[46m" 815 #define BGWHT "\x1B[47m" 818 #define sheepyRGBFP len = fprintf(stream, "%*s", (int)(info->left ? -info->width : info->width), b) 819 #define sheepyBOOLFP len = fprintf(stream, "%*s", (int)(info->left ? -info->width : info->width), boolS(value)) 827 #define timeNs(func) do{\ 828 u64 UNIQVAR(endTime);\ 829 u64 UNIQVAR(startTime) = getMonotonicTime();\ 831 UNIQVAR(endTime) = getMonotonicTime();\ 832 printf(BLD GRN "time" RST ": %" PRIu64 "ns " BLD UDL YLW "%s" RST "\n", UNIQVAR(endTime)-UNIQVAR(startTime), stringifyExpr(func));\ 835 #define TIMEUNITUS "us" 836 #define TIMEUNITMS "ms" 837 #define TIMEUNITSC "s" 845 #define timeDivs(func, div, timeunit) do{\ 846 u64 UNIQVAR(endTime);\ 847 u64 UNIQVAR(startTime) = getMonotonicTime();\ 849 UNIQVAR(endTime) = getMonotonicTime();\ 850 printf(BLD GRN "time:" RST " %f"timeunit" " BLD UDL YLW "%s" RST "\n", (f32)(UNIQVAR(endTime)-UNIQVAR(startTime))/div, stringifyExpr(func));\ 859 #define timeUs(func) timeDivs(func,1E3, TIMEUNITUS) 867 #define timeMs(func) timeDivs(func,1E6, TIMEUNITMS) 875 #define timeSec(func) timeDivs(func,1E9, TIMEUNITSC) 880 #define stopwatchStart shStopwatch(0) 885 #define stopwatchLog printf(BLD GRN "time" RST ": %" PRIu64 "ns\n", shStopwatch(1)) 890 #define stopwatchLogDivs(div, timeunit) printf(BLD GRN "time" RST ": %f"timeunit"\n", ((float)shStopwatch(1))/div) 895 #define stopwatchLogUs stopwatchLogDivs(1E3, TIMEUNITUS) 900 #define stopwatchLogMs stopwatchLogDivs(1E6, TIMEUNITMS) 905 #define stopwatchLogSec stopwatchLogDivs(1E9, TIMEUNITSC) 912 #define LOG_EMERGENCY 0 914 #define LOG_CRITICAL 2 917 #undef LOG_WARNING // conflict with syslog.h 919 #define LOG_WARNING 4 923 #undef LOG_INFO // conflict with syslog.h 927 #define LOG_INVALID 9 928 #define LOG_MAX_LEVEL LOG_INVALID 931 #define LOG_DISABLE -1 941 #define LOG_VERBOSE 0 946 #define LOG_CONCISE 1 951 #define LOG_DATE 2 // default 966 #define LOG_PROGNDATE 5 981 #define LOG_PROGNFUNC 8 986 #define LOG_INVALID_MODE 9 990 #define openLogFile setLogFile 997 #define MUST_CHECK __attribute__ ((warn_unused_result)) 1053 #define pLog(level, ...) _pLog(level, __FILE__, __func__, __LINE__, __VA_ARGS__); 1055 void _pLog(
int,
const char *,
const char *,
int,
const char *, ...);
1057 #define logY(...) pLog(LOG_EMERGENCY, __VA_ARGS__) 1058 #define logA(...) pLog(LOG_ALERT, __VA_ARGS__) 1059 #define logC(...) pLog(LOG_CRITICAL, __VA_ARGS__) 1060 #define logE(...) pLog(LOG_ERROR, __VA_ARGS__) 1061 #define logW(...) pLog(LOG_WARNING, __VA_ARGS__) 1062 #define logN(...) pLog(LOG_NOTICE, __VA_ARGS__) 1063 #define logP(...) pLog(LOG_PASS, __VA_ARGS__) 1064 #define logI(...) pLog(LOG_INFO, __VA_ARGS__) 1065 #define logD(...) pLog(LOG_DEBUG, __VA_ARGS__) 1072 #define logSY(format, string) do {\ 1073 char *libsheepyInternalString = string;\ 1074 logY(format, libsheepyInternalString);\ 1075 free(libsheepyInternalString);\ 1083 #define logSA(format, string) do {\ 1084 char *libsheepyInternalString = string;\ 1085 logA(format, libsheepyInternalString);\ 1086 free(libsheepyInternalString);\ 1094 #define logSC(format, string) do {\ 1095 char *libsheepyInternalString = string;\ 1096 logC(format, libsheepyInternalString);\ 1097 free(libsheepyInternalString);\ 1105 #define logSE(format, string) do {\ 1106 char *libsheepyInternalString = string;\ 1107 logE(format, libsheepyInternalString);\ 1108 free(libsheepyInternalString);\ 1116 #define logSW(format, string) do {\ 1117 char *libsheepyInternalString = string;\ 1118 logW(format, libsheepyInternalString);\ 1119 free(libsheepyInternalString);\ 1127 #define logSN(format, string) do {\ 1128 char *libsheepyInternalString = string;\ 1129 logN(format, libsheepyInternalString);\ 1130 free(libsheepyInternalString);\ 1138 #define logSP(format, string) do {\ 1139 char *libsheepyInternalString = string;\ 1140 logP(format, libsheepyInternalString);\ 1141 free(libsheepyInternalString);\ 1149 #define logSI(format, string) do {\ 1150 char *libsheepyInternalString = string;\ 1151 logI(format, libsheepyInternalString);\ 1152 free(libsheepyInternalString);\ 1160 #define logSD(format, string) do {\ 1161 char *libsheepyInternalString = string;\ 1162 logD(format, libsheepyInternalString);\ 1163 free(libsheepyInternalString);\ 1200 #define pLogMask(mask, level, ...) if ((mask) & logMask) pLog(level, __VA_ARGS__) 1202 #define logMY(mask, ...) pLogMask(mask, LOG_EMERGENCY, __VA_ARGS__) 1203 #define logMA(mask, ...) pLogMask(mask, LOG_ALERT, __VA_ARGS__) 1204 #define logMC(mask, ...) pLogMask(mask, LOG_CRITICAL, __VA_ARGS__) 1205 #define logME(mask, ...) pLogMask(mask, LOG_ERROR, __VA_ARGS__) 1206 #define logMW(mask, ...) pLogMask(mask, LOG_WARNING, __VA_ARGS__) 1207 #define logMN(mask, ...) pLogMask(mask, LOG_NOTICE, __VA_ARGS__) 1208 #define logMP(mask, ...) pLogMask(mask, LOG_PASS, __VA_ARGS__) 1209 #define logMI(mask, ...) pLogMask(mask, LOG_INFO, __VA_ARGS__) 1210 #define logMD(mask, ...) pLogMask(mask, LOG_DEBUG, __VA_ARGS__) 1213 #define showLogsInMask(mask) logMask |= mask 1216 #define hideLogsInMask(mask) logMask &= ~(mask) 1223 #define logSMY(mask, format, string) do {\ 1224 char *libsheepyInternalString = string;\ 1225 logMY(mask, format, libsheepyInternalString);\ 1226 free(libsheepyInternalString);\ 1234 #define logSMA(mask, format, string) do {\ 1235 char *libsheepyInternalString = string;\ 1236 logMA(mask, format, libsheepyInternalString);\ 1237 free(libsheepyInternalString);\ 1245 #define logSMC(mask, format, string) do {\ 1246 char *libsheepyInternalString = string;\ 1247 logMC(mask, format, libsheepyInternalString);\ 1248 free(libsheepyInternalString);\ 1256 #define logSME(mask, format, string) do {\ 1257 char *libsheepyInternalString = string;\ 1258 logME(mask, format, libsheepyInternalString);\ 1259 free(libsheepyInternalString);\ 1267 #define logSMW(mask, format, string) do {\ 1268 char *libsheepyInternalString = string;\ 1269 logMW(mask, format, libsheepyInternalString);\ 1270 free(libsheepyInternalString);\ 1278 #define logSMN(mask, format, string) do {\ 1279 char *libsheepyInternalString = string;\ 1280 logMN(mask, format, libsheepyInternalString);\ 1281 free(libsheepyInternalString);\ 1289 #define logSMP(mask, format, string) do {\ 1290 char *libsheepyInternalString = string;\ 1291 logMP(mask, format, libsheepyInternalString);\ 1292 free(libsheepyInternalString);\ 1300 #define logSMI(mask, format, string) do {\ 1301 char *libsheepyInternalString = string;\ 1302 logMI(mask, format, libsheepyInternalString);\ 1303 free(libsheepyInternalString);\ 1311 #define logSMD(mask, format, string) do {\ 1312 char *libsheepyInternalString = string;\ 1313 logMD(mask, format, libsheepyInternalString);\ 1314 free(libsheepyInternalString);\ 1386 #define Q_SORT3(q_a1, q_a2, q_a3, Q_LESS, Q_SWAP) do {\ 1387 if (Q_LESS(q_a2, q_a1)) {\ 1388 if (Q_LESS(q_a3, q_a2))\ 1389 Q_SWAP(q_a1, q_a3);\ 1391 Q_SWAP(q_a1, q_a2);\ 1392 if (Q_LESS(q_a3, q_a2))\ 1393 Q_SWAP(q_a2, q_a3);\ 1396 else if (Q_LESS(q_a3, q_a2)) {\ 1397 Q_SWAP(q_a2, q_a3);\ 1398 if (Q_LESS(q_a2, q_a1))\ 1399 Q_SWAP(q_a1, q_a2); \ 1406 #define Q_PARTITION(q_l, q_r, q_i, q_j, Q_UINT, Q_LESS, Q_SWAP) do {\ 1408 Q_UINT UNIQVAR(q_m) = q_l + ((q_r - q_l) >> 1);\ 1415 Q_SORT3(q_l + 1, UNIQVAR(q_m), q_r, Q_LESS, Q_SWAP);\ 1417 Q_SWAP(q_l, UNIQVAR(q_m));\ 1421 q_i = q_l + 1; q_j = q_r;\ 1423 do q_i++; while (Q_LESS(q_i, q_l));\ 1424 do q_j--; while (Q_LESS(q_l, q_j));\ 1425 if (q_i >= q_j) break; \ 1443 #define Q_INSERTION_SORT(q_l, q_r, Q_UINT, Q_LESS, Q_SWAP) do {\ 1444 Q_UINT UNIQVAR(q_i), UNIQVAR(q_j);\ 1446 for (UNIQVAR(q_i) = q_l + 1; UNIQVAR(q_i) <= q_r; UNIQVAR(q_i)++)\ 1448 for (UNIQVAR(q_j) = UNIQVAR(q_i); UNIQVAR(q_j) > q_l && (Q_LESS(UNIQVAR(q_j), UNIQVAR(q_j) - 1)); UNIQVAR(q_j)--)\ 1449 Q_SWAP(UNIQVAR(q_j), UNIQVAR(q_j) - 1);\ 1460 #define Q_LOOP(Q_UINT, Q_N, Q_LESS, Q_SWAP) do {\ 1461 Q_UINT UNIQVAR(q_l) = 0;\ 1462 Q_UINT UNIQVAR(q_r) = (Q_N) - 1;\ 1463 Q_UINT UNIQVAR(q_sp) = 0; \ 1464 struct { Q_UINT q_l, q_r; }\ 1469 UNIQVAR(q_st)[sizeof(Q_UINT) > 4 && sizeof(Q_N) > 4 ? 48 : 32];\ 1471 if (UNIQVAR(q_r) - UNIQVAR(q_l) + 1 >= Q_THRESH) {\ 1472 Q_UINT UNIQVAR(q_i), UNIQVAR(q_j);\ 1473 Q_PARTITION(UNIQVAR(q_l), UNIQVAR(q_r), UNIQVAR(q_i), UNIQVAR(q_j), Q_UINT, Q_LESS, Q_SWAP);\ 1476 if (UNIQVAR(q_j) - UNIQVAR(q_l) >= UNIQVAR(q_r) - UNIQVAR(q_i))\ 1477 Q_SUBFILES(UNIQVAR(q_l), UNIQVAR(q_j), UNIQVAR(q_i), UNIQVAR(q_r));\ 1479 Q_SUBFILES(UNIQVAR(q_i), UNIQVAR(q_r), UNIQVAR(q_l), UNIQVAR(q_j));\ 1482 Q_INSERTION_SORT(UNIQVAR(q_l), UNIQVAR(q_r), Q_UINT, Q_LESS, Q_SWAP);\ 1484 if (UNIQVAR(q_sp) == 0) break;\ 1486 UNIQVAR(q_l) = UNIQVAR(q_st)[UNIQVAR(q_sp)].q_l;\ 1487 UNIQVAR(q_r) = UNIQVAR(q_st)[UNIQVAR(q_sp)].q_r;\ 1494 #define Q_SUBFILES(q_l1, q_r1, q_l2, q_r2) do {\ 1499 if (q_l2 == q_r2) {\ 1500 UNIQVAR(q_l) = q_l1;\ 1501 UNIQVAR(q_r) = q_r1;\ 1506 UNIQVAR(q_st)[UNIQVAR(q_sp)].q_l = q_l1;\ 1507 UNIQVAR(q_st)[UNIQVAR(q_sp)].q_r = q_r1;\ 1510 UNIQVAR(q_l) = q_l2;\ 1511 UNIQVAR(q_r) = q_r2;\ 1516 #define QSORT(Q_N, Q_LESS, Q_SWAP) do {\ 1518 if (sizeof(Q_N) == sizeof(unsigned long)) {\ 1519 Q_LOOP(unsigned long, Q_N, Q_LESS, Q_SWAP);}\ 1520 else if (sizeof(Q_N) <= sizeof(unsigned)) {\ 1521 Q_LOOP(unsigned, Q_N, Q_LESS, Q_SWAP);}\ 1555 #define BSEARCH(RESULT_INDEX, SEARCH_ELEMENT, B_N, B_LESS, B_EQUAL) do {\ 1556 ssize_t UNIQVAR(b_first) = 0, UNIQVAR(b_middle), UNIQVAR(b_last);\ 1557 UNIQVAR(b_last) = B_N-1;\ 1558 while (UNIQVAR(b_first) <= UNIQVAR(b_last)) {\ 1559 UNIQVAR(b_middle) = (UNIQVAR(b_first)+UNIQVAR(b_last))/2;\ 1560 if (B_LESS(UNIQVAR(b_middle), SEARCH_ELEMENT)) UNIQVAR(b_first) = UNIQVAR(b_middle) + 1;\ 1561 else if (B_EQUAL(UNIQVAR(b_middle), SEARCH_ELEMENT)) {\ 1562 RESULT_INDEX = UNIQVAR(b_middle);\ 1565 else UNIQVAR(b_last) = UNIQVAR(b_middle) -1;\ 1578 #define libsheepyPrealloc (1024*1024) 1579 #define makeRoom(length, alloc, addlength) funcbegin\ 1581 typeof(alloc) newlen = (length) + (addlength);\ 1582 if (newlen < (alloc)) {\ 1586 if (newlen < libsheepyPrealloc) {\ 1590 r = newlen + libsheepyPrealloc;\ 1599 #define initLibsheepy(progPath) initLibsheepyF(progPath, NULL) 1635 #define systemNFree(command) systemNFreeF(command, __LINE__, __func__, __FILE__) 1732 #define isPath fileExists 1752 #define readFileS readFileToS 1753 #define bReadFileS bReadFileToS 1754 #define bLReadFileS bLReadFileToS 1755 #define readStreamS readStreamToS 1756 #define bReadStreamS bReadStreamToS 1757 #define bLReadStreamS bLReadStreamToS 1862 #define charToS(dst, c) \ 1863 ;char dst[2] = {c, 0} 1867 #define freeManyS(...) freeManySF("", __VA_ARGS__, NULL) 1882 void loghex(
const void *buf,
size_t len);
1894 #define put puts(""); 1900 char *
strNCpy(
char *restrict dst,
const char *restrict src,
size_t srcSize)
MUST_CHECK;
1901 char *
strLCpy(
char *restrict dst,
size_t dstSize,
const char *restrict src)
MUST_CHECK;
1905 char *
strNCat(
char *restrict dst,
const char *restrict src,
size_t srcLen)
MUST_CHECK;
1906 char *
strLCat(
char *restrict dst,
size_t dstSize,
const char *restrict src)
MUST_CHECK;
1907 char *
strLNCat(
char *restrict dst,
size_t dstSize,
const char *restrict src,
size_t srcLen)
MUST_CHECK;
1911 #define catS(...) catSF("", __VA_ARGS__, NULL) 1915 #define iCatS(dst, ...) iCatSF(dst, "", __VA_ARGS__, NULL) 1917 char *
bLCatSF(
char *dst,
size_t dstSize,
const char *paramType, ...)
MUST_CHECK;
1918 #define bLCatS(dst, dstSize, ...) bLCatSF(dst, dstSize, "", __VA_ARGS__, NULL) 1927 char *
bLFormatS(
char *
string,
size_t stringSize, const
char *fmt, ...) MUST_CHECK;
1930 char *
appendS(const
char *string1, const
char *string2) MUST_CHECK;
1931 char *
appendCharS(const
char *string1,
char c) MUST_CHECK;
1932 char *
appendSChar(
char c, const
char *string2) MUST_CHECK;
1933 char *
iAppendS(
char **string1, const
char *string2) MUST_CHECK;
1935 char *
iAppendNFreeS(
char **string1,
char *string2) MUST_CHECK;
1936 char *
iAppendManySF(
char **
string, const
char *paramType, ...) MUST_CHECK;
1937 #define iAppendManyS(s, s1, ...) iAppendManySF(s, s1, __VA_ARGS__, NULL) 1938 char *
bAppendManySF(
char *
string,
const char *paramType, ...) MUST_CHECK;
1939 #define bAppendManyS(s, s1, ...) bAppendManySF(s, s1, __VA_ARGS__, NULL) 1940 char *
bLAppendManySF(
char *
string,
size_t stringSize,
const char *paramType, ...) MUST_CHECK;
1941 #define bLAppendManyS(s, sSize, s1, ...) bLAppendManySF(s, sSize, s1, __VA_ARGS__, NULL) 1958 #define replaceS_max(s,olds,news) replaceS(s,olds,news, 0) 1959 #define replaceSMax replaceS_max 1962 #define replaceSMaxLen(s,olds,news) replaceSLen(s,olds,news, 0) 1967 #define iReplaceS_max(s,olds,news) iReplaceS(s,olds,news, 0) 1968 #define iReplaceSMax iReplaceS_max 1970 #define bReplaceS_max(s,olds,news) bReplaceS(s,olds,news, 0) 1971 #define bReplaceSMax bReplaceS_max 1973 #define bLReplaceS_max(s,sSize,olds,news) bLReplaceS(s,sSize,olds,news, 0) 1974 #define bLReplaceSMax bLReplaceS_max 1978 #define replaceManyS(s, ...) replaceManySF(s, __VA_ARGS__, NULL) 1979 char *
iReplaceManySF(
char **
string,
char *paramType, ...) MUST_CHECK;
1980 #define iReplaceManyS(s, olds, ...) iReplaceManySF(s, olds, __VA_ARGS__, NULL) 1982 #define bReplaceManyS(s, olds, ...) bReplaceManySF(s, olds, __VA_ARGS__, NULL) 1983 char *
bLReplaceManySF(
char *s,
size_t sSize,
char *paramType, ...) MUST_CHECK;
1984 #define bLReplaceManyS(s, sSize, olds, ...) bLReplaceManySF(s, sSize, olds, __VA_ARGS__, NULL) 1991 #define icReplaceS_max(s,olds,news) icReplaceS(s,olds,news, 0) 1992 #define icReplaceSMax icReplaceS_max 1997 #define iicReplaceS_max(s,olds,news) iicReplaceS(s,olds,news, 0) 1998 #define iicReplaceSMax iicReplaceS_max 2000 #define bicReplaceS_max(s,olds,news) bicReplaceS(s,olds,news, 0) 2001 #define bicReplaceSMax bicReplaceS_max 2003 #define bLicReplaceS_max(s,sSize,olds,news) bLicReplaceS(s,sSize,olds,news, 0) 2004 #define bLicReplaceSMax bLicReplaceS_max 2008 #define icReplaceManyS(s, ...) icReplaceManySF(s, __VA_ARGS__, NULL) 2010 #define iicReplaceManyS(s, olds, ...) iicReplaceManySF(s, olds, __VA_ARGS__, NULL) 2012 #define bicReplaceManyS(s, olds, ...) bicReplaceManySF(s, olds, __VA_ARGS__, NULL) 2013 char *
bLicReplaceManySF(
char *s,
size_t sSize,
char *paramType, ...) MUST_CHECK;
2014 #define bLicReplaceManyS(s, sSize, olds, ...) bLicReplaceManySF(s, sSize, olds, __VA_ARGS__, NULL) 2017 bool eqS(
const char *string1,
const char *string2)
MUST_CHECK;
2023 bool eqIS(
const char *string1,
const char *string2, int64_t index)
MUST_CHECK;
2045 bool icEqIS(
const char *string1,
const char *string2, int64_t index)
MUST_CHECK;
2127 #define toUpper(c) ((c) = toupper(c), c) 2137 #define toLower(c) ((c) = tolower(c), c) 2159 #define uniqSlash(s) uniqS(s, '/') 2160 #define iUniqSlash(s) iUniqS(&(s), '/') 2161 #define bUniqSlash(s) bUniqS(s, '/') 2172 char *
bLRepeatS(
char *dest,
size_t destSize,
const char *
string,
size_t count)
MUST_CHECK;
2184 char *
bLEllipsisStartS(
char *dest,
size_t destSize,
const char *
string,
size_t targetLength,
const char *ellipsisString)
MUST_CHECK;
2196 char *
bEllipsisEndS(
char *dest,
const char *
string,
size_t targetLength,
const char *ellipsisString)
MUST_CHECK;
2197 char *
bLEllipsisEndS(
char *dest,
size_t destSize,
const char *
string,
size_t targetLength,
const char *ellipsisString)
MUST_CHECK;
2204 char *
padStartS(
const char *
string,
size_t targetLength,
const char *padString)
MUST_CHECK;
2206 char *
bPadStartS(
char *dest,
const char *
string,
size_t targetLength,
const char *padString)
MUST_CHECK;
2207 char *
bLPadStartS(
char *dest,
size_t destSize,
const char *
string,
size_t targetLength,
const char *padString)
MUST_CHECK;
2217 char *
padEndS(
const char *
string,
size_t targetLength,
const char *padString)
MUST_CHECK;
2218 char *
iPadEndS(
char **
string,
size_t targetLength,
const char *padString)
MUST_CHECK;
2219 char *
bPadEndS(
char *dest,
const char *
string,
size_t targetLength,
const char *padString)
MUST_CHECK;
2220 char *
bLPadEndS(
char *dest,
size_t destSize,
const char *
string,
size_t targetLength,
const char *padString)
MUST_CHECK;
2224 char *
bLPadEndCharS(
char *dest,
size_t destSize,
const char *
string,
size_t targetLength,
char padChar)
MUST_CHECK;
2239 char *
bLSwapS(
char *
string,
size_t size, int64_t index1, int64_t index2)
MUST_CHECK;
2246 char *
bLSliceS(
char *
string,
size_t stringSize, int64_t start, int64_t end)
MUST_CHECK;
2255 char *
insertS(
const char *
string, int64_t index,
const char *toInsert)
MUST_CHECK;
2260 char *
bLInsertS(
char *
string,
size_t stringSize, int64_t index,
const char *toInsert)
MUST_CHECK;
2266 char *
bLInjectS(
char *
string,
size_t stringSize, int64_t index,
char toInject)
MUST_CHECK;
2270 char *
delS(
const char *
string, int64_t start, int64_t end)
MUST_CHECK;
2273 char *
bLDelS(
char *
string,
size_t stringSize, int64_t start, int64_t end)
MUST_CHECK;
2302 char *
tokS(
char *s,
const char *delim,
char **saveptr)
MUST_CHECK;
2328 #define codeSizeUTF8(utf8) codeSzUTF8[*(const uint8_t *)(utf8)] 2331 #define nextCodeUTF8(utf8) ((utf8) + codeSizeUTF8(utf8)) 2334 #define nxtCodeUTF8(utf8) EVA(utf8, nextCodeUTF8(utf8)) 2335 #define nxCodeUTF8(utf8) (utf8 = nextCodeUTF8(utf8)) 2410 bool eqIUTF8(const
char *string1, const
char *string2, int64_t index) MUST_CHECK;
2413 bool eqICharUTF8(const
char *string1,
char c, int64_t index) MUST_CHECK;
2416 bool icEqUTF8(const
char *string1, const
char *string2) MUST_CHECK;
2417 bool icEqCharUTF8(
char c, const
char *string2) MUST_CHECK;
2418 bool icEqUTF8Char(const
char *string1,
char c) MUST_CHECK;
2421 bool icEqIUTF8(const
char *string1, const
char *string2, int64_t index) MUST_CHECK;
2423 bool icEqICharUTF8(const
char *string1,
char c, int64_t index) MUST_CHECK;
2426 bool icStartsWithUTF8(const
char *string1, const
char *string2) MUST_CHECK;
2429 bool icEndsWithUTF8(const
char *string1, const
char *string2) MUST_CHECK;
2432 ssize_t
icCountUTF8(const
char *s, const
char *needle) MUST_CHECK;
2448 char *
upperUTF8(const
char *
string) MUST_CHECK;
2457 char *
lowerUTF8(const
char *
string) MUST_CHECK;
2466 char *
uniqUTF8(const
char *
string, const
char *code) MUST_CHECK;
2467 char *
iUniqUTF8(
char **
string, const
char *code) MUST_CHECK;
2468 char *
bUniqUTF8(
char *
string, const
char *code) MUST_CHECK;
2470 char *
icUniqUTF8(const
char *
string, const
char *code) MUST_CHECK;
2472 char *
iicUniqUTF8(
char **
string, const
char *code) MUST_CHECK;
2474 char *
bicUniqUTF8(
char *
string,
char c) MUST_CHECK;
2477 rune
getUTF8(const
char *
string, int64_t index) MUST_CHECK;
2480 char *
setUTF8(
char *
string, int64_t index, rune c) MUST_CHECK;
2483 char *
sliceUTF8(const
char *
string, int64_t start, int64_t end) MUST_CHECK;
2484 char *
iSliceUTF8(
char **
string, int64_t start, int64_t end) MUST_CHECK;
2485 char *
bSliceUTF8(
char *
string, int64_t start, int64_t end) MUST_CHECK;
2486 char *
bLSliceUTF8(
char *
string,
size_t stringSize, int64_t start, int64_t end) MUST_CHECK;
2489 char *
insertUTF8(const
char *
string, int64_t index, const
char *toInsert) MUST_CHECK;
2490 char *
insertNFreeUTF8(const
char *
string, int64_t index,
char *toInsert) MUST_CHECK;
2491 char *
iInsertUTF8(
char **
string, int64_t index, const
char *toInsert) MUST_CHECK;
2492 char *
iInsertNFreeUTF8(
char **
string, int64_t index,
char *toInsert) MUST_CHECK;
2493 char *
bInsertUTF8(
char *
string, int64_t index, const
char *toInsert) MUST_CHECK;
2494 char *
bLInsertUTF8(
char *
string,
size_t stringSize, int64_t index, const
char *toInsert) MUST_CHECK;
2497 char *
delUTF8(const
char *
string, int64_t start, int64_t end) MUST_CHECK;
2498 char *
iDelUTF8(
char **
string, int64_t start, int64_t end) MUST_CHECK;
2499 char *
bDelUTF8(
char *
string, int64_t start, int64_t end) MUST_CHECK;
2500 char *
bLDelUTF8(
char *
string,
size_t stringSize, int64_t start, int64_t end) MUST_CHECK;
2503 ssize_t
indexOfUTF8(const
char *
string, const
char *needle) MUST_CHECK;
2505 ssize_t
icIndexOfUTF8(const
char *
string, const
char *needle) MUST_CHECK;
2508 bool icHasUTF8(const
char *
string, const
char *needle) MUST_CHECK;
2511 char *
icTokUTF8(const
char *s, const
char *delim,
char **saveptr) MUST_CHECK;
2514 char **
icExtractUTF8(const
char *
string, const
char* delim1, const
char* delim2) MUST_CHECK;
2515 char **
icExtractCharSUTF8(const
char *
string,
char delim1, const
char* delim2) MUST_CHECK;
2516 char **
icExtractSCharUTF8(const
char *
string, const
char* delim1,
char delim2) MUST_CHECK;
2523 bool icListEqUTF8(
char **list1,
char **list2) MUST_CHECK;
2526 bool icListHasUTF8(
char **list, const
char *
string) MUST_CHECK;
2544 #define emptyS(string) \ 2545 string = strdup(""); 2549 #define bEmptyS(string) \ 2558 #define orS(string, alternative) \ 2559 !isEmptyS(string) ? (string) : (alternative) 2567 #define orBlankS(string, alternative) \ 2568 !isBlankS(string) ? (string) : (alternative) 2573 #define nS(string) \ 2574 (string) ? (string) : "" 2579 #define nAS(string, alternative) \ 2580 (string) ? (string) : (alternative) 2584 ssize_t
intIndex(int64_t index, int64_t length);
2587 #define listEmptyS(list) \ 2589 list = malloc(1 * sizeof(char *)); \ 2590 if (list) list[0] = NULL; \ 2604 char **
listCreateSF(
const char *paramType, ...) MUST_CHECK;
2605 #define listCreateS(...) listCreateSF("", __VA_ARGS__, NULL) 2634 #define listFreeManyS(...) listFreeManySF(NULL, __VA_ARGS__, NULL) 2684 char *
bLJoin(
char *
string,
size_t stringSize,
char **list,
const char* delim)
MUST_CHECK;
2688 char **
extractS(
const char *
string,
const char* delim1,
const char* delim2)
MUST_CHECK;
2709 char **
listCatSF(
char **paramType, ...) MUST_CHECK;
2710 #define listCatS(...) listCatSF(NULL, __VA_ARGS__, NULL) 2723 char **
listAddS(
char **list1,
char **list2);
2724 char **
listAddCS(
char **list1,
const char **list2);
2751 char **
iListRemoveS(
char ***list, int64_t start, int64_t end);
2765 #define forever while(1) 2772 #define range(index, maxCount) \ 2773 ;size_t UNIQVAR(maxCnt) = (size_t)(maxCount); \ 2774 for (size_t index = 0 ; index < UNIQVAR(maxCnt) ; index++) 2780 #define rangeInf(index) \ 2781 for (size_t index = 0 ;; index++) 2786 #define rangeDown(index, maxCount) \ 2787 for (ssize_t index = (maxCount)-1 ; index >= 0 ; index--) 2794 #define rangeDownTo(index, maxCount, to) \ 2795 ;ssize_t UNIQVAR(_to) = to;\ 2796 for (ssize_t index = (maxCount)-1 ; index >= UNIQVAR(_to) ; index--) 2803 #define rangeFrom(index, from, maxCount) \ 2804 ;size_t UNIQVAR(maxCnt) = (size_t)(maxCount); \ 2805 for (size_t index = from ; index < UNIQVAR(maxCnt) ; index++) 2814 #define arange(index, array) range(index, ARRAY_SIZE(array)) 2823 #define arangeDown(index, array) rangeDown(index, ARRAY_SIZE(array)) 2832 #define arangeDownTo(index, array, to) rangeDownTo(index, ARRAY_SIZE(array), to) 2841 #define arangeFrom(index, from, array) rangeFrom(index, from, ARRAY_SIZE(array)) 2854 #define circular(index, from, maxCount) \ 2855 ;bool UNIQVAR(libsheepyInternalStatus) = true; \ 2856 size_t UNIQVAR(maxCnt) = (size_t)(maxCount); \ 2857 size_t UNIQVAR(frm) = (size_t)(from); \ 2858 for (size_t index = UNIQVAR(frm) ; (index != UNIQVAR(frm)) || (UNIQVAR(libsheepyInternalStatus)); index == (UNIQVAR(maxCnt)-1) ? index = 0 : index++, UNIQVAR(libsheepyInternalStatus) = false) 2871 #define circularDown(index, from, maxCount) \ 2872 ;bool UNIQVAR(libsheepyInternalStatus) = true; \ 2873 size_t UNIQVAR(maxCnt) = (size_t)(maxCount); \ 2874 size_t UNIQVAR(frm) = (size_t)(from); \ 2875 for (size_t index = UNIQVAR(frm) ; (index != UNIQVAR(frm)) || (UNIQVAR(libsheepyInternalStatus)); index == 0 ? index = (UNIQVAR(maxCnt)-1) : index--, UNIQVAR(libsheepyInternalStatus) = false) 2882 #define rangeStep(index, maxCount, step) \ 2883 ;size_t UNIQVAR(maxCnt) = (size_t)(maxCount); \ 2884 for (size_t index = 0 ; index < UNIQVAR(maxCnt) ; index+=step) 2889 #define rangeDownStep(index, maxCount, step) \ 2890 for (int64_t index = (maxCount)-1 ; index >= 0 ; index-=step) 2897 #define rangeFromStep(index, from, maxCount, step) \ 2898 ;size_t UNIQVAR(maxCnt) = (size_t)(maxCount); \ 2899 for (size_t index = from ; index < UNIQVAR(maxCnt) ; index+=(size_t)step) 2907 #define loop(maxCount) \ 2908 ;size_t UNIQVAR(maxCnt) = (size_t)(maxCount); \ 2909 for (size_t UNIQVAR(index) = 0 ; UNIQVAR(index) < UNIQVAR(maxCnt) ; UNIQVAR(index)++) 2916 #define loopDownTo(maxCount, to) \ 2917 ;ssize_t UNIQVAR(_to) = to;\ 2918 for (ssize_t UNIQVAR(index) = (maxCount)-1 ; UNIQVAR(index) >= UNIQVAR(_to) ; UNIQVAR(index)--) 2925 #define loopFrom(from, maxCount) \ 2926 ;size_t UNIQVAR(maxCnt) = (size_t)(maxCount); \ 2927 for (size_t UNIQVAR(index) = from ; UNIQVAR(index) < UNIQVAR(maxCnt) ; UNIQVAR(index)++) 2934 #define loopStep(maxCount, step) \ 2935 ;size_t UNIQVAR(maxCnt) = (size_t)(maxCount); \ 2936 for (size_t UNIQVAR(index) = 0 ; UNIQVAR(index) < UNIQVAR(maxCnt) ; UNIQVAR(index)+=step) 2943 #define loopFromStep(from, maxCount, step) \ 2944 ;size_t UNIQVAR(maxCnt) = (size_t)(maxCount); \ 2945 for (size_t UNIQVAR(index) = from ; UNIQVAR(index) < UNIQVAR(maxCnt) ; UNIQVAR(index)+=step) 2956 #define aForEach(array, element) \ 2957 ;size_t UNIQVAR(libsheepyInternalIndex) = 0; \ 2958 for (typeof(&array[0]) element = &array[0] ; UNIQVAR(libsheepyInternalIndex) < ARRAY_SIZE(array) ; UNIQVAR(libsheepyInternalIndex)++, element = &array[UNIQVAR(libsheepyInternalIndex)]) 2971 #define aEnumerate(array, index, element) \ 2972 ; size_t index = 0 ; \ 2973 for (typeof(&array[0]) element = &array[0] ; index < ARRAY_SIZE(array) ; index++, element = &array[index]) 2979 #define forEachCharP(list, element) \ 2980 for (char **element=list ; *element != NULL ; element++) 2985 #define forEachCCharP(list, element) \ 2986 for (const char **element=list ; *element != NULL ; element++) 2994 #define forEachS(list, element) \ 2995 ;size_t UNIQVAR(libsheepyInternalIndex) = 0; \ 2996 for (char *element = (list)[0]; (list)[UNIQVAR(libsheepyInternalIndex)]!= NULL ; UNIQVAR(libsheepyInternalIndex)++, element = (list)[UNIQVAR(libsheepyInternalIndex)]) 3001 #define forEachCS(list, element) \ 3002 ;size_t UNIQVAR(libsheepyInternalIndex) = 0; \ 3003 for (const char *element = (list)[0]; (list)[UNIQVAR(libsheepyInternalIndex)]!= NULL ; UNIQVAR(libsheepyInternalIndex)++, element = (list)[UNIQVAR(libsheepyInternalIndex)]) 3008 #define forEachType(type, list, element) \ 3009 for (type **element=list ; *element != NULL ; element++) 3017 #define enumerateCharP(list, element, index) \ 3018 ;size_t index = 0; \ 3019 for (char **element=list; *element != NULL ; element++, index++) 3027 #define enumerateCCharP(list, element, index) \ 3028 ;size_t index = 0; \ 3029 for (const char **element=list; *element != NULL ; element++, index++) 3037 #define enumerateS(list, element, index) \ 3038 ;size_t index = 0; \ 3039 for (char *element=(list)[0]; element != NULL ; index++, element = (list)[index]) 3047 #define enumerateCS(list, element, index) \ 3048 ;size_t index = 0; \ 3049 for (const char *element=(list)[0]; element != NULL ; index++, element = (list)[index]) 3056 #define enumerateType(type, list, element, index) \ 3057 ;size_t index = 0; \ 3058 for (type **element=list; *element != NULL ; element++, index++) 3068 #define lForEach(node, startNode)\ 3069 for(var node = startNode; node ; node = (node)->next) 3079 #define lForEachDown(node, startNode)\ 3080 for(var node = startNode; node ; node = (node)->prev) 3082 #define lForEachPrev lForEachDown 3119 #define execOutf systemOutf 3120 #define execf systemf 3123 char **
systemOutf(
const char *fmt, ...) MUST_CHECK;
3125 #define systemOut execOut 3126 int systemf(
const char *fmt, ...) MUST_CHECK;
3129 #define logSystem(cmd) funcbegin\ 3130 var UNIQVAR(cm) = cmd;\ 3131 logI("%s",UNIQVAR(cm));\ 3132 system (UNIQVAR(cm));\ 3134 #define logExec logSystem 3135 #define logSystemOut(cmd) ({\ 3136 var UNIQVAR(cm) = cmd;\ 3137 logI("%s",UNIQVAR(cm));\ 3138 systemOut(UNIQVAR(cm));\ 3140 #define logExecOut logSystemOut 3141 #define logSystemOutf(fmt, ...) ({\ 3142 logI (fmt, __VA_ARGS__);\ 3143 systemOutf(fmt, __VA_ARGS__);}) 3144 #define logExecOutf logSystemOutf 3145 #define logSystemf(fmt, ...) ({\ 3146 logI (fmt, __VA_ARGS__);\ 3147 systemf(fmt, __VA_ARGS__);}) 3148 #define logExecf logSystemf 3151 #define command(cmd) commandF(cmd, __LINE__, __func__, __FILE__) 3152 int commandF(
const char *cmd,
int line,
const char *thisFunc,
const char *thisFileName)
MUST_CHECK;
3153 #define commandf(...) commandfF(__LINE__, __func__, __FILE__, __VA_ARGS__) 3154 int commandfF(
int line,
const char *thisFunc,
const char *thisFileName,
const char *fmt, ...) MUST_CHECK;
3155 #define commandNFree(cmd) commandNFreeF(cmd, __LINE__, __func__, __FILE__) 3157 #define commandOut execOut 3158 #define commandOutf systemOutf 3161 #define logCommand(cmd) funcbegin\ 3162 var UNIQVAR(cm) = cmd;\ 3163 logI("%s",UNIQVAR(cm));\ 3164 command (UNIQVAR(cm));\ 3167 #define logCommandf(fmt, ...) funcbegin\ 3168 logI (fmt, __VA_ARGS__);\ 3169 commandf(fmt, __VA_ARGS__);\ 3172 #define logCommandNFree(cmd) funcbegin\ 3173 var UNIQVAR(cm) = cmd;\ 3174 logI ("%s",UNIQVAR(cm));\ 3175 commandNFree(UNIQVAR(cm));\ 3178 #define logCommandOut logExecOut 3179 #define logCommandOutf logExecOutf 3249 #define logBtrace char **UNIQVAR(r)=btrace();if(UNIQVAR(r)){logN("\n"BLD WHT"Backtrace:"RST);forEachS(UNIQVAR(r), element){logN(element);}listFreeS(UNIQVAR(r));logN("---");} 3255 #define logEBtrace if (btraceCfg) { char **UNIQVAR(r)=btrace();if(UNIQVAR(r)){logE("\n"BLD WHT"Backtrace:"RST);forEachS(UNIQVAR(r), element){logE(element);}listFreeS(UNIQVAR(r));logE("---");} } 3263 #define listEmpty(list) \ 3265 list = malloc(1 * sizeof(void *)); \ 3266 if (list) list[0] = NULL; \ 3276 void **
listCreateF(
void *paramType, ...) MUST_CHECK;
3277 #define listCreate(...) listCreateF(NULL, __VA_ARGS__, NULL) 3301 #define listFreeMany(...) listFreeManyF(NULL, __VA_ARGS__, NULL) 3320 void **
listCatF(
void **paramType, ...) MUST_CHECK;
3321 #define listCat(...) listCatF(NULL, __VA_ARGS__, NULL) 3364 #define newPtr(name, type)\ 3365 ;type *name = malloc(sizeof(type)) 3368 #define new0Ptr(name, type)\ 3369 ;type *name = calloc(1, sizeof(type)) 3372 #define allocAPtr(name) name = malloc(sizeof(*(name))) 3375 #define callocAPtr(name) name = calloc(1, sizeof(*(name))) 3378 #define newArray(name, type, count)\ 3379 ;type *name = malloc((count) * sizeof(type)) 3382 #define new0Array(name, type, count)\ 3383 ;type *name = calloc(count, sizeof(type)) 3386 #define allocArray(name, count) malloc((count) * sizeof(*(name))) 3389 #define allocAArray(name, count) name = malloc((count) * sizeof(*(name))) 3392 #define callocArray(name, count) calloc(count, sizeof(*(name))) 3395 #define callocAArray(name, count) name = calloc(count, sizeof(*(name))) 3398 #define reallocArray(name, count) realloc(name, (count) * sizeof(*(name))) 3455 #define sliceT(typeName, elementType)\ 3458 elementType *array;\ 3461 #define createSlice(typeName, name) ;typeName name; sliceInit(&name) 3463 #define createSliceCount(typeName, name, count) ;typeName name; sliceInitCount(&name, count) 3465 #define createSliceClearCount(typeName, name, count) ;typeName name; sliceCalloc(&name, count) 3467 #define createAllocateSlice(typeName, name) ;typeName *name = calloc(1, sizeof(typeName)) 3469 #define createAllocateSliceCount(typeName, name, count) ;typeName *name = calloc(1, sizeof(typeName)); sliceInitCount(name, count) 3471 #define createAllocateSliceClearCount(typeName, name, count) ;typeName *name = calloc(1, sizeof(typeName)); sliceCalloc(name, count) 3473 #define sliceTerminate(name) if (name) sliceFree(name);free(name) 3481 #define sliceInit(name) do{\ 3482 (name)->array = NULL;\ 3494 #define sliceInitCount(name, countInt) do{\ 3495 var UNIQVAR(c) = countInt;\ 3497 (name)->array = malloc(UNIQVAR(c) * sizeof (name)->array[0]);\ 3509 #define sliceCalloc(name, countInt) do{\ 3510 var UNIQVAR(c) = countInt;\ 3511 (name)->array = calloc(UNIQVAR(c), sizeof (name)->array[0]);\ 3518 #define sliceResize(name, countInt) do{\ 3519 var UNIQVAR(c) = countInt;\ 3520 if ((name)->array) {\ 3522 (name)->array = realloc((name)->array, sizeof((name)->array[0]) * UNIQVAR(c));\ 3526 (name)->array = malloc(sizeof((name)->array[0]) * UNIQVAR(c));\ 3529 if (UNIQVAR(c) < (name)->count) (name)->count = UNIQVAR(c);\ 3536 #define sliceClearResize(name, countInt) do{\ 3537 var UNIQVAR(c) = countInt;\ 3538 if ((name)->array) {\ 3540 (name)->array = realloc((name)->array, sizeof((name)->array[0]) * UNIQVAR(c));\ 3541 if ((name)->count < UNIQVAR(c)) {\ 3543 memset(&(name)->array[(name)->count], 0, (UNIQVAR(c) - (name)->count) * sizeof (name)->array[0]);\ 3548 (name)->array = calloc(UNIQVAR(c), sizeof((name)->array[0]));\ 3551 if (UNIQVAR(c) < (name)->count) (name)->count = UNIQVAR(c);\ 3560 #define sliceFree(name) free((name)->array) 3565 #define sliceElemType(name) typeof((name)->array[0]) 3570 #define sliceElemPtrType(name) typeof(&(name)->array[0]) 3575 #define sliceDup(name) ({\ 3576 typeof(*(name)) dest;\ 3577 sliceInitCount(&dest, (name)->count);\ 3578 if ((name)->array) {\ 3579 memcpy(dest.array, (name)->array, (name)->count * sizeof (name)->array[0]);\ 3580 dest.count = (name)->count;\ 3601 #define sliceCreateNDup(name, dest) ;typeof(*(name)) dest; sliceInitCount(&dest, (name)->count); if ((name)->array) { memcpy(dest.array, (name)->array, (name)->count * sizeof (name)->array[0]); dest.count = (name)->count;} 3606 #define sliceBDup(name, dest) do{\ 3607 var UNIQVAR(dst) = dest;\ 3608 sliceResize(UNIQVAR(dst), (name)->count);\ 3609 if ((name)->array) {\ 3610 memcpy(UNIQVAR(dst)->array, (name)->array, (name)->count * sizeof (name)->array[0]);\ 3611 UNIQVAR(dst)->count = (name)->count;\ 3619 #define sliceData(name) (name)->array 3624 #define sliceFrom(name, array, countInt) do{\ 3625 var UNIQVAR(c) = countInt;\ 3626 var UNIQVAR(a) = array;\ 3627 if (sizeof((name)->array[0]) == sizeof(*(UNIQVAR(a)))) {\ 3628 sliceResize(name, UNIQVAR(c));\ 3629 memcpy((name)->array, UNIQVAR(a), UNIQVAR(c) * sizeof UNIQVAR(a)[0]);\ 3630 (name)->count = UNIQVAR(c);\ 3638 #define sliceMirror(name, start, end) ({\ 3639 var UNIQVAR(strt) = start;\ 3640 typeof(*(name)) UNIQVAR(r);\ 3641 UNIQVAR(r).array = slicePtr(name, UNIQVAR(strt));\ 3642 UNIQVAR(r).count = end - UNIQVAR(strt);\ 3653 #define sliceBMirror(name, dest, start, end) do{\ 3654 var UNIQVAR(strt) = start;\ 3655 var UNIQVAR(dst) = dest;\ 3656 UNIQVAR(dst)->array = slicePtr(name, UNIQVAR(strt));\ 3657 UNIQVAR(dst)->count = end - UNIQVAR(strt);\ 3664 #define sliceMirrorFrom(name, array, countInt) do{\ 3665 var UNIQVAR(strt) = start;\ 3666 (name)->array = array;\ 3667 (name)->count = countInt;\ 3675 #define sliceClear(name) do{\ 3677 memset((name)->array, 0, (name)->count * sizeof (name)->array[0]);\ 3680 #define sliceClearRange(name, start, end) do{\ 3682 memset((name)->array + start, 0, (end-start) * sizeof (name)->array[0]);\ 3690 #define sliceEmpty(name) (name)->count = 0 3695 #define sliceIsEmpty(name) ((name)->count == 0 || !(name)->array) 3700 #define sliceFit(name) do{\ 3701 sliceResize(name, (name)->count);\ 3707 #define sliceCount(name) (name)->count 3712 #define sliceElemSize(name) sizeof((name)->array[0]) 3718 #define sliceAlloc(name) do{\ 3719 if (!(name)->array) {\ 3720 (name)->array = malloc(sliceSz * sizeof (name)->array[0]);\ 3723 (name)->array = realloc((name)->array, ((name)->count + sliceSz) * sizeof (name)->array[0]);\ 3730 #define sliceClearElem(name, index) memset(&(name)->array[index], 0, sizeof (name)->array[0]) 3739 #define slicePush(name) do {\ 3752 #define sliceAppend(name, v) do{\ 3754 sliceLast(name) = v;\ 3765 #define sliceClearPush(name) do{\ 3767 sliceClearElem(name, (name)->count - 1);\ 3781 #define slicePop(name) ((name)->count--, (name)->array[(name)->count]) 3788 #define sliceDelLast(name) ((name)->count--) 3793 #define sliceSet(name, index, v) do{\ 3794 var UNIQVAR(idx) = index;\ 3795 if (UNIQVAR(idx) >= (name)->count) {\ 3797 sliceClearResize(name, UNIQVAR(idx)+1);\ 3799 sliceAt(name, UNIQVAR(idx)) = v;\ 3810 #define sliceAt(name, index) ((name)->array[index]) 3820 #define slicePtr(name, index) ((name)->array + index) 3828 #define sliceLast(name) ((name)->array[(name)->count-1]) 3836 #define sliceLastPtr(name) ((name)->array + (name)->count - 1) 3841 #define sliceLastIndex(name) ((name)->count - 1) 3850 #define sliceFirst(name) ((name)->array[0]) 3860 #define sliceWriteFilename(name, filename) do {\ 3861 FILE *UNIQVAR(f) = fopen(filename, "w");\ 3863 fwrite((name)->array, sizeof((name)->array[0]), sliceCount(name), UNIQVAR(f));\ 3864 fclose(UNIQVAR(f));\ 3875 #define sliceWrite(name, file) fwrite((name)->array, sizeof((name)->array[0]), sliceCount(name), file) 3884 #define sliceReadFilename(name, filename) do {\ 3885 if (fileExists(filename)) {\ 3886 size_t UNIQVAR(sz) = fileSize(filename);\ 3887 FILE *UNIQVAR(f) = fopen(filename, "r");\ 3889 range(UNIQVAR(i), UNIQVAR(sz)/sizeof((name)->array[0])) {\ 3891 fread(sliceLastPtr(name), 1, sizeof((name)->array[0]), UNIQVAR(f));\ 3893 fclose(UNIQVAR(f));\ 3905 #define sliceRead(name, file) do {\ 3906 fseek(file, 0 , SEEK_END);\ 3907 size_t UNIQVAR(sz) = ftell(file);\ 3908 fseek(file, 0 , SEEK_SET);\ 3909 range(UNIQVAR(i), UNIQVAR(sz)/sizeof((name)->array[0])) {\ 3911 fread(sliceLastPtr(name), 1, sizeof((name)->array[0]), file);\ 3924 #define forEachSc(name, index) range(index, (name)->count) 3934 #define sliceForEach(name, element) \ 3935 ;size_t UNIQVAR(libsheepyInternalIndex) = 0; \ 3936 for (sliceElemPtrType(name) element = slicePtr(name, 0) ; UNIQVAR(libsheepyInternalIndex) < (name)->count ; UNIQVAR(libsheepyInternalIndex)++, element = slicePtr(name, UNIQVAR(libsheepyInternalIndex))) 3949 #define sliceEnumerate(name, index, element) \ 3950 ; size_t index = 0 ; \ 3951 for (sliceElemPtrType(name) element = slicePtr(name, 0) ; index < (name)->count ; index++, element = slicePtr(name, index)) 3958 #define sliceInject(name, index) do {\ 3959 var UNIQVAR(idx) = index;\ 3961 if (index < sliceCount(name)) {\ 3962 memmove(slicePtr(name, UNIQVAR(idx) +1), slicePtr(name, UNIQVAR(idx)), ((name)->count - UNIQVAR(idx)-1) * sizeof (name)->array[0]);\ 3974 #define slicePrepend(name, v) do {\ 3975 sliceInject(name, 0);\ 3976 sliceAt(name, 0) = v;\ 3985 #define sliceDequeue(name) ({\ 3986 var r = sliceAt(name, 0);\ 3987 sliceDelFirst(name);\ 3995 #define sliceDelFirst(name) do {\ 3996 if ((name)->count) {\ 3997 if ((name)->count > 1) {\ 3999 memcpy((name)->array, (name)->array +1 , ((name)->count - 1) * sizeof (name)->array[0]);\ 4011 #define sliceDelElem(name, index) do {\ 4012 var UNIQVAR(idx) = index;\ 4013 if ((size_t)UNIQVAR(idx) < (size_t)sliceLastIndex(name)) {\ 4015 memmove(slicePtr(name, UNIQVAR(idx)), slicePtr(name, UNIQVAR(idx) +1), ((name)->count - (UNIQVAR(idx) +1)) * sizeof (name)->array[0]);\ 4025 #define sliceDel(name, start, end) do {\ 4026 var UNIQVAR(strt) = start;\ 4027 var UNIQVAR(ed) = end;\ 4028 if (UNIQVAR(ed) < (name)->count and UNIQVAR(strt) < UNIQVAR(ed)) {\ 4030 memmove(slicePtr(name, UNIQVAR(strt)), slicePtr(name, UNIQVAR(ed)), ((name)->count - UNIQVAR(ed)) * sizeof (name)->array[0]);\ 4032 (name)->count -= UNIQVAR(ed) - UNIQVAR(strt);\ 4039 #define sliceVAppend(name, slice) do {\ 4040 var UNIQVAR(vec) = slice;\ 4041 if (sizeof((name)->array[0]) == sizeof((UNIQVAR(vec))->array[0])) {\ 4042 sliceResize(name, (name)->count + (UNIQVAR(vec))->count);\ 4043 memmove((name)->array + (name)->count, (UNIQVAR(vec))->array, (UNIQVAR(vec))->count * sizeof (name)->array[0]);\ 4044 (name)->count += (UNIQVAR(vec))->count;\ 4052 #define sliceAppendFrom(name, array, countInt) do {\ 4053 var UNIQVAR(c) = countInt;\ 4054 var UNIQVAR(a) = array;\ 4055 if (sizeof((name)->array[0]) == sizeof(*(UNIQVAR(a)))) {\ 4056 sliceResize(name, (name)->count + UNIQVAR(c));\ 4057 memmove((name)->array + (name)->count, UNIQVAR(a), UNIQVAR(c) * sizeof (name)->array[0]);\ 4058 (name)->count += UNIQVAR(c);\ 4067 #define sliceVPrepend(name, slice) do {\ 4068 var UNIQVAR(vec) = slice;\ 4069 if (sizeof((name)->array[0]) == sizeof((UNIQVAR(vec))->array[0])) {\ 4070 sliceResize(name, (name)->count + (UNIQVAR(vec))->count);\ 4071 memmove((name)->array + (UNIQVAR(vec))->count, (name)->array, (name)->count * sizeof (name)->array[0]);\ 4072 memmove((name)->array, (UNIQVAR(vec))->array, (UNIQVAR(vec))->count * sizeof (name)->array[0]);\ 4073 (name)->count += (UNIQVAR(vec))->count;\ 4082 #define slicePrependFrom(name, array, countInt) do {\ 4083 var UNIQVAR(c) = countInt;\ 4084 var UNIQVAR(a) = array;\ 4085 if (sizeof((name)->array[0]) == sizeof(*(UNIQVAR(a)))) {\ 4086 sliceResize(name, (name)->count + UNIQVAR(c));\ 4087 memmove((name)->array + UNIQVAR(c), (name)->array, (name)->count * sizeof (name)->array[0]);\ 4088 memmove((name)->array, UNIQVAR(a), UNIQVAR(c) * sizeof (name)->array[0]);\ 4089 (name)->count += UNIQVAR(c);\ 4098 #define sliceInsert(name, index, slice) do {\ 4099 var UNIQVAR(idx) = index;\ 4100 var UNIQVAR(vec) = slice;\ 4101 if (UNIQVAR(idx) == (name)->count) {\ 4102 sliceAppend(name, UNIQVAR(vec));\ 4104 else if (sizeof((name)->array[0]) == sizeof((UNIQVAR(vec))->array[0])) {\ 4105 sliceResize(name, (name)->count + (UNIQVAR(vec))->count);\ 4106 memmove((name)->array + UNIQVAR(idx) + (UNIQVAR(vec))->count, (name)->array + UNIQVAR(idx), ((name)->count - UNIQVAR(idx)) * sizeof (name)->array[0]);\ 4107 memmove((name)->array + UNIQVAR(idx), (UNIQVAR(vec))->array, (UNIQVAR(vec))->count * sizeof (name)->array[0]);\ 4108 (name)->count += (UNIQVAR(vec))->count;\ 4117 #define sliceInsertFrom(name, index, array, countInt) do {\ 4118 var UNIQVAR(idx) = index;\ 4119 var UNIQVAR(c) = countInt;\ 4120 var UNIQVAR(a) = array;\ 4121 if (UNIQVAR(idx) == (name)->count) {\ 4122 sliceAppendFrom(name, UNIQVAR(a), UNIQVAR(c));\ 4124 else if (sizeof((name)->array[0]) == sizeof(UNIQVAR(a)[0])) {\ 4125 sliceResize(name, (name)->count + UNIQVAR(c));\ 4126 memmove((name)->array + UNIQVAR(idx) + UNIQVAR(c), (name)->array + UNIQVAR(idx), ((name)->count - UNIQVAR(idx)) * sizeof (name)->array[0]);\ 4127 memmove((name)->array + UNIQVAR(idx), UNIQVAR(a), UNIQVAR(c) * sizeof (name)->array[0]);\ 4128 (name)->count += UNIQVAR(c);\ 4138 #define sliceSlice(name, start, end) ({\ 4139 var UNIQVAR(strt) = start;\ 4140 var UNIQVAR(ed) = end;\ 4142 memmove((name)->array, (name)->array + UNIQVAR(strt), (UNIQVAR(ed) - UNIQVAR(strt)) * sizeof (name)->array[0]);\ 4143 (name)->count = UNIQVAR(ed) - UNIQVAR(strt);\ 4153 #define sliceCopy(name, start, end) ({\ 4154 var UNIQVAR(strt) = start;\ 4155 var UNIQVAR(ed) = end;\ 4156 createAllocateSliceCount(typeof(*(name)),UNIQVAR(r), UNIQVAR(ed) - UNIQVAR(strt));\ 4157 memmove(UNIQVAR(r)->array, (name)->array + UNIQVAR(strt), (UNIQVAR(ed) - UNIQVAR(strt)) * sizeof (name)->array[0]);\ 4158 UNIQVAR(r)->count = UNIQVAR(ed) - UNIQVAR(strt);\ 4167 #define sliceBCopy(name, dest, start, end) do{\ 4168 if (sizeof((name)->array[0]) == sizeof((dest)->array[0])) {\ 4169 var UNIQVAR(strt) = start;\ 4170 var UNIQVAR(ed) = end;\ 4171 sliceResize(dest, UNIQVAR(ed) - UNIQVAR(strt));\ 4172 memmove((dest)->array, (name)->array + UNIQVAR(strt), (UNIQVAR(ed) - UNIQVAR(strt)) * sizeof (name)->array[0]);\ 4173 (dest)->count = UNIQVAR(ed) - UNIQVAR(strt);\ 4186 #define sliceSort(name, compareFunction) do{ \ 4187 qsort((name)->array, sizeof (name)->array[0], compareFunction);\ 4195 #define sliceEq(name, slice, eqFunction) ({\ 4196 var UNIQVAR(vec) = slice;\ 4197 bool UNIQVAR(r) = true;\ 4198 if (sizeof((name)->array[0]) == sizeof((UNIQVAR(vec))->array[0]) and (name)->count == UNIQVAR(vec)->count) {\ 4199 forEachV(name, UNIQVAR(idx)) {\ 4200 if (not eqFunction(sliceAt(name,UNIQVAR(idx)), sliceAt(UNIQVAR(vec),UNIQVAR(idx)))) {\ 4201 UNIQVAR(r) = false;\ 4206 else UNIQVAR(r) = false;\ 4215 #define sliceHas(name, value, eqFunction) ({\ 4216 var UNIQVAR(v) = value;\ 4217 bool UNIQVAR(r) = false;\ 4218 forEachV(name, UNIQVAR(idx)) {\ 4219 if (eqFunction(sliceAt(name,UNIQVAR(idx)), UNIQVAR(v))) {\ 4234 #define sliceIndexOf(name, value, eqFunction) ({\ 4235 var UNIQVAR(v) = value;\ 4236 ssize_t UNIQVAR(r) = -1;\ 4237 forEachV(name, UNIQVAR(idx)) {\ 4238 if (eqFunction(sliceAt(name,UNIQVAR(idx)), UNIQVAR(v))) {\ 4239 UNIQVAR(r) = UNIQVAR(idx);\ 4260 #define sliceBinarySearch(name, value, less, equal) ({\ 4261 var UNIQVAR(v) = value;\ 4262 ssize_t UNIQVAR(r);\ 4263 BSEARCH(UNIQVAR(r), UNIQVAR(v), (name)->count, less, equal);\ 4274 #define sliceUniq(name, eqFunction) do{\ 4275 if ((name)->count > 1) {\ 4278 size_t UNIQVAR(addIdx) = 0;\ 4280 forEachV(name, UNIQVAR(idx)) {\ 4282 bool UNIQVAR(has) = false;\ 4284 if (UNIQVAR(idx) < (name)->count) {\ 4285 rangeFrom(UNIQVAR(i), UNIQVAR(idx)+1, (name)->count) {\ 4286 if (eqFunction(sliceAt(name,UNIQVAR(i)), sliceAt(name,UNIQVAR(idx)))) {\ 4293 if (not UNIQVAR(has)) {\ 4296 if (UNIQVAR(addIdx) < UNIQVAR(idx)) {\ 4297 sliceAt(name,UNIQVAR(addIdx)) = sliceAt(name,UNIQVAR(idx));\ 4303 (name)->count = UNIQVAR(addIdx);\ 4360 #define staticSliceT(typeName, elementType, MAXCOUNT)\ 4363 elementType array[MAXCOUNT];\ 4366 #define createStaticSlice(typeName, name) ;typeName name; staticSliceInit(&name) 4374 #define staticSliceInit(name) do{\ 4381 #define staticSliceElemType(name) typeof((name)->array[0]) 4386 #define staticSliceElemPtrType(name) typeof(&(name)->array[0]) 4391 #define staticSliceBDup(name, dest) do{\ 4392 var UNIQVAR(dst) = dest;\ 4393 if ((name)->count <= ARRAY_SIZE(UNIQVAR(dst)->array)) {\ 4394 memcpy(UNIQVAR(dst)->array, (name)->array, (name)->count * sizeof (name)->array[0]);\ 4395 UNIQVAR(dst)->count = (name)->count;\ 4403 #define staticSliceData sliceData 4408 #define staticSliceFrom(name, array, countInt) do{\ 4409 var UNIQVAR(c) = countInt;\ 4410 var UNIQVAR(a) = array;\ 4411 if (sizeof((name)->array[0]) == sizeof(*(UNIQVAR(a))) ) {\ 4412 memcpy((name)->array, UNIQVAR(a), UNIQVAR(c) * sizeof UNIQVAR(a)[0]);\ 4413 (name)->count = UNIQVAR(c);\ 4422 #define staticSliceClear(name) memset((name)->array, 0, (name)->count * sizeof (name)->array[0]) 4424 #define staticSliceClearRange(name, start, end) memset((name)->array + start, 0, (end-start) * sizeof (name)->array[0]) 4431 #define staticSliceEmpty sliceEmpty 4436 #define staticSliceIsEmpty(name) ((name)->count == 0) 4441 #define staticSliceCount sliceCount 4446 #define staticSliceElemSize sliceElemSize 4451 #define staticSliceClearElem sliceClearElem 4460 #define staticSlicePush(name) (name)->count++ 4470 #define staticSliceAppend(name, v) do{\ 4471 staticSlicePush(name);\ 4472 staticSliceLast(name) = v;\ 4483 #define staticSliceClearPush(name) do{\ 4484 staticSlicePush(name);\ 4485 staticSliceClearElem(name, (name)->count - 1);\ 4499 #define staticSlicePop slicePop 4506 #define staticSliceDelLast sliceDelLast 4516 #define staticSliceAt sliceAt 4526 #define staticSlicePtr slicePtr 4534 #define staticSliceLast sliceLast 4542 #define staticSliceLastPtr sliceLastPtr 4547 #define staticSliceLastIndex sliceLastIndex 4556 #define staticSliceFirst sliceFirst 4566 #define staticSliceWriteFilename sliceWriteFilename 4575 #define staticSliceWrite sliceWrite 4584 #define staticSliceReadFilename(name, filename) do {\ 4585 if (fileExists(filename)) {\ 4586 size_t UNIQVAR(sz) = fileSize(filename);\ 4587 FILE *UNIQVAR(f) = fopen(filename, "r");\ 4589 range(UNIQVAR(i), UNIQVAR(sz)/sizeof((name)->array[0])) {\ 4590 staticSlicePush(name);\ 4591 fread(staticSliceLastPtr(name), 1, sizeof((name)->array[0]), UNIQVAR(f));\ 4593 fclose(UNIQVAR(f));\ 4605 #define staticSliceRead(name, file) do {\ 4606 fseek(file, 0 , SEEK_END);\ 4607 size_t UNIQVAR(sz) = ftell(file);\ 4608 fseek(file, 0 , SEEK_SET);\ 4609 range(UNIQVAR(i), UNIQVAR(sz)/sizeof((name)->array[0])) {\ 4610 staticSlicePush(name);\ 4611 fread(staticSliceLastPtr(name), 1, sizeof((name)->array[0]), file);\ 4624 #define forEachSSc forEachSc 4634 #define staticSliceForEach(name, element) \ 4635 ;size_t UNIQVAR(libsheepyInternalIndex) = 0; \ 4636 for (staticSliceElemPtrType(name) element = staticSlicePtr(name, 0) ; UNIQVAR(libsheepyInternalIndex) < (name)->count ; UNIQVAR(libsheepyInternalIndex)++, element = staticSlicePtr(name, UNIQVAR(libsheepyInternalIndex))) 4649 #define staticSliceEnumerate(name, index, element) \ 4650 ; size_t index = 0 ; \ 4651 for (staticSliceElemPtrType(name) element = staticSlicePtr(name, 0) ; index < (name)->count ; index++, element = staticSlicePtr(name, index)) 4658 #define staticSliceInject(name, index) do {\ 4659 var UNIQVAR(idx) = index;\ 4660 staticSlicePush(name);\ 4661 memmove(staticSlicePtr(name, UNIQVAR(idx) +1), staticSlicePtr(name, UNIQVAR(idx)), ((name)->count - UNIQVAR(idx)) * sizeof (name)->array[0]);\ 4672 #define staticSlicePrepend(name, v) do {\ 4673 staticSliceInject(name, 0);\ 4674 staticSliceAt(name, 0) = v;\ 4683 #define staticSliceDequeue sliceDequeue 4689 #define staticSliceDelFirst sliceDelFirst 4697 #define staticSliceDelElem sliceDelElem 4704 #define staticSliceDel sliceDel 4710 #define staticSliceVAppend(name, staticSlice) do {\ 4711 var UNIQVAR(vec) = staticSlice;\ 4712 if (sizeof((name)->array[0]) == sizeof(UNIQVAR(vec)->array[0]) ) {\ 4713 memcpy((name)->array + (name)->count, UNIQVAR(vec)->array, UNIQVAR(vec)->count * sizeof (name)->array[0]);\ 4714 (name)->count += UNIQVAR(vec)->count;\ 4722 #define staticSliceAppendFrom(name, array, countInt) do {\ 4723 var UNIQVAR(c) = countInt;\ 4724 var UNIQVAR(a) = array;\ 4725 if (sizeof((name)->array[0]) == sizeof(*(UNIQVAR(a))) ) {\ 4726 memcpy((name)->array + (name)->count, UNIQVAR(a), UNIQVAR(c) * sizeof (name)->array[0]);\ 4727 (name)->count += UNIQVAR(c);\ 4736 #define staticSliceVPrepend(name, staticSlice) do {\ 4737 var UNIQVAR(vec) = staticSlice;\ 4738 if (sizeof((name)->array[0]) == sizeof((UNIQVAR(vec))->array[0]) ) {\ 4739 memmove((name)->array + (UNIQVAR(vec))->count, (name)->array, (name)->count * sizeof (name)->array[0]);\ 4740 memcpy((name)->array, (UNIQVAR(vec))->array, (UNIQVAR(vec))->count * sizeof (name)->array[0]);\ 4741 (name)->count += (UNIQVAR(vec))->count;\ 4750 #define staticSlicePrependFrom(name, array, countInt) do {\ 4751 var UNIQVAR(c) = countInt;\ 4752 var UNIQVAR(a) = array;\ 4753 if (sizeof((name)->array[0]) == sizeof(*(UNIQVAR(a))) ) {\ 4754 staticSliceResize(name, (name)->count + UNIQVAR(c));\ 4755 memmove((name)->array + UNIQVAR(c), (name)->array, (name)->count * sizeof (name)->array[0]);\ 4756 memcpy((name)->array, UNIQVAR(a), UNIQVAR(c) * sizeof (name)->array[0]);\ 4757 (name)->count += UNIQVAR(c);\ 4766 #define staticSliceInsert(name, index, staticSlice) do {\ 4767 var UNIQVAR(idx) = index;\ 4768 var UNIQVAR(vec) = staticSlice;\ 4769 if (UNIQVAR(idx) == (name)->count) {\ 4770 staticSliceAppend(name, UNIQVAR(vec));\ 4772 else if (sizeof((name)->array[0]) == sizeof((UNIQVAR(vec))->array[0]) ) {\ 4773 memmove((name)->array + UNIQVAR(idx) + (UNIQVAR(vec))->count, (name)->array + UNIQVAR(idx), ((name)->count - UNIQVAR(idx)) * sizeof (name)->array[0]);\ 4774 memcpy((name)->array + UNIQVAR(idx), (UNIQVAR(vec))->array, (UNIQVAR(vec))->count * sizeof (name)->array[0]);\ 4775 (name)->count += (UNIQVAR(vec))->count;\ 4784 #define staticSliceInsertFrom(name, index, array, countInt) do {\ 4785 var UNIQVAR(idx) = index;\ 4786 var UNIQVAR(c) = countInt;\ 4787 var UNIQVAR(a) = array;\ 4788 if (UNIQVAR(idx) == (name)->count) {\ 4789 staticSliceAppendFrom(name, UNIQVAR(a), UNIQVAR(c));\ 4791 else if (sizeof((name)->array[0]) == sizeof(UNIQVAR(a)[0]) ) {\ 4792 memmove((name)->array + UNIQVAR(idx) + UNIQVAR(c), (name)->array + UNIQVAR(idx), ((name)->count - UNIQVAR(idx)) * sizeof (name)->array[0]);\ 4793 memcpy((name)->array + UNIQVAR(idx), UNIQVAR(a), UNIQVAR(c) * sizeof (name)->array[0]);\ 4794 (name)->count += UNIQVAR(c);\ 4804 #define staticSliceSlice sliceSlice 4811 #define staticSliceBCopy(name, dest, start, end) do{\ 4812 if (sizeof((name)->array[0]) == sizeof((dest)->array[0]) ) {\ 4813 var UNIQVAR(strt) = start;\ 4814 var UNIQVAR(ed) = end;\ 4815 staticSliceResize(dest, UNIQVAR(ed) - UNIQVAR(strt));\ 4816 memcpy((dest)->array, (name)->array + UNIQVAR(strt), (UNIQVAR(ed) - UNIQVAR(strt)) * sizeof (name)->array[0]);\ 4817 (dest)->count = UNIQVAR(ed) - UNIQVAR(strt);\ 4830 #define staticSliceSort sliceSort 4837 #define staticSliceEq sliceEq 4844 #define staticSliceHas sliceHas 4853 #define staticSliceIndexOf sliceIndexOf 4869 #define staticSliceBinarySearch sliceBinarySearch 4878 #define staticSliceUniq sliceUniq 4942 #define vectorT(typeName, elementType)\ 4946 elementType *array;\ 4950 #define createVector(typeName, name) ;typeName name; vectorInit(&name) 4952 #define createVectorCount(typeName, name, count) ;typeName name; vectorInitCount(&name, count) 4954 #define createVectorClearCount(typeName, name, count) ;typeName name; vectorCalloc(&name, count) 4956 #define createAllocateVector(typeName, name) ;typeName *name = calloc(1, sizeof(typeName)) 4958 #define createAllocateVectorCount(typeName, name, count) ;typeName *name = calloc(1, sizeof(typeName)); vectorInitCount(name, count) 4960 #define createAllocateVectorClearCount(typeName, name, count) ;typeName *name = calloc(1, sizeof(typeName)); vectorCalloc(name, count) 4962 #define vectorTerminate(name) if (name) vectorFree(name);free(name) 4970 #define vectorInit(name) do{\ 4971 (name)->array = NULL;\ 4973 (name)->maxCount = 0;\ 4984 #define vectorInitCount(name, countInt) do{\ 4985 var UNIQVAR(c) = countInt;\ 4986 (name)->array = malloc(UNIQVAR(c) * sizeof (name)->array[0]);\ 4988 (name)->maxCount = UNIQVAR(c);\ 4999 #define vectorCalloc(name, countInt) do{\ 5000 var UNIQVAR(c) = countInt;\ 5001 (name)->array = calloc(UNIQVAR(c), sizeof (name)->array[0]);\ 5003 (name)->maxCount = UNIQVAR(c);\ 5009 #define vectorResize(name, countInt) do{\ 5010 var UNIQVAR(c) = countInt;\ 5011 if ((name)->array) {\ 5013 (name)->array = realloc((name)->array, sizeof((name)->array[0]) * UNIQVAR(c));\ 5017 (name)->array = malloc(sizeof((name)->array[0]) * UNIQVAR(c));\ 5020 if (UNIQVAR(c) < (name)->count) (name)->count = UNIQVAR(c);\ 5021 (name)->maxCount = UNIQVAR(c);\ 5028 #define vectorClearResize(name, countInt) do{\ 5029 var UNIQVAR(c) = countInt;\ 5030 if ((name)->array) {\ 5032 (name)->array = realloc((name)->array, sizeof((name)->array[0]) * UNIQVAR(c));\ 5033 if ((name)->count < UNIQVAR(c)) {\ 5035 memset(&(name)->array[(name)->count], 0, (UNIQVAR(c) - (name)->count) * sizeof (name)->array[0]);\ 5040 (name)->array = calloc(UNIQVAR(c), sizeof((name)->array[0]));\ 5043 if (UNIQVAR(c) < (name)->count) (name)->count = UNIQVAR(c);\ 5044 (name)->maxCount = UNIQVAR(c);\ 5053 #define vectorFree sliceFree 5058 #define vectorElemType(name) typeof((name)->array[0]) 5063 #define vectorElemPtrType(name) typeof(&(name)->array[0]) 5068 #define vectorDup(name) ({\ 5069 typeof(*(name)) dest;\ 5070 vectorInitCount(dest, (name)->count);\ 5071 if ((name)->array) {\ 5072 memcpy(dest->array, (name)->array, (name)->count * sizeof (name)->array[0]);\ 5073 dest->count = (name)->count;\ 5080 #define vectorCreateNDup(name, dest) ;typeof(*(name)) dest; vectorInitCount(dest, (name)->count); if ((name)->array) { memcpy(dest->array, (name)->array, (name)->count * sizeof (name)->array[0]); dest->count = (name)->count;} 5085 #define vectorBDup(name, dest) do{\ 5086 var UNIQVAR(dst) = dest;\ 5087 vectorResize(UNIQVAR(dst), (name)->count);\ 5088 if ((name)->array) {\ 5089 memcpy(UNIQVAR(dst)->array, (name)->array, (name)->count * sizeof (name)->array[0]);\ 5090 dest->count = (name)->count;\ 5097 #define vectorData sliceData 5102 #define vectorFrom(name, array, countInt) do{\ 5103 var UNIQVAR(c) = countInt;\ 5104 var UNIQVAR(a) = array;\ 5105 if (sizeof((name)->array[0]) == sizeof(*(UNIQVAR(a)))) {\ 5106 if (UNIQVAR(c) > (name)->maxCount)\ 5107 vectorResize(name, UNIQVAR(c));\ 5108 memcpy((name)->array, UNIQVAR(a), UNIQVAR(c) * sizeof UNIQVAR(a)[0]);\ 5109 (name)->count = UNIQVAR(c);\ 5117 #define vectorClear sliceClear 5119 #define vectorClearRange sliceClearRange 5126 #define vectorEmpty sliceEmpty 5131 #define vectorIsEmpty sliceIsEmpty 5136 #define vectorFit(name) do{\ 5137 if ((name)->maxCount > (name)->count) {\ 5138 vectorResize(name, (name)->count);\ 5145 #define vectorCount sliceCount 5150 #define vectorMaxCount(name) (name)->maxCount 5155 #define vectorElemSize sliceElemSize 5161 #define vectorAlloc(name) do{\ 5162 if (!(name)->array) {\ 5163 (name)->array = malloc(vectorSz * sizeof (name)->array[0]);\ 5164 (name)->maxCount = vectorSz;\ 5166 else if ((name)->count == (name)->maxCount) {\ 5167 (name)->maxCount += vectorSz;\ 5168 (name)->array = realloc((name)->array, (name)->maxCount * sizeof (name)->array[0]);\ 5175 #define vectorClearElem sliceClearElem 5184 #define vectorPush(name) do {\ 5197 #define vectorAppend(name, v) do{\ 5199 vectorLast(name) = v;\ 5210 #define vectorClearPush(name) do{\ 5212 vectorClearElem(name, (name)->count - 1);\ 5226 #define vectorPop slicePop 5233 #define vectorDelLast sliceDelLast 5243 #define vectorPushCount(name, countp) procbegin\ 5244 u32 UNIQVAR(count) = countp;\ 5245 if (((name)->count + UNIQVAR(count)) > (name)->maxCount) {\ 5246 (name)->maxCount += UNIQVAR(count);\ 5247 (name)->array = realloc((name)->array, (name)->maxCount * sizeof (name)->array[0]);\ 5249 (name)->count += UNIQVAR(count);\ 5256 #define vectorSet(name, index, v) do{\ 5257 var UNIQVAR(idx) = index;\ 5258 if (UNIQVAR(idx) >= (name)->count) {\ 5260 vectorClearResize(name, UNIQVAR(idx)+1);\ 5262 vectorAt(name, UNIQVAR(idx)) = v;\ 5273 #define vectorAt sliceAt 5283 #define vectorPtr slicePtr 5291 #define vectorLast sliceLast 5299 #define vectorLastPtr sliceLastPtr 5304 #define vectorLastIndex sliceLastIndex 5313 #define vectorFirst sliceFirst 5323 #define vectorWriteFilename sliceWriteFilename 5332 #define vectorWrite sliceWrite 5341 #define vectorReadFilename(name, filename) do {\ 5342 if (fileExists(filename)) {\ 5343 size_t UNIQVAR(sz) = fileSize(filename);\ 5344 FILE *UNIQVAR(f) = fopen(filename, "r");\ 5346 range(UNIQVAR(i), UNIQVAR(sz)/sizeof((name)->array[0])) {\ 5348 fread(vectorLastPtr(name), 1, sizeof((name)->array[0]), UNIQVAR(f));\ 5350 fclose(UNIQVAR(f));\ 5362 #define vectorRead(name, file) do {\ 5363 fseek(file, 0 , SEEK_END);\ 5364 size_t UNIQVAR(sz) = ftell(file);\ 5365 fseek(file, 0 , SEEK_SET);\ 5366 range(UNIQVAR(i), UNIQVAR(sz)/sizeof((name)->array[0])) {\ 5368 fread(vectorLastPtr(name), 1, sizeof((name)->array[0]), file);\ 5381 #define forEachV forEachSc 5391 #define vectorForEach(name, element) \ 5392 ;size_t UNIQVAR(libsheepyInternalIndex) = 0; \ 5393 for (vectorElemPtrType(name) element = vectorPtr(name, 0) ; UNIQVAR(libsheepyInternalIndex) < (name)->count ; UNIQVAR(libsheepyInternalIndex)++, element = vectorPtr(name, UNIQVAR(libsheepyInternalIndex))) 5406 #define vectorEnumerate(name, index, element) \ 5407 ; size_t index = 0 ; \ 5408 for (vectorElemPtrType(name) element = vectorPtr(name, 0) ; index < (name)->count ; index++, element = vectorPtr(name, index)) 5415 #define vectorInject(name, index) do {\ 5416 var UNIQVAR(idx) = index;\ 5418 memmove(vectorPtr(name, UNIQVAR(idx) +1), vectorPtr(name, UNIQVAR(idx)), ((name)->count - UNIQVAR(idx)) * sizeof (name)->array[0]);\ 5429 #define vectorPrepend(name, v) do {\ 5430 vectorInject(name, 0);\ 5431 vectorAt(name, 0) = v;\ 5440 #define vectorDequeue sliceDequeue 5446 #define vectorDelFirst sliceDelFirst 5454 #define vectorDelElem sliceDelElem 5461 #define vectorDel sliceDel 5467 #define vectorVAppend(name, vector) do {\ 5468 var UNIQVAR(vec) = vector;\ 5469 if (sizeof((name)->array[0]) == sizeof((UNIQVAR(vec))->array[0])) {\ 5470 if (((name)->count + (UNIQVAR(vec))->count) > (name)->maxCount)\ 5471 vectorResize(name, (name)->count + (UNIQVAR(vec))->count);\ 5472 memcpy((name)->array + (name)->count, (UNIQVAR(vec))->array, (UNIQVAR(vec))->count * sizeof (name)->array[0]);\ 5473 (name)->count += (UNIQVAR(vec))->count;\ 5481 #define vectorAppendFrom(name, array, countInt) do {\ 5482 var UNIQVAR(c) = countInt;\ 5483 var UNIQVAR(a) = array;\ 5484 if (sizeof((name)->array[0]) == sizeof(*(UNIQVAR(a)))) {\ 5485 if (((name)->count + UNIQVAR(c)) > (name)->maxCount)\ 5486 vectorResize(name, (name)->count + UNIQVAR(c));\ 5487 memcpy((name)->array + (name)->count, UNIQVAR(a), UNIQVAR(c) * sizeof (name)->array[0]);\ 5488 (name)->count += UNIQVAR(c);\ 5497 #define vectorVPrepend(name, vector) do {\ 5498 var UNIQVAR(vec) = vector;\ 5499 if (sizeof((name)->array[0]) == sizeof((UNIQVAR(vec))->array[0])) {\ 5500 if (((name)->count + (UNIQVAR(vec))->count) > (name)->maxCount)\ 5501 vectorResize(name, (name)->count + (UNIQVAR(vec))->count);\ 5502 memmove((name)->array + (UNIQVAR(vec))->count, (name)->array, (name)->count * sizeof (name)->array[0]);\ 5503 memcpy((name)->array, (UNIQVAR(vec))->array, (UNIQVAR(vec))->count * sizeof (name)->array[0]);\ 5504 (name)->count += (UNIQVAR(vec))->count;\ 5513 #define vectorPrependFrom(name, array, countInt) do {\ 5514 var UNIQVAR(c) = countInt;\ 5515 var UNIQVAR(a) = array;\ 5516 if (sizeof((name)->array[0]) == sizeof(*(UNIQVAR(a)))) {\ 5517 if (((name)->count + UNIQVAR(c)) > (name)->maxCount)\ 5518 vectorResize(name, (name)->count + UNIQVAR(c));\ 5519 memmove((name)->array + UNIQVAR(c), (name)->array, (name)->count * sizeof (name)->array[0]);\ 5520 memcpy((name)->array, UNIQVAR(a), UNIQVAR(c) * sizeof (name)->array[0]);\ 5521 (name)->count += UNIQVAR(c);\ 5530 #define vectorInsert(name, index, vector) do {\ 5531 var UNIQVAR(idx) = index;\ 5532 var UNIQVAR(vec) = vector;\ 5533 if (UNIQVAR(idx) == (name)->count) {\ 5534 vectorAppend(name, UNIQVAR(vec));\ 5536 else if (sizeof((name)->array[0]) == sizeof((UNIQVAR(vec))->array[0])) {\ 5537 if (((name)->count + (UNIQVAR(vec))->count) > (name)->maxCount)\ 5538 vectorResize(name, (name)->count + (UNIQVAR(vec))->count);\ 5539 memmove((name)->array + UNIQVAR(idx) + (UNIQVAR(vec))->count, (name)->array + UNIQVAR(idx), ((name)->count - UNIQVAR(idx)) * sizeof (name)->array[0]);\ 5540 memcpy((name)->array + UNIQVAR(idx), (UNIQVAR(vec))->array, (UNIQVAR(vec))->count * sizeof (name)->array[0]);\ 5541 (name)->count += (UNIQVAR(vec))->count;\ 5550 #define vectorInsertFrom(name, index, array, countInt) do {\ 5551 var UNIQVAR(idx) = index;\ 5552 var UNIQVAR(c) = countInt;\ 5553 var UNIQVAR(a) = array;\ 5554 if (UNIQVAR(idx) == (name)->count) {\ 5555 vectorAppendFrom(name, UNIQVAR(a), UNIQVAR(c));\ 5557 else if (sizeof((name)->array[0]) == sizeof(UNIQVAR(a)[0])) {\ 5558 if (((name)->count + UNIQVAR(c)) > (name)->maxCount)\ 5559 vectorResize(name, (name)->count + UNIQVAR(c));\ 5560 memmove((name)->array + UNIQVAR(idx) + UNIQVAR(c), (name)->array + UNIQVAR(idx), ((name)->count - UNIQVAR(idx)) * sizeof (name)->array[0]);\ 5561 memcpy((name)->array + UNIQVAR(idx), UNIQVAR(a), UNIQVAR(c) * sizeof (name)->array[0]);\ 5562 (name)->count += UNIQVAR(c);\ 5572 #define vectorSlice sliceSlice 5580 #define vectorCopy(name, start, end) ({\ 5581 var UNIQVAR(strt) = start;\ 5582 var UNIQVAR(ed) = end;\ 5583 createAllocateVectorCount(typeof(*(name)),UNIQVAR(r), UNIQVAR(ed) - UNIQVAR(strt));\ 5584 memcpy(UNIQVAR(r)->array, (name)->array + UNIQVAR(strt), (UNIQVAR(ed) - UNIQVAR(strt)) * sizeof (name)->array[0]);\ 5585 UNIQVAR(r)->count = UNIQVAR(ed) - UNIQVAR(strt);\ 5594 #define vectorBCopy(name, dest, start, end) do{\ 5595 if (sizeof((name)->array[0]) == sizeof((dest)->array[0])) {\ 5596 var UNIQVAR(strt) = start;\ 5597 var UNIQVAR(ed) = end;\ 5598 if ((UNIQVAR(ed) - UNIQVAR(strt)) > (dest)->maxCount)\ 5599 vectorResize(dest, UNIQVAR(ed) - UNIQVAR(strt));\ 5600 memcpy((dest)->array, (name)->array + UNIQVAR(strt), (UNIQVAR(ed) - UNIQVAR(strt)) * sizeof (name)->array[0]);\ 5601 (dest)->count = UNIQVAR(ed) - UNIQVAR(strt);\ 5614 #define vectorSort sliceSort 5621 #define vectorEq sliceEq 5628 #define vectorHas sliceHas 5637 #define vectorIndexOf sliceIndexOf 5653 #define vectorBinarySearch sliceBinarySearch 5662 #define vectorUniq sliceUniq 5720 #define dVectorBits 6 5723 #define dVectorSz (1<<dVectorBits) 5724 #define dVectorMask (dVectorSz-1) 5734 #define dVectorT(typeName, elementType)\ 5739 elementType element;\ 5743 #define createDVector(typeName, name) ;typeName name; dVectorInit(&name) 5745 #define createDVectorCount(typeName, name, count) ;typeName name; dVectorInitCount(&name, count) 5753 #define dVectorInit(a) do{\ 5755 (a)->buffers = malloc(sizeof(void*));\ 5756 (a)->buffers[0] = malloc(dVectorSz * sizeof((a)->element));\ 5769 #define dVectorInitCount(a, count) do{\ 5771 if (count > dVectorSz) {\ 5772 (a)->buffers = realloc((a)->buffers, ((count>>dVectorBits)+1) * sizeof(void*));\ 5773 rangeFrom(UNIQVAR(i), 1, (count>>dVectorBits)+1) {\ 5774 (a)->buffers[UNIQVAR(i)] = malloc(dVectorSz * sizeof((a)->element));\ 5776 (a)->maxCount = (count>>dVectorBits)+1;\ 5780 #define dVectorResize(a, count) do{\ 5781 if (count > (a)->maxCount * dVectorSz) {\ 5783 (a)->buffers = realloc((a)->buffers, ((count>>dVectorBits)+1) * sizeof(void*));\ 5784 rangeFrom(UNIQVAR(i), (a)->maxCount, (count>>dVectorBits)+1) {\ 5785 (a)->buffers[UNIQVAR(i)] = malloc(dVectorSz * sizeof((a)->element));\ 5787 (a)->maxCount = (count>>dVectorBits)+1;\ 5798 #define dVectorFree(a) do{\ 5799 range(UNIQVAR(i), (size_t)(a)->maxCount) {\ 5800 free((a)->buffers[UNIQVAR(i)]);\ 5802 free((a)->buffers);\ 5808 #define dVectorElemType(name) typeof((name)->element) 5813 #define dVectorElemPtrType(name) typeof(&(name)->element) 5819 #define dVectorEmpty(name) (name)->count = 0 5824 #define dVectorIsEmpty(name) ((name)->count == 0) 5829 #define dVectorCount(name) (name)->count 5834 #define dVectorMaxCount(name) ((name)->maxCount * dVectorSz) 5843 #define dVectorAlloc(a) do{\ 5844 if ((a)->count == dVectorMaxCount(a)) {\ 5846 (a)->buffers = realloc((a)->buffers, (a)->maxCount * sizeof(void*));\ 5847 (a)->buffers[(a)->maxCount-1] = malloc(dVectorSz * sizeof((a)->element));\ 5860 #define dVectorPush(a) do{\ 5873 #define dVectorAppend(a, v) do{\ 5875 if ((a)->count < dVectorMaxCount(a)) {\ 5876 typeof((a)->element) *UNIQVAR(buffer) = (a)->buffers[((a)->count)>>dVectorBits];\ 5877 *(UNIQVAR(buffer)+ (((a)->count)&dVectorMask)) = v;\ 5893 #define dVectorPop(a) ((a)->count--, *((typeof((a)->element)*)((a)->buffers[((a)->count)>>dVectorBits])+(((a)->count)&dVectorMask))) 5900 #define dVectorDelLast(a) ((a)->count--) 5916 #define dVectorAt(a, index) (*((typeof((a)->element)*)((a)->buffers[(index)>>dVectorBits])+((index)&dVectorMask))) 5926 #define dVectorPtr(a, index) ((typeof((a)->element)*)((a)->buffers[(index)>>dVectorBits])+((index)&dVectorMask)) 5934 #define dVectorLast(a) (*((typeof((a)->element)*)((a)->buffers[((a)->count-1)>>dVectorBits])+(((a)->count-1)&dVectorMask))) 5942 #define dVectorLastPtr(a) ((typeof((a)->element)*)((a)->buffers[((a)->count-1)>>dVectorBits])+(((a)->count-1)&dVectorMask)) 5947 #define dVectorLastIndex(a) ((a)->count-1) 5955 #define dVectorFirst(a) (*((typeof((a)->element)*)((a)->buffers[0]))) 5964 #define dVectorWriteFilename(a, filename) do {\ 5965 FILE *UNIQVAR(f) = fopen(filename, "w");\ 5967 range(UNIQVAR(i), (size_t)dVectorCount(a)) {\ 5968 typeof((a)->element) *firstElement = (a)->buffers[UNIQVAR(i)/dVectorSz];\ 5969 fwrite(firstElement+(UNIQVAR(i)%dVectorSz), 1, sizeof((a)->element), UNIQVAR(f));\ 5971 fclose(UNIQVAR(f));\ 5982 #define dVectorWrite(a, file) do {\ 5983 range(UNIQVAR(i), (size_t)dVectorCount(a)) {\ 5984 typeof((a)->element) *firstElement = (a)->buffers[UNIQVAR(i)/dVectorSz];\ 5985 fwrite(firstElement+(UNIQVAR(i)%dVectorSz), 1, sizeof((a)->element), file);\ 5996 #define dVectorReadFilename(a, filename) do {\ 5997 if (fileExists(filename)) {\ 5998 size_t UNIQVAR(sz) = fileSize(filename);\ 5999 FILE *UNIQVAR(f) = fopen(filename, "r");\ 6001 range(UNIQVAR(i), UNIQVAR(sz)/sizeof((a)->element)) {\ 6003 fread(dVectorLastPtr(a), 1, sizeof((a)->element), UNIQVAR(f));\ 6005 fclose(UNIQVAR(f));\ 6017 #define dVectorRead(a, file) do {\ 6018 fseek(file, 0 , SEEK_END);\ 6019 size_t UNIQVAR(sz) = ftell(file);\ 6020 fseek(file, 0 , SEEK_SET);\ 6021 range(UNIQVAR(i), UNIQVAR(sz)/sizeof((a)->element)) {\ 6023 fread(dVectorLastPtr(a), 1, sizeof((a)->element), file);\ 6035 #define dVectorForEach(name, element) \ 6036 ;size_t UNIQVAR(libsheepyInternalIndex) = 0; \ 6037 for (dVectorElemPtrType(name) element = dVectorPtr(name, 0) ; UNIQVAR(libsheepyInternalIndex) < (name)->count ; UNIQVAR(libsheepyInternalIndex)++, element = dVectorPtr(name, UNIQVAR(libsheepyInternalIndex))) 6050 #define dVectorEnumerate(name, index, element) \ 6051 ; size_t index = 0 ; \ 6052 for (dVectorElemPtrType(name) element = dVectorPtr(name, 0) ; index < (name)->count ; index++, element = dVectorPtr(name, index)) 6124 #define staticArrayT(typeName, element, MAXCOUNT)\ 6130 element list[MAXCOUNT];\ 6133 #define createStaticArray(typeName, name) ;typeName name; staticArrayInit(name) 6142 #define staticArrayInit(name)\ 6144 (name).last = (name).head = 0;\ 6145 (name).maxCount = COUNT_ELEMENTS((name).list);\ 6146 (name).isEmpty = true;\ 6152 #define staticArrayElemType(name) typeof((name).list[0]) 6157 #define staticArrayElemPtrType(name) typeof(&(name).list[0]) 6163 #define staticArrayEmpty(name)\ 6165 (name).last = (name).head = 0;\ 6166 (name).isEmpty = true;\ 6172 #define staticArrayIsEmpty(name) ((name).isEmpty) 6177 #define staticArrayIsFull(name) ((name).isEmpty ? 0 : ((((name).last+1) % (name).maxCount) == (name).head)) 6182 #define staticArrayCount(name) ((name).isEmpty ? 0 : ((((name).last) >= ((name).head)) ? ((name).last-(name).head+1) : (((name).maxCount-(name).head + (name).last+1))) ) 6188 #define staticArrayPush(name)\ 6190 if ((name).isEmpty) {\ 6191 (name).isEmpty = false;\ 6195 (name).last %= (name).maxCount;\ 6202 #define staticArrayPop(name)\ 6204 if (!(name).isEmpty && ((name).last == (name).head)) {\ 6205 (name).isEmpty = true;\ 6207 else if (!(name).isEmpty && ((name).last != (name).head)) {\ 6211 (name).last+=(name).maxCount-1;\ 6215 #define staticArrayDelLast staticArrayPop 6221 #define staticArrayPrepend(name)\ 6223 if ((name).isEmpty) {\ 6224 (name).isEmpty = false;\ 6230 (name).head+=(name).maxCount-1;\ 6237 #define staticArrayDequeue(name)\ 6239 if (!(name).isEmpty && ((name).last == (name).head)) {\ 6240 (name).isEmpty = true;\ 6242 else if (!(name).isEmpty && ((name).last != (name).head)) {\ 6244 (name).head %= (name).maxCount;\ 6248 #define staticArrayDelFirst staticArrayDequeue 6253 #define staticArrayGet(name, index) (name).list[(((index) >= 0) ? (index) : staticArrayCount(name) + (index) )] 6254 #define staticArrayAt staticArrayGet 6259 #define staticArrayGetIndex(name, index) ((((index) >= 0) ? (index) : staticArrayCount(name) + (index) )) 6264 #define staticArrayRef(name, index) (name).list[((((index) >= 0) ? (index) : staticArrayCount(name) + (index) ) + name.head) % name.maxCount] 6269 #define staticArrayRefIndex(name, index) (((((index) >= 0) ? (index) : staticArrayCount(name) + (index) ) + name.head) % name.maxCount) 6274 #define staticArrayLast(name) (name).list[(name).last] 6279 #define staticArrayLastIndex(name) (name).last 6284 #define staticArrayFirst(name) (name).list[(name).head] 6289 #define staticArrayFirstIndex(name) (name).head 6294 #define staticArrayDelElem(name, index) do {\ 6295 if ((name).head < (name).last) {\ 6297 if (index < (name).last) {\ 6298 memmove(&(name).list[index], &(name).list[index+1], ((name).last - index) * sizeof((name).list[0]));\ 6301 elif ((name).head > (name).last) {\ 6302 if (index >= (name).head) {\ 6304 if (index < (name).maxCount - 1) {\ 6305 memmove(&(name).list[index], &(name).list[index+1], ((name).maxCount - index -1) * sizeof((name).list[0]));\ 6309 staticArrayAt((name), (name).maxCount-1) = staticArrayAt((name), 0);\ 6310 if ((name).last > 0) {\ 6311 memmove(&(name).list[0], &(name).list[1], (name).last * sizeof((name).list[0]));\ 6317 if (index < (name).last) {\ 6318 memmove(&(name).list[index], &(name).list[index+1], ((name).last - index) * sizeof((name).list[0]));\ 6322 staticArrayDelLast((name));\ 6332 #define staticArrayWriteFilename(name, filename) do {\ 6333 FILE *UNIQVAR(f) = fopen(filename, "w");\ 6335 if ((name).head <= (name).last) {\ 6336 fwrite(&((name).list[(name).head]), 1, (size_t)staticArrayCount(name) * sizeof((name).list[0]), UNIQVAR(f));\ 6339 fwrite(&((name).list[(name).head]), 1, (size_t)((name).maxCount - (name).head) * sizeof((name).list[0]), UNIQVAR(f));\ 6340 fwrite(&((name).list[(name).head])+((name).maxCount - (name).head), 1, (size_t)((name).last+1) * sizeof((name).list[0]), UNIQVAR(f));\ 6342 fclose(UNIQVAR(f));\ 6353 #define staticArrayWrite(name, file) do {\ 6354 if ((name).head <= (name).last) {\ 6355 fwrite(&((name).list[(name).head]), 1, (size_t)staticArrayCount(name) * sizeof((name).list[0]), file);\ 6358 fwrite(&((name).list[(name).head]), 1, (size_t)((name).maxCount - (name).head) * sizeof((name).list[0]), file);\ 6359 fwrite(&((name).list[(name).head])+((name).maxCount - (name).head), 1, (size_t)((name).last+1) * sizeof((name).list[0]), file);\ 6370 #define staticArrayReadFilename(name, filename) do {\ 6371 if (fileExists(filename)) {\ 6372 size_t UNIQVAR(sz) = fileSize(filename);\ 6373 if (UNIQVAR(sz) > sizeof((name).list)) break;\ 6375 if (UNIQVAR(sz) % sizeof((name).list[0])) break;\ 6376 FILE *UNIQVAR(f) = fopen(filename, "r");\ 6378 fread((name).list, 1, UNIQVAR(sz), UNIQVAR(f));\ 6379 fclose(UNIQVAR(f));\ 6382 (name).last = (UNIQVAR(sz) / sizeof((name).list[0])) - 1;\ 6383 (name).isEmpty = false;\ 6387 (name).isEmpty = true;\ 6400 #define staticArrayRead(name, file) do {\ 6401 fseek(file, 0 , SEEK_END);\ 6402 size_t UNIQVAR(sz) = ftell(file);\ 6403 fseek(file, 0 , SEEK_SET);\ 6404 if (UNIQVAR(sz) > sizeof((name).list)) break;\ 6406 if (UNIQVAR(sz) % sizeof((name).list[0])) break;\ 6407 fread((name).list, 1, UNIQVAR(sz), file);\ 6410 (name).last = (UNIQVAR(sz) / sizeof((name).list[0])) - 1;\ 6411 (name).isEmpty = false;\ 6415 (name).isEmpty = true;\ 6427 #define staticArrayForEach(name, element) \ 6428 ;size_t UNIQVAR(libsheepyInternalIndex) = 0; \ 6429 for (staticArrayElemPtrType(name) element = &staticArrayRef(name, 0) ; UNIQVAR(libsheepyInternalIndex) < staticArrayCount(name) ; UNIQVAR(libsheepyInternalIndex)++, element = &staticArrayRef(name, UNIQVAR(libsheepyInternalIndex))) 6442 #define staticArrayEnumerate(name, index, element) \ 6443 ;size_t UNIQVAR(libsheepyInternalIndex) = 0; \ 6444 ; size_t index = name.head ; \ 6445 for (staticArrayElemPtrType(name) element = &staticArrayRef(name, 0) ; UNIQVAR(libsheepyInternalIndex) < staticArrayCount(name) ; UNIQVAR(libsheepyInternalIndex)++, index = (name.head + UNIQVAR(libsheepyInternalIndex)) % name.maxCount, element = &staticArrayRef(name, index)) 6499 #define indexer staticArrayBase 6507 #define indexerT(typeName, INT_TYPE)\ 6515 #define createIndexer(typeName, name, maxCount) ;typeName name; indexerInit(name, maxCount) 6526 #define indexerInit(name, MAXCOUNT)\ 6528 (name).last = (name).head = 0;\ 6529 (name).maxCount = MAXCOUNT;\ 6530 (name).isEmpty = true;\ 6533 #define indexerPInit ringInit 6539 #define indexerEmpty staticArrayEmpty 6540 #define indexerPEmpty ringEmpty 6545 #define indexerIsEmpty staticArrayIsEmpty 6546 #define indexerPIsEmpty ringIsEmpty 6551 #define indexerIsFull staticArrayIsFull 6552 #define indexerPIsFull ringIsFull 6557 #define indexerCount staticArrayCount 6558 #define indexerPCount ringCount 6564 #define indexerPush staticArrayPush 6565 #define indexerPPush ringPush 6570 #define indexerPop staticArrayPop 6571 #define indexerPPop ringPop 6577 #define indexerPrepend staticArrayPrepend 6578 #define indexerPPrepend ringPrepend 6583 #define indexerDequeue staticArrayDequeue 6584 #define indexerPDequeue ringDequeue 6589 #define indexerRef(name, index) (((((index) >= 0) ? (index) : indexerCount(name) + (index) ) + name.head) % name.maxCount) 6590 #define indexerPRef(name, index) (((((index) >= 0) ? (index) : indexerPCount(name) + (index) ) + name->head) % name->maxCount) 6595 #define indexerLast(name) name.last 6596 #define indexerPLast(name) (name)->last 6601 #define indexerFirst(name) (name.head) 6602 #define indexerPFirst(name) (name)->head 6639 #define ringBase staticArrayBase 6652 #define ringMake staticArrayT 6663 #define ringStaticInit staticArrayInit 6666 int ringInit(
void *ring,
int maxCount);
6698 #define ringGet(name, index) (name)->list[(((index) >= 0) ? (index) : ringCount(name) + (index) )] 6703 #define ringRef(name, index) (name)->list[((((index) >= 0) ? (index) : ringCount(name) + (index) ) + name->head) % name->maxCount] 6708 #define ringLast(name) (name)->list[(name)->last] 6713 #define ringLastIndex(name) (name)->last 6718 #define ringFirst(name) (name)->list[(name)->head] 6729 #define ringSend(name, value)\ 6731 if (ringPush(name) >= 0) ringLast(name) = value;\ 6735 #define ringSendSt(status, name, value)\ 6737 if ((status = ringPush(name)) >= 0) ringLast(name) = value;\ 6749 #define ringRecv(name, result)\ 6751 result = ringFirst(name);\ 6756 #define ringRecvSt(status, name, result)\ 6758 if ((status = ringIsEmpty(name)) == 0) {\ 6759 result = ringFirst(name);\ 6869 #define fiberCtx(thisSlot) fibers.context[thisSlot] 6896 #define startJump(func)\ 6897 if (!setjmp(fibers.jumpBuffers[0])) {\ 6908 #define yield(slotValue, slot)\ 6909 if (!(slotValue = setjmp(fibers.jumpBuffers[slot]))) {\ 6910 staticArrayPush(fibers.L);\ 6911 staticArrayLast(fibers.L) = slot;\ 6912 longjmp(fibers.jumpBuffers[0], 1);\ 6919 #define fiberEnd(slot)\ 6920 if (!setjmp(fibers.jumpBuffers[slot])) {\ 6921 longjmp(fibers.jumpBuffers[0], 1);\ 6925 #define schedulerYield(backToSlot)\ 6926 if (!setjmp(fibers.jumpBuffers[0])) {\ 6927 longjmp(fibers.jumpBuffers[backToSlot], backToSlot);\ 6984 #define dArrayBits 6 6987 #define dArraySz (1<<dArrayBits) 6988 #define dArrayMask (dArraySz-1) 6998 #define dArrayT(typeName, elementType)\ 7004 elementType element;\ 7008 #define createDArray(typeName, name) ;typeName name; dArrayInit(&name) 7010 #define createDArrayCount(typeName, name, count) ;typeName name; dArrayInitCount(&name, count) 7018 #define dArrayInit(a) do{\ 7019 (a)->last = (a)->head = 0;\ 7020 (a)->buffers = malloc(sizeof(void*));\ 7021 (a)->buffers[0] = malloc(dArraySz * sizeof((a)->element));\ 7033 #define dArrayInitCount(a, count) do{\ 7035 if ((count) > dArraySz) {\ 7036 (a)->buffers = realloc((a)->buffers, (((count)>>dArrayBits)+1) * sizeof(void*));\ 7037 rangeFrom(UNIQVAR(i), 1, ((count)>>dArrayBits)+1) {\ 7038 (a)->buffers[UNIQVAR(i)] = malloc(dArraySz * sizeof((a)->element));\ 7040 (a)->maxCount = ((count)>>dArrayBits)+1;\ 7044 #define dArrayResize(a, count) do{\ 7045 if ((count) > (a)->maxCount * dArraySz) {\ 7047 (a)->buffers = realloc((a)->buffers, (((count)>>dArrayBits)+1) * sizeof(void*));\ 7048 rangeFrom(UNIQVAR(i), (a)->maxCount, ((count)>>dArrayBits)+1) {\ 7049 (a)->buffers[UNIQVAR(i)] = malloc(dArraySz * sizeof((a)->element));\ 7051 (a)->maxCount = ((count)>>dArrayBits)+1;\ 7062 #define dArrayFree dVectorFree 7067 #define dArrayElemType(a) typeof((a)->element) 7072 #define dArrayElemPtrType(a) typeof(&(a)->element) 7078 #define dArrayEmpty(name) do{\ 7079 (name)->last = (name)->head = 0;\ 7085 #define dArrayIsEmpty(name) ((name)->head == (name)->last) 7090 #define dArrayCount(name) ((name)->last - (name)->head) 7095 #define dArrayMaxCount(name) ((name)->maxCount * dArraySz) 7104 #define dArrayAlloc(a) do{\ 7105 if ((a)->last == dArrayMaxCount(a)) {\ 7107 (a)->buffers = realloc((a)->buffers, (size_t)(a)->maxCount * sizeof(void*));\ 7108 (a)->buffers[(a)->maxCount-1] = malloc(dArraySz * sizeof((a)->element));\ 7121 #define dArrayPush(a) do{\ 7134 #define dArrayAppend(a, v) do{\ 7136 if ((a)->last < dArrayMaxCount(a)) {\ 7137 typeof((a)->element) *UNIQVAR(buffer) = (a)->buffers[((a)->last)>>dArrayBits];\ 7138 *(UNIQVAR(buffer)+ (((a)->last)&dArrayMask)) = v;\ 7154 #define dArrayPop(a) ((a)->last--, *((typeof((a)->element)*)((a)->buffers[((a)->last)>>dArrayBits])+(((a)->last)&dArrayMask))) 7161 #define dArrayDelLast(a) ((a)->last--) 7171 #define dArrayPrepend(a, v) do{\ 7172 if ((a)->head > 0) {\ 7174 typeof((a)->element) *UNIQVAR(buffer) = (a)->buffers[((a)->head)>>dArrayBits];\ 7175 *(UNIQVAR(buffer)+ (((a)->head)&dArrayMask)) = v;\ 7190 #define dArrayDequeue(a) ((a)->head++, *((typeof((a)->element)*)((a)->buffers[((a)->head-1)>>dArrayBits])+(((a)->head-1)&dArrayMask))) 7197 #define dArrayDelFirst(a) ((a)->head++) 7207 #define dArrayAt(a, index) (*((typeof((a)->element)*)((a)->buffers[(index)>>dArrayBits])+((index)&dArrayMask))) 7217 #define dArrayPtr(a, index) ((typeof((a)->element)*)((a)->buffers[(index)>>dArrayBits])+((index)&dArrayMask)) 7222 #define dArraySet(a, index, v) do{\ 7223 var UNIQVAR(idx) = index;\ 7224 if (UNIQVAR(idx) < (a)->last) {\ 7226 dArrayAt(a, UNIQVAR(idx)) = v;\ 7227 if (UNIQVAR(idx) < (a)->head) {\ 7229 (a)->head = UNIQVAR(idx);\ 7235 if (UNIQVAR(idx) >= dArrayMaxCount(a)) {\ 7237 dArrayResize(a, UNIQVAR(idx)+1);\ 7239 dArrayAt(a, UNIQVAR(idx)) = v;\ 7241 (a)->last = UNIQVAR(idx)+1;\ 7256 #define dArraySparseSet(a, index, v) do{\ 7257 var UNIQVAR(idx) = index;\ 7258 var UNIQVAR(bIdx) = UNIQVAR(idx)>>dArrayBits;\ 7259 if (UNIQVAR(idx) >= dArrayMaxCount(a)) {\ 7261 (a)->buffers = realloc((a)->buffers, (((UNIQVAR(bIdx)+1)>>dArrayBits)+1) * sizeof(void*));\ 7263 memset(&(a)->buffers[(a)->maxCount], 0, (UNIQVAR(bIdx)+1) - (a)->maxCount);\ 7264 (a)->maxCount = UNIQVAR(bIdx)+1;\ 7266 (a)->buffers[UNIQVAR(bIdx)] = malloc(dArraySz * sizeof((a)->element));\ 7267 dArrayAt(a, UNIQVAR(idx)) = v;\ 7271 if (!(a)->buffers[UNIQVAR(bIdx)]) {\ 7273 (a)->buffers[UNIQVAR(bIdx)] = malloc(dArraySz * sizeof((a)->element));\ 7275 dArrayAt(a, UNIQVAR(idx)) = v;\ 7285 #define dArrayLast(a) (*((typeof((a)->element)*)((a)->buffers[((a)->last-1)>>dArrayBits])+(((a)->last-1)&dArrayMask))) 7293 #define dArrayLastPtr(a) ((typeof((a)->element)*)((a)->buffers[((a)->last-1)>>dArrayBits])+(((a)->last-1)&dArrayMask)) 7298 #define dArrayLastIndex(a) ((a)->last-1) 7303 #define dArrayLastIndexVar(a) ((a)->last) 7311 #define dArrayFirst(a) (*((typeof((a)->element)*)((a)->buffers[((a)->head)>>dArrayBits])+((a)->head)&dArrayMask)) 7316 #define dArrayFirstIndex(a) ((a)->head) 7325 #define dArrayWriteFilename(a, filename) do {\ 7326 FILE *UNIQVAR(f) = fopen(filename, "w");\ 7328 range(UNIQVAR(i), (size_t)dArrayCount(a)) {\ 7329 typeof((a)->element) *firstElement = (a)->buffers[UNIQVAR(i)/dArraySz];\ 7330 fwrite(firstElement+(UNIQVAR(i)%dArraySz), 1, sizeof((a)->element), UNIQVAR(f));\ 7332 fclose(UNIQVAR(f));\ 7343 #define dArrayWrite(a, file) do {\ 7344 range(UNIQVAR(i), (size_t)dArrayCount(a)) {\ 7345 typeof((a)->element) *firstElement = (a)->buffers[UNIQVAR(i)/dArraySz];\ 7346 fwrite(firstElement+(UNIQVAR(i)%dArraySz), 1, sizeof((a)->element), file);\ 7357 #define dArrayReadFilename(a, filename) do {\ 7358 if (fileExists(filename)) {\ 7359 size_t UNIQVAR(sz) = fileSize(filename);\ 7360 FILE *UNIQVAR(f) = fopen(filename, "r");\ 7362 range(UNIQVAR(i), UNIQVAR(sz)/sizeof((a)->element)) {\ 7364 fread(dArrayLastPtr(a), 1, sizeof((a)->element), UNIQVAR(f));\ 7366 fclose(UNIQVAR(f));\ 7378 #define dArrayRead(a, file) do {\ 7379 fseek(file, 0 , SEEK_END);\ 7380 size_t UNIQVAR(sz) = ftell(file);\ 7381 fseek(file, 0 , SEEK_SET);\ 7382 range(UNIQVAR(i), UNIQVAR(sz)/sizeof((a)->element)) {\ 7384 fread(dArrayLastPtr(a), 1, sizeof((a)->element), file);\ 7396 #define dArrayForEach(name, element) \ 7397 ;size_t UNIQVAR(libsheepyInternalIndex) = (name)->head; \ 7398 for (dArrayElemPtrType(name) element = dArrayPtr(name, (name)->head) ; UNIQVAR(libsheepyInternalIndex) < (name)->last + 1 ; UNIQVAR(libsheepyInternalIndex)++, element = dArrayPtr(name, UNIQVAR(libsheepyInternalIndex))) 7411 #define dArrayEnumerate(name, index, element) \ 7412 ; size_t index = (name)->head; \ 7413 for (dArrayElemPtrType(name) element = dArrayPtr(name, (name)->head) ; index < (name)->last + 1 ; index++, element = dArrayPtr(name, index)) 7479 #define slabT(typeName, elementType)\ 7484 elementType *array;\ 7488 #define createSlab(typeName, name) ;typeName name; slabInit(&name) 7490 #define createSlabCount(typeName, name, count) ;typeName name; slabInitCount(&name, count) 7498 #define slabInit(a) do{\ 7499 (a)->last = (a)->head = 0;\ 7500 (a)->array = malloc(sizeof(*((a)->array)) * slabSz);\ 7501 (a)->maxCount = slabSz;\ 7513 #define slabInitCount(a, count) do{\ 7514 var UNIQVAR(c) = count;\ 7515 (a)->last = (a)->head = 0;\ 7516 (a)->array = malloc(sizeof(*((a)->array)) * UNIQVAR(c));\ 7517 (a)->maxCount = UNIQVAR(c);\ 7520 #define slabResize(a, count) do{\ 7521 var UNIQVAR(c) = count;\ 7522 (a)->array = realloc((a)->array, sizeof(*((a)->array)) * UNIQVAR(c));\ 7523 (a)->maxCount = UNIQVAR(c);\ 7524 if (((a)->last >= (a)->maxCount) || ((a)->head >= (a)->maxCount)) {\ 7526 (a)->last = (a)->head = 0;\ 7536 #define slabFree sliceFree 7541 #define slabElemType(name) typeof((name)->array[0]) 7546 #define slabElemPtrType(name) typeof(&(name)->array[0]) 7551 #define slabEmpty(name) do{\ 7552 (name)->last = (name)->head = 0;\ 7558 #define slabIsEmpty(name) ((name)->head == (name)->last) 7563 #define slabCount(name) ((name)->last - (name)->head) 7568 #define slabMaxCount vectorMaxCount 7577 #define slabAlloc(a) do{\ 7578 if ((a)->last == slabMaxCount(a)) {\ 7579 (a)->maxCount += slabSz;\ 7580 slabResize(a, (a)->maxCount);\ 7591 #define slabPush(a) do{\ 7604 #define slabAppend(a, v) do{\ 7606 if ((a)->last < slabMaxCount(a)) {\ 7607 *( (a)->array + (a)->last ) = v;\ 7623 #define slabPop(a) ((a)->last--, *((a)->array + (a)->last)) 7630 #define slabDelLast(a) ((a)->last--) 7640 #define slabPrepend(a, v) do{\ 7641 if ((a)->head > 0) {\ 7643 *( (a)->array + (a)->head ) = v;\ 7658 #define slabDequeue(a) ((a)->head++, *((a)->array + (a)->head -1)) 7665 #define slabDelFirst(a) ((a)->head++) 7675 #define slabAt sliceAt 7685 #define slabPtr slicePtr 7693 #define slabLast(a) (*((a)->array + (a)->last -1)) 7701 #define slabLastPtr(a) ((a)->array + (a)->last -1) 7706 #define slabLastIndex(a) ((a)->last-1) 7711 #define slabLastIndexVar(a) ((a)->last) 7719 #define slabFirst(a) (*((a)->array + (a)->head)) 7724 #define slabFirstIndex(a) ((a)->head) 7733 #define slabWriteFilename(a, filename) do {\ 7734 FILE *UNIQVAR(f) = fopen(filename, "w");\ 7736 fwrite((a)->array + (a)->head, 1, sizeof(*((a)->array)) * slabCount(a), UNIQVAR(f));\ 7737 fclose(UNIQVAR(f));\ 7748 #define slabWrite(a, file) fwrite((a)->array + (a)->head, 1, sizeof(*((a)->array)) * slabCount(a), file) 7757 #define slabReadFilename(a, filename) do {\ 7758 if (fileExists(filename)) {\ 7759 size_t UNIQVAR(sz) = fileSize(filename);\ 7760 FILE *UNIQVAR(f) = fopen(filename, "r");\ 7762 range(UNIQVAR(i), UNIQVAR(sz)/sizeof(*((a)->array))) {\ 7764 fread(slabLastPtr(a), 1, sizeof(*((a)->array)), UNIQVAR(f));\ 7766 fclose(UNIQVAR(f));\ 7778 #define slabRead(a, file) do {\ 7779 fseek(file, 0 , SEEK_END);\ 7780 size_t UNIQVAR(sz) = ftell(file);\ 7781 fseek(file, 0 , SEEK_SET);\ 7782 range(UNIQVAR(i), UNIQVAR(sz)/sizeof(*((a)->array))) {\ 7784 fread(slabLastPtr(a), 1, sizeof(*((a)->array)), file);\ 7796 #define slabForEach(name, element) \ 7797 ;size_t UNIQVAR(libsheepyInternalIndex) = (name)->head; \ 7798 for (slabElemPtrType(name) element = slabPtr(name, (name)->head) ; UNIQVAR(libsheepyInternalIndex) < (name)->last + 1 ; UNIQVAR(libsheepyInternalIndex)++, element = slabPtr(name, UNIQVAR(libsheepyInternalIndex))) 7811 #define slabEnumerate(name, index, element) \ 7812 ; size_t index = (name)->head; \ 7813 for (slabElemPtrType(name) element = slabPtr(name, (name)->head) ; index < (name)->last + 1 ; index++, element = slabPtr(name, index)) 7850 #define staticBitsetT(typeName, containerType, count)\ 7851 typedef struct {containerType map[BUCKETS(count, 8 * sizeof(containerType))];} typeName; 7853 #define staticBitsetInit staticBitsetClear 7856 #define staticBitsetCount(name) (sizeof((name)->map) * 8) 7859 #define staticBitsetClear(name) memset(name, 0, sizeof(*(name))); 7862 #define staticBitsetBucket(name, index) (name)->map[index / (8 * sizeof((name)->map[0]))] 7865 #define staticBitset0(name, index) do{\ 7866 var UNIQVAR(idx) = index;\ 7867 size_t byteOffset = UNIQVAR(idx) / (8 * sizeof((name)->map[0]));\ 7868 size_t bitOffset = UNIQVAR(idx) % (8 * sizeof((name)->map[0]));\ 7869 (name)->map[byteOffset] &= 0xFFFFFFFFFFFFFFFFUL ^ (1UL<<bitOffset);\ 7873 #define staticBitset1(name, index) do{\ 7874 var UNIQVAR(idx) = index;\ 7875 size_t byteOffset = UNIQVAR(idx) / (8 * sizeof((name)->map[0]));\ 7876 size_t bitOffset = UNIQVAR(idx) % (8 * sizeof((name)->map[0]));\ 7877 (name)->map[byteOffset] |= 1UL<<bitOffset;\ 7881 #define staticBitsetSet(name, index, value) do{\ 7882 var UNIQVAR(idx) = index;\ 7883 size_t byteOffset = UNIQVAR(idx) / (8 * sizeof((name)->map[0]));\ 7884 size_t bitOffset = UNIQVAR(idx) % (8 * sizeof((name)->map[0]));\ 7887 (name)->map[byteOffset] &= 0xFFFFFFFFFFFFFFFFUL ^ (1UL<<bitOffset);\ 7889 (name)->map[byteOffset] |= 1UL<<bitOffset;\ 7893 #define staticBitsetInv(name, index) do{\ 7894 var UNIQVAR(idx) = index;\ 7895 size_t byteOffset = UNIQVAR(idx) / (8 * sizeof((name)->map[0]));\ 7896 size_t bitOffset = UNIQVAR(idx) % (8 * sizeof((name)->map[0]));\ 7897 (name)->map[byteOffset] ^= 1UL<<bitOffset;\ 7901 #define staticBitsetGet(name, index) ({\ 7902 var UNIQVAR(idx) = index;\ 7903 size_t byteOffset = UNIQVAR(idx) / (8 * sizeof((name)->map[0]));\ 7904 size_t bitOffset = UNIQVAR(idx) % (8 * sizeof((name)->map[0]));\ 7905 ((name)->map[byteOffset] & (1UL<<bitOffset)) == 1UL<<bitOffset;\ 7921 #define bitsetModulo 8 7924 #define bitsetBucket(name, index) (name)->map[index / (bitsetModulo)] 7931 #define bitset0(name, at, index) do{\ 7932 var UNIQVAR(idx) = index;\ 7933 size_t byteOffset = UNIQVAR(idx) / (bitsetModulo);\ 7934 size_t bitOffset = UNIQVAR(idx) % (bitsetModulo);\ 7935 at(name, byteOffset) &= 0xFFFFFFFFFFFFFFFFUL ^ (1UL<<bitOffset);\ 7943 #define bitset1(name, at, index) do{\ 7944 var UNIQVAR(idx) = index;\ 7945 size_t byteOffset = UNIQVAR(idx) / (bitsetModulo);\ 7946 size_t bitOffset = UNIQVAR(idx) % (bitsetModulo);\ 7947 at(name, byteOffset) |= 1UL<<bitOffset;\ 7955 #define bitsetSet(name, at, index, value) do{\ 7956 var UNIQVAR(idx) = index;\ 7957 size_t byteOffset = UNIQVAR(idx) / (bitsetModulo);\ 7958 size_t bitOffset = UNIQVAR(idx) % (bitsetModulo);\ 7961 at(name, byteOffset) &= 0xFFFFFFFFFFFFFFFFUL ^ (1UL<<bitOffset);\ 7963 at(name, byteOffset) |= 1UL<<bitOffset;\ 7971 #define bitsetInv(name, at, index) do{\ 7972 var UNIQVAR(idx) = index;\ 7973 size_t byteOffset = UNIQVAR(idx) / (bitsetModulo);\ 7974 size_t bitOffset = UNIQVAR(idx) % (bitsetModulo);\ 7975 at(name, byteOffset) ^= 1UL<<bitOffset;\ 7984 #define bitsetGet(name, at, index) ({\ 7985 var UNIQVAR(idx) = index;\ 7986 size_t byteOffset = UNIQVAR(idx) / (bitsetModulo);\ 7987 size_t bitOffset = UNIQVAR(idx) % (bitsetModulo);\ 7988 (at(name, byteOffset) & (1UL<<bitOffset)) == 1UL<<bitOffset;\ 8034 #define FIELD_SET(dst, val, msb, lsb) dst = ( (dst) & ((0xFFFFFFFFFFFFFFFEUL << (msb)) | ((1UL<<(lsb))-1) )) | ((~(0xFFFFFFFFFFFFFFFEUL << ((msb)-(lsb))) & (val)) << (lsb)) 8036 #define FIELD_GET EXTRACT 8053 #define FIELD_SETL(dst, index, val, len) FIELD_SET(dst, val, ((index)+1)*(len)-1, (index)*(len)) 8068 #define BITFIELD_SET(array, index, val, len) FIELD_SET((array)[((index)*(len))/64], val, ((index)*(len))%64+(len)-1, ((index)*(len))%64) 8081 #define BITFIELD_GET(array, index, len) EXTRACT((array)[((index)*(len))/64], ((index)*(len))%64+(len)-1, ((index)*(len))%64) 8086 #define BITFIELD_SIZE(count, len, containerType) BUCKETS((count)*(len), 8 * sizeof(containerType)) 8091 #define BITFIELD_VAR(array, count, len) u64 array[BITFIELD_SIZE(count, len, u64)] 8102 #define nanoSleep(time) pError0(nanoSleepF(time)) 8105 #define nanoSleep(time) pError0(nanoSleepF(time)) 8108 #define nanoSleepE(time, cmd) pErrorCmd(nanoSleepF(time), == 0, cmd) 8111 #define usSleep(time) pError0(nanoSleepF(1000 * (uint64_t)time)) 8114 #define msSleep(time) pError0(nanoSleepF(1000000 * (uint64_t)time)) 8118 #define UNUSED __attribute__ ((unused)) 8119 #define DEPRECATED __attribute__ ((deprecated)) 8120 #define PACKED __attribute__((__packed__)) 8137 #define CLEANUP(func) __attribute__((cleanup(func))) 8151 #define FALLTHRU __attribute__ ((fallthrough)) 8157 #define AINLINE inline __attribute__ ((always_inline)) 8160 #define NOINLINE __attribute__ ((noinline)) 8178 #define NORETURN __attribute__ ((noreturn)) 8181 #define AMALLOC __attribute__ ((malloc)) 8184 #define USED __attribute__ ((used)) 8187 #define ALIGN(X) __attribute__ ((aligned, (x))) 8188 #define ALIGN_MAX __attribute__ ((aligned)) 8210 #define likely(x) (x) 8211 #define unlikely(x) (x) 8214 #endif // _libsheepyH char * iAppendCharS(char **string1, char c) MUST_CHECK
append char to string
char * makeValidUTF8(const char *utf8) MUST_CHECK
make valid UTF-8 encoded string
const char * findNextUTF8(const char *string, size_t utf8Size, const char *utf8) MUST_CHECK
find next UTF-8 code point even not at the start of a code point
char * iExpandHome(char **path) MUST_CHECK
expands ~/ ($HOME) or ~USER
char * iNormalizePath(char **path) MUST_CHECK
normalize path
char * iAppendS(char **string1, const char *string2) MUST_CHECK
append strings
bool eqS(const char *string1, const char *string2) MUST_CHECK
string Equal compare string1 to string2
char ** icExtractSCharUTF8(const char *string, const char *delim1, char delim2) MUST_CHECK
char * quoteS(const char *s, char delim) MUST_CHECK
add backslash '\' before delim('\'' or '"') and backslash the backslashes in the result avoid splitti...
char * setUTF8(char *string, int64_t index, rune c) MUST_CHECK
set UTF8 encoded string
char * appendCharS(const char *string1, char c) MUST_CHECK
append char to string when c is 0 the result is string1
int writeFileS(const char *filePath, const char *string) MUST_CHECK
write string to file
char ** btrace(void)
generate backtrace the program has to be linked the -rdynamic option for btrace to work btrace can ba...
char ** listEmptySF(void) MUST_CHECK
list Empty String Function
char * bGetCurrentDate(char *dst) MUST_CHECK
char ** splitS(const char *string, const char *delim) MUST_CHECK
char * readLine(FILE *fp) MUST_CHECK
readLine from file stream the fist new line is converted to 0
char * iEllipsisStartCharS(char **string, size_t targetLength, char ellipsisChar) MUST_CHECK
ellipsis start string
bool isWritable(const char *path) MUST_CHECK
is path writable
size_t listLengthS(char **list) MUST_CHECK
list Length String return number of elements until the first NULL element
char ** readDirAll(const char *dirPath) MUST_CHECK
list files in a directory and sort the list
void loghex(const void *buf, size_t len)
print buffer as hexadecimal string
char * sliceUTF8(const char *string, int64_t start, int64_t end) MUST_CHECK
slice UTF8 encoded String return new string which is the string between start and end negative indexe...
char * setS(char *string, int64_t index, char c) MUST_CHECK
set string
bool eqIS(const char *string1, const char *string2, int64_t index) MUST_CHECK
string Index Equal compare string1 at index to string2 when string2 is empty, the result is false ...
void ** listEmptyF(void) MUST_CHECK
list Empty Function
char * iStripCtrlS(char **string) MUST_CHECK
remove terminal control char from string
bool listIsBlankS(char **list) MUST_CHECK
list Is Empty String
char * bLDelS(char *string, size_t stringSize, int64_t start, int64_t end) MUST_CHECK
buffer size delete string
char * ellipsisStartS(const char *string, size_t targetLength, const char *ellipsisString) MUST_CHECK
ellipsis start string
char ** listFromCArrayS(const char **array, size_t size) MUST_CHECK
list From Const Array String
char * iAppendNFreeS(char **string1, char *string2) MUST_CHECK
append and free strings
ssize_t padStartLenS(const char *string, size_t targetLength, const char *padString) MUST_CHECK
length of string after padStart
char * bLowerS(char *string) MUST_CHECK
buffer lower case String
ssize_t countS(const char *s, const char *needle) MUST_CHECK
count String count number of (non-overlapping) occurrences of a substring
char * findCharS(const char *string, char c) MUST_CHECK
char * strLCatUTF8(char *dst, size_t dstSize, const char *src) MUST_CHECK
strLCatUTF8 - concatenate two UTF-8 encoded strings
void freeManySF(char *paramType,...)
free Many String
int randomUrandomOpen(void) MUST_CHECK
open /dev/urandom in libsheepy
ssize_t listBinarySearchS(char **list, const char *string) MUST_CHECK
list binary search string
int ringInit(void *ring, int maxCount)
list Sort duplicate list and sort
char * bStripCtrlS(char *string) MUST_CHECK
remove terminal control char from string
char * bUniqS(char *string, char c) MUST_CHECK
buffer uniq String
void ** iListSlice(void ***list, int64_t start, int64_t end) MUST_CHECK
list Slice return list with elements from start and end in list negative indexes are allowed ...
void ** iListInsert(void ***list, int64_t index, void **toInsert) MUST_CHECK
list Insert
char * bTimeToYMDS(char *dst, const time_t t) MUST_CHECK
char * emptySF(void) MUST_CHECK
empty String Function
char * injectS(const char *string, int64_t index, char toInject) MUST_CHECK
inject a char in string at index
char * casefoldUTF8(const char *utf8) MUST_CHECK
casefold UTF-8 encoded string
bool isNumber(const char *string) MUST_CHECK
is Number (integer or float) String
bool eqICharS(const char *string1, char c, int64_t index) MUST_CHECK
bool getLogStdout(void) MUST_CHECK
get stdout state, when TRUE (default) all logs are printed to stdout
char ** iListSliceS(char ***list, int64_t start, int64_t end) MUST_CHECK
list Slice String return list with elements from start and end in list negative indexes are allowed ...
char ** iListDelS(char ***list, int64_t start, int64_t end) MUST_CHECK
list Delete String return list without elements from start and end in list negative indexes are allow...
bool icListEqC1S(const char **list1, char **list2) MUST_CHECK
ignore case const(list1) list Equal String compare each element of list1 and list2 ...
mode_t getUmask(void) MUST_CHECK
get umask
char * uniqUTF8(const char *string, const char *code) MUST_CHECK
uniq UTF-8 String duplicate string
char ** iListInsertS(char ***list, int64_t index, char **toInsert) MUST_CHECK
list Insert string
char * bLEscapeS(char *dest, size_t destSize, const char *s, char delim) MUST_CHECK
escape string according the json specification (RFC 8259) if there is in the string, the backslash is escaped and it will be parsed as the string '' be the json parsers the unicode characters should be converted to UTF8 codepoints instead of using the result can be included in a json string and the parsing will be correct
char * bicUniqUTF8(char *string, char c) MUST_CHECK
char * iSwapS(char **string, int64_t index1, int64_t index2) MUST_CHECK
swap characters in string
char * listGetS(char **list, int64_t index) MUST_CHECK
list Get String duplicate string at given index index can be negative
void setSoftwareRandom(void)
use software random numbers works on all cpu architectures the default random function is software ...
char ** splitChar(const char *string, char delim) MUST_CHECK
char * bLPadStartCharS(char *dest, size_t destSize, const char *string, size_t targetLength, char padChar) MUST_CHECK
pad start string
bool appendCText(const char *filePath, const char **list) MUST_CHECK
append const list to filePath
ssize_t listBinarySearchCharS(char **list, char c) MUST_CHECK
char * tokS(char *s, const char *delim, char **saveptr) MUST_CHECK
token in String
void ** listAdd(void **list1, void **list2) MUST_CHECK
list Add add list1 and list2 in a new list
rune toupperUTF8(rune c) MUST_CHECK
rune toupper UTF8
i64 ringPrepend(void *ring)
prepend element to ring (only decreases head) use ringFirst to access the element ...
char * bLicReplaceUTF8(char *s, size_t sSize, const char *olds, const char *news, size_t max) MUST_CHECK
char * bQuoteS(char *dest, const char *s, char delim) MUST_CHECK
add backslash '\' before delim('\'' or '"') and backslash the backslashes in the result avoid splitti...
char * icReplaceCharSUTF8(const char *s, char olds, const char *news, size_t max) MUST_CHECK
char ** readText(const char *filePath) MUST_CHECK
return text from filePath in a list new line characters are removed
bool writeCStream(FILE *fp, const char **list) MUST_CHECK
write const list to stream
ssize_t icListIndexOfCS(const char **list, const char *string) MUST_CHECK
ignore case and return index of string in const list
void cleanUpCharFree(char **val)
void keepAnsiColorsInLog(bool state)
enable/disable ansi color codes in logs
ssize_t listIndexOfCharS(char **list, char c) MUST_CHECK
void setDefaultProgName(void)
set default program name
char * bSliceS(char *string, int64_t start, int64_t end) MUST_CHECK
buffer slice String return string which is the string between start and end negative indexes are allo...
bool icHasS(const char *string, const char *needle) MUST_CHECK
ignore case has String
uint64_t randomChoice(uint64_t range) MUST_CHECK
return a random value between 0 and range 0<=value<range call randomUrandomOpen before this calling f...
bool icEqCharS(char c, const char *string2) MUST_CHECK
char ** icListSortUTF8(char **list) MUST_CHECK
ignore case list Sort UTF8 encoded String duplicate list and sort
char * iEllipsisEndCharS(char **string, size_t targetLength, char ellipsisChar) MUST_CHECK
ellipsis end string
char * replaceS(const char *s, const char *olds, const char *news, size_t max) MUST_CHECK
replace String the original remains unchanged duplicate s the olds string is replaced with the news s...
char * bUpperUTF8(char *string) MUST_CHECK
char ** iListReverseS(char ***list) MUST_CHECK
list Reverse String reverse list, the last element is the first element of the list ...
char * findS(const char *string, const char *needle) MUST_CHECK
find String
bool eqCharS(char c, const char *string2) MUST_CHECK
char * delElemS(const char *string, int64_t index) MUST_CHECK
delete element/character string
char * iInsertS(char **string, int64_t index, const char *toInsert) MUST_CHECK
insert string in string at index
char * cropS(char *string, int64_t start, int64_t end) MUST_CHECK
Crop String return a new string with characters from start and end in string and delete characters fr...
char * listPopS(char ***list) MUST_CHECK
list Pop String return last string from list and remove last element from the list ...
ssize_t icListIndexOfCharS(char **list, char c) MUST_CHECK
char * ellipsisEndCharS(const char *string, size_t targetLength, char ellipsisChar) MUST_CHECK
ellipsis end string
int rmAll(const char *path) MUST_CHECK
remove all delete recursively files and directories
ssize_t listIntIndexS(char **list, int64_t index) MUST_CHECK
list int to index String index can be negative
int enableCoreDump(void) MUST_CHECK
enable core dump
char * strLCat(char *restrict dst, size_t dstSize, const char *restrict src) MUST_CHECK
strLCat - concatenate two strings
bool fiberAdd(void *ctx, int thisSlot, fiberFT func)
add new fiber
char * bPadStartS(char *dest, const char *string, size_t targetLength, const char *padString) MUST_CHECK
pad start string
const uint8_t codeSzUTF8[256]
char * expandHome(const char *path) MUST_CHECK
expands ~/ ($HOME) or ~USER duplicate and expand path.
void ** listSlice(void **list, int64_t start, int64_t end) MUST_CHECK
list Slice
char * listGetCS(const char **list, int64_t index) MUST_CHECK
const list Get String duplicate string at given index index can be negative
char ** walkDir(const char *dirPath) MUST_CHECK
list all files in a directory recursively and sort the list
char ** listSwapS(char **list, int64_t index1, int64_t index2) MUST_CHECK
swap elements in list
char ** icExtractUTF8(const char *string, const char *delim1, const char *delim2) MUST_CHECK
char * relPath(const char *path, const char *start) MUST_CHECK
relative path
char * randomS(uint64_t length) MUST_CHECK
random string
char * bLicReplaceS(char *s, size_t sSize, const char *olds, const char *news, size_t max) MUST_CHECK
buffer size ignore case replace String the olds string is replaced with the news string max times in ...
char * iicReplaceManySF(char **string, char *paramType,...) MUST_CHECK
in place ignore case replace Many Strings the olds string is replaced with the news string max times ...
char * prependCharS(const char *string1, char c) MUST_CHECK
prepend char to string
char * timeToYMDS(const time_t t) MUST_CHECK
time To Year-Month-Day Hour:Minute:Second String convert unix time to string
void setMaxLogLevel(int logLevel)
set max log level logs above logMaxLevel are skipped
char ** listUniqS(char **list) MUST_CHECK
Uniquify elements of list duplicate list each elements are unique in the new list.
char * prependSChar(char c, const char *string2) MUST_CHECK
prepend string to char
char * formatS(const char *fmt,...) MUST_CHECK
format string allocate and format string using asprintf
char ** iListCropS(char ***list, int64_t start, int64_t end) MUST_CHECK
list Crop String return a new list with elements from start and end in list and delete elements from ...
char * insertUTF8(const char *string, int64_t index, const char *toInsert) MUST_CHECK
insert string in UTF8 encoded string at index
char * bLTimeToS(char *dst, size_t dstSize, const time_t t) MUST_CHECK
bool icStartsWithS(const char *string1, const char *string2) MUST_CHECK
ignore case starts With String compare start of string1 with string2
bool icListHasUTF8(char **list, const char *string) MUST_CHECK
ignore case and return true when list has UTF8 encoded string
char nibbleToHex(u8 n) MUST_CHECK
convert number between 0 and 15 to hexadecimal character '0' to 'F'
bool icListHasS(char **list, const char *string) MUST_CHECK
ignore case and return true when list has string
char * strNCpy(char *restrict dst, const char *restrict src, size_t srcSize) MUST_CHECK
strNCpy - copy src to dst
char * strCat(char *restrict dst, const char *restrict src) MUST_CHECK
strCat - concatenate two strings
void ** listAppend(void ***list1, void **list2) MUST_CHECK
list Append
char * bEllipsisStartCharS(char *dest, const char *string, size_t targetLength, char ellipsisChar) MUST_CHECK
ellipsis start string
jmp_buf tryJumpBuffers[maxTryThrowCount]
setjmp buffers for try/throw,throwV macros
void ** iListDel(void ***list, int64_t start, int64_t end) MUST_CHECK
list Delete return list without elements from start and end in list negative indexes are allowed ...
const bool FALSE
type bool false (glibc true is not bool), for use in generics
int64_t ptr2IdxUTF8(const char *utf8, const char *pos) MUST_CHECK
pointer to code point index UTF8 encoded string
char * delUTF8(const char *string, int64_t start, int64_t end) MUST_CHECK
delete UTF8 encoded string
void ** listPush(void ***list, void *s) MUST_CHECK
list Push
size_t quoteLenS(const char *s, char delim) MUST_CHECK
return the length of the escaped string (without the terminating \0)
char * iicUniqS(char **string, char c) MUST_CHECK
in place ignore case uniq String
char * bLSwapS(char *string, size_t size, int64_t index1, int64_t index2) MUST_CHECK
swap characters in string
char * iicReplaceManyUTF8F(char **s, char *paramType,...) MUST_CHECK
bool isReadable(const char *path) MUST_CHECK
is path readable
char * bInsertS(char *string, int64_t index, const char *toInsert) MUST_CHECK
buffer insert string in string at index
char * iListGetS(char **list, int64_t index) MUST_CHECK
list Get String index can be negative
size_t bLLenUTF8(const char *s, size_t maxSize) MUST_CHECK
buffer character length of UTF-8 string
void(* fiberFT)(int)
fiber function type
char * strCpy(char *restrict dst, const char *restrict src) MUST_CHECK
strCpy - copy src to dst
bool icListHasCharCS(const char **list, char c) MUST_CHECK
char ** listReverseS(char **list) MUST_CHECK
list Reverse String duplicate and reverse list, the last element is the first element of the new list...
char ** extractCharSS(const char *string, char delim1, const char *delim2) MUST_CHECK
char * icUniqS(const char *string, char c) MUST_CHECK
ignore case uniq String duplicate string
char * listDequeueS(char ***list) MUST_CHECK
list Dequeue String return first string from list and remove it from the list
char * appendSChar(char c, const char *string2) MUST_CHECK
append string to char
void * bReadStreamToS(FILE *fp, void *dst) MUST_CHECK
buffer read file to string
ssize_t bReadFile(const char *filePath, void *buffer) MUST_CHECK
buffer read file to buffer
bool appendText(const char *filePath, char **list) MUST_CHECK
append list to filePath
bool fileExists(const char *filePath) MUST_CHECK
detect files and directories
char * iicUniqUTF8(char **string, const char *code) MUST_CHECK
char * bReplaceS(char *s, const char *olds, const char *news, size_t max) MUST_CHECK
buffer replace String the olds string is replaced with the news string max times in the result 0 for ...
char * iDelUTF8(char **string, int64_t start, int64_t end) MUST_CHECK
delete UTF8 encoded string
bool icStartsWithUTF8(const char *string1, const char *string2) MUST_CHECK
ignore case starts With UTF8 encoded String compare start of string1 with string2 ...
char * icFindS(const char *string, const char *needle) MUST_CHECK
ignore case Find String
char * bLAppendManySF(char *string, size_t stringSize, const char *paramType,...) MUST_CHECK
buffer size append many strings
char ** listAppendS(char ***list1, char **list2) MUST_CHECK
list Append String Append list2 at the end of list1
char * bTimeToS(char *dst, const time_t t) MUST_CHECK
void * bLReadStreamToS(FILE *fp, void *dst, size_t dstSize) MUST_CHECK
buffer size read file to string
char * iPrependCharS(char **string1, char c) MUST_CHECK
prepend char to string
void * readFileToS(const char *filePath) MUST_CHECK
read file to string
void cleanUpListFree(char ***val)
bool icEqUTF8Char(const char *string1, char c) MUST_CHECK
char ** iListCompactS(char ***list) MUST_CHECK
remove empty strings from list
char * bLCEscapeS(char *dest, size_t destSize, const char *S) MUST_CHECK
escape string to become a valid C source string control characters, backslash and double quotes are e...
char * bRandomAlphaNumS(char *dst, size_t dstSize) MUST_CHECK
buffer random alpha numerical string
char ** icExtractS(const char *string, const char *delim1, const char *delim2) MUST_CHECK
ignore case extract string between delim1 and delim2 strings return list
char ** iListDupS(char **list) MUST_CHECK
list Duplicate String
char * padStartCharS(const char *string, size_t targetLength, char padChar) MUST_CHECK
pad start string
char * stripColorsS(const char *string) MUST_CHECK
remove ansi colors from string
char * joinS(char **list, const char *delim) MUST_CHECK
rune code2RuneUTF8(const char *code) MUST_CHECK
UTF-8 code point to rune.
char * bicReplaceUTF8(char *s, const char *olds, const char *news, size_t max) MUST_CHECK
int nanoSleepF(uint64_t time) MUST_CHECK
nanosleep
char ** iListRemoveElemS(char ***list, int64_t index) MUST_CHECK
list Remove Element String return list without the element at index the element is removed without be...
char * replaceManySF(const char *paramType,...) MUST_CHECK
replace Many Strings the original remains unchanged duplicate s the olds string is replaced with the ...
size_t escapeLenS(const char *s, char delim) MUST_CHECK
return the length of the escaped string (without the terminating \0)
char * normalizePath(const char *path) MUST_CHECK
normalize path
size_t sizeS(const char *string) MUST_CHECK
string buffer size
size_t cEscapeLenS(const char *s) MUST_CHECK
return the length of the escaped string (without the terminating \0)
int shRename(const char *src, const char *dst) MUST_CHECK
rename file
char ** listPrependS(char ***list, const char *s) MUST_CHECK
list Prepend String append s at the beginning of the list when list is NULL, a new list with one elem...
void * bReadFileToS(const char *filePath, void *dst) MUST_CHECK
buffer read file to string
char * bSliceUTF8(char *string, int64_t start, int64_t end) MUST_CHECK
buffer slice UTF8 encoded String return string which is the string between start and end negative ind...
ssize_t icListIndexOfS(char **list, const char *string) MUST_CHECK
ignore case and return index of string in list
bool bLIsUTF8(const char *string, size_t stringSize) MUST_CHECK
buffer length is UTF-8 string
const char * getRealProgPath(void) MUST_CHECK
get real program path The first call allocates libSheepyRealProgPath, it is freed with freeRealProgPa...
char * iPadStartS(char **string, size_t targetLength, const char *padString) MUST_CHECK
pad start string
char * listCropElemS(char **list, int64_t index) MUST_CHECK
list Crop Element String return element at index and delete element at index in the original list neg...
bool writeStream(FILE *fp, char **list) MUST_CHECK
write list to stream
bool icListEqCCS(const char **list1, const char **list2) MUST_CHECK
ignore case const(list1 and 2) list Equal String compare each element of list1 and list2 ...
char * iicReplaceCharSUTF8(char **s, char olds, const char *news, size_t max) MUST_CHECK
char * bLRepeatS(char *dest, size_t destSize, const char *string, size_t count) MUST_CHECK
repeat string count times
char * bUniqUTF8(char *string, const char *code) MUST_CHECK
buffer uniq String
char * iInsertUTF8(char **string, int64_t index, const char *toInsert) MUST_CHECK
insert string in UTF8 encoded string at index
void setLogSymbols(int mode)
set log symbols
char ** icSplitChar(const char *string, char delim) MUST_CHECK
char ** iListSetS(char **list, int64_t index, char *s) MUST_CHECK
list Set String store string at given index index can be negative
void _pLog(int, const char *, const char *, int, const char *,...)
void initLibsheepyF(const char *progPath, initLibsheepyObjectP initF)
initialize libsheepy (optional, for debug)
ssize_t listStrLengthS(char **list) MUST_CHECK
list String Length String
char ** iListDelElemS(char ***list, int64_t index) MUST_CHECK
list Delete Element String return list without the element at index negative indexes are allowed ...
bool icEqCharUTF8(char c, const char *string2) MUST_CHECK
bool fiberPrepend(void *ctx, int thisSlot, fiberFT func)
add new fiber and start immediately after next yield
char * iDelS(char **string, int64_t start, int64_t end) MUST_CHECK
delete string
char * iReplaceCharSS(char **s, char olds, const char *news, size_t max) MUST_CHECK
char * bLSliceUTF8(char *string, size_t stringSize, int64_t start, int64_t end) MUST_CHECK
buffer size slice UTF8 encoded String return string which is the string between start and end negativ...
char * iStripColorsS(char **string) MUST_CHECK
remove ansi colors from string
char ** extractSCharS(const char *string, const char *delim1, char delim2) MUST_CHECK
uint64_t logMask
variable to control which group logs to show, all logs are enabled by default (0xFFFFFFFFFFFFFFFF) ...
char ** listCreateSF(const char *paramType,...) MUST_CHECK
list Create String Function create a list from the list of parameters used from the listCreateS(...
char * insertNFreeS(const char *string, int64_t index, char *toInsert) MUST_CHECK
insert string in string at index and free toInsert when successful
char * repeatCharS(char c, size_t count) MUST_CHECK
repeat char count times
ssize_t joinLength(char **list, const char *delim) MUST_CHECK
join Length list length after joined with delimiter
char ** execOut(const char *cmd) MUST_CHECK
execute command return stdout from cmd
char * bLReplaceS(char *s, size_t sSize, const char *olds, const char *news, size_t max) MUST_CHECK
buffer size replace String the olds string is replaced with the news string max times in the result 0...
bool eqICharUTF8(const char *string1, char c, int64_t index) MUST_CHECK
char * endlink(const char *path) MUST_CHECK
end link
ssize_t listIndexOfCharCS(const char **list, char c) MUST_CHECK
#define staticArrayT(typeName, element, MAXCOUNT)
declares type for staticArray or ring
char ** iListPrependS(char ***list, char *s) MUST_CHECK
list Prepend String append s pointer at the beginning of the list when list is NULL, a new list with one element is returned when list and s are NULL return list with 2 NULL elements when s is NULL, the operation is canceled
char * bLEllipsisEndS(char *dest, size_t destSize, const char *string, size_t targetLength, const char *ellipsisString) MUST_CHECK
ellipsis end string
char * shReadlink(const char *path) MUST_CHECK
sheepy read link
int getLogSymbols(void) MUST_CHECK
get current log symbols
ssize_t icIndexOfUTF8(const char *string, const char *needle) MUST_CHECK
bool listHasCharS(char **list, char c) MUST_CHECK
int64_t parseI64Char(char c) MUST_CHECK
char * replaceSCharS(const char *s, const char *olds, char news, size_t max) MUST_CHECK
void * bLReadFileToS(const char *filePath, void *dst, size_t dstSize) MUST_CHECK
buffer size read file to string
ssize_t fileSizeFP(FILE *fp) MUST_CHECK
get file size from file pointer
char * bLDelElemS(char *string, size_t stringSize, int64_t index) MUST_CHECK
buffer size delete element/character string
char ** listCropS(char **list, int64_t start, int64_t end) MUST_CHECK
list Crop String return a new list with elements from start and end in list and delete elements from ...
char ** icExtractCharCharS(const char *string, char delim1, char delim2) MUST_CHECK
void ** iListEmptyF(void ***list) MUST_CHECK
list Empty Function
ssize_t countCharS(const char *s, char c) MUST_CHECK
char * randomAlphaNumS(uint64_t length) MUST_CHECK
random alpha numerical string
ssize_t padEndLenS(const char *string, size_t targetLength, const char *padString) MUST_CHECK
length of string after padEnd
char * bTrimS(char *string) MUST_CHECK
buffer trim String
char ** listDelElemS(char **list, int64_t index) MUST_CHECK
list Delete Element String return new list without the element at index negative indexes are allowed ...
char * bReplaceManySF(char *s, char *paramType,...) MUST_CHECK
buffer replace Many Strings the olds string is replaced with the news string max times in the result ...
char cropElemS(char *string, int64_t index) MUST_CHECK
char * rTrimS(const char *string) MUST_CHECK
right trim String duplicate string
#define range(index, maxCount)
range loop ;size_t UNIQVAR needed to avoid: error: a label can only be part of a statement and a decl...
char * bEllipsisEndS(char *dest, const char *string, size_t targetLength, const char *ellipsisString) MUST_CHECK
ellipsis end string
void ** listSet(void **list, int64_t index, void *s) MUST_CHECK
list Set
uint64_t parseHex(const char *string) MUST_CHECK
parse hexadecimal number in a string
void closeLogFiles(void)
close logfiles opened with setLogFile
uint8_t runeLenUTF8(rune r) MUST_CHECK
rune length as UTF-8 code point
char * bRandomS(char *dst, size_t length) MUST_CHECK
buffer random string
char * bLDirname(char *path, size_t pathSize) MUST_CHECK
buffer size dirname
char ** listSetCharS(char **list, int64_t index, char c) MUST_CHECK
char * strNCat(char *restrict dst, const char *restrict src, size_t srcLen) MUST_CHECK
strNCat - concatenate two strings
char ** iListShiftS(char ***list1, char **list2) MUST_CHECK
in place list Shift String Append list2 at the start of list1 by copying the pointers from list2 to l...
void setLogStdout(bool state)
enable/disable printing logs to stdout
bool equalModificationTimes(const char *path1, const char *path2) MUST_CHECK
compare modification times for path1 and path2
void scheduler(void)
fiber usage
bool isInt(const char *string) MUST_CHECK
is Integer String
staticArray type definition
char * bLGetCurrentDate(char *dst, size_t dstSize) MUST_CHECK
char * iSliceS(char **string, int64_t start, int64_t end) MUST_CHECK
slice String return string which is the string between start and end negative indexes are allowed ...
bool icEqUTF8(const char *string1, const char *string2) MUST_CHECK
ignore case UTF8 encoded string Equal compare string1 to string2
char * bLRepeatCharS(char *dest, size_t destSize, char c, size_t count) MUST_CHECK
repeat char count times
char * timeToS(const time_t t) MUST_CHECK
time To String convert unix time to string (ctime is not used here because it adds at the end of th...
char * getCwd(void) MUST_CHECK
get current working directory
char ** walkDirDir(const char *dirPath) MUST_CHECK
list all directories in a directory recursively and sort the list
char * icReplaceCharSS(const char *s, char olds, const char *news, size_t max) MUST_CHECK
char * bLEllipsisStartS(char *dest, size_t destSize, const char *string, size_t targetLength, const char *ellipsisString) MUST_CHECK
ellipsis start string
bool hasS(const char *string, const char *needle) MUST_CHECK
has String
char * dupS(const char *string) MUST_CHECK
duplicate string
char * bPadEndS(char *dest, const char *string, size_t targetLength, const char *padString) MUST_CHECK
pad end string
char * bLMakeValidUTF8(char *dst, size_t dstSize, const char *utf8) MUST_CHECK
buffer destination size make valid UTF-8 encoded string
char ** walkDirAll(const char *dirPath) MUST_CHECK
list all files and directories in a directory recursively and sort the list
char * bLReadS(char *dst, size_t dstSize) MUST_CHECK
buffer read String read user input (one line) as a string
void finalizeLibsheepyCharAtExit(void)
finalize libsheepy char at exit
void logNFree(char *s)
log and free
int getMaxLogLevel(void) MUST_CHECK
get current max log level
char * strLCpy(char *restrict dst, size_t dstSize, const char *restrict src) MUST_CHECK
strLCpy - copy src to dst
void ** listDup(void **list) MUST_CHECK
list Duplicate
char * upperS(const char *string) MUST_CHECK
upper case String duplicate string
char * bEllipsisStartS(char *dest, const char *string, size_t targetLength, const char *ellipsisString) MUST_CHECK
ellipsis start string
int64_t parseIntChar(char c) MUST_CHECK
char * bEscapeS(char *dest, const char *s, char delim) MUST_CHECK
escape string according the json specification (RFC 8259) if there is in the string, the backslash is escaped and it will be parsed as the string '' be the json parsers the unicode characters should be converted to UTF8 codepoints instead of using the result can be included in a json string and the parsing will be correct
char ** icSplitS(const char *string, const char *delim) MUST_CHECK
char * delS(const char *string, int64_t start, int64_t end) MUST_CHECK
delete string
uint64_t randomWordFromHW(void) MUST_CHECK
return random 64 bit unsigned integer from the cpu when the cpu doesn't have the random generator ins...
char * icReplaceManySF(const char *paramType,...) MUST_CHECK
ignore case replace Many Strings the original remains unchanged duplicate s the olds string is replac...
char ** iListInsertNFreeS(char ***list, int64_t index, char **toInsert) MUST_CHECK
list Insert string and free toInsert
char ** listPrependCharS(char ***list, char c) MUST_CHECK
bool icEqSChar(const char *string1, char c) MUST_CHECK
void setLogMode(int mode)
set log mode LOG_VERBOSE, LOG_CONCISE, .
char * iUpperS(char **string) MUST_CHECK
upper case String
char ** listDupCS(const char **list) MUST_CHECK
const list Duplicate String
time_t strToUnixTime(const char *date, const char *format) MUST_CHECK
convert date string to unix time
const char * getProgPath(void) MUST_CHECK
get program path When initLibsheepy is called before this function, it returns the given program path...
char * iDelElemS(char **string, int64_t index) MUST_CHECK
delete element/character string
void cleanUpFileFree(FILE **val)
char * bicUniqS(char *string, char c) MUST_CHECK
ignore case buffer uniq String
void ** iListReverse(void ***list) MUST_CHECK
list Reverse reverse list, the last element is the first element of the list
bool endsWithS(const char *string1, const char *string2) MUST_CHECK
ends With String compare end of string1 with string2
const char * bPrevUTF8(const char *string, const char *utf8) MUST_CHECK
buffer previous UTF-8 code point
bool listEqCCS(const char **list1, const char **list2) MUST_CHECK
const(list1 and 2) list Equal String compare each element of list1 and list2
char * iTrimS(char **string) MUST_CHECK
trim String
char * iEllipsisEndS(char **string, size_t targetLength, const char *ellipsisString) MUST_CHECK
ellipsis end string
const bool TRUE
type bool true (glibc true is not bool), for use in generics
const char * bLNextUTF8(const char *string, size_t utf8Size, const char *utf8) MUST_CHECK
buffer length next UTF-8 code point
char ** listDupS(char **list) MUST_CHECK
list Duplicate String
char ** split(const char *string, const char *delim) MUST_CHECK
split string with delim string when updating this function, also update splitS (identical to split) r...
rune tolowerUTF8(rune c) MUST_CHECK
rune tolower UTF8
char * icReplaceUTF8(const char *s, const char *olds, const char *news, size_t max) MUST_CHECK
ssize_t icIndexOfCharS(const char *string, char c) MUST_CHECK
int(* shCmpt)(const void *a, const void *b)
char * bGetHomePath(char *path) MUST_CHECK
copy home path to path
char * ellipsisStartCharS(const char *string, size_t targetLength, char ellipsisChar) MUST_CHECK
ellipsis start string
char * upperUTF8(const char *string) MUST_CHECK
upper case UTF-8 encoded string duplicate string
char * iUpperUTF8(char **string) MUST_CHECK
upper case UTF-8 encoded string
int commandfF(int line, const char *thisFunc, const char *thisFileName, const char *fmt,...) MUST_CHECK
run command with formatting in default shell
int commandF(const char *cmd, int line, const char *thisFunc, const char *thisFileName) MUST_CHECK
run command in default shell
char * toHexSepS(const void *buf, size_t len, const char *separator) MUST_CHECK
create a string with bytes in buf converted to hex strings separated by separator ...
void listFreeManySF(char **paramType,...)
list free many String
const char * prevUTF8(const char *utf8) MUST_CHECK
previous UTF-8 code point
bool isLink(const char *path) MUST_CHECK
is symbolic link
char * replaceCharCharS(const char *s, char olds, char news, size_t max) MUST_CHECK
fiberLT startL
fibers to start
char * iicReplaceS(char **s, const char *olds, const char *news, size_t max) MUST_CHECK
in place ignore case replace String the olds string is replaced with the news string max times in the...
void(* initLibsheepyObjectP)(void)
char ** iListCopyS(char **list, int64_t start, int64_t end) MUST_CHECK
list Copy String return new list with element pointers from start and end in list negative indexes ar...
char * catSF(const char *paramType,...) MUST_CHECK
cat String Function
char * bLJoin(char *string, size_t stringSize, char **list, const char *delim) MUST_CHECK
buffer size join list, the elements are seperated with delim in the resulting string ...
char * doubleToS(double n) MUST_CHECK
double To String
ssize_t readFile(const char *filePath, void **buffer) MUST_CHECK
read file to buffer
char * lTrimS(const char *string) MUST_CHECK
left trim String duplicate string
size_t lenS(const char *string) MUST_CHECK
length string
fibersT fibers
data for fiber system
char ** iListInjectS(char ***list, int64_t index, char *toInject) MUST_CHECK
list Inject string
char * iicReplaceCharSS(char **s, char olds, const char *news, size_t max) MUST_CHECK
char * iRTrimS(char **string) MUST_CHECK
right trim String
ssize_t listIndexOfCS(const char **list, const char *string) MUST_CHECK
return index of string in const list
bool getLogShortPath(void) MUST_CHECK
get current log long/short path value
char * iReplaceManySF(char **string, char *paramType,...) MUST_CHECK
replace Many Strings the olds string is replaced with the news string max times in the result ...
int64_t bLPtr2NegIdxUTF8(const char *utf8, size_t utf8Size, const char *pos) MUST_CHECK
buffer size pointer to negative code point index UTF8 encoded string
char ** iListAppendNSmashS(char ***list1, char **list2) MUST_CHECK
list Append and smash list2 Append list2 at the end of list1 by copying the pointers from list2 to li...
char ** systemOutf(const char *fmt,...) MUST_CHECK
execute system command with formatting
ssize_t indexOfUTF8(const char *string, const char *needle) MUST_CHECK
indexOf UTF8 encoded String relative to start
int ringIsFull(void *ring)
1 when full 0 not full -1 error
char * replaceCharSS(const char *s, char olds, const char *news, size_t max) MUST_CHECK
ssize_t listIndexOfS(char **list, const char *string) MUST_CHECK
return index of string in list
int systemf(const char *fmt,...) MUST_CHECK
execute system command with formatting
size_t listLength(void **list) MUST_CHECK
list Length return number of elements until the first NULL element
char ** iListEmptySF(char ***list) MUST_CHECK
list Empty String Function
char * escapeS(const char *s, char delim) MUST_CHECK
escape string according the json specification (RFC 8259) if there is in the string, the backslash is escaped and it will be parsed as the string '' be the json parsers the unicode characters should be converted to UTF8 codepoints instead of using the result can be included in a json string and the parsing will be correct
int ringEmpty(void *ring)
empty ring Allocated buffers in the list must be freed before running staticArrayEmpty ...
void * memdup(const void *buf, size_t size) MUST_CHECK
memory duplicate allocate and copy buffer
char * iUniqS(char **string, char c) MUST_CHECK
uniq String
bool isBlankS(const char *string) MUST_CHECK
is Blank String
void ** listPrepend(void ***list, void *s) MUST_CHECK
list Prepend
char * bLQuoteS(char *dest, size_t destSize, const char *s, char delim) MUST_CHECK
add backslash '\' before delim('\'' or '"') and backslash the backslashes in the result avoid splitti...
ssize_t ellipsisLenS(const char *string, size_t targetLength, const char *ellipsisString) MUST_CHECK
length of string after ellipsis
char ** listSortS(char **list) MUST_CHECK
list Sort String duplicate list and sort
int64_t getStackLimit(void) MUST_CHECK
get current stack limit
int ringPop(void *ring)
pop element from ring (only decreases last)
char ** listSliceS(char **list, int64_t start, int64_t end) MUST_CHECK
list Slice String return new list with elements from start and end in list negative indexes are allow...
char ** iListRemoveS(char ***list, int64_t start, int64_t end)
list Remove String return list without elements from start and end in list the elements are removed w...
void readEnter(void)
read Enter key wait until press the enter key
char * icReplaceSCharS(const char *s, const char *olds, char news, size_t max) MUST_CHECK
void setHardwareRandom(void)
use cpu hardware random number generator
bool listEqC1S(const char **list1, char **list2) MUST_CHECK
const(list1) list Equal String compare each element of list1 and list2
char * bLSliceS(char *string, size_t stringSize, int64_t start, int64_t end) MUST_CHECK
buffer size slice String return string which is the string between start and end negative indexes are...
char * iListCropElemS(char ***list, int64_t index) MUST_CHECK
list Crop Element String return element at index and delete element at index in the original list neg...
char * shDirname(const char *path) MUST_CHECK
sheepy dirname
bool zeroS(char *string) MUST_CHECK
write zero to all bytes in string with memset, for clearing password buffers
int writeLStream(FILE *fp, void *buffer, size_t len) MUST_CHECK
write buffer to file
char * iicReplaceSCharUTF8(char **s, const char *olds, char news, size_t max) MUST_CHECK
char * bDelElemS(char *string, int64_t index) MUST_CHECK
buffer delete element/character string
bool icEqIS(const char *string1, const char *string2, int64_t index) MUST_CHECK
ignore case string Index Equal compare string1 at index to string2 when string2 is empty...
int systemNFreeF(char *command, int line, const char *thisFunc, const char *thisFileName) MUST_CHECK
run system command and free command buffer a message is printed when an error occurs ...
char * bPadEndCharS(char *dest, const char *string, size_t targetLength, char padChar) MUST_CHECK
pad end string
void listFreeManyF(void **paramType,...)
list free many
char * iSliceUTF8(char **string, int64_t start, int64_t end) MUST_CHECK
slice UTF8 encoded String return string which is the string between start and end negative indexes ar...
char * bCEscapeS(char *dest, const char *S) MUST_CHECK
escape string to become a valid C source string control characters, backslash and double quotes are e...
char * strNCpyUTF8(char *dst, const char *src, size_t srcLen) MUST_CHECK
strNCpyUTF8 - copy src to dst with srcLen in code points
char * iEmptySF(char **string) MUST_CHECK
empty String Function
char ** iListAppendS(char ***list1, char **list2) MUST_CHECK
in place list Append String Append list2 at the end of list1 by copying the pointers from list2 to li...
char * bUpperS(char *string) MUST_CHECK
buffer upper case String
char * bLRelPath(char *dest, size_t destSize, char *path, const char *start) MUST_CHECK
relative path
char * toHexS(const void *buf, size_t len) MUST_CHECK
create a string with bytes in buf converted to hex strings
double parseDouble(const char *string) MUST_CHECK
convert string to double
char * readS(void) MUST_CHECK
read String read user input (one line) as a string
time_t getModificationTime(const char *path) MUST_CHECK
get modification time for path
char iCropElemS(char **string, int64_t index) MUST_CHECK
char * iUniqUTF8(char **string, const char *code) MUST_CHECK
uniq UTF-8 String
time_t getCurrentUnixTime(void) MUST_CHECK
get current unix time in seconds
char * bLEllipsisStartCharS(char *dest, size_t destSize, const char *string, size_t targetLength, char ellipsisChar) MUST_CHECK
ellipsis start string
int64_t bLPtr2IdxUTF8(const char *utf8, size_t utf8Size, const char *pos) MUST_CHECK
buffer size pointer to code point index UTF8 encoded string
char * iAppendManySF(char **string, const char *paramType,...) MUST_CHECK
append many strings
int listPrintS(char **list) MUST_CHECK
print list elements to stdout
char * bLowerUTF8(char *string) MUST_CHECK
bool icEndsWithUTF8(const char *string1, const char *string2) MUST_CHECK
ignore case ends With UTF8 encoded String compare end of string1 with string2
char ** icListSortS(char **list) MUST_CHECK
ignore case list Sort String duplicate list and sort
bool listHasS(char **list, const char *string) MUST_CHECK
return true when list has string
char ** icListUniqS(char **list) MUST_CHECK
ignore case and uniquify elements of list duplicate list each elements are unique in the new list ...
char * bDelS(char *string, int64_t start, int64_t end) MUST_CHECK
buffer delete string
char * bDelUTF8(char *string, int64_t start, int64_t end) MUST_CHECK
buffer delete UTF8 encoded string
char * lowerUTF8(const char *string) MUST_CHECK
lower case UTF-8 String duplicate string
void ** listReverse(void **list) MUST_CHECK
list Reverse create index list and reverse list, the last element is the first element of the new lis...
char ** listDelS(char **list, int64_t start, int64_t end) MUST_CHECK
list Delete String return new list without elements from start and end in list negative indexes are a...
ssize_t icListBinarySearchS(char **list, const char *string) MUST_CHECK
ignore case list binary search string
char ** listFromArrayS(char **array, size_t size) MUST_CHECK
list From Array String
char * bLDelUTF8(char *string, size_t stringSize, int64_t start, int64_t end) MUST_CHECK
buffer size delete UTF8 encoded string
void * listDequeue(void ***list) MUST_CHECK
list Dequeue return first element from list and remove last element from the list ...
char ** readDir(const char *dirPath) MUST_CHECK
list files in a directory and sort the list
void ** listInsert(void **list, int64_t index, void **toInsert) MUST_CHECK
list Insert
int setModificationTime(const char *path, time_t mtime) MUST_CHECK
set modification time for path
bool listEqS(char **list1, char **list2) MUST_CHECK
list Equal String compare each element of list1 and list2
int writeStreamS(FILE *fp, const char *string) MUST_CHECK
write string to file
char * bExpandHome(char *path) MUST_CHECK
buffer expands ~/ ($HOME) or ~USER
char ** iListInjectCharS(char ***list, int64_t index, char toInject) MUST_CHECK
char * bLicReplaceManyUTF8F(char *s, size_t sSize, char *paramType,...) MUST_CHECK
char ** listAddS(char **list1, char **list2)
list Add String add list1 and list2 in a new list
char ** iListSortFS(char ***list, shCmpt compareFunction) MUST_CHECK
list Sort String
char * bDoubleToS(char *s, double n) MUST_CHECK
buffer double To String
char * icTokS(char *s, const char *delim, char **saveptr) MUST_CHECK
ignore case token in String
int getLogMode(void) MUST_CHECK
get current log mode (verbose, concise)
char * bFormatS(char *string, const char *fmt,...) MUST_CHECK
format and store in string: bFormatS(string, "Value %d", i);
char * insertNFreeUTF8(const char *string, int64_t index, char *toInsert) MUST_CHECK
insert string in UTF8 encoded string at index and free toInsert
const char * nextUTF8(const char *utf8) MUST_CHECK
next UTF-8 code point
ssize_t icCountS(const char *s, const char *needle) MUST_CHECK
ignore case count String count number of (non-overlapping) occurrences of a substring ...
char ** listInsertS(char **list, int64_t index, char **toInsert) MUST_CHECK
list Insert string
uint64_t shStopwatch(uint8_t op)
nanosecond stopwatch
char * bRepeatCharS(char *dest, char c, size_t count) MUST_CHECK
repeat char count times
bool icListEqUTF8(char **list1, char **list2) MUST_CHECK
ignore case list Equal UTF8 encoded String compare each element of list1 and list2 ...
void shPrintfS(const char *fmt,...)
sheepy Print String
char ** listCatSF(char **paramType,...) MUST_CHECK
list Cat String
char * icReplaceManyUTF8F(const char *paramType,...) MUST_CHECK
char * iInsertNFreeUTF8(char **string, int64_t index, char *toInsert) MUST_CHECK
insert string in UTF8 encoded string at index and free toInsert
char * bEllipsisEndCharS(char *dest, const char *string, size_t targetLength, char ellipsisChar) MUST_CHECK
ellipsis end string
char * iInsertNFreeS(char **string, int64_t index, char *toInsert) MUST_CHECK
insert string in string at index and free toInsert
bool fileChmod(const char *filePath, mode_t mode) MUST_CHECK
like chmod in stdlibc but return true/false
char ** icExtractSCharS(const char *string, const char *delim1, char delim2) MUST_CHECK
char * iReplaceSCharS(char **s, const char *olds, char news, size_t max) MUST_CHECK
char * bRTrimS(char *string) MUST_CHECK
buffer right trim String
bool icStartsWithCharS(const char *string1, char c) MUST_CHECK
void ** listCreateF(void *paramType,...) MUST_CHECK
list Create Function create a list from the list of parameters used from the listCreate(...) macro
bool icListHasCharS(char **list, char c) MUST_CHECK
char ** icSplit(const char *string, const char *delim) MUST_CHECK
ignore case split string with delim string when updating this function, also update icSplitS (identic...
char ** listInjectCharS(char **list, int64_t index, char toInject) MUST_CHECK
char * bJoinChar(char *string, char **list, char delim) MUST_CHECK
char * bNMakeValidUTF8(char *dst, const char *utf8, size_t utf8Len) MUST_CHECK
buffer length make valid UTF-8 encoded string
char * iRelPath(char **path, const char *start) MUST_CHECK
relative path
char * swapS(char *string, int64_t index1, int64_t index2) MUST_CHECK
swap characters in string
char * icReplaceS(const char *s, const char *olds, const char *news, size_t max) MUST_CHECK
ignore case Replace String the original remains unchanged duplicate s the olds string is replaced wit...
ssize_t icListBinarySearchUTF8(char **list, const char *string) MUST_CHECK
ignore case list binary search UTF8 encoded string
char * bLFormatS(char *string, size_t stringSize, const char *fmt,...) MUST_CHECK
format and store in string: bLFormatS(string, sizeof(string), "Value %d", i);
int writeFile(const char *filePath, void *buffer, size_t len) MUST_CHECK
write buffer to file
char * appendS(const char *string1, const char *string2) MUST_CHECK
append strings
char * bLicReplaceManySF(char *s, size_t sSize, char *paramType,...) MUST_CHECK
buffer size ignore case replace Many Strings the olds string is replaced with the news string max tim...
char * intToS(int64_t n) MUST_CHECK
int To String
char * bLInsertUTF8(char *string, size_t stringSize, int64_t index, const char *toInsert) MUST_CHECK
buffer size insert string in UTF8 encoded string at index
bool startsWithS(const char *string1, const char *string2) MUST_CHECK
starts With String compare start of string1 with string2
char * iInjectS(char **string, int64_t index, char toInject) MUST_CHECK
inject a char in string at index
void ** listFromArray(void **array, size_t size) MUST_CHECK
list From Array
char * toHexHeadSepS(const void *buf, size_t len, const char *head, const char *separator) MUST_CHECK
create a string with bytes in buf converted to hex strings separated by separator and with head strin...
int64_t bPtr2IdxUTF8(const char *start, const char *utf8, const char *pos) MUST_CHECK
buffer pointer to code point index UTF8 encoded string
char * strLCpyUTF8(char *dst, size_t dstSize, const char *src) MUST_CHECK
strLCpyUTF8 - copy src to dst
char * bInjectS(char *string, int64_t index, char toInject) MUST_CHECK
buffer inject a char in string at index
char * iLTrimS(char **string) MUST_CHECK
left trim String
char * icTokUTF8(const char *s, const char *delim, char **saveptr) MUST_CHECK
char * bLJoinChar(char *string, size_t stringSize, char **list, char delim) MUST_CHECK
const char * bLIdx2PtrUTF8(const char *utf8, size_t utf8Size, int64_t index) MUST_CHECK
char ** iListUniqS(char ***list) MUST_CHECK
Uniquify elements of list each elements are unique in the list.
char * bStripColorsS(char *string) MUST_CHECK
remove terminal control char from string
ssize_t repeatLenS(const char *string, size_t count) MUST_CHECK
length of string repeated count times
char * icReplaceSCharUTF8(const char *s, const char *olds, char news, size_t max) MUST_CHECK
rune code2RuneLUTF8(const char *code, uint8_t *n) MUST_CHECK
UTF-8 code point to rune and length.
char * bLEllipsisEndCharS(char *dest, size_t destSize, const char *string, size_t targetLength, char ellipsisChar) MUST_CHECK
ellipsis end string
bool isExecutable(const char *path) MUST_CHECK
is path executable
int setStackLimit(int64_t stackSize) MUST_CHECK
set stack limit
char * iPrependS(char **string1, const char *string2) MUST_CHECK
prepend strings
char * iicReplaceCharCharS(char **s, char olds, char news, size_t max) MUST_CHECK
char * iLowerUTF8(char **string) MUST_CHECK
lower case String
char * iPadEndS(char **string, size_t targetLength, const char *padString) MUST_CHECK
pad end string
char ** icExtractCharSS(const char *string, char delim1, const char *delim2) MUST_CHECK
void ** listDel(void **list, int64_t start, int64_t end) MUST_CHECK
list Delete return new list without elements from start and end in list negative indexes are allowed ...
ssize_t icListBinarySearchCharS(char **list, char c) MUST_CHECK
char * bicReplaceManyUTF8F(char *s, char *paramType,...) MUST_CHECK
char * repeatS(const char *string, size_t count) MUST_CHECK
repeat string count times
ssize_t fileSize(const char *filePath) MUST_CHECK
get file size
char * iicReplaceUTF8(char **s, const char *olds, const char *news, size_t max) MUST_CHECK
bool icEndsWithS(const char *string1, const char *string2) MUST_CHECK
ignore case ends With String compare end of string1 with string2
char * iPrependNFreeS(char **string1, char *string2) MUST_CHECK
prepend and free strings
bool icEqICharS(const char *string1, char c, int64_t index) MUST_CHECK
char ** listShiftS(char ***list1, char **list2) MUST_CHECK
list Shift String Append list2 at the start of list1
char * bRelPath(char *dest, const char *path, const char *start) MUST_CHECK
relative path
char * stripCtrlS(const char *string) MUST_CHECK
remove terminal control char from string
char * iCropS(char **string, int64_t start, int64_t end) MUST_CHECK
Crop String return a new string with characters from start and end in string and delete characters fr...
const char * getCHomePath(void) MUST_CHECK
get home path as a const char*
char getS(const char *string, int64_t index) MUST_CHECK
get string
char * icFindCharS(const char *string, char c) MUST_CHECK
ssize_t icCountUTF8(const char *s, const char *needle) MUST_CHECK
ignore case count UTF8 encoded String count number of (non-overlapping) occurrences of a substring ...
int64_t parseI64(const char *string) MUST_CHECK
convert string to decimal integer
char ** listSortFS(char **list, shCmpt compareFunction) MUST_CHECK
list Sort String duplicate list and sort
int commandNFreeF(char *cmd, int line, const char *thisFunc, const char *thisFileName) MUST_CHECK
run command in default shell and free the cmd parameter
bool zeroBuf(void *buf, size_t len) MUST_CHECK
write zero to all bytes in buffer with memset
char * iEllipsisStartS(char **string, size_t targetLength, const char *ellipsisString) MUST_CHECK
ellipsis start string
char * bicReplaceManySF(char *s, char *paramType,...) MUST_CHECK
buffer ignore case replace Many Strings the olds string is replaced with the news string max times in...
char * iPadStartCharS(char **string, size_t targetLength, char padChar) MUST_CHECK
pad start string
ssize_t ringCount(void *ring)
return elements count
void listFreeS(char **list)
list Free String
char * bLReplaceManySF(char *s, size_t sSize, char *paramType,...) MUST_CHECK
buffer size replace Many Strings the olds string is replaced with the news string max times in the re...
uint64_t getMonotonicTime(void) MUST_CHECK
end bitfield
size_t lenUTF8(const char *s) MUST_CHECK
character length of UTF-8 string
char * bMakeValidUTF8(char *utf8) MUST_CHECK
buffer make valid UTF-8 encoded string
mode_t getCurrentPermissions(void) MUST_CHECK
get current permissions for creating directories
int64_t parseInt(const char *string) MUST_CHECK
convert string to decimal integer
char * getCurrentDate(void) MUST_CHECK
get current date in ctime format (Wed Dec 12 11:44:08 2018)
ssize_t icIndexOfS(const char *string, const char *needle) MUST_CHECK
ignore case indexOf String relative to start
char ** listSetS(char **list, int64_t index, const char *s) MUST_CHECK
list Set String duplicate string and store at given index, the existing element is freed index can be...
bool isCodeUTF8(const char *code) MUST_CHECK
is code point UTF8 encoded string
bool listIsEmpty(void **list) MUST_CHECK
list Is Empty
bool icEqICharUTF8(const char *string1, char c, int64_t index) MUST_CHECK
FILE *SH_PREFIX() setLogFile(char *filename)
set log file the logs are appended to all log files set with this function
void * listGet(void **list, int64_t index) MUST_CHECK
list Get
bool writeText(const char *filePath, char **list) MUST_CHECK
write list to filePath
char * bLPadStartS(char *dest, size_t destSize, const char *string, size_t targetLength, const char *padString) MUST_CHECK
pad start string
char * bInsertUTF8(char *string, int64_t index, const char *toInsert) MUST_CHECK
buffer insert string in UTF8 encoded string at index
char ** iicListSortUTF8(char ***list) MUST_CHECK
ignore case list Sort UTF8 encoded String
bool icEqS(const char *string1, const char *string2) MUST_CHECK
ignore case string Equal compare string1 to string2
char * bLTimeToYMDS(char *dst, size_t dstSize, const time_t t) MUST_CHECK
bool appendFileS(const char *filePath, const char *string) MUST_CHECK
append string to filePath
size_t bRune2CodeUTF8(char *dst, rune c) MUST_CHECK
rune to UTF-8 code point
char * cEscapeS(const char *S) MUST_CHECK
escape string to become a valid C source string control characters, backslash and double quotes are e...
char ** listPushS(char ***list, const char *s) MUST_CHECK
list Push String append s at the end of the list when list is NULL, a new list with one element is re...
char * bPrependS(char *string1, const char *string2) MUST_CHECK
buffer prepend strings
uint64_t randomWord(void) MUST_CHECK
return random 64 bit unsigned integer call randomUrandomOpen before this calling function ...
char ** iListPushS(char ***list, char *s) MUST_CHECK
list Push String append s pointer at the end of the list when list is NULL, a new list with one eleme...
double parseDoubleChar(char c) MUST_CHECK
char * strLNCat(char *restrict dst, size_t dstSize, const char *restrict src, size_t srcLen) MUST_CHECK
strLNCat - concatenate two strings
char * lowerS(const char *string) MUST_CHECK
lower case String duplicate string
i64 ringPush(void *ring)
push element to ring (only increases last, use ringSend) use ringLast to access the element ...
char * iReplaceCharCharS(char **s, char olds, char news, size_t max) MUST_CHECK
bool icEqIUTF8(const char *string1, const char *string2, int64_t index) MUST_CHECK
void freeRealProgPath(void)
free real program path finalizeLibsheepy calls this function
ssize_t icListIndexOfCharCS(const char **list, char c) MUST_CHECK
char * bLGetHomePath(char *path, size_t pathSize) MUST_CHECK
copy home path to path maximum pathSize
void setLogShortPath(bool shortPath)
set log long/short file path value for VERBOSE mode
char * prependS(const char *string1, const char *string2) MUST_CHECK
prepend strings
char ** readStream(FILE *fp) MUST_CHECK
return text from stream fp in a list new line characters are removed
bool startsWithCharS(const char *string1, char c) MUST_CHECK
char * bDirname(char *path) MUST_CHECK
buffer dirname
int shMove(const char *src, const char *dst) MUST_CHECK
move files recursively
char * uniqS(const char *string, char c) MUST_CHECK
uniq String duplicate string
char ** icListUniqUTF8(char **list) MUST_CHECK
ignore case and uniquify UTF8 encoded elements of list duplicate list each elements are unique in the...
size_t listLengthCS(const char **list) MUST_CHECK
const list Length String return number of elements until the first NULL element
const char * iListGetCS(const char **list, int64_t index) MUST_CHECK
const list Get String index can be negative
char * strNCatUTF8(char *dst, const char *src, size_t srcLen) MUST_CHECK
strNCatUTF8 - concatenate two UTF-8 encoded strings
char * padEndCharS(const char *string, size_t targetLength, char padChar) MUST_CHECK
pad end string
rune getUTF8(const char *string, int64_t index) MUST_CHECK
get UTF8 encoded string
char * bLExpandHome(char *path, size_t pathSize) MUST_CHECK
buffer size expands ~/ ($HOME) or ~USER
char * bLTrimS(char *string) MUST_CHECK
buffer left trim String
char ** listAddCS(char **list1, const char **list2)
const list Add String add list1 and list2 in a new list
bool listHasCharCS(const char **list, char c) MUST_CHECK
char * iicReplaceSCharS(char **s, const char *olds, char news, size_t max) MUST_CHECK
ssize_t indexOfCharS(const char *string, char c) MUST_CHECK
char ** listInjectS(char **list, int64_t index, char *toInject) MUST_CHECK
list Inject string
char * insertS(const char *string, int64_t index, const char *toInsert) MUST_CHECK
insert string in string at index
bool btraceConfig(void) MUST_CHECK
char * icUniqUTF8(const char *string, const char *code) MUST_CHECK
char * bPadStartCharS(char *dest, const char *string, size_t targetLength, char padChar) MUST_CHECK
pad start string
ssize_t icListIndexOfUTF8(char **list, const char *string) MUST_CHECK
ignore case and return index of UTF8 encoded string in list
char ** iicListUniqS(char ***list) MUST_CHECK
ignore case and uniquify elements of list each elements are unique in the list
size_t replaceSLen(const char *s, const char *olds, const char *news, size_t max) MUST_CHECK
replaceSLen returns the length of the resulting string
char * bLGetCurrentDateYMD(char *dst, size_t dstSize) MUST_CHECK
char * strLNCatUTF8(char *dst, size_t dstSize, const char *src, size_t srcLen) MUST_CHECK
strLNCatUTF8 - concatenate two UTF-8 encoded strings
char * bIntToS(char *s, int64_t n) MUST_CHECK
buffer int To String
char ** listAddrS(char **list, int64_t index) MUST_CHECK
list address String index can be negative
bool listEqCS(char **list1, const char **list2) MUST_CHECK
const(list2) list Equal String compare each element of list1 and list2
char * padEndS(const char *string, size_t targetLength, const char *padString) MUST_CHECK
pad end string
int chDir(const char *path) MUST_CHECK
change directory
const char * getProgName(void) MUST_CHECK
get program name
char * icReplaceCharCharS(const char *s, char olds, char news, size_t max) MUST_CHECK
char * bLCatSF(char *dst, size_t dstSize, const char *paramType,...) MUST_CHECK
cat and copy String Function
bool listIsEmptyS(char **list) MUST_CHECK
list Is Empty String
char ** listCompactS(char **list) MUST_CHECK
remove empty strings from list
int copy(const char *src, const char *dst) MUST_CHECK
copy files recursively This function is equivalent to 'cp -Ra' without wildcards and circular link de...
bool btraceCfg
backtrace in error messages is enabled by default
char ** iicListUniqUTF8(char ***list) MUST_CHECK
ignore case and uniquify UTF8 encoded elements of list each elements are unique in the list ...
void shEPrintfS(const char *fmt,...)
sheepy Error printf String print with logE
int mkdirParents(const char *path) MUST_CHECK
recursive mkdir
char ** readDirDir(const char *dirPath) MUST_CHECK
list directories in a directory and sort the list
char * joinCS(const char **list, const char *delim) MUST_CHECK
join list, the elements are seperated with delim in the resulting string
const char * idx2PtrUTF8(const char *utf8, int64_t index) MUST_CHECK
index to pointer UTF8 encoded string
int ringDequeue(void *ring)
dequeue element from ring (only increases head, use ringRecv)
char ** iListShiftNSmashS(char ***list1, char **list2) MUST_CHECK
list Append and smash list2 Append list2 at the start of list1 by copying the pointers from list2 to ...
char * bLNMakeValidUTF8(char *dst, size_t dstSize, const char *utf8, size_t utf8Len) MUST_CHECK
buffer destination size source length make valid UTF-8 encoded string
ssize_t intIndex(int64_t index, int64_t length)
int to positive index index can be negative
char * getCurrentDateYMD(void) MUST_CHECK
get current date in Y-m-d H:M:S format
bool hasCharS(const char *string, char c) MUST_CHECK
bool appendFile(const char *filePath, void *buffer, size_t len) MUST_CHECK
append buffer to file
char * bLPadEndS(char *dest, size_t destSize, const char *string, size_t targetLength, const char *padString) MUST_CHECK
pad end string
char * nMakeValidUTF8(const char *utf8, size_t utf8Len) MUST_CHECK
length make valid UTF-8 encoded string
char * iPadEndCharS(char **string, size_t targetLength, char padChar) MUST_CHECK
pad end string
char ** iicListSortS(char ***list) MUST_CHECK
ignore case list Sort String
char * bLNormalizePath(char *path, size_t pathSize) MUST_CHECK
buffer size normalize path
bool eqIUTF8(const char *string1, const char *string2, int64_t index) MUST_CHECK
UTF8 encoded string Index Equal compare string1 at character index to string2 when string2 is empty...
bool listHasCS(const char **list, const char *string) MUST_CHECK
return true when const list has string
char * bLPrependS(char *string1, size_t string1Size, const char *string2) MUST_CHECK
buffer prepend strings
char * ellipsisEndS(const char *string, size_t targetLength, const char *ellipsisString) MUST_CHECK
ellipsis end string
void randomUrandomClose(void)
close /dev/urandom in libsheepy call this function when random are not needed anymore ...
char * iLowerS(char **string) MUST_CHECK
lower case String
bool icListEqCS(char **list1, const char **list2) MUST_CHECK
ignore case const(list2) list Equal String compare each element of list1 and list2 ...
char * bLPadEndCharS(char *dest, size_t destSize, const char *string, size_t targetLength, char padChar) MUST_CHECK
pad end string
ssize_t icCountCharS(const char *s, char c) MUST_CHECK
void * readStreamToS(FILE *fp) MUST_CHECK
read file to string
data type for fiber system
bool isDir(const char *path) MUST_CHECK
is directory
bool isUTF8(const char *string) MUST_CHECK
is UTF-8 string
char ** iListSwapS(char **list, int64_t index1, int64_t index2) MUST_CHECK
swap elements in list
bool icListHasCS(const char **list, const char *string) MUST_CHECK
ignore case and return true when const list has string
char * bicReplaceS(char *s, const char *olds, const char *news, size_t max) MUST_CHECK
buffer ignore case replace String the olds string is replaced with the news string max times in the r...
char * bGetCurrentDateYMD(char *dst) MUST_CHECK
char * trimS(const char *string) MUST_CHECK
trim String duplicate string
char * bNormalizePath(char *path) MUST_CHECK
buffer normalize path
char * bLInjectS(char *string, size_t stringSize, int64_t index, char toInject) MUST_CHECK
buffer size inject a char in string at index
ssize_t indexOfS(const char *string, const char *needle) MUST_CHECK
indexOf String relative to start
int ringIsEmpty(void *ring)
1 when empty 0 not empty -1 error
bool icListEqS(char **list1, char **list2) MUST_CHECK
ignore case list Equal String compare each element of list1 and list2
char * readPasswordS(void) MUST_CHECK
read hidden password string
void listFree(void **list)
list Free
char * bRepeatS(char *dest, const char *string, size_t count) MUST_CHECK
repeat string count times
char * iRepeatS(char **string, size_t count) MUST_CHECK
repeat string count times
char * bLInsertS(char *string, size_t stringSize, int64_t index, const char *toInsert) MUST_CHECK
buffer size insert string in string at index
void * listPop(void ***list) MUST_CHECK
list Pop return last element from list and remove last element from the list
char * bLGetCwd(char *path, size_t pathSize) MUST_CHECK
bool setProgName(const char *name) MUST_CHECK
set program name
char * bAppendManySF(char *string, const char *paramType,...) MUST_CHECK
buffer append many strings
bool hasCtrlChar(const char *string) MUST_CHECK
has control char
void ** listCatF(void **paramType,...) MUST_CHECK
list Cat
bool icHasUTF8(const char *string, const char *needle) MUST_CHECK
ignore case has UTF8 encoded String
int listPrintCS(const char **list) MUST_CHECK
char ** icExtractCharSUTF8(const char *string, char delim1, const char *delim2) MUST_CHECK
char ** extractS(const char *string, const char *delim1, const char *delim2) MUST_CHECK
extract string between delim1 and delim2 strings return list
char * bSwapS(char *string, int64_t index1, int64_t index2) MUST_CHECK
swap characters in string
char ** iListSortS(char ***list) MUST_CHECK
list Sort String
bool icHasCharS(const char *string, char c) MUST_CHECK
ssize_t bLReadFile(const char *filePath, void *buffer, size_t dstSize) MUST_CHECK
buffer size read file to buffer
all contexts must start with fiberBaseT
char * joinChar(char **list, char delim) MUST_CHECK
char ** extractCharCharS(const char *string, char delim1, char delim2) MUST_CHECK
char * iReplaceS(char **s, const char *olds, const char *news, size_t max) MUST_CHECK
replace String the olds string is replaced with the news string max times in the result 0 for max mea...
bool writeCText(const char *filePath, const char **list) MUST_CHECK
write const list to filePath
char * sliceS(const char *string, int64_t start, int64_t end) MUST_CHECK
slice String return new string which is the string between start and end negative indexes are allowed...
bool eqSChar(const char *string1, char c) MUST_CHECK
char * padStartS(const char *string, size_t targetLength, const char *padString) MUST_CHECK
pad start string
void freeProgName(void)
free ProgName if set with setProgName
char * getHomePath(void) MUST_CHECK
get home path
char * bJoin(char *string, char **list, const char *delim) MUST_CHECK
buffer join list, the elements are seperated with delim in the resulting string
bool icEndsWithCharS(const char *string1, char c) MUST_CHECK
char ** listPushCharS(char ***list, char c) MUST_CHECK
bool isEmptyS(const char *string) MUST_CHECK
is Empty String
bool endsWithCharS(const char *string1, char c) MUST_CHECK
char * join(char **list, const char *delim) MUST_CHECK
join list, the elements are seperated with delim in the resulting string when updating this function...
bool openProgLogFile(void) MUST_CHECK
log to a file named progName.log Use closeLogFiles when finished logging
#define maxTryThrowCount
setjmp buffers for try/throw,throwV macros
char * iCatSF(char *dst, const char *paramType,...) MUST_CHECK
cat and copy String Function dst has to be big enough to hold the result