-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathWHICH.PAS
73 lines (68 loc) · 1.61 KB
/
WHICH.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
{ @author: Sylvain Maltais ([email protected])
@created: 2022
@website(https://www.gladir.com/linux-0)
@abstract(Target: Turbo Pascal, Free Pascal)
}
Program WHICH;
Uses DOS;
Var
J,I:Integer;
PATH,TPath,FullName:String;
Function FileExist(Name:String):Boolean;
Var
Rec:SearchRec;
Begin
FindFirst(Name,AnyFile,Rec);
FileExist:=DosError=0;
End;
BEGIN
If(ParamStr(1)='/?')or(ParamStr(1)='--help')or(ParamStr(1)='-h')or
(ParamStr(1)='/h')or(ParamStr(1)='/H')Then Begin
WriteLn('WHICH : Cette commande permet de localiser l''emplacement ',
'd''une commande.');
WriteLn;
WriteLn('Syntaxe : WHICH nomdufichier');
End
Else
Begin
For J:=1 to ParamCount do Begin
PATH:=GetEnv('PATH');
TPath:='';
For I:=1 to Length(PATH)do Begin
If PATH[I]=';'Then Begin
FullName:=FExpand(TPath);
If Not(FullName[Length(FullName)]in['\','/'])Then FullName:=FullName+'\';
FullName:=FullName+ParamStr(1);
If FileExist(FullName)Then Begin
WriteLn(FullName);
TPath:='';
Break;
End;
If FileExist(FullName+'.EXE')Then Begin
WriteLn(FullName,'.EXE');
TPath:='';
Break;
End;
TPath:='';
End
Else
TPath:=TPath+Path[I];
End;
If TPath<>''Then Begin
FullName:=FExpand(TPath);
If Not(FullName[Length(FullName)]in['\','/'])Then FullName:=FullName+'\';
FullName:=FullName+ParamStr(1);
If FileExist(FullName)Then Begin
WriteLn(FullName);
TPath:='';
Break;
End;
If FileExist(FullName+'.EXE')Then Begin
WriteLn(FullName,'.EXE');
TPath:='';
Break;
End;
End;
End;
End;
END.