summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2022-03-04 13:18:35 +0100
committerTyge Løvset <[email protected]>2022-03-04 13:18:35 +0100
commit3c379fbfb2b7301cd5c4f5371a9f0b96a1369b60 (patch)
tree46975c8374107e44fd9605894ce5b02d981ba538
parentc4301c6b492bb962a943335bf8df4920b2a699cf (diff)
downloadSTC-modified-3c379fbfb2b7301cd5c4f5371a9f0b96a1369b60.tar.gz
STC-modified-3c379fbfb2b7301cd5c4f5371a9f0b96a1369b60.zip
Updated printf formatting to portable code. This was also to use http://winlibs.com gcc+clang with ucrt runtime-libs without warnings.
-rw-r--r--benchmarks/misc/rust_cmap.c10
-rw-r--r--benchmarks/misc/string_bench.c2
-rw-r--r--benchmarks/shootout_hashmaps.cpp14
-rw-r--r--docs/cbits_api.md6
-rw-r--r--docs/ccommon_api.md2
-rw-r--r--docs/cpque_api.md2
-rw-r--r--docs/cstr_api.md2
-rw-r--r--examples/birthday.c4
-rw-r--r--examples/bits.c12
-rw-r--r--examples/books.c2
-rw-r--r--examples/box2.c12
-rw-r--r--examples/complex.c2
-rw-r--r--examples/csmap_erase.c4
-rw-r--r--examples/csmap_find.c2
-rw-r--r--examples/cstr_match.c2
-rw-r--r--examples/demos.c10
-rw-r--r--examples/make.sh13
-rw-r--r--examples/mapmap.c8
-rw-r--r--examples/new_queue.c4
-rw-r--r--examples/prime.c6
-rw-r--r--examples/priority.c4
-rw-r--r--examples/queue.c2
-rw-r--r--examples/random.c6
-rw-r--r--examples/rawptr_elements.c2
-rw-r--r--examples/regex2.c2
-rw-r--r--examples/regex_match.c2
-rw-r--r--include/stc/carc.h2
-rw-r--r--include/stc/ccommon.h2
-rw-r--r--include/stc/cstr.h10
-rw-r--r--src/casefold.py3
30 files changed, 79 insertions, 75 deletions
diff --git a/benchmarks/misc/rust_cmap.c b/benchmarks/misc/rust_cmap.c
index aa96c2c5..7df8fa59 100644
--- a/benchmarks/misc/rust_cmap.c
+++ b/benchmarks/misc/rust_cmap.c
@@ -30,7 +30,7 @@ int main()
ms = CLOCKS_PER_SEC/1000;
cmap_u64_max_load_factor(&m, 0.8);
cmap_u64_reserve(&m, n);
- printf("STC cmap n = %zu, mask = 0x%zx\n", n, mask);
+ printf("STC cmap n = %" PRIuMAX ", mask = 0x%" PRIxMAX "\n", n, mask);
uint64_t rng[3] = {1872361123, 123879177, 87739234}, sum;
clock_t now = clock();
@@ -38,17 +38,17 @@ int main()
uint64_t key = romu_trio(rng) & mask;
cmap_u64_insert(&m, key, 0).ref->second += 1;
}
- printf("insert : %zums \tsize : %zu\n", (clock() - now)/ms, cmap_u64_size(m));
+ printf("insert : %zums \tsize : %" PRIuMAX "\n", (clock() - now)/ms, cmap_u64_size(m));
now = clock();
sum = 0;
c_forrange (key, mask + 1) { sum += cmap_u64_contains(&m, key); }
- printf("lookup : %zums \tsum : %zu\n", (clock() - now)/ms, sum);
+ printf("lookup : %zums \tsum : %" PRIuMAX "\n", (clock() - now)/ms, sum);
now = clock();
sum = 0;
c_foreach (i, cmap_u64, m) { sum += i.ref->second; }
- printf("iterate : %zums \tsum : %zu\n", (clock() - now)/ms, sum);
+ printf("iterate : %zums \tsum : %" PRIuMAX "\n", (clock() - now)/ms, sum);
uint64_t rng2[3] = {1872361123, 123879177, 87739234};
now = clock();
@@ -56,7 +56,7 @@ int main()
uint64_t key = romu_trio(rng2) & mask;
cmap_u64_erase(&m, key);
}
- printf("remove : %zums \tsize : %zu\n", (clock() - now)/ms, cmap_u64_size(m));
+ printf("remove : %zums \tsize : %" PRIuMAX "\n", (clock() - now)/ms, cmap_u64_size(m));
printf("press a key:\n"); getchar();
}
} \ No newline at end of file
diff --git a/benchmarks/misc/string_bench.c b/benchmarks/misc/string_bench.c
index e93328d4..fb2a70b2 100644
--- a/benchmarks/misc/string_bench.c
+++ b/benchmarks/misc/string_bench.c
@@ -149,5 +149,5 @@ void benchmark(cvec_str vec_string, struct Maps maps)
grandtotal += total;
printf(" timing:%5.0fms\n", (clock() - stopwatch) / (float)CLOCKS_PER_SEC * 1000.0f);
- printf("C grandtotal: %zu <--- Ignore this\n", grandtotal);
+ printf("C grandtotal: %" PRIuMAX " <--- Ignore this\n", grandtotal);
}
diff --git a/benchmarks/shootout_hashmaps.cpp b/benchmarks/shootout_hashmaps.cpp
index 6c8c1f00..cd336931 100644
--- a/benchmarks/shootout_hashmaps.cpp
+++ b/benchmarks/shootout_hashmaps.cpp
@@ -145,7 +145,7 @@ size_t seed;
sum += ++ M##_EMPLACE(X, RAND(keybits), i); \
} \
difference = clock() - before; \
- printf(#M ": time: %5.02f, size: %zu, buckets: %8zu, sum: %zu\n", \
+ printf(#M ": time: %5.02f, size: %" PRIuMAX ", buckets: %8zu, sum: %" PRIuMAX "\n", \
(float) difference / CLOCKS_PER_SEC, (size_t) M##_SIZE(X), (size_t) M##_BUCKETS(X), sum); \
M##_DTOR(X); \
}
@@ -161,7 +161,7 @@ size_t seed;
erased += M##_ERASE(X, RAND(keybits)); \
} \
difference = clock() - before; \
- printf(#M ": time: %5.02f, size: %zu, buckets: %8zu, erased %zu, sum: %zu\n", \
+ printf(#M ": time: %5.02f, size: %" PRIuMAX ", buckets: %8zu, erased %" PRIuMAX ", sum: %" PRIuMAX "\n", \
(float) difference / CLOCKS_PER_SEC, (size_t) M##_SIZE(X), (size_t) M##_BUCKETS(X), erased, sum); \
M##_DTOR(X); \
}
@@ -176,7 +176,7 @@ size_t seed;
for (size_t i = 0; i < n; ++i) \
erased += M##_ERASE(X, i); \
difference = clock() - before; \
- printf(#M ": time: %5.02f, size: %zu, buckets: %8zu, erased %zu\n", \
+ printf(#M ": time: %5.02f, size: %" PRIuMAX ", buckets: %8zu, erased %" PRIuMAX "\n", \
(float) difference / CLOCKS_PER_SEC, (size_t) M##_SIZE(X), (size_t) M##_BUCKETS(X), erased); \
M##_DTOR(X); \
}
@@ -194,7 +194,7 @@ size_t seed;
for (size_t i = 0; i < n; ++i) \
erased += M##_ERASE(X, RAND(keybits)); \
difference = clock() - before; \
- printf(#M ": time: %5.02f, size: %zu, buckets: %8zu, erased %zu\n", \
+ printf(#M ": time: %5.02f, size: %" PRIuMAX ", buckets: %8zu, erased %" PRIuMAX "\n", \
(float) difference / CLOCKS_PER_SEC, (size_t) M##_SIZE(X), (size_t) M##_BUCKETS(X), erased); \
M##_DTOR(X); \
}
@@ -212,7 +212,7 @@ size_t seed;
for (size_t k=0; k < x; k++) M##_FOR (X, it) \
sum += M##_ITEM(X, it); \
difference = clock() - before; \
- printf(#M ": time: %5.02f, size: %zu, buckets: %8zu, repeats: %zu, sum: %zu\n", \
+ printf(#M ": time: %5.02f, size: %" PRIuMAX ", buckets: %8zu, repeats: %" PRIuMAX ", sum: %" PRIuMAX "\n", \
(float) difference / CLOCKS_PER_SEC, (size_t) M##_SIZE(X), (size_t) M##_BUCKETS(X), x, sum); \
M##_DTOR(X); \
}
@@ -234,7 +234,7 @@ size_t seed;
for (size_t i = 0; i < x; ++i) \
found += M##_FIND(X, RAND(keybits)); \
difference = clock() - before; \
- printf(#M ": time: %5.02f, size: %zu, buckets: %8zu, lookups: %zu, found: %zu\n", \
+ printf(#M ": time: %5.02f, size: %" PRIuMAX ", buckets: %8zu, lookups: %" PRIuMAX ", found: %" PRIuMAX "\n", \
(float) difference / CLOCKS_PER_SEC, (size_t) M##_SIZE(X), (size_t) M##_BUCKETS(X), x*2, found); \
M##_DTOR(X); \
}
@@ -273,7 +273,7 @@ int main(int argc, char* argv[])
"UMAP = std::unordered_map\n\n");
printf("Usage %s [n-million=%d key-bits=%d]\n", argv[0], DEFAULT_N_MILL, DEFAULT_KEYBITS);
- printf("N-base = %d. Random keys are in range [0, 2^%d). Seed = %zu:\n", n_mill, keybits, seed);
+ printf("N-base = %d. Random keys are in range [0, 2^%d). Seed = %" PRIuMAX ":\n", n_mill, keybits, seed);
printf("\nT0: Insert/update random keys:\n");
RUN_TEST(0)
diff --git a/docs/cbits_api.md b/docs/cbits_api.md
index f6077d20..1cf03c4c 100644
--- a/docs/cbits_api.md
+++ b/docs/cbits_api.md
@@ -89,18 +89,18 @@ cbits sieveOfEratosthenes(size_t n)
int main(void)
{
size_t n = 100000000;
- printf("computing prime numbers up to %zu\n", n);
+ printf("computing prime numbers up to %" PRIuMAX "\n", n);
clock_t t1 = clock();
cbits primes = sieveOfEratosthenes(n + 1);
size_t nprimes = cbits_count(primes);
clock_t t2 = clock();
- printf("number of primes: %zu, time: %f\n", nprimes, (float)(t2 - t1)/CLOCKS_PER_SEC);
+ printf("number of primes: %" PRIuMAX ", time: %f\n", nprimes, (float)(t2 - t1)/CLOCKS_PER_SEC);
printf(" 2");
for (size_t i = 3; i < 1000; i += 2)
- if (cbits_test(primes, i>>1)) printf(" %zu", i);
+ if (cbits_test(primes, i>>1)) printf(" %" PRIuMAX "", i);
puts("");
cbits_drop(&primes);
diff --git a/docs/ccommon_api.md b/docs/ccommon_api.md
index db9ef911..e7949b25 100644
--- a/docs/ccommon_api.md
+++ b/docs/ccommon_api.md
@@ -159,7 +159,7 @@ Declare an iterator and specify a range to iterate with a for loop. Like python'
```c
c_forrange (5) printf("x");
// xxxxx
-c_forrange (i, 5) printf(" %zu", i);
+c_forrange (i, 5) printf(" %" PRIuMAX "", i);
// 0 1 2 3 4
c_forrange (i, int, -3, 3) printf(" %d", i);
// -3 -2 -1 0 1 2
diff --git a/docs/cpque_api.md b/docs/cpque_api.md
index fbc1786d..97ac70f5 100644
--- a/docs/cpque_api.md
+++ b/docs/cpque_api.md
@@ -83,7 +83,7 @@ int main()
// Extract and display the fifty smallest.
c_forrange (50) {
- printf("%zd ", *cpque_i_top(&heap));
+ printf("%" PRIdMAX " ", *cpque_i_top(&heap));
cpque_i_pop(&heap);
}
}
diff --git a/docs/cstr_api.md b/docs/cstr_api.md
index 0f6b2e89..4f7c689e 100644
--- a/docs/cstr_api.md
+++ b/docs/cstr_api.md
@@ -109,7 +109,7 @@ int c_strncasecmp(const char* str1, const char* str2, size_t n);
int main() {
cstr s0 = cstr_new("Initialization without using strlen().");
- printf("%s\nLength: %zu\n\n", s0.str, cstr_size(s0));
+ printf("%s\nLength: %" PRIuMAX "\n\n", s0.str, cstr_size(s0));
cstr s1 = cstr_new("one-nine-three-seven-five.");
printf("%s\n", s1.str);
diff --git a/examples/birthday.c b/examples/birthday.c
index f848436c..94438077 100644
--- a/examples/birthday.c
+++ b/examples/birthday.c
@@ -24,7 +24,7 @@ static void test_repeats(void)
c_forrange (i, N) {
uint64_t k = stc64_rand(&rng) & mask;
int v = cmap_ic_insert(&m, k, 0).ref->second += 1;
- if (v > 1) printf("repeated value %zu (%d) at 2^%d\n", k, v, (int) log2((double) i));
+ if (v > 1) printf("repeated value %" PRIuMAX " (%d) at 2^%d\n", k, v, (int) log2((double) i));
}
}
}
@@ -52,7 +52,7 @@ void test_distribution(void)
sum /= map.size;
c_foreach (i, cmap_x, map) {
- printf("%4u: %zu - %zu: %11.8f\n", i.ref->first, i.ref->second, sum, (1 - (double) i.ref->second / sum));
+ printf("%4u: %" PRIuMAX " - %" PRIuMAX ": %11.8f\n", i.ref->first, i.ref->second, sum, (1 - (double) i.ref->second / sum));
}
}
}
diff --git a/examples/bits.c b/examples/bits.c
index ac59bd32..9fdf1d5d 100644
--- a/examples/bits.c
+++ b/examples/bits.c
@@ -4,11 +4,11 @@
int main()
{
c_autovar (cbits set = cbits_with_size(23, true), cbits_drop(&set)) {
- printf("count %zu, %zu\n", cbits_count(set), set.size);
+ printf("count %" PRIuMAX ", %" PRIuMAX "\n", cbits_count(set), set.size);
cbits s1 = cbits_new("1110100110111");
char buf[256];
cbits_to_str(s1, buf, 0, -1);
- printf("buf: %s: %zu\n", buf, cbits_count(s1));
+ printf("buf: %s: %" PRIuMAX "\n", buf, cbits_count(s1));
cbits_drop(&s1);
cbits_reset(&set, 9);
@@ -16,7 +16,7 @@ int main()
c_autobuf (str, char, set.size + 1)
printf(" str: %s\n", cbits_to_str(set, str, 0, -1));
- printf("%4zu: ", set.size);
+ printf("%4" PRIuMAX ": ", set.size);
c_forrange (i, int, set.size)
printf("%d", cbits_test(set, i));
puts("");
@@ -26,12 +26,12 @@ int main()
cbits_resize(&set, 93, false);
cbits_resize(&set, 102, true);
cbits_set_value(&set, 99, false);
- printf("%4zu: ", set.size);
+ printf("%4" PRIuMAX ": ", set.size);
c_forrange (i, int, set.size)
printf("%d", cbits_test(set, i));
puts("\nIterate:");
- printf("%4zu: ", set.size);
+ printf("%4" PRIuMAX ": ", set.size);
c_forrange (i, int, set.size)
printf("%d", cbits_test(set, i));
puts("");
@@ -53,7 +53,7 @@ int main()
puts("");
cbits_set_all(&set, false);
- printf("%4zu: ", set.size);
+ printf("%4" PRIuMAX ": ", set.size);
c_forrange (i, int, set.size)
printf("%d", cbits_test(set, i));
puts("");
diff --git a/examples/books.c b/examples/books.c
index 8ddce634..10b5c416 100644
--- a/examples/books.c
+++ b/examples/books.c
@@ -32,7 +32,7 @@ int main()
// When collections store owned values (String), they can still be
// queried using references (&str).
if (cmap_str_contains(&book_reviews, "Les Misérables")) {
- printf("We've got %zu reviews, but Les Misérables ain't one.",
+ printf("We've got %" PRIuMAX " reviews, but Les Misérables ain't one.",
cmap_str_size(book_reviews));
}
diff --git a/examples/box2.c b/examples/box2.c
index d5905877..e5b4dacd 100644
--- a/examples/box2.c
+++ b/examples/box2.c
@@ -67,22 +67,22 @@ int main(void) {
// Double indirection
box_in_a_box = cbox_BoxPoint_from(boxed_origin());
- printf("Point occupies %zu bytes on the stack\n",
+ printf("Point occupies %" PRIuMAX " bytes on the stack\n",
sizeof(point));
- printf("Rectangle occupies %zu bytes on the stack\n",
+ printf("Rectangle occupies %" PRIuMAX " bytes on the stack\n",
sizeof(rectangle));
// box size == pointer size
- printf("Boxed point occupies %zu bytes on the stack\n",
+ printf("Boxed point occupies %" PRIuMAX " bytes on the stack\n",
sizeof(boxed_point));
- printf("Boxed rectangle occupies %zu bytes on the stack\n",
+ printf("Boxed rectangle occupies %" PRIuMAX " bytes on the stack\n",
sizeof(boxed_rectangle));
- printf("Boxed box occupies %zu bytes on the stack\n",
+ printf("Boxed box occupies %" PRIuMAX " bytes on the stack\n",
sizeof(box_in_a_box));
// Copy the data contained in `boxed_point` into `unboxed_point`
Point unboxed_point = *boxed_point.get;
- printf("Unboxed point occupies %zu bytes on the stack\n",
+ printf("Unboxed point occupies %" PRIuMAX " bytes on the stack\n",
sizeof(unboxed_point));
}
}
diff --git a/examples/complex.c b/examples/complex.c
index b0cd7a01..9ccd2dae 100644
--- a/examples/complex.c
+++ b/examples/complex.c
@@ -41,7 +41,7 @@ int main() {
// Put in some data in stack array
stack.data[x] = 3.1415927f;
- printf("stack size: %zu\n", FloatStack_size(stack));
+ printf("stack size: %" PRIuMAX "\n", FloatStack_size(stack));
StackList list = StackList_init();
StackList_push_back(&list, stack);
diff --git a/examples/csmap_erase.c b/examples/csmap_erase.c
index 68a0378b..2716ad8f 100644
--- a/examples/csmap_erase.c
+++ b/examples/csmap_erase.c
@@ -12,7 +12,7 @@ void printmap(mymap m)
{
c_foreach (elem, mymap, m)
printf(" [%d, %s]", elem.ref->first, elem.ref->second.str);
- printf("\nsize() == %zu\n\n", mymap_size(m));
+ printf("\nsize() == %" PRIuMAX "\n\n", mymap_size(m));
}
int main()
@@ -72,7 +72,7 @@ int main()
// The 3rd member function removes elements with a given Key
size_t count = mymap_erase(&m3, 2);
// The 3rd member function also returns the number of elements removed
- printf("The number of elements removed from m3 is: %zu\n", count);
+ printf("The number of elements removed from m3 is: %" PRIuMAX "\n", count);
puts("After the element with a key of 2 is deleted, the map m3 is:");
printmap(m3);
}
diff --git a/examples/csmap_find.c b/examples/csmap_find.c
index ea86d71b..9e3aba83 100644
--- a/examples/csmap_find.c
+++ b/examples/csmap_find.c
@@ -18,7 +18,7 @@ void print_elem(csmap_istr_raw p) {
#define using_print_collection(CX) \
void print_collection_##CX(CX t) { \
- printf("%zu elements: ", CX##_size(t)); \
+ printf("%" PRIuMAX " elements: ", CX##_size(t)); \
\
c_foreach (p, CX, t) { \
print_elem(CX##_value_toraw(p.ref)); \
diff --git a/examples/cstr_match.c b/examples/cstr_match.c
index db5b3ecf..057334f6 100644
--- a/examples/cstr_match.c
+++ b/examples/cstr_match.c
@@ -5,7 +5,7 @@ int main()
{
c_autovar (cstr ss = cstr_new("The quick brown fox jumps over the lazy dog.JPG"), cstr_drop(&ss)) {
size_t pos = cstr_find_n(ss, "brown", 0, 5);
- printf("%zu [%s]\n", pos, pos == cstr_npos ? "<NULL>" : &ss.str[pos]);
+ printf("%" PRIuMAX " [%s]\n", pos, pos == cstr_npos ? "<NULL>" : &ss.str[pos]);
printf("equals: %d\n", cstr_equals(ss, "The quick brown fox jumps over the lazy dog.JPG"));
printf("contains: %d\n", cstr_contains(ss, "umps ove"));
printf("starts_with: %d\n", cstr_starts_with(ss, "The quick brown"));
diff --git a/examples/demos.c b/examples/demos.c
index 93192ee5..e91be28a 100644
--- a/examples/demos.c
+++ b/examples/demos.c
@@ -41,14 +41,14 @@ void vectordemo1()
for (size_t i = 10; i <= 100; i += 10)
cvec_ix_push_back(&bignums, i * i);
- printf("erase - %d: %zu\n", 3, bignums.data[3]);
+ printf("erase - %d: %" PRIuMAX "\n", 3, bignums.data[3]);
cvec_ix_erase_n(&bignums, 3, 1); // erase index 3
cvec_ix_pop_back(&bignums); // erase the last
cvec_ix_erase_n(&bignums, 0, 1); // erase the first
for (size_t i = 0; i < cvec_ix_size(bignums); ++i) {
- printf("%zu: %zu\n", i, bignums.data[i]);
+ printf("%" PRIuMAX ": %" PRIuMAX "\n", i, bignums.data[i]);
}
}
}
@@ -174,11 +174,11 @@ void mapdemo3()
cmap_str_iter it = cmap_str_find(&table, "Make");
c_foreach (i, cmap_str, table)
printf("entry: %s: %s\n", i.ref->first.str, i.ref->second.str);
- printf("size %zu: remove: Make: %s\n", cmap_str_size(table), it.ref->second.str);
+ printf("size %" PRIuMAX ": remove: Make: %s\n", cmap_str_size(table), it.ref->second.str);
//cmap_str_erase(&table, "Make");
cmap_str_erase_at(&table, it);
- printf("size %zu\n", cmap_str_size(table));
+ printf("size %" PRIuMAX "\n", cmap_str_size(table));
c_foreach (i, cmap_str, table)
printf("entry: %s: %s\n", i.ref->first.str, i.ref->second.str);
cmap_str_drop(&table); // frees key and value cstrs, and hash table.
@@ -198,7 +198,7 @@ void arraydemo1()
float **arr2 = arr3.data[5];
float *arr1 = arr3.data[5][4];
- printf("arr3: %zu: (%zu, %zu, %zu) = %zu\n", sizeof(arr3),
+ printf("arr3: %" PRIuMAX ": (%" PRIuMAX ", %" PRIuMAX ", %" PRIuMAX ") = %" PRIuMAX "\n", sizeof(arr3),
arr3.xdim, arr3.ydim, arr3.zdim, carr3_f_size(arr3));
printf("%g\n", arr1[3]); // = 10.2
diff --git a/examples/make.sh b/examples/make.sh
index ccce036f..3f2247b6 100644
--- a/examples/make.sh
+++ b/examples/make.sh
@@ -1,11 +1,14 @@
#!/bin/bash
-cc='gcc -O2 -Wall -std=c99 -pedantic'
+cc='gcc -s -O2 -Wall -std=c99 -pedantic'
+#cc='clang -s -O2 -Wall -std=c99 -pedantic'
#cc='clang'
#cc='clang -c -DSTC_HEADER'
-#cc='cl -nologo'
+#cc='cl -O2 -nologo -W2 -MD'
#cc='cl -nologo -TP'
#cc='cl -nologo -std:c11'
libs=''
+#oflag='/Fe:'
+oflag='-o '
run=0
if [ -z "$OS" ]; then
libs='-lm -pthread'
@@ -24,8 +27,8 @@ fi
if [ $run = 0 ] ; then
for i in *.c ; do
- echo $cc -I../include $i $libs
- $cc -I../include $i $libs
+ echo $cc -I../include $i $libs $oflag$(basename $i .c).exe
+ $cc -I../include $i $libs $oflag$(basename $i .c).exe
done
else
for i in *.c ; do
@@ -37,4 +40,4 @@ else
done
fi
-rm -f a.out *.o *.obj *.exe
+rm -f a.out *.o *.obj # *.exe
diff --git a/examples/mapmap.c b/examples/mapmap.c
index f0bf31a8..b3360d1e 100644
--- a/examples/mapmap.c
+++ b/examples/mapmap.c
@@ -58,10 +58,10 @@ int main(void)
printf("%s: %s - %s\n", i.ref->first.str, _.name.str, _.email.str);
puts("");
- c_auto (Stack, s) printf("found: %zu\n", Stack_size(s = contains(&map, "Nick Denton")));
- c_auto (Stack, s) printf("found: %zu\n", Stack_size(s = contains(&map, "Patrick Dust")));
- c_auto (Stack, s) printf("found: %zu\n", Stack_size(s = contains(&map, "Dennis Kay")));
- c_auto (Stack, s) printf("found: %zu\n", Stack_size(s = contains(&map, "Serena Bath")));
+ c_auto (Stack, s) printf("found: %" PRIuMAX "\n", Stack_size(s = contains(&map, "Nick Denton")));
+ c_auto (Stack, s) printf("found: %" PRIuMAX "\n", Stack_size(s = contains(&map, "Patrick Dust")));
+ c_auto (Stack, s) printf("found: %" PRIuMAX "\n", Stack_size(s = contains(&map, "Dennis Kay")));
+ c_auto (Stack, s) printf("found: %" PRIuMAX "\n", Stack_size(s = contains(&map, "Serena Bath")));
puts("Done");
}
}
diff --git a/examples/new_queue.c b/examples/new_queue.c
index 718c025f..1b7c021c 100644
--- a/examples/new_queue.c
+++ b/examples/new_queue.c
@@ -31,7 +31,7 @@ int main() {
cqueue_int_push(&Q, stc64_uniform(&rng, &dist));
// Push or pop on the queue ten million times
- printf("befor: size %zu, capacity %zu\n", cqueue_int_size(Q), cqueue_int_capacity(Q));
+ printf("befor: size %" PRIuMAX ", capacity %" PRIuMAX "\n", cqueue_int_size(Q), cqueue_int_capacity(Q));
for (int i=n; i>0; --i) {
int r = stc64_uniform(&rng, &dist);
if (r & 1)
@@ -39,6 +39,6 @@ int main() {
else
cqueue_int_pop(&Q);
}
- printf("after: size %zu, capacity %zu\n", cqueue_int_size(Q), cqueue_int_capacity(Q));
+ printf("after: size %" PRIuMAX ", capacity %" PRIuMAX "\n", cqueue_int_size(Q), cqueue_int_capacity(Q));
}
}
diff --git a/examples/prime.c b/examples/prime.c
index 0e2ede56..4d70ee24 100644
--- a/examples/prime.c
+++ b/examples/prime.c
@@ -24,7 +24,7 @@ cbits sieveOfEratosthenes(size_t n)
int main(void)
{
size_t n = 1000000000;
- printf("computing prime numbers up to %zu\n", n);
+ printf("computing prime numbers up to %" PRIuMAX "\n", n);
clock_t t1 = clock();
c_autovar (cbits primes = sieveOfEratosthenes(n + 1), cbits_drop(&primes)) {
@@ -32,10 +32,10 @@ int main(void)
size_t np = cbits_count(primes);
clock_t t2 = clock();
- printf("number of primes: %zu, time: %f\n", np, (t2 - t1) / (float)CLOCKS_PER_SEC);
+ printf("number of primes: %" PRIuMAX ", time: %f\n", np, (t2 - t1) / (float)CLOCKS_PER_SEC);
printf("2");
for (size_t i = 3; i < 1000; i += 2)
- if (cbits_test(primes, i>>1)) printf(" %zu", i);
+ if (cbits_test(primes, i>>1)) printf(" %" PRIuMAX "", i);
puts("");
}
}
diff --git a/examples/priority.c b/examples/priority.c
index 184cad9f..1767dba8 100644
--- a/examples/priority.c
+++ b/examples/priority.c
@@ -15,7 +15,7 @@ int main() {
c_auto (cpque_i, heap)
{
// Push ten million random numbers to priority queue
- printf("Push %zu numbers\n", N);
+ printf("Push %" PRIuMAX " numbers\n", N);
c_forrange (N)
cpque_i_push(&heap, stc64_uniform(&rng, &dist));
@@ -27,7 +27,7 @@ int main() {
puts("Extract the hundred smallest.");
c_forrange (100) {
- printf("%zd ", *cpque_i_top(&heap));
+ printf("%" PRIdMAX " ", *cpque_i_top(&heap));
cpque_i_pop(&heap);
}
}
diff --git a/examples/queue.c b/examples/queue.c
index 2c2052e5..db5f0e05 100644
--- a/examples/queue.c
+++ b/examples/queue.c
@@ -26,6 +26,6 @@ int main() {
else
--n, cqueue_i_pop(&queue);
}
- printf("%d, %zu\n", n, cqueue_i_size(queue));
+ printf("%d, %" PRIuMAX "\n", n, cqueue_i_size(queue));
}
}
diff --git a/examples/random.c b/examples/random.c
index 81fe71c5..59c1eb95 100644
--- a/examples/random.c
+++ b/examples/random.c
@@ -18,7 +18,7 @@ int main()
sum += (uint32_t) stc64_rand(&rng);
}
diff = clock() - before;
- printf("full range\t\t: %f secs, %zu, avg: %f\n", (float) diff / CLOCKS_PER_SEC, N, (double) sum / N);
+ printf("full range\t\t: %f secs, %" PRIuMAX ", avg: %f\n", (float) diff / CLOCKS_PER_SEC, N, (double) sum / N);
stc64_uniform_t dist1 = stc64_uniform_init(0, range);
rng = stc64_init(seed);
@@ -28,7 +28,7 @@ int main()
sum += stc64_uniform(&rng, &dist1); // unbiased
}
diff = clock() - before;
- printf("unbiased 0-%zu\t: %f secs, %zu, avg: %f\n", range, (float) diff / CLOCKS_PER_SEC, N, (double) sum / N);
+ printf("unbiased 0-%" PRIuMAX "\t: %f secs, %" PRIuMAX ", avg: %f\n", range, (float) diff / CLOCKS_PER_SEC, N, (double) sum / N);
sum = 0;
rng = stc64_init(seed);
@@ -37,6 +37,6 @@ int main()
sum += stc64_rand(&rng) % (range + 1); // biased
}
diff = clock() - before;
- printf("biased 0-%zu \t: %f secs, %zu, avg: %f\n", range, (float) diff / CLOCKS_PER_SEC, N, (double) sum / N);
+ printf("biased 0-%" PRIuMAX " \t: %f secs, %" PRIuMAX ", avg: %f\n", range, (float) diff / CLOCKS_PER_SEC, N, (double) sum / N);
}
diff --git a/examples/rawptr_elements.c b/examples/rawptr_elements.c
index 3ff0dc8a..483e7c9a 100644
--- a/examples/rawptr_elements.c
+++ b/examples/rawptr_elements.c
@@ -57,6 +57,6 @@ int main()
cmap_str_emplace(&map, "goodbye", 400);
c_forpair (name, number, cmap_str, map)
- printf("%s: %zd\n", _.name.str, *_.number);
+ printf("%s: %" PRIdMAX "\n", _.name.str, *_.number);
}
}
diff --git a/examples/regex2.c b/examples/regex2.c
index 96ac7ed4..d27b0406 100644
--- a/examples/regex2.c
+++ b/examples/regex2.c
@@ -25,7 +25,7 @@ int main()
c_forrange (j, cregex_captures(re))
{
csview cap = {m[j].str, m[j].len};
- printf(" submatch %zu: " c_PRIsv "\n", j, c_ARGsv(cap));
+ printf(" submatch %" PRIuMAX ": " c_PRIsv "\n", j, c_ARGsv(cap));
}
puts("");
}
diff --git a/examples/regex_match.c b/examples/regex_match.c
index f543fc31..cc5bb483 100644
--- a/examples/regex_match.c
+++ b/examples/regex_match.c
@@ -20,7 +20,7 @@ int main()
printf("%d\n", res);
cregmatch m[10];
if (cregex_find(&re, s, 10, m, 0) > 0) {
- printf("Found digits at position %zu-%zu\n", m[0].str - s, m[0].str - s + m[0].len);
+ printf("Found digits at position %" PRIuMAX "-%" PRIuMAX "\n", m[0].str - s, m[0].str - s + m[0].len);
} else {
printf("Could not find any digits\n");
}
diff --git a/include/stc/carc.h b/include/stc/carc.h
index 9c7d52c1..e3deb376 100644
--- a/include/stc/carc.h
+++ b/include/stc/carc.h
@@ -43,7 +43,7 @@ int main() {
carc_person p = carc_person_from(Person_new("John", "Smiths"));
carc_person q = carc_person_clone(p); // share the pointer
- printf("%s %s. uses: %zu\n", q.get->name.str, q.get->last.str, *q.use_count);
+ printf("%s %s. uses: %" PRIuMAX "\n", q.get->name.str, q.get->last.str, *q.use_count);
c_drop(carc_person, &p, &q);
}
*/
diff --git a/include/stc/ccommon.h b/include/stc/ccommon.h
index e5a595e0..263971a0 100644
--- a/include/stc/ccommon.h
+++ b/include/stc/ccommon.h
@@ -24,7 +24,7 @@
#define CCOMMON_H_INCLUDED
#define _CRT_SECURE_NO_WARNINGS
-#include <stdint.h>
+#include <inttypes.h>
#include <stddef.h>
#include <stdbool.h>
#include <string.h>
diff --git a/include/stc/cstr.h b/include/stc/cstr.h
index 937e5151..fc4c22d1 100644
--- a/include/stc/cstr.h
+++ b/include/stc/cstr.h
@@ -32,11 +32,11 @@
#include <ctype.h>
#define cstr_npos (SIZE_MAX >> 1)
-typedef struct { size_t size, cap; char chr; } _cstr_rep_t;
+typedef struct { size_t size, cap; char chr[1]; } _cstr_rep_t;
#define _cstr_rep(self) c_container_of((self)->str, _cstr_rep_t, chr)
#ifdef _i_static
- static _cstr_rep_t _cstr_nullrep = {0, 0, 0};
- static const cstr cstr_null = {&_cstr_nullrep.chr};
+ static _cstr_rep_t _cstr_nullrep = {0, 0, {0}};
+ static const cstr cstr_null = {_cstr_nullrep.chr};
#else
extern const cstr cstr_null;
#endif
@@ -186,7 +186,7 @@ cstr_reserve(cstr* self, const size_t cap) {
const size_t oldcap = rep->cap;
if (cap > oldcap) {
rep = (_cstr_rep_t*) c_realloc(oldcap ? rep : NULL, _cstr_opt_mem(cap));
- self->str = &rep->chr;
+ self->str = rep->chr;
if (oldcap == 0) self->str[rep->size = 0] = '\0';
return (rep->cap = _cstr_opt_cap(cap));
}
@@ -205,7 +205,7 @@ STC_DEF cstr
cstr_from_n(const char* str, const size_t n) {
if (n == 0) return cstr_null;
_cstr_rep_t* rep = (_cstr_rep_t*) c_malloc(_cstr_opt_mem(n));
- cstr s = {(char *) memcpy(&rep->chr, str, n)};
+ cstr s = {(char *) memcpy(rep->chr, str, n)};
s.str[rep->size = n] = '\0';
rep->cap = _cstr_opt_cap(n);
return s;
diff --git a/src/casefold.py b/src/casefold.py
index 73d6fcbc..82d19853 100644
--- a/src/casefold.py
+++ b/src/casefold.py
@@ -2,7 +2,7 @@
import pandas as pd
import numpy as np
-def read_unidata(catfilter, casefilter=None, big=False):
+def read_unidata(catfilter='Lu', casefilter='lowcase', big=False):
ud = pd.read_csv("ucd/UnicodeData.txt", sep=';', converters={0: lambda x: int(x, base=16)},
names=['code', 'name', 'category', 'canclass', 'bidircat', 'chrdecomp',
'decdig', 'digval', 'numval', 'mirrored', 'uc1name', 'comment',
@@ -119,6 +119,7 @@ static struct CaseFold { uint16_t c0, c1, m1; } casefold[] = {''')
def make_casetable():
df = read_casefold()
+ #df = read_unidata()
letters = make_caselist(df)
cfold = make_casefold(letters)
return cfold