19 {$INCLUDE "options.inc"} |
19 {$INCLUDE "options.inc"} |
20 |
20 |
21 unit ArgParsers; |
21 unit ArgParsers; |
22 interface |
22 interface |
23 |
23 |
24 {$IFNDEF HWLIBRARY} |
|
25 procedure GetParams; |
24 procedure GetParams; |
26 {$ELSE} |
25 {$IFDEF HWLIBRARY} |
27 procedure parseCommandLine(argc: LongInt; argv: PPChar); |
26 var operatingsystem_parameter_argc: LongInt = 0; export; |
28 |
|
29 var operatingsystem_parameter_argc: integer = 0; export; |
|
30 operatingsystem_parameter_argv: pointer = nil; export; |
27 operatingsystem_parameter_argv: pointer = nil; export; |
31 operatingsystem_parameter_envp: pointer = nil; export; |
28 operatingsystem_parameter_envp: pointer = nil; export; |
|
29 |
|
30 function ParamCount: LongInt; |
|
31 function ParamStr(i: LongInt): shortstring; |
32 {$ENDIF} |
32 {$ENDIF} |
33 |
33 |
34 implementation |
34 implementation |
35 uses uVariables, uTypes, uUtils, uSound, uConsts; |
35 uses uVariables, uTypes, uUtils, uSound, uConsts; |
36 var isInternal: Boolean {$IFDEF HWLIBRARY} = true{$ENDIF}; |
36 var isInternal: Boolean; |
|
37 |
|
38 {$IFDEF HWLIBRARY} |
|
39 |
|
40 type PCharArray = array[0..255] of PChar; |
|
41 PPCharArray = ^PCharArray; |
|
42 |
|
43 function ParamCount: LongInt; |
|
44 begin |
|
45 ParamCount:= operatingsystem_parameter_argc - 1 |
|
46 end; |
|
47 |
|
48 function ParamStr(i: LongInt): shortstring; |
|
49 begin |
|
50 ParamStr:= StrPas(PPCharArray(operatingsystem_parameter_argv)^[i]) |
|
51 end; |
|
52 |
|
53 {$ENDIF} |
37 |
54 |
38 procedure GciEasterEgg; |
55 procedure GciEasterEgg; |
39 begin |
56 begin |
40 WriteLn(stdout, ' '); |
57 WriteLn(stdout, ' '); |
41 WriteLn(stdout, ' /\\\\\\\\\\\\ /\\\\\\\\\ /\\\\\\\\\\\ '); |
58 WriteLn(stdout, ' /\\\\\\\\\\\\ /\\\\\\\\\ /\\\\\\\\\\\ '); |
308 WriteLn(stdout, 'Attempted to automatically convert to the new syntax:'); |
325 WriteLn(stdout, 'Attempted to automatically convert to the new syntax:'); |
309 WriteLn(stdout, newSyntax); |
326 WriteLn(stdout, newSyntax); |
310 WriteLn(stdout, ''); |
327 WriteLn(stdout, ''); |
311 end; |
328 end; |
312 |
329 |
313 procedure parseCommandLine{$IFDEF HWLIBRARY}(argc: LongInt; argv: PPChar){$ENDIF}; |
330 procedure parseCommandLine; |
314 var paramIndex: LongInt; |
331 var paramIndex: LongInt; |
315 paramTotal: LongInt; |
332 paramTotal: LongInt; |
316 index, nextIndex: LongInt; |
333 index, nextIndex: LongInt; |
317 wrongParameter: boolean; |
334 wrongParameter: boolean; |
318 //var tmpInt: LongInt; |
335 //var tmpInt: LongInt; |
319 begin |
336 begin |
320 {$IFDEF HWLIBRARY} |
337 |
321 operatingsystem_parameter_argc:= argc; |
338 paramIndex:= 1; |
322 operatingsystem_parameter_argv:= argv; |
339 paramTotal:= ParamCount; //-1 because pascal enumeration is inclusive |
323 {$ENDIF} |
|
324 |
|
325 paramIndex:= {$IFDEF HWLIBRARY}0{$ELSE}1{$ENDIF}; |
|
326 paramTotal:= {$IFDEF HWLIBRARY}argc-1{$ELSE}ParamCount{$ENDIF}; //-1 because pascal enumeration is inclusive |
|
327 (* |
340 (* |
328 WriteLn(stdout, 'total parameters: ' + inttostr(paramTotal)); |
341 WriteLn(stdout, 'total parameters: ' + inttostr(paramTotal)); |
329 tmpInt:= 0; |
342 tmpInt:= 0; |
330 while (tmpInt <= paramTotal) do |
343 while (tmpInt <= paramTotal) do |
331 begin |
344 begin |
338 begin |
351 begin |
339 // avoid going past the number of paramTotal (esp. w/ library) |
352 // avoid going past the number of paramTotal (esp. w/ library) |
340 index:= paramIndex; |
353 index:= paramIndex; |
341 if index = paramTotal then nextIndex:= index |
354 if index = paramTotal then nextIndex:= index |
342 else nextIndex:= index+1; |
355 else nextIndex:= index+1; |
343 {$IFDEF HWLIBRARY} |
|
344 wrongParameter:= parseParameter( argv[index], argv[nextIndex], paramIndex); |
|
345 {$ELSE} |
|
346 wrongParameter:= parseParameter( ParamStr(index), ParamStr(nextIndex), paramIndex); |
356 wrongParameter:= parseParameter( ParamStr(index), ParamStr(nextIndex), paramIndex); |
347 {$ENDIF} |
|
348 inc(paramIndex); |
357 inc(paramIndex); |
349 end; |
358 end; |
350 if wrongParameter = true then |
359 if wrongParameter = true then |
351 GameType:= gmtSyntax; |
360 GameType:= gmtSyntax; |
352 end; |
361 end; |
353 |
362 |
354 {$IFNDEF HWLIBRARY} |
|
355 procedure GetParams; |
363 procedure GetParams; |
356 begin |
364 begin |
357 isInternal:= (ParamStr(1) = '--internal'); |
365 isInternal:= (ParamStr(1) = '--internal'); |
358 |
366 |
359 UserPathPrefix := _S'.'; |
367 UserPathPrefix := _S'.'; |