From 81dd6b162351d93dae5d71a45df56ee1a74a36ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Manuel=20Tom=C3=A1s?= Date: Tue, 7 Jul 2020 13:04:26 -0300 Subject: Split application into server and client --- buffer.cpp | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) (limited to 'buffer.cpp') diff --git a/buffer.cpp b/buffer.cpp index 9313380..d1762d0 100644 --- a/buffer.cpp +++ b/buffer.cpp @@ -1,21 +1,24 @@ struct Buffer { const char *name; - Point start; - Point cursor; + Page *storage; - Buffer(const char *name) : name(name), start(), cursor(start) {} + Buffer(const char *name) : name(name), storage(new Page()) {} - void prev_line(int window_width) { - cursor--; - cursor.rseek('\n', window_width - 1); + void read(const char *file) { + FILE *f = fopen(file, "r"); + char c; + Point p(storage, 0); + while ((c = fgetc(f)) != EOF) { + p.push(c); + } + fclose(f); } - void next_line(int window_width) { - cursor.seek('\n', window_width); - if (cursor.element() == '\n') { - cursor++; + void write(const char *file) { + FILE *f = fopen(file, "w+"); + for (Point p(storage, 0); !p.at_end(); p++) { + fputc(p.element(), f); } + fclose(f); } - }; - -- cgit v1.2.3