From 9efa7363a1a867cbb436e91fdb91fcd8fa5336a8 Mon Sep 17 00:00:00 2001 From: czjstmax Date: Wed, 18 Mar 2026 22:49:59 +0100 Subject: ver 1 - done! Signed-off-by: czjstmax --- nosh.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/nosh.c b/nosh.c index 14065c7..ebcd57d 100644 --- a/nosh.c +++ b/nosh.c @@ -1,9 +1,7 @@ -/* - * nosh - noshell - * a 2-hour C shell for POSIX mates - * - * czjstmax +/* nosh - noshell + * precisely 100 lines of pure POSIX and standard C code for thy eyes! * + * von czjstmax, */ #include @@ -15,11 +13,8 @@ #include #include -// void handlecc(int sig); -void freeStuff(); -// char *line = NULL; size_t len = 0; wordexp_t p; @@ -44,7 +39,8 @@ int main(void) if (strlen(line) == 0) continue; //otherwise.. SIGSEGV! if (strcmp(p.we_wordv[0], ":q") == 0 || strcmp(p.we_wordv[0], "exit") == 0) { - freeStuff(); + wordfree(&p); + free(line); return 0; } else if (strcmp(p.we_wordv[0], "echo") == 0) { @@ -64,6 +60,17 @@ int main(void) printf("\033[2J\033[H\033[3J"); fflush(stdout); } + else if (strcmp(p.we_wordv[0], "help") == 0) { + printf( + "nosh - noshell\na minimal POSIX C shell for *NIX dudes.\n\nbuilt-ins:\n" + "echo -> outputs a string of text, doesn't need \" enclosure.\n" + " supports '-c' for output without '\\n'" + "clear -> clears screen (and scrollback)\n" + "cd -> change working directory\n" + "help -> prints this screen\n" + "\ngithub repo: github.com/jstmaxlol/nosh\n" + ); + } else { pid_t pid = fork(); char **argv = p.we_wordv; // pray with me now @@ -88,13 +95,6 @@ int main(void) void handlecc(int sig) { printf("\nnsh! %d caught.\nfreeing stuff before quitting.\n", sig); - freeStuff(); exit(0); } -void freeStuff() -{ - wordfree(&p); - free(line); -} - -- cgit v1.3.1