#/usr/local/perl ####################### ## ## SSI-PL ## ## A library, which implements including perl files from within ## Perl script, taking into account SSI stuff. ## ## function to be called: DoInclude(URI); ## ## V0.1 ## ## Fixed a bug when existing SSIVARS were overwritten by ENV ## ## V0.0 ## ## implemented: ## ## \n"; } } # debug ("End: InHTMLComment = " . InHTMLComment() ); } sub HandleHTML { local $HTML = @_[0]; if (MayOutput()) { print "$HTML"; } } sub ProcessLine { # process the line and return the remainder local $ALine = @_[0]; # debug("CurrLine: $ALine\n"); if ($ALine =~ /^(.*?)\<\!--(.*?)--\>(.*)$/) { # debug("[$1] [$2] [$3]\n"); HandleHTML($1); HandleCommentStart($2); HandleCommentEnd(""); return "$3"; } if (InHTMLComment()) { # debug("CurrLine0: $ALine\n"); if ($ALine =~ /(.*?)--\>(.*)/) { HandleCommentEnd($1); # debug("valright1: $2\n"); return $2; } else { HandleCommentCont($ALine ."\n"); return ""; } } else { # normal run # debug("CurrLine: $ALine\n"); if ($ALine =~ /^(.*?)\<\!--(.*)/g) { HandleHTML($1); local $RestOfLine = $2; if ($RestOfLine =~ /(.*?)--\>(.*)/) { HandleCommentStart($1); HandleCommentCont(""); HandleCommentEnd(""); # debug("valright: $2\n"); return $2; } else { HandleCommentStart($RestOfLine); return ""; } } else { HandleHTML($ALine . "\n"); return ""; } } } sub DoInclude { ### include a file & print it & parse it for SSI stuff local $FName = TransPath(@_[0]); # print "FNAME: $FName\n"; local *SSIHTML; local @SSILINES; local $CurrLine; foreach $aName (keys %ENV) { $SSIVARS{$aName} = $ENV{$aName}; } push (@InHTMLComment, 0); if(open(SSIHTML, "<" . $FName)) { @SSILINES = ; close (SSIHTML); foreach $CurrLine (@SSILINES) { chomp($CurrLine); while (($CurrLine = ProcessLine($CurrLine)) ne "") { } } } else { ReportError("I/O error while including the file"); } $CommentVal = pop(@InHTMLComment); if ( $CommentVal != 0) { ReportError("Unclosed comment $CommentVal in file $FName"); } } return 1;