16 if (!config || config->num_usage_lines == 0) {
17 char *buffer = SAFE_MALLOC(1,
char *);
23 size_t buffer_capacity = 4096;
24 char *buffer = SAFE_MALLOC(buffer_capacity,
char *);
27 for (
size_t i = 0; i < config->num_usage_lines; i++) {
28 const usage_descriptor_t *
usage = &config->usage_lines[i];
31 if (offset + 512 >= buffer_capacity) {
33 buffer = SAFE_REALLOC(buffer, buffer_capacity,
char *);
36 offset +=
safe_snprintf(buffer + offset, buffer_capacity - offset,
".TP\n");
37 offset +=
safe_snprintf(buffer + offset, buffer_capacity - offset,
".B ascii-chat");
39 offset +=
safe_snprintf(buffer + offset, buffer_capacity - offset,
" %s",
usage->mode);
41 if (
usage->positional) {
42 offset +=
safe_snprintf(buffer + offset, buffer_capacity - offset,
" %s",
usage->positional);
44 if (
usage->show_options) {
45 offset +=
safe_snprintf(buffer + offset, buffer_capacity - offset,
" [options...]");
47 offset +=
safe_snprintf(buffer + offset, buffer_capacity - offset,
"\n");
49 if (
usage->description) {
55 offset +=
safe_snprintf(buffer + offset, buffer_capacity - offset,
"\n");
57 log_debug(
"Generated USAGE section (%zu bytes)", offset);
const char * escape_groff_special(const char *str)
int safe_snprintf(char *buffer, size_t buffer_size, const char *format,...)
Safe formatted string printing to buffer.