-
Notifications
You must be signed in to change notification settings - Fork 5
/
m_argv.pas
242 lines (210 loc) · 6.29 KB
/
m_argv.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
//------------------------------------------------------------------------------
//
// FPCDoom - Port of Doom to Free Pascal Compiler
// Copyright (C) 1993-1996 by id Software, Inc.
// Copyright (C) 2004-2007 by Jim Valavanis
// Copyright (C) 2017-2022 by Jim Valavanis
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
//------------------------------------------------------------------------------
// E-Mail: [email protected]
// Site : https://sourceforge.net/projects/fpcdoom/
//------------------------------------------------------------------------------
{$I FPCDoom.inc}
unit m_argv;
interface
//
// MISC
//
const
MAXARGS = 1024;
var
myargc: integer;
myargv: array[0..MAXARGS] of string;
{ Returns the position of the given parameter }
{ in the arg list (0 if not found). }
//==============================================================================
//
// M_CheckParm
//
//==============================================================================
function M_CheckParm(const check: string): integer;
//==============================================================================
//
// M_CheckParmCDROM
//
//==============================================================================
function M_CheckParmCDROM: boolean;
//==============================================================================
//
// M_InitArgv
//
//==============================================================================
procedure M_InitArgv;
//==============================================================================
//
// M_CmdShowCommandLineParams
//
//==============================================================================
procedure M_CmdShowCommandLineParams(const parm: string);
//==============================================================================
//
// M_CmdShowCmdline
//
//==============================================================================
procedure M_CmdShowCmdline(const parm: string);
//==============================================================================
//
// M_SaveFileName
//
//==============================================================================
function M_SaveFileName(const filename: string): string;
const
CD_WORKDIR = 'c:\doomdata\';
APP_WORKDIR = '.\data\';
implementation
uses
d_fpc,
c_cmds,
i_system;
var
cdchecked: integer = -1;
var
cmdparams: TDStringList;
//==============================================================================
//
// M_CheckParm
//
//==============================================================================
function M_CheckParm(const check: string): integer;
var
i: integer;
begin
if cmdparams.IndexOf(check) < 0 then
cmdparams.Add(check);
for i := 1 to myargc - 1 do
if strupper(check) = myargv[i] then
begin
result := i;
exit;
end;
result := 0;
end;
//==============================================================================
//
// M_CheckParmCDROM
//
//==============================================================================
function M_CheckParmCDROM: boolean;
begin
if cdchecked = -1 then
begin
if I_IsCDRomDrive then
cdchecked := 1
else
cdchecked := M_CheckParm('-cdrom');
if cdchecked > 0 then
MakeDir(CD_WORKDIR);
end;
result := cdchecked > 0;
end;
//==============================================================================
//
// M_InitArgv
//
//==============================================================================
procedure M_InitArgv;
var
i: integer;
cmdln: string;
begin
myargc := ParamCount + 1;
for i := 0 to myargc - 1 do
begin
myargv[i] := strupper(ParamStr(i));
if i = MAXARGS then
begin
myargc := i + 1;
exit;
end;
if myargv[i] <> '' then
if myargv[i][1] <> '-' then
if fexists(myargv[i]) then
myargv[i] := fexpand(myargv[i]);
end;
for i := myargc to MAXARGS do
myargv[i] := '';
cmdln := fname(myargv[0]);
for i := 1 to myargc - 1 do
cmdln := cmdln + ' ' + myargv[i];
printf('%s'#13#10, [cmdln]);
ChDir(fpath(myargv[0]));
end;
//==============================================================================
//
// M_CmdShowCommandLineParams
//
//==============================================================================
procedure M_CmdShowCommandLineParams(const parm: string);
var
i: integer;
mlist: TDStringList;
mask: string;
begin
if parm = '' then
mask := '*'
else
mask := parm;
mlist := C_GetMachingList(cmdparams, mask);
printf('Command line parameters: '#13#10);
for i := 0 to mlist.Count - 1 do
printf(' %s'#13#10, [mlist[i]]);
mlist.Free;
end;
//==============================================================================
//
// M_CmdShowCmdline
//
//==============================================================================
procedure M_CmdShowCmdline(const parm: string);
var
i: integer;
begin
for i := 1 to myargc - 1 do
printf('%s ', [myargv[i]]);
printf(#13#10);
end;
//==============================================================================
//
// M_SaveFileName
//
//==============================================================================
function M_SaveFileName(const filename: string): string;
begin
if M_CheckParmCDROM then
result := CD_WORKDIR + filename
else
begin
MakeDir(APP_WORKDIR);
result := APP_WORKDIR + filename;
end;
end;
initialization
cmdparams := TDStringList.Create;
finalization
cmdparams.Free;
end.