wm: teppich

Download patch

ref: 0406ab471ab3c21903bd6c331cb75426b9e7fb1c
parent: 3efc26626b4a096aa3ff8770037b3b4726bf4c3d
author: mkf <mkf@cloud9p.org>
date: Sun Dec 3 02:22:13 EST 2023

rc: clean up rc and remove cwd, also add new programs

--- a/cmd/rc.c
+++ b/cmd/rc.c
@@ -1,10 +1,9 @@
 #include <u.h>
 #include <libc.h>
-
 #include <ps2.h>
-
 #include <mem.h>
 #include <err.h>
+#include <user.h>
 #include "rc.h"
 
 static char *cwd;
@@ -18,13 +17,13 @@
 	for(int i = 0 ; i < sizeof(cmdtab) ; i++)
 	{
 		if(!strcmp(argv0, cmdtab[i].name))
-			status = cmdtab[i].main(argc, argv, cwd);
+			status = cmdtab[i].main(argc, argv);
 	}
-	
 	/* free the memory, whetever if we found a match or not */
 	for(int j = 0 ; j < argc+1 ; j++)
 		free(argv[j]);
 	free(argv0);
+
 	return status;
 }
 
@@ -59,14 +58,14 @@
 void
 rc_main(void)
 {
-	char c;
-	char *cmd;
+	int i;
+	char c, *cmd;
 
 	cwd = "/";
-	int i = 0;
+	i = 0;
 	cmd = malloc(25);
 	
-	printf("> ");
+	printf("%s> ", cuser.name);
 	while(1)
 	{
 		c = ps2_getc();
@@ -77,12 +76,12 @@
 			cmd[i] = '\0';
 			if(call(cmd) == NO_SUCH_CMD)
 				printf("No such command\n");
-			
+
 			/* clear the mess */
 			memset(cmd, '\0', 25);
 			i = 0;
-			
-			printf("> ");
+
+			printf("%s> ", cuser.name);
 		}
 		/* ignore spaces as first character and ignore more than one space */
 		else if((c == ' ') && (i == 0 || cmd[i - 1] == ' '))
@@ -97,7 +96,7 @@
 			/* we don't want a negative i */
 			if(i)
 				i--;
-			cmd[i] = 0;
+			cmd[i] = '\0';
 		}
 	}
 }
--- a/cmd/rc.h
+++ b/cmd/rc.h
@@ -1,13 +1,16 @@
 #pragma once
 
-void rc_main(void);
-int echo_main(int argc, char** argv, char *cwd);
-int clear_main(int argc, char** argv, char *cwd);
-int check_main(int argc, char** argv, char *cwd);
-int cal_main(int argc, char** argv, char *cwd);
-int ls_main(int argc, char** argv, char *cwd);
-int reboot_main(int argc, char** argv, char *cwd);
-int memory_main(int argc, char** argv, char *cwd);
+extern void rc_main(void);
+extern int echo_main(int argc, char **argv);
+extern int clear_main(int argc, char **argv);
+extern int check_main(int argc, char **argv);
+extern int cal_main(int argc, char **argv);
+extern int ls_main(int argc, char **argv);
+extern int reboot_main(int argc, char **argv);
+extern int memory_main(int argc, char **argv);
+extern int cat_main(int argc, char **argv);
+extern int login_main(int argc, char **argv);
+extern int id_main(int argc, char **argv);
 
 static prog_t cmdtab[] =
 {
@@ -18,4 +21,7 @@
 	{"ls", ls_main},
 	{"reboot", reboot_main},
 	{"memory", memory_main},
+	{"cat", cat_main},
+	{"login", login_main},
+	{"id", id_main},
 };
--- a/include/u.h
+++ b/include/u.h
@@ -24,6 +24,6 @@
 typedef struct
 {
 	char *name;
-	int (*main)(int argc, char **argv, char *cwd);
+	int (*main)(int argc, char **argv);
 }prog_t;