All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Classes | Functions
Text Buffers

Classes

struct  txtbuf
 

Functions

void tb_init (struct txtbuf *tb, char *txt, size_t txt_sz)
 
size_t tb_len (struct txtbuf *tb)
 
size_t tb_free (struct txtbuf *tb)
 
bool tb_put (struct txtbuf *tb, void *buf, size_t buf_sz)
 
void tb_strtrim (struct txtbuf *tb)
 
bool tb_strput (struct txtbuf *tb, char *str)
 
int tb_strnum (struct txtbuf *tb)
 
bool tb_strget (struct txtbuf *tb, int index, char *dst, size_t dst_sz)
 
bool tb_strlast (struct txtbuf *tb, int index, char *dst, size_t dst_sz)
 

Detailed Description

Text buffers are simple fixed-size buffers that can hold variable lenght strings.

Text buffers are mainly used for the debug console and for the chat history.

Function Documentation

size_t tb_free ( struct txtbuf tb)
inline

Returns the number of free bytes in the textbuffer tb

Parameters
[in]tbA text buffer
Returns
This function returns the number of free bytes in the textbuffer tb
void tb_init ( struct txtbuf tb,
char *  txt,
size_t  txt_sz 
)

Initialize a text buffer structure

Parameters
[in]tbText buffer structure
[in]txtFixed-size buffer that will hold text buffer strings
[in]txt_szSize of the buffer
size_t tb_len ( struct txtbuf tb)
inline

Return number of bytes used by the textbuffer tb

Parameters
[in]tbA text buffer
Returns
This function returns the number of bytes used by the textbuffer tb
bool tb_put ( struct txtbuf tb,
void *  buf,
size_t  buf_sz 
)

Store the variable lenght buffer buf to the text buffer tb

Parameters
[in]tbA text buffer
[in]bufBuffer that will be copied to tb
[in]buf_szBuffer size
Returns
true On success
false If there's not enough space in the buffer
bool tb_strget ( struct txtbuf tb,
int  index,
char *  dst,
size_t  dst_sz 
)

Retrieve a string at position index from the text buffer, where 0 is the most recent string added to the buffer

This function retrieves a string from the text buffer according to index An index o 0 means the most recent string, 1 is the 2nd most recent ...

Parameters
[in]tbA text buffer
[in]indexIndex of the string to retrieve, where 0 is the most recent one
[out]dstBuffer to store the string to
[in]dst_szSize of the output buffer
Return values
trueOn success
falseIf index out of range
bool tb_strlast ( struct txtbuf tb,
int  index,
char *  dst,
size_t  dst_sz 
)

Retrieve a string at position index from the text buffer, where 0 is the oldest string added to the buffer (the opposite of of tb_strget)

Parameters
[in]tbA text buffer
[in]indexIndex of the string to retrieve, where 0 is the oldest one
[out]dstBuffer to store the string to
[in]dst_szSize of the output buffer
Return values
trueOn success
falseIf index out of range
int tb_strnum ( struct txtbuf tb)

Return number of strings stored in the txtbuf

Parameters
[in]tbA text buffer
Returns
This function returns the number of strings stored in the text buffer
bool tb_strput ( struct txtbuf tb,
char *  str 
)

Store a string into a text buffer

Note
This function removes old strings if there's not enough space
Parameters
[in]tbA text buffer
[in]strA string
Return values
trueIf the string was successfully stored
falseIf string is larget than the textbuffer total size
void tb_strtrim ( struct txtbuf tb)

Delete the oldest string in the textbuffer

This function tries to move the head forward to the beginning of the next string

Parameters
[in]tbA text buffer