#include #include #include #include #include extern char **environ; extern struct _reent *_impure_ptr; uint8_t buf_test[1024*300]; // void hello() { // ascci art: http://patorjk.com/software/taag/#p=testall&f=Cards&t=Fool%20OS puts( "\033c" "\033[36m" " ______ __ ____ _____ \n" " / ____/___ ____ / / / __ \\/ ___/ \n" " / /_ / __ \\/ __ \\/ / / / / /\\__ \\ \n" " / __/ / /_/ / /_/ / / / /_/ /___/ / \n" " /_/ \\____/\\____/_/ \\____//____/ \n" " \n" "\033[37;44m" " \n" " Welcome to FoolShell v0.12 (Compiled on " __DATE__ " at " __TIME__")\n" " ------------------------------------------------------------------\n\n" " Please type 'help' anytime, to show shell \"built-ins\". You can execute \n" " user programms that are in your $PATH directory by simply typing \n" " their filenames. Get additional information for many, of the available\n" " commands by invoking them with --help or -h. (e.g. ls --help) \n" " \n" "\033[37;40m" ); printf(" Your $PATH is currently set to: %s\n",getenv("PATH")); printf(" Type 'ls %s' to list programms on your $PATH.\n\n",getenv("PATH")); } void prompt() { printf("\033[36mfool\033[37m@\033[32mhill\033[33m:%s%s\033[37m",getenv("PWD"),getenv("PS1")); } int main(int argc, char **argv) { bool silent=false; for(int i=0;i\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( "\nfoolshell: supported built-in commands:\n\n" "'help' - show this message\n" "'echo [string]' - print given string to stdout\n" "'getenv [var]' - show environment variable\n" "'putenv/setenv [var] [val]' - set environemnet variable\n" "'env' - show all environment variables\n" "'cd [dir]' - change directory (set $PWD)\n" "'exit' - exit running foolshell\n\n"); } 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); if(buf[0]==0)setenv("PWD","/",1); else setenv("PWD",buf,1); } else if(!strcmp(command,"exit")) { _exit(1); } else if(!strcmp(command,"echo")) { printf("\"%s\"\n",token[1]); } else if(!strcmp(command,"getenv")) { printf("(0x%08X) get: '%s' = '%s'(0x%08X) \n",environ,token[1],getenv(token[1]),getenv(token[1])); } 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])); } else if(!strcmp(command,"env")) { int i=0; printf("env: 0x%08X\n",environ); while(environ[i]!=NULL) { printf("envvar %s (0x%08X)\n" ,environ[i],environ[i]); i++; } } else { int pid=_fork(); if(pid==0) { sprintf(buf,"%s",token[0]); _execve(buf,token,environ); sprintf(buf,"%s/%s",getenv("PATH"),token[0]); _execve(buf,token,environ); puts("foolshell: command not found"); exit(0); } if(token[1]!=NULL&&strcmp(token[1],"branch"))_wait(pid); } return 0; }