aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/dict
diff options
context:
space:
mode:
authorRuss Cox <rsc@swtch.com>2007-08-22 09:00:26 -0400
committerRuss Cox <rsc@swtch.com>2007-08-22 09:00:26 -0400
commitebda53e16b473c6ad8df070edd6f58e2e1e10994 (patch)
tree97b3ef1ba2cd5bb632487a3f42322da11d3a13f9 /src/cmd/dict
parent841d71b5c6be4851572a60c5a9f9dd239ea69e56 (diff)
parent841d71b5c6be4851572a60c5a9f9dd239ea69e56 (diff)
downloadplan9port-ebda53e16b473c6ad8df070edd6f58e2e1e10994.tar.gz
plan9port-ebda53e16b473c6ad8df070edd6f58e2e1e10994.tar.bz2
plan9port-ebda53e16b473c6ad8df070edd6f58e2e1e10994.zip
merge
Diffstat (limited to 'src/cmd/dict')
-rw-r--r--src/cmd/dict/dict.c29
-rw-r--r--src/cmd/dict/dict.h1
-rw-r--r--src/cmd/dict/robert.c10
-rw-r--r--src/cmd/dict/utils.c122
4 files changed, 92 insertions, 70 deletions
diff --git a/src/cmd/dict/dict.c b/src/cmd/dict/dict.c
index 9e196b11..d9cdca62 100644
--- a/src/cmd/dict/dict.c
+++ b/src/cmd/dict/dict.c
@@ -68,7 +68,7 @@ main(int argc, char **argv)
dict = 0;
for(i=0; dicts[i].name; i++){
- if(access(unsharp(dicts[i].path), 0)>=0 && access(unsharp(dicts[i].indexpath), 0)>=0){
+ if(access(dictfile(dicts[i].path), 0)>=0 && access(dictfile(dicts[i].indexpath), 0)>=0){
dict = &dicts[i];
break;
}
@@ -119,8 +119,8 @@ main(int argc, char **argv)
line = malloc(strlen(p)+5);
sprint(line, "/%s/P\n", p);
}
- dict->path = unsharp(dict->path);
- dict->indexpath = unsharp(dict->indexpath);
+ dict->path = dictfile(dict->path);
+ dict->indexpath = dictfile(dict->indexpath);
bdict = Bopen(dict->path, OREAD);
if(!bdict) {
err("can't open dictionary %s", dict->path);
@@ -171,7 +171,7 @@ usage(void)
Bprint(bout, "dictionaries (brackets mark dictionaries not present on this system):\n");
for(i = 0; dicts[i].name; i++){
a = b = "";
- if(access(unsharp(dicts[i].path), 0)<0 || access(unsharp(dicts[i].indexpath), 0)<0){
+ if(access(dictfile(dicts[i].path), 0)<0 || access(dictfile(dicts[i].indexpath), 0)<0){
a = "[";
b = "]";
}
@@ -675,3 +675,24 @@ setdotprev(void)
dot->n = 1;
dot->cur = 0;
}
+
+/*
+ * find the specified file and return a path.
+ * default location is #9/dict, but can be
+ * in $dictdir instead.
+ */
+char*
+dictfile(char *f)
+{
+ static char *dict;
+ static int did;
+
+ if(!did){
+ dict = getenv("dictpath");
+ did = 1;
+ }
+
+ if(dict)
+ return smprint("%s/%s", dict, f);
+ return unsharp(smprint("#9/dict/%s", f));
+}
diff --git a/src/cmd/dict/dict.h b/src/cmd/dict/dict.h
index bf7a80c3..43597674 100644
--- a/src/cmd/dict/dict.h
+++ b/src/cmd/dict/dict.h
@@ -115,6 +115,7 @@ void outnl(int);
void outpiece(char *, char *);
void runescpy(Rune*, Rune*);
long runetol(Rune*);
+char *dictfile(char*);
long oednextoff(long);
void oedprintentry(Entry, int);
diff --git a/src/cmd/dict/robert.c b/src/cmd/dict/robert.c
index 877c3b13..96e71e34 100644
--- a/src/cmd/dict/robert.c
+++ b/src/cmd/dict/robert.c
@@ -84,10 +84,10 @@ initsubtab(void)
#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[] = "#9/dict/robert/cits.rob";
-static char dfile[] = "#9/dict/robert/defs.rob";
-static char efile[] = "#9/dict/robert/etym.rob";
-static char kfile[] = "#9/dict/robert/_phon";
+static char cfile[] = "robert/cits.rob";
+static char dfile[] = "robert/defs.rob";
+static char efile[] = "robert/etym.rob";
+static char kfile[] = "robert/_phon";
static Biobuf * cb;
static Biobuf * db;
@@ -316,7 +316,7 @@ Bouvrir(char *fichier)
{
Biobuf *db;
- fichier = unsharp(fichier);
+ fichier = dictfile(fichier);
db = Bopen(fichier, OREAD);
if(db == 0){
fprint(2, "%s: impossible d'ouvrir %s: %r\n", argv0, fichier);
diff --git a/src/cmd/dict/utils.c b/src/cmd/dict/utils.c
index d7033d37..d60d0bb9 100644
--- a/src/cmd/dict/utils.c
+++ b/src/cmd/dict/utils.c
@@ -5,163 +5,163 @@
Dict dicts[] = {
{"oed", "Oxford English Dictionary, 2nd Ed.",
- "#9/dict/oed2", "#9/dict/oed2index",
+ "oed2", "oed2index",
oednextoff, oedprintentry, oedprintkey},
{"ahd", "American Heritage Dictionary, 2nd College Ed.",
- "#9/dict/ahd/DICT.DB", "#9/dict/ahd/index",
+ "ahd/DICT.DB", "ahd/index",
ahdnextoff, ahdprintentry, ahdprintkey},
{"pgw", "Project Gutenberg Webster Dictionary",
- "#9/dict/pgw", "#9/dict/pgwindex",
+ "pgw", "pgwindex",
pgwnextoff, pgwprintentry, pgwprintkey},
{"thesaurus", "Collins Thesaurus",
- "#9/dict/thesaurus", "#9/dict/thesindex",
+ "thesaurus", "thesindex",
thesnextoff, thesprintentry, thesprintkey},
{"roget", "Project Gutenberg Roget's Thesaurus",
- "#9/dict/roget", "#9/dict/rogetindex",
+ "roget", "rogetindex",
rogetnextoff, rogetprintentry, rogetprintkey},
{"ce", "Gendai Chinese->English",
- "#9/dict/world/sansdata/sandic24.dat",
- "#9/dict/world/sansdata/ceindex",
+ "world/sansdata/sandic24.dat",
+ "world/sansdata/ceindex",
worldnextoff, worldprintentry, worldprintkey},
{"ceh", "Gendai Chinese->English (Hanzi index)",
- "#9/dict/world/sansdata/sandic24.dat",
- "#9/dict/world/sansdata/cehindex",
+ "world/sansdata/sandic24.dat",
+ "world/sansdata/cehindex",
worldnextoff, worldprintentry, worldprintkey},
{"ec", "Gendai English->Chinese",
- "#9/dict/world/sansdata/sandic24.dat",
- "#9/dict/world/sansdata/ecindex",
+ "world/sansdata/sandic24.dat",
+ "world/sansdata/ecindex",
worldnextoff, worldprintentry, worldprintkey},
{"dae", "Gyldendal Danish->English",
- "#9/dict/world/gylddata/sandic30.dat",
- "#9/dict/world/gylddata/daeindex",
+ "world/gylddata/sandic30.dat",
+ "world/gylddata/daeindex",
worldnextoff, worldprintentry, worldprintkey},
{"eda", "Gyldendal English->Danish",
- "#9/dict/world/gylddata/sandic29.dat",
- "#9/dict/world/gylddata/edaindex",
+ "world/gylddata/sandic29.dat",
+ "world/gylddata/edaindex",
worldnextoff, worldprintentry, worldprintkey},
{"due", "Wolters-Noordhoff Dutch->English",
- "#9/dict/world/woltdata/sandic07.dat",
- "#9/dict/world/woltdata/deindex",
+ "world/woltdata/sandic07.dat",
+ "world/woltdata/deindex",
worldnextoff, worldprintentry, worldprintkey},
{"edu", "Wolters-Noordhoff English->Dutch",
- "#9/dict/world/woltdata/sandic06.dat",
- "#9/dict/world/woltdata/edindex",
+ "world/woltdata/sandic06.dat",
+ "world/woltdata/edindex",
worldnextoff, worldprintentry, worldprintkey},
{"fie", "WSOY Finnish->English",
- "#9/dict/world/werndata/sandic32.dat",
- "#9/dict/world/werndata/fieindex",
+ "world/werndata/sandic32.dat",
+ "world/werndata/fieindex",
worldnextoff, worldprintentry, worldprintkey},
{"efi", "WSOY English->Finnish",
- "#9/dict/world/werndata/sandic31.dat",
- "#9/dict/world/werndata/efiindex",
+ "world/werndata/sandic31.dat",
+ "world/werndata/efiindex",
worldnextoff, worldprintentry, worldprintkey},
{"fe", "Collins French->English",
- "#9/dict/fe", "#9/dict/feindex",
+ "fe", "feindex",
pcollnextoff, pcollprintentry, pcollprintkey},
{"ef", "Collins English->French",
- "#9/dict/ef", "#9/dict/efindex",
+ "ef", "efindex",
pcollnextoff, pcollprintentry, pcollprintkey},
{"ge", "Collins German->English",
- "#9/dict/ge", "#9/dict/geindex",
+ "ge", "geindex",
pcollgnextoff, pcollgprintentry, pcollgprintkey},
{"eg", "Collins English->German",
- "#9/dict/eg", "#9/dict/egindex",
+ "eg", "egindex",
pcollgnextoff, pcollgprintentry, pcollgprintkey},
{"ie", "Collins Italian->English",
- "#9/dict/ie", "#9/dict/ieindex",
+ "ie", "ieindex",
pcollnextoff, pcollprintentry, pcollprintkey},
{"ei", "Collins English->Italian",
- "#9/dict/ei", "#9/dict/eiindex",
+ "ei", "eiindex",
pcollnextoff, pcollprintentry, pcollprintkey},
{"je", "Sanshusha Japanese->English",
- "#9/dict/world/sansdata/sandic18.dat",
- "#9/dict/world/sansdata/jeindex",
+ "world/sansdata/sandic18.dat",
+ "world/sansdata/jeindex",
worldnextoff, worldprintentry, worldprintkey},
{"jek", "Sanshusha Japanese->English (Kanji index)",
- "#9/dict/world/sansdata/sandic18.dat",
- "#9/dict/world/sansdata/jekindex",
+ "world/sansdata/sandic18.dat",
+ "world/sansdata/jekindex",
worldnextoff, worldprintentry, worldprintkey},
{"ej", "Sanshusha English->Japanese",
- "#9/dict/world/sansdata/sandic18.dat",
- "#9/dict/world/sansdata/ejindex",
+ "world/sansdata/sandic18.dat",
+ "world/sansdata/ejindex",
worldnextoff, worldprintentry, worldprintkey},
{"tjeg", "Sanshusha technical Japanese->English,German",
- "#9/dict/world/sansdata/sandic16.dat",
- "#9/dict/world/sansdata/tjegindex",
+ "world/sansdata/sandic16.dat",
+ "world/sansdata/tjegindex",
worldnextoff, worldprintentry, worldprintkey},
{"tjegk", "Sanshusha technical Japanese->English,German (Kanji index)",
- "#9/dict/world/sansdata/sandic16.dat",
- "#9/dict/world/sansdata/tjegkindex",
+ "world/sansdata/sandic16.dat",
+ "world/sansdata/tjegkindex",
worldnextoff, worldprintentry, worldprintkey},
{"tegj", "Sanshusha technical English->German,Japanese",
- "#9/dict/world/sansdata/sandic16.dat",
- "#9/dict/world/sansdata/tegjindex",
+ "world/sansdata/sandic16.dat",
+ "world/sansdata/tegjindex",
worldnextoff, worldprintentry, worldprintkey},
{"tgje", "Sanshusha technical German->Japanese,English",
- "#9/dict/world/sansdata/sandic16.dat",
- "#9/dict/world/sansdata/tgjeindex",
+ "world/sansdata/sandic16.dat",
+ "world/sansdata/tgjeindex",
worldnextoff, worldprintentry, worldprintkey},
{"ne", "Kunnskapforlaget Norwegian->English",
- "#9/dict/world/kunndata/sandic28.dat",
- "#9/dict/world/kunndata/neindex",
+ "world/kunndata/sandic28.dat",
+ "world/kunndata/neindex",
worldnextoff, worldprintentry, worldprintkey},
{"en", "Kunnskapforlaget English->Norwegian",
- "#9/dict/world/kunndata/sandic27.dat",
- "#9/dict/world/kunndata/enindex",
+ "world/kunndata/sandic27.dat",
+ "world/kunndata/enindex",
worldnextoff, worldprintentry, worldprintkey},
{"re", "Leon Ungier Russian->English",
- "#9/dict/re", "#9/dict/reindex",
+ "re", "reindex",
simplenextoff, simpleprintentry, simpleprintkey},
{"er", "Leon Ungier English->Russian",
- "#9/dict/re", "#9/dict/erindex",
+ "re", "erindex",
simplenextoff, simpleprintentry, simpleprintkey},
{"se", "Collins Spanish->English",
- "#9/dict/se", "#9/dict/seindex",
+ "se", "seindex",
pcollnextoff, pcollprintentry, pcollprintkey},
{"es", "Collins English->Spanish",
- "#9/dict/es", "#9/dict/esindex",
+ "es", "esindex",
pcollnextoff, pcollprintentry, pcollprintkey},
{"swe", "Esselte Studium Swedish->English",
- "#9/dict/world/essedata/sandic34.dat",
- "#9/dict/world/essedata/sweindex",
+ "world/essedata/sandic34.dat",
+ "world/essedata/sweindex",
worldnextoff, worldprintentry, worldprintkey},
{"esw", "Esselte Studium English->Swedish",
- "#9/dict/world/essedata/sandic33.dat",
- "#9/dict/world/essedata/eswindex",
+ "world/essedata/sandic33.dat",
+ "world/essedata/eswindex",
worldnextoff, worldprintentry, worldprintkey},
{"movie", "Movies -- by title",
- "movie/data", "#9/dict/movtindex",
+ "movie/data", "movtindex",
movienextoff, movieprintentry, movieprintkey},
{"moviea", "Movies -- by actor",
- "movie/data", "#9/dict/movaindex",
+ "movie/data", "movaindex",
movienextoff, movieprintentry, movieprintkey},
{"movied", "Movies -- by director",
- "movie/data", "#9/dict/movdindex",
+ "movie/data", "movdindex",
movienextoff, movieprintentry, movieprintkey},
{"slang", "English Slang",
- "#9/dict/slang", "#9/dict/slangindex",
+ "slang", "slangindex",
slangnextoff, slangprintentry, slangprintkey},
{"robert", "Robert Électronique",
- "#9/dict/robert/_pointers", "#9/dict/robert/_index",
+ "robert/_pointers", "robert/_index",
robertnextoff, robertindexentry, robertprintkey},
{"robertv", "Robert Électronique - formes des verbes",
- "#9/dict/robert/flex.rob", "#9/dict/robert/_flexindex",
+ "robert/flex.rob", "robert/_flexindex",
robertnextflex, robertflexentry, robertprintkey},
{0, 0, 0, 0, 0}