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 path0098.pas
More file actions
392 lines (322 loc) · 9.21 KB
/
Copy path0098.pas
File metadata and controls
392 lines (322 loc) · 9.21 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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
{ I made this to time stamp my programs with a time stamp giving the
version no. Much of it is courtesy of SWAG and TP6's on line help.
Use, improve, modify or whatever, but at one's own risk.
Albert L. Fowler.
Kircaldy, Scotland }
{------------------------------------------------------------------}
Program time_and_date_stamp_the_passed_file; { stamp_it.pas }
(* A file date and time stamping facility.
By A. L. Fowler 10th November 1996 *)
Uses
Dos, Crt, List_A; { for List_A.pas see below }
Var
hrs, mins : Word; { to set time stamp }
Function LeadingZero (w : Word) : String;
Var
s : String;
Begin
Str (w : 0, s);
If Length (s) = 1 Then
s := '0' + s;
LeadingZero := s;
End;
Procedure header;
Begin
GotoXY (4, 1);
TextColor (14);
Write ('STAMP_IT A File Time & Date Updating Facility. By A. L. Fowler. 1996');
NormVideo;
End;
Procedure check_passed_param;
Var
s : String [80];
f : Text;
ft : LongInt; { For Get/SetFTime }
dt : DateTime; { For Pack/UnpackTime }
Begin
GetDir (0, s); { 0 = Current drive }
If ( ParamCount <> 1 ) Then
Begin
header;
GotoXY (14, 4);
TextColor (10);
Write ('STAMP_IT Does not have a following filename');
GotoXY (8, 6);
Write ('e.g. ', s, '\STAMP_IT [drive:][path][filename]');
NormVideo;
GotoXY (1, 24);
Halt (1);
End;
If Not FileExists (ParamStr (1) ) Then
Begin
header;
TextColor (10);
GotoXY (8, 4);
Write (' File ', UpperCase (ParamStr (1) ), ' not found.');
GotoXY (8, 6);
Write ('Syntax ', s, '\STAMP_IT [drive:][path][filename]');
NormVideo;
GotoXY (1, 24);
Halt (2);
End
Else
GotoXY (4, 3);
TextColor (11);
Write (UpperCase (ParamStr (1) ) );
Assign (f, ParamStr (1) );
Reset (f); { Open specified File }
GetFTime (f, ft); { Get creation time }
UnpackTime (ft, dt);
With dt Do
Begin
Write (' [ Time Stamped ', LeadingZero (hour), ':', LeadingZero (min),
':', LeadingZero (sec), ' & Dated ', day, '-', month, '-', year, ' ]');
End;
GotoXY (4, 4);
WriteLn ('Will be Stamped with Today''s Date & given a Time Stamp you can choose.');
NormVideo;
End;
Procedure choose_time_stamp;
Var
yn, ap, Confirm : Char;
_h, _m : String [3];
c, h, inp : Integer;
Label
again, h1, m1;
Begin
hrs := 0;
mins := 0;
_h := '0';
_m := '0';
FlushKeyBuffer;
again :
GotoXY (4, 6);
TextColor (10);
Write ('Is the Default Time Stamp of 12:01a Acceptable? Y/N ');
CursorOff;
yn := ReadKey;
If yn = #13 Then
Goto again;
If yn = #27 Then
Begin
CursorOn;
NormVideo;
GotoXY(1, 24);
Halt (3);
End;
If Not ( UpCase (yn) In [ 'N', 'Y'] ) Then
Begin { Only accept y or n }
Alarm;
Goto again;
End
Else
If UpCase (yn) = 'N' Then { User time stamp requested }
Begin { of user input }
h1 : { Do not accept nul or error input }
GotoXY (4, 8);
Write ('Enter hours. ');
ReadLn (_h);
If _h = '0' Then
_h := '00'; { ok its a bodge }
If Ord (_h [0]) >= 3 Then { oversize hours inputs }
Begin
GotoXY (17, 8);
Write (' Input not recognised, enter again. ');
Alarm;
Goto h1;
End;
{ First delete any leading zeros in the hours string }
If (Ord (_h [0]) >= 1) And (_h [1] = '0') Then
_h := Copy (_h, 2, Ord (_h [0]) - 1);
Val (_h, hrs, c); { Convert to hrs }
If ( c <> 0 ) Or ( hrs > 23 ) Then { Rubbish inputs }
Begin
GotoXY (17, 8);
Write (' Hours in the Range 0 to 23 please. ');
Alarm;
Goto h1;
End;
m1 : { Do not accept nul or error input }
GotoXY (4, 10);
Write ('Enter mins. ');
ReadLn (_m);
If _m = '0' Then
_m := '00'; { ok its another bodge }
If Ord (_m [0]) >= 3 Then { oversize mins inputs }
Begin
GotoXY (17, 10);
Write (' Input not recognised, enter again. ');
Alarm;
Goto m1;
End;
{ First delete any leading zeros in the mins string }
If (Ord (_m [0]) >= 1) And (_m [1] = '0') Then
_m := Copy (_m, 2, Ord (_m [0]) - 1);
Val (_m, mins, c); { Convert to min }
If ( c <> 0 ) Or ( mins > 59 ) Then { Rubbish inputs }
Begin
GotoXY (17, 10);
Write (' Minutes in the Range 0 to 59 please. ');
Alarm;
Goto m1;
End;
End; { of user input }
If UpCase (yn) = 'Y' Then { User accepts 12:01a }
Begin
_h := '0';
Val (_h, hrs, c); { Convert to hrs }
_m := '1';
Val (_m, mins, c); { Convert to min }
End;
Begin { Section produces time in am pm format }
If hrs < 12 Then { now convert hrs & mins for user to see }
Begin
ap := 'a';
If hrs = 0 Then
_h := '12';
End
Else
Begin
ap := 'p';
h := hrs - 12; { to display in am pm format }
Str (h, _h);
End;
If mins < 10 Then
_m := '0' + _m;
End; { am pm on screen information }
GotoXY (4, 12);
Write ('File will be Time Stamped ', _h, ':', _m, ap);
GotoXY (4, 14);
Write ('Is this acceptable? . . . . Y/N ');
Confirm := ReadKey;
If (Confirm = #27) Or (Confirm = #110) Or (Confirm = #78) Then
Begin { Esc , N or n pressed }
GotoXY (4, 14);
Write ('Exit confirmed, file has not been changed.');
CursorOn;
GotoXY (1, 24);
NormVideo;
Halt (4);
End;
If (Confirm = #89) Or (Confirm = #121) Then
GotoXY (1, 24);
CursorOn;
NormVideo;
End;
Procedure stamp_file;
Var
f : Text;
ftime : LongInt; { For Get/SetFTime }
dt : DateTime; { For Pack/UnpackTime }
year, month, day, DofW : Word; { for GetDate }
Begin
Assign (f, ParamStr (1) );
GetDate (year, month, day, DofW); { Today''s Date }
Reset (f); { Open existing File }
GetFTime (f, ftime); { Get old creation time }
UnpackTime (ftime, dt);
GotoXY (4, 17);
TextColor (11);
With dt Do
Begin
Write ('Old File TimeStamp was: ', LeadingZero (hour), ':', LeadingZero
(min), ':', LeadingZero (sec), ' Dated: ', day, '-', month, '-', year);
GetDate (year, month, day, DofW); { Again to Set/Confirm today's date }
hour := hrs;
min := mins; { These for chosen time stamp }
sec := 0;
PackTime (dt, ftime);
Reset (f);
{ Re-open File For reading otherwise, close will update time }
SetFTime (f, ftime);
GetFTime (f, ftime); { Get new creation time }
UnpackTime (ftime, dt);
GotoXY (4, 19);
With dt Do
Begin
Write ('New File TimeStamp is: ', LeadingZero (hour), ':',
LeadingZero (min),
':', LeadingZero (sec), ' Dated: ', day, '-', month, '-', year );
End;
End;
GotoXY (1, 24);
Close (f); { Close File }
NormVideo;
End;
Begin
ClrScr;
check_passed_param;
header;
choose_time_stamp;
stamp_file;
End.
{-------------------------------------------------------------------------}
Unit LIST_A;
(* LIST_A a simple list, used in STAMPIT, etc. *)
Interface
Uses Crt, Dos;
Procedure CursorOff;
Procedure CursorOn;
Procedure FlushKeyBuffer;
Procedure Alarm;
Function FileExists (FileName : String) : Boolean;
Function UpperCase (s : String) : String;
Implementation
{*****************************************************************************}
Procedure CursorOff;
Assembler;
Asm
MOV ax, $0100
MOV cx, $2607
Int $10
End;
Procedure CursorOn;
Assembler;
Asm
MOV ax, $0100
MOV cx, $0506
Int $10
End;
Procedure FlushKeyBuffer;
Var
recpack : Registers;
Begin
With recpack Do
Begin
ax := ($0c ShL 8) Or 6;
dx := $00ff;
End;
Intr ($21, recpack);
End; {FlushKeyBuffer}
Function FileExists (FileName : String) : Boolean;
{ Returns True if file exists; otherwise, it returns False.
Closes the file and exists. }
Var
f : File;
Begin
{$I-}
Assign (f, FileName);
Reset (f);
Close (f);
{$I+}
FileExists := (IOResult = 0) And (FileName <> '');
End; { FileExists }
Function UpperCase (s : String) : String;
Var
I : Integer;
Begin
For I := 1 To Ord (s [0]) Do
If s [I] In ['a'..'z'] Then
Dec (s [I], 32);
UpperCase := s;
End;
Procedure Alarm;
Begin
Sound (466);
Delay (150);
Sound (349);
Delay (200);
NoSound;
End;
End.