Namazu-devel-ja(旧)


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: mknmzrcの読み込み制限



臼田です。

Tadamasa Teranishi wrote:

> Yukio USUDA wrote:
> > 
> > parse_optionの実行時点を変えることによる不具合は
> > 整理して解決しないといけませんが、結構むずかしそうですね。
> 
> そう思います。
> archive 系フィルタでコマンドラインオプションが追加できる機能も
> 面白いのですが、それなりに問題になりますし。
> (usage に追加するのは大変ですし...。)
> 

parse_option周りをいじって --debug オプションをつけたときに
mknmzrcファイルが読み込まれている様子がわかるようにしてみました。
あわせて --norc オプションもつけました。

HEADへのdiffを添付しています。

archive系フィルタでコマンドラインオプションを追加できる機能は、
usageへの追加のほかにも課題がありそうです。
今の実行順序では
$conf::FILTERDIRの形で読み込み先を指定することは不可能?
なので今の形と違う実装方法を考えたいです。

臼田幸生
Index: scripts/mknmz.in
===================================================================
RCS file: /storage/cvsroot/namazu/scripts/mknmz.in,v
retrieving revision 1.133
diff -u -r1.133 mknmz.in
--- scripts/mknmz.in	7 Mar 2004 09:47:17 -0000	1.133
+++ scripts/mknmz.in	7 Mar 2004 13:48:08 -0000
@@ -86,11 +86,25 @@
     util::set_lang();
     textdomain('namazu', $util::LANG_MSG);
 
-    load_rcfiles() if !(defined $ENV{'MKNMZNORC'});
-    load_modules();
     load_archivemodules();
-    my ($output_dir, @targets) = parse_options();
-    my ($docid_base, $total_files_num) = prep($output_dir, @targets);
+
+    my ($output_dir, $targetsref, $wakati, $optconfref, $conffile, $norc, $info) = parse_options();
+    load_rcfiles() if (!(defined $ENV{'MKNMZNORC'}) && !(defined $norc));
+    load_rcfile($conffile) if (defined $conffile);
+
+    load_modules();
+    load_filtermodules(); # to make effect $opt_config, $index_lang.
+    load_schememodules();
+
+    # $optcontref{$key} overwrites rcfile's parameter.
+    foreach my $key (keys %$optconfref){
+	if (defined ($$optconfref{$key})) { 
+	     ${*{$conf::{$key}}{SCALAR}} = $$optconfref{$key};
+	}
+    }
+    $conf::WAKATI = ${*{$conf::{$wakati}}{SCALAR}} if (defined $wakati);
+    show_info($info);
+    my ($docid_base, $total_files_num) = prep($output_dir, @$targetsref);
 
     my $swap = 1;
     my $docid_count = 0;
@@ -360,17 +374,13 @@
     # workaround for test suites.
     unshift @INC, $ENV{'top_builddir'} . "/pl" if defined $ENV{'top_builddir'};
 
+    require "var.pl" || die "unable to require \"var.pl\"\n";
     require "conf.pl" || die "unable to require \"conf.pl\"\n";
     require "util.pl" || die "unable to require \"util.pl\"\n";
     require "gettext.pl" || die "unable to require \"gettext.pl\"\n";
 }
 
-sub postload_modules () {
-#    require "htmlsplit.pl" || die "unable to require \"htmlsplit.pl\"\n";
-}
-
 sub load_modules () {
-    require "var.pl" || die "unable to require \"var.pl\"\n";
     require "usage.pl" || die "unable to require \"usage.pl\"\n";
     require "codeconv.pl" || die "unable to require \"codeconv.pl\"\n";
     require "wakati.pl" || die "unable to require \"wakati.pl\"\n";
@@ -1160,6 +1170,9 @@
     my $index_lang = undef;
 
     my %opt_conf;
+    my $wakati = undef;
+    my $info = undef;
+    my $norc = undef;
 
 #    Getopt::Long::Configure('bundling');
     Getopt::Long::config('bundling');
@@ -1204,6 +1217,7 @@
 	       'x|no-heading-summary'=> \$var::Opt{'noheadabst'},
 	       'z|check-filesize'    => \$var::Opt{'checkfilesize'},
 	       'decode-base64'       => \$var::Opt{'decodebase64'},
+	       'norc'                => \$norc,
 	       );
     my $mediatype;
     foreach $mediatype (keys %var::ARCHIVE_REQUIRE_ACTIONS) {
@@ -1226,36 +1240,17 @@
 	open(STDOUT, ">$devnull") || die "$devnull: $!";
     }
 
