-
Notifications
You must be signed in to change notification settings - Fork 0
/
CHOICE.PAS
185 lines (178 loc) · 4.77 KB
/
CHOICE.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
{ @author: Sylvain Maltais (support@gladir.com)
@created: 2022
@website(https://www.gladir.com/pcdos-0)
@abstract(Target: Turbo Pascal, Free Pascal)
}
Program Choice;
Uses Crt,DOS;
Var
Language:(_French,_English,_Germany,_Italian,_Spain);
TmpLanguage:String;
StartTime,EndTime,CurrTime:LongInt;
OptionFlag:(_None,_C);
NoPrompt,Found,CheckCase:Boolean;
I,nn:Integer;
Err:Word;
C,defaultChar:Char;
ChoiceString,TextString,CurrParam:String;
Function GetCurrTime:LongInt;
Var
Hour,Min,Sec,Sec100:Word;
Begin
GetTime(Hour,Min,Sec,Sec100);
GetCurrTime:=Sec100+(Sec*100)+(Min*60*100)+(Hour*60*60*100);
End;
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;
BEGIN
{$IFDEF FPC}
{$IFDEF WINDOWS}
SetUseACP(False);
{$ENDIF}
{$ENDIF}
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;
End;
If(ParamStr(1)='/?')or(ParamStr(1)='--help')or(ParamStr(1)='-h')Then Begin
Case Language of
_Germany:Begin
WriteLn('Wartet auf die Answahl des Benutzers der angeigten Optionen.');
WriteLn;
WriteLn('CHOICE [/C[:]Tasten] [/N] [/S] [/T[:]c,nn] [Text]');
WriteLn;
WriteLn('/C[:]Tasten Angabe der zul„ssigen Tasten. Standard ist JN.');
WriteLn('/N Keine Anzeigne eines ?-Zeichens am Ende der Meldung.');
WriteLn('/S Groá-/Kleinschreibung fšr Tasten wird beachtet.');
WriteLn('/T[:]c,nn Nach nn Sekunden wird Standardausahl c ausgefšhrt.');
WriteLn('Text Meldung, die angezeigt wird.');
End;
_English:Begin
WriteLn('CHOICE : Waits for you to choose one of a set of choices.');
WriteLn;
WriteLn('Formats: CHOICE [/C[:]choices] [/N] [/S] [/T[:]c,nn]');
WriteLn;
WriteLn('/C[:]choices Specifies allowable keys. Default is YN.');
WriteLn('/N Does not display choices and ? at end of prompt string.');
WriteLn('/S Treats choice keys as case sensitive.');
End;
Else Begin
WriteLn('CHOICE : Cette commande permet de faire un choix.');
WriteLn;
WriteLn('Syntaxe : CHOICE [/C[:]choix] [/N] [/S] [/T[:]c,nn]');
WriteLn;
WriteLn('/C[:]touches Indique la liste des touches accept‚es comme r‚ponse');
End;
End;
End
Else
Begin
nn:=-1;defaultChar:=#0;
NoPrompt:=False;
CheckCase:=False;
OptionFlag:=_None;
ChoiceString:='';
TextString:='';
For I:=1 to ParamCount do Begin
If OptionFlag<>_None Then Begin
Case OptionFlag of
_C:ChoiceString:=ParamStr(I);
End;
OptionFlag:=_None;
End
Else
If Copy(StrToUpper(ParamStr(I)),1,2)='/T'Then Begin
CurrParam:=StrToUpper(ParamStr(I));
If CurrParam[3]=':'Then Begin
defaultChar:=CurrParam[4];
If CurrParam[5]<>','Then Begin
Write('Virgule attendu');
Halt;
End;
Val(Copy(CurrParam,6,255),nn,Err);
End
Else
Begin
defaultChar:=CurrParam[3];
If CurrParam[4]<>','Then Begin
Write('Virgule attendu');
Halt;
End;
Val(Copy(CurrParam,5,255),nn,Err);
End;
End
Else
If StrToUpper(ParamStr(I))='/S'Then CheckCase:=True Else
If StrToUpper(ParamStr(I))='/N'Then NoPrompt:=True Else
If StrToUpper(ParamStr(I))='/C'Then OptionFlag:=_C Else
If StrToUpper(Copy(ParamStr(I),1,3))='/C:'Then Begin
ChoiceString:=Copy(ParamStr(I),4,255);
End
Else
Begin
TextString:=TextString+' '+ParamStr(I);
OptionFlag:=_None;
End;
End;
If ChoiceString=''Then Begin
Case Language of
_English:ChoiceString:='YN';
_Germany:ChoiceString:='JN';
Else ChoiceString:='ON';
End;
End;
If Not(NoPrompt)Then Begin
Write('[');
For I:=1 to Length(ChoiceString)do Begin
If I<>1Then Write(',');
Write(ChoiceString[I]);
End;
Write(']?');
End;
Found:=False;
Repeat
If nn<>-1 Then Begin
StartTime:=GetCurrTime;
EndTime:=StartTime+nn*100;
C:=DefaultChar;
Repeat
CurrTime:=GetCurrTime;
If(KeyPressed)Then Begin
C:=ReadKey;
If C=#0 Then ReadKey;
Break;
End;
Until CurrTime>EndTime;
End
Else
C:=ReadKey;
If(CheckCase)Then Begin
For I:=1 to Length(ChoiceString)do If C=ChoiceString[I]Then Begin
Found:=True;
Halt(I);
Break;
End;
End
Else
Begin
For I:=1 to Length(ChoiceString)do If UpCase(C)=UpCase(ChoiceString[I])Then Begin
Found:=True;
Halt(I);
Break;
End;
End;
Until Found;
End;
END.