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

Man page resource loading and management. More...

Go to the source code of this file.

Functions

asciichat_error_t manpage_resources_load (manpage_resources_t *resources)
 
void manpage_resources_destroy (manpage_resources_t *resources)
 
bool manpage_resources_is_valid (const manpage_resources_t *resources)
 

Detailed Description

Man page resource loading and management.

Abstracts loading man page resources from either embedded (production) or filesystem (development) sources. Provides a clean interface that hides the complexity of the underlying embedded_resources API.

Definition in file resources.c.

Function Documentation

◆ manpage_resources_destroy()

void manpage_resources_destroy ( manpage_resources_t *  resources)

Definition at line 151 of file resources.c.

151 {
152 if (!resources) {
153 return;
154 }
155
156 // Only free content if it was allocated (i.e., loaded from filesystem in debug builds)
157 if (resources->allocated) {
158#ifndef NDEBUG
159 // In debug builds, template and content were allocated by load_single_resource
160 if (resources->template_content) {
161 char *template_ptr = (char *)resources->template_content;
162 SAFE_FREE(template_ptr);
163 }
164 if (resources->content_sections) {
165 char *content_ptr = (char *)resources->content_sections;
166 SAFE_FREE(content_ptr);
167 }
168#endif
169 }
170
171 // Clear the structure
172 resources->template_content = NULL;
173 resources->template_len = 0;
174 resources->content_sections = NULL;
175 resources->content_len = 0;
176 resources->is_embedded = false;
177 resources->allocated = false;
178}

Referenced by options_config_generate_manpage_merged().

◆ manpage_resources_is_valid()

bool manpage_resources_is_valid ( const manpage_resources_t *  resources)

Definition at line 180 of file resources.c.

180 {
181 if (!resources) {
182 return false;
183 }
184
185 // Resources are valid if template is loaded (content is now optional/merged into template)
186 return resources->template_content != NULL && resources->template_len > 0;
187}

Referenced by options_config_generate_manpage_merged().

◆ manpage_resources_load()

asciichat_error_t manpage_resources_load ( manpage_resources_t *  resources)

Definition at line 107 of file resources.c.

107 {
108 if (!resources) {
109 return SET_ERRNO(ERROR_INVALID_PARAM, "resources pointer cannot be NULL");
110 }
111
112 // Initialize to safe state
113 resources->template_content = NULL;
114 resources->template_len = 0;
115 resources->content_sections = NULL;
116 resources->content_len = 0;
117 resources->is_embedded = false;
118 resources->allocated = false;
119
120 // Load template resource
121 asciichat_error_t err = load_single_resource(&resources->template_content, &resources->template_len,
122 get_manpage_template, "man page template");
123 if (err != ASCIICHAT_OK) {
124 return err;
125 }
126
127 // Content is now merged into template - no separate content file needed
128 // Set to NULL so cleanup doesn't try to free a string literal
129 resources->content_sections = NULL;
130 resources->content_len = 0;
131
132 // Determine if resources came from embedded binary
133 // In production (NDEBUG), both would be embedded; in development, both would be files
134#ifdef NDEBUG
135 resources->is_embedded = true;
136#else
137 resources->is_embedded = false;
138#endif
139
140 // Mark that we may have allocated memory (only in debug builds for filesystem reads)
141#ifdef NDEBUG
142 resources->allocated = false;
143#else
144 resources->allocated = true;
145#endif
146
147 log_debug("Resources loaded successfully (embedded=%d, allocated=%d)", resources->is_embedded, resources->allocated);
148 return ASCIICHAT_OK;
149}
int get_manpage_template(FILE **out_file, const char **out_content, size_t *out_len)

References get_manpage_template().

Referenced by options_config_generate_manpage_merged().