2
* Hedgewars, a free turn based strategy game
3
* Copyright (c) 2004-2013 Andrey Korotaev <unC0Rr@gmail.com>
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; version 2 of the License
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
19
procedure GciEasterEgg;
22
WriteLn(stdout, ' /\\\\\\\\\\\\ /\\\\\\\\\ /\\\\\\\\\\\ ');
23
WriteLn(stdout, ' /\\\////////// /\\\//////// \/////\\\/// ');
24
WriteLn(stdout, ' /\\\ /\\\/ \/\\\ ');
25
WriteLn(stdout, ' \/\\\ /\\\\\\\ /\\\ \/\\\ ');
26
WriteLn(stdout, ' \/\\\ \/////\\\ \/\\\ \/\\\ ');
27
WriteLn(stdout, ' \/\\\ \/\\\ \//\\\ \/\\\ ');
28
WriteLn(stdout, ' \/\\\ \/\\\ \///\\\ \/\\\ ');
29
WriteLn(stdout, ' \/\\\\\\\\\\\\\/ \////\\\\\\\\\ /\\\\\\\\\\\ ');
30
WriteLn(stdout, ' \///////////// \///////// \/////////// ');
32
WriteLn(stdout, ' Command Line Parser Implementation by a Google Code-In Student ');
33
WriteLn(stdout, ' ASCII Art easter egg idea by @sheepluva ');
37
procedure DisplayUsage;
39
WriteLn(stdout, 'Usage: hwengine <path to replay file> [options]');
41
WriteLn(stdout, 'where [options] can be any of the following:');
42
WriteLn(stdout, ' --prefix [path to folder]');
43
WriteLn(stdout, ' --user-prefix [path to folder]');
44
WriteLn(stdout, ' --locale [name of language file]');
45
WriteLn(stdout, ' --nick [string]');
46
WriteLn(stdout, ' --fullscreen-width [fullscreen width in pixels]');
47
WriteLn(stdout, ' --fullscreen-height [fullscreen height in pixels]');
48
WriteLn(stdout, ' --width [window width in pixels]');
49
WriteLn(stdout, ' --height [window height in pixels]');
50
WriteLn(stdout, ' --volume [sound level]');
51
WriteLn(stdout, ' --frame-interval [milliseconds]');
52
Writeln(stdout, ' --stereo [value]');
53
WriteLn(stdout, ' --raw-quality [flags]');
54
WriteLn(stdout, ' --low-quality');
55
WriteLn(stdout, ' --nomusic');
56
WriteLn(stdout, ' --nosound');
57
WriteLn(stdout, ' --fullscreen');
58
WriteLn(stdout, ' --showfps');
59
WriteLn(stdout, ' --altdmg');
60
WriteLn(stdout, ' --stats-only');
61
WriteLn(stdout, ' --help');
63
WriteLn(stdout, 'For more detailed help and examples go to:');
64
WriteLn(stdout, 'http://code.google.com/p/hedgewars/wiki/CommandLineOptions');
68
procedure setDepth(var paramIndex: LongInt);
70
WriteLn(stdout, 'WARNING: --depth is a deprecated command, which could be removed in a future version!');
71
WriteLn(stdout, ' This option no longer does anything, please consider removing it');
76
procedure statsOnlyGame;
79
cReducedQuality:= $FFFFFFFF xor rqLowRes;
85
procedure setIpcPort(port: LongInt; var wrongParameter:Boolean);
91
WriteLn(stderr, 'ERROR: use of --port is not allowed');
92
wrongParameter := true;
96
function parseNick(nick: String): String;
99
parseNick:= DecodeBase64(nick)
104
procedure setStereoMode(tmp: LongInt);
107
{$IFDEF USE_S3D_RENDERING}
108
if (tmp > 6) and (tmp < 13) then
110
// set the gray anaglyph rendering
112
cStereoMode:= TStereoMode(max(0, min(ord(high(TStereoMode)), tmp-6)))
114
else if tmp <= 6 then
115
// set the fullcolor anaglyph
116
cStereoMode:= TStereoMode(max(0, min(ord(high(TStereoMode)), tmp)))
119
cStereoMode:= TStereoMode(max(0, min(ord(high(TStereoMode)), tmp-6)));
122
cStereoMode:= smNone;
126
procedure startVideoRecording(var paramIndex: LongInt);
128
// Silence the hint that appears when USE_VIDEO_RECORDING is not defined
129
paramIndex:= paramIndex;
130
{$IFDEF USE_VIDEO_RECORDING}
131
GameType:= gmtRecord;
133
cVideoFramerateNum:= StrToInt(ParamStr(paramIndex)); inc(paramIndex);
134
cVideoFramerateDen:= StrToInt(ParamStr(paramIndex)); inc(paramIndex);
135
RecPrefix:= ParamStr(paramIndex); inc(paramIndex);
136
cAVFormat:= ParamStr(paramIndex); inc(paramIndex);
137
cVideoCodec:= ParamStr(paramIndex); inc(paramIndex);
138
cVideoQuality:= StrToInt(ParamStr(paramIndex)); inc(paramIndex);
139
cAudioCodec:= ParamStr(paramIndex); inc(paramIndex);
143
function getLongIntParameter(str:String; var paramIndex:LongInt; var wrongParameter:Boolean): LongInt;
144
var tmpInt, c: LongInt;
148
wrongParameter:= c <> 0;
149
if wrongParameter then
150
WriteLn(stderr, 'ERROR: '+ParamStr(paramIndex-1)+' expects a number, you passed "'+str+'"');
151
getLongIntParameter:= tmpInt;
154
function getStringParameter(str:String; var paramIndex:LongInt; var wrongParameter:Boolean): String;
157
wrongParameter:= (str='') or (Copy(str,1,2) = '--');
158
if wrongParameter then
159
WriteLn(stderr, 'ERROR: '+ParamStr(paramIndex-1)+' expects a string, you passed "'+str+'"');
160
getStringParameter:= str;
164
procedure parseClassicParameter(cmdArray: Array of String; size:LongInt; var paramIndex:LongInt); Forward;
166
function parseParameter(cmd:String; arg:String; var paramIndex:LongInt): Boolean;
167
const videoArray: Array [1..5] of String = ('--fullscreen-width','--fullscreen-height', '--width', '--height', '--depth');
168
audioArray: Array [1..3] of String = ('--volume','--nomusic','--nosound');
169
otherArray: Array [1..3] of String = ('--locale','--fullscreen','--showfps');
170
mediaArray: Array [1..10] of String = ('--fullscreen-width', '--fullscreen-height', '--width', '--height', '--depth', '--volume','--nomusic','--nosound','--locale','--fullscreen');
171
allArray: Array [1..14] of String = ('--fullscreen-width','--fullscreen-height', '--width', '--height', '--depth','--volume','--nomusic','--nosound','--locale','--fullscreen','--showfps','--altdmg','--frame-interval','--low-quality');
172
reallyAll: array[0..30] of shortstring = (
173
'--prefix', '--user-prefix', '--locale', '--fullscreen-width', '--fullscreen-height', '--width',
174
'--height', '--frame-interval', '--volume','--nomusic', '--nosound',
175
'--fullscreen', '--showfps', '--altdmg', '--low-quality', '--raw-quality', '--stereo', '--nick',
176
{deprecated} '--depth', '--set-video', '--set-audio', '--set-other', '--set-multimedia', '--set-everything',
177
{internal} '--internal', '--port', '--recorder', '--landpreview',
178
{misc} '--stats-only', '--gci', '--help');
181
parseParameter:= false;
184
//NOTE: Any update to the list of parameters must be reflected in the case statement below, the reallyAll array above,
185
// the the DisplayUsage() procedure, the HWForm::getDemoArguments() function, and the online wiki
187
while (cmdIndex <= High(reallyAll)) and (cmd <> reallyAll[cmdIndex]) do inc(cmdIndex);
189
{--prefix} 0 : PathPrefix := getStringParameter (arg, paramIndex, parseParameter);
190
{--user-prefix} 1 : UserPathPrefix := getStringParameter (arg, paramIndex, parseParameter);
191
{--locale} 2 : cLocaleFName := getStringParameter (arg, paramIndex, parseParameter);
192
{--fullscreen-width} 3 : cFullscreenWidth := max(getLongIntParameter(arg, paramIndex, parseParameter), cMinScreenWidth);
193
{--fullscreen-height} 4 : cFullscreenHeight := max(getLongIntParameter(arg, paramIndex, parseParameter), cMinScreenHeight);
194
{--width} 5 : cWindowedWidth := max(2 * (getLongIntParameter(arg, paramIndex, parseParameter) div 2), cMinScreenWidth);
195
{--height} 6 : cWindowedHeight := max(2 * (getLongIntParameter(arg, paramIndex, parseParameter) div 2), cMinScreenHeight);
196
{--frame-interval} 7 : cTimerInterval := getLongIntParameter(arg, paramIndex, parseParameter);
197
{--volume} 8 : SetVolume ( max(getLongIntParameter(arg, paramIndex, parseParameter), 0) );
198
{--nomusic} 9 : SetMusic ( false );
199
{--nosound} 10 : SetSound ( false );
200
{--fullscreen} 11 : cFullScreen := true;
201
{--showfps} 12 : cShowFPS := true;
202
{--altdmg} 13 : cAltDamage := true;
203
{--low-quality} 14 : cReducedQuality := $FFFFFFFF xor rqLowRes;
204
{--raw-quality} 15 : cReducedQuality := getLongIntParameter(arg, paramIndex, parseParameter);
205
{--stereo} 16 : setStereoMode ( getLongIntParameter(arg, paramIndex, parseParameter) );
206
{--nick} 17 : UserNick := parseNick( getStringParameter(arg, paramIndex, parseParameter) );
208
{--depth} 18 : setDepth(paramIndex);
209
{--set-video} 19 : parseClassicParameter(videoArray,5,paramIndex);
210
{--set-audio} 20 : parseClassicParameter(audioArray,3,paramIndex);
211
{--set-other} 21 : parseClassicParameter(otherArray,3,paramIndex);
212
{--set-multimedia} 22 : parseClassicParameter(mediaArray,10,paramIndex);
213
{--set-everything} 23 : parseClassicParameter(allArray,14,paramIndex);
215
{--internal} 24 : {$IFDEF HWLIBRARY}isInternal:= true{$ENDIF};
216
{--port} 25 : setIpcPort( getLongIntParameter(arg, paramIndex, parseParameter), parseParameter );
217
{--recorder} 26 : startVideoRecording(paramIndex);
218
{--landpreview} 27 : GameType := gmtLandPreview;
220
{--stats-only} 28 : statsOnlyGame();
221
{--gci} 29 : GciEasterEgg();
222
{--help} 30 : DisplayUsage();
225
//Asusme the first "non parameter" is the replay file, anything else is invalid
226
if (recordFileName = '') and (Copy(cmd,1,2) <> '--') then
227
recordFileName := cmd
230
WriteLn(stderr, '"'+cmd+'" is not a valid option');
231
parseParameter:= true;
237
procedure parseClassicParameter(cmdArray: Array of String; size:LongInt; var paramIndex:LongInt);
238
var index, tmpInt: LongInt;
239
isBool, isValid: Boolean;
240
cmd, arg, newSyntax: String;
242
WriteLn(stdout, 'WARNING: you are using a deprecated command, which could be removed in a future version!');
243
WriteLn(stdout, ' Consider updating to the latest syntax, which is much more flexible!');
244
WriteLn(stdout, ' Run `hwegine --help` to learn it!');
249
while (index < size) do
253
cmd:= cmdArray[index];
254
arg:= ParamStr(paramIndex);
255
isValid:= (cmd<>'--depth');
257
// check if the parameter is a boolean one
258
isBool:= (cmd = '--nomusic') or (cmd = '--nosound') or (cmd = '--fullscreen') or (cmd = '--showfps') or (cmd = '--altdmg');
259
if isBool and (arg='0') then
261
if (cmd='--nomusic') or (cmd='--nosound') then
262
isValid:= not isValid;
266
parseParameter(cmd, arg, tmpInt);
267
newSyntax := newSyntax + cmd + ' ';
269
newSyntax := newSyntax + arg + ' ';
274
WriteLn(stdout, 'Attempted to automatically convert to the new syntax:');
275
WriteLn(stdout, newSyntax);
279
procedure parseCommandLine{$IFDEF HWLIBRARY}(argc: LongInt; argv: PPChar){$ENDIF};
280
var paramIndex: LongInt;
282
index, nextIndex: LongInt;
283
wrongParameter: boolean;
284
//var tmpInt: LongInt;
286
paramIndex:= {$IFDEF HWLIBRARY}0{$ELSE}1{$ENDIF};
287
paramTotal:= {$IFDEF HWLIBRARY}argc-1{$ELSE}ParamCount{$ENDIF}; //-1 because pascal enumeration is inclusive
289
WriteLn(stdout, 'total parameters: ' + inttostr(paramTotal));
291
while (tmpInt <= paramTotal) do
293
WriteLn(stdout, inttostr(tmpInt) + ': ' + {$IFDEF HWLIBRARY}argv[tmpInt]{$ELSE}paramCount(tmpInt){$ENDIF});
297
wrongParameter:= false;
298
while (paramIndex <= paramTotal) do
300
// avoid going past the number of paramTotal (esp. w/ library)
302
if index = paramTotal then nextIndex:= index
303
else nextIndex:= index+1;
305
wrongParameter:= parseParameter( argv[index], argv[nextIndex], paramIndex);
307
wrongParameter:= parseParameter( ParamStr(index), ParamStr(nextIndex), paramIndex);
311
if wrongParameter = true then
312
GameType:= gmtSyntax;
318
isInternal:= (ParamStr(1) = '--internal');
320
UserPathPrefix := '.';
321
PathPrefix := cDefaultPathPrefix;
322
recordFileName := '';
325
if (isInternal) and (ParamCount<=1) then
327
WriteLn(stderr, '--internal should not be manually used');
328
GameType := gmtSyntax;
331
if (not isInternal) and (recordFileName = '') then
333
WriteLn(stderr, 'You must specify a replay file');
334
GameType := gmtSyntax;
336
else if (recordFileName <> '') then
337
WriteLn(stdout, 'Attempting to play demo file "' + recordFilename + '"');
339
if (GameType = gmtSyntax) then
340
WriteLn(stderr, 'Please use --help to see possible arguments and their usage');
343
WriteLn(stdout,'PathPrefix: ' + PathPrefix);
344
WriteLn(stdout,'UserPathPrefix: ' + UserPathPrefix);