diff --git a/src/hstr.c b/src/hstr.c index 8183031..10d712f 100644 --- a/src/hstr.c +++ b/src/hstr.c @@ -854,8 +854,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 a55724f..3881716 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.h b/src/include/hstr.h index 25383d8..a68cb7d 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 diff --git a/src/include/hstr_favorites.h b/src/include/hstr_favorites.h index 21a9648..4a213d6 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;