File: install-manpage

package info (click to toggle)
man-db 2.3.10-65
  • links: PTS
  • area: main
  • in suites: hamm
  • size: 2,440 kB
  • ctags: 1,826
  • sloc: ansic: 12,508; lex: 925; makefile: 642; sh: 328; sed: 93; perl: 62
file content (102 lines) | stat: -rw-r--r-- 3,402 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/usr/bin/perl   -d

# install-manpage - (c) 1998 by Fabrizio Polacco <fpolacco@debian.org>
# This program is under GPL License, see /usr/doc/copyright/GPL .
#
# this utility "installs" (copies) a manpage into his "right[TM]"
# location, using the "right[TM]" name, depending on its content
# (mainly the .TH and the .SH NAME sections).
# Allowed modifiers are --local, --debian for the location,
# -section <sect> and --name <name> for the name.
# option --link creates symlinks for alternative names and
# --gzip compresses the manpage.
# --debian implies --link and --gzip .
#
#

die "work in progress: don't use!";

my $version='0.1';

my $usage = "Usage:\t"."install-manpage [options] <file> ...\n".
"    Installs <file> into its correct location, \n".
"    with its correct name, depending on the  \n".
"    content of the .TH and .SH NAME sections. \n".
"    '-' as <file> means stdin; both are filtered to text.\n".
"options:\n".
"    --local		installs in /usr/local instead of /usr;\n".
"    --debian [<path>]	installs in ./debian/<path>/usr\n".
"			<path> is optional and defaults to 'tmp'\n".
"			implies --link and --gzip .\n".
"    --section <sect>	uses <sect> in name. (deprecated)\n".
"    --name <name>	uses <name> in name. (deprecated)\n".
"    --LANG <lang>	forces installation in <lang> subdirectory.\n".
"    --[no]link		creates one symlink for each name in .SH NAME.\n".
"    --[no]gzip		compresses the page using gzip -9 .\n".
"    --help --VERSION --quiet --verbose\n";

use Getopt::Long;
$Getopt::Long::ignorecase = 0;	# distinct Upper 

local $opt_help;	# used only once

die $usage if !		# in case of error
&GetOptions 
	(''		# -	<stdin>
	,'local'	# -l	--local
	,'debian:s'	# -d	--debian [<path>|"tmp"]
	,'section=s'	# -s	--section <string>
	,'name=s'	# -n	--name <string>
	,'LANG=s'	# -L	--LANG <string>
	,'link!'	# -l	--link --nolink
	,'gzip!'	# -g	--gzip --nogzip
	#
	,'help'		# -h		--help
	,'VERSION'	# -V		--VERSION
	,'quiet'	# -q		--quiet
	,'verbose'	# -v		--verbose
	);
die $usage if $opt_help;

die "lang name missing\n" . $usage if ! $opt_lang;
die "action flag missing (--add, --remove).\n" . $usage
	if ((! $opt_add) and (! $opt_remove));
die "too much action flags (--add and --remove).\n" . $usage
	if ( $opt_add and $opt_remove);

$OUT = " $opt_file";
open( OUT) or die "cannot copy file $OUT\n";
$IN = " $opt_file" . ".bak";
open( IN, "> $IN") or die "cannot copy to $IN\n";
print IN <OUT>;		# copy original file
close( IN); close( OUT);

open( IN,  "< $IN ") or die "cannot open input file $IN\n";
open( OUT, "> $OUT") or die "cannot open output file $OUT\n";
while( <IN>) {
	print OUT $_ and next if ! m|$opt_keyword| ;

	# process lines containing the keyword
	print OUT $_ and next if m|^[\t ]*#| ;
	#print OUT "# ", $_ and next if m|$base/$opt_lang| ;
	next if m|$base/$opt_lang| ;
	print OUT $_ and next if ! m|[\t ]*$base[\t ]*| ;
	print OUT $_ and next if m|[\t ]*$base/| ;

	# process only lines declaring $base as global_manpath
	($key, $global, $relative) = split;
	print OUT "$key\t$global/$opt_lang\t\t$relative/$opt_lang\n" if $opt_add;
	print OUT ;
	print OUT <IN>;
}
close( IN); close( OUT);

# catman dirs MUST be owned by man
#if ( $opt_add ) {
#	# create the cat directories only if the man directories exist
#	$res=`mkcatdirs man root 0755`;
#	print $res if $opt_verbose;
#} else {
#	system "su man -c \"rm -rf $relative/$opt_lang \"";
#}