- #!/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 $filen" ;
- 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 -> $newfilen" ;
- while ($line = <F>)
- {
- if ($line =~ /^$TOKENs*BEGINs+(w+)s*$/ or
- $line =~ m[s*/*$TOKENs*BEGINs+(w+)s*$] )
- {
- print " Section $1 beginsn" if $Verbose ;
- $InSection{$1} ++ ;
- $Section{$1} = '' unless $Section{$1} ;
- }
- elsif ($line =~ /^$TOKENs*ENDs+(w+)s*$/ or
- $line =~ m[^s*/*$TOKENs*ENDs+(w+)s*$] )
- {
- warn "Encountered END without a begin [$line]n"
- unless $InSection{$1} ;
- delete $InSection{$1} ;
- print " Section $1 endsn" 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 terminatedn" ;
- foreach (sort keys %InSection)
- { print "t$_n" }
- exit 1 ;
- }
- close F ;
- close N ;
- }
- print "nnCreating pod file(s)nn" 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 -> $podn" ;
- while ($line = <PPOD>)
- {
- if ( $line =~ /^s*$TOKENs*(w+)s*$/)
- {
- warn "No code insert '$1' availablen"
- unless $Section{$1} ;
- print "Expanding section $1n" if $Verbose ;
- print POD $Section{$1} ;
- }
- else
- {
- # $line =~ s/[#([^]])]/$Macros{$1}/ge ;
- print POD $line ;
- }
- }
- close PPOD ;
- close POD ;
- }