CNDP  22.08.0
cli_gapbuf.h File Reference
#include <stdlib.h>
#include <string.h>
#include <cne_log.h>
#include <stdint.h>
#include "cne_common.h"

Go to the source code of this file.

Functions

CNDP_API struct gapbuf * gb_create (void)
 
CNDP_API void gb_destroy (struct gapbuf *gb)
 
CNDP_API int gb_init_buf (struct gapbuf *gb, int size)
 
CNDP_API int gb_reset_buf (struct gapbuf *gb)
 
CNDP_API uint32_t gb_copy_to_buf (struct gapbuf *gb, char *dst, uint32_t size)
 
CNDP_API void gb_dump (struct gapbuf *gb, const char *msg)
 
static uint32_t gb_buf_size (struct gapbuf *gb)
 
static uint32_t gb_gap_size (struct gapbuf *gb)
 
static uint32_t gb_data_size (struct gapbuf *gb)
 
static char * gb_start_of_buf (struct gapbuf *gb)
 
static char * gb_start_of_gap (struct gapbuf *gb)
 
static char * gb_end_of_gap (struct gapbuf *gb)
 
static char * gb_end_of_buf (struct gapbuf *gb)
 
static char * gb_point_at (struct gapbuf *gb)
 
static int gb_point_at_start (struct gapbuf *gb)
 
static int gb_point_at_end (struct gapbuf *gb)
 
static int gb_point_at_gap (struct gapbuf *gb)
 
static void gb_set_point (struct gapbuf *gb, int idx)
 
static int gb_point_offset (struct gapbuf *gb)
 
static int gb_eof (struct gapbuf *gb)
 
static void gb_move_gap_to_point (struct gapbuf *gb)
 
static void gb_expand_buf (struct gapbuf *gb, uint32_t more)
 
static void gb_expand_gap (struct gapbuf *gb, uint32_t size)
 
static char gb_get (struct gapbuf *gb)
 
static char gb_get_prev (struct gapbuf *gb)
 
static char gb_get_next (struct gapbuf *gb)
 
static void gb_put (struct gapbuf *gb, char c)
 
static char gb_getc (struct gapbuf *gb)
 
static char gb_getc_prev (struct gapbuf *gb)
 
static void gb_putc (struct gapbuf *gb, char c)
 
static void gb_insert (struct gapbuf *gb, char c)
 
static void gb_del (struct gapbuf *gb, int cnt)
 
static uint32_t gb_str_insert (struct gapbuf *gb, char *str, uint32_t size)
 
static uint32_t gb_left_data_size (struct gapbuf *gb)
 
static uint32_t gb_right_data_size (struct gapbuf *gb)
 
static void gb_move_right (struct gapbuf *gb)
 
static void gb_move_left (struct gapbuf *gb)
 

Detailed Description

CLI Gap Buffer support

Definition in file cli_gapbuf.h.

Function Documentation

◆ gb_create()

CNDP_API struct gapbuf* gb_create ( void  )

Create the Gap Buffer structure

Returns
NULL on error or pointer to struct gapbuf

◆ gb_destroy()

CNDP_API void gb_destroy ( struct gapbuf *  gb)

Destroy

Parameters
gbThe gapbuf structure pointer.
Returns
N/A

◆ gb_init_buf()

CNDP_API int gb_init_buf ( struct gapbuf *  gb,
int  size 
)

Allocate buffer and initialize, if buffer exist free and reallocate.

Parameters
gbThe gapbuf structure pointer.
sizeInit the gap buffer to the size given
Returns
0 is OK or Error

◆ gb_reset_buf()

CNDP_API int gb_reset_buf ( struct gapbuf *  gb)

Reset the gap buffer

Parameters
gbThe gapbuf structure pointer.
Returns
0 is OK or Error

◆ gb_copy_to_buf()

CNDP_API uint32_t gb_copy_to_buf ( struct gapbuf *  gb,
char *  dst,
uint32_t  size 
)

Copy the buffer data into a given buffer

Parameters
gbThe gapbuf structure pointer.
dstLocation to copy the data into
sizeTotal number of bytes to copy
Returns
Number of bytes copied into the buffer

◆ gb_dump()

CNDP_API void gb_dump ( struct gapbuf *  gb,
const char *  msg 
)

Print out a debug list of the Gap buffer and pointers

Parameters
gbThe gapbuf structure pointer.
msgMessage to print out before dump of buffer data
Returns
N/A

◆ gb_buf_size()

static uint32_t gb_buf_size ( struct gapbuf *  gb)
inlinestatic

