-
Notifications
You must be signed in to change notification settings - Fork 1
/
LOOK.PAS
98 lines (93 loc) · 2.2 KB
/
LOOK.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
{ @author: Sylvain Maltais (support@gladir.com)
@created: 2022
@website(https://www.gladir.com/linux-0)
@abstract(Target: Turbo Pascal, Free Pascal)
}
Program LOOK;
Var
Option:Set Of (IgnoreCase);
Handle:Text;
I,J:Integer;
Mode:(_None,_text,_file);
TextSearch,FileName,CurrLine:String;
Function StrToUpper(S:String):String;
Var
I:Byte;
Begin
For I:=1 to Length(S)do Begin
If S[I] in['a'..'z']Then S[I]:=Chr(Ord(S[I])-32);
End;
StrToUpper:=S;
End;
Function TrimL(S:String):String;
Var
I:Byte;
Begin
For I:=1to Length(S)do Begin
If S[I]<>' 'Then Begin
TrimL:=Copy(S,I,255);
Exit;
End;
End;
TrimL:=S;
End;
BEGIN
If(ParamStr(1)='/?')or(ParamStr(1)='--help')or(ParamStr(1)='-h')or
(ParamStr(1)='/h')or(ParamStr(1)='/H')Then Begin
WriteLn('LOOK : Cette commande permet de rechercher les lignes ',
'commen‡ant par une texte specifie.');
WriteLn;
WriteLn('Syntaxe : LOOK texte fichier');
WriteLn;
WriteLn(' fichier Ce paramŠtre permet d''indiquer le fichier a analyser');
WriteLn(' texte Ce paramŠtre optionnel permet d''indiquer le texte … ',
'rechercher.');
End
Else
If ParamCount>1Then Begin
Option:=[];
TextSearch:='';
FileName:='';
Mode:=_text;
For I:=1 to ParamCount do Begin
If(ParamStr(I)='-f')or(ParamStr(I)='--ignore-case')Then Include(Option,IgnoreCase) Else
If Mode=_Text Then Begin
TextSearch:=ParamStr(I);
Mode:=_File;
End
Else
If Mode=_File Then Begin
FileName:=ParamStr(I);
Mode:=_None;
End
Else
Begin
WriteLn('Parametre non reconnu : ',ParamStr(I));
End;
End;
If FileName<>''Then Begin
Assign(Handle,FileName);
{$I-}Reset(Handle);{$I+}
If IOResult=0Then Begin
While NOT EOF(Handle)do Begin
ReadLn(Handle,CurrLine);
If(IgnoreCase in Option)Then Begin
If(StrToUpper(Copy(TrimL(CurrLine),1,Length(TextSearch)))=
StrToUpper(TextSearch))Then Begin
WriteLn(CurrLine);
End;
End
Else
If(Copy(TrimL(CurrLine),1,Length(TextSearch))=TextSearch)Then Begin
WriteLn(CurrLine);
End;
End;
Close(Handle);
End;
End
Else
WriteLn('Fichier attendu');
End
Else
WriteLn('ParamŠtre insuffisant');
END.