null+****@clear*****
null+****@clear*****
2011年 7月 6日 (水) 10:42:13 JST
Kouhei Sutou 2011-07-06 01:42:13 +0000 (Wed, 06 Jul 2011) New Revision: 6f4ab469e46c7264aaa1a4629e31f8571e2ac70b Log: [libedit] support history. Modified files: src/groonga.c Modified: src/groonga.c (+18 -0) =================================================================== --- src/groonga.c 2011-07-06 01:31:55 +0000 (b033f89) +++ src/groonga.c 2011-07-06 01:42:13 +0000 (be23942) @@ -78,6 +78,7 @@ static const char *input_path = NULL; static EditLine *edit_line; static HistoryW *command_history; static HistEventW command_history_event; +static char command_history_path[PATH_MAX]; inline static const wchar_t * disp_prompt(EditLine *e __attribute__((unused))) @@ -2287,10 +2288,23 @@ main(int argc, char **argv) } #ifdef HAVE_LIBEDIT if (!batchmode) { + static const char groonga_history_path[] = "/.groonga-history"; + setlocale(LC_ALL, ""); + command_history_path[0] = '\0'; + if (getenv("HOME") && + (strlen(getenv("HOME")) + strlen(groonga_history_path) < PATH_MAX)) { + strcat(command_history_path, getenv("HOME")); + strcat(command_history_path, "/.groonga-history"); + } + command_history = history_winit(); history_w(command_history, &command_history_event, H_SETSIZE, 200); + if (command_history_path[0]) { + history_w(command_history, &command_history_event, + H_LOAD, command_history_path); + } edit_line = el_init(argv[0], stdin, stdout, stderr); el_wset(edit_line, EL_PROMPT, &disp_prompt); @@ -2374,6 +2388,10 @@ main(int argc, char **argv) #ifdef HAVE_LIBEDIT if (!batchmode) { el_end(edit_line); + if (command_history_path[0]) { + history_w(command_history, &command_history_event, + H_SAVE, command_history_path); + } history_wend(command_history); } #endif