#------------------------------------------------------------------- # Program options #------------------------------------------------------------------- $InputFilename = "CodeLibrary.bas"; $FileExtension = "htm"; $OutputFilename = "index.$FileExtension"; $Titles = "BlibbleBlobble.co.uk - Code Library"; #------------------------------------------------------------------- # Set-up the index files #------------------------------------------------------------------- if( ! -d("Functions" )) { mkdir("./Functions") || die("tried and failed to create Functions directory"); } #Read BASIC file into text string open (INPUT, $InputFilename) || die ("Could not read file"); @Lines = ; close INPUT; $Basic = join( "" , @Lines ); #Open index files for output open (INDEX, ">$OutputFilename") || die("Could not write file"); $HtmlHeader = "\n\nUntitled\n\n\n\n\n"; $HtmlFooter = "\n\n\n\n"; $Style = ""; $Functions = 0; $MainHeader=$HtmlHeader; $MainStyle = ""; $MainHeader =~ s/\<\!-- Style --\>/$MainStyle/; $MainHeader =~ s/\Untitled/$Titles/; print INDEX $MainHeader; print INDEX "

CodeLibrary, a selection of VB functions

\n"; print INDEX "

Download as ZIP file

"; print INDEX "

Perl program used to create this website

"; open (COPY, ">copyright.htm"); print COPY $HtmlHeader . "

Copyright statement

\n

Not yet defined

" . $HtmlFooter; close COPY; #------------------------------------------------------------------- # Loop through all functions and subroutines in the BASIC file #------------------------------------------------------------------- # while ($Basic =~ /\n\s*(public|private)?\s*(function|sub)\s+(\w+)\((.*?)\)\s*(as (\w+))?(.*?)\n\s*end (function|sub)/gis) while ($Basic =~ /(\n\s*\'.*?\n)*\s*(public|private)?\s*(function|sub)\s+(\w+)\((.*?)\)\s*(as (\w+))?(.*?)\n\s*end (function|sub)/gis) { $Comments = $1; $Scope = $2; $SubOrFunction = $3; $Name = $4; $Arguments = $5; $ReturnTypeDeclaration = $6; $ReturnType = $7; $Function = $8; $Comments =~ s/\n/\n /g; $Arguments =~ s/_\n/ /g; $FunctionDeclaration = "$Scope $SubOrFunction $Name ($Arguments) $ReturnTypeDeclaration"; if ($Scope eq 'Public') { print INDEX "

$Name ($Arguments)

\n"; #------------------------------------------------------------------- # Create a special HTML file to just just this one function #------------------------------------------------------------------- open (FUNCTION, ">Functions\\$Name.$FileExtension") || die("\nCouldn't open Functions\\$Name.$FileExtension"); # Take the function, convert it to HTML, and colour it $HtmlFunction = ColoriseVB( ConvertToHtml( $Function )); # Create an HTML page, containing an appropriate title $Html = #Display heading in a box "

< $Scope $SubOrFunction " . "$Name ($Arguments) " . "$ReturnTypeDeclaration" . " (?)" . "

" . #Display the function comments "\n
Comments

". $Comments ."

\n" . # Display function itself in a box "
\n". "\n

\n\n$FunctionDeclaration
\n$HtmlFunction\n
End $SubOrFunction\n\n

" . "
" . "\n
\n

Copying, Return to index

" ; $NewHeader = $HtmlHeader; $NewHeader =~ s/Untitled/$Titles - Function $Name/i; $NewHeader =~ s/\<\!-- Style --\>/$Style/; # Write this HMTL file to disk print FUNCTION $NewHeader . $Html . $HtmlFooter; close FUNCTION; print "\n (" . ++$Functions . ") $Name"; } } #------------------------------------------------------------------- # Close the index files #------------------------------------------------------------------- print INDEX $HtmlFooter; close INDEX; #------------------------------------------------------------------- # Take HTML-formatted VB code, and add color to the keywords #------------------------------------------------------------------- sub ColoriseVB { $Html = shift(); $Color1 = "blue"; $Html = Colorise($Html, "Dim", $Color1); $Html = Colorise($Html, "As", $Color1); $Html = Colorise($Html, "Public", $Color1); $Html = Colorise($Html, "Private", $Color1); $Html = Colorise($Html, "Const", $Color1); $Html = Colorise($Html, "Global", $Color1); $Html = Colorise($Html, "String", $Color1); $Html = Colorise($Html, "Boolean", $Color1); $Html = Colorise($Html, "Integer", $Color1); $Html = Colorise($Html, "Long", $Color1); $Html = Colorise($Html, "Single", $Color1); $Html = Colorise($Html, "Double", $Color1); $Html = Colorise($Html, "Object", $Color1); $Html = Colorise($Html, "Variant", $Color1); $Html = Colorise($Html, "Byte", $Color1); $Html = Colorise($Html, "If", $Color1); $Html = Colorise($Html, "Then", $Color1); $Html = Colorise($Html, "Else", $Color1); $Html = Colorise($Html, "Do", $Color1); $Html = Colorise($Html, "While", $Color1); $Html = Colorise($Html, "Wend", $Color1); $Html = Colorise($Html, "End", $Color1); $Html = Colorise($Html, "Exit", $Color1); $Html = Colorise($Html, "For", $Color1); $Html = Colorise($Html, "To", $Color1); $Html = Colorise($Html, "Step", $Color1); $Html = Colorise($Html, "Next", $Color1); $Html = Colorise($Html, "Select", $Color1); $Html = Colorise($Html, "Case", $Color1); $Html = Colorise($Html, "With", $Color1); $Html = Colorise($Html, "Sub", $Color1); $Html = Colorise($Html, "Function", $Color1); $Html = Colorise($Html, "Call", $Color1); $Html = Colorise($Html, "Not", $Color1); $Html = Colorise($Html, "And", $Color1); $Html = Colorise($Html, "Or", $Color1); $Html = Colorise($Html, "Xor", $Color1); # Color comments in green $Html =~ s/('.*?)\n/$1<\/font>\n/; return $Html; } #------------------------------------------------------------------- # Replace a particular keyword with a colored version #------------------------------------------------------------------- sub Colorise { $Html = shift(); $Keyword = shift(); $NewColor = shift(); $Html =~ s/\b$Keyword\b/$Keyword<\/font>/g; return $Html; } #------------------------------------------------------------------- # Convert text (VB) file to HTML #------------------------------------------------------------------- sub ConvertToHtml { $Html = shift(); $Html =~ s/&/&/g; $Html =~ s//>/g; $Html =~ s/\"/"/g; $Html =~ s/\n/\n
/g; $Html =~ s/\t/ /g; $Html =~ s/ / /g; return $Html; }