FDOSTUI
FreeDOS Text User Interface
Classes | Functions
gapbuf.h File Reference

A dynamic text buffer implementing the gap buffer algorithm. More...

Go to the source code of this file.

Classes

struct  gapbuf
 

Functions

void gapbuf_assign (struct gapbuf *const o_gap)
 initialize gapbuf object More...
 
void gapbuf_discharge (struct gapbuf *const io_gap)
 release resources held by object More...
 
int gapbuf_backspace (struct gapbuf *const io_gap, size_t const i_offset)
 perform a backspace operation More...
 
int gapbuf_insert (struct gapbuf *const io_gap, size_t const i_offset, unsigned char const i_char)
 insert a character More...
 
int gapbuf_delete (struct gapbuf *const io_gap, size_t const i_offset)
 delete a character More...
 
unsigned char __FAR * gapbuf_char_next (size_t *io_offset, struct gapbuf const *const i_gap)
 move to next character More...
 
unsigned char __FAR * gapbuf_char_prev (size_t *io_offset, struct gapbuf const *const i_gap)
 move to previous character More...
 
unsigned char __FAR * gapbuf_line_next (size_t *io_offset, struct gapbuf const *const i_gap)
 move to next line More...
 
unsigned char __FAR * gapbuf_line_prev (size_t *io_offset, struct gapbuf const *const i_gap)
 move to previous line More...
 
int gapbuf_overwrite (struct gapbuf *const io_gap, size_t const i_offset, unsigned char const i_char)
 overwrite character More...
 
unsigned char const __FAR * gapbuf_text (struct gapbuf *const io_gap)
 get the text buffer More...
 
unsigned char __FAR * gapbuf_ptr (struct gapbuf const *const i_gap, size_t const i_offset)
 get the text buffer More...
 

Detailed Description

A dynamic text buffer implementing the gap buffer algorithm.

A cursor (point) is not provided, it must be maintained externally. Routines taking a cursor expect it to be within normal boundaries of the buffer.

See also
edit

Function Documentation

◆ gapbuf_assign()

void gapbuf_assign ( struct gapbuf *const  o_gap)

initialize gapbuf object

Parameters
[out]o_gapgapbuf object
Returns
none

Memory is not allocated to the gap buffer until a character is inserted.

◆ gapbuf_backspace()

int gapbuf_backspace ( struct gapbuf *const  io_gap,
size_t const  i_offset 
)

perform a backspace operation

Parameters
[in,out]io_gapgap buffer object
[in]i_offsetcursor location to perform backspace
Returns
0 operation could not be performed
!0 operation performed

◆ gapbuf_char_next()

unsigned char __FAR * gapbuf_char_next ( size_t *  io_offset,
struct gapbuf const *const  i_gap 
)

move to next character

Parameters
[in,out]io_offsetcursor to advance
[in]i_gapgap buffer object
Returns
0 end of file
!0 pointer to next character in the buffer

◆ gapbuf_char_prev()

unsigned char __FAR * gapbuf_char_prev ( size_t *  io_offset,
struct gapbuf const *const  i_gap 
)

move to previous character

Parameters
[in,out]io_offsetcursor to decrement
[in]i_gapgap buffer object
Returns
0 beginning of file
!0 previous character

◆ gapbuf_delete()

int gapbuf_delete ( struct gapbuf *const  io_gap,
size_t const  i_offset 
)

delete a character

Parameters
[in,out]io_gapgap buffer oject
[in]i_offsetcursor location to perform delete
Returns
0 operation could not be performed
!0 operation performed

◆ gapbuf_discharge()

void gapbuf_discharge ( struct gapbuf *const  io_gap)

release resources held by object

Parameters
[in,out]io_gapobject to release
Returns
none

◆ gapbuf_insert()

int gapbuf_insert ( struct gapbuf *const  io_gap,
size_t const  i_offset,
unsigned char const  i_char 
)

insert a character

Parameters
[in,out]io_gapgap buffer oject
[in]i_offsetcursor location to perform insert
[in]i_charcharacter to insert
Returns
0 operation could not be performed
!0 operation performed

◆ gapbuf_line_next()

unsigned char __FAR * gapbuf_line_next ( size_t *  io_offset,
struct gapbuf const *const  i_gap 
)

move to next line

Parameters
[in,out]io_offsetcursor to advance
[in]i_gapgap buffer object
Returns
0 end of file
!0 beginning of next line

◆ gapbuf_line_prev()

unsigned char __FAR * gapbuf_line_prev ( size_t *  io_offset,
struct gapbuf const *const  i_gap 
)

move to previous line

Parameters
[in,out]io_offsetcursor to decrement
[in]i_gapgap buffer object
Returns
0 beginning of file
!0 beginning of previous line

◆ gapbuf_overwrite()

int gapbuf_overwrite ( struct gapbuf *const  io_gap,
size_t const  i_offset,
unsigned char const  i_char 
)

overwrite character

Parameters
[in,out]io_gapgap buffer object
[in]i_offsetcursor location to preform overwrite
[in]i_charcharacter to overwrite
Returns
0 operation could not be performed
!0 character overwritten

◆ gapbuf_ptr()

unsigned char __FAR * gapbuf_ptr ( struct gapbuf const *const  i_gap,
size_t const  i_offset 
)

get the text buffer

Parameters
[in]i_gapgap buffer object
[in]i_offsetcursor location
Returns
0 buffer empty or invalid cursor location
!0 pointer to buffer

The routine does not move the gap. The returned address points to either before the start of the gap or after the end of the gap.

◆ gapbuf_text()

unsigned char const __FAR * gapbuf_text ( struct gapbuf *const  io_gap)

get the text buffer

Parameters
[in,out]io_gapgap buffer object
Returns
0 buffer empty
!0 pointer to buffer

The routine will move the gap so the buffer can be accessed sequentially.

Buffer contents should not be modified.

The returned address is only valid until the next operation that affects the gap.