From c1fe19d4c1db610692365472a90f4661e48449c1 Mon Sep 17 00:00:00 2001 From: Eric Andersen Date: Mon, 9 Oct 2000 20:06:30 +0000 Subject: Bug ugly formatting update --- libc/misc/regex/.indent.pro | 33 + libc/misc/regex/Makefile | 11 +- libc/misc/regex/rx.c | 11355 ++++++++++++++++++++--------------------- libc/misc/time/.indent.pro | 33 + libc/misc/time/Makefile | 11 +- libc/misc/time/asc_conv.c | 68 +- libc/misc/time/asctime.c | 14 +- libc/misc/time/asctime_r.c | 14 +- libc/misc/time/ctime.c | 35 +- libc/misc/time/ctime_r.c | 35 +- libc/misc/time/gmtime.c | 12 +- libc/misc/time/gmtime_r.c | 12 +- libc/misc/time/localtime.c | 21 +- libc/misc/time/localtime_r.c | 21 +- libc/misc/time/mktime.c | 314 +- libc/misc/time/tm_conv.c | 207 +- 16 files changed, 5993 insertions(+), 6203 deletions(-) create mode 100644 libc/misc/regex/.indent.pro create mode 100644 libc/misc/time/.indent.pro (limited to 'libc/misc') diff --git a/libc/misc/regex/.indent.pro b/libc/misc/regex/.indent.pro new file mode 100644 index 000000000..492ecf1c7 --- /dev/null +++ b/libc/misc/regex/.indent.pro @@ -0,0 +1,33 @@ +--blank-lines-after-declarations +--blank-lines-after-procedures +--break-before-boolean-operator +--no-blank-lines-after-commas +--braces-on-if-line +--braces-on-struct-decl-line +--comment-indentation25 +--declaration-comment-column25 +--no-comment-delimiters-on-blank-lines +--cuddle-else +--continuation-indentation4 +--case-indentation0 +--else-endif-column33 +--space-after-cast +--line-comments-indentation0 +--declaration-indentation1 +--dont-format-first-column-comments +--dont-format-comments +--honour-newlines +--indent-level4 +/* changed from 0 to 4 */ +--parameter-indentation4 +--line-length78 /* changed from 75 */ +--continue-at-parentheses +--no-space-after-function-call-names +--dont-break-procedure-type +--dont-star-comments +--leave-optional-blank-lines +--dont-space-special-semicolon +--tab-size4 +/* additions by Mark */ +--case-brace-indentation0 +--leave-preprocessor-space diff --git a/libc/misc/regex/Makefile b/libc/misc/regex/Makefile index b8b38faa9..006ea75cc 100644 --- a/libc/misc/regex/Makefile +++ b/libc/misc/regex/Makefile @@ -26,13 +26,16 @@ LIBC=$(TOPDIR)libc.a CSRC=rx.c COBJS=$(patsubst %.c,%.o, $(CSRC)) +OBJS=$(COBJS) -all: $(COBJS) $(LIBC) +all: $(OBJS) $(LIBC) -$(LIBC): $(COBJS) - $(AR) $(ARFLAGS) $(LIBC) $(COBJS) +$(LIBC): ar-target -$(COBJS): Makefile +ar-target: $(OBJS) + $(AR) $(ARFLAGS) $(LIBC) $(OBJS) + +$(OBJS): Makefile clean: rm -f *.[oa] *~ core diff --git a/libc/misc/regex/rx.c b/libc/misc/regex/rx.c index 1abff8cc5..39f77adb6 100644 --- a/libc/misc/regex/rx.c +++ b/libc/misc/regex/rx.c @@ -22,7 +22,7 @@ write to the Free Software Foundation, 675 Mass Ave, Cambridge, MA * Do not put ANYTHING before it! */ #if !defined (__GNUC__) && defined (_AIX) - #pragma alloca +#pragma alloca #endif /* To make linux happy? */ @@ -50,6 +50,7 @@ write to the Free Software Foundation, 675 Mass Ave, Cambridge, MA #define MIN(a, b) ((a) < (b) ? (a) : (b)) typedef char boolean; + #define false 0 #define true 1 @@ -64,17 +65,17 @@ typedef char boolean; /* Make alloca work the best possible way. */ #ifdef __GNUC__ #define alloca __builtin_alloca -#else /* not __GNUC__ */ +#else /* not __GNUC__ */ #if HAVE_ALLOCA_H #include -#else /* not __GNUC__ or HAVE_ALLOCA_H */ -#ifndef _AIX /* Already did AIX, up at the top. */ -char *alloca (); -#endif /* not _AIX */ -#endif /* not HAVE_ALLOCA_H */ -#endif /* not __GNUC__ */ +#else /* not __GNUC__ or HAVE_ALLOCA_H */ +#ifndef _AIX /* Already did AIX, up at the top. */ +char *alloca(); +#endif /* not _AIX */ +#endif /* not HAVE_ALLOCA_H */ +#endif /* not __GNUC__ */ -#endif /* not alloca */ +#endif /* not alloca */ /* Memory management and stuff for emacs. */ @@ -90,14 +91,14 @@ char *alloca (); #ifdef REGEX_MALLOC #define REGEX_ALLOCATE malloc -#else /* not REGEX_MALLOC */ +#else /* not REGEX_MALLOC */ #define REGEX_ALLOCATE alloca -#endif /* not REGEX_MALLOC */ +#endif /* not REGEX_MALLOC */ #ifdef RX_WANT_RX_DEFS #define RX_DECL extern -#define RX_DEF_QUAL +#define RX_DEF_QUAL #else #define RX_WANT_RX_DEFS #define RX_DECL static @@ -114,137 +115,132 @@ char *alloca (); */ #ifdef __STDC__ RX_DECL struct rx_hash_item - *rx_hash_find (struct rx_hash *, unsigned long, - void *, struct rx_hash_rules *); +*rx_hash_find(struct rx_hash *, unsigned long, + + void *, struct rx_hash_rules *); RX_DECL struct rx_hash_item - *rx_hash_find (struct rx_hash *, unsigned long, - void *, struct rx_hash_rules *); +*rx_hash_find(struct rx_hash *, unsigned long, + + void *, struct rx_hash_rules *); RX_DECL struct rx_hash_item - *rx_hash_store (struct rx_hash *, unsigned long, - void *, struct rx_hash_rules *); -RX_DECL void rx_hash_free (struct rx_hash_item *, - struct rx_hash_rules *); -RX_DECL void rx_free_hash_table (struct rx_hash *, rx_hash_freefn, - struct rx_hash_rules *); -RX_DECL rx_Bitset - rx_cset (struct rx *); -RX_DECL rx_Bitset - rx_copy_cset (struct rx *, rx_Bitset); -RX_DECL void rx_free_cset (struct rx *, rx_Bitset); +*rx_hash_store(struct rx_hash *, unsigned long, + + void *, struct rx_hash_rules *); +RX_DECL void rx_hash_free(struct rx_hash_item *, struct rx_hash_rules *); +RX_DECL void rx_free_hash_table(struct rx_hash *, rx_hash_freefn, + + struct rx_hash_rules *); +RX_DECL rx_Bitset rx_cset(struct rx *); +RX_DECL rx_Bitset rx_copy_cset(struct rx *, rx_Bitset); +RX_DECL void rx_free_cset(struct rx *, rx_Bitset); static struct rx_hash_item - *compiler_hash_item_alloc (struct rx_hash_rules *, void *); +*compiler_hash_item_alloc(struct rx_hash_rules *, void *); static struct rx_hash - *compiler_hash_alloc (struct rx_hash_rules *); -static void compiler_free_hash (struct rx_hash *, - struct rx_hash_rules *); -static void compiler_free_hash_item (struct rx_hash_item *, - struct rx_hash_rules *); +*compiler_hash_alloc(struct rx_hash_rules *); +static void compiler_free_hash(struct rx_hash *, struct rx_hash_rules *); +static void compiler_free_hash_item(struct rx_hash_item *, + + struct rx_hash_rules *); RX_DECL struct rexp_node - *rexp_node (struct rx *, enum rexp_node_type); +*rexp_node(struct rx *, enum rexp_node_type); RX_DECL struct rexp_node - *rx_mk_r_cset (struct rx *, rx_Bitset); +*rx_mk_r_cset(struct rx *, rx_Bitset); RX_DECL struct rexp_node - *rx_mk_r_concat (struct rx *, struct rexp_node *, - struct rexp_node *); +*rx_mk_r_concat(struct rx *, struct rexp_node *, struct rexp_node *); RX_DECL struct rexp_node - *rx_mk_r_alternate (struct rx *, struct rexp_node *, - struct rexp_node *); +*rx_mk_r_alternate(struct rx *, struct rexp_node *, struct rexp_node *); RX_DECL struct rexp_node - *rx_mk_r_alternate (struct rx *, struct rexp_node *, - struct rexp_node *); +*rx_mk_r_alternate(struct rx *, struct rexp_node *, struct rexp_node *); RX_DECL struct rexp_node - *rx_mk_r_opt (struct rx *, struct rexp_node *); +*rx_mk_r_opt(struct rx *, struct rexp_node *); RX_DECL struct rexp_node - *rx_mk_r_star (struct rx *, struct rexp_node *); +*rx_mk_r_star(struct rx *, struct rexp_node *); RX_DECL struct rexp_node - *rx_mk_r_2phase_star (struct rx *, struct rexp_node *, - struct rexp_node *); +*rx_mk_r_2phase_star(struct rx *, struct rexp_node *, struct rexp_node *); RX_DECL struct rexp_node - *rx_mk_r_side_effect (struct rx *, rx_side_effect); +*rx_mk_r_side_effect(struct rx *, rx_side_effect); + //RX_DECL struct rexp_node // *rx_mk_r_data (struct rx *, void *); -RX_DECL void rx_free_rexp (struct rx *, struct rexp_node *); +RX_DECL void rx_free_rexp(struct rx *, struct rexp_node *); RX_DECL struct rexp_node - *rx_copy_rexp (struct rx *, struct rexp_node *); +*rx_copy_rexp(struct rx *, struct rexp_node *); RX_DECL struct rx_nfa_state - *rx_nfa_state (struct rx *); -RX_DECL void rx_free_nfa_state (struct rx_nfa_state *); +*rx_nfa_state(struct rx *); +RX_DECL void rx_free_nfa_state(struct rx_nfa_state *); RX_DECL struct rx_nfa_state - *rx_id_to_nfa_state (struct rx *, int); +*rx_id_to_nfa_state(struct rx *, int); RX_DECL struct rx_nfa_edge - *rx_nfa_edge (struct rx *, enum rx_nfa_etype, - struct rx_nfa_state *, - struct rx_nfa_state *); -RX_DECL void rx_free_nfa_edge (struct rx_nfa_edge *); +*rx_nfa_edge(struct rx *, enum rx_nfa_etype, + + struct rx_nfa_state *, struct rx_nfa_state *); +RX_DECL void rx_free_nfa_edge(struct rx_nfa_edge *); static struct rx_possible_future - *rx_possible_future (struct rx *, struct rx_se_list *); -static void rx_free_possible_future (struct rx_possible_future *); -RX_DECL void rx_free_nfa (struct rx *); -RX_DECL int rx_build_nfa (struct rx *, struct rexp_node *, - struct rx_nfa_state **, - struct rx_nfa_state **); -RX_DECL void rx_name_nfa_states (struct rx *); -static int se_list_cmp (void *, void *); -static int se_list_equal (void *, void *); +*rx_possible_future(struct rx *, struct rx_se_list *); +static void rx_free_possible_future(struct rx_possible_future *); +RX_DECL void rx_free_nfa(struct rx *); +RX_DECL int rx_build_nfa(struct rx *, struct rexp_node *, + struct rx_nfa_state **, struct rx_nfa_state **); +RX_DECL void rx_name_nfa_states(struct rx *); +static int se_list_cmp(void *, void *); +static int se_list_equal(void *, void *); static struct rx_se_list - *hash_cons_se_prog (struct rx *, struct rx_hash *, - void *, struct rx_se_list *); +*hash_cons_se_prog(struct rx *, struct rx_hash *, + + void *, struct rx_se_list *); static struct rx_se_list - *hash_se_prog (struct rx *, struct rx_hash *, - struct rx_se_list *); -static int nfa_set_cmp (void *, void *); -static int nfa_set_equal (void *, void *); +*hash_se_prog(struct rx *, struct rx_hash *, struct rx_se_list *); +static int nfa_set_cmp(void *, void *); +static int nfa_set_equal(void *, void *); static struct rx_nfa_state_set - *nfa_set_cons (struct rx *, struct rx_hash *, - struct rx_nfa_state *, - struct rx_nfa_state_set *); +*nfa_set_cons(struct rx *, struct rx_hash *, + + struct rx_nfa_state *, struct rx_nfa_state_set *); static struct rx_nfa_state_set - *nfa_set_enjoin (struct rx *, struct rx_hash *, - struct rx_nfa_state *, - struct rx_nfa_state_set *); +*nfa_set_enjoin(struct rx *, struct rx_hash *, + + struct rx_nfa_state *, struct rx_nfa_state_set *); #endif #ifndef emacs #ifdef SYNTAX_TABLE extern char *re_syntax_table; -#else /* not SYNTAX_TABLE */ +#else /* not SYNTAX_TABLE */ #ifndef RX_WANT_RX_DEFS RX_DECL char re_syntax_table[CHAR_SET_SIZE]; #endif #ifdef __STDC__ -static void -init_syntax_once (void) +static void init_syntax_once(void) #else -static void -init_syntax_once () +static void init_syntax_once() #endif { - register int c; - static int done = 0; + register int c; + static int done = 0; - if (done) - return; + if (done) + return; - bzero (re_syntax_table, sizeof re_syntax_table); + bzero(re_syntax_table, sizeof re_syntax_table); - for (c = 'a'; c <= 'z'; c++) - re_syntax_table[c] = Sword; + for (c = 'a'; c <= 'z'; c++) + re_syntax_table[c] = Sword; - for (c = 'A'; c <= 'Z'; c++) - re_syntax_table[c] = Sword; + for (c = 'A'; c <= 'Z'; c++) + re_syntax_table[c] = Sword; - for (c = '0'; c <= '9'; c++) - re_syntax_table[c] = Sword; + for (c = '0'; c <= '9'; c++) + re_syntax_table[c] = Sword; - re_syntax_table['_'] = Sword; + re_syntax_table['_'] = Sword; - done = 1; + done = 1; } -#endif /* not SYNTAX_TABLE */ -#endif /* not emacs */ +#endif /* not SYNTAX_TABLE */ +#endif /* not emacs */ /* Compile with `-DRX_DEBUG' and use the following flags. * @@ -257,7 +253,7 @@ init_syntax_once () int rx_debug_compile = 0; int rx_debug_trace = 0; -static struct re_pattern_buffer * dbug_rxb = 0; +static struct re_pattern_buffer *dbug_rxb = 0; /* @@ -265,903 +261,845 @@ static struct re_pattern_buffer * dbug_rxb = 0; */ #ifdef __STDC__ typedef void (*side_effect_printer) (struct rx *, void *, FILE *); -static void print_cset (struct rx *, rx_Bitset, FILE *); -static void print_rexp (struct rx *, struct rexp_node *, int, - side_effect_printer, FILE *); -static void print_nfa (struct rx *, struct rx_nfa_state *, - side_effect_printer, FILE *); -static void re_seprint (struct rx *, void *, FILE *); -void print_compiled_pattern (struct re_pattern_buffer *); -void print_fastmap (char *); +static void print_cset(struct rx *, rx_Bitset, FILE *); +static void print_rexp(struct rx *, struct rexp_node *, int, + side_effect_printer, FILE *); +static void print_nfa(struct rx *, struct rx_nfa_state *, + side_effect_printer, FILE *); +static void re_seprint(struct rx *, void *, FILE *); +void print_compiled_pattern(struct re_pattern_buffer *); +void print_fastmap(char *); #else typedef void (*side_effect_printer) (); -static void print_cset (); +static void print_cset(); #endif #ifdef __STDC__ static void -print_rexp (struct rx *rx, - struct rexp_node *node, int depth, - side_effect_printer seprint, FILE * fp) -#else -static void -print_rexp (rx, node, depth, seprint, fp) - struct rx *rx; - struct rexp_node *node; - int depth; - side_effect_printer seprint; - FILE * fp; -#endif -{ - if (!node) - return; - else - { - switch (node->type) - { - case r_cset: - { - fprintf (fp, "%*s", depth, ""); - print_cset (rx, node->params.cset, fp); - fputc ('\n', fp); - break; - } - - case r_opt: - case r_star: - fprintf (fp, "%*s%s\n", depth, "", - node->type == r_opt ? "opt" : "star"); - print_rexp (rx, node->params.pair.left, depth + 3, seprint, fp); - break; - - case r_2phase_star: - fprintf (fp, "%*s2phase star\n", depth, ""); - print_rexp (rx, node->params.pair.right, depth + 3, seprint, fp); - print_rexp (rx, node->params.pair.left, depth + 3, seprint, fp); - break; - +print_rexp(struct rx *rx, + struct rexp_node *node, int depth, + side_effect_printer seprint, FILE * fp) +#else +static void print_rexp(rx, node, depth, seprint, fp) +struct rx *rx; +struct rexp_node *node; +int depth; +side_effect_printer seprint; +FILE *fp; +#endif +{ + if (!node) + return; + else { + switch (node->type) { + case r_cset: + { + fprintf(fp, "%*s", depth, ""); + print_cset(rx, node->params.cset, fp); + fputc('\n', fp); + break; + } - case r_alternate: - case r_concat: - fprintf (fp, "%*s%s\n", depth, "", - node->type == r_alternate ? "alt" : "concat"); - print_rexp (rx, node->params.pair.left, depth + 3, seprint, fp); - print_rexp (rx, node->params.pair.right, depth + 3, seprint, fp); - break; - case r_side_effect: - fprintf (fp, "%*sSide effect: ", depth, ""); - seprint (rx, node->params.side_effect, fp); - fputc ('\n', fp); + case r_opt: + case r_star: + fprintf(fp, "%*s%s\n", depth, "", + node->type == r_opt ? "opt" : "star"); + print_rexp(rx, node->params.pair.left, depth + 3, seprint, fp); + break; + + case r_2phase_star: + fprintf(fp, "%*s2phase star\n", depth, ""); + print_rexp(rx, node->params.pair.right, depth + 3, seprint, + fp); + print_rexp(rx, node->params.pair.left, depth + 3, seprint, fp); + break; + + + case r_alternate: + case r_concat: + fprintf(fp, "%*s%s\n", depth, "", + node->type == r_alternate ? "alt" : "concat"); + print_rexp(rx, node->params.pair.left, depth + 3, seprint, fp); + print_rexp(rx, node->params.pair.right, depth + 3, seprint, + fp); + break; + case r_side_effect: + fprintf(fp, "%*sSide effect: ", depth, ""); + seprint(rx, node->params.side_effect, fp); + fputc('\n', fp); + } } - } } #ifdef __STDC__ static void -print_nfa (struct rx * rx, - struct rx_nfa_state * n, - side_effect_printer seprint, FILE * fp) -#else -static void -print_nfa (rx, n, seprint, fp) - struct rx * rx; - struct rx_nfa_state * n; - side_effect_printer seprint; - FILE * fp; -#endif -{ - while (n) - { - struct rx_nfa_edge *e = n->edges; - struct rx_possible_future *ec = n->futures; - fprintf (fp, "node %d %s\n", n->id, - n->is_final ? "final" : (n->is_start ? "start" : "")); - while (e) - { - fprintf (fp, " edge to %d, ", e->dest->id); - switch (e->type) - { - case ne_epsilon: - fprintf (fp, "epsilon\n"); - break; - case ne_side_effect: - fprintf (fp, "side effect "); - seprint (rx, e->params.side_effect, fp); - fputc ('\n', fp); - break; - case ne_cset: - fprintf (fp, "cset "); - print_cset (rx, e->params.cset, fp); - fputc ('\n', fp); - break; - } - e = e->next; - } +print_nfa(struct rx *rx, + struct rx_nfa_state *n, side_effect_printer seprint, FILE * fp) +#else +static void print_nfa(rx, n, seprint, fp) +struct rx *rx; +struct rx_nfa_state *n; +side_effect_printer seprint; +FILE *fp; +#endif +{ + while (n) { + struct rx_nfa_edge *e = n->edges; + struct rx_possible_future *ec = n->futures; + + fprintf(fp, "node %d %s\n", n->id, + n->is_final ? "final" : (n->is_start ? "start" : "")); + while (e) { + fprintf(fp, " edge to %d, ", e->dest->id); + switch (e->type) { + case ne_epsilon: + fprintf(fp, "epsilon\n"); + break; + case ne_side_effect: + fprintf(fp, "side effect "); + seprint(rx, e->params.side_effect, fp); + fputc('\n', fp); + break; + case ne_cset: + fprintf(fp, "cset "); + print_cset(rx, e->params.cset, fp); + fputc('\n', fp); + break; + } + e = e->next; + } - while (ec) - { - int x; - struct rx_nfa_state_set * s; - struct rx_se_list * l; - fprintf (fp, " eclosure to {"); - for (s = ec->destset; s; s = s->cdr) - fprintf (fp, "%d ", s->car->id); - fprintf (fp, "} ("); - for (l = ec->effects; l; l = l->cdr) - { - seprint (rx, l->car, fp); - fputc (' ', fp); - } - fprintf (fp, ")\n"); - ec = ec->next; + while (ec) { + int x; + struct rx_nfa_state_set *s; + struct rx_se_list *l; + + fprintf(fp, " eclosure to {"); + for (s = ec->destset; s; s = s->cdr) + fprintf(fp, "%d ", s->car->id); + fprintf(fp, "} ("); + for (l = ec->effects; l; l = l->cdr) { + seprint(rx, l->car, fp); + fputc(' ', fp); + } + fprintf(fp, ")\n"); + ec = ec->next; + } + n = n->next; } - n = n->next; - } } -static char * efnames [] = -{ - "bogon", - "re_se_try", - "re_se_pushback", - "re_se_push0", - "re_se_pushpos", - "re_se_chkpos", - "re_se_poppos", - "re_se_at_dot", - "re_se_syntax", - "re_se_not_syntax", - "re_se_begbuf", - "re_se_hat", - "re_se_wordbeg", - "re_se_wordbound", - "re_se_notwordbound", - "re_se_wordend", - "re_se_endbuf", - "re_se_dollar", - "re_se_fail", +static char *efnames[] = { + "bogon", + "re_se_try", + "re_se_pushback", + "re_se_push0", + "re_se_pushpos", + "re_se_chkpos", + "re_se_poppos", + "re_se_at_dot", + "re_se_syntax", + "re_se_not_syntax", + "re_se_begbuf", + "re_se_hat", + "re_se_wordbeg", + "re_se_wordbound", + "re_se_notwordbound", + "re_se_wordend", + "re_se_endbuf", + "re_se_dollar", + "re_se_fail", }; -static char * efnames2[] = -{ - "re_se_win", - "re_se_lparen", - "re_se_rparen", - "re_se_backref", - "re_se_iter", - "re_se_end_iter", - "re_se_tv" +static char *efnames2[] = { + "re_se_win", + "re_se_lparen", + "re_se_rparen", + "re_se_backref", + "re_se_iter", + "re_se_end_iter", + "re_se_tv" }; -static char * inx_names[] = -{ - "rx_backtrack_point", - "rx_do_side_effects", - "rx_cache_miss", - "rx_next_char", - "rx_backtrack", - "rx_error_inx", - "rx_num_instructions" +static char *inx_names[] = { + "rx_backtrack_point", + "rx_do_side_effects", + "rx_cache_miss", + "rx_next_char", + "rx_backtrack", + "rx_error_inx", + "rx_num_instructions" }; #ifdef __STDC__ -static void -re_seprint (struct rx * rx, void * effect, FILE * fp) +static void re_seprint(struct rx *rx, void *effect, FILE * fp) #else -static void -re_seprint (rx, effect, fp) - struct rx * rx; - void * effect; - FILE * fp; -#endif -{ - if ((int)effect < 0) - fputs (efnames[-(int)effect], fp); - else if (dbug_rxb) - { - struct re_se_params * p = &dbug_rxb->se_params[(int)effect]; - fprintf (fp, "%s(%d,%d)", efnames2[p->se], p->op1, p->op2); - } - else - fprintf (fp, "[complex op # %d]", (int)effect); +static void re_seprint(rx, effect, fp) +struct rx *rx; +void *effect; +FILE *fp; +#endif +{ + if ((int) effect < 0) + fputs(efnames[-(int) effect], fp); + else if (dbug_rxb) { + struct re_se_params *p = &dbug_rxb->se_params[(int) effect]; + + fprintf(fp, "%s(%d,%d)", efnames2[p->se], p->op1, p->op2); + } else + fprintf(fp, "[complex op # %d]", (int) effect); } /* These are so the regex.c regression tests will compile. */ -void -print_compiled_pattern (rxb) - struct re_pattern_buffer * rxb; +void print_compiled_pattern(rxb) +struct re_pattern_buffer *rxb; { } -void -print_fastmap (fm) - char * fm; +void print_fastmap(fm) +char *fm; { } -#endif /* RX_DEBUG */ - +#endif /* RX_DEBUG */ + /* This page: Bitsets. Completely unintersting. */ //RX_DECL int rx_bitset_is_equal (int, rx_Bitset, rx_Bitset); -RX_DECL int rx_bitset_is_subset (int, rx_Bitset, rx_Bitset); +RX_DECL int rx_bitset_is_subset(int, rx_Bitset, rx_Bitset); + //RX_DECL int rx_bitset_empty (int, rx_Bitset); -RX_DECL void rx_bitset_null (int, rx_Bitset); -RX_DECL void rx_bitset_complement (int, rx_Bitset); -RX_DECL void rx_bitset_complement (int, rx_Bitset); -RX_DECL void rx_bitset_assign (int, rx_Bitset, rx_Bitset); -RX_DECL void rx_bitset_union (int, rx_Bitset, rx_Bitset); -RX_DECL void rx_bitset_intersection (int, rx_Bitset, rx_Bitset); -RX_DECL void rx_bitset_difference (int, rx_Bitset, rx_Bitset); +RX_DECL void rx_bitset_null(int, rx_Bitset); +RX_DECL void rx_bitset_complement(int, rx_Bitset); +RX_DECL void rx_bitset_complement(int, rx_Bitset); +RX_DECL void rx_bitset_assign(int, rx_Bitset, rx_Bitset); +RX_DECL void rx_bitset_union(int, rx_Bitset, rx_Bitset); +RX_DECL void rx_bitset_intersection(int, rx_Bitset, rx_Bitset); +RX_DECL void rx_bitset_difference(int, rx_Bitset, rx_Bitset); + //RX_DECL void rx_bitset_revdifference (int, rx_Bitset, rx_Bitset); #ifdef emacs -RX_DECL void rx_bitset_xor (int, rx_Bitset, rx_Bitset); +RX_DECL void rx_bitset_xor(int, rx_Bitset, rx_Bitset); #endif -RX_DECL unsigned long - rx_bitset_hash (int, rx_Bitset); +RX_DECL unsigned long rx_bitset_hash(int, rx_Bitset); #if 0 #ifdef __STDC__ -RX_DECL int -rx_bitset_is_equal (int size, rx_Bitset a, rx_Bitset b) +RX_DECL int rx_bitset_is_equal(int size, rx_Bitset a, rx_Bitset b) #else -RX_DECL int -rx_bitset_is_equal (size, a, b) - int size; - rx_Bitset a; - rx_Bitset b; +RX_DECL int rx_bitset_is_equal(size, a, b) +int size; +rx_Bitset a; +rx_Bitset b; #endif { - int x; - RX_subset s = b[0]; - b[0] = ~a[0]; + int x; + RX_subset s = b[0]; - for (x = rx_bitset_numb_subsets(size) - 1; a[x] == b[x]; --x) - ; + b[0] = ~a[0]; - b[0] = s; - return !x && s == a[0]; + for (x = rx_bitset_numb_subsets(size) - 1; a[x] == b[x]; --x); + + b[0] = s; + return !x && s == a[0]; } #endif #ifdef __STDC__ -RX_DECL int -rx_bitset_is_subset (int size, rx_Bitset a, rx_Bitset b) +RX_DECL int rx_bitset_is_subset(int size, rx_Bitset a, rx_Bitset b) #else -RX_DECL int -rx_bitset_is_subset (size, a, b) - int size; - rx_Bitset a; - rx_Bitset b; +RX_DECL int rx_bitset_is_subset(size, a, b) +int size; +rx_Bitset a; +rx_Bitset b; #endif { - int x = rx_bitset_numb_subsets(size) - 1; - while (x-- && (a[x] & b[x]) == a[x]); - return x == -1; + int x = rx_bitset_numb_subsets(size) - 1; + + while (x-- && (a[x] & b[x]) == a[x]); + return x == -1; } #if 0 #ifdef __STDC__ -RX_DECL int -rx_bitset_empty (int size, rx_Bitset set) +RX_DECL int rx_bitset_empty(int size, rx_Bitset set) #else -RX_DECL int -rx_bitset_empty (size, set) - int size; - rx_Bitset set; +RX_DECL int rx_bitset_empty(size, set) +int size; +rx_Bitset set; #endif { - int x; - RX_subset s = set[0]; - set[0] = 1; - for (x = rx_bitset_numb_subsets(size) - 1; !set[x]; --x) - ; - set[0] = s; - return !s; + int x; + RX_subset s = set[0]; + + set[0] = 1; + for (x = rx_bitset_numb_subsets(size) - 1; !set[x]; --x); + set[0] = s; + return !s; } #endif #ifdef __STDC__ -RX_DECL void -rx_bitset_null (int size, rx_Bitset b) +RX_DECL void rx_bitset_null(int size, rx_Bitset b) #else -RX_DECL void -rx_bitset_null (size, b) - int size; - rx_Bitset b; +RX_DECL void rx_bitset_null(size, b) +int size; +rx_Bitset b; #endif { - bzero (b, rx_sizeof_bitset(size)); + bzero(b, rx_sizeof_bitset(size)); } #ifdef __STDC__ -RX_DECL void -rx_bitset_universe (int size, rx_Bitset b) +RX_DECL void rx_bitset_universe(int size, rx_Bitset b) #else -RX_DECL void -rx_bitset_universe (size, b) - int size; - rx_Bitset b; +RX_DECL void rx_bitset_universe(size, b) +int size; +rx_Bitset b; #endif { - int x = rx_bitset_numb_subsets (size); - while (x--) - *b++ = ~(RX_subset)0; + int x = rx_bitset_numb_subsets(size); + + while (x--) + *b++ = ~(RX_subset) 0; } #ifdef __STDC__ -RX_DECL void -rx_bitset_complement (int size, rx_Bitset b) +RX_DECL void rx_bitset_complement(int size, rx_Bitset b) #else -RX_DECL void -rx_bitset_complement (size, b) - int size; - rx_Bitset b; +RX_DECL void rx_bitset_complement(size, b) +int size; +rx_Bitset b; #endif { - int x = rx_bitset_numb_subsets (size); - while (x--) - { - *b = ~*b; - ++b; - } + int x = rx_bitset_numb_subsets(size); + + while (x--) { + *b = ~*b; + ++b; + } } #ifdef __STDC__ -RX_DECL void -rx_bitset_assign (int size, rx_Bitset a, rx_Bitset b) +RX_DECL void rx_bitset_assign(int size, rx_Bitset a, rx_Bitset b) #else -RX_DECL void -rx_bitset_assign (size, a, b) - int size; - rx_Bitset a; - rx_Bitset b; +RX_DECL void rx_bitset_assign(size, a, b) +int size; +rx_Bitset a; +rx_Bitset b; #endif { - int x; - for (x = rx_bitset_numb_subsets(size) - 1; x >=0; --x) - a[x] = b[x]; + int x; + + for (x = rx_bitset_numb_subsets(size) - 1; x >= 0; --x) + a[x] = b[x]; } #ifdef __STDC__ -RX_DECL void -rx_bitset_union (int size, rx_Bitset a, rx_Bitset b) +RX_DECL void rx_bitset_union(int size, rx_Bitset a, rx_Bitset b) #else -RX_DECL void -rx_bitset_union (size, a, b) - int size; - rx_Bitset a; - rx_Bitset b; +RX_DECL void rx_bitset_union(size, a, b) +int size; +rx_Bitset a; +rx_Bitset b; #endif { - int x; - for (x = rx_bitset_numb_subsets(size) - 1; x >=0; --x) - a[x] |= b[x]; + int x; + + for (x = rx_bitset_numb_subsets(size) - 1; x >= 0; --x) + a[x] |= b[x]; } #ifdef __STDC__ -RX_DECL void -rx_bitset_intersection (int size, - rx_Bitset a, rx_Bitset b) +RX_DECL void rx_bitset_intersection(int size, rx_Bitset a, rx_Bitset b) #else -RX_DECL void -rx_bitset_intersection (size, a, b) - int size; - rx_Bitset a; - rx_Bitset b; +RX_DECL void rx_bitset_intersection(size, a, b) +int size; +rx_Bitset a; +rx_Bitset b; #endif { - int x; - for (x = rx_bitset_numb_subsets(size) - 1; x >=0; --x) - a[x] &= b[x]; + int x; + + for (x = rx_bitset_numb_subsets(size) - 1; x >= 0; --x) + a[x] &= b[x]; } #ifdef __STDC__ -RX_DECL void -rx_bitset_difference (int size, rx_Bitset a, rx_Bitset b) +RX_DECL void rx_bitset_difference(int size, rx_Bitset a, rx_Bitset b) #else -RX_DECL void -rx_bitset_difference (size, a, b) - int size; - rx_Bitset a; - rx_Bitset b; +RX_DECL void rx_bitset_difference(size, a, b) +int size; +rx_Bitset a; +rx_Bitset b; #endif { - int x; - for (x = rx_bitset_numb_subsets(size) - 1; x >=0; --x) - a[x] &= ~ b[x]; + int x; + + for (x = rx_bitset_numb_subsets(size) - 1; x >= 0; --x) + a[x] &= ~b[x]; } #if 0 #ifdef __STDC__ -RX_DECL void -rx_bitset_revdifference (int size, - rx_Bitset a, rx_Bitset b) +RX_DECL void rx_bitset_revdifference(int size, rx_Bitset a, rx_Bitset b) #else -RX_DECL void -rx_bitset_revdifference (size, a, b) - int size; - rx_Bitset a; - rx_Bitset b; +RX_DECL void rx_bitset_revdifference(size, a, b) +int size; +rx_Bitset a; +rx_Bitset b; #endif { - int x; - for (x = rx_bitset_numb_subsets(size) - 1; x >=0; --x) - a[x] = ~a[x] & b[x]; + int x; + + for (x = rx_bitset_numb_subsets(size) - 1; x >= 0; --x) + a[x] = ~a[x] & b[x]; } #endif #ifdef emacs #ifdef __STDC__ -RX_DECL void -rx_bitset_xor (int size, rx_Bitset a, rx_Bitset b) +RX_DECL void rx_bitset_xor(int size, rx_Bitset a, rx_Bitset b) #else -RX_DECL void -rx_bitset_xor (size, a, b) - int size; - rx_Bitset a; - rx_Bitset b; -#endif -{ - int x; - for (x = rx_bitset_numb_subsets(size) - 1; x >=0; --x) - a[x] ^= b[x]; -} -#endif - - -#ifdef __STDC__ -RX_DECL unsigned long -rx_bitset_hash (int size, rx_Bitset b) -#else -RX_DECL unsigned long -rx_bitset_hash (size, b) - int size; - rx_Bitset b; -#endif -{ - int x; - unsigned long hash = (unsigned long)rx_bitset_hash; - - for (x = rx_bitset_numb_subsets(size) - 1; x >= 0; --x) - hash ^= rx_bitset_subset_val(b, x); - - return hash; -} - -RX_DECL RX_subset rx_subset_singletons [RX_subset_bits] = -{ - 0x1, - 0x2, - 0x4, - 0x8, - 0x10, - 0x20, - 0x40, - 0x80, - 0x100, - 0x200, - 0x400, - 0x800, - 0x1000, - 0x2000, - 0x4000, - 0x8000, - 0x10000, - 0x20000, - 0x40000, - 0x80000, - 0x100000, - 0x200000, - 0x400000, - 0x800000, - 0x1000000, - 0x2000000, - 0x4000000, - 0x8000000, - 0x10000000, - 0x20000000, - 0x40000000, - 0x80000000 +RX_DECL void rx_bitset_xor(size, a, b) +int size; +rx_Bitset a; +rx_Bitset b; +#endif +{ + int x; + + for (x = rx_bitset_numb_subsets(size) - 1; x >= 0; --x) + a[x] ^= b[x]; +} +#endif + + +#ifdef __STDC__ +RX_DECL unsigned long rx_bitset_hash(int size, rx_Bitset b) +#else +RX_DECL unsigned long rx_bitset_hash(size, b) +int size; +rx_Bitset b; +#endif +{ + int x; + unsigned long hash = (unsigned long) rx_bitset_hash; + + for (x = rx_bitset_numb_subsets(size) - 1; x >= 0; --x) + hash ^= rx_bitset_subset_val(b, x); + + return hash; +} + +RX_DECL RX_subset rx_subset_singletons[RX_subset_bits] = { + 0x1, + 0x2, + 0x4, + 0x8, + 0x10, + 0x20, + 0x40, + 0x80, + 0x100, + 0x200, + 0x400, + 0x800, + 0x1000, + 0x2000, + 0x4000, + 0x8000, + 0x10000, + 0x20000, + 0x40000, + 0x80000, + 0x100000, + 0x200000, + 0x400000, + 0x800000, + 0x1000000, + 0x2000000, + 0x4000000, + 0x8000000, + 0x10000000, + 0x20000000, + 0x40000000, + 0x80000000 }; #ifdef RX_DEBUG #ifdef __STDC__ -static void -print_cset (struct rx *rx, rx_Bitset cset, FILE * fp) +static void print_cset(struct rx *rx, rx_Bitset cset, FILE * fp) #else -static void -print_cset (rx, cset, fp) - struct rx *rx; - rx_Bitset cset; - FILE * fp; -#endif -{ - int x; - fputc ('[', fp); - for (x = 0; x < rx->local_cset_size; ++x) - if (RX_bitset_member (cset, x)) - { - if (isprint(x)) - fputc (x, fp); - else - fprintf (fp, "\\0%o ", x); - } - fputc (']', fp); -} +static void print_cset(rx, cset, fp) +struct rx *rx; +rx_Bitset cset; +FILE *fp; +#endif +{ + int x; -#endif /* RX_DEBUG */ + fputc('[', fp); + for (x = 0; x < rx->local_cset_size; ++x) + if (RX_bitset_member(cset, x)) { + if (isprint(x)) + fputc(x, fp); + else + fprintf(fp, "\\0%o ", x); + } + fputc(']', fp); +} +#endif /* RX_DEBUG */ -static unsigned long rx_hash_masks[4] = -{ - 0x12488421, - 0x96699669, - 0xbe7dd7eb, - 0xffffffff + +static unsigned long rx_hash_masks[4] = { + 0x12488421, + 0x96699669, + 0xbe7dd7eb, + 0xffffffff }; /* Hash tables */ #ifdef __STDC__ -RX_DECL struct rx_hash_item * -rx_hash_find (struct rx_hash * table, - unsigned long hash, - void * value, - struct rx_hash_rules * rules) -#else -RX_DECL struct rx_hash_item * -rx_hash_find (table, hash, value, rules) - struct rx_hash * table; - unsigned long hash; - void * value; - struct rx_hash_rules * rules; -#endif -{ - rx_hash_eq eq = rules->eq; - int maskc = 0; - long mask = rx_hash_masks [0]; - int bucket = (hash & mask) % 13; - - while (table->children [bucket]) - { - table = table->children [bucket]; - ++maskc; - mask = rx_hash_masks[maskc]; - bucket = (hash & mask) % 13; - } +RX_DECL struct rx_hash_item *rx_hash_find(struct rx_hash *table, + unsigned long hash, + void *value, + struct rx_hash_rules *rules) +#else +RX_DECL struct rx_hash_item *rx_hash_find(table, hash, value, rules) +struct rx_hash *table; +unsigned long hash; +void *value; +struct rx_hash_rules *rules; +#endif +{ + rx_hash_eq eq = rules->eq; + int maskc = 0; + long mask = rx_hash_masks[0]; + int bucket = (hash & mask) % 13; + + while (table->children[bucket]) { + table = table->children[bucket]; + ++maskc; + mask = rx_hash_masks[maskc]; + bucket = (hash & mask) % 13; + } - { - struct rx_hash_item * it = table->buckets[bucket]; - while (it) - if (eq (it->data, value)) - return it; - else - it = it->next_same_hash; - } - - return 0; -} - -#ifdef __STDC__ -RX_DECL struct rx_hash_item * -rx_hash_store (struct rx_hash * table, - unsigned long hash, - void * value, - struct rx_hash_rules * rules) -#else -RX_DECL struct rx_hash_item * -rx_hash_store (table, hash, value, rules) - struct rx_hash * table; - unsigned long hash; - void * value; - struct rx_hash_rules * rules; -#endif -{ - rx_hash_eq eq = rules->eq; - int maskc = 0; - long mask = rx_hash_masks[0]; - int bucket = (hash & mask) % 13; - int depth = 0; - - while (table->children [bucket]) - { - table = table->children [bucket]; - ++maskc; - mask = rx_hash_masks[maskc]; - bucket = (hash & mask) % 13; - ++depth; - } - - { - struct rx_hash_item * it = table->buckets[bucket]; - while (it) - if (eq (it->data, value)) - return it; - else - it = it->next_same_hash; - } - - { - if ( (depth < 3) - && (table->bucket_size [bucket] >= 4)) - { - struct rx_hash * newtab = ((struct rx_hash *) - rules->hash_alloc (rules)); - if (!newtab) - goto add_to_bucket; - bzero (newtab, sizeof (*newtab)); - newtab->parent = table; { - struct rx_hash_item * them = table->buckets[bucket]; - unsigned long newmask = rx_hash_masks[maskc + 1]; - while (them) - { - struct rx_hash_item * save = them->next_same_hash; - int new_buck = (them->hash & newmask) % 13; - them->next_same_hash = newtab->buckets[new_buck]; - newtab->buckets[new_buck] = them; - them->table = newtab; - them = save; - ++newtab->bucket_size[new_buck]; - ++newtab->refs; - } - table->refs = (table->refs - table->bucket_size[bucket] + 1); - table->bucket_size[bucket] = 0; - table->buckets[bucket] = 0; - table->children[bucket] = newtab; - table = newtab; - bucket = (hash & newmask) % 13; + struct rx_hash_item *it = table->buckets[bucket]; + + while (it) + if (eq(it->data, value)) + return it; + else + it = it->next_same_hash; } - } - } - add_to_bucket: - { - struct rx_hash_item * it = ((struct rx_hash_item *) - rules->hash_item_alloc (rules, value)); - if (!it) - return 0; - it->hash = hash; - it->table = table; - /* DATA and BINDING are to be set in hash_item_alloc */ - it->next_same_hash = table->buckets [bucket]; - table->buckets[bucket] = it; - ++table->bucket_size [bucket]; - ++table->refs; - return it; - } -} + return 0; +} #ifdef __STDC__ -RX_DECL void -rx_hash_free (struct rx_hash_item * it, struct rx_hash_rules * rules) +RX_DECL struct rx_hash_item *rx_hash_store(struct rx_hash *table, + unsigned long hash, + void *value, + struct rx_hash_rules *rules) #else -RX_DECL void -rx_hash_free (it, rules) - struct rx_hash_item * it; - struct rx_hash_rules * rules; -#endif -{ - if (it) - { - struct rx_hash * table = it->table; - unsigned long hash = it->hash; - int depth = (table->parent - ? (table->parent->parent - ? (table->parent->parent->parent - ? 3 - : 2) - : 1) - : 0); - int bucket = (hash & rx_hash_masks [depth]) % 13; - struct rx_hash_item ** pos = &table->buckets [bucket]; - - while (*pos != it) - pos = &(*pos)->next_same_hash; - *pos = it->next_same_hash; - rules->free_hash_item (it, rules); - --table->bucket_size[bucket]; - --table->refs; - while (!table->refs && depth) +RX_DECL struct rx_hash_item *rx_hash_store(table, hash, value, rules) +struct rx_hash *table; +unsigned long hash; +void *value; +struct rx_hash_rules *rules; +#endif +{ + rx_hash_eq eq = rules->eq; + int maskc = 0; + long mask = rx_hash_masks[0]; + int bucket = (hash & mask) % 13; + int depth = 0; + + while (table->children[bucket]) { + table = table->children[bucket]; + ++maskc; + mask = rx_hash_masks[maskc]; + bucket = (hash & mask) % 13; + ++depth; + } + { - struct rx_hash * save = table; - table = table->parent; - --depth; - bucket = (hash & rx_hash_masks [depth]) % 13; - --table->refs; - table->children[bucket] = 0; - rules->free_hash (save, rules); + struct rx_hash_item *it = table->buckets[bucket]; + + while (it) + if (eq(it->data, value)) + return it; + else + it = it->next_same_hash; + } + + { + if ((depth < 3) + && (table->bucket_size[bucket] >= 4)) { + struct rx_hash *newtab = ((struct rx_hash *) + rules->hash_alloc(rules)); + + if (!newtab) + goto add_to_bucket; + bzero(newtab, sizeof(*newtab)); + newtab->parent = table; + { + struct rx_hash_item *them = table->buckets[bucket]; + unsigned long newmask = rx_hash_masks[maskc + 1]; + + while (them) { + struct rx_hash_item *save = them->next_same_hash; + int new_buck = (them->hash & newmask) % 13; + + them->next_same_hash = newtab->buckets[new_buck]; + newtab->buckets[new_buck] = them; + them->table = newtab; + them = save; + ++newtab->bucket_size[new_buck]; + ++newtab->refs; + } + table->refs = + (table->refs - table->bucket_size[bucket] + 1); + table->bucket_size[bucket] = 0; + table->buckets[bucket] = 0; + table->children[bucket] = newtab; + table = newtab; + bucket = (hash & newmask) % 13; + } + } + } + add_to_bucket: + { + struct rx_hash_item *it = ((struct rx_hash_item *) + rules->hash_item_alloc(rules, value)); + + if (!it) + return 0; + it->hash = hash; + it->table = table; + /* DATA and BINDING are to be set in hash_item_alloc */ + it->next_same_hash = table->buckets[bucket]; + table->buckets[bucket] = it; + ++table->bucket_size[bucket]; + ++table->refs; + return it; + } +} + + +#ifdef __STDC__ +RX_DECL void +rx_hash_free(struct rx_hash_item *it, struct rx_hash_rules *rules) +#else +RX_DECL void rx_hash_free(it, rules) +struct rx_hash_item *it; +struct rx_hash_rules *rules; +#endif +{ + if (it) { + struct rx_hash *table = it->table; + unsigned long hash = it->hash; + int depth = (table->parent + ? (table->parent->parent + ? (table->parent->parent->parent ? 3 : 2) + : 1) + : 0); + int bucket = (hash & rx_hash_masks[depth]) % 13; + struct rx_hash_item **pos = &table->buckets[bucket]; + + while (*pos != it) + pos = &(*pos)->next_same_hash; + *pos = it->next_same_hash; + rules->free_hash_item(it, rules); + --table->bucket_size[bucket]; + --table->refs; + while (!table->refs && depth) { + struct rx_hash *save = table; + + table = table->parent; + --depth; + bucket = (hash & rx_hash_masks[depth]) % 13; + --table->refs; + table->children[bucket] = 0; + rules->free_hash(save, rules); + } } - } } #ifdef __STDC__ RX_DECL void -rx_free_hash_table (struct rx_hash * tab, rx_hash_freefn freefn, - struct rx_hash_rules * rules) +rx_free_hash_table(struct rx_hash *tab, rx_hash_freefn freefn, + struct rx_hash_rules *rules) #else -RX_DECL void -rx_free_hash_table (tab, freefn, rules) - struct rx_hash * tab; - rx_hash_freefn freefn; - struct rx_hash_rules * rules; -#endif -{ - int x; - - for (x = 0; x < 13; ++x) - if (tab->children[x]) - { - rx_free_hash_table (tab->children[x], freefn, rules); - rules->free_hash (tab->children[x], rules); - } - else - { - struct rx_hash_item * them = tab->buckets[x]; - while (them) - { - struct rx_hash_item * that = them; - them = that->next_same_hash; - freefn (that); - rules->free_hash_item (that, rules); - } - } -} +RX_DECL void rx_free_hash_table(tab, freefn, rules) +struct rx_hash *tab; +rx_hash_freefn freefn; +struct rx_hash_rules *rules; +#endif +{ + int x; + for (x = 0; x < 13; ++x) + if (tab->children[x]) { + rx_free_hash_table(tab->children[x], freefn, rules); + rules->free_hash(tab->children[x], rules); + } else { + struct rx_hash_item *them = tab->buckets[x]; + while (them) { + struct rx_hash_item *that = them; + + them = that->next_same_hash; + freefn(that); + rules->free_hash_item(that, rules); + } + } +} + + /* Utilities for manipulating bitset represntations of characters sets. */ #ifdef __STDC__ -RX_DECL rx_Bitset -rx_cset (struct rx *rx) +RX_DECL rx_Bitset rx_cset(struct rx *rx) #else -RX_DECL rx_Bitset -rx_cset (rx) - struct rx *rx; +RX_DECL rx_Bitset rx_cset(rx) +struct rx *rx; #endif { - rx_Bitset b = (rx_Bitset) malloc (rx_sizeof_bitset (rx->local_cset_size)); - if (b) - rx_bitset_null (rx->local_cset_size, b); - return b; + rx_Bitset b = + + (rx_Bitset) malloc(rx_sizeof_bitset(rx->local_cset_size)); + if (b) + rx_bitset_null(rx->local_cset_size, b); + return b; } #ifdef __STDC__ -RX_DECL rx_Bitset -rx_copy_cset (struct rx *rx, rx_Bitset a) +RX_DECL rx_Bitset rx_copy_cset(struct rx * rx, rx_Bitset a) #else -RX_DECL rx_Bitset -rx_copy_cset (rx, a) - struct rx *rx; - rx_Bitset a; +RX_DECL rx_Bitset rx_copy_cset(rx, a) +struct rx *rx; +rx_Bitset a; #endif { - rx_Bitset cs = rx_cset (rx); + rx_Bitset cs = rx_cset(rx); - if (cs) - rx_bitset_union (rx->local_cset_size, cs, a); + if (cs) + rx_bitset_union(rx->local_cset_size, cs, a); - return cs; + return cs; } #ifdef __STDC__ -RX_DECL void -rx_free_cset (struct rx * rx, rx_Bitset c) +RX_DECL void rx_free_cset(struct rx *rx, rx_Bitset c) #else -RX_DECL void -rx_free_cset (rx, c) - struct rx * rx; - rx_Bitset c; +RX_DECL void rx_free_cset(rx, c) +struct rx *rx; +rx_Bitset c; #endif { - if (c) - free ((char *)c); + if (c) + free((char *) c); } - + /* Hash table memory allocation policy for the regexp compiler */ #ifdef __STDC__ -static struct rx_hash * -compiler_hash_alloc (struct rx_hash_rules * rules) +static struct rx_hash *compiler_hash_alloc(struct rx_hash_rules *rules) #else -static struct rx_hash * -compiler_hash_alloc (rules) - struct rx_hash_rules * rules; +static struct rx_hash *compiler_hash_alloc(rules) +struct rx_hash_rules *rules; #endif { - return (struct rx_hash *)malloc (sizeof (struct rx_hash)); + return (struct rx_hash *) malloc(sizeof(struct rx_hash)); } #ifdef __STDC__ -static struct rx_hash_item * -compiler_hash_item_alloc (struct rx_hash_rules * rules, void * value) +static struct rx_hash_item *compiler_hash_item_alloc(struct rx_hash_rules + *rules, void *value) #else -static struct rx_hash_item * -compiler_hash_item_alloc (rules, value) - struct rx_hash_rules * rules; - void * value; +static struct rx_hash_item *compiler_hash_item_alloc(rules, value) +struct rx_hash_rules *rules; +void *value; #endif { - struct rx_hash_item * it; - it = (struct rx_hash_item *)malloc (sizeof (*it)); - if (it) - { - it->data = value; - it->binding = 0; - } - return it; + struct rx_hash_item *it; + + it = (struct rx_hash_item *) malloc(sizeof(*it)); + if (it) { + it->data = value; + it->binding = 0; + } + return it; } #ifdef __STDC__ static void -compiler_free_hash (struct rx_hash * tab, - struct rx_hash_rules * rules) +compiler_free_hash(struct rx_hash *tab, struct rx_hash_rules *rules) #else -static void -compiler_free_hash (tab, rules) - struct rx_hash * tab; - struct rx_hash_rules * rules; +static void compiler_free_hash(tab, rules) +struct rx_hash *tab; +struct rx_hash_rules *rules; #endif { - free ((char *)tab); + free((char *) tab); } #ifdef __STDC__ static void -compiler_free_hash_item (struct rx_hash_item * item, - struct rx_hash_rules * rules) +compiler_free_hash_item(struct rx_hash_item *item, + struct rx_hash_rules *rules) #else -static void -compiler_free_hash_item (item, rules) - struct rx_hash_item * item; - struct rx_hash_rules * rules; +static void compiler_free_hash_item(item, rules) +struct rx_hash_item *item; +struct rx_hash_rules *rules; #endif { - free ((char *)item); + free((char *) item); } - + /* This page: REXP_NODE (expression tree) structures. */ #ifdef __STDC__ -RX_DECL struct rexp_node * -rexp_node (struct rx *rx, - enum rexp_node_type type) +RX_DECL struct rexp_node *rexp_node(struct rx *rx, + enum rexp_node_type type) #else -RX_DECL struct rexp_node * -rexp_node (rx, type) - struct rx *rx; - enum rexp_node_type type; +RX_DECL struct rexp_node *rexp_node(rx, type) +struct rx *rx; +enum rexp_node_type type; #endif { - struct rexp_node *n; + struct rexp_node *n; - n = (struct rexp_node *)malloc (sizeof (*n)); - if (n) - { - bzero (n, sizeof (*n)); - n->type = type; - } - return n; + n = (struct rexp_node *) malloc(sizeof(*n)); + if (n) { + bzero(n, sizeof(*n)); + n->type = type; + } + return n; } @@ -1169,303 +1107,271 @@ rexp_node (rx, type) * can be freed using rx_free_cset. */ #ifdef __STDC__ -RX_DECL struct rexp_node * -rx_mk_r_cset (struct rx * rx, - rx_Bitset b) +RX_DECL struct rexp_node *rx_mk_r_cset(struct rx *rx, rx_Bitset b) #else -RX_DECL struct rexp_node * -rx_mk_r_cset (rx, b) - struct rx * rx; - rx_Bitset b; +RX_DECL struct rexp_node *rx_mk_r_cset(rx, b) +struct rx *rx; +rx_Bitset b; #endif { - struct rexp_node * n = rexp_node (rx, r_cset); - if (n) - n->params.cset = b; - return n; + struct rexp_node *n = rexp_node(rx, r_cset); + + if (n) + n->params.cset = b; + return n; } #ifdef __STDC__ -RX_DECL struct rexp_node * -rx_mk_r_concat (struct rx * rx, - struct rexp_node * a, - struct rexp_node * b) +RX_DECL struct rexp_node *rx_mk_r_concat(struct rx *rx, + struct rexp_node *a, + struct rexp_node *b) #else -RX_DECL struct rexp_node * -rx_mk_r_concat (rx, a, b) - struct rx * rx; - struct rexp_node * a; - struct rexp_node * b; +RX_DECL struct rexp_node *rx_mk_r_concat(rx, a, b) +struct rx *rx; +struct rexp_node *a; +struct rexp_node *b; #endif { - struct rexp_node * n = rexp_node (rx, r_concat); - if (n) - { - n->params.pair.left = a; - n->params.pair.right = b; - } - return n; + struct rexp_node *n = rexp_node(rx, r_concat); + + if (n) { + n->params.pair.left = a; + n->params.pair.right = b; + } + return n; } #ifdef __STDC__ -RX_DECL struct rexp_node * -rx_mk_r_alternate (struct rx * rx, - struct rexp_node * a, - struct rexp_node * b) +RX_DECL struct rexp_node *rx_mk_r_alternate(struct rx *rx, + struct rexp_node *a, + struct rexp_node *b) #else -RX_DECL struct rexp_node * -rx_mk_r_alternate (rx, a, b) - struct rx * rx; - struct rexp_node * a; - struct rexp_node * b; +RX_DECL struct rexp_node *rx_mk_r_alternate(rx, a, b) +struct rx *rx; +struct rexp_node *a; +struct rexp_node *b; #endif { - struct rexp_node * n = rexp_node (rx, r_alternate); - if (n) - { - n->params.pair.left = a; - n->params.pair.right = b; - } - return n; + struct rexp_node *n = rexp_node(rx, r_alternate); + + if (n) { + n->params.pair.left = a; + n->params.pair.right = b; + } + return n; } #ifdef __STDC__ -RX_DECL struct rexp_node * -rx_mk_r_opt (struct rx * rx, - struct rexp_node * a) +RX_DECL struct rexp_node *rx_mk_r_opt(struct rx *rx, struct rexp_node *a) #else -RX_DECL struct rexp_node * -rx_mk_r_opt (rx, a) - struct rx * rx; - struct rexp_node * a; +RX_DECL struct rexp_node *rx_mk_r_opt(rx, a) +struct rx *rx; +struct rexp_node *a; #endif { - struct rexp_node * n = rexp_node (rx, r_opt); - if (n) - { - n->params.pair.left = a; - n->params.pair.right = 0; - } - return n; + struct rexp_node *n = rexp_node(rx, r_opt); + + if (n) { + n->params.pair.left = a; + n->params.pair.right = 0; + } + return n; } #ifdef __STDC__ -RX_DECL struct rexp_node * -rx_mk_r_star (struct rx * rx, - struct rexp_node * a) +RX_DECL struct rexp_node *rx_mk_r_star(struct rx *rx, struct rexp_node *a) #else -RX_DECL struct rexp_node * -rx_mk_r_star (rx, a) - struct rx * rx; - struct rexp_node * a; +RX_DECL struct rexp_node *rx_mk_r_star(rx, a) +struct rx *rx; +struct rexp_node *a; #endif { - struct rexp_node * n = rexp_node (rx, r_star); - if (n) - { - n->params.pair.left = a; - n->params.pair.right = 0; - } - return n; + struct rexp_node *n = rexp_node(rx, r_star); + + if (n) { + n->params.pair.left = a; + n->params.pair.right = 0; + } + return n; } #ifdef __STDC__ -RX_DECL struct rexp_node * -rx_mk_r_2phase_star (struct rx * rx, - struct rexp_node * a, - struct rexp_node * b) +RX_DECL struct rexp_node *rx_mk_r_2phase_star(struct rx *rx, + struct rexp_node *a, + struct rexp_node *b) #else -RX_DECL struct rexp_node * -rx_mk_r_2phase_star (rx, a, b) - struct rx * rx; - struct rexp_node * a; - struct rexp_node * b; +RX_DECL struct rexp_node *rx_mk_r_2phase_star(rx, a, b) +struct rx *rx; +struct rexp_node *a; +struct rexp_node *b; #endif { - struct rexp_node * n = rexp_node (rx, r_2phase_star); - if (n) - { - n->params.pair.left = a; - n->params.pair.right = b; - } - return n; + struct rexp_node *n = rexp_node(rx, r_2phase_star); + + if (n) { + n->params.pair.left = a; + n->params.pair.right = b; + } + return n; } #ifdef __STDC__ -RX_DECL struct rexp_node * -rx_mk_r_side_effect (struct rx * rx, - rx_side_effect a) +RX_DECL struct rexp_node *rx_mk_r_side_effect(struct rx *rx, + rx_side_effect a) #else -RX_DECL struct rexp_node * -rx_mk_r_side_effect (rx, a) - struct rx * rx; - rx_side_effect a; +RX_DECL struct rexp_node *rx_mk_r_side_effect(rx, a) +struct rx *rx; +rx_side_effect a; #endif { - struct rexp_node * n = rexp_node (rx, r_side_effect); - if (n) - { - n->params.side_effect = a; - n->params.pair.right = 0; - } - return n; + struct rexp_node *n = rexp_node(rx, r_side_effect); + + if (n) { + n->params.side_effect = a; + n->params.pair.right = 0; + } + return n; } #if 0 #ifdef __STDC__ -RX_DECL struct rexp_node * -rx_mk_r_data (struct rx * rx, - void * a) +RX_DECL struct rexp_node *rx_mk_r_data(struct rx *rx, void *a) #else -RX_DECL struct rexp_node * -rx_mk_r_data (rx, a) - struct rx * rx; - void * a; +RX_DECL struct rexp_node *rx_mk_r_data(rx, a) +struct rx *rx; +void *a; #endif { - struct rexp_node * n = rexp_node (rx, r_data); - if (n) - { - n->params.pair.left = a; - n->params.pair.right = 0; - } - return n; + struct rexp_node *n = rexp_node(rx, r_data); + + if (n) { + n->params.pair.left = a; + n->params.pair.right = 0; + } + return n; } #endif #ifdef __STDC__ -RX_DECL void -rx_free_rexp (struct rx * rx, struct rexp_node * node) +RX_DECL void rx_free_rexp(struct rx *rx, struct rexp_node *node) #else -RX_DECL void -rx_free_rexp (rx, node) - struct rx * rx; - struct rexp_node * node; +RX_DECL void rx_free_rexp(rx, node) +struct rx *rx; +struct rexp_node *node; #endif { - if (node) - { - switch (node->type) - { - case r_cset: - if (node->params.cset) - rx_free_cset (rx, node->params.cset); + if (node) { + switch (node->type) { + case r_cset: + if (node->params.cset) + rx_free_cset(rx, node->params.cset); - case r_side_effect: - break; - - case r_concat: - case r_alternate: - case r_2phase_star: - case r_opt: - case r_star: - rx_free_rexp (rx, node->params.pair.left); - rx_free_rexp (rx, node->params.pair.right); - break; + case r_side_effect: + break; - case r_data: - /* This shouldn't occur. */ - break; + case r_concat: + case r_alternate: + case r_2phase_star: + case r_opt: + case r_star: + rx_free_rexp(rx, node->params.pair.left); + rx_free_rexp(rx, node->params.pair.right); + break; + + case r_data: + /* This shouldn't occur. */ + break; + } + free((char *) node); } - free ((char *)node); - } } #ifdef __STDC__ -RX_DECL struct rexp_node * -rx_copy_rexp (struct rx *rx, - struct rexp_node *node) +RX_DECL struct rexp_node *rx_copy_rexp(struct rx *rx, + struct rexp_node *node) #else -RX_DECL struct rexp_node * -rx_copy_rexp (rx, node) - struct rx *rx; - struct rexp_node *node; +RX_DECL struct rexp_node *rx_copy_rexp(rx, node) +struct rx *rx; +struct rexp_node *node; #endif { - if (!node) - return 0; - else - { - struct rexp_node *n = rexp_node (rx, node->type); - if (!n) - return 0; - switch (node->type) - { - case r_cset: - n->params.cset = rx_copy_cset (rx, node->params.cset); - if (!n->params.cset) - { - rx_free_rexp (rx, n); - return 0; - } - break; - - case r_side_effect: - n->params.side_effect = node->params.side_effect; - break; + if (!node) + return 0; + else { + struct rexp_node *n = rexp_node(rx, node->type); - case r_concat: - case r_alternate: - case r_opt: - case r_2phase_star: - case r_star: - n->params.pair.left = - rx_copy_rexp (rx, node->params.pair.left); - n->params.pair.right = - rx_copy_rexp (rx, node->params.pair.right); - if ( (node->params.pair.left && !n->params.pair.left) - || (node->params.pair.right && !n->params.pair.right)) - { - rx_free_rexp (rx, n); - return 0; - } - break; - case r_data: - /* shouldn't happen */ - break; + if (!n) + return 0; + switch (node->type) { + case r_cset: + n->params.cset = rx_copy_cset(rx, node->params.cset); + if (!n->params.cset) { + rx_free_rexp(rx, n); + return 0; + } + break; + + case r_side_effect: + n->params.side_effect = node->params.side_effect; + break; + + case r_concat: + case r_alternate: + case r_opt: + case r_2phase_star: + case r_star: + n->params.pair.left = rx_copy_rexp(rx, node->params.pair.left); + n->params.pair.right = + rx_copy_rexp(rx, node->params.pair.right); + if ((node->params.pair.left && !n->params.pair.left) + || (node->params.pair.right && !n->params.pair.right)) { + rx_free_rexp(rx, n); + return 0; + } + break; + case r_data: + /* shouldn't happen */ + break; + } + return n; } - return n; - } } + - /* This page: functions to build and destroy graphs that describe nfa's */ /* Constructs a new nfa node. */ #ifdef __STDC__ -RX_DECL struct rx_nfa_state * -rx_nfa_state (struct rx *rx) +RX_DECL struct rx_nfa_state *rx_nfa_state(struct rx *rx) #else -RX_DECL struct rx_nfa_state * -rx_nfa_state (rx) - struct rx *rx; +RX_DECL struct rx_nfa_state *rx_nfa_state(rx) +struct rx *rx; #endif { - struct rx_nfa_state * n = (struct rx_nfa_state *)malloc (sizeof (*n)); - if (!n) - return 0; - bzero (n, sizeof (*n)); - n->next = rx->nfa_states; - rx->nfa_states = n; - return n; + struct rx_nfa_state *n = (struct rx_nfa_state *) malloc(sizeof(*n)); + + if (!n) + return 0; + bzero(n, sizeof(*n)); + n->next = rx->nfa_states; + rx->nfa_states = n; + return n; } #ifdef __STDC__ -RX_DECL void -rx_free_nfa_state (struct rx_nfa_state * n) +RX_DECL void rx_free_nfa_state(struct rx_nfa_state *n) #else -RX_DECL void -rx_free_nfa_state (n) - struct rx_nfa_state * n; +RX_DECL void rx_free_nfa_state(n) +struct rx_nfa_state *n; #endif { - free ((char *)n); + free((char *) n); } @@ -1473,21 +1379,19 @@ rx_free_nfa_state (n) * assigned after the nfa has been built. */ #ifdef __STDC__ -RX_DECL struct rx_nfa_state * -rx_id_to_nfa_state (struct rx * rx, - int id) +RX_DECL struct rx_nfa_state *rx_id_to_nfa_state(struct rx *rx, int id) #else -RX_DECL struct rx_nfa_state * -rx_id_to_nfa_state (rx, id) - struct rx * rx; - int id; +RX_DECL struct rx_nfa_state *rx_id_to_nfa_state(rx, id) +struct rx *rx; +int id; #endif { - struct rx_nfa_state * n; - for (n = rx->nfa_states; n; n = n->next) - if (n->id == id) - return n; - return 0; + struct rx_nfa_state *n; + + for (n = rx->nfa_states; n; n = n->next) + if (n->id == id) + return n; + return 0; } @@ -1496,133 +1400,125 @@ rx_id_to_nfa_state (rx, id) */ #ifdef __STDC__ -RX_DECL struct rx_nfa_edge * -rx_nfa_edge (struct rx *rx, - enum rx_nfa_etype type, - struct rx_nfa_state *start, - struct rx_nfa_state *dest) +RX_DECL struct rx_nfa_edge *rx_nfa_edge(struct rx *rx, + enum rx_nfa_etype type, + struct rx_nfa_state *start, + struct rx_nfa_state *dest) #else -RX_DECL struct rx_nfa_edge * -rx_nfa_edge (rx, type, start, dest) - struct rx *rx; - enum rx_nfa_etype type; - struct rx_nfa_state *start; - struct rx_nfa_state *dest; +RX_DECL struct rx_nfa_edge *rx_nfa_edge(rx, type, start, dest) +struct rx *rx; +enum rx_nfa_etype type; +struct rx_nfa_state *start; +struct rx_nfa_state *dest; #endif { - struct rx_nfa_edge *e; - e = (struct rx_nfa_edge *)malloc (sizeof (*e)); - if (!e) - return 0; - e->next = start->edges; - start->edges = e; - e->type = type; - e->dest = dest; - return e; + struct rx_nfa_edge *e; + + e = (struct rx_nfa_edge *) malloc(sizeof(*e)); + if (!e) + return 0; + e->next = start->edges; + start->edges = e; + e->type = type; + e->dest = dest; + return e; } #ifdef __STDC__ -RX_DECL void -rx_free_nfa_edge (struct rx_nfa_edge * e) +RX_DECL void rx_free_nfa_edge(struct rx_nfa_edge *e) #else -RX_DECL void -rx_free_nfa_edge (e) - struct rx_nfa_edge * e; +RX_DECL void rx_free_nfa_edge(e) +struct rx_nfa_edge *e; #endif { - free ((char *)e); + free((char *) e); } /* This constructs a POSSIBLE_FUTURE, which is a kind epsilon-closure * of an NFA. These are added to an nfa automaticly by eclose_nfa. - */ + */ #ifdef __STDC__ -static struct rx_possible_future * -rx_possible_future (struct rx * rx, - struct rx_se_list * effects) +static struct rx_possible_future *rx_possible_future(struct rx *rx, struct rx_se_list + *effects) #else -static struct rx_possible_future * -rx_possible_future (rx, effects) - struct rx * rx; - struct rx_se_list * effects; +static struct rx_possible_future *rx_possible_future(rx, effects) +struct rx *rx; +struct rx_se_list *effects; #endif { - struct rx_possible_future *ec; - ec = (struct rx_possible_future *) malloc (sizeof (*ec)); - if (!ec) - return 0; - ec->destset = 0; - ec->next = 0; - ec->effects = effects; - return ec; + struct rx_possible_future *ec; + + ec = (struct rx_possible_future *) malloc(sizeof(*ec)); + if (!ec) + return 0; + ec->destset = 0; + ec->next = 0; + ec->effects = effects; + return ec; } #ifdef __STDC__ -static void -rx_free_possible_future (struct rx_possible_future * pf) +static void rx_free_possible_future(struct rx_possible_future *pf) #else -static void -rx_free_possible_future (pf) - struct rx_possible_future * pf; +static void rx_free_possible_future(pf) +struct rx_possible_future *pf; #endif { - free ((char *)pf); + free((char *) pf); } #ifdef __STDC__ -RX_DECL void -rx_free_nfa (struct rx *rx) +RX_DECL void rx_free_nfa(struct rx *rx) #else -RX_DECL void -rx_free_nfa (rx) - struct rx *rx; +RX_DECL void rx_free_nfa(rx) +struct rx *rx; #endif { - while (rx->nfa_states) - { - while (rx->nfa_states->edges) - { - switch (rx->nfa_states->edges->type) - { - case ne_cset: - rx_free_cset (rx, rx->nfa_states->edges->params.cset); - break; - default: - break; - } - { - struct rx_nfa_edge * e; - e = rx->nfa_states->edges; - rx->nfa_states->edges = rx->nfa_states->edges->next; - rx_free_nfa_edge (e); - } - } /* while (rx->nfa_states->edges) */ - { - /* Iterate over the partial epsilon closures of rx->nfa_states */ - struct rx_possible_future * pf = rx->nfa_states->futures; - while (pf) - { - struct rx_possible_future * pft = pf; - pf = pf->next; - rx_free_possible_future (pft); - } - } - { - struct rx_nfa_state *n; - n = rx->nfa_states; - rx->nfa_states = rx->nfa_states->next; - rx_free_nfa_state (n); - } - } -} - + while (rx->nfa_states) { + while (rx->nfa_states->edges) { + switch (rx->nfa_states->edges->type) { + case ne_cset: + rx_free_cset(rx, rx->nfa_states->edges->params.cset); + break; + default: + break; + } + { + struct rx_nfa_edge *e; + e = rx->nfa_states->edges; + rx->nfa_states->edges = rx->nfa_states->edges->next; + rx_free_nfa_edge(e); + } + } /* while (rx->nfa_states->edges) */ + { + /* Iterate over the partial epsilon closures of rx->nfa_states */ + struct rx_possible_future *pf = rx->nfa_states->futures; + + while (pf) { + struct rx_possible_future *pft = pf; + + pf = pf->next; + rx_free_possible_future(pft); + } + } + { + struct rx_nfa_state *n; + + n = rx->nfa_states; + rx->nfa_states = rx->nfa_states->next; + rx_free_nfa_state(n); + } + } +} + + /* This page: translating a pattern expression into an nfa and doing the * static part of the nfa->super-nfa translation. */ @@ -1639,133 +1535,130 @@ rx_free_nfa (rx) #ifdef __STDC__ RX_DECL int -rx_build_nfa (struct rx *rx, - struct rexp_node *rexp, - struct rx_nfa_state **start, - struct rx_nfa_state **end) +rx_build_nfa(struct rx *rx, + struct rexp_node *rexp, + struct rx_nfa_state **start, struct rx_nfa_state **end) #else -RX_DECL int -rx_build_nfa (rx, rexp, start, end) - struct rx *rx; - struct rexp_node *rexp; - struct rx_nfa_state **start; - struct rx_nfa_state **end; +RX_DECL int rx_build_nfa(rx, rexp, start, end) +struct rx *rx; +struct rexp_node *rexp; +struct rx_nfa_state **start; +struct rx_nfa_state **end; #endif { - struct rx_nfa_edge *edge; + struct rx_nfa_edge *edge; - /* Start & end nodes may have been allocated by the caller. */ - *start = *start ? *start : rx_nfa_state (rx); + /* Start & end nodes may have been allocated by the caller. */ + *start = *start ? *start : rx_nfa_state(rx); - if (!*start) - return 0; + if (!*start) + return 0; - if (!rexp) - { - *end = *star