/* **主函数 */ int main (void) { int choice; struct student * head, * phead; struct student * p1; printf("\033[36;m"); menu(); scanf ("%d",&choice); while (choice != 0) { switch (choice ) { case 1: head = creat_list (); printf("录入完毕,任意键返回\n"); clear_s(); break; case 2: print_list (head); printf ("输出完毕,任意键返回\n"); clear_s(); break; case 3: delete_list(head); if (head == NULL) { printf ("删除不成功,请选择:\n"); scanf ("%d",&choice); break; } printf ("删除完毕,任意键返回\n"); clear_s(); break; case 4: p1 = find_stu(head); print_find(p1); printf ("查找完毕,任意键返回\n"); clear_s(); break; case 5: phead = ave_list (head); print_list(phead); printf ("排序完毕,任意键返回\n"); clear_s(); break; case 6: head = insert (head); print_list(head); printf ("插入完毕,任意键返回\n"); clear_s(); break; case 0: exit (0); break; } scanf ("%d",&choice); } }
int main(int argc, char *argv[]) { char* arguments[MAX_ARGS]; pipe(pipefd); signal(SIGCHLD, sig_chld_handler); //catching sigchld signal, for showing approporiate message when a child process has terminated printf("Basic Shell >"); int counter = 0; int is_blocking; char** commands; while ((flagwhile==1)&&(fgets(s,in,stdin)!=NULL)) /// command to reading from stdin 80 char in S { commands = splitCmd(s); if( overflowecheck() == 1) { printf("Overflowe!!!"); } else { counter =0; while(commands[counter]!= '\0') { is_blocking = parseCommand(commands[counter], arguments); // convert command string to an array if(arguments[0] !='\0') // check whether the input was an empty string or not { if (strcmp(arguments[0], "exit") == 0) { exit(EXIT_SUCCESS); } else if(strcmp(arguments[0], "cd") == 0) { if(chdir(arguments[1]) == -1) { //on error printf("%s\n",strerror(errno)); } } else if(strcmp(arguments[0], "source") == 0) { FILE * f; char * fline = NULL; size_t flen = 0; ssize_t read; f = fopen(arguments[1], "r"); if (f == NULL) { printf("file open error\n"); return EXIT_FAILURE; } while ((read = getline(&fline, &flen, f)) != -1) { char* arguments2[MAX_ARGS]; is_blocking = parseCommand(fline, arguments2); execLauncher(arguments2, is_blocking); } free(fline); // return EXIT_SUCCESS; } else { execLauncher(arguments, is_blocking); } } counter++; } } free(commands);// free the memory which allocated for the buffer clear_s(); redirect_stdout = false; redirect_stdin = false; piping = false; printf("Basic Shell >"); }//end while return 0; }// end main