aboutsummaryrefslogtreecommitdiffstats
path: root/cmake/src/base/UCommandLine.pas
blob: ac0db2c24c50066ecc1d5a63f9cbaafa74551dcd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
{* UltraStar Deluxe - Karaoke Game
 *
 * UltraStar Deluxe is the legal property of its developers, whose names
 * are too numerous to list here. Please refer to the COPYRIGHT
 * file distributed with this source distribution.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; see the file COPYING. If not, write to
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 *
 * $URL$
 * $Id$
 *}

unit UCommandLine;

interface

{$IFDEF FPC}
  {$MODE Delphi}
{$ENDIF}

{$I switches.inc}

uses
  UPath;

type
  TScreenMode = (scmDefault, scmFullscreen, scmWindowed);

  {**
   * Reads infos from ParamStr and set some easy interface variables
   *}
  TCMDParams = class
    private
      fLanguage:   string;
      fResolution: string;

      procedure ShowHelp();

      procedure ReadParamInfo;
      procedure ResetVariables;

      function GetLanguage:   integer;
      function GetResolution: integer;
    public
      // some boolean variables set when reading infos
      Debug:      boolean;
      Benchmark:  boolean;
      NoLog:      boolean;
      ScreenMode: TScreenMode;
      Joypad:     boolean;

      // some value variables set when reading infos {-1: Not Set, others: Value}
      Depth:      integer;
      Screens:    integer;

      // some strings set when reading infos {Length=0: Not Set}
      SongPath:   IPath;
      ConfigFile: IPath;
      ScoreFile:  IPath;

      // pseudo integer values
      property Language:      integer read GetLanguage;
      property Resolution:    integer read GetResolution;

      // some procedures for reading infos
      constructor Create;
  end;

var
  Params:    TCMDParams;
  
const
  cHelp            = 'help';
  cDebug           = 'debug';
  cMediaInterfaces = 'showinterfaces';


implementation

uses SysUtils,
     UPlatform;

{**
 * Resets variables and reads info
 *}
constructor TCMDParams.Create;
begin
  inherited;
  
  if FindCmdLineSwitch( cHelp ) or FindCmdLineSwitch( 'h' ) then
    ShowHelp();

  ResetVariables;
  ReadParamInfo;
end;

procedure TCMDParams.ShowHelp();

  function Fmt(aString : string) : string;
  begin
    Result := Format('%-15s', [aString]);
  end;

begin
  writeln;
  writeln('**************************************************************');
  writeln('  UltraStar Deluxe - Command line switches                    ');
  writeln('**************************************************************');
  writeln;
  writeln('  '+ Fmt('Switch') +' : Purpose');
  writeln('  ----------------------------------------------------------');
  writeln('  '+ Fmt(cMediaInterfaces) +' : Show in-use media interfaces');
  writeln('  '+ Fmt(cDebug) +' : Display Debugging info');
  writeln;

  platform.halt;
end;

{**
 * Reset Class Variables
 *}
procedure TCMDParams.ResetVariables;
begin
  Debug       := False;
  Benchmark   := False;
  NoLog       := False;
  ScreenMode  := scmDefault;
  Joypad      := False;

  // some value variables set when reading infos {-1: Not Set, others: Value}
  fResolution := '';
  fLanguage   := '';
  Depth       := -1;
  Screens     := -1;

  // some strings set when reading infos {Length=0 Not Set}
  SongPath    := PATH_NONE;
  ConfigFile  := PATH_NONE;
  ScoreFile   := PATH_NONE;
end;

{**
 * Read command-line parameters
 *}
procedure TCMDParams.ReadParamInfo;
var
  I:        integer;
  PCount:   integer;
  Command:  string;
