Imports system.Text.RegularExpressions
Imports System.IO
Module ConvertCodetoHTML
Sub Main(ByVal args() As String)
If (args.Length < 1) OrElse (args.Length > 3) Then
Console.WriteLine("Usage:")
Console.WriteLine("ConvertVBtoHTML SourceFile [DestinationFile] [KeyWordFile]")
Console.WriteLine("SourceFile := Name of visual basic source code file to convert.")
Console.WriteLine("DestinationFile := Name of HTML file to which results are written")
Console.WriteLine("If omitted, then output file has the same name as the inputfile with "".html"" appended")
Console.WriteLine("KeyWordFile := Name of the XML file from which keywords are read")
Console.WriteLine("If omitted, then KeyWordFile = keywords.xml")
Exit Sub
Else
Dim strMatch As String
Dim strReplace As String
Dim filein As String = args(0)
Dim fileout As String = filein & ".html"
Dim keyfile As String = My.Application.CurrentDirectory & "\keywords.xml"
Select Case args.Length
Case 1
Case 2
fileout = args(1)
Case 3
fileout = args(1)
keyfile = args(2)
End Select
If (Not IO.File.Exists(filein)) Then
Console.WriteLine("InFile not found")
Exit Sub
End If
Dim strworking As String = New StreamReader(filein).ReadToEnd()
If (Not IO.File.Exists(keyfile)) Then
Console.WriteLine("KeyWordFile not found")
Exit Sub
End If
strMatch = "&"
strReplace = "&"
strworking = RegExReplace(strworking, strMatch, strReplace, -1)
strMatch = "\<"
strReplace = "<"
strworking = RegExReplace(strworking, strMatch, strReplace, -1)
strMatch = "\>"
strReplace = ">"
strworking = RegExReplace(strworking, strMatch, strReplace, -1)
strMatch = "(?([ \t][^""]\s*'+[\S ]*))"
strReplace = ""color:#006400;"">${comment}"
strworking = RegExReplace(strworking, strMatch, strReplace, -1)
strMatch = "</?((summary)|(param.*)|(remarks)|(returns))>"
strReplace = ""color:#A52A2A;"">$&"
strworking = RegExReplace(strworking, strMatch, strReplace, -1)
Dim gigo As String = "blah 'batshit' blah"
strMatch = "(?((.)|(\n))*)"
strReplace = ""-//W3C//DTD XHTML 1.0 Transitional//EN"" ""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"">"http://www.w3.org/1999/xhtml"">"font-family:Monospace"
"> " + ControlChars.CrLf + " ${doc} " + ControlChars.CrLf
strworking = RegExReplace(strworking, strMatch, strReplace, 1)
Dim kwords As keywords = New keywords()
kwords = CKeyWords.GetKeywords(keyfile, "keywords.xsd")
Dim colors() As String = {"aqua", "black", "black", "blue", "fuchsia", "gray", "green", "lime", "maroon", "navy", "olive", "purple", "red", "silver", "teal", "white", "yellow"}
For n As Integer = 0 To colors.GetUpperBound(0)
Dim rows() As DataRow
rows = kwords.keyword.Select("color = '" & colors(n) & "'", "keyword_text DESC")
If (rows.Length > 0) Then
Dim strKeyWords As String = "(?(\b)("
For Each dr As DataRow In rows
strKeyWords &= "(" & CType(dr, keywords.keywordRow).keyword_text & ")|"
Next
strKeyWords = Left(strKeyWords, strKeyWords.Length() - 1)
strKeyWords &= ")(\b))"
strReplace = ""color:" & colors(n) & """>${keyword}"
strworking = RegExReplace(strworking, strKeyWords, strReplace, -1)
End If
Next n
Dim sw As New StreamWriter(fileout)
sw.AutoFlush = True
sw.WriteLine(strworking)
sw.Close()
End If
End Sub
Public Function RegExReplace(ByVal InString As String, ByVal SearchPattern As String, ByVal Replacement As String, ByVal MaxReplace As Integer) As String
Trace.WriteLine("Entering RegExReplace")
Trace.WriteLine(String.Format("Total Memory: {0}", GC.GetTotalMemory(False)))
Dim rx As Regex
Dim strWorking As String = InString
Dim generation As Integer = 0
Try
rx = New Regex(SearchPattern, RegexOptions.Multiline)
generation = GC.GetGeneration(rx)
Dim strMatch As String = Regex.Match(strWorking, SearchPattern).ToString()
strWorking = rx.Replace(strWorking, Replacement, MaxReplace)
Return (strWorking)
Catch ex As Exception
Trace.WriteLine("Error: " & ex.Message)
Return (InString)
Finally
Trace.WriteLine("Pre GC")
Trace.WriteLine(String.Format("Total Memory: {0}", GC.GetTotalMemory(False)))
rx = Nothing
GC.Collect()
Trace.WriteLine("Post GC")
Trace.WriteLine(String.Format("Total Memory: {0}", GC.GetTotalMemory(False)))
Trace.WriteLine("Exiting RegExReplace")
End Try
End Function
End Module