summaryrefslogtreecommitdiff
path: root/buffer.cpp
diff options
context:
space:
mode:
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);
}
-
};
-