From 73bb0e48640b842824a0b45fe4854df8ff7faf7b Mon Sep 17 00:00:00 2001 From: Benji Dial Date: Sun, 6 Sep 2020 13:44:20 -0400 Subject: bugfixes, init program, hello world --- src/user/knob/file.c | 16 +++++++--------- src/user/knob/task.c | 13 +++++++++++++ 2 files changed, 20 insertions(+), 9 deletions(-) create mode 100644 src/user/knob/task.c (limited to 'src/user/knob') diff --git a/src/user/knob/file.c b/src/user/knob/file.c index 8ab7acd..0032cf2 100644 --- a/src/user/knob/file.c +++ b/src/user/knob/file.c @@ -9,9 +9,9 @@ struct file { uint32_t length; }; -static const char *try_remove_prefix(const char *path, uint8_t *dn_out) { +const char *remove_prefix(const char *path, uint8_t *dn_out) { if ((path[0] != 's') || (path[1] != 'd')) - return 0; + goto no_prefix; const char *num_part = path + 2; for (uint32_t i = 0; num_part[i]; ++i) @@ -19,22 +19,20 @@ static const char *try_remove_prefix(const char *path, uint8_t *dn_out) { uint32_t dn_large; if (!try_sntoi(num_part, i, &dn_large) || dn_large > 255) - return 0; + goto no_prefix; *dn_out = (uint8_t)dn_large; return num_part + i + 1; } - return 0; +no_prefix: + *dn_out = current_drive; + return path; } struct file *open_file(const char *path) { uint8_t dn; - const char *path_part = try_remove_prefix(path, &dn); - if (path_part) - path = path_part; - else - dn = current_drive; + path = remove_prefix(path, &dn); _file_handle_t h = _open_file(dn, path); if (!h) diff --git a/src/user/knob/task.c b/src/user/knob/task.c new file mode 100644 index 0000000..aa18eab --- /dev/null +++ b/src/user/knob/task.c @@ -0,0 +1,13 @@ +#include +#include +#include + +bool try_run_command(const char *path) { + uint8_t dn; + path = remove_prefix(path, &dn); + return _start_task(dn, path); +} + +void yield_task() { + _yield_task(); +} \ No newline at end of file -- cgit v1.2.3