-
Notifications
You must be signed in to change notification settings - Fork 0
/
JOT.PAS
314 lines (306 loc) · 7.87 KB
/
JOT.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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
{ @author: Sylvain Maltais (support@gladir.com)
@created: 2024
@website(https://www.gladir.com/freebsd-0)
@abstract(Target: Turbo Pascal 7, Free Pascal 3.2)
}
Program JOT;
Uses DOS;
Var
Language:(_Albanian,_French,_English,_Germany,_Italian,_Spain);
TmpLanguage:String;
ModeParam:(_None,_BWord,_Precision,_Separator,_Format);
Value:Array[0..3]of Real;
SkipValue:Array[0..3]of Boolean;
First,Last,Step,IR:Real;
I,PosValue,Precision:Integer;
PrintChar,NewLine,RandomValue:Boolean;
Err:Word;
BWord,Separator,Format: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 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:Real):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(Trunc(Value));
'f':Begin
Str(Value,T);
R:=R+T;
End;
'd','g','i','l':Begin
Str(Trunc(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(Trunc(Value),PadLeft);
End;
End;
End
Else
R:=R+S[I];
Inc(I);
End;
FormatString:=R;
End;
BEGIN
Language:=_French;
TmpLanguage:=GetEnv('LANGUAGE');
If TmpLanguage<>''Then Begin
If TmpLanguage[1]='"'Then TmpLanguage:=Copy(TmpLanguage,2,255);
If StrToUpper(Copy(TmpLanguage,1,2))='EN'Then Language:=_English Else
If StrToUpper(Copy(TmpLanguage,1,2))='GR'Then Language:=_Germany Else
If StrToUpper(Copy(TmpLanguage,1,2))='IT'Then Language:=_Italian Else
If StrToUpper(Copy(TmpLanguage,1,2))='SP'Then Language:=_Spain Else
If(StrToUpper(Copy(TmpLanguage,1,2))='SQ')or
(StrToUpper(Copy(TmpLanguage,1,3))='ALB')Then Language:=_Albanian;
End;
If(ParamStr(1)='/?')or(ParamStr(1)='--help')or(ParamStr(1)='-h')or
(ParamStr(1)='/h')or(ParamStr(1)='/H')Then Begin
Case Language of
_English:Begin
WriteLn('jot : print sequential or random data');
WriteLn;
WriteLn('Syntax: jot [-cnr] [-b word] [-w word] [-s string]',
' [-p precision] [reps [begin [end [s]]]]');
WriteLn;
WriteLn(' -r Generate random data instead of the default sequential data.');
WriteLn(' -b word Just print word repetitively.');
WriteLn(' -w word Print word with the generated data appended to it.');
WriteLn(' -c This is an abbreviation for -w %c.');
WriteLn(' -s string Print data separated by string.');
WriteLn(' -n Do not print the final newline normally appended to the output.');
WriteLn(' -p precision Print only as many digits or characters of the data as ',
'indicated by the integer precision.');
End;
Else Begin
WriteLn('JOT : Cette commande permet d''afficher des donn‚es ',
's‚quentiel ou al‚atoire.');
WriteLn;
WriteLn('Syntaxe : JOT [options] [reps [first [last [step]]]]');
WriteLn;
WriteLn(' first Indique le d‚but de la boucle');
WriteLn(' last Indique la fin de la boucle');
WriteLn(' reps Indique le nombre de r‚p‚tition');
WriteLn(' step Indique le saut de la boucle');
WriteLn(' -b word Affiche le mot sp‚cifi‚');
WriteLn(' -c Affiche le nombre en caractŠre');
WriteLn(' -n N''affiche pas de saut de ligne');
WriteLn(' -p precision Indique le nombre de chiffre de pr‚cision');
WriteLn(' -r G‚nŠre des nombres al‚atoires');
WriteLn(' -s separator Indique le s‚parateur entre les ‚l‚ments');
WriteLn(' -w format Utilise un format d''affichage style printf.');
WriteLn;
End;
End;
End
Else
If ParamCount>0Then Begin
ModeParam:=_None;
Separator:='';
BWord:='';
Format:='';
First:=1;
Last:=1;
Step:=1;
PosValue:=0;
Precision:=0;
PrintChar:=False;
NewLine:=True;
RandomValue:=False;
FillChar(Value,SizeOf(Value),0);
FillChar(SkipValue,SizeOf(SkipValue),0);
For I:=1 to ParamCount do Begin
Case ModeParam of
_BWord:Begin
BWord:=ParamStr(I);
ModeParam:=_None;
End;
_Format:Begin
Format:=ParamStr(I);
ModeParam:=_None;
End;
_Precision:Begin
Val(ParamStr(I),Precision,Err);
ModeParam:=_None;
End;
_Separator:Begin
Separator:=ParamStr(I);
ModeParam:=_None;
End;
Else Begin
If ParamStr(I)='-b'Then ModeParam:=_BWord Else
If ParamStr(I)='-c'Then PrintChar:=True Else
If ParamStr(I)='-cn'Then Begin
PrintChar:=True;
NewLine:=False;
End
Else
If(ParamStr(I)='-cnr')or(ParamStr(I)='-crn')or
(ParamStr(I)='-ncr')or(ParamStr(I)='-nrc')or
(ParamStr(I)='-rcn')or(ParamStr(I)='-rnc')Then Begin
PrintChar:=True;
NewLine:=False;
RandomValue:=True;
Randomize;
End
Else
If ParamStr(I)='-cr'Then Begin
PrintChar:=True;
RandomValue:=True;
Randomize;
End
Else
If ParamStr(I)='-n'Then NewLine:=False Else
If ParamStr(I)='-nc'Then Begin
PrintChar:=True;
NewLine:=False;
End
Else
If ParamStr(I)='-nr'Then Begin
NewLine:=False;
RandomValue:=True;
Randomize;
End
Else
If ParamStr(I)='-p'Then ModeParam:=_Precision Else
If ParamStr(I)='-r'Then Begin
RandomValue:=True;
Randomize;
End
Else
If ParamStr(I)='-rc'Then Begin
PrintChar:=True;
RandomValue:=True;
Randomize;
End
Else
If ParamStr(I)='-rn'Then Begin
NewLine:=False;
RandomValue:=True;
Randomize;
End
Else
If ParamStr(I)='-s'Then ModeParam:=_Separator Else
If ParamStr(I)='-w'Then ModeParam:=_Format
Else
If PosValue<=3 Then Begin
If ParamStr(I)='-'Then SkipValue[PosValue]:=True
Else 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:Begin
If Value[0]=0 Then Begin { Boucle infini }
First:=1;
Step:=0;
Last:=2;
End
Else
Begin
First:=1;
Last:=First+Value[0];
Step:=1;
End;
End;
2:Begin
Step:=1;
First:=Value[1];
Last:=First+Step*Value[0];
End;
3:Begin
First:=Value[1];
Last:=Value[2];
If(SkipValue[0])Then Step:=1
Else Step:=(Last-First)/Value[0];
End;
4:Begin
First:=Value[1];
Last:=Value[2];
Step:=Value[3];
Last:=First+(Step*Value[0]);
End;
Else Begin
WriteLn('Nombre de paramŠtre invalide !');
Halt(2);
End;
End;
IR:=First;
While(IR<=Last)do Begin
If(BWord<>'')Then Write(BWord) Else
If(PrintChar)Then Begin
If(RandomValue)Then Write(Chr(Random(Trunc(Last-First))+Trunc(First)))
Else Write(Chr(Trunc(IR)));
End
Else
Begin
If(Format<>'')Then Begin
If(RandomValue)Then Write(FormatString(Format,Random(Trunc(Last-First))+Trunc(First)))
Else Write(FormatString(Format,IR));
End
Else
If(RandomValue)Then Write(Random(Trunc(Last-First))+Trunc(First))
Else Write(IR:0:Precision);
End;
If(Separator<>'')Then Write(Separator) Else
If(NewLine)Then WriteLn;
IR:=IR+Step;
End;
End;
END.