Lines Matching defs:abp
50 asr_buf_t *abp;
52 if ((abp = asr_zalloc(sizeof (asr_buf_t))) == NULL)
55 abp->asrb_allocated = len;
56 abp->asrb_data = asr_alloc(len);
58 if (abp->asrb_data == NULL && len != 0) {
59 free(abp);
64 abp->asrb_data[0] = '\0';
66 abp->asrb_error = EASR_NONE;
68 return (abp);
77 asr_buf_grow(asr_buf_t *abp, size_t len)
82 newlen = abp->asrb_allocated * 2;
83 if (abp->asrb_length + len + 1 > newlen)
84 newlen = abp->asrb_length + len + 1;
87 if (abp->asrb_error == EASR_NONE)
88 abp->asrb_error = EASR_NOMEM;
92 bcopy(abp->asrb_data, newdata, abp->asrb_length);
93 free(abp->asrb_data);
95 abp->asrb_data = newdata;
96 abp->asrb_allocated = newlen;
106 asr_buf_append(asr_buf_t *abp, const char *fmt, ...)
115 if (abp->asrb_length + len >= abp->asrb_allocated &&
116 asr_buf_grow(abp, len) != 0)
120 (void) vsnprintf(abp->asrb_data + abp->asrb_length,
121 abp->asrb_allocated - abp->asrb_length, fmt, ap);
124 abp->asrb_length += len;
132 asr_buf_vappend(asr_buf_t *abp, const char *fmt, va_list ap)
137 if (abp->asrb_length + len >= abp->asrb_allocated &&
138 asr_buf_grow(abp, len) != 0)
141 (void) vsnprintf(abp->asrb_data + abp->asrb_length,
142 abp->asrb_allocated - abp->asrb_length, fmt, ap);
144 abp->asrb_length += len;
153 asr_buf_append_str(asr_buf_t *abp, const char *str)
158 if (abp->asrb_length + glen >= abp->asrb_allocated &&
159 asr_buf_grow(abp, glen) != 0)
162 (void) strcpy(abp->asrb_data + abp->asrb_length, str);
163 abp->asrb_length += len;
172 asr_buf_append_buf(asr_buf_t *abp, const asr_buf_t *buf)
177 if (abp->asrb_length + glen >= abp->asrb_allocated &&
178 asr_buf_grow(abp, glen) != 0)
180 bcopy(buf->asrb_data, abp->asrb_data + abp->asrb_length, len);
181 abp->asrb_length += len;
182 abp->asrb_data[abp->asrb_length] = '\0';
190 asr_buf_append_raw(asr_buf_t *abp, const void *ptr, size_t sz)
193 if (abp->asrb_length + len >= abp->asrb_allocated &&
194 asr_buf_grow(abp, len) != 0)
197 bcopy(ptr, abp->asrb_data + abp->asrb_length, sz);
198 abp->asrb_length += sz;
199 abp->asrb_data[abp->asrb_length] = '\0';
208 asr_buf_append_char(asr_buf_t *abp, const char ch)
210 if (abp->asrb_length + 1 >= abp->asrb_allocated &&
211 asr_buf_grow(abp, ASRB_GROW_LEN) != 0)
214 abp->asrb_data[abp->asrb_length] = ch;
215 abp->asrb_length++;
226 asr_buf_terminate(asr_buf_t *abp)
228 if (abp->asrb_length + 1 >= abp->asrb_allocated &&
229 asr_buf_grow(abp, ASRB_GROW_LEN) != 0)
232 abp->asrb_data[abp->asrb_length] = '\0';
240 asr_buf_trim(asr_buf_t *abp)
243 char *data = abp->asrb_data;
245 for (r = 0; r < abp->asrb_length; r++) {
251 for (i = r, j = 0; i < abp->asrb_length; i++, j++) {
254 abp->asrb_length -= r;
255 data[abp->asrb_length] = '\0';
258 for (i = abp->asrb_length - 1; i >= 0; i--) {
263 r = abp->asrb_length - i - 1;
265 abp->asrb_length -= r;
266 data[abp->asrb_length] = '\0';
275 asr_buf_free(asr_buf_t *abp)
277 if (abp != NULL) {
278 free(abp->asrb_data);
279 abp->asrb_data = NULL;
280 free(abp);
289 asr_buf_free_struct(asr_buf_t *abp)
292 if (abp != NULL) {
293 data = abp->asrb_data;
294 free(abp);
304 asr_buf_reset(asr_buf_t *abp)
306 if (abp != NULL) {
307 if (abp->asrb_length > 0) {
308 abp->asrb_length = 0;
309 abp->asrb_data[0] = '\0';
318 asr_buf_data(asr_buf_t *abp)
320 return (abp == NULL ? NULL : abp->asrb_data);
327 asr_buf_size(asr_buf_t *abp)
329 return (abp == NULL ? 0 : abp->asrb_length);
336 asr_buf_append_xml_nval(asr_buf_t *abp, const char *value, int n)
343 limit = abp->asrb_length + n;
349 if (limit > 0 && (abp->asrb_length + 4) > limit)
351 err |= asr_buf_append(abp, "<");
354 if (limit > 0 && (abp->asrb_length + 4) > limit)
356 err |= asr_buf_append(abp, ">");
359 if (limit > 0 && (abp->asrb_length + 5) > limit)
361 err |= asr_buf_append(abp, "&");
364 if (limit > 0 && (abp->asrb_length + 6) > limit)
366 err |= asr_buf_append(abp, """);
369 if (limit > 0 && (abp->asrb_length + 6) > limit)
371 err |= asr_buf_append(abp, "'");
379 if (limit > 0 && (abp->asrb_length + 1) > limit)
381 err |= asr_buf_append_char(abp, ch);
388 asr_buf_append_xml_val(asr_buf_t *abp, const char *value)
390 return (asr_buf_append_xml_nval(abp, value, -1));
399 asr_buf_append_xml_token(asr_buf_t *abp, const char *value)
420 err |= asr_buf_append_char(abp, ch);
423 err |= asr_buf_terminate(abp);
431 asr_buf_append_xml_elem(asr_buf_t *abp, unsigned int pad, const char *name)
434 err |= asr_buf_append_pad(abp, pad);
435 err |= asr_buf_append(abp, "<%s>\n", name);
443 asr_buf_append_xml_end(asr_buf_t *abp, unsigned int pad, const char *name)
446 err |= asr_buf_append_pad(abp, pad);
447 err |= asr_buf_append(abp, "</%s>\n", name);
456 asr_buf_append_xml_nv(asr_buf_t *abp, unsigned int pad,
461 err |= asr_buf_append_pad(abp, pad);
463 err |= asr_buf_append(abp, "<%s/>\n", name);
465 err |= asr_buf_append(abp, "<%s>", name);
466 err |= asr_buf_append_xml_val(abp, value);
467 err |= asr_buf_append(abp, "</%s>\n", name);
478 asr_buf_append_xml_nnv(asr_buf_t *abp, unsigned int pad,
483 err |= asr_buf_append_pad(abp, pad);
485 err |= asr_buf_append(abp, "<%s/>\n", name);
487 err |= asr_buf_append(abp, "<%s>", name);
488 err |= asr_buf_append_xml_nval(abp, value, n);
489 err |= asr_buf_append(abp, "</%s>\n", name);
500 asr_buf_append_xml_nb(asr_buf_t *abp, unsigned int pad,
504 abp, pad, name, value ? "true" : "false"));
513 asr_buf_append_xml_nvtoken(asr_buf_t *abp, unsigned int pad,
518 err |= asr_buf_append_pad(abp, pad);
520 err |= asr_buf_append(abp, "<%s/>\n", name);
522 err |= asr_buf_append(abp, "<%s>", name);
523 err |= asr_buf_append_xml_token(abp, value);
524 err |= asr_buf_append(abp, "</%s>\n", name);
535 asr_buf_append_xml_anv(asr_buf_t *abp, unsigned int pad,
541 return (asr_buf_append_xml_nv(abp, pad, name, value));
544 err |= asr_buf_append_pad(abp, pad);
545 err |= asr_buf_append(abp, "<%s %s='", name, aname);
546 err |= asr_buf_append_xml_val(abp, avalue);
547 err |= asr_buf_append(abp, "'>");
548 err |= asr_buf_append_xml_val(abp, value);
549 err |= asr_buf_append(abp, "</%s>\n", name);
596 asr_buf_append_pad(asr_buf_t *abp, unsigned int pad)
600 err = asr_buf_append_char(abp, '\t');
611 asr_buf_readln(asr_buf_t *abp, FILE *file)
614 int rollback = abp->asrb_length;
619 err = asr_buf_append_char(abp, c);
622 (void) asr_buf_terminate(abp);
626 if (err != 0 && asr_buf_terminate(abp) != 0) {
627 abp->asrb_length = rollback;
629 (void) asr_buf_terminate(abp);