Browse Source

hist: hist_pos()

Serj Kalichev 1 year ago
parent
commit
e00db914d7
2 changed files with 15 additions and 2 deletions
  1. 1 0
      tinyrl/hist.h
  2. 14 2
      tinyrl/hist/hist.c

+ 1 - 0
tinyrl/hist.h

@@ -19,6 +19,7 @@ void hist_add(hist_t *hist, const char *line);
 void hist_clear(hist_t *hist);
 
 void hist_pos_reset(hist_t *hist);
+const char *hist_pos(hist_t *hist);
 const char *hist_pos_up(hist_t *hist);
 const char *hist_pos_down(hist_t *hist);
 

+ 14 - 2
tinyrl/hist/hist.c

@@ -47,7 +47,7 @@ hist_t *hist_new(size_t stifle)
 		return NULL;
 
 	// Init
-	hist->list = faux_list_new(FAUX_LIST_UNSORTED, FAUX_LIST_UNIQUE,
+	hist->list = faux_list_new(FAUX_LIST_UNSORTED, FAUX_LIST_NONUNIQUE,
 		hist_compare, hist_kcompare, (void (*)(void *))faux_str_free);
 	hist->pos = NULL; // It means position is reset
 	hist->stifle = stifle;
@@ -75,6 +75,18 @@ void hist_pos_reset(hist_t *hist)
 }
 
 
+const char *hist_pos(hist_t *hist)
+{
+	if (!hist)
+		return NULL;
+
+	if (!hist->pos)
+		return NULL;
+
+	return (const char *)faux_list_data(hist->pos);
+}
+
+
 const char *hist_pos_up(hist_t *hist)
 {
 	if (!hist)
@@ -133,8 +145,8 @@ void hist_clear(hist_t *hist)
 	if (!hist)
 		return;
 
-	hist_pos_reset(hist);
 	faux_list_del_all(hist->list);
+	hist_pos_reset(hist);
 }