* Rebuild a format string in a gettext-friendly format. This function * is exposed to tools can perform this function. See xo(1). */
| 6556 | * is exposed to tools can perform this function. See xo(1). |
| 6557 | */ |
| 6558 | char * |
| 6559 | xo_simplify_format (xo_handle_t *xop, const char *fmt, int with_numbers, |
| 6560 | xo_simplify_field_func_t field_cb) |
| 6561 | { |
| 6562 | xop = xo_default(xop); |
| 6563 | |
| 6564 | xop->xo_columns = 0; /* Always reset it */ |
| 6565 | xop->xo_errno = errno; /* Save for "%m" */ |
| 6566 | |
| 6567 | unsigned max_fields = xo_count_fields(xop, fmt); |
| 6568 | xo_field_info_t fields[max_fields]; |
| 6569 | |
| 6570 | bzero(fields, max_fields * sizeof(fields[0])); |
| 6571 | |
| 6572 | if (xo_parse_fields(xop, fields, max_fields, fmt)) |
| 6573 | return NULL; /* Warning already displayed */ |
| 6574 | |
| 6575 | xo_buffer_t xb; |
| 6576 | xo_buf_init(&xb); |
| 6577 | |
| 6578 | if (with_numbers) |
| 6579 | xo_gettext_finish_numbering_fields(xop, fmt, fields); |
| 6580 | |
| 6581 | if (xo_gettext_simplify_format(xop, &xb, fields, -1, fmt, field_cb)) |
| 6582 | return NULL; |
| 6583 | |
| 6584 | return xb.xb_bufp; |
| 6585 | } |
| 6586 | |
| 6587 | xo_ssize_t |
| 6588 | xo_emit_hv (xo_handle_t *xop, const char *fmt, va_list vap) |
no test coverage detected