aboutsummaryrefslogtreecommitdiff
path: root/gnu/usr.bin/man/makewhatis/makewhatis.perl
diff options
context:
space:
mode:
authorAndrey A. Chernov <ache@FreeBSD.org>1999-09-11 18:21:16 +0000
committerAndrey A. Chernov <ache@FreeBSD.org>1999-09-11 18:21:16 +0000
commit198f193685b643e8aee53c3200ecc2cc57a43f6c (patch)
treec800e96af4c6945b317141c48c47311c6d0410cc /gnu/usr.bin/man/makewhatis/makewhatis.perl
parent04d5308a6b5a55134100a6f46837bf08b410ce84 (diff)
downloadsrc-198f193685b643e8aee53c3200ecc2cc57a43f6c.tar.gz
src-198f193685b643e8aee53c3200ecc2cc57a43f6c.zip
localize it
Submitted by: Alexey Zelkin <phantom@crimea.edu>
Notes
Notes: svn path=/head/; revision=51170
Diffstat (limited to 'gnu/usr.bin/man/makewhatis/makewhatis.perl')
-rw-r--r--gnu/usr.bin/man/makewhatis/makewhatis.perl79
1 files changed, 64 insertions, 15 deletions
diff --git a/gnu/usr.bin/man/makewhatis/makewhatis.perl b/gnu/usr.bin/man/makewhatis/makewhatis.perl
index 7094c92b6cde..7b55005f4cfd 100644
--- a/gnu/usr.bin/man/makewhatis/makewhatis.perl
+++ b/gnu/usr.bin/man/makewhatis/makewhatis.perl
@@ -32,8 +32,8 @@
sub usage {
warn <<EOF;
-usage: makewhatis [-a|-append ] [-h|-help] [-i|-indent column]
- [-n|-name name] [-o|-outfile file] [-v|-verbose]
+usage: makewhatis [-a|-append] [-h|-help] [-i|-indent column] [-L|-locale]
+ [-n|-name name] [-o|-outfile file] [-v|-verbose]
[directories ...]
EOF
exit 1;
@@ -53,11 +53,9 @@ sub open_output {
}
$tmp = $whatisdb; # for signals
-
# Array of all entries
@a = ();
-
# Append mode
if ($append) {
local($file) = $whatisdb;
@@ -97,7 +95,6 @@ sub close_output {
$w =~ s/\.tmp$//;
if ($success) { # success
-
# uniq
warn "\n" if $verbose && $pointflag;
warn "sort -u > $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(<F>) {
# ``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(<F>) { last unless /^\./ } # Skip
#chop; $list = $_;
while(<F>) {
@@ -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(<F>) {
@@ -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);
+ }
}
}