-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfut_stte.bas
More file actions
125 lines (125 loc) · 4.44 KB
/
fut_stte.bas
File metadata and controls
125 lines (125 loc) · 4.44 KB
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
Rem This file is part of the 'File Update Tool' program.
Rem Copyright (C) 2025 Ihar S. Areshchankau
Rem
Rem This program is free software: you can redistribute it and/or modify
Rem it under the terms of the GNU General Public License as published by
Rem the Free Software Foundation, either version 3 of the License, or
Rem (at your option) any later version.
Rem
Rem This program is distributed in the hope that it will be useful,
Rem but WITHOUT ANY WARRANTY; without even the implied warranty of
Rem MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Rem GNU General Public License for more details.
Rem
Rem You should have received a copy of the GNU General Public License
Rem along with this program. If not, see <https://www.gnu.org/licenses/>.
Rem
Rem ========================================================
Rem Ìîäóëü ðàáîòû ñ ñîñòîÿíèåì ñèñòåìû.
Rem Ñîñòîÿíèÿ õðàíÿòñÿ â ñòðîêàõ òåêñòîâîãî ôàéëà â ôîðìàòå:
Rem ÍàçâàíèåÑîñòîÿíèÿ=Çíà÷åíèåÑîñòîÿíèÿ.
Rem Ñòðîêà ñîñòîÿíèÿ, êîòîðîå áûëî èçìåíåíî ïîñëåäíèì,
Rem áóäåò ïîñëåäíåé ñòðîêîé â ôàéëå.
Rem ßçûê ïðîãðàììèðîâàíèÿ: FreeBasic.
Rem ========================================================
Const UBSTATE As Integer = 4
Dim Shared FileName As String
Rem ============================================
Rem Óêàçàíèå èìåíè ôàéëà ñ ñîñòîÿíèÿìè ñèñòåìû.
Rem Âûçîâ: fn - èìÿ ôàéëà ñ ñîñòîÿíèÿìè ñèñòåìû.
Rem ============================================
Public Sub stteSetFileName (ByRef fn As String)
FileName = fn
End Sub
Rem ===========================================
Rem Ïîëó÷åíèå çíà÷åíèÿ èíòåðåñóþùåãî ñîñòîÿíèÿ.
Rem Âûçîâ: StateName - íàèìåíîâàíèå ñîñòîÿíèÿ.
Rem Âîçâðàò: ñòðîêà ñî çíà÷åíèåì ñîñòîÿíèÿ
Rem èëè ïóñòàÿ ñòðîêà â ñëó÷àå îøèáêè.
Rem ===========================================
Public Function stteGetValue (ByRef StateName As Const String) As String
Dim res As String, FileNumber As Integer, StateLine As String, _
Pattern As String, lp As Integer
If "" <> FileName Then
Pattern = StateName + "="
lp = Len (Pattern)
FileNumber = FreeFile
Open FileName For Input As #FileNumber
While 0 = Err AndAlso 0 = EOF (FileNumber)
Line Input #FileNumber, StateLine
If 0 = Err AndAlso "" <> StateLine Then
If Left (StateLine, lp) = Pattern Then
res = Mid (StateLine, lp + 1)
End If
End If
Wend
Close #FileNumber
End If
stteGetValue = res
End Function
Rem =====================================================
Rem Óñòàíîâêà çíà÷åíèÿ ñîñòîÿíèÿ.
Rem Âûçîâ: StateName - íàèìåíîâàíèå ñîñòîÿíèÿ,
Rem StateValue - çíà÷åíèå ñîñòîÿíèÿ.
Rem Âîçâðàò: -1 - çíà÷åíèå ñîñòîÿíèÿ óñòàíîâëåíî óñïåøíî,
Rem 0 - îøèáêà óñòàíîâêè çíà÷åíèÿ ñîñòîÿíèÿ
Rem =====================================================
Public Function stteSetValue (ByRef StateName As Const String, ByRef StateValue As Const String) As Integer
Dim res As Integer, FileNumber As Integer, StateLines (UBSTATE) As String, _
i As Integer, n As Integer, Pattern As String, PatternLen As Integer, _
StateLine As String
res = -1
Pattern = StateName + "="
PatternLen = Len (Pattern)
If "" <> FileName Then
Rem Ñ÷èòûâàíèå ñòðîê èç ôàéëà ñîñòîÿíèé ñèñòåìû.
FileNumber = FreeFile
Open FileName For Input As #FileNumber
If 0 = Err Then
While 0 = Err AndAlso 0 = EOF (FileNumber) AndAlso n <= UBSTATE
Line Input #FileNumber, StateLine
StateLine = Trim (StateLine)
Rem Ïðîïóñê ïóñòûõ ñòðîê è ñòðîêè ñ èçìåíÿåìûì ñîñòîÿíèåì.
If "" <> StateLine AndAlso Left (StateLine, PatternLen) <> Pattern Then
StateLines(n) = StateLine
n += 1
End If
Wend
If 0 <> Err Then
Rem Îøèáêà ïðè ÷òåíèè ôàéëà.
res = 0
End If
Close #FileNumber
Else
Rem Îøèáêà ïðè îòêðûòèè ôàéëà äëÿ ÷òåíèÿ.
res = 0
End If
If -1 = res Then
If n <= UBSTATE Then
Rem Äîáàâëåíèå ñòðîêè ñ óñòàíàâëèâàåìûì ñîñòîÿíèåì.
StateLines(n) = Pattern + StateValue
Rem Ñîõðàíåíèå ñîñòîÿíèé â ôàéë.
i = 0
Open FileName For Output As #FileNumber
If 0 = Err Then
While 0 = Err AndAlso i <= n
Print #FileNumber, StateLines(i)
i += 1
Wend
If 0 <> Err Then
Rem Îøèáêà ïðè çàïèñè â ôàéë.
res = 0
End If
Close #FileNumber
Else
Rem Îøèáêà ïðè îòêðûòèè ôàéëà äëÿ çàïèñè.
res = 0
End If
Else
Rem Íåò ìåñòà äëÿ íîâîãî ïàðàìåòðà.
res = 0
End If
End If
End If
stteSetValue = res
End Function