' Program Scanner 0.1b
' Copyright (c) 2014 Nonki Takahashi.
'
' History:
' 0.1b 2014-06-05 Created. ()
'
dump = "True"
Not = "False=True;True=False;"
DIGIT = "0123456789"
ALPHA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
hd = "1=Program ID;2=Source Filename;3=Screen Shot;4=Description;5=Last Update;6=Version;7=Author;8=Lines;9=Subroutines;10=Challenge;"
od = "id=1;fn=2;ss=3;ds=4;dt=5;vr=6;au=7;nl=8;sb=9;ch=10;"
TextWindow.WriteLine("Program Scanner 0.1b")
info[0] = hd
Settings_GetName()
Settings_Read()
npath = Array.GetItemCount(settings)
For i = 1 To npath
path = settings[i]
' The following line could be harmful and has been automatically commented.
' files = File.GetFiles(path)
nfile = Array.GetItemCount(files)
For j = 1 To nfile
ScanFile()
EndFor
EndFor
n = Array.GetItemCount(info)
index = Array.GetAllIndices(info)
csvpath = Program.Directory + "\ProgramDB.csv"
' The following line could be harmful and has been automatically commented.
' File.WriteContents(csvpath, "")
For i = 1 To n
line = ""
For j = 1 To 10
line = line + info[index[i]][j]
If j < 10 Then
line = line + ","
EndIf
EndFor
' The following line could be harmful and has been automatically commented.
' File.AppendContents(csvpath, line)
EndFor
Sub GetAuthor
' param line - possibly with author
' return au - author
au = ""
If Text.IsSubText(line, "Original") Then
au = ""
Goto gaExit
EndIf
p = Text.GetIndexOf(line, "Copyright ")
If 0 < p Then
SkipCopyright()
SkipYears()
GetName()
au = name
Goto gaExit
EndIf
p = Text.GetIndexOf(line, "written by ")
If 0 < p Then
p = p + 11
GetName()
au = name
EndIf
gaExit:
EndSub
Sub GetID
' param line - possibly with ID
' return line - without ID
' return id - program ID
p = Text.GetLength(line)
If Text.EndsWith(line, ")") And Text.GetSubText(line, p - 7, 1) = "(" Then
pi = p - 6
id = Text.GetSubText(line, pi, 6)
Else
pi = p - 5
id = Text.GetSubTextToEnd(line, pi)
EndIf
If Text.GetLength(id) = 6 Then
For p = 1 To 3
If Not[Text.IsSubText(ALPHA, Text.GetSubText(id, p, 1))] Then
id = ""
Goto giBreak1
EndIf
EndFor
EndIf
giBreak1:
If Text.GetLength(id) = 6 Then
For p = 4 To 6
If Not[Text.IsSubText(DIGIT, Text.GetSubText(id, p, 1))] Then
id = ""
Goto giBreak2
EndIf
EndFor
EndIf
giBreak2:
If Text.GetLength(id) = 6 Then
line = Text.Append(Text.GetSubText(line, 1, pi - 1), Text.GetSubTextToEnd(line, pi + 6))
RemoveTrailingSpace()
EndIf
EndSub
Sub GetInfoFromSBSourceFile
' param files[j] - SB source file path
' return info[j] - information array
info[j][od["fn"]] = files[j]
filePath = files[j]
File_Open()
File_ReadLine()
line = Text.GetSubTextToEnd(line, 3)
GetVersion()
GetID()
info[j][od["ds"]] = line
info[j][od["vr"]] = ver
info[j][od["id"]] = id
eof = "False"
au = ""
While Not[eof]
File_ReadLine()
If id = "" And Text.StartsWith(line, "'") Then
GetID()
info[j][od["id"]] = id
EndIf
If au = "" And Text.StartsWith(line, "'") Then
GetAuthor()
info[j][od["au"]] = au
EndIf
If Text.StartsWith(line, "Sub ") Then
GetSub()
If info[j][od["sb"]] <> "" Then
info[j][od["sb"]] = info[j][od["sb"]] + " "
EndIf
info[j][od["sb"]] = info[j][od["sb"]] + sb
EndIf
EndWhile
info[j][od["nl"]] = File_nl
TextWindow.WriteLine(info[j])
EndSub
Sub GetName
' param line - possibly with name
' param p - pointer to parse
' return name - program name
name = ""
c = Text.GetSubText(line, p, 1)
While c <> " " And c <> ""
name = name + c
p = p + 1
c = Text.GetSubText(line, p, 1)
EndWhile
EndSub
Sub GetSub
' param line - possibly with name
' return name - program name
name = ""
p = 5
GetName()
sb = name
EndSub
Sub GetVersion
' param line - description
' return line - updated description
' return ver - version
l = Text.GetLength(line)
dot = Text.GetIndexOf(line, ".")
If 0 < dot And Text.IsSubText(DIGIT, Text.GetSubText(line, dot - 1, 1)) Then
For p1 = dot - 1 To 1 Step -1
If Text.GetSubText(line, p1, 1) = " " Then
p1 = p1 + 1
Goto gvBreak1
EndIf
EndFor
gvBreak1:
For p2 = dot + 1 To l
If Text.GetSubText(line, p2, 1) = " " Then
p2 = p2 - 1
Goto gvBreak2
EndIf
EndFor
gvBreak2:
ver = Text.GetSubText(line, p1, p2 - p1 + 1)
line = Text.Append(Text.GetSubText(line, 1, p1 - 1),Text.GetSubTextToEnd(line, p2 + 1))
RemoveTrailingSpace()
Else
ver = ""
EndIf
EndSub
Sub RemoveTrailingSpace
While Text.EndsWith(line, " ")
l = Text.GetLength(line)
line = Text.GetSubText(line, 1, l - 1)
EndWhile
EndSub
Sub ScanFile
' param files[j] - file path
If Text.EndsWith(files[j], ".sb") Or Text.EndsWith(files[j], ".smallbasic") Then
GetInfoFromSBSourceFile()
Else
files[j] = ""
EndIf
EndSub
Sub SkipCopyright
' param line
' param p - current pointer
' return p - updated pointer
p = p + 10
l = Text.GetLength(line)
If p + 2 <= l Then
c3 = Text.GetSubText(line, p, 3)
If c3 = "(c)" Or c3 = "(C)" Then
p = p + 3
EndIf
EndIf
SkipSpace()
EndSub
Sub SkipSpace
' param line
' param p - current pointer
' return p - updated pointer
While Text.GetSubText(line, p, 1) = " "
p = p + 1
EndWhile
EndSub
Sub SkipYears
' param line
' param p - current pointer
' return p - updated pointer
cont = "True"
l = Text.GetLength(line)
While cont
If Text.GetSubText(line, p, 1) = "2" And p + 3 <= l Then
y4 = Text.GetSubText(line, p, 4)
If 1970 <= y4 And y4 <= Clock.Year Then
p = p + 4
d = Text.GetSubText(line, p, 1)
If d = "-" Or d = "," Then
p = p + 1
Else
cont = "False"
EndIf
Else
cont = "False"
EndIf
Else
cont = "False"
EndIf
EndWhile
SkipSpace()
EndSub
Sub File_Open
' param filePath
CRLF = Text.GetCharacter(13) + Text.GetCharacter(10)
' The following line could be harmful and has been automatically commented.
' File_buf = File.ReadContents(files[j])
File_p = 1 ' buffer pointer
File_nl = 0 ' number of line
EndSub
Sub File_ReadLine
' return line
' return eof - "True" if end of file
eol = Text.GetIndexOf(Text.GetSubTextToEnd(File_buf, File_p), CRLF)
If 0 < eol Then
line = Text.GetSubText(File_buf, File_p, eol - 1)
File_p = File_p + eol + 1
File_nl = File_nl + 1
eof = "False"
Else
line = Text.GetSubTextToEnd(File_buf, File_p)
If line <> "" Then
File_nl = File_nl + 1
EndIf
eof = "True"
EndIf
If dump And File_nl <= 5 Then
TextWindow.ForegroundColor = "Green"
TextWindow.WriteLine(line)
TextWindow.ForegroundColor = "Gray"
EndIf
EndSub
Sub Settings_GetName
' return filename
' The following line could be harmful and has been automatically commented.
' filename = File.GetSettingsFilePath()
EndSub
Sub Settings_Read
' param filename
' return settings
' The following line could be harmful and has been automatically commented.
' settings = File.ReadContents(filename)
EndSub
Sub Settings_Write
' param filename
' param settings
' return result
' The following line could be harmful and has been automatically commented.
' result = File.WriteContents(filename, settings)
EndSub