summaryrefslogtreecommitdiff
path: root/userspace/shell.c
diff options
context:
space:
mode:
authorMichal Idziorek <m.i@gmx.at>2014-11-23 23:26:26 +0100
committerMichal Idziorek <m.i@gmx.at>2014-11-23 23:26:26 +0100
commitec0ba7bc40854eab6a1cdb41364f41f9c11407e1 (patch)
tree88f3896c70ac32bc1b70dcd7ebddbbe595c6608f /userspace/shell.c
parent50300fa573bf2bc00f9732e812d54ab77cf03dd7 (diff)
foolshell and syscalls improvememets
Diffstat (limited to 'userspace/shell.c')
-rw-r--r--userspace/shell.c158
1 files changed, 0 insertions, 158 deletions
diff --git a/userspace/shell.c b/userspace/shell.c
deleted file mode 100644
index bb8b873..0000000
--- a/userspace/shell.c
+++ /dev/null
@@ -1,158 +0,0 @@
-#include <stdio.h>
-#include <stdint.h>
-#include <stdbool.h>
-#include <string.h>
-
-// ascci art: http://patorjk.com/software/taag/#p=testall&f=Cards&t=Fool%20OS
-//
-void hello()
-{
- 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 programms/commands that are on your $PATH (e.g. ls)\n"
- );
-}
-
-void prompt()
-{
- printf(
- "$ "
- );
-}
-
-int main(int argc, char **argv)
-{
-
- bool silent=false;
- for(int i=0;i<argc;i++)
- {
- if(!strcmp(argv[i],"--silent"))silent=true;
- }
-
- if(!silent)hello();
-
- char *buf=malloc(256);
-
- while(1)
- {
- prompt();
- fgets(buf,255,stdin);
- buf[strlen(buf)-1]=0; // remove \n
- process(buf);
- }
-
- return 0;
-}
-
-char **tokenize(char *buf)
-{
-
- char **token;
- token=malloc(10*sizeof(char*));
-
- int l=strlen(buf);
-
- int i;
- int c=0;
-
- for(i=0;i<l;i++)
- {
- // init space for next token
- token[c]=malloc(256);
-
- //skip all the whitespace
- while(buf[i]==' '&&i<l)i++;
- if(i==l)break;
-
- //get token
- int t=0;
-
- while(buf[i]!=' '&&i<l)
- {
- token[c][t]=buf[i];
- t++;
- i++;
- }
- token[c][t]=0;
-
-
-
-// printf("token %i : <%s>\n",c, token[c]);
- c++;
- token[c]=NULL;
-
- }
-
- return token;
-
-}
-
-int process(char *buf)
-{
-
- char **token=tokenize(buf);
- char *command=token[0];
- // puts(command);
- // copied from trottelshell
-
- if(!strcmp(command,"help"))
- {
- puts("foolshell: supported built-in commands: 'help', 'echo [string]', exec [inode_nr],'malloc [bytes]', 'free [address]', 'getenv [var]', 'putenv [var] [val]'");
- }
- else if(!strcmp(command,"exec"))
- {
- execve(atoi(token[1]),token,0);
-
- }
- else if(!strcmp(command,"echo"))
- {
- printf("\"%s\"\n",token[1]);
-
- }
- else if(!strcmp(command,"malloc"))
- {
- uint8_t *mall=malloc(atoi(token[1]));
- printf("allocated %d bytes at 0x%08X (%i).\n",atoi(token[1]),mall,mall);
- }
- else if(!strcmp(command,"free"))
- {
- free(atoi(token[1]));
- printf("called free(0x%08X).\n",atoi(token[1]));
- }
- else if(!strcmp(command,"getenv"))
- {
- printf("%s = %s \n",token[1],getenv(token[1]));
- }
- else if(!strcmp(command,"putenv"))
- {
- char buf[256];
- sprintf(buf,"%s=%s",token[1],token[2]);
- putenv(buf);
- printf("set: %s = %s \n",token[1],getenv(token[1]));
- }
- else
- {
- puts("foolshell: command not found");
- }
-
-}
-
-
-
-
-