#!/usr/local/bin/perl # # crea_web.perl # # Current Version : 2.1.1 # ################################################################################### # # Brief Description: # # # created: april 1997 (Version 2.00b01) # # Version History # # Version: 2.1.1 (Sep 98) # - a #NOTINDEXED tag : do not put the text in the index. # # Version: 2.00b02 (Oct 97) # - Trying to make the code less poem-specific and insulate poem-specific code. # This appears to be mainly a question of terminology :-) # - At least the location is no more hard coded, but defined # # Version: 2.00b01 (Oct 97) # - Based upon text2poems.perl 1.210 # Waiting for improvments # # # author of the script: Garp # ################################################################################### #use strict; one day ? # SOME USER DEFINABLE FLAGS $DEBUG_LEVEL = 1000; # display debug msg if greater that 0. # $TEXTTEMPLATE_NAME = 'texttemplate.htm'; # Name of the template for texts $TEXTTEMPLATE_NAME = 'poemtemplate.htm'; # Name of the template for texts $INDEXTEMPLATE_NAME= 'indextemplate.htm'; # Name of the template for index $FILE_LOCATION_PREFIX = "/export/home/patois/public_html"; $HTTP_LOCATION_PREFIX = "/www.sura.org/~patois"; # Options specifics to Poems retranscription $MULTI = 0; # single poem per file (0) / multi (1) $INDEX = 1; # generate an index $POEMSWRIT = 1; # write the .html file on disk $ASTAZ = 1; # This is used to put the authors name on the index # in a very specific way that is done on the "Le site de # poesie de Marie..." page. Very specific, use only if u know # exactly what u r doing. $TEXT_MODE = 0; # Text mode : dont
line break (1) # Poem mode :
line break (0) $PREV_NEXT = 1; # When enabled, will link pages in the same order as the index # Work only with 'one level' index (no tag #INDEX_LOC). $UPDATE_OLD = 1; # When (0), look at files.html in ../ and dont create output # if the file already exist # When (1), create a new .html file whatever. $RESET_INDEX_LOC = 1;# if (1) Reset the index_loc to 0 after each poem. # if (0) the index_loc remain the same for # each following texts until explicitly modified. $ULUL = 0; #   indentation (0) / indentation (1) # (waiting for a 'tab' tag) the
should do it # CONSTANTS $LITTERAL = 1; # do not 'html' the submited text # (this is probably already an html file) $NOWHERE = 0; # Where we are in the source file $INPOEM = 1; # $ININDEX = 2; # $NOWHAT = 0; # Some constant for specific $TITLEPAGE= 1; # items in the text $TITLE = 2; # $BODY = 3; # $AUTHOR = 4; # $DATE = 5; # $DEDICACE = 6; # $NOTE = 7; # $CITATION = 8; # #GLOBAL VARIABLE $index_loc =0; $number =0; # --------------------------------------------------------------------------------- # Print debug information # --------------------------------------------------------------------------------- sub dbprint # --------------------------------------------------------------------------------- { my ($level,$s)= @_; if ($level<$DEBUG_LEVEL) {print $s;} } # --------------------------------------------------------------------------------- # Load a file into an array # --------------------------------------------------------------------------------- sub loadfile # --------------------------------------------------------------------------------- { my ($fname,$array)= @_; # my(CHG); open(CHG, $fname); @$array = ; close(CHG); } # --------------------------------------------------------------------------------- # write the output file # --------------------------------------------------------------------------------- sub poem_write # --------------------------------------------------------------------------------- { my ($outfile,@ptmp) = @_; my ($ls); if (!$UPDATE_OLD) { $ls = qx{ls ../$outfile}; if ($ls) {return;} } open(FOUT, ">$outfile"); print FOUT @ptmp; close(FOUT); } # # build_location # sub build_location { my($p,$filename,$location) = @_; my($outfile,$n); $$location = qx{pwd}; chop($$location); $$location =~ s/$FILE_LOCATION_PREFIX/$HTTP_LOCATION_PREFIX/; $$location =~ s/\/test//; if ($MULTI == 0) { $outfile = $filename; $outfile =~ s/\.txt$/.html/; } else { $n = $number; $outfile = $filename; $outfile =~ s/\.txt$//; $outfile = "$outfile$n.html"; } $$location = $$location.'/'.$outfile; return($outfile); } # # ptmp_scan # sub ptmp_scan { my ($p,$filename) = @_; my($i); for ($i=0;$i<@{$$p->{ptmp}};$i++) { if ($$p->{ptmp}[$i] =~ /\$/) { $_ = $$p->{ptmp}[$i]; SWITCH: { if(/\$pagetitle/) { $$p->{ptmp}[$i] =~ s/\$pagetitle/$$p->{pagetitle}/; last SWITCH; } if(/\$title/) { $$p->{ptmp}[$i] =~ s/\$title/$$p->{title}/; last SWITCH; } if(/\$location/) { $outfile = build_location($p,$filename,\$location); $$p->{ptmp}[$i] =~ s/\$location/$location/; last SWITCH; } if(/\$pagedate/) { $pagedate = qx{date}; chop($$p->{date}); $$p->{ptmp}[$i] =~ s/\$pagedate/$pagedate/; last SWITCH; } if(/\$text/) { splice(@{$$p->{ptmp}},$i,1,@{$$p->{text}}); last SWITCH; } if(/\$author/) { $$p->{ptmp}[$i] =~ s/\$author/$$p->{author}/; last SWITCH; } if(/\$date/) { $$p->{ptmp}[$i] =~ s/\$date/$$p->{date}/; last SWITCH; } if(/\$dedicace/) { if ($$p->{dedicace}) {$$p->{ptmp}[$i] =~ s/\$dedicace/$$p->{dedicace}/;} else {$$p->{ptmp}[$i] = "";} last SWITCH; } if(/\$citation/) { if ($$p->{citation}) {$$p->{ptmp}[$i] =~ s/\$citation/$$p->{citation}/;} else {$$p->{ptmp}[$i] = "";} last SWITCH; } if(/\$note/) { if ($$p->{note}) {$$p->{ptmp}[$i] =~ s/\$note/$$p->{note}/;} else {$$p->{ptmp}[$i] = "";} last SWITCH; } } } } return($outfile); } # # poem_build # sub poem_build { my ($p,$filename,$ip) = @_; my ($i,$outfile); $outfile = ptmp_scan($p,$filename); if ($POEMSWRIT) { poem_write($outfile,@{$$p->{ptmp}}); $$p->{where} = $NOWHERE; } if ($INDEX) { $$p->{title} =~ s/\n/ /g; $$p->{author}=~ s/\n/ /g; $$p->{author}=~ s/[\;\,\(].*$/\1/; $$p->{author}=~ s/\s*$//; $outfile =~ s/\n/ /g; if ($$p->{in_index}) { push(@{$$ip->{titleindex} [$index_loc]},$$p->{title}); push(@{$$ip->{authorindex}[$index_loc]},$$p->{author}); $$ip->{n}++; push(@{$$ip->{fileindex}[$index_loc]},$outfile); push(@{$$ip->{new_mark} [$index_loc]},$$p->{new_mark}); } if ($RESET_INDEX_LOC) {$index_loc = 0;} } if ($MULTI) { $number++; @{$$p->{ptmp}} = @{$$p->{poemtemp}}; @{$$p->{text}} = (); $$p->{where} = $NOWHERE; $$p->{what} = $NOWHAT; $$p->{litteral} = 0; $$p->{state} = $TITLEPAGE; $$p->{white} = 1; $$p->{dedicace} = ""; $$p->{citation} = ""; $$p->{note} = ""; $$p->{bodyskip} = 0; $$p->{tab} = 0; $$p->{new_mark} = 0; $$p->{in_index} = 1; $$p->{excluded} = 0; } } sub execute_poem_command { my ($p,$command,$filename,$ip)= @_; $_ = $command; SWITCH: { if (/^poem/i) { $$p->{where} = $INPOEM; last SWITCH; } if (/^\!poem/i) { poem_build($p,$filename,$ip); last SWITCH; } if (/^\!title/i) { $$p->{what} = $NOWHAT; $$p->{state} = $BODY; last SWITCH; } if (/^\index_location/i) { $command =~ s/(^\index_location)/\2/i; $index_loc = ($command+$command)/2; last SWITCH; } if (/^title/i) {$$p->{what} = $TITLE; last SWITCH; } if (/^\!author/i) {$$p->{what} = $NOWHAT; last SWITCH; } if (/^author/i) {$$p->{what} = $AUTHOR; last SWITCH; } if (/^dedicace/i) {$$p->{what} = $DEDICACE;last SWITCH; } if (/^\!dedicace/i) {$$p->{what} = $NOWHAT; last SWITCH; } if (/^citation/i) {$$p->{what} = $CITATION;last SWITCH; } if (/^\!citation/i) {$$p->{what} = $NOWHAT; last SWITCH; } if (/^\!note/i) {$$p->{what} = $NOWHAT; last SWITCH; } if (/^note/i) {$$p->{what} = $NOTE; last SWITCH; } if (/^\!litteral/i) {$$p->{litteral} = 0; last SWITCH; } if (/^litteral/i) {$$p->{litteral} = $LITTERAL;last SWITCH; } if (/^new/i) {$$p->{new_mark} = 1; last SWITCH; } if (/^not\_indexed/i){$$p->{in_index} = 0; last SWITCH; } if (/^exclude/i) {$$p->{excluded} = 1; last SWITCH; } if (/^\!text/i) {$TEXT_MODE = 0; last SWITCH; } if (/^text/i) {$TEXT_MODE = 1; last SWITCH; } } } # # space_skip # sub space_skip { my($skip,$s) = @_; if ($skip == 0) { if ($s !~ /^\s*$/) { return(1); } else { return(0); } } return(1); } # # html_tabling # sub html_tabling { my($p,$s) = @_; if (($nb = $$s =~ s/\t/\t/g)||($$p->{tab})) { if ($ULUL) { $suiv = $$p->{lines}[1+$j] =~ s/\t/\t/g; $$s =~ s/\t//g; for($k=0;$k<$nb-$$p->{tab};$k++) {$$s= '';} if ($nb-$suiv <= 0) {return(0);} $$p->{tab} = $nb; return(1); } else { $$s =~ s/\t/\ \;\ \;\ \;\ \;\ \;\ \;\ \;\ \;\ \;\ \;/g; return(0); } } return(0); } # # scan_in_body # sub scan_in_body { my ($p,$s,$filename,$ip,$j) = @_; $$p->{bodyskip} = space_skip($$p->{bodyskip},$s); if (!$$p->{bodyskip}) {return();} if ($$p->{litteral}) { push(@{$$p->{text}},$s); } else { if ($s =~ /^\s*$/) { # void line $$p->{white}++; if ($$p->{white} == 2) {$$p->{state}++;} $$p->{tab} = 0; } else { chop($s); #changing '&' to html $s =~ s/\& /\&\; /g; if ($$p->{white}) { if ((!$TEXT_MODE)&&(!html_tabling($p,\$s))) {$s = $s.'
';} push(@{$$p->{text}},'

