Lines Matching refs:state

59 struct state {  struct
65 int (*append_char)(struct state *, unsigned char); argument
66 int (*reserve)(struct state *, size_t); argument
72 as_reserve (struct state *state, size_t n)
74 if (state->s + n > state->theend) {
75 int off = state->s - state->str;
78 if (state->max_sz && state->sz >= state->max_sz)
81 state->sz = max(state->sz * 2, state->sz + n);
82 if (state->max_sz)
83 state->sz = min(state->sz, state->max_sz);
84 tmp = realloc (state->str, state->sz);
87 state->str = tmp;
88 state->s = state->str + off;
89 state->theend = state->str + state->sz - 1;
95 as_append_char (struct state *state, unsigned char c)
97 if(as_reserve (state, 1))
100 *state->s++ = c;
107 append_number(struct state *state, in append_number() argument
123 if((*state->append_char)(state, rep[num % base])) in append_number()
131 if((*state->append_char)(state, '0')) in append_number()
144 if((*state->append_char)(state, '0')) in append_number()
152 if((*state->append_char)(state, rep[10] + 23)) /* XXX */ in append_number()
154 if((*state->append_char)(state, '0')) in append_number()
159 if((*state->append_char)(state, '-')) in append_number()
163 if((*state->append_char)(state, '+')) in append_number()
167 if((*state->append_char)(state, ' ')) in append_number()
174 char c = state->s[-i-1]; in append_number()
175 state->s[-i-1] = state->s[-len+i]; in append_number()
176 state->s[-len+i] = c; in append_number()
180 if((*state->append_char)(state, ' ')) in append_number()
187 char c = state->s[-i-1]; in append_number()
188 state->s[-i-1] = state->s[-len+i]; in append_number()
189 state->s[-len+i] = c; in append_number()
196 append_string (struct state *state, in append_string() argument
208 if((*state->append_char) (state, ' ')) in append_string()
212 if ((*state->append_char) (state, *arg++)) in append_string()
216 if ((*state->append_char) (state, *arg++)) in append_string()
221 if((*state->append_char) (state, ' ')) in append_string()
227 append_char(struct state *state, in append_char() argument
233 if((*state->append_char) (state, ' ')) in append_char()
236 if((*state->append_char) (state, arg)) in append_char()
239 if((*state->append_char) (state, ' ')) in append_char()
262 xyzprintf (struct state *state, const char *char_format, va_list ap) in xyzprintf() argument
335 if(append_char(state, va_arg(ap, int), width, flags)) in xyzprintf()
339 if (append_string(state, in xyzprintf()
360 if (append_number (state, num, 10, "0123456789", in xyzprintf()
370 if (append_number (state, arg, 10, "0123456789", in xyzprintf()
380 if (append_number (state, arg, 010, "01234567", in xyzprintf()
390 if (append_number (state, arg, 0x10, "0123456789abcdef", in xyzprintf()
400 if (append_number (state, arg, 0x10, "0123456789ABCDEF", in xyzprintf()
408 if (append_number (state, arg, 0x10, "0123456789ABCDEF", in xyzprintf()
415 *arg = state->s - state->str; in xyzprintf()
422 if ((*state->append_char)(state, c)) in xyzprintf()
426 if ( (*state->append_char)(state, '%') in xyzprintf()
427 || (*state->append_char)(state, c)) in xyzprintf()
432 if ((*state->append_char) (state, c)) in xyzprintf()
475 struct state state;
477 state.max_sz = max_sz;
478 state.sz = 1;
479 state.str = malloc(state.sz);
480 if (state.str == NULL) {
484 state.s = state.str;
485 state.theend = state.s + state.sz - 1;
486 state.append_char = as_append_char;
487 state.reserve = as_reserve;
489 st = xyzprintf (&state, format, args);
491 free (state.str);
497 *state.s = '\0';
498 len = state.s - state.str;
499 tmp = realloc (state.str, len+1);
501 free (state.str);