#include #include #include #include "dict.h" /* * Robert ֳ‰lectronique. */ enum { CIT = MULTIE+1, /* citation ptr followed by long int and ascii label */ BROM, /* bold roman */ ITON, /* start italic */ ROM, /* roman */ SYM, /* symbol font? */ HEL, /* helvetica */ BHEL, /* helvetica bold */ SMALL, /* smaller? */ ITOFF, /* end italic */ SUP, /* following character is superscript */ SUB /* following character is subscript */ }; static Rune intab[256] = { /*0*/ /*1*/ /*2*/ /*3*/ /*4*/ /*5*/ /*6*/ /*7*/ /*00*/ NONE, L'ג˜÷', L'ג˜»', L'ג™¥', L'ג™¦', L'ג™£', L'ג™ ', L'ג€¢', 0x25d8, L'�˜', L'\n', L'ג™‚', L'ג™€', L'ג™×', 0x266b, L'ג€»', /*10*/ L'ג‡¨', L'ג‡¦', L'ג†•', L'ג€¼', L'ֲ¶', L'ֲ§', L'ג�ƒ', L'ג†¨', L'ג†‘', L'ג†“', L'ג†’', L'ג†�', L'ג�™', L'ג†”', 0x25b4, 0x25be, /*20*/ L' ', L'!', L'"', L'#', L'$', L'%', L'&', L''', L'(', L')', L'*', L'+', L',', L'-', L'.', L'/', /*30*/ L'0', L'1', L'2', L'3', L'4', L'5', L'6', L'7', L'8', L'9', L':', L';', L'<', L'=', L'>', L'?', /*40*/ L'@', L'A', L'B', L'C', L'D', L'E', L'F', L'G', L'H', L'I', L'J', L'K', L'L', L'M', L'N', L'O', /*50*/ L'P', L'Q', L'R', L'S', L'T', L'U', L'V', L'W', L'X', L'Y', L'Z', L'[', L'\\', L']', L'^', L'_', /*60*/ L'`', L'a', L'b', L'c', L'd', L'e', L'f', L'g', L'h', L'i', L'j', L'k', L'l', L'm', L'n', L'o', /*70*/ L'p', L'q', L'r', L's', L't', L'u', L'v', L'w', L'x', L'y', L'z', L'{', L'|', L'}', L'~', L'', /*80*/ L'ֳ‡', L'ֳ¼', L'ֳ©', L'ֳ¢', L'ֳ₪', L'ֳ ', L'ֳ¥', L'ֳ§', L'ֳ×', L'ֳ«', L'ֳ¨', L'ֳ¯', L'ֳ®', L'ֳ¬', L'ֳ„', L'ֳ…', /*90*/ L'ֳ‰', L'ֳ¦', L'ֳ†', L'ֳ´', L'ֳ¶', L'ֳ²', L'ֳ»', L'ֳ¹', L'ֳ¿', L'ֳ–', L'ֳ�', L'ֲ¢', L'ֲ£', L'ֲ¥', L'ג‚§', L'�ƒ', /*a0*/ L'ֳ¡', L'ֳ­', L'ֳ³', L'ֳ÷', L'ֳ±', L'ֳ‘', L'ֲ×', L'ֲ÷', L'ֲ¿', L'ג��', L'ֲ¬', L'ֲ½', L'ֲ¼', L'ֲ¡', L'ֲ«', L'ֲ»', /*b0*/ NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, /*c0*/ NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, CIT, BROM, NONE, ITON, ROM, SYM, HEL, BHEL, /*d0*/ NONE, SMALL, ITOFF, SUP, SUB, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, /*e0*/ L'־±', L'ֳ�', L'־³', L'ֿ€', L'־£', L'ֿƒ', L'ֲµ', L'ֿ„', L'־¦', L'־˜', L'־©', L'־´', L'גˆ�', L'ֳ˜', L'־µ', L'גˆ©', /*f0*/ L'ג‰¡', L'ֲ±', L'ג‰¥', L'ג‰₪', L'ג� ', L'ג�¡', L'ֳ·', L'ג‰ˆ', L'ֲ°', L'גˆ™', L'ֲ·', L'גˆ�', L'ג�¿', L'ֲ²', L'גˆ�', L'ֲ ', }; static Rune suptab[] = { ['0'] L'ג�°', ['1'] L'ג�±', ['2'] L'ג�²', ['3'] L'ג�³', ['4'] L'ג�´', ['5'] L'ג�µ', ['6'] L'ג�¶', ['7'] L'ג�·', ['8'] L'ג�¸', ['9'] L'ג�¹', ['+'] L'ג�÷', ['-'] L'ג�»', ['='] L'ג�¼', ['('] L'ג�½', [')'] L'ג�¾', ['a'] L'ֲ×', ['n'] L'ג�¿', ['o'] L'ֲ÷' }; static Rune subtab[] = { ['0'] L'ג‚€', ['1'] L'ג‚�', ['2'] L'ג‚‚', ['3'] L'ג‚ƒ', ['4'] L'ג‚„', ['5'] L'ג‚…', ['6'] L'ג‚†', ['7'] L'ג‚‡', ['8'] L'ג‚ˆ', ['9'] L'ג‚‰', ['+'] L'ג‚�', ['-'] L'ג‚‹', ['='] L'ג‚�', ['('] L'ג‚�', [')'] L'ג‚�' }; #define GSHORT(p) (((p)[0]<<8) | (p)[1]) #define GLONG(p) (((p)[0]<<24) | ((p)[1]<<16) | ((p)[2]<<8) | (p)[3]) static char cfile[] = "/lib/dict/robert/cits.rob"; static char dfile[] = "/lib/dict/robert/defs.rob"; static char efile[] = "/lib/dict/robert/etym.rob"; static char kfile[] = "/lib/dict/robert/_phon"; static Biobuf * cb; static Biobuf * db; static Biobuf * eb; static Biobuf * Bouvrir(char*); static void citation(int, int); static void robertprintentry(Entry*, Entry*, int); void robertindexentry(Entry e, int cmd) { uchar *p = (uchar *)e.start; long ea, el, da, dl, fa; Entry def, etym; ea = GLONG(&p[0]); el = GSHORT(&p[4]); da = GLONG(&p[6]); dl = GSHORT(&p[10]); fa = GLONG(&p[12]); USED(fa); if(db == 0) db = Bouvrir(dfile); def.start = malloc(dl+1); def.end = def.start + dl; def.doff = da; Bseek(db, da, 0); Bread(db, def.start, dl); *def.end = 0; if(cmd == 'h'){ robertprintentry(&def, 0, cmd); }else{ if(eb == 0) eb = Bouvrir(efile); etym.start = malloc(el+1); etym.end = etym.start + el; etym.doff = ea; Bseek(eb, ea, 0); Bread(eb, etym.start, el); *etym.end = 0; robertprintentry(&def, &etym, cmd); free(etym.start); } free(def.start); } static void robertprintentry(Entry *def, Entry *etym, int cmd) { uchar *p, *pe; Rune r; int c, n; int baseline = 0; int lineno = 0; int cit = 0; p = (uchar *)def->start; pe = (uchar *)def->end; while(p < pe){ if(cmd == 'r'){ outchar(*p++); continue; } c = *p++; switch(r = intab[c]){ /* assign = */ case BROM: case ITON: case ROM: case SYM: case HEL: case BHEL: case SMALL: case ITOFF: case NONE: if(debug) outprint("\\%.2ux", c); baseline = 0; break; case SUP: baseline = 1; break; case SUB: baseline = -1; break; case CIT: n = p[0] | (p[1]<<8) | (p[2]<<16) | (p[3]<<24); p += 4; if(debug) outprint("[%d]", n); while(*p == ' ' || ('0'<=*p && *p<='9') || *p == '.'){ if(debug) outchar(*p); ++p; } ++cit; outnl(2); citation(n, cmd); baseline = 0; break; case '\n': outnl(0); baseline = 0; ++lineno; break; default: if(baseline > 0 && r < nelem(suptab)) r = suptab[r]; else if(baseline < 0 && r < nelem(subtab)) r = subtab[r]; if(cit){ outchar('\n'); cit = 0; } outrune(r); baseline = 0; break; } if(r == '\n'){ if(cmd == 'h') break; if(lineno == 1 && etym) robertprintentry(etym, 0, cmd); } } outnl(0); } static void citation(int addr, int cmd) { Entry cit; if(cb == 0) cb = Bouvrir(cfile); Bseek(cb, addr, 0); cit.start = Brdline(cb, 0xc8); cit.end = cit.start + Blinelen(cb) - 1; cit.doff = addr; *cit.end = 0; robertprintentry(&cit, 0, cmd); } long robertnextoff(long fromoff) { return (fromoff & ~15) + 16; } void robertprintkey(void) { Biobuf *db; char *l; db = Bouvrir(kfile); while(l = Brdline(db, '\n')) /* assign = */ Bwrite(bout, l, Blinelen(db)); Bterm(db); } void robertflexentry(Entry e, int cmd) { uchar *p, *pe; Rune r; int c; int lineno = 1; p = (uchar *)e.start; pe = (uchar *)e.end; while(p < pe){ if(cmd == 'r'){ Bputc(bout, *p++); continue; } c = *p++; r = intab[c]; if(r == '$') r = '\n'; if(r == '\n'){ ++lineno; if(cmd == 'h' && lineno > 2) break; } if(cmd == 'h' && lineno < 2) continue; if(r > MULTIE){ if(debug) Bprint(bout, "\\%.2ux", c); continue; } if(r < Runeself) Bputc(bout, r); else Bputrune(bout, r); } outnl(0); } long robertnextflex(long fromoff) { int c; if(Bseek(bdict, fromoff, 0) < 0) return -1; while((c = Bgetc(bdict)) >= 0){ if(c == '$') return Boffset(bdict); } return -1; } static Biobuf * Bouvrir(char *fichier) { Biobuf *db; db = Bopen(fichier, OREAD); if(db == 0){ fprint(2, "%s: impossible d'ouvrir %s: %r\n", argv0, fichier); exits("ouvrir"); } return db; }