hedgewars/ArgParsers.inc
author Rowan D
Fri, 30 Nov 2012 10:51:29 +0100
changeset 8150 6b30a4cd7c7c
parent 7848 775a72905708
child 8160 f837447298c3
child 8167 96635d815141
child 8197 6d9371d6d045
permissions -rw-r--r--
GCI2012: Command Line Parsing
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
00428183300f patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff changeset
    19
00428183300f patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff changeset
    20
procedure internalStartGameWithParameters();
4004
b1c2c2f6fc5e update branch with latest head, most likely breaking water color in stereo mode
koda
parents: 3858
diff changeset
    21
var tmp: LongInt;
3678
00428183300f patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff changeset
    22
begin
5239
f34f391a223b Bit more reusability
nemo
parents: 5238
diff changeset
    23
    UserPathPrefix:= ParamStr(1);
7151
ec15d9e1a7e3 pas2c stuff
unc0rr
parents: 7021
diff changeset
    24
    cScreenWidth:= StrToInt(ParamStr(2));
ec15d9e1a7e3 pas2c stuff
unc0rr
parents: 7021
diff changeset
    25
    cScreenHeight:= StrToInt(ParamStr(3));
ec15d9e1a7e3 pas2c stuff
unc0rr
parents: 7021
diff changeset
    26
    cBits:= StrToInt(ParamStr(4));
ec15d9e1a7e3 pas2c stuff
unc0rr
parents: 7021
diff changeset
    27
    ipcPort:= StrToInt(ParamStr(5));
3678
00428183300f patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff changeset
    28
    cFullScreen:= ParamStr(6) = '1';
7021
0c75512a8920 adjust the scope of a few uSound variables and functions
koda
parents: 6982
diff changeset
    29
    SetSound(ParamStr(7) = '1');
0c75512a8920 adjust the scope of a few uSound variables and functions
koda
parents: 6982
diff changeset
    30
    SetMusic(ParamStr(8) = '1');
7151
ec15d9e1a7e3 pas2c stuff
unc0rr
parents: 7021
diff changeset
    31
    SetVolume(StrToInt(ParamStr(9)));
ec15d9e1a7e3 pas2c stuff
unc0rr
parents: 7021
diff changeset
    32
    cTimerInterval:= StrToInt(ParamStr(10));
3709
c7849b74748d clean and reorder arguments passed to engine
koda
parents: 3708
diff changeset
    33
    PathPrefix:= ParamStr(11);
c7849b74748d clean and reorder arguments passed to engine
koda
parents: 3708
diff changeset
    34
    cShowFPS:= ParamStr(12) = '1';
c7849b74748d clean and reorder arguments passed to engine
koda
parents: 3708
diff changeset
    35
    cAltDamage:= ParamStr(13) = '1';
c7849b74748d clean and reorder arguments passed to engine
koda
parents: 3708
diff changeset
    36
    UserNick:= DecodeBase64(ParamStr(14));
7151
ec15d9e1a7e3 pas2c stuff
unc0rr
parents: 7021
diff changeset
    37
    cReducedQuality:= StrToInt(ParamStr(15));
ec15d9e1a7e3 pas2c stuff
unc0rr
parents: 7021
diff changeset
    38
    tmp:= StrToInt(ParamStr(16));
6982
8d41d22a291d breaking news, we don't support typed consts anymore
koda
parents: 6700
diff changeset
    39
    GrayScale:= false;
5441
39962b855540 Add grayscale option for 3d, helps with colour clashing
nemo
parents: 5239
diff changeset
    40
    if (tmp > 9) and (tmp < 16) then 
39962b855540 Add grayscale option for 3d, helps with colour clashing
nemo
parents: 5239
diff changeset
    41
        begin
6982
8d41d22a291d breaking news, we don't support typed consts anymore
koda
parents: 6700
diff changeset
    42
        GrayScale:= true;
5441
39962b855540 Add grayscale option for 3d, helps with colour clashing
nemo
parents: 5239
diff changeset
    43
        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
    44
        end
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6426
diff changeset
    45
    else if tmp <= 9 then 
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6426
diff changeset
    46
        cStereoMode:= TStereoMode(max(0, min(ord(high(TStereoMode)), tmp)))
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6426
diff changeset
    47
    else 
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6426
diff changeset
    48
        cStereoMode:= TStereoMode(max(0, min(ord(high(TStereoMode)), tmp-6)));
4004
b1c2c2f6fc5e update branch with latest head, most likely breaking water color in stereo mode
koda
parents: 3858
diff changeset
    49
    cLocaleFName:= ParamStr(17);
3678
00428183300f patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff changeset
    50
