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

Man page template parsing and section extraction implementation. More...

Go to the source code of this file.

Functions

asciichat_error_t manpage_parser_parse_file (FILE *f, parsed_section_t **out_sections, size_t *out_count)
 
asciichat_error_t manpage_parser_parse_memory (const char *content, size_t content_len, parsed_section_t **out_sections, size_t *out_count)
 
void manpage_parser_free_sections (parsed_section_t *sections, size_t count)
 
const parsed_section_t * manpage_parser_find_section (const parsed_section_t *sections, size_t count, const char *section_name)
 

Detailed Description

Man page template parsing and section extraction implementation.

Parses man page templates to extract sections and detect their types (AUTO-generated, MANUAL, or MERGE sections).

Definition in file parser.c.

Function Documentation

◆ manpage_parser_find_section()

const parsed_section_t * manpage_parser_find_section ( const parsed_section_t *  sections,
size_t  count,
const char *  section_name 
)

Definition at line 397 of file parser.c.

398 {
399 if (!sections || !section_name) {
400 return NULL;
401 }
402
403 for (size_t i = 0; i < count; i++) {
404 if (sections[i].section_name && strcmp(sections[i].section_name, section_name) == 0) {
405 return &sections[i];
406 }
407 }
408
409 return NULL;
410}

Referenced by find_section().

◆ manpage_parser_free_sections()

void manpage_parser_free_sections ( parsed_section_t *  sections,
size_t  count 
)

Definition at line 380 of file parser.c.

380 {
381 if (!sections) {
382 return;
383 }
384
385 for (size_t i = 0; i < count; i++) {
386 if (sections[i].section_name) {
387 SAFE_FREE(sections[i].section_name);
388 }
389 if (sections[i].content) {
390 SAFE_FREE(sections[i].content);
391 }
392 }
393
394 SAFE_FREE(sections);
395}

Referenced by free_parsed_sections().

◆ manpage_parser_parse_file()

asciichat_error_t manpage_parser_parse_file ( FILE *  f,
parsed_section_t **  out_sections,
size_t *  out_count 
)

Definition at line 339 of file parser.c.

339 {
340 if (!f || !out_sections || !out_count) {
341 return SET_ERRNO(ERROR_INVALID_PARAM, "Invalid parameters for manpage_parser_parse_file");
342 }
343
344 return parse_sections_internal(f, out_sections, out_count);
345}

Referenced by parse_manpage_sections().

◆ manpage_parser_parse_memory()

asciichat_error_t manpage_parser_parse_memory ( const char *  content,
size_t  content_len,
parsed_section_t **  out_sections,
size_t *  out_count 
)

Definition at line 347 of file parser.c.

348 {
349 if (!content || content_len == 0 || !out_sections || !out_count) {
350 return SET_ERRNO(ERROR_INVALID_PARAM, "Invalid parameters for manpage_parser_parse_memory");
351 }
352
353 // Create temporary file from memory
354 FILE *tmp = platform_tmpfile();
355 if (!tmp) {
356 return SET_ERRNO_SYS(ERROR_CONFIG, "Failed to create temporary file for memory parsing");
357 }
358
359 // Write content to temporary file
360 // Write content_len + 1 to include the null terminator.
361 // The embedded string is content_len + 1 bytes (content_len chars + null terminator).
362 // platform_getline() needs the null terminator to properly handle EOF.
363 size_t bytes_to_write = content_len + 1;
364 size_t written = fwrite(content, 1, bytes_to_write, tmp);
365 if (written != bytes_to_write) {
366 fclose(tmp);
367 return SET_ERRNO_SYS(ERROR_CONFIG, "Failed to write complete content to temporary file");
368 }
369
370 // Rewind to beginning for reading
371 rewind(tmp);
372
373 // Parse using common function
374 asciichat_error_t err = parse_sections_internal(tmp, out_sections, out_count);
375 fclose(tmp);
376
377 return err;
378}
FILE * platform_tmpfile(void)

References platform_tmpfile().