/*
a state machine for interpreting gb.
*/
void
gbproc(int c, Rune **r, long input_loc)
{
static enum { state0, state1 } state = state0;
static int lastc;
long n, ch, cold = c;
switch(state)
{
case state0: /* idle state */
if(c < 0)
return;
if(c >= 0xA1){
lastc = c;
state = state1;
return;
}
emit(c);
return;
case state1: /* seen a font spec */
if(c >= 0xA1)
n = (lastc-0xA0)*100 + (c-0xA0);
else {
nerrors++;
if(squawk)
warn("bad gb glyph %d (from 0x%x,0x%lx) near byte %ld in %s", c-0xA0, lastc, cold, input_loc, file);
if(!clean)
emit(BADMAP);
state = state0;
return;
}
ch = tabgb[n];
if(ch < 0){
nerrors++;
if(squawk)
warn("unknown gb %ld (from 0x%x,0x%lx) near byte %ld in %s", n, lastc, cold, input_loc, file);
if(!clean)
emit(BADMAP);
} else
emit(ch);
state = state0;
}
}
void
gb_in(int fd, long *, struct convert *out)
{
Rune ob[N];
Rune *r, *re;
uchar ibuf[N];
int n, i;
long nin;