-
Notifications
You must be signed in to change notification settings - Fork 7
/
COSTA.PAS
139 lines (113 loc) · 3.25 KB
/
COSTA.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
PROGRAM costa_launcher;
{ The Costa GUI launcher
Runs DESKTOP.EXE and any external programs requested by the desktop.
This allows the desktop to exit and memory to be freed while external
programs are run.
Written using Borland Turbo Pascal 7.01
}
{ Set stack to minimal size }
{$M 1536, 0, 0}
USES
DOS;
CONST
costa_exe = 'COSTA.EXE';
desktop_exe = 'DESKTOP.EXE';
run_dat = 'DATA\RUN.DAT';
continuestr = 'Press Enter to continue...';
VAR
current_dir : PathStr;
sresults : SearchRec;
file_name : TEXT;
run_command : ComStr;
run_path : PathStr;
run_params : ComStr;
run_pause : CHAR;
{ Run an external program - handle errors }
PROCEDURE RunProgram(command, params: ComStr; path: PathStr; pause: CHAR);
BEGIN
{$IFDEF DEBUG}
Writeln('Changing path to ', path);
Writeln('Running program ', command);
Writeln('With parameters ', path);
Write(continuestr);
Readln;
{$ENDIF}
IF Length(path) > 0 THEN
BEGIN
chdir(path);
END
ELSE
BEGIN
chdir(current_dir);
END;
SwapVectors;
Exec(command, params);
SwapVectors;
{ Low memory condition }
IF DosError = 8 THEN
BEGIN
Writeln('Out of memory.');
pause := '1';
{ If desktop can't be launched, exit }
IF command = desktop_exe THEN
Halt(1);
END;
{ Wait for keypress before returning? }
IF pause = '1' THEN
BEGIN
Writeln;
Write(continuestr);
Readln;
END;
END; { RunProgram }
BEGIN
{ Low byte of DosVersion contains major DOS version.
This program will actually run on DOS 3.0, but the other
included programs won't, so might as well check here }
IF Lo(DosVersion) < 4 THEN
BEGIN
Writeln('DOS 4+ required.');
Halt(1);
END;
{ Retrieve path of self from paramstr, used later on to find relative paths regardless
of current path when this program was executed }
current_dir := ParamStr(0);
{ Remove last backslash and name of this executable, leaving only path }
{ 13 = max 8.3 filename lenght 12 including the dot, plus a backslash }
Delete(current_dir, pos('\' + costa_exe, current_dir), 13);
{$IFDEF DEBUG}
Writeln('Path to Costa is ', current_dir);
Write(continuestr);
Readln;
{$ENDIF}
{ Verify that desktop exe exists in same path as this executable }
FindFirst(current_dir + '\' + desktop_exe, Archive, sresults);
IF DosError > 0 THEN
BEGIN
Writeln(desktop_exe + ' not found.');
Halt(1);
END;
WHILE True DO
BEGIN
{ Run the desktop }
RunProgram(desktop_exe, current_dir, '', '0');
{ Exit code 1 means exit }
IF DosExitCode = 1 THEN
halt(0);
{ If run.dat exists, run it and delete it }
FindFirst(current_dir + '\' + run_dat, Archive, sresults);
IF DosError > 0 THEN
continue;
{ Open file, read data and delete file }
Assign(file_name, current_dir + '\' + run_dat);
Reset(file_name);
Readln(file_name, run_command);
Readln(file_name, run_params);
Readln(file_name, run_path);
Read(file_name, run_pause);
Erase(file_name);
Close(file_name);
{ Run program - obviously }
RunProgram(run_command, run_params, run_path, run_pause)
END; { main loop }
END.