summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2022-12-31 00:20:26 +0100
committerTyge Løvset <[email protected]>2022-12-31 00:20:26 +0100
commit9d48d93be9be4e5702979c82c9445cd8d4e90d04 (patch)
treec7ec7f8e540f6fa4363430c90d9aa0ecd6eb11a2
parent9d59845f622fbb9c225bbe32246a3128ad9ec0b1 (diff)
downloadSTC-modified-9d48d93be9be4e5702979c82c9445cd8d4e90d04.tar.gz
STC-modified-9d48d93be9be4e5702979c82c9445cd8d4e90d04.zip
Moved fmt.h to include/c11 folder. Not used by the lib or examples as lib is c99 only.
-rw-r--r--include/c11/fmt.h (renamed from misc/include/c11/fmt.h)23
-rw-r--r--include/stc/algo/crange.h6
-rw-r--r--include/stc/algo/csort.h8
-rw-r--r--include/stc/algo/cspan.h10
4 files changed, 24 insertions, 23 deletions
diff --git a/misc/include/c11/fmt.h b/include/c11/fmt.h
index d5ba3575..6e2f8e55 100644
--- a/misc/include/c11/fmt.h
+++ b/include/c11/fmt.h
@@ -1,15 +1,16 @@
-#ifndef FMT_INCLUDED
-#define FMT_INCLUDED
+#ifndef FMT_H_INCLUDED
+#define FMT_H_INCLUDED
/*
void fmt_print(dst, fmt, ...);
-void fmt_destroy(fmt_buffer* buf);
+void fmt_drop_buffer(fmt_buffer* buf);
- dst - destination
- int 1=stdout, 2=stderr
- FILE* file Write to a file
+ dst - destination, one of:
+ int fd 1=stdout, 2=stderr
+ FILE* fp Write to a file
char* strbuf Write to a pre-allocated string buffer
- fmt_buffer* b Auto realloc the needed memory. Set b->stream=1 for stream-mode.
- b->data must be freed after usage.
+ fmt_buffer* buf Auto realloc the needed memory (safe).
+ Set buf->stream=1 for stream-mode.
+ Call fmt_drop_buffer(buf) after usage.
fmt - format string
{} Auto-detected format. If :MOD is not specified,
@@ -51,7 +52,7 @@ int main() {
fmt_print(1, "{}, len={}, cap={}\n", out->data, out->len, out->cap);
fmt_print(out, "{} {}", ", Pi squared is:", pi*pi);
fmt_print(1, "{}, len={}, cap={}\n", out->data, out->len, out->cap);
- fmt_destroy(out);
+ fmt_drop_buffer(out);
}
*/
#include <stdio.h>
@@ -86,7 +87,7 @@ typedef struct {
_Bool stream;
} fmt_buffer;
-FMT_API void fmt_destroy(fmt_buffer* buf);
+FMT_API void fmt_drop_buffer(fmt_buffer* buf);
FMT_API int _fmt_parse(char* p, int nargs, const char *fmt, ...);
FMT_API void _fmt_iprint(int fd, const char* fmt, ...);
FMT_API void _fmt_bprint(fmt_buffer*, const char* fmt, ...);
@@ -183,7 +184,7 @@ FMT_API void _fmt_bprint(fmt_buffer*, const char* fmt, ...);
#include <stdarg.h>
#include <string.h>
-FMT_API void fmt_destroy(fmt_buffer* buf) {
+FMT_API void fmt_drop_buffer(fmt_buffer* buf) {
free(buf->data);
}
diff --git a/include/stc/algo/crange.h b/include/stc/algo/crange.h
index ccdd13ae..933d97b2 100644
--- a/include/stc/algo/crange.h
+++ b/include/stc/algo/crange.h
@@ -28,15 +28,15 @@
int main()
{
crange r1 = crange_make(80, 90);
- c_foreach (i, crange, r1)
+ c_FOREACH (i, crange, r1)
printf(" %lld", *i.ref);
puts("");
// use a temporary crange object.
int a = 100, b = INT32_MAX;
- c_forfilter (i, crange, crange_LITERAL(a, b, 8)
+ c_FORFILTER (i, crange, crange_LITERAL(a, b, 8)
, i.index > 10
- , c_flt_take(i, 3))
+ , c_FLT_TAKE(i, 3))
printf(" %lld", *i.ref);
puts("");
}
diff --git a/include/stc/algo/csort.h b/include/stc/algo/csort.h
index 9b115398..9c6a1e80 100644
--- a/include/stc/algo/csort.h
+++ b/include/stc/algo/csort.h
@@ -27,7 +27,7 @@
#define c_PASTE(a, b) c_CONCAT(a, b)
#endif
-/* Generic Quicksort in C
+/* Generic Quicksort in C, performs as fast as c++ std::sort().
template params:
#define i_val - value type [required]
#define i_less - less function. default: *x < *y
@@ -38,8 +38,8 @@ template params:
#include <time.h>
#include <stdlib.h>
#define i_val int
-#include <stc/crandom.h>
#include <stc/algo/csort.h>
+#include <stc/crandom.h>
#ifdef __cplusplus
#include <algorithm>
#endif
@@ -47,10 +47,10 @@ template params:
int testsort(csortval_int *a, size_t size, const char *desc) {
clock_t t = clock();
#ifdef __cplusplus
- puts("std::sort");
+ printf("std::sort: ");
std::sort(a, a + size);
#else
- puts("csort");
+ printf("csort: ");
csort_int(a, size);
#endif
t = clock() - t;
diff --git a/include/stc/algo/cspan.h b/include/stc/algo/cspan.h
index d6d6dd56..e348d860 100644
--- a/include/stc/algo/cspan.h
+++ b/include/stc/algo/cspan.h
@@ -28,17 +28,17 @@ using_cspan(IntSpan, int);
int main()
{
int array[] = {1, 2, 3, 4, 5};
- IntSpan iv = {array, c_arraylen(array)};
+ IntSpan span = {array, c_ARRAYLEN(array)};
- c_foreach (i, IntSpan, iv)
+ c_FOREACH (i, IntSpan, span)
printf(" %d", *i.ref);
puts("");
// use a temporary IntSpan object.
- c_forfilter (i, IntSpan, cspan_LITERAL(IntSpan, {10, 20, 30, 23, 22, 21})
- , c_flt_skipwhile(i, *i.ref < 25)
+ c_FORFILTER (i, IntSpan, cspan_LITERAL(IntSpan, {10, 20, 30, 23, 22, 21})
+ , c_FLT_SKIPWHILE(i, *i.ref < 25)
&& (*i.ref & 1) == 0 // even only
- , c_flt_take(i, 2)) // break after 2
+ , c_FLT_TAKE(i, 2)) // break after 2
printf(" %d", *i.ref);
puts("");
}