diff options
author | Vern Paxson <vern@ee.lbl.gov> | 1987-11-08 22:24:44 +0000 |
---|---|---|
committer | Vern Paxson <vern@ee.lbl.gov> | 1987-11-08 22:24:44 +0000 |
commit | 2cc578462372baa1b85936749946608d7f36415f (patch) | |
tree | b103972512328042bbc4e7541616e88369619b2c /ccl.c |
Initial revision
Diffstat (limited to 'ccl.c')
-rw-r--r-- | ccl.c | 98 |
1 files changed, 98 insertions, 0 deletions
@@ -0,0 +1,98 @@ +/* lexccl - routines for character classes */ + +/* + * Copyright (c) University of California, 1987 + */ + +#include "flexdef.h" + +/* ccladd - add a single character to a ccl + * + * synopsis + * int cclp; + * char ch; + * ccladd( cclp, ch ); + */ +ccladd( cclp, ch ) +int cclp; +char ch; + + { + int ind, len, newpos, i; + + len = ccllen[cclp]; + ind = cclmap[cclp]; + + /* check to see if the character is already in the ccl */ + + for ( i = 0; i < len; ++i ) + if ( ccltbl[ind + i] == ch ) + return; + + newpos = ind + len; + + if ( newpos >= current_max_ccl_tbl_size ) + { + current_max_ccl_tbl_size += MAX_CCL_TBL_SIZE_INCREMENT; + + ++num_reallocs; + + ccltbl = reallocate_character_array( ccltbl, current_max_ccl_tbl_size ); + } + + ccllen[cclp] = len + 1; + ccltbl[newpos] = ch; + } + + +/* cclinit - make an empty ccl + * + * synopsis + * int cclinit(); + * new_ccl = cclinit(); + */ +int cclinit() + + { + if ( ++lastccl >= current_maxccls ) + { + current_maxccls += MAXCCLS_INCREMENT; + + ++num_reallocs; + + cclmap = reallocate_integer_array( cclmap, current_maxccls ); + ccllen = reallocate_integer_array( ccllen, current_maxccls ); + cclng = reallocate_integer_array( cclng, current_maxccls ); + } + + if ( lastccl == 1 ) + /* we're making the first ccl */ + cclmap[lastccl] = 0; + + else + /* the new pointer is just past the end of the last ccl. Since + * the cclmap points to the \first/ character of a ccl, adding the + * length of the ccl to the cclmap pointer will produce a cursor + * to the first free space + */ + cclmap[lastccl] = cclmap[lastccl - 1] + ccllen[lastccl - 1]; + + ccllen[lastccl] = 0; + cclng[lastccl] = 0; /* ccl's start out life un-negated */ + + return ( lastccl ); + } + + +/* cclnegate - negate a ccl + * + * synopsis + * int cclp; + * cclnegate( ccl ); + */ +cclnegate( cclp ) +int cclp; + + { + cclng[cclp] = 1; + } |