Lines Matching refs:state

56  * Common state
59 struct state {
65 int (*append_char)(struct state *, unsigned char);
66 int (*reserve)(struct state *, size_t);
72 sn_reserve (struct state *state, size_t n)
74 return state->s + n > state->theend;
78 sn_append_char (struct state *state, unsigned char c)
80 if (sn_reserve (state, 1)) {
83 *state->s++ = c;
91 as_reserve (struct state *state, size_t n)
93 if (state->s + n > state->theend) {
94 int off = state->s - state->str;
97 if (state->max_sz && state->sz >= state->max_sz)
100 state->sz = max(state->sz * 2, state->sz + n);
101 if (state->max_sz)
102 state->sz = min(state->sz, state->max_sz);
103 tmp = realloc (state->str, state->sz);
106 state->str = tmp;
107 state->s = state->str + off;
108 state->theend = state->str + state->sz - 1;
114 as_append_char (struct state *state, unsigned char c)
116 if(as_reserve (state, 1))
119 *state->s++ = c;
126 append_number(struct state *state,
142 if((*state->append_char)(state, rep[num % base]))
150 if((*state->append_char)(state, '0'))
163 if((*state->append_char)(state, '0'))
171 if((*state->append_char)(state, rep[10] + 23)) /* XXX */
173 if((*state->append_char)(state, '0'))
178 if((*state->append_char)(state, '-'))
182 if((*state->append_char)(state, '+'))
186 if((*state->append_char)(state, ' '))
193 char c = state->s[-i-1];
194 state->s[-i-1] = state->s[-len+i];
195 state->s[-len+i] = c;
199 if((*state->append_char)(state, ' '))
206 char c = state->s[-i-1];
207 state->s[-i-1] = state->s[-len+i];
208 state->s[-len+i] = c;
215 append_string (struct state *state,
227 if((*state->append_char) (state, ' '))
231 if ((*state->append_char) (state, *arg++))
235 if ((*state->append_char) (state, *arg++))
240 if((*state->append_char) (state, ' '))
246 append_char(struct state *state,
252 if((*state->append_char) (state, ' '))
255 if((*state->append_char) (state, arg))
258 if((*state->append_char) (state, ' '))
281 xyzprintf (struct state *state, const char *char_format, va_list ap)
354 if(append_char(state, va_arg(ap, int), width, flags))
358 if (append_string(state,
379 if (append_number (state, num, 10, "0123456789",
389 if (append_number (state, arg, 10, "0123456789",
399 if (append_number (state, arg, 010, "01234567",
409 if (append_number (state, arg, 0x10, "0123456789abcdef",
419 if (append_number (state, arg, 0x10, "0123456789ABCDEF",
427 if (append_number (state, arg, 0x10, "0123456789ABCDEF",
434 *arg = state->s - state->str;
441 if ((*state->append_char)(state, c))
445 if ( (*state->append_char)(state, '%')
446 || (*state->append_char)(state, c))
451 if ((*state->append_char) (state, c))
564 struct state state;
566 state.max_sz = max_sz;
567 state.sz = 1;
568 state.str = malloc(state.sz);
569 if (state.str == NULL) {
573 state.s = state.str;
574 state.theend = state.s + state.sz - 1;
575 state.append_char = as_append_char;
576 state.reserve = as_reserve;
578 st = xyzprintf (&state, format, args);
580 free (state.str);
586 *state.s = '\0';
587 len = state.s - state.str;
588 tmp = realloc (state.str, len+1);
590 free (state.str);
605 struct state state;
609 state.max_sz = 0;
610 state.sz = sz;
611 state.str = ustr;
612 state.s = ustr;
613 state.theend = ustr + sz - 1;
614 state.append_char = sn_append_char;
615 state.reserve = sn_reserve;
617 ret = xyzprintf (&state, format, args);
618 *state.s = '\0';
622 return state.s - state.str;