• Home
  • Raw
  • Download

Lines Matching refs:state

66 struct state {  struct
72 int (*append_char)(struct state *, unsigned char); argument
73 int (*reserve)(struct state *, size_t); argument
79 sn_reserve (struct state *state, size_t n) in sn_reserve() argument
81 return state->s + n > state->theend; in sn_reserve()
85 sn_append_char (struct state *state, unsigned char c) in sn_append_char() argument
87 if (sn_reserve (state, 1)) { in sn_append_char()
90 *state->s++ = c; in sn_append_char()
98 as_reserve (struct state *state, size_t n)
100 if (state->s + n > state->theend) {
101 int off = state->s - state->str;
104 if (state->max_sz && state->sz >= state->max_sz)
107 state->sz = max(state->sz * 2, state->sz + n);
108 if (state->max_sz)
109 state->sz = min(state->sz, state->max_sz);
110 tmp = realloc (state->str, state->sz);
113 state->str = tmp;
114 state->s = state->str + off;
115 state->theend = state->str + state->sz - 1;
121 as_append_char (struct state *state, unsigned char c)
123 if(as_reserve (state, 1))
126 *state->s++ = c;
133 append_number(struct state *state, in append_number() argument
149 if((*state->append_char)(state, rep[num % base])) in append_number()
157 if((*state->append_char)(state, '0')) in append_number()
170 if((*state->append_char)(state, '0')) in append_number()
178 if((*state->append_char)(state, rep[10] + 23)) /* XXX */ in append_number()
180 if((*state->append_char)(state, '0')) in append_number()
185 if((*state->append_char)(state, '-')) in append_number()
189 if((*state->append_char)(state, '+')) in append_number()
193 if((*state->append_char)(state, ' ')) in append_number()
200 char c = state->s[-i-1]; in append_number()
201 state->s[-i-1] = state->s[-len+i]; in append_number()
202 state->s[-len+i] = c; in append_number()
206 if((*state->append_char)(state, ' ')) in append_number()
213 char c = state->s[-i-1]; in append_number()
214 state->s[-i-1] = state->s[-len+i]; in append_number()
215 state->s[-len+i] = c; in append_number()
222 append_string (struct state *state, in append_string() argument
234 if((*state->append_char) (state, ' ')) in append_string()
238 if ((*state->append_char) (state, *arg++)) in append_string()
242 if ((*state->append_char) (state, *arg++)) in append_string()
247 if((*state->append_char) (state, ' ')) in append_string()
253 append_char(struct state *state, in append_char() argument
259 if((*state->append_char) (state, ' ')) in append_char()
262 if((*state->append_char) (state, arg)) in append_char()
265 if((*state->append_char) (state, ' ')) in append_char()
288 xyzprintf (struct state *state, const char *char_format, va_list ap) in xyzprintf() argument
361 if(append_char(state, va_arg(ap, int), width, flags)) in xyzprintf()
365 if (append_string(state, in xyzprintf()
386 if (append_number (state, num, 10, "0123456789", in xyzprintf()
396 if (append_number (state, arg, 10, "0123456789", in xyzprintf()
406 if (append_number (state, arg, 010, "01234567", in xyzprintf()
416 if (append_number (state, arg, 0x10, "0123456789abcdef", in xyzprintf()
426 if (append_number (state, arg, 0x10, "0123456789ABCDEF", in xyzprintf()
434 if (append_number (state, arg, 0x10, "0123456789ABCDEF", in xyzprintf()
441 *arg = state->s - state->str; in xyzprintf()
448 if ((*state->append_char)(state, c)) in xyzprintf()
452 if ( (*state->append_char)(state, '%') in xyzprintf()
453 || (*state->append_char)(state, c)) in xyzprintf()
458 if ((*state->append_char) (state, c)) in xyzprintf()
571 struct state state;
573 state.max_sz = max_sz;
574 state.sz = 1;
575 state.str = malloc(state.sz);
576 if (state.str == NULL) {
580 state.s = state.str;
581 state.theend = state.s + state.sz - 1;
582 state.append_char = as_append_char;
583 state.reserve = as_reserve;
585 st = xyzprintf (&state, format, args);
587 free (state.str);
593 *state.s = '\0';
594 len = state.s - state.str;
595 tmp = realloc (state.str, len+1);
597 free (state.str);
612 struct state state; in vsnprintf() local
616 state.max_sz = 0; in vsnprintf()
617 state.sz = sz; in vsnprintf()
618 state.str = ustr; in vsnprintf()
619 state.s = ustr; in vsnprintf()
620 state.theend = ustr + sz - 1; in vsnprintf()
621 state.append_char = sn_append_char; in vsnprintf()
622 state.reserve = sn_reserve; in vsnprintf()
624 ret = xyzprintf (&state, format, args); in vsnprintf()
625 *state.s = '\0'; in vsnprintf()
629 return state.s - state.str; in vsnprintf()