aboutsummaryrefslogtreecommitdiff
path: root/client/parse.h
blob: 1beb714b1d2aa9eb2f8c331e2529354c6f22674c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#pragma once

#include <stddef.h>

/**
 * \ingroup pbc
 * \defgroup pbc_parse Parse
 * \brief Debug \c send command parser utilities
 * \{
 */

//! Internal field separator (i.e. whitespace delimiter)
#define IFS " \t\n"

//! Octal digit character set
#define SET_OCT "01234567"
//! Decimal digit character set
#define SET_DEC "0123456789"
//! Hexadecimal digit character set
#define SET_HEX SET_DEC"abcdefABCDEF"
//! (Hexadecimal) byte string character set
#define SET_HEX_STR SET_HEX":"

/**
 * \brief modify \p token to point to the first token when broken up on \p ifs
 * and return the remaining data
 *
 * \p token will be null-terminated to indicate the end of the first token. A
 * pointer to the remaining line after the NULL byte is returned, or NULL when
 * the end of the string has been reached.
 *
 * \param token  input string
 * \param ifs    string containing field separators
 *
 * \return the remaining data after \p token and the first \p ifs
 */
char* consume_token(char * token, const char * ifs);

/**
 * \brief convert string with literals into raw data
 *
 * \param str   input string containing literals
 * \param data  pointer to \c char* that will store the resulting data
 * \param size  size of \p data
 *
 * \return 0 or a negative integer representing the index where there is a
 * syntax error if there was an error, or a positive integer representing the
 * amount of bytes parsed from \p str
 *
 * \note The pointer that \p data refers to will not be initialized by this
 * function if parsing fails
 */
int strtodata(const char * str, char ** data, size_t * size);

/// \}