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
|
#!/usr/bin/perl -i
my($line,$list,$l,@lists,$v1,$v2,$debug,$output);
my($conf) = shift @ARGV;
$debug=0;
if( not $conf or not $ARGV[0] ){
print STDERR "use: $0 ifhp.conf file\n";
exit 1;
}
open( CONF, "<$conf") or die "cannot open '$conf'";
while( <CONF> ){
chomp();
if( /^# PRINTER / ){
s/^# PRINTER //;
if( /^-/ ){
s/-//;
$line .= $_;
} else {
if( $line ){
$line =~ s,^(\S*) - (.*)$,<row><entry><literal>$1</literal></entry><entry>$2</entry></row>,;
$output .= "$line\n";
}
$line = $_;
}
} elsif( $line and /^\[/ ){
if( $line !~ /\%/ ){
print STDERR $line if $debug;
$line =~ s,^(\S*) - (.*)$,<row><entry><literal>$1</literal></entry><entry>$2</entry></row>,;
$output .= "$line\n";
$line = "";
next;
}
@lists = split(' ',$_);
foreach $list (@lists){
next if not $list;
next if $list =~ /\[/;
next if $list =~ /\]/;
$l = $line;
print STDERR "X $list $l\n" if $debug;
$l =~ s/%/$list/;
print STDERR "$l\n" if $debug;
if( $l =~ m,{/(.*)/(.*)/}, ){
print STDERR "$1, $2\n" if $debug;
$v1 = $1;
$v2 = $2;
eval "\$list =~ s/$v1/$v2/";
print STDERR "Match '$list'\n" if $debug;
$l =~ s/{.*}/$list/;
print STDERR "Final $l\n" if $debug;
}
print STDERR "$l\n" if $debug;
$l =~ s,^(\S*) - (.*)$,<row><entry><literal>$1</literal></entry><entry>$2</entry></row>,;
$output .= "$l\n";
}
$line = "";
}
}
print STDERR "OUTPUT ". $output if $debug;
$skip = 0;
print STDERR "XX START\n" if $debug;
while( <> ){
print STDERR "INPUT $_" if $debug;
if( /SUPPORTED START/ ){
print;
print <<'EOF' ;
<table frame=all id=configentries>
<title><literal/ifhp.conf/ Configuration Entries </title>
<tgroup cols=2 colsep=1 rowsep=1 align=left >
<thead><row><entry/Configuration/<entry/Printer Supported/</row></thead>
<tbody>
EOF
print $output;
print STDERR "YY $_" if $debug;
print STDERR "ZZ $output" if $debug;
print <<'EOF' ;
</tbody>
</tgroup>
</table>
EOF
$skip = 1;
} elsif( $skip ){
$skip = 0 if( /SUPPORTED END/ );
}
print if( not $skip );
if( $debug ){ print STDERR "XX $_" if( not $skip ); }
}
|