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
|
Program GetDate;
{ GetDate v1.0 1995 by Andreas Tetzl }
{ Public Domain }
{
Translated to fpc pascal
19 Mar 2001.
nils.sjoholm@mailbox.swipnet.se
}
uses amigados, strings;
const template : pchar = 'Format/K,Help/S';
version : pchar = '$VER: GetDate 1.0 (21.2.95)';
VAR DS : tDateStamp;
DT : tDateTime;
rda : pRDArgs;
WeekDay, Date, Time, hours, mins, secs, day, month, year : pchar;
vec : Array[0..1] of longint;
i : longint;
LFormat : pchar;
Procedure PrintFormat;
VAR Str : string;
tmp : string;
Begin
Str := strpas(LFormat);
tmp := '';
For i:=1 to length(Str) do
begin
If Str[i]='%' then
Begin
Case UpCase(Str[i+1]) of
('D') : tmp := tmp + strpas(Date);
('W') : tmp := tmp + strpas(WeekDay);
('T') : tmp := tmp + strpas(Time);
('H') : tmp := tmp + strpas(hours);
('M') : tmp := tmp + strpas(Mins);
('S') : tmp := tmp + strpas(Secs);
('A') : tmp := tmp + strpas(Day);
('O') : tmp := tmp + strpas(Month);
('Y') : tmp := tmp + strpas(Year);
end;
i:=i+1;
end
else
tmp := tmp + Str[i];
end;
Writeln(tmp);
end;
Procedure Help;
Begin
Writeln(#10'GetDate v1.0 1995 by Andreas Tetzl');
Writeln('Public Domain'#10);
Writeln('How to use the placeholders for Format:'#10);
Writeln(' %d : Datum');
Writeln(' %w : Weekday');
Writeln(' %t : Time with Hour, Minutes and Seconds');
Writeln(' %h : Hour');
Writeln(' %m : Minutes');
Writeln(' %s : Seconds');
Writeln(' %a : Day');
Writeln(' %o : Month');
Writeln(' %y : Year'#10);
Exit;
end;
begin
For i:=0 to 1 do Vec[i]:=0;
rda:=ReadArgs(Template,@vec,NIL);
If rda=NIL then
Begin
If PrintFault(IoErr,NIL) then;
halt(10);
end;
LFormat:=StrAlloc(100);
If StrComp(pointer(vec[0]),pchar('')) <> 0 then StrCopy(LFormat,pointer(vec[0])) else LFormat:=NIL;
If vec[1]<>0 then Help;
WeekDay:=StrAlloc(LEN_DATSTRING);
Date:=StrAlloc(LEN_DATSTRING);
Time:=StrAlloc(LEN_DATSTRING);
Hours:=StrAlloc(10);
Mins:=StrAlloc(10);
Secs:=StrAlloc(10);
Day:=StrAlloc(10);
Month:=StrAlloc(10);
Year:=StrAlloc(10);
DateStamp(pDateStamp(@DS));
DT.dat_Stamp:=DS;
DT.dat_Format:=Format_DOS;
DT.dat_StrDay:=WeekDay;
DT.dat_StrDate:=Date;
DT.dat_StrTime:=Time;
If DateToStr(@DT) then begin
StrlCopy(hours,Time,2);
StrlCopy(Mins,addr(Time[3]),2);
StrlCopy(Secs,addr(Time[6]),2);
StrlCopy(Day,Date,2);
StrlCopy(Month,addr(Date[3]),3);
StrlCopy(Year,addr(Date[7]),2);
{ In den deutschen Locale-Strings von OS3.0 scheint ein Fehler zu sein. }
{ Am Datums-String ist hinten noch ein Leerzeichen, also '16-Feb-95 '. }
{ Hier wird geprüft, ob das letzte Zeichen ein Leerzeichen ist. }
{ Das Leerzeichen wird dann durch '\0' (Stringende) ersetzt. }
If Date[StrLen(Date)-1]=' ' then Date[StrLen(Date)-1]:=#0;
end;
If LFormat=NIL then
Writeln(WeekDay,' ',Date,' ',Time)
else
PrintFormat;
StrDispose(LFormat);
StrDispose(WeekDay);
StrDispose(date);
StrDispose(Time);
StrDispose(hours);
StrDispose(mins);
StrDispose(secs);
StrDispose(Day);
StrDispose(Month);
StrDispose(Year);
end.
|