Read the input filename from the command line

This commit is contained in:
Eugen Wissner 2025-02-02 08:22:40 +01:00
parent b41d6fb907
commit e04c659d19
Signed by: belka
GPG Key ID: A27FDC1E8EE902C0

View File

@ -20,6 +20,9 @@ type
end, end,
FILE = record FILE = record
dummy: Int dummy: Int
end,
CommandLine = record
input: pointer to Char
end; end;
const const
@ -141,19 +144,6 @@ end;
End of standard procedures. 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; proc read_source(filename: String): pointer to Char;
var var
input_file: pointer to FILE, input_file: pointer to FILE,
@ -677,32 +667,51 @@ begin
return tokens return tokens
end; 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 var
parameter: pointer to pointer to Char, parameter: pointer to pointer to Char,
i: Int; i: Int,
result: pointer to CommandLine;
begin begin
write_s("Argument count: "); if argc < 2 then
write_i(argc - 1); write_s("Fatal error: no input files.\n");
write_s("\nArguments:"); return nil
end;
if argc > 2 then
write_s("Fatal error: Unknown command line options:");
i := 1; i := 2;
while i < argc do while i < argc do
parameter := argv + i * cast(sizeof(pointer to Char) as Int); 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(' '); parameter := argv + cast(sizeof(pointer to Char) as Int);
write_s(parameter^); result := cast(malloc(sizeof(CommandLine)) as pointer to CommandLine);
i := i + 1 result^.input := parameter^;
end
return result
end; end;
proc compile(); proc process(argc: Int, argv: pointer to pointer to Char): Int;
var var
input: pointer to Char, input: pointer to Char,
tokens: pointer to Token, tokens: pointer to Token,
tokens_size: Word; tokens_size: Word,
command_line: pointer to CommandLine;
begin 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); tokens := tokenize(input, @tokens_size);
free(input); free(input);
@ -711,9 +720,5 @@ begin
end; end;
begin begin
command_line(count, parameters); exit(process(count, parameters))
compile();
test_primitive();
exit(0)
end. end.