int e_X(void) { int c; while((c = getrune()) >= 0 && c != '\'' && c != '\n') outrune(c); if(c == '\n'){ warn("newline in %CX'...'", backslash); outrune(c); } if(c < 0) warn("eof in %CX'...'", backslash); return 0; }
void out(Rune *s) { if(s == nil) return; for(; *s; s++) outrune(*s); }
int e_bang(void) { Rune *line; line = readline(CopyMode); out(line); outrune('\n'); free(line); return 0; }
void inroman(Rune r) { int f; f = getnr(L(".f")); nr(L(".f"), 1); runmacro1(L("font")); outrune(r); nr(L(".f"), f); runmacro1(L("font")); }
void runinput(void) { int c; bol = 1; for(;;){ c = getnext(); if(c < 0) break; if((c == dot || c == tick) && bol){ inrequest = 1; dotline(c); bol = 1; inrequest = 0; }else if(c == '\n'){ newline(); itrap(); linepos = 0; }else{ outtrap(); startoutput(); showihtml(); if(c == '\t'){ /* XXX do better */ outrune(' '); while(++linepos%4) outrune(' '); }else{ outrune(c); linepos++; } bol = 0; } } }
void newline(void) { int n; if(bol) sp(eval(L("1v"))); bol = 1; if((n=getnr(L(".ce"))) > 0){ nr(L(".ce"), n-1); br(); } if(getnr(L(".fi")) == 0) br(); outrune('\n'); }
/* * Get the next logical character in the input stream. */ int getnext(void) { int i, r; next: r = getrune(); if(r < 0) return -1; if(r == Uformatted){ br(); assert(!isoutput); while((r = getrune()) >= 0 && r != Uunformatted){ if(r == Uformatted) continue; outrune(r); } goto next; } if(r == Uunformatted) goto next; if(r == backslash){ r = getrune(); if(r < 0) return -1; for(i=0; i<nesc; i++){ if(r == esc[i].r && (inputmode&esc[i].mode)==inputmode){ if(esc[i].f == e_warn) warn("ignoring %C%C", backslash, r); r = esc[i].f(); if(r <= 0) goto next; return r; } } if(inputmode&(ArgMode|CopyMode)){ ungetrune(r); r = backslash; } } return r; }
void outhtml(Rune *s) { Rune r; for(; *s; s++){ switch(r = *s){ case '<': r = Ult; break; case '>': r = Ugt; break; case '&': r = Uamp; break; case ' ': r = Uspace; break; } outrune(r); } }
void pcollprintentry(Entry e, int cmd) { char *p, *pe; long r, rprev, t, rlig; int saveoi; Rune *transtab; p = e.start; pe = e.end; transtab = normtab; rprev = NONE; changett(0, 0, 0); curentry = e; saveoi = 0; if(cmd == 'h') outinhibit = 1; while(p < pe) { if(cmd == 'r') { outchar(*p++); continue; } r = transtab[(*p++)&0x7F]; if(r < NONE) { /* Emit the rune, but buffer in case of ligature */ if(rprev != NONE) outrune(rprev); rprev = r; } else if(r == TAGS) { p = gettag(p, pe); t = lookassoc(tagtab, asize(tagtab), tag); if(t == -1) { if(debug && !outinhibit) err("tag %ld %d %s", e.doff, cursize, tag); continue; } if(t < NONE) { if(rprev != NONE) outrune(rprev); rprev = t; } else if(t >= LIGS && t < LIGE) { /* handle possible ligature */ rlig = liglookup(t, rprev); if(rlig != NONE) rprev = rlig; /* overwrite rprev */ else { /* could print accent, but let's not */ if(rprev != NONE) outrune(rprev); rprev = NONE; } } else if(t >= MULTI && t < MULTIE) { if(rprev != NONE) { outrune(rprev); rprev = NONE; } outrunes(multitab[t-MULTI]); } else { if(rprev != NONE) { outrune(rprev); rprev = NONE; } switch(t){ case H: if(cmd == 'h') outinhibit = 0; else outnl(0); break; case X: if(cmd == 'h') outinhibit = 1; else outchars(". "); break; case Ps: /* don't know enough of pron. key yet */ saveoi = outinhibit; outinhibit = 1; break; case Pe: outinhibit = saveoi; break; } } } } if(cmd == 'h') outinhibit = 0; outnl(0); }
void pcollgprintentry(Entry e, int cmd) { uint8_t *p, *pe; int r, rprev = NONE, rx, over = 0, font; char buf[16]; p = (uint8_t *)e.start; pe = (uint8_t *)e.end; curentry = e; if(cmd == 'h') outinhibit = 1; while(p < pe){ if(cmd == 'r'){ outchar(*p++); continue; } switch(r = intab[*p++]){ /* assign = */ case TAGS: if(rprev != NONE){ outrune(rprev); rprev = NONE; } p = reach(p, 0x06); font = tag[0]; if(cmd == 'h') outinhibit = (font != 'h'); break; case TAGE: /* an extra one */ break; case SPCS: p = reach(p, 0xba); r = looknassoc(numtab, asize(numtab), strtol(tag,0,0)); if(r < 0){ if(rprev != NONE){ outrune(rprev); rprev = NONE; } sprint(buf, "\\N'%s'", tag); outchars(buf); break; } /* else fall through */ default: if(over){ rx = looknassoc(overtab, asize(overtab), r); if(rx > 0) rx = liglookup(rx, rprev); if(rx > 0 && rx != NONE) outrune(rx); else{ outrune(rprev); if(r == ':') outrune(L'¨'); else{ outrune(L'^'); outrune(r); } } over = 0; rprev = NONE; }else if(r == '^'){ over = 1; }else{ if(rprev != NONE) outrune(rprev); rprev = r; } } } if(rprev != NONE) outrune(rprev); if(cmd == 'h') outinhibit = 0; outnl(0); }
/* * cmd is one of: * 'p': normal print * 'h': just print headwords * 'P': print raw */ void pgwprintentry(Entry e, int cmd) { char *p, *pe; int t; long r, rprev, rlig; Rune *transtab; p = e.start; pe = e.end; transtab = normtab; rprev = NONE; changett(0, 0, 0); curentry = e; if(cmd == 'h') outinhibit = 1; while(p < pe) { if(cmd == 'r') { outchar(*p++); continue; } r = transtab[(*p++)&0x7F]; if(r < NONE) { /* Emit the rune, but buffer in case of ligature */ if(rprev != NONE) outrune(rprev); rprev = r; } else if(r == SPCS) { /* Start of special character name */ p = getspec(p, pe); r = lookassoc(spectab, asize(spectab), spec); if(r == -1) { if(debug) err("spec %ld %d %s", e.doff, cursize, spec); r = L'�'; } if(r >= LIGS && r < LIGE) { /* handle possible ligature */ rlig = liglookup(r, rprev); if(rlig != NONE) rprev = rlig; /* overwrite rprev */ else { /* could print accent, but let's not */ if(rprev != NONE) outrune(rprev); rprev = NONE; } } else if(r >= MULTI && r < MULTIE) { if(rprev != NONE) { outrune(rprev); rprev = NONE; } outrunes(multitab[r-MULTI]); } else if(r == PAR) { if(rprev != NONE) { outrune(rprev); rprev = NONE; } outnl(1); } else { if(rprev != NONE) outrune(rprev); rprev = r; } } else if(r == TAGS) { /* Start of tag name */ if(rprev != NONE) { outrune(rprev); rprev = NONE; } p = gettag(p, pe); t = lookassoc(tagtab, asize(tagtab), tag); if(t == -1) { if(debug) err("tag %ld %d %s", e.doff, cursize, tag); continue; } switch(t) { case Hw: if(cmd == 'h') { if(!tagstarts) outchar(' '); outinhibit = !tagstarts; } break; case Sn: if(tagstarts) { outnl(2); } break; case P: outnl(tagstarts); break; case Col: case Br: case Blockquote: if(tagstarts) outnl(1); break; case U: outchar('/'); } } } if(cmd == 'h') { outinhibit = 0; outnl(0); } }
static void putchar(int c, int *state) { int xflag = 0; Rune r; int hi, lo; switch(state[0]){ case Kanahi: case GBhi: if(CANS2JH(c) || c == 0xff){ state[0]++; state[1] = c; break; } /* fall through */ case Utf: if(c == 0xfe){ state[0] = Kanahi; break; }else if(c == 0xff){ state[0] = GBhi; break; } r = chartab[c]; if(r < 0x80 && state[2] == 0) outchar(r); else if(r == NONE){ switch(c){ case 0xfb: if(!xflag){ state[2] = 1; break; } case 0xfc: if(!xflag){ state[2] = 0; break; } case 0x10: case 0xc7: case 0xc8: case 0xd8: case 0xd9: case 0xda: case 0xdc: case 0xdd: case 0xde: case 0xdf: case 0xfd: if(!xflag) break; /* fall through */ default: outprint("\\%.2ux", c); } }else if(state[2] == 0) outrune(r); break; case Kanalo: case GBlo: if(state[1] == 0xff && c == 0xff){ state[0] = Utf; break; } state[0]--; hi = state[1]; lo = c; S2J(hi, lo); /* convert to JIS */ r = hi*100 + lo - 3232; /* convert to jis208 */ if(state[0] == Kanahi && r < JIS208MAX) r = tabjis208[r]; else if(state[0] == GBhi && r < GB2312MAX) r = tabgb2312[r]; else r = NONE; if(r == NONE) outprint("\\%.2ux\\%.2ux", state[1], c); else outrune(r); break; } }