-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodel.h
More file actions
62 lines (54 loc) · 1.98 KB
/
model.h
File metadata and controls
62 lines (54 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#ifndef BUFFER_H
#define BUFFER_H
#include <stddef.h>
#include <sched.h>
#define INITIAL_LINES_CAPACITY 10
// Gap buffer for efficient text editing
typedef struct {
char* buffer;
int buffer_size;
int gap_start;
int gap_end;
int text_len;
} GapBuffer;
// Cache for nesting levels (syntax highlighting state per line)
typedef struct {
int valid; // Is this cache entry valid?
int brace_level;
int brace_top;
int brace_stack[256];
int kw_level;
int kw_top;
int kw_stack[100];
} NestingCache;
typedef struct {
GapBuffer** lines;
int num_lines;
int capacity;
NestingCache* nesting_cache; // Cache of nesting levels per line
} Buffer;
// GapBuffer operations
GapBuffer* gap_buffer_create();
void gap_buffer_free(GapBuffer* gb);
void gap_buffer_insert(GapBuffer* gb, int pos, char c);
void gap_buffer_delete(GapBuffer* gb, int pos);
char gap_buffer_get_char(const GapBuffer* gb, int pos);
const char* gap_buffer_get_text(const GapBuffer* gb);
int gap_buffer_length(const GapBuffer* gb);
void gap_buffer_move_gap(GapBuffer* gb, int pos);
void buffer_init(Buffer* buf);
void buffer_free(Buffer* buf);
int buffer_load_from_file(Buffer* buf, const char* filename);
int buffer_save_to_file(const Buffer* buf, const char* filename);
char* buffer_get_line(const Buffer* buf, int line); // caller must free
int buffer_get_line_length(const Buffer* buf, int line);
int buffer_num_lines(const Buffer* buf);
char buffer_get_char(const Buffer* buf, int line, int col);
int buffer_insert_line(Buffer* buf, int line, const char* content);
int buffer_delete_line(Buffer* buf, int line);
int buffer_insert_char(Buffer* buf, int line, int col, char c);
int buffer_delete_char(Buffer* buf, int line, int col);
int buffer_delete_range(Buffer* buf, int start_line, int start_col, int end_line, int end_col);
int buffer_insert_text(Buffer* buf, int line, int col, const char* text);
void buffer_replace_all(Buffer* buf, const char* search_regex, const char* replace_str);
#endif