-
Notifications
You must be signed in to change notification settings - Fork 5
/
APPLY.PAS
83 lines (78 loc) · 1.9 KB
/
APPLY.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
{ @author: Sylvain Maltais ([email protected])
@created: 2022
@website(https://www.gladir.com/corail)
@abstract(Target: Turbo Pascal, Free Pascal)
}
Program APPLY;
{$M 16384,0,0}
Uses DOS;
Var
I:Integer;
NoFile:Boolean;
FileASCII:Text;
CurrParam,CurrCommand,Command,FileName,CurrLine:String;
BEGIN
If(ParamStr(1)='/?')or(ParamStr(1)='--help')or(ParamStr(1)='-h')or
(ParamStr(1)='/h')or(ParamStr(1)='/H')Then Begin
WriteLn('APPLY : Cette commande permet d''appliquer des commandes ',
'… plusieurs reprises.');
WriteLn;
WriteLn('Syntaxe : APPLY fichier "command"');
End
Else
If ParamCount>0 Then Begin
Command:='';
FileName:='';
NoFile:=False;
For I:=1 to ParamCount do Begin
CurrParam:=ParamStr(I);
If CurrParam='-'Then NoFile:=True Else
If Copy(CurrParam,1,1)='"'Then Begin
Command:=Copy(CurrParam,2,Length(CurrParam)-2);
End
Else
If Pos('.',CurrParam)>0 Then Begin
FileName:=CurrParam;
End
Else
Command:=CurrParam;
End;
If Command=''Then Begin
WriteLn('Commande requise');
End
Else
If NoFile Then Begin
If Pos('%',Command)>0 Then Begin
CurrCommand:=Copy(Command,1,Pos('%',Command)-1)+
Copy(Command,Pos('%',Command)+1,255);
End
Else
CurrCommand:=Command;
Exec(GetEnv('COMSPEC'),'/C '+CurrCommand);
End
Else
If FileName=''Then Begin
WriteLn('Nom de fichier absent');
End
Else
Begin
{$I-}Assign(FileASCII,FileName);
Reset(FileASCII);{$I+}
If IOResult=0 Then Begin
While Not(EOF(FileASCII))do Begin
ReadLn(FileASCII,CurrLine);
If Pos('%',Command)>0 Then Begin
CurrCommand:=Copy(Command,1,Pos('%',Command)-1)+CurrLine+
Copy(Command,Pos('%',Command)+1,255);
End
Else
CurrCommand:=Command;
Exec(GetEnv('COMSPEC'),'/C '+CurrCommand);
End;
Close(FileASCII);
End;
End;
End
Else
WriteLn('ParamŠtre requis !');
END.