Blob


1 #include <u.h>
2 #include <libc.h>
3 #include <bio.h>
4 #include <ctype.h>
5 #include "dict.h"
7 /* Roget's Thesaurus from project Gutenberg */
9 /* static long Last = 0; */
11 void
12 rogetprintentry(Entry e, int cmd)
13 {
14 int spc;
15 char c, *p;
17 spc = 0;
18 p = e.start;
20 if(cmd == 'h'){
21 while(!isspace((uchar)*p) && p < e.end)
22 p++;
23 while(strncmp(p, " -- ", 4) != 0 && p < e.end){
24 while(isspace((uchar)*p) && p < e.end)
25 p++;
26 if (*p == '[' || *p == '{'){
27 c = (*p == '[')? ']': '}';
28 while(*p != c && p < e.end)
29 p++;
30 p++;
31 continue;
32 }
33 if (isdigit((uchar)*p) || ispunct((uchar)*p)){
34 while(!isspace((uchar)*p) && p < e.end)
35 p++;
36 continue;
37 }
40 if (isspace((uchar)*p))
41 spc = 1;
42 else
43 if (spc){
44 outchar(' ');
45 spc = 0;
46 }
48 while(!isspace((uchar)*p) && p < e.end)
49 outchar(*p++);
50 }
51 return;
52 }
54 while(p < e.end && !isspace((uchar)*p))
55 p++;
56 while(p < e.end && isspace((uchar)*p))
57 p++;
59 while (p < e.end){
60 if (p < e.end -4 && strncmp(p, " -- ", 4) == 0){ /* first line */
61 outnl(2);
62 p += 4;
63 spc = 0;
64 }
66 if (p < e.end -2 && strncmp(p, "[ ", 4) == 0){ /* twiddle layout */
67 outchars(" [");
68 continue;
69 }
71 if (p < e.end -4 && strncmp(p, "&c (", 4) == 0){ /* usefull xref */
72 if (spc)
73 outchar(' ');
74 outchar('/');
75 while(p < e.end && *p != '(')
76 p++;
77 p++;
78 while(p < e.end && *p != ')')
79 outchar(*p++);
80 p++;
81 while(p < e.end && isspace((uchar)*p))
82 p++;
83 while(p < e.end && isdigit((uchar)*p))
84 p++;
85 outchar('/');
86 continue;
87 }
89 if (p < e.end -3 && strncmp(p, "&c ", 3) == 0){ /* less usefull xref */
90 while(p < e.end && !isdigit((uchar)*p))
91 p++;
92 while(p < e.end && isdigit((uchar)*p))
93 p++;
94 continue;
95 }
97 if (*p == '\n' && p < (e.end -1)){ /* their newlines */
98 spc = 0;
99 p++;
100 if (isspace((uchar)*p)){ /* their continuation line */
101 while (isspace((uchar)*p))
102 p++;
103 p--;
105 else{
106 outnl(2);
109 if (spc && *p != ';' && *p != '.' &&
110 *p != ',' && !isspace((uchar)*p)){ /* drop spaces before punct */
111 spc = 0;
112 outchar(' ');
114 if (isspace((uchar)*p))
115 spc = 1;
116 else
117 outchar(*p);
118 p++;
120 outnl(0);
123 long
124 rogetnextoff(long fromoff)
126 int i;
127 vlong l;
128 char *p;
130 Bseek(bdict, fromoff, 0);
131 Brdline(bdict, '\n');
132 while ((p = Brdline(bdict, '\n')) != nil){
133 l = Blinelen(bdict);
134 if (!isdigit((uchar)*p))
135 continue;
136 for (i = 0; i < l-4; i++)
137 if (strncmp(p+i, " -- ", 4) == 0)
138 return Boffset(bdict)-l;
140 return Boffset(bdict);
143 void
144 rogetprintkey(void)
146 Bprint(bout, "No pronunciation key.\n");