aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/dict
diff options
context:
space:
mode:
authorrsc <devnull@localhost>2005-01-13 04:49:19 +0000
committerrsc <devnull@localhost>2005-01-13 04:49:19 +0000
commitc8b6342d3c2a167dec16931815926e9e4387e7ef (patch)
tree80d3ec6ea074462b30639168113def880476dad6 /src/cmd/dict
parent741f510ce758f77ed5193256fb693a09a7daecce (diff)
downloadplan9port-c8b6342d3c2a167dec16931815926e9e4387e7ef.tar.gz
plan9port-c8b6342d3c2a167dec16931815926e9e4387e7ef.tar.bz2
plan9port-c8b6342d3c2a167dec16931815926e9e4387e7ef.zip
Many small edits.
Diffstat (limited to 'src/cmd/dict')
-rw-r--r--src/cmd/dict/dict.h3
-rw-r--r--src/cmd/dict/mkfile2
-rw-r--r--src/cmd/dict/roget.c147
-rw-r--r--src/cmd/dict/utils.c3
4 files changed, 154 insertions, 1 deletions
diff --git a/src/cmd/dict/dict.h b/src/cmd/dict/dict.h
index 28a92e80..9b843d8a 100644
--- a/src/cmd/dict/dict.h
+++ b/src/cmd/dict/dict.h
@@ -134,6 +134,9 @@ void movieprintkey(void);
long pgwnextoff(long);
void pgwprintentry(Entry,int);
void pgwprintkey(void);
+void rogetprintentry(Entry, int);
+long rogetnextoff(long);
+void rogetprintkey(void);
long slangnextoff(long);
void slangprintentry(Entry, int);
void slangprintkey(void);
diff --git a/src/cmd/dict/mkfile b/src/cmd/dict/mkfile
index 43d1e156..d2a3a364 100644
--- a/src/cmd/dict/mkfile
+++ b/src/cmd/dict/mkfile
@@ -2,7 +2,7 @@
TARG=dict
LFILES=oed.$O ahd.$O pcollins.$O pcollinsg.$O movie.$O slang.$O robert.$O\
- world.$O jis208.$O gb2312.$O thesaurus.$O simple.$O pgw.$O
+ world.$O jis208.$O gb2312.$O thesaurus.$O simple.$O pgw.$O roget.$O\
OFILES=dict.$O\
$LFILES\
diff --git a/src/cmd/dict/roget.c b/src/cmd/dict/roget.c
new file mode 100644
index 00000000..16bfeae5
--- /dev/null
+++ b/src/cmd/dict/roget.c
@@ -0,0 +1,147 @@
+#include <u.h>
+#include <libc.h>
+#include <bio.h>
+#include <ctype.h>
+#include "dict.h"
+
+/* Roget's Thesaurus from project Gutenberg */
+
+/* static long Last = 0; */
+
+void
+rogetprintentry(Entry e, int cmd)
+{
+ int spc;
+ char c, *p;
+
+ spc = 0;
+ p = e.start;
+
+ if(cmd == 'h'){
+ while(!isspace(*p) && p < e.end)
+ p++;
+ while(strncmp(p, " -- ", 4) != 0 && p < e.end){
+ while(isspace(*p) && p < e.end)
+ p++;
+ if (*p == '[' || *p == '{'){
+ c = (*p == '[')? ']': '}';
+ while(*p != c && p < e.end)
+ p++;
+ p++;
+ continue;
+ }
+ if (isdigit(*p) || ispunct(*p)){
+ while(!isspace(*p) && p < e.end)
+ p++;
+ continue;
+ }
+
+
+ if (isspace(*p))
+ spc = 1;
+ else
+ if (spc){
+ outchar(' ');
+ spc = 0;
+ }
+
+ while(!isspace(*p) && p < e.end)
+ outchar(*p++);
+ }
+ return;
+ }
+
+ while(p < e.end && !isspace(*p))
+ p++;
+ while(p < e.end && isspace(*p))
+ p++;
+
+ while (p < e.end){
+ if (p < e.end -4 && strncmp(p, " -- ", 4) == 0){ /* first line */
+ outnl(2);
+ p += 4;
+ spc = 0;
+ }
+
+ if (p < e.end -2 && strncmp(p, "[ ", 4) == 0){ /* twiddle layout */
+ outchars(" [");
+ continue;
+ }
+
+ if (p < e.end -4 && strncmp(p, "&c (", 4) == 0){ /* usefull xref */
+ if (spc)
+ outchar(' ');
+ outchar('/');
+ while(p < e.end && *p != '(')
+ p++;
+ p++;
+ while(p < e.end && *p != ')')
+ outchar(*p++);
+ p++;
+ while(p < e.end && isspace(*p))
+ p++;
+ while(p < e.end && isdigit(*p))
+ p++;
+ outchar('/');
+ continue;
+ }
+
+ if (p < e.end -3 && strncmp(p, "&c ", 3) == 0){ /* less usefull xref */
+ while(p < e.end && !isdigit(*p))
+ p++;
+ while(p < e.end && isdigit(*p))
+ p++;
+ continue;
+ }
+
+ if (*p == '\n' && p < (e.end -1)){ /* their newlines */
+ spc = 0;
+ p++;
+ if (isspace(*p)){ /* their continuation line */
+ while (isspace(*p))
+ p++;
+ p--;
+ }
+ else{
+ outnl(2);
+ }
+ }
+ if (spc && *p != ';' && *p != '.' &&
+ *p != ',' && !isspace(*p)){ /* drop spaces before punct */
+ spc = 0;
+ outchar(' ');
+ }
+ if (isspace(*p))
+ spc = 1;
+ else
+ outchar(*p);
+ p++;
+ }
+ outnl(0);
+}
+
+long
+rogetnextoff(long fromoff)
+{
+ int i;
+ vlong l;
+ char *p;
+
+ Bseek(bdict, fromoff, 0);
+ Brdline(bdict, '\n');
+ while ((p = Brdline(bdict, '\n')) != nil){
+ l = Blinelen(bdict);
+ if (!isdigit(*p))
+ continue;
+ for (i = 0; i < l-4; i++)
+ if (strncmp(p+i, " -- ", 4) == 0)
+ return Boffset(bdict)-l;
+ }
+ return Boffset(bdict);
+}
+
+void
+rogetprintkey(void)
+{
+ Bprint(bout, "No pronunciation key.\n");
+}
diff --git a/src/cmd/dict/utils.c b/src/cmd/dict/utils.c
index 0920dc27..b5baab92 100644
--- a/src/cmd/dict/utils.c
+++ b/src/cmd/dict/utils.c
@@ -16,6 +16,9 @@ Dict dicts[] = {
{"thesaurus", "Collins Thesaurus",
"#9/dict/thesaurus", "#9/dict/thesindex",
thesnextoff, thesprintentry, thesprintkey},
+ {"roget", "Project Gutenberg Roget's Thesaurus",
+ "#9/dict/roget", "#9/dict/rogetindex",
+ rogetnextoff, rogetprintentry, rogetprintkey},
{"ce", "Gendai Chinese->English",
"#9/dict/world/sansdata/sandic24.dat",