hedgewars/ArgParsers.inc
author Michael Hartman <omh1280@gmail.com>
Sun, 30 Dec 2012 09:23:30 -0500
branchwebgl
changeset 8334 abb48dd39e26
parent 8332 9333216f2054
child 8444 75db7bb8dce8
permissions -rw-r--r--
Added shaders and -GL2 option
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4976
088d40d8aba2 Happy 2011 :)
koda
parents: 4004
diff changeset
     1
(*
088d40d8aba2 Happy 2011 :)
koda
parents: 4004
diff changeset
     2
 * Hedgewars, a free turn based strategy game
6700
e04da46ee43c the most important commit of the year
koda
parents: 6580
diff changeset
     3
 * Copyright (c) 2004-2012 Andrey Korotaev <unC0Rr@gmail.com>
4976
088d40d8aba2 Happy 2011 :)
koda
parents: 4004
diff changeset
     4
 *
088d40d8aba2 Happy 2011 :)
koda
parents: 4004
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
088d40d8aba2 Happy 2011 :)
koda
parents: 4004
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
088d40d8aba2 Happy 2011 :)
koda
parents: 4004
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
088d40d8aba2 Happy 2011 :)
koda
parents: 4004
diff changeset
     8
 *
088d40d8aba2 Happy 2011 :)
koda
parents: 4004
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
088d40d8aba2 Happy 2011 :)
koda
parents: 4004
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
088d40d8aba2 Happy 2011 :)
koda
parents: 4004
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
088d40d8aba2 Happy 2011 :)
koda
parents: 4004
diff changeset
    12
 * GNU General Public License for more details.
088d40d8aba2 Happy 2011 :)
koda
parents: 4004
diff changeset
    13
 *
088d40d8aba2 Happy 2011 :)
koda
parents: 4004
diff changeset
    14
 * You should have received a copy of the GNU General Public License
088d40d8aba2 Happy 2011 :)
koda
parents: 4004
diff changeset
    15
 * along with this program; if not, write to the Free Software
088d40d8aba2 Happy 2011 :)
koda
parents: 4004
diff changeset
    16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
088d40d8aba2 Happy 2011 :)
koda
parents: 4004
diff changeset
    17
 *)
3678
00428183300f patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff changeset
    18
8325
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
    19
procedure GciEasterEgg;
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
    20
begin
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
    21
    WriteLn(stdout, '                                                                ');
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
    22
    WriteLn(stdout, '      /\\\\\\\\\\\\        /\\\\\\\\\  /\\\\\\\\\\\             ');
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
    23
    WriteLn(stdout, '     /\\\//////////      /\\\////////  \/////\\\///             ');
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
    24
    WriteLn(stdout, '     /\\\               /\\\/               \/\\\               ');
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
    25
    WriteLn(stdout, '     \/\\\    /\\\\\\\  /\\\                 \/\\\              ');
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
    26
    WriteLn(stdout, '      \/\\\   \/////\\\ \/\\\                 \/\\\             ');
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
    27
    WriteLn(stdout, '       \/\\\       \/\\\ \//\\\                \/\\\            ');
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
    28
    WriteLn(stdout, '        \/\\\       \/\\\  \///\\\              \/\\\           ');
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
    29
    WriteLn(stdout, '         \/\\\\\\\\\\\\\/     \////\\\\\\\\\  /\\\\\\\\\\\      ');
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
    30
    WriteLn(stdout, '          \/////////////          \/////////  \///////////      ');
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
    31
    WriteLn(stdout, '                                                                ');
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
    32
    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
    33
    WriteLn(stdout, '             ASCII Art easter egg idea by @sheepluva            ');
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
end;
3678
00428183300f patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff changeset
    36
8325
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
    37
procedure DisplayUsage;
3678
00428183300f patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff changeset
    38
