aboutsummaryrefslogtreecommitdiff
path: root/smash
diff options
context:
space:
mode:
authorNathan Reiner <nathan@nathanreiner.xyz>2022-12-15 21:17:41 +0100
committerNathan Reiner <nathan@nathanreiner.xyz>2022-12-15 21:17:41 +0100
commit02062f0cf84e1cb7fb294de54b0c00db6323c529 (patch)
treec71b34ef1ffdeb95fabc0ec10516d13b81984309 /smash
parent828dd435725ea315abd2ea9875325ee3b17041a9 (diff)
add 'cd' to smash
Diffstat (limited to 'smash')
-rw-r--r--smash/builtin.c8
-rwxr-xr-xsmash/smashbin49336 -> 49496 bytes
-rwxr-xr-xsmash/testbin20712 -> 0 bytes
-rw-r--r--smash/test.c3
-rw-r--r--smash/variables.c120
-rw-r--r--smash/variables.h8
6 files changed, 7 insertions, 132 deletions
diff --git a/smash/builtin.c b/smash/builtin.c
index ad9c839..63a4013 100644
--- a/smash/builtin.c
+++ b/smash/builtin.c
@@ -3,6 +3,7 @@
#include "../lib/sys/exit.h"
#include "../lib/cstr/cstr.h"
#include "../lib/sys/io.h"
+#include "../lib/sys/chdir.h"
u64 __find_builtin_function_by_name(const char *name);
@@ -30,7 +31,12 @@ int __builtin_fn_exit(int argc, const char **argv)
int __builtin_fn_cd(int argc, const char **argv)
{
- /* TODO: Implement */
+ if (argc != 2) {
+ write(STDOUT_FD, "path missing\n", 9);
+ return -1;
+ }
+
+ return chdir(argv[1]);
}
int __builtin_fn_help(int argc, const char **argv)
diff --git a/smash/smash b/smash/smash
index 5d0b5e3..c444927 100755
--- a/smash/smash
+++ b/smash/smash
Binary files differ
diff --git a/smash/test b/smash/test
deleted file mode 100755
index d282011..0000000
--- a/smash/test
+++ /dev/null
Binary files differ
diff --git a/smash/test.c b/smash/test.c
deleted file mode 100644
index cb3f748..0000000
--- a/smash/test.c
+++ /dev/null
@@ -1,3 +0,0 @@
-int main() {
- return 0;
-}
diff --git a/smash/variables.c b/smash/variables.c
deleted file mode 100644
index b3b6689..0000000
--- a/smash/variables.c
+++ /dev/null
@@ -1,120 +0,0 @@
-#include "variables.h"
-
-#include "../lib/avl_tree/avl_tree.h"
-#include "../lib/cstr/cstr.h"
-#include "../lib/malloc/malloc.h"
-
-typedef struct {
- const char *name;
- const char *value;
-} variable_pair_t;
-
-i8 __variable_pair_compare(void *a, void *b);
-
-avl_tree_t *variable_tree;
-
-
-/** DOC
- * @type function
- * @name __variable_pair_compare
- *
- * @param void *a
- * @param void *b
- * @return u8
- *
- * @description
- * Compair function for `variable_pair_t`.
- */
-i8 __variable_pair_compare(void *a, void *b)
-{
- variable_pair_t *va = (variable_pair_t*)a;
- variable_pair_t *vb = (variable_pair_t*)b;
-
- return cstr_compare(va->name, vb->name);
-}
-
-
-/** DOC
- * @type function
- * @name init_variables
- *
- * @description
- * Initializes the variable binary tree.
- */
-void init_variables()
-{
- variable_tree = new_avl_tree(__variable_pair_compare, 1);
-}
-
-
-/** DOC
- * @type function
- * @name set_variable
- *
- * @param const char *name
- * @param const char *value
- *
- * @description
- * Sets a variable.
- */
-void set_variable(const char *name, const char *value)
-{
- variable_pair_t *pair = malloc(sizeof(variable_pair_t));
- pair->name = name;
- pair->value = value;
- avl_tree_insert(variable_tree, pair);
-}
-
-
-/** DOC
- * @type function
- * @name get_variable
- *
- * @param const char *name
- *
- * @description
- * Gets a variable.
- */
-const char *get_variable(const char *name)
-{
- variable_pair_t query = { .name = name, .value = 0 };
- variable_pair_t *res = avl_tree_search(variable_tree, &query);
-
- if (res)
- return res->value;
- return 0;
-}
-
-
-#ifdef VARIABLES_UNIT_TEST
-
-#include "../lib/sys/write.h"
-
-void test_get(const char *name)
-{
- const char *value = get_variable(name);
- if (value)
- write(0, value, cstr_length(value));
- else
- write(0, "value = nullptr", 15);
-
- write(0, "\n", 1);
-
-}
-
-int main()
-{
- init_variables();
- set_variable("name", "john");
- set_variable("user", "n8");
-
- test_get("name");
- test_get("user");
-
- set_variable("user", "freak");
-
- test_get("user");
-
-}
-
-#endif
diff --git a/smash/variables.h b/smash/variables.h
deleted file mode 100644
index af71ee4..0000000
--- a/smash/variables.h
+++ /dev/null
@@ -1,8 +0,0 @@
-#ifndef VARIABLES_H
-#define VARIABLES_H
-
-void set_variable(const char *name, const char *value);
-const char *get_variable(const char *name);
-void init_variables();
-
-#endif