summaryrefslogtreecommitdiff
path: root/userspace/foolshell.c
diff options
context:
space:
mode:
authorMichal Idziorek <m.i@gmx.at>2014-11-24 11:07:32 +0100
committerMichal Idziorek <m.i@gmx.at>2014-11-24 11:07:32 +0100
commita06d25b7afcd8b28ca001349634abaef87958fdc (patch)
tree58d282a899fbf13562d0a846351aa93115850a23 /userspace/foolshell.c
parent1cb7a6bd1ab40188987feeaeefce021d441819e6 (diff)
implemented basic 'cd' in foolshell
Diffstat (limited to 'userspace/foolshell.c')
-rw-r--r--userspace/foolshell.c90
1 files changed, 76 insertions, 14 deletions
diff --git a/userspace/foolshell.c b/userspace/foolshell.c
index 29e8438..faa46be 100644
--- a/userspace/foolshell.c
+++ b/userspace/foolshell.c
@@ -10,17 +10,20 @@ void hello()
// ascci art: http://patorjk.com/software/taag/#p=testall&f=Cards&t=Fool%20OS
puts(
- " ______ __ ____ _____ \n"
- " / ____/___ ____ / / / __ \\/ ___/ \n"
- " / /_ / __ \\/ __ \\/ / / / / /\\__ \\ \n"
- " / __/ / /_/ / /_/ / / / /_/ /___/ / \n"
- " /_/ \\____/\\____/_/ \\____//____/ \n"
- " \n"
- "Welcome to FoolShell v0.2 (Compiled on " __DATE__ " at " __TIME__ "\n"
- "--------------------------------------------------------------------\n\n"
- "type 'help' anytime to show shell built-ins\n"
- "or execute user programms that are in the '/bin' directory (e.g. ls)\n"
+ " ______ __ ____ _____ \n"
+ " / ____/___ ____ / / / __ \\/ ___/ \n"
+ " / /_ / __ \\/ __ \\/ / / / / /\\__ \\ \n"
+ " / __/ / /_/ / /_/ / / / /_/ /___/ / \n"
+ " /_/ \\____/\\____/_/ \\____//____/ \n"
+ " \n"
+ "Welcome to FoolShell v0.3 (Compiled on " __DATE__ " at " __TIME__ "\n"
+ "------------------------------------------------------------------\n\n"
+ "Please type 'help' anytime, to show shell \"built-ins\" or execute \n"
+ "user programms that are in you $PATH directory by simply typing \n"
+ "their filenames.\n"
);
+
+ printf("Your $PATH is currently set to: %s\n\n",getenv("PATH"));
}
void prompt()
@@ -105,10 +108,68 @@ int process(char *buf)
if(!strcmp(command,"help"))
{
- puts("foolshell: supported built-in commands: 'help', 'echo [string]', 'malloc [bytes]', 'free [address]', 'getenv [var]', 'putenv [var] [val]', 'env' 'cd [dir]'");
+ puts("foolshell: supported built-in commands: 'help', 'echo [string]', 'malloc [bytes]', 'free [address]', 'getenv [var]', 'putenv/setenv [var] [val]', 'env' 'cd [dir]'");
}
else if(!strcmp(command,"cd"))
{
+ char *dir=getenv("PWD");
+
+ char buf[256];
+
+ if(token[1][0]!='/')
+ {
+ sprintf(buf,"%s%s%s",dir,dir[0]=='/'&&dir[1]==0?"":"/",token[1]);
+ }
+ else
+ {
+ sprintf(buf,"%s",token[1]);
+ }
+
+ char token[10];
+
+ //adjust pwd (resolve '..' and '.')
+//// printf("adjusting pwd: '%s'\n",buf);
+ int left=1;
+ int right=0;
+
+ do{
+
+ int t=0;
+ do
+ {
+ right++;
+ token[t]=buf[right];
+
+ t++;
+ }
+ while(buf[right]!=0&&buf[right]!='/');
+ token[t-1]=0;
+
+// printf("path token: '%s'\n",token);
+
+
+
+ if(!strcmp(token,".."))
+ {
+ left--;
+ while(buf[left]!='/')left--;
+ }
+ else if(!strcmp(token,"."))
+ {
+ }
+ else
+ {
+ int i=0;
+ if(left!=1)buf[left++]='/';
+ do{buf[left++]=token[i++];}while(token[i]!=0);
+
+ }
+
+ }while(buf[right]!=0);
+ buf[left]=0;
+// printf("adjusted: '%s'\n",buf);
+
+ setenv("PWD",buf,1);
}
else if(!strcmp(command,"echo"))
@@ -128,14 +189,14 @@ int process(char *buf)
}
else if(!strcmp(command,"getenv"))
{
- printf("(0x%08X) put: %s = %s(0x%08X) \n",environ,token[1],getenv(token[1]),getenv(token[1]));
+ printf("(0x%08X) get: '%s' = '%s'(0x%08X) \n",environ,token[1],getenv(token[1]),getenv(token[1]));
}
- else if(!strcmp(command,"putenv"))
+ else if(!strcmp(command,"putenv")||!strcmp(command,"setenv"))
{
char buf[256];
sprintf(buf,"%s=%s",token[1],token[2]);
putenv(buf);
- printf("(0x%08X) set: %s = %s \n",environ,token[1],getenv(token[1]));
+ printf("(0x%08X) set: '%s' = '%s' \n",environ,token[1],getenv(token[1]));
}
else if(!strcmp(command,"env"))
{
@@ -152,6 +213,7 @@ int process(char *buf)
execve(token[0],token,0);
char buf[256];
sprintf(buf,"/bin/%s",token[0]);
+ asm("mov $0x05bff,%esp"); // set stack pointer
execve(buf,token,environ);
puts("foolshell: command not found");
}