Return the number of bytes total in the buffer includes gap size

Parameters
gbThe gapbuf structure pointer.
Returns
The number of bytes in the buffer

Definition at line 113 of file cli_gapbuf.h.

◆ gb_gap_size()

static uint32_t gb_gap_size ( struct gapbuf *  gb)
inlinestatic

Return the gap size in bytes

Parameters
gbThe gapbuf structure pointer.
Returns
Number of bytes in the gap.

Definition at line 127 of file cli_gapbuf.h.

◆ gb_data_size()

static uint32_t gb_data_size ( struct gapbuf *  gb)
inlinestatic

Number of data bytes

Parameters
gbThe gapbuf structure pointer.
Returns
Number of data bytes

Definition at line 141 of file cli_gapbuf.h.

◆ gb_start_of_buf()

static char* gb_start_of_buf ( struct gapbuf *  gb)
inlinestatic

Return the start of the buffer address

Parameters
gbThe gapbuf structure pointer.
Returns
The pointer to the start of the buffer

Definition at line 155 of file cli_gapbuf.h.

◆ gb_start_of_gap()

static char* gb_start_of_gap ( struct gapbuf *  gb)
inlinestatic

Return the pointer to the gap start

Parameters
gbThe gapbuf structure pointer.
Returns
Pointer to the gap start location

Definition at line 169 of file cli_gapbuf.h.

◆ gb_end_of_gap()

static char* gb_end_of_gap ( struct gapbuf *  gb)
inlinestatic

Return the pointer to the end of the gap

Parameters
gbThe gapbuf structure pointer.
Returns
The end of the gap pointer

Definition at line 183 of file cli_gapbuf.h.

◆ gb_end_of_buf()

static char* gb_end_of_buf ( struct gapbuf *  gb)
inlinestatic

Return the pointer to the end of the buffer

Parameters
gbThe gapbuf structure pointer.
Returns
End of buffer pointer

Definition at line 197 of file cli_gapbuf.h.

◆ gb_point_at()

static char* gb_point_at ( struct gapbuf *  gb)
inlinestatic

Return the point location

Parameters
gbThe gapbuf structure pointer.
Returns
Pointer to point

Definition at line 211 of file cli_gapbuf.h.

◆ gb_point_at_start()

static int gb_point_at_start ( struct gapbuf *  gb)
inlinestatic

Is point at start of buffer

Parameters
gbThe gapbuf structure pointer.
Returns
true if point is at start of buffer

Definition at line 225 of file cli_gapbuf.h.

◆ gb_point_at_end()

static int gb_point_at_end ( struct gapbuf *  gb)
inlinestatic

is point at the end of buffer

Parameters
gbThe gapbuf structure pointer.
Returns
true if the point is at the end of buffer

Definition at line 239 of file cli_gapbuf.h.

◆ gb_point_at_gap()

static int gb_point_at_gap ( struct gapbuf *  gb)
inlinestatic

is point at start of gap

Parameters
gbThe gapbuf structure pointer.
Returns
true if the point is at the gap start

Definition at line 253 of file cli_gapbuf.h.

◆ gb_set_point()

static void gb_set_point ( struct gapbuf *  gb,
int  idx 
)
inlinestatic

Set point to a givewn index into the buffer

Parameters
gbThe gapbuf structure pointer.
idxIndex into the buffer to put point
Returns
N/A

Definition at line 269 of file cli_gapbuf.h.

◆ gb_point_offset()

static int gb_point_offset ( struct gapbuf *  gb)
inlinestatic

Get offset of point

Parameters
gbThe gapbuf structure pointer.
Returns
Offset of point from start of buffer

Definition at line 289 of file cli_gapbuf.h.

◆ gb_eof()

static int gb_eof ( struct gapbuf *  gb)
inlinestatic

Return true if point is at end of buffer data.

Parameters
gbThe gapbuf structure pointer.
Returns
True if end of buffer data

Definition at line 306 of file cli_gapbuf.h.

◆ gb_move_gap_to_point()

static void gb_move_gap_to_point ( struct gapbuf *  gb)
inlinestatic

Move the gap to the location of the point.

Parameters
gbThe gapbuf structure pointer.
Returns
N/A

Definition at line 322 of file cli_gapbuf.h.

◆ gb_expand_buf()

static void gb_expand_buf ( struct gapbuf *  gb,
uint32_t  more 
)
inlinestatic

Expand the buffer by the given bytes.

Parameters
gbThe gapbuf structure pointer.
moreThe number of bytes to increase the buffer
Returns
N/A