begin
8325
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
    39
    WriteLn(stdout, 'Usage: hwengine <path to replay file> [options]');
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, 'where [options] can be any of the following:');
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
    42
    WriteLn(stdout, ' --prefix [path to folder]');
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
    43
    WriteLn(stdout, ' --user-prefix [path to folder]');
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
    44
    WriteLn(stdout, ' --locale [name of language file]');
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
    45
    WriteLn(stdout, ' --nick [string]');
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
    46
    WriteLn(stdout, ' --width [screen width in pixels]');
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
    47
    WriteLn(stdout, ' --height [screen height in pixels]');
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
    48
    WriteLn(stdout, ' --volume [sound level]');
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
    49
    WriteLn(stdout, ' --frame-interval [milliseconds]');
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
    50
    Writeln(stdout, ' --stereo [value]');
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
    51
    WriteLn(stdout, ' --raw-quality [flags]');
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
    52
    WriteLn(stdout, ' --low-quality');
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
    53
    WriteLn(stdout, ' --nomusic');
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
    54
    WriteLn(stdout, ' --nosound');
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
    55
    WriteLn(stdout, ' --fullscreen');
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
    56
    WriteLn(stdout, ' --showfps');
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
    57
    WriteLn(stdout, ' --altdmg');
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
    58
    WriteLn(stdout, ' --stats-only');
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
    59
    WriteLn(stdout, ' --help');
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
    60
    WriteLn(stdout, '');
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
    61
    WriteLn(stdout, 'For more detailed help and examples go to:');
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
    62
    WriteLn(stdout, 'http://code.google.com/p/hedgewars/wiki/CommandLineOptions');
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
    63
    GameType:= gmtSyntax;
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
    64
end;
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
    65
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
    66
procedure setDepth(var paramIndex: LongInt);
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
    67
begin
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
    68
    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
    69
    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
    70
    WriteLn(stdout, '');
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
    71
   inc(ParamIndex);
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
    72
end;
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
    73
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
    74
procedure statsOnlyGame;
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
    75
begin
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
    76
    cOnlyStats:= true;
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
    77
    cReducedQuality:= $FFFFFFFF xor rqLowRes;
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
    78
    SetSound(false);
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
    79
    SetMusic(false);
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
    80
    SetVolume(0);
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 setIpcPort(port: LongInt; var wrongParameter:Boolean);
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
    if isInternal then
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
    86
        ipcPort := port
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
    87
    else
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
    88
        begin
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
    89
        WriteLn(stderr, 'ERROR: use of --port is not allowed');
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
    90
        wrongParameter := true;
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
    91
        end
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
    92
end;
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
    93
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
    94
function parseNick(nick: String): String;
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
    95
begin
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
    96
    if isInternal then
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
    97
        parseNick:= DecodeBase64(nick)
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
    98
    else
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
    99
        parseNick:= nick;
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   100
end;
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   101
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   102
procedure setStereoMode(tmp: LongInt);
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   103
begin
6982
8d41d22a291d breaking news, we don't support typed consts anymore
koda
parents: 6700
diff changeset
   104
    GrayScale:= false;
8221
5e2dc5813408 don't set stereomode when stereo is disabled
koda
parents: 8213
diff changeset
   105
{$IFDEF USE_S3D_RENDERING}
5e2dc5813408 don't set stereomode when stereo is disabled
koda
parents: 8213
diff changeset
   106
    if (tmp > 9) and (tmp < 16) then
5441
39962b855540 Add grayscale option for 3d, helps with colour clashing
nemo
parents: 5239
diff changeset
   107
        begin
8221
5e2dc5813408 don't set stereomode when stereo is disabled
koda
parents: 8213
diff changeset
   108
        // set the gray anaglyph rendering
6982
8d41d22a291d breaking news, we don't support typed consts anymore
koda
parents: 6700
diff changeset
   109
        GrayScale:= true;
5441
39962b855540 Add grayscale option for 3d, helps with colour clashing
nemo
parents: 5239
diff changeset
   110
        cStereoMode:= TStereoMode(max(0, min(ord(high(TStereoMode)), tmp-9)))
