Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge of pknowles 201706 #222

Open
wants to merge 3 commits into
base: merge-of-pknowles-201706
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 36 additions & 28 deletions src/hstr.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,11 @@
#define K_BACKSPACE 127
#define K_ENTER 13

#define HH_THEME_MONO 0
#define HH_THEME_COLOR 1<<7
#define HH_THEME_LIGHT 1|HH_THEME_COLOR
#define HH_THEME_DARK 2|HH_THEME_COLOR
#define HH_THEME_NONE 0
#define HH_THEME_MONO 1
#define HH_THEME_COLOR (1<<7)
#define HH_THEME_LIGHT ((1<<6)|HH_THEME_COLOR)
#define HH_THEME_DARK ((1<<5)|HH_THEME_COLOR)

#define HH_COLOR_NORMAL 1
#define HH_COLOR_HIROW 2
Expand Down Expand Up @@ -120,12 +121,12 @@
#define HH_DEBUG_LEVEL_DEBUG 2

#define HH_VIEW_RANKING 0
#define HH_VIEW_HISTORY 1
#define HH_VIEW_FAVORITES 2
#define HH_VIEW_FAVORITES 1
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strings in HH_VIEW_LABELS etc need to be updated to reflect these values.

#define HH_VIEW_HISTORY 2

#define HH_MATCH_SUBSTRING 0
#define HH_MATCH_REGEXP 1
#define HH_MATCH_KEYWORDS 2
#define HH_MATCH_KEYWORDS 0
#define HH_MATCH_SUBSTRING 1
#define HH_MATCH_REGEXP 2

#define HH_NUM_HISTORY_MATCH 3

Expand Down Expand Up @@ -312,7 +313,7 @@ void hstr_init()
hstr->showHelp = true;
hstr->promptBottom = false;

hstr->theme=HH_THEME_MONO;
hstr->theme=HH_THEME_NONE; // allow config to override
hstr->bigKeys=RADIX_BIG_KEYS_SKIP;
hstr->debugLevel=HH_DEBUG_LEVEL_NONE;

Expand Down Expand Up @@ -343,6 +344,12 @@ unsigned recalculate_max_history_items()

