#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;
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;
history->buffer = PUSH_LT(lt, nth_calloc(capacity, sizeof(char*)), free);
if (history->buffer == NULL) {
- throw_error(ERROR_TYPE_LIBC);
RETURN_LT(lt, NULL);
}
void destroy_history(History *history)
{
- assert(history);
+ trace_assert(history);
for (size_t i = 0; i < history->capacity; ++i) {
if (history->buffer[i] != NULL) {
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;
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 {
void history_next(History *history)
{
- assert(history);
+ trace_assert(history);
history->cursor = (history->cursor + 1) % history->capacity;
}