int test(int* arg) { int i; char name[257]; for (i = 0; i < 50; i++) { sprintf(name, "%d", i); if (minifile_mkdir(name) == -1) { printf("mkdir failed on %dth entry. abort!\n", i); return -1; } if (minifile_cd(name) == -1) { printf("cd failed on %dth entry. abort!\n", i); return -1; } } for (i = 49; i >= 0; i--) { sprintf(name, "%d", i); if (minifile_cd("..") == -1) { printf("cd failed on %dth entry. abort!\n", i); return -1; } printf("curr dir: %s\n", minifile_pwd()); if (minifile_rmdir(name) == -1) { printf("rmdir failed on %dth entry. abort!\n", i); return -1; } } printf("all tests pass\n"); return 0; }
int shell(int *g) { char command[BUFFER_SIZE]; char func[BUFFER_SIZE],arg1[BUFFER_SIZE],arg2[BUFFER_SIZE]; int i; minifile_cd("/"); //cd to root (will also initialize the system if necessary) printf("%s\n", IDstring); while(1) { memset(command,'\0',BUFFER_SIZE); memset(func,'\0',BUFFER_SIZE); memset(arg1,'\0',BUFFER_SIZE); memset(arg2,'\0',BUFFER_SIZE); put_prompt(); gets(command); //extract first three strings in command (delimited by spaces) sscanf(command,"%s %s %s",func,arg1,arg2); if(strcmp(func,"help") == 0) help_screen(); else if(strcmp(func,"cd") == 0) minifile_cd(arg1); else if(strcmp(func,"ls") == 0 || strcmp(func,"dir") == 0) { char **files = minifile_ls(arg1); printf("File listing for %s\n", arg1); for(i = 0; files != NULL && files[i] != NULL; ++i) { printf("\t%s\n",files[i]); free(files[i]); } if(files != NULL) free(files); } else if(strcmp(func,"pwd") == 0) printf("%s\n", minifile_pwd()); else if(strcmp(func,"mkdir") == 0) minifile_mkdir(arg1); else if(strcmp(func,"rmdir") == 0) minifile_rmdir(arg1); else if(strcmp(func,"rm") == 0 || strcmp(func,"del") == 0) minifile_unlink(arg1); else if(strcmp(func,"import") == 0) importfile(arg1,arg2); else if(strcmp(func,"export") == 0) exportfile(arg1,arg2); else if(strcmp(func,"type") == 0) typefile(arg1); else if(strcmp(func,"input") == 0) inputfile(arg1); else if(strcmp(func,"cp") == 0 || strcmp(func,"copy") == 0) copy(arg1,arg2); else if(strcmp(func,"mv") == 0 || strcmp(func,"move") == 0) move(arg1,arg2); else if(strcmp(func,"whoami") == 0) printf("You are minithread %d, running our shell\n",minithread_id()); else if(strcmp(func,"exit") == 0) break; else if(strcmp(func,"doscmd") == 0) system(command+7); else if(strcmp(func,"exec") == 0) { //this is not efficient -- just for fun!!! char cmdline[BUFFER_SIZE]; memset(cmdline,'\0',BUFFER_SIZE); strcpy(cmdline,"tmp0000~.exe "); strcpy(cmdline+13,command+5+strlen(arg1)); exportfile(arg1,"tmp0000~.exe"); system(cmdline); system("rm tmp0000~.exe"); } else printf("%s: Command not found\n",func); } printf("Good-bye :-)\n"); return 0; }
void put_prompt() { printf("%d@localhost: %s %%",minithread_id(), minifile_pwd()); }
void put_prompt() { printf("thread%d@localhost", minithread_id()); printf(": %s %% ", minifile_pwd()); fflush(stdout); }