changeset 128:ca9f01e6e2bf

First attempt at argv and argc, probably screwed up a bit it has been so long...
author Jonathan Pevarnek <pevarnj@gmail.com>
date Thu, 11 Aug 2011 20:58:46 -0400
parents 2d47a53a5736
children 86ec817aa4f4
files src/os/shell.c src/prog/echo.c
diffstat 2 files changed, 29 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/src/os/shell.c	Fri Jun 24 11:04:54 2011 -0400
+++ b/src/os/shell.c	Thu Aug 11 20:58:46 2011 -0400
@@ -16,7 +16,7 @@
 void start(u64 __memsize)
 {
 	char buffer[128];
-	char *b, *c, *track;
+	char *c, *track; //TODO rememember if there was any reason I used b and c as variable names...
 	ErrCode err;
 	init_all(__memsize);
 	if(isError(init_fs(0x100, __memsize))) die();
@@ -26,8 +26,7 @@
 	while(1) {
 		sPrint("$ ");
 		sGet(buffer, 78);
-		b = buffer;
-		c = strtok_r(b, " ", &track);
+		c = strtok_r(buffer, " ", &track);
 
 		u32 fid;
 		if(isError(err = lookupFile(c, &fid))) {
@@ -66,6 +65,16 @@
 			pcb.psw.ea = 1;
 			pcb.psw.ba = 1;
 			pcb.psw.ptr = eHdr->e_entry;
+
+			char *clps[10]; //for now, only accept ten values
+			char **argv = clps;
+			pcb.registers[3] = (u64)argv; //TODO where should this actually be stored??
+			
+			while((*argv++ = strtok_r(NULL, " ", &track))) { //there was another item passed to the program
+				pcb.registers[2]++; //this starts at 0
+				if(pcb.registers[2] == 10) break; //TODO find a better way to deal with this
+			}
+
 			swapcontext_pcb(&shellPCB, &pcb);
 		loopCont:
 			free(data);
--- a/src/prog/echo.c	Fri Jun 24 11:04:54 2011 -0400
+++ b/src/prog/echo.c	Thu Aug 11 20:58:46 2011 -0400
@@ -2,16 +2,24 @@
 #include <std.h>
 #include <string.h>
 
-void start() //TODO: accept a command line argument of what to print
+void start(int argc, char** argv) //TODO: accept a command line argument of what to print
 {
-	char buffer[128];
-	char *b, *c, *track;
-	sGet(buffer, 128);
-	b = buffer;
-	while((c = strtok_r(b, " ,.", &track))) {
-		if(b) b = NULL;
-		sPrint(c);
-		sPrint("\n");
+	if(argc) {
+		int i;
+		for(i = 0; i < argc; i++) {
+			sPrint(*argv++);
+			sPrint("\n");
+		}
+	} else {
+		char buffer[128];
+		char *b, *c, *track;
+		sGet(buffer, 128);
+		b = buffer;
+		while((c = strtok_r(b, " ,.", &track))) {
+			if(b) b = NULL;
+			sPrint(c);
+			sPrint("\n");
+		}
 	}
 	exit();
 }