From 2cfa074c13638cfdd694728c200e8f772b84e4c8 Mon Sep 17 00:00:00 2001 From: Martin Dvorak Date: Sat, 8 Feb 2014 07:06:50 +0100 Subject: [PATCH] Code review and stabilization. --- dist/ubuntu-env.sh | 1 + src/hstr.c | 58 +++++++++++++++++++-------------- tests/monster/monster-hh-env.sh | 11 +++++++ tests/src/test_keyb.c | 3 ++ 4 files changed, 49 insertions(+), 24 deletions(-) create mode 100755 tests/monster/monster-hh-env.sh diff --git a/dist/ubuntu-env.sh b/dist/ubuntu-env.sh index 52dc56c..74c5aaf 100755 --- a/dist/ubuntu-env.sh +++ b/dist/ubuntu-env.sh @@ -11,6 +11,7 @@ export HHBUILD=hstr-${NOW} #export UBUNTUVERSION=quantal #export UBUNTUVERSION=raring export UBUNTUVERSION=saucy +#export UBUNTUVERSION=trusty export HHBZRMSG="Making radix sort allocation more effient and inserts more robust." diff --git a/src/hstr.c b/src/hstr.c index 5a919b1..0588c24 100644 --- a/src/hstr.c +++ b/src/hstr.c @@ -27,7 +27,7 @@ #define SELECTION_CURSOR_IN_PROMPT -1 #define SELECTION_PREFIX_MAX_LNG 500 -#define CMDLINE_LNG 250 +#define CMDLINE_LNG 2048 #define Y_OFFSET_PROMPT 0 #define Y_OFFSET_HELP 1 @@ -108,7 +108,7 @@ static unsigned selectionSize=0; static bool caseSensitive=FALSE; static bool defaultOrder=FALSE; static bool hicolor=FALSE; -static char screenLine[1000]; +static char screenLine[CMDLINE_LNG]; static char cmdline[CMDLINE_LNG]; void get_env_configuration() @@ -172,17 +172,13 @@ void print_cmd_deleted_label(char *cmd, int occurences) void print_history_label(HistoryItems *history) { - sprintf(screenLine, "- HISTORY - case:%s (C-t) - order:%s (C-/) - %d/%d ", + int width=getmaxx(stdscr); + snprintf(screenLine, width, "- HISTORY - case:%s (C-t) - order:%s (C-/) - %d/%d ", (caseSensitive?"sensitive":"insensitive"), (defaultOrder?"history":"ranking"), history->count, history->rawCount); - int width=getmaxx(stdscr); width -= strlen(screenLine); - if(width<0) { - width = 0; - screenLine[getmaxx(stdscr)]=0; - } unsigned i; for (i=0; i < width; i++) { strcat(screenLine, "-"); @@ -199,7 +195,8 @@ void print_history_label(HistoryItems *history) refresh(); } -void print_pattern(char *pattern, int y, int x) { +void print_pattern(char *pattern, int y, int x) +{ color_attr_on(A_BOLD); mvprintw(y, x, "%s", pattern); color_attr_off(A_BOLD); @@ -214,16 +211,15 @@ unsigned get_max_history_items() void realloc_selection(unsigned size) { - selectionSize=size; - if(selection!=NULL) { - if(size>0) { + if(selection) { + if(size) { selection=realloc(selection, size); } else { free(selection); selection=NULL; } } else { - if(size>0) { + if(size) { selection = malloc(size); } } @@ -232,12 +228,18 @@ void realloc_selection(unsigned size) unsigned make_selection(char *prefix, HistoryItems *history, int maxSelectionCount) { realloc_selection(sizeof(char*) * maxSelectionCount); + unsigned i, selectionCount=0; char **source=(defaultOrder?history->raw:history->items); + unsigned count=(defaultOrder?history->rawCount:history->count); - for(i=0; icount && selectionCountcount && selectionCount0) { + if(prefix && strlen(prefix)>0) { color_attr_on(A_BOLD); char *p; if(caseSensitive) { @@ -292,7 +295,8 @@ void print_selection_row(char *text, int y, int width, char *prefix) { } } -void print_highlighted_selection_row(char *text, int y, int width) { +void print_highlighted_selection_row(char *text, int y, int width) +{ color_attr_on(A_BOLD); if(hicolor) { color_attr_on(COLOR_PAIR(2)); @@ -313,10 +317,12 @@ void print_highlighted_selection_row(char *text, int y, int width) { char *print_selection(unsigned maxHistoryItems, char *prefix, HistoryItems *history) { - char *result=""; + char *result; unsigned selectionCount=make_selection(prefix, history, maxHistoryItems); if (selectionCount > 0) { - result = selection[0]; + result=selection[0]; + } else { + result=""; } int height=get_max_history_items(stdscr); @@ -370,7 +376,8 @@ void selection_remove(char *cmd, HistoryItems *history) } } -void hstr_on_exit() { +void hstr_on_exit() +{ history_mgmt_flush(); free_prioritized_history(); } @@ -521,7 +528,9 @@ void loop_to_select(HistoryItems *history) selectionCursorPosition=0; } } - highlight_selection(selectionCursorPosition, previousSelectionCursorPosition, pattern); + if(selectionSize) { + highlight_selection(selectionCursorPosition, previousSelectionCursorPosition, pattern); + } move(y, basex+strlen(pattern)); break; case K_ENTER: @@ -576,7 +585,8 @@ void loop_to_select(HistoryItems *history) } } -void assemble_cmdline(int argc, char *argv[]) { +void assemble_cmdline(int argc, char *argv[]) +{ // TODO support BASH substitutions: !!, !!ps, !$, !* int i; cmdline[0]=0; diff --git a/tests/monster/monster-hh-env.sh b/tests/monster/monster-hh-env.sh new file mode 100755 index 0000000..95d30a0 --- /dev/null +++ b/tests/monster/monster-hh-env.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +export HISTCONTROL=ignorespace +export HISTFILE=/home/dvorka/p/hstr/monster/.bash_history_50M +#export HISTFILE=/home/dvorka/p/hstr/monster/.bash_history_23M +#export HISTFILE=/home/dvorka/p/hstr/monster/.bash_history_500k +#export HISTFILE=/home/dvorka/p/hstr/monster/.bash_history +export HISTFILESIZE=10000000 +export HISTSIZE=1000000 + +# eof diff --git a/tests/src/test_keyb.c b/tests/src/test_keyb.c index 1d5dc96..1d58e05 100644 --- a/tests/src/test_keyb.c +++ b/tests/src/test_keyb.c @@ -11,6 +11,9 @@ #include #include +// $ xev +// ... get keycodes + void echo_printable_characters() { int c;