diff options
author | Vern Paxson <vern@ee.lbl.gov> | 1993-04-14 22:41:35 +0000 |
---|---|---|
committer | Vern Paxson <vern@ee.lbl.gov> | 1993-04-14 22:41:35 +0000 |
commit | da65ac15e3bf4e7391dc967aed49394798d21bf5 (patch) | |
tree | a902cd44cadb4d8e8e5a3901b244dad56a852aae /ccl.c | |
parent | 38bb4c0fcd54539764cf2db73d3cc58d60cdc579 (diff) |
Reformatting.
Diffstat (limited to 'ccl.c')
-rw-r--r-- | ccl.c | 162 |
1 files changed, 69 insertions, 93 deletions
@@ -33,143 +33,119 @@ static char rcsid[] = #include "flexdef.h" -/* ccladd - add a single character to a ccl - * - * synopsis - * int cclp; - * int ch; - * ccladd( cclp, ch ); - */ +/* ccladd - add a single character to a ccl */ void ccladd( cclp, ch ) int cclp; int ch; + { + int ind, len, newpos, i; - { - int ind, len, newpos, i; + len = ccllen[cclp]; + ind = cclmap[cclp]; - len = ccllen[cclp]; - ind = cclmap[cclp]; + /* check to see if the character is already in the ccl */ - /* check to see if the character is already in the ccl */ + for ( i = 0; i < len; ++i ) + if ( ccltbl[ind + i] == ch ) + return; - for ( i = 0; i < len; ++i ) - if ( ccltbl[ind + i] == ch ) - return; + newpos = ind + len; - newpos = ind + len; + if ( newpos >= current_max_ccl_tbl_size ) + { + current_max_ccl_tbl_size += MAX_CCL_TBL_SIZE_INCREMENT; - if ( newpos >= current_max_ccl_tbl_size ) - { - current_max_ccl_tbl_size += MAX_CCL_TBL_SIZE_INCREMENT; + ++num_reallocs; - ++num_reallocs; + ccltbl = reallocate_Character_array( ccltbl, + current_max_ccl_tbl_size ); + } - ccltbl = reallocate_Character_array( ccltbl, current_max_ccl_tbl_size ); + ccllen[cclp] = len + 1; + ccltbl[newpos] = ch; } - ccllen[cclp] = len + 1; - ccltbl[newpos] = ch; - } - -/* cclinit - make an empty ccl - * - * synopsis - * int cclinit(); - * new_ccl = cclinit(); - */ +/* cclinit - return an empty ccl */ int cclinit() - - { - if ( ++lastccl >= current_maxccls ) { - current_maxccls += MAX_CCLS_INCREMENT; + if ( ++lastccl >= current_maxccls ) + { + current_maxccls += MAX_CCLS_INCREMENT; - ++num_reallocs; + ++num_reallocs; - cclmap = reallocate_integer_array( cclmap, current_maxccls ); - ccllen = reallocate_integer_array( ccllen, current_maxccls ); - cclng = reallocate_integer_array( cclng, current_maxccls ); - } + 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; + 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]; + 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 */ + ccllen[lastccl] = 0; + cclng[lastccl] = 0; /* ccl's start out life un-negated */ - return ( lastccl ); - } + return lastccl; + } -/* cclnegate - negate a ccl - * - * synopsis - * int cclp; - * cclnegate( ccl ); - */ +/* cclnegate - negate the given ccl */ void cclnegate( cclp ) int cclp; - - { - cclng[cclp] = 1; - } + { + cclng[cclp] = 1; + } /* list_character_set - list the members of a set of characters in CCL form * - * synopsis - * int cset[CSIZE]; - * FILE *file; - * list_character_set( cset ); - * - * writes to the given file a character-class representation of those - * characters present in the given set. A character is present if it - * has a non-zero value in the set array. + * Writes to the given file a character-class representation of those + * characters present in the given CCL. A character is present if it + * has a non-zero value in the cset array. */ void list_character_set( file, cset ) FILE *file; int cset[]; + { + char *readable_form(); + register int i; - { - register int i; - char *readable_form(); + putc( '[', file ); - putc( '[', file ); + for ( i = 0; i < csize; ++i ) + { + if ( cset[i] ) + { + register int start_char = i; - for ( i = 0; i < csize; ++i ) - { - if ( cset[i] ) - { - register int start_char = i; + putc( ' ', file ); - putc( ' ', file ); + fputs( readable_form( i ), file ); - fputs( readable_form( i ), file ); + while ( ++i < csize && cset[i] ) + ; - while ( ++i < csize && cset[i] ) - ; + if ( i - 1 > start_char ) + /* this was a run */ + fprintf( file, "-%s", readable_form( i - 1 ) ); - if ( i - 1 > start_char ) - /* this was a run */ - fprintf( file, "-%s", readable_form( i - 1 ) ); + putc( ' ', file ); + } + } - putc( ' ', file ); - } + putc( ']', file ); } - - putc( ']', file ); - } |