From: Koichi KAMICHI Date: Thu, 16 Dec 2004 06:51:32 +0000 (+0000) Subject: Add alias-db. X-Git-Url: http://git.chise.org/gitweb/?a=commitdiff_plain;h=945249589fdec99f45902027bc4ca0a82acd628c;p=chise%2Fkage.git Add alias-db. --- diff --git a/kagecgi/kagecgi.h b/kagecgi/kagecgi.h index 25fb575..26836e6 100755 --- a/kagecgi/kagecgi.h +++ b/kagecgi/kagecgi.h @@ -13,6 +13,7 @@ #define pngFilePath "/var/www/v0.4/" #define partsdbFileName "/var/www/kagedb/partsdb" #define idsdbFileName "/var/www/kagedb/idsdb" +#define aliasdbFileName "/var/www/kagedb/aliasdb" #define kBaseline 188 #define pngWidth 200 @@ -25,6 +26,7 @@ DB *kPartsdbDatabase; DB *kIdsdbDatabase; +DB *kAliasdbDatabase; FILE *debug; diff --git a/kagecgi/kagedb.c b/kagecgi/kagedb.c index e1bfa21..cebb14d 100755 --- a/kagecgi/kagedb.c +++ b/kagecgi/kagedb.c @@ -10,12 +10,15 @@ int initDB(){ kPartsdbDatabase->open(kPartsdbDatabase, NULL, partsdbFileName, NULL, DB_HASH, DB_RDONLY, 0644); db_create(&kIdsdbDatabase, NULL, 0); kIdsdbDatabase->open(kIdsdbDatabase, NULL, idsdbFileName, NULL, DB_HASH, DB_RDONLY, 0644); + db_create(&kAliasdbDatabase, NULL, 0); + kAliasdbDatabase->open(kAliasdbDatabase, NULL, aliasdbFileName, NULL, DB_HASH, DB_RDONLY, 0644); return 0; } int closeDB(){ kPartsdbDatabase->close(kPartsdbDatabase, 0); kIdsdbDatabase->close(kIdsdbDatabase, 0); + kAliasdbDatabase->close(kAliasdbDatabase, 0); return 0; } @@ -77,6 +80,22 @@ void searchAliasData(const KGString *in, KGString *out){ dbkey.data = temp->str; dbkey.size = temp->len; kg_string_set_size(out, 0); + kAliasdbDatabase->get(kAliasdbDatabase, NULL, &dbkey, &dbdata, 0); + if(dbdata.size != 0){ + buf = (char *)malloc(dbdata.size + 1); + strncpy(buf, dbdata.data, dbdata.size); + buf[dbdata.size] = '\0'; + //fprintf(stderr,"%s\n",buf); + kg_string_append(out, buf); + free(buf); + return; + } + + memset(&dbkey,0,sizeof(DBT)); + memset(&dbdata,0,sizeof(DBT)); + dbkey.data = temp->str; + dbkey.size = temp->len; + kg_string_set_size(out, 0); kIdsdbDatabase->get(kIdsdbDatabase, NULL, &dbkey, &dbdata, 0); if(dbdata.size != 0){ buf = (char *)malloc(dbdata.size + 1); diff --git a/kagedb/alias.txt b/kagedb/alias.txt new file mode 100644 index 0000000..7a599cf --- /dev/null +++ b/kagedb/alias.txt @@ -0,0 +1 @@ +u2ebc u6708-9903 diff --git a/kagedb/makealiasdb.pl b/kagedb/makealiasdb.pl new file mode 100644 index 0000000..3f895cc --- /dev/null +++ b/kagedb/makealiasdb.pl @@ -0,0 +1,45 @@ +############################################################################### +# makealiasdb.pl +# +# create DB file for KAGE/cgi from alias.txt +# by Koichi Kamichi +############################################################################### + +if($#ARGV != 0 || !(-d $ARGV[0])){ + print "Usage: perl makealiasdb.pl alias_dir\n"; + exit; +} +$aliasdir = $ARGV[0]; +$aliasdir =~ s/\/?$//; # remove the last slash + +if(-e "aliasdb"){ + print "Remove old aliasdb first.\n"; + exit; +} + +use Fcntl; +use BerkeleyDB; + +tie %db, "BerkeleyDB::Hash", -Filename => "aliasdb", -Flags => DB_CREATE +or die "An error occured at ceating DB file.\n"; +%db = (); + +open(FH, "<$ARGV[0]/alias.txt"); +@buffer = ; + +$counter = 1; + +foreach(@buffer){ + $_ =~ m/(.*?)\t(.*)\n/; + $key = $1; + $value = $2; + if($value ne ""){ + print "\rcreating ... [$counter] key : $key "; + $db{$key} = $value; + $counter++; + } +} + +close(FH); +untie(%db); +print "\n\rdone.\n"; diff --git a/kagedb/readme.en b/kagedb/readme.en index 178fa87..68761db 100644 --- a/kagedb/readme.en +++ b/kagedb/readme.en @@ -9,6 +9,14 @@ Get makepartsdb.pl and parts.txt, please type like follows. Then ''partsdb'' is to be created. +* aliasdb : Kanji parts alias database for KAGE/cgi + +Get makealiasdb.pl and alias.txt, please type like follows. + + % perl makealiasdb.pl . + +Then ''aliasdb'' is to be created. + * idsdb : Kanji alias IDS database for KAGE/cgi Get makeidsdb.pl and CHISE/IDS data, please type like follows.