* vfs.c (vfs_init) [!WITH_MCFS]: Don't register mcfs.
[midnight-commander.git] / src / gindex.pl
blobeabf920f0183a77d9a2264bf610b21b4b756e621
1 #! /usr/bin/perl -w
2 # Since we use a linear search trought the block and the license and
3 # the warranty are quite big, we leave them at the end of the help file,
4 # the index will be consulted quite frequently, so we put it at the beginning.
6 $man2hlp = './man2hlp';
7 if ($#ARGV == 4) {
8 $Topics = "$ARGV[3]";
9 $man2hlp = "$ARGV[4]";
10 } elsif ($#ARGV == 3) {
11 $Topics = "$ARGV[3]";
12 } elsif ($#ARGV == 2) {
13 $Topics = 'Topics:';
14 } else {
15 die "Usage: gindex.pl man_file tmpl_file out_file [Topic section header] [man2hlp]";
18 $man_file = "$ARGV[0]";
19 $tmpl_file = "$ARGV[1]";
20 $out_file = "$ARGV[2]";
22 $help_width = 58;
23 open (HELP1, "$man2hlp $help_width $man_file |") or
24 die "Cannot open read output of man2hlp: $!\n";;
25 @help_file = <HELP1>;
26 close (HELP1);
28 open (HELP2, "< $tmpl_file") or die "Cannot open $tmpl_file: $!\n";
29 push @help_file, <HELP2>;
30 close (HELP2);
32 if ($Topics eq ''){
33 $Topics = shift (@help_file);
34 chomp ($Topics);
37 foreach $line (@help_file){
38 if ($line =~ /\x04\[(.*)\]/ && $line !~ /\x04\[main\]/){
39 if (length $1) {
40 $node = $1;
41 } else {
42 push @nodes, '';
44 $line =~ s/(\x04\[) */$1/;
45 } elsif (defined ($node)){
46 if ($line ne "\n") {
47 push @nodes, "$node\x02$line";
48 } else {
49 push @nodes, "$node\x02$node";
51 undef ($node);
55 unlink ("$out_file");
56 if (-e "$out_file") {
57 die "Cannot remove $out_file\n";
60 open (OUTPUT, "> $out_file") or die "Cannot open $out_file: $!\n";
62 print OUTPUT "\x04[Contents]\n$Topics\n\n";
63 foreach $node (@nodes){
64 if (length $node){
65 $node =~ m/^( *)(.*)\x02(.*)$/;
66 print OUTPUT (" $1\x01 $3 \x02$2\x03");
68 print OUTPUT "\n";
71 print OUTPUT @help_file;
73 close (OUTPUT);