void hstr_get_env_configuration(Hstr *hstr)
{
/* To provide config priorities the MAX or MIN is taken.
* This means the constants must be in order of priority.
* In some cases where the default is not the lowest priority,
* an _NONE option is used and the default is set if unchanged
*/

const char *hstr_config=getenv(HH_ENV_VAR_CONFIG);
if (!hstr_config || !strlen(hstr_config)) {
return;
Expand All @@ -354,39 +361,33 @@ void hstr_get_env_configuration(Hstr *hstr)
char* item;
while ((item = strtok_r(saveptr, ",", &saveptr)) != NULL) {
if(strcmp(item,HH_CONFIG_THEME_MONOCHROMATIC)==0) {
hstr->theme=HH_THEME_MONO;
hstr->theme=MIN(hstr->theme, HH_THEME_MONO);
} else if(strcmp(item,HH_CONFIG_THEME_HICOLOR)==0) {
hstr->theme=HH_THEME_DARK;
hstr->theme=MIN(hstr->theme, HH_THEME_DARK);
} else if(strcmp(item,HH_CONFIG_CASE)==0) {
hstr->caseSensitive=HH_CASE_SENSITIVE;
} else if(strcmp(item,HH_CONFIG_REGEXP)==0) {
hstr->historyMatch=HH_MATCH_REGEXP;
hstr->historyMatch=MAX(hstr->historyMatch, HH_MATCH_REGEXP);
} else if(strcmp(item,HH_CONFIG_SUBSTRING)==0) {
hstr->historyMatch=HH_MATCH_SUBSTRING;
hstr->historyMatch=MAX(hstr->historyMatch, HH_MATCH_SUBSTRING);
} else if(strcmp(item, HH_CONFIG_KEYWORDS)==0) {
hstr->historyMatch=HH_MATCH_KEYWORDS;
hstr->historyMatch=MAX(hstr->historyMatch, HH_MATCH_KEYWORDS);
} else if(strcmp(item,HH_CONFIG_SORTING)==0) {
hstr->historyView=HH_VIEW_HISTORY;
hstr->historyView=MAX(hstr->historyView, HH_VIEW_HISTORY);
} else if(strcmp(item,HH_CONFIG_FAVORITES)==0) {
hstr->historyView=HH_VIEW_FAVORITES;
hstr->historyView=MAX(hstr->historyView, HH_VIEW_FAVORITES);
} else if(strcmp(item,HH_CONFIG_BIG_KEYS_EXIT)==0) {
hstr->bigKeys=RADIX_BIG_KEYS_EXIT;
hstr->bigKeys=MAX(hstr->bigKeys, RADIX_BIG_KEYS_EXIT);
} else if(strcmp(item,HH_CONFIG_BIG_KEYS_FLOOR)==0) {
hstr->bigKeys=RADIX_BIG_KEYS_FLOOR;
hstr->bigKeys=MAX(hstr->bigKeys, RADIX_BIG_KEYS_FLOOR);
} else if(strcmp(item,HH_CONFIG_BLACKLIST)==0) {
hstr->blacklist.useFile=true;
/* TODO content of while loop to be reverted to original code
}
if(strstr(hstr_config,HH_CONFIG_KEEP_PAGE)) {
} else if(strcmp(hstr_config,HH_CONFIG_KEEP_PAGE)==0) {
hstr->keepPage=true;
}

if(strstr(hstr_config,HH_CONFIG_DEBUG)) {
*/
} else if(strcmp(item,HH_CONFIG_DEBUG)==0) {
hstr->debugLevel=HH_DEBUG_LEVEL_DEBUG;
hstr->debugLevel=MIN(hstr->debugLevel, HH_DEBUG_LEVEL_DEBUG);
} else if(strcmp(item,HH_CONFIG_WARN)==0) {
hstr->debugLevel=HH_DEBUG_LEVEL_WARN;
hstr->debugLevel=MIN(hstr->debugLevel, HH_DEBUG_LEVEL_WARN);
} else if(strcmp(item,HH_CONFIG_DUPLICATES)==0) {
hstr->unique=false;
} else if(strcmp(item,HH_CONFIG_PROMPT_BOTTOM)==0) {
Expand All @@ -398,6 +399,10 @@ void hstr_get_env_configuration(Hstr *hstr)
}
}
free(config_items);

if (hstr->theme == HH_THEME_NONE) {
hstr->theme = HH_THEME_MONO;
}
}

int print_prompt()
Expand Down Expand Up @@ -1415,7 +1420,10 @@ int main(int argc, char *argv[])
blacklist_load(&hstr->blacklist);
hstr_main(hstr);

hstr_realloc_selection(0, hstr);
favorites_destroy(hstr->favorites);
blacklist_destroy(&hstr->blacklist);
hstr_regexp_destroy(&hstr->regexp);
free(hstr);

return EXIT_SUCCESS;
Expand Down
1 change: 0 additions & 1 deletion src/hstr_blacklist.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,5 @@ void blacklist_destroy(Blacklist *blacklist)
}
hashset_destroy(blacklist->set, false);
free(blacklist->set);
free(blacklist);
}
}
17 changes: 12 additions & 5 deletions src/hstr_history.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,12 @@ int get_item_offset()

HistoryItems *get_prioritized_history(int optionBigKeys, HashSet *blacklist)
{
assert(prioritizedHistory == NULL);

using_history();

char *historyFile = get_history_file_name();
// TODO: clear_history() here?
if(read_history(historyFile)!=0) {
fprintf(stderr, "\nUnable to read history file from '%s'!\n",historyFile);
exit(EXIT_FAILURE);
Expand Down Expand Up @@ -192,20 +195,23 @@ HistoryItems *get_prioritized_history(int optionBigKeys, HashSet *blacklist)
free(prioritizedRadix[i]->data);
free(prioritizedRadix[i]);
}
free(prioritizedRadix);

radixsort_destroy(&rs);
// TODO rankmap (?) and blacklist (?) to be destroyed

return prioritizedHistory;
} else {
return NULL;
hashset_destroy(&rankmap, false); // FIXME: free items true/false?
}

return prioritizedHistory;
}

void free_prioritized_history()
{
free(prioritizedHistory->items);
free(prioritizedHistory->rawItems);
free(prioritizedHistory);

// free memory (do not write_history after this!)
clear_history();
}

void history_mgmt_open()
Expand Down Expand Up @@ -260,6 +266,7 @@ int history_mgmt_remove_from_system_history(char *cmd)
write_history(get_history_file_name());
dirty=true;
}

return occurences;
}

Expand Down
3 changes: 3 additions & 0 deletions src/radixsort.c
Original file line number Diff line number Diff line change
Expand Up @@ -235,4 +235,7 @@ void radixsort_destroy(RadixSorter *rs)
free(rs->_slotDescriptors[topIndex]);
}
} while(--topIndex>=0);

free(rs->topDigits);
free(rs->_slotDescriptors);
}