-
Notifications
You must be signed in to change notification settings - Fork 1
/
PRINTF.PAS
100 lines (95 loc) · 1.95 KB
/
PRINTF.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
{ @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 PRINTF;
Var
CurrParam:Integer;
Function PadZeroLeft(Value:String;Space:Byte):String;
Var
S:String;
Begin
S:=Value;
While Length(S)<Space do S:='0'+S;
PadZeroLeft:=S;
End;
Function FormatString(S:String):String;
Var
I,PadLeft:Integer;
Err:Word;
R,T:String;
ValueStr:String;
Begin
R:='';
I:=1;
While I<=Length(S)do Begin
If S[I]='\'Then Begin
Inc(I);
If I>Length(S)Then Break;
Case S[I]of
'0':R:=R+#0;
'a':R:=R+#7;
'b':R:=R+#8;
'f':R:=R+#12;
'n':R:=R+#10;
'r':R:=R+#13;
't':R:=R+#9;
'v':R:=R+#11;
'\':R:=R+'\';
'''':R:=R+'''';
'"':R:=R+'"';
'?':R:=R+'?';
End;
End
Else
If S[I]='%'Then Begin
Inc(I);
If I>Length(S)Then Break;
Case S[I]of
'c':Begin
ValueStr:=ParamStr(CurrParam);
Inc(CurrParam);
If Length(ValueStr)>0 Then R:=R+ValueStr[1];
End;
'd','f','g','i','l':Begin
T:=ParamStr(CurrParam);
Inc(CurrParam);
R:=R+T;
End;
'0'..'9':Begin
T:='';
While(S[I]in['0'..'9'])and(I<=Length(S))do Begin
T:=T+S[I];
Inc(I);
End;
Val(T,PadLeft,Err);
R:=R+PadZeroLeft(ParamStr(CurrParam),PadLeft);
Inc(CurrParam);
End;
End;
End
Else
R:=R+S[I];
Inc(I);
End;
FormatString:=R;
End;
BEGIN
If(ParamStr(1)='/?')or(ParamStr(1)='--help')or(ParamStr(1)='-h')or
(ParamStr(1)='/h')or(ParamStr(1)='/H')Then Begin
WriteLn('PRINTF : Cette commande permet d''afficher un message avec ',
'le format sp‚cifi‚.');
WriteLn;
WriteLn('Syntaxe : PRINTF format [arguments]');
WriteLn;
WriteLn(' format Indique la chaine de caractŠres de format');
WriteLn(' arguments Indique les diff‚rentes valeurs');
WriteLn;
End
Else
If ParamCount>0Then Begin
CurrParam:=2;
Write(FormatString(ParamStr(1)));
End;
END.