39962b855540 Add grayscale option for 3d, helps with colour clashing
nemo
parents: 5239
diff changeset
   111
        end
8221
5e2dc5813408 don't set stereomode when stereo is disabled
koda
parents: 8213
diff changeset
   112
    else if tmp <= 9 then
5e2dc5813408 don't set stereomode when stereo is disabled
koda
parents: 8213
diff changeset
   113
        // 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
   114
        cStereoMode:= TStereoMode(max(0, min(ord(high(TStereoMode)), tmp)))
8221
5e2dc5813408 don't set stereomode when stereo is disabled
koda
parents: 8213
diff changeset
   115
    else
5e2dc5813408 don't set stereomode when stereo is disabled
koda
parents: 8213
diff changeset
   116
        // 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
   117
        cStereoMode:= TStereoMode(max(0, min(ord(high(TStereoMode)), tmp-6)));
8221
5e2dc5813408 don't set stereomode when stereo is disabled
koda
parents: 8213
diff changeset
   118
{$ELSE}
8325
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   119
    cStereoMode:= smNone;
8221
5e2dc5813408 don't set stereomode when stereo is disabled
koda
parents: 8213
diff changeset
   120
{$ENDIF}
3678
00428183300f patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff changeset
   121
end;
00428183300f patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff changeset
   122
8325
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   123
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
   124
begin
8325
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   125
{$IFDEF USE_VIDEO_RECORDING}
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   126
    GameType:= gmtRecord;
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   127
    inc(paramIndex);
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   128
    cVideoFramerateNum:= StrToInt(ParamStr(paramIndex)); inc(paramIndex);
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   129
    cVideoFramerateDen:= StrToInt(ParamStr(paramIndex)); inc(paramIndex);
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   130
    RecPrefix:= ParamStr(paramIndex);                    inc(paramIndex);
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   131
    cAVFormat:= ParamStr(paramIndex);                    inc(paramIndex);
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   132
    cVideoCodec:= ParamStr(paramIndex);                  inc(paramIndex);
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   133
    cVideoQuality:= StrToInt(ParamStr(paramIndex));      inc(paramIndex);
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   134
    cAudioCodec:= ParamStr(paramIndex);                  inc(paramIndex);
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   135
{$ENDIF}
3678
00428183300f patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff changeset
   136
end;
00428183300f patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff changeset
   137
8150
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   138
function getLongIntParameter(str:String; var paramIndex:LongInt; var wrongParameter:Boolean): LongInt;
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   139
var tmpInt, c: LongInt;
3678
00428183300f patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff changeset
   140
begin
8308
cdf83bdf7b27 move GetParams in ArgParser, print a warning when using a deprecated command, pascalisation of +1s
koda
parents: 8307
diff changeset
   141
    inc(paramIndex);
8150
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   142
    val(str, tmpInt, c);
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   143
    wrongParameter:= c <> 0;
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   144
    if wrongParameter then
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   145
        WriteLn(stderr, 'ERROR: '+ParamStr(paramIndex-1)+' expects a number, you passed "'+str+'"');
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   146
    getLongIntParameter:= tmpInt;
3678
00428183300f patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff changeset
   147
end;
00428183300f patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff changeset
   148
8302
a7934cd12469 improve engine cmd line parsing and its documentation
RowanD
parents: 8221
diff changeset
   149
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
   150
begin
8308
cdf83bdf7b27 move GetParams in ArgParser, print a warning when using a deprecated command, pascalisation of +1s
koda
parents: 8307
diff changeset
   151
    inc(paramIndex);
8302
a7934cd12469 improve engine cmd line parsing and its documentation
RowanD
parents: 8221
diff changeset
   152
    wrongParameter:= (str='') or (Copy(str,1,2) = '--');
