aboutsummaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/for.c45
-rwxr-xr-xcore/init5
-rw-r--r--core/mount.c2
-rw-r--r--core/unmount.c12
4 files changed, 58 insertions, 6 deletions
diff --git a/core/for.c b/core/for.c
new file mode 100644
index 0000000..d576bf8
--- /dev/null
+++ b/core/for.c
@@ -0,0 +1,45 @@
+#include "../lib/exec/exec.h"
+#include "../lib/sys/fork.h"
+#include "../lib/sys/wait4.h"
+#include "../lib/io/io.h"
+#include "../lib/sys/types.h"
+#include "../lib/cstr/cstr.h"
+
+char line[BUFSIZ];
+
+
+void replace_args(char **argv, char *rep)
+{
+ for (; *argv; ++argv) {
+ if (cstr_compare(*argv, "%") == 0) {
+ *argv = rep;
+ }
+ }
+}
+
+
+int main(int argc, char **argv)
+{
+ if (argc <= 1) {
+ wff(STDERR_FD, "for command [args...] % [args...]")
+ return -1;
+ }
+
+ i64 size;
+ int pid;
+
+ while ((size = get_next_line_from_fd(STDIN_FD, line)) >= 0) {
+
+ pid = fork();
+ if (pid == 0) {
+ replace_args(argv + 1, line);
+ exec((const char**)(argv + 1));
+ wff(STDERR_FD, "command not found: %s", argv[1]);
+ return -1;
+ }
+
+ wait4(pid, 0, 0);
+ }
+
+ return 0;
+}
diff --git a/core/init b/core/init
deleted file mode 100755
index 5802b36..0000000
--- a/core/init
+++ /dev/null
@@ -1,5 +0,0 @@
-#!/system/core/smash
-/system/core/clear
-/system/core/read /system/config/banner | /system/core/mdv
-/system/core/env -f /system/config/env /system/core/smash
-/system/core/powerctl poweroff
diff --git a/core/mount.c b/core/mount.c
index a7a4527..3bbf52b 100644
--- a/core/mount.c
+++ b/core/mount.c
@@ -12,7 +12,7 @@ int main(int argc, char **argv)
int err;
if ((err = mount(argv[2], argv[3], argv[1], 0, 0))) {
- wff(STDERR_FD, "error: %s", errstr[-err]);
+ wff(STDERR_FD, "error: %s\n", errstr[-err]);
return err;
}
diff --git a/core/unmount.c b/core/unmount.c
new file mode 100644
index 0000000..81103d9
--- /dev/null
+++ b/core/unmount.c
@@ -0,0 +1,12 @@
+#include "../lib/io/io.h"
+#include "../lib/sys/unmount.h"
+
+int main(int argc, char **argv)
+{
+ if (argc != 2) {
+ wff(STDERR_FD, "unmount <path>\n");
+ return -1;
+ }
+
+ return unmount(argv[1], 9);
+}