end;
00428183300f patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff changeset
    51
7198
5debd5fe526e 1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents: 7180
diff changeset
    52
{$IFDEF USE_VIDEO_RECORDING}
5debd5fe526e 1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents: 7180
diff changeset
    53
procedure internalStartVideoRecordingWithParameters();
5debd5fe526e 1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents: 7180
diff changeset
    54
begin
5debd5fe526e 1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents: 7180
diff changeset
    55
    internalStartGameWithParameters();
5debd5fe526e 1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents: 7180
diff changeset
    56
    GameType:= gmtRecord;
7376
48b79b3ca592 rework saving of camera positions so there is no need to know framerate during prerecording.
Stepan777 <stepik-777@mail.ru>
parents: 7306
diff changeset
    57
    cVideoFramerateNum:= StrToInt(ParamStr(18));
48b79b3ca592 rework saving of camera positions so there is no need to know framerate during prerecording.
Stepan777 <stepik-777@mail.ru>
parents: 7306
diff changeset
    58
    cVideoFramerateDen:= StrToInt(ParamStr(19));
7306
3cff5c769509 Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents: 7235
diff changeset
    59
    RecPrefix:= ParamStr(20);
7198
5debd5fe526e 1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents: 7180
diff changeset
    60
    cAVFormat:= ParamStr(21);
5debd5fe526e 1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents: 7180
diff changeset
    61
    cVideoCodec:= ParamStr(22);
5debd5fe526e 1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents: 7180
diff changeset
    62
    cVideoQuality:= StrToInt(ParamStr(23));
7376
48b79b3ca592 rework saving of camera positions so there is no need to know framerate during prerecording.
Stepan777 <stepik-777@mail.ru>
parents: 7306
diff changeset
    63
    cAudioCodec:= ParamStr(24);
7198
5debd5fe526e 1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents: 7180
diff changeset
    64
end;
5debd5fe526e 1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents: 7180
diff changeset
    65
{$ENDIF}
5debd5fe526e 1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents: 7180
diff changeset
    66
8150
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
    67
procedure DisplayUsage;
3678
00428183300f patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff changeset
    68
begin
8150
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
    69
    WriteLn(stdout, 'Usage:');
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
    70
    WriteLn(stdout, '');
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
    71
    WriteLn(stdout, '  hwengine <path to user hedgewars folder> <path to global data folder> <path to replay file> [options]');
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
    72
    WriteLn(stdout, '');
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
    73
    WriteLn(stdout, 'where [options] are any of the following:');
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
    74
    WriteLn(stdout, ' --locale [path to language file]');
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
    75
    WriteLn(stdout, ' --width  [screen width in pixels]');
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
    76
    WriteLn(stdout, ' --height [screen height in pixels]');
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
    77
    WriteLn(stdout, ' --depth  [color depth]');
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
    78
    WriteLn(stdout, ' --volume [sound level]');
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
    79
    WriteLn(stdout, ' --time   [number of seconds]');
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
    80
    WriteLn(stdout, ' --nomusic');
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
    81
    WriteLn(stdout, ' --nosound');
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
    82
    WriteLn(stdout, ' --fullscreen');
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
    83
    WriteLn(stdout, ' --showfps');
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
    84
    WriteLn(stdout, ' --altdmg');
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
    85
    WriteLn(stdout, ' --lowquality');
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
    86
    WriteLn(stdout, ' --stats-only');
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
    87
    WriteLn(stdout, ' --help');
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
    88
    WriteLn(stdout, '');
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
    89
    WriteLn(stdout, 'Deprecated options:');
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
    90
    WriteLn(stdout, ' --set-video [screen width] [screen height] [color dept]');
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
    91
    WriteLn(stdout, ' --set-audio [volume] [enable music] [enable sounds]');
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
    92
    WriteLn(stdout, ' --set-other [language file] [full screen] [show FPS]');
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
    93
    WriteLn(stdout, ' --set-multimedia [screen width] [screen height] [color dept] [volume] [enable music] [enable sounds] [language file] [full screen]');
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
    94
    WriteLn(stdout, ' --set-everything [screen width] [screen height] [color dept] [volume] [enable music] [enable sounds] [language file] [full screen] [show FPS] [alternate damage] [timer value] [reduced quality]');
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
    95
    WriteLn(stdout, '');
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
    96
    WriteLn(stdout, 'For a more detailed help and examples go to:');
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
    97
    WriteLn(stdout, 'http://code.google.com/p/hedgewars/wiki/CommandLineOptions');
3678
00428183300f patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff changeset
    98
end;
00428183300f patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff changeset
    99
