Changeset 222 for trunk/src/helpers/regexp.c
- Timestamp:
- Sep 3, 2002, 8:17:46 PM (23 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/helpers/regexp.c
r178 r222 62 62 #include <malloc.h> 63 63 #include <memory.h> 64 65 #include "setup.h" // code generation and debugging options 66 64 67 #define ERE_C 65 68 #include "helpers\regexp.h" … … 67 70 #define isword(c) (isalnum(c)||(c)=='_') 68 71 69 staticint val_of_hex(char c)72 STATIC int val_of_hex(char c) 70 73 { 71 74 if (c >= '0' && c <= '9') … … 78 81 } 79 82 80 staticint escaped(const char *s)83 STATIC int escaped(const char *s) 81 84 { 82 85 if (s[0] == 'x' && isxdigit(s[1])) … … 109 112 } 110 113 111 staticconst char *past_escaped(const char *s)114 STATIC const char *past_escaped(const char *s) 112 115 { 113 116 if (s[0] == 'x' && isxdigit(s[1])) … … 119 122 #define zero_cclass(cclass) memset(cclass, 0, 0x100 >> 3) 120 123 121 staticunsigned char bits[] =124 STATIC unsigned char bits[] = 122 125 {0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01}; 123 126 … … 126 129 #define remove_from_cclass(n, cclass) (cclass[(unsigned char)(n)>>3] &= ~bits[(unsigned char)(n) & 7]) 127 130 128 staticvoid invert_cclass(unsigned char *cclass)131 STATIC void invert_cclass(unsigned char *cclass) 129 132 { 130 133 int i; … … 148 151 /* I use my own wrapper functions so I can take their addresses. 149 152 * Remember, isalnum etc. can be implemented as macros... */ 150 staticBOOLEAN my_isalnum(int ch)153 STATIC BOOLEAN my_isalnum(int ch) 151 154 { 152 155 return isalnum(ch); 153 156 } 154 staticBOOLEAN my_isalpha(int ch)157 STATIC BOOLEAN my_isalpha(int ch) 155 158 { 156 159 return isalpha(ch); 157 160 } 158 staticBOOLEAN my_isblank(int ch)161 STATIC BOOLEAN my_isblank(int ch) 159 162 { 160 163 return ch == ' ' || ch == '\t'; 161 164 } 162 staticBOOLEAN my_iscntrl(int ch)165 STATIC BOOLEAN my_iscntrl(int ch) 163 166 { 164 167 return iscntrl(ch); 165 168 } 166 staticBOOLEAN my_isdigit(int ch)169 STATIC BOOLEAN my_isdigit(int ch) 167 170 { 168 171 return isdigit(ch); 169 172 } 170 staticBOOLEAN my_islower(int ch)173 STATIC BOOLEAN my_islower(int ch) 171 174 { 172 175 return islower(ch); 173 176 } 174 staticBOOLEAN my_isprint(int ch)177 STATIC BOOLEAN my_isprint(int ch) 175 178 { 176 179 return isprint(ch); 177 180 } 178 staticBOOLEAN my_ispunct(int ch)181 STATIC BOOLEAN my_ispunct(int ch) 179 182 { 180 183 return ispunct(ch); 181 184 } 182 staticBOOLEAN my_isspace(int ch)185 STATIC BOOLEAN my_isspace(int ch) 183 186 { 184 187 return isspace(ch); 185 188 } 186 staticBOOLEAN my_isupper(int ch)189 STATIC BOOLEAN my_isupper(int ch) 187 190 { 188 191 return isupper(ch); 189 192 } 190 staticBOOLEAN my_isxdigit(int ch)193 STATIC BOOLEAN my_isxdigit(int ch) 191 194 { 192 195 return isxdigit(ch); … … 201 204 POSIX_CCLASS; 202 205 203 staticPOSIX_CCLASS posix_cclass[] =206 STATIC POSIX_CCLASS posix_cclass[] = 204 207 { 205 208 5, "alnum", my_isalnum, … … 216 219 }; 217 220 218 staticint find_posix(const char *str)221 STATIC int find_posix(const char *str) 219 222 { 220 223 int p; … … 236 239 } 237 240 238 staticint cclass_thisch(const char *str)241 STATIC int cclass_thisch(const char *str) 239 242 { 240 243 switch (str[0]) … … 255 258 } 256 259 257 staticconst char *cclass_nextch(const char *str)260 STATIC const char *cclass_nextch(const char *str) 258 261 { 259 262 int p; … … 268 271 } 269 272 270 staticunsigned char *compile_cclass(const char *str,273 STATIC unsigned char *compile_cclass(const char *str, 271 274 const char **str_after, 272 275 int erecf, … … 424 427 }; 425 428 426 staticMATCH null_match =429 STATIC MATCH null_match = 427 430 {MTYPE_NULL}; 428 431 429 432 #define NULL_MATCH (&null_match) 430 433 431 staticvoid delete_match(MATCH * match)434 STATIC void delete_match(MATCH * match) 432 435 { 433 436 if (match == NULL_MATCH) … … 477 480 */ 478 481 479 staticunsigned shortest_match(const MATCH * match)482 STATIC unsigned shortest_match(const MATCH * match) 480 483 { 481 484 unsigned a, b; … … 535 538 } 536 539 537 staticBOOLEAN got_backrefs(MATCH * match)540 STATIC BOOLEAN got_backrefs(MATCH * match) 538 541 { 539 542 switch (match->mtype) … … 555 558 } 556 559 557 staticMATCH *remove_subs(MATCH * match)560 STATIC MATCH *remove_subs(MATCH * match) 558 561 { 559 562 switch (match->mtype) … … 584 587 } 585 588 586 staticint count_sub(const MATCH * match)589 STATIC int count_sub(const MATCH * match) 587 590 { 588 591 switch (match->mtype) … … 652 655 #define CH_BACK_END (-2000+9) 653 656 654 staticint boring_string(const char *s)657 STATIC int boring_string(const char *s) 655 658 { 656 659 int n = 0; … … 666 669 } 667 670 668 staticint thisch(const char *str)671 STATIC int thisch(const char *str) 669 672 { 670 673 int n; … … 739 742 } 740 743 741 staticconst char *nextch(const char *str)744 STATIC const char *nextch(const char *str) 742 745 { 743 746 int n; … … 792 795 } 793 796 794 staticMATCH *compile_match(const char *str, const char **str_after, int erecf, int *rc);795 796 staticconst char *scan_number(const char *str, unsigned *num)797 STATIC MATCH *compile_match(const char *str, const char **str_after, int erecf, int *rc); 798 799 STATIC const char *scan_number(const char *str, unsigned *num) 797 800 { 798 801 if (!isdigit(*str)) … … 805 808 } 806 809 807 staticMATCH *create_match(int *rc)810 STATIC MATCH *create_match(int *rc) 808 811 { 809 812 MATCH *match; … … 817 820 } 818 821 819 staticMATCH *compile_term(const char *str, const char **str_after, int erecf, int *rc)822 STATIC MATCH *compile_term(const char *str, const char **str_after, int erecf, int *rc) 820 823 { 821 824 MATCH *match; … … 995 998 } 996 999 997 staticMTYPE repeat_type_of(int c)1000 STATIC MTYPE repeat_type_of(int c) 998 1001 { 999 1002 switch (c) … … 1012 1015 } 1013 1016 1014 staticMATCH *compile_factor(const char *str, const char **str_after, int erecf, int *rc)1017 STATIC MATCH *compile_factor(const char *str, const char **str_after, int erecf, int *rc) 1015 1018 { 1016 1019 MATCH *match, *parent; … … 1084 1087 } 1085 1088 1086 staticMATCH *compile_factors(const char *str, const char **str_after, int erecf, int *rc)1089 STATIC MATCH *compile_factors(const char *str, const char **str_after, int erecf, int *rc) 1087 1090 { 1088 1091 MATCH *match; … … 1120 1123 1121 1124 /*...scompile_match \45\ factors\124\factors:0: */ 1122 staticMATCH *compile_match(const char *str, const char **str_after, int erecf, int *rc)1125 STATIC MATCH *compile_match(const char *str, const char **str_after, int erecf, int *rc) 1123 1126 { 1124 1127 MATCH *match; … … 1158 1161 /*...sprint_tree:0: */ 1159 1162 /*...sdo_indent:0: */ 1160 staticvoid do_indent(int indent)1163 STATIC void do_indent(int indent) 1161 1164 { 1162 1165 while (indent--) … … 1164 1167 } 1165 1168 1166 staticvoid print_tree(const MATCH * match, int indent)1169 STATIC void print_tree(const MATCH * match, int indent) 1167 1170 { 1168 1171 do_indent(indent); … … 1327 1330 1328 1331 /*...screate_fsm:0: */ 1329 staticFSM *create_fsm(int *rc)1332 STATIC FSM *create_fsm(int *rc) 1330 1333 { 1331 1334 FSM *fsm; … … 1353 1356 1354 1357 /*...smalloc_state:0: */ 1355 staticint malloc_state(FSM * fsm)1358 STATIC int malloc_state(FSM * fsm) 1356 1359 { 1357 1360 if (fsm->n_states == MAX_STATES) … … 1365 1368 * Return TRUE if all went ok. */ 1366 1369 1367 staticBOOLEAN malloc_edge(int s, EDGE * edge, FSM * fsm)1370 STATIC BOOLEAN malloc_edge(int s, EDGE * edge, FSM * fsm) 1368 1371 { 1369 1372 int edge_no, n_edges = fsm->n_edges++; … … 1431 1434 /*...smake_fsm_from_match:0: */ 1432 1435 /*...sadd_edge_to_fsm_character:0: */ 1433 staticBOOLEAN add_edge_to_fsm_character(int s, int f, FSM * fsm, char character)1436 STATIC BOOLEAN add_edge_to_fsm_character(int s, int f, FSM * fsm, char character) 1434 1437 { 1435 1438 EDGE edge; … … 1441 1444 } 1442 1445 /*...sadd_edge_to_fsm_ncharacter:0: */ 1443 staticBOOLEAN add_edge_to_fsm_ncharacter(int s, int f, FSM * fsm, char character)1446 STATIC BOOLEAN add_edge_to_fsm_ncharacter(int s, int f, FSM * fsm, char character) 1444 1447 { 1445 1448 EDGE edge; … … 1451 1454 } 1452 1455 /*...sadd_edge_to_fsm_string:0: */ 1453 staticBOOLEAN add_edge_to_fsm_string(int s, int f, FSM * fsm, char *string)1456 STATIC BOOLEAN add_edge_to_fsm_string(int s, int f, FSM * fsm, char *string) 1454 1457 { 1455 1458 EDGE edge; … … 1461 1464 } 1462 1465 /*...sadd_edge_to_fsm_cclass:0: */ 1463 staticBOOLEAN add_edge_to_fsm_cclass(int s, int f, FSM * fsm, unsigned char *cclass)1466 STATIC BOOLEAN add_edge_to_fsm_cclass(int s, int f, FSM * fsm, unsigned char *cclass) 1464 1467 { 1465 1468 EDGE edge; … … 1471 1474 } 1472 1475 /*...sadd_edge_to_fsm_dot:0: */ 1473 staticBOOLEAN add_edge_to_fsm_dot(int s, int f, FSM * fsm)1476 STATIC BOOLEAN add_edge_to_fsm_dot(int s, int f, FSM * fsm) 1474 1477 { 1475 1478 EDGE edge; … … 1480 1483 } 1481 1484 /*...sadd_edge_to_fsm_word:0: */ 1482 staticBOOLEAN add_edge_to_fsm_word(int s, int f, FSM * fsm)1485 STATIC BOOLEAN add_edge_to_fsm_word(int s, int f, FSM * fsm) 1483 1486 { 1484 1487 EDGE edge; … … 1489 1492 } 1490 1493 /*...sadd_edge_to_fsm_nword:0: */ 1491 staticBOOLEAN add_edge_to_fsm_nword(int s, int f, FSM * fsm)1494 STATIC BOOLEAN add_edge_to_fsm_nword(int s, int f, FSM * fsm) 1492 1495 { 1493 1496 EDGE edge; … … 1498 1501 } 1499 1502 /*...sadd_edge_to_fsm_epsilon:0: */ 1500 staticBOOLEAN add_edge_to_fsm_epsilon(int s, int f, FSM * fsm)1503 STATIC BOOLEAN add_edge_to_fsm_epsilon(int s, int f, FSM * fsm) 1501 1504 { 1502 1505 EDGE edge; … … 1507 1510 } 1508 1511 /*...sadd_edge_to_fsm_special:0: */ 1509 staticBOOLEAN add_edge_to_fsm_special(int s, int f, FSM * fsm, ETYPE etype)1512 STATIC BOOLEAN add_edge_to_fsm_special(int s, int f, FSM * fsm, ETYPE etype) 1510 1513 { 1511 1514 EDGE edge; … … 1517 1520 } 1518 1521 /*...sadd_edge_to_fsm_back:0: */ 1519 staticBOOLEAN add_edge_to_fsm_back(int s, int f, FSM * fsm, int n_span)1522 STATIC BOOLEAN add_edge_to_fsm_back(int s, int f, FSM * fsm, int n_span) 1520 1523 { 1521 1524 EDGE edge; … … 1528 1531 } 1529 1532 1530 staticBOOLEAN make_fsm_from_match(MATCH * match, FSM * fsm, int *s, int *f)1533 STATIC BOOLEAN make_fsm_from_match(MATCH * match, FSM * fsm, int *s, int *f) 1531 1534 { 1532 1535 int n1, n2, n3, n4, i; … … 1850 1853 * recursion on loops of epsilon moves. */ 1851 1854 1852 staticBOOLEAN is_finish_reachable(FSM * fsm, int state_no)1855 STATIC BOOLEAN is_finish_reachable(FSM * fsm, int state_no) 1853 1856 { 1854 1857 int edge_no; … … 1880 1883 1881 1884 1882 staticvoid finish_states(int f, FSM * fsm, FSM * fsm_without)1885 STATIC void finish_states(int f, FSM * fsm, FSM * fsm_without) 1883 1886 { 1884 1887 int state_no; … … 1892 1895 1893 1896 /*...sdetermine_reachable:0: */ 1894 staticvoid determine_reachable(int s, FSM * fsm, FSM * fsm_without)1897 STATIC void determine_reachable(int s, FSM * fsm, FSM * fsm_without) 1895 1898 { 1896 1899 int edge_no, to_state; … … 1906 1909 1907 1910 /*...scopy_non_epsilons:0: */ 1908 staticvoid copy_non_epsilons(FSM * fsm, FSM * fsm_without)1911 STATIC void copy_non_epsilons(FSM * fsm, FSM * fsm_without) 1909 1912 { 1910 1913 int state_no, edge_no; … … 1930 1933 */ 1931 1934 1932 staticBOOLEAN copy_edges_reachable(1935 STATIC BOOLEAN copy_edges_reachable( 1933 1936 FSM * fsm, 1934 1937 FSM * fsm_without, … … 1969 1972 1970 1973 1971 staticBOOLEAN follow_epsilons(FSM * fsm, FSM * fsm_without)1974 STATIC BOOLEAN follow_epsilons(FSM * fsm, FSM * fsm_without) 1972 1975 { 1973 1976 int state_no; … … 1981 1984 1982 1985 1983 staticBOOLEAN remove_epsilons(int s, int f, FSM * fsm, FSM * fsm_without)1986 STATIC BOOLEAN remove_epsilons(int s, int f, FSM * fsm, FSM * fsm_without) 1984 1987 { 1985 1988 // FSM with no epsilon moves will have the same number of states … … 2056 2059 #define NR 2057 2060 2058 staticvoid NR walk_fsm(const char *str, int state_no, CONTEXT * cx);2059 2060 staticvoid NR walk_fsm_gated(const char *str, CONTEXT * cx, EDGE * e)2061 STATIC void NR walk_fsm(const char *str, int state_no, CONTEXT * cx); 2062 2063 STATIC void NR walk_fsm_gated(const char *str, CONTEXT * cx, EDGE * e) 2061 2064 { 2062 2065 if (e->gate != str) … … 2071 2074 } 2072 2075 2073 staticvoid NR walk_fsm_ssub(const char *str, CONTEXT * cx, EDGE * e)2076 STATIC void NR walk_fsm_ssub(const char *str, CONTEXT * cx, EDGE * e) 2074 2077 { 2075 2078 SUBS subs; … … 2085 2088 } 2086 2089 2087 staticvoid NR walk_fsm_esub(const char *str, CONTEXT * cx, EDGE * e)2090 STATIC void NR walk_fsm_esub(const char *str, CONTEXT * cx, EDGE * e) 2088 2091 { 2089 2092 SUBS *subs = cx->subs; … … 2102 2105 } 2103 2106 2104 staticvoid NR walk_fsm(const char *str, int state_no, CONTEXT * cx)2107 STATIC void NR walk_fsm(const char *str, int state_no, CONTEXT * cx) 2105 2108 { 2106 2109 int edge_no; … … 2241 2244 } 2242 2245 2243 staticconst char *match_fsm(FSM * fsm,2246 STATIC const char *match_fsm(FSM * fsm, 2244 2247 int eremf, 2245 2248 const char *str, … … 2268 2271 #ifdef DEBUG 2269 2272 /*...sprint_fsm:0: */ 2270 staticvoid print_fsm(FSM * fsm, int s, BOOLEAN not_just_reachable)2273 STATIC void print_fsm(FSM * fsm, int s, BOOLEAN not_just_reachable) 2271 2274 { 2272 2275 int state_no, edge_no;
Note:
See TracChangeset
for help on using the changeset viewer.