-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDataStorer.au3
174 lines (153 loc) · 5.23 KB
/
DataStorer.au3
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
; This file only constains function related to storing the hierarchy in a tree-like tructure
Func AddNode($Kind, $Module ,$Node, $Parent, $File, $CarretPos)
FileSetPos($DataFile, 0, $FILE_END)
If $Parent == "" And $Kind == "type" Then
$Parent = "ROOT"
ElseIf $Kind == "module" Then
$Module = " "
$Parent = " "
EndIf
FileWrite($DataFile, "@K="&$Kind&", @M="&$Module&", @N="&$Node&", @P="&$Parent&", @F="&$File&", @C="&$CarretPos&","&@CRLF)
EndFunc
; Search node by name and returns one data
Func GetData($Node, $Data)
FileSetPos($DataFile, 0, $FILE_BEGIN)
Local $CurrentLine = ""
Local $CurrentData
Local $RegexResult
Local $Regex
Switch $Data
Case "kind"
$Regex = "\@K=(.+?),"
Case "parent"
$Regex = "\@P=(.+?),"
Case "file"
$Regex = "\@F=(.+?),"
Case "carretpos"
$Regex = "\@C=(.+?),"
EndSwitch
FileSetPos($DataFile, 0, $FILE_BEGIN)
Do
$CurrentLine = FileReadLine($DataFile)
If @error == -1 Then
Return ""
ExitLoop
EndIf
$CurrentData = StringRegExp($CurrentLine, "\@N=(.+?),", $STR_REGEXPARRAYMATCH)
Until $Node == $CurrentData[0]
$CurrentData = StringRegExp($CurrentLine, $Regex, $STR_REGEXPARRAYMATCH)
Return $CurrentData[0]
EndFunc
; Returns an array of parent nodes, up to the root, starting with the root
Func GetParents($Node)
Local $CurrentParent = $Node
Local $ParentsArray[0]
Local $NbOfParents = 1
While $CurrentParent <> "ROOT"
ReDim $ParentsArray[$NbOfParents]
$ParentsArray[$NbOfParents-1] = $CurrentParent
$CurrentParent = GetData($CurrentParent, "parent")
If $CurrentParent == "" Then
FileWrite($Log, "ERROR : Couldn't find "&$ParentsArray[$NbOfParents-1]&"'s parent !")
$CurrentParent = "ERROR !"
ReDim $ParentsArray[$NbOfParents]
$ParentsArray[$NbOfParents-1] = $CurrentParent
ExitLoop
EndIf
$NbOfParents += 1
WEnd
_ArrayReverse($ParentsArray)
_ArrayDelete($ParentsArray, $NbOfParents)
Return $ParentsArray
EndFunc
Func DataSort()
Local $SortedDataFile = FileOpen(@ScriptDir & "\TreeHierarchySorted.csv", $FO_OVERWRITE)
Local $Line = ""
Local $LineNb = 1
Local $RegexResults
Local $CurrentModule
Local $CurrentType
FileSetPos($DataFile, 0, $FILE_BEGIN)
While True
$Line = FileReadLine($DataFile)
If @error then ExitLoop
$RegexResults = StringRegExp($Line, "\@K=(.+?),", $STR_REGEXPARRAYMATCH)
If $RegexResults[0] == "module" Then
ConsoleWrite(".")
$RegexResults = StringRegExp($Line, "\@N=(.+?),", $STR_REGEXPARRAYMATCH)
$CurrentModule = $RegexResults[0]
FileWriteLine($SortedDataFile, $Line)
FileClose($DataFile)
_FileWriteToLine(@ScriptDir & "\TreeHierarchy.csv", $LineNb, "", True)
$DataFile = FileOpen(@ScriptDir & "\TreeHierarchy.csv", 1)
FileSetPos($DataFile, 0, $FILE_BEGIN)
$LineNb = 1
While True
$Line = FileReadLine($DataFile)
If @error then ExitLoop
$RegexResults = StringRegExp($Line, "\@K=(.+?),", $STR_REGEXPARRAYMATCH)
If $RegexResults[0] == "type" Then
$RegexResults = StringRegExp($Line, "\@M=(.+?),", $STR_REGEXPARRAYMATCH)
If $RegexResults[0] == $CurrentModule Then
$RegexResults = StringRegExp($Line, "\@N=(.+?),", $STR_REGEXPARRAYMATCH)
$CurrentType = $RegexResults[0]
FileWriteLine($SortedDataFile, $Line)
FileClose($DataFile)
_FileWriteToLine(@ScriptDir & "\TreeHierarchy.csv", $LineNb, "", True)
$DataFile = FileOpen(@ScriptDir & "\TreeHierarchy.csv", 1)
FileSetPos($DataFile, 0, $FILE_BEGIN)
$LineNb = 1
While True
$Line = FileReadLine($DataFile)
If @error then ExitLoop
$RegexResults = StringRegExp($Line, "\@K=(.+?),", $STR_REGEXPARRAYMATCH)
If $RegexResults[0] == "function" Then
$RegexResults = StringRegExp($Line, "\@P=(.+?),", $STR_REGEXPARRAYMATCH)
If $RegexResults[0] == $CurrentType Then
FileWriteLine($SortedDataFile, $Line)
FileClose($DataFile)
_FileWriteToLine(@ScriptDir & "\TreeHierarchy.csv", $LineNb, "", True)
$DataFile = FileOpen(@ScriptDir & "\TreeHierarchy.csv", 1)
FileSetPos($DataFile, 0, $FILE_BEGIN)
$LineNb = 0
EndIf
EndIf
$LineNb += 1
WEnd
FileSetPos($DataFile, 0, $FILE_BEGIN)
$LineNb = 0
EndIf
EndIf
$LineNb += 1
WEnd
FileSetPos($DataFile, 0, $FILE_BEGIN)
$LineNb = 0
EndIf
$LineNb += 1
Wend
If FileGetSize(@ScriptDir & "\TreeHierarchy.csv") <> 0 Then
FileWrite($Log, "ERROR : Some items couldn't be sorted. Verify them in the file TreeHierarchy.csv"&@CRLF)
ConsoleWrite(@CRLF&"INFO : Some items couldn't be sorted. Verify them in the file TreeHierarchy.csv"&@CRLF)
EndIf
FileClose($DataFile)
$DataFile = $SortedDataFile
EndFunc
Func FindInFunctionList($String)
Local $Line = ""
Local $TempStringArray
FileSetPos($FunctionList, 0, $FILE_BEGIN)
;FileWrite($Log, 'Trying to find the function prototype for : ' & $String & @CRLF)
While 1
$Line = FileReadLine($FunctionList)
If @error = -1 Then
SetError(0)
FileWrite($Log, "ERROR : Couldn't find " & $String & " in file. Does this method exitsts ?" & @CRLF)
Return $String
EndIf
If StringInStr($Line, $String) Then
$TempStringArray = StringSplit($Line, "-")
$Line = "[" & $TempStringArray[1] & ":" & $TempStringArray[2] & "()]" & '(#' & StringLower($Line) & ')'
Return $Line
EndIf
WEnd
EndFunc