8150
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   100
function getLongIntParameter(str:String; var paramIndex:LongInt; var wrongParameter:Boolean): LongInt;
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   101
var tmpInt, c: LongInt;
3678
00428183300f patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff changeset
   102
begin
8150
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   103
    paramIndex:= paramIndex + 1;
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   104
    val(str, tmpInt, c);
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   105
    wrongParameter:= c <> 0;
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   106
    if wrongParameter then
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   107
        WriteLn(stderr, 'ERROR: '+ParamStr(paramIndex-1)+' expects a number, you passed "'+str+'"');
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   108
    getLongIntParameter:= tmpInt;
3678
00428183300f patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff changeset
   109
end;
00428183300f patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff changeset
   110
8150
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   111
function getStringParameter(str:String; var paramIndex:LongInt): String;
3678
00428183300f patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff changeset
   112
begin
8150
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   113
    paramIndex:= paramIndex + 1;
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   114
    getStringParameter:= str;
3678
00428183300f patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff changeset
   115
end;
00428183300f patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff changeset
   116
8150
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   117
procedure parseClassicParameter(cmdArray: Array of String; size:LongInt; var paramIndex:LongInt); Forward;
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   118
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   119
function parseParameter(cmd:String; arg:String; var paramIndex:LongInt): Boolean;
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   120
const videoArray: Array [1..3] of String = ('--width','--height','--depth');
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   121
const audioArray: Array [1..3] of String = ('--volume','--nomusic','--nosound');
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   122
const otherArray: Array [1..3] of String = ('--locale','--fullscreen','--showfps');
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   123
const mediaArray: Array [1..8] of String = ('--width','--height','--depth','--volume','--nomusic','--nosound','--locale','--fullscreen');
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   124
const allArray: Array [1..12] of String = ('--width','--height','--depth','--volume','--nomusic','--nosound','--locale','--fullscreen','--showfps','--altdmg','--time','--lowquality');
3678
00428183300f patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff changeset
   125
begin
8150
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   126
    parseParameter:= false;
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   127
    case cmd of
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   128
        '--locale'     : cLocaleFName   := getStringParameter (arg, paramIndex);
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   129
        '--width'      : cScreenWidth   := getLongIntParameter(arg, paramIndex, parseParameter);
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   130
        '--height'     : cScreenHeight  := getLongIntParameter(arg, paramIndex, parseParameter);
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   131
        '--depth'      : cBits          := getLongIntParameter(arg, paramIndex, parseParameter);
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   132
        '--time'       : cTimerInterval := getLongIntParameter(arg, paramIndex, parseParameter);
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   133
        '--volume'     : SetVolume       ( getLongIntParameter(arg, paramIndex, parseParameter) );
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   134
        '--nomusic'    : SetMusic        ( false );
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   135
        '--nosound'    : SetSound        ( false );
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   136
        '--fullscreen' : cFullScreen    := true;
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   137
        '--showfps'    : cShowFPS       := true;
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   138
        '--altdmg'     : cAltDamage     := true;
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   139
        '--lowquality' : cReducedQuality:= ($FFFFFFFF * getLongIntParameter(arg, paramIndex, parseParameter)) xor rqLowRes; //HACK!
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   140
        '--set-video'      : parseClassicParameter(videoArray,3,paramIndex);
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   141
        '--set-audio'      : parseClassicParameter(audioArray,3,paramIndex);
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   142
        '--set-other'      : parseClassicParameter(otherArray,3,paramIndex);
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   143
        '--set-multimedia' : parseClassicParameter(mediaArray,8,paramIndex);
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   144
        '--set-everything' : parseClassicParameter(allArray,12,paramIndex);
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   145
        '--stats-only' : begin
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   146
                         cOnlyStats:= true;
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   147
                         SetSound(false);
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   148
                         SetMusic(false);
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   149
                         cReducedQuality:= $FFFFFFFF xor rqLowRes;
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   150
                         end;
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   151
        '--gci' : begin            //     We had to make up all this saved space some how...     \\
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   152
                  WriteLn(stdout, '                                                                ');
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   153
                  WriteLn(stdout, '      /\\\\\\\\\\\\        /\\\\\\\\\  /\\\\\\\\\\\             ');
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   154
                  WriteLn(stdout, '     /\\\//////////      /\\\////////  \/////\\\///             ');
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   155
                  WriteLn(stdout, '     /\\\               /\\\/               \/\\\               ');
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   156
                  WriteLn(stdout, '     \/\\\    /\\\\\\\  /\\\                 \/\\\              ');
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   157
                  WriteLn(stdout, '      \/\\\   \/////\\\ \/\\\                 \/\\\             ');
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   158
                  WriteLn(stdout, '       \/\\\       \/\\\ \//\\\                \/\\\            ');
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   159
                  WriteLn(stdout, '        \/\\\       \/\\\  \///\\\              \/\\\           ');
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   160
                  WriteLn(stdout, '         \//\\\\\\\\\\\\/     \////\\\\\\\\\  /\\\\\\\\\\\      ');
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   161
                  WriteLn(stdout, '          \////////////           \/////////  \///////////      ');
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   162
                  WriteLn(stdout, '                                                                ');
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   163
                  WriteLn(stdout, ' Command Line Parser Implementation by a Google Code-In Student ');
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   164
                  WriteLn(stdout, '             ASCII Art easter egg idea by @sheepluva            ');
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   165
                  WriteLn(stdout, '                                                                ');
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   166
                  end;
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   167
        '--help' : begin
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   168
                   DisplayUsage();
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   169
                   GameType:= gmtSyntax;
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   170
                   end;
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   171
    else
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   172
        begin
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   173
        WriteLn(stderr, 'ERROR: '+cmd+' is not a valid argument');
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   174
        parseParameter:= true;
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   175
        end
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   176
    end;
