#! @PERL@ eval 'exec @PERL@ -S $0 ${1+"$@"}' if 0; # -*- Perl -*- # info2txt -- Convert a Info document to plain text. # # Copyright (C) 1997 Motoyuki Kasahara # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2, or (at your option) # any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. eval 'exec @PERL@ -S $0 ${1+"$@"}' if 0; # Program name, version and mailing address $progname ='info2txt'; $version = '1.2'; $mailing_address = '@MAILING_ADDRESS@'; $help = "Usage: $progname [option...] [info-file] Options: -h, --help display this help, then exit -S, --no-split don\'t read split info-files -v, --version display version number, then exit Report bugs to $mailing_address. "; $tryhelp = "try \`$0 --help\' for more information\n"; @option_list = ('-h --help no-argument', '-S --no-split no-argument', '-v --version no-argument'); $columns = 70; # # Parse command line options. # $split_mode = 1; &getopt_initialize(@option_list); while (($opt, $arg) = &getopt_long) { if ($opt eq '-h') { print $help; exit(0); } elsif ($opt eq '-S') { $split_mode = 0; } elsif ($opt eq '-v') { print "$progname version $version\n\n"; print "Copyright (c) 1997, 1998 Motoyuki Kasahara\n\n"; print "This is free software; you can redistribute it and/or modify\n"; print "it under the terms of the GNU General Public License as published by\n"; print "the Free Software Foundation; either version 2, or (at your optio n)\n"; print "any later version.\n\n"; print "This program is distributed in the hope that it will be useful,\n "; print "but WITHOUT ANY WARRANTY; without even the implied warranty\n"; print "of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"; print "GNU General Public License for more details.\n"; exit(0); } else { die $tryhelp; } } die "too many arguments\n$tryhelp" if (2 <= @ARGV); # # Search `info-file-1', `info-file-2', ... when `--no-split' and `-S' # are not specified. # if ($split_mode && @ARGV == 1 && -f "$ARGV[0]-1") { $basename = pop(@ARGV); push(@ARGV, "$basename-1"); for ($i = 2; -f "$basename-$i"; $i++) { push(@ARGV, "$basename-$i"); } } # # Main loop. # ($STATUS_TEXT, $STATUS_DIR_ENTRY, $STATUS_NODE, $STATUS_MENU) = (0..4); while (<>) { if (/Tag Table:/) { last; } elsif (/^START-INFO-DIR-ENTRY/) { $status = $STATUS_DIR_ENTRY; $dir_entry++; } elsif (/^END-INFO-DIR-ENTRY/) { $status = $STATUS_TEXT; print "\n" if ($dir_entry == 1); } elsif (/^\* Menu:/) { $status = $STATUS_MENU; } elsif (/^\037/) { $status = $STATUS_NODE; } elsif ($status == $STATUS_NODE && /Node: Top,/) { $top_node = 1; } elsif ($status == $STATUS_DIR_ENTRY && $dir_entry == 1) { if (($name, $title) = /^\* ([^:]*): \([^\)]*\)\.[ \t]+(.*)$/) { $is_title = 1; $namepad = ($columns - length($name)) / 2; $titlepad = ($columns - length($title)) / 2; print "\n"; print ' ' x $namepad if (0 < $namepad); print "$name\n"; print ' ' x $titlepad if (0 < $titlepad); print "$title\n"; } elsif (s/^[ \t]+// && $is_title) { chop; $titlepad = ($columns - length($_)) / 2; print ' ' x $titlepad if (0 < $titlepad); print "$_\n"; } else { $is_title = 0; } } else { print if ($status == $STATUS_TEXT && $top_node); $status = $STATUS_TEXT if ($status == $STATUS_NODE); } } # Local Variables: # mode: perl # End: