static void remember_in_history(const char *str) { int i; if (!(state->flags & DO_HISTORY)) return; i = state->cnt_history; free(state->history[MAX_HISTORY]); state->history[MAX_HISTORY] = NULL; /* After max history, remove the oldest command */ if (i >= MAX_HISTORY) { free(state->history[0]); for (i = 0; i < MAX_HISTORY-1; i++) state->history[i] = state->history[i+1]; } // Maybe "if (!i || strcmp(history[i-1], command) != 0) ..." // (i.e. do not save dups?) state->history[i++] = xstrdup(str); state->cur_history = i; state->cnt_history = i; #if ENABLE_FEATURE_EDITING_SAVEHISTORY if ((state->flags & SAVE_HISTORY) && state->hist_file) save_history(state->hist_file); #endif USE_FEATURE_EDITING_FANCY_PROMPT(num_ok_lines++;) }
void history_add(history_t *ph, char *string) { if (ph -> history_size > 0) { int loop; int found = -1; load_history(ph); /* bail out if this string is already in the history */ for(loop=0; loop<ph -> history_size; loop++) { if ((ph -> history)[loop] != NULL && strcmp((ph -> history)[loop], string) == 0) return ; } /* find free spot */ found = history_find_null_entry(ph); /* when no free spot was found, free-up an entry */ if (found == -1) { myfree((ph -> history)[ph -> history_size - 1]); memmove(&(ph -> history)[1], &(ph -> history)[0], sizeof(char *) * (ph -> history_size - 1)); found = 0; } (ph -> history)[found] = mystrdup(string); save_history(ph); } }
void reset_term(t_term *term) { term->c_lflag |= ICANON; term->c_lflag |= ECHO; tputs(tgetstr("te", NULL), 1, tputs_char); tputs(tgetstr("ve", NULL), 1, tputs_char); tcsetattr(0, 0, term); save_history(g_data); }
static void ft_clean_history(int histo_fd) { t_histo *histo; histo = save_history(NULL, 0); if (histo_fd > 0) { close(histo_fd); unlink(histo->path_cmd); } if (histo != NULL) { free_histo(); if (histo->path_cmd != NULL) free(histo->path_cmd); free(histo); } open_history(); }
int bi_history(t_shell *shell) { t_histo *histo; int nbr; histo = save_history(NULL, 0); if (shell->cmd[1] == NULL) { ft_print_full_history(histo, 20); return (0); } nbr = ft_atoi(shell->cmd[1]); if (ft_strcmp("-c", shell->cmd[1]) == 0) ft_clean_history(histo->fd); else if (nbr > 0) ft_print_full_history(histo, nbr); else ft_hist_help(); return (0); }
static void savegamestate(struct memfile *mf) { unsigned book_id; mtag(mf, 0, MTAG_GAMESTATE); mfmagic_set(mf, STATE_MAGIC); /* must come before migrating_objs and migrating_mons are freed */ save_timers(mf, level, RANGE_GLOBAL); save_light_sources(mf, level, RANGE_GLOBAL); saveobjchn(mf, invent); savemonchn(mf, migrating_mons); save_mvitals(mf); save_quest_status(mf); save_spellbook(mf); save_artifacts(mf); save_oracles(mf); mwrite(mf, pl_character, sizeof pl_character); mwrite(mf, pl_fruit, sizeof pl_fruit); mwrite32(mf, current_fruit); savefruitchn(mf); savenames(mf); save_waterlevel(mf); mwrite32(mf, lastinvnr); save_mt_state(mf); save_track(mf); save_food(mf); save_steal(mf); save_dig_status(mf); book_id = book ? book->o_id : 0; mwrite32(mf, book_id); mwrite32(mf, stetho_last_used_move); mwrite32(mf, stetho_last_used_movement); mwrite32(mf, multi); save_rndmonst_state(mf); save_history(mf); }
/* Called when an item is selected from history menu */ static void item_selected(GtkMenuItem *menu_item, gpointer user_data) { /* Get the text from the right element and set as clipboard */ GList* element = g_list_nth(history, GPOINTER_TO_INT(user_data)); history = g_list_remove_link(history, element); history = g_list_concat(element, history); history_item *elem_data = history->data; gtk_clipboard_set_text(clipboard, (gchar*)elem_data->content, -1); gtk_clipboard_set_text(primary, (gchar*)elem_data->content, -1); save_history(); /* Paste the clipboard contents automatically if enabled */ if (prefs.automatic_paste) { gchar* cmd = g_strconcat("/bin/sh -c 'xdotool key ctrl+v'", NULL); GPid pid; gchar **argv; g_shell_parse_argv(cmd, NULL, &argv, NULL); g_free(cmd); g_spawn_async(NULL, argv, NULL, G_SPAWN_DO_NOT_REAP_CHILD, NULL, NULL, &pid, NULL); g_child_watch_add(pid, (GChildWatchFunc)action_exit, NULL); g_strfreev(argv); } }
int exit_pgm(int exit_code) { t_node *tree; t_line *stline; t_duo *env; tree = savior_tree(NULL, FALSE); savior_history(NULL, FALSE); stline = savior_stline(NULL, FALSE); env = savior_env(NULL, FALSE); del_tree(&tree); savior_tree(NULL, TRUE); save_history(); duo_del(&env); savior_env(NULL, TRUE); reset_term(); del_stline(&stline); savior_stline(NULL, TRUE); exit(exit_code); return (0); }
void save_word_history(const gchar *word){ GList *list; gint length; LOG(LOG_DEBUG, "IN : save_word_history()"); // 既にリストにあるときは、いちばん上にもってくる list = check_duplicate_entry(word_history, word); if(list){ word_history = g_list_remove(word_history, list->data); } list = g_list_first(word_history); length =0; while(list != NULL){ list = g_list_next(list); length++; } if(word_history == NULL){ word_history = g_list_append(word_history, g_strdup(word)); } else if(length >= max_remember_words){ list = g_list_nth(word_history, max_remember_words-1); free(list->data); word_history = g_list_remove(word_history, list->data); word_history = g_list_prepend(word_history, g_strdup(word)); } else { word_history = g_list_prepend(word_history, g_strdup(word)); } gtk_combo_set_popdown_strings( GTK_COMBO(combo_word), word_history) ; save_history(); LOG(LOG_DEBUG, "OUT : save_word_history()"); }
/** * @brief Reads a whole line from the input channel. * @note Input chars are echoed on the same stream object with the * following exceptions: * - DEL and BS are echoed as BS-SPACE-BS. * - CR is echoed as CR-LF. * - 0x4 is echoed as "^D". * - Other values below 0x20 are not echoed. * . * * @param[in] scfg pointer to a @p ShellConfig object * @param[in] line pointer to the line buffer * @param[in] size buffer maximum length * @param[in] shp pointer to a @p ShellHistory object or NULL * @return The operation status. * @retval true the channel was reset or CTRL-D pressed. * @retval false operation successful. * * @api */ bool shellGetLine(ShellConfig *scfg, char *line, unsigned size, ShellHistory *shp) { char *p = line; BaseSequentialStream *chp = scfg->sc_channel; #if SHELL_USE_ESC_SEQ == TRUE bool escape = false; bool bracket = false; #endif #if SHELL_USE_HISTORY != TRUE (void) shp; #endif while (true) { char c; if (streamRead(chp, (uint8_t *)&c, 1) == 0) return true; #if SHELL_USE_ESC_SEQ == TRUE if (c == 27) { escape = true; continue; } if (escape) { escape = false; if (c == '[') { escape = true; bracket = true; continue; } if (bracket) { bracket = false; #if SHELL_USE_HISTORY == TRUE if (c == 'A') { int len = get_history(shp, line, SHELL_HIST_DIR_BK); if (len > 0) { _shell_reset_cur(chp); _shell_clr_line(chp); chprintf(chp, "%s", line); p = line + len; } continue; } if (c == 'B') { int len = get_history(shp, line, SHELL_HIST_DIR_FW); if (len == 0) *line = 0; if (len >= 0) { _shell_reset_cur(chp); _shell_clr_line(chp); chprintf(chp, "%s", line); p = line + len; } continue; } #endif } continue; } #endif #if (SHELL_CMD_EXIT_ENABLED == TRUE) && !defined(_CHIBIOS_NIL_) if (c == 4) { chprintf(chp, "^D"); return true; } #endif if ((c == 8) || (c == 127)) { if (p != line) { streamPut(chp, 0x08); streamPut(chp, 0x20); streamPut(chp, 0x08); p--; } continue; } if (c == '\r') { chprintf(chp, SHELL_NEWLINE_STR); #if SHELL_USE_HISTORY == TRUE save_history(shp, line, p - line); #endif *p = 0; return false; } #if SHELL_USE_COMPLETION == TRUE if (c == '\t') { if (p < line + size - 1) { *p = 0; get_completions(scfg, line); int len = process_completions(scfg, line, p - line, size); if (len > 0) { write_completions(scfg, line, p - line); p = line + len; } } continue; } #endif #if SHELL_USE_HISTORY == TRUE if (c == 14) { int len = get_history(shp, line, SHELL_HIST_DIR_FW); if (len == 0) *line = 0; if (len >= 0) { _shell_reset_cur(chp); _shell_clr_line(chp); chprintf(chp, "%s", line); p = line + len; } continue; } if (c == 16) { int len = get_history(shp, line, SHELL_HIST_DIR_BK); if (len > 0) { _shell_reset_cur(chp); _shell_clr_line(chp); chprintf(chp, "%s", line); p = line + len; } continue; } #endif if (c < 0x20) continue; if (p < line + size - 1) { streamPut(chp, c); *p++ = (char)c; } } }
/** * vinagre_connect: * @window: A Window * * Return value: (allow-none) (transfer full): */ VinagreConnection * vinagre_connect (VinagreWindow *window) { VinagreConnection *conn = NULL; gint result; VinagreConnectDialog dialog; dialog.xml = vinagre_utils_get_builder (); if (!dialog.xml) return NULL; dialog.dialog = GTK_WIDGET (gtk_builder_get_object (dialog.xml, "connect_dialog")); gtk_window_set_transient_for (GTK_WINDOW (dialog.dialog), GTK_WINDOW (window)); dialog.protocol_combo = GTK_WIDGET (gtk_builder_get_object (dialog.xml, "protocol_combo")); dialog.protocol_description_label = GTK_WIDGET (gtk_builder_get_object (dialog.xml, "protocol_description_label")); dialog.host_entry = GTK_WIDGET (gtk_builder_get_object (dialog.xml, "host_entry")); dialog.find_button = GTK_WIDGET (gtk_builder_get_object (dialog.xml, "find_button")); dialog.fullscreen_check = GTK_WIDGET (gtk_builder_get_object (dialog.xml, "fullscreen_check")); dialog.plugin_box = GTK_WIDGET (gtk_builder_get_object (dialog.xml, "plugin_options_connect_vbox")); dialog.connect_button = GTK_WIDGET (gtk_builder_get_object (dialog.xml, "connect_button")); setup_protocol (&dialog); setup_combo (&dialog); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog.fullscreen_check), vinagre_cache_prefs_get_boolean ("connection", "fullscreen", FALSE)); #ifdef VINAGRE_HAVE_AVAHI g_signal_connect (dialog.find_button, "clicked", G_CALLBACK (vinagre_connect_find_button_cb), &dialog); #else gtk_widget_hide (dialog.find_button); gtk_widget_set_no_show_all (dialog.find_button, TRUE); #endif gtk_widget_show_all (dialog.dialog); result = gtk_dialog_run (GTK_DIALOG (dialog.dialog)); if (result == GTK_RESPONSE_HELP) { vinagre_utils_show_help (GTK_WINDOW (window), "connect"); } else if (result == GTK_RESPONSE_OK) { gchar *host = NULL, *error_msg = NULL, *protocol = NULL, *actual_host; gint port; GtkWidget *options; GtkTreeIter iter; VinagreProtocol *ext; host = gtk_combo_box_text_get_active_text (GTK_COMBO_BOX_TEXT (dialog.host_entry)); gtk_widget_hide (GTK_WIDGET (dialog.dialog)); if (!host || !g_strcmp0 (host, "")) goto fail; save_history (dialog.host_entry); if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (dialog.protocol_combo), &iter)) { g_warning (_("Could not get the active protocol from the protocol list.")); goto fail; } gtk_tree_model_get (GTK_TREE_MODEL (dialog.protocol_store), &iter, PROTOCOL_NAME, &protocol, PROTOCOL_OPTIONS, &options, PROTOCOL_PLUGIN, &ext, -1); vinagre_cache_prefs_set_string ("connection", "last-protocol", protocol); g_free (protocol); vinagre_cache_prefs_set_boolean ("connection", "fullscreen", gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog.fullscreen_check))); conn = vinagre_protocol_new_connection (ext); if (vinagre_connection_split_string (host, vinagre_connection_get_protocol (conn), &protocol, &actual_host, &port, &error_msg)) { g_object_set (conn, "host", actual_host, "port", port, "fullscreen", gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog.fullscreen_check)), NULL); if (options) vinagre_connection_parse_options_widget (conn, options); g_free (protocol); g_free (actual_host); } else { vinagre_utils_show_error_dialog (NULL, error_msg ? error_msg : _("Unknown error"), GTK_WINDOW (window)); } g_object_unref (ext); if (options) g_object_unref (options); fail: g_free (host); g_free (error_msg); } gtk_widget_destroy (dialog.dialog); g_object_unref (dialog.xml); return conn; }
//------------------------------------------------------------------------------ static char* call_readline_impl(const char* prompt) { static int initialised = 0; int expand_result; char* text; char* expanded; char* prepared_prompt; char cwd_cache[MAX_PATH]; // Turn off EOL wrapping as Readline will take care of it. { HANDLE handle_stdout = GetStdHandle(STD_OUTPUT_HANDLE); SetConsoleMode(handle_stdout, ENABLE_PROCESSED_OUTPUT); } // Initialisation if (!initialised) { initialise_clink_settings(); initialise_lua(); initialise_fwrite(); load_history(); history_inhibit_expansion_function = history_expand_control; rl_catch_signals = 0; rl_startup_hook = initialise_hook; initialised = 1; } // If no prompt was provided assume the line is prompted already and // extract it. If a prompt was provided filter it through Lua. prepared_prompt = NULL; if (prompt == NULL) { prepared_prompt = extract_prompt(1); // Even though we're not going to display filtered result the extracted // prompt is run through Lua. This is a little bit of a hack, but helps // to keep behaviour consistent. if (prepared_prompt != NULL) { char buffer[1024]; str_cpy(buffer, prepared_prompt, sizeof(buffer)); lua_filter_prompt(buffer, sizeof_array(buffer)); } } else { prepared_prompt = filter_prompt(prompt); } GetCurrentDirectory(sizeof_array(cwd_cache), cwd_cache); do { // Call readline rl_already_prompted = (prompt == NULL); text = readline(prepared_prompt ? prepared_prompt : ""); if (!text) { goto call_readline_epilogue; } // Expand history designators in returned buffer. expanded = NULL; expand_result = expand_from_history(text, &expanded); if (expand_result > 0 && expanded != NULL) { free(text); text = expanded; // If there was some expansion then display the expanded result. if (expand_result > 0) { hooked_fprintf(NULL, "History expansion: %s\n", text); } } // Should we read the history from disk. if (get_clink_setting_int("history_io")) { load_history(); add_to_history(text); save_history(); } else add_to_history(text); } while (!text || expand_result == 2); call_readline_epilogue: free_prompt(prepared_prompt); SetCurrentDirectory(cwd_cache); return text; }