#include #include #include void hello() { puts( "Welcome to FoolShell v0.1" ); } void prompt() { printf( "$ " ); } int main(int argc, char **argv) { // 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\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"); } }