49 first_mark = l =
vec_len (i->buffer);
50 if (
vec_len (i->buffer_marks) > 0)
51 first_mark = i->buffer_marks[0];
58 for (l = 0; l <
vec_len (i->buffer_marks); l++)
59 i->buffer_marks[l] -= first_mark;
63 i->index = i->fill_buffer (i);
67 if (i->index >=
vec_len (i->buffer))
101 uword n = l - i->index;
104 p = i->buffer + i->index;
105 p_end = p + (n > n_max ? n_max : n);
149 s =
format (s,
"{END_OF_INPUT}");
155 vec_add (s, i->buffer + i->index, n);
174 uword delimiter_character,
175 uword format_character, va_list * va)
177 u8 **string_return = va_arg (*va,
u8 **);
180 word is_paren_delimited = 0;
184 switch (delimiter_character)
189 delimiter_character = 0;
198 add_to_vector = string_return != 0;
211 if (paren == 0 &&
vec_len (s) == 0)
213 is_paren_delimited = 1;
221 if (is_paren_delimited && paren == 0)
229 if (!is_paren_delimited)
237 if (!is_paren_delimited && c == delimiter_character)
260 if (format_character ==
's')
274 u8 **hexstring_return = va_arg (*va,
u8 **);
283 if (c >=
'0' && c <=
'9')
284 d = 16 * d + c -
'0';
285 else if (c >=
'a' && c <=
'f')
286 d = 16 * d + 10 + c -
'a';
287 else if (c >=
'A' && c <=
'F')
288 d = 16 * d + 10 + c -
'A';
315 *hexstring_return = s;
330 u8 *token_chars = va_arg (*va,
u8 *);
331 u8 **string_return = va_arg (*va,
u8 **);
336 token_chars = (
u8 *)
"a-zA-Z0-9_";
339 for (s = token_chars; *s;)
348 if (s[1] ==
'-' && s[0] < s[2])
350 for (i = s[0]; i <= s[2]; i++)
401 u8 *line = 0, **result = va_arg (*va,
u8 **);
426 #define UNFORMAT_INTEGER_SIGNED 1 427 #define UNFORMAT_INTEGER_UNSIGNED 0 440 if (base < 2 || base > 64)
473 digit = 10 + (c -
'a');
477 digit = 10 + (base >= 36 ? 26 : 0) + (c -
'A');
500 uword new_value = base * value + digit;
503 if (new_value < value)
519 void *v = va_arg (*va,
void *);
521 if (data_bytes == ~0)
522 data_bytes =
sizeof (int);
555 static f64 t[8] = { 1e+0, 1e+1, 1e+2, 1e+3, 1e+4, 1e+5, 1e+6, 1e+7, };
565 static f64 t[8] = { 1e-0, 1e-1, 1e-2, 1e-3, 1e-4, 1e-5, 1e-6, 1e-7, };
581 uword n_digits[3], value_index = 0;
582 uword signs[2], sign_index = 0;
594 if (value_index == 2 && n_digits[2] == 0)
597 else if (value_index < 2 && n_digits[0] > 0)
604 else if (n_input > 0)
607 signs[sign_index++] = 1;
611 if (value_index == 2 && n_digits[2] == 0)
614 else if (value_index < 2 && n_digits[0] > 0)
621 else if (n_input > 0)
623 signs[sign_index++] = 0;
644 tmp = values[value_index] * 10 + c -
'0';
647 if (tmp < values[value_index])
649 values[value_index] = tmp;
650 n_digits[value_index] += 1;
665 f64 f_values[2], *value_return;
669 if (n_digits[0] + n_digits[1] <= 0)
672 f_values[0] = values[0];
674 f_values[0] = -f_values[0];
676 f_values[1] = values[1];
679 f_values[0] += f_values[1];
687 value_return = va_arg (*va,
f64 *);
688 *value_return = f_values[0];
706 if (cf == 0 || cf ==
'%' || cf ==
' ')
721 uword cf, n, data_bytes = ~0;
733 data_bytes =
sizeof (
uword);
741 data_bytes =
sizeof (
long long);
745 data_bytes =
sizeof (long);
751 data_bytes =
sizeof (
long long);
759 data_bytes = va_arg (*va,
int);
781 data_bytes = va_arg (*va,
int);
806 int *var = va_arg (*va,
int *);
807 uword val = va_arg (*va,
int);
842 uword input_matches_format;
843 uword default_skip_input_white_space;
844 uword n_input_white_space_skipped;
845 uword last_non_white_space_match_percent;
846 uword last_non_white_space_match_format;
849 sizeof (input->buffer_marks[0]));
852 default_skip_input_white_space = 1;
853 input_matches_format = 0;
854 last_non_white_space_match_percent = 0;
855 last_non_white_space_match_format = 0;
860 uword is_percent, skip_input_white_space;
868 skip_input_white_space = f == fmt || default_skip_input_white_space;
873 skip_input_white_space = 1;
886 default_skip_input_white_space =
887 !default_skip_input_white_space;
894 if (!default_skip_input_white_space
895 && !(f == fmt + 2 || *f == 0))
913 n_input_white_space_skipped = 0;
914 if (skip_input_white_space)
925 if (skip_input_white_space
926 && !last_non_white_space_match_percent
927 && !last_non_white_space_match_format
928 && n_input_white_space_skipped == 0
934 last_non_white_space_match_percent = is_percent;
935 last_non_white_space_match_format = 0;
938 if (cf ==
' ' && !default_skip_input_white_space)
940 if (n_input_white_space_skipped == 0)
955 last_non_white_space_match_format = g > f;
960 input_matches_format = 1;
968 if (!input_matches_format)
969 input->index = input->buffer_marks[l - 1];
971 _vec_len (input->buffer_marks) = l - 1;
974 return input_matches_format;
995 l =
vec_len (input->buffer_marks);
997 sizeof (input->buffer_marks[0]));
1000 result = func (input, &va);
1004 input->index = input->buffer_marks[l];
1006 _vec_len (input->buffer_marks) = l;
1020 for (i = 1; argv[
i]; i++)
1022 vec_add (input->buffer, argv[i], strlen (argv[i]));
1033 vec_add (input->buffer,
string, string_len);
1040 input->buffer = vector_string;
1053 n = read (fd, input->buffer + l, 4096);
1055 _vec_len (input->buffer) = l + n;
1060 return input->index;
1074 char *val = getenv (var);
1084 u64 *
a = va_arg (*args,
u64 *);
1085 if (
unformat (input,
"%lluGb", &_a))
1087 else if (
unformat (input,
"%lluG", &_a))
1089 else if (
unformat (input,
"%lluMb", &_a))
1091 else if (
unformat (input,
"%lluM", &_a))
1093 else if (
unformat (input,
"%lluKb", &_a))
1095 else if (
unformat (input,
"%lluK", &_a))
1097 else if (
unformat (input,
"%llu", a))
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
#define vec_add(V, E, N)
Add N elements to end of vector V (no header, unspecified alignment)
#define vec_add1_aligned(V, E, A)
Add 1 element to end of vector (alignment specified).
#define vec_resize(V, N)
Resize a vector (no header, unspecified alignment) Add N elements to end of given vector V...
#define vec_free(V)
Free vector's memory (no header).
#define uword_to_pointer(u, type)
#define vec_delete(V, N, M)
Delete N elements starting at element M.
static uword pointer_to_uword(const void *p)
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)