Move write procedures to the common module

This commit is contained in:
2025-08-14 14:06:57 +03:00
parent 5146ea61b9
commit cec020ea92
6 changed files with 101 additions and 118 deletions

View File

@@ -3,11 +3,10 @@
obtain one at https://mozilla.org/MPL/2.0/. *)
module;
from FIO import WriteString, WriteChar, WriteLine, StdErr;
import cstdlib, common;
import cstdlib, cstring, common;
type
CommandLine = record
CommandLine* = record
input: ^Char;
output: ^Char;
lex: Bool;
@@ -17,16 +16,16 @@ type
proc parse_command_line*(argc: Int, argv: ^^Char) -> ^CommandLine;
var
parameter: ^Char;
i: Word;
i: Int;
result: ^CommandLine;
parsed: Bool;
begin
i := 1u;
NEW(result);
i := 1;
result := cast(malloc(#size(CommandLine)): ^CommandLine);
result^.lex := false;
result^.parse := false;
memset(@result^.input, 0, 256);
result^.output[1] := CHAR(0);
result^.input := nil;
result^.output := nil;
while i < argc & result <> nil do
parameter := (argv + i)^;
@@ -41,10 +40,10 @@ begin
result^.parse := true
end;
if strcmp(parameter, "-o\0".ptr) = 0 then
i := i + 1u;
i := i + 1;
if i = argc then
WriteString(StdErr, "Fatal error: expecting a file name following -o.");
write_s("Fatal error: expecting a file name following -o.");
result := nil
end;
if i < argc then
@@ -57,12 +56,11 @@ begin
parsed := true;
if result^.input <> nil then
WriteString(StdErr, "Fatal error: only one source file can be compiled at once. First given \"");
WriteString(StdErr, result^.input);
WriteString(StdErr, "\", then \"");
WriteString(StdErr, parameter);
WriteString(StdErr, "\".");
WriteLine(StdErr);
write_s("Fatal error: only one source file can be compiled at once. First given \"");
write_z(result^.input);
write_s("\", then \"");
write_z(parameter);
write_s("\".\n");
result := nil
end;
if result <> nil then
@@ -70,20 +68,18 @@ begin
end
end;
if ~parsed then
WriteString(StdErr, "Fatal error: unknown command line options: ");
write_s("Fatal error: unknown command line options: ");
WriteString(StdErr, parameter);
WriteChar(StdErr, '.');
WriteLine(StdErr);
write_z(parameter);
write_s(".\n");
result := nil
end;
i := i + 1u
i := i + 1
end;
if result <> nil & result^.input = nil then
WriteString(StdErr, "Fatal error: no input files.");
WriteLine(StdErr);
write_s("Fatal error: no input files.\n");
result := nil
end;