summaryrefslogtreecommitdiff
path: root/source/command_line_interface.elna
diff options
context:
space:
mode:
authorEugen Wissner <belka@caraus.de>2025-12-02 10:22:06 +0100
committerEugen Wissner <belka@caraus.de>2025-12-02 17:14:18 +0100
commit23b6f074c7f560d701e9a1fa5713a965af3a18a3 (patch)
tree87549a4eba3da8d8ed6e3fbb2e337e152a8bc96a /source/command_line_interface.elna
parent5f7d83974114c73327ce9fff3635927df050b5e4 (diff)
downloadelna-23b6f074c7f560d701e9a1fa5713a965af3a18a3.tar.gz
Merge GCC frontend into the branch
Diffstat (limited to 'source/command_line_interface.elna')
-rw-r--r--source/command_line_interface.elna93
1 files changed, 93 insertions, 0 deletions
diff --git a/source/command_line_interface.elna b/source/command_line_interface.elna
new file mode 100644
index 0000000..040fdeb
--- /dev/null
+++ b/source/command_line_interface.elna
@@ -0,0 +1,93 @@
+(* This Source Code Form is subject to the terms of the Mozilla Public License,
+ v. 2.0. If a copy of the MPL was not distributed with this file, You can
+ obtain one at https://mozilla.org/MPL/2.0/. *)
+
+(*
+ Command line handling.
+*)
+module;
+
+import cstdlib, cstring, common;
+
+type
+ CommandLine* = record
+ input: ^Char;
+ output: ^Char;
+ lex: Bool;
+ parse: Bool
+ end;
+
+proc parse_command_line*(argc: Int, argv: ^^Char) -> ^CommandLine;
+var
+ parameter: ^Char;
+ i: Int;
+ result: ^CommandLine;
+ parsed: Bool;
+begin
+ i := 1;
+ result := cast(malloc(#size(CommandLine)): ^CommandLine);
+ result^.lex := false;
+ result^.parse := false;
+ result^.input := nil;
+ result^.output := nil;
+
+ while i < argc & result <> nil do
+ parameter := (argv + i)^;
+ parsed := false;
+
+ if strcmp(parameter, "--lex\0".ptr) = 0 then
+ parsed := true;
+ result^.lex := true
+ end;
+ if strcmp(parameter, "--parse\0".ptr) = 0 then
+ parsed := true;
+ result^.parse := true
+ end;
+ if strcmp(parameter, "-o\0".ptr) = 0 then
+ i := i + 1;
+
+ if i = argc then
+ write_s("Fatal error: expecting a file name following -o.");
+ result := nil
+ end;
+ if i < argc then
+ parameter := (argv + i)^;
+ result^.output := parameter
+ end;
+ parsed := true
+ end;
+ if (parameter^ <> '-') & ~parsed then
+ parsed := true;
+
+ if result^.input <> nil then
+ 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
+ result^.input := parameter
+ end
+ end;
+ if ~parsed then
+ 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;
+
+end.