13 #ifndef _CLI_GAPBUF_H_
14 #define _CLI_GAPBUF_H_
26 #define GB_DEFAULT_GAP_SIZE 8
88 CNDP_API uint32_t
gb_copy_to_buf(
struct gapbuf *gb,
char *dst, uint32_t size);
100 CNDP_API
void gb_dump(
struct gapbuf *gb,
const char *msg);
112 static inline uint32_t
115 return gb->ebuf - gb->buf;
126 static inline uint32_t
129 return gb->egap - gb->gap;
140 static inline uint32_t
143 return (gb->ebuf - gb->buf) - (gb->egap - gb->gap);
227 return (gb->point == gb->buf);
241 return (gb->ebuf == gb->point);
255 return (gb->gap == gb->point);
272 gb->point = gb->ebuf;
275 gb->point = gb->buf + idx;
276 if (gb->point > gb->gap)
277 gb->point += gb->egap - gb->gap;
291 if (gb->point > gb->egap)
292 return (gb->point - gb->buf) - (gb->egap - gb->gap);
294 return gb->point - gb->buf;
308 return (gb->point == gb->gap) ? (gb->egap == gb->ebuf) : (gb->point == gb->ebuf);
324 if (gb->point == gb->gap)
327 if (gb->point == gb->egap)
332 if (gb->point < gb->gap) {
333 cnt = gb->gap - gb->point;
334 memmove(gb->egap - cnt, gb->point, cnt);
337 }
else if (gb->point > gb->egap) {
338 cnt = gb->point - gb->egap;
339 memmove(gb->gap, gb->egap, cnt);
341 gb->egap = gb->point;
344 cnt = gb->point - gb->gap;
345 memmove(gb->gap, gb->egap, cnt);
366 if (((gb->ebuf - gb->buf) + more) >
gb_buf_size(gb)) {
369 more = (gb->ebuf - gb->buf) + more + GB_DEFAULT_GAP_SIZE;
371 gb->buf = (
char *)realloc(gb->buf, more);
373 cne_panic(
"realloc(%d) in %s failed", more, __func__);
375 gb->point += (gb->buf - old);
376 gb->ebuf += (gb->buf - old);
377 gb->gap += (gb->buf - old);
378 gb->egap += (gb->buf - old);
396 size += GB_DEFAULT_GAP_SIZE;
400 memmove(gb->egap + size, gb->egap, gb->ebuf - gb->egap);
418 if (gb->point == gb->gap)
419 gb->point = gb->egap;
435 if (gb->point == gb->egap)
438 if (gb->point == gb->buf) {
439 if (gb->point == gb->gap)
445 return *(gb->point - 1);
459 if (gb->point == gb->gap)
460 gb->point = gb->egap;
462 if (gb->point == gb->ebuf)
465 return *(gb->point + 1);
481 if (gb->point == gb->gap)
482 gb->point = gb->egap;
484 if (gb->point == gb->ebuf) {
503 if (gb->point == gb->gap) {
504 gb->point = gb->egap + 1;
508 return *(gb->point++);
524 if (gb->point == gb->egap)
527 return *(--gb->point);
545 if (gb->point == gb->ebuf) {
566 if (gb->point != gb->gap)
569 if (gb->gap == gb->egap)
588 if (gb->point != gb->gap)
606 static inline uint32_t
639 static inline uint32_t
642 return gb->gap - gb->buf;
653 static inline uint32_t
658 return gb->ebuf - gb->egap;
672 if (gb->point == gb->gap)
673 gb->point = gb->egap;
674 gb->point = ((gb->point + 1) > gb->ebuf) ? gb->ebuf : (gb->point + 1);
688 if (gb->point == gb->egap)
690 gb->point = ((gb->point - 1) < gb->buf) ? gb->buf : (gb->point - 1);
static void gb_move_gap_to_point(struct gapbuf *gb)
static char gb_get_prev(struct gapbuf *gb)
CNDP_API uint32_t gb_copy_to_buf(struct gapbuf *gb, char *dst, uint32_t size)
static void gb_set_point(struct gapbuf *gb, int idx)
static void gb_move_left(struct gapbuf *gb)
static void gb_put(struct gapbuf *gb, char c)
static char gb_getc_prev(struct gapbuf *gb)
CNDP_API void gb_dump(struct gapbuf *gb, const char *msg)
static int gb_point_offset(struct gapbuf *gb)
static int gb_point_at_end(struct gapbuf *gb)
static int gb_point_at_start(struct gapbuf *gb)
CNDP_API struct gapbuf * gb_create(void)
static char * gb_start_of_buf(struct gapbuf *gb)
static void gb_putc(struct gapbuf *gb, char c)
static void gb_del(struct gapbuf *gb, int cnt)
static char * gb_end_of_gap(struct gapbuf *gb)
static void gb_insert(struct gapbuf *gb, char c)
static uint32_t gb_str_insert(struct gapbuf *gb, char *str, uint32_t size)
static char * gb_point_at(struct gapbuf *gb)
static char gb_get(struct gapbuf *gb)
CNDP_API int gb_reset_buf(struct gapbuf *gb)
static void gb_expand_gap(struct gapbuf *gb, uint32_t size)
static void gb_expand_buf(struct gapbuf *gb, uint32_t more)
static int gb_eof(struct gapbuf *gb)
static uint32_t gb_left_data_size(struct gapbuf *gb)
static void gb_move_right(struct gapbuf *gb)
static int gb_point_at_gap(struct gapbuf *gb)
static char gb_get_next(struct gapbuf *gb)
static uint32_t gb_right_data_size(struct gapbuf *gb)
CNDP_API int gb_init_buf(struct gapbuf *gb, int size)
static char * gb_end_of_buf(struct gapbuf *gb)
static uint32_t gb_data_size(struct gapbuf *gb)
static char gb_getc(struct gapbuf *gb)
static char * gb_start_of_gap(struct gapbuf *gb)
CNDP_API void gb_destroy(struct gapbuf *gb)
static uint32_t gb_buf_size(struct gapbuf *gb)
static uint32_t gb_gap_size(struct gapbuf *gb)
#define cne_panic(format, args...)