static void echo_read_cb(struct bufferevent *bev, void *ctx) { char * line; char* retval; size_t len; /* This callback is invoked when there is data to read on bev. */ struct evbuffer *input = bufferevent_get_input(bev); struct evbuffer *output = bufferevent_get_output(bev); struct evbuffer_iovec v[2]; line = evbuffer_readln(input, &len, EVBUFFER_EOL_CRLF); retval = (char*)command_parser(line); //command_parser(line); evbuffer_reserve_space(output, strlen(retval), v, 2); evbuffer_add(output, retval, strlen(retval)); evbuffer_commit_space(output, v, 1); //evbuffer_add_buffer(output, input); //evbuffer_copyout(input, line, buffer_len); /* Copy all the data from the input buffer to the output buffer. */ printf("%s\n",line); free(line); }
int main(int argc, char *argv[]) { init_shell(); // Initalizes the shell welcome_screen(); // Displays the welcome screen setenv("shell", getcwd(currentDirectory, 1024), 1); command_parser(); return (0); }
int main(int argc, char **argv) { FILE* input; int i; file_count(argc, argv); Filenames = malloc(sizeof(char*) * Num_Files); if(Filenames == NULL) { printf("Error: Failed To Allocate %lu Bytes\n", (sizeof(char*) * Num_Files)); printf("Terminating Program . . .\n"); return 1; } command_parser(argc, argv); if(!(Options & HELP)) { /* If no files are supplied, Num_Files is set to 1for stdin */ if(*Filenames == NULL) Num_Files++; for(i = 0; i < Num_Files; i++) { /* Determine the input */ if(*Filenames) { input = fopen(Filenames[i], "rt"); if(input == NULL) { printf("Error: Failed To Open %s\n", Filenames[i]); printf("Terminating Program . . .\n"); return 1; } } else input = stdin; filter(input, space_per_tab, replace_arg, delete_arg); if(*Filenames) free(input); } } else help(); free(Filenames); return 0; }
void client_handle(client * this_client) { int recvd = 0; char buffer[1024]; memset(buffer, 0, 1024); send(this_client->sock, "220 Welcome\n", 12, 0); while ((recvd = recv(this_client->sock, buffer, sizeof(buffer)/sizeof(char), 0)) > 0) { command_parser(this_client, buffer); memset(buffer, 0, 1024); } if (recvd == -1) { ERR("Client %d socket broken\n", this_client->id); } else { LOG("Client %d closed connection\n", this_client->id); } remove_client(this_client); }
int concat_command(char *cmd, char c) { int i; i = 0; if (c == '\n') { command_parser(cmd); memset(cmd, '\0', 256); return (0); } while (cmd[i] != '\0') { i = i + 1; } cmd[i] = c; return (0); }
/** * @brief Start a client to interact with the storage server. * * Decides where to start logging based on the LOGGING constant. * Calls the command_parser function. */ int main(int argc, char *argv[]) { int status = 0; if(TIME_EVAL == 1) client_time_log = fopen("client_times.log", "a"); while(status != -1) status = command_parser(); sprintf(trash, "Total %d gets performed in %ld microseconds\n", n_gets, get_processing_time.tv_usec); logger(client_time_log, trash); sprintf(trash, "Total %d sets performed in %ld microseconds\n", n_sets, set_processing_time.tv_usec); logger(client_time_log, trash); if(TIME_EVAL == 1) fclose(client_time_log); return status; }
int command_interpreter(FTPinfo * FTP_information) { char pure_command[MAXLINE]; char arg_opt[MAXLINE]; int fail; // this variable make program code readable. char buf[MAXLINE]; // This will be used for multiple purpose below. char* userpath; // user relative path. strcpy(pure_command, FTP_information->RAW_command); //unsafe. fail = command_parser(FTP_information->RAW_command, pure_command, arg_opt); /* for example, command_parser("USER localhost -arg -opt", buffer-pointer, buffer-pointer2); buffer-pointer -> USER buffer-pointer2 -> localhost -arg -opt */ /* if(fail) // fail to parse command due to invalid command. { perror("parse error"); return -1; } */ /* interpret command. */ if( strcmp(pure_command, "USER") == 0) { //strcpy(FTP_information->response_code, "331"); strcpy(FTP_information->response_code, "331 Please specify the password.\r\n"); strcpy(FTP_information->loginID, arg_opt); write(FTP_information->controlsockfd, FTP_information->response_code, strlen(FTP_information->response_code)); // send response. return 331; } else if( strcmp(pure_command, "PASS") == 0) { chdir("/Users/tracking/Desktop/old/REAL_FTP/REAL_FTP"); // for xcode debug. you should delete fail = checkID(FTP_information->loginID, arg_opt); if(fail) { strcpy(FTP_information->response_code, "530 Login incorrect.\r\n"); return 530; } // if there not exist user directory, then the program need to make it. if( access(FTP_information->loginID,F_OK) == -1) mkdir(FTP_information->loginID, 0777); // you'd better correct permission. // configure user directory. chdir(FTP_information->loginID); getcwd(FTP_information->root_directory, BUFSIZE); getcwd(FTP_information->working_directory, BUFSIZE); strcpy(FTP_information->response_code, "230- Welcome to my FTP world.\r\n"); strcat(FTP_information->response_code, "230-\r\n"); strcat(FTP_information->response_code, "230- This system is for authorized users only. All access is logged.\r\n"); strcat(FTP_information->response_code, "230 Login successful.\r\n"); write(FTP_information->controlsockfd, FTP_information->response_code, strlen(FTP_information->response_code)); // send response. return 230; } else if( strcmp(pure_command, "SYST") == 0) { strcpy(FTP_information->response_code, "215 MACOS Type: L8\r\n"); write(FTP_information->controlsockfd, FTP_information->response_code, strlen(FTP_information->response_code)); // send response. return 215; } else if( strcmp(pure_command, "FEAT") == 0) { strcpy(FTP_information->response_code, "211 \r\n"); write(FTP_information->controlsockfd, FTP_information->response_code, strlen(FTP_information->response_code)); // send response. return 211; } else if( strcmp(pure_command, "PWD") == 0) { // strcpy(buf, FTP_information->working_directory); userpath = Generate_userpath(FTP_information->working_directory, FTP_information->root_directory); if( *userpath == 0) // NULL is user-root directory { buf[0] = '/'; buf[1] = 0; userpath = buf; } sprintf(FTP_information->response_code, "257 \"%s\"\r\n", userpath); write(FTP_information->controlsockfd, FTP_information->response_code, strlen(FTP_information->response_code)); // send response. return 257; } else if( strcmp(pure_command, "CWD") == 0) { if(access(arg_opt, F_OK ) == -1) { sprintf(FTP_information->response_code, "550 %s: No such file or directory\r\n", arg_opt); return 550; } chdir(arg_opt); getcwd(buf, MAXLINE); // since user can't move upper directory than user direcory! if( strlen(buf) < strlen(FTP_information->root_directory)) chdir(FTP_information->root_directory); getcwd(FTP_information->working_directory, BUFSIZE); strcpy(FTP_information->response_code, "250 CWD command successful.\r\n"); write(FTP_information->controlsockfd, FTP_information->response_code, strlen(FTP_information->response_code)); // send response. return 250; } else if( strcmp(pure_command, "QUIT") == 0) { sprintf(FTP_information->response_code, "221 Goodbye \r\n"); close(FTP_information->controlsockfd); write(FTP_information->controlsockfd, FTP_information->response_code, strlen(FTP_information->response_code)); // send response. return 221; } else if( strcmp(pure_command, "PORT") == 0) { /* previous code. Get_dataportandIP(FTP_information,arg_opt); strcpy(FTP_information->response_code, "200 PORT command successful.\r\n"); strcpy(FTP_information->RAW_command, pure_command); */ Get_dataportandIP(FTP_information,arg_opt); strcpy(FTP_information->response_code, "200 PORT command successful.\r\n"); write(FTP_information->controlsockfd, FTP_information->response_code, strlen(FTP_information->response_code)); active_open(FTP_information); strcpy(FTP_information->response_code, "150 Data Connection OK\r\n"); write(FTP_information->controlsockfd, FTP_information->response_code, strlen(FTP_information->response_code)); return 200; } else if( strcmp(pure_command, "NOOP") == 0) { strcpy(FTP_information->response_code, "200 NOOP command successful.\r\n"); write(FTP_information->controlsockfd, FTP_information->response_code, strlen(FTP_information->response_code)); // send response. return 200; } else if( strcmp(pure_command, "PASV") == 0) { passive_open(FTP_information); // on failure, I would send the message "cannot open connection.". strcpy(FTP_information->response_code, "150 Data Connection OK\r\n"); // not need. write(FTP_information->controlsockfd, FTP_information->response_code, strlen(FTP_information->response_code)); // send response. return 227; } /* else if( strcmp(pure_command, "LIST") == 0) { active_open(FTP_information); // needs to return -1 or 0. for exception proces strcpy(FTP_information->response_code, "125 Data Connection OK\r\n"); write(FTP_information->controlsockfd, FTP_information->response_code, strlen(FTP_information->response_code)); // send response. return 125; } */ else if( strcmp(pure_command, "TYPE") == 0) { strcpy(FTP_information->response_code,"200 TYPE Command OK\r\n"); write(FTP_information->controlsockfd, FTP_information->response_code, strlen(FTP_information->response_code)); // send response. return 200; } else if( strcmp(pure_command, "MKD") == 0) { // strcpy(FTP_information->response_code, ") fail = mkdir(arg_opt, 0644); if(fail) { perror("directory error : "); strcpy(FTP_information->response_code, "503 Bad sequence of commands.\r\n"); return 503; } else { strcpy(FTP_information->response_code, "257 Directory Command succesful\r\n"); return 257; } write(FTP_information->controlsockfd, FTP_information->response_code, strlen(FTP_information->response_code)); // send response. } else { fail = Data_gateway(FTP_information); // maybe data transfer command. if(fail) { sprintf(FTP_information->response_code, "502 Command not implemented.\r\n"); write(FTP_information->controlsockfd, FTP_information->response_code, strlen(FTP_information->response_code)); return 502; } else { close(FTP_information->datasockfd); // transfer complete. write(FTP_information->controlsockfd, FTP_information->response_code, strlen(FTP_information->response_code)); return 226; } } return 0; }
int main(int argc, char **argv) { int ch, longindex, ret; unsigned long flags; struct option *long_options; const struct command *commands; const char *short_options; char *p; const struct sd_option *sd_opts; uint8_t sdhost[16]; int sdport; log_dog_operation(argc, argv); install_crash_handler(crash_handler); init_commands(&commands); if (argc < 2) usage(commands, 0); flags = setup_commands(commands, argv[1], argv[2]); optind = 3; sd_opts = build_sd_options(command_opts); long_options = build_long_options(sd_opts); short_options = build_short_options(sd_opts); while ((ch = getopt_long(argc, argv, short_options, long_options, &longindex)) >= 0) { switch (ch) { case 'a': if (!str_to_addr(optarg, sdhost)) { sd_err("Invalid ip address %s", optarg); return EXIT_FAILURE; } memcpy(sd_nid.addr, sdhost, sizeof(sdhost)); break; case 'p': sdport = strtol(optarg, &p, 10); if (optarg == p || sdport < 1 || sdport > UINT16_MAX) { sd_err("Invalid port number '%s'", optarg); exit(EXIT_USAGE); } sd_nid.port = sdport; break; case 'r': raw_output = true; break; case 'v': verbose = true; break; case 'h': subcommand_usage(argv[1], argv[2], EXIT_SUCCESS); break; case '?': usage(commands, EXIT_USAGE); break; default: if (command_parser) command_parser(ch, optarg); else usage(commands, EXIT_USAGE); break; } } if (!is_stdout_console() || raw_output) highlight = false; if (flags & CMD_NEED_NODELIST) { ret = update_node_list(SD_MAX_NODES); if (ret < 0) { sd_err("Failed to get node list"); exit(EXIT_SYSFAIL); } } if (flags & CMD_NEED_ARG && argc == optind) subcommand_usage(argv[1], argv[2], EXIT_USAGE); if (init_event(EPOLL_SIZE) < 0) exit(EXIT_SYSFAIL); if (init_work_queue(get_nr_nodes) != 0) { sd_err("Failed to init work queue"); exit(EXIT_SYSFAIL); } if (sockfd_init()) { sd_err("sockfd_init() failed"); exit(EXIT_SYSFAIL); } ret = command_fn(argc, argv); if (ret == EXIT_USAGE) subcommand_usage(argv[1], argv[2], EXIT_USAGE); return ret; }
int main(int argc, char **argv) { int ch, longindex, ret; unsigned long flags; struct option *long_options; const char *short_options; char *p; struct command commands[] = { vdi_command, node_command, cluster_command, debug_command, {NULL,} }; if (argc < 3) usage(commands, 0); flags = setup_command(commands, argv[1], argv[2]); optind = 3; long_options = build_long_options(command_options); short_options = build_short_options(command_options); while ((ch = getopt_long(argc, argv, short_options, long_options, &longindex)) >= 0) { switch (ch) { case 'a': sdhost = optarg; break; case 'p': sdport = strtol(optarg, &p, 10); if (optarg == p || sdport < 1 || sdport > UINT16_MAX) { fprintf(stderr, "Invalid port number '%s'\n", optarg); exit(EXIT_USAGE); } break; case 'r': raw_output = 1; break; case 'h': subcommand_usage(argv[1], argv[2], EXIT_SUCCESS); break; case '?': usage(commands, EXIT_USAGE); break; default: if (command_parser) command_parser(ch, optarg); else usage(commands, EXIT_USAGE); break; } } if (!isatty(STDOUT_FILENO) || raw_output) highlight = 0; if (flags & SUBCMD_FLAG_NEED_NODELIST) { ret = update_node_list(SD_MAX_NODES, 0); if (ret < 0) { fprintf(stderr, "Failed to get node list\n"); exit(EXIT_SYSFAIL); } } if (flags & SUBCMD_FLAG_NEED_THIRD_ARG && argc == optind) subcommand_usage(argv[1], argv[2], EXIT_USAGE); return command_fn(argc, argv); }
int main(int argc, char **argv) { int ch, longindex, ret; unsigned long flags; struct option *long_options; const struct command *commands; const char *short_options; char *p, *env; const struct sd_option *sd_opts; uint8_t sdhost[16]; int sdport; struct timespec start, end; start = get_time_tick(); log_dog_operation(argc, argv); install_crash_handler(crash_handler); init_commands(&commands); if (argc < 2) usage(commands, 0); flags = setup_commands(commands, argv[1], argv[2]); optind = 3; sd_opts = build_sd_options(command_opts); long_options = build_long_options(sd_opts); short_options = build_short_options(sd_opts); env = getenv("SHEEPDOG_DOG_ADDR"); if (env) { if (!str_to_addr(env, sdhost)) { sd_err("Invalid ip address %s", env); return EXIT_FAILURE; } memcpy(sd_nid.addr, sdhost, sizeof(sdhost)); } env = getenv("SHEEPDOG_DOG_PORT"); if (env) { sdport = strtol(env, &p, 10); if (env == p || sdport < 1 || sdport > UINT16_MAX || !is_numeric(env)) { sd_err("Invalid port number '%s'", env); exit(EXIT_USAGE); } sd_nid.port = sdport; } while ((ch = getopt_long(argc, argv, short_options, long_options, &longindex)) >= 0) { switch (ch) { case 'a': if (!str_to_addr(optarg, sdhost)) { sd_err("Invalid ip address %s", optarg); return EXIT_FAILURE; } memcpy(sd_nid.addr, sdhost, sizeof(sdhost)); break; case 'p': sdport = strtol(optarg, &p, 10); if (optarg == p || sdport < 1 || sdport > UINT16_MAX || !is_numeric(optarg)) { sd_err("Invalid port number '%s'", optarg); exit(EXIT_USAGE); } sd_nid.port = sdport; break; case 'r': raw_output = true; break; case 'v': verbose = true; break; case 'h': subcommand_usage(argv[1], argv[2], EXIT_SUCCESS); break; case 'T': elapsed_time = true; break; case '?': usage(commands, EXIT_USAGE); break; default: if (command_parser) command_parser(ch, optarg); else usage(commands, EXIT_USAGE); break; } } if (sd_inode_actor_init(dog_bnode_writer, dog_bnode_reader) < 0) exit(EXIT_SYSFAIL); if (!is_stdout_console() || raw_output) highlight = false; if (flags & CMD_NEED_NODELIST) { ret = update_node_list(SD_MAX_NODES); if (ret < 0) { sd_err("Failed to get node list"); exit(EXIT_SYSFAIL); } } if (flags & CMD_NEED_ARG && argc == optind) subcommand_usage(argv[1], argv[2], EXIT_USAGE); if (init_event(EPOLL_SIZE) < 0) exit(EXIT_SYSFAIL); if (wq_trace_init() < 0) exit(EXIT_SYSFAIL); if (init_work_queue(get_nr_nodes) != 0) { sd_err("Failed to init work queue"); exit(EXIT_SYSFAIL); } if (sockfd_init()) { sd_err("sockfd_init() failed"); exit(EXIT_SYSFAIL); } ret = command_fn(argc, argv); if (ret == EXIT_USAGE) subcommand_usage(argv[1], argv[2], EXIT_USAGE); if (elapsed_time) { end = get_time_tick(); printf("\nElapsed time: %.3lf seconds\n", get_time_interval(&start, &end)); } return ret; }
int main(int argc, char **argv) { int ch, longindex, ret; unsigned long flags; struct option *long_options; const struct command *commands; const char *short_options; char *p; const struct sd_option *sd_opts; install_crash_handler(crash_handler); init_commands(&commands); if (argc < 3) usage(commands, 0); flags = setup_commands(commands, argv[1], argv[2]); optind = 3; sd_opts = build_sd_options(command_opts); long_options = build_long_options(sd_opts); short_options = build_short_options(sd_opts); while ((ch = getopt_long(argc, argv, short_options, long_options, &longindex)) >= 0) { switch (ch) { case 'a': sdhost = optarg; break; case 'p': sdport = strtol(optarg, &p, 10); if (optarg == p || sdport < 1 || sdport > UINT16_MAX) { fprintf(stderr, "Invalid port number '%s'\n", optarg); exit(EXIT_USAGE); } break; case 'r': raw_output = true; break; case 'h': subcommand_usage(argv[1], argv[2], EXIT_SUCCESS); break; case '?': usage(commands, EXIT_USAGE); break; default: if (command_parser) command_parser(ch, optarg); else usage(commands, EXIT_USAGE); break; } } if (!is_stdout_console() || raw_output) highlight = false; if (flags & SUBCMD_FLAG_NEED_NODELIST) { ret = update_node_list(SD_MAX_NODES, 0); if (ret < 0) { fprintf(stderr, "Failed to get node list\n"); exit(EXIT_SYSFAIL); } } if (flags & SUBCMD_FLAG_NEED_ARG && argc == optind) subcommand_usage(argv[1], argv[2], EXIT_USAGE); return command_fn(argc, argv); }
static void interactive_mode(void) { int libfd=-1, maxdev, ndevs; fd_set readfds; ossmix_select_poll_t pollfunc; struct timeval tmout; libfd=ossmix_get_fd(&pollfunc); ossmix_set_callback(event_callback); printf("libfd=%d, func=%p\n", libfd, pollfunc); printf("\n"); printf("> ");fflush(stdout); if (libfd >= 0) { tmout.tv_sec = 0; tmout.tv_usec = 100000; /* 0.1 sec */ } else { tmout.tv_sec = 0; tmout.tv_usec = 0; } while (1) { FD_ZERO (&readfds); maxdev = 0; FD_SET (0, &readfds); // Stdin if (libfd > 0) FD_SET (libfd, &readfds); if (libfd > maxdev) maxdev = libfd; if ((ndevs = select (maxdev + 1, &readfds, NULL, NULL, &tmout)) == -1) { perror ("select"); exit (-1); } if (ndevs == 0) { ossmix_timertick(); tmout.tv_sec = 0; tmout.tv_usec = 100000; /* 0.1 sec */ } if (FD_ISSET (0, &readfds)) /* Stdio */ { char line[128]; if (fgets(line, sizeof(line)-1, stdin) != NULL) { command_parser(line); printf("> ");fflush(stdout); } } if (libfd > 0) if (FD_ISSET (libfd, &readfds)) pollfunc(); } }
void LEDtest3(void) { LEDSTR *p2Matrix=NULL; unsigned char temp; // unsigned char show_led=0; // LEDscreen_setShiftEnded_voidCallback(timetoshift); LEDscreen_setActualMSJ("**C5N**"); for (;;) { adcval=atd_getsample(); _printf("ADC;%d \n",adcval); ///// putcspi0(show_led++); p2Matrix=LEDscreen_getScreenAddress(); PORTA |= 0x01; LEDscreen_ShiftMSJ(); // shift msg one colum left if( Get_End_Of_Shift_Status() == TRUE) //Ckeck if the whole msg was sent { //_printf("Hallo Welt \n "); end_of_transmision = FALSE; Reset_FSM(); QueueInit(); Sci1_Putchar(XON); // HC05 Bluetooth //////// rti_start(); // Non Blocking W/hardware Timer Set_Timer_ms(3000); // 3 seconds window /* TIMER TEST _printf("Timer in \n"); while(1){ if( Get_Timer_ms_Status()) { _printf("Timer\n"); Set_Timer_ms(1000); } } TIMER TEST END*/ //// _printf("-(%c)[%.2X]-",ch,ch); do { if(messages_count()) _printf("Remaining mess %d\n",messages_count()); if(new_messages()) op_status=command_parser(commands); // Process the cmd } while ((endsts=(end_of_transmision == FALSE)) && (timsts=(Get_Timer_ms_Status()!=TIME_OUT))); if(!endsts) _printf("end_of_trans EOT\n"); if(!timsts) _printf("timeout EOT\n"); ////////////// rti_stop(); while(QueueStatus()) /// cleanup op_status=PullQueue(&temp); } Matrix2Vector(p2Matrix); // Convert Matrix to Vector Set_Color(color); Set_Intensity(Led_intensity); WS2812B_Init(); WS2812B_Set_Data_pointer((unsigned char *)DestLedScreen); WS2812B_Set_Data_Length(32*8*sizeof(LEDSTR)); WS2812B_Send_data(); PORTA &= 0xFE; //21.3 ms /// Set_Timer_ms(24); // 24 ms esto es normal velocidad posta Set_Timer_ms(speed); while (Get_Timer_ms_Status()!=TIME_OUT) ; // test_delay(100); //24.8 ms (OLD) _asm nop; _asm nop; _asm nop; _asm nop; } }
/* execution for the shell */ int execute() { /* e.g. "ls -l | cat -n" */ char line[MAX_LINE_LEN]; /* e.g. "ls -l", "cat -n" */ char cmd[MAX_CMD][MAX_CMD_LEN]; /* e.g. "ls", "-l" */ char buf[MAX_ARGC][MAX_ARG_LEN]; int status; /* background flag */ int is_bg; char str[2]; int i, n; /* processes to be waited */ pid_t wpid[MAX_CMD]; int cmd_num; COMMAND command; is_bg = 0; /* handle child processes exit signal and ctrl-c signal */ if (signal(SIGCHLD, chldHandler) == SIG_ERR || signal(SIGINT, intHandler) == SIG_ERR) { perror("Signal() error"); return DEFAULT_STATUS; } if (cflag) { if ((n = syntax_check(ccmd, &is_bg)) == -1) { fprintf(stderr, "sish: %s: Syntax error\n", ccmd); return DEFAULT_STATUS; } else if (n == 0) return EXIT_SUCCESS; cmd_num = command_parser(ccmd, cmd); if (xflag) { trace(cmd, cmd_num); } /* exit and cd */ if (cmd_num == 1) { command_init(&command); argument_parser(cmd[0], buf, &command); if (strcmp(command.arg[0], "exit") == 0) { if (exit_syntax_check(command.arg) == -1) { exit_usage(); ret_val = EXIT_FAILURE; return ret_val; } else { return ret_val; } } else if (strcmp(command.arg[0], "cd") == 0) { if (cd_syntax_check(command.arg) == -1) { cd_usage(); ret_val = EXIT_FAILURE; return ret_val; } ret_val = cd_exec(command.arg); return ret_val; } } execute_command(cmd, wpid, cmd_num); if (!is_bg) { for (i = 0; i < cmd_num; i++) { if (waitpid(wpid[i], &status, 0) == -1) { if (errno == ECHILD) { errno = 0; continue; } fprintf(stderr, "%d: waitpid() error" ": %s\n", wpid[i], strerror(errno)); return ret_val; } ret_val = check_status(status); } } return ret_val; } for (;;) { LBEGIN: print(); i = 0; while ((n = read(STDIN_FILENO, str, 1)) > 0) { str[1] = '\0'; if (strcmp(str, "\n") == 0) { line[i] = '\0'; break; } if (i >= MAX_LINE_LEN - 1) { fprintf(stderr, "sish: commands too long\n"); ret_val = EXIT_FAILURE; goto LBEGIN; } line[i] = str[0]; i++; } if (n < 0) { fprintf(stderr, "sish: read() error: %s\n", strerror(errno)); ret_val = EXIT_FAILURE; continue; } if ((n = syntax_check(line, &is_bg)) == -1) { fprintf(stderr, "sish: %s: Syntax error\n", line); ret_val = DEFAULT_STATUS; continue; } else if (n == 0) { continue; } cmd_num = command_parser(line, cmd); if (xflag) { trace(cmd, cmd_num); } /* exit and cd */ if (cmd_num == 1) { command_init(&command); argument_parser(cmd[0], buf, &command); if (strcmp(command.arg[0], "exit") == 0) { if (exit_syntax_check(command.arg) == -1) { exit_usage(); ret_val = EXIT_FAILURE; continue; } else { break; } } else if (strcmp(command.arg[0], "cd") == 0) { if (cd_syntax_check(command.arg) == -1) { cd_usage(); ret_val = EXIT_FAILURE; continue; } ret_val = cd_exec(command.arg); continue; } } execute_command(cmd, wpid, cmd_num); if (!is_bg) { for (i = 0; i < cmd_num; i++) { if (waitpid(wpid[i], &status, 0) == -1) { if (errno == ECHILD) { errno = 0; continue; } fprintf(stderr, "%d: waitpid() error" ": %s\n", wpid[i], strerror(errno)); return ret_val; } ret_val = check_status(status); } } } return ret_val; }