This is Unofficial EPICS BASE Doxygen Site
ecs.c File Reference
#include "flexdef.h"
+ Include dependency graph for ecs.c:

Go to the source code of this file.

Functions

void ccl2ecl (void)
 
int cre8ecs (int fwd[], int bck[], int num)
 
int ecs_from_xlation (int ecmap[])
 
void mkeccl (unsigned char ccls[], int lenccl, int fwd[], int bck[], int llsiz, int NUL_mapping)
 
void mkechar (int tch, int fwd[], int bck[])
 

Function Documentation

void ccl2ecl ( void  )

Definition at line 45 of file ecs.c.

46 {
47  int i, ich, newlen, cclp, ccls, cclmec;
48 
49  for ( i = 1; i <= lastccl; ++i )
50  {
51  /* we loop through each character class, and for each character
52  * in the class, add the character's equivalence class to the
53  * new "character" class we are creating. Thus when we are all
54  * done, character classes will really consist of collections
55  * of equivalence classes
56  */
57 
58  newlen = 0;
59  cclp = cclmap[i];
60 
61  for ( ccls = 0; ccls < ccllen[i]; ++ccls )
62  {
63  ich = ccltbl[cclp + ccls];
64  cclmec = ecgroup[ich];
65 
66  if ( xlation && cclmec < 0 )
67  {
68  /* special hack--if we're doing %t tables then it's
69  * possible that no representative of this character's
70  * equivalence class is in the ccl. So waiting till
71  * we see the representative would be disastrous. Instead,
72  * we add this character's equivalence class anyway, if it's
73  * not already present.
74  */
75  int j;
76 
77  /* this loop makes this whole process n^2; but we don't
78  * really care about %t performance anyway
79  */
80  for ( j = 0; j < newlen; ++j )
81  if ( ccltbl[cclp + j] == -cclmec )
82  break;
83 
84  if ( j >= newlen )
85  { /* no representative yet, add this one in */
86  ccltbl[cclp + newlen] = -cclmec;
87  ++newlen;
88  }
89  }
90 
91  else if ( cclmec > 0 )
92  {
93  ccltbl[cclp + newlen] = cclmec;
94  ++newlen;
95  }
96  }
97 
98  ccllen[i] = newlen;
99  }
100  }
int ecgroup[CSIZE+1]
Definition: flex.c:83
int i
Definition: scan.c:967
int * xlation
Definition: flex.c:85
int * ccllen
Definition: flex.c:96
int * cclmap
Definition: flex.c:96
Char * ccltbl
Definition: flex.c:98
int lastccl
Definition: flex.c:96
int cre8ecs ( int  fwd[],
int  bck[],
int  num 
)

Definition at line 115 of file ecs.c.

116 {
117  int i, j, numcl;
118 
119  numcl = 0;
120 
121  /* create equivalence class numbers. From now on, abs( bck(x) )
122  * is the equivalence class number for object x. If bck(x)
123  * is positive, then x is the representative of its equivalence
124  * class.
125  */
126  for ( i = 1; i <= num; ++i )
127  if ( bck[i] == NIL )
128  {
129  bck[i] = ++numcl;
130  for ( j = fwd[i]; j != NIL; j = fwd[j] )
131  bck[j] = -numcl;
132  }
133 
134  return ( numcl );
135  }
int i
Definition: scan.c:967
#define NIL
Definition: flexdef.h:153
int ecs_from_xlation ( int  ecmap[])

Definition at line 150 of file ecs.c.

