"Fossies" - the Fresh Open Source Software Archive

Member "vpnc-0.5.3/makeman.pl" (19 Nov 2008, 3731 Bytes) of package /linux/privat/old/vpnc-0.5.3.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Perl source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "makeman.pl" see the Fossies "Dox" file reference documentation.

    1 #! /usr/bin/perl -w
    2 
    3 # $Id: makeman.pl 312 2008-06-15 18:09:42Z Joerg Mayer $
    4 
    5 # Written by Wolfram Sang (wolfram@the-dreams.de) in 2007,
    6 # some inspiration from help2man by Brendan O'Dea and from Perl::Critic
    7 
    8 # Generate the vpnc-manpage from a template and the --long-help-output.
    9 # Version 0.2
   10 
   11 # Command-line options: none
   12 # Files needed        : ./vpnc ./vpnc.8.template ./VERSION
   13 # Files created       : ./vpnc.8
   14 # Exit status         : errno-values or 255 (Magic string not found)
   15 
   16 # Distributed under the same licence as vpnc.
   17 
   18 use strict;
   19 use Fatal    qw(open close);
   20 use filetest qw(access);    # to always get errno-values on filetests
   21 use POSIX    qw(strftime setlocale LC_ALL);
   22 
   23 my $vpnc = './vpnc';
   24 -e $vpnc or die "$0: Can't find $vpnc. Did you compile it?\n";
   25 -x $vpnc or die "$0: Can't execute $vpnc. Please check permissions.\n";
   26 
   27 # The code converting the help-output to manpage format is lots of
   28 # regex-fiddling, sorry. It got a bit more complicated by additionally
   29 # indenting lists (those originally starting with an asterisk). I hope
   30 # this pays off when converting the manpage to HTML or such.
   31 
   32 open my $LONGHELP, '-|', "$vpnc --long-help";
   33 my $vpnc_options    = '';
   34 my $relative_indent = 0;
   35 my $indent_needed   = 0;
   36 
   37 while (<$LONGHELP>) {
   38     if (/^  /) {
   39 
   40     # Check if additional indent needs to be finished by comparing the
   41     # amount of spaces at the beginning. A bit ugly, but I don't see a
   42     # better way to do it.
   43     if ($relative_indent) {
   44         /^( *)/;
   45         if (length($1) < $relative_indent) {
   46         $vpnc_options .= ".RE\n";
   47         $relative_indent = 0;
   48         $indent_needed = 1;
   49         }
   50     }
   51     
   52     # Highlight the option and make an optional argument italic.
   53     if (s/^ *(--[\w-]+)/\n.TP\n.BI "$1"/) {
   54         s/(<.+>)/ " $1"/;
   55     }
   56     
   57     # Highlight conffile-only options.
   58     s/^ *(\(configfile only option\))/\n.TP\n.B $1/;
   59 
   60     # Position the Default-string
   61     s/^ *(Default:)/.IP\n$1/;
   62 
   63     # Highlight the conf-variable and make an optional argument italic.
   64     if (s/^ *(conf-variable:) (.+?) ?([<\n])/.P\n$1\n.BI "$2"$3/) {
   65         s/(<.+>)/ " $1"/;
   66     }
   67 
   68     # Replace asterisk with bulletin; indent if needed.
   69     if (s/^( +)\* /.IP \\(bu\n/) {
   70         if (not $relative_indent) {
   71         $vpnc_options .= ".RS\n";
   72             $relative_indent = length $1;
   73         }
   74     }
   75 
   76     # Do we need to add an .IP-command after .RE or is there already one?
   77     if ($indent_needed and not /^\n?\.[TI]?P/) {
   78         $vpnc_options .= ".IP\n";
   79         $indent_needed = 0;
   80     }
   81     
   82     # Finalize string and add it to buffer
   83         s/^ *//;
   84     s/ *$//;
   85     s/-/\\-/g;
   86         $vpnc_options .= $_;
   87     }
   88 }
   89 close $LONGHELP;
   90 
   91 # Hopefully the code speaks for itself from now on...
   92 
   93 setlocale( LC_ALL, 'C' );
   94 my $date = strftime( '%B %Y', localtime );
   95 
   96 open my $VERSION, '<', './VERSION';
   97 my $vpnc_version = <$VERSION>;
   98 close $VERSION;
   99 chomp $vpnc_version;
  100 
  101 open my $TEMPLATE, '<', './vpnc.8.template';
  102 open my $MANPAGE , '>', './vpnc.8';
  103 my $magic_found;
  104 my $MAGIC_FOR_HEADER  = qq(.\\" ###makeman.pl: Replace header here!\n);
  105 my $MAGIC_FOR_OPTIONS = qq(.\\" ###makeman.pl: Insert options from help-output here!\n);
  106 
  107 # Skip the template-header
  108 while (<$TEMPLATE>) {
  109     last if ($magic_found = ($_ eq $MAGIC_FOR_HEADER));
  110 }
  111 die "$0: Missing magic: $MAGIC_FOR_HEADER" if not $magic_found;
  112 
  113 print {$MANPAGE} <<"END_MANPAGE_HEADER";
  114 .\\" This manpage is generated!
  115 .\\" Please edit the template-file in the source-distribution only.
  116 .TH VPNC "8" "$date" "vpnc version $vpnc_version" "System Administration Utilities"
  117 END_MANPAGE_HEADER
  118 
  119 $magic_found = 0;
  120 
  121 while (<$TEMPLATE>) {
  122     if ($_ ne $MAGIC_FOR_OPTIONS) {
  123     print {$MANPAGE} $_;
  124     } else {
  125     print {$MANPAGE} $vpnc_options;
  126     $magic_found = 1;
  127     }
  128 }
  129 die "$0: Missing magic: $MAGIC_FOR_OPTIONS" if not $magic_found;
  130 
  131 close $TEMPLATE;
  132 close $MANPAGE;