beterraba

commit 6a51cd2810157bc9e2a36be81186346426edfbf4

Author: Pedro Lucas Porcellis <porcellis@eletrotupi.com>

beterraba/parse: list and initially parse service definitions

 beterraba/beterraba.ha | 12 ++++++++++++
 beterraba/parse.ha | 40 ++++++++++++++++++++++++++++++++++++++++


diff --git a/beterraba/beterraba.ha b/beterraba/beterraba.ha
new file mode 100644
index 0000000000000000000000000000000000000000..849191a1df6013c38783c73fbf44d47d73ad7d19
--- /dev/null
+++ b/beterraba/beterraba.ha
@@ -0,0 +1,12 @@
+// TODO: Include things like enabled/disabled?
+export type status = enum {
+	STOPPED,
+	STARTED,
+	CRASHED
+};
+
+export type service = struct {
+	name: str,
+	description: str,
+	status: status
+};




diff --git a/beterraba/parse.ha b/beterraba/parse.ha
new file mode 100644
index 0000000000000000000000000000000000000000..30cb405d698e6d5110a3e2f63f54fcd9ecd993fc
--- /dev/null
+++ b/beterraba/parse.ha
@@ -0,0 +1,40 @@
+use bufio;
+use io;
+use fmt;
+use format::ini;
+use strings;
+
+export type servdef = struct { name: str };
+export type invalid = !void;
+
+export fn parse(in: io::handle) void = {
+	const scanner = ini::scan(in);
+
+	// TODO: Rig up with the type definition
+	let definition = servdef { ... };
+	defer ini::finish(&scanner);
+
+	for (true) {
+		const ent = match (ini::next(&scanner)!) {
+		case let ent: ini::entry =>
+			yield ent;
+		case io::EOF =>
+			break;
+		};
+
+		switch (ent.0) {
+		case "Unit" =>
+			switch (ent.1) {
+			case "Name" =>
+				definition.name = strings::dup(ent.2);
+			case =>
+				continue;
+			};
+		case =>
+			continue;
+		};
+	};
+
+	// TODO: Fetch a use case
+	fmt::printfln("Unit name: {}", definition.name)!;
+};