1 /* ccl - routines for character classes */
4 * Copyright (c) 1990 The Regents of the University of California.
7 * This code is derived from software contributed to Berkeley by
10 * The United States Government has rights in this work pursuant
11 * to contract no. DE-AC03-76SF00098 between the United States
12 * Department of Energy and the University of California.
14 * Redistribution and use in source and binary forms are permitted provided
15 * that: (1) source distributions retain this entire copyright notice and
16 * comment, and (2) distributions including binaries display the following
17 * acknowledgement: ``This product includes software developed by the
18 * University of California, Berkeley and its contributors'' in the
19 * documentation or other materials provided with the distribution and in
20 * all advertising materials mentioning features or use of this software.
21 * Neither the name of the University nor the names of its contributors may
22 * be used to endorse or promote products derived from this software without
23 * specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
25 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
26 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
29 /* $Header: /home/daffy/u0/vern/flex/RCS/ccl.c,v 2.9 93/09/16 20:32:14 vern Exp $ */
30 #include <sys/cdefs.h>
31 __FBSDID("$FreeBSD$");
35 /* ccladd - add a single character to a ccl */
37 void ccladd( cclp, ch )
41 int ind, len, newpos, i;
48 /* check to see if the character is already in the ccl */
50 for ( i = 0; i < len; ++i )
51 if ( ccltbl[ind + i] == ch )
56 if ( newpos >= current_max_ccl_tbl_size )
58 current_max_ccl_tbl_size += MAX_CCL_TBL_SIZE_INCREMENT;
62 ccltbl = reallocate_Character_array( ccltbl,
63 current_max_ccl_tbl_size );
66 ccllen[cclp] = len + 1;
71 /* cclinit - return an empty ccl */
75 if ( ++lastccl >= current_maxccls )
77 current_maxccls += MAX_CCLS_INCREMENT;
81 cclmap = reallocate_integer_array( cclmap, current_maxccls );
82 ccllen = reallocate_integer_array( ccllen, current_maxccls );
83 cclng = reallocate_integer_array( cclng, current_maxccls );
87 /* we're making the first ccl */
91 /* The new pointer is just past the end of the last ccl.
92 * Since the cclmap points to the \first/ character of a
93 * ccl, adding the length of the ccl to the cclmap pointer
94 * will produce a cursor to the first free space.
96 cclmap[lastccl] = cclmap[lastccl - 1] + ccllen[lastccl - 1];
99 cclng[lastccl] = 0; /* ccl's start out life un-negated */
105 /* cclnegate - negate the given ccl */
107 void cclnegate( cclp )
114 /* list_character_set - list the members of a set of characters in CCL form
116 * Writes to the given file a character-class representation of those
117 * characters present in the given CCL. A character is present if it
118 * has a non-zero value in the cset array.
121 void list_character_set( file, cset )
129 for ( i = 0; i < csize; ++i )
137 fputs( readable_form( i ), file );
139 while ( ++i < csize && cset[i] )
142 if ( i - 1 > start_char )
144 fprintf( file, "-%s", readable_form( i - 1 ) );