16 if (!config || config->num_positional_args == 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_positional_args; i++) {
28 const positional_arg_descriptor_t *pos_arg = &config->positional_args[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 %s\n", pos_arg->name);
39 if (pos_arg->help_text) {
45 if (pos_arg->num_examples > 0) {
46 offset +=
safe_snprintf(buffer + offset, buffer_capacity - offset,
".RS\n");
47 offset +=
safe_snprintf(buffer + offset, buffer_capacity - offset,
".B Examples:\n");
48 offset +=
safe_snprintf(buffer + offset, buffer_capacity - offset,
".RS\n");
49 offset +=
safe_snprintf(buffer + offset, buffer_capacity - offset,
".nf\n");
50 for (
size_t j = 0; j < pos_arg->num_examples; j++) {
51 offset +=
safe_snprintf(buffer + offset, buffer_capacity - offset,
"%s\n",
54 offset +=
safe_snprintf(buffer + offset, buffer_capacity - offset,
".fi\n");
55 offset +=
safe_snprintf(buffer + offset, buffer_capacity - offset,
".RE\n");
56 offset +=
safe_snprintf(buffer + offset, buffer_capacity - offset,
".RE\n");
60 log_debug(
"Generated POSITIONAL ARGUMENTS 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.