summaryrefslogtreecommitdiffhomepage
path: root/examples
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2022-05-30 14:22:44 +0200
committerTyge Løvset <[email protected]>2022-05-30 14:22:44 +0200
commit58bb58e7980d1eae175ed66dbe873893a05ab81e (patch)
tree2756b2d1b62264c34a6d40265dc85f07eb2f1112 /examples
parentb28d3fa7c3b9233ca485014744bf84e6c4f5a1d3 (diff)
downloadSTC-modified-58bb58e7980d1eae175ed66dbe873893a05ab81e.tar.gz
STC-modified-58bb58e7980d1eae175ed66dbe873893a05ab81e.zip
Done refactoring:
- Non-templated types (cstr, csview, cbits, crandom) have no longer default static linking. Now i_header is defined, i.e. files are as headers only. ==> Define `i_implement` before file inclusion. Still possible to do static linkage by defining `i_static` before inclusion or global STC_STATIC. - Templated containers still have static linkage by default. - Renamed csview_substr(), csview_slice() to csview_substr_ex(), csview_slice_ex(). Added simpler inlined csview_substr(), csview_slice().
Diffstat (limited to 'examples')
-rw-r--r--examples/arc_containers.c1
-rw-r--r--examples/astar.c2
-rw-r--r--examples/birthday.c1
-rw-r--r--examples/bits.c1
-rw-r--r--examples/bits2.c1
-rw-r--r--examples/books.c2
-rw-r--r--examples/box.c1
-rw-r--r--examples/city.c1
-rw-r--r--examples/complex.c1
-rw-r--r--examples/convert.c1
-rw-r--r--examples/csmap_erase.c1
-rw-r--r--examples/csmap_find.c1
-rw-r--r--examples/csmap_insert.c2
-rw-r--r--examples/cstr_match.c1
-rw-r--r--examples/demos.c1
-rw-r--r--examples/gauss1.c3
-rw-r--r--examples/gauss2.c2
-rw-r--r--examples/hashmap.c2
-rw-r--r--examples/inits.c2
-rw-r--r--examples/list.c1
-rw-r--r--examples/mapmap.c2
-rw-r--r--examples/mmap.c1
-rw-r--r--examples/multimap.c2
-rw-r--r--examples/music_arc.c2
-rw-r--r--examples/new_arr.c2
-rw-r--r--examples/new_deq.c1
-rw-r--r--examples/new_list.c2
-rw-r--r--examples/new_map.c1
-rw-r--r--examples/new_queue.c1
-rw-r--r--examples/new_smap.c1
-rw-r--r--examples/new_sptr.c1
-rw-r--r--examples/new_vec.c1
-rw-r--r--examples/person_arc.c1
-rw-r--r--examples/phonebook.c2
-rw-r--r--examples/prime.c2
-rw-r--r--examples/priority.c1
-rw-r--r--examples/queue.c1
-rw-r--r--examples/random.c1
-rw-r--r--examples/rawptr_elements.c1
-rw-r--r--examples/read.c1
-rw-r--r--examples/regex1.c1
-rw-r--r--examples/regex2.c3
-rw-r--r--examples/regex_match.c6
-rw-r--r--examples/replace.c2
-rw-r--r--examples/splitstr.c4
-rw-r--r--examples/sso_map.c2
-rw-r--r--examples/sso_substr.c14
-rw-r--r--examples/sview_split.c2
-rw-r--r--examples/unordered_set.c1
-rw-r--r--examples/utf8replace_c.c1
-rw-r--r--examples/vikings.c2
-rw-r--r--examples/words.c1
52 files changed, 64 insertions, 30 deletions
diff --git a/examples/arc_containers.c b/examples/arc_containers.c
index 0ee2cbeb..1fe227f7 100644
--- a/examples/arc_containers.c
+++ b/examples/arc_containers.c
@@ -1,5 +1,6 @@
// Create a stack and a list of shared pointers to maps,
// and demonstrate sharing and cloning of maps.
+#define i_static
#include <stc/cstr.h>
#define i_type Map
#define i_key_str // strings
diff --git a/examples/astar.c b/examples/astar.c
index bce03716..5bcbe7e9 100644
--- a/examples/astar.c
+++ b/examples/astar.c
@@ -4,7 +4,7 @@
// This is a reimplementation of the CTL example to STC:
// https://github.com/glouw/ctl/blob/master/examples/astar.c
// https://www.redblobgames.com/pathfinding/a-star/introduction.html
-
+#define i_implement
#include <stc/cstr.h>
#include <stdio.h>
diff --git a/examples/birthday.c b/examples/birthday.c
index 7c95f961..15d85e0c 100644
--- a/examples/birthday.c
+++ b/examples/birthday.c
@@ -1,6 +1,7 @@
#include <math.h>
#include <stdio.h>
#include <time.h>
+#define i_implement
#include <stc/crandom.h>
#define i_tag ic
diff --git a/examples/bits.c b/examples/bits.c
index 8888f73e..051beb02 100644
--- a/examples/bits.c
+++ b/examples/bits.c
@@ -1,4 +1,5 @@
#include <stdio.h>
+#define i_implement
#include <stc/cbits.h>
int main()
diff --git a/examples/bits2.c b/examples/bits2.c
index 81e28d60..af87df42 100644
--- a/examples/bits2.c
+++ b/examples/bits2.c
@@ -3,6 +3,7 @@
#define i_type Bits
#define i_len 80 // enable fixed bitset on the stack
+#define i_implement
#include <stc/cbits.h>
int main()
diff --git a/examples/books.c b/examples/books.c
index eb644ba7..de724a19 100644
--- a/examples/books.c
+++ b/examples/books.c
@@ -1,5 +1,5 @@
// https://doc.rust-lang.org/std/collections/struct.HashMap.html
-
+#define i_implement
#include <stc/cstr.h>
#define i_key_str
#define i_val_str
diff --git a/examples/box.c b/examples/box.c
index 2f82a694..4502f479 100644
--- a/examples/box.c
+++ b/examples/box.c
@@ -1,4 +1,5 @@
/* cbox: heap allocated boxed type */
+#define i_implement
#include <stc/cstr.h>
typedef struct { cstr name, last; } Person;
diff --git a/examples/city.c b/examples/city.c
index fb863e3c..8ee1576f 100644
--- a/examples/city.c
+++ b/examples/city.c
@@ -1,3 +1,4 @@
+#define i_implement
#include <stc/cstr.h>
typedef struct {
diff --git a/examples/complex.c b/examples/complex.c
index 584343be..c5ac9882 100644
--- a/examples/complex.c
+++ b/examples/complex.c
@@ -1,3 +1,4 @@
+#define i_implement
#include <stc/cstr.h>
void check_drop(float* v) {printf("destroy %g\n", *v);}
diff --git a/examples/convert.c b/examples/convert.c
index a17e41f6..48ba2ecf 100644
--- a/examples/convert.c
+++ b/examples/convert.c
@@ -1,3 +1,4 @@
+#define i_implement
#include <stc/cstr.h>
#define i_key_str
diff --git a/examples/csmap_erase.c b/examples/csmap_erase.c
index 09d28d78..b1dbaada 100644
--- a/examples/csmap_erase.c
+++ b/examples/csmap_erase.c
@@ -1,5 +1,6 @@
// map_erase.c
// From C++ example: https://docs.microsoft.com/en-us/cpp/standard-library/map-class?view=msvc-160#example-16
+#define i_implement
#include <stc/cstr.h>
#include <stdio.h>
diff --git a/examples/csmap_find.c b/examples/csmap_find.c
index c3047110..7fac5bc2 100644
--- a/examples/csmap_find.c
+++ b/examples/csmap_find.c
@@ -1,5 +1,6 @@
// This implements the c++ std::map::find example at:
// https://docs.microsoft.com/en-us/cpp/standard-library/map-class?view=msvc-160#example-17
+#define i_implement
#include <stc/cstr.h>
#define i_key int
diff --git a/examples/csmap_insert.c b/examples/csmap_insert.c
index 07fba9ed..24f536e9 100644
--- a/examples/csmap_insert.c
+++ b/examples/csmap_insert.c
@@ -1,5 +1,5 @@
+#define i_implement
#include <stc/cstr.h>
-#include <stdio.h>
// This implements the std::map insert c++ example at:
// https://docs.microsoft.com/en-us/cpp/standard-library/map-class?view=msvc-160#example-19
diff --git a/examples/cstr_match.c b/examples/cstr_match.c
index 637fa7f9..a110e49a 100644
--- a/examples/cstr_match.c
+++ b/examples/cstr_match.c
@@ -1,3 +1,4 @@
+#define i_implement
#include <stc/cstr.h>
#include <stc/csview.h>
#include <stdio.h>
diff --git a/examples/demos.c b/examples/demos.c
index c0cecac2..29bfba66 100644
--- a/examples/demos.c
+++ b/examples/demos.c
@@ -1,3 +1,4 @@
+#define i_implement
#include <stc/cstr.h>
void stringdemo1()
diff --git a/examples/gauss1.c b/examples/gauss1.c
index 081a4a73..da58c86e 100644
--- a/examples/gauss1.c
+++ b/examples/gauss1.c
@@ -1,7 +1,8 @@
-#include <stdio.h>
#include <time.h>
#include <math.h>
+#define i_implement
#include <stc/crandom.h>
+#define i_implement
#include <stc/cstr.h>
// Declare int -> int hashmap. Uses typetag 'ii' for ints.
diff --git a/examples/gauss2.c b/examples/gauss2.c
index 5ded4714..496c43e1 100644
--- a/examples/gauss2.c
+++ b/examples/gauss2.c
@@ -1,6 +1,8 @@
#include <stdio.h>
#include <time.h>
+#define i_implement
#include <stc/crandom.h>
+#define i_implement
#include <stc/cstr.h>
// Declare int -> int sorted map.
diff --git a/examples/hashmap.c b/examples/hashmap.c
index 9ff019e6..62f20079 100644
--- a/examples/hashmap.c
+++ b/examples/hashmap.c
@@ -1,5 +1,5 @@
// https://doc.rust-lang.org/rust-by-example/std/hash.html
-
+#define i_implement
#include <stc/cstr.h>
#define i_key_str
#define i_val_str
diff --git a/examples/inits.c b/examples/inits.c
index ae64f6ec..1c904dda 100644
--- a/examples/inits.c
+++ b/examples/inits.c
@@ -1,4 +1,4 @@
-#include <stdio.h>
+#define i_implement
#include <stc/cstr.h>
#define i_key int
diff --git a/examples/list.c b/examples/list.c
index 1b3ccdba..a0dbd49f 100644
--- a/examples/list.c
+++ b/examples/list.c
@@ -1,5 +1,6 @@
#include <stdio.h>
#include <time.h>
+#define i_implement
#include <stc/crandom.h>
#define i_val double
diff --git a/examples/mapmap.c b/examples/mapmap.c
index ccf09314..9ac22371 100644
--- a/examples/mapmap.c
+++ b/examples/mapmap.c
@@ -1,5 +1,5 @@
// unordered_map<string, unordered_map<string, string>>:
-
+#define i_implement
#include <stc/cstr.h>
#define i_type People
#define i_key_str
diff --git a/examples/mmap.c b/examples/mmap.c
index 16b5d2df..4754656f 100644
--- a/examples/mmap.c
+++ b/examples/mmap.c
@@ -2,6 +2,7 @@
// https://en.cppreference.com/w/cpp/container/multimap/insert
// Multimap entries
+#define i_implement
#include <stc/cstr.h>
#define i_val_str
#include <stc/clist.h>
diff --git a/examples/multimap.c b/examples/multimap.c
index 17181d70..ee118dde 100644
--- a/examples/multimap.c
+++ b/examples/multimap.c
@@ -1,5 +1,5 @@
+#define i_implement
#include <stc/cstr.h>
-#include <stdio.h>
// Olympics multimap example
diff --git a/examples/music_arc.c b/examples/music_arc.c
index 489a136f..b6b59489 100644
--- a/examples/music_arc.c
+++ b/examples/music_arc.c
@@ -1,6 +1,6 @@
// shared_ptr-examples.cpp
// based on https://docs.microsoft.com/en-us/cpp/cpp/how-to-create-and-use-shared-ptr-instances?view=msvc-160
-
+#define i_implement
#include <stc/cstr.h>
struct Song
diff --git a/examples/new_arr.c b/examples/new_arr.c
index 0561764a..d046c835 100644
--- a/examples/new_arr.c
+++ b/examples/new_arr.c
@@ -1,4 +1,4 @@
-#include <stdio.h>
+#define i_implement
#include <stc/cstr.h>
#define i_val int
diff --git a/examples/new_deq.c b/examples/new_deq.c
index 9022c377..f1e872f0 100644
--- a/examples/new_deq.c
+++ b/examples/new_deq.c
@@ -1,3 +1,4 @@
+#define i_implement
#include <stc/cstr.h>
#include <stc/forward.h>
diff --git a/examples/new_list.c b/examples/new_list.c
index 20a64ad3..43556aca 100644
--- a/examples/new_list.c
+++ b/examples/new_list.c
@@ -1,5 +1,5 @@
+#define i_implement
#include <stc/cstr.h>
-#include <stc/forward.h>
forward_clist(clist_i32, int);
forward_clist(clist_pnt, struct Point);
diff --git a/examples/new_map.c b/examples/new_map.c
index 32a4ce68..0882d02f 100644
--- a/examples/new_map.c
+++ b/examples/new_map.c
@@ -1,3 +1,4 @@
+#define i_implement
#include <stc/cstr.h>
#include <stc/forward.h>
diff --git a/examples/new_queue.c b/examples/new_queue.c
index 3dde97f5..86f4227c 100644
--- a/examples/new_queue.c
+++ b/examples/new_queue.c
@@ -1,3 +1,4 @@
+#define i_implement
#include <stc/crandom.h>
#include <stc/forward.h>
#include <stdio.h>
diff --git a/examples/new_smap.c b/examples/new_smap.c
index 38822585..2a885d03 100644
--- a/examples/new_smap.c
+++ b/examples/new_smap.c
@@ -1,3 +1,4 @@
+#define i_implement
#include <stc/cstr.h>
#include <stc/forward.h>
diff --git a/examples/new_sptr.c b/examples/new_sptr.c
index 84f7e075..58f68dae 100644
--- a/examples/new_sptr.c
+++ b/examples/new_sptr.c
@@ -1,3 +1,4 @@
+#define i_implement
#include <stc/cstr.h>
struct Person { cstr name, last; } typedef Person;
diff --git a/examples/new_vec.c b/examples/new_vec.c
index d1fe8728..3f3d5de8 100644
--- a/examples/new_vec.c
+++ b/examples/new_vec.c
@@ -1,3 +1,4 @@
+#define i_implement
#include <stc/cstr.h>
#include <stc/forward.h>
diff --git a/examples/person_arc.c b/examples/person_arc.c
index c77ca315..5ac1e9c2 100644
--- a/examples/person_arc.c
+++ b/examples/person_arc.c
@@ -1,4 +1,5 @@
/* cbox: heap allocated boxed type */
+#define i_implement
#include <stc/cstr.h>
typedef struct { cstr name, last; } Person;
diff --git a/examples/phonebook.c b/examples/phonebook.c
index 26f4ff9e..ab782653 100644
--- a/examples/phonebook.c
+++ b/examples/phonebook.c
@@ -21,7 +21,7 @@
// Program to emulates the phone book.
-#include <stdio.h>
+#define i_implement
#include <stc/cstr.h>
#define i_key_str
diff --git a/examples/prime.c b/examples/prime.c
index cc16603b..92fafde4 100644
--- a/examples/prime.c
+++ b/examples/prime.c
@@ -1,7 +1,7 @@
#include <stdio.h>
#include <math.h>
#include <time.h>
-
+#define i_implement
#include <stc/cbits.h>
cbits sieveOfEratosthenes(size_t n)
diff --git a/examples/priority.c b/examples/priority.c
index 66e400dd..65543590 100644
--- a/examples/priority.c
+++ b/examples/priority.c
@@ -1,6 +1,7 @@
#include <stdio.h>
#include <time.h>
+#define i_implement
#include <stc/crandom.h>
#define i_val int64_t
diff --git a/examples/queue.c b/examples/queue.c
index 5f2fa03d..1b56d96a 100644
--- a/examples/queue.c
+++ b/examples/queue.c
@@ -1,3 +1,4 @@
+#define i_implement
#include <stc/crandom.h>
#include <stdio.h>
diff --git a/examples/random.c b/examples/random.c
index 9ffcf0e2..39fd7fa1 100644
--- a/examples/random.c
+++ b/examples/random.c
@@ -1,5 +1,6 @@
#include <stdio.h>
#include <time.h>
+#define i_implement
#include <stc/crandom.h>
int main()
diff --git a/examples/rawptr_elements.c b/examples/rawptr_elements.c
index c438727b..64d73843 100644
--- a/examples/rawptr_elements.c
+++ b/examples/rawptr_elements.c
@@ -13,6 +13,7 @@ struct { double x, y; } typedef Point;
#define i_tag pnt
#include <stc/cset.h>
+#define i_implement
#include <stc/cstr.h>
// Map of int64 pointers: Define i_valraw as int64_t for easy emplace calls!
typedef int64_t inttype;
diff --git a/examples/read.c b/examples/read.c
index 5f31e357..67b7e67e 100644
--- a/examples/read.c
+++ b/examples/read.c
@@ -1,3 +1,4 @@
+#define i_implement
#include <stc/cstr.h>
#define i_val_str
#include <stc/cvec.h>
diff --git a/examples/regex1.c b/examples/regex1.c
index 7481fbb1..84a5e28b 100644
--- a/examples/regex1.c
+++ b/examples/regex1.c
@@ -1,3 +1,4 @@
+#define i_implement
#include <stc/cstr.h>
#include <stc/cregex.h>
diff --git a/examples/regex2.c b/examples/regex2.c
index 7089956f..19c49ec2 100644
--- a/examples/regex2.c
+++ b/examples/regex2.c
@@ -1,6 +1,7 @@
+#define i_implement
+#include <stc/cstr.h>
#include <stc/cregex.h>
#include <stc/csview.h>
-#include <stc/cstr.h>
int main()
{
diff --git a/examples/regex_match.c b/examples/regex_match.c
index 0aa740d4..c2499733 100644
--- a/examples/regex_match.c
+++ b/examples/regex_match.c
@@ -1,12 +1,6 @@
-#include <stdio.h>
#define i_implement
#include <stc/cstr.h>
#include <stc/cregex.h>
-#include <stc/crandom.h>
-#include <stc/csview.h>
-#define i_val double
-#include <time.h>
-
int main()
{
diff --git a/examples/replace.c b/examples/replace.c
index f658fb3c..57018618 100644
--- a/examples/replace.c
+++ b/examples/replace.c
@@ -1,4 +1,4 @@
-
+#define i_implement
#include <stc/cstr.h>
int main ()
diff --git a/examples/splitstr.c b/examples/splitstr.c
index 390a6c6f..0cd48067 100644
--- a/examples/splitstr.c
+++ b/examples/splitstr.c
@@ -1,7 +1,9 @@
+#define i_implement
#include <stc/cstr.h>
+#define i_implement
+#include <stc/csview.h>
#define i_val_str
#include <stc/cvec.h>
-#include <stc/csview.h>
void print_split(csview str, csview sep)
{
diff --git a/examples/sso_map.c b/examples/sso_map.c
index bab182e3..53fac3e3 100644
--- a/examples/sso_map.c
+++ b/examples/sso_map.c
@@ -1,9 +1,9 @@
+#define i_implement
#include <stc/cstr.h>
#define i_key_str
#define i_val_str
#include <stc/cmap.h>
-
int main()
{
c_auto (cmap_str, m) {
diff --git a/examples/sso_substr.c b/examples/sso_substr.c
index 8e21b7fe..288d0b85 100644
--- a/examples/sso_substr.c
+++ b/examples/sso_substr.c
@@ -1,19 +1,21 @@
+#define i_implement
#include <stc/cstr.h>
+#define i_implement
#include <stc/csview.h>
int main ()
{
cstr str = cstr_new("We think in generalities, but we live in details.");
- csview sv1 = cstr_substr(&str, 3, 5); // "think"
- size_t pos = cstr_find(str, "live"); // position of "live"
- csview sv2 = cstr_substr(&str, pos, 4); // "live"
- csview sv3 = cstr_slice(&str, -8, -1); // "details"
+ csview sv1 = cstr_substr_ex(&str, 3, 5); // "think"
+ size_t pos = cstr_find(str, "live"); // position of "live"
+ csview sv2 = cstr_substr_ex(&str, pos, 4); // "live"
+ csview sv3 = cstr_slice_ex(&str, -8, -1); // "details"
printf("%" c_PRIsv ", %" c_PRIsv ", %" c_PRIsv "\n",
c_ARGsv(sv1), c_ARGsv(sv2), c_ARGsv(sv3));
cstr_assign(&str, "apples are green or red");
- cstr s2 = cstr_from_sv(cstr_substr(&str, -3, 3)); // "red"
- cstr s3 = cstr_from_sv(cstr_substr(&str, 0, 6)); // "apples"
+ cstr s2 = cstr_from_sv(cstr_substr_ex(&str, -3, 3)); // "red"
+ cstr s3 = cstr_from_sv(cstr_substr_ex(&str, 0, 6)); // "apples"
#ifndef STC_CSTR_V1
printf("%s %s: %d, %d\n", cstr_str(&s2), cstr_str(&s3),
cstr_is_long(&str), cstr_is_long(&s2));
diff --git a/examples/sview_split.c b/examples/sview_split.c
index 3594a599..ec664ba0 100644
--- a/examples/sview_split.c
+++ b/examples/sview_split.c
@@ -1,4 +1,6 @@
+#define i_implement
#include <stc/cstr.h>
+#define i_implement
#include <stc/csview.h>
int main()
diff --git a/examples/unordered_set.c b/examples/unordered_set.c
index 11ffea80..9ecd59fe 100644
--- a/examples/unordered_set.c
+++ b/examples/unordered_set.c
@@ -1,5 +1,6 @@
// https://iq.opengenus.org/containers-cpp-stl/
// C program to demonstrate various function of stc cset
+#define i_implement
#include <stc/cstr.h>
#define i_key_str
#include <stc/cset.h>
diff --git a/examples/utf8replace_c.c b/examples/utf8replace_c.c
index 89d5375f..733245e5 100644
--- a/examples/utf8replace_c.c
+++ b/examples/utf8replace_c.c
@@ -1,3 +1,4 @@
+#define i_implement
#include <stc/cstr.h>
#include <stc/csview.h>
diff --git a/examples/vikings.c b/examples/vikings.c
index 623cd172..c63b7ffc 100644
--- a/examples/vikings.c
+++ b/examples/vikings.c
@@ -1,4 +1,4 @@
-#include <stdio.h>
+#define i_implement
#include <stc/cstr.h>
typedef struct Viking {
diff --git a/examples/words.c b/examples/words.c
index 8a86ba7f..ed800ae7 100644
--- a/examples/words.c
+++ b/examples/words.c
@@ -1,4 +1,5 @@
#include <math.h>
+#define i_implement
#include <stc/cstr.h>
#define i_val_str