version 1.8, 2015/11/19 23:34:56 |
version 1.9, 2015/11/20 18:54:49 |
|
|
|
|
/* ccl2ecl - convert character classes to set of equivalence classes */ |
/* ccl2ecl - convert character classes to set of equivalence classes */ |
|
|
void ccl2ecl () |
void |
|
ccl2ecl(void) |
{ |
{ |
int i, ich, newlen, cclp, ccls, cclmec; |
int i, ich, newlen, cclp, ccls, cclmec; |
|
|
for (i = 1; i <= lastccl; ++i) { |
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 |
* We loop through each character class, and for each |
* new "character" class we are creating. Thus when we are all |
* character in the class, add the character's equivalence |
* done, character classes will really consist of collections |
* class to the new "character" class we are creating. Thus |
* of equivalence classes |
* when we are all done, character classes will really |
|
* consist of collections of equivalence classes |
*/ |
*/ |
|
|
newlen = 0; |
newlen = 0; |
|
|
* Returned is the number of classes. |
* Returned is the number of classes. |
*/ |
*/ |
|
|
int cre8ecs (fwd, bck, num) |
int |
int fwd[], bck[], num; |
cre8ecs(int *fwd, int *bck, int num) |
{ |
{ |
int i, j, numcl; |
int i, j, numcl; |
|
|
numcl = 0; |
numcl = 0; |
|
|
/* Create equivalence class numbers. From now on, ABS( bck(x) ) |
/* |
* is the equivalence class number for object x. If bck(x) |
* Create equivalence class numbers. From now on, ABS( bck(x) ) is |
* is positive, then x is the representative of its equivalence |
* the equivalence class number for object x. If bck(x) is positive, |
* class. |
* then x is the representative of its equivalence class. |
*/ |
*/ |
for (i = 1; i <= num; ++i) |
for (i = 1; i <= num; ++i) |
if (bck[i] == NIL) { |
if (bck[i] == NIL) { |
|
|
for (j = fwd[i]; j != NIL; j = fwd[j]) |
for (j = fwd[i]; j != NIL; j = fwd[j]) |
bck[j] = -numcl; |
bck[j] = -numcl; |
} |
} |
|
|
return numcl; |
return numcl; |
} |
} |
|
|
|
|
* NUL_mapping is the value which NUL (0) should be mapped to. |
* NUL_mapping is the value which NUL (0) should be mapped to. |
*/ |
*/ |
|
|
void mkeccl (ccls, lenccl, fwd, bck, llsiz, NUL_mapping) |
void |
u_char ccls[]; |
mkeccl(u_char *ccls, int lenccl, int *fwd, int *bck, int llsiz, int NUL_mapping) |
int lenccl, fwd[], bck[], llsiz, NUL_mapping; |
|
{ |
{ |
int cclp, oldec, newec; |
int cclp, oldec, newec; |
int cclm, i, j; |
int cclm, i, j; |
static unsigned char cclflags[CSIZE]; /* initialized to all '\0' */ |
static unsigned char cclflags[CSIZE]; /* initialized to all '\0' */ |
|
|
/* Note that it doesn't matter whether or not the character class is |
/* |
|
* Note that it doesn't matter whether or not the character class is |
* negated. The same results will be obtained in either case. |
* negated. The same results will be obtained in either case. |
*/ |
*/ |
|
|
|
|
|
|
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 (i = fwd[cclm]; i != NIL && i <= llsiz; i = fwd[i]) { |
|
/* look for the symbol in the character class */ |
for (; j < lenccl; ++j) { |
for (; j < lenccl; ++j) { |
int ccl_char; |
int ccl_char; |
|
|
|
|
break; |
break; |
|
|
if (ccl_char == i && !cclflags[j]) { |
if (ccl_char == i && !cclflags[j]) { |
/* We found an old companion of cclm |
/* |
|
* We found an old companion of cclm |
* in the ccl. Link it into the new |
* in the ccl. Link it into the new |
* equivalence class and flag it as |
* equivalence class and flag it as |
* having been processed. |
* having been processed. |
|
|
} |
} |
} |
} |
|
|
/* 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; |
|
|
|
|
oldec = i; |
oldec = i; |
|
|
next_pt:; |
next_pt: ; |
} |
} |
|
|
if (bck[cclm] != NIL || oldec != bck[cclm]) { |
if (bck[cclm] != NIL || oldec != bck[cclm]) { |
bck[cclm] = NIL; |
bck[cclm] = NIL; |
fwd[oldec] = NIL; |
fwd[oldec] = NIL; |
} |
} |
|
|
fwd[newec] = NIL; |
fwd[newec] = NIL; |
|
|
/* Find next ccl member to process. */ |
/* Find next ccl member to process. */ |
|
|
|
|
/* mkechar - create equivalence class for single character */ |
/* mkechar - create equivalence class for single character */ |
|
|
void mkechar (tch, fwd, bck) |
void |
int tch, fwd[], bck[]; |
mkechar(int tch, int *fwd, int *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) |
if (fwd[tch] != NIL) |