48 first_mark = l =
vec_len (i->buffer);
49 if (
vec_len (i->buffer_marks) > 0)
50 first_mark = i->buffer_marks[0];
57 for (l = 0; l <
vec_len (i->buffer_marks); l++)
58 i->buffer_marks[l] -= first_mark;
62 i->index = i->fill_buffer (i);
66 if (i->index >=
vec_len (i->buffer))
97 uword n = l - i->index;
100 p = i->buffer + i->index;
101 p_end = p + (n > n_max ? n_max : n);
114 case '\r':
vec_add (s,
"\\r", 2);
break;
115 case '\n':
vec_add (s,
"\\n", 2);
break;
116 case '\t':
vec_add (s,
"\\t", 2);
break;
137 s =
format (s,
"{END_OF_INPUT}");
143 vec_add (s, i->buffer + i->index, n);
159 uword delimiter_character,
160 uword format_character,
163 u8 ** string_return = va_arg (*va,
u8 **);
166 word is_paren_delimited = 0;
170 switch (delimiter_character)
175 delimiter_character = 0;
184 add_to_vector = string_return != 0;
197 if (paren == 0 &&
vec_len (s) == 0)
199 is_paren_delimited = 1;
207 if (is_paren_delimited && paren == 0)
215 if (! is_paren_delimited)
223 if (! is_paren_delimited && c == delimiter_character)
246 if (format_character ==
's')
261 u8 ** hexstring_return = va_arg (*va,
u8 **);
270 if (c >=
'0' && c <=
'9')
272 else if (c >=
'a' && c <=
'f')
273 d = 16*d + 10 + c -
'a';
274 else if (c >=
'A' && c <=
'F')
275 d = 16*d + 10 + c -
'A';
297 *hexstring_return = s;
313 u8 * token_chars = va_arg (*va,
u8 *);
314 u8 ** string_return = va_arg (*va,
u8 **);
319 token_chars = (
u8 *)
"a-zA-Z0-9_";
321 memset (map, 0,
sizeof (map));
322 for (s = token_chars; *s; )
325 if (s[0] < s[2] && s[1] ==
'-')
327 for (i = s[0]; i <= s[2]; i++)
376 u8 * line = 0, ** result = va_arg (*va,
u8 **);
400 #define UNFORMAT_INTEGER_SIGNED 1 401 #define UNFORMAT_INTEGER_UNSIGNED 0 417 if (base < 2 || base > 64)
450 digit = 10 + (c -
'a');
454 digit = 10 + (base >= 36 ? 26 : 0) + (c -
'A');
477 uword new_value = base*value + digit;
480 if (new_value < value)
496 void * v = va_arg (*va,
void *);
498 if (data_bytes == ~0)
499 data_bytes =
sizeof (int);
503 case 1: *(
u8 *) v = value;
break;
504 case 2: *(
u16 *) v = value;
break;
505 case 4: *(
u32 *) v = value;
break;
506 case 8: *(
u64 *) v = value;
break;
523 static f64 t[8] = { 1e+0, 1e+1, 1e+2, 1e+3, 1e+4, 1e+5, 1e+6, 1e+7, };
533 static f64 t[8] = { 1e-0, 1e-1, 1e-2, 1e-3, 1e-4, 1e-5, 1e-6, 1e-7, };
550 uword n_digits[3], value_index = 0;
551 uword signs[2], sign_index = 0;
554 memset (values, 0,
sizeof (values));
555 memset (n_digits, 0,
sizeof (n_digits));
556 memset (signs, 0,
sizeof (signs));
563 if (value_index == 2 && n_digits[2] == 0)
566 else if (value_index < 2 && n_digits[0] > 0)
573 else if (n_input > 0)
576 signs[sign_index++] = 1;
580 if (value_index == 2 && n_digits[2] == 0)
583 else if (value_index < 2 && n_digits[0] > 0)
590 else if (n_input > 0)
592 signs[sign_index++] = 0;
613 tmp = values[value_index] * 10 + c -
'0';
616 if (tmp < values[value_index])
618 values[value_index] = tmp;
619 n_digits[value_index] += 1;
634 f64 f_values[2], * value_return;
638 if (n_digits[0] + n_digits[1] <= 0)
641 f_values[0] = values[0];
643 f_values[0] = -f_values[0];
645 f_values[1] = values[1];
648 f_values[0] += f_values[1];
656 value_return = va_arg (*va,
f64 *);
657 *value_return = f_values[0];
674 if (cf == 0 || cf ==
'%' || cf ==
' ')
688 uword cf, n, data_bytes = ~0;
700 data_bytes =
sizeof (
uword);
708 data_bytes =
sizeof (
long long);
712 data_bytes =
sizeof (long);
718 data_bytes =
sizeof (
long long);
726 data_bytes = va_arg (*va,
int);
748 data_bytes = va_arg (*va,
int);
773 int * var = va_arg (*va,
int *);
774 uword val = va_arg (*va,
int);
808 uword input_matches_format;
809 uword default_skip_input_white_space;
810 uword n_input_white_space_skipped;
811 uword last_non_white_space_match_percent;
812 uword last_non_white_space_match_format;
814 vec_add1_aligned (input->buffer_marks, input->index, sizeof (input->buffer_marks[0]));
817 default_skip_input_white_space = 1;
818 input_matches_format = 0;
819 last_non_white_space_match_percent = 0;
820 last_non_white_space_match_format = 0;
825 uword is_percent, skip_input_white_space;
833 skip_input_white_space = f == fmt || default_skip_input_white_space;
838 skip_input_white_space = 1;
851 default_skip_input_white_space = !default_skip_input_white_space;
858 if (! default_skip_input_white_space
859 && ! (f == fmt + 2 || *f == 0))
877 n_input_white_space_skipped = 0;
878 if (skip_input_white_space)
889 if (skip_input_white_space
890 && ! last_non_white_space_match_percent
891 && ! last_non_white_space_match_format
892 && n_input_white_space_skipped == 0
898 last_non_white_space_match_percent = is_percent;
899 last_non_white_space_match_format = 0;
902 if (cf ==
' ' && !default_skip_input_white_space)
904 if (n_input_white_space_skipped == 0)
919 last_non_white_space_match_format = g > f;
924 input_matches_format = 1;
932 if (! input_matches_format)
933 input->index = input->buffer_marks[l-1];
935 _vec_len (input->buffer_marks) = l - 1;
938 return input_matches_format;
959 l =
vec_len (input->buffer_marks);
960 vec_add1_aligned (input->buffer_marks, input->index, sizeof (input->buffer_marks[0]));
963 result = func (input, &va);
967 input->index = input->buffer_marks[l];
969 _vec_len (input->buffer_marks) = l;
983 for (i = 1; argv[
i]; i++)
985 vec_add (input->buffer, argv[i], strlen (argv[i]));
997 vec_add (input->buffer,
string, string_len);
1004 input->buffer = vector_string;
1016 n = read (fd, input->buffer + l, 4096);
1018 _vec_len (input->buffer) = l + n;
1023 return input->index;
1027 int file_descriptor)
1036 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)