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

Man page content merging and orchestration. More...

Go to the source code of this file.

Functions

char * manpage_merger_merge_options (const options_config_t *config, const parsed_section_t *existing_section)
 
char * manpage_merger_merge_environment (const options_config_t *config, const parsed_section_t *existing_section)
 
char * manpage_merger_merge_positional (const options_config_t *config, const parsed_section_t *existing_section)
 
asciichat_error_t manpage_merger_generate_usage (const options_config_t *config, char **out_content, size_t *out_len)
 
asciichat_error_t manpage_merger_generate_synopsis (const char *mode_name, char **out_content, size_t *out_len)
 
void manpage_merger_free_content (char *content)
 

Detailed Description

Man page content merging and orchestration.

Orchestrates the man page generation pipeline and handles intelligent merging of auto-generated content with manual sections.

Definition in file merger.c.

Function Documentation

◆ manpage_merger_free_content()

void manpage_merger_free_content ( char *  content)

Definition at line 179 of file merger.c.

179 {
180 if (content) {
181 SAFE_FREE(content);
182 }
183}

Referenced by options_config_generate_manpage_merged(), and options_config_generate_manpage_template().

◆ manpage_merger_generate_synopsis()

asciichat_error_t manpage_merger_generate_synopsis ( const char *  mode_name,
char **  out_content,
size_t *  out_len 
)

Definition at line 137 of file merger.c.

137 {
138 if (!out_content || !out_len) {
139 return SET_ERRNO(ERROR_INVALID_PARAM, "Invalid output parameters for manpage_merger_generate_synopsis");
140 }
141
142 // Allocate buffer for synopsis
143 size_t buffer_size = 512;
144 char *buffer = SAFE_MALLOC(buffer_size, char *);
145 size_t offset = 0;
146
147 // Note: Section header is already in template, don't duplicate it
148
149 if (mode_name) {
150 // Mode-specific synopsis
151 offset += safe_snprintf(buffer + offset, buffer_size - offset,
152 ".B ascii-chat\n"
153 ".I %s\n"
154 "[\\fIoptions\\fR]\n",
155 mode_name);
156 } else {
157 // Binary-level synopsis - show main modes
158 offset += safe_snprintf(buffer + offset, buffer_size - offset,
159 ".B ascii-chat\n"
160 "[\\fIoptions\\fR]\n"
161 "\n"
162 ".B ascii-chat\n"
163 "[\\fIoptions\\fR] \\fI<session-string>\\fR\n"
164 "\n"
165 ".B ascii-chat\n"
166 "[\\fIoptions\\fR] [\\fBserver\\fR | \\fBclient\\fR | \\fBmirror\\fR | "
167 "\\fBdiscovery-service\\fR] [\\fImode-options\\fR]\n");
168 }
169
170 offset += safe_snprintf(buffer + offset, buffer_size - offset, "\n");
171
172 *out_content = buffer;
173 *out_len = offset;
174
175 log_debug("Generated synopsis section (%zu bytes)", *out_len);
176 return ASCIICHAT_OK;
177}
int buffer_size
Size of circular buffer.
Definition grep.c:84
int safe_snprintf(char *buffer, size_t buffer_size, const char *format,...)
Safe formatted string printing to buffer.
Definition system.c:456

References buffer_size, and safe_snprintf().

Referenced by options_config_generate_manpage_merged(), and options_config_generate_manpage_template().

◆ manpage_merger_generate_usage()

asciichat_error_t manpage_merger_generate_usage ( const options_config_t *  config,
char **  out_content,
size_t *  out_len 
)

Definition at line 79 of file merger.c.

