diff options
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/bits.c | 6 | ||||
| -rw-r--r-- | examples/bits2.c | 5 | ||||
| -rw-r--r-- | examples/cpque.c | 9 | ||||
| -rw-r--r-- | examples/new_arr.c | 9 | ||||
| -rw-r--r-- | examples/prime.c | 2 | ||||
| -rw-r--r-- | examples/regex2.c | 2 | ||||
| -rw-r--r-- | examples/regex_replace.c | 2 |
7 files changed, 16 insertions, 19 deletions
diff --git a/examples/bits.c b/examples/bits.c index ca4de6af..43a57c51 100644 --- a/examples/bits.c +++ b/examples/bits.c @@ -13,9 +13,9 @@ int main() cbits_reset(&set, 9); cbits_resize(&set, 43, false); - c_autobuf (str, char, cbits_size(&set) + 1) - printf(" str: %s\n", cbits_to_str(&set, str, 0, -1)); - + { char str[128]; + printf(" str: %s\n", cbits_to_str(&set, str, 0, 128)); + } printf("%4" c_ZU ": ", cbits_size(&set)); c_forrange (i, cbits_size(&set)) printf("%d", cbits_test(&set, i)); diff --git a/examples/bits2.c b/examples/bits2.c index 95eb8b83..59e0b337 100644 --- a/examples/bits2.c +++ b/examples/bits2.c @@ -11,12 +11,11 @@ int main() printf("size %" c_ZU "\n", Bits_size(&s1)); char buf[256]; - Bits_to_str(&s1, buf, 0, -1); + Bits_to_str(&s1, buf, 0, 256); printf("buf: %s: count=%" c_ZU "\n", buf, Bits_count(&s1)); Bits_reset(&s1, 8); - c_autobuf (str, char, Bits_size(&s1) + 1) - printf(" s1: %s\n", Bits_to_str(&s1, str, 0, -1)); + printf(" s1: %s\n", Bits_to_str(&s1, buf, 0, 256)); Bits s2 = Bits_clone(s1); diff --git a/examples/cpque.c b/examples/cpque.c index 63d07c6b..dba4552f 100644 --- a/examples/cpque.c +++ b/examples/cpque.c @@ -9,6 +9,7 @@ #include <stdbool.h> #include <stc/forward.h> #include <stc/views.h> +#include <stc/cstr.h> // predeclare declare_cpque(ipque, int); @@ -18,7 +19,7 @@ struct { bool (*less)(const int*, const int*); } typedef IPQueue; -#define IPQueue_obj(less) ((IPQueue){ipque_init(), less}) +#define IPQueue_drop(q) ipque_drop(&(q)->Q) #define i_type ipque #define i_val int @@ -52,9 +53,9 @@ int main() const int data[] = {1,8,5,6,3,4,0,9,7,2}, n = c_arraylen(data); print("data", data, n); - c_with (IPQueue q1 = IPQueue_obj(int_less), ipque_drop(&q1.Q)) // Max priority queue - c_with (IPQueue minq1 = IPQueue_obj(int_greater), ipque_drop(&minq1.Q)) // Min priority queue - c_with (IPQueue q5 = IPQueue_obj(int_lambda), ipque_drop(&q5.Q)) // Using lambda to compare elements. + c_autodrop (IPQueue, q1, {ipque_init(), int_less}) // Max priority queue + c_autodrop (IPQueue, minq1, {ipque_init(), int_greater}) // Min priority queue + c_autodrop (IPQueue, q5, {ipque_init(), int_lambda}) // Using lambda to compare elements. { c_forrange (i, n) ipque_push(&q1.Q, data[i]); diff --git a/examples/new_arr.c b/examples/new_arr.c index 598e5323..51955b46 100644 --- a/examples/new_arr.c +++ b/examples/new_arr.c @@ -13,8 +13,7 @@ int main() { int w = 7, h = 5, d = 3; - c_with (carr2_int volume = carr2_int_new_uninit(w, h), - carr2_int_drop(&volume)) + c_autodrop (carr2_int, volume, carr2_int_new_uninit(w, h)) { int *dat = carr2_int_data(&volume); for (size_t i = 0; i < carr2_int_size(&volume); ++i) @@ -30,8 +29,7 @@ int main() puts("\n"); } - c_with (carr3_int volume = carr3_int_new_uninit(w, h, d), - carr3_int_drop(&volume)) + c_autodrop (carr3_int, volume, carr3_int_new_uninit(w, h, d)) { int *dat = carr3_int_data(&volume); for (size_t i = 0; i < carr3_int_size(&volume); ++i) @@ -48,8 +46,7 @@ int main() puts(""); } - c_with (carr2_str text2d = carr2_str_with_size(h, d, cstr_init()), - carr2_str_drop(&text2d)) + c_autodrop (carr2_str, text2d, carr2_str_with_size(h, d, cstr_init())) { cstr_assign(&text2d.data[2][1], "hello"); cstr_assign(&text2d.data[4][0], "world"); diff --git a/examples/prime.c b/examples/prime.c index 287fb69b..d2fc5efa 100644 --- a/examples/prime.c +++ b/examples/prime.c @@ -28,7 +28,7 @@ int main(void) printf("computing prime numbers up to %" c_ZU "\n", n); clock_t t1 = clock(); - c_with (cbits primes = sieveOfEratosthenes(n + 1), cbits_drop(&primes)) { + c_autodrop (cbits, primes, sieveOfEratosthenes(n + 1)) { puts("done"); size_t np = cbits_count(&primes); clock_t t2 = clock(); diff --git a/examples/regex2.c b/examples/regex2.c index 1f656265..6dffc8c4 100644 --- a/examples/regex2.c +++ b/examples/regex2.c @@ -14,7 +14,7 @@ int main() {"!((abc|123)+)!", "!123abcabc!"} }; - c_with (cregex re = cregex_init(), cregex_drop(&re)) + c_auto (cregex, re) c_forrange (i, c_arraylen(s)) { int res = cregex_compile(&re, s[i].pattern, cre_default); diff --git a/examples/regex_replace.c b/examples/regex_replace.c index e6054d9f..13bc9bf0 100644 --- a/examples/regex_replace.c +++ b/examples/regex_replace.c @@ -35,7 +35,7 @@ int main() printf("brack: %s\n", cstr_str(&str)); /* Shows how to compile RE separately */ - c_with (cregex re = cregex_from(pattern, cre_default), cregex_drop(&re)) { + c_autodrop (cregex, re, cregex_from(pattern, cre_default)) { if (cregex_captures(&re) == 0) continue; // break c_with /* European date format. */ |