Definition at line 364 of file cli_gapbuf.h.

◆ gb_expand_gap()

static void gb_expand_gap ( struct gapbuf *  gb,
uint32_t  size 
)
inlinestatic

Expand the Gap by the size given.

Parameters
gbThe gapbuf structure pointer.
sizeIncrease the gap by the number of bytes given
Returns
N/A

Definition at line 393 of file cli_gapbuf.h.

◆ gb_get()

static char gb_get ( struct gapbuf *  gb)
inlinestatic

Get the byte at the point location.

Parameters
gbThe gapbuf structure pointer.
Returns
Byte at point

Definition at line 416 of file cli_gapbuf.h.

◆ gb_get_prev()

static char gb_get_prev ( struct gapbuf *  gb)
inlinestatic

Get the byte at the point - 1 location.

Parameters
gbThe gapbuf structure pointer.
Returns
Byte at point

Definition at line 433 of file cli_gapbuf.h.

◆ gb_get_next()

static char gb_get_next ( struct gapbuf *  gb)
inlinestatic

Get the byte at the point + 1 location.

Parameters
gbThe gapbuf structure pointer.
Returns
Byte at point

Definition at line 457 of file cli_gapbuf.h.

◆ gb_put()

static void gb_put ( struct gapbuf *  gb,
char  c 
)
inlinestatic

Put character at point

Parameters
gbThe gapbuf structure pointer.
cThe character to put at point
Returns
N/A

Definition at line 479 of file cli_gapbuf.h.

◆ gb_getc()

static char gb_getc ( struct gapbuf *  gb)
inlinestatic

Get the byte at the point location and advance point

Parameters
gbThe gapbuf structure pointer.
Returns
Byte at point

Definition at line 501 of file cli_gapbuf.h.

◆ gb_getc_prev()

static char gb_getc_prev ( struct gapbuf *  gb)
inlinestatic

Move point left and return character at point.

fmrgetc() (point == ehole ? *(point = hole - 1) : *(–point))

Parameters
gbThe gapbuf structure pointer.
Returns
Character at point

Definition at line 522 of file cli_gapbuf.h.

◆ gb_putc()

static void gb_putc ( struct gapbuf *  gb,
char  c 
)
inlinestatic

Put character at point and advance point

Parameters
gbThe gapbuf structure pointer.
cThe character to put at point
Returns
N/A

Definition at line 541 of file cli_gapbuf.h.

◆ gb_insert()

static void gb_insert ( struct gapbuf *  gb,
char  c 
)
inlinestatic

Insert the character at point and move point.

Parameters
gbThe gapbuf structure pointer.
cThe character to add to buffer
Returns
N/A

Definition at line 564 of file cli_gapbuf.h.

◆ gb_del()

static void gb_del ( struct gapbuf *  gb,
int  cnt 
)
inlinestatic

Delete the character(s) at point

Parameters
gbThe gapbuf structure pointer.
cntNumber of characters to delete at point.
Returns
N/A

Definition at line 586 of file cli_gapbuf.h.

◆ gb_str_insert()

static uint32_t gb_str_insert ( struct gapbuf *  gb,
char *  str,
uint32_t  size 
)
inlinestatic

Insert a string at point and move point

Parameters
gbThe gapbuf structure pointer.
strString to put at point
sizeSize of the string to insert at point, if zero use strlen() to find length
Returns
Number of bytes inserted

Definition at line 607 of file cli_gapbuf.h.

◆ gb_left_data_size()

static uint32_t gb_left_data_size ( struct gapbuf *  gb)
inlinestatic

Left size of the data in the gap buffer

Parameters
gbThe gapbuf structure pointer.
Returns
Number of bytes in the left size of gap buffer

Definition at line 640 of file cli_gapbuf.h.

◆ gb_right_data_size()

static uint32_t gb_right_data_size ( struct gapbuf *  gb)
inlinestatic

Right size of the data in the gap buffer

Parameters
gbThe gapbuf structure pointer.
Returns
Number of bytes in the right size of gap buffer

Definition at line 654 of file cli_gapbuf.h.

◆ gb_move_right()

static void gb_move_right ( struct gapbuf *  gb)
inlinestatic

Move point right one byte

Parameters
gbThe gapbuf structure pointer.
Returns
N/A

Definition at line 670 of file cli_gapbuf.h.

◆ gb_move_left()

static void gb_move_left ( struct gapbuf *  gb)
inlinestatic

Move point left one byte

Parameters
gbThe gapbuf structure pointer.
Returns
N/A

Definition at line 686 of file cli_gapbuf.h.