void trigger_op_recurse(t_ast *ast, char *input, int *tuple, t_sh *shell) { char **cut; char *tmp; char *eof_entry; ast->cmd = NULL; cut = cut_input(input, tuple); if (ast->op == 4) { tmp = get_eof(cut[1]); eof_entry = build_eof_entry(tmp, shell); ast->left = ast_build(eof_entry, 1, shell); ast->right = ast_build(ft_strjoin(cut[0], &cut[1][skip_eof(cut[1])]), 0, shell); free(cut[0]); free(cut[1]); } else if (ast->op == 11) process_pipe_stderr(cut, ast, shell); else { ast->left = ast_build(cut[0], 0, shell); ast->right = ast_build(cut[1], 0, shell); } free(cut); }
int tu_file::read_string ( char *dst, int max_length ) { int i = 0; while ( i < max_length ) { dst[i] = read8(); if ( get_eof() == true || dst[i] == '\n' || dst[i] == 0 ) { // remove the last '\r' if ( i > 0 && dst[i - 1] == '\r' ) { i--; } dst[i] = 0; return i + 1; } i++; } dst[i - 1] = 0; // force termination. return i; }
void tu_file::copy_to(membuf* dst) // Copy remaining contents of *this into *dst. { static const int BUFSIZE = 4096; while (get_eof() == false) { // Make room at the end of dst. dst->resize(dst->size() + BUFSIZE); int bytes_read = read_bytes(((char*) dst->data()) + dst->size() - BUFSIZE, BUFSIZE); if (bytes_read < BUFSIZE) { // Didn't use everything we allocated; trim the unused bytes. dst->resize(dst->size() - (BUFSIZE - bytes_read)); } if (get_error()) { break; } } }