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 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
|
#!/usr/local/bin/perl5
# Filename: mkpod
#
# Author: Paul Marquess
# File types
#
# Macro files end with .M
# Tagged source files end with .T
# Output from the code ends with .O
# Pre-Pod file ends with .P
#
# Tags
#
# ## BEGIN tagname
# ...
# ## END tagname
#
# ## 0
# ## 1
#
# Constants
$TOKEN = '##' ;
$Verbose = 1 if $ARGV[0] =~ /^-v/i ;
# Macros files first
foreach $file (glob("*.M"))
{
open (F, "<$file") or die "Cannot open '$file':$!\n" ;
print " Processing Macro file $file\n" ;
while (<F>)
{
# Skip blank & comment lines
next if /^\s*$/ || /^\s*#/ ;
#
($name, $expand) = split (/\t+/, $_, 2) ;
$expand =~ s/^\s*// ;
$expand =~ s/\s*$// ;
if ($expand =~ /\[#/ )
{
}
$Macros{$name} = $expand ;
}
close F ;
}
# Suck up all the code files
foreach $file (glob("t/*.T"))
{
($newfile = $file) =~ s/\.T$// ;
open (F, "<$file") or die "Cannot open '$file':$!\n" ;
open (N, ">$newfile") or die "Cannot open '$newfile':$!\n" ;
print " Processing $file -> $newfile\n" ;
while ($line = <F>)
{
if ($line =~ /^$TOKEN\s*BEGIN\s+(\w+)\s*$/ or
$line =~ m[\s*/\*$TOKEN\s*BEGIN\s+(\w+)\s*$] )
{
print " Section $1 begins\n" if $Verbose ;
$InSection{$1} ++ ;
$Section{$1} = '' unless $Section{$1} ;
}
elsif ($line =~ /^$TOKEN\s*END\s+(\w+)\s*$/ or
$line =~ m[^\s*/\*$TOKEN\s*END\s+(\w+)\s*$] )
{
warn "Encountered END without a begin [$line]\n"
unless $InSection{$1} ;
delete $InSection{$1} ;
print " Section $1 ends\n" if $Verbose ;
}
else
{
print N $line ;
chop $line ;
$line =~ s/\s*$// ;
# Save the current line in each of the sections
foreach( keys %InSection)
{
if ($line !~ /^\s*$/ )
#{ $Section{$_} .= " $line" }
{ $Section{$_} .= $line }
$Section{$_} .= "\n" ;
}
}
}
if (%InSection)
{
# Check for unclosed sections
print "The following Sections are not terminated\n" ;
foreach (sort keys %InSection)
{ print "\t$_\n" }
exit 1 ;
}
close F ;
close N ;
}
print "\n\nCreating pod file(s)\n\n" if $Verbose ;
@ppods = glob('*.P') ;
#$ppod = $ARGV[0] ;
#$pod = $ARGV[1] ;
# Now process the pre-pod file
foreach $ppod (@ppods)
{
($pod = $ppod) =~ s/\.P$// ;
open (PPOD, "<$ppod") or die "Cannot open file '$ppod': $!\n" ;
open (POD, ">$pod") or die "Cannot open file '$pod': $!\n" ;
print " $ppod -> $pod\n" ;
while ($line = <PPOD>)
{
if ( $line =~ /^\s*$TOKEN\s*(\w+)\s*$/)
{
warn "No code insert '$1' available\n"
unless $Section{$1} ;
print "Expanding section $1\n" if $Verbose ;
print POD $Section{$1} ;
}
else
{
# $line =~ s/\[#([^\]])]/$Macros{$1}/ge ;
print POD $line ;
}
}
close PPOD ;
close POD ;
}
|