-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgap_buffer.h
61 lines (55 loc) · 2.24 KB
/
gap_buffer.h
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
/*
* Copyright (C) 2015 Richard Burke
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef WED_GAP_BUFFER_H
#define WED_GAP_BUFFER_H
#include <stddef.h>
#ifndef GAP_INCREMENT
#define GAP_INCREMENT 1024
#endif
/* GapBuffer is the data structure used to
* store text in wed */
typedef struct {
char *text; /* Memory allocated to hold text */
size_t point; /* Position in buffer */
size_t gap_start; /* Position gap starts */
size_t gap_end; /* Position gap ends */
size_t allocated; /* Bytes allocated */
size_t lines; /* Number of new line (\n) characters */
} GapBuffer;
GapBuffer *gb_new(size_t size);
void gb_free(GapBuffer *);
size_t gb_length(const GapBuffer *);
size_t gb_lines(const GapBuffer *);
size_t gb_gap_size(const GapBuffer *);
int gb_preallocate(GapBuffer *, size_t size);
void gb_contiguous_storage(GapBuffer *);
int gb_insert(GapBuffer *, const char *str, size_t str_len);
int gb_add(GapBuffer *, const char *str, size_t str_len);
int gb_delete(GapBuffer *, size_t byte_num);
int gb_replace(GapBuffer *, size_t byte_num, const char *str, size_t str_len);
void gb_clear(GapBuffer *);
size_t gb_get_point(const GapBuffer *);
int gb_set_point(GapBuffer *, size_t point);
char gb_get(const GapBuffer *);
char gb_get_at(const GapBuffer *, size_t point);
unsigned char gb_getu_at(const GapBuffer *, size_t point);
size_t gb_get_range(const GapBuffer *, size_t point, char *buf,
size_t num_bytes);
int gb_find_next(const GapBuffer *, size_t point, size_t *next, char c);
int gb_find_prev(const GapBuffer *, size_t point, size_t *prev, char c);
#endif