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';
310 *hexstring_return = s;
325 u8 *token_chars = va_arg (*va,
u8 *);
326 u8 **string_return = va_arg (*va,
u8 **);
331 token_chars = (
u8 *)
"a-zA-Z0-9_";
333 memset (map, 0,
sizeof (map));
334 for (s = token_chars; *s;)
337 if (s[0] < s[2] && s[1] ==
'-')
339 for (i = s[0]; i <= s[2]; i++)
390 u8 *line = 0, **result = va_arg (*va,
u8 **);
414 #define UNFORMAT_INTEGER_SIGNED 1 415 #define UNFORMAT_INTEGER_UNSIGNED 0 428 if (base < 2 || base > 64)
461 digit = 10 + (c -
'a');
465 digit = 10 + (base >= 36 ? 26 : 0) + (c -
'A');
488 uword new_value = base * value + digit;
491 if (new_value < value)
507 void *v = va_arg (*va,
void *);
509 if (data_bytes == ~0)
510 data_bytes =
sizeof (int);
543 static f64 t[8] = { 1e+0, 1e+1, 1e+2, 1e+3, 1e+4, 1e+5, 1e+6, 1e+7, };
553 static f64 t[8] = { 1e-0, 1e-1, 1e-2, 1e-3, 1e-4, 1e-5, 1e-6, 1e-7, };
569 uword n_digits[3], value_index = 0;
570 uword signs[2], sign_index = 0;
573 memset (values, 0,
sizeof (values));
574 memset (n_digits, 0,
sizeof (n_digits));
575 memset (signs, 0,
sizeof (signs));
582 if (value_index == 2 && n_digits[2] == 0)
585 else if (value_index < 2 && n_digits[0] > 0)
592 else if (n_input > 0)
595 signs[sign_index++] = 1;
599 if (value_index == 2 && n_digits[2] == 0)
602 else if (value_index < 2 && n_digits[0] > 0)
609 else if (n_input > 0)
611 signs[sign_index++] = 0;
632 tmp = values[value_index] * 10 + c -
'0';
635 if (tmp < values[value_index])
637 values[value_index] = tmp;
638 n_digits[value_index] += 1;
653 f64 f_values[2], *value_return;
657 if (n_digits[0] + n_digits[1] <= 0)
660 f_values[0] = values[0];
662 f_values[0] = -f_values[0];
664 f_values[1] = values[1];
667 f_values[0] += f_values[1];
675 value_return = va_arg (*va,
f64 *);
676 *value_return = f_values[0];
694 if (cf == 0 || cf ==
'%' || cf ==
' ')
709 uword cf, n, data_bytes = ~0;
721 data_bytes =
sizeof (
uword);
729 data_bytes =
sizeof (
long long);
733 data_bytes =
sizeof (long);
739 data_bytes =
sizeof (
long long);
747 data_bytes = va_arg (*va,
int);
769 data_bytes = va_arg (*va,
int);
794 int *var = va_arg (*va,
int *);
795 uword val = va_arg (*va,
int);
830 uword input_matches_format;
831 uword default_skip_input_white_space;
832 uword n_input_white_space_skipped;
833 uword last_non_white_space_match_percent;
834 uword last_non_white_space_match_format;
837 sizeof (input->buffer_marks[0]));
840 default_skip_input_white_space = 1;
841 input_matches_format = 0;
842 last_non_white_space_match_percent = 0;
843 last_non_white_space_match_format = 0;
848 uword is_percent, skip_input_white_space;
856 skip_input_white_space = f == fmt || default_skip_input_white_space;
861 skip_input_white_space = 1;
874 default_skip_input_white_space =
875 !default_skip_input_white_space;
882 if (!default_skip_input_white_space
883 && !(f == fmt + 2 || *f == 0))
901 n_input_white_space_skipped = 0;
902 if (skip_input_white_space)
913 if (skip_input_white_space
914 && !last_non_white_space_match_percent
915 && !last_non_white_space_match_format
916 && n_input_white_space_skipped == 0
922 last_non_white_space_match_percent = is_percent;
923 last_non_white_space_match_format = 0;
926 if (cf ==
' ' && !default_skip_input_white_space)
928 if (n_input_white_space_skipped == 0)
943 last_non_white_space_match_format = g > f;
948 input_matches_format = 1;
956 if (!input_matches_format)
957 input->index = input->buffer_marks[l - 1];
959 _vec_len (input->buffer_marks) = l - 1;
962 return input_matches_format;
983 l =
vec_len (input->buffer_marks);
985 sizeof (input->buffer_marks[0]));
988 result = func (input, &va);
992 input->index = input->buffer_marks[l];
994 _vec_len (input->buffer_marks) = l;
1008 for (i = 1; argv[
i]; i++)
1010 vec_add (input->buffer, argv[i], strlen (argv[i]));
1021 vec_add (input->buffer,
string, string_len);
1028 input->buffer = vector_string;
1041 n = read (fd, input->buffer + l, 4096);
1043 _vec_len (input->buffer) = l + n;
1048 return input->index;
1062 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)