typedef struct PCB /* Control block controlling specification parse */
{
char *base; /* start of specification */
char *current; /* current parse point */
long last; /* last Rune returned */
long final; /* final Rune in a span */
} Pcb;
if (cflag) {
memset((char *) f, 0xff, sizeof f);
while ((c = canon(&pfrom)) >= 0)
CLEARBIT(f, c);
} else {
while ((c = canon(&pfrom)) >= 0)
SETBIT(f, c);
}
if (sflag) {
while ((c = canon(&pto)) >= 0)
SETBIT(t, c);
}
last = 0x10000;
while ((c = Bgetrune(&fin)) >= 0) {
if(!BITSET(f, c) && (c != last || !BITSET(t,c))) {
last = c;
if (Bputrune(&fout, c) < 0)
error("write error");
}
}
}
void
complement(void)
{
Rune *p;
int i;
long from, to, lastc, high;
lastc = 0;
high = 0;
while ((from = canon(&pfrom)) >= 0) {
if (from > high) high = from;
SETBIT(f, from);
}
while ((to = canon(&pto)) > 0) {
if (to > high) high = to;
SETBIT(t,to);
}
Prewind(&pto);
if ((p = (Rune *) malloc((high+1)*sizeof(Rune))) == 0)
error("can't allocate memory");
for (i = 0; i <= high; i++){
if (!BITSET(f,i)) {
if ((to = canon(&pto)) < 0)
to = lastc;
else lastc = to;
p[i] = to;
}
else p[i] = i;
}
if (sflag){
lastc = 0x10000;
while ((from = Bgetrune(&fin)) >= 0) {
if (from > high) from = to;
else from = p[from];
if (from != lastc || !BITSET(t,from)) {
lastc = from;
if (Bputrune(&fout, from) < 0)
error("write error");
}
}
} else {
while ((from = Bgetrune(&fin)) >= 0){
if (from > high) from = to;
else from = p[from];
if (Bputrune(&fout, from) < 0)
error("write error");
}
}
}
void
translit(void)
{
Rune *p;
int i;
long from, to, lastc, high;
lastc = 0;
high = 0;
while ((from = canon(&pfrom)) >= 0)
if (from > high) high = from;
Prewind(&pfrom);
if ((p = (Rune *) malloc((high+1)*sizeof(Rune))) == 0)
error("can't allocate memory");
for (i = 0; i <= high; i++)
p[i] = i;
while ((from = canon(&pfrom)) >= 0) {
if ((to = canon(&pto)) < 0)
to = lastc;
else lastc = to;
if (BITSET(f,from) && p[from] != to)
error("ambiguous translation");
SETBIT(f,from);
p[from] = to;
SETBIT(t,to);
}
while ((to = canon(&pto)) >= 0) {
SETBIT(t,to);
}
if (sflag){
lastc = 0x10000;
while ((from = Bgetrune(&fin)) >= 0) {
if (from <= high) from = p[from];
if (from != lastc || !BITSET(t,from)) {
lastc = from;
if (Bputrune(&fout, from) < 0)
error("write error");
}
}
} else {
while ((from = Bgetrune(&fin)) >= 0){
if (from <= high) from = p[from];
if (Bputrune(&fout, from) < 0)
error("write error");
}
}
}
char *
getrune(char *s, Rune *rp)
{
Rune r;
char *save;
int i, n;
s += chartorune(rp, s);
if((r = *rp) == '\\' && *s){
n = 0;
if (*s == 'x') {
s++;
for (i = 0; i < 4; i++) {
save = s;
s += chartorune(&r, s);
if ('0' <= r && r <= '9')
n = 16*n + r - '0';
else if ('a' <= r && r <= 'f')
n = 16*n + r - 'a' + 10;
else if ('A' <= r && r <= 'F')
n = 16*n + r - 'A' + 10;
else {
if (i == 0)
*rp = 'x';
else *rp = n;
return save;
}
}
} else {
for(i = 0; i < 3; i++) {
save = s;
s += chartorune(&r, s);
if('0' <= r && r <= '7')
n = 8*n + r - '0';
else {
if (i == 0)
{
*rp = r;
return s;
}
*rp = n;
return save;
}
}
if(n > 0377)
error("char>0377");
}
*rp = n;
}
return s;
}