-
Notifications
You must be signed in to change notification settings - Fork 1
/
GETENT.PAS
141 lines (137 loc) · 3.57 KB
/
GETENT.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
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
{ @author: Sylvain Maltais (support@gladir.com)
@created: 2024
@website(https://www.gladir.com/linux-0)
@abstract(Target: Turbo Pascal 7, Free Pascal 3.2)
}
Program GETENT;
Var
ModeOutput:(_Raw,_CSV,_TSV,_HTML,_XML);
I:Integer;
FileName,KeyName:String;
Procedure ReadFileEtc(FileName:String);
Var
FileEtc:Text;
I:Integer;
Skip:Boolean;
CurrLine,CurrWord:String;
Begin
{$I-}Assign(FileEtc,'/etc/'+FileName);
Reset(FileEtc);{$I+}
If IOResult<>0 Then Begin
WriteLn('Erreur de lecture du fichier /etc/',FileName);
Halt(1);
End;
Case ModeOutput of
_HTML:WriteLn('<table>');
_XML:Begin
WriteLn('<?xml version="1.0" encoding="UTF-8"?>');
WriteLn('<table>');
End;
End;
While Not EOF(FileEtc)do Begin
ReadLn(FileEtc,CurrLine);
If KeyName<>''Then Begin
Skip:=True;
CurrWord:='';
For I:=1 to Length(CurrLine)do Begin
If CurrLine[I]=':'Then Begin
If(CurrWord=KeyName)Then Skip:=False;
Break;
End
Else
CurrWord:=CurrWord+CurrLine[I];
End;
End
Else
Skip:=False;
If Not(Skip)Then Case ModeOutput of
_CSV:Begin
For I:=1 to Length(CurrLine)do Begin
If CurrLine[I]=':'Then Write(',')
Else Write(CurrLine[I]);
End;
WriteLn;
End;
_HTML:Begin
WriteLn(' ':4,'<tr>');
Write(' ':8,'<td>');
For I:=1 to Length(CurrLine)do Begin
If CurrLine[I]=':'Then Begin
WriteLn('</td>');
Write(' ':8,'<td>');
End
Else
Write(CurrLine[I]);
End;
WriteLn('</td>');
WriteLn(' ':4,'</tr>');
End;
_TSV:Begin
For I:=1 to Length(CurrLine)do Begin
If CurrLine[I]=':'Then Write(#9)
Else Write(CurrLine[I]);
End;
WriteLn;
End;
_XML:Begin
WriteLn(' ':4,'<line>');
Write(' ':8,'<colonne>');
For I:=1 to Length(CurrLine)do Begin
If CurrLine[I]=':'Then Begin
WriteLn('</td>');
Write(' ':8,'<colonne>');
End
Else
Write(CurrLine[I]);
End;
WriteLn('</colonne>');
WriteLn(' ':4,'</line>');
End;
Else WriteLn(CurrLine);
End;
End;
If(ModeOutput in [_HTML,_XML])Then WriteLn('</table>');
Close(FileEtc);
End;
BEGIN
If(ParamStr(1)='/?')or(ParamStr(1)='--help')or(ParamStr(1)='-h')or
(ParamStr(1)='/h')or(ParamStr(1)='/H')Then Begin
WriteLn('GETENT : Cette commande permet de demander les entr‚es de la ',
'base de donn‚es administrative.');
WriteLn;
WriteLn('Syntaxe : GETENT [option] database key ');
WriteLn;
WriteLn(' database Indique le nom de la base de donn‚es.');
WriteLn(' key Indique le nom de la clef … rechercher.');
WriteLn(' --help Affiche l''aide sur cette commande.');
WriteLn(' --output:format Formatage de sortie : CSV, HTML, TSV ou XML.');
WriteLn(' --version Indique la version de la commande.');
End
Else
If(ParamStr(1)='-v')or(ParamStr(1)='--version')Then Begin
WriteLn('GETENT 1.0 - Clone Pascal de linux, freebsd ou corail');
WriteLn('Licence MIT');
WriteLn;
WriteLn('crit par Sylvain Maltais');
End
Else
If ParamCount>0 Then Begin
ModeOutput:=_Raw;
FileName:='';
KeyName:='';
For I:=1 to ParamCount do Begin
If ParamStr(I)='--output:csv'Then ModeOutput:=_CSV Else
If ParamStr(I)='--output:html'Then ModeOutput:=_HTML Else
If ParamStr(I)='--output:tsv'Then ModeOutput:=_TSV Else
If ParamStr(I)='--output:xml'Then ModeOutput:=_XML Else
If FileName=''Then FileName:=ParamStr(I)
Else KeyName:=ParamStr(I);
End;
If FileName<>''Then ReadFileEtc(FileName)
Else
Begin
WriteLn('Nom de base de donn‚e requis !');
Halt(2);
End;
End;
END.