b.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/*
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include "awk.def"
#include "stdio.h"
#include "awk.h"
#define MAXLIN 256
#define NCHARS 128
#define NSTATES 256
/*
* encoding in tree NODEs:
* leaf (CCL, NCCL, CHAR, DOT): left is index,
* right contains value or pointer to value
* unary (FINAL, STAR, PLUS, QUEST): left is child, right is null
* binary (CAT, OR): left and right are children
* parent contains pointer to parent
*/
struct fa {
union {
ccl_chars_t s;
int h;
} cc;
#define MAX_CODESET 3
};
int setcnt;
int line;
static int ccln_member();
static int insert_table();
static int delete_table();
#ifdef DEBUG
#define ddump_table(t, s) dump_table(t, s)
#else
#define ddump_table(t, s)
#endif
struct fa *
makedfa(p) /* returns dfa for tree pointed to by p */
NODE *p;
{
/* put DOT STAR in front of reg. exp. */
line = 0;
return (fap);
}
penter(p) /* set up parent pointers and leaf indices */
NODE *p;
{
switch (type(p)) {
break;
break;
case CAT:
case OR:
break;
default:
break;
}
}
freetr(p) /* free parse tree and follow sets */
NODE *p;
{
switch (type(p)) {
xfree(p);
break;
xfree(p);
break;
case CAT:
case OR:
xfree(p);
break;
default:
break;
}
}
cclenter(p)
register wchar_t *p;
{
register int i, cn;
register ccl_chars_t *new;
op = p;
i = 0;
while ((c = *p++) != 0) {
if (c == '-' && i > 0) {
if (*p != 0) {
/*
* If there are not in same code set, the
* class should be ignore (make two independent
* characters)!
*/
c = *p++;
goto char_array;
continue;
}
}
if (i >= MAXLIN)
overflo();
pc = c;
}
i = (i + 1) * sizeof (ccl_chars_t);
return (new);
}
overflo()
{
}
cfoll(v) /* enter follow set of each leaf of vertex v into foll[leaf] */
register NODE *v;
{
register i;
int prev;
int *add();
switch (type(v)) {
setcnt = 0;
for (i = 1; i <= line; i++)
setvec[i] = 0;
follow(v);
break;
break;
case CAT:
case OR:
break;
default:
}
}
first(p) /* collects initially active leaves of p into setvec */
register NODE *p;
/* returns 0 or 1 depending on whether p matches empty string */
{
register b;
switch (type(p)) {
setcnt++;
}
return (0); /* empty CCL */
else return (1);
case FINAL:
case PLUS:
return (0);
return (1);
case STAR:
case QUEST:
return (0);
case CAT:
return (0);
return (1);
case OR:
return (0);
return (1);
}
return (-1);
}
follow(v)
NODE *v; /* collects leaves that can follow v into setvec */
{
NODE *p;
return;
p = parent(v);
switch (type(p)) {
case STAR:
follow(p);
return;
case OR:
return;
follow(p);
return;
}
} else /* v is right child */
follow(p);
return;
setcnt++;
}
return;
}
}
/*
* There are three type of functions for checking member ship. Because I have
* been changed structure of CCL tables. And some CCL tables end up with NULLs
* but someone has length and will includes NULLs in table as one of data.
* Please note, CCL table which has a length data and data will include NULLs,
* it only used within a this source file("b.c").
*/
register int ns;
register int ne;
register ccl_chars_t *s;
{
/*
* The specified range(cs, ce) must be beside the range between
* s->cc_start and s->cc_end to determine member.
*/
return (1);
s++;
}
return (0);
}
static
register int ns;
register int ne;
register ccl_chars_t *s;
register int n;
{
/*
* The specified range(cs, ce) must be beside the range between
* s->cc_start and s->cc_end to determine member.
*/
while (n-- > 0) {
return (1);
s++;
}
return (0);
}
member(c, s) /* is c in s? */
register wchar_t c, *s;
{
while (*s)
if (c == *s++)
return (1);
return (0);
}
int **array;
int *prev; {
register i, j;
int *ptr;
for (i = 0; i <= n; i++) {
for (j = 0; j < setcnt; j++)
*prev = i;
return (0);
}
nxt: /* dummy */;
}
return (1);
}
int *add(n) { /* remember setvec */
int *ptr, *p;
register i;
overflo();
*ptr = n;
for (i = 1; i <= line; i++)
if (setvec[i] == 1) {
*(++ptr) = i;
}
return (p);
}
struct fa *
cgotofn()
{
register i, k;
register int *ptr;
register ccl_chars_t *p;
int finflg;
struct {
int n;
} fatab[257];
int hatcn;
for (i = 0; i < NCHARS; i++)
symax = 0;
setcnt = 0;
/* compute initial positions and symbols of state 0 */
ismax = 0;
ssmax = 0;
for (i = 0; i < spinit; i++) {
case CHAR:
}
break;
case DOT:
cs = WC_VERY_SMALL;
ns = 0;
}
ce = WC_VERY_LARGE;
ne = MAX_CODESET;
}
break;
case CCL:
p->cc_cs; p++) {
}
}
break;
case NCCL:
ns = 0;
cs = WC_VERY_SMALL;
p->cc_cs; p++) {
p->cc_ns,
p->cc_cs-1);
}
} else {
}
}
}
break;
}
}
symax = 0;
n = 0;
for (s = 0; s <= n; s++) {
ind = 0;
numtrans = 0;
finflg = 0;
finflg = 1;
goto tenter;
}
for (i = 0; i < num; i++) {
}
case CHAR:
ns, k,
ns, k);
}
break;
case DOT:
cs = WC_VERY_SMALL;
ns = 0;
}
ce = WC_VERY_LARGE;
ne = MAX_CODESET;
}
break;
case CCL:
p->cc_cs; p++) {
! ccln_member(p->cc_ns,
symax)) {
}
}
break;
case NCCL:
ns = 0;
cs = WC_VERY_SMALL;
}
= p->cc_cs-1;
} else {
}
}
}
break;
}
}
for (j = 0; j < ssmax; j++) { /* nextstate(s, ssyms[j]) */
setcnt = 0;
for (i = 0; i < spmax; i++) {
k == NCCL &&
for (k = 0; k < num; k++) {
setcnt++;
}
}
}
}
} /* end nextstate */
if (n >= NSTATES - 1) {
overflo();
}
dprintf(" delta(%d,[%o,%o])",
numtrans++;
} else {
if (prev != 0) {
dprintf(" delta(%d,[%o,%o])",
dprintf("= %d, ind = %d\n",
numtrans++;
}
}
}
overflo();
if (finflg)
else
}
}
for (i = 0; i <= n; i++) {
if (i != 0) /* state[0] is freed later in freetr() */
dprintf(" numtrans = %d, default = %o\n",
dprintf(" char = [%o,%o], nextstate = %o\n",
}
}
return (where[0]);
}
return (where[0]);
}
/*
* Insert CCL entry to CCL table with maintain optimized order.
*/
static int
register int table_size;
{
register int i;
register ccl_chars_t *table;
register ccl_chars_t *saved_table;
int saved_i;
/*
* Searching the table to find out where should put the new item.
*/
/*
* Quick! insert to font of current table entries.
*/
table_size++;
for (; i < table_size; i++, table++) {
}
goto add_null;
/*
* Starting point is within the current entry.
*/
}
return (table_size);
}
goto combine;
}
}
/*
* Adding new one to end of table.
*/
table_size++;
goto add_null;
/*
* Check and try to combine the new entry with rest of entries.
*/
if ((i + 1) >= table_size) {
return (table_size);
}
saved_table = table++;
saved_i = i++;
/*
* Finding the spot where we should put the end point.
*/
for (; i < table_size; i++, table++) {
break;
} else
/*
* Tack with this table.
*/
}
table++;
i++;
break;
}
}
/*
* Moving the rest of entries.
*/
for (; i < table_size; i++, table++)
*(++saved_table) = *table;
return (table_size);
}
static int
register int table_size;
{
register int i;
int saved_i;
register ccl_chars_t *table;
register ccl_chars_t *saved_table;
register int tns;
register int tne;
return (table_size);
/*
* Shrink type 1.
*/
return (table_size);
} else {
/*
* Spliting !!
*/
table_size++;
for (; i < table_size; i++, table++) {
}
return (table_size);
}
/*
* Shrink current table(type 2).
*/
table++;
i++;
}
/*
* Search for the end point.
*/
saved_i = i;
saved_table = table;
for (; i < table_size; i++, table++) {
/*
* Easy point, no shrinks!
*/
break;
/*
* Shrinking...
*/
break;
}
}
/*
* Moving(removing) backword.
*/
for (; i < table_size; i++)
*saved_table++ = *table++;
return (saved_i);
}
}
return (table_size);
}
#ifdef DEBUG
register ccl_chars_t *table;
register int size;
{
register int i;
if (! dbg)
return;
size++; /* To watch out NULL */
{
}
printf("\n");
}
#endif /* DEBUG */
register wchar_t *p;
{
register count;
if (p == 0)
return (0);
do {
c = *p;
n = wcsetno(c);
p++;
goto adv;
}
} while (*p++ != 0);
return (0);
}
return (1);
do {
c = *p;
n = wcsetno(c);
break;
}
return (1);
} while (*p++ != 0);
return (0);
}