This is Unofficial EPICS BASE Doxygen Site
ccl.c
Go to the documentation of this file.
1 /*************************************************************************\
2 * Copyright (c) 2002 The University of Chicago, as Operator of Argonne
3 * National Laboratory.
4 * Copyright (c) 2002 The Regents of the University of California, as
5 * Operator of Los Alamos National Laboratory.
6 * EPICS BASE is distributed subject to a Software License Agreement found
7 * in file LICENSE that is included with this distribution.
8 \*************************************************************************/
9 /* ccl - routines for character classes */
10 
11 /*-
12  * Copyright (c) 1990 The Regents of the University of California.
13  * All rights reserved.
14  *
15  * This code is derived from software contributed to Berkeley by
16  * Vern Paxson.
17  *
18  * The United States Government has rights in this work pursuant
19  * to contract no. DE-AC03-76SF00098 between the United States
20  * Department of Energy and the University of California.
21  *
22  * Redistribution and use in source and binary forms are permitted provided
23  * that: (1) source distributions retain this entire copyright notice and
24  * comment, and (2) distributions including binaries display the following
25  * acknowledgement: ``This product includes software developed by the
26  * University of California, Berkeley and its contributors'' in the
27  * documentation or other materials provided with the distribution and in
28  * all advertising materials mentioning features or use of this software.
29  * Neither the name of the University nor the names of its contributors may
30  * be used to endorse or promote products derived from this software without
31  * specific prior written permission.
32  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
33  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
34  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
35  */
36 
37 #include "flexdef.h"
38 
39 /* ccladd - add a single character to a ccl
40  *
41  * synopsis
42  * int cclp;
43  * int ch;
44  * ccladd( cclp, ch );
45  */
46 
47 void ccladd(int cclp, int ch)
48 {
49  int ind, len, newpos, i;
50 
51  len = ccllen[cclp];
52  ind = cclmap[cclp];
53 
54  /* check to see if the character is already in the ccl */
55 
56  for ( i = 0; i < len; ++i )
57  if ( ccltbl[ind + i] == ch )
58  return;
59 
60  newpos = ind + len;
61 
62  if ( newpos >= current_max_ccl_tbl_size )
63  {
65 
66  ++num_reallocs;
67 
69  }
70 
71  ccllen[cclp] = len + 1;
72  ccltbl[newpos] = ch;
73  }
74 
75 
76 /* cclinit - make an empty ccl
77  *
78  * synopsis
79  * int cclinit();
80  * new_ccl = cclinit();
81  */
82 
83 int cclinit(void)
84 {
85  if ( ++lastccl >= current_maxccls )
86  {
88 
89  ++num_reallocs;
90 
94  }
95 
96  if ( lastccl == 1 )
97  /* we're making the first ccl */
98  cclmap[lastccl] = 0;
99 
100  else
101  /* the new pointer is just past the end of the last ccl. Since
102  * the cclmap points to the \first/ character of a ccl, adding the
103  * length of the ccl to the cclmap pointer will produce a cursor
104  * to the first free space
105  */
106  cclmap[lastccl] = cclmap[lastccl - 1] + ccllen[lastccl - 1];
107 
108  ccllen[lastccl] = 0;
109  cclng[lastccl] = 0; /* ccl's start out life un-negated */
110 
111  return ( lastccl );
112  }
113 
114 
115 /* cclnegate - negate a ccl
116  *
117  * synopsis
118  * int cclp;
119  * cclnegate( ccl );
120  */
121 
122 void cclnegate(int cclp)
123 {
124  cclng[cclp] = 1;
125  }
126 
127 
128 /* list_character_set - list the members of a set of characters in CCL form
129  *
130  * synopsis
131  * int cset[CSIZE];
132  * FILE *file;
133  * list_character_set( cset );
134  *
135  * writes to the given file a character-class representation of those
136  * characters present in the given set. A character is present if it
137  * has a non-zero value in the set array.
138  */
139 
140 void list_character_set(FILE *file, int cset[])
141 {
142  int i;
143  char *readable_form();
144 
145  putc( '[', file );
146 
147  for ( i = 0; i < csize; ++i )
148  {
149  if ( cset[i] )
150  {
151  int start_char = i;
152 
153  putc( ' ', file );
154 
155  fputs( readable_form( i ), file );
156 
157  while ( ++i < csize && cset[i] )
158  ;
159 
160  if ( i - 1 > start_char )
161  /* this was a run */
162  fprintf( file, "-%s", readable_form( i - 1 ) );
163 
164  putc( ' ', file );
165  }
166  }
167 
168  putc( ']', file );
169  }
void ccladd(int cclp, int ch)
Definition: ccl.c:47
int i
Definition: scan.c:967
#define MAX_CCLS_INCREMENT
Definition: flexdef.h:161
int num_reallocs
Definition: flex.c:100
int current_maxccls
Definition: flex.c:96
int * cclng
Definition: flex.c:96
char * readable_form(int c)
Definition: misc.c:672
int csize
Definition: flex.c:68
void list_character_set(FILE *file, int cset[])
Definition: ccl.c:140
#define reallocate_integer_array(array, size)
Definition: flexdef.h:584
void cclnegate(int cclp)
Definition: ccl.c:122
int * ccllen
Definition: flex.c:96
int * cclmap
Definition: flex.c:96
#define reallocate_character_array(array, size)
Definition: flexdef.h:610
Char * ccltbl
Definition: flex.c:98
int cclinit(void)
Definition: ccl.c:83
int lastccl
Definition: flex.c:96
#define MAX_CCL_TBL_SIZE_INCREMENT
Definition: flexdef.h:165
int current_max_ccl_tbl_size
Definition: flex.c:97