]> git.lizzy.rs Git - nothing.git/blobdiff - src/ui/history.c
`Lt *` -> `Lt `
[nothing.git] / src / ui / history.c
index 645fc5599943d13866a53aa42b993465c72eb56e..935e88d99db6010394e1630e42f66db1191ad68d 100644 (file)
@@ -1,16 +1,15 @@
 #include <stdio.h>
 #include <stdlib.h>
-#include <assert.h>
+#include "system/stacktrace.h"
 
 #include "history.h"
-#include "str.h"
-#include "system/error.h"
+#include "system/str.h"
 #include "system/lt.h"
 #include "system/nth_alloc.h"
 
 struct History
 {
-    Lt *lt;
+    Lt lt;
 
     char **buffer;
     size_t begin;
@@ -20,17 +19,16 @@ struct History
 
 History *create_history(size_t capacity)
 {
-    Lt *lt = create_lt();
+    Lt lt = create_lt();
     if (lt == NULL) {
         return NULL;
     }
 
     History *history = PUSH_LT(
         lt,
-        nth_alloc(sizeof(History)),
+        nth_calloc(1, sizeof(History)),
         free);
     if (history == NULL) {
-        throw_error(ERROR_TYPE_LIBC);
         RETURN_LT(lt, NULL);
     }
     history->lt = lt;
@@ -41,7 +39,6 @@ History *create_history(size_t capacity)
 
     history->buffer = PUSH_LT(lt, nth_calloc(capacity, sizeof(char*)), free);
     if (history->buffer == NULL) {
-        throw_error(ERROR_TYPE_LIBC);
         RETURN_LT(lt, NULL);
     }
 
@@ -50,7 +47,7 @@ History *create_history(size_t capacity)
 
 void destroy_history(History *history)
 {
-    assert(history);
+    trace_assert(history);
 
     for (size_t i = 0; i < history->capacity; ++i) {
         if (history->buffer[i] != NULL) {
@@ -63,8 +60,8 @@ void destroy_history(History *history)
 
 int history_push(History *history, const char *command)
 {
-    assert(history);
-    assert(command);
+    trace_assert(history);
+    trace_assert(command);
 
     const size_t next_begin = (history->begin + 1) % history->capacity;
 
@@ -86,13 +83,13 @@ int history_push(History *history, const char *command)
 
 const char *history_current(History *history)
 {
-    assert(history);
+    trace_assert(history);
     return history->buffer[history->cursor];
 }
 
 void history_prev(History *history)
 {
-    assert(history);
+    trace_assert(history);
     if (history->cursor == 0) {
         history->cursor = history->capacity - 1;
     } else {
@@ -102,6 +99,6 @@ void history_prev(History *history)
 
 void history_next(History *history)
 {
-    assert(history);
+    trace_assert(history);
     history->cursor = (history->cursor + 1) % history->capacity;
 }