From 1efda72797797ceb2a1693c88e4f5cc1f421e241 Mon Sep 17 00:00:00 2001 From: Curtis McEnroe Date: Wed, 21 Nov 2018 22:32:22 -0500 Subject: Read files in edi --- bin/edi/edi.h | 61 ++++++++++++++++++++++++----------------------------------- 1 file changed, 25 insertions(+), 36 deletions(-) (limited to 'bin/edi/edi.h') diff --git a/bin/edi/edi.h b/bin/edi/edi.h index 412e6d19..d8b1846b 100644 --- a/bin/edi/edi.h +++ b/bin/edi/edi.h @@ -17,11 +17,9 @@ #include #include -struct Span { +static inline struct Span { size_t at, to; -}; - -static inline struct Span spanNext(struct Span span, size_t len) { +} spanNext(struct Span span, size_t len) { return (struct Span) { span.to, span.to + len }; } @@ -31,15 +29,13 @@ struct Slice { }; struct Buffer { - size_t cap; - size_t len; + size_t cap, len; struct Slice slice; struct Block { struct Block *prev; wchar_t chars[]; } *block; }; - struct Buffer bufferAlloc(size_t cap); void bufferFree(struct Buffer *buf); void bufferInsert(struct Buffer *buf); @@ -47,43 +43,36 @@ void bufferAppend(struct Buffer *buf, wchar_t ch); void bufferDelete(struct Buffer *buf); wchar_t *bufferDest(struct Buffer *buf, size_t len); -struct Table { - size_t len; - size_t hot; +static const struct Table { + size_t cap, len; + size_t ins; struct Slice *slices; -}; -static const struct Table TableEmpty = { 0, 0, NULL }; - -struct Table tableInsert(struct Table prev, size_t at, struct Slice ins); -struct Table tableDelete(struct Table prev, struct Span del); +} TableEmpty; +struct Table tableAlloc(size_t cap); +void tableFree(struct Table *table); +void tablePush(struct Table *table, struct Slice slice); +struct Table tableInsert(const struct Table *prev, size_t at, struct Slice ins); +struct Table tableDelete(const struct Table *prev, struct Span del); +void tableUpdate(struct Table *table, struct Slice ins); struct Log { - size_t cap; - size_t len; - size_t idx; + size_t cap, len; + size_t state; struct State { struct Table table; - size_t prev; - size_t next; + size_t prev, next; } *states; }; - struct Log logAlloc(size_t cap); void logFree(struct Log *log); void logPush(struct Log *log, struct Table table); -static inline struct Table logTable(struct Log log) { - return log.states[log.idx].table; -} -static inline void logPrev(struct Log *log) { - log->idx = log->states[log->idx].prev; -} -static inline void logNext(struct Log *log) { - log->idx = log->states[log->idx].next; -} -static inline void logBack(struct Log *log) { - if (log->idx) log->idx--; -} -static inline void logFore(struct Log *log) { - if (log->idx + 1 < log->len) log->idx++; -} +struct File { + char *path; + struct Buffer buf; + struct Log log; + size_t clean; +}; +struct File fileAlloc(char *path); +void fileFree(struct File *file); +void fileRead(struct File *file); -- cgit 1.4.1