aboutsummaryrefslogtreecommitdiffstats
path: root/src/vppinfra/format.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/vppinfra/format.h')
-rw-r--r--src/vppinfra/format.h55
1 files changed, 51 insertions, 4 deletions
diff --git a/src/vppinfra/format.h b/src/vppinfra/format.h
index 70882adac99..a1a70a2d64f 100644
--- a/src/vppinfra/format.h
+++ b/src/vppinfra/format.h
@@ -98,6 +98,7 @@ _(format_hex_bytes_no_wrap);
_(format_white_space);
_(format_f64);
_(format_time_interval);
+_ (format_duration);
#ifdef CLIB_UNIX
/* Unix specific formats. */
@@ -132,8 +133,11 @@ typedef struct _unformat_input_t
(and argument). */
uword (*fill_buffer) (struct _unformat_input_t * i);
- /* Return values for fill buffer function which indicate whether not
- input has been exhausted. */
+ /* User's function to be called on input_free */
+ void (*free) (struct _unformat_input_t *i);
+
+ /* Return values for fill buffer function which indicate whether not
+ input has been exhausted. */
#define UNFORMAT_END_OF_INPUT (~0)
#define UNFORMAT_MORE_INPUT 0
@@ -154,6 +158,8 @@ unformat_init (unformat_input_t * i,
always_inline void
unformat_free (unformat_input_t * i)
{
+ if (i->free)
+ i->free (i);
vec_free (i->buffer);
vec_free (i->buffer_marks);
clib_memset (i, 0, sizeof (i[0]));
@@ -199,6 +205,22 @@ unformat_put_input (unformat_input_t * input)
input->index -= 1;
}
+always_inline uword
+is_white_space (uword c)
+{
+ switch (c)
+ {
+ case ' ':
+ case '\t':
+ case '\n':
+ case '\r':
+ return 1;
+
+ default:
+ return 0;
+ }
+}
+
/* Peek current input character without advancing. */
always_inline uword
unformat_peek_input (unformat_input_t * input)
@@ -242,8 +264,8 @@ uword va_unformat (unformat_input_t * i, const char *fmt, va_list * args);
void unformat_init_command_line (unformat_input_t * input, char *argv[]);
/* Setup for unformat of given string. */
-void unformat_init_string (unformat_input_t * input,
- char *string, int string_len);
+void unformat_init_string (unformat_input_t *input, const char *string,
+ int string_len);
always_inline void
unformat_init_cstring (unformat_input_t * input, char *string)
@@ -254,6 +276,12 @@ unformat_init_cstring (unformat_input_t * input, char *string)
/* Setup for unformat of given vector string; vector will be freed by unformat_string. */
void unformat_init_vector (unformat_input_t * input, u8 * vector_string);
+/* Unformat u8 */
+unformat_function_t unformat_u8;
+
+/* Unformat u16 */
+unformat_function_t unformat_u16;
+
/* Format function for unformat input usable when an unformat error
has occurred. */
u8 *format_unformat_error (u8 * s, va_list * va);
@@ -287,6 +315,16 @@ unformat_function_t unformat_eof;
/* Parse memory size e.g. 100, 100k, 100m, 100g. */
unformat_function_t unformat_memory_size;
+/* Unformat C string array, takes array length as 2nd argument */
+unformat_function_t unformat_c_string_array;
+
+/* Unformat sigle and double quoted string */
+unformat_function_t unformat_single_quoted_string;
+unformat_function_t unformat_double_quoted_string;
+
+/* Format base 10 e.g. 100, 100K, 100M, 100G */
+u8 *format_base10 (u8 *s, va_list *va);
+
/* Unparse memory size e.g. 100, 100k, 100m, 100g. */
u8 *format_memory_size (u8 * s, va_list * va);
@@ -301,12 +339,21 @@ u8 *format_c_identifier (u8 * s, va_list * va);
/* Format hexdump with both hex and printable chars - compatible with text2pcap */
u8 *format_hexdump (u8 * s, va_list * va);
+u8 *format_hexdump_u16 (u8 *s, va_list *va);
+u8 *format_hexdump_u32 (u8 *s, va_list *va);
+u8 *format_hexdump_u64 (u8 *s, va_list *va);
+
+/* Format bitmap of array of uword numbers */
+u8 *format_uword_bitmap (u8 *s, va_list *va);
/* Unix specific formats. */
#ifdef CLIB_UNIX
/* Setup input from Unix file. */
void unformat_init_clib_file (unformat_input_t * input, int file_descriptor);
+/* Setup input from flesystem path. */
+uword unformat_init_file (unformat_input_t *input, char *fmt, ...);
+
/* Take input from Unix environment variable; returns
1 if variable exists zero otherwise. */
uword unformat_init_unix_env (unformat_input_t * input, char *var);