commit 4ccb4563ad982f3076e440e7c8dd92d80ad438c1
parent e64b5cf4ca2cb7e6a30db882054b1781cd1e6306
Author: Remy Noulin <loader2x@gmail.com>
Date: Thu, 24 Mar 2022 22:28:20 +0200
add setSmallBytes in setG, add openLogFile, use memmove in slice macros, add staticArrayDelElem macro, rename bt, vbt and dbt structs to btt, vbtt, dbtt (to avoid name collision with bt: button in gui code), add keepAnsiColorsInLog() to keep or remove colors in logs, stripColorsS, iStripColorsS, bStripColorsS to remove ansi colors
README.md | 2 +-
release/json/libsheepyCSmallBytes.h | 1 +
release/libsheepy.c | 261 ++++-
release/libsheepy.h | 67 +-
release/libsheepyBt.c | 266 ++---
release/libsheepyBt.h | 620 +++++------
release/libsheepyObject.h | 110 +-
src/json/libsheepyCSmallBytes.c | 6 +
src/json/libsheepyCSmallBytes.h | 1 +
src/libsheepy.c | 2030 ++++++++++++++++++++---------------
src/libsheepy.h | 67 +-
src/libsheepyBt.c | 266 ++---
src/libsheepyBt.h | 620 +++++------
src/libsheepyObject.h | 110 +-
14 files changed, 2513 insertions(+), 1914 deletions(-)
Diffstat:
14 files changed, 2513 insertions(+), 1914 deletions(-)
diff --git a/README.md b/README.md
@@ -62,7 +62,7 @@ libsheepy is NULL safe and any parameter can be NULL.
- the list*S functions assume the list elements are not NULL
- the listn*S functions can process lists with NULL elements. When there are NULL elements, the developer has to keep track of the list length.
-Check out the [user guide](http://spartatek.se/libsheepyUserGuide/) to learn how to use libsheepy and read the more detailed documentation at [http://spartatek.se/libsheepy/](http://spartatek.se/libsheepy/)
+Check out the [user guide](https://spartatek.se/libsheepyUserGuide/) to learn how to use libsheepy and read the more detailed documentation at [https://spartatek.se/libsheepy/](https://spartatek.se/libsheepy/)
__Status__: (libsheepy.h and libsheepy.c)
- Unit tests: 97% code coverage of the core functionality - 98% branch coverage (mainly malloc failures are not tested)
diff --git a/release/json/libsheepyCSmallBytes.h b/release/json/libsheepyCSmallBytes.h
@@ -300,6 +300,7 @@ smallBytest* duplicateSmallBytesG (smallBytest *self);
void freeSmallBytesG (smallBytest *self);
+smallBytest* setSmallBytesG(smallBytest *self, void *data, uint32_t size);
char getAtSmallBytesG(smallBytest *self, char retType UNUSED, int64_t index);
smallBytest* pushSmallBytesG (smallBytest *self, char data);
size_t lenSmallBytesG(smallBytest *self);
diff --git a/release/libsheepy.c b/release/libsheepy.c
@@ -96,6 +96,7 @@ void setLogShortPath(bool shortPath);
bool getLogStdout(void);
void setLogStdout(bool state);
bool openProgLogFile(void);
+void keepAnsiColorsInLog(bool state);
void _pLog(int loglevel, const char *file, const char *func, int line, const char *msg, ...);
#if (!(__APPLE__ || __FreeBSD__ || __TERMUX__ || __OpenBSD__ || __DragonFly__ || MUSL_LIBC || __sun__ || __HAIKU__))
int print_k(FILE *stream, const struct printf_info *info, const void *const *args);
@@ -339,6 +340,9 @@ bool hasCtrlChar(const char *string);
char *stripCtrlS(const char *string);
char *iStripCtrlS(char **string);
char *bStripCtrlS(char *string);
+char *stripColorsS(const char *string);
+char *iStripColorsS(char **string);
+char *bStripColorsS(char *string);
bool isNumber(const char *string);
bool isInt(const char *string);
int64_t parseInt(const char *string);
@@ -953,6 +957,8 @@ static bool _log_verbose_short_path = true;
static bool _logToStdout = true;
+static bool keepAnsiColors = true;
+
// logging file 0 is stdout
static uint16_t _current_log_file = 1;
@@ -1156,6 +1162,16 @@ bool openProgLogFile(void) {
return(true);
}
+/**
+ * enable/disable ansi color codes in logs
+ *
+ * TRUE: print colors
+ * FALSE: strip colors
+ */
+void keepAnsiColorsInLog(bool state) {
+
+ keepAnsiColors = state;
+}
/**
* print logging levels
@@ -1212,7 +1228,7 @@ void _pLog(int loglevel, const char *file, const char *func, int line, const cha
}
// set console color for printing the tag
- if (_logToStdout) {
+ if (_logToStdout && keepAnsiColors) {
switch (loglevel) {
case LOG_EMERGENCY:
printf(BLD RED);
@@ -1248,6 +1264,12 @@ void _pLog(int loglevel, const char *file, const char *func, int line, const cha
}
}
+ if (!keepAnsiColors) {
+ if (!bStripColorsS(buffer)) {
+ return;
+ }
+ }
+
// long or short file path in VERBOSE mode
if ((_log_current_mode == LOG_VERBOSE) && _log_verbose_short_path) {
const char *slashP[3] = {NULL, NULL, NULL};
@@ -9498,6 +9520,243 @@ char *bStripCtrlS(char *string) {
}
/**
+ * remove ansi colors from string
+ *
+ * \param
+ * string
+ * \return
+ * new string without colors
+ * NULL when string is NULL
+ */
+char *stripColorsS(const char *string) {
+ char *r = NULL;
+
+ if (!string) {
+ return(NULL);
+ }
+
+ size_t len = strlen(string)+1;
+ r = MALLOC(len);
+ if (!r) {
+ return(NULL);
+ }
+
+ size_t j = 0;
+ uint16_t state = 0;
+ range(i, len) {
+ char ch = string[i];
+ // suppress \r only when followed by \n
+ if (state == 1) {
+ if (ch != 0x0d) {
+ state = 0;
+ }
+ if (ch != 0x0a) {
+ r[j++] = 0x0d;
+ }
+ }
+ if (state == 0 && ch == 0x0d) {
+ state = 1;
+ }
+ // strip colors
+ if (state == 5) {
+ state = 0;
+ continue;
+ }
+ if (state == 4) {
+ if (ch == 7) {
+ state = 0;
+ continue;
+ }
+ elif (ch == 0x1b) {
+ state = 5;
+ }
+ }
+ if (state == 3) {
+ if (ch != ';' && (ch < '0' || ch > '9') && ch != '?') {
+ state = 0;
+ continue;
+ }
+ }
+ if (state == 2) {
+ if (ch == '[') {
+ state = 3;
+ }
+ elif (ch == ']' && string[i+1] <= '9') {
+ state = 4;
+ }
+ elif (ch == '%') {
+ state = 0;
+ continue;
+ }
+ }
+ if (state == 0 && ch == 0x1b) {
+ state = 2;
+ }
+ if (state == 0) {
+ r[j++] = ch;
+ }
+ }
+ r[j] = 0;
+ return(r);
+}
+
+/**
+ * remove ansi colors from string
+ *
+ * \param
+ * string pointer to a string
+ * \return
+ * string without the control chars
+ * NULL when string is NULL
+ */
+char *iStripColorsS(char **string) {
+
+ if (!string || !*string) {
+ return(NULL);
+ }
+
+ size_t i = 0, j = 0;
+ uint16_t state = 0;
+
+ while ((*string)[i]) {
+ char ch = (*string)[i];
+ // suppress \r only when followed by \n
+ if (state == 1) {
+ if (ch != 0x0d) {
+ state = 0;
+ }
+ if (ch != 0x0a) {
+ (*string)[j++] = 0x0d;
+ }
+ }
+ if (state == 0 && ch == 0x0d) {
+ state = 1;
+ }
+ // strip colors
+ if (state == 5) {
+ state = 0;
+ goto cont;
+ }
+ if (state == 4) {
+ if (ch == 7) {
+ state = 0;
+ goto cont;
+ }
+ elif (ch == 0x1b) {
+ state = 5;
+ }
+ }
+ if (state == 3) {
+ if (ch != ';' && (ch < '0' || ch > '9') && ch != '?') {
+ state = 0;
+ goto cont;
+ }
+ }
+ if (state == 2) {
+ if (ch == '[') {
+ state = 3;
+ }
+ elif (ch == ']' && (*string)[i+1] <= '9') {
+ state = 4;
+ }
+ elif (ch == '%') {
+ state = 0;
+ goto cont;
+ }
+ }
+ if (state == 0 && ch == 0x1b) {
+ state = 2;
+ }
+ if (state == 0) {
+ (*string)[j++] = ch;
+ }
+ cont:
+ i++;
+ }
+
+ (*string)[j] = 0;;
+ return(*string);
+}
+
+/**
+ * remove terminal control char from string
+ *
+ * \param
+ * string
+ * \return
+ * string without the control chars
+ * NULL when string is NULL
+ */
+char *bStripColorsS(char *string) {
+
+ if (!string) {
+ return(NULL);
+ }
+
+ size_t i = 0, j = 0;
+ uint16_t state = 0;
+
+ while (string[i]) {
+ char ch = string[i];
+ // suppress \r only when followed by \n
+ if (state == 1) {
+ if (ch != 0x0d) {
+ state = 0;
+ }
+ if (ch != 0x0a) {
+ string[j++] = 0x0d;
+ }
+ }
+ if (state == 0 && ch == 0x0d) {
+ state = 1;
+ }
+ // strip colors
+ if (state == 5) {
+ state = 0;
+ goto cont;
+ }
+ if (state == 4) {
+ if (ch == 7) {
+ state = 0;
+ goto cont;
+ }
+ elif (ch == 0x1b) {
+ state = 5;
+ }
+ }
+ if (state == 3) {
+ if (ch != ';' && (ch < '0' || ch > '9') && ch != '?') {
+ state = 0;
+ goto cont;
+ }
+ }
+ if (state == 2) {
+ if (ch == '[') {
+ state = 3;
+ }
+ elif (ch == ']' && string[i+1] <= '9') {
+ state = 4;
+ }
+ elif (ch == '%') {
+ state = 0;
+ goto cont;
+ }
+ }
+ if (state == 0 && ch == 0x1b) {
+ state = 2;
+ }
+ if (state == 0) {
+ string[j++] = ch;
+ }
+ cont:
+ i++;
+ }
+
+ string[j] = 0;;
+ return(string);
+}
+
+/**
* is Number (integer or float) String
*
* 1, -12
diff --git a/release/libsheepy.h b/release/libsheepy.h
@@ -98,7 +98,7 @@
// version accoring to the version package: Release.Major.minor.patch
// https://noulin.net/version/file/README.md.html
-#define LIBSHEEPY_VERSION "2.2.8.2"
+#define LIBSHEEPY_VERSION "2.2.9"
#ifndef SH_PREFIX
#define SH_PREFIX(NAME) NAME
@@ -974,6 +974,7 @@ uint64_t shStopwatch(uint8_t op);
// add a log file, maximum 15 files
FILE *SH_PREFIX(setLogFile)(char *filename);
+#define openLogFile setLogFile
#ifdef __GNUC__
/** force function callers to check return value
@@ -1021,6 +1022,9 @@ void setLogStdout(bool state);
// log to a file named progName.log
bool openProgLogFile(void) MUST_CHECK;
+// keep ansi colors in logs
+void keepAnsiColorsInLog(bool state);
+
/**
* print logging levels
*
@@ -2045,6 +2049,11 @@ char *stripCtrlS(const char *string) MUST_CHECK;
char *iStripCtrlS(char **string) MUST_CHECK;
char *bStripCtrlS(char *string) MUST_CHECK;
+// remove ansi colors from string
+char *stripColorsS(const char *string) MUST_CHECK;
+char *iStripColorsS(char **string) MUST_CHECK;
+char *bStripColorsS(char *string) MUST_CHECK;
+
// true when string is a number (integer or float)
bool isNumber(const char *string) MUST_CHECK;
@@ -3969,7 +3978,7 @@ void **iListDel(void ***list, int64_t start, int64_t end) MUST_CHECK;
var UNIQVAR(idx) = index;\
if ((size_t)UNIQVAR(idx) < (size_t)sliceLastIndex(name)) {\
/* move elements */\
- memcpy(slicePtr(name, UNIQVAR(idx)), slicePtr(name, UNIQVAR(idx) +1), ((name)->count - (UNIQVAR(idx) +1)) * sizeof (name)->array[0]);\
+ memmove(slicePtr(name, UNIQVAR(idx)), slicePtr(name, UNIQVAR(idx) +1), ((name)->count - (UNIQVAR(idx) +1)) * sizeof (name)->array[0]);\
}\
(name)->count--;\
} while(0)
@@ -3984,7 +3993,7 @@ void **iListDel(void ***list, int64_t start, int64_t end) MUST_CHECK;
var UNIQVAR(ed) = end;\
if (UNIQVAR(ed) < (name)->count and UNIQVAR(strt) < UNIQVAR(ed)) {\
/* move elements */\
- memcpy(slicePtr(name, UNIQVAR(strt)), slicePtr(name, UNIQVAR(ed)), ((name)->count - UNIQVAR(ed)) * sizeof (name)->array[0]);\
+ memmove(slicePtr(name, UNIQVAR(strt)), slicePtr(name, UNIQVAR(ed)), ((name)->count - UNIQVAR(ed)) * sizeof (name)->array[0]);\
}\
(name)->count -= UNIQVAR(ed) - UNIQVAR(strt);\
} while(0)
@@ -3997,7 +4006,7 @@ void **iListDel(void ***list, int64_t start, int64_t end) MUST_CHECK;
var UNIQVAR(vec) = slice;\
if (sizeof((name)->array[0]) == sizeof((UNIQVAR(vec))->array[0])) {\
sliceResize(name, (name)->count + (UNIQVAR(vec))->count);\
- memcpy((name)->array + (name)->count, (UNIQVAR(vec))->array, (UNIQVAR(vec))->count * sizeof (name)->array[0]);\
+ memmove((name)->array + (name)->count, (UNIQVAR(vec))->array, (UNIQVAR(vec))->count * sizeof (name)->array[0]);\
(name)->count += (UNIQVAR(vec))->count;\
}\
} while(0)
@@ -4011,7 +4020,7 @@ void **iListDel(void ***list, int64_t start, int64_t end) MUST_CHECK;
var UNIQVAR(a) = array;\
if (sizeof((name)->array[0]) == sizeof(*(UNIQVAR(a)))) {\
sliceResize(name, (name)->count + UNIQVAR(c));\
- memcpy((name)->array + (name)->count, UNIQVAR(a), UNIQVAR(c) * sizeof (name)->array[0]);\
+ memmove((name)->array + (name)->count, UNIQVAR(a), UNIQVAR(c) * sizeof (name)->array[0]);\
(name)->count += UNIQVAR(c);\
}\
} while(0)
@@ -4026,7 +4035,7 @@ void **iListDel(void ***list, int64_t start, int64_t end) MUST_CHECK;
if (sizeof((name)->array[0]) == sizeof((UNIQVAR(vec))->array[0])) {\
sliceResize(name, (name)->count + (UNIQVAR(vec))->count);\
memmove((name)->array + (UNIQVAR(vec))->count, (name)->array, (name)->count * sizeof (name)->array[0]);\
- memcpy((name)->array, (UNIQVAR(vec))->array, (UNIQVAR(vec))->count * sizeof (name)->array[0]);\
+ memmove((name)->array, (UNIQVAR(vec))->array, (UNIQVAR(vec))->count * sizeof (name)->array[0]);\
(name)->count += (UNIQVAR(vec))->count;\
}\
} while(0)
@@ -4042,7 +4051,7 @@ void **iListDel(void ***list, int64_t start, int64_t end) MUST_CHECK;
if (sizeof((name)->array[0]) == sizeof(*(UNIQVAR(a)))) {\
sliceResize(name, (name)->count + UNIQVAR(c));\
memmove((name)->array + UNIQVAR(c), (name)->array, (name)->count * sizeof (name)->array[0]);\
- memcpy((name)->array, UNIQVAR(a), UNIQVAR(c) * sizeof (name)->array[0]);\
+ memmove((name)->array, UNIQVAR(a), UNIQVAR(c) * sizeof (name)->array[0]);\
(name)->count += UNIQVAR(c);\
}\
} while(0);
@@ -4061,7 +4070,7 @@ void **iListDel(void ***list, int64_t start, int64_t end) MUST_CHECK;
else if (sizeof((name)->array[0]) == sizeof((UNIQVAR(vec))->array[0])) {\
sliceResize(name, (name)->count + (UNIQVAR(vec))->count);\
memmove((name)->array + UNIQVAR(idx) + (UNIQVAR(vec))->count, (name)->array + UNIQVAR(idx), ((name)->count - UNIQVAR(idx)) * sizeof (name)->array[0]);\
- memcpy((name)->array + UNIQVAR(idx), (UNIQVAR(vec))->array, (UNIQVAR(vec))->count * sizeof (name)->array[0]);\
+ memmove((name)->array + UNIQVAR(idx), (UNIQVAR(vec))->array, (UNIQVAR(vec))->count * sizeof (name)->array[0]);\
(name)->count += (UNIQVAR(vec))->count;\
}\
} while(0)
@@ -4081,7 +4090,7 @@ void **iListDel(void ***list, int64_t start, int64_t end) MUST_CHECK;
else if (sizeof((name)->array[0]) == sizeof(UNIQVAR(a)[0])) {\
sliceResize(name, (name)->count + UNIQVAR(c));\
memmove((name)->array + UNIQVAR(idx) + UNIQVAR(c), (name)->array + UNIQVAR(idx), ((name)->count - UNIQVAR(idx)) * sizeof (name)->array[0]);\
- memcpy((name)->array + UNIQVAR(idx), UNIQVAR(a), UNIQVAR(c) * sizeof (name)->array[0]);\
+ memmove((name)->array + UNIQVAR(idx), UNIQVAR(a), UNIQVAR(c) * sizeof (name)->array[0]);\
(name)->count += UNIQVAR(c);\
}\
} while(0)
@@ -4096,7 +4105,7 @@ void **iListDel(void ***list, int64_t start, int64_t end) MUST_CHECK;
var UNIQVAR(strt) = start;\
var UNIQVAR(ed) = end;\
if (UNIQVAR(strt))\
- memcpy((name)->array, (name)->array + UNIQVAR(strt), (UNIQVAR(ed) - UNIQVAR(strt)) * sizeof (name)->array[0]);\
+ memmove((name)->array, (name)->array + UNIQVAR(strt), (UNIQVAR(ed) - UNIQVAR(strt)) * sizeof (name)->array[0]);\
(name)->count = UNIQVAR(ed) - UNIQVAR(strt);\
name;\
})
@@ -4111,7 +4120,7 @@ void **iListDel(void ***list, int64_t start, int64_t end) MUST_CHECK;
var UNIQVAR(strt) = start;\
var UNIQVAR(ed) = end;\
createAllocateSliceCount(typeof(*(name)),UNIQVAR(r), UNIQVAR(ed) - UNIQVAR(strt));\
- memcpy(UNIQVAR(r)->array, (name)->array + UNIQVAR(strt), (UNIQVAR(ed) - UNIQVAR(strt)) * sizeof (name)->array[0]);\
+ memmove(UNIQVAR(r)->array, (name)->array + UNIQVAR(strt), (UNIQVAR(ed) - UNIQVAR(strt)) * sizeof (name)->array[0]);\
UNIQVAR(r)->count = UNIQVAR(ed) - UNIQVAR(strt);\
UNIQVAR(r);\
})
@@ -4126,7 +4135,7 @@ void **iListDel(void ***list, int64_t start, int64_t end) MUST_CHECK;
var UNIQVAR(strt) = start;\
var UNIQVAR(ed) = end;\
sliceResize(dest, UNIQVAR(ed) - UNIQVAR(strt));\
- memcpy((dest)->array, (name)->array + UNIQVAR(strt), (UNIQVAR(ed) - UNIQVAR(strt)) * sizeof (name)->array[0]);\
+ memmove((dest)->array, (name)->array + UNIQVAR(strt), (UNIQVAR(ed) - UNIQVAR(strt)) * sizeof (name)->array[0]);\
(dest)->count = UNIQVAR(ed) - UNIQVAR(strt);\
}\
} while(0)
@@ -6246,6 +6255,40 @@ typedef struct {
#define staticArrayFirstIndex(name) (name).head
/**
+ * delete an element in the array and move elements after it to fill the gap
+ */
+#define staticArrayDelElem(name, index) do {\
+ if ((name).head < (name).last) {\
+ /* move elements after index in latest static array */\
+ if (index < (name).last) {\
+ memmove(&(name).list[index], &(name).list[index+1], ((name).last - index) * sizeof((name).list[0]));\
+ }\
+ }\
+ elif ((name).head > (name).last) {\
+ if (index >= (name).head) {\
+ /* move elements after index in latest static array */\
+ if (index < (name).maxCount - 1) {\
+ memmove(&(name).list[index], &(name).list[index+1], ((name).maxCount - index -1) * sizeof((name).list[0]));\
+ }\
+ /* move list[0] to list[maxCount-1] */\
+ /* then shift elements in [1..last+1] to [0..last] if needed */\
+ staticArrayAt((name), (name).maxCount-1) = staticArrayAt((name), 0);\
+ if ((name).last > 0) {\
+ memmove(&(name).list[0], &(name).list[1], (name).last * sizeof((name).list[0]));\
+ }\
+ }\
+ else {\
+ /* 0 < index < last+1 */\
+ /* move elements after index in latest static array */\
+ if (index < (name).last) {\
+ memmove(&(name).list[index], &(name).list[index+1], ((name).last - index) * sizeof((name).list[0]));\
+ }\
+ }\
+ }\
+ staticArrayDelLast((name));\
+ } while(0)
+
+/**
* write the staticArray content to filename file
* No NULL checks are done on the parameters
*
diff --git a/release/libsheepyBt.c b/release/libsheepyBt.c
@@ -21,32 +21,32 @@
#endif
/**
- * return a bt object with s as buffer
+ * return a btt object with s as buffer
*/
-bt initCharB(char *s) {
+btt initCharB(char *s) {
ret charB(s);
}
/**
- * return a bt object with s as buffer
+ * return a btt object with s as buffer
* the buffer is not going to be reallocated
*/
-bt initCCharB(char *s) {
+btt initCCharB(char *s) {
ret ccharB(s);
}
/**
- * return a bt object with buf as buffer
+ * return a btt object with buf as buffer
*/
-bt initB(void *buf, u32 len, bool allocated) {
+btt initB(void *buf, u32 len, bool allocated) {
ret voidB(buf, len, allocated);
}
/**
- * return a bt object with a heap allocated buffer of size allocateSize
+ * return a btt object with a heap allocated buffer of size allocateSize
*/
-bt newB(u32 allocateSize) {
- bt r = {.len = 0};
+btt newB(u32 allocateSize) {
+ btt r = {.len = 0};
r.b = malloc(allocateSize);
if (!r.b) ret emptybt;
r.alloc = allocateSize;
@@ -54,19 +54,19 @@ bt newB(u32 allocateSize) {
}
/**
- * return a heap allocated bt object with a heap allocated buffer of size allocateSize
+ * return a heap allocated btt object with a heap allocated buffer of size allocateSize
*/
-bt *allocNewB(u32 allocateSize) {
- bt *r = malloc(sizeof(*r));
+btt *allocNewB(u32 allocateSize) {
+ btt *r = malloc(sizeof(*r));
*r = newB(allocateSize);
ret r;
}
// not needed, use charB or ccharB
// /**
-// * set buf in the b bt object
+// * set buf in the b btt object
// */
-// bt *setB(bt *b, char *buf, bool allocated) {
+// btt *setB(btt *b, char *buf, bool allocated) {
// if (!b or !buf) ret null;
// b->b = buf;
// b->len = strlen(buf);
@@ -75,79 +75,79 @@ bt *allocNewB(u32 allocateSize) {
// }
/**
- * return a heap allocated bt object with buf assigned to it
+ * return a heap allocated btt object with buf assigned to it
*/
-bt *allocCharB(char *buf) {
+btt *allocCharB(char *buf) {
if (!buf) ret null;
- bt *r = malloc(sizeof(*r));
+ btt *r = malloc(sizeof(*r));
if (!r) ret null;
*r = charB(buf);
ret r;
}
/**
- * return a heap allocated bt object with buf assigned to it
+ * return a heap allocated btt object with buf assigned to it
*/
-bt *allocCCharB(char *buf) {
+btt *allocCCharB(char *buf) {
if (!buf) ret null;
- bt *r = malloc(sizeof(*r));
+ btt *r = malloc(sizeof(*r));
if (!r) ret null;
*r = ccharB(buf);
ret r;
}
-bt *allocBufB(void *buf, u32 len, bool allocated) {
+btt *allocBufB(void *buf, u32 len, bool allocated) {
if (!buf) ret null;
- bt *r = malloc(sizeof(*r));
+ btt *r = malloc(sizeof(*r));
if (!r) ret null;
*r = voidB(buf, len, allocated);
ret r;
}
/**
- * return a heap allocated bt object with b assigned to it
+ * return a heap allocated btt object with b assigned to it
*/
-bt *allocB(const bt b) {
- bt *r = malloc(sizeof(*r));
+btt *allocB(const btt b) {
+ btt *r = malloc(sizeof(*r));
if (!r) ret null;
*r = b;
ret r;
}
/**
- * return a heap allocated bt object with *b assigned to it
+ * return a heap allocated btt object with *b assigned to it
*/
-bt *allocPB(const bt *b) {
+btt *allocPB(const btt *b) {
if (!b) ret null;
ret allocB(*b);
}
/**
- * return a bt object with a heap allocated copy of b.b
+ * return a btt object with a heap allocated copy of b.b
*/
-bt copyB(const bt b) {
- bt r = b;
+btt copyB(const btt b) {
+ btt r = b;
r.b = malloc(b.len);
r.alloc = b.len;
memcpy(r.b, b.b, b.len);
ret r;
}
-bt copyPB(bt *b) {
+btt copyPB(btt *b) {
if (!b) ret emptybt;
ret copyB(*b);
}
/**
- * return a heap allocated bt object with a heap allocated copy of b.b
+ * return a heap allocated btt object with a heap allocated copy of b.b
*/
-bt *dupB(const bt b) {
- bt *r = malloc(sizeof(*r));
+btt *dupB(const btt b) {
+ btt *r = malloc(sizeof(*r));
*r = copyB(b);
ret r;
}
-bt *dupPB(bt *b) {
+btt *dupPB(btt *b) {
if (!b) ret null;
ret dupB(*b);
}
@@ -156,7 +156,7 @@ bt *dupPB(bt *b) {
* free heap allocated .b
* nothing if not heap allocated
*/
-void freeB(bt b) {
+void freeB(btt b) {
if (b.alloc) {
free(b.b);
}
@@ -166,7 +166,7 @@ void freeB(bt b) {
* free heap allocated .b and assign null to .b
* nothing if not heap allocated
*/
-void freenB(bt *b) {
+void freenB(btt *b) {
if (b and b->alloc) {
freen(b->b);
b->len = 0;
@@ -175,9 +175,9 @@ void freenB(bt *b) {
}
/**
- * free the heap allocated bt object (container only, not .b)
+ * free the heap allocated btt object (container only, not .b)
*/
-void finishB(bt **b) {
+void finishB(btt **b) {
if (b) {
free(*b);
*b = null;
@@ -185,9 +185,9 @@ void finishB(bt **b) {
}
/**
- * free the heap allocated bt object and free .b
+ * free the heap allocated btt object and free .b
*/
-void terminateB(bt **b) {
+void terminateB(btt **b) {
if (b) {
if (*b and (*b)->alloc) {
free((*b)->b);
@@ -198,34 +198,34 @@ void terminateB(bt **b) {
}
// terminate val when it is out of scope
-void cleanUpTerminateB(bt **val) {
+void cleanUpTerminateB(btt **val) {
terminateB(val);
}
// free local val when it is out of scope
-void cleanUpFreeLocalB(bt *val) {
+void cleanUpFreeLocalB(btt *val) {
freeB(*val);
}
// free val when it is out of scope
-void cleanUpFreeB(bt **val) {
+void cleanUpFreeB(btt **val) {
freeB(**val);
}
// finish val when it is out of scope
-void cleanUpFinishB(bt **val) {
+void cleanUpFinishB(btt **val) {
finishB(val);
}
/**
- * return a bt object with s appended to b
+ * return a btt object with s appended to b
* b doesn't need to have a heap allocated buffer
*/
-bt pushB(const bt b, const char *s) {
+btt pushB(const btt b, const char *s) {
// duplicate b.b
// copy s to b end
- bt r = copyB(b);
- bt *p = bPushB(&r, s);
+ btt r = copyB(b);
+ btt *p = bPushB(&r, s);
if (p) ret r;
else {
freeB(r);
@@ -239,7 +239,7 @@ bt pushB(const bt b, const char *s) {
* update b and append s
* b.b is reallocated
*/
-bt *bPushB(bt *b, const char *s) {
+btt *bPushB(btt *b, const char *s) {
if (!b or !b->b or !s) ret null;
size_t len = strlen(s);
@@ -260,14 +260,14 @@ bt *bPushB(bt *b, const char *s) {
// TODO bPushManyB
/**
- * return a bt object with s bt object appended to b
+ * return a btt object with s btt object appended to b
* b doesn't need to have a heap allocated buffer
*/
-bt pushBB(const bt b, const bt s) {
+btt pushBB(const btt b, const btt s) {
// duplicate b.b
// copy s to b end
- bt r = copyB(b);
- bt *p = bPushBB(&r, s);
+ btt r = copyB(b);
+ btt *p = bPushBB(&r, s);
if (p) ret r;
else {
freeB(r);
@@ -279,10 +279,10 @@ bt pushBB(const bt b, const bt s) {
// TODO bPushManyBB
/**
- * update b and append s bt object
+ * update b and append s btt object
* b.b is reallocated
*/
-bt *bPushBB(bt *b, const bt s) {
+btt *bPushBB(btt *b, const btt s) {
if (!b or !b->b or !s.b) ret null;
if (!s.len) ret b;
@@ -304,10 +304,10 @@ bt *bPushBB(bt *b, const bt s) {
// TODO bPushManyBB
/**
- * return a bt object with *s bt object appended to b
+ * return a btt object with *s btt object appended to b
* b doesn't need to have a heap allocated buffer
*/
-bt pushBPB(const bt b, const bt *s) {
+btt pushBPB(const btt b, const btt *s) {
if (!s) ret emptybt;
// duplicate b.b
// copy s to b end
@@ -317,10 +317,10 @@ bt pushBPB(const bt b, const bt *s) {
// TODO bPushManyBPB
/**
- * update b and append *s bt object
+ * update b and append *s btt object
* b.b is reallocated
*/
-bt *bPushBPB(bt *b, const bt *s) {
+btt *bPushBPB(btt *b, const btt *s) {
if (!s) ret null;
// copy s to b end
ret bPushBB(b, *s);
@@ -329,30 +329,30 @@ bt *bPushBPB(bt *b, const bt *s) {
// TODO bPushManyBB
/**
- * return a bt object with s appended to *b
+ * return a btt object with s appended to *b
* b doesn't need to have a heap allocated buffer
*/
-bt pushPB(const bt *b, const char *s) {
+btt pushPB(const btt *b, const char *s) {
if (!b) ret emptybt;
ret pushB(*b, s);
}
// TODO pushManyPB...
/**
- * return a bt object with s bt object appended to *b
+ * return a btt object with s btt object appended to *b
* b doesn't need to have a heap allocated buffer
*/
-bt pushPBB(const bt *b, const bt s) {
+btt pushPBB(const btt *b, const btt s) {
if (!b) ret emptybt;
ret pushBB(*b, s);
}
// TODO pushManyPBB...
/**
- * return a bt object with *s bt object appended to *b
+ * return a btt object with *s btt object appended to *b
* b doesn't need to have a heap allocated buffer
*/
-bt pushPBPB(const bt *b, const bt *s) {
+btt pushPBPB(const btt *b, const btt *s) {
if (!b) ret emptybt;
ret pushBPB(*b, s);
}
@@ -362,7 +362,7 @@ bt pushPBPB(const bt *b, const bt *s) {
* split b in vb static vector
* the vector is not reallocated
*/
-vbt *sasplitB(vbt *vb, const bt b, const bt delim) {
+vbtt *sasplitB(vbtt *vb, const btt b, const btt delim) {
if (!vb or !b.b or !delim.b) ret null;
vb->count = 0;
@@ -384,7 +384,7 @@ vbt *sasplitB(vbt *vb, const bt b, const bt delim) {
break;
if (vb->count >= vb->maxCount) ret null;
nextTokenStart = ptr + 1;
- bt tok = {.b = working, .len = ptr-working, .alloc = 0};
+ btt tok = {.b = working, .len = ptr-working, .alloc = 0};
vectorAppend(vb, tok);
i += tok.len + delim.len;
working = b.b + i;
@@ -397,14 +397,14 @@ vbt *sasplitB(vbt *vb, const bt b, const bt delim) {
break;
if (vb->count >= vb->maxCount) ret null;
nextTokenStart = ptr + delim.len;
- bt tok = {.b = working, .len = ptr-working, .alloc = 0};
+ btt tok = {.b = working, .len = ptr-working, .alloc = 0};
vectorAppend(vb, tok);
i += tok.len + delim.len;
working = b.b + i;
}
}
if (vb->count >= vb->maxCount) ret null;
- bt tok = {.b = nextTokenStart, .len = (b.b+b.len)-nextTokenStart, .alloc = 0};
+ btt tok = {.b = nextTokenStart, .len = (b.b+b.len)-nextTokenStart, .alloc = 0};
vectorAppend(vb, tok);
ret vb;
@@ -414,8 +414,8 @@ vbt *sasplitB(vbt *vb, const bt b, const bt delim) {
* split b in vb static vector
* the vector is not reallocated
*/
-vbt *sasplitCharB(vbt *vb, const bt b, char *delim) {
- bt d = ccharB(delim);
+vbtt *sasplitCharB(vbtt *vb, const btt b, char *delim) {
+ btt d = ccharB(delim);
ret sasplitB(vb, b, d);
}
@@ -423,7 +423,7 @@ vbt *sasplitCharB(vbt *vb, const bt b, char *delim) {
* split b in vb static vector
* the vector is not reallocated
*/
-vbt *sasplitDPB(vbt *vb, const bt b, const bt *delim) {
+vbtt *sasplitDPB(vbtt *vb, const btt b, const btt *delim) {
if (!delim) ret null;
ret sasplitB(vb, b, *delim);
}
@@ -432,7 +432,7 @@ vbt *sasplitDPB(vbt *vb, const bt b, const bt *delim) {
* split b in vb static vector
* the vector is not reallocated
*/
-vbt *sasplitPB(vbt *vb, const bt *b, const bt delim) {
+vbtt *sasplitPB(vbtt *vb, const btt *b, const btt delim) {
if (!b) ret null;
ret sasplitB(vb, *b, delim);
}
@@ -441,7 +441,7 @@ vbt *sasplitPB(vbt *vb, const bt *b, const bt delim) {
* split b in vb static vector
* the vector is not reallocated
*/
-vbt *sasplitPCharB(vbt *vb, const bt *b, char *delim) {
+vbtt *sasplitPCharB(vbtt *vb, const btt *b, char *delim) {
if (!b) ret null;
ret sasplitCharB(vb, *b, delim);
}
@@ -450,7 +450,7 @@ vbt *sasplitPCharB(vbt *vb, const bt *b, char *delim) {
* split b in vb static vector
* the vector is not reallocated
*/
-vbt *sasplitPDPB(vbt *vb, const bt *b, const bt *delim) {
+vbtt *sasplitPDPB(vbtt *vb, const btt *b, const btt *delim) {
if (!b or !delim) ret null;
ret sasplitB(vb, *b, *delim);
}
@@ -481,7 +481,7 @@ vbt *sasplitPDPB(vbt *vb, const bt *b, const bt *delim) {
/**
* split b in vb vector
*/
-vbt *asplitB(vbt *vb, const bt b, const bt delim) {
+vbtt *asplitB(vbtt *vb, const btt b, const btt delim) {
if (!vb or !b.b or !delim.b) ret null;
vb->count = 0;
@@ -501,7 +501,7 @@ vbt *asplitB(vbt *vb, const bt b, const bt delim) {
if (!ptr)
break;
nextTokenStart = ptr + 1;
- bt tok = {.b = working, .len = ptr-working, .alloc = 0};
+ btt tok = {.b = working, .len = ptr-working, .alloc = 0};
vectorAppend(vb, tok);
i += tok.len + delim.len;
working = b.b + i;
@@ -513,13 +513,13 @@ vbt *asplitB(vbt *vb, const bt b, const bt delim) {
if (!ptr)
break;
nextTokenStart = ptr + delim.len;
- bt tok = {.b = working, .len = ptr-working, .alloc = 0};
+ btt tok = {.b = working, .len = ptr-working, .alloc = 0};
vectorAppend(vb, tok);
i += tok.len + delim.len;
working = b.b + i;
}
}
- bt tok = {.b = nextTokenStart, .len = (b.b+b.len)-nextTokenStart, .alloc = 0};
+ btt tok = {.b = nextTokenStart, .len = (b.b+b.len)-nextTokenStart, .alloc = 0};
vectorAppend(vb, tok);
ret vb;
@@ -528,15 +528,15 @@ vbt *asplitB(vbt *vb, const bt b, const bt delim) {
/**
* split b in vb vector
*/
-vbt *asplitCharB(vbt *vb, const bt b, char *delim) {
- bt d = ccharB(delim);
+vbtt *asplitCharB(vbtt *vb, const btt b, char *delim) {
+ btt d = ccharB(delim);
ret asplitB(vb, b, d);
}
/**
* split b in vb vector
*/
-vbt *asplitDPB(vbt *vb, const bt b, const bt *delim) {
+vbtt *asplitDPB(vbtt *vb, const btt b, const btt *delim) {
if (!delim) ret null;
ret asplitB(vb, b, *delim);
}
@@ -544,7 +544,7 @@ vbt *asplitDPB(vbt *vb, const bt b, const bt *delim) {
/**
* split b in vb vector
*/
-vbt *asplitPB(vbt *vb, const bt *b, const bt delim) {
+vbtt *asplitPB(vbtt *vb, const btt *b, const btt delim) {
if (!b) ret null;
ret asplitB(vb, *b, delim);
}
@@ -552,7 +552,7 @@ vbt *asplitPB(vbt *vb, const bt *b, const bt delim) {
/**
* split b in vb vector
*/
-vbt *asplitPCharB(vbt *vb, const bt *b, char *delim) {
+vbtt *asplitPCharB(vbtt *vb, const btt *b, char *delim) {
if (!b) ret null;
ret asplitCharB(vb, *b, delim);
}
@@ -560,17 +560,17 @@ vbt *asplitPCharB(vbt *vb, const bt *b, char *delim) {
/**
* split b in vb vector
*/
-vbt *asplitPDPB(vbt *vb, const bt *b, const bt *delim) {
+vbtt *asplitPDPB(vbtt *vb, const btt *b, const btt *delim) {
if (!b or !delim) ret null;
ret asplitB(vb, *b, *delim);
}
/**
- * return vbt vector with tokens from b
+ * return vbtt vector with tokens from b
* this function has good performance for small element counts
*/
-vbt splitB(const bt b, const bt delim) {
- vbt r;
+vbtt splitB(const btt b, const btt delim) {
+ vbtt r;
if (!b.b or !delim.b) ret emptyvbt;
vectorInitCount(&r, 5);
@@ -581,17 +581,17 @@ vbt splitB(const bt b, const bt delim) {
}
/**
- * return vbt vector with tokens from b
+ * return vbtt vector with tokens from b
* this function has good performance for small element counts
*/
-vbt splitCharB(const bt b, char *delim) {
- vbt r;
+vbtt splitCharB(const btt b, char *delim) {
+ vbtt r;
if (!b.b or !delim) ret emptyvbt;
vectorInitCount(&r, 5);
- bt d = ccharB(delim);
+ btt d = ccharB(delim);
asplitB(&r, b, d);
ret r;
@@ -600,7 +600,7 @@ vbt splitCharB(const bt b, char *delim) {
/**
* split b in vb vector
*/
-vbt splitDPB(const bt b, const bt *delim) {
+vbtt splitDPB(const btt b, const btt *delim) {
if (!delim) ret emptyvbt;
ret splitB(b, *delim);
}
@@ -608,16 +608,16 @@ vbt splitDPB(const bt b, const bt *delim) {
/**
* split b in vb vector
*/
-vbt splitPB(const bt *b, const bt delim) {
+vbtt splitPB(const btt *b, const btt delim) {
if (!b) ret emptyvbt;
ret splitB(*b, delim);
}
/**
- * return vbt vector with tokens from b
+ * return vbtt vector with tokens from b
* this function has good performance for small element counts
*/
-vbt splitPCharB(const bt *b, char *delim) {
+vbtt splitPCharB(const btt *b, char *delim) {
if (!b) ret emptyvbt;
ret splitCharB(*b, delim);
}
@@ -625,17 +625,17 @@ vbt splitPCharB(const bt *b, char *delim) {
/**
* split b in vb vector
*/
-vbt splitPDPB(const bt *b, const bt *delim) {
+vbtt splitPDPB(const btt *b, const btt *delim) {
if (!b or !delim) ret emptyvbt;
ret splitB(*b, *delim);
}
/**
- * return dbt vector with tokens from b
+ * return dbtt vector with tokens from b
* this function has good performance for large element counts
*/
-dbt dsplitB(const bt b, const bt delim) {
- dbt r;
+dbtt dsplitB(const btt b, const btt delim) {
+ dbtt r;
if (!b.b or !delim.b) ret emptydbt;
@@ -656,7 +656,7 @@ dbt dsplitB(const bt b, const bt delim) {
if (!ptr)
break;
nextTokenStart = ptr + 1;
- bt tok = {.b = working, .len = ptr-working, .alloc = 0};
+ btt tok = {.b = working, .len = ptr-working, .alloc = 0};
dVectorAppend(&r, tok);
i += tok.len + delim.len;
working = b.b + i;
@@ -668,70 +668,70 @@ dbt dsplitB(const bt b, const bt delim) {
if (!ptr)
break;
nextTokenStart = ptr + delim.len;
- bt tok = {.b = working, .len = ptr-working, .alloc = 0};
+ btt tok = {.b = working, .len = ptr-working, .alloc = 0};
dVectorAppend(&r, tok);
i += tok.len + delim.len;
working = b.b + i;
}
}
- bt tok = {.b = nextTokenStart, .len = (b.b+b.len)-nextTokenStart, .alloc = 0};
+ btt tok = {.b = nextTokenStart, .len = (b.b+b.len)-nextTokenStart, .alloc = 0};
dVectorAppend(&r, tok);
ret r;
}
/**
- * return dbt vector with tokens from b
+ * return dbtt vector with tokens from b
* this function has good performance for large element counts
*/
-dbt dsplitCharB(const bt b, char *delim) {
- bt d = ccharB(delim);
+dbtt dsplitCharB(const btt b, char *delim) {
+ btt d = ccharB(delim);
ret dsplitB(b, d);
}
/**
- * return dbt vector with tokens from b
+ * return dbtt vector with tokens from b
* this function has good performance for large element counts
*/
-dbt dsplitDPB(const bt b, const bt *delim) {
+dbtt dsplitDPB(const btt b, const btt *delim) {
if (!delim) ret emptydbt;
ret dsplitB(b, *delim);
}
/**
- * return dbt vector with tokens from b
+ * return dbtt vector with tokens from b
* this function has good performance for large element counts
*/
-dbt dsplitPB(const bt *b, const bt delim) {
+dbtt dsplitPB(const btt *b, const btt delim) {
if (!b) ret emptydbt;
ret dsplitB(*b, delim);
}
/**
- * return dbt vector with tokens from b
+ * return dbtt vector with tokens from b
* this function has good performance for large element counts
*/
-dbt dsplitPCharB(const bt *b, char *delim) {
+dbtt dsplitPCharB(const btt *b, char *delim) {
if (!b) ret emptydbt;
ret dsplitCharB(*b, delim);
}
/**
- * return dbt vector with tokens from b
+ * return dbtt vector with tokens from b
* this function has good performance for large element counts
*/
-dbt dsplitPDPB(const bt *b, const bt *delim) {
+dbtt dsplitPDPB(const btt *b, const btt *delim) {
if (!b or !delim) ret emptydbt;
ret dsplitB(*b, *delim);
}
/**
* slice String
- * return a bt object which is the string between start and end
+ * return a btt object which is the string between start and end
* negative indexes are allowed
*/
-bt sliceB(const bt b, int64_t start, int64_t end) {
- bt r = {0};
+btt sliceB(const btt b, int64_t start, int64_t end) {
+ btt r = {0};
if (!b.b) ret emptybt;
#define checkRange(B, rval)\
@@ -766,10 +766,10 @@ bt sliceB(const bt b, int64_t start, int64_t end) {
/**
* slice String
- * update the b bt object and keep only the string between start and end
+ * update the b btt object and keep only the string between start and end
* negative indexes are allowed
*/
-bt *bSliceB(bt *b, int64_t start, int64_t end) {
+btt *bSliceB(btt *b, int64_t start, int64_t end) {
if (!b) ret null;
checkRange(*b, null);
@@ -789,19 +789,19 @@ bt *bSliceB(bt *b, int64_t start, int64_t end) {
/**
* slice String
- * return a bt object which is the string between start and end
+ * return a btt object which is the string between start and end
* negative indexes are allowed
*/
-bt slicePB(const bt *b, int64_t start, int64_t end) {
+btt slicePB(const btt *b, int64_t start, int64_t end) {
if (!b) ret emptybt;
ret sliceB(*b, start, end);
}
/**
- * return a bt object without the leading and trailing spaces
+ * return a btt object without the leading and trailing spaces
*/
-bt trimB(const bt b) {
- bt r = {0};
+btt trimB(const btt b) {
+ btt r = {0};
if (!b.b) ret emptybt;
r.b = b.b;
@@ -830,13 +830,13 @@ bt trimB(const bt b) {
}
/**
- * update b bt object and remove the leading and trailing spaces
+ * update b btt object and remove the leading and trailing spaces
*/
// memmove data
-bt *bTrimB(bt *b) {
+btt *bTrimB(btt *b) {
if (!b or !b->b) ret null;
- bt t = trimB(*b);
+ btt t = trimB(*b);
if (t.b != b->b)
memmove(b->b, t.b, t.len);
@@ -846,25 +846,25 @@ bt *bTrimB(bt *b) {
}
/**
- * return a bt object without the leading and trailing spaces
+ * return a btt object without the leading and trailing spaces
*/
-bt trimPB(const bt *b) {
+btt trimPB(const btt *b) {
if (!b) emptybt;
ret trimB(*b);
}
-void printB(const bt b) {
+void printB(const btt b) {
write(STDOUT_FILENO, b.b, b.len);
}
-void printDebugB(const bt b) {
+void printDebugB(const btt b) {
write(STDOUT_FILENO, "\"", 1);
printB(b);
write(STDOUT_FILENO, "\"", 1);
put;
}
-void printDebugInfoB(const bt b) {
+void printDebugInfoB(const btt b) {
logD("b: %p, len: %"PRIu32", alloc: %"PRIu32, b.b, b.len, b.alloc);
printDebugB(b);
}
diff --git a/release/libsheepyBt.h b/release/libsheepyBt.h
@@ -1,11 +1,11 @@
/*
- * bt is a dynamic Byte buffer Type (Bytes Type)
+ * btt is a dynamic Byte buffer Type (Bytes Type)
*
* Status: under development, not tested, the comments don't match the implementation
*
- * # How bt works
+ * # How btt works
*
- * When a bt object represents a string, it doesn't need to be NUL terminated,
+ * When a btt object represents a string, it doesn't need to be NUL terminated,
* this allow spliting string more efficiently.
*
* - simple to use
@@ -14,64 +14,64 @@
* - works with memcheck
*
*
- * # Advantages and disadvantages of bt
+ * # Advantages and disadvantages of btt
*
- * bt is implemented using a structure defining the byte buffer like this:
+ * btt is implemented using a structure defining the byte buffer like this:
* ```
* struct {
* u8 *b;
* u32 len;
* u32 alloc;
- * } bt;
+ * } btt;
* ```
- * The bt structure is managed by the *B functions.
+ * The btt structure is managed by the *B functions.
*
- * - Disadvantage 1: bt doesn't work with standard C string functions
+ * - Disadvantage 1: btt doesn't work with standard C string functions
*
- * - Advantage 1: Giving the address of a bt to B functions, updates the bt in place:
+ * - Advantage 1: Giving the address of a btt to B functions, updates the btt in place:
* ```
* pushBG(&b, s);
* ```
*
* - Advantage 2: trimming and slicing buffers don't need memory allocations and spliting uses less memory allocations
*
- * - Advantage 3: the index for accessing the bytes in bt is range check in the getB, setB functions and it works even the buffer in bt is reallocated
+ * - Advantage 3: the index for accessing the bytes in btt is range check in the getB, setB functions and it works even the buffer in btt is reallocated
*
*
- * # bt basics
+ * # btt basics
*
- * Here is how to declare a bt, assign a string (RO) and print it:
+ * Here is how to declare a btt, assign a string (RO) and print it:
*
* ```
- * bt mystring = ccharB("Hello World!");
+ * btt mystring = ccharB("Hello World!");
* printB(mystring);
*
* output> Hello World!
* ```
*
- * The above small program shows a few important things about bt:
- * - bt are stack allocated (or heap allocated)
- * - printB prints the bt content
+ * The above small program shows a few important things about btt:
+ * - btt are stack allocated (or heap allocated)
+ * - printB prints the btt content
* - there is no memory allocations so there is no free.
*
*
- * # Creating bt strings
+ * # Creating btt strings
*
* ```
- * bt mystring = ccharB("Hello World!");
- * bt mystring2 = charB(strdup("Hello World!"), true);
- * bt mybuf = voidB("Binary", sizeof("Binary"), false);
+ * btt mystring = ccharB("Hello World!");
+ * btt mystring2 = charB(strdup("Hello World!"), true);
+ * btt mybuf = voidB("Binary", sizeof("Binary"), false);
* createCharB(mystring3, "bytes", false);
* // from another string:
- * bt mirror = mystring;
- * bt empty = {0};
+ * btt mirror = mystring;
+ * btt empty = {0};
* // preallocate buf
- * bt pre = newB(allocateSize);
- * // allocate bt struct and buf
- * bt *heap = allocNewB(allocateSize);
+ * btt pre = newB(allocateSize);
+ * // allocate btt struct and buf
+ * btt *heap = allocNewB(allocateSize);
*
* // allocate and set string
- * bt *new = allocB("STR", false);
+ * btt *new = allocB("STR", false);
* finishB(new);
* ```
*
@@ -84,9 +84,9 @@
*
* # Destroying strings
*
- * - freeB frees the buffer pointed by .b and can be called with non allocated bt objects (it does nothing)
- * - terminateB frees the buffer if allocated and the bt struct
- * - finishB frees the bt struct only (doesn't touch the .b buffer)
+ * - freeB frees the buffer pointed by .b and can be called with non allocated btt objects (it does nothing)
+ * - terminateB frees the buffer if allocated and the btt struct
+ * - finishB frees the btt struct only (doesn't touch the .b buffer)
*
*
* # Concatenating strings
@@ -107,22 +107,22 @@
* # Trimming and slicing
*
* ```
- * bt T = ccharB(" trim ");
- * bt r = trimB(T);
- * bt s = sliceB(T, 2, 6);
+ * btt T = ccharB(" trim ");
+ * btt r = trimB(T);
+ * btt s = sliceB(T, 2, 6);
* ```
*
*
* # String copying
*
* ```
- * // copy bt
- * bt mystringCopy = copyB(mystring);
+ * // copy btt
+ * btt mystringCopy = copyB(mystring);
* // the buffer in mystringCopy is heap allocated
* freeB(mystringCopy);
*
- * // duplicate bt
- * bt *dup = dupB(mystring);
+ * // duplicate btt
+ * btt *dup = dupB(mystring);
* // dup and the buffer in dup are heap allocated
* terminateB(dup);
* ```
@@ -130,8 +130,8 @@
* # Splitting strings
*
* ```
- * bt ss = ccharB("Hello World!");
- * vbt lsspl = splitB(ss, " ");
+ * btt ss = ccharB("Hello World!");
+ * vbtt lsspl = splitB(ss, " ");
* puts("");
* vectorForEach(&ll, e) {
* printB(*e);
@@ -145,7 +145,7 @@
*
* When alloc is 0 and len > 0, the buffer has not been allocated
*
- * createCharB declares a bt object with the given string, there is no allocation
+ * createCharB declares a btt object with the given string, there is no allocation
*
* Appending strings:
* s is updated, b or i are same
@@ -154,14 +154,14 @@
*
* New string:
* 1 malloc (better cache locality):
- * bt s2 = pushB(s, "qweqwe");
- * bt s3 = pushManyB(s, "qweqwe", "wer");
+ * btt s2 = pushB(s, "qweqwe");
+ * btt s3 = pushManyB(s, "qweqwe", "wer");
*
* //2 mallocs:
- * //bt *s4 = appendB(s, "qweqwe");
- * //bt *s5 = appendManyB(s, "qweqwe", "wer");
+ * //btt *s4 = appendB(s, "qweqwe");
+ * //btt *s5 = appendManyB(s, "qweqwe", "wer");
*
- * bt s6 = catB("1","2");
+ * btt s6 = catB("1","2");
*
* pushB(&s, s2);
*
@@ -172,13 +172,13 @@
* Spliting string doesn't require any buffer copying
* createCharB(h, "Hello World!", 0);
*
- * bt h2 = {0};
+ * btt h2 = {0};
* h2.b = h.b+6;
* h2.len = 5;
*
* Example:
- * Empty bt:
- * bt s = {0};
+ * Empty btt:
+ * btt s = {0};
* Assign C string:
* s = charB("a string", no);
* s.b = "asdasd";
@@ -189,116 +189,116 @@
#include "libsheepy.h"
-// bt bytes type
+// btt bytes type
// point to a byte buffer at .b of length .len
// .alloc is the allocated size of the buffer
typ struct {
u8 *b;
u32 len;
u32 alloc;
-} bt;
+} btt;
typ struct {
u8 *b;
u64 len;
u64 alloc;
-} b64t;
-// TODO functions supporting b64t
+} bt64t;
+// TODO functions supporting bt64t
-// vector of bt elements
+// vector of btt elements
// This data structure has good performance for small element counts
typ struct {
u32 count;
u32 maxCount;
- bt *array;
-} vbt;
+ btt *array;
+} vbtt;
-// dynamic segmented vector of bt elements
+// dynamic segmented vector of btt elements
// This data structure has good performance for large element counts
typ struct {
u32 count;
u32 maxCount;
void** buffers;
- bt element;
-} dbt;
+ btt element;
+} dbtt;
// object returned by some functions
-#define emptybt ((bt){0})
-#define emptyvbt ((vbt){0})
-#define emptydbt ((dbt){0})
+#define emptybt ((btt){0})
+#define emptyvbt ((vbtt){0})
+#define emptydbt ((dbtt){0})
-// assign a u8 a[count] array to bt object
+// assign a u8 a[count] array to btt object
// Example:
// u8 s[10] = {0};
-// bt b;
+// btt b;
// arrayB(b, s);
#define arrayB(name, a)\
(name).b = a; (name).len = 0; (name).alloc = ARRAY_SIZE(a)
-// declare name vbt object and assign the a array defined as bt a[maxCnt] with cnt element already initialized
+// declare name vbtt object and assign the a array defined as btt a[maxCnt] with cnt element already initialized
#define vectorB(name, a, cnt, maxCnt)\
- vbt name; name.count = cnt; name.maxCount = maxCnt; name.array = a
+ vbtt name; name.count = cnt; name.maxCount = maxCnt; name.array = a
-// declare name vbt object, declare the a array of count bt elements and assign it to name the vbt object
+// declare name vbtt object, declare the a array of count btt elements and assign it to name the vbtt object
#define listB(name, a, maxCnt)\
- bt a[maxCnt] = {0}; vbt name; name.count = 0; name.maxCount = maxCnt; name.array = a
+ btt a[maxCnt] = {0}; vbtt name; name.count = 0; name.maxCount = maxCnt; name.array = a
-// declare name vbt object and assign the empty a array defined as bt a[maxCnt]
+// declare name vbtt object and assign the empty a array defined as btt a[maxCnt]
#define listAB(name, a)\
- vbt name; name.count = 0; name.maxCount = ARRAY_SIZE(a); name.array = a
+ vbtt name; name.count = 0; name.maxCount = ARRAY_SIZE(a); name.array = a
-// initialize a bt object with a heap allocated string
-#define charB(string) (bt){.b = string, .len = strlen(string), .alloc = strlen(string)}
-// initialize a bt object with a string that can't be reallocated
-#define ccharB(string) (bt){.b = string, .len = strlen(string), .alloc = 0 }
-// initialize a bt object with a heap allocated binary buffer
-#define voidB( buf, length, allocated) (bt){.b = buf, .len = length, .alloc = (allocated) ? length : 0 }
+// initialize a btt object with a heap allocated string
+#define charB(string) (btt){.b = string, .len = strlen(string), .alloc = strlen(string)}
+// initialize a btt object with a string that can't be reallocated
+#define ccharB(string) (btt){.b = string, .len = strlen(string), .alloc = 0 }
+// initialize a btt object with a heap allocated binary buffer
+#define voidB( buf, length, allocated) (btt){.b = buf, .len = length, .alloc = (allocated) ? length : 0 }
/**
- * declare pointer name with type bt and terminate name when it is out of scope
+ * declare pointer name with type btt and terminate name when it is out of scope
*/
-#define cleanBP(name) bt *name CLEANUP(cleanUpTerminateB)
+#define cleanBP(name) btt *name CLEANUP(cleanUpTerminateB)
/**
- * allocate bt (pointer) and clean up when it is out of scope
+ * allocate btt (pointer) and clean up when it is out of scope
*/
#define cleanAllocateB(obj) ;cleanBP(obj); obj = allocNewB(8)
/**
- * declare local object name with type bt and free name when it is out of scope
+ * declare local object name with type btt and free name when it is out of scope
*/
-#define cleanB(name) bt name CLEANUP(cleanUpFreeLocalB)
+#define cleanB(name) btt name CLEANUP(cleanUpFreeLocalB)
/**
- * declare pointer name with type bt and free name when it is out of scope
+ * declare pointer name with type btt and free name when it is out of scope
*/
-#define cleanFreeBP(name) bt *name CLEANUP(cleanUpFreeB)
+#define cleanFreeBP(name) btt *name CLEANUP(cleanUpFreeB)
/**
- * declare pointer name with type bt and finish name when it is out of scope
+ * declare pointer name with type btt and finish name when it is out of scope
*/
-#define cleanFinishBP(name) bt *name CLEANUP(cleanUpFinishB)
+#define cleanFinishBP(name) btt *name CLEANUP(cleanUpFinishB)
-// create name bt object and initialize it with a string
+// create name btt object and initialize it with a string
// string is char* and is evaluated one time, allocated true/false
-#define createCharB(name, string, allocated) bt name;u8 *UNIQVAR(s) = (u8*)string;name.b = UNIQVAR(s); name.len = strlen(UNIQVAR(s)); name.alloc = (allocated) ? name.len : 0
+#define createCharB(name, string, allocated) btt name;u8 *UNIQVAR(s) = (u8*)string;name.b = UNIQVAR(s); name.len = strlen(UNIQVAR(s)); name.alloc = (allocated) ? name.len : 0
-// create name bt object and initialize it with a binary buffer
-#define createB(name, buf, length, allocated) bt name;name.b = buf; name.len = len; name.alloc = (allocated) ? name.length : 0
+// create name btt object and initialize it with a binary buffer
+#define createB(name, buf, length, allocated) btt name;name.b = buf; name.len = len; name.alloc = (allocated) ? name.length : 0
#define createAllocateCharB(name, string, allocated)\
- bt *name = malloc(sizeof(*name)); u8 *UNIQVAR(s) = (u8*)string;name->b = UNIQVAR(s); name->len = strlen(UNIQVAR(s)); name->alloc = (allocated) ? name->len : 0
+ btt *name = malloc(sizeof(*name)); u8 *UNIQVAR(s) = (u8*)string;name->b = UNIQVAR(s); name->len = strlen(UNIQVAR(s)); name->alloc = (allocated) ? name->len : 0
#define createAllocateB(name, buf, length, allocated)\
- bt *name = malloc(sizeof(*name));name->b = buf; name->len = length; name->alloc = (allocated) ? name->len : 0
+ btt *name = malloc(sizeof(*name));name->b = buf; name->len = length; name->alloc = (allocated) ? name->len : 0
-// create clean name bt object and initialize it with a string
+// create clean name btt object and initialize it with a string
// string is char* and is evaluated one time
#define cleanCharB(name, string) cleanB(name);u8 *UNIQVAR(s) = (u8*)string;name.b = UNIQVAR(s); name.len = strlen(UNIQVAR(s)); name.alloc = name.len
-// create clean name bt object and initialize it with a binary buffer
+// create clean name btt object and initialize it with a binary buffer
#define ccleanB(name, buf, length) cleanB(name);name.b = buf; name.len = len; name.alloc = name.length
#define cleanAllocateCharB(name, string, allocated)\
@@ -308,71 +308,71 @@ typ struct {
cleanBP(name) = malloc(sizeof(*name));name->b = buf; name->len = length; name->alloc = (allocated) ? name->len : 0
-// return a bt object with s as buffer
-bt initCharB(char *s);
+// return a btt object with s as buffer
+btt initCharB(char *s);
-// return a bt object with s as buffer
+// return a btt object with s as buffer
// the buffer is not going to be reallocated
-bt initCCharB(char *s);
+btt initCCharB(char *s);
-// return a bt object with buf as buffer
-bt initB(void *buf, u32 len, bool allocated);
+// return a btt object with buf as buffer
+btt initB(void *buf, u32 len, bool allocated);
-// return a bt object with a heap allocated buffer of size allocateSize
-bt newB(u32 allocateSize);
+// return a btt object with a heap allocated buffer of size allocateSize
+btt newB(u32 allocateSize);
-// return a heap allocated bt object with a heap allocated buffer of size allocateSize
-bt *allocNewB(u32 allocateSize);
+// return a heap allocated btt object with a heap allocated buffer of size allocateSize
+btt *allocNewB(u32 allocateSize);
-// return a heap allocated bt object with buf assigned to it
-bt *allocCharB(char *buf);
+// return a heap allocated btt object with buf assigned to it
+btt *allocCharB(char *buf);
-// return a heap allocated bt object with buf assigned to it
-bt *allocCCharB(char *buf);
+// return a heap allocated btt object with buf assigned to it
+btt *allocCCharB(char *buf);
-bt *allocBufB(void *buf, u32 len, bool allocated);
+btt *allocBufB(void *buf, u32 len, bool allocated);
-// return a heap allocated bt object with b assigned to it
-bt *allocB(const bt b);
+// return a heap allocated btt object with b assigned to it
+btt *allocB(const btt b);
/**
- * return a heap allocated bt object with *b assigned to it
+ * return a heap allocated btt object with *b assigned to it
*/
-bt *allocPB(const bt *b);
+btt *allocPB(const btt *b);
#define allocBG(b) _Generic(b,\
- bt: allocB,\
- const bt: allocB,\
- bt*: allocPB,\
- const bt*: allocPB,\
+ btt: allocB,\
+ const btt: allocB,\
+ btt*: allocPB,\
+ const btt*: allocPB,\
char*: allocCharB,\
const char*: allocCCharB\
)(b)
-// return a bt object with a heap allocated copy of b.b
-bt copyB(const bt b);
+// return a btt object with a heap allocated copy of b.b
+btt copyB(const btt b);
-bt copyPB(bt *b);
+btt copyPB(btt *b);
#define copyBG(b) _Generic(b,\
- bt: copyB,\
- bt*: copyPB\
+ btt: copyB,\
+ btt*: copyPB\
)(b)
-// return a heap allocated bt object with a heap allocated copy of b.b
-bt *dupB(const bt b);
+// return a heap allocated btt object with a heap allocated copy of b.b
+btt *dupB(const btt b);
-bt *dupPB(bt *b);
+btt *dupPB(btt *b);
#define dupBG(b) _Generic(b,\
- bt: dupB,\
- bt*: dupPB\
+ btt: dupB,\
+ btt*: dupPB\
)(b)
// TODO:
// ..lenB
// ..freeB
-// ..terminateB(bt *b)
+// ..terminateB(btt *b)
// ..pushBB
// ..pushManyBB
// // NO - growzero: memset 0 to new part
@@ -394,12 +394,12 @@ bt *dupPB(bt *b);
// use b.b instead
-// u8* bufferB(bt b) {
+// u8* bufferB(btt b) {
// ret b.b;
// }
// use b.len instead
-// size_t lenB(bt b) {
+// size_t lenB(btt b) {
// ret b.len;
// }
@@ -407,133 +407,133 @@ bt *dupPB(bt *b);
* free heap allocated .b
* nothing if not heap allocated
*/
-void freeB(bt b);
+void freeB(btt b);
/**
* free heap allocated .b and assign null to .b
* nothing if not heap allocated
*/
-void freenB(bt *b);
+void freenB(btt *b);
/**
- * free the heap allocated bt object (container only, not .b)
+ * free the heap allocated btt object (container only, not .b)
*/
-void finishB(bt **b);
+void finishB(btt **b);
/**
- * free the heap allocated bt object and free .b
+ * free the heap allocated btt object and free .b
*/
-void terminateB(bt **b);
+void terminateB(btt **b);
// terminate val when it is out of scope
-void cleanUpTerminateB(bt **val);
+void cleanUpTerminateB(btt **val);
// free local val when it is out of scope
-void cleanUpFreeLocalB(bt *val);
+void cleanUpFreeLocalB(btt *val);
// free val when it is out of scope
-void cleanUpFreeB(bt **val);
+void cleanUpFreeB(btt **val);
// finish val when it is out of scope
-void cleanUpFinishB(bt **val);
+void cleanUpFinishB(btt **val);
-// return a bt object with s appended to b
+// return a btt object with s appended to b
// b doesn't need to have a heap allocated buffer
#define appendB pushB
-bt pushB(const bt b, const char *s);
+btt pushB(const btt b, const char *s);
// TODO pushManyB
// update b and append s
// b.b is reallocated
#define bAppendB bPushB
-bt *bPushB(bt *b, const char *s);
+btt *bPushB(btt *b, const char *s);
// TODO bPushManyB
-// return a bt object with s bt object appended to b
+// return a btt object with s btt object appended to b
// b doesn't need to have a heap allocated buffer
#define appendBB pushBB
-bt pushBB(const bt b, const bt s);
+btt pushBB(const btt b, const btt s);
// TODO bPushManyBB
-// update b and append s bt object
+// update b and append s btt object
// b.b is reallocated
#define bAppendBB bPushBB
-bt *bPushBB(bt *b, const bt s);
+btt *bPushBB(btt *b, const btt s);
// TODO bPushManyBB
-// return a bt object with *s bt object appended to b
+// return a btt object with *s btt object appended to b
// b doesn't need to have a heap allocated buffer
#define appendBPB pushBPB
-bt pushBPB(const bt b, const bt *s);
+btt pushBPB(const btt b, const btt *s);
// TODO bPushManyBPB
-// update b and append *s bt object
+// update b and append *s btt object
// b.b is reallocated
#define bAppendBPB bPushBPB
-bt *bPushBPB(bt *b, const bt *s);
+btt *bPushBPB(btt *b, const btt *s);
// TODO bPushManyBB
-// return a bt object with s appended to *b
+// return a btt object with s appended to *b
// b doesn't need to have a heap allocated buffer
#define appendPB pushPB
-bt pushPB(const bt *b, const char *s);
+btt pushPB(const btt *b, const char *s);
// TODO pushManyPB...
-// return a bt object with s bt object appended to *b
+// return a btt object with s btt object appended to *b
// b doesn't need to have a heap allocated buffer
#define appendPBB pushPBB
-bt pushPBB(const bt *b, const bt s);
+btt pushPBB(const btt *b, const btt s);
// TODO pushManyPBB...
-// return a bt object with *s bt object appended to *b
+// return a btt object with *s btt object appended to *b
// b doesn't need to have a heap allocated buffer
#define appendPBPB pushPBPB
-bt pushPBPB(const bt *b, const bt *s);
+btt pushPBPB(const btt *b, const btt *s);
// TODO pushManyPBPB...
#define appendBG pushBG
#define pushBG(b, s) _Generic( b,\
- bt: _Generic(s,\
+ btt: _Generic(s,\
const char *: pushB,\
char *: pushB,\
- const bt: pushBB,\
- bt: pushBB,\
- const bt*: pushBPB,\
- bt*: pushBPB\
+ const btt: pushBB,\
+ btt: pushBB,\
+ const btt*: pushBPB,\
+ btt*: pushBPB\
),\
- bt*: _Generic(s,\
+ btt*: _Generic(s,\
const char *: bPushB,\
char *: bPushB,\
- const bt: bPushBB,\
- bt: bPushBB,\
- const bt*: bPushBPB,\
- bt*: bPushBPB\
+ const btt: bPushBB,\
+ btt: bPushBB,\
+ const btt*: bPushBPB,\
+ btt*: bPushBPB\
),\
- const bt*: _Generic(s,\
+ const btt*: _Generic(s,\
const char *: pushPB,\
char *: pushPB,\
- const bt: pushPBB,\
- bt: pushPBB,\
- const bt*: pushPBPB,\
- bt*: pushPBPB\
+ const btt: pushPBB,\
+ btt: pushPBB,\
+ const btt*: pushPBPB,\
+ btt*: pushPBPB\
)\
)(b, s)
-// bt catBF(const char *paramType, ...) MUST_CHECK;
+// btt catBF(const char *paramType, ...) MUST_CHECK;
#define catB(...) catBF("", __VA_ARGS__, NULL)
-// add allocates bt object
-// bt *addBF(const char *paramType, ...) MUST_CHECK;
+// add allocates btt object
+// btt *addBF(const char *paramType, ...) MUST_CHECK;
#define addB(...) catBF("", __VA_ARGS__, NULL)
-// %q to print bt
-// %Q to print bt*
+// %q to print btt
+// %Q to print btt*
// printB(char *fmt, ...)
// register %q and %Q
@@ -571,260 +571,260 @@ bt pushPBPB(const bt *b, const bt *s);
// split b in vb static vector
// the vector is not reallocated
-vbt *sasplitB(vbt *vb, const bt b, const bt delim);
+vbtt *sasplitB(vbtt *vb, const btt b, const btt delim);
// split b in vb static vector
// the vector is not reallocated
-vbt *sasplitCharB(vbt *vb, const bt b, char *delim);
+vbtt *sasplitCharB(vbtt *vb, const btt b, char *delim);
// split b in vb static vector
// the vector is not reallocated
-vbt *sasplitDPB(vbt *vb, const bt b, const bt *delim);
+vbtt *sasplitDPB(vbtt *vb, const btt b, const btt *delim);
// split b in vb static vector
// the vector is not reallocated
-vbt *sasplitPB(vbt *vb, const bt *b, const bt delim);
+vbtt *sasplitPB(vbtt *vb, const btt *b, const btt delim);
// split b in vb static vector
// the vector is not reallocated
-vbt *sasplitPCharB(vbt *vb, const bt *b, char *delim);
+vbtt *sasplitPCharB(vbtt *vb, const btt *b, char *delim);
// split b in vb static vector
// the vector is not reallocated
-vbt *sasplitPDPB(vbt *vb, const bt *b, const bt *delim);
+vbtt *sasplitPDPB(vbtt *vb, const btt *b, const btt *delim);
#define sasplitBG(vb, b, delim) _Generic(b,\
- bt: _Generic(delim,\
+ btt: _Generic(delim,\
char*: sasplitCharB,\
const char*: sasplitCharB,\
- bt: sasplitB,\
- const bt: sasplitB,\
- bt*: sasplitDPB,\
- const bt*: sasplitDPB),\
- const bt: _Generic(delim,\
+ btt: sasplitB,\
+ const btt: sasplitB,\
+ btt*: sasplitDPB,\
+ const btt*: sasplitDPB),\
+ const btt: _Generic(delim,\
char*: sasplitCharB,\
const char*: sasplitCharB,\
- bt: sasplitB,\
- const bt: sasplitB,\
- bt*: sasplitDPB,\
- const bt*: sasplitDPB),\
- bt*: _Generic(delim,\
+ btt: sasplitB,\
+ const btt: sasplitB,\
+ btt*: sasplitDPB,\
+ const btt*: sasplitDPB),\
+ btt*: _Generic(delim,\
char*: sasplitPCharB,\
const char*: sasplitPCharB,\
- bt: sasplitPB,\
- const bt: sasplitPB,\
- bt*: sasplitPDPB,\
- const bt*: sasplitPDPB),\
- const bt*: _Generic(delim,\
+ btt: sasplitPB,\
+ const btt: sasplitPB,\
+ btt*: sasplitPDPB,\
+ const btt*: sasplitPDPB),\
+ const btt*: _Generic(delim,\
char*: sasplitPCharB,\
const char*: sasplitPCharB,\
- bt: sasplitPB,\
- const bt: sasplitPB,\
- bt*: sasplitPDPB,\
- const bt*: sasplitPDPB)\
+ btt: sasplitPB,\
+ const btt: sasplitPB,\
+ btt*: sasplitPDPB,\
+ const btt*: sasplitPDPB)\
)(vb, b, delim)
// split b in vb vector
-vbt *asplitB(vbt *vb, const bt b, const bt delim);
+vbtt *asplitB(vbtt *vb, const btt b, const btt delim);
// split b in vb vector
-vbt *asplitCharB(vbt *vb, const bt b, char *delim);
+vbtt *asplitCharB(vbtt *vb, const btt b, char *delim);
// split b in vb vector
-vbt *asplitDPB(vbt *vb, const bt b, const bt *delim);
+vbtt *asplitDPB(vbtt *vb, const btt b, const btt *delim);
// split b in vb vector
-vbt *asplitPB(vbt *vb, const bt *b, const bt delim);
+vbtt *asplitPB(vbtt *vb, const btt *b, const btt delim);
// split b in vb vector
-vbt *asplitPCharB(vbt *vb, const bt *b, char *delim);
+vbtt *asplitPCharB(vbtt *vb, const btt *b, char *delim);
// split b in vb vector
-vbt *asplitPDPB(vbt *vb, const bt *b, const bt *delim);
+vbtt *asplitPDPB(vbtt *vb, const btt *b, const btt *delim);
#define asplitBG(vb, b, delim) _Generic(b,\
- bt: _Generic(delim,\
+ btt: _Generic(delim,\
char*: asplitCharB,\
const char*: asplitCharB,\
- bt: asplitB,\
- const bt: asplitB,\
- bt*: asplitDPB,\
- const bt*: asplitDPB),\
- const bt: _Generic(delim,\
+ btt: asplitB,\
+ const btt: asplitB,\
+ btt*: asplitDPB,\
+ const btt*: asplitDPB),\
+ const btt: _Generic(delim,\
char*: asplitCharB,\
const char*: asplitCharB,\
- bt: asplitB,\
- const bt: asplitB,\
- bt*: asplitDPB,\
- const bt*: asplitDPB),\
- bt*: _Generic(delim,\
+ btt: asplitB,\
+ const btt: asplitB,\
+ btt*: asplitDPB,\
+ const btt*: asplitDPB),\
+ btt*: _Generic(delim,\
char*: asplitPCharB,\
const char*: asplitPCharB,\
- bt: asplitPB,\
- const bt: asplitPB,\
- bt*: asplitPDPB,\
- const bt*: asplitPDPB),\
- const bt*: _Generic(delim,\
+ btt: asplitPB,\
+ const btt: asplitPB,\
+ btt*: asplitPDPB,\
+ const btt*: asplitPDPB),\
+ const btt*: _Generic(delim,\
char*: asplitPCharB,\
const char*: asplitPCharB,\
- bt: asplitPB,\
- const bt: asplitPB,\
- bt*: asplitPDPB,\
- const bt*: asplitPDPB)\
+ btt: asplitPB,\
+ const btt: asplitPB,\
+ btt*: asplitPDPB,\
+ const btt*: asplitPDPB)\
)(vb, b, delim)
-// return vbt vector with tokens from b
+// return vbtt vector with tokens from b
// this function has good performance for small element counts
-vbt splitB(const bt b, const bt delim);
+vbtt splitB(const btt b, const btt delim);
-// return vbt vector with tokens from b
+// return vbtt vector with tokens from b
// this function has good performance for small element counts
-vbt splitCharB(const bt b, char *delim);
+vbtt splitCharB(const btt b, char *delim);
// split b in vb vector
-vbt splitDPB(const bt b, const bt *delim);
+vbtt splitDPB(const btt b, const btt *delim);
// split b in vb vector
-vbt splitPB(const bt *b, const bt delim);
+vbtt splitPB(const btt *b, const btt delim);
-// return vbt vector with tokens from b
+// return vbtt vector with tokens from b
// this function has good performance for small element counts
-vbt splitPCharB(const bt *b, char *delim);
+vbtt splitPCharB(const btt *b, char *delim);
// split b in vb vector
-vbt splitPDPB(const bt *b, const bt *delim);
+vbtt splitPDPB(const btt *b, const btt *delim);
#define splitBG(b, delim) _Generic(b,\
- bt: _Generic(delim,\
+ btt: _Generic(delim,\
char*: splitCharB,\
const char*: splitCharB,\
- bt: splitB,\
- const bt: splitB,\
- bt*: splitDPB,\
- const bt*: splitDPB),\
- const bt: _Generic(delim,\
+ btt: splitB,\
+ const btt: splitB,\
+ btt*: splitDPB,\
+ const btt*: splitDPB),\
+ const btt: _Generic(delim,\
char*: splitCharB,\
const char*: splitCharB,\
- bt: splitB,\
- const bt: splitB,\
- bt*: splitDPB,\
- const bt*: splitDPB),\
- bt*: _Generic(delim,\
+ btt: splitB,\
+ const btt: splitB,\
+ btt*: splitDPB,\
+ const btt*: splitDPB),\
+ btt*: _Generic(delim,\
char*: splitPCharB,\
const char*: splitPCharB,\
- bt: splitPB,\
- const bt: splitPB,\
- bt*: splitPDPB,\
- const bt*: splitPDPB),\
- const bt*: _Generic(delim,\
+ btt: splitPB,\
+ const btt: splitPB,\
+ btt*: splitPDPB,\
+ const btt*: splitPDPB),\
+ const btt*: _Generic(delim,\
char*: splitPCharB,\
const char*: splitPCharB,\
- bt: splitPB,\
- const bt: splitPB,\
- bt*: splitPDPB,\
- const bt*: splitPDPB)\
+ btt: splitPB,\
+ const btt: splitPB,\
+ btt*: splitPDPB,\
+ const btt*: splitPDPB)\
)(b, delim)
-// return dbt vector with tokens from b
+// return dbtt vector with tokens from b
// this function has good performance for large element counts
-dbt dsplitB(const bt b, const bt delim);
+dbtt dsplitB(const btt b, const btt delim);
-// return dbt vector with tokens from b
+// return dbtt vector with tokens from b
// this function has good performance for large element counts
-dbt dsplitCharB(const bt b, char *delim);
+dbtt dsplitCharB(const btt b, char *delim);
-// return dbt vector with tokens from b
+// return dbtt vector with tokens from b
// this function has good performance for large element counts
-dbt dsplitDPB(const bt b, const bt *delim);
+dbtt dsplitDPB(const btt b, const btt *delim);
-// return dbt vector with tokens from b
+// return dbtt vector with tokens from b
// this function has good performance for large element counts
-dbt dsplitPB(const bt *b, const bt delim);
+dbtt dsplitPB(const btt *b, const btt delim);
-// return dbt vector with tokens from b
+// return dbtt vector with tokens from b
// this function has good performance for large element counts
-dbt dsplitPCharB(const bt *b, char *delim);
+dbtt dsplitPCharB(const btt *b, char *delim);
-// return dbt vector with tokens from b
+// return dbtt vector with tokens from b
// this function has good performance for large element counts
-dbt dsplitPDPB(const bt *b, const bt *delim);
+dbtt dsplitPDPB(const btt *b, const btt *delim);
#define dsplitBG(b, delim) _Generic(b,\
- bt: _Generic(delim,\
+ btt: _Generic(delim,\
char*: dsplitCharB,\
const char*: dsplitCharB,\
- bt: dsplitB,\
- const bt: dsplitB,\
- bt*: dsplitDPB,\
- const bt*: dsplitDPB),\
- const bt: _Generic(delim,\
+ btt: dsplitB,\
+ const btt: dsplitB,\
+ btt*: dsplitDPB,\
+ const btt*: dsplitDPB),\
+ const btt: _Generic(delim,\
char*: dsplitCharB,\
const char*: dsplitCharB,\
- bt: dsplitB,\
- const bt: dsplitB,\
- bt*: dsplitDPB,\
- const bt*: dsplitDPB),\
- bt*: _Generic(delim,\
+ btt: dsplitB,\
+ const btt: dsplitB,\
+ btt*: dsplitDPB,\
+ const btt*: dsplitDPB),\
+ btt*: _Generic(delim,\
char*: dsplitPCharB,\
const char*: dsplitPCharB,\
- bt: dsplitPB,\
- const bt: dsplitPB,\
- bt*: dsplitPDPB,\
- const bt*: dsplitPDPB),\
- const bt*: _Generic(delim,\
+ btt: dsplitPB,\
+ const btt: dsplitPB,\
+ btt*: dsplitPDPB,\
+ const btt*: dsplitPDPB),\
+ const btt*: _Generic(delim,\
char*: dsplitPCharB,\
const char*: dsplitPCharB,\
- bt: dsplitPB,\
- const bt: dsplitPB,\
- bt*: dsplitPDPB,\
- const bt*: dsplitPDPB)\
+ btt: dsplitPB,\
+ const btt: dsplitPB,\
+ btt*: dsplitPDPB,\
+ const btt*: dsplitPDPB)\
)(b, delim)
// slice String
-// return a bt object which is the string between start and end
+// return a btt object which is the string between start and end
// negative indexes are allowed
-bt sliceB(const bt b, int64_t start, int64_t end);
+btt sliceB(const btt b, int64_t start, int64_t end);
// slice String
-// update the b bt object and keep only the string between start and end
+// update the b btt object and keep only the string between start and end
// negative indexes are allowed
-bt *bSliceB(bt *b, int64_t start, int64_t end);
+btt *bSliceB(btt *b, int64_t start, int64_t end);
// slice String
-// return a bt object which is the string between start and end
+// return a btt object which is the string between start and end
// negative indexes are allowed
-bt slicePB(const bt *b, int64_t start, int64_t end);
+btt slicePB(const btt *b, int64_t start, int64_t end);
#define sliceBG(b, start, end) _Generic(b,\
- bt: sliceB,\
- const bt: sliceB,\
- bt*: bSliceB,\
- const bt*: slicePB\
+ btt: sliceB,\
+ const btt: sliceB,\
+ btt*: bSliceB,\
+ const btt*: slicePB\
)(b, start, end);
-// return a bt object without the leading and trailing spaces
-bt trimB(const bt b);
+// return a btt object without the leading and trailing spaces
+btt trimB(const btt b);
-// update b bt object and remove the leading and trailing spaces
-bt *bTrimB(bt *b);
+// update b btt object and remove the leading and trailing spaces
+btt *bTrimB(btt *b);
-// return a bt object without the leading and trailing spaces
-bt trimPB(const bt *b);
+// return a btt object without the leading and trailing spaces
+btt trimPB(const btt *b);
#define trimBG(b) _Generic(b,\
- bt: trimB,\
- const bt: trimB,\
- bt*: bTrimB,\
- const bt*: trimPB\
+ btt: trimB,\
+ const btt: trimB,\
+ btt*: bTrimB,\
+ const btt*: trimPB\
)(b)
-void printB(const bt b);
+void printB(const btt b);
-void printDebugB(const bt b);
+void printDebugB(const btt b);
-void printDebugInfoB(const bt b);
+void printDebugInfoB(const btt b);
// vim: set expandtab ts=2 sw=2:
diff --git a/release/libsheepyObject.h b/release/libsheepyObject.h
@@ -158,10 +158,10 @@ static const bool checkObjectTypes = true;
const char *: allocSmallString, \
char **: allocArraySmallArray, \
const char **: allocCArraySmallArray, \
- bt: allocB, \
- const bt: allocB, \
- bt*: allocPB, \
- const bt*: allocPB \
+ btt: allocB, \
+ const btt: allocB, \
+ btt*: allocPB, \
+ const btt*: allocPB \
)(value)
@@ -333,10 +333,10 @@ void terminateManyOF(void *paramType, ...);
char***: "char***", \
void*: "void*", \
FILE*: "FILE*", \
- bt: "bt", \
- bt*: "bt*", \
- const bt: "const bt", \
- const bt*: "const bt*", \
+ btt: "btt", \
+ btt*: "btt*", \
+ const btt: "const btt", \
+ const btt*: "const btt*", \
default: NULL \
)
@@ -701,31 +701,31 @@ void finishManyOF(void *paramType, ...);
int: listPushCharS, \
default: listPushS \
), \
- bt: _Generic(value, \
+ btt: _Generic(value, \
const char *: pushB, \
char *: pushB, \
- const bt: pushBB, \
- bt: pushBB, \
- const bt*: pushBPB, \
- bt*: pushBPB, \
+ const btt: pushBB, \
+ btt: pushBB, \
+ const btt*: pushBPB, \
+ btt*: pushBPB, \
default: pushB \
), \
- bt*: _Generic(value, \
+ btt*: _Generic(value, \
const char *: bPushB, \
char *: bPushB, \
- const bt: bPushBB, \
- bt: bPushBB, \
- const bt*: bPushBPB, \
- bt*: bPushBPB, \
+ const btt: bPushBB, \
+ btt: bPushBB, \
+ const btt*: bPushBPB, \
+ btt*: bPushBPB, \
default: bPushB \
), \
- const bt*: _Generic(value, \
+ const btt*: _Generic(value, \
const char *: pushPB, \
char *: pushPB, \
- const bt: pushPBB, \
- bt: pushPBB, \
- const bt*: pushPBPB, \
- bt*: pushPBPB, \
+ const btt: pushPBB, \
+ btt: pushPBB, \
+ const btt*: pushPBPB, \
+ btt*: pushPBPB, \
default: pushPB) \
)(self, value)
@@ -923,6 +923,7 @@ void finishManyOF(void *paramType, ...);
smallContainert*: setAtSmallContainerSmallArrayG, \
undefinedt*: setAtUndefinedSmallArrayG, \
default: setAtVoidSmallArrayG), \
+ smallBytest*: setSmallBytesG,\
smallJsont*: _Generic(key, \
char *: _Generic((value), \
baset*: setSmallJsonG, \
@@ -3772,8 +3773,8 @@ void finishManyOF(void *paramType, ...);
const char *: dupS,\
char **: listDupS, \
const char **: listDupCG, \
- bt: dupB, \
- bt*: dupPB \
+ btt: dupB, \
+ btt*: dupPB \
)(self)
#define replaceO(self, olds, news, max) (self)->f->replace(self, olds, news, max)
@@ -5192,10 +5193,10 @@ void finishManyOF(void *paramType, ...);
smallDictt *: trimSmallDictG, \
smallJsont *: trimSmallJsonG, \
smallStringt *: trimSmallStringG, \
- bt: trimB, \
- const bt: trimB, \
- bt*: bTrimB, \
- const bt*: trimPB \
+ btt: trimB, \
+ const btt: trimB, \
+ btt*: bTrimB, \
+ const btt*: trimPB \
)(self)
#define lTrimO(self) (self)->f->lTrim(self)
@@ -5247,10 +5248,10 @@ void finishManyOF(void *paramType, ...);
smallArrayt *: sliceSmallArrayG, \
smallJsont *: sliceSmallJsonG, \
smallStringt *: sliceSmallStringG, \
- bt: sliceB, \
- const bt: sliceB, \
- bt*: bSliceB, \
- const bt*: slicePB \
+ btt: sliceB, \
+ const btt: sliceB, \
+ btt*: bSliceB, \
+ const btt*: slicePB \
)(self, start, end)
@@ -6679,37 +6680,37 @@ void finishManyOF(void *paramType, ...);
smallStringt *: splitSmallStringSmallStringG, \
default: splitSmallStringG \
), \
- bt: _Generic(delim, \
+ btt: _Generic(delim, \
char*: splitCharB, \
const char*: splitCharB, \
- bt: splitB, \
- const bt: splitB, \
- bt*: splitDPB, \
- const bt*: splitDPB, \
+ btt: splitB, \
+ const btt: splitB, \
+ btt*: splitDPB, \
+ const btt*: splitDPB, \
default: splitB), \
- const bt: _Generic(delim, \
+ const btt: _Generic(delim, \
char*: splitCharB, \
const char*: splitCharB, \
- bt: splitB, \
- const bt: splitB, \
- bt*: splitDPB, \
- const bt*: splitDPB, \
+ btt: splitB, \
+ const btt: splitB, \
+ btt*: splitDPB, \
+ const btt*: splitDPB, \
default: splitB), \
- bt*: _Generic(delim, \
+ btt*: _Generic(delim, \
char*: splitPCharB, \
const char*: splitPCharB, \
- bt: splitPB, \
- const bt: splitPB, \
- bt*: splitPDPB, \
- const bt*: splitPDPB, \
+ btt: splitPB, \
+ const btt: splitPB, \
+ btt*: splitPDPB, \
+ const btt*: splitPDPB, \
default: splitPB),\
- const bt*: _Generic(delim, \
+ const btt*: _Generic(delim, \
char*: splitPCharB, \
const char*: splitPCharB, \
- bt: splitPB, \
- const bt: splitPB, \
- bt*: splitPDPB, \
- const bt*: splitPDPB, \
+ btt: splitPB, \
+ const btt: splitPB, \
+ btt*: splitPDPB, \
+ const btt*: splitPDPB, \
default: splitPB)\
)(self, delim)
@@ -8297,9 +8298,6 @@ void finishManyOF(void *paramType, ...);
#define setCArraycO(self, key, array) (self)->f->setCArrayc(self, key, array)
#define setCArraycG setCArraycO
-#define setSmallBytesO(self, key, value) (self)->f->setSmallBytes(self, key, value)
-#define setSmallBytesG setSmallBytesO
-
#define setKCharO(self, key, value) (self)->f->setKChar(self, key, value)
#define setKCharG setKCharO
diff --git a/src/json/libsheepyCSmallBytes.c b/src/json/libsheepyCSmallBytes.c
@@ -83,6 +83,7 @@ internal bool equalSmallBytesChar(smallBytest *self, const char *value);
internal bool equalSmallBytesSmallString(smallBytest *self, smallStringt *value);
internal bool equalSmallBytesBase(smallBytest *self, baset *value);
smallBytest* duplicateSmallBytesG (smallBytest *self);
+smallBytest* setSmallBytesG(smallBytest *self, void *data, uint32_t size);
char getAtSmallBytesG(smallBytest *self, char retType UNUSED, int64_t index);
smallBytest* pushSmallBytesG (smallBytest *self, char data);
size_t lenSmallBytesG(smallBytest *self);
@@ -849,6 +850,11 @@ smallBytest* duplicateSmallBytesG (smallBytest *self) {
void freeSmallBytesG (smallBytest *self) {self->f->free(self);}
+smallBytest* setSmallBytesG(smallBytest *self, void *data, uint32_t size) {
+
+ return(self->f->set(self, data, size));
+}
+
char getAtSmallBytesG(smallBytest *self, char retType UNUSED, int64_t index) {
return(self->f->getAt(self,index));
diff --git a/src/json/libsheepyCSmallBytes.h b/src/json/libsheepyCSmallBytes.h
@@ -300,6 +300,7 @@ smallBytest* duplicateSmallBytesG (smallBytest *self);
void freeSmallBytesG (smallBytest *self);
+smallBytest* setSmallBytesG(smallBytest *self, void *data, uint32_t size);
char getAtSmallBytesG(smallBytest *self, char retType UNUSED, int64_t index);
smallBytest* pushSmallBytesG (smallBytest *self, char data);
size_t lenSmallBytesG(smallBytest *self);
diff --git a/src/libsheepy.c b/src/libsheepy.c
@@ -98,6 +98,7 @@ void setLogShortPath(bool shortPath);
bool getLogStdout(void);
void setLogStdout(bool state);
bool openProgLogFile(void);
+void keepAnsiColorsInLog(bool state);
void _pLog(int loglevel, const char *file, const char *func, int line, const char *msg, ...);
#if (!(__APPLE__ || __FreeBSD__ || __TERMUX__ || __OpenBSD__ || __DragonFly__ || MUSL_LIBC || __sun__ || __HAIKU__))
int print_k(FILE *stream, const struct printf_info *info, const void *const *args);
@@ -341,6 +342,9 @@ bool hasCtrlChar(const char *string);
char *stripCtrlS(const char *string);
char *iStripCtrlS(char **string);
char *bStripCtrlS(char *string);
+char *stripColorsS(const char *string);
+char *iStripColorsS(char **string);
+char *bStripColorsS(char *string);
bool isNumber(const char *string);
bool isInt(const char *string);
int64_t parseInt(const char *string);
@@ -1009,6 +1013,8 @@ static bool _log_verbose_short_path = true;
static bool _logToStdout = true;
+static bool keepAnsiColors = true;
+
// logging file 0 is stdout
static uint16_t _current_log_file = 1;
@@ -1212,6 +1218,16 @@ bool openProgLogFile(void) {
return(true);
}
+/**
+ * enable/disable ansi color codes in logs
+ *
+ * TRUE: print colors
+ * FALSE: strip colors
+ */
+void keepAnsiColorsInLog(bool state) {
+
+ keepAnsiColors = state;
+}
/**
* print logging levels
@@ -1268,7 +1284,7 @@ void _pLog(int loglevel, const char *file, const char *func, int line, const cha
}
// set console color for printing the tag
- if (_logToStdout) {
+ if (_logToStdout && keepAnsiColors) {
switch (loglevel) {
case LOG_EMERGENCY:
printf(BLD RED);
@@ -1304,6 +1320,12 @@ void _pLog(int loglevel, const char *file, const char *func, int line, const cha
}
}
+ if (!keepAnsiColors) {
+ if (!bStripColorsS(buffer)) {
+ return;
+ }
+ }
+
// long or short file path in VERBOSE mode
if ((_log_current_mode == LOG_VERBOSE) && _log_verbose_short_path) {
const char *slashP[3] = {NULL, NULL, NULL};
@@ -9554,6 +9576,243 @@ char *bStripCtrlS(char *string) {
}
/**
+ * remove ansi colors from string
+ *
+ * \param
+ * string
+ * \return
+ * new string without colors
+ * NULL when string is NULL
+ */
+char *stripColorsS(const char *string) {
+ char *r = NULL;
+
+ if (!string) {
+ return(NULL);
+ }
+
+ size_t len = strlen(string)+1;
+ r = MALLOC(len);
+ if (!r) {
+ return(NULL);
+ }
+
+ size_t j = 0;
+ uint16_t state = 0;
+ range(i, len) {
+ char ch = string[i];
+ // suppress \r only when followed by \n
+ if (state == 1) {
+ if (ch != 0x0d) {
+ state = 0;
+ }
+ if (ch != 0x0a) {
+ r[j++] = 0x0d;
+ }
+ }
+ if (state == 0 && ch == 0x0d) {
+ state = 1;
+ }
+ // strip colors
+ if (state == 5) {
+ state = 0;
+ continue;
+ }
+ if (state == 4) {
+ if (ch == 7) {
+ state = 0;
+ continue;
+ }
+ elif (ch == 0x1b) {
+ state = 5;
+ }
+ }
+ if (state == 3) {
+ if (ch != ';' && (ch < '0' || ch > '9') && ch != '?') {
+ state = 0;
+ continue;
+ }
+ }
+ if (state == 2) {
+ if (ch == '[') {
+ state = 3;
+ }
+ elif (ch == ']' && string[i+1] <= '9') {
+ state = 4;
+ }
+ elif (ch == '%') {
+ state = 0;
+ continue;
+ }
+ }
+ if (state == 0 && ch == 0x1b) {
+ state = 2;
+ }
+ if (state == 0) {
+ r[j++] = ch;
+ }
+ }
+ r[j] = 0;
+ return(r);
+}
+
+/**
+ * remove ansi colors from string
+ *
+ * \param
+ * string pointer to a string
+ * \return
+ * string without the control chars
+ * NULL when string is NULL
+ */
+char *iStripColorsS(char **string) {
+
+ if (!string || !*string) {
+ return(NULL);
+ }
+
+ size_t i = 0, j = 0;
+ uint16_t state = 0;
+
+ while ((*string)[i]) {
+ char ch = (*string)[i];
+ // suppress \r only when followed by \n
+ if (state == 1) {
+ if (ch != 0x0d) {
+ state = 0;
+ }
+ if (ch != 0x0a) {
+ (*string)[j++] = 0x0d;
+ }
+ }
+ if (state == 0 && ch == 0x0d) {
+ state = 1;
+ }
+ // strip colors
+ if (state == 5) {
+ state = 0;
+ goto cont;
+ }
+ if (state == 4) {
+ if (ch == 7) {
+ state = 0;
+ goto cont;
+ }
+ elif (ch == 0x1b) {
+ state = 5;
+ }
+ }
+ if (state == 3) {
+ if (ch != ';' && (ch < '0' || ch > '9') && ch != '?') {
+ state = 0;
+ goto cont;
+ }
+ }
+ if (state == 2) {
+ if (ch == '[') {
+ state = 3;
+ }
+ elif (ch == ']' && (*string)[i+1] <= '9') {
+ state = 4;
+ }
+ elif (ch == '%') {
+ state = 0;
+ goto cont;
+ }
+ }
+ if (state == 0 && ch == 0x1b) {
+ state = 2;
+ }
+ if (state == 0) {
+ (*string)[j++] = ch;
+ }
+ cont:
+ i++;
+ }
+
+ (*string)[j] = 0;;
+ return(*string);
+}
+
+/**
+ * remove terminal control char from string
+ *
+ * \param
+ * string
+ * \return
+ * string without the control chars
+ * NULL when string is NULL
+ */
+char *bStripColorsS(char *string) {
+
+ if (!string) {
+ return(NULL);
+ }
+
+ size_t i = 0, j = 0;
+ uint16_t state = 0;
+
+ while (string[i]) {
+ char ch = string[i];
+ // suppress \r only when followed by \n
+ if (state == 1) {
+ if (ch != 0x0d) {
+ state = 0;
+ }
+ if (ch != 0x0a) {
+ string[j++] = 0x0d;
+ }
+ }
+ if (state == 0 && ch == 0x0d) {
+ state = 1;
+ }
+ // strip colors
+ if (state == 5) {
+ state = 0;
+ goto cont;
+ }
+ if (state == 4) {
+ if (ch == 7) {
+ state = 0;
+ goto cont;
+ }
+ elif (ch == 0x1b) {
+ state = 5;
+ }
+ }
+ if (state == 3) {
+ if (ch != ';' && (ch < '0' || ch > '9') && ch != '?') {
+ state = 0;
+ goto cont;
+ }
+ }
+ if (state == 2) {
+ if (ch == '[') {
+ state = 3;
+ }
+ elif (ch == ']' && string[i+1] <= '9') {
+ state = 4;
+ }
+ elif (ch == '%') {
+ state = 0;
+ goto cont;
+ }
+ }
+ if (state == 0 && ch == 0x1b) {
+ state = 2;
+ }
+ if (state == 0) {
+ string[j++] = ch;
+ }
+ cont:
+ i++;
+ }
+
+ string[j] = 0;;
+ return(string);
+}
+
+/**
* is Number (integer or float) String
*
* 1, -12
@@ -56465,906 +56724,897 @@ int MAIN(int ARGC, char** ARGV) {
char **l UNUSED = NULL;
argc = ARGC; argv = ARGV;
- typ struct {int a; int b;} structuret;;
-
- logSystem("git log -n 2 --pretty=\"%ai\"");
-
- sliceT(slStruct, structuret);
- slStruct slc;
- sliceInit(&slc);
- slicePush(&slc);
- slicePush(&slc);
- sliceEnumerate(&slc, i, elm) {
- elm->a = 0;;
- elm->b = 0;;
- printf("sliceEnumerate %zd\n", i);
- }
- sliceFree(&slc);
-
- // list
-
- /* i8 a = 0 */
- /* i16 s = 0 */
- /* i32 d = 0 */
- /* i64 f = 0 */
- /* u8 g = 0 */
- /* u16 h = 0 */
- /* u32 j = 0 */
- u64 k = 7;
- /* f32 x = 0 */
- /* f64 p = 0 */
-
-
- char *toBCroped = strdup("123456");
- char *crp = iCropS(&toBCroped, -1, 1);
- logVar(toBCroped, "s");
- logVar(crp, "s");
-
- char **lst = listCreateS("1","2","3","4","5");
- char **lcrop = listCropS(lst, 1,3);
- pError0(listPrintS(lst));
- AT
- pError0(listPrintS(lcrop));
-
- setLogStdout(no);
-
- logExit(EXIT_SUCCESS, "qweqwe");
- logXSuccess("qweqwe");
- logXFailure("qweqwe");
-
- logSystemf("ls /home/%s/.ssh/", "remy");
-
- char *rel = relPath("/wer/w/e", "../wer/ef");;
- printf("rel path %s\n", rel);
- free(rel);
-
- //printf(">%s< %zu\n",nS(padEndS("123", 10, "-=|=123123")), lenS(padEndS("123", 10, "-=|=123123")));
- char *e = ellipsisStartS("123", 10, "...");;
- printf("ellipsis start %s\n", e);
- free(e);
- e =ellipsisStartS("1234567890", 10, "...");
- printf("ellipsis start %s\n", e);
- free(e);
- e =ellipsisStartS("1234567890abcdef", 10, "...");
- printf("ellipsis start %s\n", e);
- free(e);
- e =ellipsisStartS("1234567890abcdef", 10, "...xxxxxxxxxxxxxxxxxxxxxxxxx");
- printf("ellipsis start %s\n", e);
- free(e);
- e =ellipsisEndS("123", 10, "...");
- printf("ellipsis end %s\n", e);
- free(e);
- e =ellipsisEndS("1234567890", 10, "...");
- printf("ellipsis end %s\n", e);
- free(e);
- e =ellipsisEndS("1234567890abcdef", 10, "...");
- printf("ellipsis end %s\n", e);
- free(e);
- e =ellipsisEndS("1234567890abcdef", 10, "...****************************");
- printf("ellipsis end %s\n", e);
- free(e);
-
- XSUCCESS
-
- char a[8192] = "";
-
- initLibsheepy("exe");
- setLogSymbols(LOG_UTF8);
-
- logVar(absV(-2), "d");
- logVar(CMP(2,2), "d");
-
- char **li = NULL;
- //char **li2;
-
- // list negative index
- pErrorNULL(listPushS(&li, "1"));
- pErrorNULL(listPushS(&li, "22"));
- pErrorNULL(listPushS(&li, "333"));
- pErrorNULL(listPushS(&li, "4444"));
- //li2 = iListCropS(&li, 1,-1)
- char *stri = iListCropElemS(&li, 1);
-
- pError0(listPrintS(li));
- put
- puts(stri);
- //listPrintS(li2);
-
- XSUCCESS
-
- sliceT(slicet, char*);
- slicet slce;
- sliceInit(&slce);
- //sliceElemType(&slce) slEl;
-
- staticSliceT(sslicet, char*, 2);
- sslicet sslce;
- staticSliceInit(&sslce);
- staticSlicePush(&sslce);
- //staticSliceForEach(&sslce, S UNUSED) S = NULL;
- //staticSliceEnumerate(&sslce, iS, S UNUSED) S = NULL;
-
- //staticSliceElemType(&sslce) sslEl;
-
- puts(getCurrentDate());
-
- vectorT(vect, char *);
-
- vect vec;
-
- //vectorElemType(&vec) vecE;
-
- vectorInitCount(&vec, 17);
-
-
- logVar(vectorMaxCount(&vec), "zu");
- logVar(vectorCount(&vec), "zu");
-
- vectorAppend(&vec, "qwe");
- vectorAppend(&vec, "2345");
-
- //vectorForEach(&vec, S UNUSED) S = NULL;
- //vectorEnumerate(&vec, iv, S) S = NULL;
-
- logVar(vectorMaxCount(&vec), "zu");
- logVar(vectorCount(&vec), "zu");
-
- char *vc = vectorAt(&vec, 1);
- logI(vc);
+ /* typ struct {int a; int b;} structuret; */
- forEachV(&vec, i) { {
- logI(vectorAt(&vec, i));
- }
- }
-
- vectorDelElem(&vec, 0);
-
- vc = vectorDequeue(&vec);
- logI(vc);
-
-
- logVar(vectorMaxCount(&vec), "zu");
- logVar(vectorCount(&vec), "zu");
-
- vectorInject(&vec, 0);
-
- logVar(vectorMaxCount(&vec), "zu");
- logVar(vectorCount(&vec), "zu");
+ cleanCharP(nocolor) = stripColorsS(BLD RED"RED is a primary color"RST);;
+ puts(nocolor);
+ logE(BLD RED"RED is a primary color"RST);
+ keepAnsiColorsInLog(no);
+ logE(BLD RED"RED is a primary color"RST);
- vectorAt(&vec, 0) = "#$345";
-
- forEachV(&vec, i) { {
- logI(vectorAt(&vec, i));
- }
- }
-
- var v = vectorCopy(&vec, 0, 1);;
-
- logI("copy");
-
- forEachV(v, i) { {
- logI(vectorAt(v, i));
- }
- }
-
- vectorTerminate(v);
-
- vectorFree(&vec);
-
- dVectorT(dvect, void*);
- dvect dvec;
- dVectorInit(&dvec);
- //dVectorElemType(&dvec) dvecE;
-
- //dVectorForEach(&dvec, S UNUSED) S = NULL;
- //dVectorEnumerate(&dvec, idv, S UNUSED) S = NULL;
- XSUCCESS
-
-
- char *h;
- puts(h = toHexS("123", 4));;
- free(h);
- puts(h = toHexSepS("123", 4, ","));;
- free(h);
- puts(h = toHexHeadSepS("123", 3, "\\x", ""));;
- free(h);
- logSI("Buf: [%s]", toHexSepS("123", 4, ","));
- logSMI(1,"Mask Buf: [%s]", toHexSepS("123", 4, ","));
-
- const char *AA[] = {"WER", "asd", NULL};
- char **CA = listCreateS("zxc", "cvb");;
-
- pError0(listPrintS((char**)AA));
- pError0(listPrintS(CA));
-
- char *utf8 = "Футбол России и мира, новости футбола, видео голов...";;
- char *utf8_l6 = "Футбол";;
- char *utg8_l6 = "/åäöéà";;
- // extra bytes for bLPtr2IdxUTF8
- //char *utg8_l6bad = "/åäöéàX";
- char aq[20] = {0x66, 0x7e, 0xc6,0xc1, 0};;
-
- puts("---------------");
- puts(shDirname("./wer"));
- puts(shDirname("wer"));
- puts(shDirname("DFGDFG/wer"));
- puts("---------------");
-
- logVar(strlen(utf8_l6), "zu");
- logVar(lenUTF8(utf8_l6), "zu");
- logVar(isUTF8(utf8_l6), "b");
- puts(utf8_l6);
- logVar(strlen(utg8_l6), "zu");
- logVar(lenUTF8(utg8_l6), "zu");
- logVar(bLLenUTF8(utg8_l6,3), "zu");
- logVar(isUTF8(utg8_l6), "b");
- // idx2PtrUTF8 test
- logPtr(utg8_l6);
- logPtr(utg8_l6+strlen(utg8_l6));
- logVar(makeValidUTF8(utg8_l6), "s");
- logVar(makeValidUTF8(aq), "s");
- pErrorNULL(strNCpyUTF8(aq, utg8_l6, 5));
- logVar(aq, "s");
- /* logVar(ptr2IdxUTF8(utg8_l6, utg8_l6+strlen(utg8_l6)+1),"d"); */
- /* logVar(ptr2IdxUTF8(utg8_l6, utg8_l6),"d"); */
- /* logVar(ptr2IdxUTF8(utg8_l6, utg8_l6+1),"d"); */
- /* logVar(ptr2IdxUTF8(utg8_l6, utg8_l6+2),"d"); */
- /* logVar(ptr2IdxUTF8(utg8_l6, utg8_l6+3),"d"); */
- /* logVar(ptr2IdxUTF8(utg8_l6, utg8_l6+10),"d"); */
- /* logVar(ptr2IdxUTF8(utg8_l6, utg8_l6+11),"d"); */
- /* logVar(ptr2IdxUTF8(utg8_l6, utg8_l6+12),"d"); */
- /* logVar(bPtr2IdxUTF8(utg8_l6, utg8_l6, utg8_l6+strlen(utg8_l6)+1),"d"); */
- /* logVar(bPtr2IdxUTF8(utg8_l6, utg8_l6, utg8_l6),"d"); */
- /* logVar(bPtr2IdxUTF8(utg8_l6, utg8_l6, utg8_l6+1),"d"); */
- /* logVar(bPtr2IdxUTF8(utg8_l6, utg8_l6, utg8_l6+2),"d"); */
- /* logVar(bPtr2IdxUTF8(utg8_l6, utg8_l6, utg8_l6+3),"d"); */
- /* logVar(bPtr2IdxUTF8(utg8_l6, utg8_l6, utg8_l6+10),"d"); */
- /* logVar(bPtr2IdxUTF8(utg8_l6, utg8_l6, utg8_l6+11),"d"); */
- /* logVar(bPtr2IdxUTF8(utg8_l6, utg8_l6, utg8_l6+12),"d"); */
- /* logVar(bLPtr2IdxUTF8(utg8_l6, strlen(utg8_l6)+1, utg8_l6+strlen(utg8_l6)+1),"d"); */
- /* logVar(bLPtr2IdxUTF8(utg8_l6, strlen(utg8_l6)+1, utg8_l6),"d"); */
- /* logVar(bLPtr2IdxUTF8(utg8_l6, strlen(utg8_l6)+1, utg8_l6+1),"d"); */
- /* logVar(bLPtr2IdxUTF8(utg8_l6, strlen(utg8_l6)+1, utg8_l6+2),"d"); */
- /* logVar(bLPtr2IdxUTF8(utg8_l6, strlen(utg8_l6)+1, utg8_l6+3),"d"); */
- /* logVar(bLPtr2IdxUTF8(utg8_l6, strlen(utg8_l6)+1, utg8_l6+10),"d"); */
- /* logVar(bLPtr2IdxUTF8(utg8_l6, strlen(utg8_l6)+1, utg8_l6+11),"d"); */
- /* logVar(bLPtr2IdxUTF8(utg8_l6, strlen(utg8_l6)+1, utg8_l6+12),"d"); */
- /* logVar(bLPtr2IdxUTF8(utg8_l6bad, strlen(utg8_l6)+1, utg8_l6bad+strlen(utg8_l6)+1),"d"); */
- /* logVar(bLPtr2IdxUTF8(utg8_l6bad, strlen(utg8_l6)+1, utg8_l6bad),"d"); */
- /* logVar(bLPtr2IdxUTF8(utg8_l6bad, strlen(utg8_l6)+1, utg8_l6bad+1),"d"); */
- /* logVar(bLPtr2IdxUTF8(utg8_l6bad, strlen(utg8_l6)+1, utg8_l6bad+2),"d"); */
- /* logVar(bLPtr2IdxUTF8(utg8_l6bad, strlen(utg8_l6)+1, utg8_l6bad+3),"d"); */
- /* logVar(bLPtr2IdxUTF8(utg8_l6bad, strlen(utg8_l6)+1, utg8_l6bad+10),"d"); */
- /* logVar(bLPtr2IdxUTF8(utg8_l6bad, strlen(utg8_l6)+1, utg8_l6bad+11),"d"); */
- /* logVar(bLPtr2IdxUTF8(utg8_l6bad, strlen(utg8_l6)+1, utg8_l6bad+12),"d"); */
- // negative index
- /* loghex(utg8_l6, strlen(utg8_l6)+1);put */
- /* logVar(ptr2IdxUTF8(utg8_l6+strlen(utg8_l6),utg8_l6),"d"); */
- /* logVar(ptr2IdxUTF8(utg8_l6+strlen(utg8_l6),utg8_l6+1),"d"); */
- /* logVar(ptr2IdxUTF8(utg8_l6+strlen(utg8_l6),utg8_l6+2),"d"); */
- /* logVar(ptr2IdxUTF8(utg8_l6+strlen(utg8_l6),utg8_l6+3),"d"); */
- /* logVar(ptr2IdxUTF8(utg8_l6+strlen(utg8_l6),utg8_l6+9),"d"); */
- /* logVar(ptr2IdxUTF8(utg8_l6+strlen(utg8_l6),utg8_l6+10),"d"); */
- /* logVar(ptr2IdxUTF8(utg8_l6+strlen(utg8_l6),utg8_l6+11),"d"); */
- /* logVar(ptr2IdxUTF8(utg8_l6+strlen(utg8_l6),utg8_l6+12),"d"); */
- /* logVar(bPtr2IdxUTF8(utg8_l6, utg8_l6+strlen(utg8_l6),utg8_l6-1),"d"); */
- /* logVar(bPtr2IdxUTF8(utg8_l6, utg8_l6+strlen(utg8_l6),utg8_l6),"d"); */
- /* logVar(bPtr2IdxUTF8(utg8_l6, utg8_l6+strlen(utg8_l6),utg8_l6+1),"d"); */
- /* logVar(bPtr2IdxUTF8(utg8_l6, utg8_l6+strlen(utg8_l6),utg8_l6+2),"d"); */
- /* logVar(bPtr2IdxUTF8(utg8_l6, utg8_l6+strlen(utg8_l6),utg8_l6+3),"d"); */
- /* logVar(bPtr2IdxUTF8(utg8_l6, utg8_l6+strlen(utg8_l6),utg8_l6+9),"d"); */
- /* logVar(bPtr2IdxUTF8(utg8_l6, utg8_l6+strlen(utg8_l6),utg8_l6+10),"d"); */
- /* logVar(bPtr2IdxUTF8(utg8_l6, utg8_l6+strlen(utg8_l6),utg8_l6+11),"d"); */
- /* logVar(bPtr2IdxUTF8(utg8_l6, utg8_l6+strlen(utg8_l6),utg8_l6+12),"d"); */
- /* logVar(bLPtr2NegIdxUTF8(utg8_l6, 1+strlen(utg8_l6),utg8_l6-1),"d"); */
- /* logVar(bLPtr2NegIdxUTF8(utg8_l6, 1+strlen(utg8_l6),utg8_l6),"d"); */
- /* logVar(bLPtr2NegIdxUTF8(utg8_l6, 1+strlen(utg8_l6),utg8_l6+1),"d"); */
- /* logVar(bLPtr2NegIdxUTF8(utg8_l6, 1+strlen(utg8_l6),utg8_l6+2),"d"); */
- /* logVar(bLPtr2NegIdxUTF8(utg8_l6, 1+strlen(utg8_l6),utg8_l6+3),"d"); */
- /* logVar(bLPtr2NegIdxUTF8(utg8_l6, 1+strlen(utg8_l6),utg8_l6+9),"d"); */
- /* logVar(bLPtr2NegIdxUTF8(utg8_l6, 1+strlen(utg8_l6),utg8_l6+10),"d"); */
- /* logVar(bLPtr2NegIdxUTF8(utg8_l6, 1+strlen(utg8_l6),utg8_l6+11),"d"); */
- /* logVar(bLPtr2NegIdxUTF8(utg8_l6, 1+strlen(utg8_l6),utg8_l6+12),"d"); */
- /* logVar(bLPtr2NegIdxUTF8(utg8_l6bad+1, 1+strlen(utg8_l6),utg8_l6bad-1),"d"); */
- /* logVar(bLPtr2NegIdxUTF8(utg8_l6bad+1, 1+strlen(utg8_l6),utg8_l6bad),"d"); */
- /* logVar(bLPtr2NegIdxUTF8(utg8_l6bad+1, 1+strlen(utg8_l6),utg8_l6bad+1),"d"); */
- /* logVar(bLPtr2NegIdxUTF8(utg8_l6bad+1, 1+strlen(utg8_l6),utg8_l6bad+2),"d"); */
- /* logVar(bLPtr2NegIdxUTF8(utg8_l6bad+1, 1+strlen(utg8_l6),utg8_l6bad+3),"d"); */
- /* logVar(bLPtr2NegIdxUTF8(utg8_l6bad+1, 1+strlen(utg8_l6),utg8_l6bad+9),"d"); */
- /* logVar(bLPtr2NegIdxUTF8(utg8_l6bad+1, 1+strlen(utg8_l6),utg8_l6bad+10),"d"); */
- /* logVar(bLPtr2NegIdxUTF8(utg8_l6bad+1, 1+strlen(utg8_l6),utg8_l6bad+11),"d"); */
- /* logVar(bLPtr2NegIdxUTF8(utg8_l6bad+1, 1+strlen(utg8_l6),utg8_l6bad+12),"d"); */
- /* logPtr(idx2PtrUTF8(utg8_l6, 0)); */
- /* logPtr(idx2PtrUTF8(utg8_l6, 1)); */
- /* logPtr(idx2PtrUTF8(utg8_l6, 2)); */
- /* logPtr(idx2PtrUTF8(utg8_l6, 3)); */
- /* logPtr(idx2PtrUTF8(utg8_l6, 4)); */
- /* logPtr(idx2PtrUTF8(utg8_l6, 5)); */
- /* logPtr(idx2PtrUTF8(utg8_l6, 6)); */
- /* logPtr(idx2PtrUTF8(utg8_l6, 7)); */
- /* logPtr(idx2PtrUTF8(utg8_l6, -1)); */
- /* logPtr(idx2PtrUTF8(utg8_l6, -2)); */
- /* logPtr(idx2PtrUTF8(utg8_l6, -3)); */
- /* logPtr(idx2PtrUTF8(utg8_l6, -4)); */
- /* logPtr(idx2PtrUTF8(utg8_l6, -5)); */
- /* logPtr(idx2PtrUTF8(utg8_l6, -6)); */
- /* logPtr(idx2PtrUTF8(utg8_l6, -7)); */
- /* logPtr(idx2PtrUTF8(utg8_l6, -8)); */
- puts(utg8_l6);
- puts(utf8);
- logVar(bLLenUTF8(aq,sizeof(aq)), "zu");
- logVar(isUTF8(aq), "b");
- logVar(isCodeUTF8(&aq[1]), "b");
- logVar(isCodeUTF8(&aq[2]), "b");
- logVar(isCodeUTF8(&aq[3]), "b");
- logVar(isCodeUTF8(&aq[4]), "b");
-
- char *next = nextUTF8(utf8_l6);;
- puts(next);
- puts(nxtCodeUTF8(next));
-
-
- pLogMask(0x1, LOG_INFO, "mask");
- logMask = 0;;
- puts("__");
- pLogMask(0x1, LOG_INFO, "mask");
- puts("--");
-
- #define group1 0x03
- #define group11 0x01
- #define group12 0x02
- #define group2 0x04
- logMask = group11;;
- logMI(group1, "is shown when logMask has bit 0 or 1 set");
- logMI(group11, "is shown when logMask has bit 0 set");
- logMI(group12, "is shown when logMask has bit 1 set");
- logMI(group2, "is shown when logMask has bit 2 set");
-
- setMaxLogLevel(LOG_DISABLE);
- pLog(LOG_CRITICAL, "QWE");
- setMaxLogLevel(LOG_INFO);
-
- puts(getHomePath());
-
- printf("k = %" PRIu64 "\n", EXTRACT(k,1,1));
-
- staticArrayT(type, u32, 10);
- type $;
- staticArrayInit($);
-
- //staticArrayElemType($) $E;
-
- range(i, 5) {
- staticArrayPush($);
- staticArrayLast($) = i;;
- }
-
- //staticArrayForEach($, S UNUSED) S = 0;
- //staticArrayEnumerate($, isa, S UNUSED) S = 0;
-
- rangeInf(i) {
- puts("infinity");
- if (i == 5) {
- break;
- }
- }
-
- staticArrayWriteFilename($, "test.bin");
-
- staticArrayDequeue($);
-
- logVar($.head, "d");
- logVar($.last, "d");
-
- staticArrayReadFilename($, "test.bin");
-
- logVar($.head, "d");
- logVar($.last, "d");
-
- circularDown(i, 2, 4) {
- printf("%d\n", (int)i);
- }
-
- setLogMode(LOG_VERBOSE);
- logI("%k%KRGB color" RST, 0x99EEFF, 0x666666);
- bool bl = true;;
- logI("%b", bl);
-
- intSlabt b;
- slabInitCount(&b, 25);
- /*slabResize(&b, 500);
-
- slabReadFilename(&b, "slab.bin");
- printf("count %ld\n", slabCount(&b));
- printf("max count %ld\n", slabMaxCount(&b));
-
- range(i, (size_t)slabCount(&b)) {
- printf("%d\n", slabAt(&b, i));
- }
- XSUCCESS
-
- range(i, 70) {
- slabAppend(&b, i);
- }
- printf("count %ld\n", slabCount(&b));
- FILE *ff;
- ff = fopen("slab.bin", "w");
- slabWrite(&b, ff);
- fclose(ff);
- XSUCCESS*/
-
- slabAppend(&b, 1);
- slabAppend(&b, 2);
-
- //slabForEach(&b, S UNUSED) S = 0;
- //slabEnumerate(&b, isl, S UNUSED) S = 0;
-
- printf("size %d\n", slabSz);
-
- slabAt(&b, 1) = 3;
- int *ePtr = slabPtr(&b, 1);;
- printf("element 1: %"PRIi32"\n", *ePtr);
- printf("get %"PRIi32"\n", slabAt(&b, 0));
- printf("pop %"PRIi32"\n", slabPop(&b));
- printf("dQ %"PRIi32"\n", slabDequeue(&b));
- slabFirstIndex(&b) = slabMaxCount(&b);;
- slabLastIndexVar(&b) = slabMaxCount(&b);;
- slabPrepend(&b, 10);
- printf("get %"PRIi32"\n", slabAt(&b, 0));
- printf("get %"PRIi32"\n", slabAt(&b, slabLastIndex(&b)));
-
- printf("count %ld\n", slabCount(&b));
-
- slabFree(&b);
-
- //slabElemType(&b) slabE;
-
- XSUCCESS
-
- char **bt = btrace();;
- pError0(listPrintS(bt));
- listFreeS(bt);
-
- logPtr(bt);
-
- bttt();
- freeRealProgPath();
- XSUCCESS
-
- stopwatchStart;
- stopwatchLog;
- stopwatchStart;
- stopwatchLogUs;
-
- timeNs();
-
- timeUs(loghex(a, 10));
-
- intDynt bbb UNUSED;
- //dArrayForEach(&bbb, S UNUSED) S = 0;
- //dArrayEnumerate(&bbb, ida, S UNUSED) S = 0;
- //dArrayElemType(&bbb) bbbE;
- /*
- intDynt b;
- dArrayInitCount(&b, 25);
- dArrayResize(&b, 500);
-
- dArrayReadFilename(&b, "darray.bin");
- printf("count %ld\n", dArrayCount(&b));
-
- range(i, (size_t)dArrayCount(&b)) {
- printf("%d\n", dArrayAt(&b, i));
- }
- XSUCCESS
-
- range(i, 70) {
- dArrayAppend(&b, i);
- }
- printf("count %ld\n", dArrayCount(&b));
- FILE *ff;
- ff = fopen("darray.bin", "w");
- dArrayWrite(&b, ff);
- fclose(ff);
- XSUCCESS
-
- dArrayAppend(&b, 1);
- dArrayAppend(&b, 2);
-
- printf("size %d\n", dArraySz);
-
- dArrayAt(&b, 1) = 3
- int *ePtr = dArrayPtr(&b, 1);
- printf("element 1: %"PRIi32"\n", *ePtr);
- printf("get %"PRIi32"\n", dArrayAt(&b, 0));
- printf("pop %"PRIi32"\n", dArrayPop(&b));
- printf("dQ %"PRIi32"\n", dArrayDequeue(&b));
- dArrayFirstIndex(&b) = dArrayMaxCount(&b);
- dArrayLastIndexVar(&b) = dArrayMaxCount(&b);
- dArrayPrepend(&b, 10);
- printf("get %"PRIi32"\n", dArrayAt(&b, 0));
- printf("get %"PRIi32"\n", dArrayAt(&b, dArrayLastIndex(&b)));
-
- printf("count %ld\n", dArrayCount(&b));
-
- dArrayFree(&b);*/
-
- /* indexerT(iT, i8); */
- /* iT ii; */
- /* logVar(sizeof ii,"lu"); */
- /* logVar(sizeof(staticArrayBase),"lu"); */
+ /* logSystem("git log -n 2 --pretty=\"%ai\""); */
/* */
- /* indexerInit(ii, 90); */
+ /* sliceT(slStruct, structuret); */
+ /* slStruct slc; */
+ /* sliceInit(&slc); */
+ /* slicePush(&slc); */
+ /* slicePush(&slc); */
+ /* sliceEnumerate(&slc, i, elm) { */
+ /* elm->a = 0; */
+ /* elm->b = 0; */
+ /* printf("sliceEnumerate %zd\n", i); */
+ /* } */
+ /* sliceFree(&slc); */
/* */
- /* int A[] = {1,5,7,9,10,65}; */
- /* A[0] = ARRAY_SIZE(A); */
- /* ssize_t bsr; */
+ /* // list */
/* */
- /* #define less(i, se) A[i] < se */
- /* #define equal(i, se) A[i] == se */
+ /* #<{(| i8 a = 0 |)}># */
+ /* #<{(| i16 s = 0 |)}># */
+ /* #<{(| i32 d = 0 |)}># */
+ /* #<{(| i64 f = 0 |)}># */
+ /* #<{(| u8 g = 0 |)}># */
+ /* #<{(| u16 h = 0 |)}># */
+ /* #<{(| u32 j = 0 |)}># */
+ /* u64 k = 7 */
+ /* #<{(| f32 x = 0 |)}># */
+ /* #<{(| f64 p = 0 |)}># */
/* */
- /* BSEARCH(bsr, 65, COUNT_ELEMENTS(A), less, equal); */
- /* logVar(bsr,"zd"); */
- /* if bsr != -1 */
- /* logVar(A[bsr],"d"); */
-
- XSUCCESS
-
- //listPrintS(systemf("ls %s", "-ltrh"));
-
- puts(bLGetCurrentDateYMD(a, 50));
-
- FILE *f = fopen("textOutTest.null", "r");
- logVar(fileSizeFP(f), "ld");
- fclose(f);
-
- logVar(fileSizeFP(NULL), "ld");
-
- // bug in cg_c
- /* getCurrentUnixTime(); */
- /* time_t tim = strToUnixTime("2018", "%Y"); */
- /* logVar(tim, "ld"); */
- /* tim = strToUnixTime("asd", "%Y"); */
- /* logVar(tim, "ld"); */
-
- staticArrayInit(fibers.L);
- staticArrayPush(fibers.L);
- //logVar(staticArrayCount(fibers.L), "d");
- staticArrayLast(fibers.L) = 10;;
- staticArrayPush(fibers.L);
- staticArrayLast(fibers.L) = 11;;
- staticArrayPush(fibers.L);
- staticArrayLast(fibers.L) = 12;;
- staticArrayPush(fibers.L);
- staticArrayLast(fibers.L) = 13;;
- int r = staticArrayGet(fibers.L, -1);;
- logVar(r, "d");
- r = staticArrayGet(fibers.L, 3);;
- logVar(r, "d");
- r = indexerRef(fibers.L, -1);;
- logVar(r, "d");
- r = indexerRef(fibers.L, 3);;
- logVar(r, "d");
- r = staticArrayGet(fibers.L, -2);;
- logVar(r, "d");
- r = staticArrayGet(fibers.L, 2);;
- logVar(r, "d");
- r = indexerRef(fibers.L, -2);;
- logVar(r, "d");
- r = indexerRef(fibers.L, 2);;
- logVar(r, "d");
- r = staticArrayGet(fibers.L, -3);;
- logVar(r, "d");
- r = staticArrayGet(fibers.L, 1);;
- logVar(r, "d");
- r = indexerRef(fibers.L, -3);;
- logVar(r, "d");
- r = indexerRef(fibers.L, 1);;
- logVar(r, "d");
- r = staticArrayGet(fibers.L, -4);;
- logVar(r, "d");
- r = staticArrayGet(fibers.L, 0);;
- logVar(r, "d");
- r = indexerRef(fibers.L, -4);;
- logVar(r, "d");
- r = indexerRef(fibers.L, 0);;
- logVar(r, "d");
- staticArrayDequeue(fibers.L);
- put
- r = staticArrayRef(fibers.L, -1);;
- logVar(r, "d");
- r = staticArrayRef(fibers.L, 2);;
- logVar(r, "d");
- r = indexerRef(fibers.L, -1);;
- logVar(r, "d");
- r = indexerRef(fibers.L, 2);;
- logVar(r, "d");
- r = staticArrayRef(fibers.L, -2);;
- logVar(r, "d");
- r = staticArrayRef(fibers.L, 1);;
- logVar(r, "d");
- r = indexerRef(fibers.L, -2);;
- logVar(r, "d");
- r = indexerRef(fibers.L, 1);;
- logVar(r, "d");
- r = staticArrayRef(fibers.L, -3);;
- logVar(r, "d");
- r = staticArrayRef(fibers.L, 0);;
- logVar(r, "d");
- r = indexerRef(fibers.L, -3);;
- logVar(r, "d");
- r = indexerRef(fibers.L, 0);;
- logVar(r, "d");
-
- char **aList = listCreateS("11", "22", "33");
- char **p = listAddrS(aList, -3);;
- puts(*p);
- p = listAddrS(aList, -1);;
- puts(*p);
- p = listAddrS(aList, 0);;
- puts(*p);
- p = listAddrS(aList, 2);;
- puts(*p);
-
- XSUCCESS
-
- indexer id;
- indexerInit(id, 10);
- indexerPush(id);
- logVar(id.last, PRIi64);
- a[indexerLast(id)] = 'a';;
- indexerPush(id);
- logVar(id.last, PRIi64);
- a[id.last] = 'b';;
- indexerPush(id);
- a[id.last] = 0;;
- logVar(id.last, PRIi64);
- indexerPop(id);
- logVar(id.last, PRIi64);
-
- //passwordEnter:;
- char *c;
-
- printf("P: ");
- c = readPasswordS();
- puts(c);
- printf("O: ");
- char *d = readPasswordS();
- puts(d);
- puts(c);
- XSUCCESS
-
- pError0(listPrintS(walkDirDir("dirTest.null")));
-
- circular(i, 2, 4) {
- printf("%d\n", (int)i);
- }
-
- char **l2 = listCreateS("lib");
- listEmptyS(l);
- char **R = listInsertS(l, -1, l2);;
- puts(R[0]);
-
- pErrorNULL(injectS("s", -2, 'D'));
-
- c = strdup(" SHeePY");
- pErrorNULL(iLTrimS(&c));
- printf(">%s<\n",c);
- free(c);
-
- pError0(copy("dirTest.null", ".."));
-
- puts(getProgPath());
- initLibsheepy("test");
- puts(getProgPath());
-
- puts( EVA(c, normalizePath("/wef/./../")) );
- free(c);
- puts(__func__);
- AT;
-
- pErrorNULL(iCatS(a, "qwee ", "wefwef", "--1`21`2123"));
- puts(a);
-
- XSUCCESS
-
- rangeDown(i, 10)
- printf("%ld\n", i);
-
- XSUCCESS
-
- initLibsheepy(argv[0]);
- puts(getProgPath());
-
- //mkdirParents("rmAllTest.null/null");
- k = rmAll("link");;
- logVar(k, PRIi64);
-
- forEachS(l, L) {
- free(L);
- }
- forEachS(l, L) {
- free(L);
- }
-
- XSUCCESS
-
- puts("readDir");
- put
- pError0(listPrintS(readDir(".")));
- puts("readDirDir");
- put
- pError0(listPrintS(readDirDir(".")));
- puts("readDirAll");
- put
- pError0(listPrintS(readDirAll(".")));
-
- pError0(isNumber("-12.3"));
- XSUCCESS
-
- /* int r = 0 */
- /* tryV(r, 0) { */
- /* throwV(0, 10); */
- /* puts("does not print"); */
+ /* */
+ /* char *toBCroped = strdup("123456") */
+ /* char *crp = iCropS(&toBCroped, -1, 1) */
+ /* logVar(toBCroped, "s"); */
+ /* logVar(crp, "s"); */
+ /* */
+ /* char **lst = listCreateS("1","2","3","4","5") */
+ /* char **lcrop = listCropS(lst, 1,3) */
+ /* pError0(listPrintS(lst)); */
+ /* AT */
+ /* pError0(listPrintS(lcrop)); */
+ /* */
+ /* setLogStdout(no); */
+ /* */
+ /* logExit(EXIT_SUCCESS, "qweqwe"); */
+ /* logXSuccess("qweqwe"); */
+ /* logXFailure("qweqwe"); */
+ /* */
+ /* logSystemf("ls /home/%s/.ssh/", "remy"); */
+ /* */
+ /* char *rel = relPath("/wer/w/e", "../wer/ef"); */
+ /* printf("rel path %s\n", rel); */
+ /* free rel */
+ /* */
+ /* //printf(">%s< %zu\n",nS(padEndS("123", 10, "-=|=123123")), lenS(padEndS("123", 10, "-=|=123123"))); */
+ /* char *e = ellipsisStartS("123", 10, "..."); */
+ /* printf("ellipsis start %s\n", e); */
+ /* free e */
+ /* e =ellipsisStartS("1234567890", 10, "...") */
+ /* printf("ellipsis start %s\n", e); */
+ /* free e */
+ /* e =ellipsisStartS("1234567890abcdef", 10, "...") */
+ /* printf("ellipsis start %s\n", e); */
+ /* free e */
+ /* e =ellipsisStartS("1234567890abcdef", 10, "...xxxxxxxxxxxxxxxxxxxxxxxxx") */
+ /* printf("ellipsis start %s\n", e); */
+ /* free e */
+ /* e =ellipsisEndS("123", 10, "...") */
+ /* printf("ellipsis end %s\n", e); */
+ /* free e */
+ /* e =ellipsisEndS("1234567890", 10, "...") */
+ /* printf("ellipsis end %s\n", e); */
+ /* free e */
+ /* e =ellipsisEndS("1234567890abcdef", 10, "...") */
+ /* printf("ellipsis end %s\n", e); */
+ /* free e */
+ /* e =ellipsisEndS("1234567890abcdef", 10, "...****************************") */
+ /* printf("ellipsis end %s\n", e); */
+ /* free e */
+ /* */
+ /* XSUCCESS */
+ /* */
+ /* char a[8192] = "" */
+ /* */
+ /* initLibsheepy("exe"); */
+ /* setLogSymbols(LOG_UTF8); */
+ /* */
+ /* logVar(absV(-2), "d"); */
+ /* logVar(CMP(2,2), "d"); */
+ /* */
+ /* char **li = NULL */
+ /* //char **li2; */
+ /* */
+ /* // list negative index */
+ /* pErrorNULL(listPushS(&li, "1")); */
+ /* pErrorNULL(listPushS(&li, "22")); */
+ /* pErrorNULL(listPushS(&li, "333")); */
+ /* pErrorNULL(listPushS(&li, "4444")); */
+ /* //li2 = iListCropS(&li, 1,-1) */
+ /* char *stri = iListCropElemS(&li, 1) */
+ /* */
+ /* pError0(listPrintS(li)); */
+ /* put */
+ /* puts(stri); */
+ /* //listPrintS(li2); */
+ /* */
+ /* XSUCCESS */
+ /* */
+ /* sliceT(slicet, char*); */
+ /* slicet slce; */
+ /* sliceInit(&slce); */
+ /* //sliceElemType(&slce) slEl; */
+ /* */
+ /* staticSliceT(sslicet, char*, 2); */
+ /* sslicet sslce; */
+ /* staticSliceInit(&sslce); */
+ /* staticSlicePush(&sslce); */
+ /* //staticSliceForEach(&sslce, S UNUSED) S = NULL; */
+ /* //staticSliceEnumerate(&sslce, iS, S UNUSED) S = NULL; */
+ /* */
+ /* //staticSliceElemType(&sslce) sslEl; */
+ /* */
+ /* puts(getCurrentDate()); */
+ /* */
+ /* vectorT(vect, char *); */
+ /* */
+ /* vect vec; */
+ /* */
+ /* //vectorElemType(&vec) vecE; */
+ /* */
+ /* vectorInitCount(&vec, 17); */
+ /* */
+ /* */
+ /* logVar(vectorMaxCount(&vec), "zu"); */
+ /* logVar(vectorCount(&vec), "zu"); */
+ /* */
+ /* vectorAppend(&vec, "qwe"); */
+ /* vectorAppend(&vec, "2345"); */
+ /* */
+ /* //vectorForEach(&vec, S UNUSED) S = NULL; */
+ /* //vectorEnumerate(&vec, iv, S) S = NULL; */
+ /* */
+ /* logVar(vectorMaxCount(&vec), "zu"); */
+ /* logVar(vectorCount(&vec), "zu"); */
+ /* */
+ /* char *vc = vectorAt(&vec, 1) */
+ /* logI(vc); */
+ /* */
+ /* forEachV(&vec, i) { */
+ /* logI(vectorAt(&vec, i)); */
/* } */
- /* else */
- /* printf("except value %d\n", r); */
-
- printf("%" PRIu64 "\n", getMonotonicTime());
-
- /* AArgs Aa; */
- /* Aa.a = 0 */
- /* A(&Aa); */
- //AB();
-
- AArgs Aa;
- BArgs Ba;
-
- initLibsheepy(argv[0]);
+ /* */
+ /* vectorDelElem(&vec, 0); */
+ /* */
+ /* vc = vectorDequeue(&vec) */
+ /* logI(vc); */
+ /* */
+ /* */
+ /* logVar(vectorMaxCount(&vec), "zu"); */
+ /* logVar(vectorCount(&vec), "zu"); */
+ /* */
+ /* vectorInject(&vec, 0); */
+ /* */
+ /* logVar(vectorMaxCount(&vec), "zu"); */
+ /* logVar(vectorCount(&vec), "zu"); */
+ /* */
+ /* vectorAt(&vec, 0) = "#$345" */
+ /* */
+ /* forEachV(&vec, i) { */
+ /* logI(vectorAt(&vec, i)); */
+ /* } */
+ /* */
+ /* var v = vectorCopy(&vec, 0, 1); */
+ /* */
+ /* logI("copy"); */
+ /* */
+ /* forEachV(v, i) { */
+ /* logI(vectorAt(v, i)); */
+ /* } */
+ /* */
+ /* vectorTerminate(v); */
+ /* */
+ /* vectorFree(&vec); */
+ /* */
+ /* dVectorT(dvect, void*); */
+ /* dvect dvec; */
+ /* dVectorInit(&dvec); */
+ /* //dVectorElemType(&dvec) dvecE; */
+ /* */
+ /* //dVectorForEach(&dvec, S UNUSED) S = NULL; */
+ /* //dVectorEnumerate(&dvec, idv, S UNUSED) S = NULL; */
+ /* XSUCCESS */
+ /* */
+ /* */
+ /* char *h; */
+ /* puts(h = toHexS("123", 4)); */
+ /* free h */
+ /* puts(h = toHexSepS("123", 4, ",")); */
+ /* free h */
+ /* puts(h = toHexHeadSepS("123", 3, "\\x", "")); */
+ /* free h */
+ /* logSI("Buf: [%s]", toHexSepS("123", 4, ",")); */
+ /* logSMI(1,"Mask Buf: [%s]", toHexSepS("123", 4, ",")); */
+ /* */
+ /* const char *AA[] = {"WER", "asd", NULL} */
+ /* char **CA = listCreateS("zxc", "cvb"); */
+ /* */
+ /* pError0(listPrintS((char**)AA)); */
+ /* pError0(listPrintS(CA)); */
+ /* */
+ /* char *utf8 = "Футбол России и мира, новости футбола, видео голов..."; */
+ /* char *utf8_l6 = "Футбол"; */
+ /* char *utg8_l6 = "/åäöéà"; */
+ /* // extra bytes for bLPtr2IdxUTF8 */
+ /* //char *utg8_l6bad = "/åäöéàX"; */
+ /* char aq[20] = {0x66, 0x7e, 0xc6,0xc1, 0}; */
+ /* */
+ /* puts("---------------"); */
+ /* puts(shDirname("./wer")); */
+ /* puts(shDirname("wer")); */
+ /* puts(shDirname("DFGDFG/wer")); */
+ /* puts("---------------"); */
+ /* */
+ /* logVar(strlen(utf8_l6), "zu"); */
+ /* logVar(lenUTF8(utf8_l6), "zu"); */
+ /* logVar(isUTF8(utf8_l6), "b"); */
+ /* puts(utf8_l6); */
+ /* logVar(strlen(utg8_l6), "zu"); */
+ /* logVar(lenUTF8(utg8_l6), "zu"); */
+ /* logVar(bLLenUTF8(utg8_l6,3), "zu"); */
+ /* logVar(isUTF8(utg8_l6), "b"); */
+ /* // idx2PtrUTF8 test */
+ /* logPtr(utg8_l6); */
+ /* logPtr(utg8_l6+strlen(utg8_l6)); */
+ /* logVar(makeValidUTF8(utg8_l6), "s"); */
+ /* logVar(makeValidUTF8(aq), "s"); */
+ /* pErrorNULL(strNCpyUTF8(aq, utg8_l6, 5)); */
+ /* logVar(aq, "s"); */
+ /* #<{(| logVar(ptr2IdxUTF8(utg8_l6, utg8_l6+strlen(utg8_l6)+1),"d"); |)}># */
+ /* #<{(| logVar(ptr2IdxUTF8(utg8_l6, utg8_l6),"d"); |)}># */
+ /* #<{(| logVar(ptr2IdxUTF8(utg8_l6, utg8_l6+1),"d"); |)}># */
+ /* #<{(| logVar(ptr2IdxUTF8(utg8_l6, utg8_l6+2),"d"); |)}># */
+ /* #<{(| logVar(ptr2IdxUTF8(utg8_l6, utg8_l6+3),"d"); |)}># */
+ /* #<{(| logVar(ptr2IdxUTF8(utg8_l6, utg8_l6+10),"d"); |)}># */
+ /* #<{(| logVar(ptr2IdxUTF8(utg8_l6, utg8_l6+11),"d"); |)}># */
+ /* #<{(| logVar(ptr2IdxUTF8(utg8_l6, utg8_l6+12),"d"); |)}># */
+ /* #<{(| logVar(bPtr2IdxUTF8(utg8_l6, utg8_l6, utg8_l6+strlen(utg8_l6)+1),"d"); |)}># */
+ /* #<{(| logVar(bPtr2IdxUTF8(utg8_l6, utg8_l6, utg8_l6),"d"); |)}># */
+ /* #<{(| logVar(bPtr2IdxUTF8(utg8_l6, utg8_l6, utg8_l6+1),"d"); |)}># */
+ /* #<{(| logVar(bPtr2IdxUTF8(utg8_l6, utg8_l6, utg8_l6+2),"d"); |)}># */
+ /* #<{(| logVar(bPtr2IdxUTF8(utg8_l6, utg8_l6, utg8_l6+3),"d"); |)}># */
+ /* #<{(| logVar(bPtr2IdxUTF8(utg8_l6, utg8_l6, utg8_l6+10),"d"); |)}># */
+ /* #<{(| logVar(bPtr2IdxUTF8(utg8_l6, utg8_l6, utg8_l6+11),"d"); |)}># */
+ /* #<{(| logVar(bPtr2IdxUTF8(utg8_l6, utg8_l6, utg8_l6+12),"d"); |)}># */
+ /* #<{(| logVar(bLPtr2IdxUTF8(utg8_l6, strlen(utg8_l6)+1, utg8_l6+strlen(utg8_l6)+1),"d"); |)}># */
+ /* #<{(| logVar(bLPtr2IdxUTF8(utg8_l6, strlen(utg8_l6)+1, utg8_l6),"d"); |)}># */
+ /* #<{(| logVar(bLPtr2IdxUTF8(utg8_l6, strlen(utg8_l6)+1, utg8_l6+1),"d"); |)}># */
+ /* #<{(| logVar(bLPtr2IdxUTF8(utg8_l6, strlen(utg8_l6)+1, utg8_l6+2),"d"); |)}># */
+ /* #<{(| logVar(bLPtr2IdxUTF8(utg8_l6, strlen(utg8_l6)+1, utg8_l6+3),"d"); |)}># */
+ /* #<{(| logVar(bLPtr2IdxUTF8(utg8_l6, strlen(utg8_l6)+1, utg8_l6+10),"d"); |)}># */
+ /* #<{(| logVar(bLPtr2IdxUTF8(utg8_l6, strlen(utg8_l6)+1, utg8_l6+11),"d"); |)}># */
+ /* #<{(| logVar(bLPtr2IdxUTF8(utg8_l6, strlen(utg8_l6)+1, utg8_l6+12),"d"); |)}># */
+ /* #<{(| logVar(bLPtr2IdxUTF8(utg8_l6bad, strlen(utg8_l6)+1, utg8_l6bad+strlen(utg8_l6)+1),"d"); |)}># */
+ /* #<{(| logVar(bLPtr2IdxUTF8(utg8_l6bad, strlen(utg8_l6)+1, utg8_l6bad),"d"); |)}># */
+ /* #<{(| logVar(bLPtr2IdxUTF8(utg8_l6bad, strlen(utg8_l6)+1, utg8_l6bad+1),"d"); |)}># */
+ /* #<{(| logVar(bLPtr2IdxUTF8(utg8_l6bad, strlen(utg8_l6)+1, utg8_l6bad+2),"d"); |)}># */
+ /* #<{(| logVar(bLPtr2IdxUTF8(utg8_l6bad, strlen(utg8_l6)+1, utg8_l6bad+3),"d"); |)}># */
+ /* #<{(| logVar(bLPtr2IdxUTF8(utg8_l6bad, strlen(utg8_l6)+1, utg8_l6bad+10),"d"); |)}># */
+ /* #<{(| logVar(bLPtr2IdxUTF8(utg8_l6bad, strlen(utg8_l6)+1, utg8_l6bad+11),"d"); |)}># */
+ /* #<{(| logVar(bLPtr2IdxUTF8(utg8_l6bad, strlen(utg8_l6)+1, utg8_l6bad+12),"d"); |)}># */
+ /* // negative index */
+ /* #<{(| loghex(utg8_l6, strlen(utg8_l6)+1);put |)}># */
+ /* #<{(| logVar(ptr2IdxUTF8(utg8_l6+strlen(utg8_l6),utg8_l6),"d"); |)}># */
+ /* #<{(| logVar(ptr2IdxUTF8(utg8_l6+strlen(utg8_l6),utg8_l6+1),"d"); |)}># */
+ /* #<{(| logVar(ptr2IdxUTF8(utg8_l6+strlen(utg8_l6),utg8_l6+2),"d"); |)}># */
+ /* #<{(| logVar(ptr2IdxUTF8(utg8_l6+strlen(utg8_l6),utg8_l6+3),"d"); |)}># */
+ /* #<{(| logVar(ptr2IdxUTF8(utg8_l6+strlen(utg8_l6),utg8_l6+9),"d"); |)}># */
+ /* #<{(| logVar(ptr2IdxUTF8(utg8_l6+strlen(utg8_l6),utg8_l6+10),"d"); |)}># */
+ /* #<{(| logVar(ptr2IdxUTF8(utg8_l6+strlen(utg8_l6),utg8_l6+11),"d"); |)}># */
+ /* #<{(| logVar(ptr2IdxUTF8(utg8_l6+strlen(utg8_l6),utg8_l6+12),"d"); |)}># */
+ /* #<{(| logVar(bPtr2IdxUTF8(utg8_l6, utg8_l6+strlen(utg8_l6),utg8_l6-1),"d"); |)}># */
+ /* #<{(| logVar(bPtr2IdxUTF8(utg8_l6, utg8_l6+strlen(utg8_l6),utg8_l6),"d"); |)}># */
+ /* #<{(| logVar(bPtr2IdxUTF8(utg8_l6, utg8_l6+strlen(utg8_l6),utg8_l6+1),"d"); |)}># */
+ /* #<{(| logVar(bPtr2IdxUTF8(utg8_l6, utg8_l6+strlen(utg8_l6),utg8_l6+2),"d"); |)}># */
+ /* #<{(| logVar(bPtr2IdxUTF8(utg8_l6, utg8_l6+strlen(utg8_l6),utg8_l6+3),"d"); |)}># */
+ /* #<{(| logVar(bPtr2IdxUTF8(utg8_l6, utg8_l6+strlen(utg8_l6),utg8_l6+9),"d"); |)}># */
+ /* #<{(| logVar(bPtr2IdxUTF8(utg8_l6, utg8_l6+strlen(utg8_l6),utg8_l6+10),"d"); |)}># */
+ /* #<{(| logVar(bPtr2IdxUTF8(utg8_l6, utg8_l6+strlen(utg8_l6),utg8_l6+11),"d"); |)}># */
+ /* #<{(| logVar(bPtr2IdxUTF8(utg8_l6, utg8_l6+strlen(utg8_l6),utg8_l6+12),"d"); |)}># */
+ /* #<{(| logVar(bLPtr2NegIdxUTF8(utg8_l6, 1+strlen(utg8_l6),utg8_l6-1),"d"); |)}># */
+ /* #<{(| logVar(bLPtr2NegIdxUTF8(utg8_l6, 1+strlen(utg8_l6),utg8_l6),"d"); |)}># */
+ /* #<{(| logVar(bLPtr2NegIdxUTF8(utg8_l6, 1+strlen(utg8_l6),utg8_l6+1),"d"); |)}># */
+ /* #<{(| logVar(bLPtr2NegIdxUTF8(utg8_l6, 1+strlen(utg8_l6),utg8_l6+2),"d"); |)}># */
+ /* #<{(| logVar(bLPtr2NegIdxUTF8(utg8_l6, 1+strlen(utg8_l6),utg8_l6+3),"d"); |)}># */
+ /* #<{(| logVar(bLPtr2NegIdxUTF8(utg8_l6, 1+strlen(utg8_l6),utg8_l6+9),"d"); |)}># */
+ /* #<{(| logVar(bLPtr2NegIdxUTF8(utg8_l6, 1+strlen(utg8_l6),utg8_l6+10),"d"); |)}># */
+ /* #<{(| logVar(bLPtr2NegIdxUTF8(utg8_l6, 1+strlen(utg8_l6),utg8_l6+11),"d"); |)}># */
+ /* #<{(| logVar(bLPtr2NegIdxUTF8(utg8_l6, 1+strlen(utg8_l6),utg8_l6+12),"d"); |)}># */
+ /* #<{(| logVar(bLPtr2NegIdxUTF8(utg8_l6bad+1, 1+strlen(utg8_l6),utg8_l6bad-1),"d"); |)}># */
+ /* #<{(| logVar(bLPtr2NegIdxUTF8(utg8_l6bad+1, 1+strlen(utg8_l6),utg8_l6bad),"d"); |)}># */
+ /* #<{(| logVar(bLPtr2NegIdxUTF8(utg8_l6bad+1, 1+strlen(utg8_l6),utg8_l6bad+1),"d"); |)}># */
+ /* #<{(| logVar(bLPtr2NegIdxUTF8(utg8_l6bad+1, 1+strlen(utg8_l6),utg8_l6bad+2),"d"); |)}># */
+ /* #<{(| logVar(bLPtr2NegIdxUTF8(utg8_l6bad+1, 1+strlen(utg8_l6),utg8_l6bad+3),"d"); |)}># */
+ /* #<{(| logVar(bLPtr2NegIdxUTF8(utg8_l6bad+1, 1+strlen(utg8_l6),utg8_l6bad+9),"d"); |)}># */
+ /* #<{(| logVar(bLPtr2NegIdxUTF8(utg8_l6bad+1, 1+strlen(utg8_l6),utg8_l6bad+10),"d"); |)}># */
+ /* #<{(| logVar(bLPtr2NegIdxUTF8(utg8_l6bad+1, 1+strlen(utg8_l6),utg8_l6bad+11),"d"); |)}># */
+ /* #<{(| logVar(bLPtr2NegIdxUTF8(utg8_l6bad+1, 1+strlen(utg8_l6),utg8_l6bad+12),"d"); |)}># */
+ /* #<{(| logPtr(idx2PtrUTF8(utg8_l6, 0)); |)}># */
+ /* #<{(| logPtr(idx2PtrUTF8(utg8_l6, 1)); |)}># */
+ /* #<{(| logPtr(idx2PtrUTF8(utg8_l6, 2)); |)}># */
+ /* #<{(| logPtr(idx2PtrUTF8(utg8_l6, 3)); |)}># */
+ /* #<{(| logPtr(idx2PtrUTF8(utg8_l6, 4)); |)}># */
+ /* #<{(| logPtr(idx2PtrUTF8(utg8_l6, 5)); |)}># */
+ /* #<{(| logPtr(idx2PtrUTF8(utg8_l6, 6)); |)}># */
+ /* #<{(| logPtr(idx2PtrUTF8(utg8_l6, 7)); |)}># */
+ /* #<{(| logPtr(idx2PtrUTF8(utg8_l6, -1)); |)}># */
+ /* #<{(| logPtr(idx2PtrUTF8(utg8_l6, -2)); |)}># */
+ /* #<{(| logPtr(idx2PtrUTF8(utg8_l6, -3)); |)}># */
+ /* #<{(| logPtr(idx2PtrUTF8(utg8_l6, -4)); |)}># */
+ /* #<{(| logPtr(idx2PtrUTF8(utg8_l6, -5)); |)}># */
+ /* #<{(| logPtr(idx2PtrUTF8(utg8_l6, -6)); |)}># */
+ /* #<{(| logPtr(idx2PtrUTF8(utg8_l6, -7)); |)}># */
+ /* #<{(| logPtr(idx2PtrUTF8(utg8_l6, -8)); |)}># */
+ /* puts(utg8_l6); */
+ /* puts(utf8); */
+ /* logVar(bLLenUTF8(aq,sizeof(aq)), "zu"); */
+ /* logVar(isUTF8(aq), "b"); */
+ /* logVar(isCodeUTF8(&aq[1]), "b"); */
+ /* logVar(isCodeUTF8(&aq[2]), "b"); */
+ /* logVar(isCodeUTF8(&aq[3]), "b"); */
+ /* logVar(isCodeUTF8(&aq[4]), "b"); */
+ /* */
+ /* char *next = nextUTF8(utf8_l6); */
+ /* puts(next); */
+ /* puts(nxtCodeUTF8(next)); */
+ /* */
+ /* */
+ /* pLogMask(0x1, LOG_INFO, "mask"); */
+ /* logMask = 0; */
+ /* puts("__"); */
+ /* pLogMask(0x1, LOG_INFO, "mask"); */
+ /* puts("--"); */
+ /* */
+ /* #define group1 0x03 */
+ /* #define group11 0x01 */
+ /* #define group12 0x02 */
+ /* #define group2 0x04 */
+ /* logMask = group11; */
+ /* logMI(group1, "is shown when logMask has bit 0 or 1 set"); */
+ /* logMI(group11, "is shown when logMask has bit 0 set"); */
+ /* logMI(group12, "is shown when logMask has bit 1 set"); */
+ /* logMI(group2, "is shown when logMask has bit 2 set"); */
+ /* */
+ /* setMaxLogLevel(LOG_DISABLE); */
+ /* pLog(LOG_CRITICAL, "QWE"); */
+ /* setMaxLogLevel(LOG_INFO); */
+ /* */
+ /* puts(getHomePath()); */
+ /* */
+ /* printf("k = %" PRIu64 "\n", EXTRACT(k,1,1)); */
+ /* */
+ /* staticArrayT(type, u32, 10); */
+ /* type $; */
+ /* staticArrayInit($); */
+ /* */
+ /* //staticArrayElemType($) $E; */
+ /* */
+ /* range(i, 5) { */
+ /* staticArrayPush($); */
+ /* staticArrayLast($) = i; */
+ /* } */
+ /* */
+ /* //staticArrayForEach($, S UNUSED) S = 0; */
+ /* //staticArrayEnumerate($, isa, S UNUSED) S = 0; */
+ /* */
+ /* rangeInf(i) { */
+ /* puts("infinity"); */
+ /* if i = 5 */
+ /* break; */
+ /* } */
+ /* */
+ /* staticArrayWriteFilename($, "test.bin"); */
+ /* */
+ /* staticArrayDequeue($); */
+ /* */
+ /* logVar($.head, "d"); */
+ /* logVar($.last, "d"); */
+ /* */
+ /* staticArrayReadFilename($, "test.bin"); */
+ /* */
+ /* logVar($.head, "d"); */
+ /* logVar($.last, "d"); */
+ /* */
+ /* circularDown(i, 2, 4) { */
+ /* printf("%d\n", (int)i); */
+ /* } */
+ /* */
+ /* setLogMode(LOG_VERBOSE); */
+ /* logI("%k%KRGB color" RST, 0x99EEFF, 0x666666); */
+ /* bool bl = true; */
+ /* logI("%b", bl); */
+ /* */
+ /* intSlabt b; */
+ /* slabInitCount(&b, 25); */
+ /* #<{(|slabResize(&b, 500); */
+ /* */
+ /* slabReadFilename(&b, "slab.bin"); */
+ /* printf("count %ld\n", slabCount(&b)); */
+ /* printf("max count %ld\n", slabMaxCount(&b)); */
+ /* */
+ /* range(i, (size_t)slabCount(&b)) { */
+ /* printf("%d\n", slabAt(&b, i)); */
+ /* } */
+ /* XSUCCESS */
+ /* */
+ /* range(i, 70) { */
+ /* slabAppend(&b, i); */
+ /* } */
+ /* printf("count %ld\n", slabCount(&b)); */
+ /* FILE *ff; */
+ /* ff = fopen("slab.bin", "w"); */
+ /* slabWrite(&b, ff); */
+ /* fclose(ff); */
+ /* XSUCCESS|)}># */
+ /* */
+ /* slabAppend(&b, 1); */
+ /* slabAppend(&b, 2); */
+ /* */
+ /* //slabForEach(&b, S UNUSED) S = 0; */
+ /* //slabEnumerate(&b, isl, S UNUSED) S = 0; */
+ /* */
+ /* printf("size %d\n", slabSz); */
+ /* */
+ /* slabAt(&b, 1) = 3 */
+ /* int *ePtr = slabPtr(&b, 1); */
+ /* printf("element 1: %"PRIi32"\n", *ePtr); */
+ /* printf("get %"PRIi32"\n", slabAt(&b, 0)); */
+ /* printf("pop %"PRIi32"\n", slabPop(&b)); */
+ /* printf("dQ %"PRIi32"\n", slabDequeue(&b)); */
+ /* slabFirstIndex(&b) = slabMaxCount(&b); */
+ /* slabLastIndexVar(&b) = slabMaxCount(&b); */
+ /* slabPrepend(&b, 10); */
+ /* printf("get %"PRIi32"\n", slabAt(&b, 0)); */
+ /* printf("get %"PRIi32"\n", slabAt(&b, slabLastIndex(&b))); */
+ /* */
+ /* printf("count %ld\n", slabCount(&b)); */
+ /* */
+ /* slabFree(&b); */
+ /* */
+ /* //slabElemType(&b) slabE; */
+ /* */
+ /* XSUCCESS */
+ /* */
+ /* char **bt = btrace(); */
+ /* pError0(listPrintS(bt)); */
+ /* listFreeS(bt); */
+ /* */
+ /* logPtr(bt); */
+ /* */
+ /* bttt(); */
+ /* freeRealProgPath(); */
+ /* XSUCCESS */
+ /* */
+ /* stopwatchStart; */
+ /* stopwatchLog; */
+ /* stopwatchStart; */
+ /* stopwatchLogUs; */
+ /* */
+ /* timeNs(); */
+ /* */
+ /* timeUs(loghex(a, 10)); */
+ /* */
+ /* intDynt bbb UNUSED; */
+ /* //dArrayForEach(&bbb, S UNUSED) S = 0; */
+ /* //dArrayEnumerate(&bbb, ida, S UNUSED) S = 0; */
+ /* //dArrayElemType(&bbb) bbbE; */
+ /* #<{(| */
+ /* intDynt b; */
+ /* dArrayInitCount(&b, 25); */
+ /* dArrayResize(&b, 500); */
+ /* */
+ /* dArrayReadFilename(&b, "darray.bin"); */
+ /* printf("count %ld\n", dArrayCount(&b)); */
+ /* */
+ /* range(i, (size_t)dArrayCount(&b)) { */
+ /* printf("%d\n", dArrayAt(&b, i)); */
+ /* } */
+ /* XSUCCESS */
+ /* */
+ /* range(i, 70) { */
+ /* dArrayAppend(&b, i); */
+ /* } */
+ /* printf("count %ld\n", dArrayCount(&b)); */
+ /* FILE *ff; */
+ /* ff = fopen("darray.bin", "w"); */
+ /* dArrayWrite(&b, ff); */
+ /* fclose(ff); */
+ /* XSUCCESS */
+ /* */
+ /* dArrayAppend(&b, 1); */
+ /* dArrayAppend(&b, 2); */
+ /* */
+ /* printf("size %d\n", dArraySz); */
+ /* */
+ /* dArrayAt(&b, 1) = 3 */
+ /* int *ePtr = dArrayPtr(&b, 1); */
+ /* printf("element 1: %"PRIi32"\n", *ePtr); */
+ /* printf("get %"PRIi32"\n", dArrayAt(&b, 0)); */
+ /* printf("pop %"PRIi32"\n", dArrayPop(&b)); */
+ /* printf("dQ %"PRIi32"\n", dArrayDequeue(&b)); */
+ /* dArrayFirstIndex(&b) = dArrayMaxCount(&b); */
+ /* dArrayLastIndexVar(&b) = dArrayMaxCount(&b); */
+ /* dArrayPrepend(&b, 10); */
+ /* printf("get %"PRIi32"\n", dArrayAt(&b, 0)); */
+ /* printf("get %"PRIi32"\n", dArrayAt(&b, dArrayLastIndex(&b))); */
+ /* */
+ /* printf("count %ld\n", dArrayCount(&b)); */
+ /* */
+ /* dArrayFree(&b);|)}># */
+ /* */
+ /* #<{(| indexerT(iT, i8); |)}># */
+ /* #<{(| iT ii; |)}># */
+ /* #<{(| logVar(sizeof ii,"lu"); |)}># */
+ /* #<{(| logVar(sizeof(staticArrayBase),"lu"); |)}># */
+ /* #<{(| |)}># */
+ /* #<{(| indexerInit(ii, 90); |)}># */
+ /* #<{(| |)}># */
+ /* #<{(| int A[] = {1,5,7,9,10,65}; |)}># */
+ /* #<{(| A[0] = ARRAY_SIZE(A); |)}># */
+ /* #<{(| ssize_t bsr; |)}># */
+ /* #<{(| |)}># */
+ /* #<{(| #define less(i, se) A[i] < se |)}># */
+ /* #<{(| #define equal(i, se) A[i] == se |)}># */
+ /* #<{(| |)}># */
+ /* #<{(| BSEARCH(bsr, 65, COUNT_ELEMENTS(A), less, equal); |)}># */
+ /* #<{(| logVar(bsr,"zd"); |)}># */
+ /* #<{(| if bsr != -1 |)}># */
+ /* #<{(| logVar(A[bsr],"d"); |)}># */
+ /* */
+ /* XSUCCESS */
+ /* */
+ /* //listPrintS(systemf("ls %s", "-ltrh")); */
+ /* */
+ /* puts(bLGetCurrentDateYMD(a, 50)); */
+ /* */
+ /* FILE *f = fopen("textOutTest.null", "r") */
+ /* logVar(fileSizeFP(f), "ld"); */
+ /* fclose(f); */
+ /* */
+ /* logVar(fileSizeFP(NULL), "ld"); */
+ /* */
+ /* // bug in cg_c */
+ /* #<{(| getCurrentUnixTime(); |)}># */
+ /* #<{(| time_t tim = strToUnixTime("2018", "%Y"); |)}># */
+ /* #<{(| logVar(tim, "ld"); |)}># */
+ /* #<{(| tim = strToUnixTime("asd", "%Y"); |)}># */
+ /* #<{(| logVar(tim, "ld"); |)}># */
+ /* */
/* staticArrayInit(fibers.L); */
- /* staticArrayInit(fibers.startL); */
-
- puts(__func__);
- Aa.a = 0;
- fiberAdd(&Aa, 1, fiberA);
-
- puts(__func__);
- Ba.a = 1;
- Ba.b = 2;
- fiberAdd(&Ba, 2, fiberB);
-
- scheduler();
-
- /* if !setjmp(buf) */
- /* longjmp(buf,1); */
- /* else */
- /* puts("except"); */
-
- XSUCCESS
-
- pError0(copy("cov.info", "qwe"));
- pError0(copy("dirTest.null/", "mkdirTest.null/null/"));
- pError0(copy("dirTest.null", "mkdirTest.null/"));
-
- initLibsheepy(argv[0]);
-
- //NO - limited to 2GB files - sendfile(0, 0, 0, 10);
- setLogFile(NULL);
-
- //char *s = formatS("%s/%d\n", "qwd",645);
- char *s = NULL;
- s = formatS("%s/%d\n", "qwd",645);;
- //char *s = NULL;
- //pError(asprintf(&s, "%s/%s\n", "qwd","qw"));
- puts(s);
-
- pError0(listPrintS(walkDirAll(".")));
- printf("%o\n", 0777 & ~getUmask());
- pError0(mkdirParents("mkdirTest.null/null"));
-
- /* pErrorCmd(isDir("json"), == false, pLog(LOG_WARNING, "json is NOT dir")) */
- /* else */
- /* pLog(LOG_INFO, "json is dir"); */
+ /* staticArrayPush(fibers.L); */
+ /* //logVar(staticArrayCount(fibers.L), "d"); */
+ /* staticArrayLast(fibers.L) = 10; */
+ /* staticArrayPush(fibers.L); */
+ /* staticArrayLast(fibers.L) = 11; */
+ /* staticArrayPush(fibers.L); */
+ /* staticArrayLast(fibers.L) = 12; */
+ /* staticArrayPush(fibers.L); */
+ /* staticArrayLast(fibers.L) = 13; */
+ /* int r = staticArrayGet(fibers.L, -1); */
+ /* logVar(r, "d"); */
+ /* r = staticArrayGet(fibers.L, 3); */
+ /* logVar(r, "d"); */
+ /* r = indexerRef(fibers.L, -1); */
+ /* logVar(r, "d"); */
+ /* r = indexerRef(fibers.L, 3); */
+ /* logVar(r, "d"); */
+ /* r = staticArrayGet(fibers.L, -2); */
+ /* logVar(r, "d"); */
+ /* r = staticArrayGet(fibers.L, 2); */
+ /* logVar(r, "d"); */
+ /* r = indexerRef(fibers.L, -2); */
+ /* logVar(r, "d"); */
+ /* r = indexerRef(fibers.L, 2); */
+ /* logVar(r, "d"); */
+ /* r = staticArrayGet(fibers.L, -3); */
+ /* logVar(r, "d"); */
+ /* r = staticArrayGet(fibers.L, 1); */
+ /* logVar(r, "d"); */
+ /* r = indexerRef(fibers.L, -3); */
+ /* logVar(r, "d"); */
+ /* r = indexerRef(fibers.L, 1); */
+ /* logVar(r, "d"); */
+ /* r = staticArrayGet(fibers.L, -4); */
+ /* logVar(r, "d"); */
+ /* r = staticArrayGet(fibers.L, 0); */
+ /* logVar(r, "d"); */
+ /* r = indexerRef(fibers.L, -4); */
+ /* logVar(r, "d"); */
+ /* r = indexerRef(fibers.L, 0); */
+ /* logVar(r, "d"); */
+ /* staticArrayDequeue(fibers.L); */
+ /* put */
+ /* r = staticArrayRef(fibers.L, -1); */
+ /* logVar(r, "d"); */
+ /* r = staticArrayRef(fibers.L, 2); */
+ /* logVar(r, "d"); */
+ /* r = indexerRef(fibers.L, -1); */
+ /* logVar(r, "d"); */
+ /* r = indexerRef(fibers.L, 2); */
+ /* logVar(r, "d"); */
+ /* r = staticArrayRef(fibers.L, -2); */
+ /* logVar(r, "d"); */
+ /* r = staticArrayRef(fibers.L, 1); */
+ /* logVar(r, "d"); */
+ /* r = indexerRef(fibers.L, -2); */
+ /* logVar(r, "d"); */
+ /* r = indexerRef(fibers.L, 1); */
+ /* logVar(r, "d"); */
+ /* r = staticArrayRef(fibers.L, -3); */
+ /* logVar(r, "d"); */
+ /* r = staticArrayRef(fibers.L, 0); */
+ /* logVar(r, "d"); */
+ /* r = indexerRef(fibers.L, -3); */
+ /* logVar(r, "d"); */
+ /* r = indexerRef(fibers.L, 0); */
+ /* logVar(r, "d"); */
/* */
- /* pErrorCmd(isDir("qweqwe"), == false, pLog(LOG_WARNING, "qweqwe is NOT dir")) */
- /* else */
- /* pLog(LOG_INFO, "qweqwe is dir"); */
-
-
- setLogMode(LOG_CONCISE);
- pLog(LOG_CRITICAL, "1");
- pLog(LOG_ERROR, "1");
- pLog(LOG_WARNING, "1");
- pLog(LOG_INFO, "1");
- pLog(LOG_INVALID, "1");
- pLog(10, "1");
-
- //uint32_t x;
- //_rdrand32_step(&x);
- //setHardwareRandom();
-
- //pErrorResult(k, randomWordF(), == 0)
- //pErrorResultCmd(k, randomWordF(), == 0, return(1)
- setSoftwareRandom();
- pErrorResultCmd(k, randomWordF(), == 0, XFAILURE);
- logVar(k, PRIu64)
- printf("%" PRIu64 "\n\n", randomWordF());
-
- puts(getProgPath());
- puts(getRealProgPath());
- freeRealProgPath();
- //l = readText("/home/remy/tmp/auth.log");
-
- /* time_t t = getModificationTime("exe") */
- /* char *ti = timeToS(t) */
- /* logNFree(ti); */
- /* logNFree(timeToS(0)); */
-
-
- /* char *s = readS() */
+ /* char **aList = listCreateS("11", "22", "33") */
+ /* char **p = listAddrS(aList, -3); */
+ /* puts(*p); */
+ /* p = listAddrS(aList, -1); */
+ /* puts(*p); */
+ /* p = listAddrS(aList, 0); */
+ /* puts(*p); */
+ /* p = listAddrS(aList, 2); */
+ /* puts(*p); */
+ /* */
+ /* XSUCCESS */
+ /* */
+ /* indexer id; */
+ /* indexerInit(id, 10); */
+ /* indexerPush(id); */
+ /* logVar(id.last, PRIi64); */
+ /* a[indexerLast(id)] = 'a'; */
+ /* indexerPush(id); */
+ /* logVar(id.last, PRIi64); */
+ /* a[id.last] = 'b'; */
+ /* indexerPush(id); */
+ /* a[id.last] = 0; */
+ /* logVar(id.last, PRIi64); */
+ /* indexerPop(id); */
+ /* logVar(id.last, PRIi64); */
+ /* */
+ /* //passwordEnter:; */
+ /* char *c; */
+ /* */
+ /* printf("P: "); */
+ /* c = readPasswordS() */
+ /* puts(c); */
+ /* printf("O: "); */
+ /* char *d = readPasswordS() */
+ /* puts(d); */
+ /* puts(c); */
+ /* XSUCCESS */
+ /* */
+ /* pError0(listPrintS(walkDirDir("dirTest.null"))); */
+ /* */
+ /* circular(i, 2, 4) { */
+ /* printf("%d\n", (int)i); */
+ /* } */
+ /* */
+ /* char **l2 = listCreateS("lib") */
+ /* listEmptyS(l); */
+ /* char **R = listInsertS(l, -1, l2); */
+ /* puts(R[0]); */
+ /* */
+ /* pErrorNULL(injectS("s", -2, 'D')); */
+ /* */
+ /* c = strdup(" SHeePY") */
+ /* pErrorNULL(iLTrimS(&c)); */
+ /* printf(">%s<\n",c); */
+ /* free(c); */
+ /* */
+ /* pError0(copy("dirTest.null", "..")); */
+ /* */
+ /* puts(getProgPath()); */
+ /* initLibsheepy("test"); */
+ /* puts(getProgPath()); */
+ /* */
+ /* puts( EVA(c, normalizePath("/wef/./../")) ); */
+ /* free c */
+ /* puts(__func__); */
+ /* AT; */
+ /* */
+ /* pErrorNULL(iCatS(a, "qwee ", "wefwef", "--1`21`2123")); */
+ /* puts(a); */
+ /* */
+ /* XSUCCESS */
+ /* */
+ /* rangeDown(i, 10) */
+ /* printf("%ld\n", i); */
+ /* */
+ /* XSUCCESS */
+ /* */
+ /* initLibsheepy(argv[0]); */
+ /* puts(getProgPath()); */
+ /* */
+ /* //mkdirParents("rmAllTest.null/null"); */
+ /* k = rmAll("link"); */
+ /* logVar(k, PRIi64); */
+ /* */
+ /* forEachS(l, L) */
+ /* free L */
+ /* forEachS(l, L) */
+ /* free L */
+ /* */
+ /* XSUCCESS */
+ /* */
+ /* puts("readDir"); */
+ /* put */
+ /* pError0(listPrintS(readDir("."))); */
+ /* puts("readDirDir"); */
+ /* put */
+ /* pError0(listPrintS(readDirDir("."))); */
+ /* puts("readDirAll"); */
+ /* put */
+ /* pError0(listPrintS(readDirAll("."))); */
+ /* */
+ /* pError0(isNumber("-12.3")); */
+ /* XSUCCESS */
+ /* */
+ /* #<{(| int r = 0 |)}># */
+ /* #<{(| tryV(r, 0) { |)}># */
+ /* #<{(| throwV(0, 10); |)}># */
+ /* #<{(| puts("does not print"); |)}># */
+ /* #<{(| } |)}># */
+ /* #<{(| else |)}># */
+ /* #<{(| printf("except value %d\n", r); |)}># */
+ /* */
+ /* printf("%" PRIu64 "\n", getMonotonicTime()); */
+ /* */
+ /* #<{(| AArgs Aa; |)}># */
+ /* #<{(| Aa.a = 0 |)}># */
+ /* #<{(| A(&Aa); |)}># */
+ /* //AB(); */
+ /* */
+ /* AArgs Aa; */
+ /* BArgs Ba; */
+ /* */
+ /* initLibsheepy(argv[0]); */
+ /* #<{(| staticArrayInit(fibers.L); |)}># */
+ /* #<{(| staticArrayInit(fibers.startL); |)}># */
+ /* */
+ /* puts(__func__); */
+ /* Aa.a = 0 */
+ /* fiberAdd(&Aa, 1, fiberA); */
+ /* */
+ /* puts(__func__); */
+ /* Ba.a = 1 */
+ /* Ba.b = 2 */
+ /* fiberAdd(&Ba, 2, fiberB); */
+ /* */
+ /* scheduler(); */
+ /* */
+ /* #<{(| if !setjmp(buf) |)}># */
+ /* #<{(| longjmp(buf,1); |)}># */
+ /* #<{(| else |)}># */
+ /* #<{(| puts("except"); |)}># */
+ /* */
+ /* XSUCCESS */
+ /* */
+ /* pError0(copy("cov.info", "qwe")); */
+ /* pError0(copy("dirTest.null/", "mkdirTest.null/null/")); */
+ /* pError0(copy("dirTest.null", "mkdirTest.null/")); */
+ /* */
+ /* initLibsheepy(argv[0]); */
+ /* */
+ /* //NO - limited to 2GB files - sendfile(0, 0, 0, 10); */
+ /* setLogFile(NULL); */
+ /* */
+ /* //char *s = formatS("%s/%d\n", "qwd",645); */
+ /* char *s = NULL */
+ /* s = formatS("%s/%d\n", "qwd",645); */
+ /* //char *s = NULL; */
+ /* //pError(asprintf(&s, "%s/%s\n", "qwd","qw")); */
/* puts(s); */
- /* puts("Read enter"); */
- /* readEnter(); */
-
- //bool cond = true
- //puts(stringifyExpr(cond));
-
- XSUCCESS
-
-
- time_t t = getModificationTime("exe");; {
- pError0(getModificationTime("wrong")) {
-
- pError(setModificationTime("exe", t)) {
- pError(setModificationTime("wrong",t)) {
-
-
- if (equalModificationTimes("exe", "exe")) {
- puts("exe =");
- }
-
- if (equalModificationTimes("exe", "libsheepy.h")) {
- puts("exe = ls h");
- }
-
- l = listCreateS("fdfg", "@#$");;
-
- forEachS(l, e) {
- puts(e);
- }
- enumerateS(l, E, i) {
- printf("%d %s", (int)i, E);
- printf("\n");
- }
-
- int *er = NULL;
- cast(char **, tt, er)
- tt = NULL;
- er = (int*)tt;
-
- char *dum = strdup("ls dasd");;
- pErrorNot0(systemNFree(dum));
-
- // no ~/
- char *s;
- s = expandHome("sheepy");;
- //ck_assert_str_eq(s, "sheepy");
- free(s);
- // NULL path
- //ck_assert_ptr_eq(expandHome(NULL), NULL);
-
- s = strdup(";//w//ef//");
- pErrorNULL(iUniqS(&s, '/'));
- puts(s);
- puts(uniqS("wef", '/'));
- puts(uniqS("//w//ef//", '/'));
-
- l = NULL;
- *l = (char *)1;;
+ /* */
+ /* pError0(listPrintS(walkDirAll("."))); */
+ /* printf("%o\n", 0777 & ~getUmask()); */
+ /* pError0(mkdirParents("mkdirTest.null/null")); */
+ /* */
+ /* #<{(| pErrorCmd(isDir("json"), == false, pLog(LOG_WARNING, "json is NOT dir")) |)}># */
+ /* #<{(| else |)}># */
+ /* #<{(| pLog(LOG_INFO, "json is dir"); |)}># */
+ /* #<{(| |)}># */
+ /* #<{(| pErrorCmd(isDir("qweqwe"), == false, pLog(LOG_WARNING, "qweqwe is NOT dir")) |)}># */
+ /* #<{(| else |)}># */
+ /* #<{(| pLog(LOG_INFO, "qweqwe is dir"); |)}># */
+ /* */
+ /* */
+ /* setLogMode(LOG_CONCISE); */
+ /* pLog(LOG_CRITICAL, "1"); */
+ /* pLog(LOG_ERROR, "1"); */
+ /* pLog(LOG_WARNING, "1"); */
+ /* pLog(LOG_INFO, "1"); */
+ /* pLog(LOG_INVALID, "1"); */
+ /* pLog(10, "1"); */
+ /* */
+ /* //uint32_t x; */
+ /* //_rdrand32_step(&x); */
+ /* //setHardwareRandom(); */
+ /* */
+ /* //pErrorResult(k, randomWordF(), == 0) */
+ /* //pErrorResultCmd(k, randomWordF(), == 0, return(1) */
+ /* setSoftwareRandom(); */
+ /* pErrorResultCmd(k, randomWordF(), == 0, XFAILURE) */
+ /* logVar(k, PRIu64) */
+ /* printf("%" PRIu64 "\n\n", randomWordF()); */
+ /* */
+ /* puts(getProgPath()); */
+ /* puts(getRealProgPath()); */
+ /* freeRealProgPath(); */
+ /* //l = readText("/home/remy/tmp/auth.log"); */
+ /* */
+ /* #<{(| time_t t = getModificationTime("exe") |)}># */
+ /* #<{(| char *ti = timeToS(t) |)}># */
+ /* #<{(| logNFree(ti); |)}># */
+ /* #<{(| logNFree(timeToS(0)); |)}># */
+ /* */
+ /* */
+ /* #<{(| char *s = readS() |)}># */
+ /* #<{(| puts(s); |)}># */
+ /* #<{(| puts("Read enter"); |)}># */
+ /* #<{(| readEnter(); |)}># */
+ /* */
+ /* //bool cond = true */
+ /* //puts(stringifyExpr(cond)); */
+ /* */
+ /* XSUCCESS */
+ /* */
+ /* */
+ /* time_t t = getModificationTime("exe"); */
+ /* pError0(getModificationTime("wrong")) */
+ /* */
+ /* pError(setModificationTime("exe", t)) */
+ /* pError(setModificationTime("wrong",t)) */
+ /* */
+ /* */
+ /* if equalModificationTimes("exe", "exe") */
+ /* puts("exe ="); */
+ /* */
+ /* if equalModificationTimes("exe", "libsheepy.h") */
+ /* puts("exe = ls h"); */
+ /* */
+ /* l = listCreateS("fdfg", "@#$"); */
+ /* */
+ /* forEachS(l, e) */
+ /* puts(e); */
+ /* enumerateS(l, E, i) */
+ /* print '%d %s', (int)i, E */
+ /* */
+ /* int *er = NULL */
+ /* cast(char **, tt, er) */
+ /* tt = NULL */
+ /* er = (int*)tt */
+ /* */
+ /* char *dum = strdup("ls dasd"); */
+ /* pErrorNot0(systemNFree(dum)); */
+ /* */
+ /* // no ~/ */
+ /* char *s1; */
+ /* s1 = expandHome("sheepy"); */
+ /* //ck_assert_str_eq(s1, "sheepy"); */
+ /* free(s1); */
+ /* // NULL path */
+ /* //ck_assert_ptr_eq(expandHome(NULL), NULL); */
+ /* */
+ /* s1 = strdup("//w//ef//"); */
+ /* pErrorNULL(iUniqS(&s1, '/')); */
+ /* puts(s1); */
+ /* puts(uniqS("wef", '/')); */
+ /* puts(uniqS("//w//ef//", '/')); */
+ /* */
+ /* l = NULL */
+ /* *l = (char *)1; */
XSUCCESS;
}
- }
- }
- }
- }
diff --git a/src/libsheepy.h b/src/libsheepy.h
@@ -98,7 +98,7 @@
// version accoring to the version package: Release.Major.minor.patch
// https://noulin.net/version/file/README.md.html
-#define LIBSHEEPY_VERSION "2.2.8.2"
+#define LIBSHEEPY_VERSION "2.2.9"
#ifndef SH_PREFIX
#define SH_PREFIX(NAME) NAME
@@ -974,6 +974,7 @@ uint64_t shStopwatch(uint8_t op);
// add a log file, maximum 15 files
FILE *SH_PREFIX(setLogFile)(char *filename);
+#define openLogFile setLogFile
#ifdef __GNUC__
/** force function callers to check return value
@@ -1021,6 +1022,9 @@ void setLogStdout(bool state);
// log to a file named progName.log
bool openProgLogFile(void) MUST_CHECK;
+// keep ansi colors in logs
+void keepAnsiColorsInLog(bool state);
+
/**
* print logging levels
*
@@ -2045,6 +2049,11 @@ char *stripCtrlS(const char *string) MUST_CHECK;
char *iStripCtrlS(char **string) MUST_CHECK;
char *bStripCtrlS(char *string) MUST_CHECK;
+// remove ansi colors from string
+char *stripColorsS(const char *string) MUST_CHECK;
+char *iStripColorsS(char **string) MUST_CHECK;
+char *bStripColorsS(char *string) MUST_CHECK;
+
// true when string is a number (integer or float)
bool isNumber(const char *string) MUST_CHECK;
@@ -3969,7 +3978,7 @@ void **iListDel(void ***list, int64_t start, int64_t end) MUST_CHECK;
var UNIQVAR(idx) = index;\
if ((size_t)UNIQVAR(idx) < (size_t)sliceLastIndex(name)) {\
/* move elements */\
- memcpy(slicePtr(name, UNIQVAR(idx)), slicePtr(name, UNIQVAR(idx) +1), ((name)->count - (UNIQVAR(idx) +1)) * sizeof (name)->array[0]);\
+ memmove(slicePtr(name, UNIQVAR(idx)), slicePtr(name, UNIQVAR(idx) +1), ((name)->count - (UNIQVAR(idx) +1)) * sizeof (name)->array[0]);\
}\
(name)->count--;\
} while(0)
@@ -3984,7 +3993,7 @@ void **iListDel(void ***list, int64_t start, int64_t end) MUST_CHECK;
var UNIQVAR(ed) = end;\
if (UNIQVAR(ed) < (name)->count and UNIQVAR(strt) < UNIQVAR(ed)) {\
/* move elements */\
- memcpy(slicePtr(name, UNIQVAR(strt)), slicePtr(name, UNIQVAR(ed)), ((name)->count - UNIQVAR(ed)) * sizeof (name)->array[0]);\
+ memmove(slicePtr(name, UNIQVAR(strt)), slicePtr(name, UNIQVAR(ed)), ((name)->count - UNIQVAR(ed)) * sizeof (name)->array[0]);\
}\
(name)->count -= UNIQVAR(ed) - UNIQVAR(strt);\
} while(0)
@@ -3997,7 +4006,7 @@ void **iListDel(void ***list, int64_t start, int64_t end) MUST_CHECK;
var UNIQVAR(vec) = slice;\
if (sizeof((name)->array[0]) == sizeof((UNIQVAR(vec))->array[0])) {\
sliceResize(name, (name)->count + (UNIQVAR(vec))->count);\
- memcpy((name)->array + (name)->count, (UNIQVAR(vec))->array, (UNIQVAR(vec))->count * sizeof (name)->array[0]);\
+ memmove((name)->array + (name)->count, (UNIQVAR(vec))->array, (UNIQVAR(vec))->count * sizeof (name)->array[0]);\
(name)->count += (UNIQVAR(vec))->count;\
}\
} while(0)
@@ -4011,7 +4020,7 @@ void **iListDel(void ***list, int64_t start, int64_t end) MUST_CHECK;
var UNIQVAR(a) = array;\
if (sizeof((name)->array[0]) == sizeof(*(UNIQVAR(a)))) {\
sliceResize(name, (name)->count + UNIQVAR(c));\
- memcpy((name)->array + (name)->count, UNIQVAR(a), UNIQVAR(c) * sizeof (name)->array[0]);\
+ memmove((name)->array + (name)->count, UNIQVAR(a), UNIQVAR(c) * sizeof (name)->array[0]);\
(name)->count += UNIQVAR(c);\
}\
} while(0)
@@ -4026,7 +4035,7 @@ void **iListDel(void ***list, int64_t start, int64_t end) MUST_CHECK;
if (sizeof((name)->array[0]) == sizeof((UNIQVAR(vec))->array[0])) {\
sliceResize(name, (name)->count + (UNIQVAR(vec))->count);\
memmove((name)->array + (UNIQVAR(vec))->count, (name)->array, (name)->count * sizeof (name)->array[0]);\
- memcpy((name)->array, (UNIQVAR(vec))->array, (UNIQVAR(vec))->count * sizeof (name)->array[0]);\
+ memmove((name)->array, (UNIQVAR(vec))->array, (UNIQVAR(vec))->count * sizeof (name)->array[0]);\
(name)->count += (UNIQVAR(vec))->count;\
}\
} while(0)
@@ -4042,7 +4051,7 @@ void **iListDel(void ***list, int64_t start, int64_t end) MUST_CHECK;
if (sizeof((name)->array[0]) == sizeof(*(UNIQVAR(a)))) {\
sliceResize(name, (name)->count + UNIQVAR(c));\
memmove((name)->array + UNIQVAR(c), (name)->array, (name)->count * sizeof (name)->array[0]);\
- memcpy((name)->array, UNIQVAR(a), UNIQVAR(c) * sizeof (name)->array[0]);\
+ memmove((name)->array, UNIQVAR(a), UNIQVAR(c) * sizeof (name)->array[0]);\
(name)->count += UNIQVAR(c);\
}\
} while(0);
@@ -4061,7 +4070,7 @@ void **iListDel(void ***list, int64_t start, int64_t end) MUST_CHECK;
else if (sizeof((name)->array[0]) == sizeof((UNIQVAR(vec))->array[0])) {\
sliceResize(name, (name)->count + (UNIQVAR(vec))->count);\
memmove((name)->array + UNIQVAR(idx) + (UNIQVAR(vec))->count, (name)->array + UNIQVAR(idx), ((name)->count - UNIQVAR(idx)) * sizeof (name)->array[0]);\
- memcpy((name)->array + UNIQVAR(idx), (UNIQVAR(vec))->array, (UNIQVAR(vec))->count * sizeof (name)->array[0]);\
+ memmove((name)->array + UNIQVAR(idx), (UNIQVAR(vec))->array, (UNIQVAR(vec))->count * sizeof (name)->array[0]);\
(name)->count += (UNIQVAR(vec))->count;\
}\
} while(0)
@@ -4081,7 +4090,7 @@ void **iListDel(void ***list, int64_t start, int64_t end) MUST_CHECK;
else if (sizeof((name)->array[0]) == sizeof(UNIQVAR(a)[0])) {\
sliceResize(name, (name)->count + UNIQVAR(c));\
memmove((name)->array + UNIQVAR(idx) + UNIQVAR(c), (name)->array + UNIQVAR(idx), ((name)->count - UNIQVAR(idx)) * sizeof (name)->array[0]);\
- memcpy((name)->array + UNIQVAR(idx), UNIQVAR(a), UNIQVAR(c) * sizeof (name)->array[0]);\
+ memmove((name)->array + UNIQVAR(idx), UNIQVAR(a), UNIQVAR(c) * sizeof (name)->array[0]);\
(name)->count += UNIQVAR(c);\
}\
} while(0)
@@ -4096,7 +4105,7 @@ void **iListDel(void ***list, int64_t start, int64_t end) MUST_CHECK;
var UNIQVAR(strt) = start;\
var UNIQVAR(ed) = end;\
if (UNIQVAR(strt))\
- memcpy((name)->array, (name)->array + UNIQVAR(strt), (UNIQVAR(ed) - UNIQVAR(strt)) * sizeof (name)->array[0]);\
+ memmove((name)->array, (name)->array + UNIQVAR(strt), (UNIQVAR(ed) - UNIQVAR(strt)) * sizeof (name)->array[0]);\
(name)->count = UNIQVAR(ed) - UNIQVAR(strt);\
name;\
})
@@ -4111,7 +4120,7 @@ void **iListDel(void ***list, int64_t start, int64_t end) MUST_CHECK;
var UNIQVAR(strt) = start;\
var UNIQVAR(ed) = end;\
createAllocateSliceCount(typeof(*(name)),UNIQVAR(r), UNIQVAR(ed) - UNIQVAR(strt));\
- memcpy(UNIQVAR(r)->array, (name)->array + UNIQVAR(strt), (UNIQVAR(ed) - UNIQVAR(strt)) * sizeof (name)->array[0]);\
+ memmove(UNIQVAR(r)->array, (name)->array + UNIQVAR(strt), (UNIQVAR(ed) - UNIQVAR(strt)) * sizeof (name)->array[0]);\
UNIQVAR(r)->count = UNIQVAR(ed) - UNIQVAR(strt);\
UNIQVAR(r);\
})
@@ -4126,7 +4135,7 @@ void **iListDel(void ***list, int64_t start, int64_t end) MUST_CHECK;
var UNIQVAR(strt) = start;\
var UNIQVAR(ed) = end;\
sliceResize(dest, UNIQVAR(ed) - UNIQVAR(strt));\
- memcpy((dest)->array, (name)->array + UNIQVAR(strt), (UNIQVAR(ed) - UNIQVAR(strt)) * sizeof (name)->array[0]);\
+ memmove((dest)->array, (name)->array + UNIQVAR(strt), (UNIQVAR(ed) - UNIQVAR(strt)) * sizeof (name)->array[0]);\
(dest)->count = UNIQVAR(ed) - UNIQVAR(strt);\
}\
} while(0)
@@ -6246,6 +6255,40 @@ typedef struct {
#define staticArrayFirstIndex(name) (name).head
/**
+ * delete an element in the array and move elements after it to fill the gap
+ */
+#define staticArrayDelElem(name, index) do {\
+ if ((name).head < (name).last) {\
+ /* move elements after index in latest static array */\
+ if (index < (name).last) {\
+ memmove(&(name).list[index], &(name).list[index+1], ((name).last - index) * sizeof((name).list[0]));\
+ }\
+ }\
+ elif ((name).head > (name).last) {\
+ if (index >= (name).head) {\
+ /* move elements after index in latest static array */\
+ if (index < (name).maxCount - 1) {\
+ memmove(&(name).list[index], &(name).list[index+1], ((name).maxCount - index -1) * sizeof((name).list[0]));\
+ }\
+ /* move list[0] to list[maxCount-1] */\
+ /* then shift elements in [1..last+1] to [0..last] if needed */\
+ staticArrayAt((name), (name).maxCount-1) = staticArrayAt((name), 0);\
+ if ((name).last > 0) {\
+ memmove(&(name).list[0], &(name).list[1], (name).last * sizeof((name).list[0]));\
+ }\
+ }\
+ else {\
+ /* 0 < index < last+1 */\
+ /* move elements after index in latest static array */\
+ if (index < (name).last) {\
+ memmove(&(name).list[index], &(name).list[index+1], ((name).last - index) * sizeof((name).list[0]));\
+ }\
+ }\
+ }\
+ staticArrayDelLast((name));\
+ } while(0)
+
+/**
* write the staticArray content to filename file
* No NULL checks are done on the parameters
*
diff --git a/src/libsheepyBt.c b/src/libsheepyBt.c
@@ -21,32 +21,32 @@
#endif
/**
- * return a bt object with s as buffer
+ * return a btt object with s as buffer
*/
-bt initCharB(char *s) {
+btt initCharB(char *s) {
ret charB(s);
}
/**
- * return a bt object with s as buffer
+ * return a btt object with s as buffer
* the buffer is not going to be reallocated
*/
-bt initCCharB(char *s) {
+btt initCCharB(char *s) {
ret ccharB(s);
}
/**
- * return a bt object with buf as buffer
+ * return a btt object with buf as buffer
*/
-bt initB(void *buf, u32 len, bool allocated) {
+btt initB(void *buf, u32 len, bool allocated) {
ret voidB(buf, len, allocated);
}
/**
- * return a bt object with a heap allocated buffer of size allocateSize
+ * return a btt object with a heap allocated buffer of size allocateSize
*/
-bt newB(u32 allocateSize) {
- bt r = {.len = 0};
+btt newB(u32 allocateSize) {
+ btt r = {.len = 0};
r.b = malloc(allocateSize);
if (!r.b) ret emptybt;
r.alloc = allocateSize;
@@ -54,19 +54,19 @@ bt newB(u32 allocateSize) {
}
/**
- * return a heap allocated bt object with a heap allocated buffer of size allocateSize
+ * return a heap allocated btt object with a heap allocated buffer of size allocateSize
*/
-bt *allocNewB(u32 allocateSize) {
- bt *r = malloc(sizeof(*r));
+btt *allocNewB(u32 allocateSize) {
+ btt *r = malloc(sizeof(*r));
*r = newB(allocateSize);
ret r;
}
// not needed, use charB or ccharB
// /**
-// * set buf in the b bt object
+// * set buf in the b btt object
// */
-// bt *setB(bt *b, char *buf, bool allocated) {
+// btt *setB(btt *b, char *buf, bool allocated) {
// if (!b or !buf) ret null;
// b->b = buf;
// b->len = strlen(buf);
@@ -75,79 +75,79 @@ bt *allocNewB(u32 allocateSize) {
// }
/**
- * return a heap allocated bt object with buf assigned to it
+ * return a heap allocated btt object with buf assigned to it
*/
-bt *allocCharB(char *buf) {
+btt *allocCharB(char *buf) {
if (!buf) ret null;
- bt *r = malloc(sizeof(*r));
+ btt *r = malloc(sizeof(*r));
if (!r) ret null;
*r = charB(buf);
ret r;
}
/**
- * return a heap allocated bt object with buf assigned to it
+ * return a heap allocated btt object with buf assigned to it
*/
-bt *allocCCharB(char *buf) {
+btt *allocCCharB(char *buf) {
if (!buf) ret null;
- bt *r = malloc(sizeof(*r));
+ btt *r = malloc(sizeof(*r));
if (!r) ret null;
*r = ccharB(buf);
ret r;
}
-bt *allocBufB(void *buf, u32 len, bool allocated) {
+btt *allocBufB(void *buf, u32 len, bool allocated) {
if (!buf) ret null;
- bt *r = malloc(sizeof(*r));
+ btt *r = malloc(sizeof(*r));
if (!r) ret null;
*r = voidB(buf, len, allocated);
ret r;
}
/**
- * return a heap allocated bt object with b assigned to it
+ * return a heap allocated btt object with b assigned to it
*/
-bt *allocB(const bt b) {
- bt *r = malloc(sizeof(*r));
+btt *allocB(const btt b) {
+ btt *r = malloc(sizeof(*r));
if (!r) ret null;
*r = b;
ret r;
}
/**
- * return a heap allocated bt object with *b assigned to it
+ * return a heap allocated btt object with *b assigned to it
*/
-bt *allocPB(const bt *b) {
+btt *allocPB(const btt *b) {
if (!b) ret null;
ret allocB(*b);
}
/**
- * return a bt object with a heap allocated copy of b.b
+ * return a btt object with a heap allocated copy of b.b
*/
-bt copyB(const bt b) {
- bt r = b;
+btt copyB(const btt b) {
+ btt r = b;
r.b = malloc(b.len);
r.alloc = b.len;
memcpy(r.b, b.b, b.len);
ret r;
}
-bt copyPB(bt *b) {
+btt copyPB(btt *b) {
if (!b) ret emptybt;
ret copyB(*b);
}
/**
- * return a heap allocated bt object with a heap allocated copy of b.b
+ * return a heap allocated btt object with a heap allocated copy of b.b
*/
-bt *dupB(const bt b) {
- bt *r = malloc(sizeof(*r));
+btt *dupB(const btt b) {
+ btt *r = malloc(sizeof(*r));
*r = copyB(b);
ret r;
}
-bt *dupPB(bt *b) {
+btt *dupPB(btt *b) {
if (!b) ret null;
ret dupB(*b);
}
@@ -156,7 +156,7 @@ bt *dupPB(bt *b) {
* free heap allocated .b
* nothing if not heap allocated
*/
-void freeB(bt b) {
+void freeB(btt b) {
if (b.alloc) {
free(b.b);
}
@@ -166,7 +166,7 @@ void freeB(bt b) {
* free heap allocated .b and assign null to .b
* nothing if not heap allocated
*/
-void freenB(bt *b) {
+void freenB(btt *b) {
if (b and b->alloc) {
freen(b->b);
b->len = 0;
@@ -175,9 +175,9 @@ void freenB(bt *b) {
}
/**
- * free the heap allocated bt object (container only, not .b)
+ * free the heap allocated btt object (container only, not .b)
*/
-void finishB(bt **b) {
+void finishB(btt **b) {
if (b) {
free(*b);
*b = null;
@@ -185,9 +185,9 @@ void finishB(bt **b) {
}
/**
- * free the heap allocated bt object and free .b
+ * free the heap allocated btt object and free .b
*/
-void terminateB(bt **b) {
+void terminateB(btt **b) {
if (b) {
if (*b and (*b)->alloc) {
free((*b)->b);
@@ -198,34 +198,34 @@ void terminateB(bt **b) {
}
// terminate val when it is out of scope
-void cleanUpTerminateB(bt **val) {
+void cleanUpTerminateB(btt **val) {
terminateB(val);
}
// free local val when it is out of scope
-void cleanUpFreeLocalB(bt *val) {
+void cleanUpFreeLocalB(btt *val) {
freeB(*val);
}
// free val when it is out of scope
-void cleanUpFreeB(bt **val) {
+void cleanUpFreeB(btt **val) {
freeB(**val);
}
// finish val when it is out of scope
-void cleanUpFinishB(bt **val) {
+void cleanUpFinishB(btt **val) {
finishB(val);
}
/**
- * return a bt object with s appended to b
+ * return a btt object with s appended to b
* b doesn't need to have a heap allocated buffer
*/
-bt pushB(const bt b, const char *s) {
+btt pushB(const btt b, const char *s) {
// duplicate b.b
// copy s to b end
- bt r = copyB(b);
- bt *p = bPushB(&r, s);
+ btt r = copyB(b);
+ btt *p = bPushB(&r, s);
if (p) ret r;
else {
freeB(r);
@@ -239,7 +239,7 @@ bt pushB(const bt b, const char *s) {
* update b and append s
* b.b is reallocated
*/
-bt *bPushB(bt *b, const char *s) {
+btt *bPushB(btt *b, const char *s) {
if (!b or !b->b or !s) ret null;
size_t len = strlen(s);
@@ -260,14 +260,14 @@ bt *bPushB(bt *b, const char *s) {
// TODO bPushManyB
/**
- * return a bt object with s bt object appended to b
+ * return a btt object with s btt object appended to b
* b doesn't need to have a heap allocated buffer
*/
-bt pushBB(const bt b, const bt s) {
+btt pushBB(const btt b, const btt s) {
// duplicate b.b
// copy s to b end
- bt r = copyB(b);
- bt *p = bPushBB(&r, s);
+ btt r = copyB(b);
+ btt *p = bPushBB(&r, s);
if (p) ret r;
else {
freeB(r);
@@ -279,10 +279,10 @@ bt pushBB(const bt b, const bt s) {
// TODO bPushManyBB
/**
- * update b and append s bt object
+ * update b and append s btt object
* b.b is reallocated
*/
-bt *bPushBB(bt *b, const bt s) {
+btt *bPushBB(btt *b, const btt s) {
if (!b or !b->b or !s.b) ret null;
if (!s.len) ret b;
@@ -304,10 +304,10 @@ bt *bPushBB(bt *b, const bt s) {
// TODO bPushManyBB
/**
- * return a bt object with *s bt object appended to b
+ * return a btt object with *s btt object appended to b
* b doesn't need to have a heap allocated buffer
*/
-bt pushBPB(const bt b, const bt *s) {
+btt pushBPB(const btt b, const btt *s) {
if (!s) ret emptybt;
// duplicate b.b
// copy s to b end
@@ -317,10 +317,10 @@ bt pushBPB(const bt b, const bt *s) {
// TODO bPushManyBPB
/**
- * update b and append *s bt object
+ * update b and append *s btt object
* b.b is reallocated
*/
-bt *bPushBPB(bt *b, const bt *s) {
+btt *bPushBPB(btt *b, const btt *s) {
if (!s) ret null;
// copy s to b end
ret bPushBB(b, *s);
@@ -329,30 +329,30 @@ bt *bPushBPB(bt *b, const bt *s) {
// TODO bPushManyBB
/**
- * return a bt object with s appended to *b
+ * return a btt object with s appended to *b
* b doesn't need to have a heap allocated buffer
*/
-bt pushPB(const bt *b, const char *s) {
+btt pushPB(const btt *b, const char *s) {
if (!b) ret emptybt;
ret pushB(*b, s);
}
// TODO pushManyPB...
/**
- * return a bt object with s bt object appended to *b
+ * return a btt object with s btt object appended to *b
* b doesn't need to have a heap allocated buffer
*/
-bt pushPBB(const bt *b, const bt s) {
+btt pushPBB(const btt *b, const btt s) {
if (!b) ret emptybt;
ret pushBB(*b, s);
}
// TODO pushManyPBB...
/**
- * return a bt object with *s bt object appended to *b
+ * return a btt object with *s btt object appended to *b
* b doesn't need to have a heap allocated buffer
*/
-bt pushPBPB(const bt *b, const bt *s) {
+btt pushPBPB(const btt *b, const btt *s) {
if (!b) ret emptybt;
ret pushBPB(*b, s);
}
@@ -362,7 +362,7 @@ bt pushPBPB(const bt *b, const bt *s) {
* split b in vb static vector
* the vector is not reallocated
*/
-vbt *sasplitB(vbt *vb, const bt b, const bt delim) {
+vbtt *sasplitB(vbtt *vb, const btt b, const btt delim) {
if (!vb or !b.b or !delim.b) ret null;
vb->count = 0;
@@ -384,7 +384,7 @@ vbt *sasplitB(vbt *vb, const bt b, const bt delim) {
break;
if (vb->count >= vb->maxCount) ret null;
nextTokenStart = ptr + 1;
- bt tok = {.b = working, .len = ptr-working, .alloc = 0};
+ btt tok = {.b = working, .len = ptr-working, .alloc = 0};
vectorAppend(vb, tok);
i += tok.len + delim.len;
working = b.b + i;
@@ -397,14 +397,14 @@ vbt *sasplitB(vbt *vb, const bt b, const bt delim) {
break;
if (vb->count >= vb->maxCount) ret null;
nextTokenStart = ptr + delim.len;
- bt tok = {.b = working, .len = ptr-working, .alloc = 0};
+ btt tok = {.b = working, .len = ptr-working, .alloc = 0};
vectorAppend(vb, tok);
i += tok.len + delim.len;
working = b.b + i;
}
}
if (vb->count >= vb->maxCount) ret null;
- bt tok = {.b = nextTokenStart, .len = (b.b+b.len)-nextTokenStart, .alloc = 0};
+ btt tok = {.b = nextTokenStart, .len = (b.b+b.len)-nextTokenStart, .alloc = 0};
vectorAppend(vb, tok);
ret vb;
@@ -414,8 +414,8 @@ vbt *sasplitB(vbt *vb, const bt b, const bt delim) {
* split b in vb static vector
* the vector is not reallocated
*/
-vbt *sasplitCharB(vbt *vb, const bt b, char *delim) {
- bt d = ccharB(delim);
+vbtt *sasplitCharB(vbtt *vb, const btt b, char *delim) {
+ btt d = ccharB(delim);
ret sasplitB(vb, b, d);
}
@@ -423,7 +423,7 @@ vbt *sasplitCharB(vbt *vb, const bt b, char *delim) {
* split b in vb static vector
* the vector is not reallocated
*/
-vbt *sasplitDPB(vbt *vb, const bt b, const bt *delim) {
+vbtt *sasplitDPB(vbtt *vb, const btt b, const btt *delim) {
if (!delim) ret null;
ret sasplitB(vb, b, *delim);
}
@@ -432,7 +432,7 @@ vbt *sasplitDPB(vbt *vb, const bt b, const bt *delim) {
* split b in vb static vector
* the vector is not reallocated
*/
-vbt *sasplitPB(vbt *vb, const bt *b, const bt delim) {
+vbtt *sasplitPB(vbtt *vb, const btt *b, const btt delim) {
if (!b) ret null;
ret sasplitB(vb, *b, delim);
}
@@ -441,7 +441,7 @@ vbt *sasplitPB(vbt *vb, const bt *b, const bt delim) {
* split b in vb static vector
* the vector is not reallocated
*/
-vbt *sasplitPCharB(vbt *vb, const bt *b, char *delim) {
+vbtt *sasplitPCharB(vbtt *vb, const btt *b, char *delim) {
if (!b) ret null;
ret sasplitCharB(vb, *b, delim);
}
@@ -450,7 +450,7 @@ vbt *sasplitPCharB(vbt *vb, const bt *b, char *delim) {
* split b in vb static vector
* the vector is not reallocated
*/
-vbt *sasplitPDPB(vbt *vb, const bt *b, const bt *delim) {
+vbtt *sasplitPDPB(vbtt *vb, const btt *b, const btt *delim) {
if (!b or !delim) ret null;
ret sasplitB(vb, *b, *delim);
}
@@ -481,7 +481,7 @@ vbt *sasplitPDPB(vbt *vb, const bt *b, const bt *delim) {
/**
* split b in vb vector
*/
-vbt *asplitB(vbt *vb, const bt b, const bt delim) {
+vbtt *asplitB(vbtt *vb, const btt b, const btt delim) {
if (!vb or !b.b or !delim.b) ret null;
vb->count = 0;
@@ -501,7 +501,7 @@ vbt *asplitB(vbt *vb, const bt b, const bt delim) {
if (!ptr)
break;
nextTokenStart = ptr + 1;
- bt tok = {.b = working, .len = ptr-working, .alloc = 0};
+ btt tok = {.b = working, .len = ptr-working, .alloc = 0};
vectorAppend(vb, tok);
i += tok.len + delim.len;
working = b.b + i;
@@ -513,13 +513,13 @@ vbt *asplitB(vbt *vb, const bt b, const bt delim) {
if (!ptr)
break;
nextTokenStart = ptr + delim.len;
- bt tok = {.b = working, .len = ptr-working, .alloc = 0};
+ btt tok = {.b = working, .len = ptr-working, .alloc = 0};
vectorAppend(vb, tok);
i += tok.len + delim.len;
working = b.b + i;
}
}
- bt tok = {.b = nextTokenStart, .len = (b.b+b.len)-nextTokenStart, .alloc = 0};
+ btt tok = {.b = nextTokenStart, .len = (b.b+b.len)-nextTokenStart, .alloc = 0};
vectorAppend(vb, tok);
ret vb;
@@ -528,15 +528,15 @@ vbt *asplitB(vbt *vb, const bt b, const bt delim) {
/**
* split b in vb vector
*/
-vbt *asplitCharB(vbt *vb, const bt b, char *delim) {
- bt d = ccharB(delim);
+vbtt *asplitCharB(vbtt *vb, const btt b, char *delim) {
+ btt d = ccharB(delim);
ret asplitB(vb, b, d);
}
/**
* split b in vb vector
*/
-vbt *asplitDPB(vbt *vb, const bt b, const bt *delim) {
+vbtt *asplitDPB(vbtt *vb, const btt b, const btt *delim) {
if (!delim) ret null;
ret asplitB(vb, b, *delim);
}
@@ -544,7 +544,7 @@ vbt *asplitDPB(vbt *vb, const bt b, const bt *delim) {
/**
* split b in vb vector
*/
-vbt *asplitPB(vbt *vb, const bt *b, const bt delim) {
+vbtt *asplitPB(vbtt *vb, const btt *b, const btt delim) {
if (!b) ret null;
ret asplitB(vb, *b, delim);
}
@@ -552,7 +552,7 @@ vbt *asplitPB(vbt *vb, const bt *b, const bt delim) {
/**
* split b in vb vector
*/
-vbt *asplitPCharB(vbt *vb, const bt *b, char *delim) {
+vbtt *asplitPCharB(vbtt *vb, const btt *b, char *delim) {
if (!b) ret null;
ret asplitCharB(vb, *b, delim);
}
@@ -560,17 +560,17 @@ vbt *asplitPCharB(vbt *vb, const bt *b, char *delim) {
/**
* split b in vb vector
*/
-vbt *asplitPDPB(vbt *vb, const bt *b, const bt *delim) {
+vbtt *asplitPDPB(vbtt *vb, const btt *b, const btt *delim) {
if (!b or !delim) ret null;
ret asplitB(vb, *b, *delim);
}
/**
- * return vbt vector with tokens from b
+ * return vbtt vector with tokens from b
* this function has good performance for small element counts
*/
-vbt splitB(const bt b, const bt delim) {
- vbt r;
+vbtt splitB(const btt b, const btt delim) {
+ vbtt r;
if (!b.b or !delim.b) ret emptyvbt;
vectorInitCount(&r, 5);
@@ -581,17 +581,17 @@ vbt splitB(const bt b, const bt delim) {
}
/**
- * return vbt vector with tokens from b
+ * return vbtt vector with tokens from b
* this function has good performance for small element counts
*/
-vbt splitCharB(const bt b, char *delim) {
- vbt r;
+vbtt splitCharB(const btt b, char *delim) {
+ vbtt r;
if (!b.b or !delim) ret emptyvbt;
vectorInitCount(&r, 5);
- bt d = ccharB(delim);
+ btt d = ccharB(delim);
asplitB(&r, b, d);
ret r;
@@ -600,7 +600,7 @@ vbt splitCharB(const bt b, char *delim) {
/**
* split b in vb vector
*/
-vbt splitDPB(const bt b, const bt *delim) {
+vbtt splitDPB(const btt b, const btt *delim) {
if (!delim) ret emptyvbt;
ret splitB(b, *delim);
}
@@ -608,16 +608,16 @@ vbt splitDPB(const bt b, const bt *delim) {
/**
* split b in vb vector
*/
-vbt splitPB(const bt *b, const bt delim) {
+vbtt splitPB(const btt *b, const btt delim) {
if (!b) ret emptyvbt;
ret splitB(*b, delim);
}
/**
- * return vbt vector with tokens from b
+ * return vbtt vector with tokens from b
* this function has good performance for small element counts
*/
-vbt splitPCharB(const bt *b, char *delim) {
+vbtt splitPCharB(const btt *b, char *delim) {
if (!b) ret emptyvbt;
ret splitCharB(*b, delim);
}
@@ -625,17 +625,17 @@ vbt splitPCharB(const bt *b, char *delim) {
/**
* split b in vb vector
*/
-vbt splitPDPB(const bt *b, const bt *delim) {
+vbtt splitPDPB(const btt *b, const btt *delim) {
if (!b or !delim) ret emptyvbt;
ret splitB(*b, *delim);
}
/**
- * return dbt vector with tokens from b
+ * return dbtt vector with tokens from b
* this function has good performance for large element counts
*/
-dbt dsplitB(const bt b, const bt delim) {
- dbt r;
+dbtt dsplitB(const btt b, const btt delim) {
+ dbtt r;
if (!b.b or !delim.b) ret emptydbt;
@@ -656,7 +656,7 @@ dbt dsplitB(const bt b, const bt delim) {
if (!ptr)
break;
nextTokenStart = ptr + 1;
- bt tok = {.b = working, .len = ptr-working, .alloc = 0};
+ btt tok = {.b = working, .len = ptr-working, .alloc = 0};
dVectorAppend(&r, tok);
i += tok.len + delim.len;
working = b.b + i;
@@ -668,70 +668,70 @@ dbt dsplitB(const bt b, const bt delim) {
if (!ptr)
break;
nextTokenStart = ptr + delim.len;
- bt tok = {.b = working, .len = ptr-working, .alloc = 0};
+ btt tok = {.b = working, .len = ptr-working, .alloc = 0};
dVectorAppend(&r, tok);
i += tok.len + delim.len;
working = b.b + i;
}
}
- bt tok = {.b = nextTokenStart, .len = (b.b+b.len)-nextTokenStart, .alloc = 0};
+ btt tok = {.b = nextTokenStart, .len = (b.b+b.len)-nextTokenStart, .alloc = 0};
dVectorAppend(&r, tok);
ret r;
}
/**
- * return dbt vector with tokens from b
+ * return dbtt vector with tokens from b
* this function has good performance for large element counts
*/
-dbt dsplitCharB(const bt b, char *delim) {
- bt d = ccharB(delim);
+dbtt dsplitCharB(const btt b, char *delim) {
+ btt d = ccharB(delim);
ret dsplitB(b, d);
}
/**
- * return dbt vector with tokens from b
+ * return dbtt vector with tokens from b
* this function has good performance for large element counts
*/
-dbt dsplitDPB(const bt b, const bt *delim) {
+dbtt dsplitDPB(const btt b, const btt *delim) {
if (!delim) ret emptydbt;
ret dsplitB(b, *delim);
}
/**
- * return dbt vector with tokens from b
+ * return dbtt vector with tokens from b
* this function has good performance for large element counts
*/
-dbt dsplitPB(const bt *b, const bt delim) {
+dbtt dsplitPB(const btt *b, const btt delim) {
if (!b) ret emptydbt;
ret dsplitB(*b, delim);
}
/**
- * return dbt vector with tokens from b
+ * return dbtt vector with tokens from b
* this function has good performance for large element counts
*/
-dbt dsplitPCharB(const bt *b, char *delim) {
+dbtt dsplitPCharB(const btt *b, char *delim) {
if (!b) ret emptydbt;
ret dsplitCharB(*b, delim);
}
/**
- * return dbt vector with tokens from b
+ * return dbtt vector with tokens from b
* this function has good performance for large element counts
*/
-dbt dsplitPDPB(const bt *b, const bt *delim) {
+dbtt dsplitPDPB(const btt *b, const btt *delim) {
if (!b or !delim) ret emptydbt;
ret dsplitB(*b, *delim);
}
/**
* slice String
- * return a bt object which is the string between start and end
+ * return a btt object which is the string between start and end
* negative indexes are allowed
*/
-bt sliceB(const bt b, int64_t start, int64_t end) {
- bt r = {0};
+btt sliceB(const btt b, int64_t start, int64_t end) {
+ btt r = {0};
if (!b.b) ret emptybt;
#define checkRange(B, rval)\
@@ -766,10 +766,10 @@ bt sliceB(const bt b, int64_t start, int64_t end) {
/**
* slice String
- * update the b bt object and keep only the string between start and end
+ * update the b btt object and keep only the string between start and end
* negative indexes are allowed
*/
-bt *bSliceB(bt *b, int64_t start, int64_t end) {
+btt *bSliceB(btt *b, int64_t start, int64_t end) {
if (!b) ret null;
checkRange(*b, null);
@@ -789,19 +789,19 @@ bt *bSliceB(bt *b, int64_t start, int64_t end) {
/**
* slice String
- * return a bt object which is the string between start and end
+ * return a btt object which is the string between start and end
* negative indexes are allowed
*/
-bt slicePB(const bt *b, int64_t start, int64_t end) {
+btt slicePB(const btt *b, int64_t start, int64_t end) {
if (!b) ret emptybt;
ret sliceB(*b, start, end);
}
/**
- * return a bt object without the leading and trailing spaces
+ * return a btt object without the leading and trailing spaces
*/
-bt trimB(const bt b) {
- bt r = {0};
+btt trimB(const btt b) {
+ btt r = {0};
if (!b.b) ret emptybt;
r.b = b.b;
@@ -830,13 +830,13 @@ bt trimB(const bt b) {
}
/**
- * update b bt object and remove the leading and trailing spaces
+ * update b btt object and remove the leading and trailing spaces
*/
// memmove data
-bt *bTrimB(bt *b) {
+btt *bTrimB(btt *b) {
if (!b or !b->b) ret null;
- bt t = trimB(*b);
+ btt t = trimB(*b);
if (t.b != b->b)
memmove(b->b, t.b, t.len);
@@ -846,25 +846,25 @@ bt *bTrimB(bt *b) {
}
/**
- * return a bt object without the leading and trailing spaces
+ * return a btt object without the leading and trailing spaces
*/
-bt trimPB(const bt *b) {
+btt trimPB(const btt *b) {
if (!b) emptybt;
ret trimB(*b);
}
-void printB(const bt b) {
+void printB(const btt b) {
write(STDOUT_FILENO, b.b, b.len);
}
-void printDebugB(const bt b) {
+void printDebugB(const btt b) {
write(STDOUT_FILENO, "\"", 1);
printB(b);
write(STDOUT_FILENO, "\"", 1);
put;
}
-void printDebugInfoB(const bt b) {
+void printDebugInfoB(const btt b) {
logD("b: %p, len: %"PRIu32", alloc: %"PRIu32, b.b, b.len, b.alloc);
printDebugB(b);
}
diff --git a/src/libsheepyBt.h b/src/libsheepyBt.h
@@ -1,11 +1,11 @@
/*
- * bt is a dynamic Byte buffer Type (Bytes Type)
+ * btt is a dynamic Byte buffer Type (Bytes Type)
*
* Status: under development, not tested, the comments don't match the implementation
*
- * # How bt works
+ * # How btt works
*
- * When a bt object represents a string, it doesn't need to be NUL terminated,
+ * When a btt object represents a string, it doesn't need to be NUL terminated,
* this allow spliting string more efficiently.
*
* - simple to use
@@ -14,64 +14,64 @@
* - works with memcheck
*
*
- * # Advantages and disadvantages of bt
+ * # Advantages and disadvantages of btt
*
- * bt is implemented using a structure defining the byte buffer like this:
+ * btt is implemented using a structure defining the byte buffer like this:
* ```
* struct {
* u8 *b;
* u32 len;
* u32 alloc;
- * } bt;
+ * } btt;
* ```
- * The bt structure is managed by the *B functions.
+ * The btt structure is managed by the *B functions.
*
- * - Disadvantage 1: bt doesn't work with standard C string functions
+ * - Disadvantage 1: btt doesn't work with standard C string functions
*
- * - Advantage 1: Giving the address of a bt to B functions, updates the bt in place:
+ * - Advantage 1: Giving the address of a btt to B functions, updates the btt in place:
* ```
* pushBG(&b, s);
* ```
*
* - Advantage 2: trimming and slicing buffers don't need memory allocations and spliting uses less memory allocations
*
- * - Advantage 3: the index for accessing the bytes in bt is range check in the getB, setB functions and it works even the buffer in bt is reallocated
+ * - Advantage 3: the index for accessing the bytes in btt is range check in the getB, setB functions and it works even the buffer in btt is reallocated
*
*
- * # bt basics
+ * # btt basics
*
- * Here is how to declare a bt, assign a string (RO) and print it:
+ * Here is how to declare a btt, assign a string (RO) and print it:
*
* ```
- * bt mystring = ccharB("Hello World!");
+ * btt mystring = ccharB("Hello World!");
* printB(mystring);
*
* output> Hello World!
* ```
*
- * The above small program shows a few important things about bt:
- * - bt are stack allocated (or heap allocated)
- * - printB prints the bt content
+ * The above small program shows a few important things about btt:
+ * - btt are stack allocated (or heap allocated)
+ * - printB prints the btt content
* - there is no memory allocations so there is no free.
*
*
- * # Creating bt strings
+ * # Creating btt strings
*
* ```
- * bt mystring = ccharB("Hello World!");
- * bt mystring2 = charB(strdup("Hello World!"), true);
- * bt mybuf = voidB("Binary", sizeof("Binary"), false);
+ * btt mystring = ccharB("Hello World!");
+ * btt mystring2 = charB(strdup("Hello World!"), true);
+ * btt mybuf = voidB("Binary", sizeof("Binary"), false);
* createCharB(mystring3, "bytes", false);
* // from another string:
- * bt mirror = mystring;
- * bt empty = {0};
+ * btt mirror = mystring;
+ * btt empty = {0};
* // preallocate buf
- * bt pre = newB(allocateSize);
- * // allocate bt struct and buf
- * bt *heap = allocNewB(allocateSize);
+ * btt pre = newB(allocateSize);
+ * // allocate btt struct and buf
+ * btt *heap = allocNewB(allocateSize);
*
* // allocate and set string
- * bt *new = allocB("STR", false);
+ * btt *new = allocB("STR", false);
* finishB(new);
* ```
*
@@ -84,9 +84,9 @@
*
* # Destroying strings
*
- * - freeB frees the buffer pointed by .b and can be called with non allocated bt objects (it does nothing)
- * - terminateB frees the buffer if allocated and the bt struct
- * - finishB frees the bt struct only (doesn't touch the .b buffer)
+ * - freeB frees the buffer pointed by .b and can be called with non allocated btt objects (it does nothing)
+ * - terminateB frees the buffer if allocated and the btt struct
+ * - finishB frees the btt struct only (doesn't touch the .b buffer)
*
*
* # Concatenating strings
@@ -107,22 +107,22 @@
* # Trimming and slicing
*
* ```
- * bt T = ccharB(" trim ");
- * bt r = trimB(T);
- * bt s = sliceB(T, 2, 6);
+ * btt T = ccharB(" trim ");
+ * btt r = trimB(T);
+ * btt s = sliceB(T, 2, 6);
* ```
*
*
* # String copying
*
* ```
- * // copy bt
- * bt mystringCopy = copyB(mystring);
+ * // copy btt
+ * btt mystringCopy = copyB(mystring);
* // the buffer in mystringCopy is heap allocated
* freeB(mystringCopy);
*
- * // duplicate bt
- * bt *dup = dupB(mystring);
+ * // duplicate btt
+ * btt *dup = dupB(mystring);
* // dup and the buffer in dup are heap allocated
* terminateB(dup);
* ```
@@ -130,8 +130,8 @@
* # Splitting strings
*
* ```
- * bt ss = ccharB("Hello World!");
- * vbt lsspl = splitB(ss, " ");
+ * btt ss = ccharB("Hello World!");
+ * vbtt lsspl = splitB(ss, " ");
* puts("");
* vectorForEach(&ll, e) {
* printB(*e);
@@ -145,7 +145,7 @@
*
* When alloc is 0 and len > 0, the buffer has not been allocated
*
- * createCharB declares a bt object with the given string, there is no allocation
+ * createCharB declares a btt object with the given string, there is no allocation
*
* Appending strings:
* s is updated, b or i are same
@@ -154,14 +154,14 @@
*
* New string:
* 1 malloc (better cache locality):
- * bt s2 = pushB(s, "qweqwe");
- * bt s3 = pushManyB(s, "qweqwe", "wer");
+ * btt s2 = pushB(s, "qweqwe");
+ * btt s3 = pushManyB(s, "qweqwe", "wer");
*
* //2 mallocs:
- * //bt *s4 = appendB(s, "qweqwe");
- * //bt *s5 = appendManyB(s, "qweqwe", "wer");
+ * //btt *s4 = appendB(s, "qweqwe");
+ * //btt *s5 = appendManyB(s, "qweqwe", "wer");
*
- * bt s6 = catB("1","2");
+ * btt s6 = catB("1","2");
*
* pushB(&s, s2);
*
@@ -172,13 +172,13 @@
* Spliting string doesn't require any buffer copying
* createCharB(h, "Hello World!", 0);
*
- * bt h2 = {0};
+ * btt h2 = {0};
* h2.b = h.b+6;
* h2.len = 5;
*
* Example:
- * Empty bt:
- * bt s = {0};
+ * Empty btt:
+ * btt s = {0};
* Assign C string:
* s = charB("a string", no);
* s.b = "asdasd";
@@ -189,116 +189,116 @@
#include "libsheepy.h"
-// bt bytes type
+// btt bytes type
// point to a byte buffer at .b of length .len
// .alloc is the allocated size of the buffer
typ struct {
u8 *b;
u32 len;
u32 alloc;
-} bt;
+} btt;
typ struct {
u8 *b;
u64 len;
u64 alloc;
-} b64t;
-// TODO functions supporting b64t
+} bt64t;
+// TODO functions supporting bt64t
-// vector of bt elements
+// vector of btt elements
// This data structure has good performance for small element counts
typ struct {
u32 count;
u32 maxCount;
- bt *array;
-} vbt;
+ btt *array;
+} vbtt;
-// dynamic segmented vector of bt elements
+// dynamic segmented vector of btt elements
// This data structure has good performance for large element counts
typ struct {
u32 count;
u32 maxCount;
void** buffers;
- bt element;
-} dbt;
+ btt element;
+} dbtt;
// object returned by some functions
-#define emptybt ((bt){0})
-#define emptyvbt ((vbt){0})
-#define emptydbt ((dbt){0})
+#define emptybt ((btt){0})
+#define emptyvbt ((vbtt){0})
+#define emptydbt ((dbtt){0})
-// assign a u8 a[count] array to bt object
+// assign a u8 a[count] array to btt object
// Example:
// u8 s[10] = {0};
-// bt b;
+// btt b;
// arrayB(b, s);
#define arrayB(name, a)\
(name).b = a; (name).len = 0; (name).alloc = ARRAY_SIZE(a)
-// declare name vbt object and assign the a array defined as bt a[maxCnt] with cnt element already initialized
+// declare name vbtt object and assign the a array defined as btt a[maxCnt] with cnt element already initialized
#define vectorB(name, a, cnt, maxCnt)\
- vbt name; name.count = cnt; name.maxCount = maxCnt; name.array = a
+ vbtt name; name.count = cnt; name.maxCount = maxCnt; name.array = a
-// declare name vbt object, declare the a array of count bt elements and assign it to name the vbt object
+// declare name vbtt object, declare the a array of count btt elements and assign it to name the vbtt object
#define listB(name, a, maxCnt)\
- bt a[maxCnt] = {0}; vbt name; name.count = 0; name.maxCount = maxCnt; name.array = a
+ btt a[maxCnt] = {0}; vbtt name; name.count = 0; name.maxCount = maxCnt; name.array = a
-// declare name vbt object and assign the empty a array defined as bt a[maxCnt]
+// declare name vbtt object and assign the empty a array defined as btt a[maxCnt]
#define listAB(name, a)\
- vbt name; name.count = 0; name.maxCount = ARRAY_SIZE(a); name.array = a
+ vbtt name; name.count = 0; name.maxCount = ARRAY_SIZE(a); name.array = a
-// initialize a bt object with a heap allocated string
-#define charB(string) (bt){.b = string, .len = strlen(string), .alloc = strlen(string)}
-// initialize a bt object with a string that can't be reallocated
-#define ccharB(string) (bt){.b = string, .len = strlen(string), .alloc = 0 }
-// initialize a bt object with a heap allocated binary buffer
-#define voidB( buf, length, allocated) (bt){.b = buf, .len = length, .alloc = (allocated) ? length : 0 }
+// initialize a btt object with a heap allocated string
+#define charB(string) (btt){.b = string, .len = strlen(string), .alloc = strlen(string)}
+// initialize a btt object with a string that can't be reallocated
+#define ccharB(string) (btt){.b = string, .len = strlen(string), .alloc = 0 }
+// initialize a btt object with a heap allocated binary buffer
+#define voidB( buf, length, allocated) (btt){.b = buf, .len = length, .alloc = (allocated) ? length : 0 }
/**
- * declare pointer name with type bt and terminate name when it is out of scope
+ * declare pointer name with type btt and terminate name when it is out of scope
*/
-#define cleanBP(name) bt *name CLEANUP(cleanUpTerminateB)
+#define cleanBP(name) btt *name CLEANUP(cleanUpTerminateB)
/**
- * allocate bt (pointer) and clean up when it is out of scope
+ * allocate btt (pointer) and clean up when it is out of scope
*/
#define cleanAllocateB(obj) ;cleanBP(obj); obj = allocNewB(8)
/**
- * declare local object name with type bt and free name when it is out of scope
+ * declare local object name with type btt and free name when it is out of scope
*/
-#define cleanB(name) bt name CLEANUP(cleanUpFreeLocalB)
+#define cleanB(name) btt name CLEANUP(cleanUpFreeLocalB)
/**
- * declare pointer name with type bt and free name when it is out of scope
+ * declare pointer name with type btt and free name when it is out of scope
*/
-#define cleanFreeBP(name) bt *name CLEANUP(cleanUpFreeB)
+#define cleanFreeBP(name) btt *name CLEANUP(cleanUpFreeB)
/**
- * declare pointer name with type bt and finish name when it is out of scope
+ * declare pointer name with type btt and finish name when it is out of scope
*/
-#define cleanFinishBP(name) bt *name CLEANUP(cleanUpFinishB)
+#define cleanFinishBP(name) btt *name CLEANUP(cleanUpFinishB)
-// create name bt object and initialize it with a string
+// create name btt object and initialize it with a string
// string is char* and is evaluated one time, allocated true/false
-#define createCharB(name, string, allocated) bt name;u8 *UNIQVAR(s) = (u8*)string;name.b = UNIQVAR(s); name.len = strlen(UNIQVAR(s)); name.alloc = (allocated) ? name.len : 0
+#define createCharB(name, string, allocated) btt name;u8 *UNIQVAR(s) = (u8*)string;name.b = UNIQVAR(s); name.len = strlen(UNIQVAR(s)); name.alloc = (allocated) ? name.len : 0
-// create name bt object and initialize it with a binary buffer
-#define createB(name, buf, length, allocated) bt name;name.b = buf; name.len = len; name.alloc = (allocated) ? name.length : 0
+// create name btt object and initialize it with a binary buffer
+#define createB(name, buf, length, allocated) btt name;name.b = buf; name.len = len; name.alloc = (allocated) ? name.length : 0
#define createAllocateCharB(name, string, allocated)\
- bt *name = malloc(sizeof(*name)); u8 *UNIQVAR(s) = (u8*)string;name->b = UNIQVAR(s); name->len = strlen(UNIQVAR(s)); name->alloc = (allocated) ? name->len : 0
+ btt *name = malloc(sizeof(*name)); u8 *UNIQVAR(s) = (u8*)string;name->b = UNIQVAR(s); name->len = strlen(UNIQVAR(s)); name->alloc = (allocated) ? name->len : 0
#define createAllocateB(name, buf, length, allocated)\
- bt *name = malloc(sizeof(*name));name->b = buf; name->len = length; name->alloc = (allocated) ? name->len : 0
+ btt *name = malloc(sizeof(*name));name->b = buf; name->len = length; name->alloc = (allocated) ? name->len : 0
-// create clean name bt object and initialize it with a string
+// create clean name btt object and initialize it with a string
// string is char* and is evaluated one time
#define cleanCharB(name, string) cleanB(name);u8 *UNIQVAR(s) = (u8*)string;name.b = UNIQVAR(s); name.len = strlen(UNIQVAR(s)); name.alloc = name.len
-// create clean name bt object and initialize it with a binary buffer
+// create clean name btt object and initialize it with a binary buffer
#define ccleanB(name, buf, length) cleanB(name);name.b = buf; name.len = len; name.alloc = name.length
#define cleanAllocateCharB(name, string, allocated)\
@@ -308,71 +308,71 @@ typ struct {
cleanBP(name) = malloc(sizeof(*name));name->b = buf; name->len = length; name->alloc = (allocated) ? name->len : 0
-// return a bt object with s as buffer
-bt initCharB(char *s);
+// return a btt object with s as buffer
+btt initCharB(char *s);
-// return a bt object with s as buffer
+// return a btt object with s as buffer
// the buffer is not going to be reallocated
-bt initCCharB(char *s);
+btt initCCharB(char *s);
-// return a bt object with buf as buffer
-bt initB(void *buf, u32 len, bool allocated);
+// return a btt object with buf as buffer
+btt initB(void *buf, u32 len, bool allocated);
-// return a bt object with a heap allocated buffer of size allocateSize
-bt newB(u32 allocateSize);
+// return a btt object with a heap allocated buffer of size allocateSize
+btt newB(u32 allocateSize);
-// return a heap allocated bt object with a heap allocated buffer of size allocateSize
-bt *allocNewB(u32 allocateSize);
+// return a heap allocated btt object with a heap allocated buffer of size allocateSize
+btt *allocNewB(u32 allocateSize);
-// return a heap allocated bt object with buf assigned to it
-bt *allocCharB(char *buf);
+// return a heap allocated btt object with buf assigned to it
+btt *allocCharB(char *buf);
-// return a heap allocated bt object with buf assigned to it
-bt *allocCCharB(char *buf);
+// return a heap allocated btt object with buf assigned to it
+btt *allocCCharB(char *buf);
-bt *allocBufB(void *buf, u32 len, bool allocated);
+btt *allocBufB(void *buf, u32 len, bool allocated);
-// return a heap allocated bt object with b assigned to it
-bt *allocB(const bt b);
+// return a heap allocated btt object with b assigned to it
+btt *allocB(const btt b);
/**
- * return a heap allocated bt object with *b assigned to it
+ * return a heap allocated btt object with *b assigned to it
*/
-bt *allocPB(const bt *b);
+btt *allocPB(const btt *b);
#define allocBG(b) _Generic(b,\
- bt: allocB,\
- const bt: allocB,\
- bt*: allocPB,\
- const bt*: allocPB,\
+ btt: allocB,\
+ const btt: allocB,\
+ btt*: allocPB,\
+ const btt*: allocPB,\
char*: allocCharB,\
const char*: allocCCharB\
)(b)
-// return a bt object with a heap allocated copy of b.b
-bt copyB(const bt b);
+// return a btt object with a heap allocated copy of b.b
+btt copyB(const btt b);
-bt copyPB(bt *b);
+btt copyPB(btt *b);
#define copyBG(b) _Generic(b,\
- bt: copyB,\
- bt*: copyPB\
+ btt: copyB,\
+ btt*: copyPB\
)(b)
-// return a heap allocated bt object with a heap allocated copy of b.b
-bt *dupB(const bt b);
+// return a heap allocated btt object with a heap allocated copy of b.b
+btt *dupB(const btt b);
-bt *dupPB(bt *b);
+btt *dupPB(btt *b);
#define dupBG(b) _Generic(b,\
- bt: dupB,\
- bt*: dupPB\
+ btt: dupB,\
+ btt*: dupPB\
)(b)
// TODO:
// ..lenB
// ..freeB
-// ..terminateB(bt *b)
+// ..terminateB(btt *b)
// ..pushBB
// ..pushManyBB
// // NO - growzero: memset 0 to new part
@@ -394,12 +394,12 @@ bt *dupPB(bt *b);
// use b.b instead
-// u8* bufferB(bt b) {
+// u8* bufferB(btt b) {
// ret b.b;
// }
// use b.len instead
-// size_t lenB(bt b) {
+// size_t lenB(btt b) {
// ret b.len;
// }
@@ -407,133 +407,133 @@ bt *dupPB(bt *b);
* free heap allocated .b
* nothing if not heap allocated
*/
-void freeB(bt b);
+void freeB(btt b);
/**
* free heap allocated .b and assign null to .b
* nothing if not heap allocated
*/
-void freenB(bt *b);
+void freenB(btt *b);
/**
- * free the heap allocated bt object (container only, not .b)
+ * free the heap allocated btt object (container only, not .b)
*/
-void finishB(bt **b);
+void finishB(btt **b);
/**
- * free the heap allocated bt object and free .b
+ * free the heap allocated btt object and free .b
*/
-void terminateB(bt **b);
+void terminateB(btt **b);
// terminate val when it is out of scope
-void cleanUpTerminateB(bt **val);
+void cleanUpTerminateB(btt **val);
// free local val when it is out of scope
-void cleanUpFreeLocalB(bt *val);
+void cleanUpFreeLocalB(btt *val);
// free val when it is out of scope
-void cleanUpFreeB(bt **val);
+void cleanUpFreeB(btt **val);
// finish val when it is out of scope
-void cleanUpFinishB(bt **val);
+void cleanUpFinishB(btt **val);
-// return a bt object with s appended to b
+// return a btt object with s appended to b
// b doesn't need to have a heap allocated buffer
#define appendB pushB
-bt pushB(const bt b, const char *s);
+btt pushB(const btt b, const char *s);
// TODO pushManyB
// update b and append s
// b.b is reallocated
#define bAppendB bPushB
-bt *bPushB(bt *b, const char *s);
+btt *bPushB(btt *b, const char *s);
// TODO bPushManyB
-// return a bt object with s bt object appended to b
+// return a btt object with s btt object appended to b
// b doesn't need to have a heap allocated buffer
#define appendBB pushBB
-bt pushBB(const bt b, const bt s);
+btt pushBB(const btt b, const btt s);
// TODO bPushManyBB
-// update b and append s bt object
+// update b and append s btt object
// b.b is reallocated
#define bAppendBB bPushBB
-bt *bPushBB(bt *b, const bt s);
+btt *bPushBB(btt *b, const btt s);
// TODO bPushManyBB
-// return a bt object with *s bt object appended to b
+// return a btt object with *s btt object appended to b
// b doesn't need to have a heap allocated buffer
#define appendBPB pushBPB
-bt pushBPB(const bt b, const bt *s);
+btt pushBPB(const btt b, const btt *s);
// TODO bPushManyBPB
-// update b and append *s bt object
+// update b and append *s btt object
// b.b is reallocated
#define bAppendBPB bPushBPB
-bt *bPushBPB(bt *b, const bt *s);
+btt *bPushBPB(btt *b, const btt *s);
// TODO bPushManyBB
-// return a bt object with s appended to *b
+// return a btt object with s appended to *b
// b doesn't need to have a heap allocated buffer
#define appendPB pushPB
-bt pushPB(const bt *b, const char *s);
+btt pushPB(const btt *b, const char *s);
// TODO pushManyPB...
-// return a bt object with s bt object appended to *b
+// return a btt object with s btt object appended to *b
// b doesn't need to have a heap allocated buffer
#define appendPBB pushPBB
-bt pushPBB(const bt *b, const bt s);
+btt pushPBB(const btt *b, const btt s);
// TODO pushManyPBB...
-// return a bt object with *s bt object appended to *b
+// return a btt object with *s btt object appended to *b
// b doesn't need to have a heap allocated buffer
#define appendPBPB pushPBPB
-bt pushPBPB(const bt *b, const bt *s);
+btt pushPBPB(const btt *b, const btt *s);
// TODO pushManyPBPB...
#define appendBG pushBG
#define pushBG(b, s) _Generic( b,\
- bt: _Generic(s,\
+ btt: _Generic(s,\
const char *: pushB,\
char *: pushB,\
- const bt: pushBB,\
- bt: pushBB,\
- const bt*: pushBPB,\
- bt*: pushBPB\
+ const btt: pushBB,\
+ btt: pushBB,\
+ const btt*: pushBPB,\
+ btt*: pushBPB\
),\
- bt*: _Generic(s,\
+ btt*: _Generic(s,\
const char *: bPushB,\
char *: bPushB,\
- const bt: bPushBB,\
- bt: bPushBB,\
- const bt*: bPushBPB,\
- bt*: bPushBPB\
+ const btt: bPushBB,\
+ btt: bPushBB,\
+ const btt*: bPushBPB,\
+ btt*: bPushBPB\
),\
- const bt*: _Generic(s,\
+ const btt*: _Generic(s,\
const char *: pushPB,\
char *: pushPB,\
- const bt: pushPBB,\
- bt: pushPBB,\
- const bt*: pushPBPB,\
- bt*: pushPBPB\
+ const btt: pushPBB,\
+ btt: pushPBB,\
+ const btt*: pushPBPB,\
+ btt*: pushPBPB\
)\
)(b, s)
-// bt catBF(const char *paramType, ...) MUST_CHECK;
+// btt catBF(const char *paramType, ...) MUST_CHECK;
#define catB(...) catBF("", __VA_ARGS__, NULL)
-// add allocates bt object
-// bt *addBF(const char *paramType, ...) MUST_CHECK;
+// add allocates btt object
+// btt *addBF(const char *paramType, ...) MUST_CHECK;
#define addB(...) catBF("", __VA_ARGS__, NULL)
-// %q to print bt
-// %Q to print bt*
+// %q to print btt
+// %Q to print btt*
// printB(char *fmt, ...)
// register %q and %Q
@@ -571,260 +571,260 @@ bt pushPBPB(const bt *b, const bt *s);
// split b in vb static vector
// the vector is not reallocated
-vbt *sasplitB(vbt *vb, const bt b, const bt delim);
+vbtt *sasplitB(vbtt *vb, const btt b, const btt delim);
// split b in vb static vector
// the vector is not reallocated
-vbt *sasplitCharB(vbt *vb, const bt b, char *delim);
+vbtt *sasplitCharB(vbtt *vb, const btt b, char *delim);
// split b in vb static vector
// the vector is not reallocated
-vbt *sasplitDPB(vbt *vb, const bt b, const bt *delim);
+vbtt *sasplitDPB(vbtt *vb, const btt b, const btt *delim);
// split b in vb static vector
// the vector is not reallocated
-vbt *sasplitPB(vbt *vb, const bt *b, const bt delim);
+vbtt *sasplitPB(vbtt *vb, const btt *b, const btt delim);
// split b in vb static vector
// the vector is not reallocated
-vbt *sasplitPCharB(vbt *vb, const bt *b, char *delim);
+vbtt *sasplitPCharB(vbtt *vb, const btt *b, char *delim);
// split b in vb static vector
// the vector is not reallocated
-vbt *sasplitPDPB(vbt *vb, const bt *b, const bt *delim);
+vbtt *sasplitPDPB(vbtt *vb, const btt *b, const btt *delim);
#define sasplitBG(vb, b, delim) _Generic(b,\
- bt: _Generic(delim,\
+ btt: _Generic(delim,\
char*: sasplitCharB,\
const char*: sasplitCharB,\
- bt: sasplitB,\
- const bt: sasplitB,\
- bt*: sasplitDPB,\
- const bt*: sasplitDPB),\
- const bt: _Generic(delim,\
+ btt: sasplitB,\
+ const btt: sasplitB,\
+ btt*: sasplitDPB,\
+ const btt*: sasplitDPB),\
+ const btt: _Generic(delim,\
char*: sasplitCharB,\
const char*: sasplitCharB,\
- bt: sasplitB,\
- const bt: sasplitB,\
- bt*: sasplitDPB,\
- const bt*: sasplitDPB),\
- bt*: _Generic(delim,\
+ btt: sasplitB,\
+ const btt: sasplitB,\
+ btt*: sasplitDPB,\
+ const btt*: sasplitDPB),\
+ btt*: _Generic(delim,\
char*: sasplitPCharB,\
const char*: sasplitPCharB,\
- bt: sasplitPB,\
- const bt: sasplitPB,\
- bt*: sasplitPDPB,\
- const bt*: sasplitPDPB),\
- const bt*: _Generic(delim,\
+ btt: sasplitPB,\
+ const btt: sasplitPB,\
+ btt*: sasplitPDPB,\
+ const btt*: sasplitPDPB),\
+ const btt*: _Generic(delim,\
char*: sasplitPCharB,\
const char*: sasplitPCharB,\
- bt: sasplitPB,\
- const bt: sasplitPB,\
- bt*: sasplitPDPB,\
- const bt*: sasplitPDPB)\
+ btt: sasplitPB,\
+ const btt: sasplitPB,\
+ btt*: sasplitPDPB,\
+ const btt*: sasplitPDPB)\
)(vb, b, delim)
// split b in vb vector
-vbt *asplitB(vbt *vb, const bt b, const bt delim);
+vbtt *asplitB(vbtt *vb, const btt b, const btt delim);
// split b in vb vector
-vbt *asplitCharB(vbt *vb, const bt b, char *delim);
+vbtt *asplitCharB(vbtt *vb, const btt b, char *delim);
// split b in vb vector
-vbt *asplitDPB(vbt *vb, const bt b, const bt *delim);
+vbtt *asplitDPB(vbtt *vb, const btt b, const btt *delim);
// split b in vb vector
-vbt *asplitPB(vbt *vb, const bt *b, const bt delim);
+vbtt *asplitPB(vbtt *vb, const btt *b, const btt delim);
// split b in vb vector
-vbt *asplitPCharB(vbt *vb, const bt *b, char *delim);
+vbtt *asplitPCharB(vbtt *vb, const btt *b, char *delim);
// split b in vb vector
-vbt *asplitPDPB(vbt *vb, const bt *b, const bt *delim);
+vbtt *asplitPDPB(vbtt *vb, const btt *b, const btt *delim);
#define asplitBG(vb, b, delim) _Generic(b,\
- bt: _Generic(delim,\
+ btt: _Generic(delim,\
char*: asplitCharB,\
const char*: asplitCharB,\
- bt: asplitB,\
- const bt: asplitB,\
- bt*: asplitDPB,\
- const bt*: asplitDPB),\
- const bt: _Generic(delim,\
+ btt: asplitB,\
+ const btt: asplitB,\
+ btt*: asplitDPB,\
+ const btt*: asplitDPB),\
+ const btt: _Generic(delim,\
char*: asplitCharB,\
const char*: asplitCharB,\
- bt: asplitB,\
- const bt: asplitB,\
- bt*: asplitDPB,\
- const bt*: asplitDPB),\
- bt*: _Generic(delim,\
+ btt: asplitB,\
+ const btt: asplitB,\
+ btt*: asplitDPB,\
+ const btt*: asplitDPB),\
+ btt*: _Generic(delim,\
char*: asplitPCharB,\
const char*: asplitPCharB,\
- bt: asplitPB,\
- const bt: asplitPB,\
- bt*: asplitPDPB,\
- const bt*: asplitPDPB),\
- const bt*: _Generic(delim,\
+ btt: asplitPB,\
+ const btt: asplitPB,\
+ btt*: asplitPDPB,\
+ const btt*: asplitPDPB),\
+ const btt*: _Generic(delim,\
char*: asplitPCharB,\
const char*: asplitPCharB,\
- bt: asplitPB,\
- const bt: asplitPB,\
- bt*: asplitPDPB,\
- const bt*: asplitPDPB)\
+ btt: asplitPB,\
+ const btt: asplitPB,\
+ btt*: asplitPDPB,\
+ const btt*: asplitPDPB)\
)(vb, b, delim)
-// return vbt vector with tokens from b
+// return vbtt vector with tokens from b
// this function has good performance for small element counts
-vbt splitB(const bt b, const bt delim);
+vbtt splitB(const btt b, const btt delim);
-// return vbt vector with tokens from b
+// return vbtt vector with tokens from b
// this function has good performance for small element counts
-vbt splitCharB(const bt b, char *delim);
+vbtt splitCharB(const btt b, char *delim);
// split b in vb vector
-vbt splitDPB(const bt b, const bt *delim);
+vbtt splitDPB(const btt b, const btt *delim);
// split b in vb vector
-vbt splitPB(const bt *b, const bt delim);
+vbtt splitPB(const btt *b, const btt delim);
-// return vbt vector with tokens from b
+// return vbtt vector with tokens from b
// this function has good performance for small element counts
-vbt splitPCharB(const bt *b, char *delim);
+vbtt splitPCharB(const btt *b, char *delim);
// split b in vb vector
-vbt splitPDPB(const bt *b, const bt *delim);
+vbtt splitPDPB(const btt *b, const btt *delim);
#define splitBG(b, delim) _Generic(b,\
- bt: _Generic(delim,\
+ btt: _Generic(delim,\
char*: splitCharB,\
const char*: splitCharB,\
- bt: splitB,\
- const bt: splitB,\
- bt*: splitDPB,\
- const bt*: splitDPB),\
- const bt: _Generic(delim,\
+ btt: splitB,\
+ const btt: splitB,\
+ btt*: splitDPB,\
+ const btt*: splitDPB),\
+ const btt: _Generic(delim,\
char*: splitCharB,\
const char*: splitCharB,\
- bt: splitB,\
- const bt: splitB,\
- bt*: splitDPB,\
- const bt*: splitDPB),\
- bt*: _Generic(delim,\
+ btt: splitB,\
+ const btt: splitB,\
+ btt*: splitDPB,\
+ const btt*: splitDPB),\
+ btt*: _Generic(delim,\
char*: splitPCharB,\
const char*: splitPCharB,\
- bt: splitPB,\
- const bt: splitPB,\
- bt*: splitPDPB,\
- const bt*: splitPDPB),\
- const bt*: _Generic(delim,\
+ btt: splitPB,\
+ const btt: splitPB,\
+ btt*: splitPDPB,\
+ const btt*: splitPDPB),\
+ const btt*: _Generic(delim,\
char*: splitPCharB,\
const char*: splitPCharB,\
- bt: splitPB,\
- const bt: splitPB,\
- bt*: splitPDPB,\
- const bt*: splitPDPB)\
+ btt: splitPB,\
+ const btt: splitPB,\
+ btt*: splitPDPB,\
+ const btt*: splitPDPB)\
)(b, delim)
-// return dbt vector with tokens from b
+// return dbtt vector with tokens from b
// this function has good performance for large element counts
-dbt dsplitB(const bt b, const bt delim);
+dbtt dsplitB(const btt b, const btt delim);
-// return dbt vector with tokens from b
+// return dbtt vector with tokens from b
// this function has good performance for large element counts
-dbt dsplitCharB(const bt b, char *delim);
+dbtt dsplitCharB(const btt b, char *delim);
-// return dbt vector with tokens from b
+// return dbtt vector with tokens from b
// this function has good performance for large element counts
-dbt dsplitDPB(const bt b, const bt *delim);
+dbtt dsplitDPB(const btt b, const btt *delim);
-// return dbt vector with tokens from b
+// return dbtt vector with tokens from b
// this function has good performance for large element counts
-dbt dsplitPB(const bt *b, const bt delim);
+dbtt dsplitPB(const btt *b, const btt delim);
-// return dbt vector with tokens from b
+// return dbtt vector with tokens from b
// this function has good performance for large element counts
-dbt dsplitPCharB(const bt *b, char *delim);
+dbtt dsplitPCharB(const btt *b, char *delim);
-// return dbt vector with tokens from b
+// return dbtt vector with tokens from b
// this function has good performance for large element counts
-dbt dsplitPDPB(const bt *b, const bt *delim);
+dbtt dsplitPDPB(const btt *b, const btt *delim);
#define dsplitBG(b, delim) _Generic(b,\
- bt: _Generic(delim,\
+ btt: _Generic(delim,\
char*: dsplitCharB,\
const char*: dsplitCharB,\
- bt: dsplitB,\
- const bt: dsplitB,\
- bt*: dsplitDPB,\
- const bt*: dsplitDPB),\
- const bt: _Generic(delim,\
+ btt: dsplitB,\
+ const btt: dsplitB,\
+ btt*: dsplitDPB,\
+ const btt*: dsplitDPB),\
+ const btt: _Generic(delim,\
char*: dsplitCharB,\
const char*: dsplitCharB,\
- bt: dsplitB,\
- const bt: dsplitB,\
- bt*: dsplitDPB,\
- const bt*: dsplitDPB),\
- bt*: _Generic(delim,\
+ btt: dsplitB,\
+ const btt: dsplitB,\
+ btt*: dsplitDPB,\
+ const btt*: dsplitDPB),\
+ btt*: _Generic(delim,\
char*: dsplitPCharB,\
const char*: dsplitPCharB,\
- bt: dsplitPB,\
- const bt: dsplitPB,\
- bt*: dsplitPDPB,\
- const bt*: dsplitPDPB),\
- const bt*: _Generic(delim,\
+ btt: dsplitPB,\
+ const btt: dsplitPB,\
+ btt*: dsplitPDPB,\
+ const btt*: dsplitPDPB),\
+ const btt*: _Generic(delim,\
char*: dsplitPCharB,\
const char*: dsplitPCharB,\
- bt: dsplitPB,\
- const bt: dsplitPB,\
- bt*: dsplitPDPB,\
- const bt*: dsplitPDPB)\
+ btt: dsplitPB,\
+ const btt: dsplitPB,\
+ btt*: dsplitPDPB,\
+ const btt*: dsplitPDPB)\
)(b, delim)
// slice String
-// return a bt object which is the string between start and end
+// return a btt object which is the string between start and end
// negative indexes are allowed
-bt sliceB(const bt b, int64_t start, int64_t end);
+btt sliceB(const btt b, int64_t start, int64_t end);
// slice String
-// update the b bt object and keep only the string between start and end
+// update the b btt object and keep only the string between start and end
// negative indexes are allowed
-bt *bSliceB(bt *b, int64_t start, int64_t end);
+btt *bSliceB(btt *b, int64_t start, int64_t end);
// slice String
-// return a bt object which is the string between start and end
+// return a btt object which is the string between start and end
// negative indexes are allowed
-bt slicePB(const bt *b, int64_t start, int64_t end);
+btt slicePB(const btt *b, int64_t start, int64_t end);
#define sliceBG(b, start, end) _Generic(b,\
- bt: sliceB,\
- const bt: sliceB,\
- bt*: bSliceB,\
- const bt*: slicePB\
+ btt: sliceB,\
+ const btt: sliceB,\
+ btt*: bSliceB,\
+ const btt*: slicePB\
)(b, start, end);
-// return a bt object without the leading and trailing spaces
-bt trimB(const bt b);
+// return a btt object without the leading and trailing spaces
+btt trimB(const btt b);
-// update b bt object and remove the leading and trailing spaces
-bt *bTrimB(bt *b);
+// update b btt object and remove the leading and trailing spaces
+btt *bTrimB(btt *b);
-// return a bt object without the leading and trailing spaces
-bt trimPB(const bt *b);
+// return a btt object without the leading and trailing spaces
+btt trimPB(const btt *b);
#define trimBG(b) _Generic(b,\
- bt: trimB,\
- const bt: trimB,\
- bt*: bTrimB,\
- const bt*: trimPB\
+ btt: trimB,\
+ const btt: trimB,\
+ btt*: bTrimB,\
+ const btt*: trimPB\
)(b)
-void printB(const bt b);
+void printB(const btt b);
-void printDebugB(const bt b);
+void printDebugB(const btt b);
-void printDebugInfoB(const bt b);
+void printDebugInfoB(const btt b);
// vim: set expandtab ts=2 sw=2:
diff --git a/src/libsheepyObject.h b/src/libsheepyObject.h
@@ -158,10 +158,10 @@ static const bool checkObjectTypes = true;
const char *: allocSmallString, \
char **: allocArraySmallArray, \
const char **: allocCArraySmallArray, \
- bt: allocB, \
- const bt: allocB, \
- bt*: allocPB, \
- const bt*: allocPB \
+ btt: allocB, \
+ const btt: allocB, \
+ btt*: allocPB, \
+ const btt*: allocPB \
)(value)
@@ -333,10 +333,10 @@ void terminateManyOF(void *paramType, ...);
char***: "char***", \
void*: "void*", \
FILE*: "FILE*", \
- bt: "bt", \
- bt*: "bt*", \
- const bt: "const bt", \
- const bt*: "const bt*", \
+ btt: "btt", \
+ btt*: "btt*", \
+ const btt: "const btt", \
+ const btt*: "const btt*", \
default: NULL \
)
@@ -701,31 +701,31 @@ void finishManyOF(void *paramType, ...);
int: listPushCharS, \
default: listPushS \
), \
- bt: _Generic(value, \
+ btt: _Generic(value, \
const char *: pushB, \
char *: pushB, \
- const bt: pushBB, \
- bt: pushBB, \
- const bt*: pushBPB, \
- bt*: pushBPB, \
+ const btt: pushBB, \
+ btt: pushBB, \
+ const btt*: pushBPB, \
+ btt*: pushBPB, \
default: pushB \
), \
- bt*: _Generic(value, \
+ btt*: _Generic(value, \
const char *: bPushB, \
char *: bPushB, \
- const bt: bPushBB, \
- bt: bPushBB, \
- const bt*: bPushBPB, \
- bt*: bPushBPB, \
+ const btt: bPushBB, \
+ btt: bPushBB, \
+ const btt*: bPushBPB, \
+ btt*: bPushBPB, \
default: bPushB \
), \
- const bt*: _Generic(value, \
+ const btt*: _Generic(value, \
const char *: pushPB, \
char *: pushPB, \
- const bt: pushPBB, \
- bt: pushPBB, \
- const bt*: pushPBPB, \
- bt*: pushPBPB, \
+ const btt: pushPBB, \
+ btt: pushPBB, \
+ const btt*: pushPBPB, \
+ btt*: pushPBPB, \
default: pushPB) \
)(self, value)
@@ -923,6 +923,7 @@ void finishManyOF(void *paramType, ...);
smallContainert*: setAtSmallContainerSmallArrayG, \
undefinedt*: setAtUndefinedSmallArrayG, \
default: setAtVoidSmallArrayG), \
+ smallBytest*: setSmallBytesG,\
smallJsont*: _Generic(key, \
char *: _Generic((value), \
baset*: setSmallJsonG, \
@@ -3772,8 +3773,8 @@ void finishManyOF(void *paramType, ...);
const char *: dupS,\
char **: listDupS, \
const char **: listDupCG, \
- bt: dupB, \
- bt*: dupPB \
+ btt: dupB, \
+ btt*: dupPB \
)(self)
#define replaceO(self, olds, news, max) (self)->f->replace(self, olds, news, max)
@@ -5192,10 +5193,10 @@ void finishManyOF(void *paramType, ...);
smallDictt *: trimSmallDictG, \
smallJsont *: trimSmallJsonG, \
smallStringt *: trimSmallStringG, \
- bt: trimB, \
- const bt: trimB, \
- bt*: bTrimB, \
- const bt*: trimPB \
+ btt: trimB, \
+ const btt: trimB, \
+ btt*: bTrimB, \
+ const btt*: trimPB \
)(self)
#define lTrimO(self) (self)->f->lTrim(self)
@@ -5247,10 +5248,10 @@ void finishManyOF(void *paramType, ...);
smallArrayt *: sliceSmallArrayG, \
smallJsont *: sliceSmallJsonG, \
smallStringt *: sliceSmallStringG, \
- bt: sliceB, \
- const bt: sliceB, \
- bt*: bSliceB, \
- const bt*: slicePB \
+ btt: sliceB, \
+ const btt: sliceB, \
+ btt*: bSliceB, \
+ const btt*: slicePB \
)(self, start, end)
@@ -6679,37 +6680,37 @@ void finishManyOF(void *paramType, ...);
smallStringt *: splitSmallStringSmallStringG, \
default: splitSmallStringG \
), \
- bt: _Generic(delim, \
+ btt: _Generic(delim, \
char*: splitCharB, \
const char*: splitCharB, \
- bt: splitB, \
- const bt: splitB, \
- bt*: splitDPB, \
- const bt*: splitDPB, \
+ btt: splitB, \
+ const btt: splitB, \
+ btt*: splitDPB, \
+ const btt*: splitDPB, \
default: splitB), \
- const bt: _Generic(delim, \
+ const btt: _Generic(delim, \
char*: splitCharB, \
const char*: splitCharB, \
- bt: splitB, \
- const bt: splitB, \
- bt*: splitDPB, \
- const bt*: splitDPB, \
+ btt: splitB, \
+ const btt: splitB, \
+ btt*: splitDPB, \
+ const btt*: splitDPB, \
default: splitB), \
- bt*: _Generic(delim, \
+ btt*: _Generic(delim, \
char*: splitPCharB, \
const char*: splitPCharB, \
- bt: splitPB, \
- const bt: splitPB, \
- bt*: splitPDPB, \
- const bt*: splitPDPB, \
+ btt: splitPB, \
+ const btt: splitPB, \
+ btt*: splitPDPB, \
+ const btt*: splitPDPB, \
default: splitPB),\
- const bt*: _Generic(delim, \
+ const btt*: _Generic(delim, \
char*: splitPCharB, \
const char*: splitPCharB, \
- bt: splitPB, \
- const bt: splitPB, \
- bt*: splitPDPB, \
- const bt*: splitPDPB, \
+ btt: splitPB, \
+ const btt: splitPB, \
+ btt*: splitPDPB, \
+ const btt*: splitPDPB, \
default: splitPB)\
)(self, delim)
@@ -8297,9 +8298,6 @@ void finishManyOF(void *paramType, ...);
#define setCArraycO(self, key, array) (self)->f->setCArrayc(self, key, array)
#define setCArraycG setCArraycO
-#define setSmallBytesO(self, key, value) (self)->f->setSmallBytes(self, key, value)
-#define setSmallBytesG setSmallBytesO
-
#define setKCharO(self, key, value) (self)->f->setKChar(self, key, value)
#define setKCharG setKCharO