diff options
Diffstat (limited to 'main.c')
| -rw-r--r-- | main.c | 55 |
1 files changed, 45 insertions, 10 deletions
@@ -459,24 +459,44 @@ static Str normalize_path(Str s) { return path; } -static void build_file(Str path) { +static void build_file(Str path, int debugp) { (void)path; - shell_run("make"); + shell_run(debugp ? "make DEBUG=1" : "make"); } #define WED_DEV_DIR "/mnt/user/wrmr/src/wed/" -#define WED_DEV_EXE (WED_DEV_DIR "wed") +#define WED_DEV_EXE WED_DEV_DIR "wed" -static void run_file(Str path) { +int is_wed_path(Str path) { + return str_starts(normalize_path(path), S(WED_DEV_DIR)); +} + +static void run_file(Str path, int debugp) { path = normalize_path(path); - if (str_starts(path, S(WED_DEV_DIR))) { + if (is_wed_path(path)) { vui_fini(); - system("make"); + system(debugp ? "make DEBUG=1" : "make"); char ofs[32]; sprintf(ofs, "-b%d", txt_ofs(cur)); execl(WED_DEV_EXE, WED_DEV_EXE, ofs, str_to_cstr(path, &scratch), 0); } else { - shell_run("make run"); + shell_run(debugp ? "make DEBUG=1 run" : "make run"); + } +} + +static void debug_file(Str path) { + if (is_wed_path(path)) { + vui_disable(); + system("make DEBUG=1"); + char ofs[32]; + sprintf(ofs, "-b%d", txt_ofs(cur)); + Str cmd = S("exec gdb -ex run --args " WED_DEV_EXE " "); + str_cat(&cmd, str_from_cstr(ofs), &scratch); + execl("/bin/sh", "sh", "-c", str_to_cstr(cmd, &scratch), 0); + } else { + Str cmd = S("gdb -ex run --args "); + str_cat(&cmd, path, &scratch); + shell_run(str_to_cstr(cmd, &scratch)); } } @@ -495,7 +515,7 @@ int main(int argc, const char **argv) { argc--; } - const char *path = "test.txt"; + const char *path = "main.c"; if (argc > 1) path = argv[1]; vui_init(); @@ -597,10 +617,25 @@ int main(int argc, const char **argv) { case ' ': switch ((u32)vui_key()) { case 'm': - build_file(str_from_cstr(path)); + build_file(str_from_cstr(path), 1); + break; + case 'M': + build_file(str_from_cstr(path), 0); break; case 'r': - run_file(str_from_cstr(path)); + run_file(str_from_cstr(path), 1); + break; + case 'R': + run_file(str_from_cstr(path), 0); + break; + case 'D': + debug_file(str_from_cstr(path)); + break; + case 'e': + vui_disable(); + system("make clean"); + vui_enable(); + vui_redraw(); break; default: /* TODO: flash */ |
