summaryrefslogtreecommitdiff
path: root/userspace
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
parent1cb7a6bd1ab40188987feeaeefce021d441819e6 (diff)
implemented basic 'cd' in foolshell
Diffstat (limited to 'userspace')
-rw-r--r--userspace/Makefile3
-rw-r--r--userspace/foolshell.c90
-rw-r--r--userspace/ls.c24
3 files changed, 91 insertions, 26 deletions
diff --git a/userspace/Makefile b/userspace/Makefile
index 3de83ea..63310bf 100644
--- a/userspace/Makefile
+++ b/userspace/Makefile
@@ -1,10 +1,11 @@
CC=i686-foolos-gcc
CFLAGS=
+CFLAGS+=-I..
CFLAGS+=-w
CFLAGS+=-std=gnu11
-PROGS=foolshell simple brainfuck add checker ls clear
+PROGS=foolshell ls simple brainfuck add checker clear
ext2.img: $(PROGS)
dd if=/dev/zero of=ext2.img bs=512 count=5000
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");
}
diff --git a/userspace/ls.c b/userspace/ls.c
index 4cbcb6d..1cbb065 100644
--- a/userspace/ls.c
+++ b/userspace/ls.c
@@ -1,28 +1,30 @@
-#include "../fs/fs.h"
+#include "fs/fs.h"
void usage()
{
puts("ls [inode_nr]");
}
+
+
int main(int argc, char **argv)
{
- char *dir;
+
fs_dirent *dirs=malloc(sizeof(fs_dirent)*25);
+ char *dir=getenv("PWD");
+// printf("PWD = %s\n",dir);
- if(argc!=2)
- {
- dir=getenv("PWD");
- }
- else
+ if(argc==2)
{
- if(argv[1][0]=="/")dir=argv[1];
- else
+ if(argv[1][0]!='/')
{
char buf[256];
- sprintf(buf,"%s/%s",getenv("PWD"),argv[1]);
+ sprintf(buf,"%s/%s",dir,argv[1]);
dir=buf;
-
+ }
+ else
+ {
+ dir=argv[1];
}
}