static int handle_input_file(char *fname, struct handle_param *hparam) { FILE *f = NULL; char buf[1024*1024] = {0}; char *p = NULL; blog(LOG_DEBUG, "handling file:%s", fname); if(!(f = fopen(fname, "r"))){ blog(LOG_ERR, "open file failed:%s", buf); return -1; } while(!feof(f)){ if(!(p = fgets(buf, sizeof(buf) - 1, f))){ if(!feof(f)){ blog(LOG_ERR, "read file error"); break; } break; } blog(LOG_DEBUG, "get line from file : %s", p); handle_input_line(buf, hparam); } fclose(f); return 0; }
void shell_run(shell_t *shell) { char line_buf[255]; while(1) { int res = readline(shell, line_buf, sizeof(line_buf)); shell->put_char('>'); if (! res ) { char* line_copy = strdup(line_buf); handle_input_line(shell, line_copy); free(line_copy); } } }
void shell_run(const shell_command_t *shell_commands, char *line_buf, int len) { print_prompt(); while (1) { int res = readline(line_buf, len); if (!res) { handle_input_line(shell_commands, line_buf); } print_prompt(); } }
void shell_run(shell_t *shell) { char line_buf[shell->shell_buffer_size]; print_prompt(shell); while (1) { int res = readline(shell, line_buf, sizeof(line_buf)); if (!res) { handle_input_line(shell, line_buf); } print_prompt(shell); } }