a7934cd12469 improve engine cmd line parsing and its documentation
RowanD
parents: 8221
diff changeset
   153
    if wrongParameter then
a7934cd12469 improve engine cmd line parsing and its documentation
RowanD
parents: 8221
diff changeset
   154
         WriteLn(stderr, 'ERROR: '+ParamStr(paramIndex-1)+' expects a string, you passed "'+str+'"');
8150
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   155
    getStringParameter:= str;
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
8332
9333216f2054 fix hwc install and pas2c preprocessing (but not total conversion)
koda
parents: 8330
diff changeset
   158
procedure parseClassicParameter(cmdArray: array of String; size:LongInt; var paramIndex:LongInt); forward;
8150
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   159
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   160
function parseParameter(cmd:String; arg:String; var paramIndex:LongInt): Boolean;
8332
9333216f2054 fix hwc install and pas2c preprocessing (but not total conversion)
koda
parents: 8330
diff changeset
   161
const videoArray: array [1..3] of String = ('--width','--height','--depth');
9333216f2054 fix hwc install and pas2c preprocessing (but not total conversion)
koda
parents: 8330
diff changeset
   162
      audioArray: array [1..3] of String = ('--volume','--nomusic','--nosound');
9333216f2054 fix hwc install and pas2c preprocessing (but not total conversion)
koda
parents: 8330
diff changeset
   163
      otherArray: array [1..3] of String = ('--locale','--fullscreen','--showfps');
9333216f2054 fix hwc install and pas2c preprocessing (but not total conversion)
koda
parents: 8330
diff changeset
   164
      mediaArray: array [1..8] of String = ('--width','--height','--depth','--volume','--nomusic','--nosound','--locale','--fullscreen');
9333216f2054 fix hwc install and pas2c preprocessing (but not total conversion)
koda
parents: 8330
diff changeset
   165
      allArray: array [1..12] of String = ('--width','--height','--depth','--volume','--nomusic','--nosound','--locale','--fullscreen','--showfps','--altdmg','--frame-interval','--low-quality');
