diff options
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/advanced.c | 2 | ||||
| -rw-r--r-- | examples/birthday.c | 2 | ||||
| -rw-r--r-- | examples/bits.c | 4 | ||||
| -rw-r--r-- | examples/cpque.c | 6 | ||||
| -rw-r--r-- | examples/csmap_erase.c | 6 | ||||
| -rw-r--r-- | examples/csmap_find.c | 4 | ||||
| -rw-r--r-- | examples/csmap_insert.c | 11 | ||||
| -rw-r--r-- | examples/cstr_match.c | 15 | ||||
| -rw-r--r-- | examples/demos.c | 12 | ||||
| -rw-r--r-- | examples/ex_gauss1.c | 6 | ||||
| -rw-r--r-- | examples/ex_gauss2.c | 4 | ||||
| -rw-r--r-- | examples/inits.c | 10 | ||||
| -rw-r--r-- | examples/list.c | 2 | ||||
| -rw-r--r-- | examples/list_erase.c | 2 | ||||
| -rw-r--r-- | examples/list_splice.c | 4 | ||||
| -rw-r--r-- | examples/mapmap.c | 2 | ||||
| -rw-r--r-- | examples/mmap.c | 2 | ||||
| -rw-r--r-- | examples/multimap.c | 2 | ||||
| -rw-r--r-- | examples/phonebook.c | 4 | ||||
| -rw-r--r-- | examples/prime.c | 2 | ||||
| -rw-r--r-- | examples/priority.c | 2 | ||||
| -rw-r--r-- | examples/queue.c | 2 | ||||
| -rw-r--r-- | examples/replace.c | 8 | ||||
| -rw-r--r-- | examples/stack.c | 8 | ||||
| -rw-r--r-- | examples/stc_astar.c | 6 | ||||
| -rw-r--r-- | examples/svmap.c | 2 |
26 files changed, 72 insertions, 58 deletions
diff --git a/examples/advanced.c b/examples/advanced.c index 1d8a8cf2..147ba041 100644 --- a/examples/advanced.c +++ b/examples/advanced.c @@ -41,7 +41,7 @@ using_cmap_keydef(vk, Viking, int, vikingraw_equals, vikingraw_hash, int main() { - c_fordefer (cmap_vk vikings = cmap_vk_init(), cmap_vk_del(&vikings)) { + c_forvar (cmap_vk vikings = cmap_vk_init(), cmap_vk_del(&vikings)) { c_emplace(cmap_vk, vikings, { { {"Einar", "Norway"}, 20}, { {"Olaf", "Denmark"}, 24}, diff --git a/examples/birthday.c b/examples/birthday.c index 80802572..0dbb544a 100644 --- a/examples/birthday.c +++ b/examples/birthday.c @@ -35,7 +35,7 @@ void test_distribution(void) stc64_t rng = stc64_init(seed);
const size_t N = 1ull << BITS ;
- c_fordefer (cmap_x map = cmap_x_init(), cmap_x_del(&map)) {
+ c_forvar (cmap_x map = cmap_x_init(), cmap_x_del(&map)) {
c_forrange (N) {
uint64_t k = stc64_rand(&rng);
cmap_x_emplace(&map, k & 0xf, 0).ref->second += 1;
diff --git a/examples/bits.c b/examples/bits.c index e478321c..84bdbb6b 100644 --- a/examples/bits.c +++ b/examples/bits.c @@ -3,7 +3,7 @@ int main()
{
- c_fordefer (cbits set = cbits_with_size(23, true), cbits_del(&set)) {
+ c_forvar (cbits set = cbits_with_size(23, true), cbits_del(&set)) {
printf("count %zu, %zu\n", cbits_count(set), set.size);
cbits s1 = cbits_from_str("1110100110111");
char buf[256];
@@ -35,7 +35,7 @@ int main() printf("%d", cbits_test(set, i));
puts("");
- c_fordefer (cbits s2 = cbits_clone(set), cbits_del(&s2)) {
+ c_forvar (cbits s2 = cbits_clone(set), cbits_del(&s2)) {
cbits_flip_all(&s2);
cbits_set(&s2, 16);
cbits_set(&s2, 17);
diff --git a/examples/cpque.c b/examples/cpque.c index 937b7ac9..3c22fdfd 100644 --- a/examples/cpque.c +++ b/examples/cpque.c @@ -31,9 +31,9 @@ int main() {
const int data[] = {1,8,5,6,3,4,0,9,7,2};
- c_fordefer (cpque_imax q = cpque_imax_init(), cpque_imax_del(&q)) // init() and defered del()
- c_fordefer (cpque_imin q2 = cpque_imin_init(), cpque_imin_del(&q2))
- c_fordefer (cpque_imix q3 = cpque_imix_init(), cpque_imix_del(&q3))
+ c_forvar (cpque_imax q = cpque_imax_init(), cpque_imax_del(&q)) // init() and defered del()
+ c_forvar (cpque_imin q2 = cpque_imin_init(), cpque_imin_del(&q2))
+ c_forvar (cpque_imix q3 = cpque_imix_init(), cpque_imix_del(&q3))
{
c_forrange (n, c_arraylen(data))
cpque_imax_push(&q, n);
diff --git a/examples/csmap_erase.c b/examples/csmap_erase.c index 58a90d4b..35afbe3a 100644 --- a/examples/csmap_erase.c +++ b/examples/csmap_erase.c @@ -15,7 +15,7 @@ void printmap(csmap_my map) int main()
{
- c_fordefer (csmap_my m1 = csmap_my_init(), csmap_my_del(&m1))
+ c_forvar (csmap_my m1 = csmap_my_init(), csmap_my_del(&m1))
{
// Fill in some data to test with, one at a time
csmap_my_emplace(&m1, 1, "A");
@@ -32,7 +32,7 @@ int main() printmap(m1);
}
- c_fordefer (csmap_my m2 = csmap_my_init(), csmap_my_del(&m2))
+ c_forvar (csmap_my m2 = csmap_my_init(), csmap_my_del(&m2))
{
// Fill in some data to test with, one at a time, using emplace
c_emplace(csmap_my, m2, {
@@ -54,7 +54,7 @@ int main() printmap(m2);
}
- c_fordefer (csmap_my m3 = csmap_my_init(), csmap_my_del(&m3))
+ c_forvar (csmap_my m3 = csmap_my_init(), csmap_my_del(&m3))
{
// Fill in some data to test with, one at a time, using emplace
csmap_my_emplace(&m3, 1, "red");
diff --git a/examples/csmap_find.c b/examples/csmap_find.c index 4fcedb43..314e702e 100644 --- a/examples/csmap_find.c +++ b/examples/csmap_find.c @@ -38,8 +38,8 @@ void findit(csmap_istr c, csmap_istr_key_t val) { int main()
{
- c_fordefer (csmap_istr m1 = csmap_istr_init(), csmap_istr_del(&m1))
- c_fordefer (cvec_istr v = cvec_istr_init(), cvec_istr_del(&v)) {
+ c_forvar (csmap_istr m1 = csmap_istr_init(), csmap_istr_del(&m1))
+ c_forvar (cvec_istr v = cvec_istr_init(), cvec_istr_del(&v)) {
c_emplace(csmap_istr, m1, { { 40, "Zr" }, { 45, "Rh" } });
puts("The starting map m1 is (key, value):");
print_collection_csmap_istr(m1);
diff --git a/examples/csmap_insert.c b/examples/csmap_insert.c index 0f32e586..684d499a 100644 --- a/examples/csmap_insert.c +++ b/examples/csmap_insert.c @@ -25,7 +25,7 @@ void print_istr(csmap_istr map) { int main()
{
// insert single values
- c_fordefer (csmap_ii m1 = csmap_ii_init(), csmap_ii_del(&m1)) {
+ c_forvar (csmap_ii m1 = csmap_ii_init(), csmap_ii_del(&m1)) {
csmap_ii_insert(&m1, 1, 10);
csmap_ii_insert(&m1, 2, 20);
@@ -52,9 +52,8 @@ int main() }
// The templatized version inserting a jumbled range
- // c_fordefer_var(type, v) is shorthand for: c_fordefer (type v = type_init(), type_del(&v))
- c_fordefer (csmap_ii m2 = csmap_ii_init(), csmap_ii_del(&m2))
- c_fordefer (cvec_ii v = cvec_ii_init(), cvec_ii_del(&v)) {
+ c_forvar (csmap_ii m2 = csmap_ii_init(), csmap_ii_del(&m2))
+ c_forvar (cvec_ii v = cvec_ii_init(), cvec_ii_del(&v)) {
cvec_ii_push_back(&v, (cvec_ii_value_t){43, 294});
cvec_ii_push_back(&v, (cvec_ii_value_t){41, 262});
cvec_ii_push_back(&v, (cvec_ii_value_t){45, 330});
@@ -73,7 +72,7 @@ int main() }
// The templatized versions move-constructing elements
- c_fordefer (csmap_istr m3 = csmap_istr_init(), csmap_istr_del(&m3)) {
+ c_forvar (csmap_istr m3 = csmap_istr_init(), csmap_istr_del(&m3)) {
csmap_istr_value_t ip1 = {475, cstr_lit("blue")}, ip2 = {510, cstr_lit("green")};
// single element
@@ -88,7 +87,7 @@ int main() puts("");
}
- c_fordefer (csmap_ii m4 = csmap_ii_init(), csmap_ii_del(&m4)) {
+ c_forvar (csmap_ii m4 = csmap_ii_init(), csmap_ii_del(&m4)) {
// Insert the elements from an initializer_list
c_emplace(csmap_ii, m4, { { 4, 44 }, { 2, 22 }, { 3, 33 }, { 1, 11 }, { 5, 55 } });
puts("After initializer_list insertion, m4 contains:");
diff --git a/examples/cstr_match.c b/examples/cstr_match.c new file mode 100644 index 00000000..07a6b8d4 --- /dev/null +++ b/examples/cstr_match.c @@ -0,0 +1,15 @@ +#include <stc/cstr.h>
+#include <stdio.h>
+
+int main()
+{
+ c_forvar (cstr ss = cstr_lit("The quick brown fox jumps over the lazy dog.JPG"), cstr_del(&ss)) {
+ size_t pos = cstr_find_n(ss, "brown", 0, 5);
+ printf("%zu [%s]\n", pos, pos == cstr_npos ? "<NULL>" : &ss.str[pos]);
+ printf("iequals: %d\n", cstr_iequals(ss, "the quick brown fox jumps over the lazy dog.jpg"));
+ printf("icontains: %d\n", cstr_icontains(ss, "uMPS Ove"));
+ printf("ibegins_with: %d\n", cstr_ibegins_with(ss, "The Quick Brown"));
+ printf("iends_with: %d\n", cstr_iends_with(ss, ".Jpg"));
+ printf("ends_with: %d\n", cstr_ends_with(ss, ".JPG"));
+ }
+}
\ No newline at end of file diff --git a/examples/demos.c b/examples/demos.c index a9fad4ab..bb4deb22 100644 --- a/examples/demos.c +++ b/examples/demos.c @@ -9,7 +9,7 @@ void stringdemo1()
{
printf("\nSTRINGDEMO1\n");
- c_fordefer (cstr cs = cstr_from("one-nine-three-seven-five"), cstr_del(&cs))
+ c_forvar (cstr cs = cstr_from("one-nine-three-seven-five"), cstr_del(&cs))
{
printf("%s.\n", cs.str);
@@ -40,7 +40,7 @@ using_cvec(ix, int64_t); // ix is just an example tag name. void vectordemo1()
{
printf("\nVECTORDEMO1\n");
- c_fordefer (cvec_ix bignums = cvec_ix_with_capacity(100), cvec_ix_del(&bignums))
+ c_forvar (cvec_ix bignums = cvec_ix_with_capacity(100), cvec_ix_del(&bignums))
{
cvec_ix_reserve(&bignums, 100);
for (size_t i = 10; i <= 100; i += 10)
@@ -64,7 +64,7 @@ using_cvec_str(); void vectordemo2()
{
printf("\nVECTORDEMO2\n");
- c_fordefer (cvec_str names = cvec_str_init(), cvec_str_del(&names)) {
+ c_forvar (cvec_str names = cvec_str_init(), cvec_str_del(&names)) {
cvec_str_emplace_back(&names, "Mary");
cvec_str_emplace_back(&names, "Joe");
cvec_str_emplace_back(&names, "Chris");
@@ -82,8 +82,8 @@ using_clist(ix, int); void listdemo1()
{
printf("\nLISTDEMO1\n");
- c_fordefer (clist_ix nums = clist_ix_init(), clist_ix_del(&nums))
- c_fordefer (clist_ix nums2 = clist_ix_init(), clist_ix_del(&nums2))
+ c_forvar (clist_ix nums = clist_ix_init(), clist_ix_del(&nums))
+ c_forvar (clist_ix nums2 = clist_ix_init(), clist_ix_del(&nums2))
{
for (int i = 0; i < 10; ++i)
clist_ix_push_back(&nums, i);
@@ -142,7 +142,7 @@ using_cmap_strkey(si, int); // Shorthand macro for the general using_cmap expans void mapdemo2()
{
printf("\nMAPDEMO2\n");
- c_fordefer (cmap_si nums = cmap_si_init(), cmap_si_del(&nums))
+ c_forvar (cmap_si nums = cmap_si_init(), cmap_si_del(&nums))
{
cmap_si_emplace_or_assign(&nums, "Hello", 64);
cmap_si_emplace_or_assign(&nums, "Groovy", 121);
diff --git a/examples/ex_gauss1.c b/examples/ex_gauss1.c index d44c2b4e..1365d27c 100644 --- a/examples/ex_gauss1.c +++ b/examples/ex_gauss1.c @@ -30,8 +30,8 @@ int main() stc64_normalf_t dist = stc64_normalf_init(Mean, StdDev);
// Create and init histogram vec and map with defered destructors:
- c_fordefer (cvec_e vhist = cvec_e_init(), cvec_e_del(&vhist))
- c_fordefer (cmap_i mhist = cmap_i_init(), cmap_i_del(&mhist))
+ c_forvar (cvec_e vhist = cvec_e_init(), cvec_e_del(&vhist))
+ c_forvar (cmap_i mhist = cmap_i_init(), cmap_i_del(&mhist))
{
c_forrange (N) {
int index = (int) round( stc64_normalf(&rng, &dist) );
@@ -45,7 +45,7 @@ int main() cvec_e_sort(&vhist);
// Print the gaussian bar chart
- c_fordefer (cstr bar = cstr_null, cstr_del(&bar))
+ c_forvar (cstr bar = cstr_null, cstr_del(&bar))
c_foreach (i, cvec_e, vhist) {
size_t n = (size_t) (i.ref->second * StdDev * Scale * 2.5 / (float)N);
if (n > 0) {
diff --git a/examples/ex_gauss2.c b/examples/ex_gauss2.c index 23d8dd7a..553846aa 100644 --- a/examples/ex_gauss2.c +++ b/examples/ex_gauss2.c @@ -21,8 +21,8 @@ int main() stc64_normalf_t dist = stc64_normalf_init(Mean, StdDev);
// Create and init histogram map with defered destruct
- c_fordefer (csmap_i mhist = csmap_i_init(), csmap_i_del(&mhist))
- c_fordefer (cstr bar = cstr_init(), cstr_del(&bar))
+ c_forvar (csmap_i mhist = csmap_i_init(), csmap_i_del(&mhist))
+ c_forvar (cstr bar = cstr_init(), cstr_del(&bar))
{
c_forrange (N) {
int index = (int) round( stc64_normalf(&rng, &dist) );
diff --git a/examples/inits.c b/examples/inits.c index 91f5c3c1..40e89139 100644 --- a/examples/inits.c +++ b/examples/inits.c @@ -23,7 +23,7 @@ int main(void) {
// CVEC FLOAT / PRIORITY QUEUE
- c_fordefer (cvec_f floats = cvec_f_init(), cvec_f_del(&floats)) {
+ c_forvar (cvec_f floats = cvec_f_init(), cvec_f_del(&floats)) {
c_emplace(cvec_f, floats, {4.0f, 2.0f, 5.0f, 3.0f, 1.0f});
c_foreach (i, cvec_f, floats) printf("%.1f ", *i.ref);
@@ -45,7 +45,7 @@ int main(void) // CMAP ID
int year = 2020;
- c_fordefer (cmap_id idnames = cmap_id_init(), cmap_id_del(&idnames)) {
+ c_forvar (cmap_id idnames = cmap_id_init(), cmap_id_del(&idnames)) {
cmap_id_emplace(&idnames, 100, "Hello");
cmap_id_insert(&idnames, 110, cstr_from("World"));
cmap_id_insert(&idnames, 120, cstr_from_fmt("Howdy, -%d-", year));
@@ -57,7 +57,7 @@ int main(void) // CMAP CNT
- c_fordefer (cmap_cnt countries = cmap_cnt_init(), cmap_cnt_del(&countries)) {
+ c_forvar (cmap_cnt countries = cmap_cnt_init(), cmap_cnt_del(&countries)) {
c_emplace(cmap_cnt, countries, {
{"Norway", 100},
{"Denmark", 50},
@@ -80,7 +80,7 @@ int main(void) // CVEC PAIR
- c_fordefer (cvec_ip pairs1 = cvec_ip_init(), cvec_ip_del(&pairs1)) {
+ c_forvar (cvec_ip pairs1 = cvec_ip_init(), cvec_ip_del(&pairs1)) {
c_emplace (cvec_ip, pairs1, {{5, 6}, {3, 4}, {1, 2}, {7, 8}});
cvec_ip_sort(&pairs1);
@@ -91,7 +91,7 @@ int main(void) // CLIST PAIR
- c_fordefer (clist_ip pairs2 = clist_ip_init(), clist_ip_del(&pairs2)) {
+ c_forvar (clist_ip pairs2 = clist_ip_init(), clist_ip_del(&pairs2)) {
c_emplace(clist_ip, pairs2, {{5, 6}, {3, 4}, {1, 2}, {7, 8}});
clist_ip_sort(&pairs2);
diff --git a/examples/list.c b/examples/list.c index e4b027a9..327b477c 100644 --- a/examples/list.c +++ b/examples/list.c @@ -8,7 +8,7 @@ int main() { int k;
const int n = 2000000;
- c_fordefer (clist_fx list = clist_fx_init(), clist_fx_del(&list)) {
+ c_forvar (clist_fx list = clist_fx_init(), clist_fx_del(&list)) {
stc64_t rng = stc64_init(1234);
stc64_uniformf_t dist = stc64_uniformf_init(100.0f, n);
int m = 0;
diff --git a/examples/list_erase.c b/examples/list_erase.c index a9d2b9d3..523ee0b8 100644 --- a/examples/list_erase.c +++ b/examples/list_erase.c @@ -6,7 +6,7 @@ using_clist(i, int); int main ()
{
- c_fordefer (clist_i L = clist_i_init(), clist_i_del(&L))
+ c_forvar (clist_i L = clist_i_init(), clist_i_del(&L))
{
c_emplace(clist_i, L, {10, 20, 30, 40, 50});
// 10 20 30 40 50
diff --git a/examples/list_splice.c b/examples/list_splice.c index f80ac860..8379dbde 100644 --- a/examples/list_splice.c +++ b/examples/list_splice.c @@ -14,8 +14,8 @@ void print_ilist(const char* s, clist_i list) int main () { - c_fordefer (clist_i list1 = clist_i_init(), clist_i_del(&list1)) - c_fordefer (clist_i list2 = clist_i_init(), clist_i_del(&list2)) + c_forvar (clist_i list1 = clist_i_init(), clist_i_del(&list1)) + c_forvar (clist_i list2 = clist_i_init(), clist_i_del(&list2)) { c_emplace(clist_i, list1, {1, 2, 3, 4, 5}); c_emplace(clist_i, list2, {10, 20, 30, 40, 50}); diff --git a/examples/mapmap.c b/examples/mapmap.c index 21b2cac9..e582ab64 100644 --- a/examples/mapmap.c +++ b/examples/mapmap.c @@ -9,7 +9,7 @@ using_cmap_str(); using_cmap_strkey(cfg, cmap_str, cmap_str_del, c_no_clone);
int main(void) {
- c_fordefer (cmap_cfg cfg = cmap_cfg_init(), cmap_cfg_del(&cfg)) {
+ c_forvar (cmap_cfg cfg = cmap_cfg_init(), cmap_cfg_del(&cfg)) {
cmap_str init = cmap_str_init();
cmap_str_emplace(&cmap_cfg_insert(&cfg, cstr_from("user"), init).ref->second, "name", "Joe");
cmap_str_emplace(&cmap_cfg_insert(&cfg, cstr_from("user"), init).ref->second, "groups", "proj1,proj3");
diff --git a/examples/mmap.c b/examples/mmap.c index 58511c37..04e501aa 100644 --- a/examples/mmap.c +++ b/examples/mmap.c @@ -26,7 +26,7 @@ void insert(csmap_m* mmap, int key, const char* str) int main()
{
- c_fordefer (csmap_m mmap = csmap_m_init(), csmap_m_del(&mmap))
+ c_forvar (csmap_m mmap = csmap_m_init(), csmap_m_del(&mmap))
{
// list-initialize
struct {int i; const char* s;} vals[] = {{2, "foo"}, {2, "bar"}, {3, "baz"}, {1, "abc"}, {5, "def"}};
diff --git a/examples/multimap.c b/examples/multimap.c index 4b192e29..03d4712d 100644 --- a/examples/multimap.c +++ b/examples/multimap.c @@ -55,7 +55,7 @@ using_csmap_strkey(OL, clist_OL, clist_OL_del, c_no_clone); int main()
{
// Define the multimap with destructor defered to when block is completed.
- c_fordefer (csmap_OL multimap = csmap_OL_init(), csmap_OL_del(&multimap))
+ c_forvar (csmap_OL multimap = csmap_OL_init(), csmap_OL_del(&multimap))
{
clist_OL empty = clist_OL_init();
diff --git a/examples/phonebook.c b/examples/phonebook.c index e755923f..a69e701b 100644 --- a/examples/phonebook.c +++ b/examples/phonebook.c @@ -39,14 +39,14 @@ int main(int argc, char **argv) {
c_static_assert(3 == 3, "hello");
- c_fordefer (cset_str names = cset_str_init(), cset_str_del(&names)) {
+ c_forvar (cset_str names = cset_str_init(), cset_str_del(&names)) {
c_emplace (cset_str, names, {"Hello", "Cool", "True"});
c_foreach (i, cset_str, names) printf("%s ", i.ref->str);
puts("");
}
bool erased;
- c_fordefer (cmap_str phone_book = cmap_str_init(), cmap_str_del(&phone_book)) {
+ c_forvar (cmap_str phone_book = cmap_str_init(), cmap_str_del(&phone_book)) {
c_emplace (cmap_str, phone_book, {
{"Lilia Friedman", "(892) 670-4739"},
{"Tariq Beltran", "(489) 600-7575"},
diff --git a/examples/prime.c b/examples/prime.c index 67f92c7b..7ac19eb0 100644 --- a/examples/prime.c +++ b/examples/prime.c @@ -27,7 +27,7 @@ int main(void) printf("computing prime numbers up to %zu\n", n);
clock_t t1 = clock();
- c_fordefer (cbits primes = sieveOfEratosthenes(n + 1), cbits_del(&primes)) {
+ c_forvar (cbits primes = sieveOfEratosthenes(n + 1), cbits_del(&primes)) {
size_t np = cbits_count(primes);
clock_t t2 = clock();
diff --git a/examples/priority.c b/examples/priority.c index e0865054..ee64bf42 100644 --- a/examples/priority.c +++ b/examples/priority.c @@ -13,7 +13,7 @@ int main() { size_t N = 10000000;
stc64_t rng = stc64_init(time(NULL));
stc64_uniform_t dist = stc64_uniform_init(0, N * 10);
- c_fordefer (cpque_i heap = cpque_i_init(), cpque_i_del(&heap))
+ c_forvar (cpque_i heap = cpque_i_init(), cpque_i_del(&heap))
{
// Push ten million random numbers to priority queue
c_forrange (N)
diff --git a/examples/queue.c b/examples/queue.c index d2687507..1e96b53a 100644 --- a/examples/queue.c +++ b/examples/queue.c @@ -17,7 +17,7 @@ int main() { stc64_t rng = stc64_init(1234);
dist = stc64_uniform_init(0, n);
- c_fordefer (cqueue_i queue = cqueue_i_init(), cqueue_i_del(&queue))
+ c_forvar (cqueue_i queue = cqueue_i_init(), cqueue_i_del(&queue))
{
// Push ten million random numbers onto the queue.
c_forrange (n)
diff --git a/examples/replace.c b/examples/replace.c index 69928917..cfbcc1e5 100644 --- a/examples/replace.c +++ b/examples/replace.c @@ -13,7 +13,7 @@ int main () // Ustring positions: 0123456789*123456789*12345
cstr s = cstr_from(base); // "this is a test string."
cstr m = cstr_clone(s);
- c_fordefer ((cstr_del(&s), cstr_del(&m))) {
+ c_fordefer (cstr_del(&s), cstr_del(&m)) {
cstr_append(&m, m.str);
cstr_append(&m, m.str);
printf("%s\n", m.str);
@@ -25,8 +25,8 @@ int main () cstr_replace(&s, 8, 10, "just a"); // "this is just a phrase." (3)
printf("(3) %s\n", s.str);
cstr_replace_n(&s, 8, 6,"a shorty", 7); // "this is a short phrase." (4)
- printf("(4) %s\n", s.str);
+ printf("(4) %s\n", s.str);
cstr_replace(&s, 22, 1, "!!!"); // "this is a short phrase!!!" (5)
- printf("(5) %s\n", s.str);
- }
+ printf("(5) %s\n", s.str);
+ }
}
diff --git a/examples/stack.c b/examples/stack.c index 83c8cc08..7ae53e0f 100644 --- a/examples/stack.c +++ b/examples/stack.c @@ -11,16 +11,16 @@ using_cstack(c, cvec_c); int main() {
cstack_i stack = cstack_i_init();
cstack_c chars = cstack_c_init();
- c_fordefer ((cstack_i_del(&stack), cstack_c_del(&chars)))
+ c_fordefer (cstack_i_del(&stack), cstack_c_del(&chars))
{
- c_forrange (i, int, 101)
+ c_forrange (i, int, 101)
cstack_i_push(&stack, i*i);
printf("%d\n", *cstack_i_top(&stack));
- c_forrange (i, int, 90)
+ c_forrange (i, int, 90)
cstack_i_pop(&stack);
-
+
c_foreach (i, cstack_i, stack)
printf(" %d", *i.ref);
puts("");
diff --git a/examples/stc_astar.c b/examples/stc_astar.c index ecca939f..6122aad4 100644 --- a/examples/stc_astar.c +++ b/examples/stc_astar.c @@ -83,9 +83,9 @@ astar(cstr maze, int width) cpque_pnt frontier = cpque_pnt_init();
csmap_step came_from = csmap_step_init();
csmap_cost cost_so_far = csmap_cost_init();
- c_fordefer ((cpque_pnt_del(&frontier),
- csmap_step_del(&came_from),
- csmap_cost_del(&cost_so_far)))
+ c_fordefer (cpque_pnt_del(&frontier),
+ csmap_step_del(&came_from),
+ csmap_cost_del(&cost_so_far))
{
cpque_pnt_push(&frontier, start);
csmap_cost_insert(&cost_so_far, start, 0);
diff --git a/examples/svmap.c b/examples/svmap.c index 3087706e..8cacf95a 100644 --- a/examples/svmap.c +++ b/examples/svmap.c @@ -9,7 +9,7 @@ int main() { csview fox = c_lit("The quick brown fox jumps over the lazy dog.");
printf("\"%s\", length=%zu\n", fox.str, fox.size);
- c_fordefer (cmap_si frequencies = cmap_si_init(), cmap_si_del(&frequencies))
+ c_forvar (cmap_si frequencies = cmap_si_init(), cmap_si_del(&frequencies))
{
// Non-emplace: cstr element API
cmap_si_insert(&frequencies, cstr_lit("thousand"), 1000);
|
