This repository was archived by the owner on Oct 11, 2022. It is now read-only.
forked from nickelsworth/swag
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path0051.pas
More file actions
242 lines (207 loc) · 6.47 KB
/
Copy path0051.pas
File metadata and controls
242 lines (207 loc) · 6.47 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
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
{**********************************************************************
** UNIT SETUP2 **
** Handles an *.INI-File similiar to Windows **
**********************************************************************
** The Setup-variables all have a unique name an can be retrieved **
** by using the name. A default-value must be given when retrieving **
** a value, so that the returned value is always valid! **
** There are different functions for different data types **
** A BAK-file is created when touching the INI-file **
** For added speed a copy of the INI file is held in variable SETUP **
**********************************************************************
** This is untested stuff, it runs flawlessly here in my programs **
** (c) 1994 by Dirk Paessler, given to the public domain **
** if you change anything please note; leave my name in here!! **
** if you have questions or suggestions, please contact me **
┌───────────────────┬─────────────┬───────────────────────────────────┐
│ Dirk Paessler │ │ E-Mail: FIDO 2:2490/1145.15 │
│ Laerchenweg 8 │Fax │ CIS 100114,42 2:2490/2091.5 │
│ D-91058 Erlangen │+499131601169│ internet 100114.42@compuserve.com │
└───────────────────┴─────────────┴───────────────────────────────────┘
usage:
USES setup2;
VAR MyData:string;
BEGIN
Mydata:=GetStrProfile('MyData','nothing yet');
WriteLn(mydata);
PutStrProfile('MyData','New stuff');
Mydata:=GetStrProfile('MyData','nothing yet');
WriteLn(mydata);
END.
}
UNIT Setup2;
INTERFACE
FUNCTION GetIntProfile(name:STRING; default:INTEGER):INTEGER;
PROCEDURE PutRealProfile(name:STRING; wert:REAL);
FUNCTION GetRealProfile(name:STRING; default:REAL):REAL;
PROCEDURE PutStrProfile(name,wert:STRING);
PROCEDURE PutBoolProfile(name:STRING; wert:BOOLEAN);
FUNCTION GetStrProfile(name,default:STRING):STRING;
FUNCTION GetNumProfile(name:STRING):REAL;
FUNCTION GetBoolProfile(name:STRING; default:BOOLEAN):BOOLEAN;
TYPE PSetup = ^Setuptype;
SetupType = ARRAY [1 .. 70] OF STRING[140];
VAR Setup : PSetup;
IMPLEMENTATION
VAR q:INTEGER;
CONST anzsetups:INTEGER=0;
newsetup:BOOLEAN=TRUE;
FUNCTION ReadALine(VAR Fil:TEXT):STRING;
VAR a:CHAR; b:STRING;
BEGIN
b:='';
a:=#13;
WHILE (a<>#10) AND NOT (EOF(FIL)) DO
BEGIN
IF a<>#13 THEN b:=b+a;
Read(fil,a);
END;
ReadAline:=b;
END;
PROCEDURE Zerleg(a:STRING; VAR b,c:STRING);
VAR i:INTEGER;
BEGIN
i:=0;
REPEAT
i:=i+1;
UNTIL (a[i]='=') OR (i>length(a));
IF i>length(a) THEN i:=length(a);
b:=copy(a,1,i-1);
c:=copy(a,i+1,length(a)-i);
END;
FUNCTION FileExist(Fname:string):BOOLEAN;
VAR f:file;
BEGIN
{$I-}
Assign(f,fname);
Reset(f);
Close(f);
{$I+}
FileExist := (IOResult=0) and (fname<>'');
END;
PROCEDURE ReadSetup;
VAR MyFil:TEXT;a,myname,wert:STRING;
BEGIN
IF NOT Fileexist('astro5.ini') THEN
BEGIN
Assign(MyFil,'astro5.ini');
Rewrite(MyFil);
WriteLn(MyFil,'; *** PSCS-Astro V5 INI ***');
Close(MyFil);
END;
IF Setup=NIL THEN
BEGIN
New(setup);
END;
Assign(MyFil,'astro5.ini');
Reset(MyFil);
q:=1;
REPEAT
REPEAT
a:=ReadALine(MyFil);
UNTIL (a[1]<>';') OR (eof(myfil));
setup^[q]:=a;
q:=q+1;
UNTIL (EOF(MyFil));
anzsetups:=q-1;
Close(MyFil);
NewSetup:=FALSE;
END;
FUNCTION GetStrProfile(name,default:STRING):STRING;
VAR MyFil:TEXT;a,myname,wert:STRING;
BEGIN
GetStrProfile:=default;
IF Fileexist('astro5.ini') THEN
BEGIN
IF Setup=NIL THEN
BEGIN
New(setup);
END;
IF NewSetup THEN ReadSetup;
q:=1;
REPEAT
Zerleg(setup^[q],MyName,wert);
q:=q+1;
UNTIL (name=MyName) OR (q>anzsetups);
IF name=MyName THEN GetStrProfile:=wert;
END;
END;
FUNCTION GetBoolProfile(name:STRING; default:BOOLEAN):BOOLEAN;
VAR hlpstrg:STRING;
BEGIN
hlpstrg:=GetStrProfile(name,'t');
GetBoolProfile := default;
IF hlpstrg='TRUE' THEN GetBoolProfile := TRUE;
IF hlpstrg='FALSE' THEN GetBoolProfile := FALSE;
END;
PROCEDURE PutBoolProfile(name:STRING; wert:BOOLEAN);
VAR hlpstrg:STRING;
BEGIN
hlpstrg:='FALSE';
IF wert THEN hlpstrg:='TRUE';
PutStrProfile(name,hlpstrg);
END;
FUNCTION GetIntProfile(name:STRING; default:INTEGER):INTEGER;
BEGIN
GetIntProfile:=Round(GetRealProfile(name,default*1.0));
END;
FUNCTION GetRealProfile(name:STRING; default:REAL):REAL;
VAR hlpstrg:STRING; i:INTEGER; a:REAL;
BEGIN
str(default,hlpstrg);
hlpstrg:=GetStrProfile(name,hlpstrg);
val(hlpstrg,a,i);
GetRealProfile:=a;
END;
PROCEDURE PutRealProfile(name:STRING; wert:REAL);
VAR hlpstrg:STRING;
BEGIN
Str(wert:1:10,hlpstrg);
PutStrProfile(name,hlpstrg);
END;
PROCEDURE PutStrProfile(name,wert:STRING);
VAR MyFil,my2fil,my3fil:TEXT;a,myname,altwert,Mywert:STRING; WasIt:BOOLEAN;
BEGIN
altwert:=getStrProfile(name,'#*äöü');
IF altwert=wert THEN exit;
IF NOT Fileexist('astro5.ini') THEN
BEGIN
Assign(MyFil,'astro5.ini');
Rewrite(MyFil);
WriteLn(MyFil,'; *** PSCS-Astro V5 INI ***');
Close(MyFil);
END;
Assign(MyFil,'astro5ini.tmp');
Rewrite(MyFil);
Assign(My2Fil,'astro5.ini');
ReSet(My2Fil);
WasIt:=FALSE;
REPEAT
a:=ReadALine(My2fil);
Zerleg(a,myname,mywert);
IF myname=name THEN BEGIN
WriteLn(myfil,name,'=',wert);
WasIt:=TRUE;
END
ELSE WriteLn(myfil,a)
UNTIL EOF(my2fil);
IF NOT WasIt THEN WriteLn(myfil,name,'=',wert);
Close(MyFil);
Close(My2Fil);
IF Fileexist('astro5.bak') THEN
BEGIN
Assign (my3fil,'astro5.bak');
erase(my3fil);
END;
Rename(My2Fil,'astro5.bak');
Rename(MyFil,'astro5.ini');
ReadSetup;
END;
FUNCTION GetNumProfile(name:STRING):REAL;
BEGIN
END;
BEGIN
END.
{be sure to insert the following line into your exit-code!!!}
IF setup<>NIL THEN Dispose(setup);