-
Notifications
You must be signed in to change notification settings - Fork 2
/
RUNCMD.INC
355 lines (341 loc) · 11.1 KB
/
RUNCMD.INC
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
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
{/////////////////////////////////////////////////////////////////////////
//
// Dos Navigator Version 1.51 Copyright (C) 1991-99 RIT Research Labs
//
// This programs is free for commercial and non-commercial use as long as
// the following conditions are aheared to.
//
// Copyright remains RIT Research Labs, and as such any Copyright notices
// in the code are not to be removed. If this package is used in a
// product, RIT Research Labs should be given attribution as the RIT Research
// Labs of the parts of the library used. This can be in the form of a textual
// message at program startup or in documentation (online or textual)
// provided with the package.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// 1. Redistributions of source code must retain the copyright
// notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// 3. All advertising materials mentioning features or use of this software
// must display the following acknowledgement:
// "Based on TinyWeb Server by RIT Research Labs."
//
// THIS SOFTWARE IS PROVIDED BY RIT RESEARCH LABS "AS IS" AND ANY EXPRESS
// OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
// IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// The licence and distribution terms for any publically available
// version or derivative of this code cannot be changed. i.e. this code
// cannot simply be copied and put under another distribution licence
// (including the GNU Public Licence).
//
//////////////////////////////////////////////////////////////////////////}
procedure SaveDsk;
begin
if StartupData.Unload and osuAutosave = 0 then
PDNApplication(Application)^.SaveDesktop(SwpDir+'DN'+ItoS(DNNumber)+'.SWP');
end;
procedure ExecString(S: Str128);
var F1: Text;
I: Integer;
M: String;
DT: DateTime;
label 1;
begin
DelRight(S);
if not Chk4Dos and (Pos('||', S) <> 0) then
begin
Assign(F1, SwpDir+'$DN'+ItoS(DNNumber)+'$.BAT'); ClrIO;
Rewrite(F1); if IOResult <> 0 then begin Close(F1); Exit; end;
I := 0;
repeat
I := Pos('||', S);
if I = 0 then I := Length(S)+1;
WriteLn(F1, MakeCMDParams(Copy(S, 1, I-1),
CnvString(CurFileActive),
CnvString(CurFilePassive)));
Delete(S, 1, I+1);
until (S = '');
Close(F1);
S := SwpDir+'$DN'+ItoS(DNNumber)+'$.BAT ';
end else S := MakeCMDParams(S, CnvString(CurFileActive), CnvString(CurFilePassive));
1:
S := ' '+S+#13; Dec(S[0]);
if (LoaderSeg <> 0) then Move(S, mem[LoaderSeg:CommandOfs], Length(S)+2);
if (SystemData.Options and ossFastExec <> 0) or RunFrom2E then asm
mov ax, 9903h
mov cl, 1
int 2Fh
end;
if TimerMark then DDTimer := Get100s
else DDTimer := 0;
asm
mov ax, 9904h
mov dx, word ptr DDTimer
mov cx, word ptr DDTimer+2
int 2Fh
mov ax, 9902h
mov cl, 1
int 2Fh
end;
Halt(1);
end;
function SearchExt(Name: NameStr; Ext: ExtStr; var HS: String): Boolean;
var
AllRight : Boolean;
f : PTextReader;
f1 : Text;
s,s1 : String;
BgCh,EnCh: Char;
EF, First: Boolean;
I : Integer;
Local: Boolean;
label RL;
function transl(var s: string): string;
var i: integer;
b: ExtStr;
r: NameStr;
ad: string;
begin
ad := ActiveDir; if ad[Length(ad)]<>'\' then ad := ad + '\';
B := Ext; LowStr(B); Insert('.', B, 1);
R := Name; DelRight(R); LowStr(R);
Replace('!!', #0, S);
Replace('.!', B, S);
Replace('!\', LowStrg(ad), S);
Replace('!/', Copy(LowStrg(ad), 1, Length(ad)-1), S);
Replace('!', R, S);
Replace(#0, '!!', S);
Transl:=S;
end;
function InFilter(const S: String): Boolean;
var I: Integer;
M: String[3];
begin
InFilter := On;
repeat
I := PosChar(';', S1);
if I = 0 then I := PosChar(',',S1);
if I = 0 then I := Length(S1)+1;
M := Copy(S1, 1, I-1); Delete(S1, 1, I);
if M = '.' then M := '';
if InMask(S, Norm12('*.'+M)) then Exit;
until (S1 = '');
InFilter := Off;
end;
begin
First := True;
GetDir(0, ActiveDir);
SearchExt:=False;
Local := On;
f := New(PTextReader, Init('DN.EXT'));
if f=nil then
begin
RL:
Local := Off;
f := New(PTextReader, Init(SourceDir+'DN.EXT'));
end;
if f=nil then Exit; AllRight:=False;
BgCh:='{';EnCh:='}'; Abort := Off; EF:=Off;
if PShootState and 8 > 0 then begin BgCh:='[';EnCh:=']';end else
if PShootState and 3 > 0 then begin BgCh:='(';EnCh:=')';end;
While (not f^.EOF) and (not AllRight) do begin
S := f^.GetStr;
if S[1] <> ' ' then
begin
I := PosChar(BgCh, S); if I = 0 then Continue;
S1 := Copy(S, 1, I-1); UpStr(S1);
if InFilter(Name+'.'+Ext) then
begin
Assign(f1, SwpDir+'$DN'+ItoS(DNNumber)+'$.BAT'); ClrIO;
Rewrite(F1); if IOResult <> 0 then begin Dispose(F, Done); Exit; end;
System.Delete(S, 1, PosChar(BgCh, S));
repeat
Replace(']]', #0, S); Replace('))', #1, S); Replace('}}', #2, S);
DelLeft(S); DelRight(S);
if S[Length(S)] = EnCh then
begin Dec(S[0]); EF := On; if S <> '' then
begin S := Transl(S); HS := S;
Replace(#0, ']', S); Replace(#1, ')', S); Replace(#2, '}', S);
WriteLn(F1, S); Break
end;
end;
if S <> '' then
begin
if (BgCh <> '[') then S := Transl(S);
if First and (BgCh <> '[') then HS := S;
Replace(#0, ']', S); Replace(#1, ')', S); Replace(#2, '}', S);
WriteLn(F1, S);
First := False;
end;
if (F^.EOF) then Break;
if not EF then S := F^.GetStr;
until (IOResult <> 0) or Abort or EF;
Write(F1, '@echo off');
Close(F1);
AllRight := On;
end;
end;
end;
Dispose(F, Done);
if not EF and not Abort and Local then Goto RL;
if EF and (BgCh = '[') then
begin
EraseFile( SwpDir+'$dn'+ItoS(DNNumber)+'$.mnu' );
Rename(F1, SwpDir+'$dn'+ItoS(DNNumber)+'$.mnu');
EF := ExecUserMenu(Off);
if not EF then Erase(F1);
end;
SearchExt:=not Abort and EF;
end;
function ExecExtFile(const ExtFName, FName: PathStr; SIdx: TStrIdx): Boolean;
var F: PTextReader;
S: String;
Mask, Nm: String[12];
Dr: PathStr;
Xt: ExtStr;
Event: TEvent;
I,J: Integer;
PP: PView;
Success, CD: Boolean;
Local: Boolean;
label 1,1111, RepeatLocal;
begin
ExecExtFile := Off;
FileMode := $40;
Local := On;
F := New(PTextReader, Init(ExtFName));
if F = nil then
begin
RepeatLocal:
Local := Off;
F := New(PTextReader, Init(SourceDir+ExtFName));
end;
if F = nil then Exit;
FSplit(FExpand(FName), Dr, Nm, Xt);
Nm := Norm12(Nm+Xt);
While not F^.EOF do
begin
S := F^.GetStr;
DelLeft(S);
if (S <> '') and (S[1] <> ';') then
begin
repeat
J := PosChar(':', S); if J = 0 then Goto 1;
I := PosChar(',', S);
if (I <> 0) and (I < J) then
begin
Mask := Norm12('*.'+Copy(S,1,I-1));
if InMask(Nm, Mask) then
begin
Delete(S, 1, J); Goto 1111;
end else Delete(S, 1, I);
end else
begin
Mask := Norm12('*.'+Copy(S,1,J-1));
Delete(S, 1, J);
if InMask(Nm, Mask) then Goto 1111;
Break;
end;
until S='';
end;
1:
end;
ExecExtFile := Off;
Dispose(F, Done);
if Local then Goto RepeatLocal;
Exit;
1111:
Dispose(F,Done);
if not Application^.Valid(cmQuit) then Exit;
Replace('!!', #0, S);
Success := PosChar('!', S) = 0;
CD := Off;
FSplit(FExpand(FName), Dr, Nm, Xt);
if not Success then
begin
Replace('!', #0, Dr);
Replace('!', #0, Nm);
Replace('!', #0, Xt);
CD := not Replace('!\', Copy(Dr, 3, 255), S);
Replace('!:', Copy(Dr, 1, 2), S);
Replace('.!', Xt, S);
Replace('!', Nm, S);
end else S := S + ' ' + Dr+Nm+Xt;
Replace(#0, '!', S);
ClrIO;
if CD then
begin
GetDir(0, DirToChange);
ChDir(Dr);
end else DirToChange := '';
if Abort then Exit;
if S[1] = '*' then DelFC(S);
begin
PP := _WriteMsg(' '+GetString(SIdx));
InsertUserSaver(Off);
SaveDsk;
Application^.Done;
ExecString(S);
end;
end;
procedure ExecFile(Name: PathStr);
var S, M: String;
procedure PutHistory(B: Boolean);
begin
if M = '' then Exit;
CmdLine.Str := M;
CmdLine.StrModified := On;
CmdDisabled := B;
Message(CommandLine, evKeyDown, kbDown, nil);
Message(CommandLine, evKeyDown, kbUp, nil);
end;
procedure RunCommand(B: Boolean);
var ST: SessionType;
begin
if (PCommandLine(CommandLine)^.LineType in [ltOS2Window,ltOS2FullScreen]) then
begin
if PCommandLine(CommandLine)^.LineType = ltOS2FullScreen then ST := stOS2FullScreen
else ST := stOS2Windowed;
RunOS2Command(M, Off, ST);
CmdLine.StrModified := On;
Message(CommandLine, evKeyDown, kbDown, nil);
Exit;
end;
SaveDsk;
Application^.Done;
if B then begin WriteLn(#13#10, ActiveDir+'>', M); M := M + #13 end;
ExecString(M);
end;
begin
S := LowStrg(Norm12(Name));
FreeStr := '';
M := '';
if (ShiftState and (3 or kbAltShift) <> 0) or
(Pos(#0+Copy(S, 10, 3)+#0, Executables) = 0) then
begin
if SearchExt(Copy(S, 1, 8), Copy(S, 10, 3), M) then
begin
PutHistory(On);
M := SwpDir+'$DN'+ItoS(DNNumber)+'$.BAT ' + FreeStr;
RunCommand(Off);
end else Exit;
end;
M := LowStrg(MakeFileName(S));
PutHistory(Off);
M := Name;
RunCommand(On);
end;