3678
00428183300f patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff changeset
   177
end;
00428183300f patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff changeset
   178
8150
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   179
procedure parseClassicParameter(cmdArray: Array of String; size:LongInt; var paramIndex:LongInt);
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   180
var index, tmpInt: LongInt;
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   181
    isBool: Boolean;
3678
00428183300f patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff changeset
   182
begin
8150
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   183
    index:= 0;
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   184
    tmpInt:= 1;
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   185
    while (index < size) do
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   186
        begin
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   187
        paramIndex:= paramIndex+1;
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   188
        //This next line is a really strange (but short), way to check if the parameter is a boolean one
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   189
        isBool:= true; case cmdArray[index] of '--nomusic':;'--nosound':;'--fullscreen':;'--showfps':;'--altdmg':;'--lowquality':; else isBool:= false; end;
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   190
        if (not isBool) or ((ParamStr(paramIndex)='1') and (cmdArray[index]<>'--nomusic') and (cmdArray[index]<>'--nosound')) then
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   191
            parseParameter(cmdArray[index], ParamStr(paramIndex), tmpInt);
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   192
        //if isBool then
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   193
        //  paramIndex:= paramIndex+1;
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   194
        index:= index+1;
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   195
        end;
3678
00428183300f patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff changeset
   196
end;
00428183300f patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff changeset
   197
00428183300f patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff changeset
   198
procedure playReplayFileWithParameters();
8150
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   199
var paramIndex, tmpInt: LongInt;
3678
00428183300f patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff changeset
   200
    wrongParameter: boolean;
00428183300f patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff changeset
   201
begin
5239
f34f391a223b Bit more reusability
nemo
parents: 5238
diff changeset
   202
    UserPathPrefix:= ParamStr(1);
5238
46ddaf14509d Enable ~/.hedgewars/Data (or platform equivalent) to override/extend pretty much everything in system Data dir. Obviously desyncing can occur, so this is at user's own risk. Should simplify map etc install. Needs testing.
nemo
parents: 5130
diff changeset
   203
    PathPrefix:= ParamStr(2);
46ddaf14509d Enable ~/.hedgewars/Data (or platform equivalent) to override/extend pretty much everything in system Data dir. Obviously desyncing can occur, so this is at user's own risk. Should simplify map etc install. Needs testing.
nemo
parents: 5130
diff changeset
   204
    recordFileName:= ParamStr(3);
46ddaf14509d Enable ~/.hedgewars/Data (or platform equivalent) to override/extend pretty much everything in system Data dir. Obviously desyncing can occur, so this is at user's own risk. Should simplify map etc install. Needs testing.
nemo
parents: 5130
diff changeset
   205
    paramIndex:= 4;
3678
00428183300f patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff changeset
   206
    wrongParameter:= false;
8150
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   207
    while (paramIndex <= ParamCount) do
3678
00428183300f patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff changeset
   208
        begin
8150
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   209
        if parseParameter( ParamStr(paramIndex), ParamStr(paramIndex+1), paramIndex) then
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   210
            wrongParameter:= true;
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   211
        paramIndex:= paramIndex+1;
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   212
        end;
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   213
    if wrongParameter = true then
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   214
        begin
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   215
        WriteLn(stderr, 'Please use --help to see possible arguments and their usage');
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   216
        GameType:= gmtSyntax;
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   217
        end
3678
00428183300f patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff changeset
   218
end;