From e9f7dec9e55a59ba61aacc89c764df9d8551b97d Mon Sep 17 00:00:00 2001 From: ache Date: Sat, 11 Sep 1999 18:21:16 +0000 Subject: localize it Submitted by: Alexey Zelkin --- gnu/usr.bin/man/makewhatis/makewhatis.1 | 4 ++ gnu/usr.bin/man/makewhatis/makewhatis.perl | 79 ++++++++++++++++++++++++------ 2 files changed, 68 insertions(+), 15 deletions(-) diff --git a/gnu/usr.bin/man/makewhatis/makewhatis.1 b/gnu/usr.bin/man/makewhatis/makewhatis.1 index ec9ae57..b715af4 100644 --- a/gnu/usr.bin/man/makewhatis/makewhatis.1 +++ b/gnu/usr.bin/man/makewhatis/makewhatis.1 @@ -34,6 +34,7 @@ .Op Fl a | Fl append .Op Fl h | Fl help .Op Fl i | Fl indent Ar column +.Op Fl L | Fl locale .Op Fl n | Fl name Ar name .Op Fl o | Fl outfile Ar file .Op Fl v | Fl verbose @@ -66,6 +67,9 @@ Print options and exit. .It Fl i , Fl indent Ar column Justify description strings to .Ar column Pq default 24 . +.It Fl L , Fl locale +Sense locale environment variables for possible localized man subdirectories +and process this entries only. .It Fl n , Fl name Ar name Use .Ar name diff --git a/gnu/usr.bin/man/makewhatis/makewhatis.perl b/gnu/usr.bin/man/makewhatis/makewhatis.perl index 7094c92..7b55005 100644 --- a/gnu/usr.bin/man/makewhatis/makewhatis.perl +++ b/gnu/usr.bin/man/makewhatis/makewhatis.perl @@ -32,8 +32,8 @@ sub usage { warn < $whatisdb\n" if $verbose; @@ -199,7 +196,7 @@ sub parse_dir { sub dir_redundant { local($dir) = @_; - local ($dev,$ino) = (stat($dir))[0..1]; + local($dev,$ino) = (stat($dir))[0..1]; if ($dir_redundant{"$dev.$ino"}) { warn "$dir is equal to: $dir_redundant{\"$dev.$ino\"}\n" if $verbose; @@ -332,12 +329,14 @@ sub manual { $extension = &ext($file); $name = &name($file); + $section_name = "NAME|Name|NAMN|BEZEICHNUNG|̾¾Î|îáú÷áîéå"; + local($source) = 0; local($list); while() { # ``man'' style pages # &&: it takes you only half the user time, regexp is slow!!! - if (/^\.SH/ && /^\.SH[ \t]+["]?(NAME|Name|NAMN|BEZEICHNUNG|̾¾Î)["]?/) { + if (/^\.SH/ && /^\.SH[ \t]+["]?($section_name)["]?/) { #while() { last unless /^\./ } # Skip #chop; $list = $_; while() { @@ -354,7 +353,7 @@ sub manual { } } &out($list); close F; return 1; - } elsif (/^\.Sh/ && /^\.Sh[ \t]+["]?(NAME|Name|BEZEICHNUNG|̾¾Î)["]?/) { + } elsif (/^\.Sh/ && /^\.Sh[ \t]+["]?($section_name)["]?/) { # ``doc'' style pages local($flag) = 0; while() { @@ -425,10 +424,20 @@ sub stripdir { sub variables { $verbose = 0; # Verbose - $indent = 24; # indent for description + $indent = 24; # Indent for description $outfile = 0; # Don't write to ./whatis $whatis_name = "whatis"; # Default name for DB $append = 0; # Don't delete old entries + $locale = 0; # Build DB only for localized man directories + + # choose localized man direcotries suffixs. If $LC_CTYPE is set, then + # its value will be used as suffix, otherwise $LANG value (if set) + $local_suffix = ""; + if ($ENV{'LC_CTYPE'}) { + $local_suffix = $ENV{'LC_CTYPE'}; + } elsif ($ENV{'LANG'}) { + $local_suffix = $ENV{'LANG'} + } # if no argument for directories given @defaultmanpath = ( '/usr/share/man' ); @@ -472,8 +481,11 @@ sub parse { elsif (/^--?(f|format|i|indent)$/) { $i = $argv[0]; shift @argv } elsif (/^--?(n|name)$/) { $whatis_name = $argv[0];shift @argv } elsif (/^--?(a|append)$/) { $append = 1 } + elsif (/^--?(L|locale)$/) { $locale = 1 } else { &usage } } + warn "Localized man directory suffix is ``$local_suffix''\n" + if $verbose && $locale; if ($i ne "") { if ($i =~ /^[0-9]+$/) { @@ -489,6 +501,31 @@ sub parse { warn "Missing directories\n"; &usage; } +# Process man directory +sub process_dir { + local($dir) = @_; + + $dir = &stripdir($dir); + &dir_redundant($dir) && &parse_dir($dir); +} + +# Process man directory and store output to file +sub process_dir_to_file { + local($dir) = @_; + + $dir = &stripdir($dir); + &dir_redundant($dir) && + &close_output(&open_output($dir) && &parse_dir($dir)); +} + +# convert locale name to short notation (ru_RU.KOI8-R -> ru.KOI8-R) +sub short_locale_name { + local($lname) = @_; + + $lname =~ s|_[A-Z][A-Z]||; + warn "short locale name is $lname\n" if $verbose && $locale; + return $lname; +} ## ## Main @@ -498,20 +535,32 @@ sub parse { # allow colons in dir: ``makewhatis dir1:dir2:dir3'' @argv = &parse(split(/[: ]/, join($", @ARGV))); # " - if ($outfile) { if(&open_output($outfile)){ foreach $dir (@argv) { - $dir = &stripdir($dir); - &dir_redundant($dir) && &parse_dir($dir); + # "Local only" flag set ? Yes ... + if ($locale) { + if ($local_suffix ne "") { + &process_dir($dir.'/'.$local_suffix); + &process_dir($dir.'/'.&short_locale_name($local_suffix)); + } + } else { + &process_dir($dir); + } } } &close_output(1); } else { foreach $dir (@argv) { - $dir = &stripdir($dir); - &dir_redundant($dir) && - &close_output(&open_output($dir) && &parse_dir($dir)); + # "Local only" flag set ? Yes ... + if ($locale) { + if ($local_suffix ne "") { + &process_dir_to_file($dir.'/'.$local_suffix); + &process_dir_to_file($dir.'/'.&short_locale_name($local_suffix)); + } + } else { + &process_dir_to_file($dir); + } } } -- cgit v1.1