ref: 3f740ebd95986bfadbb770d070546fe9ce7f7deb
parent: 50328e9cfa91932f9a208fe93a16258a0f3c494e
author: mkf <mkf@cloud9p.org>
date: Tue Nov 28 08:14:22 EST 2023
add cwd into shell and programs
--- a/cmd/cal.c
+++ b/cmd/cal.c
@@ -73,7 +73,7 @@
}
void
-cal_main(int, char**){
+cal_main(int, char**, char*){
char *input;
int num1;
int num2;
--- a/cmd/check.c
+++ b/cmd/check.c
@@ -33,7 +33,7 @@
}
int
-check_main(int argc, char **argv)
+check_main(int argc, char **argv, char *cwd)
{
malloc_test();
printf("Press any key to quit test\n");
--- a/cmd/echo.c
+++ b/cmd/echo.c
@@ -4,7 +4,7 @@
#include <bitmap.h>
void
-echo_main(int argc, char **argv)
+echo_main(int argc, char **argv, char *cwd)
{
int i;
--- a/cmd/rc.c
+++ b/cmd/rc.c
@@ -7,6 +7,8 @@
#include <err.h>
#include "rc.h"
+static char *cwd;
+
int
run(char *cmd)
{
@@ -30,10 +32,10 @@
argv[argc] = strcntok(cmd, ' ', argc);
}
}
- for(int i = 0 ; i < sizeof(cmdtbl) ; i++)
+ for(int i = 0 ; i < sizeof(cmdtab) ; i++)
{
- if(!strcmp(arg0, cmdtbl[i].name))
- return cmdtbl[i].main(argc, argv);
+ if(!strcmp(arg0, cmdtab[i].name))
+ return cmdtab[i].main(argc, argv, cwd);
}
printf("No such command\n");
@@ -46,11 +48,11 @@
char c;
char *cmd;
+ cwd = "/";
int i = 0;
memset(cmd, 0, 25);
printf("> ");
-
while(1)
{
c = ps2_getc();
--- a/cmd/rc.h
+++ b/cmd/rc.h
@@ -1,13 +1,12 @@
#pragma once
void rc_main(void);
-int echo_main(int, char**);
-int clear_main(int, char**);
-int check_main(int, char**);
-int cal_main(int, char**);
+int echo_main(int, char**, char *cwd);
+int clear_main(int, char**, char *cwd);
+int check_main(int, char**, char *cwd);
+int cal_main(int, char**, char *cwd);
-
-static prog_t cmdtbl[] =
+static prog_t cmdtab[] =
{
{"echo", echo_main},
{"clear", clear_main},
--- a/include/u.h
+++ b/include/u.h
@@ -14,8 +14,6 @@
typedef unsigned long uint32;
typedef long int32;
-
-
typedef __builtin_va_list va_list;
typedef struct
{
@@ -26,6 +24,6 @@
typedef struct
{
char *name;
- int (*main)(int argc, char **argv);
+ int (*main)(int argc, char **argv, char *cwd);
}prog_t;