diff options
Diffstat (limited to 'nim/nimrod.pas')
-rw-r--r-- | nim/nimrod.pas | 74 |
1 files changed, 33 insertions, 41 deletions
diff --git a/nim/nimrod.pas b/nim/nimrod.pas index 7f8512984..5d3785af4 100644 --- a/nim/nimrod.pas +++ b/nim/nimrod.pas @@ -6,7 +6,7 @@ // See the file "copying.txt", included in this // distribution, for details about the copyright. // -program nim; +program nimrod; {$include 'config.inc'} {@ignore} @@ -18,39 +18,37 @@ program nim; uses nsystem, charsets, sysutils, commands, scanner, condsyms, options, msgs, nversion, - nimconf, ropes, extccomp, strutils, nos, platform, main; + nimconf, ropes, extccomp, strutils, nos, platform, main, parseopt; var arguments: string = ''; // the arguments to be passed to the program that // should be run + cmdLineInfo: TLineInfo; -function ProcessCmdLine(pass: TCmdLinePass): string; +procedure ProcessCmdLine(pass: TCmdLinePass; var command, filename: string); var - i, paramCounter: int; - param: string; + p: TOptParser; begin - i := 1; - result := ''; - paramCounter := paramCount(); - while i <= paramCounter do begin - param := ParamStr(i); - if param[strStart] = '-' then begin - commands.ProcessCommand(param, pass); + p := parseopt.init(); + while true do begin + parseopt.next(p); + case p.kind of + cmdEnd: break; + cmdLongOption, cmdShortOption: + ProcessSwitch(p.key, p.val, pass, cmdLineInfo); + cmdArgument: begin + if command = '' then command := p.key + else if filename = '' then begin + filename := unixToNativePath(p.key); + // BUGFIX for portable build scripts + break + end + end end - else if i > 1 then begin - result := unixToNativePath(param); // BUGFIX for portable build scripts - options.compilerArgs := i; - break // do not process the arguments - end; - Inc(i) end; - inc(i); // skip program file // collect the arguments: if pass = passCmd2 then begin - while i <= paramCounter do begin - arguments := arguments + ' ' +{&} paramStr(i); - inc(i) - end; + arguments := getRestOfCommandLine(p); if not (optRun in gGlobalOptions) and (arguments <> '') then rawMessage(errArgsNeedRunOption); end @@ -58,42 +56,36 @@ end; procedure HandleCmdLine; var - inp: string; + command, filename: string; begin if paramCount() = 0 then writeCommandLineUsage() else begin // Process command line arguments: - inp := ProcessCmdLine(passCmd1); - if inp <> '' then begin + command := ''; + filename := ''; + ProcessCmdLine(passCmd1, command, filename); + if filename <> '' then begin if gCmd = cmdInterpret then DefineSymbol('interpreting'); - nimconf.LoadConfig(inp); // load the right config file + nimconf.LoadConfig(filename); // load the right config file // now process command line arguments again, because some options in the // command line can overwite the config file's settings extccomp.initVars(); - inp := ProcessCmdLine(passCmd2); + command := ''; + filename := ''; + ProcessCmdLine(passCmd2, command, filename); end; - MainCommand(paramStr(1), inp); + MainCommand(command, filename); if (gCmd <> cmdInterpret) and (msgs.gErrorCounter = 0) then rawMessage(hintSuccess); if optRun in gGlobalOptions then - execExternalProgram(changeFileExt(inp, '') +{&} arguments) + execExternalProgram(changeFileExt(filename, '') +{&} ' ' +{&} arguments) end end; -{@ignore} -var - Saved8087CW: Word; -{@emit} begin -{@ignore} - Saved8087CW := Default8087CW; - Set8087CW($133f); // Disable all fpu exceptions -{@emit} + cmdLineInfo := newLineInfo('command line', -1, -1); condsyms.InitDefines(); HandleCmdLine(); -{@ignore} - Set8087CW(Saved8087CW); -{@emit} halt(options.gExitcode); end. |