summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2009-11-28 04:15:19 -0800
committerKaz Kylheku <kaz@kylheku.com>2009-11-28 04:15:19 -0800
commit788cace2cb783db0b4df6338f89e6b026ae23e9b (patch)
tree62ef4b70c7631651f90da8af58c78bfe7877f454
parentec1f42927b870770d77aa196bdf7adfff4475210 (diff)
downloadtxr-788cace2cb783db0b4df6338f89e6b026ae23e9b.tar.gz
txr-788cace2cb783db0b4df6338f89e6b026ae23e9b.tar.bz2
txr-788cace2cb783db0b4df6338f89e6b026ae23e9b.zip
Code cleanup. All private functions static. Private stuff
in regex module not exposed in header. Etc.
-rw-r--r--ChangeLog68
-rwxr-xr-xconfigure2
-rw-r--r--gc.c2
-rw-r--r--gc.h1
-rw-r--r--hash.c8
-rw-r--r--lib.c6
-rw-r--r--lib.h3
-rw-r--r--match.c87
-rw-r--r--parser.h1
-rw-r--r--regex.c172
-rw-r--r--regex.h116
-rw-r--r--stream.c16
-rw-r--r--txr.c8
-rw-r--r--unwind.c2
14 files changed, 261 insertions, 231 deletions
diff --git a/ChangeLog b/ChangeLog
index 8ba37b35..4eca1bca 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,73 @@
2009-11-28 Kaz Kylheku <kkylheku@gmail.com>
+ Code cleanup. All private functions static. Private stuff
+ in regex module not exposed in header. Etc.
+
+ * configure (diag_flags): Add -Wmissing-prototypes and
+ -Wstrict-prototypes.
+
+ * gc.c (more): Turn into prototyped definition with (void).
+
+ * gc.h (unmark): Declared.
+
+ * hash.c (hash_equal, hash_destroy, hash_mark, hash_grow): Private
+ functions defined static.
+
+ * lib.c (flatten_helper, do_bind2, do_bind2other): Likewise.
+
+ * lib.h (make_package, merge, d): Declared.
+
+ * match.c (dump_shell_string, dump_byte_string, dump_var,
+ dump_bindings, depth, weird_merge, bindable, dest_bind, match_line,
+ format_field, subst_vars, eval_form, complex_open, complex_snarf,
+ complex_stream, robust_length, bind_car, bind_cdr, extract_vars,
+ extract_bindings, do_output_line, do_output, match_files): Private
+ functions defined static.
+ (map_leaf_lists, complex_close): Unused functions removed.
+
+ * parser.h (yyerror): Declared.
+
+ * regex.c (bitcell_t, BITCELL_ALL1, CHAR_SET_SIZE,
+ chset_type_t, cset_L0_t, cset_L1_t, cset_L2_t, cset_L3_t,
+ struct any_char_set, struct small_char_set, struct displaced_char_set,
+ struct large_char_set, struct xlarge_char_set, union char_set,
+ nfa_kind_t, struct nfa_state_accept, struct nfa_state_empty,
+ struct nfa_state_single, struct nfa_state_set, struct nfa_state,
+ struct nfa_machine): Definitions moved here from regex.h file.
+ (L0_fill_range, L0_contains, L1_full, L1_fill_range, L1_contains,
+ L1_free, L2_full, L2_fill_range, L2_contains, L2_free, L3_fill_range,
+ L3_contains, L3_free, char_set_create, char_set_destroy,
+ char_set_compl, char_set_add, char_set_add_range, char_set_contains,
+ nfa_state_accept, nfa_state_empty, nfa_state_single, nfa_state_wild,
+ nfa_state_free, nfa_state_shallow_free, nfa_state_set,
+ nfa_state_empty_convert, nfa_state_merge, nfa_make, nfa_combine,
+ nfa_compile_set, nfa_all-states, nfa_closure, nfa_move): Private
+ functions defined static.
+
+ * regex.h (bitcell_t, BITCELL_ALL1, CHAR_SET_SIZE,
+ chset_type_t, cset_L0_t, cset_L1_t, cset_L2_t, cset_L3_t,
+ struct any_char_set, struct small_char_set, struct displaced_char_set,
+ struct large_char_set, struct xlarge_char_set, union char_set,
+ nfa_kind_t, struct nfa_state_accept, struct nfa_state_empty,
+ struct nfa_state_single, struct nfa_state_set, struct nfa_state,
+ struct nfa_machine): Definitions removed.
+ (char_set_created, char_set_destroy, char_set_compl, char_set_add,
+ char_set_add_range, char_set_contains nfa_state_accept,
+ nfa_state_empty, nfa_state_single, nfa_state_wild, nfa_state_set,
+ nfa_state_free, nfa_state_shallow_free, nfa_state_merge): Extern
+ declarations removed.
+
+ * stream.c (stdio_stream_print, stdio_stream_destroy,
+ stdio_stream_mark, stdio_get_char, stdio_get_byte,
+ string_in_stream_mark, vformat_str): Private functions defined static.
+
+ * txr.c (oom_realloc_handler, help, hint,
+ remove_hash_bang_line): Likewise.
+
+ * unwind.c (uw_unwind_to_exit_point): Likewise.
+
+2009-11-28 Kaz Kylheku <kkylheku@gmail.com>
+
* configure: Workaround in banner code for coreutils printf %.*s bug.
2009-11-27 Kaz Kylheku <kkylheku@gmail.com>
diff --git a/configure b/configure
index 50574eaa..1a38ca37 100755
--- a/configure
+++ b/configure
@@ -116,7 +116,7 @@ yacc=${yacc-'$(cross)$(tool_prefix)$(yaccname)'}
nm=${nm-'$(cross)$(tool_prefix)nm'}
opt_flags=${opt_flags--O2}
lang_flags=${lang_flags--ansi -D_POSIX_C_SOURCE=2}
-diag_flags=${diag_flags--Wall}
+diag_flags=${diag_flags--Wall -Wmissing-prototypes -Wstrict-prototypes}
debug_flags=${debug_flags--g}
inline=${inline-}
platform_flags=${platform_flags-}
diff --git a/gc.c b/gc.c
index 07bcea6e..0582bf0c 100644
--- a/gc.c
+++ b/gc.c
@@ -108,7 +108,7 @@ void release(val *last, ...)
va_end (vl);
}
-static void more()
+static void more(void)
{
heap_t *heap = (heap_t *) chk_malloc(sizeof *heap);
obj_t *block = heap->block, *end = heap->block + HEAP_SIZE;
diff --git a/gc.h b/gc.h
index 476535d3..760f7f1f 100644
--- a/gc.h
+++ b/gc.h
@@ -33,3 +33,4 @@ void gc(void);
int gc_state(int);
void gc_mark(val);
int gc_is_reachable(val);
+void unmark(void);
diff --git a/hash.c b/hash.c
index cc0e79f1..66666c81 100644
--- a/hash.c
+++ b/hash.c
@@ -128,17 +128,17 @@ val hash_obj(val obj)
return num(ll_hash(obj));
}
-val hash_equal(val self, val other)
+static val hash_equal(val self, val other)
{
return self == other ? t : nil;
}
-void hash_destroy(val hash)
+static void hash_destroy(val hash)
{
free(hash->co.handle);
}
-void hash_mark(val hash)
+static void hash_mark(val hash)
{
struct hash *h = (struct hash *) hash->co.handle;
cnum i;
@@ -194,7 +194,7 @@ static struct cobj_ops hash_ops = {
0
};
-void hash_grow(struct hash *h)
+static void hash_grow(struct hash *h)
{
cnum i;
cnum new_modulus = 2 * h->modulus;
diff --git a/lib.c b/lib.c
index ba484ed7..bb079f9c 100644
--- a/lib.c
+++ b/lib.c
@@ -344,7 +344,7 @@ val nappend2(val list1, val list2)
return list1;
}
-val flatten_helper(val env, val item)
+static val flatten_helper(val env, val item)
{
return flatten(item);
}
@@ -1337,7 +1337,7 @@ val reduce_left(val fun, val list, val init, val key)
return init;
}
-val do_bind2(val fcons, val arg2)
+static val do_bind2(val fcons, val arg2)
{
return funcall2(car(fcons), cdr(fcons), arg2);
}
@@ -1347,7 +1347,7 @@ val bind2(val fun2, val arg)
return func_f1(cons(fun2, arg), do_bind2);
}
-val do_bind2other(val fcons, val arg1)
+static val do_bind2other(val fcons, val arg1)
{
return funcall2(car(fcons), arg1, cdr(fcons));
}
diff --git a/lib.h b/lib.h
index 5f0df256..63c8b6e7 100644
--- a/lib.h
+++ b/lib.h
@@ -306,6 +306,7 @@ val chr_str(val str, val index);
val chr_str_set(val str, val index, val chr);
val sym_name(val sym);
val make_sym(val name);
+val make_package(val name);
val find_package(val name);
val intern(val str, val package);
val symbolp(val sym);
@@ -355,6 +356,7 @@ val copy_cons(val cons);
val copy_alist(val list);
val mapcar(val fun, val list);
val mappend(val fun, val list);
+val merge(val list1, val list2, val lessfun, val keyfun);
val sort(val list, val lessfun, val keyfun);
void obj_print(val obj, val stream);
@@ -362,6 +364,7 @@ void obj_pprint(val obj, val stream);
void init(const wchar_t *progname, void *(*oom_realloc)(void *, size_t),
val *stack_bottom);
void dump(val obj, val stream);
+void d(val obj);
val match(val spec, val data);
#define nil ((obj_t *) 0)
diff --git a/match.c b/match.c
index 322a4b01..bdf7714d 100644
--- a/match.c
+++ b/match.c
@@ -102,7 +102,7 @@ static void file_err(val line, val fmt, ...)
}
-void dump_shell_string(const wchar_t *str)
+static void dump_shell_string(const wchar_t *str)
{
int ch;
@@ -119,14 +119,14 @@ void dump_shell_string(const wchar_t *str)
put_char(std_output, chr('"'));
}
-void dump_byte_string(const char *str)
+static void dump_byte_string(const char *str)
{
while (*str)
put_char(std_output, chr(*str++));
}
-void dump_var(val var, char *pfx1, size_t len1,
+static void dump_var(val var, char *pfx1, size_t len1,
char *pfx2, size_t len2, val value, int level)
{
if (len1 >= 112 || len2 >= 112)
@@ -164,7 +164,7 @@ void dump_var(val var, char *pfx1, size_t len1,
}
}
-void dump_bindings(val bindings)
+static void dump_bindings(val bindings)
{
if (opt_loglevel >= 2) {
put_line(std_error, lit("raw_bindings:"));
@@ -181,7 +181,7 @@ void dump_bindings(val bindings)
}
}
-val depth(val obj)
+static val depth(val obj)
{
val dep = zero;
@@ -199,7 +199,7 @@ val depth(val obj)
return plus(dep, one);
}
-val weird_merge(val left, val right)
+static val weird_merge(val left, val right)
{
val left_depth = depth(left);
val right_depth = depth(right);
@@ -217,21 +217,12 @@ val weird_merge(val left, val right)
return append2(left, right);
}
-val map_leaf_lists(val func, val list)
-{
- if (atom(list))
- return list;
- if (none_satisfy(list, func_n1(listp), nil))
- return funcall1(func, list);
- return mapcar(bind2(func_n2(map_leaf_lists), func), list);
-}
-
-val bindable(val obj)
+static val bindable(val obj)
{
return (obj && symbolp(obj) && obj != t && !keywordp(obj)) ? t : nil;
}
-val dest_bind(val bindings, val pattern, val value)
+static val dest_bind(val bindings, val pattern, val value)
{
if (symbolp(pattern)) {
if (bindable(pattern)) {
@@ -275,9 +266,9 @@ val dest_bind(val bindings, val pattern, val value)
return t;
}
-val match_line(val bindings, val specline, val dataline,
- val pos, val spec_lineno, val data_lineno,
- val file)
+static val match_line(val bindings, val specline, val dataline,
+ val pos, val spec_lineno, val data_lineno,
+ val file)
{
#define LOG_MISMATCH(KIND) \
debuglf(spec_lineno, lit(KIND " mismatch, position ~a (~a:~a)"), pos, \
@@ -528,7 +519,7 @@ val match_line(val bindings, val specline, val dataline,
return cons(bindings, pos);
}
-val format_field(val string_or_list, val spec)
+static val format_field(val string_or_list, val spec)
{
if (!stringp(string_or_list))
return string_or_list;
@@ -554,7 +545,7 @@ val format_field(val string_or_list, val spec)
}
}
-val subst_vars(val spec, val bindings)
+static val subst_vars(val spec, val bindings)
{
list_collect_decl(out, iter);
@@ -597,7 +588,7 @@ val subst_vars(val spec, val bindings)
return out;
}
-val eval_form(val form, val bindings)
+static val eval_form(val form, val bindings)
{
if (!form) {
return cons(t, form);
@@ -630,7 +621,7 @@ typedef struct fpip {
enum fpip_close close;
} fpip_t;
-fpip_t complex_open(val name, val output)
+static fpip_t complex_open(val name, val output)
{
fpip_t ret = { 0, 0 };
@@ -663,32 +654,12 @@ fpip_t complex_open(val name, val output)
return ret;
}
-int complex_open_failed(fpip_t fp)
+static int complex_open_failed(fpip_t fp)
{
return fp.f == 0 && fp.d == 0;
}
-void complex_close(fpip_t fp)
-{
- if (fp.f == 0)
- return;
- switch (fp.close) {
- case fpip_fclose:
- if (fp.f != stdin && fp.f != stdout)
- fclose(fp.f);
- return;
- case fpip_pclose:
- pclose(fp.f);
- return;
- case fpip_closedir:
- closedir(fp.d);
- return;
- }
-
- internal_error("bad input source type code");
-}
-
-val complex_snarf(fpip_t fp, val name)
+static val complex_snarf(fpip_t fp, val name)
{
switch (fp.close) {
case fpip_fclose:
@@ -702,7 +673,7 @@ val complex_snarf(fpip_t fp, val name)
internal_error("bad input source type");
}
-val complex_stream(fpip_t fp, val name)
+static val complex_stream(fpip_t fp, val name)
{
switch (fp.close) {
case fpip_fclose:
@@ -717,7 +688,7 @@ val complex_stream(fpip_t fp, val name)
}
-val robust_length(val obj)
+static val robust_length(val obj)
{
if (obj == nil)
return zero;
@@ -726,21 +697,21 @@ val robust_length(val obj)
return length(obj);
}
-val bind_car(val bind_cons)
+static val bind_car(val bind_cons)
{
return if3(consp(cdr(bind_cons)),
cons(car(bind_cons), car(cdr(bind_cons))),
bind_cons);
}
-val bind_cdr(val bind_cons)
+static val bind_cdr(val bind_cons)
{
return if3(consp(cdr(bind_cons)),
cons(car(bind_cons), cdr(cdr(bind_cons))),
bind_cons);
}
-val extract_vars(val output_spec)
+static val extract_vars(val output_spec)
{
list_collect_decl (vars, tai);
@@ -756,7 +727,7 @@ val extract_vars(val output_spec)
return vars;
}
-val extract_bindings(val bindings, val output_spec)
+static val extract_bindings(val bindings, val output_spec)
{
list_collect_decl (bindings_out, tail);
val var_list = extract_vars(output_spec);
@@ -768,8 +739,8 @@ val extract_bindings(val bindings, val output_spec)
return bindings_out;
}
-void do_output_line(val bindings, val specline,
- val spec_lineno, val out)
+static void do_output_line(val bindings, val specline,
+ val spec_lineno, val out)
{
for (; specline; specline = rest(specline)) {
val elem = first(specline);
@@ -839,7 +810,7 @@ void do_output_line(val bindings, val specline,
}
}
-void do_output(val bindings, val specs, val out)
+static void do_output(val bindings, val specs, val out)
{
if (equal(specs, null_list))
return;
@@ -896,9 +867,9 @@ void do_output(val bindings, val specs, val out)
}
}
-val match_files(val spec, val files,
- val bindings, val first_file_parsed,
- val data_linenum)
+static val match_files(val spec, val files,
+ val bindings, val first_file_parsed,
+ val data_linenum)
{
val data = nil;
cnum data_lineno = 0;
diff --git a/parser.h b/parser.h
index 3b58193b..a5066f32 100644
--- a/parser.h
+++ b/parser.h
@@ -32,5 +32,6 @@ extern const wchar_t *spec_file;
extern val spec_file_str;
int yyparse(void);
val get_spec(void);
+void yyerror(const char *s);
void yyerrorf(val s, ...);
void yybadtoken(int tok, val context);
diff --git a/regex.c b/regex.c
index 14ef13c6..7fe7e448 100644
--- a/regex.c
+++ b/regex.c
@@ -37,7 +37,10 @@
#include "unwind.h"
#include "regex.h"
-#define NFA_SET_SIZE 512
+typedef unsigned int bitcell_t;
+
+#define BITCELL_ALL1 UINT_MAX
+#define CHAR_SET_SIZE (256 / (sizeof (bitcell_t) * CHAR_BIT))
#define CHAR_SET_INDEX(CH) ((CH) / (sizeof (bitcell_t) * CHAR_BIT))
#define CHAR_SET_BIT(CH) ((CH) % (sizeof (bitcell_t) * CHAR_BIT))
@@ -56,6 +59,102 @@
#define CHAR_SET_L0_LO(CH) ((CH) & (~(wchar_t) 0xFF))
#define CHAR_SET_L0_HI(CH) ((CH) | ((wchar_t) 0xFF))
+typedef enum {
+ CHSET_SMALL, CHSET_DISPLACED, CHSET_LARGE, CHSET_XLARGE
+} chset_type_t;
+
+typedef bitcell_t cset_L0_t[CHAR_SET_SIZE];
+typedef cset_L0_t *cset_L1_t[16];
+typedef cset_L1_t *cset_L2_t[16];
+typedef cset_L2_t *cset_L3_t[17];
+
+struct any_char_set {
+ unsigned type : 3;
+ unsigned comp : 1;
+};
+
+struct small_char_set {
+ unsigned type : 3;
+ unsigned comp : 1;
+ cset_L0_t bitcell;
+};
+
+struct displaced_char_set {
+ unsigned type : 3;
+ unsigned comp : 1;
+ cset_L0_t bitcell;
+ wchar_t base;
+};
+
+
+struct large_char_set {
+ unsigned type : 3;
+ unsigned comp : 1;
+ cset_L2_t dir;
+};
+
+struct xlarge_char_set {
+ unsigned type : 3;
+ unsigned comp : 1;
+ cset_L3_t dir;
+};
+
+typedef union char_set {
+ struct any_char_set any;
+ struct small_char_set s;
+ struct displaced_char_set d;
+ struct large_char_set l;
+ struct xlarge_char_set xl;
+} char_set_t;
+
+#define NFA_SET_SIZE 512
+
+typedef enum {
+ nfa_accept, nfa_empty, nfa_wild, nfa_single, nfa_set
+} nfa_kind_t;
+
+struct nfa_state_accept {
+ nfa_kind_t kind;
+ unsigned visited;
+};
+
+struct nfa_state_empty {
+ nfa_kind_t kind;
+ unsigned visited;
+ nfa_state_t *trans0;
+ nfa_state_t *trans1;
+};
+
+struct nfa_state_single {
+ nfa_kind_t kind;
+ unsigned visited;
+ nfa_state_t *trans;
+ wchar_t ch;
+};
+
+struct nfa_state_set {
+ nfa_kind_t kind;
+ unsigned visited;
+ nfa_state_t *trans;
+ char_set_t *set;
+};
+
+union nfa_state {
+ struct nfa_state_accept a;
+ struct nfa_state_empty e;
+ struct nfa_state_single o;
+ struct nfa_state_set s;
+};
+
+struct nfa_machine {
+ cnum last_accept_pos;
+ unsigned visited;
+ nfa_state_t **move, **clos, **stack;
+ int nmove, nclos;
+ cnum count;
+ nfa_t nfa;
+};
+
static int L0_full(cset_L0_t *L0)
{
int i;
@@ -66,7 +165,7 @@ static int L0_full(cset_L0_t *L0)
return 1;
}
-void L0_fill_range(cset_L0_t *L0, wchar_t ch0, wchar_t ch1)
+static void L0_fill_range(cset_L0_t *L0, wchar_t ch0, wchar_t ch1)
{
int i;
int bt0 = CHAR_SET_BIT(ch0);
@@ -86,12 +185,12 @@ void L0_fill_range(cset_L0_t *L0, wchar_t ch0, wchar_t ch1)
}
}
-int L0_contains(cset_L0_t *L0, wchar_t ch)
+static int L0_contains(cset_L0_t *L0, wchar_t ch)
{
return ((*L0)[CHAR_SET_INDEX(ch)] & (1 << CHAR_SET_BIT(ch))) != 0;
}
-int L1_full(cset_L1_t *L1)
+static int L1_full(cset_L1_t *L1)
{
int i;
for (i = 0; i < 16; i++)
@@ -100,7 +199,7 @@ int L1_full(cset_L1_t *L1)
return 1;
}
-void L1_fill_range(cset_L1_t *L1, wchar_t ch0, wchar_t ch1)
+static void L1_fill_range(cset_L1_t *L1, wchar_t ch0, wchar_t ch1)
{
int i1, i10, i11;
@@ -144,7 +243,7 @@ void L1_fill_range(cset_L1_t *L1, wchar_t ch0, wchar_t ch1)
}
}
-int L1_contains(cset_L1_t *L1, wchar_t ch)
+static int L1_contains(cset_L1_t *L1, wchar_t ch)
{
int i1 = CHAR_SET_L1(ch);
cset_L0_t *L0 = (*L1)[i1];
@@ -158,7 +257,7 @@ int L1_contains(cset_L1_t *L1, wchar_t ch)
}
-void L1_free(cset_L1_t *L1)
+static void L1_free(cset_L1_t *L1)
{
int i1;
@@ -170,7 +269,7 @@ void L1_free(cset_L1_t *L1)
free((*L1)[i1]);
}
-int L2_full(cset_L2_t *L2)
+static int L2_full(cset_L2_t *L2)
{
int i;
for (i = 0; i < 16; i++)
@@ -179,7 +278,7 @@ int L2_full(cset_L2_t *L2)
return 1;
}
-void L2_fill_range(cset_L2_t *L2, wchar_t ch0, wchar_t ch1)
+static void L2_fill_range(cset_L2_t *L2, wchar_t ch0, wchar_t ch1)
{
int i2, i20, i21;
@@ -223,7 +322,7 @@ void L2_fill_range(cset_L2_t *L2, wchar_t ch0, wchar_t ch1)
}
}
-int L2_contains(cset_L2_t *L2, wchar_t ch)
+static int L2_contains(cset_L2_t *L2, wchar_t ch)
{
int i2 = CHAR_SET_L2(ch);
cset_L1_t *L1 = (*L2)[i2];
@@ -236,7 +335,7 @@ int L2_contains(cset_L2_t *L2, wchar_t ch)
return L1_contains(L1, ch);
}
-void L2_free(cset_L2_t *L2)
+static void L2_free(cset_L2_t *L2)
{
int i2;
@@ -249,7 +348,7 @@ void L2_free(cset_L2_t *L2)
}
}
-void L3_fill_range(cset_L3_t *L3, wchar_t ch0, wchar_t ch1)
+static void L3_fill_range(cset_L3_t *L3, wchar_t ch0, wchar_t ch1)
{
int i3, i30, i31;
@@ -292,7 +391,7 @@ void L3_fill_range(cset_L3_t *L3, wchar_t ch0, wchar_t ch1)
}
}
-int L3_contains(cset_L3_t *L3, wchar_t ch)
+static int L3_contains(cset_L3_t *L3, wchar_t ch)
{
int i3 = CHAR_SET_L3(ch);
cset_L2_t *L2 = (*L3)[i3];
@@ -305,7 +404,7 @@ int L3_contains(cset_L3_t *L3, wchar_t ch)
return L2_contains(L2, ch);
}
-void L3_free(cset_L3_t *L3)
+static void L3_free(cset_L3_t *L3)
{
int i3;
@@ -318,7 +417,7 @@ void L3_free(cset_L3_t *L3)
}
}
-char_set_t *char_set_create(chset_type_t type, wchar_t base)
+static char_set_t *char_set_create(chset_type_t type, wchar_t base)
{
static char_set_t blank;
char_set_t *cs = (char_set_t *) chk_malloc(sizeof *cs);
@@ -331,7 +430,7 @@ char_set_t *char_set_create(chset_type_t type, wchar_t base)
return cs;
}
-void char_set_destroy(char_set_t *set)
+static void char_set_destroy(char_set_t *set)
{
switch (set->any.type) {
case CHSET_DISPLACED:
@@ -349,12 +448,12 @@ void char_set_destroy(char_set_t *set)
}
}
-void char_set_compl(char_set_t *set)
+static void char_set_compl(char_set_t *set)
{
set->any.comp = 1;
}
-void char_set_add(char_set_t *set, wchar_t ch)
+static void char_set_add(char_set_t *set, wchar_t ch)
{
switch (set->any.type) {
case CHSET_DISPLACED:
@@ -376,7 +475,7 @@ void char_set_add(char_set_t *set, wchar_t ch)
}
}
-void char_set_add_range(char_set_t *set, wchar_t ch0, wchar_t ch1)
+static void char_set_add_range(char_set_t *set, wchar_t ch0, wchar_t ch1)
{
if (ch0 >= ch1)
return;
@@ -402,7 +501,7 @@ void char_set_add_range(char_set_t *set, wchar_t ch0, wchar_t ch1)
}
}
-int char_set_contains(char_set_t *set, wchar_t ch)
+static int char_set_contains(char_set_t *set, wchar_t ch)
{
int result = 0;
@@ -432,7 +531,7 @@ int char_set_contains(char_set_t *set, wchar_t ch)
return set->any.comp ? !result : result;
}
-nfa_state_t *nfa_state_accept(void)
+static nfa_state_t *nfa_state_accept(void)
{
nfa_state_t *st = (nfa_state_t *) chk_malloc(sizeof *st);
st->a.kind = nfa_accept;
@@ -440,7 +539,7 @@ nfa_state_t *nfa_state_accept(void)
return st;
}
-nfa_state_t *nfa_state_empty(nfa_state_t *t0, nfa_state_t *t1)
+static nfa_state_t *nfa_state_empty(nfa_state_t *t0, nfa_state_t *t1)
{
nfa_state_t *st = (nfa_state_t *) chk_malloc(sizeof *st);
st->e.kind = nfa_empty;
@@ -450,7 +549,7 @@ nfa_state_t *nfa_state_empty(nfa_state_t *t0, nfa_state_t *t1)
return st;
}
-nfa_state_t *nfa_state_single(nfa_state_t *t, wchar_t ch)
+static nfa_state_t *nfa_state_single(nfa_state_t *t, wchar_t ch)
{
nfa_state_t *st = (nfa_state_t *) chk_malloc(sizeof *st);
st->o.kind = nfa_single;
@@ -460,7 +559,7 @@ nfa_state_t *nfa_state_single(nfa_state_t *t, wchar_t ch)
return st;
}
-nfa_state_t *nfa_state_wild(nfa_state_t *t)
+static nfa_state_t *nfa_state_wild(nfa_state_t *t)
{
nfa_state_t *st = (nfa_state_t *) chk_malloc(sizeof *st);
st->o.kind = nfa_wild;
@@ -470,19 +569,19 @@ nfa_state_t *nfa_state_wild(nfa_state_t *t)
return st;
}
-void nfa_state_free(nfa_state_t *st)
+static void nfa_state_free(nfa_state_t *st)
{
if (st->a.kind == nfa_set)
char_set_destroy(st->s.set);
free(st);
}
-void nfa_state_shallow_free(nfa_state_t *st)
+static void nfa_state_shallow_free(nfa_state_t *st)
{
free(st);
}
-nfa_state_t *nfa_state_set(nfa_state_t *t, char_set_t *cs)
+static nfa_state_t *nfa_state_set(nfa_state_t *t, char_set_t *cs)
{
nfa_state_t *st = (nfa_state_t *) chk_malloc(sizeof *st);
st->s.kind = nfa_set;
@@ -500,7 +599,8 @@ nfa_state_t *nfa_state_set(nfa_state_t *t, char_set_t *cs)
* either back to itself, or to a new state in the
* surrounding new NFA.
*/
-void nfa_state_empty_convert(nfa_state_t *acc, nfa_state_t *t0, nfa_state_t *t1)
+static void nfa_state_empty_convert(nfa_state_t *acc, nfa_state_t *t0,
+ nfa_state_t *t1)
{
assert (acc->a.kind == nfa_accept);
acc->e.kind = nfa_empty;
@@ -522,13 +622,13 @@ void nfa_state_empty_convert(nfa_state_t *acc, nfa_state_t *t0, nfa_state_t *t1)
* existing start state, and allocate a new start
* state in front of it.
*/
-void nfa_state_merge(nfa_state_t *acc, nfa_state_t *st)
+static void nfa_state_merge(nfa_state_t *acc, nfa_state_t *st)
{
assert (acc->a.kind == nfa_accept);
*acc = *st;
}
-nfa_t nfa_make(nfa_state_t *s, nfa_state_t *acc)
+static nfa_t nfa_make(nfa_state_t *s, nfa_state_t *acc)
{
nfa_t ret;
ret.start = s;
@@ -541,7 +641,7 @@ nfa_t nfa_make(nfa_state_t *s, nfa_state_t *acc)
* The acceptance state of the predecessor is merged with the start state of
* the successor.
*/
-nfa_t nfa_combine(nfa_t pred, nfa_t succ)
+static nfa_t nfa_combine(nfa_t pred, nfa_t succ)
{
nfa_t ret;
ret.start = pred.start;
@@ -551,7 +651,7 @@ nfa_t nfa_combine(nfa_t pred, nfa_t succ)
return ret;
}
-nfa_t nfa_compile_set(val args, int comp)
+static nfa_t nfa_compile_set(val args, int comp)
{
val iter;
wchar_t min = WCHAR_MAX;
@@ -717,7 +817,7 @@ nfa_t nfa_compile_regex(val items)
}
}
-int nfa_all_states(nfa_state_t **inout, int num, unsigned visited)
+static int nfa_all_states(nfa_state_t **inout, int num, unsigned visited)
{
int i;
@@ -795,8 +895,8 @@ void nfa_free(nfa_t nfa)
* states which are reachable from that set with empty (epsilon) transitions.
* (Transitions that don't do not consume and match an input character).
*/
-int nfa_closure(nfa_state_t **stack, nfa_state_t **in, int nin,
- nfa_state_t **out, unsigned visited, int *accept)
+static int nfa_closure(nfa_state_t **stack, nfa_state_t **in, int nin,
+ nfa_state_t **out, unsigned visited, int *accept)
{
int i, nout = 0;
int stackp = 0;
@@ -855,7 +955,7 @@ int nfa_closure(nfa_state_t **stack, nfa_state_t **in, int nin,
* set is the set of states which are reachable from the set of
* input states on the consumpion of the input character given by ch.
*/
-int nfa_move(nfa_state_t **in, int nin, nfa_state_t **out, wchar_t ch)
+static int nfa_move(nfa_state_t **in, int nin, nfa_state_t **out, wchar_t ch)
{
int i, nmove;
diff --git a/regex.h b/regex.h
index 56e375c9..09bfa2d5 100644
--- a/regex.h
+++ b/regex.h
@@ -26,115 +26,8 @@
#include <limits.h>
-typedef unsigned int bitcell_t;
-
-#define BITCELL_ALL1 UINT_MAX
-#define CHAR_SET_SIZE (256 / (sizeof (bitcell_t) * CHAR_BIT))
-
-typedef enum {
- CHSET_SMALL, CHSET_DISPLACED, CHSET_LARGE, CHSET_XLARGE
-} chset_type_t;
-
-typedef bitcell_t cset_L0_t[CHAR_SET_SIZE];
-typedef cset_L0_t *cset_L1_t[16];
-typedef cset_L1_t *cset_L2_t[16];
-typedef cset_L2_t *cset_L3_t[17];
-
-struct any_char_set {
- unsigned type : 3;
- unsigned comp : 1;
-};
-
-struct small_char_set {
- unsigned type : 3;
- unsigned comp : 1;
- cset_L0_t bitcell;
-};
-
-struct displaced_char_set {
- unsigned type : 3;
- unsigned comp : 1;
- cset_L0_t bitcell;
- wchar_t base;
-};
-
-
-struct large_char_set {
- unsigned type : 3;
- unsigned comp : 1;
- cset_L2_t dir;
-};
-
-struct xlarge_char_set {
- unsigned type : 3;
- unsigned comp : 1;
- cset_L3_t dir;
-};
-
-typedef union char_set {
- struct any_char_set any;
- struct small_char_set s;
- struct displaced_char_set d;
- struct large_char_set l;
- struct xlarge_char_set xl;
-} char_set_t;
-
-char_set_t *char_set_create(chset_type_t, wchar_t);
-void char_set_destroy(char_set_t *);
-
-void char_set_compl(char_set_t *);
-void char_set_add(char_set_t *, wchar_t);
-void char_set_add_range(char_set_t *, wchar_t, wchar_t); /* inclusive */
-int char_set_contains(char_set_t *, wchar_t);
-
-typedef enum {
- nfa_accept, nfa_empty, nfa_wild, nfa_single, nfa_set
-} nfa_kind_t;
-
typedef union nfa_state nfa_state_t;
-struct nfa_state_accept {
- nfa_kind_t kind;
- unsigned visited;
-};
-
-struct nfa_state_empty {
- nfa_kind_t kind;
- unsigned visited;
- nfa_state_t *trans0;
- nfa_state_t *trans1;
-};
-
-struct nfa_state_single {
- nfa_kind_t kind;
- unsigned visited;
- nfa_state_t *trans;
- wchar_t ch;
-};
-
-struct nfa_state_set {
- nfa_kind_t kind;
- unsigned visited;
- nfa_state_t *trans;
- char_set_t *set;
-};
-
-union nfa_state {
- struct nfa_state_accept a;
- struct nfa_state_empty e;
- struct nfa_state_single o;
- struct nfa_state_set s;
-};
-
-nfa_state_t *nfa_state_accept(void);
-nfa_state_t *nfa_state_empty(nfa_state_t *, nfa_state_t *);
-nfa_state_t *nfa_state_single(nfa_state_t *, wchar_t ch);
-nfa_state_t *nfa_state_wild(nfa_state_t *);
-nfa_state_t *nfa_state_set(nfa_state_t *, char_set_t *);
-void nfa_state_free(nfa_state_t *st);
-void nfa_state_shallow_free(nfa_state_t *st);
-void nfa_state_merge(nfa_state_t *accept, nfa_state_t *);
-
typedef struct nfa {
nfa_state_t *start;
nfa_state_t *accept;
@@ -144,14 +37,7 @@ typedef enum nfam_result {
NFAM_INCOMPLETE, NFAM_FAIL, NFAM_MATCH
} nfam_result_t;
-typedef struct nfa_machine {
- cnum last_accept_pos;
- unsigned visited;
- nfa_state_t **move, **clos, **stack;
- int nmove, nclos;
- cnum count;
- nfa_t nfa;
-} nfa_machine_t;
+typedef struct nfa_machine nfa_machine_t;
nfa_t nfa_compile_regex(val regex);
void nfa_free(nfa_t);
diff --git a/stream.c b/stream.c
index 0ffe7d83..a0f490bb 100644
--- a/stream.c
+++ b/stream.c
@@ -70,20 +70,20 @@ struct stdio_handle {
struct utf8_decoder ud;
};
-void stdio_stream_print(val stream, val out)
+static void stdio_stream_print(val stream, val out)
{
struct stdio_handle *h = (struct stdio_handle *) stream->co.handle;
format(out, lit("#<~s ~s>"), stream->co.cls, h->descr, nao);
}
-void stdio_stream_destroy(val stream)
+static void stdio_stream_destroy(val stream)
{
struct stdio_handle *h = (struct stdio_handle *) stream->co.handle;
common_destroy(stream);
free(h);
}
-void stdio_stream_mark(val stream)
+static void stdio_stream_mark(val stream)
{
struct stdio_handle *h = (struct stdio_handle *) stream->co.handle;
gc_mark(h->descr);
@@ -189,7 +189,7 @@ static val stdio_get_line(val stream)
}
}
-val stdio_get_char(val stream)
+static val stdio_get_char(val stream)
{
struct stdio_handle *h = (struct stdio_handle *) stream->co.handle;
if (h->f) {
@@ -199,7 +199,7 @@ val stdio_get_char(val stream)
return stdio_maybe_read_error(stream);
}
-val stdio_get_byte(val stream)
+static val stdio_get_byte(val stream)
{
struct stdio_handle *h = (struct stdio_handle *) stream->co.handle;
if (h->f) {
@@ -290,7 +290,7 @@ static struct strm_ops pipe_ops = {
pipe_close
};
-void string_in_stream_mark(val stream)
+static void string_in_stream_mark(val stream)
{
val stuff = (val) stream->co.handle;
gc_mark(stuff);
@@ -681,8 +681,8 @@ static val vformat_num(val stream, const char *str,
return t;
}
-val vformat_str(val stream, val str, int width, int left,
- int precision)
+static val vformat_str(val stream, val str, int width, int left,
+ int precision)
{
const wchar_t *cstr = c_str(str);
int len = c_num(length_str(str));
diff --git a/txr.c b/txr.c
index e3c1c59e..83ef0233 100644
--- a/txr.c
+++ b/txr.c
@@ -53,14 +53,14 @@ val spec_file_str;
* pool, which sets an OOM flag. Program can check flag
* and gracefully terminate instead of aborting like this.
*/
-void *oom_realloc_handler(void *old, size_t size)
+static void *oom_realloc_handler(void *old, size_t size)
{
format(std_error, lit("~a: out of memory\n"), prog_string, nao);
put_line(std_error, lit("false"));
abort();
}
-void help(void)
+static void help(void)
{
val text = lit(
"\n"
@@ -112,13 +112,13 @@ void help(void)
format(std_output, text, auto_str(version), prog_string, nao);
}
-void hint(void)
+static void hint(void)
{
format(std_error, lit("~a: incorrect arguments: try --help\n"),
prog_string, nao);
}
-val remove_hash_bang_line(val spec)
+static val remove_hash_bang_line(val spec)
{
if (!consp(spec))
return spec;
diff --git a/unwind.c b/unwind.c
index 8d999d2a..2580758d 100644
--- a/unwind.c
+++ b/unwind.c
@@ -41,7 +41,7 @@ static uw_frame_t *uw_stack;
static uw_frame_t *uw_exit_point;
static uw_frame_t toplevel_env;
-static void uw_unwind_to_exit_point()
+static void uw_unwind_to_exit_point(void)
{
assert (uw_exit_point);