-
Notifications
You must be signed in to change notification settings - Fork 2
/
test4.pas
90 lines (81 loc) · 2.54 KB
/
test4.pas
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
program webTest;
uses
SysUtils, DateUtils, EventLog;
const
Po = '<p>'; // buka paragraf
Pc = '</p>'; // tutup paragraf
BR = '<br/>'; // baris baru
var
log: TEventLog; // objek catatan
start: TDateTime; // awal pewaktuan
// menulis kepala html
procedure writeHeader(const aTitle: string; const loadCSS: string = '');
begin
start := Now;
writeln('content-type: text/html;');
writeln; // penting!
writeln('<!DOCTYPE html>');
writeln('<html><head>');
writeln('<meta charset="utf-8">');
writeln('<meta name="viewport" content="width=device-width,initial-scale=1">');
if loadCSS <> '' then writeln('<link rel="stylesheet" href="',loadCSS,'">');
writeln('<title>',aTitle,'</title>');
writeln('</head><body>');
writeln('<!-- isi laman mulai dari sini -->');
log.Debug('#'+{$I %LINE%}+': done writing http and html header');
end;
// menulis kaki html
procedure writeFooter;
var
d: integer;
begin
d := trunc(milliSecondSpan(start,now));
writeln('<p><small>This page is served in ',d,' ms.</small></p>');
writeln('<!-- isi laman berhenti di sini -->');
writeln('</body></html>');
log.Debug('#'+{$I %LINE%}+': done writing html footer');
end;
// menulis judul html
procedure writeTitle(const aTitle: string; aLevel: integer = 1);
begin
if aLevel < 1 then aLevel := 1; // nilai terendah
if aLevel > 6 then aLevel := 6; // nilai tertinggi
writeln('<h',aLevel,'>',aTitle,'</h',aLevel,'>');
log.Debug('#'+{$I %LINE%}+': done writing html page title');
end;
// menulis span html
function span(const aText:string; const aClass:string=''; const aID:string=''): string;
begin
Result := '<span';
if aClass <> '' then Result += ' class="'+aClass+'"';
if aID <> '' then Result += ' id="'+aID+'"';
Result += '>'+aText+'</span>';
log.Debug('#'+{$I %LINE%}+': done writing html span tag');
end;
// menulis isi laman
procedure writeContent;
var
i: integer;
begin
writeln(Po,'Available environment variables:',Pc);
for i := 1 to GetEnvironmentVariableCount do
writeln(i:2,'. ',GetEnvironmentString(i),BR);
log.Debug('#'+{$I %LINE%}+': done reading environment vars');
end;
(*** program utama ***)
begin
// menyiapkan objek catatan
log := TEventLog.Create(nil);
log.logType := ltFile;
log.fileName := '/home/cabox/cgi.log';
log.identification := ExtractFilename(ParamStr(0))+':';
log.appendContent := true;
log.active := true;
// jalankan aplikasi
writeHeader('System Informations','test.css');
writeTitle('System Informations');
writeContent;
writeFooter;
// bebaskan objek catatan
log.Free;
end.