Fixed a bug.(stroke type 2 - tail jump up)
[chise/kage.git] / kagedb / makealiasdb.pl
1 ###############################################################################
2 # makealiasdb.pl
3 #
4 #   create DB file for KAGE/cgi from alias.txt 
5 #   by Koichi Kamichi
6 ###############################################################################
7
8 if($#ARGV != 0 || !(-d $ARGV[0])){
9         print "Usage: perl makealiasdb.pl alias_dir\n";
10         exit;
11 }
12 $aliasdir = $ARGV[0];
13 $aliasdir =~ s/\/?$//; # remove the last slash
14
15 if(-e "aliasdb"){
16   print "Remove old aliasdb first.\n";
17         exit;
18 }
19
20 use Fcntl;
21 use BerkeleyDB;
22
23 tie %db, "BerkeleyDB::Hash", -Filename => "aliasdb", -Flags => DB_CREATE
24 or die "An error occured at ceating DB file.\n";
25 %db = ();
26
27 open(FH, "<$ARGV[0]/alias.txt");
28 @buffer = <FH>;
29
30 $counter = 1;
31
32 foreach(@buffer){
33         $_ =~ m/(.*?)\t(.*)\n/;
34         $key = $1;
35         $value = $2;
36         if($value ne ""){
37                 print "\rcreating ... [$counter] key : $key      ";
38                 $db{$key} = $value;
39                 $counter++;
40         }
41 }
42
43 close(FH);
44 untie(%db);
45 print "\n\rdone.\n";