2 * \brief Header: text keep buffer for WEdit
5 #ifndef MC__EDIT_BUFFER_H
6 #define MC__EDIT_BUFFER_H
8 /*** typedefs(not structures) and defined constants **********************************************/
11 * The editor keeps data in two arrays of buffers.
12 * All buffers have the same size, which must be a power of 2.
15 /* Configurable: log2 of the buffer size in bytes */
16 #ifndef S_EDIT_BUF_SIZE
17 #define S_EDIT_BUF_SIZE 16
20 /* Size of the buffer */
21 #define EDIT_BUF_SIZE (((off_t) 1) << S_EDIT_BUF_SIZE)
23 /* Buffer mask (used to find cursor position relative to the buffer) */
24 #define M_EDIT_BUF_SIZE (EDIT_BUF_SIZE - 1)
27 * Configurable: Maximal allowed number of buffers in each buffer array.
28 * This number can be increased for systems with enough physical memory.
34 /* Maximal length of file that can be opened */
35 #define SIZE_LIMIT (EDIT_BUF_SIZE * (MAXBUFF - 2))
37 /*** enums ***************************************************************************************/
39 /*** structures declarations (and typedefs of structures)*****************************************/
41 typedef struct edit_buffer_struct
{
42 off_t curs1
; /* position of the cursor from the beginning of the file. */
43 off_t curs2
; /* position from the end of the file */
44 GPtrArray
*b1
; /* all data up to curs1 */
45 GPtrArray
*b2
; /* all data from end of file down to curs2 */
48 /*** global variables defined in .c file *********************************************************/
50 /*** declarations of public functions ************************************************************/
52 void edit_buffer_init (edit_buffer_t
* buf
);
53 void edit_buffer_clean (edit_buffer_t
* buf
);
55 int edit_buffer_get_byte (const edit_buffer_t
* buf
, off_t byte_index
);
57 int edit_buffer_get_utf (const edit_buffer_t
* buf
, off_t byte_index
, int *char_width
);
58 int edit_buffer_get_prev_utf (const edit_buffer_t
* buf
, off_t byte_index
, int *char_width
);
61 void edit_buffer_insert (edit_buffer_t
* buf
, int c
);
62 void edit_buffer_insert_ahead (edit_buffer_t
* buf
, int c
);
63 int edit_buffer_delete (edit_buffer_t
* buf
);
64 int edit_buffer_backspace (edit_buffer_t
* buf
);
66 off_t
edit_buffer_read_file (edit_buffer_t
* buf
, int fd
, off_t size
);
67 off_t
edit_buffer_write_file (edit_buffer_t
* buf
, int fd
);
69 /*** inline functions ****************************************************************************/
72 edit_buffer_get_current_byte (const edit_buffer_t
* buf
)
74 return edit_buffer_get_byte (buf
, buf
->curs1
);
77 /* --------------------------------------------------------------------------------------------- */
80 edit_buffer_get_previous_byte (const edit_buffer_t
* buf
)
82 return edit_buffer_get_byte (buf
, buf
->curs1
- 1);
85 /* --------------------------------------------------------------------------------------------- */
87 #endif /* MC__EDIT_BUFFER_H */