summaryrefslogtreecommitdiff
path: root/buffer.cpp
diff options
context:
space:
mode:
authorJuan Manuel Tomás <jtomas1815@gmail.com>2020-07-07 13:04:26 -0300
committerJuan Manuel Tomás <jtomas1815@gmail.com>2020-07-07 13:04:26 -0300
commit81dd6b162351d93dae5d71a45df56ee1a74a36ca (patch)
tree18585513a9fcc9fdb0f2bfbd36643b08a1786bb4 /buffer.cpp
parentc835a9729091445bb68c5d376a8b8fd7a379cb32 (diff)
downloadjet-81dd6b162351d93dae5d71a45df56ee1a74a36ca.tar.gz
jet-81dd6b162351d93dae5d71a45df56ee1a74a36ca.zip
Split application into server and client
Diffstat (limited to 'buffer.cpp')
-rw-r--r--buffer.cpp27
1 files changed, 15 insertions, 12 deletions
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);
}
-
};
-