ascii-chat 0.8.38
Real-time terminal-based video chat with ASCII art conversion
Loading...
Searching...
No Matches
positional.c File Reference

POSITIONAL ARGUMENTS section generator for man pages. More...

Go to the source code of this file.

Functions

char * manpage_content_generate_positional (const options_config_t *config)
 
void manpage_content_free_positional (char *content)
 

Detailed Description

POSITIONAL ARGUMENTS section generator for man pages.

Definition in file positional.c.

Function Documentation

◆ manpage_content_free_positional()

void manpage_content_free_positional ( char *  content)

Definition at line 64 of file positional.c.

64 {
65 if (content) {
66 SAFE_FREE(content);
67 }
68}

Referenced by options_config_generate_manpage_merged(), and options_config_generate_manpage_template().

◆ manpage_content_generate_positional()

char * manpage_content_generate_positional ( const options_config_t *  config)

Definition at line 15 of file positional.c.

15 {
16 if (!config || config->num_positional_args == 0) {
17 char *buffer = SAFE_MALLOC(1, char *);
18 buffer[0] = '\0';
19 return buffer;
20 }
21
22 // Allocate growing buffer for positional section
23 size_t buffer_capacity = 4096;
24 char *buffer = SAFE_MALLOC(buffer_capacity, char *);
25 size_t offset = 0;
26
27 for (size_t i = 0; i < config->num_positional_args; i++) {
28 const positional_arg_descriptor_t *pos_arg = &config->positional_args[i];
29
30 // Ensure buffer is large enough
31 if (offset + 512 >= buffer_capacity) {
32 buffer_capacity *= 2;
33 buffer = SAFE_REALLOC(buffer, buffer_capacity, char *);
34 }
35
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);
38
39 if (pos_arg->help_text) {
40 offset +=
41 safe_snprintf(buffer + offset, buffer_capacity - offset, "%s\n", escape_groff_special(pos_arg->help_text));
42 }
43
44 // Add examples if present
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",
52 escape_groff_special(pos_arg->examples[j]));
53 }
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");
57 }
58 }
59
60 log_debug("Generated POSITIONAL ARGUMENTS section (%zu bytes)", offset);
61 return buffer;
62}
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.
Definition system.c:456

References escape_groff_special(), and safe_snprintf().

Referenced by options_config_generate_manpage_merged(), and options_config_generate_manpage_template().