Move command line handling into a module
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
obtain one at https://mozilla.org/MPL/2.0/. *)
|
||||
program;
|
||||
|
||||
import cstdlib, cstdio, cctype, common, Lexer;
|
||||
import cstdio, cctype, common, command_line_interface, Lexer;
|
||||
|
||||
const
|
||||
SEEK_SET* := 0;
|
||||
@@ -113,11 +113,6 @@ type
|
||||
end;
|
||||
location: Location
|
||||
end;
|
||||
CommandLine = record
|
||||
input: ^Char;
|
||||
lex: Bool;
|
||||
parse: Bool
|
||||
end;
|
||||
Tokenizer* = record
|
||||
length: Word;
|
||||
data: ^Token
|
||||
@@ -702,55 +697,6 @@ begin
|
||||
return lexer
|
||||
end;
|
||||
|
||||
(*
|
||||
Command line handling.
|
||||
*)
|
||||
|
||||
proc parse_command_line*(argc: Int, argv: ^^Char) -> ^CommandLine;
|
||||
var
|
||||
parameter: ^^Char;
|
||||
i: Int;
|
||||
result: ^CommandLine;
|
||||
begin
|
||||
i := 1;
|
||||
result := cast(malloc(#size(CommandLine)): ^CommandLine);
|
||||
result^.lex := false;
|
||||
result^.parse := false;
|
||||
result^.input := nil;
|
||||
|
||||
while i < argc & result <> nil do
|
||||
parameter := argv + i;
|
||||
|
||||
if strcmp(parameter^, "--lex\0".ptr) = 0 then
|
||||
result^.lex := true
|
||||
elsif strcmp(parameter^, "--parse\0".ptr) = 0 then
|
||||
result^.parse := true
|
||||
elsif parameter^^ <> '-' then
|
||||
if result^.input <> nil then
|
||||
write_s("Fatal error: Only one source file can be given.\n");
|
||||
result := nil
|
||||
else
|
||||
result^.input := parameter^
|
||||
end
|
||||
else
|
||||
write_s("Fatal error: Unknown command line options: ");
|
||||
|
||||
write_z(parameter^);
|
||||
write_s(".\n");
|
||||
|
||||
result := nil
|
||||
end;
|
||||
|
||||
i := i + 1
|
||||
end;
|
||||
if result <> nil & result^.input = nil then
|
||||
write_s("Fatal error: no input files.\n");
|
||||
result := nil
|
||||
end;
|
||||
|
||||
return result
|
||||
end;
|
||||
|
||||
(*
|
||||
Parser.
|
||||
*)
|
||||
|
Reference in New Issue
Block a user