void fe_reset_input_mode () { #if defined(HAVE_DYN_RL) char *p = getenv("SINGULARHIST"); if ((p != NULL) && (fe_history_total_bytes != NULL)) { if((*fe_history_total_bytes)()!=0) (*fe_write_history) (p); } #endif #if defined(HAVE_READLINE) && !defined(HAVE_FEREAD) && !defined(HAVE_DYN_RL) char *p = getenv("SINGULARHIST"); if (p != NULL) { if(history_total_bytes()!=0) write_history (p); } #endif #if defined(HAVE_FEREAD) #ifndef HAVE_ATEXIT fe_reset_fe(NULL,NULL); #else fe_reset_fe(); #endif #endif }
static char* entire_history_as_one_string(void) { HIST_ENTRY **the_list = history_list(), **entryp; if (!the_list) /* i.e. if there is no history */ return mysavestring(""); char *big_string = mymalloc(history_total_bytes() + history_length + 1); char * stringp = big_string; for (entryp = the_list; *entryp; entryp++) { int length = strlen((*entryp)->line); strncpy(stringp, (*entryp)->line, length); /* copy line, without closing NULL byte; */ stringp +=length; *stringp++ = '\n'; } *stringp = '\0'; DPRINTF1(DEBUG_READLINE, "stringified %d bytes of history", (int) strlen(big_string)); return big_string; }
void cleanup_rlwrap_and_exit(int status) { unblock_all_signals(); DPRINTF0(DEBUG_TERMIO, "Cleaning up"); if (write_histfile && (histsize==0 || history_total_bytes() > 0)) /* avoid creating empty .speling_eror_history file after typo */ write_history(history_filename); /* ignore errors */ close_logfile(); DPRINTF4(DEBUG_SIGNALS, "command_pid: %d, commands_exit_status: %x, filter_pid: %d, filters_exit_status: %x", command_pid, commands_exit_status, filter_pid, filters_exit_status); mymicrosleep(10); /* we may have got an EOF or EPIPE because the filter or command died, but this doesn't mean that SIGCHLD has been caught already. Taking a little nap now improves the chance that we will catch it (no grave problem if we miss it, but diagnostics, exit status and transparent signal handling depend on it) */ if (filter_pid) kill_filter(); else if (filter_is_dead) { int filters_killer = killed_by(filters_exit_status); errno = 0; mywarn((filters_killer ? "filter was killed by signal %d (%s)": WEXITSTATUS(filters_exit_status) ? "filter died" : "filter exited"), filters_killer, signal_name(filters_killer)); } if (debug) debug_postmortem(); if (terminal_settings_saved) if (tcsetattr(STDIN_FILENO, TCSAFLUSH, &saved_terminal_settings) < 0) /* ignore errors (almost dead anyway) */ ; /* fprintf(stderr, "Arggh\n"); don't use myerror!!*/ if (!newline_came_last) /* print concluding newline, if necessary */ my_putstr("\n"); if (status != EXIT_SUCCESS) /* rlwrap itself has failed, rather than the wrapped command */ exit(status); else { int commands_killer = killed_by(commands_exit_status); if (commands_killer) suicide_by(commands_killer, commands_exit_status); /* command terminated by signal, make rlwrap's parent believe rlwrap was killed by it */ else exit(WEXITSTATUS(commands_exit_status)); /* propagate command's exit status */ } }