-    if ($opt_config) {
-	load_rcfile($ConfigFile = $opt_config);
-    }
-    foreach my $key (keys %opt_conf){
-	if (defined ($opt_conf{$key})) { 
-	     ${*{$conf::{$key}}{SCALAR}} = $opt_conf{$key};
-	}
-    }
-
     if ($index_lang) {
 	$util::LANG = $index_lang;
       util::dprint("Override indexing language: $util::LANG\n");
     }
-    load_filtermodules(); # to make effect $opt_config, $index_lang.
-    load_schememodules();
-    postload_modules();
 
     if ($opt_help) {
-	show_usage();
-	exit 1;
-    }
-
-    if ($opt_version) {
-	show_version();
-	exit 1;
-    }
-
-    if ($opt_show_config) {
-	show_config();
-	exit 1;
+	$info = 'usage';
+    }elsif ($opt_version) {
+	$info = 'version';
+    }elsif ($opt_show_config) {
+	$info = 'config';
     }
 
     if (defined $update_index) {
@@ -1275,10 +1270,19 @@
 	chdir $cwd;
 	util::dprint(_("Inherited cwd: ")."$cwd\n");
 
-	($output_dir, @targets) = parse_options();
-	$output_dir = $update_index;
-	$var::NMZ{'status'} = $orig_status;  # See also change_filenames()
-	return ($output_dir, @targets);
+        {
+	    my ($output_dir, $targetsref, $wakati, $optconfref, $conffile, $norc, $info) = parse_options();
+	    load_rcfile($conffile) if (defined $conffile);
+	    foreach my $key (keys %$optconfref){
+		if (defined ($$optconfref{$key})) { 
+		     ${*{$conf::{$key}}{SCALAR}} = $$optconfref{$key};
+		}
+	    }
+	    $conf::WAKATI = ${*{$conf::{$wakati}}{SCALAR}} if (defined $wakati);
+	    $output_dir = $update_index;
+	    $var::NMZ{'status'} = $orig_status;  # See also change_filenames()
+	    return ($output_dir, $targetsref, $wakati, $optconfref, $conffile, $info);
+        }
     }
 
     if ($opt_mailnews) {
@@ -1288,18 +1292,18 @@
 	$MediaType = 'text/html; x-type=mhonarc';
     }
     if ($opt_all) {
-	$conf::ALLOW_FILE = ".*";
+	$opt_conf{'ALLOW_FILE'} = ".*";
     }
     if ($opt_chasen) {
-	$conf::WAKATI = $conf::CHASEN;
+	$wakati = 'CHASEN';
 	$var::Opt{'noun'} = 0;
     }
     if ($opt_chasen_noun) {
-	$conf::WAKATI = $conf::CHASEN_NOUN;
+	$wakati = 'CHASEN_NOUN';
 	$var::Opt{'noun'} = 1;
     }
     if ($opt_kakasi) {
-	$conf::WAKATI = $conf::KAKASI;
+	$wakati = 'KAKASI';
 	$var::Opt{'noun'} = 0;
     }
     if ($include_file) {
@@ -1331,7 +1335,7 @@
 	util::dprint(_("Replace: ")."$orig -> $_\n");
     }
 
-    if (@ARGV == 0 && $targets_loaded == 0) {
+    if (@ARGV == 0 && $targets_loaded == 0 && !(defined $info)) {
 	show_mini_usage();
 	exit 1;
     }
@@ -1356,7 +1360,20 @@
     # unshift @ARGV, splice(@argv, 0, @argv - @ARGV);
     @ARGV = @argv;
 
-    return ($output_dir, @targets);
+    return ($output_dir, \@targets, $wakati, \%opt_conf, $opt_config, $norc, $info);
+}
+
+sub show_info ($) {
+    my ($info) = @_;
+    return if !(defined $info);
+    if ($info eq 'usage') {
+	show_usage();
+    }elsif ($info eq 'config') {
+	show_config();
+    }elsif ($info eq 'version') {
+	show_version();
+    }
+    exit 1;
 }
 
 sub show_config () {
@@ -2618,8 +2635,7 @@
 #
 muda($conf::ON_MEMORY_MAX,
      $conf::WORD_LENG_MAX, $conf::TEXT_SIZE_MAX,
-     $conf::DENY_FILE, $var::INTSIZE,
-     $conf::CHASEN_NOUN, $conf::CHASEN,
+     $conf::ALLOW_FILE, $conf::DENY_FILE, $var::INTSIZE,
      $conf::KAKASI, $var::Opt{'okurigana'},
      $var::Opt{'hiragana'}, $conf::DIRECTORY_INDEX,
      $usage::USAGE, $var::Opt{'noheadabst'}, $usage::VERSION_INFO,