begin
  PCount := ParamCount;
  //Log.LogError('ParamCount: ' + Inttostr(PCount));
  
  // check all parameters
  for I := 1 to PCount do
  begin
    Command := ParamStr(I);
    // check if the string is a parameter
    if (Length(Command) > 1) and (Command[1] = '-') then
    begin
      // remove '-' from command
      Command := LowerCase(Trim(Copy(Command, 2, Length(Command) - 1)));
      //Log.LogError('Command prepared: ' + Command);

      // check command

      // boolean triggers
      if (Command = 'debug') then
        Debug       := True
      else if (Command = 'benchmark') then
        Benchmark   := True
      else if (Command = 'nolog') then
        NoLog       := True
      else if (Command = 'fullscreen') then
        ScreenMode  := scmFullscreen
      else if (Command = 'window') then
        ScreenMode  := scmWindowed
      else if (Command = 'joypad') then
        Joypad    := True

      // integer variables
      else if (Command = 'depth') then
      begin
        // check if there is another Parameter to get the Value from
        if (PCount > I) then
        begin
          Command := ParamStr(I + 1);

          // check for valid value
          // FIXME: guessing an array-index of depth is very error prone.  
          If (Command = '16') then
            Depth := 0
          Else If (Command = '32') then
            Depth := 1;
        end;
      end

      else if (Command = 'screens') then
      begin
        // check if there is another parameter to get the value from
        if (PCount > I) then
        begin
          Command := ParamStr(I + 1);

          // check for valid value
          If (Command = '1') then
            Screens := 0
          Else If (Command = '2') then
            Screens := 1;
        end;
      end

      // pseudo integer values
      else if (Command = 'language') then
      begin
        // check if there is another parameter to get the value from
        if (PCount > I) then
        begin
          // write value to string
          fLanguage := Lowercase(ParamStr(I + 1));
        end;
      end

      else if (Command = 'resolution') then
      begin
        // check if there is another parameter to get the value from
        if (PCount > I) then
        begin
          // write value to string
          fResolution := Lowercase(ParamStr(I + 1));
        end;
      end

      // string values
      else if (Command = 'songpath') then
      begin
        // check if there is another parameter to get the value from
        if (PCount > I) then
        begin
          // write value to string
          SongPath := Path(ParamStr(I + 1));
        end;
      end

      else if (Command = 'configfile') then
      begin
        // check if there is another parameter to get the value from
        if (PCount > I) then
        begin
          // write value to string
          ConfigFile := Path(ParamStr(I + 1));

          // is this a relative path -> then add gamepath
          if (not ConfigFile.IsAbsolute) then
            ConfigFile := Platform.GetExecutionDir().Append(ConfigFile);
        end;
      end

      else if (Command = 'scorefile') then
      begin
        // check if there is another parameter to get the value from
        if (PCount > I) then
        begin
          // write value to string
          ScoreFile := Path(ParamStr(I + 1));
        end;
      end;

    end;

  end;

{
  Log.LogInfo('Screens: ' + Inttostr(Screens));
  Log.LogInfo('Depth: ' + Inttostr(Depth));

  Log.LogInfo('Resolution: ' + Inttostr(Resolution));
  Log.LogInfo('Resolution: ' + Inttostr(Language));

  Log.LogInfo('sResolution: ' + sResolution);
  Log.LogInfo('sLanguage: ' + sLanguage);

  Log.LogInfo('ConfigFile: ' + ConfigFile);
  Log.LogInfo('SongPath: ' + SongPath);
  Log.LogInfo('ScoreFile: ' + ScoreFile);
}

end;

//-------------
// GetLanguage - Get Language ID from saved String Information
//-------------
function TCMDParams.GetLanguage: integer;
{var
  I: integer;
}
begin
  Result := -1;
{*  JB - 12sep07 to remove uINI dependency

  //Search for Language
  For I := 0 to high(ILanguage) do
    if (LowerCase(ILanguage[I]) = sLanguage) then
    begin
      Result := I;
      Break;
    end;
*}
end;

//-------------
// GetResolution - Get Resolution ID from saved String Information
//-------------
function TCMDParams.GetResolution: integer;
{var
  I: integer;
}
begin
  Result := -1;
{*  JB - 12sep07 to remove uINI dependency

  //Search for Resolution
  For I := 0 to high(IResolution) do
    if (LowerCase(IResolution[I]) = sResolution) then
    begin
      Result := I;
      Break;
    end;
*}
end;

end.