author | koda |
Sat, 29 Jun 2013 01:26:05 +0200 | |
changeset 9299 | d64f80504749 |
parent 9280 | c3b11f913145 |
child 9302 | 1cf37fd7bc47 |
permissions | -rw-r--r-- |
4976 | 1 |
(* |
2 |
* Hedgewars, a free turn based strategy game |
|
9080 | 3 |
* Copyright (c) 2004-2013 Andrey Korotaev <unC0Rr@gmail.com> |
4976 | 4 |
* |
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 |
|
8 |
* |
|
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. |
|
13 |
* |
|
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 |
|
17 |
*) |
|
9280 | 18 |
|
19 |
{$INCLUDE "options.inc"} |
|
20 |
||
21 |
unit ArgParsers; |
|
22 |
interface |
|
23 |
||
24 |
procedure GetParams; |
|
25 |
||
26 |
implementation |
|
27 |
uses uConsole, uVariables, uTypes, uUtils, uSound, uConsts; |
|
28 |
var isInternal: Boolean; |
|
3678
00428183300f
patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff
changeset
|
29 |
|
8325
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
30 |
procedure GciEasterEgg; |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
31 |
begin |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
32 |
WriteLn(stdout, ' '); |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
33 |
WriteLn(stdout, ' /\\\\\\\\\\\\ /\\\\\\\\\ /\\\\\\\\\\\ '); |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
34 |
WriteLn(stdout, ' /\\\////////// /\\\//////// \/////\\\/// '); |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
35 |
WriteLn(stdout, ' /\\\ /\\\/ \/\\\ '); |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
36 |
WriteLn(stdout, ' \/\\\ /\\\\\\\ /\\\ \/\\\ '); |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
37 |
WriteLn(stdout, ' \/\\\ \/////\\\ \/\\\ \/\\\ '); |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
38 |
WriteLn(stdout, ' \/\\\ \/\\\ \//\\\ \/\\\ '); |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
39 |
WriteLn(stdout, ' \/\\\ \/\\\ \///\\\ \/\\\ '); |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
40 |
WriteLn(stdout, ' \/\\\\\\\\\\\\\/ \////\\\\\\\\\ /\\\\\\\\\\\ '); |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
41 |
WriteLn(stdout, ' \///////////// \///////// \/////////// '); |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
42 |
WriteLn(stdout, ' '); |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
43 |
WriteLn(stdout, ' Command Line Parser Implementation by a Google Code-In Student '); |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
44 |
WriteLn(stdout, ' ASCII Art easter egg idea by @sheepluva '); |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
45 |
WriteLn(stdout, ' '); |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
46 |
end; |
3678
00428183300f
patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff
changeset
|
47 |
|
8325
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
48 |
procedure DisplayUsage; |
3678
00428183300f
patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff
changeset
|
49 |
begin |
8325
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
50 |
WriteLn(stdout, 'Usage: hwengine <path to replay file> [options]'); |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
51 |
WriteLn(stdout, ''); |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
52 |
WriteLn(stdout, 'where [options] can be any of the following:'); |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
53 |
WriteLn(stdout, ' --prefix [path to folder]'); |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
54 |
WriteLn(stdout, ' --user-prefix [path to folder]'); |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
55 |
WriteLn(stdout, ' --locale [name of language file]'); |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
56 |
WriteLn(stdout, ' --nick [string]'); |
8354
c25bee85d6f8
Separated fullscreen and windowed hwengine resolution parameters.
vitiv <nikita.utiu@gmail.com>
parents:
8329
diff
changeset
|
57 |
WriteLn(stdout, ' --fullscreen-width [fullscreen width in pixels]'); |
c25bee85d6f8
Separated fullscreen and windowed hwengine resolution parameters.
vitiv <nikita.utiu@gmail.com>
parents:
8329
diff
changeset
|
58 |
WriteLn(stdout, ' --fullscreen-height [fullscreen height in pixels]'); |
c25bee85d6f8
Separated fullscreen and windowed hwengine resolution parameters.
vitiv <nikita.utiu@gmail.com>
parents:
8329
diff
changeset
|
59 |
WriteLn(stdout, ' --width [window width in pixels]'); |
c25bee85d6f8
Separated fullscreen and windowed hwengine resolution parameters.
vitiv <nikita.utiu@gmail.com>
parents:
8329
diff
changeset
|
60 |
WriteLn(stdout, ' --height [window height in pixels]'); |
8325
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
61 |
WriteLn(stdout, ' --volume [sound level]'); |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
62 |
WriteLn(stdout, ' --frame-interval [milliseconds]'); |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
63 |
Writeln(stdout, ' --stereo [value]'); |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
64 |
WriteLn(stdout, ' --raw-quality [flags]'); |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
65 |
WriteLn(stdout, ' --low-quality'); |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
66 |
WriteLn(stdout, ' --nomusic'); |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
67 |
WriteLn(stdout, ' --nosound'); |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
68 |
WriteLn(stdout, ' --fullscreen'); |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
69 |
WriteLn(stdout, ' --showfps'); |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
70 |
WriteLn(stdout, ' --altdmg'); |
9249 | 71 |
WriteLn(stdout, ' --no-teamtag'); |
72 |
WriteLn(stdout, ' --no-hogtag'); |
|
73 |
WriteLn(stdout, ' --no-healthtag'); |
|
74 |
WriteLn(stdout, ' --translucent-tags'); |
|
8325
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
75 |
WriteLn(stdout, ' --stats-only'); |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
76 |
WriteLn(stdout, ' --help'); |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
77 |
WriteLn(stdout, ''); |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
78 |
WriteLn(stdout, 'For more detailed help and examples go to:'); |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
79 |
WriteLn(stdout, 'http://code.google.com/p/hedgewars/wiki/CommandLineOptions'); |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
80 |
GameType:= gmtSyntax; |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
81 |
end; |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
82 |
|
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
83 |
procedure setDepth(var paramIndex: LongInt); |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
84 |
begin |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
85 |
WriteLn(stdout, 'WARNING: --depth is a deprecated command, which could be removed in a future version!'); |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
86 |
WriteLn(stdout, ' This option no longer does anything, please consider removing it'); |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
87 |
WriteLn(stdout, ''); |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
88 |
inc(ParamIndex); |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
89 |
end; |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
90 |
|
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
91 |
procedure statsOnlyGame; |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
92 |
begin |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
93 |
cOnlyStats:= true; |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
94 |
cReducedQuality:= $FFFFFFFF xor rqLowRes; |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
95 |
SetSound(false); |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
96 |
SetMusic(false); |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
97 |
SetVolume(0); |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
98 |
end; |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
99 |
|
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
100 |
procedure setIpcPort(port: LongInt; var wrongParameter:Boolean); |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
101 |
begin |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
102 |
if isInternal then |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
103 |
ipcPort := port |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
104 |
else |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
105 |
begin |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
106 |
WriteLn(stderr, 'ERROR: use of --port is not allowed'); |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
107 |
wrongParameter := true; |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
108 |
end |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
109 |
end; |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
110 |
|
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
111 |
function parseNick(nick: String): String; |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
112 |
begin |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
113 |
if isInternal then |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
114 |
parseNick:= DecodeBase64(nick) |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
115 |
else |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
116 |
parseNick:= nick; |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
117 |
end; |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
118 |
|
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
119 |
procedure setStereoMode(tmp: LongInt); |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
120 |
begin |
6982 | 121 |
GrayScale:= false; |
8221 | 122 |
{$IFDEF USE_S3D_RENDERING} |
8359
9a7024b2a4d3
Removed wiggle 3D mode, reorder the list of 3D modes.
martin_bede
parents:
8354
diff
changeset
|
123 |
if (tmp > 6) and (tmp < 13) then |
5441
39962b855540
Add grayscale option for 3d, helps with colour clashing
nemo
parents:
5239
diff
changeset
|
124 |
begin |
8221 | 125 |
// set the gray anaglyph rendering |
6982 | 126 |
GrayScale:= true; |
8359
9a7024b2a4d3
Removed wiggle 3D mode, reorder the list of 3D modes.
martin_bede
parents:
8354
diff
changeset
|
127 |
cStereoMode:= TStereoMode(max(0, min(ord(high(TStereoMode)), tmp-6))) |
5441
39962b855540
Add grayscale option for 3d, helps with colour clashing
nemo
parents:
5239
diff
changeset
|
128 |
end |
8359
9a7024b2a4d3
Removed wiggle 3D mode, reorder the list of 3D modes.
martin_bede
parents:
8354
diff
changeset
|
129 |
else if tmp <= 6 then |
8221 | 130 |
// set the fullcolor anaglyph |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6426
diff
changeset
|
131 |
cStereoMode:= TStereoMode(max(0, min(ord(high(TStereoMode)), tmp))) |
8221 | 132 |
else |
133 |
// any other mode |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6426
diff
changeset
|
134 |
cStereoMode:= TStereoMode(max(0, min(ord(high(TStereoMode)), tmp-6))); |
8221 | 135 |
{$ELSE} |
8425
4f226963faef
restored ios project file, updated Game() interface, tweaked arg parsing, updated log writing, minor warnings
koda
parents:
8370
diff
changeset
|
136 |
tmp:= tmp; |
8325
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
137 |
cStereoMode:= smNone; |
8221 | 138 |
{$ENDIF} |
3678
00428183300f
patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff
changeset
|
139 |
end; |
00428183300f
patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff
changeset
|
140 |
|
8325
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
141 |
procedure startVideoRecording(var paramIndex: LongInt); |
3678
00428183300f
patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff
changeset
|
142 |
begin |
8370 | 143 |
// Silence the hint that appears when USE_VIDEO_RECORDING is not defined |
144 |
paramIndex:= paramIndex; |
|
8325
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
145 |
{$IFDEF USE_VIDEO_RECORDING} |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
146 |
GameType:= gmtRecord; |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
147 |
inc(paramIndex); |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
148 |
cVideoFramerateNum:= StrToInt(ParamStr(paramIndex)); inc(paramIndex); |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
149 |
cVideoFramerateDen:= StrToInt(ParamStr(paramIndex)); inc(paramIndex); |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
150 |
RecPrefix:= ParamStr(paramIndex); inc(paramIndex); |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
151 |
cAVFormat:= ParamStr(paramIndex); inc(paramIndex); |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
152 |
cVideoCodec:= ParamStr(paramIndex); inc(paramIndex); |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
153 |
cVideoQuality:= StrToInt(ParamStr(paramIndex)); inc(paramIndex); |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
154 |
cAudioCodec:= ParamStr(paramIndex); inc(paramIndex); |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
155 |
{$ENDIF} |
3678
00428183300f
patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff
changeset
|
156 |
end; |
00428183300f
patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff
changeset
|
157 |
|
8150 | 158 |
function getLongIntParameter(str:String; var paramIndex:LongInt; var wrongParameter:Boolean): LongInt; |
159 |
var tmpInt, c: LongInt; |
|
3678
00428183300f
patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff
changeset
|
160 |
begin |
8308
cdf83bdf7b27
move GetParams in ArgParser, print a warning when using a deprecated command, pascalisation of +1s
koda
parents:
8307
diff
changeset
|
161 |
inc(paramIndex); |
8150 | 162 |
val(str, tmpInt, c); |
163 |
wrongParameter:= c <> 0; |
|
164 |
if wrongParameter then |
|
165 |
WriteLn(stderr, 'ERROR: '+ParamStr(paramIndex-1)+' expects a number, you passed "'+str+'"'); |
|
166 |
getLongIntParameter:= tmpInt; |
|
3678
00428183300f
patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff
changeset
|
167 |
end; |
00428183300f
patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff
changeset
|
168 |
|
8302
a7934cd12469
improve engine cmd line parsing and its documentation
RowanD
parents:
8221
diff
changeset
|
169 |
function getStringParameter(str:String; var paramIndex:LongInt; var wrongParameter:Boolean): String; |
3678
00428183300f
patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff
changeset
|
170 |
begin |
8308
cdf83bdf7b27
move GetParams in ArgParser, print a warning when using a deprecated command, pascalisation of +1s
koda
parents:
8307
diff
changeset
|
171 |
inc(paramIndex); |
8302
a7934cd12469
improve engine cmd line parsing and its documentation
RowanD
parents:
8221
diff
changeset
|
172 |
wrongParameter:= (str='') or (Copy(str,1,2) = '--'); |
a7934cd12469
improve engine cmd line parsing and its documentation
RowanD
parents:
8221
diff
changeset
|
173 |
if wrongParameter then |
a7934cd12469
improve engine cmd line parsing and its documentation
RowanD
parents:
8221
diff
changeset
|
174 |
WriteLn(stderr, 'ERROR: '+ParamStr(paramIndex-1)+' expects a string, you passed "'+str+'"'); |
8150 | 175 |
getStringParameter:= str; |
3678
00428183300f
patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff
changeset
|
176 |
end; |
00428183300f
patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff
changeset
|
177 |
|
8302
a7934cd12469
improve engine cmd line parsing and its documentation
RowanD
parents:
8221
diff
changeset
|
178 |
|
8150 | 179 |
procedure parseClassicParameter(cmdArray: Array of String; size:LongInt; var paramIndex:LongInt); Forward; |
180 |
||
181 |
function parseParameter(cmd:String; arg:String; var paramIndex:LongInt): Boolean; |
|
8354
c25bee85d6f8
Separated fullscreen and windowed hwengine resolution parameters.
vitiv <nikita.utiu@gmail.com>
parents:
8329
diff
changeset
|
182 |
const videoArray: Array [1..5] of String = ('--fullscreen-width','--fullscreen-height', '--width', '--height', '--depth'); |
8325
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
183 |
audioArray: Array [1..3] of String = ('--volume','--nomusic','--nosound'); |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
184 |
otherArray: Array [1..3] of String = ('--locale','--fullscreen','--showfps'); |
8354
c25bee85d6f8
Separated fullscreen and windowed hwengine resolution parameters.
vitiv <nikita.utiu@gmail.com>
parents:
8329
diff
changeset
|
185 |
mediaArray: Array [1..10] of String = ('--fullscreen-width', '--fullscreen-height', '--width', '--height', '--depth', '--volume','--nomusic','--nosound','--locale','--fullscreen'); |
9249 | 186 |
allArray: Array [1..18] of String = ('--fullscreen-width','--fullscreen-height', '--width', '--height', '--depth','--volume','--nomusic','--nosound','--locale','--fullscreen','--showfps','--altdmg','--frame-interval','--low-quality','--no-teamtag','--no-hogtag','--no-healthtag','--translucent-tags'); |
187 |
reallyAll: array[0..34] of shortstring = ( |
|
8924 | 188 |
'--prefix', '--user-prefix', '--locale', '--fullscreen-width', '--fullscreen-height', '--width', |
8354
c25bee85d6f8
Separated fullscreen and windowed hwengine resolution parameters.
vitiv <nikita.utiu@gmail.com>
parents:
8329
diff
changeset
|
189 |
'--height', '--frame-interval', '--volume','--nomusic', '--nosound', |
8924 | 190 |
'--fullscreen', '--showfps', '--altdmg', '--low-quality', '--raw-quality', '--stereo', '--nick', |
8302
a7934cd12469
improve engine cmd line parsing and its documentation
RowanD
parents:
8221
diff
changeset
|
191 |
{deprecated} '--depth', '--set-video', '--set-audio', '--set-other', '--set-multimedia', '--set-everything', |
8325
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
192 |
{internal} '--internal', '--port', '--recorder', '--landpreview', |
9249 | 193 |
{misc} '--stats-only', '--gci', '--help','--no-teamtag','--no-hogtag','--no-healthtag','--translucent-tags'); |
8197 | 194 |
var cmdIndex: byte; |
3678
00428183300f
patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff
changeset
|
195 |
begin |
8150 | 196 |
parseParameter:= false; |
8197 | 197 |
cmdIndex:= 0; |
8302
a7934cd12469
improve engine cmd line parsing and its documentation
RowanD
parents:
8221
diff
changeset
|
198 |
|
a7934cd12469
improve engine cmd line parsing and its documentation
RowanD
parents:
8221
diff
changeset
|
199 |
//NOTE: Any update to the list of parameters must be reflected in the case statement below, the reallyAll array above, |
a7934cd12469
improve engine cmd line parsing and its documentation
RowanD
parents:
8221
diff
changeset
|
200 |
// the the DisplayUsage() procedure, the HWForm::getDemoArguments() function, and the online wiki |
a7934cd12469
improve engine cmd line parsing and its documentation
RowanD
parents:
8221
diff
changeset
|
201 |
|
8197 | 202 |
while (cmdIndex <= High(reallyAll)) and (cmd <> reallyAll[cmdIndex]) do inc(cmdIndex); |
203 |
case cmdIndex of |
|
8354
c25bee85d6f8
Separated fullscreen and windowed hwengine resolution parameters.
vitiv <nikita.utiu@gmail.com>
parents:
8329
diff
changeset
|
204 |
{--prefix} 0 : PathPrefix := getStringParameter (arg, paramIndex, parseParameter); |
c25bee85d6f8
Separated fullscreen and windowed hwengine resolution parameters.
vitiv <nikita.utiu@gmail.com>
parents:
8329
diff
changeset
|
205 |
{--user-prefix} 1 : UserPathPrefix := getStringParameter (arg, paramIndex, parseParameter); |
c25bee85d6f8
Separated fullscreen and windowed hwengine resolution parameters.
vitiv <nikita.utiu@gmail.com>
parents:
8329
diff
changeset
|
206 |
{--locale} 2 : cLocaleFName := getStringParameter (arg, paramIndex, parseParameter); |
8985
fe8d1a476f0b
range checking for more engine command line parameters, issue 600
koda
parents:
8924
diff
changeset
|
207 |
{--fullscreen-width} 3 : cFullscreenWidth := max(getLongIntParameter(arg, paramIndex, parseParameter), cMinScreenWidth); |
fe8d1a476f0b
range checking for more engine command line parameters, issue 600
koda
parents:
8924
diff
changeset
|
208 |
{--fullscreen-height} 4 : cFullscreenHeight := max(getLongIntParameter(arg, paramIndex, parseParameter), cMinScreenHeight); |
8884
08fe08651130
set translucency on fruit theme water, clamp size to even number (same sdl window resize) and honouring min size, reduce calls to dmgmod a bit
nemo
parents:
8425
diff
changeset
|
209 |
{--width} 5 : cWindowedWidth := max(2 * (getLongIntParameter(arg, paramIndex, parseParameter) div 2), cMinScreenWidth); |
08fe08651130
set translucency on fruit theme water, clamp size to even number (same sdl window resize) and honouring min size, reduce calls to dmgmod a bit
nemo
parents:
8425
diff
changeset
|
210 |
{--height} 6 : cWindowedHeight := max(2 * (getLongIntParameter(arg, paramIndex, parseParameter) div 2), cMinScreenHeight); |
8354
c25bee85d6f8
Separated fullscreen and windowed hwengine resolution parameters.
vitiv <nikita.utiu@gmail.com>
parents:
8329
diff
changeset
|
211 |
{--frame-interval} 7 : cTimerInterval := getLongIntParameter(arg, paramIndex, parseParameter); |
8985
fe8d1a476f0b
range checking for more engine command line parameters, issue 600
koda
parents:
8924
diff
changeset
|
212 |
{--volume} 8 : SetVolume ( max(getLongIntParameter(arg, paramIndex, parseParameter), 0) ); |
8354
c25bee85d6f8
Separated fullscreen and windowed hwengine resolution parameters.
vitiv <nikita.utiu@gmail.com>
parents:
8329
diff
changeset
|
213 |
{--nomusic} 9 : SetMusic ( false ); |
c25bee85d6f8
Separated fullscreen and windowed hwengine resolution parameters.
vitiv <nikita.utiu@gmail.com>
parents:
8329
diff
changeset
|
214 |
{--nosound} 10 : SetSound ( false ); |
c25bee85d6f8
Separated fullscreen and windowed hwengine resolution parameters.
vitiv <nikita.utiu@gmail.com>
parents:
8329
diff
changeset
|
215 |
{--fullscreen} 11 : cFullScreen := true; |
c25bee85d6f8
Separated fullscreen and windowed hwengine resolution parameters.
vitiv <nikita.utiu@gmail.com>
parents:
8329
diff
changeset
|
216 |
{--showfps} 12 : cShowFPS := true; |
c25bee85d6f8
Separated fullscreen and windowed hwengine resolution parameters.
vitiv <nikita.utiu@gmail.com>
parents:
8329
diff
changeset
|
217 |
{--altdmg} 13 : cAltDamage := true; |
c25bee85d6f8
Separated fullscreen and windowed hwengine resolution parameters.
vitiv <nikita.utiu@gmail.com>
parents:
8329
diff
changeset
|
218 |
{--low-quality} 14 : cReducedQuality := $FFFFFFFF xor rqLowRes; |
c25bee85d6f8
Separated fullscreen and windowed hwengine resolution parameters.
vitiv <nikita.utiu@gmail.com>
parents:
8329
diff
changeset
|
219 |
{--raw-quality} 15 : cReducedQuality := getLongIntParameter(arg, paramIndex, parseParameter); |
c25bee85d6f8
Separated fullscreen and windowed hwengine resolution parameters.
vitiv <nikita.utiu@gmail.com>
parents:
8329
diff
changeset
|
220 |
{--stereo} 16 : setStereoMode ( getLongIntParameter(arg, paramIndex, parseParameter) ); |
c25bee85d6f8
Separated fullscreen and windowed hwengine resolution parameters.
vitiv <nikita.utiu@gmail.com>
parents:
8329
diff
changeset
|
221 |
{--nick} 17 : UserNick := parseNick( getStringParameter(arg, paramIndex, parseParameter) ); |
8302
a7934cd12469
improve engine cmd line parsing and its documentation
RowanD
parents:
8221
diff
changeset
|
222 |
{deprecated options} |
8354
c25bee85d6f8
Separated fullscreen and windowed hwengine resolution parameters.
vitiv <nikita.utiu@gmail.com>
parents:
8329
diff
changeset
|
223 |
{--depth} 18 : setDepth(paramIndex); |
c25bee85d6f8
Separated fullscreen and windowed hwengine resolution parameters.
vitiv <nikita.utiu@gmail.com>
parents:
8329
diff
changeset
|
224 |
{--set-video} 19 : parseClassicParameter(videoArray,5,paramIndex); |
c25bee85d6f8
Separated fullscreen and windowed hwengine resolution parameters.
vitiv <nikita.utiu@gmail.com>
parents:
8329
diff
changeset
|
225 |
{--set-audio} 20 : parseClassicParameter(audioArray,3,paramIndex); |
c25bee85d6f8
Separated fullscreen and windowed hwengine resolution parameters.
vitiv <nikita.utiu@gmail.com>
parents:
8329
diff
changeset
|
226 |
{--set-other} 21 : parseClassicParameter(otherArray,3,paramIndex); |
c25bee85d6f8
Separated fullscreen and windowed hwengine resolution parameters.
vitiv <nikita.utiu@gmail.com>
parents:
8329
diff
changeset
|
227 |
{--set-multimedia} 22 : parseClassicParameter(mediaArray,10,paramIndex); |
c25bee85d6f8
Separated fullscreen and windowed hwengine resolution parameters.
vitiv <nikita.utiu@gmail.com>
parents:
8329
diff
changeset
|
228 |
{--set-everything} 23 : parseClassicParameter(allArray,14,paramIndex); |
8325
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
229 |
{"internal" options} |
8425
4f226963faef
restored ios project file, updated Game() interface, tweaked arg parsing, updated log writing, minor warnings
koda
parents:
8370
diff
changeset
|
230 |
{--internal} 24 : {$IFDEF HWLIBRARY}isInternal:= true{$ENDIF}; |
8354
c25bee85d6f8
Separated fullscreen and windowed hwengine resolution parameters.
vitiv <nikita.utiu@gmail.com>
parents:
8329
diff
changeset
|
231 |
{--port} 25 : setIpcPort( getLongIntParameter(arg, paramIndex, parseParameter), parseParameter ); |
c25bee85d6f8
Separated fullscreen and windowed hwengine resolution parameters.
vitiv <nikita.utiu@gmail.com>
parents:
8329
diff
changeset
|
232 |
{--recorder} 26 : startVideoRecording(paramIndex); |
c25bee85d6f8
Separated fullscreen and windowed hwengine resolution parameters.
vitiv <nikita.utiu@gmail.com>
parents:
8329
diff
changeset
|
233 |
{--landpreview} 27 : GameType := gmtLandPreview; |
8302
a7934cd12469
improve engine cmd line parsing and its documentation
RowanD
parents:
8221
diff
changeset
|
234 |
{anything else} |
8354
c25bee85d6f8
Separated fullscreen and windowed hwengine resolution parameters.
vitiv <nikita.utiu@gmail.com>
parents:
8329
diff
changeset
|
235 |
{--stats-only} 28 : statsOnlyGame(); |
c25bee85d6f8
Separated fullscreen and windowed hwengine resolution parameters.
vitiv <nikita.utiu@gmail.com>
parents:
8329
diff
changeset
|
236 |
{--gci} 29 : GciEasterEgg(); |
c25bee85d6f8
Separated fullscreen and windowed hwengine resolution parameters.
vitiv <nikita.utiu@gmail.com>
parents:
8329
diff
changeset
|
237 |
{--help} 30 : DisplayUsage(); |
9249 | 238 |
{--no-teamtag} 31 : cTagsMask := cTagsMask and not htTeamName; |
239 |
{--no-hogtag} 32 : cTagsMask := cTagsMask and not htName; |
|
240 |
{--no-healthtag} 33 : cTagsMask := cTagsMask and not htHealth; |
|
241 |
{--translucent-tags} 34 : cTagsMask := cTagsMask or htTransparent |
|
8150 | 242 |
else |
243 |
begin |
|
8307 | 244 |
//Asusme the first "non parameter" is the replay file, anything else is invalid |
8325
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
245 |
if (recordFileName = '') and (Copy(cmd,1,2) <> '--') then |
8307 | 246 |
recordFileName := cmd |
247 |
else |
|
248 |
begin |
|
8325
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
249 |
WriteLn(stderr, '"'+cmd+'" is not a valid option'); |
8307 | 250 |
parseParameter:= true; |
251 |
end; |
|
252 |
end; |
|
8150 | 253 |
end; |
3678
00428183300f
patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff
changeset
|
254 |
end; |
00428183300f
patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff
changeset
|
255 |
|
8150 | 256 |
procedure parseClassicParameter(cmdArray: Array of String; size:LongInt; var paramIndex:LongInt); |
257 |
var index, tmpInt: LongInt; |
|
8325
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
258 |
isBool, isValid: Boolean; |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
259 |
cmd, arg, newSyntax: String; |
3678
00428183300f
patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff
changeset
|
260 |
begin |
8308
cdf83bdf7b27
move GetParams in ArgParser, print a warning when using a deprecated command, pascalisation of +1s
koda
parents:
8307
diff
changeset
|
261 |
WriteLn(stdout, 'WARNING: you are using a deprecated command, which could be removed in a future version!'); |
cdf83bdf7b27
move GetParams in ArgParser, print a warning when using a deprecated command, pascalisation of +1s
koda
parents:
8307
diff
changeset
|
262 |
WriteLn(stdout, ' Consider updating to the latest syntax, which is much more flexible!'); |
cdf83bdf7b27
move GetParams in ArgParser, print a warning when using a deprecated command, pascalisation of +1s
koda
parents:
8307
diff
changeset
|
263 |
WriteLn(stdout, ' Run `hwegine --help` to learn it!'); |
cdf83bdf7b27
move GetParams in ArgParser, print a warning when using a deprecated command, pascalisation of +1s
koda
parents:
8307
diff
changeset
|
264 |
WriteLn(stdout, ''); |
cdf83bdf7b27
move GetParams in ArgParser, print a warning when using a deprecated command, pascalisation of +1s
koda
parents:
8307
diff
changeset
|
265 |
|
8150 | 266 |
index:= 0; |
267 |
tmpInt:= 1; |
|
268 |
while (index < size) do |
|
269 |
begin |
|
8370 | 270 |
newSyntax:= ''; |
8325
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
271 |
inc(paramIndex); |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
272 |
cmd:= cmdArray[index]; |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
273 |
arg:= ParamStr(paramIndex); |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
274 |
isValid:= (cmd<>'--depth'); |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
275 |
|
8197 | 276 |
// check if the parameter is a boolean one |
9249 | 277 |
isBool:= (cmd = '--nomusic') or (cmd = '--nosound') or (cmd = '--fullscreen') or (cmd = '--showfps') or (cmd = '--altdmg') or (cmd = '--no-teamtag') or (cmd = '--no-hogtag') or (cmd = '--no-healthtag') or (cmd = '--translucent-tags'); |
8325
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
278 |
if isBool and (arg='0') then |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
279 |
isValid:= false; |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
280 |
if (cmd='--nomusic') or (cmd='--nosound') then |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
281 |
isValid:= not isValid; |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
282 |
|
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
283 |
if isValid then |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
284 |
begin |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
285 |
parseParameter(cmd, arg, tmpInt); |
8329 | 286 |
newSyntax := newSyntax + cmd + ' '; |
8325
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
287 |
if not isBool then |
8329 | 288 |
newSyntax := newSyntax + arg + ' '; |
8325
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
289 |
end; |
8308
cdf83bdf7b27
move GetParams in ArgParser, print a warning when using a deprecated command, pascalisation of +1s
koda
parents:
8307
diff
changeset
|
290 |
inc(index); |
8150 | 291 |
end; |
8924 | 292 |
|
8325
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
293 |
WriteLn(stdout, 'Attempted to automatically convert to the new syntax:'); |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
294 |
WriteLn(stdout, newSyntax); |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
295 |
WriteLn(stdout, ''); |
3678
00428183300f
patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff
changeset
|
296 |
end; |
00428183300f
patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff
changeset
|
297 |
|
8327
a6f3452f5f94
convert Game() library call to argc,argv format so that we can use the new parsing functions
koda
parents:
8325
diff
changeset
|
298 |
procedure parseCommandLine{$IFDEF HWLIBRARY}(argc: LongInt; argv: PPChar){$ENDIF}; |
8308
cdf83bdf7b27
move GetParams in ArgParser, print a warning when using a deprecated command, pascalisation of +1s
koda
parents:
8307
diff
changeset
|
299 |
var paramIndex: LongInt; |
8327
a6f3452f5f94
convert Game() library call to argc,argv format so that we can use the new parsing functions
koda
parents:
8325
diff
changeset
|
300 |
paramTotal: LongInt; |
8425
4f226963faef
restored ios project file, updated Game() interface, tweaked arg parsing, updated log writing, minor warnings
koda
parents:
8370
diff
changeset
|
301 |
index, nextIndex: LongInt; |
3678
00428183300f
patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff
changeset
|
302 |
wrongParameter: boolean; |
8425
4f226963faef
restored ios project file, updated Game() interface, tweaked arg parsing, updated log writing, minor warnings
koda
parents:
8370
diff
changeset
|
303 |
//var tmpInt: LongInt; |
3678
00428183300f
patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff
changeset
|
304 |
begin |
8425
4f226963faef
restored ios project file, updated Game() interface, tweaked arg parsing, updated log writing, minor warnings
koda
parents:
8370
diff
changeset
|
305 |
paramIndex:= {$IFDEF HWLIBRARY}0{$ELSE}1{$ENDIF}; |
4f226963faef
restored ios project file, updated Game() interface, tweaked arg parsing, updated log writing, minor warnings
koda
parents:
8370
diff
changeset
|
306 |
paramTotal:= {$IFDEF HWLIBRARY}argc-1{$ELSE}ParamCount{$ENDIF}; //-1 because pascal enumeration is inclusive |
4f226963faef
restored ios project file, updated Game() interface, tweaked arg parsing, updated log writing, minor warnings
koda
parents:
8370
diff
changeset
|
307 |
(* |
4f226963faef
restored ios project file, updated Game() interface, tweaked arg parsing, updated log writing, minor warnings
koda
parents:
8370
diff
changeset
|
308 |
WriteLn(stdout, 'total parameters: ' + inttostr(paramTotal)); |
4f226963faef
restored ios project file, updated Game() interface, tweaked arg parsing, updated log writing, minor warnings
koda
parents:
8370
diff
changeset
|
309 |
tmpInt:= 0; |
4f226963faef
restored ios project file, updated Game() interface, tweaked arg parsing, updated log writing, minor warnings
koda
parents:
8370
diff
changeset
|
310 |
while (tmpInt <= paramTotal) do |
4f226963faef
restored ios project file, updated Game() interface, tweaked arg parsing, updated log writing, minor warnings
koda
parents:
8370
diff
changeset
|
311 |
begin |
4f226963faef
restored ios project file, updated Game() interface, tweaked arg parsing, updated log writing, minor warnings
koda
parents:
8370
diff
changeset
|
312 |
WriteLn(stdout, inttostr(tmpInt) + ': ' + {$IFDEF HWLIBRARY}argv[tmpInt]{$ELSE}paramCount(tmpInt){$ENDIF}); |
4f226963faef
restored ios project file, updated Game() interface, tweaked arg parsing, updated log writing, minor warnings
koda
parents:
8370
diff
changeset
|
313 |
inc(tmpInt); |
4f226963faef
restored ios project file, updated Game() interface, tweaked arg parsing, updated log writing, minor warnings
koda
parents:
8370
diff
changeset
|
314 |
end; |
4f226963faef
restored ios project file, updated Game() interface, tweaked arg parsing, updated log writing, minor warnings
koda
parents:
8370
diff
changeset
|
315 |
*) |
3678
00428183300f
patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff
changeset
|
316 |
wrongParameter:= false; |
8327
a6f3452f5f94
convert Game() library call to argc,argv format so that we can use the new parsing functions
koda
parents:
8325
diff
changeset
|
317 |
while (paramIndex <= paramTotal) do |
3678
00428183300f
patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff
changeset
|
318 |
begin |
8425
4f226963faef
restored ios project file, updated Game() interface, tweaked arg parsing, updated log writing, minor warnings
koda
parents:
8370
diff
changeset
|
319 |
// avoid going past the number of paramTotal (esp. w/ library) |
4f226963faef
restored ios project file, updated Game() interface, tweaked arg parsing, updated log writing, minor warnings
koda
parents:
8370
diff
changeset
|
320 |
index:= paramIndex; |
4f226963faef
restored ios project file, updated Game() interface, tweaked arg parsing, updated log writing, minor warnings
koda
parents:
8370
diff
changeset
|
321 |
if index = paramTotal then nextIndex:= index |
4f226963faef
restored ios project file, updated Game() interface, tweaked arg parsing, updated log writing, minor warnings
koda
parents:
8370
diff
changeset
|
322 |
else nextIndex:= index+1; |
8327
a6f3452f5f94
convert Game() library call to argc,argv format so that we can use the new parsing functions
koda
parents:
8325
diff
changeset
|
323 |
{$IFDEF HWLIBRARY} |
8425
4f226963faef
restored ios project file, updated Game() interface, tweaked arg parsing, updated log writing, minor warnings
koda
parents:
8370
diff
changeset
|
324 |
wrongParameter:= parseParameter( argv[index], argv[nextIndex], paramIndex); |
8327
a6f3452f5f94
convert Game() library call to argc,argv format so that we can use the new parsing functions
koda
parents:
8325
diff
changeset
|
325 |
{$ELSE} |
8425
4f226963faef
restored ios project file, updated Game() interface, tweaked arg parsing, updated log writing, minor warnings
koda
parents:
8370
diff
changeset
|
326 |
wrongParameter:= parseParameter( ParamStr(index), ParamStr(nextIndex), paramIndex); |
8327
a6f3452f5f94
convert Game() library call to argc,argv format so that we can use the new parsing functions
koda
parents:
8325
diff
changeset
|
327 |
{$ENDIF} |
8308
cdf83bdf7b27
move GetParams in ArgParser, print a warning when using a deprecated command, pascalisation of +1s
koda
parents:
8307
diff
changeset
|
328 |
inc(paramIndex); |
8150 | 329 |
end; |
330 |
if wrongParameter = true then |
|
331 |
GameType:= gmtSyntax; |
|
3678
00428183300f
patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff
changeset
|
332 |
end; |
8308
cdf83bdf7b27
move GetParams in ArgParser, print a warning when using a deprecated command, pascalisation of +1s
koda
parents:
8307
diff
changeset
|
333 |
|
8327
a6f3452f5f94
convert Game() library call to argc,argv format so that we can use the new parsing functions
koda
parents:
8325
diff
changeset
|
334 |
{$IFNDEF HWLIBRARY} |
8308
cdf83bdf7b27
move GetParams in ArgParser, print a warning when using a deprecated command, pascalisation of +1s
koda
parents:
8307
diff
changeset
|
335 |
procedure GetParams; |
cdf83bdf7b27
move GetParams in ArgParser, print a warning when using a deprecated command, pascalisation of +1s
koda
parents:
8307
diff
changeset
|
336 |
begin |
8325
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
337 |
isInternal:= (ParamStr(1) = '--internal'); |
8308
cdf83bdf7b27
move GetParams in ArgParser, print a warning when using a deprecated command, pascalisation of +1s
koda
parents:
8307
diff
changeset
|
338 |
|
cdf83bdf7b27
move GetParams in ArgParser, print a warning when using a deprecated command, pascalisation of +1s
koda
parents:
8307
diff
changeset
|
339 |
UserPathPrefix := '.'; |
cdf83bdf7b27
move GetParams in ArgParser, print a warning when using a deprecated command, pascalisation of +1s
koda
parents:
8307
diff
changeset
|
340 |
PathPrefix := cDefaultPathPrefix; |
cdf83bdf7b27
move GetParams in ArgParser, print a warning when using a deprecated command, pascalisation of +1s
koda
parents:
8307
diff
changeset
|
341 |
recordFileName := ''; |
8327
a6f3452f5f94
convert Game() library call to argc,argv format so that we can use the new parsing functions
koda
parents:
8325
diff
changeset
|
342 |
parseCommandLine(); |
8308
cdf83bdf7b27
move GetParams in ArgParser, print a warning when using a deprecated command, pascalisation of +1s
koda
parents:
8307
diff
changeset
|
343 |
|
8325
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
344 |
if (isInternal) and (ParamCount<=1) then |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
345 |
begin |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
346 |
WriteLn(stderr, '--internal should not be manually used'); |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
347 |
GameType := gmtSyntax; |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
348 |
end; |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
349 |
|
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
350 |
if (not isInternal) and (recordFileName = '') then |
8308
cdf83bdf7b27
move GetParams in ArgParser, print a warning when using a deprecated command, pascalisation of +1s
koda
parents:
8307
diff
changeset
|
351 |
begin |
8325
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
352 |
WriteLn(stderr, 'You must specify a replay file'); |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
353 |
GameType := gmtSyntax; |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
354 |
end |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
355 |
else if (recordFileName <> '') then |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
356 |
WriteLn(stdout, 'Attempting to play demo file "' + recordFilename + '"'); |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
357 |
|
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
358 |
if (GameType = gmtSyntax) then |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
359 |
WriteLn(stderr, 'Please use --help to see possible arguments and their usage'); |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8309
diff
changeset
|
360 |
|
8308
cdf83bdf7b27
move GetParams in ArgParser, print a warning when using a deprecated command, pascalisation of +1s
koda
parents:
8307
diff
changeset
|
361 |
(* |
cdf83bdf7b27
move GetParams in ArgParser, print a warning when using a deprecated command, pascalisation of +1s
koda
parents:
8307
diff
changeset
|
362 |
WriteLn(stdout,'PathPrefix: ' + PathPrefix); |
cdf83bdf7b27
move GetParams in ArgParser, print a warning when using a deprecated command, pascalisation of +1s
koda
parents:
8307
diff
changeset
|
363 |
WriteLn(stdout,'UserPathPrefix: ' + UserPathPrefix); |
cdf83bdf7b27
move GetParams in ArgParser, print a warning when using a deprecated command, pascalisation of +1s
koda
parents:
8307
diff
changeset
|
364 |
*) |
cdf83bdf7b27
move GetParams in ArgParser, print a warning when using a deprecated command, pascalisation of +1s
koda
parents:
8307
diff
changeset
|
365 |
end; |
8327
a6f3452f5f94
convert Game() library call to argc,argv format so that we can use the new parsing functions
koda
parents:
8325
diff
changeset
|
366 |
{$ENDIF} |
a6f3452f5f94
convert Game() library call to argc,argv format so that we can use the new parsing functions
koda
parents:
8325
diff
changeset
|
367 |
|
9280 | 368 |
end. |
369 |