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
|
(* Virtual Pascal 2.1 *)
program Exemple;
(* Lit le fichier estr-tbl.txt et le convertit en unité Easter.pas *)
uses
SysUtils, WinCRT, Windows;
var
Easter : array[1900..2199] of string[5];
HrDebut, HrFin : tSystemTime;
procedure ReadEasterTable;
var
f: text;
s: string;
i, j: smallInt;
begin
Assign(f, 'estr-tbl.txt');
Reset(f);
i := 1900;
while not EOF(f) do
begin
readLn(f, s);
if (Copy(s, 2, 1) = '1') or (Copy(s, 2, 1) = '2') then
begin
for j := 0 to 9 do
begin
Easter[i + j] := Copy(s, 8 + j * 6, 5);
end;
inc(i, 10);
end;
end;
Close(f);
end;
procedure MakeUnit;
var
f: text;
s: string;
i: smallInt;
begin
assign(f, 'Easter.pas');
rewrite(f);
writeLn(f); writeLn(f, 'unit Easter;');
writeLn(f); writeLn(f, 'interface');
writeLn(f); writeLn(f, 'const');
writeLn(f, ' DateOfEaster : array [1900..2199] of string[5] = (');
for i := 1900 to 2198 do
begin
if i mod 10 = 0 then write(f, ' ');
write(f, '''' + Easter[i] + '''' + ',');
if ((i + 1) mod 10 = 0) then writeLn(f);
end;
writeLn(f, '''' + Easter[2199] + '''' + ');');
writeLn(f); writeLn(f, 'implementation');
writeLn(f); writeLn(f, 'end.');
close(f);
end;
function TEMPS_ECOULE (
HrDebut, HrFin : tSystemTime
) : Cardinal;
begin
TEMPS_ECOULE := Cardinal(HrFin.wHour) * 3600000 +
Cardinal(HrFin.wMinute) * 60000 +
Cardinal(HrFin.wSecond) * 1000 +
Cardinal(HrFin.wMilliseconds) -
Cardinal(HrDebut.wHour) * 3600000 -
Cardinal(HrDebut.wMinute) * 60000 -
Cardinal(HrDebut.wSecond) * 1000 -
Cardinal(HrDebut.wMilliseconds);
end;
begin
InitWinCRT;
GetLocalTime(HrDebut);
ReadEasterTable;
MakeUnit;
GetLocalTime(HrFin);
WriteLn('Chrono=', TEMPS_ECOULE(HrDebut,HrFin), ' ms');
ReadLn;
DoneWinCRT;
end. |
Partager