79 {
80 if (!out_content || !out_len) {
81 return SET_ERRNO(ERROR_INVALID_PARAM, "Invalid output parameters for manpage_merger_generate_usage");
82 }
83
84 if (!config || config->num_usage_lines == 0) {
85 *out_content = SAFE_MALLOC(1, char *);
86 (*out_content)[0] = '\0';
87 *out_len = 0;
88 return ASCIICHAT_OK;
89 }
90
91 // Allocate growing buffer for usage section
92 size_t buffer_capacity = 4096;
93 char *buffer = SAFE_MALLOC(buffer_capacity, char *);
94 size_t offset = 0;
95
96 for (size_t i = 0; i < config->num_usage_lines; i++) {
97 const usage_descriptor_t *usage = &config->usage_lines[i];
98
99 // Ensure buffer is large enough
100 if (offset + 512 >= buffer_capacity) {
101 buffer_capacity *= 2;
102 buffer = SAFE_REALLOC(buffer, buffer_capacity, char *);
103 }
104
105 offset += safe_snprintf(buffer + offset, buffer_capacity - offset, ".TP\n");
106 offset += safe_snprintf(buffer + offset, buffer_capacity - offset, ".B ascii-chat");
107 if (usage->mode) {
108 offset += safe_snprintf(buffer + offset, buffer_capacity - offset, " %s", usage->mode);
109 }
110 if (usage->positional) {
111 offset += safe_snprintf(buffer + offset, buffer_capacity - offset, " %s", usage->positional);
112 }
113 if (usage->show_options) {
114 // Use mode-specific options suffix for mode commands, regular options for binary-level
115 if (usage->mode && strcmp(usage->mode, "<mode>") != 0) {
116 offset += safe_snprintf(buffer + offset, buffer_capacity - offset, " [mode-options...]");
117 } else {
118 offset += safe_snprintf(buffer + offset, buffer_capacity - offset, " [options...]");
119 }
120 }
121 offset += safe_snprintf(buffer + offset, buffer_capacity - offset, "\n");
122
123 if (usage->description) {
124 offset += safe_snprintf(buffer + offset, buffer_capacity - offset, "%s\n", usage->description);
125 }
126 }
127
128 offset += safe_snprintf(buffer + offset, buffer_capacity - offset, "\n");
129
130 *out_content = buffer;
131 *out_len = offset;
132
133 log_debug("Generated usage section (%zu bytes)", offset);
134 return ASCIICHAT_OK;
135}
void usage(FILE *desc, asciichat_mode_t mode)

References safe_snprintf(), and usage().

Referenced by options_config_generate_manpage_merged(), and options_config_generate_manpage_template().

◆ manpage_merger_merge_environment()

char * manpage_merger_merge_environment ( const options_config_t *  config,
const parsed_section_t *  existing_section 
)

Definition at line 41 of file merger.c.

41 {
42 (void)existing_section; // Unused for now
43
44 if (!config) {
45 return NULL;
46 }
47
48 // For now, return empty content. In a full implementation, this would:
49 // 1. Extract environment variables from config options
50 // 2. Parse existing section for manual env var documentation
51 // 3. Merge and deduplicate
52 // 4. Return sorted, merged content
53
54 log_debug("Merging environment section (currently unimplemented - returns empty)");
55 char *content = SAFE_MALLOC(1, char *);
56 content[0] = '\0';
57 return content;
58}

◆ manpage_merger_merge_options()

char * manpage_merger_merge_options ( const options_config_t *  config,
const parsed_section_t *  existing_section 
)

Definition at line 22 of file merger.c.

22 {
23 (void)existing_section; // Unused for now
24
25 if (!config) {
26 return NULL;
27 }
28
29 // For now, return empty content. In a full implementation, this would:
30 // 1. Generate options from config
31 // 2. Parse existing section for manual options
32 // 3. Merge them by option name
33 // 4. Return merged content
34
35 log_debug("Merging options section (currently unimplemented - returns empty)");
36 char *content = SAFE_MALLOC(1, char *);
37 content[0] = '\0';
38 return content;
39}

◆ manpage_merger_merge_positional()

char * manpage_merger_merge_positional ( const options_config_t *  config,
const parsed_section_t *  existing_section 
)

Definition at line 60 of file merger.c.

60 {
61 (void)existing_section; // Unused for now
62
63 if (!config) {
64 return NULL;
65 }
66
67 // For now, return empty content. In a full implementation, this would:
68 // 1. Generate positional arguments from config
69 // 2. Parse existing section for manual content
70 // 3. Merge intelligently
71 // 4. Return merged content
72
73 log_debug("Merging positional section (currently unimplemented - returns empty)");
74 char *content = SAFE_MALLOC(1, char *);
75 content[0] = '\0';
76 return content;
77}