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 sn_reserve (struct state *state, size_t n) in sn_reserve() argument
74 return state->s + n > state->theend; in sn_reserve()
78 sn_append_char (struct state *state, unsigned char c) in sn_append_char() argument
80 if (sn_reserve (state, 1)) { in sn_append_char()
83 *state->s++ = c; in sn_append_char()
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, in append_number() argument
142 if((*state->append_char)(state, rep[num % base])) in append_number()
150 if((*state->append_char)(state, '0')) in append_number()
163 if((*state->append_char)(state, '0')) in append_number()
171 if((*state->append_char)(state, rep[10] + 23)) /* XXX */ in append_number()
173 if((*state->append_char)(state, '0')) in append_number()
178 if((*state->append_char)(state, '-')) in append_number()
182 if((*state->append_char)(state, '+')) in append_number()
186 if((*state->append_char)(state, ' ')) in append_number()
193 char c = state->s[-i-1]; in append_number()
194 state->s[-i-1] = state->s[-len+i]; in append_number()
195 state->s[-len+i] = c; in append_number()
199 if((*state->append_char)(state, ' ')) in append_number()
206 char c = state->s[-i-1]; in append_number()
207 state->s[-i-1] = state->s[-len+i]; in append_number()
208 state->s[-len+i] = c; in append_number()
215 append_string (struct state *state, in append_string() argument
227 if((*state->append_char) (state, ' ')) in append_string()
231 if ((*state->append_char) (state, *arg++)) in append_string()
235 if ((*state->append_char) (state, *arg++)) in append_string()
240 if((*state->append_char) (state, ' ')) in append_string()
246 append_char(struct state *state, in append_char() argument
252 if((*state->append_char) (state, ' ')) in append_char()
255 if((*state->append_char) (state, arg)) in append_char()
258 if((*state->append_char) (state, ' ')) in append_char()
281 xyzprintf (struct state *state, const char *char_format, va_list ap) in xyzprintf() argument
354 if(append_char(state, va_arg(ap, int), width, flags)) in xyzprintf()
358 if (append_string(state, in xyzprintf()
379 if (append_number (state, num, 10, "0123456789", in xyzprintf()
389 if (append_number (state, arg, 10, "0123456789", in xyzprintf()
399 if (append_number (state, arg, 010, "01234567", in xyzprintf()
409 if (append_number (state, arg, 0x10, "0123456789abcdef", in xyzprintf()
419 if (append_number (state, arg, 0x10, "0123456789ABCDEF", in xyzprintf()
427 if (append_number (state, arg, 0x10, "0123456789ABCDEF", in xyzprintf()
434 *arg = state->s - state->str; in xyzprintf()
441 if ((*state->append_char)(state, c)) in xyzprintf()
445 if ( (*state->append_char)(state, '%') in xyzprintf()
446 || (*state->append_char)(state, c)) in xyzprintf()
451 if ((*state->append_char) (state, c)) in xyzprintf()
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; in pcap_vsnprintf() local
609 state.max_sz = 0; in pcap_vsnprintf()
610 state.sz = sz; in pcap_vsnprintf()
611 state.str = ustr; in pcap_vsnprintf()
612 state.s = ustr; in pcap_vsnprintf()
613 state.theend = ustr + sz - 1; in pcap_vsnprintf()
614 state.append_char = sn_append_char; in pcap_vsnprintf()
615 state.reserve = sn_reserve; in pcap_vsnprintf()
617 ret = xyzprintf (&state, format, args); in pcap_vsnprintf()
618 *state.s = '\0'; in pcap_vsnprintf()
622 return state.s - state.str; in pcap_vsnprintf()