diff options
Diffstat (limited to 'examples/dte/buffer.h')
| -rw-r--r-- | examples/dte/buffer.h | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/examples/dte/buffer.h b/examples/dte/buffer.h new file mode 100644 index 0000000..4450a8f --- /dev/null +++ b/examples/dte/buffer.h | |||
| @@ -0,0 +1,103 @@ | |||
| 1 | #ifndef BUFFER_H | ||
| 2 | #define BUFFER_H | ||
| 3 | |||
| 4 | #include <limits.h> | ||
| 5 | #include <stdbool.h> | ||
| 6 | #include <stdint.h> | ||
| 7 | #include <sys/types.h> | ||
| 8 | #include <time.h> | ||
| 9 | #include "block-iter.h" | ||
| 10 | #include "change.h" | ||
| 11 | #include "encoding.h" | ||
| 12 | #include "options.h" | ||
| 13 | #include "syntax/syntax.h" | ||
| 14 | #include "util/list.h" | ||
| 15 | #include "util/macros.h" | ||
| 16 | #include "util/ptr-array.h" | ||
| 17 | #include "util/string-view.h" | ||
| 18 | #include "util/string.h" | ||
| 19 | |||
| 20 | // Subset of stat(3) struct | ||
| 21 | typedef struct { | ||
| 22 | dev_t dev; | ||
| 23 | ino_t ino; | ||
| 24 | mode_t mode; | ||
| 25 | uid_t uid; | ||
| 26 | gid_t gid; | ||
| 27 | off_t size; | ||
| 28 | struct timespec mtime; | ||
| 29 | } FileInfo; | ||
| 30 | |||
| 31 | // A representation of a specific file, as it pertains to editing, | ||
| 32 | // including text contents, filename (if saved), undo history and | ||
| 33 | // some file-specific metadata and options. | ||
| 34 | typedef struct Buffer { | ||
| 35 | ListHead blocks; | ||
| 36 | Change change_head; | ||
| 37 | Change *cur_change; | ||
| 38 | Change *saved_change; // Used to determine if buffer is modified | ||
| 39 | FileInfo file; | ||
| 40 | unsigned long id; // Needed for identifying buffers whose filename is NULL | ||
| 41 | size_t nl; | ||
| 42 | PointerArray views; // Views pointing to this buffer | ||
| 43 | char *display_filename; | ||
| 44 | char *abs_filename; | ||
| 45 | bool readonly; | ||
| 46 | bool temporary; | ||
| 47 | bool stdout_buffer; | ||
| 48 | bool locked; | ||
| 49 | bool setup; | ||
| 50 | bool crlf_newlines; | ||
| 51 | bool bom; | ||
| 52 | Encoding encoding; // Encoding of the file (buffer always contains UTF-8) | ||
| 53 | LocalOptions options; | ||
| 54 | Syntax *syn; | ||
| 55 | long changed_line_min; | ||
| 56 | long changed_line_max; | ||
| 57 | // Index 0 is always syn->states.ptrs[0]. | ||
| 58 | // Lowest bit of an invalidated value is 1. | ||
| 59 | PointerArray line_start_states; | ||
| 60 | } Buffer; | ||
| 61 | |||
| 62 | static inline void mark_all_lines_changed(Buffer *buffer) | ||
| 63 | { | ||
| 64 | buffer->changed_line_min = 0; | ||
| 65 | buffer->changed_line_max = LONG_MAX; | ||
| 66 | } | ||
| 67 | |||
| 68 | static inline bool buffer_modified(const Buffer *buffer) | ||
| 69 | { | ||
| 70 | return buffer->saved_change != buffer->cur_change && !buffer->temporary; | ||
| 71 | } | ||
| 72 | |||
| 73 | static inline BlockIter block_iter(Buffer *buffer) | ||
| 74 | { | ||
| 75 | return (BlockIter) { | ||
| 76 | .blk = BLOCK(buffer->blocks.next), | ||
| 77 | .head = &buffer->blocks, | ||
| 78 | .offset = 0 | ||
| 79 | }; | ||
| 80 | } | ||
| 81 | |||
| 82 | struct EditorState; | ||
| 83 | |||
| 84 | void buffer_mark_lines_changed(Buffer *buffer, long min, long max) NONNULL_ARGS; | ||
| 85 | void buffer_set_encoding(Buffer *buffer, Encoding encoding, bool utf8_bom) NONNULL_ARGS; | ||
| 86 | const char *buffer_filename(const Buffer *buffer) NONNULL_ARGS_AND_RETURN; | ||
| 87 | void set_display_filename(Buffer *buffer, char *name) NONNULL_ARG(1); | ||
| 88 | void update_short_filename_cwd(Buffer *buffer, const StringView *home, const char *cwd) NONNULL_ARG(1, 2); | ||
| 89 | void update_short_filename(Buffer *buffer, const StringView *home) NONNULL_ARGS; | ||
| 90 | Buffer *find_buffer(const PointerArray *buffers, const char *abs_filename) NONNULL_ARGS; | ||
| 91 | Buffer *find_buffer_by_id(const PointerArray *buffers, unsigned long id) NONNULL_ARGS; | ||
| 92 | Buffer *buffer_new(PointerArray *buffers, const GlobalOptions *gopts, const Encoding *encoding) RETURNS_NONNULL NONNULL_ARG(1, 2); | ||
| 93 | Buffer *open_empty_buffer(PointerArray *buffers, const GlobalOptions *gopts) NONNULL_ARGS_AND_RETURN; | ||
| 94 | void free_buffer(Buffer *buffer) NONNULL_ARGS; | ||
| 95 | void remove_and_free_buffer(PointerArray *buffers, Buffer *buffer) NONNULL_ARGS; | ||
| 96 | void free_blocks(Buffer *buffer) NONNULL_ARGS; | ||
| 97 | bool buffer_detect_filetype(Buffer *buffer, const PointerArray *filetypes) NONNULL_ARGS; | ||
| 98 | void buffer_update_syntax(struct EditorState *e, Buffer *buffer) NONNULL_ARGS; | ||
| 99 | void buffer_setup(struct EditorState *e, Buffer *buffer) NONNULL_ARGS; | ||
| 100 | void buffer_count_blocks_and_bytes(const Buffer *buffer, uintmax_t counts[2]) NONNULL_ARGS; | ||
| 101 | String dump_buffer(const Buffer *buffer) NONNULL_ARGS; | ||
| 102 | |||
| 103 | #endif | ||