8325
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   166
      reallyAll: array[0..28] of shortstring = (
8307
8d7c52b24e28 GCI2012: Optional Second Argument
RowanD
parents: 8302
diff changeset
   167
                '--prefix', '--user-prefix', '--locale', '--width', '--height', '--frame-interval', '--volume','--nomusic', '--nosound',
8325
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   168
                '--fullscreen', '--showfps', '--altdmg', '--low-quality', '--raw-quality', '--stereo', '--nick',
8302
a7934cd12469 improve engine cmd line parsing and its documentation
RowanD
parents: 8221
diff changeset
   169
  {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
   170
  {internal}    '--internal', '--port', '--recorder', '--landpreview',
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   171
  {misc}        '--stats-only', '--gci', '--help');
8197
6d9371d6d045 Unbreak build with freepascal < 2.6.0
unc0rr
parents: 8150
diff changeset
   172
var cmdIndex: byte;
3678
00428183300f patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff changeset
   173
begin
8150
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   174
    parseParameter:= false;
8197
6d9371d6d045 Unbreak build with freepascal < 2.6.0
unc0rr
parents: 8150
diff changeset
   175
    cmdIndex:= 0;
8302
a7934cd12469 improve engine cmd line parsing and its documentation
RowanD
parents: 8221
diff changeset
   176
a7934cd12469 improve engine cmd line parsing and its documentation
RowanD
parents: 8221
diff changeset
   177
    //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
   178
    //      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
   179
8197
6d9371d6d045 Unbreak build with freepascal < 2.6.0
unc0rr
parents: 8150
diff changeset
   180
    while (cmdIndex <= High(reallyAll)) and (cmd <> reallyAll[cmdIndex]) do inc(cmdIndex);
6d9371d6d045 Unbreak build with freepascal < 2.6.0
unc0rr
parents: 8150
diff changeset
   181
    case cmdIndex of
8307
8d7c52b24e28 GCI2012: Optional Second Argument
RowanD
parents: 8302
diff changeset
   182
        {--prefix}          0 : PathPrefix     := getStringParameter (arg, paramIndex, parseParameter);
8d7c52b24e28 GCI2012: Optional Second Argument
RowanD
parents: 8302
diff changeset
   183
        {--user-prefix}     1 : UserPathPrefix := getStringParameter (arg, paramIndex, parseParameter);
8d7c52b24e28 GCI2012: Optional Second Argument
RowanD
parents: 8302
diff changeset
   184
        {--locale}          2 : cLocaleFName   := getStringParameter (arg, paramIndex, parseParameter);
8d7c52b24e28 GCI2012: Optional Second Argument
RowanD
parents: 8302
diff changeset
   185
        {--width}           3 : cScreenWidth   := getLongIntParameter(arg, paramIndex, parseParameter);
8d7c52b24e28 GCI2012: Optional Second Argument
RowanD
parents: 8302
diff changeset
   186
        {--height}          4 : cScreenHeight  := getLongIntParameter(arg, paramIndex, parseParameter);
8d7c52b24e28 GCI2012: Optional Second Argument
RowanD
parents: 8302
diff changeset
   187
        {--frame-interval}  5 : cTimerInterval := getLongIntParameter(arg, paramIndex, parseParameter);
8d7c52b24e28 GCI2012: Optional Second Argument
RowanD
parents: 8302
diff changeset
   188
        {--volume}          6 : SetVolume       ( getLongIntParameter(arg, paramIndex, parseParameter) );
8d7c52b24e28 GCI2012: Optional Second Argument
RowanD
parents: 8302
diff changeset
   189
        {--nomusic}         7 : SetMusic        ( false );
8d7c52b24e28 GCI2012: Optional Second Argument
RowanD
parents: 8302
diff changeset
   190
        {--nosound}         8 : SetSound        ( false );
8d7c52b24e28 GCI2012: Optional Second Argument
RowanD
parents: 8302
diff changeset
   191
        {--fullscreen}      9 : cFullScreen    := true;
8d7c52b24e28 GCI2012: Optional Second Argument
RowanD
parents: 8302
diff changeset
   192
        {--showfps}        10 : cShowFPS       := true;
8d7c52b24e28 GCI2012: Optional Second Argument
RowanD
parents: 8302
diff changeset
   193
        {--altdmg}         11 : cAltDamage     := true;
8d7c52b24e28 GCI2012: Optional Second Argument
RowanD
parents: 8302
diff changeset
   194
        {--low-quality}    12 : cReducedQuality:= $FFFFFFFF xor rqLowRes;
8d7c52b24e28 GCI2012: Optional Second Argument
RowanD
parents: 8302
diff changeset
   195
        {--raw-quality}    13 : cReducedQuality:= getLongIntParameter(arg, paramIndex, parseParameter);
8325
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   196
        {--stereo}         14 : setStereoMode   ( getLongIntParameter(arg, paramIndex, parseParameter) );
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   197
        {--nick}           15 : UserNick       := parseNick( getStringParameter(arg, paramIndex, parseParameter) );
8302
a7934cd12469 improve engine cmd line parsing and its documentation
RowanD
parents: 8221
diff changeset
   198
        {deprecated options}
8325
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   199
        {--depth}          16 : setDepth(paramIndex);
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   200
        {--set-video}      17 : parseClassicParameter(videoArray,3,paramIndex);
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   201
        {--set-audio}      18 : parseClassicParameter(audioArray,3,paramIndex);
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   202
        {--set-other}      19 : parseClassicParameter(otherArray,3,paramIndex);
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   203
        {--set-multimedia} 20 : parseClassicParameter(mediaArray,8,paramIndex);
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   204
        {--set-everything} 21 : parseClassicParameter(allArray,12,paramIndex);
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   205
        {"internal" options}
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   206
        {--internal}       22 : {note it, but do nothing};
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   207
        {--port}            23 : setIpcPort( getLongIntParameter(arg, paramIndex, parseParameter), parseParameter );
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   208
        {--recorder}       24 : startVideoRecording(paramIndex);
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   209
        {--landpreview}    25 : GameType := gmtLandPreview;
8302
a7934cd12469 improve engine cmd line parsing and its documentation
RowanD
parents: 8221
diff changeset
   210
        {anything else}
8325
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   211
        {--stats-only}     26 : statsOnlyGame();
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   212
        {--gci}            27 : GciEasterEgg();
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   213
        {--help}           28 : DisplayUsage();
8150
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   214
    else
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   215
        begin
8307
8d7c52b24e28 GCI2012: Optional Second Argument
RowanD
parents: 8302
diff changeset
   216
        //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
   217
        if (recordFileName = '') and (Copy(cmd,1,2) <> '--') then
8307
8d7c52b24e28 GCI2012: Optional Second Argument
RowanD
parents: 8302
diff changeset
   218
            recordFileName := cmd
8d7c52b24e28 GCI2012: Optional Second Argument
RowanD
parents: 8302
diff changeset
   219
        else
8d7c52b24e28 GCI2012: Optional Second Argument
RowanD
parents: 8302
diff changeset
   220
            begin
8325
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   221
            WriteLn(stderr, '"'+cmd+'" is not a valid option');
8307
8d7c52b24e28 GCI2012: Optional Second Argument
RowanD
parents: 8302
diff changeset
   222
            parseParameter:= true;
8d7c52b24e28 GCI2012: Optional Second Argument
RowanD
parents: 8302
diff changeset
   223
            end;
8d7c52b24e28 GCI2012: Optional Second Argument
RowanD
parents: 8302
diff changeset
   224
        end;
8150
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   225
    end;
3678
00428183300f patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff changeset
   226
end;
00428183300f patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff changeset
   227
8332
9333216f2054 fix hwc install and pas2c preprocessing (but not total conversion)
koda
parents: 8330
diff changeset
   228
procedure parseClassicParameter(cmdArray: array of String; size:LongInt; var paramIndex:LongInt);
8150
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   229
var index, tmpInt: LongInt;
8325
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   230
    isBool, isValid: Boolean;
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   231
    cmd, arg, newSyntax: String;
3678
00428183300f patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff changeset
   232
begin
8308
cdf83bdf7b27 move GetParams in ArgParser, print a warning when using a deprecated command, pascalisation of +1s
koda
parents: 8307
diff changeset
   233
    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
   234
    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
   235
    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
   236
    WriteLn(stdout, '');
cdf83bdf7b27 move GetParams in ArgParser, print a warning when using a deprecated command, pascalisation of +1s
koda
parents: 8307
diff changeset
   237
8150
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   238
    index:= 0;
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   239
    tmpInt:= 1;
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   240
    while (index < size) do
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   241
        begin
8325
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   242
        inc(paramIndex);
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   243
        cmd:= cmdArray[index];
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   244
        arg:= ParamStr(paramIndex);
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   245
        isValid:= (cmd<>'--depth');
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   246
8197
6d9371d6d045 Unbreak build with freepascal < 2.6.0
unc0rr
parents: 8150
diff changeset
   247
        // check if the parameter is a boolean one
8325
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   248
        isBool:= (cmd = '--nomusic') or (cmd = '--nosound') or (cmd = '--fullscreen') or (cmd = '--showfps') or (cmd = '--altdmg');
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   249
        if isBool and (arg='0') then
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   250
            isValid:= false;
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   251
        if (cmd='--nomusic') or (cmd='--nosound') then
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   252
            isValid:= not isValid;
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   253
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   254
        if isValid then
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   255
            begin
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   256
            parseParameter(cmd, arg, tmpInt);
8332
9333216f2054 fix hwc install and pas2c preprocessing (but not total conversion)
koda
parents: 8330
diff changeset
   257
            newSyntax:= newSyntax + cmd + ' ';
8325
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   258
            if not isBool then
8332
9333216f2054 fix hwc install and pas2c preprocessing (but not total conversion)
koda
parents: 8330
diff changeset
   259
                newSyntax:= newSyntax + arg + ' ';
8325
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   260
            end;
8308
cdf83bdf7b27 move GetParams in ArgParser, print a warning when using a deprecated command, pascalisation of +1s
koda
parents: 8307
diff changeset
   261
        inc(index);
8150
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   262
        end;
8330
aaefa587e277 update branch with default
koda
parents: 8327
diff changeset
   263
8325
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   264
    WriteLn(stdout, 'Attempted to automatically convert to the new syntax:');
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   265
    WriteLn(stdout, newSyntax);
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   266
    WriteLn(stdout, '');
3678
00428183300f patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff changeset
   267
end;
00428183300f patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff changeset
   268
8327
a6f3452f5f94 convert Game() library call to argc,argv format so that we can use the new parsing functions
koda
parents: 8325
diff changeset
   269
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
   270
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
   271
    paramTotal: LongInt;
3678
00428183300f patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff changeset
   272
    wrongParameter: boolean;
00428183300f patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff changeset
   273
begin
8308
cdf83bdf7b27 move GetParams in ArgParser, print a warning when using a deprecated command, pascalisation of +1s
koda
parents: 8307
diff changeset
   274
    paramIndex:= 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
   275
    paramTotal:={$IFDEF HWLIBRARY}argc{$ELSE}ParamCount{$ENDIF};
3678
00428183300f patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff changeset
   276
    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
   277
    while (paramIndex <= paramTotal) do
3678
00428183300f patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff changeset
   278
        begin
8327
a6f3452f5f94 convert Game() library call to argc,argv format so that we can use the new parsing functions
koda
parents: 8325
diff changeset
   279
        {$IFDEF HWLIBRARY}
a6f3452f5f94 convert Game() library call to argc,argv format so that we can use the new parsing functions
koda
parents: 8325
diff changeset
   280
        wrongParameter:= parseParameter( argv[paramIndex], argv[paramIndex+1], paramIndex);
a6f3452f5f94 convert Game() library call to argc,argv format so that we can use the new parsing functions
koda
parents: 8325
diff changeset
   281
        {$ELSE}
a6f3452f5f94 convert Game() library call to argc,argv format so that we can use the new parsing functions
koda
parents: 8325
diff changeset
   282
        wrongParameter:= parseParameter( ParamStr(paramIndex), ParamStr(paramIndex+1), paramIndex);
a6f3452f5f94 convert Game() library call to argc,argv format so that we can use the new parsing functions
koda
parents: 8325
diff changeset
   283
        {$ENDIF}
8308
cdf83bdf7b27 move GetParams in ArgParser, print a warning when using a deprecated command, pascalisation of +1s
koda
parents: 8307
diff changeset
   284
        inc(paramIndex);
8150
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   285
        end;
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   286
    if wrongParameter = true then
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   287
        GameType:= gmtSyntax;
3678
00428183300f patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff changeset
   288
end;
8308
cdf83bdf7b27 move GetParams in ArgParser, print a warning when using a deprecated command, pascalisation of +1s
koda
parents: 8307
diff changeset
   289
8327
a6f3452f5f94 convert Game() library call to argc,argv format so that we can use the new parsing functions
koda
parents: 8325
diff changeset
   290
{$IFNDEF HWLIBRARY}
8308
cdf83bdf7b27 move GetParams in ArgParser, print a warning when using a deprecated command, pascalisation of +1s
koda
parents: 8307
diff changeset
   291
procedure GetParams;
8325
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   292
//var tmpInt: LongInt;
8308
cdf83bdf7b27 move GetParams in ArgParser, print a warning when using a deprecated command, pascalisation of +1s
koda
parents: 8307
diff changeset
   293
begin
cdf83bdf7b27 move GetParams in ArgParser, print a warning when using a deprecated command, pascalisation of +1s
koda
parents: 8307
diff changeset
   294
    (*
cdf83bdf7b27 move GetParams in ArgParser, print a warning when using a deprecated command, pascalisation of +1s
koda
parents: 8307
diff changeset
   295
    tmpInt:=0;
cdf83bdf7b27 move GetParams in ArgParser, print a warning when using a deprecated command, pascalisation of +1s
koda
parents: 8307
diff changeset
   296
    while (tmpInt <= ParamCount) do
cdf83bdf7b27 move GetParams in ArgParser, print a warning when using a deprecated command, pascalisation of +1s
koda
parents: 8307
diff changeset
   297
        begin
8325
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   298
        WriteLn(stdout, inttostr(tmpInt) + ': ' + ParamStr(tmpInt));
8308
cdf83bdf7b27 move GetParams in ArgParser, print a warning when using a deprecated command, pascalisation of +1s
koda
parents: 8307
diff changeset
   299
        inc(tmpInt);
cdf83bdf7b27 move GetParams in ArgParser, print a warning when using a deprecated command, pascalisation of +1s
koda
parents: 8307
diff changeset
   300
        end;
cdf83bdf7b27 move GetParams in ArgParser, print a warning when using a deprecated command, pascalisation of +1s
koda
parents: 8307
diff changeset
   301
    *)
cdf83bdf7b27 move GetParams in ArgParser, print a warning when using a deprecated command, pascalisation of +1s
koda
parents: 8307
diff changeset
   302
8325
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   303
    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
   304
cdf83bdf7b27 move GetParams in ArgParser, print a warning when using a deprecated command, pascalisation of +1s
koda
parents: 8307
diff changeset
   305
    UserPathPrefix := '.';
cdf83bdf7b27 move GetParams in ArgParser, print a warning when using a deprecated command, pascalisation of +1s
koda
parents: 8307
diff changeset
   306
    PathPrefix     := cDefaultPathPrefix;
cdf83bdf7b27 move GetParams in ArgParser, print a warning when using a deprecated command, pascalisation of +1s
koda
parents: 8307
diff changeset
   307
    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
   308
    parseCommandLine();
8308
cdf83bdf7b27 move GetParams in ArgParser, print a warning when using a deprecated command, pascalisation of +1s
koda
parents: 8307
diff changeset
   309
8325
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   310
    if (isInternal) and (ParamCount<=1) then
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   311
        begin
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   312
        WriteLn(stderr, '--internal should not be manually used');
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   313
        GameType := gmtSyntax;
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   314
        end;
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   315
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   316
    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
   317
        begin
8325
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   318
        WriteLn(stderr, 'You must specify a replay file');
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   319
        GameType := gmtSyntax;
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   320
        end
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   321
    else if (recordFileName <> '') then
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   322
        WriteLn(stdout, 'Attempting to play demo file "' + recordFilename + '"');
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   323
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   324
    if (GameType = gmtSyntax) then
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   325
        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
   326
8308
cdf83bdf7b27 move GetParams in ArgParser, print a warning when using a deprecated command, pascalisation of +1s
koda
parents: 8307
diff changeset
   327
    (*
cdf83bdf7b27 move GetParams in ArgParser, print a warning when using a deprecated command, pascalisation of +1s
koda
parents: 8307
diff changeset
   328
    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
   329
    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
   330
    *)
cdf83bdf7b27 move GetParams in ArgParser, print a warning when using a deprecated command, pascalisation of +1s
koda
parents: 8307
diff changeset
   331
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
   332
{$ENDIF}
a6f3452f5f94 convert Game() library call to argc,argv format so that we can use the new parsing functions
koda
parents: 8325
diff changeset
   333