coreutils

custom mini coreutils
git clone git://git.evenfri.duckdns.org/coreutils.git
Log | Files | Refs | README

commit b8a3686be2bf0ffa7c79315af97fd7a30d6be74b
parent 8ba2df1a8878f95ad5f92ad0f43b407a66456b93
Author: evenfri <evenfri256@gmail.com>
Date:   Sat,  8 Aug 2026 04:26:36 +0800

update cc

Diffstat:
Mmkfile | 9+++++----
Msh/mkfile | 5++---
Ash/sh.c | 70++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 77 insertions(+), 7 deletions(-)

diff --git a/mkfile b/mkfile @@ -1,6 +1,7 @@ -<$LPLAN9/src/mkhdr +<$PLAN9/src/mkhdr + +not_use_libc = 1 -cc = fcc ld = ld cflags = -I./libc lib = ./libc/libc.a @@ -14,5 +15,5 @@ targ = init \ dirs = sh \ -<$LPLAN9/src/mkmany -<$LPLAN9/src/mkdirs +<$PLAN9/src/mkmany +<$PLAN9/src/mkdirs diff --git a/sh/mkfile b/sh/mkfile @@ -1,6 +1,5 @@ -<$LPLAN9/src/mkhdr +<$PLAN9/src/mkhdr -cc = fcc ld = ld cflags = -I../libc lib = ../libc/libc.a @@ -9,4 +8,4 @@ ofiles = main.$o \ targ = sh -<$LPLAN9/src/mkone +<$PLAN9/src/mkone diff --git a/sh/sh.c b/sh/sh.c @@ -0,0 +1,70 @@ +#include <libc.h> + +#define msg_clear "\033[2J\033[H" + +#define max_line 256 +#define max_args 16 +#define max_cwd 256 + +static char prompt[] = "; "; + +void execcd(const char *path) { + chdir(path); +} + +int main(void) { + char line[max_line]; + char *argv[max_args]; + + while (1) { + write(stdout, prompt, 2); + + ssize_t n = read(stdin, line, max_line - 1); + if (n <= 0) continue; + + line[n] = '\0'; + if (line[n - 1] == '\n') line[n - 1] = '\0'; + + if (strlen(line) == 0) continue; + + if (strcmp(line, "clear") == 0) { + write(stdout, msg_clear, strlen(msg_clear)); + continue; + } + + if (strcmp(line, "exit") == 0) { + break; + } + + int argc = 0; + char *token = strtok(line, " "); + while (token != NULL && argc < max_args - 1) { + argv[argc++] = token; + token = strtok(NULL, " "); + } + argv[argc] = NULL; + + if (argc == 0) continue; + + if (strcmp(line, "cd") == 0) { + execcd(argv[1]); + continue; + } + + int pid = fork(); + if (pid == 0) { + /* child */ + execvp(argv[0], argv); + + write(stderr, "sh: command not found: ", 23); + write(stderr, argv[0], strlen(argv[0])); + write(stderr, "\n", 1); + exit(127); + } else if (pid > 0) { + /* parent */ + int status; + waitpid(pid, &status, 0); + } + } + return 0; +}