void reverse_search(int sig) { if(sig == SIGQUIT){ char *line; printf("Enter command to reverse search:"); line = readline(""); int index = history_search(line, 0); printf("%d\n", index); char* guess_line; HIST_ENTRY* hist = history_get(index); guess_line = hist->line; printf("%s\n", guess_line); } }
/* Search the history list for STRING starting at absolute history position POS. If STRING begins with `^', the search must match STRING at the beginning of a history line, otherwise a full substring match is performed for STRING. DIR < 0 means to search backwards through the history list, DIR >= 0 means to search forward. */ static int noninc_search_from_pos (char *string, int pos, int dir) { int ret, old; old = where_history (); history_set_pos (pos); if (*string == '^') ret = history_search_prefix (string + 1, dir); else ret = history_search (string, dir); if (ret != -1) ret = where_history (); history_set_pos (old); return (ret); }
static void parse_line(char *line_read) { char **argvp; int argcp; int i; if (line_read == NULL) { g_print("\n"); g_main_loop_quit(main_loop); return; } line_read = g_strstrip(line_read); if (*line_read == '\0') { free(line_read); return; } if (history_search(line_read, -1)) add_history(line_read); g_shell_parse_argv(line_read, &argcp, &argvp, NULL); free(line_read); for (i = 0; commands[i].cmd; i++) if (strcasecmp(commands[i].cmd, argvp[0]) == 0) break; if (commands[i].cmd) commands[i].func(argcp, argvp); else g_print("%s: command not found\n", argvp[0]); g_strfreev(argvp); }