Home | History | Annotate | Download | only in missing

Lines Matching full:state

63  * Common state
66 struct state {
72 int (*append_char)(struct state *, unsigned char);
73 int (*reserve)(struct state *, size_t);
79 sn_reserve (struct state *state, size_t n)
81 return state->s + n > state->theend;
85 sn_append_char (struct state *state, unsigned char c)
87 if (sn_reserve (state, 1)) {
90 *state->s++ = c;
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,
149 if((*state->append_char)(state, rep[num % base]))
157 if((*state->append_char)(state, '0'))
170 if((*state->append_char)(state, '0'))
178 if((*state->append_char)(state, rep[10] + 23)) /* XXX */
180 if((*state->append_char)(state, '0'))
185 if((*state->append_char)(state, '-'))
189 if((*state->append_char)(state, '+'))
193 if((*state->append_char)(state, ' '))
200 char c = state->s[-i-1];
201 state->s[-i-1] = state->s[-len+i];
202 state->s[-len+i] = c;
206 if((*state->append_char)(state, ' '))
213 char c = state->s[-i-1];
214 state->s[-i-1] = state->s[-len+i];
215 state->s[-len+i] = c;
222 append_string (struct state *state,
234 if((*state->append_char) (state, ' '))
238 if ((*state->append_char) (state, *arg++))
242 if ((*state->append_char) (state, *arg++))
247 if((*state->append_char) (state, ' '))
253 append_char(struct state *state,
259 if((*state->append_char) (state, ' '))
262 if((*state->append_char) (state, arg))
265 if((*state->append_char) (state, ' '))
288 xyzprintf (struct state *state, const char *char_format, va_list ap)
361 if(append_char(state, va_arg(ap, int), width, flags))
365 if (append_string(state,
386 if (append_number (state, num, 10, "0123456789",
396 if (append_number (state, arg, 10, "0123456789",
406 if (append_number (state, arg, 010, "01234567",
416 if (append_number (state, arg, 0x10, "0123456789abcdef",
426 if (append_number (state, arg, 0x10, "0123456789ABCDEF",
434 if (append_number (state, arg, 0x10, "0123456789ABCDEF",
441 *arg = state->s - state->str;
448 if ((*state->append_char)(state, c))
452 if ( (*state->append_char)(state, '%')
453 || (*state->append_char)(state, c))
458 if ((*state->append_char) (state, c))
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;
616 state.max_sz = 0;
617 state.sz = sz;
618 state.str = ustr;
619 state.s = ustr;
620 state.theend = ustr + sz - 1;
621 state.append_char = sn_append_char;
622 state.reserve = sn_reserve;
624 ret = xyzprintf (&state, format, args);
625 *state.s = '\0';
629 return state.s - state.str;