Lines Matching refs:state
57 struct state { struct
63 int (*append_char)(struct state *, unsigned char); argument
64 int (*reserve)(struct state *, size_t); argument
70 as_reserve (struct state *state, size_t n)
72 if (state->s + n > state->theend) {
73 int off = state->s - state->str;
76 if (state->max_sz && state->sz >= state->max_sz)
79 state->sz = max(state->sz * 2, state->sz + n);
80 if (state->max_sz)
81 state->sz = min(state->sz, state->max_sz);
82 tmp = realloc (state->str, state->sz);
85 state->str = tmp;
86 state->s = state->str + off;
87 state->theend = state->str + state->sz - 1;
93 as_append_char (struct state *state, unsigned char c)
95 if(as_reserve (state, 1))
98 *state->s++ = c;
105 append_number(struct state *state, in append_number() argument
121 if((*state->append_char)(state, rep[num % base])) in append_number()
129 if((*state->append_char)(state, '0')) in append_number()
142 if((*state->append_char)(state, '0')) in append_number()
150 if((*state->append_char)(state, rep[10] + 23)) /* XXX */ in append_number()
152 if((*state->append_char)(state, '0')) in append_number()
157 if((*state->append_char)(state, '-')) in append_number()
161 if((*state->append_char)(state, '+')) in append_number()
165 if((*state->append_char)(state, ' ')) in append_number()
172 char c = state->s[-i-1]; in append_number()
173 state->s[-i-1] = state->s[-len+i]; in append_number()
174 state->s[-len+i] = c; in append_number()
178 if((*state->append_char)(state, ' ')) in append_number()
185 char c = state->s[-i-1]; in append_number()
186 state->s[-i-1] = state->s[-len+i]; in append_number()
187 state->s[-len+i] = c; in append_number()
194 append_string (struct state *state, in append_string() argument
206 if((*state->append_char) (state, ' ')) in append_string()
210 if ((*state->append_char) (state, *arg++)) in append_string()
214 if ((*state->append_char) (state, *arg++)) in append_string()
219 if((*state->append_char) (state, ' ')) in append_string()
225 append_char(struct state *state, in append_char() argument
231 if((*state->append_char) (state, ' ')) in append_char()
234 if((*state->append_char) (state, arg)) in append_char()
237 if((*state->append_char) (state, ' ')) in append_char()
260 xyzprintf (struct state *state, const char *char_format, va_list ap) in xyzprintf() argument
333 if(append_char(state, va_arg(ap, int), width, flags)) in xyzprintf()
337 if (append_string(state, in xyzprintf()
358 if (append_number (state, num, 10, "0123456789", in xyzprintf()
368 if (append_number (state, arg, 10, "0123456789", in xyzprintf()
378 if (append_number (state, arg, 010, "01234567", in xyzprintf()
388 if (append_number (state, arg, 0x10, "0123456789abcdef", in xyzprintf()
398 if (append_number (state, arg, 0x10, "0123456789ABCDEF", in xyzprintf()
406 if (append_number (state, arg, 0x10, "0123456789ABCDEF", in xyzprintf()
413 *arg = state->s - state->str; in xyzprintf()
420 if ((*state->append_char)(state, c)) in xyzprintf()
424 if ( (*state->append_char)(state, '%') in xyzprintf()
425 || (*state->append_char)(state, c)) in xyzprintf()
430 if ((*state->append_char) (state, c)) in xyzprintf()
473 struct state state;
475 state.max_sz = max_sz;
476 state.sz = 1;
477 state.str = malloc(state.sz);
478 if (state.str == NULL) {
482 state.s = state.str;
483 state.theend = state.s + state.sz - 1;
484 state.append_char = as_append_char;
485 state.reserve = as_reserve;
487 st = xyzprintf (&state, format, args);
489 free (state.str);
495 *state.s = '\0';
496 len = state.s - state.str;
497 tmp = realloc (state.str, len+1);
499 free (state.str);