summaryrefslogtreecommitdiff
path: root/ecs.c
diff options
context:
space:
mode:
authorvern <vern>1993-04-14 22:41:35 +0000
committervern <vern>1993-04-14 22:41:35 +0000
commit818f6720384b51feebae6f3b54ec7e68ba10661d (patch)
treeabb6a96ec1ea238c5e10875bf1cc607100f7ac64 /ecs.c
parent96a2aba90f9935f1e88be225a7b0306d2e2ba6d6 (diff)
downloadflex-818f6720384b51feebae6f3b54ec7e68ba10661d.tar.gz
Reformatting.
Diffstat (limited to 'ecs.c')
-rw-r--r--ecs.c284
1 files changed, 135 insertions, 149 deletions
diff --git a/ecs.c b/ecs.c
index d3b0202..c7aabb9 100644
--- a/ecs.c
+++ b/ecs.c
@@ -28,86 +28,76 @@
#ifndef lint
static char rcsid[] =
- "@(#) $Header: /cvsroot/flex/flex/ecs.c,v 2.6 1993/02/06 21:01:45 vern Exp $ (LBL)";
+ "@(#) $Header: /cvsroot/flex/flex/ecs.c,v 2.7 1993/04/14 22:41:48 vern Exp $ (LBL)";
#endif
#include "flexdef.h"
-/* ccl2ecl - convert character classes to set of equivalence classes
- *
- * synopsis
- * ccl2ecl();
- */
+/* ccl2ecl - convert character classes to set of equivalence classes */
void ccl2ecl()
-
- {
- int i, ich, newlen, cclp, ccls, cclmec;
-
- for ( i = 1; i <= lastccl; ++i )
{
- /* we loop through each character class, and for each character
- * in the class, add the character's equivalence class to the
- * new "character" class we are creating. Thus when we are all
- * done, character classes will really consist of collections
- * of equivalence classes
- */
-
- newlen = 0;
- cclp = cclmap[i];
+ int i, ich, newlen, cclp, ccls, cclmec;
- for ( ccls = 0; ccls < ccllen[i]; ++ccls )
- {
- ich = ccltbl[cclp + ccls];
- cclmec = ecgroup[ich];
-
- if ( cclmec > 0 )
+ for ( i = 1; i <= lastccl; ++i )
{
- ccltbl[cclp + newlen] = cclmec;
- ++newlen;
+ /* We loop through each character class, and for each character
+ * in the class, add the character's equivalence class to the
+ * new "character" class we are creating. Thus when we are all
+ * done, character classes will really consist of collections
+ * of equivalence classes
+ */
+
+ newlen = 0;
+ cclp = cclmap[i];
+
+ for ( ccls = 0; ccls < ccllen[i]; ++ccls )
+ {
+ ich = ccltbl[cclp + ccls];
+ cclmec = ecgroup[ich];
+
+ if ( cclmec > 0 )
+ {
+ ccltbl[cclp + newlen] = cclmec;
+ ++newlen;
+ }
+ }
+
+ ccllen[i] = newlen;
}
- }
-
- ccllen[i] = newlen;
}
- }
/* cre8ecs - associate equivalence class numbers with class members
*
- * synopsis
- * int cre8ecs();
- * number of classes = cre8ecs( fwd, bck, num );
- *
- * fwd is the forward linked-list of equivalence class members. bck
- * is the backward linked-list, and num is the number of class members.
+ * fwd is the forward linked-list of equivalence class members. bck
+ * is the backward linked-list, and num is the number of class members.
*
- * Returned is the number of classes.
+ * Returned is the number of classes.
*/
int cre8ecs( fwd, bck, num )
int fwd[], bck[], num;
+ {
+ int i, j, numcl;
- {
- int i, j, numcl;
-
- numcl = 0;
-
- /* create equivalence class numbers. From now on, abs( bck(x) )
- * is the equivalence class number for object x. If bck(x)
- * is positive, then x is the representative of its equivalence
- * class.
- */
- for ( i = 1; i <= num; ++i )
- if ( bck[i] == NIL )
- {
- bck[i] = ++numcl;
- for ( j = fwd[i]; j != NIL; j = fwd[j] )
- bck[j] = -numcl;
- }
+ numcl = 0;
- return ( numcl );
- }
+ /* Create equivalence class numbers. From now on, abs( bck(x) )
+ * is the equivalence class number for object x. If bck(x)
+ * is positive, then x is the representative of its equivalence
+ * class.
+ */
+ for ( i = 1; i <= num; ++i )
+ if ( bck[i] == NIL )
+ {
+ bck[i] = ++numcl;
+ for ( j = fwd[i]; j != NIL; j = fwd[j] )
+ bck[j] = -numcl;
+ }
+
+ return numcl;
+ }
/* mkeccl - update equivalence classes based on character class xtions
@@ -115,11 +105,12 @@ int fwd[], bck[], num;
* synopsis
* Char ccls[];
* int lenccl, fwd[llsiz], bck[llsiz], llsiz, NUL_mapping;
- * mkeccl( ccls, lenccl, fwd, bck, llsiz, NUL_mapping );
+ * void mkeccl( Char ccls[], int lenccl, int fwd[llsiz], int bck[llsiz],
+ * int llsiz, int NUL_mapping );
*
- * where ccls contains the elements of the character class, lenccl is the
+ * ccls contains the elements of the character class, lenccl is the
* number of elements in the ccl, fwd is the forward link-list of equivalent
- * characters, bck is the backward link-list, and llsiz size of the link-list
+ * characters, bck is the backward link-list, and llsiz size of the link-list.
*
* NUL_mapping is the value which NUL (0) should be mapped to.
*/
@@ -127,116 +118,111 @@ int fwd[], bck[], num;
void mkeccl( ccls, lenccl, fwd, bck, llsiz, NUL_mapping )
Char ccls[];
int lenccl, fwd[], bck[], llsiz, NUL_mapping;
+ {
+ int cclp, oldec, newec;
+ int cclm, i, j;
+ static unsigned char cclflags[CSIZE]; /* initialized to all '\0' */
- {
- int cclp, oldec, newec;
- int cclm, i, j;
- static unsigned char cclflags[CSIZE]; /* initialized to all '\0' */
+ /* Note that it doesn't matter whether or not the character class is
+ * negated. The same results will be obtained in either case.
+ */
- /* note that it doesn't matter whether or not the character class is
- * negated. The same results will be obtained in either case.
- */
+ cclp = 0;
- cclp = 0;
+ while ( cclp < lenccl )
+ {
+ cclm = ccls[cclp];
- while ( cclp < lenccl )
- {
- cclm = ccls[cclp];
+ if ( NUL_mapping && cclm == 0 )
+ cclm = NUL_mapping;
- if ( NUL_mapping && cclm == 0 )
- cclm = NUL_mapping;
+ oldec = bck[cclm];
+ newec = cclm;
- oldec = bck[cclm];
- newec = cclm;
+ j = cclp + 1;
- j = cclp + 1;
+ for ( i = fwd[cclm]; i != NIL && i <= llsiz; i = fwd[i] )
+ { /* look for the symbol in the character class */
+ for ( ; j < lenccl; ++j )
+ {
+ register int ccl_char;
- for ( i = fwd[cclm]; i != NIL && i <= llsiz; i = fwd[i] )
- { /* look for the symbol in the character class */
- for ( ; j < lenccl; ++j )
- {
- register int ccl_char;
-
- if ( NUL_mapping && ccls[j] == 0 )
- ccl_char = NUL_mapping;
- else
- ccl_char = ccls[j];
-
- if ( ccl_char > i )
- break;
-
- if ( ccl_char == i && ! cclflags[j] )
- {
- /* we found an old companion of cclm in the ccl.
- * link it into the new equivalence class and flag it as
- * having been processed
- */
-
- bck[i] = newec;
- fwd[newec] = i;
- newec = i;
- cclflags[j] = 1; /* set flag so we don't reprocess */
-
- /* get next equivalence class member */
- /* continue 2 */
- goto next_pt;
- }
- }
+ if ( NUL_mapping && ccls[j] == 0 )
+ ccl_char = NUL_mapping;
+ else
+ ccl_char = ccls[j];
+
+ if ( ccl_char > i )
+ break;
+
+ if ( ccl_char == i && ! cclflags[j] )
+ {
+ /* We found an old companion of cclm
+ * in the ccl. Link it into the new
+ * equivalence class and flag it as
+ * having been processed.
+ */
+
+ bck[i] = newec;
+ fwd[newec] = i;
+ newec = i;
+ /* Set flag so we don't reprocess. */
+ cclflags[j] = 1;
+
+ /* Get next equivalence class member. */
+ /* continue 2 */
+ goto next_pt;
+ }
+ }
+
+ /* Symbol isn't in character class. Put it in the old
+ * equivalence class.
+ */
- /* symbol isn't in character class. Put it in the old equivalence
- * class
- */
+ bck[i] = oldec;
- bck[i] = oldec;
+ if ( oldec != NIL )
+ fwd[oldec] = i;
- if ( oldec != NIL )
- fwd[oldec] = i;
+ oldec = i;
- oldec = i;
-next_pt:
- ;
- }
+ next_pt: ;
+ }
- if ( bck[cclm] != NIL || oldec != bck[cclm] )
- {
- bck[cclm] = NIL;
- fwd[oldec] = NIL;
- }
+ if ( bck[cclm] != NIL || oldec != bck[cclm] )
+ {
+ bck[cclm] = NIL;
+ fwd[oldec] = NIL;
+ }
- fwd[newec] = NIL;
+ fwd[newec] = NIL;
- /* find next ccl member to process */
+ /* Find next ccl member to process. */
- for ( ++cclp; cclflags[cclp] && cclp < lenccl; ++cclp )
- {
- /* reset "doesn't need processing" flag */
- cclflags[cclp] = 0;
- }
+ for ( ++cclp; cclflags[cclp] && cclp < lenccl; ++cclp )
+ {
+ /* Reset "doesn't need processing" flag. */
+ cclflags[cclp] = 0;
+ }
+ }
}
- }
-/* mkechar - create equivalence class for single character
- *
- * synopsis
- * int tch, fwd[], bck[];
- * mkechar( tch, fwd, bck );
- */
+/* mkechar - create equivalence class for single character */
void mkechar( tch, fwd, bck )
int tch, fwd[], bck[];
+ {
+ /* If until now the character has been a proper subset of
+ * an equivalence class, break it away to create a new ec
+ */
- {
- /* if until now the character has been a proper subset of
- * an equivalence class, break it away to create a new ec
- */
-
- if ( fwd[tch] != NIL )
- bck[fwd[tch]] = bck[tch];
+ if ( fwd[tch] != NIL )
+ bck[fwd[tch]] = bck[tch];
- if ( bck[tch] != NIL )
- fwd[bck[tch]] = fwd[tch];
+ if ( bck[tch] != NIL )
+ fwd[bck[tch]] = fwd[tch];
- fwd[tch] = NIL;
- bck[tch] = NIL;
- }
+ fwd[tch] = NIL;
+ bck[tch] = NIL;
+ }