diff options
author | Benji Dial <benji6283@gmail.com> | 2020-09-13 22:06:40 -0400 |
---|---|---|
committer | Benji Dial <benji6283@gmail.com> | 2020-09-13 22:06:40 -0400 |
commit | 44d29a33df81ac07163d5146a9e43a0c4fb80af0 (patch) | |
tree | 94d4fb506a80d73cb53dc9ea66dfc952d7a9432a /src/user/highway/cmds.c | |
parent | 143156f63e2448733f1a35a74e629fe0ae9bb567 (diff) | |
download | portland-os-44d29a33df81ac07163d5146a9e43a0c4fb80af0.tar.gz |
new shell
Diffstat (limited to 'src/user/highway/cmds.c')
-rw-r--r-- | src/user/highway/cmds.c | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/src/user/highway/cmds.c b/src/user/highway/cmds.c new file mode 100644 index 0000000..d7a89d1 --- /dev/null +++ b/src/user/highway/cmds.c @@ -0,0 +1,46 @@ +#include <knob/file.h> +#include <knob/user.h> +#include "line.h" +#include "vars.h" + +void source(const char *path) { + struct file *f = open_file(path); + if (!f) + tell_user_sz("couldn't open file.\n"); + char buf[128]; + while (read_line_from_file(f, buf, 127)) + run_line(buf); + close_file(f); +} + +void set(const char *arg) { + const char *space = arg; + while (*space != ' ') + if (*space) + ++space; + else { + struct no_null_sn vname = { + .data = arg, + .length = space - arg + }; + del_var(vname); + return; + } + + struct no_null_sn vname = { + .data = arg, + .length = space - arg + }; + + const char *vstart = space + 1, + *vend = vstart; + while (*vend) + ++vend; + + struct no_null_sn vval = { + .data = vstart, + .length = vend - vstart + }; + + set_var(vname, vval); +}
\ No newline at end of file |