1 /* ----------------------------------------------------------------------------
2 Copyright (c) 2021, Daan Leijen
3 This is free software; you can redistribute it and/or modify it
4 under the terms of the MIT License. A copy of the license can be
5 found in the "LICENSE" file at the root of this distribution.
6 -----------------------------------------------------------------------------*/
10 #include "../include/isocline.h"
13 #include "stringbuf.h"
14 #include "completions.h"
19 //-------------------------------------------------------------
21 //-------------------------------------------------------------
23 struct editstate_s
* next
;
24 const char* input
; // input
25 ssize_t pos
; // cursor position
28 ic_private
void editstate_init( editstate_t
** es
) {
32 ic_private
void editstate_done( alloc_t
* mem
, editstate_t
** es
) {
34 editstate_t
* next
= (*es
)->next
;
35 mem_free(mem
, (*es
)->input
);
42 ic_private
void editstate_capture( alloc_t
* mem
, editstate_t
** es
, const char* input
, ssize_t pos
) {
43 if (input
== NULL
) { input
= ""; }
45 editstate_t
* entry
= mem_zalloc_tp(mem
, editstate_t
);
46 if (entry
== NULL
) { return; }
48 entry
->input
= mem_strdup( mem
, input
);
50 if (entry
->input
== NULL
) { mem_free(mem
, entry
); return; }
56 // caller should free *input
57 ic_private
bool editstate_restore( alloc_t
* mem
, editstate_t
** es
, const char** input
, ssize_t
* pos
) {
58 if (*es
== NULL
) { return false; }
60 editstate_t
* entry
= *es
;
62 *input
= entry
->input
;