|
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) |
|
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.
size_t tb_free |
( |
struct txtbuf * |
tb) | |
|
|
inline |
Returns the number of free bytes in the textbuffer tb
- Parameters
-
- 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] | tb | Text buffer structure |
[in] | txt | Fixed-size buffer that will hold text buffer strings |
[in] | txt_sz | Size of the buffer |
size_t tb_len |
( |
struct txtbuf * |
tb) | |
|
|
inline |
Return number of bytes used by the textbuffer tb
- Parameters
-
- 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] | tb | A text buffer |
[in] | buf | Buffer that will be copied to tb |
[in] | buf_sz | Buffer 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] | tb | A text buffer |
[in] | index | Index of the string to retrieve, where 0 is the most recent one |
[out] | dst | Buffer to store the string to |
[in] | dst_sz | Size of the output buffer |
- Return values
-
true | On success |
false | If 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] | tb | A text buffer |
[in] | index | Index of the string to retrieve, where 0 is the oldest one |
[out] | dst | Buffer to store the string to |
[in] | dst_sz | Size of the output buffer |
- Return values
-
true | On success |
false | If index out of range |
int tb_strnum |
( |
struct txtbuf * |
tb) | |
|
Return number of strings stored in the txtbuf
- Parameters
-
- 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] | tb | A text buffer |
[in] | str | A string |
- Return values
-
true | If the string was successfully stored |
false | If 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
-