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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
/** \file
* \brief Header: text keep buffer for WEdit
*/
#ifndef MC__EDIT_BUFFER_H
#define MC__EDIT_BUFFER_H
/*** typedefs(not structures) and defined constants **********************************************/
/*** enums ***************************************************************************************/
/*** structures declarations (and typedefs of structures)*****************************************/
typedef struct edit_buffer_struct
{
off_t curs1; /* position of the cursor from the beginning of the file. */
off_t curs2; /* position from the end of the file */
GPtrArray *b1; /* all data up to curs1 */
GPtrArray *b2; /* all data from end of file down to curs2 */
off_t size; /* file size */
long lines; /* total lines in the file */
long curs_line; /* line number of the cursor. */
} edit_buffer_t;
typedef struct edit_buffer_read_file_status_msg_struct
{
simple_status_msg_t status_msg; /* base class */
gboolean first;
edit_buffer_t *buf;
off_t loaded;
} edit_buffer_read_file_status_msg_t;
/*** global variables defined in .c file *********************************************************/
/*** declarations of public functions ************************************************************/
void edit_buffer_init (edit_buffer_t * buf, off_t size);
void edit_buffer_clean (edit_buffer_t * buf);
int edit_buffer_get_byte (const edit_buffer_t * buf, off_t byte_index);
#ifdef HAVE_CHARSET
int edit_buffer_get_utf (const edit_buffer_t * buf, off_t byte_index, int *char_length);
int edit_buffer_get_prev_utf (const edit_buffer_t * buf, off_t byte_index, int *char_length);
#endif
long edit_buffer_count_lines (const edit_buffer_t * buf, off_t first, off_t last);
off_t edit_buffer_get_bol (const edit_buffer_t * buf, off_t current);
off_t edit_buffer_get_eol (const edit_buffer_t * buf, off_t current);
GString *edit_buffer_get_word_from_pos (const edit_buffer_t * buf, off_t start_pos, off_t * start,
gsize * cut);
gboolean edit_buffer_find_word_start (const edit_buffer_t * buf, off_t * word_start,
gsize * word_len);
void edit_buffer_insert (edit_buffer_t * buf, int c);
void edit_buffer_insert_ahead (edit_buffer_t * buf, int c);
int edit_buffer_delete (edit_buffer_t * buf);
int edit_buffer_backspace (edit_buffer_t * buf);
off_t edit_buffer_get_forward_offset (const edit_buffer_t * buf, off_t current, long lines,
off_t upto);
off_t edit_buffer_get_backward_offset (const edit_buffer_t * buf, off_t current, long lines);
off_t edit_buffer_read_file (edit_buffer_t * buf, int fd, off_t size,
edit_buffer_read_file_status_msg_t * sm, gboolean * aborted);
off_t edit_buffer_write_file (edit_buffer_t * buf, int fd);
int edit_buffer_calc_percent (const edit_buffer_t * buf, off_t offset);
/*** inline functions ****************************************************************************/
static inline int
edit_buffer_get_current_byte (const edit_buffer_t * buf)
{
return edit_buffer_get_byte (buf, buf->curs1);
}
/* --------------------------------------------------------------------------------------------- */
static inline int
edit_buffer_get_previous_byte (const edit_buffer_t * buf)
{
return edit_buffer_get_byte (buf, buf->curs1 - 1);
}
/* --------------------------------------------------------------------------------------------- */
/**
* Get "begin-of-line" offset of current line
*
* @param buf editor buffer
*
* @return index of first char of current line
*/
static inline off_t
edit_buffer_get_current_bol (const edit_buffer_t * buf)
{
return edit_buffer_get_bol (buf, buf->curs1);
}
/* --------------------------------------------------------------------------------------------- */
/**
* Get "end-of-line" offset of current line
*
* @param buf editor buffer
*
* @return index of first char of current line + 1
*/
static inline off_t
edit_buffer_get_current_eol (const edit_buffer_t * buf)
{
return edit_buffer_get_eol (buf, buf->curs1);
}
/* --------------------------------------------------------------------------------------------- */
#endif /* MC__EDIT_BUFFER_H */
|