Data Accelerator Offload
|
#include <stdarg.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <assert.h>
#include <rte_config.h>
#include <rte_common.h>
#include <rte_compat.h>
Go to the source code of this file.
Data Structures | |
struct | dao_ds |
Functions | |
void | dao_ds_init (struct dao_ds *ds) |
void | dao_ds_clear (struct dao_ds *ds) |
void | dao_ds_truncate (struct dao_ds *ds, size_t new_length) |
void | dao_ds_reserve (struct dao_ds *ds, size_t min_length) |
char * | dao_ds_put_uninit (struct dao_ds *ds, size_t n) |
void | dao_ds_put_utf8 (struct dao_ds *ds, int uc) |
void | dao_ds_put_char_multiple (struct dao_ds *ds, char c, size_t n) |
void | dao_ds_put_buffer (struct dao_ds *ds, const char *buf, size_t n) |
void | dao_ds_put_cstr (struct dao_ds *ds, const char *str) |
void | dao_ds_put_and_free_cstr (struct dao_ds *ds, char *str) |
void | dao_ds_put_format (struct dao_ds *ds, const char *format,...) |
void | dao_ds_put_format_valist (struct dao_ds *ds, const char *format, va_list va) |
void | dao_ds_put_printable (struct dao_ds *ds, const char *buf, size_t size) |
void | dao_ds_put_hex (struct dao_ds *ds, const void *buf, size_t size) |
void | dao_ds_put_hex_dump (struct dao_ds *ds, const void *buf, size_t size, uintptr_t ofs, bool ascii) |
void | dao_ds_put_sparse_hex_dump (struct dao_ds *ds, const void *buf, size_t size, uintptr_t ofs, bool ascii) |
int | dao_ds_get_line (struct dao_ds *ds, FILE *file) |
int | dao_ds_get_preprocessed_line (struct dao_ds *ds, FILE *file, int *line_numberp) |
int | dao_ds_get_test_line (struct dao_ds *ds, FILE *file) |
char * | dao_ds_cstr (struct dao_ds *ds) |
char * | dao_ds_steal_cstr (struct dao_ds *ds) |
void | dao_ds_destroy (struct dao_ds *ds) |
void | dao_ds_swap (struct dao_ds *a, struct dao_ds *b) |
int | dao_ds_last (const struct dao_ds *ds) |
bool | dao_ds_chomp (struct dao_ds *ds, int c) |
void | dao_ds_clone (struct dao_ds *dst, struct dao_ds *source) |
static void | dao_ds_put_char (struct dao_ds *ds, char c) |
DAO dynamic string APIs helps to construct/store/extend/print variable length strings
A "dynamic string", that is, a buffer that can be used to construct a string across a series of operations that extend or modify it.
The 'string' member does not always point to a null-terminated string. Initially it is NULL, and even when it is nonnull, some operations do not ensure that it is null-terminated. Use dao_ds_cstr() to ensure that memory is allocated for the string and that it is null-terminated.
Definition in file dao_dynamic_string.h.
void dao_ds_init | ( | struct dao_ds * | ds | ) |
Initialize "dynamic string" object
ds | "dynamic string" object |
void dao_ds_clear | ( | struct dao_ds * | ds | ) |
Set length of string, managed by "dynamic string" object, to 0. Does not free memory
ds | "dynamic string" object |
void dao_ds_truncate | ( | struct dao_ds * | ds, |
size_t | new_length | ||
) |
Reduces length of string, managed by "dynamic string" object, to no more than 'new length'. If its length is already 'new_length' or less, does nothing.
ds | "dynamic string" object |
new_length | Length to which string to be truncated |
void dao_ds_reserve | ( | struct dao_ds * | ds, |
size_t | min_length | ||
) |
Ensures that at least 'min_length + 1' bytes (including space for a null terminator) are allocated for ds->string, allocating or reallocating memory as necessary.
ds | "dynamic string" object |
min_length | Length which ds->string should be able to hold at minimum. |
char * dao_ds_put_uninit | ( | struct dao_ds * | ds, |
size_t | n | ||
) |
Appends space for 'n' bytes to the end of 'ds->string', increasing 'ds->length' by the same amount, and returns the first appended byte. The caller should fill in all 'n' bytes starting at the return value.
ds | "dynamic string" object |
n | Number of bytes to be appended to the string of ds->string |
void dao_ds_put_utf8 | ( | struct dao_ds * | ds, |
int | uc | ||
) |
Appends unicode code point 'uc' to 'ds' in UTF-8 encoding.
ds | "dynamic string" object |
uc | unicode code point |
void dao_ds_put_char_multiple | ( | struct dao_ds * | ds, |
char | c, | ||
size_t | n | ||
) |
Append single character 'c' multiple times to 'ds'
ds | "dynamic string" object |
c | character to be added |
n | No. of times character to be added in string |
void dao_ds_put_buffer | ( | struct dao_ds * | ds, |
const char * | buf, | ||
size_t | n | ||
) |
Append buffer 'buf' of length 'n' to 'ds'
ds | "dynamic string" object |
buf | buffer to be appended |
n | length of buffer 'buf' |
void dao_ds_put_cstr | ( | struct dao_ds * | ds, |
const char * | str | ||
) |
Append string 'str' to 'ds'
ds | "dynamic string" object |
str | string to be appended |
void dao_ds_put_and_free_cstr | ( | struct dao_ds * | ds, |
char * | str | ||
) |
Append string 'str' to 'ds' and free 'str' afterwards
ds | "dynamic string" object |
str | After appending 'str' to ds, memory associated with 'str' is freed |
void dao_ds_put_format | ( | struct dao_ds * | ds, |
const char * | format, | ||
... | |||
) |
Append 'format' string to 'ds' with variable arguments. Functionality similar to sprintf()
ds | "dynamic string" object |
format | string with variable arguments |
void dao_ds_put_format_valist | ( | struct dao_ds * | ds, |
const char * | format, | ||
va_list | va | ||
) |
Append 'format' string to 'ds' with variable arguments and va_list
ds | "dynamic string" object |
format | string with variable arguments |
va | va_list |
void dao_ds_put_printable | ( | struct dao_ds * | ds, |
const char * | buf, | ||
size_t | size | ||
) |
Append buffer 'buf' of 'size' bytes to 'ds' and convert each character in printable format. In other words, print ascii characters in range of [@,A-Z, a-z,\,^.`,~,_,{,},|,]
ds | "dynamic string" object |
buf | buffer to be appended |
size | size of buffer 'buf' in bytes |
void dao_ds_put_hex | ( | struct dao_ds * | ds, |
const void * | buf, | ||
size_t | size | ||
) |
Append buffer 'buf' of 'size' bytes to 'ds' and convert each character in hexadecimal format.
ds | "dynamic string" object |
buf | buffer to be appended |
size | size of buffer 'buf' in bytes |
void dao_ds_put_hex_dump | ( | struct dao_ds * | ds, |
const void * | buf, | ||
size_t | size, | ||
uintptr_t | ofs, | ||
bool | ascii | ||
) |
Writes the 'size' bytes in 'buf' to 'string' as hex bytes arranged 16 per line. Numeric offsets are also included, starting at 'ofs' for the first byte in 'buf'. If 'ascii' is true then the corresponding ASCII characters are also rendered alongside.
ds | "dynamic string" object |
buf | buffer to be appended |
size | size of buffer 'buf' in bytes |
ofs | offset to start with |
ascii | if 'true' then ASCII characters are also rendered alongside hex |
void dao_ds_put_sparse_hex_dump | ( | struct dao_ds * | ds, |
const void * | buf, | ||
size_t | size, | ||
uintptr_t | ofs, | ||
bool | ascii | ||
) |
Same as 'dao_ds_put_hex_dump', but doesn't print lines that only contains zero bytes.
ds | "dynamic string" object |
buf | buffer to be appended |
size | size of buffer 'buf' in bytes |
ofs | offset to start with |
ascii | if 'true' then ASCII characters are also rendered alongside hex |
int dao_ds_get_line | ( | struct dao_ds * | ds, |
FILE * | file | ||
) |
Get line from 'file' until encounter '
' or 'EOF' and save it to 'ds'
ds | "dynamic string" object to which a line is written |
file | File from where a line is read |
int dao_ds_get_preprocessed_line | ( | struct dao_ds * | ds, |
FILE * | file, | ||
int * | line_numberp | ||
) |
Reads a line from 'file' into 'ds', clearing anything initially in 'ds'. Deletes comments introduced by "#" and skips lines that contains only white space (after deleting comments).
If 'line_numberp' is nonnull, increments '*line_numberp' by the number of lines read from 'file'.
ds | "dynamic string" object | |
file | File pointer | |
[out] | line_numberp | If nonnull, returns number of lines read |
int dao_ds_get_test_line | ( | struct dao_ds * | ds, |
FILE * | file | ||
) |
Reads a line from 'file' into 'ds' and does some preprocessing on it:
This is useful in some of the tests, where we want to check that parsing and then re-formatting some kind of data does not change it, but we also want to be able to put comments in the input.
ds | "dynamic string" object |
file | File pointer |
char * dao_ds_cstr | ( | struct dao_ds * | ds | ) |
Return string corresponding to ds. strxxx()/printf() operations are valid on returned string
ds | "dynamic object" |
char * dao_ds_steal_cstr | ( | struct dao_ds * | ds | ) |
Returns a null-terminated string representing the current contents of 'ds', which the caller is expected to free with free(), then clears the contents of 'ds'.
ds | "dynamic string object |
void dao_ds_destroy | ( | struct dao_ds * | ds | ) |
Free string associated with 'ds'
ds | "dynamic string" object |
Swaps the content of 'a' and 'b'.
a | First string to be swapped with string 'b' |
b | Second string to be swapped with string 'a' |
int dao_ds_last | ( | const struct dao_ds * | ds | ) |
Return last character in string associated by ds
ds | "dynamic string object |
bool dao_ds_chomp | ( | struct dao_ds * | ds, |
int | c | ||
) |
Chomp character 'c' if it is last character in ds->string and return true otherwise return false
ds | "dynamic string" object |
c | character to be chomped from last character of string |
Clone string 'source' into string 'dst'
source | "dynamic string" to be cloned |
dst | destination "dynamic string" cloned from source on return |
|
inlinestatic |
Add character to dynamic string
ds | "dynamic sting" object |
c | character to be added in ds->string |
Definition at line 404 of file dao_dynamic_string.h.