/* ******************************* * Brandon A. Spires * CS 1635 Spring 2011 * Reusable Component "Snakeman.c" * Adapted from: myshell.c * Originally written by: Brandon Spires * For: cs1550 spring 2011 * *******************************/ #include #include #include #include #include #include extern char **getline(); extern int _argcount; main() { printf("WELCOME TO THE SNAKEMAN SHELL... TYPE \"exit\" TO TERMINATE THE PROGRAM\n"); while(1) { /* character or string values */ char **args; /* Places to hold user input */ //char *getJava = "java"; char **group4File = "java" "SnakemanTrainingGrounds"; /*group4File[0] = "java"; group4File[1] = "SnakemanTrainingGrounds";*/ printf("\n(^_^) --> "); /* signal to know we are in my shell */ args = getline(); /* retrieve input */ int child = 0; if(strcmp(args[0],"exit")== 0) /* If the user wants to quit */ { printf("(-_-)zzZ \n Goodbye...\n"); exit(EXIT_SUCCESS); } else if(strcmp(args[0],"cd") == 0) /* if the user wants to change directories */ { printf("Changing directories to %s\n", args[1]); if (chdir(args[1])== -1)/* if the filechange resulted in an error */ { printf("Command Failed\n"); } } else if(strcmp(args[0],"\n") == 0)/* user did not provide input */ { printf("You must provide an input\n"); } else { if((child = fork()) != 0) /* fork and create a new thread,If this is the parent thread then wait*/ { int status = 0; waitpid(-1, &status, 0); } else { if(strcmp(args[0],"G1") == 0) { printf("Opening Group 1's component... "); //execvp("filename goes here", "parameters go here\o"); printf("Command Failed\n"); exit(errno); } if(strcmp(args[0],"G2") == 0) { printf("Opening Group 2's component... "); //execvp("filename goes here", "parameters go here\o"); printf("Command Failed\n"); exit(errno); } if(strcmp(args[0],"G3") == 0) /* includes Group 6's component execution */ { printf("Opening Group 3's component... "); /* execvp("filename goes here", "parameters go here\o"); if((child = fork()) != 0) // fork and create a new thread, If this is the parent thread then wait { int status = 0; waitpid(-1, &status, 0); //perhaps this space is better used to toggle whenever the lever is able to be turned? } else { printf("Opening Group 6's component... "); //execvp("filename goes here", "parameters go here\o"); printf("Command Failed\n"); exit(errno); } */ printf("Command Failed\n"); exit(errno); } if(strcmp(args[0],"G4") == 0) { printf("Opening Group 4's component... "); execvp(group4File[0], group4File); printf("Command Failed\n"); exit(errno); } if(strcmp(args[0],"G5") == 0) { printf("Opening Group 5's component... "); //execvp("filename goes here", "parameters go here\o"); printf("Command Failed\n"); exit(errno); } if(strcmp(args[0],"G7") == 0) { printf("Opening Group 7's component... "); //execvp("filename goes here", "parameters go here\o"); printf("Command Failed\n"); exit(errno); } } } } }