-
Notifications
You must be signed in to change notification settings - Fork 2
/
ProgramFinder.sb
140 lines (131 loc) · 3.61 KB
/
ProgramFinder.sb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
' Program Finder 0.5b
' Copyright © 2015-2017 Nonki Takahashi. The MIT License.
' History:
' 0.5b 2017-07-22 #11 Bug fixed: only LF not treated.
' 0.4b 2017-05-03 #16 Bug fixed: shows redundant path name.
' 0.3b 2016-04-08 Changed not only for comments.
' 0.2b 2016-03-28 Output full path and periods while finding.
' 0.1b 2015-12-20 Created (to find top 20 comments for each program).
'
title = "Program Finder 0.5b"
Not = "False=True;True=False;"
dump = "False"
TextWindow.WriteLine(title)
filename = Program.Directory + "\ProgramScanner.settings" ' Settings_GetName()
stdout = Program.Directory + "\found.txt"
Settings_Read()
npath = Array.GetItemCount(settings)
keyword = "dummy"
While keyword <> ""
TextWindow.Write("Keyword? ")
keyword = TextWindow.Read()
If keyword <> "" Then
For i = 1 To npath
path = settings[i]
files = File.GetFiles(path)
nfile = Array.GetItemCount(files)
For j = 1 To nfile
filepath = files[j]
FindFile()
EndFor
TextWindow.Write(".")
EndFor
TextWindow.WriteLine("")
EndIf
EndWhile
Program.End()
Sub FindFile
' Find file including keyword
' param filepath - file path
' param keyword - key word
If Text.EndsWith(filepath, ".sb") Or Text.EndsWith(filepath, ".smallbasic") Then
File_Open()
File_ReadLine()
While Not[File_eof] And File_nl < 50
' p = Text.GetIndexOf(line, "'")
len = Text.GetLength(line)
' If 0 < p And p + keyword <= len Then
If Text.GetLength(keyword) <= len Then
' If Text.IsSubText(Text.GetSubTextToEnd(line, p + 1), keyword) Then
If Text.IsSubText(line, keyword) Then
' RemoveFolders()
buf = CR + LF
buf = buf + filepath + "("
buf = buf + File_nl + "):"
buf = buf + line + CR + LF
TextWindow.Write(buf)
File.AppendContents(stdout, buf)
EndIf
EndIf
File_ReadLine()
EndWhile
EndIf
EndSub
Sub RemoveFolders
' Remove folders from filepath
' param filepath
' return filepath
pSlash = 0
p = Text.GetIndexOf(filepath, "\")
If 0 < p Then
While 0 < p
pSlash = pSlash + p
p = Text.GetIndexOf(Text.GetSubTextToEnd(filepath, pSlash + 1), "\")
EndWhile
filepath = Text.GetSubTextToEnd(filepath, pSlash + 1)
EndIf
EndSub
Sub File_Open
' File | open
' param filepath
CR = Text.GetCharacter(13)
LF = Text.GetCharacter(10)
File_buf = File.ReadContents(filepath)
File_p = 1 ' buffer pointer
File_nl = 0 ' number of line
File_eof = "False"
EndSub
Sub File_ReadLine
' File | read line
' return line
eol = Text.GetIndexOf(Text.GetSubTextToEnd(File_buf, File_p), LF)
If 0 < eol Then
If Text.GetSubText(File_buf, File_p + eol - 2, 1) = CR Then
line = Text.GetSubText(File_buf, File_p, eol - 2)
Else
line = Text.GetSubText(File_buf, File_p, eol - 1)
EndIf
File_p = File_p + eol
File_nl = File_nl + 1
File_eof = "False"
Else
line = Text.GetSubTextToEnd(File_buf, File_p)
If line <> "" Then
File_nl = File_nl + 1
EndIf
File_eof = "True"
EndIf
If dump And File_nl <= 5 Then
TextWindow.ForegroundColor = "Green"
TextWindow.WriteLine(line)
TextWindow.ForegroundColor = "Gray"
EndIf
EndSub
Sub Settings_GetName
' Settings | get settings file name
' return filename
filename = File.GetSettingsFilePath()
EndSub
Sub Settings_Read
' Settings | read
' param filename
' return settings
settings = File.ReadContents(filename)
EndSub
Sub Settings_Write
' Settings | write
' param filename
' param settings
' return result
result = File.WriteContents(filename, settings)
EndSub