'.$s."\n"); } elsif($$p->{lines}[$j+1] =~ /^\s*$/) { if (!$TEXT_MODE) {html_tabling($p,\$s);} push(@{$$p->{text}},$s.'

'."\n"); } else { if ((!$TEXT_MODE)&&(!html_tabling($p,\$s))) {$s = $s.'
';} push(@{$$p->{text}},$s."\n"); } $$p->{white}=0; } } } # # scan_in_nowhat # sub scan_in_nowhat { my ($p,$s,$filename,$ip,$j) = @_; SWITCH: { if ($$p->{state} == $TITLEPAGE) { if ($s !~ /^\s*$/) { chop($s); $$p->{pagetitle} = $s; $$p->{state}++; } last SWITCH; } if ($$p->{state} == $TITLE) { if ($s !~ /^\s*$/) { chop($s); $$p->{title} = $s; $$p->{state}++; } last SWITCH; } if ($$p->{state} == $BODY) { scan_in_body($p,$s,$filename,$ip,$j); last SWITCH; } if ($$p->{state} == $AUTHOR) { if ($s !~ /^\s*$/) { chop($s); $$p->{author} = $s; $$p->{state}++; } last SWITCH; } if ($$p->{state} == $DATE) { if ($s !~ /^\s*$/) { $$p->{date} = $s; chop($$p->{date}); $$p->{state}++; } last SWITCH; } } } # # scan_in_poem # sub scan_in_poem { my ($p,$s,$filename,$ip,$j) = @_; SWITCH: { if ($$p->{what} == $NOWHAT) { scan_in_nowhat($p,$s,$filename,$ip,$j); last SWITCH; } if ($$p->{what} == $TITLEPAGE) { $$p->{titlepage} = $$p->{titlepage}.$s; last SWITCH; } if ($$p->{what} == $TITLE) { $$p->{title} = $$p->{title}.$s; last SWITCH; } if ($$p->{what} == $AUTHOR) { $$p->{author} = $$p->{author}.$s; last SWITCH; } if ($$p->{what} == $DATE) { $$p->{date} = $$p->{date}.$s; last SWITCH; } if ($$p->{what} == $DEDICACE) { $$p->{dedicace} = $$p->{dedicace}.$s; last SWITCH; } if ($$p->{what} == $CITATION) { $$p->{citation} = $$p->{citation}.$s; last SWITCH; } if ($$p->{what} == $NOTE) { $$p->{note} = $$p->{note}.$s; last SWITCH; } } } # # file_scan # sub file_scan { my ($p,$filename,$ip) = @_; my($j,$s); for ($j=0;$j<@{$$p->{lines}};$j++) { $s=$$p->{lines}[$j]; if (($MULTI == 0)&&($j==@{$$p->{lines}}-1)) {$s = "#!POEM\n"} if ($s =~ /^\#/) { $s = substr($s,1); chop($s); execute_poem_command($p,$s,$filename,$ip); if ($$p->{excluded}) {return;} }elsif ($$p->{where} == $INPOEM) { scan_in_poem($p,$s,$filename,$ip,$j); } } } sub makepoem { my ($filename, $poemtemp,$ip) = @_; my ($parameters); $parameters = { ptmp => [ @$poemtemp ], poemtemp => [ @$poemtemp ], lines => [ () ], text => [ () ], where => $NOWHERE, what => $NOWHAT, litteral => 0, state => $TITLEPAGE, white => 1, number => 0, dedicace => "", author => "-", title => "", date => "", note => "", bodyskip => 0, tab => 0, new_mark => 0, in_index => 1, # has to be referenced in the index excluded => 0, }; # $filename = $file; $input++; unless (open($input, $filename)) { print STDERR "Can't open $filename: $!\n"; return; } @{$parameters->{lines}} = <$input>; close($input); print "processing : ";print $filename;print "\n"; if ($MULTI == 0) {$parameters->{where} = $INPOEM;} file_scan(\$parameters,$filename,$ip); } # # astaz_index_option # sub astaz_index_option { my($indexout,$ip,$ipp,$lastauthor,$k) = @_; if (!($$ip->{authorindex}[$$ipp->{index_loc}][$k] =~ /^$$lastauthor/)) { push(@$indexout,''."\n"); push(@$indexout ,''.$$ip->{authorindex}[$$ipp->{index_loc}][$k].''."\n"); push(@$indexout,'