#include #include #include #include extern char **environ; // 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" ); } void prompt() { printf("%s",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("foolshell: supported built-in commands: 'help', 'echo [string]', 'malloc [bytes]', 'free [address]', 'getenv [var]', 'putenv [var] [val]', 'env'"); } 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("(0x%08X) put: %s = %s(0x%08X) \n",environ,token[1],getenv(token[1]),getenv(token[1])); } else if(!strcmp(command,"putenv")) { 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 { execve(token[0],token,0); char buf[256]; sprintf(buf,"/bin/%s",token[0]); execve(buf,token,environ); puts("foolshell: command not found"); } }