Read the input filename from the command line
This commit is contained in:
parent
b41d6fb907
commit
e04c659d19
71
source.elna
71
source.elna
@ -20,6 +20,9 @@ type
|
||||
end,
|
||||
FILE = record
|
||||
dummy: Int
|
||||
end,
|
||||
CommandLine = record
|
||||
input: pointer to Char
|
||||
end;
|
||||
|
||||
const
|
||||
@ -141,19 +144,6 @@ end;
|
||||
End of standard procedures.
|
||||
*)
|
||||
|
||||
proc test_primitive();
|
||||
begin
|
||||
write_s("\nTest primitives:\n");
|
||||
write_u(25u);
|
||||
write_c('\n');
|
||||
|
||||
write_i(8);
|
||||
write_c('\n');
|
||||
|
||||
write_b(true);
|
||||
write_c('\n')
|
||||
end;
|
||||
|
||||
proc read_source(filename: String): pointer to Char;
|
||||
var
|
||||
input_file: pointer to FILE,
|
||||
@ -677,32 +667,51 @@ begin
|
||||
return tokens
|
||||
end;
|
||||
|
||||
proc command_line(argc: Int, argv: pointer to pointer to Char);
|
||||
proc parse_command_line(argc: Int, argv: pointer to pointer to Char): pointer to CommandLine;
|
||||
var
|
||||
parameter: pointer to pointer to Char,
|
||||
i: Int;
|
||||
i: Int,
|
||||
result: pointer to CommandLine;
|
||||
begin
|
||||
write_s("Argument count: ");
|
||||
write_i(argc - 1);
|
||||
write_s("\nArguments:");
|
||||
if argc < 2 then
|
||||
write_s("Fatal error: no input files.\n");
|
||||
return nil
|
||||
end;
|
||||
if argc > 2 then
|
||||
write_s("Fatal error: Unknown command line options:");
|
||||
|
||||
i := 1;
|
||||
while i < argc do
|
||||
parameter := argv + i * cast(sizeof(pointer to Char) as Int);
|
||||
i := 2;
|
||||
while i < argc do
|
||||
parameter := argv + i * cast(sizeof(pointer to Char) as Int);
|
||||
|
||||
write_c(' ');
|
||||
write_s(parameter^);
|
||||
i := i + 1
|
||||
end;
|
||||
write_s(".\n");
|
||||
return nil
|
||||
end;
|
||||
|
||||
write_c(' ');
|
||||
write_s(parameter^);
|
||||
i := i + 1
|
||||
end
|
||||
parameter := argv + cast(sizeof(pointer to Char) as Int);
|
||||
result := cast(malloc(sizeof(CommandLine)) as pointer to CommandLine);
|
||||
result^.input := parameter^;
|
||||
|
||||
return result
|
||||
end;
|
||||
|
||||
proc compile();
|
||||
proc process(argc: Int, argv: pointer to pointer to Char): Int;
|
||||
var
|
||||
input: pointer to Char,
|
||||
tokens: pointer to Token,
|
||||
tokens_size: Word;
|
||||
tokens_size: Word,
|
||||
command_line: pointer to CommandLine;
|
||||
begin
|
||||
input := read_source("example.elna");
|
||||
command_line := parse_command_line(argc, argv);
|
||||
|
||||
if cast(command_line as Word) = 0u then
|
||||
return 2
|
||||
end;
|
||||
input := read_source(command_line^.input);
|
||||
tokens := tokenize(input, @tokens_size);
|
||||
|
||||
free(input);
|
||||
@ -711,9 +720,5 @@ begin
|
||||
end;
|
||||
|
||||
begin
|
||||
command_line(count, parameters);
|
||||
compile();
|
||||
test_primitive();
|
||||
|
||||
exit(0)
|
||||
exit(process(count, parameters))
|
||||
end.
|
||||
|
Loading…
x
Reference in New Issue
Block a user