mylsh

my own shell, based on brenns10's
Log | Files | Refs | Feed

commit d5dd8b2c74c84fb25700123a891dffbb1e9ea0a3
parent c7765ef991d05f59ee129afe9169a46795eaaa64
Author: Jenny Doe <tng@soykaf.me>
Date:   Tue, 19 Mar 2019 18:26:28 +0100

added: cd/chdir and small tweaks

Diffstat:
Mlsh.c | 27+++++++++++++++++++++++++--
1 file changed, 25 insertions(+), 2 deletions(-)

diff --git a/lsh.c b/lsh.c @@ -53,22 +53,43 @@ lsh_execute(wchar_t * *words) return (0); #define sc(s) wcscmp(words[0], s) == 0 + if (sc(L"echo")) { for (int i = 1; words[i] != NULL; i++) printf("%ls\n", words[i]); if (words[1] == NULL) /* to mimick classic 'echo' */ putchar('\n'); + } else if (sc(L"pwd")) { if (words[1] != NULL) - fprintf(stderr, "too much arguments!\n"); + fprintf(stderr, "pwd: too much arguments!\n"); else { char buf[MAXPATHLEN]; printf("%s\n", getwd(&buf[0])); } + + } else if (sc(L"cd") || sc(L"chdir")) { + + if (words[1] == NULL) + fprintf(stderr, "cd: missing argument!\n"); + else if (words[2] != NULL) { + fprintf(stderr, "cd: too much arguments!\n"); + + } else { + syslog(LOG_DEBUG, "chdir to %ls", words[1]); + + char *t = malloc(sizeof(char) * wcslen(words[1])); + + wcsrtombs(&t[0], &words[1], sizeof(t), NULL); + if (chdir(t) == -1) + perror("cd"); + + free(t); + } + } else { fprintf(stderr, "command not found!\n"); - return (0); } #undef sc @@ -194,6 +215,8 @@ main(void) openlog("message from lsh", LOG_PERROR | LOG_PID, LOG_USER); signal(SIGINFO, lsh_siginfo); + syslog(LOG_DEBUG, "just started!"); + lsh_loop(); return (0);