static void wrapper_for_write_history() { #if 1 /* Alternative code, saves one disk access */ if (history_is_stifled()) unstifle_history(); if (gnuplot_history_size >= 0) stifle_history (gnuplot_history_size); /* returns 0 on success */ if (write_history(expanded_history_filename)) fprintf (stderr, "Warning: Could not write history file!!!\n"); unstifle_history(); #else /* if writing was successful, truncate history * to gnuplot_history_size lines */ if (write_history(expanded_history_filename)) { if (gnuplot_history_size >= 0) history_truncate_file(expanded_history_filename, gnuplot_history_size); } #endif }
static bool HHVM_FUNCTION(readline_write_history, const String& filename /* = null */) { if (filename.isNull()) { return write_history(nullptr) == 0; } else { return write_history(filename.data()) == 0; } }
static bool HHVM_FUNCTION(readline_write_history, const Variant& filename /* = null */) { if (filename.isNull()) { return write_history(nullptr) == 0; } else { auto const filenameString = filename.toString(); return write_history(filenameString.data()) == 0; } }
int main(int argc, char **argv) { int r; setlocale(LC_ALL, ""); parse_opts(argc, argv); aug = aug_init(root, loadpath, flags|AUG_NO_ERR_CLOSE); if (aug == NULL || aug_error(aug) != AUG_NOERROR) { fprintf(stderr, "Failed to initialize Augeas\n"); if (aug != NULL) print_aug_error(); exit(EXIT_FAILURE); } add_transforms(transforms, transformslen); if (print_version) { print_version_info(); return EXIT_SUCCESS; } readline_init(); if (optind < argc) { // Accept one command from the command line r = run_args(argc - optind, argv+optind); } else { r = main_loop(); } if (history_file != NULL) write_history(history_file); return r == 0 ? EXIT_SUCCESS : EXIT_FAILURE; }
static void quit(const char *line) { gp_close( port ); if ( write_history(historyfile) ) perror( "writing history" ); exit(EXIT_SUCCESS); }
int Spider_Url_Rinse::uninitialize() { write_history(); evdns_base_free(m_evdnsbase, 0); event_base_free(m_evbase); return 0; }
int CLI::shell() { for (exitShell_ = false; !exitShell_; ) { char* cmdline = readline("desaster> "); if (!cmdline) { printf("\n"); return 0; } if (!shellHistoryFilename_.empty()) add_history(cmdline); try { evaluate(cmdline); } catch (MultipleCommandsMatchError& e) { printf("%s\n", e.what()); } catch (NotFoundError& e) { printf("%s\n", e.what()); } if (!shellHistoryFilename_.empty()) write_history(shellHistoryFilename_.c_str()); } return 0; }
void Shell::saveShellHistory() { #ifdef CONFIG_READLINE // Only save history for interactive sessions if (_listenOnSocket) return; // Construct the path name of the history file QStringList pathList = QString(mt_history_file).split("/", QString::SkipEmptyParts); pathList.pop_back(); QString path = pathList.join("/"); // Create history path, if it does not exist if (!QDir::home().exists(path) && !QDir::home().mkpath(path)) debugerr("Error creating path for saving the history"); // Save the history for the next launch QString histFile = QDir::home().absoluteFilePath(mt_history_file); QByteArray ba = histFile.toLocal8Bit(); int ret = write_history(ba.constData()); if (ret) debugerr("Error #" << ret << " occured when trying to save the " "history data to \"" << histFile << "\""); #endif }
static int console_update_history(const char *histfile) { int ret = 0; #ifdef HAVE_READLINE int max_history_length, truncate_entries; /* * Calculate how much we should keep in the current history file. */ max_history_length = (me) ? me->history_length : 100; truncate_entries = max_history_length - history_length; if (truncate_entries < 0) { truncate_entries = 0; } /* * First, try to truncate the history file, and if it * fails, the file is probably not present, and we * can use write_history to create it. */ if (history_truncate_file(histfile, truncate_entries) == 0) { ret = append_history(history_length, histfile); } else { ret = write_history(histfile); } #endif return ret; }
gint main (gint argc, gchar **argv) { cli_infos_t *cli_infos; setlocale (LC_ALL, ""); cli_infos = cli_infos_init (argc - 1, argv + 1); /* Execute command, if connection status is ok */ if (cli_infos) { if (cli_infos->mode == CLI_EXECUTION_MODE_INLINE) { loop_once (cli_infos, argc - 1, argv + 1); } else { gchar *filename; filename = configuration_get_string (cli_infos->config, "HISTORY_FILE"); read_history (filename); using_history (); loop_run (cli_infos); write_history (filename); } } cli_infos_free (cli_infos); return 0; }
void readline_constructor_impl::impl::stop() { if (current_readline == NULL) { // We're already stopped return; } assert(detail::current_readline == this); stdin_reader_.cancel(); redisplay_timer_.cancel(); rl_callback_handler_remove(); detail::current_readline = NULL; std::cout << std::endl; if (!history_file_.empty()) { boost::filesystem::create_directories(history_file_.parent_path()); if (0 == write_history(history_file_.c_str())) { if (0 != history_truncate_file( history_file_.c_str(), history_length )) { throw relasio_error("error truncating history\n"); } } else { throw relasio_error("error writing history\n"); } } }
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 }
int main(int argc, char *argv[]) { read_history(history_file); load_tab_completion(); signal(SIGINT, &sighandler); // Don't die on sigint FILE * fd_sig = fdopen(5, "r"); // get signals to read from fd5 if(!fd_sig) exit(0); FILE * fd_out = fdopen(6, "w"); // output lines on fd6 if(!fd_out) exit(0); if(argc > 1) // load the prompt if available prompt = argv[1]; do { read_command(fd_sig, fd_out); } while(command); free(command); command = NULL; fclose(fd_sig); fclose(fd_out); write_history(history_file); return 0; }
static PyObject * write_history_file(PyObject *self, PyObject *args) { PyObject *filename_obj = Py_None, *filename_bytes; char *filename; int err; if (!PyArg_ParseTuple(args, "|O:write_history_file", &filename_obj)) return NULL; if (filename_obj != Py_None) { if (!PyUnicode_FSConverter(filename_obj, &filename_bytes)) return NULL; filename = PyBytes_AsString(filename_bytes); } else { filename_bytes = NULL; filename = NULL; } errno = err = write_history(filename); if (!err && _history_length >= 0) history_truncate_file(filename, _history_length); Py_XDECREF(filename_bytes); errno = err; if (errno) return PyErr_SetFromErrno(PyExc_IOError); Py_RETURN_NONE; }
/* * Here's our exit function. Just make sure everything * is freed, and any open files are closed. Added exit * message if you have anything to say, if you don't * you can pass it NULL and nothing will be printed. */ void exit_clean(int ret_no, const char *exit_message){ /*This is a bit hacky, try to append_history. *if that doesn't work, write history, which creates *the file, then writes to it. Should suffice for now. */ if(history){ if(append_history(1000, history_filename) != 0) if(write_history(history_filename) != 0){ write_to_log(SHELL_OOPS, "could not write history"); perror("history"); } } if(input) free(input); if(history_filename) free(history_filename); if(env) free(env); if(rc_file) fclose(rc_file); if(PS1 && specified_PS1 == 1) free(PS1); if(log_open) fclose(log_file); if(exit_message) fprintf(stderr,"%s", exit_message); exit(ret_no); }
void cli_context_loop (cli_context_t *ctx, gint argc, gchar **argv) { /* Execute command, if connection status is ok */ if (argc == 0) { gchar *filename = configuration_get_string (ctx->config, "HISTORY_FILE"); ctx->mode = CLI_EXECUTION_MODE_SHELL; /* print welcome message before initialising readline */ if (configuration_get_boolean (ctx->config, "SHELL_START_MESSAGE")) { g_printf (_("Welcome to the XMMS2 CLI shell!\n")); g_printf (_("Type 'help' to list the available commands " "and 'exit' (or CTRL-D) to leave the shell.\n")); } readline_resume (ctx); read_history (filename); using_history (); while (!cli_context_in_status (ctx, CLI_ACTION_STATUS_FINISH)) { cli_context_event_loop_select (ctx); } write_history (filename); } else { ctx->mode = CLI_EXECUTION_MODE_INLINE; cli_context_command_or_flag_dispatch (ctx, argc , argv); while (cli_context_in_status (ctx, CLI_ACTION_STATUS_BUSY) || cli_context_in_status (ctx, CLI_ACTION_STATUS_REFRESH)) { cli_context_event_loop_select (ctx); } } }
static void save_history_dotfile(void) { char *dotfile = g_strconcat(g_get_home_dir(), "/.fsp_history", NULL); stifle_history(100); /* arbitrarily restrict history file to 100 entries */ write_history(dotfile); g_free(dotfile); }
void attribute_hidden Rstd_savehistory(SEXP call, SEXP op, SEXP args, SEXP env) { SEXP sfile; char file[PATH_MAX]; const char *p; sfile = CAR(args); if (!isString(sfile) || LENGTH(sfile) < 1) errorcall(call, _("invalid '%s' argument"), "file"); p = R_ExpandFileName(translateChar(STRING_ELT(sfile, 0))); if(strlen(p) > PATH_MAX - 1) errorcall(call, _("'file' argument is too long")); strcpy(file, p); #if defined(HAVE_LIBREADLINE) && defined(HAVE_READLINE_HISTORY_H) if(R_Interactive && UsingReadline) { int err; err = write_history(file); if(err) error(_("problem in saving the history file '%s'"), file); /* Note that q() uses stifle_history, but here we do not want * to truncate the active history when saving during a session */ #ifdef HAVE_HISTORY_TRUNCATE_FILE R_setupHistory(); /* re-read the history size */ err = history_truncate_file(file, R_HistorySize); if(err) warning(_("problem in truncating the history file")); #endif } else errorcall(call, _("no history available to save")); #else errorcall(call, _("no history available to save")); #endif }
static void _save_history_file (void) { char *hfile = _get_history_file (); write_history (hfile); free (hfile); }
void append_history(char *path, char *cmd) { if (!path || !cmd) return; add_history(cmd); write_history(path); }
//------------------------------------------------------------------------------ void save_history() { int max_history; char buffer[512]; get_history_file_name(buffer, sizeof(buffer)); // Get max history size. max_history = get_clink_setting_int("history_file_lines"); max_history = (max_history == 0) ? INT_MAX : max_history; if (max_history < 0) { unlink(buffer); return; } // Write new history to the file, and truncate to our maximum. if (append_history(g_new_history_count, buffer) != 0) { write_history(buffer); } if (max_history != INT_MAX) { history_truncate_file(buffer, max_history); } g_new_history_count = 0; }
//------------------------------------------------------------------------------ void save_history() { int max_history; char buffer[1024]; const char* c; if (get_clink_setting_int("persist_history") == 0) { return; } get_history_file_name(buffer, sizeof(buffer)); // Get max history size. c = rl_variable_value("history-size"); max_history = (c != NULL) ? atoi(c) : 1000; // Write new history to the file, and truncate to our maximum. if (append_history(g_new_history_count, buffer) != 0) { write_history(buffer); } history_truncate_file(buffer, max_history); }
int lua_interactive (int argc, char * argv[]) { int error = 0; char * line; lua_State * L; char history_filename[256]; snprintf(history_filename, 256, "%s/%s", getenv("HOME"), LUA_HISTORY_FILENAME); L = luaL_newstate(); lua_rt_init(L, argc, argv); read_history(history_filename); while (1) { line = readline("X) "); add_history(line); stifle_history(LUA_HISTORY_LINES); write_history(history_filename); error = luaL_dostring(L, line); if (error) { line = (char *) luaL_checkstring(L, -1); printf("%s\n", line); } fflush(stdout); } return 0; }
void edit_deinit(const char *history_file, int (*filter_cb)(void *ctx, const char *cmd)) { rl_callback_handler_remove(); readline_free_completions(); eloop_unregister_read_sock(STDIN_FILENO); if (history_file) { /* Save command history, excluding lines that may contain * passwords. */ HIST_ENTRY *h; history_set_pos(0); while ((h = current_history())) { char *p = h->line; while (*p == ' ' || *p == '\t') p++; if (filter_cb && filter_cb(edit_cb_ctx, p)) { h = remove_history(where_history()); if (h) { os_free(h->line); free(h->data); os_free(h); } else next_history(); } else next_history(); } write_history(history_file); } }
finishInput(int exitstatus, void *arg) #endif { #ifdef USE_READLINE if (useHistory) { char *home; char *psql_history; home = getenv("HOME"); if (home) { psql_history = (char *) malloc(strlen(home) + 1 + strlen(PSQLHISTORY) + 1); if (psql_history) { int hist_size; hist_size = GetVariableNum(pset.vars, "HISTSIZE", -1, -1, true); if (hist_size >= 0) stifle_history(hist_size); sprintf(psql_history, "%s/%s", home, PSQLHISTORY); write_history(psql_history); free(psql_history); } } } #endif }
static void readline_exit(void) { char *path = expand_tilde(HISTORY_FILENAME); if (path) { write_history(path); free(path); } }
void deinit_readline(void) { str history = mal_clients->history; if (history) { write_history(history); } }
static int f_write_history(lua_State *L) { const char* file = lua_tostring(L,1); if(write_history(file) != 0) luaL_error(L, "writing history from file %s failed", file); lua_pushboolean(L, 1); return 1; }
static void cleanup_exit(int code) { if (chardev || sockdev) show("", ON_NEW_LINE); if (history_active) (void)write_history(historyfilename); exit(code); }
void halcmd_save_history() { char path[PATH_MAX]; snprintf(path,sizeof(path),"%s/%s", getenv("HOME"), HALCMD_HISTORY); if ((write_history (path))) perror(path); history_truncate_file (path, MAX_HISTORY); }