From 7ab5c49a47de856ea58a979cdc086ea22d8eceff Mon Sep 17 00:00:00 2001 From: Tyge Løvset Date: Sun, 16 Jan 2022 17:46:56 +0100 Subject: Made private functions (not called by header inlines) always static. Added required param tp examples/regex1.c. --- examples/regex1.c | 8 ++++++-- include/stc/cdeq.h | 37 +++++++++++++++++++------------------ include/stc/clist.h | 6 +++--- include/stc/csmap.h | 15 ++++++++------- include/stc/cvec.h | 2 +- 5 files changed, 37 insertions(+), 31 deletions(-) diff --git a/examples/regex1.c b/examples/regex1.c index 7385d69e..e24e5400 100644 --- a/examples/regex1.c +++ b/examples/regex1.c @@ -1,8 +1,12 @@ #include #include -int main() +int main(int argc, char* argv[]) { + if (argc <= 1) { + printf("Usage: regex1 -i\n"); + return 0; + } c_auto (cstr, input) c_auto (cregex, float_expr) { @@ -10,7 +14,7 @@ int main() // Until "q" is given, ask for another number while (true) { - printf("Enter float number (q for quit): "); + printf("Enter a double precision number (q for quit): "); cstr_getline(&input, stdin); // Exit when the user inputs q diff --git a/include/stc/cdeq.h b/include/stc/cdeq.h index fb4f4ffb..cb291fbe 100644 --- a/include/stc/cdeq.h +++ b/include/stc/cdeq.h @@ -42,10 +42,11 @@ _cx_deftypes(_c_cdeq_types, _cx_self, i_val); typedef i_valraw _cx_raw; STC_API _cx_self _cx_memb(_init)(void); +STC_API _cx_self _cx_memb(_with_capacity)(const size_t n); +STC_API bool _cx_memb(_reserve)(_cx_self* self, const size_t n); STC_API void _cx_memb(_clear)(_cx_self* self); STC_API void _cx_memb(_drop)(_cx_self* self); STC_API _cx_value* _cx_memb(_push_back)(_cx_self* self, i_val value); -STC_API bool _cx_memb(_expand_right_half_)(_cx_self* self, size_t idx, size_t n); STC_API void _cx_memb(_shrink_to_fit)(_cx_self *self); #ifndef _i_queue #if !c_option(c_no_clone) @@ -100,13 +101,6 @@ STC_INLINE void _cx_memb(_next)(_cx_iter* it) { ++it->ref; } STC_INLINE _cx_iter _cx_memb(_advance)(_cx_iter it, intptr_t offs) { it.ref += offs; return it; } -STC_INLINE _cx_self -_cx_memb(_with_capacity)(const size_t n) { - _cx_self cx = _cx_memb(_init)(); - _cx_memb(_expand_right_half_)(&cx, 0, n); - return cx; -} - #ifndef _i_queue STC_INLINE void _cx_memb(_pop_back)(_cx_self* self) { @@ -123,12 +117,6 @@ STC_INLINE size_t _cx_memb(_index)(_cx_self cx, _cx_iter it) { return it.ref - cx.data; } -STC_INLINE bool -_cx_memb(_reserve)(_cx_self* self, const size_t n) { - const size_t sz = cdeq_rep_(self)->size; - return n <= sz || _cx_memb(_expand_right_half_)(self, sz, n - sz); -} - STC_INLINE _cx_iter _cx_memb(_insert)(_cx_self* self, const size_t idx, i_val value) { return _cx_memb(_insert_range_p)(self, self->data + idx, &value, &value + 1); @@ -256,7 +244,7 @@ _cx_memb(_drop)(_cx_self* self) { c_free(rep); } -STC_DEF size_t +static size_t _cx_memb(_realloc_)(_cx_self* self, const size_t n) { struct cdeq_rep* rep = cdeq_rep_(self); const size_t sz = rep->size, cap = (size_t) (sz*1.7) + n + 7; @@ -270,7 +258,7 @@ _cx_memb(_realloc_)(_cx_self* self, const size_t n) { return cap; } -STC_DEF bool +static bool _cx_memb(_expand_right_half_)(_cx_self* self, const size_t idx, const size_t n) { struct cdeq_rep* rep = cdeq_rep_(self); const size_t sz = rep->size, cap = rep->cap; @@ -292,6 +280,19 @@ _cx_memb(_expand_right_half_)(_cx_self* self, const size_t idx, const size_t n) return true; } +STC_DEF _cx_self +_cx_memb(_with_capacity)(const size_t n) { + _cx_self cx = _cx_memb(_init)(); + _cx_memb(_expand_right_half_)(&cx, 0, n); + return cx; +} + +STC_DEF bool +_cx_memb(_reserve)(_cx_self* self, const size_t n) { + const size_t sz = cdeq_rep_(self)->size; + return n <= sz || _cx_memb(_expand_right_half_)(self, sz, n - sz); +} + STC_DEF _cx_value* _cx_memb(_push_back)(_cx_self* self, i_val value) { struct cdeq_rep* rep = cdeq_rep_(self); @@ -314,7 +315,7 @@ _cx_memb(_clone)(_cx_self cx) { #ifndef _i_queue -STC_DEF void +static void _cx_memb(_expand_left_half_)(_cx_self* self, const size_t idx, const size_t n) { struct cdeq_rep* rep = cdeq_rep_(self); size_t cap = rep->cap; @@ -331,7 +332,7 @@ _cx_memb(_expand_left_half_)(_cx_self* self, const size_t idx, const size_t n) { } } -STC_DEF _cx_value* +static _cx_value* _cx_memb(_insert_space_)(_cx_self* self, const _cx_value* pos, const size_t n) { const size_t idx = pos - self->data; if (idx*2 < cdeq_rep_(self)->size) _cx_memb(_expand_left_half_)(self, idx, n); diff --git a/include/stc/clist.h b/include/stc/clist.h index 7d482956..a2642ed9 100644 --- a/include/stc/clist.h +++ b/include/stc/clist.h @@ -304,14 +304,14 @@ _cx_memb(_remove)(_cx_self* self, i_valraw val) { return n; } -STC_DEF int +static int _cx_memb(_sort_cmp_)(const clist_VOID_node* x, const clist_VOID_node* y) { i_valraw a = i_valto(&((const _cx_node *) x)->value); i_valraw b = i_valto(&((const _cx_node *) y)->value); return i_cmp(&a, &b); } -STC_API clist_VOID_node* +static clist_VOID_node* _clist_mergesort(clist_VOID_node *list, int (*cmp)(const clist_VOID_node*, const clist_VOID_node*)); STC_DEF void @@ -342,7 +342,7 @@ _clist_count(const clist_VOID* self) { #if !c_option(c_no_cmp) // Singly linked list Mergesort implementation by Simon Tatham. O(n*log n). // https://www.chiark.greenend.org.uk/~sgtatham/algorithms/listsort.html -STC_DEF clist_VOID_node * +static clist_VOID_node * _clist_mergesort(clist_VOID_node *list, int (*cmp)(const clist_VOID_node*, const clist_VOID_node*)) { clist_VOID_node *p, *q, *e, *tail, *oldhead; int insize = 1, nmerges, psize, qsize, i; diff --git a/include/stc/csmap.h b/include/stc/csmap.h index 10166b0e..68e6e652 100644 --- a/include/stc/csmap.h +++ b/include/stc/csmap.h @@ -112,7 +112,6 @@ STC_API _cx_value* _cx_memb(_back)(const _cx_self* self); STC_API int _cx_memb(_erase)(_cx_self* self, i_keyraw rkey); STC_API _cx_iter _cx_memb(_erase_at)(_cx_self* self, _cx_iter it); STC_API _cx_iter _cx_memb(_erase_range)(_cx_self* self, _cx_iter it1, _cx_iter it2); -STC_API _cx_result _cx_memb(_insert_entry_)(_cx_self* self, i_keyraw rkey); STC_API void _cx_memb(_next)(_cx_iter* it); STC_INLINE bool _cx_memb(_empty)(_cx_self tree) { return _csmap_rep(&tree)->size == 0; } @@ -240,7 +239,7 @@ _cx_memb(_reserve)(_cx_self* self, const size_t cap) { return true; } -STC_DEF _cx_size +static _cx_size _cx_memb(_node_new_)(_cx_self* self, int level) { size_t tn; struct csmap_rep *rep = _csmap_rep(self); if (rep->disp) { @@ -255,6 +254,8 @@ _cx_memb(_node_new_)(_cx_self* self, int level) { return (_cx_size) tn; } +static _cx_result _cx_memb(_insert_entry_)(_cx_self* self, i_keyraw rkey); + STC_DEF _cx_result _cx_memb(_insert)(_cx_self* self, i_key key _i_MAP_ONLY(, i_val mapped)) { _cx_result res = _cx_memb(_insert_entry_)(self, i_keyto(&key)); @@ -350,7 +351,7 @@ _cx_memb(_split_)(_cx_node *d, _cx_size tn) { return tn; } -STC_DEF _cx_size +static _cx_size _cx_memb(_insert_entry_i_)(_cx_self* self, _cx_size tn, const _cx_rawkey* rkey, _cx_result* res) { _cx_size up[64], tx = tn; _cx_node* d = self->nodes; @@ -375,7 +376,7 @@ _cx_memb(_insert_entry_i_)(_cx_self* self, _cx_size tn, const _cx_rawkey* rkey, return up[0]; } -STC_DEF _cx_result +static _cx_result _cx_memb(_insert_entry_)(_cx_self* self, i_keyraw rkey) { _cx_result res = {NULL, false}; _cx_size tn = _cx_memb(_insert_entry_i_)(self, (_cx_size) _csmap_rep(self)->root, &rkey, &res); @@ -384,7 +385,7 @@ _cx_memb(_insert_entry_)(_cx_self* self, i_keyraw rkey) { return res; } -STC_DEF _cx_size +static _cx_size _cx_memb(_erase_r_)(_cx_node *d, _cx_size tn, const _cx_rawkey* rkey, int *erased) { if (tn == 0) return 0; @@ -469,7 +470,7 @@ _cx_memb(_value_clone)(_cx_value _val) { return _val; } -STC_DEF _cx_size +static _cx_size _cx_memb(_clone_r_)(_cx_self* self, _cx_node* src, _cx_size sn) { if (sn == 0) return 0; _cx_size tx, tn = _cx_memb(_node_new_)(self, src[sn].level); @@ -501,7 +502,7 @@ _cx_memb(_emplace)(_cx_self* self, i_keyraw rkey _i_MAP_ONLY(, i_valraw rmapped) #endif #endif // !c_no_clone -STC_DEF void +static void _cx_memb(_drop_r_)(_cx_node* d, _cx_size tn) { if (tn) { _cx_memb(_drop_r_)(d, d[tn].link[0]); diff --git a/include/stc/cvec.h b/include/stc/cvec.h index 9da2ba56..d9f6b18d 100644 --- a/include/stc/cvec.h +++ b/include/stc/cvec.h @@ -296,7 +296,7 @@ _cx_memb(_push_back)(_cx_self* self, i_val value) { *v = value; return v; } -STC_DEF _cx_value* +static _cx_value* _cx_memb(_insert_space_)(_cx_self* self, _cx_value* pos, const size_t len) { const size_t idx = pos - self->data, size = cvec_rep_(self)->size; if (len == 0) return pos; -- cgit v1.2.3