diff --git a/.ecode/project_build.json b/.ecode/project_build.json deleted file mode 100644 index 07ad835..0000000 --- a/.ecode/project_build.json +++ /dev/null @@ -1,37 +0,0 @@ -{ - "Debug": { - "build": [ - { - "args": "-j8", - "command": "make", - "working_dir": "" - } - ], - "build_types": [], - "clean": [ - { - "args": "clean", - "command": "c3c", - "working_dir": "" - } - ], - "config": { - "clear_sys_env": false - }, - "os": [], - "output_parser": { - "config": { - "preset": "generic", - "relative_file_paths": true - } - }, - "run": [ - { - "args": "", - "command": "build/ugui", - "name": "Custom Executable", - "working_dir": "" - } - ] - } -} \ No newline at end of file diff --git a/lib/schrift.c3l b/lib/schrift.c3l index 64d168f..fedf67e 160000 --- a/lib/schrift.c3l +++ b/lib/schrift.c3l @@ -1 +1 @@ -Subproject commit 64d168f53b0fe70bda77e2ed7bec35f3f0f1af78 +Subproject commit fedf67ecfe4fcfa6ea617a03628d51c1657f8da2 diff --git a/lib/sdl3.c3l b/lib/sdl3.c3l deleted file mode 160000 index e7356df..0000000 --- a/lib/sdl3.c3l +++ /dev/null @@ -1 +0,0 @@ -Subproject commit e7356df5d1d0c22a6bba822bda6994062b0b75d7 diff --git a/lib/sdl3.c3l b/lib/sdl3.c3l new file mode 100644 index 0000000..475688a Binary files /dev/null and b/lib/sdl3.c3l differ diff --git a/lib/ugui.c3l b/lib/ugui.c3l index 60bec17..1584b04 160000 --- a/lib/ugui.c3l +++ b/lib/ugui.c3l @@ -1 +1 @@ -Subproject commit 60bec17d36aa2fd1bddb3ffd4413bbfe867b6716 +Subproject commit 1584b04fd31490967fd53c95af57b516e5e99cdc diff --git a/lib/ugui_sdl.c3l b/lib/ugui_sdl.c3l index 050624f..6c2f3fc 160000 --- a/lib/ugui_sdl.c3l +++ b/lib/ugui_sdl.c3l @@ -1 +1 @@ -Subproject commit 050624fd67c2d80190114c7774ccfa64b0f449b9 +Subproject commit 6c2f3fc2834a439bab4adaf1194ee0789edacb82 diff --git a/project.json b/project.json index ec744aa..79142e7 100644 --- a/project.json +++ b/project.json @@ -1,12 +1,12 @@ { "langrev": "1", - "warnings": ["no-unused"], - "dependency-search-paths": ["lib"], - "dependencies": ["ugui", "ugui_sdl3"], - "features": ["DEBUG_POINTER"], - "authors": ["Alessandro Mauri "], + "warnings": [ "no-unused" ], + "dependency-search-paths": [ "lib" ], + "dependencies": [ "ugui", "ugui_sdl3", "sdl3", "schrift" ], + "features": [ "DEBUG_POINTER" ], + "authors": [ "Alessandro Mauri " ], "version": "0.1.0", - "sources": ["src/**"], + "sources": [ "src/**" ], "output": "build", "target": "linux-x64", "targets": { diff --git a/src/conf.c3 b/src/conf.c3 index 108a163..345c774 100644 --- a/src/conf.c3 +++ b/src/conf.c3 @@ -17,40 +17,55 @@ alias StrList = list::List{String}; alias ConfFList = list::List{ConfigFile}; -fn Path? String.to_expanded_path(&str, Allocator allocator) +fn Path? String.to_expanded_path(&str, Allocator allocator, String[] extra_env = {}) { @pool() { StrList l; l.tinit(); Path str_path = str.to_tpath()!; - + l.push(str_path.basename()); Path? p = str_path.parent(); while (true) { Path? x; if (try p) { String n = p.basename(); - + l.push("/"); + // env variable if (n.starts_with("$")) { - l.push(env::tget_var(n[1..]))!; + String? e = env::tget_var(n[1..]); + if (catch e) { + // var is not in regular environment, check extra_env + bool in_extra = false; + foreach_r (j: extra_env) { + if (j.starts_with(n[1..])) { + l.push(j.strip_suffix(n[1..])[1..]); + in_extra = true; + break; + } + } + if (!in_extra) { + return NOT_FOUND~; + } + } else { + l.push(e); + } } else { l.push(n); } - + x = p.parent(); } else { break; } p = x; } + l.reverse(); + String path; + path = string::tjoin(l.array_view(), path); - Path path = path::temp("")!; - foreach_r (idx, s: l) { - path = path.tappend(s)!; - } - - return path::new(allocator, path.str_view(), path.env); + return path::new(allocator, path); }; } @@ -69,7 +84,7 @@ fn StrList? get_qemu_cmdline(Allocator allocator, Object* conf) cmd.push(conf.get_string("qemu"))!!; // then the drive cmd.push("-drive"); - cmd.push(string::format(allocator, "file=%s", disk_path.str_view())); + cmd.push(string::format(allocator, "file=%s", (String)disk_path)); // memory cmd.push("-m"); cmd.push(conf.get_string("memory"))!!; @@ -78,7 +93,7 @@ fn StrList? get_qemu_cmdline(Allocator allocator, Object* conf) cmd.push(conf.get_string("processors") ?? "1"); // then all the parameters Object* parameters = conf.get("parameters")!!; - for (usz i = 0; i < parameters.get_len(); i++) { + for (sz i = 0; i < parameters.get_len(); i++) { Object* p = parameters.get_at(i); if (p.is_string()) { cmd.push(string::format(allocator, "-%s", p.s)); @@ -100,7 +115,7 @@ fn ConfFList? get_config_list(Allocator allocator) // find the right config directory Path conf_dir = env::get_config_dir(tmem).append(tmem, "simple-qemu-manager")!; - if (!file::exists(conf_dir.str_view()) || !file::is_dir(conf_dir.str_view())) { + if (!file::exists((String)conf_dir) || !file::is_dir((String)conf_dir)) { path::mkdir(conf_dir, recursive:true)!; return l; } @@ -109,14 +124,13 @@ fn ConfFList? get_config_list(Allocator allocator) PathList pl = path::ls(tmem, conf_dir)!; foreach (fname : pl) @pool() { if ((fname.extension() ?? "") != "json") continue; - Path fpath = conf_dir.append(tmem, fname.str_view())!; + Path fpath = conf_dir.append(tmem, (String)fname)!; - File cf = file::open_path(fpath, "r")!; - defer (void)cf.close(); + char[] cf = file::load_temp(fpath)!; - Object* c = json::parse(tmem, &cf)!; + Object* c = json::parse(tmem, (String)cf)!; ConfigFile e = { - .path = path::new(allocator, fpath.str_view(), fpath.env)!, + .path = path::new(allocator, (String)fpath)!, .name = string::format(allocator, "%s", c.get_string("name"))!, }; l.push(e); diff --git a/src/main.c3 b/src/main.c3 index 927af4c..b12ff0e 100644 --- a/src/main.c3 +++ b/src/main.c3 @@ -8,7 +8,7 @@ import std::time; import conf; import vm; import ugui; -import ugui::sdl::ren; +import ugui::sdl3::ren; const char[*] VS_PATH = "resources/shaders/compiled/ugui.vert.spv"; @@ -36,12 +36,12 @@ fn int main(String[] args) ren.init("Qemu Manager", 800, 600, VSYNC); defer ren.free(); ui.input_window_size(800, 600)!!; - + ui.load_font(&arena, "font1", "resources/hack-nerd.ttf", 16)!!; ren.font_atlas_id = ui.get_font_id("font1"); Atlas* font_atlas = ui.get_font_atlas("font1")!!; ren.new_texture("font1", JUST_ALPHA, font_atlas.buffer, font_atlas.width, font_atlas.height); - + ui.sprite_atlas_create("icons", AtlasType.ATLAS_R8G8B8A8, 512, 512)!!; ui.import_sprite_file_qoi("tick", "resources/tick_sdf.qoi", SpriteType.SPRITE_MSDF)!!; ui.import_sprite_file_qoi("vm", "resources/vm.qoi", SpriteType.SPRITE_NORMAL)!!; @@ -77,7 +77,7 @@ fn int main(String[] args) if (ui.check_key_combo(ugui::KMOD_CTRL, "q")) quit = true; - static usz which_vm = 0; + static sz which_vm = 0; ui.@div(ugui::@grow(), ugui::@grow()) { ui.@div(ugui::@fit((short)(ui.width*0.4)), ugui::@grow(), COLUMN, scroll_x: false, scroll_y: true, resize: {.right = true}) { foreach (idx, &vm : vm_list) { @@ -100,7 +100,7 @@ fn int main(String[] args) // TODO: implement a "selectable div" to display the information of the right vm VirtualMachineDesc* vm = &vm_list[which_vm]; ui.text(string::tformat("Name: %s", vm.name))!!; - ui.text(string::tformat("Disk: %s (%s)", vm.disk_path.str_view(), bytes_to_human_readable(tmem, file::get_size(vm.disk_path.str_view()))))!!; + ui.text(string::tformat("Disk: %s (%s)", (String)vm.disk_path, bytes_to_human_readable(tmem, file::get_size((String)vm.disk_path))))!!; ui.text(string::tformat("Runner: %s", vm.config.get_string("qemu")))!!; ui.text(string::tformat("Memory: %s", vm.config.get_string("memory")))!!; ui.text(string::tformat("Processors: %s", vm.config.get_string("processors")))!!; @@ -109,7 +109,7 @@ fn int main(String[] args) ui.frame_end()!!; /* End UI Handling */ - + /* Start UI Drawing */ ren.begin_render(true); ren.render_ugui(&ui.cmd_queue); @@ -126,8 +126,8 @@ fn int main(String[] args) } -fn String bytes_to_human_readable(Allocator allocator, usz bytes, int dp = 1) { - static usz thresh = 1024; +fn String bytes_to_human_readable(Allocator allocator, sz bytes, int dp = 1) { + static sz thresh = 1024; static String[] units = {"B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB"}; double b = bytes; @@ -138,4 +138,3 @@ fn String bytes_to_human_readable(Allocator allocator, usz bytes, int dp = 1) { return string::format(allocator, "%.*f %s", dp, b, units[u]); } - diff --git a/src/vm.c3 b/src/vm.c3 index 71f6feb..1ec9cde 100644 --- a/src/vm.c3 +++ b/src/vm.c3 @@ -9,12 +9,13 @@ import conf; struct VirtualMachineDesc { + Allocator allocator; Path config_path; Object* config; String name; StrList cmdline; Path disk_path; - SubProcess process; + Process process; } @@ -24,12 +25,12 @@ alias VMList = list::List{VirtualMachineDesc}; fn VirtualMachineDesc? new_from_path(Allocator allocator, Path path) { VirtualMachineDesc desc; - desc.config_path = path::new(allocator, path.str_view(), path.env)!; + desc.allocator = allocator; + desc.config_path = path::new(allocator, (String)path)!; - File file = file::open_path(path, "r")!; - defer (void)file.close(); + char[] file = file::load_temp(path)!; - desc.config = json::parse(allocator, &file)!; + desc.config = json::parse(allocator, (String)file)!; desc.name = desc.config.get_string("name")!; desc.disk_path = desc.config.get_string("disk").to_expanded_path(allocator)!; @@ -42,11 +43,11 @@ fn VirtualMachineDesc? new_from_path(Allocator allocator, Path path) <* @param[&in] desc *> fn bool VirtualMachineDesc.is_initialized(&desc) { - return desc.config_path.str_view() != "" - && desc.config != null - && desc.name != "" - && desc.disk_path.str_view() != "" - && desc.cmdline.len() != 0; + return (String)desc.config_path != "" + && desc.config != null + && desc.name != "" + && (String)desc.disk_path != "" + && desc.cmdline.len() != 0; } @@ -55,10 +56,10 @@ fn void VirtualMachineDesc.free(&desc) { if (!desc.is_initialized()) return; (void)desc.stop(); - desc.config_path.free(); + desc.config_path.free(desc.allocator); desc.config.free(); // desc.name.free() name is just a string view into desc.config - desc.disk_path.free(); + desc.disk_path.free(desc.allocator); desc.cmdline.free(); *desc = {}; @@ -71,7 +72,7 @@ fn void? VirtualMachineDesc.start(&desc) if (!desc.is_initialized()) return; if ((desc.process.is_running() ?? false)) return; - desc.process = process::create(desc.cmdline.array_view(), {.inherit_stdio=true, .inherit_environment=true})!; + desc.process = process::spawn(desc.cmdline.array_view(), INHERIT_STDIO|INHERIT_ENV)!; }