From 516a46e1d3c02c3e6a70e97238fa69084b08f66f Mon Sep 17 00:00:00 2001 From: Thibault Charbonnier Date: Wed, 9 Dec 2020 23:38:27 -0800 Subject: [PATCH 1/2] Remove duplicated includes from hstr.h These are already in hstr_curses.h, which I noticed after updating the ncurse.h path trying to build on Arch Linx. --- src/include/hstr.h | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/include/hstr.h b/src/include/hstr.h index b6a4629..e21ec68 100644 --- a/src/include/hstr.h +++ b/src/include/hstr.h @@ -21,13 +21,6 @@ #include #include -#ifdef __APPLE__ - #include -#elif defined(__FreeBSD__) - #include -#else - #include -#endif #include #include #include From f8cf3aa795bf2618d7ef76096a03a1513b04dd5d Mon Sep 17 00:00:00 2001 From: Thibault Charbonnier Date: Thu, 10 Dec 2020 11:59:29 -0800 Subject: [PATCH 2/2] Ensure 'skip-favorites-comments' does not strip comments when adding a new favorite. --- src/hstr.c | 4 ++-- src/hstr_favorites.c | 26 ++++++++++++++++++++------ src/include/hstr_favorites.h | 2 ++ 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/hstr.c b/src/hstr.c index 2f09fbf..7089483 100644 --- a/src/hstr.c +++ b/src/hstr.c @@ -832,8 +832,8 @@ unsigned hstr_make_selection(char* prefix, HistoryItems* history, unsigned maxSe count=history->rawCount; break; case HSTR_VIEW_FAVORITES: - source=hstr->favorites->items; - count=hstr->favorites->count; + source=hstr->favorites->itemsView; + count=hstr->favorites->countView; break; case HSTR_VIEW_RANKING: default: diff --git a/src/hstr_favorites.c b/src/hstr_favorites.c index 4dde8fc..01a8753 100644 --- a/src/hstr_favorites.c +++ b/src/hstr_favorites.c @@ -22,6 +22,8 @@ void favorites_init(FavoriteItems* favorites) { + favorites->itemsView=NULL; + favorites->countView=0; favorites->items=NULL; favorites->count=0; favorites->loaded=false; @@ -83,18 +85,26 @@ void favorites_get(FavoriteItems* favorites) } favorites->items = malloc(sizeof(char*) * favorites->count); + favorites->itemsView = malloc(sizeof(char*) * favorites->count); favorites->count = 0; char* pb=fileContent, *pe, *s; pe=strchr(fileContent, '\n'); while(pe!=NULL) { *pe=0; - if(!hashset_contains(favorites->set,pb)) { - if(!favorites->skipComments || !(strlen(pb) && pb[0]=='#')) { - s=hstr_strdup(pb); - favorites->items[favorites->count++]=s; - hashset_add(favorites->set,s); - } + if(!strlen(pb)) { + goto next; } + s=hstr_strdup(pb); + favorites->items[favorites->count++]=s; + if(pb[0]=='#' && favorites->skipComments) { + goto next; + } + if(!hashset_contains(favorites->set,pb)) { + s=hstr_strdup(pb); + favorites->itemsView[favorites->countView++]=s; + hashset_add(favorites->set,s); + } +next: pb=pe+1; pe=strchr(pb, '\n'); } @@ -206,7 +216,11 @@ void favorites_destroy(FavoriteItems* favorites) for(i=0; icount; i++) { free(favorites->items[i]); } + for(i=0; icountView; i++) { + free(favorites->itemsView[i]); + } free(favorites->items); + free(favorites->itemsView); hashset_destroy(favorites->set, false); free(favorites->set); free(favorites); diff --git a/src/include/hstr_favorites.h b/src/include/hstr_favorites.h index a3a8f11..98e35b8 100644 --- a/src/include/hstr_favorites.h +++ b/src/include/hstr_favorites.h @@ -27,7 +27,9 @@ typedef struct { char** items; + char** itemsView; unsigned count; + unsigned countView; bool loaded; bool reorderOnChoice; bool skipComments;