aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/dict/thesaurus.c
blob: 8ad3006bbe545b2256e0bdf88aa719afa4f3127e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include <u.h>
#include <libc.h>
#include <bio.h>
#include "dict.h"

void
thesprintentry(Entry e, int cmd)
{
	char *p, *pe;
	int c, i;

	p = e.start;
	pe = e.end;
	while(p < pe) {
		c = *p++;
		if(cmd == 'r') {
			outchar(c);
			continue;
		}
		switch(c) {
		case '*':
			c = *p++;
			if(cmd == 'h' && c != 'L') {
				outnl(0);
				return;
			}
			if(c == 'L' && cmd != 'h')
				outnl(0);
			if(c == 'S') {
				outchar('(');
				outchar(*p++);
				outchar(')');
			}
			break;
		case '#':
			c = *p++;
			i = *p++ - '0' - 1;
			if(i < 0 || i > 4)
				break;
			switch(c) {
			case 'a': outrune(L"áàâäa"[i]); break;
			case 'e': outrune(L"éèêëe"[i]); break;
			case 'o': outrune(L"óòôöo"[i]); break;
			case 'c': outrune(L"ccccç"[i]); break;
			default: outchar(c); break;
			}
			break;
		case '+':
		case '<':
			break;
		case ' ':
			if(cmd == 'h' && *p == '*') {
				outnl(0);
				return;
			}
		default:
			outchar(c);
		}
	}
	outnl(0);
}

long
thesnextoff(long fromoff)
{
	long a;
	char *p;

	a = Bseek(bdict, fromoff, 0);
	if(a < 0)
		return -1;
	for(;;) {
		p = Brdline(bdict, '\n');
		if(!p)
			break;
		if(p[0] == '*' && p[1] == 'L')
			return (Boffset(bdict)-Blinelen(bdict));
	}
	return -1;
}

void
thesprintkey(void)
{
	Bprint(bout, "No key\n");
}