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 **);
419 #define UNFORMAT_INTEGER_SIGNED 1 420 #define UNFORMAT_INTEGER_UNSIGNED 0 433 if (base < 2 || base > 64)
466 digit = 10 + (c -
'a');
470 digit = 10 + (base >= 36 ? 26 : 0) + (c -
'A');
493 uword new_value = base * value + digit;
496 if (new_value < value)
512 void *
v = va_arg (*va,
void *);
514 if (data_bytes == ~0)
515 data_bytes =
sizeof (int);
548 static f64 t[8] = { 1e+0, 1e+1, 1e+2, 1e+3, 1e+4, 1e+5, 1e+6, 1e+7, };
558 static f64 t[8] = { 1e-0, 1e-1, 1e-2, 1e-3, 1e-4, 1e-5, 1e-6, 1e-7, };
574 uword n_digits[3], value_index = 0;
575 uword signs[2], sign_index = 0;
578 memset (values, 0,
sizeof (values));
579 memset (n_digits, 0,
sizeof (n_digits));
580 memset (signs, 0,
sizeof (signs));
587 if (value_index == 2 && n_digits[2] == 0)
590 else if (value_index < 2 && n_digits[0] > 0)
597 else if (n_input > 0)
600 signs[sign_index++] = 1;
604 if (value_index == 2 && n_digits[2] == 0)
607 else if (value_index < 2 && n_digits[0] > 0)
614 else if (n_input > 0)
616 signs[sign_index++] = 0;
637 tmp = values[value_index] * 10 + c -
'0';
640 if (tmp < values[value_index])
642 values[value_index] = tmp;
643 n_digits[value_index] += 1;
658 f64 f_values[2], *value_return;
662 if (n_digits[0] + n_digits[1] <= 0)
665 f_values[0] = values[0];
667 f_values[0] = -f_values[0];
669 f_values[1] = values[1];
672 f_values[0] += f_values[1];
680 value_return = va_arg (*va,
f64 *);
681 *value_return = f_values[0];
699 if (cf == 0 || cf ==
'%' || cf ==
' ')
714 uword cf, n, data_bytes = ~0;
726 data_bytes =
sizeof (
uword);
734 data_bytes =
sizeof (
long long);
738 data_bytes =
sizeof (long);
744 data_bytes =
sizeof (
long long);
752 data_bytes = va_arg (*va,
int);
774 data_bytes = va_arg (*va,
int);
799 int *var = va_arg (*va,
int *);
800 uword val = va_arg (*va,
int);
835 uword input_matches_format;
836 uword default_skip_input_white_space;
837 uword n_input_white_space_skipped;
838 uword last_non_white_space_match_percent;
839 uword last_non_white_space_match_format;
842 sizeof (input->buffer_marks[0]));
845 default_skip_input_white_space = 1;
846 input_matches_format = 0;
847 last_non_white_space_match_percent = 0;
848 last_non_white_space_match_format = 0;
853 uword is_percent, skip_input_white_space;
861 skip_input_white_space = f == fmt || default_skip_input_white_space;
866 skip_input_white_space = 1;
879 default_skip_input_white_space =
880 !default_skip_input_white_space;
887 if (!default_skip_input_white_space
888 && !(f == fmt + 2 || *f == 0))
906 n_input_white_space_skipped = 0;
907 if (skip_input_white_space)
918 if (skip_input_white_space
919 && !last_non_white_space_match_percent
920 && !last_non_white_space_match_format
921 && n_input_white_space_skipped == 0
927 last_non_white_space_match_percent = is_percent;
928 last_non_white_space_match_format = 0;
931 if (cf ==
' ' && !default_skip_input_white_space)
933 if (n_input_white_space_skipped == 0)
948 last_non_white_space_match_format = g > f;
953 input_matches_format = 1;
961 if (!input_matches_format)
962 input->index = input->buffer_marks[l - 1];
964 _vec_len (input->buffer_marks) = l - 1;
967 return input_matches_format;
988 l =
vec_len (input->buffer_marks);
990 sizeof (input->buffer_marks[0]));
993 result = func (input, &va);
997 input->index = input->buffer_marks[l];
999 _vec_len (input->buffer_marks) = l;
1013 for (i = 1; argv[
i]; i++)
1015 vec_add (input->buffer, argv[i], strlen (argv[i]));
1026 vec_add (input->buffer,
string, string_len);
1033 input->buffer = vector_string;
1046 n = read (fd, input->buffer + l, 4096);
1048 _vec_len (input->buffer) = l + n;
1053 return input->index;
1067 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)