-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSEQ.PAS
188 lines (183 loc) · 3.79 KB
/
SEQ.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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
{ @author: Sylvain Maltais ([email protected])
@created: 2023
@website(https://www.gladir.com/linux-0)
@abstract(Target: Turbo Pascal 7, Free Pascal 3.2)
}
Program SEQ;
Var
EqualWidth:Boolean;
ModeParam:(_None,_Format,_Separator);
Value:Array[0..2]of LongInt;
First,Last,Step:LongInt;
I,PosValue:Integer;
Err:Word;
Format,Separator,LastS:String;
Function PadZeroLeft(Value:Integer;Space:Byte):String;
Var
S:String;
Begin
Str(Value,S);
While Length(S)<Space do S:='0'+S;
PadZeroLeft:=S;
End;
Function FormatString(S:String;Value:LongInt):String;
Var
I,PadLeft:Integer;
Err:Word;
R,T: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':R:=R+Char(Value);
'd','f','g','i','l':Begin
Str(Value,T);
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(Value,PadLeft);
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('SEQ : Cette commande permet de g‚n‚rer des nombres selon ',
'l''intervalle et le saut sp‚cifi‚.');
WriteLn;
WriteLn('Syntaxe : SEQ [options] last');
WriteLn(' SEQ [options] first last');
WriteLn(' SEQ [options] first incremental last');
WriteLn;
WriteLn(' first Indique le d‚but de la boucle');
WriteLn(' last Indique la fin de la boucle');
WriteLn(' incremental Indique le saut de la boucle');
WriteLn(' -f format Indique un format de formatage');
WriteLn(' -s chaine Indique le s‚parateur de valeur');
WriteLn(' -w Indique qu''il faut ‚galiser la largeur des nombres');
WriteLn;
End
Else
If ParamCount>0Then Begin
EqualWidth:=False;
Separator:='';
ModeParam:=_None;
Format:='';
PosValue:=0;
First:=1;
Last:=0;
Step:=1;
FillChar(Value,SizeOf(Value),0);
For I:=1 to ParamCount do Begin
Case ModeParam of
_Format:Begin
ModeParam:=_None;
Format:=ParamStr(I);
End;
_Separator:Begin
ModeParam:=_None;
Separator:=ParamStr(I);
End;
Else Begin
If(ParamStr(I)='-w')or(ParamStr(I)='--equal-width')Then Begin
EqualWidth:=True;
End
Else
If ParamStr(I)='-f'Then Begin
ModeParam:=_Format;
End
Else
If ParamStr(I)='-s'Then Begin
ModeParam:=_Separator;
End
Else
If PosValue<=2 Then Begin
Val(ParamStr(I),Value[PosValue],Err);
Inc(PosValue);
End
Else
Begin
WriteLn('Trop de paramŠtre !');
Halt(1);
End;
End;
End;
End;
Case PosValue of
1:Last:=Value[0];
2:Begin
First:=Value[0];
Last:=Value[1];
End;
3:Begin
First:=Value[0];
Step:=Value[1];
Last:=Value[2];
End;
Else Begin
WriteLn('Nombre de paramŠtre invalide !');
Halt(2);
End;
End;
I:=First;
Str(Last,LastS);
While(I<=Last)do Begin
If Format<>''Then Begin
If Separator<>''Then Begin
Write(FormatString(Format,I),Separator);
End
Else
WriteLn(FormatString(Format,I));
End
Else
Begin
If(EqualWidth)Then Begin
Write(PadZeroLeft(I,Length(LastS)));
End
Else
Write(I);
If Separator<>''Then Begin
Write(Separator);
End
Else
WriteLn;
End;
Inc(I,Step);
End;
End;
END.