ascii-chat
Binary v0.16.50-198-g78f51665f
Library lib/v0.3.2-2240-g78f51665f
Video chat in your terminal
Loading...
Searching...
No Matches
formatter.c
Go to the documentation of this file.
1
9
10/* Storage capacities in elements; text buffers include the terminating NUL. */
11#define OPTIONS_MANPAGE_FORMATTER_DATE_BUFFER_SIZE 32
12#define OPTIONS_MANPAGE_FORMATTER_FULL_NAME_BUFFER_SIZE 256
13
15#include <ascii-chat/common.h>
16#include <libplatform/system.h>
17#include <stdio.h>
18#include <string.h>
19#include <time.h>
20
21// ============================================================================
22// Escape and Basic Formatting
23// ============================================================================
24
25const char *manpage_fmt_escape_groff(const char *str) {
26 // For simplicity, we'll just return the string as-is
27 // In a more robust implementation, we'd escape special characters
28 // But for man page content, most strings don't have problematic characters
29 return str ? str : "";
30}
31
32void manpage_fmt_write_section(FILE *f, const char *section_name) {
33 if (!f || !section_name) {
34 return;
35 }
36 fprintf(f, ".SH %s\n", section_name);
37}
38
40 if (!f) {
41 return;
42 }
43 fprintf(f, "\n");
44}
45
46void manpage_fmt_write_bold(FILE *f, const char *text) {
47 if (!f || !text) {
48 return;
49 }
50 fprintf(f, ".B %s\n", text);
51}
52
53void manpage_fmt_write_italic(FILE *f, const char *text) {
54 if (!f || !text) {
55 return;
56 }
57 fprintf(f, ".I %s\n", text);
58}
59
61 if (!f) {
62 return;
63 }
64 fprintf(f, ".TP\n");
65}
66
67void manpage_fmt_write_text(FILE *f, const char *text) {
68 if (!f) {
69 return;
70 }
71
72 if (text) {
73 fprintf(f, "%s\n", text);
74 } else {
75 fprintf(f, "\n");
76 }
77}
78
79void manpage_fmt_write_title(FILE *f, const char *program_name, const char *mode_name, const char *brief_description) {
80 if (!f || !program_name || !brief_description) {
81 return;
82 }
83
84 time_t now = time(NULL);
85 struct tm tm_buf;
86 platform_localtime(&now, &tm_buf);
88 strftime(date_str, sizeof(date_str), "%B %Y", &tm_buf);
89
90 // Build full program name (e.g., "ascii-chat-server" or just "ascii-chat")
92 if (mode_name) {
93 safe_snprintf(full_name, sizeof(full_name), "%s-%s", program_name, mode_name);
94 } else {
95 safe_snprintf(full_name, sizeof(full_name), "%s", program_name);
96 }
97
98 // .TH NAME SECTION DATE SOURCE MANUAL
99 // Section 1 = user commands, 5 = file formats
100 fprintf(f, ".TH %s 1 \"%s\" \"%s\" \"User Commands\"\n", full_name, date_str, program_name);
101 fprintf(f, ".SH NAME\n");
102 fprintf(f, ".B %s\n", full_name);
103 fprintf(f, "\\- %s\n", manpage_fmt_escape_groff(brief_description));
104 fprintf(f, "\n");
105}
void manpage_fmt_write_title(FILE *f, const char *program_name, const char *mode_name, const char *brief_description)
Write groff title/header (.TH directive).
Definition formatter.c:79
void manpage_fmt_write_section(FILE *f, const char *section_name)
Write a section header directive.
Definition formatter.c:32
const char * manpage_fmt_escape_groff(const char *str)
Escape special characters for groff output.
Definition formatter.c:25
void manpage_fmt_write_bold(FILE *f, const char *text)
Write text in bold format.
Definition formatter.c:46
#define OPTIONS_MANPAGE_FORMATTER_DATE_BUFFER_SIZE
Definition formatter.c:11
void manpage_fmt_write_tagged_paragraph(FILE *f)
Write a tagged paragraph header.
Definition formatter.c:60
void manpage_fmt_write_italic(FILE *f, const char *text)
Write text in italic format.
Definition formatter.c:53
#define OPTIONS_MANPAGE_FORMATTER_FULL_NAME_BUFFER_SIZE
Definition formatter.c:12
void manpage_fmt_write_blank_line(FILE *f)
Write a blank line (for spacing between sections).
Definition formatter.c:39
void manpage_fmt_write_text(FILE *f, const char *text)
Write plain text line (without directive).
Definition formatter.c:67
Groff/troff formatting utilities for man page generation.
⚙️ Common definitions, error codes, macros, and types shared throughout the application
🔤 String Manipulation and Shell Escaping Utilities
⏱️ High-precision timing utilities using sokol_time.h and uthash
int platform_localtime(const time_t *timer, struct tm *result)
Definition util.c:57