151 {
152  int i;
153  int nul_is_alone = false;
154  int did_default_xlation_class = false;
155 
156  if ( xlation[0] != 0 )
157  {
158  /* if NUL shares its translation with other characters, choose one
159  * of the other characters as the representative for the equivalence
160  * class. This allows a cheap test later to see whether we can
161  * do away with NUL's equivalence class.
162  */
163  for ( i = 1; i < csize; ++i )
164  if ( xlation[i] == -xlation[0] )
165  {
166  xlation[i] = xlation[0];
167  ecmap[0] = -xlation[0];
168  break;
169  }
170 
171  if ( i >= csize )
172  /* didn't find a companion character--remember this fact */
173  nul_is_alone = true;
174  }
175 
176  for ( i = 1; i < csize; ++i )
177  if ( xlation[i] == 0 )
178  {
179  if ( did_default_xlation_class )
180  ecmap[i] = -num_xlations;
181 
182  else
183  {
184  /* make an equivalence class for those characters not
185  * specified in the %t table
186  */
187  ++num_xlations;
188  ecmap[i] = num_xlations;
189  did_default_xlation_class = true;
190  }
191  }
192 
193  else
194  ecmap[i] = xlation[i];
195 
196  if ( nul_is_alone )
197  /* force NUL's equivalence class to be the last one */
198  {
199  ++num_xlations;
200  ecmap[0] = num_xlations;
201 
202  /* there's actually a bug here: if someone is fanatic enough to
203  * put every character in its own translation class, then right
204  * now we just promoted NUL's equivalence class to be csize + 1;
205  * we can handle NUL's class number being == csize (by instead
206  * putting it in its own table), but we can't handle some *other*
207  * character having to be put in its own table, too. So in
208  * this case we bail out.
209  */
210  if ( num_xlations > csize )
211  flexfatal( "too many %t classes!" );
212  }
213 
214  return num_xlations;
215  }
int i
Definition: scan.c:967
int * xlation
Definition: flex.c:85
int csize
Definition: flex.c:68
void flexfatal(char[])
int num_xlations
Definition: flex.c:86
void mkeccl ( unsigned char  ccls[],
int  lenccl,
int  fwd[],
int  bck[],
int  llsiz,
int  NUL_mapping 
)

Definition at line 232 of file ecs.c.

233 {
234  int cclp, oldec, newec;
235  int cclm, i, j;
236  static unsigned char cclflags[CSIZE]; /* initialized to all '\0' */
237 
238  /* note that it doesn't matter whether or not the character class is
239  * negated. The same results will be obtained in either case.
240  */
241 
242  cclp = 0;
243 
244  while ( cclp < lenccl )
245  {
246  cclm = ccls[cclp];
247 
248  if ( NUL_mapping && cclm == 0 )
249  cclm = NUL_mapping;
250 
251  oldec = bck[cclm];
252  newec = cclm;
253 
254  j = cclp + 1;
255 
256  for ( i = fwd[cclm]; i != NIL && i <= llsiz; i = fwd[i] )
257  { /* look for the symbol in the character class */
258  for ( ; j < lenccl; ++j )
259  {
260  int ccl_char;
261 
262  if ( NUL_mapping && ccls[j] == 0 )
263  ccl_char = NUL_mapping;
264  else
265  ccl_char = ccls[j];
266 
267  if ( ccl_char > i )
268  break;
269 
270  if ( ccl_char == i && ! cclflags[j] )
271  {
272  /* we found an old companion of cclm in the ccl.
273  * link it into the new equivalence class and flag it as
274  * having been processed
275  */
276 
277  bck[i] = newec;
278  fwd[newec] = i;
279  newec = i;
280  cclflags[j] = 1; /* set flag so we don't reprocess */
281 
282  /* get next equivalence class member */
283  /* continue 2 */
284  goto next_pt;
285  }
286  }
287 
288  /* symbol isn't in character class. Put it in the old equivalence
289  * class
290  */
291 
292  bck[i] = oldec;
293 
294  if ( oldec != NIL )
295  fwd[oldec] = i;
296 
297  oldec = i;
298 next_pt:
299  ;
300  }
301 
302  if ( bck[cclm] != NIL || oldec != bck[cclm] )
303  {
304  bck[cclm] = NIL;
305  fwd[oldec] = NIL;
306  }
307 
308  fwd[newec] = NIL;
309 
310  /* find next ccl member to process */
311 
312  for ( ++cclp; cclflags[cclp] && cclp < lenccl; ++cclp )
313  {
314  /* reset "doesn't need processing" flag */
315  cclflags[cclp] = 0;
316  }
317  }
318  }
int i
Definition: scan.c:967
#define NIL
Definition: flexdef.h:153
#define CSIZE
Definition: flexdef.h:58
void mkechar ( int  tch,
int  fwd[],
int  bck[] 
)

Definition at line 328 of file ecs.c.

329 {
330  /* if until now the character has been a proper subset of
331  * an equivalence class, break it away to create a new ec
332  */
333 
334  if ( fwd[tch] != NIL )
335  bck[fwd[tch]] = bck[tch];
336 
337  if ( bck[tch] != NIL )
338  fwd[bck[tch]] = fwd[tch];
339 
340  fwd[tch] = NIL;
341  bck[tch] = NIL;
342  }
#define NIL
Definition: flexdef.h:153