Sub ParseCodeFiles(strFolder As String, strB4AFile As String) As Map
Dim i As Int
Dim strB4AProjectText As String
Dim strModuleName As String
Dim bModule As Boolean
Dim lstModules As List
Dim strCode As String
Dim strCodeLC As String
Dim arrLines() As String
Dim iEqualsPos As Int
Dim mapModules As Map
lstModules.Initialize
mapModules.Initialize
strB4AProjectText = File.GetText(strFolder, strB4AFile)
arrLines = Regex.Split(CRLF, strB4AProjectText)
For i = 0 To arrLines.Length - 1
If arrLines(i).ToLowerCase.StartsWith("module") Then
iEqualsPos = arrLines(i).IndexOf("=")
strModuleName = arrLines(i).SubString(iEqualsPos + 1).Trim
If strModuleName.Contains("=") = False Then
lstModules.Add(strModuleName)
bModule = True
End If
Else
If bModule Then
Exit
End If
End If
Next
'as this file holds Subs as well, a lot more if we have an activity based project with lots of code in Main!
'-----------------------------------------------------------------------------------------------------------
lstModules.Add(strB4AFile.SubString2(0, strB4AFile.Length - 4))
For i = 0 To lstModules.Size - 1
strModuleName = lstModules.Get(i)
If i = lstModules.Size - 1 Then
strCode = File.GetText(strFolder, strB4AFile)
Else
strCode = File.GetText(strFolder, strModuleName & ".bas")
End If
strCodeLC = strCode.ToLowerCase
Dim lstSubs As List
lstSubs.Initialize
GetSubNames(strCode, strCodeLC, CRLF & "sub ", lstSubs)
GetSubNames(strCode, strCodeLC, CRLF & "private sub ", lstSubs)
GetSubNames(strCode, strCodeLC, CRLF & "public sub ", lstSubs)
If lstSubs.Size > 0 Then
If i = lstModules.Size - 1 Then
mapModules.Put("Main" & " (activity module) " & lstSubs.Size, lstSubs)
Else
If strCodeLC.Contains("type=class") Then
If strCodeLC.Contains("private sub b4xpage_created") Then
mapModules.Put(strModuleName & " (B4XPages class) " & lstSubs.Size, lstSubs)
Else
mapModules.Put(strModuleName & " (normal class) " & lstSubs.Size, lstSubs)
End If
Else
If strCodeLC.Contains("type=service") Then
mapModules.Put(strModuleName & " (service module) " & lstSubs.Size, lstSubs)
Else
If strCodeLC.Contains("type=staticcode") Then
mapModules.Put(strModuleName & " (code module) " & lstSubs.Size, lstSubs)
Else
mapModules.Put(strModuleName & " " & lstSubs.Size, lstSubs)
End If
End If
End If
End If
End If
Next 'For i = 0 To lstModules.Size - 1
Return mapModules
End Sub
Sub GetSubNames(strCode As String, strCodeLC As String, strLookFor As String, lstSubs As List)
Dim iSubPos As Int
Dim iAsPos As Int
Dim iLookForLength As Int = strLookFor.Length
Dim iOpenBracketPos As Int
Dim iLinebreakPos As Int
Dim iSingleQuotePos As Int
Dim iSubNameEnd As Int
Dim strSubName As String
iSubPos = strCodeLC.IndexOf2(strLookFor, iSubPos) + 1
Do While iSubPos > 0
iOpenBracketPos = strCodeLC.IndexOf2("(", iSubPos + iLookForLength)
iLinebreakPos = strCodeLC.IndexOf2(CRLF, iSubPos + iLookForLength) - 1
If iOpenBracketPos > -1 Then
iSubNameEnd = Min(iOpenBracketPos, iLinebreakPos)
Else
iSubNameEnd = iLinebreakPos
End If
strSubName = strCode.SubString2(iSubPos, iSubNameEnd)
iAsPos = strSubName.ToLowerCase.IndexOf(" as ")
iSingleQuotePos = strSubName.IndexOf(Chr(39))
If iAsPos > -1 Then
If iSingleQuotePos > -1 Then
iSubNameEnd = Min(iAsPos, iSingleQuotePos)
lstSubs.Add(strSubName.SubString2(0, iSubNameEnd - 1))
Else
lstSubs.Add(strSubName.SubString2(0, iAsPos))
End If
Else
If iSingleQuotePos > -1 Then
lstSubs.Add(strSubName.SubString2(0, iSingleQuotePos - 1))
Else
lstSubs.Add(strSubName)
End If
End If
iSubPos = strCodeLC.IndexOf2(strLookFor, iSubPos + strLookFor.Length) + 1
Loop
End Sub