diff options
author | Leo Tenenbaum <pommicket@gmail.com> | 2021-03-01 15:02:40 -0500 |
---|---|---|
committer | Leo Tenenbaum <pommicket@gmail.com> | 2021-03-01 15:02:40 -0500 |
commit | 12bb6e2cd377d3dfa2f7ec037c31463c3f9070d1 (patch) | |
tree | e3311ad77bd0fb768adcdce7582397cf97f40183 /buffer.c | |
parent | 2d327302b30bf67a87538dc5e005c0399c0b8f1a (diff) |
restore session
Diffstat (limited to 'buffer.c')
-rw-r--r-- | buffer.c | 16 |
1 files changed, 15 insertions, 1 deletions
@@ -112,7 +112,6 @@ void buffer_create(TextBuffer *buffer, Ted *ted) { buffer->ted = ted; } - void line_buffer_create(TextBuffer *buffer, Ted *ted) { buffer_create(buffer, ted); buffer->is_line_buffer = true; @@ -142,6 +141,21 @@ static bool buffer_pos_valid(TextBuffer *buffer, BufferPos p) { return p.line < buffer->nlines && p.index <= buffer->lines[p.line].len; } +// write a buffer position to a file +void buffer_pos_write(BufferPos pos, FILE *fp) { + write_u32(fp, pos.line); + write_u32(fp, pos.index); +} + +// read a buffer position from a file, and validate it +BufferPos buffer_pos_read(TextBuffer *buffer, FILE *fp) { + BufferPos pos = {0}; + pos.line = read_u32(fp); + pos.index = read_u32(fp); + buffer_pos_validate(buffer, &pos); + return pos; +} + // are there any unsaved changes? bool buffer_unsaved_changes(TextBuffer *buffer) { if (buffer_is_untitled(buffer) && buffer_empty(buffer)) |