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_";
338 memset (map, 0,
sizeof (map));
339 for (s = token_chars; *s;)
342 if (s[0] < s[2] && s[1] ==
'-')
344 for (i = s[0]; i <= s[2]; i++)
395 u8 *line = 0, **result = va_arg (*va,
u8 **);
420 #define UNFORMAT_INTEGER_SIGNED 1 421 #define UNFORMAT_INTEGER_UNSIGNED 0 434 if (base < 2 || base > 64)
467 digit = 10 + (c -
'a');
471 digit = 10 + (base >= 36 ? 26 : 0) + (c -
'A');
494 uword new_value = base * value + digit;
497 if (new_value < value)
513 void *
v = va_arg (*va,
void *);
515 if (data_bytes == ~0)
516 data_bytes =
sizeof (int);
549 static f64 t[8] = { 1e+0, 1e+1, 1e+2, 1e+3, 1e+4, 1e+5, 1e+6, 1e+7, };
559 static f64 t[8] = { 1e-0, 1e-1, 1e-2, 1e-3, 1e-4, 1e-5, 1e-6, 1e-7, };
575 uword n_digits[3], value_index = 0;
576 uword signs[2], sign_index = 0;
579 memset (values, 0,
sizeof (values));
580 memset (n_digits, 0,
sizeof (n_digits));
581 memset (signs, 0,
sizeof (signs));
588 if (value_index == 2 && n_digits[2] == 0)
591 else if (value_index < 2 && n_digits[0] > 0)
598 else if (n_input > 0)
601 signs[sign_index++] = 1;
605 if (value_index == 2 && n_digits[2] == 0)
608 else if (value_index < 2 && n_digits[0] > 0)
615 else if (n_input > 0)
617 signs[sign_index++] = 0;
638 tmp = values[value_index] * 10 + c -
'0';
641 if (tmp < values[value_index])
643 values[value_index] = tmp;
644 n_digits[value_index] += 1;
659 f64 f_values[2], *value_return;
663 if (n_digits[0] + n_digits[1] <= 0)
666 f_values[0] = values[0];
668 f_values[0] = -f_values[0];
670 f_values[1] = values[1];
673 f_values[0] += f_values[1];
681 value_return = va_arg (*va,
f64 *);
682 *value_return = f_values[0];
700 if (cf == 0 || cf ==
'%' || cf ==
' ')
715 uword cf, n, data_bytes = ~0;
727 data_bytes =
sizeof (
uword);
735 data_bytes =
sizeof (
long long);
739 data_bytes =
sizeof (long);
745 data_bytes =
sizeof (
long long);
753 data_bytes = va_arg (*va,
int);
775 data_bytes = va_arg (*va,
int);
800 int *var = va_arg (*va,
int *);
801 uword val = va_arg (*va,
int);
836 uword input_matches_format;
837 uword default_skip_input_white_space;
838 uword n_input_white_space_skipped;
839 uword last_non_white_space_match_percent;
840 uword last_non_white_space_match_format;
843 sizeof (input->buffer_marks[0]));
846 default_skip_input_white_space = 1;
847 input_matches_format = 0;
848 last_non_white_space_match_percent = 0;
849 last_non_white_space_match_format = 0;
854 uword is_percent, skip_input_white_space;
862 skip_input_white_space = f == fmt || default_skip_input_white_space;
867 skip_input_white_space = 1;
880 default_skip_input_white_space =
881 !default_skip_input_white_space;
888 if (!default_skip_input_white_space
889 && !(f == fmt + 2 || *f == 0))
907 n_input_white_space_skipped = 0;
908 if (skip_input_white_space)
919 if (skip_input_white_space
920 && !last_non_white_space_match_percent
921 && !last_non_white_space_match_format
922 && n_input_white_space_skipped == 0
928 last_non_white_space_match_percent = is_percent;
929 last_non_white_space_match_format = 0;
932 if (cf ==
' ' && !default_skip_input_white_space)
934 if (n_input_white_space_skipped == 0)
949 last_non_white_space_match_format = g > f;
954 input_matches_format = 1;
962 if (!input_matches_format)
963 input->index = input->buffer_marks[l - 1];
965 _vec_len (input->buffer_marks) = l - 1;
968 return input_matches_format;
989 l =
vec_len (input->buffer_marks);
991 sizeof (input->buffer_marks[0]));
994 result = func (input, &va);
998 input->index = input->buffer_marks[l];
1000 _vec_len (input->buffer_marks) = l;
1014 for (i = 1; argv[
i]; i++)
1016 vec_add (input->buffer, argv[i], strlen (argv[i]));
1027 vec_add (input->buffer,
string, string_len);
1034 input->buffer = vector_string;
1047 n = read (fd, input->buffer + l, 4096);
1049 _vec_len (input->buffer) = l + n;
1054 return input->index;
1068 char *val = getenv (var);
sll srl srl sll sra u16x4 i
#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...
static uword pointer_to_uword(const void *p)
#define uword_to_pointer(u, type)
#define vec_free(V)
Free vector's memory (no header).
#define vec_delete(V, N, M)
Delete N elements starting at element M.
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)