80 if (!config || config->num_examples == 0) {
81 char *buffer = SAFE_MALLOC(1,
char *);
88 srand((
unsigned int)((uintptr_t)config));
91 size_t buffer_capacity = 8192;
92 char *buffer = SAFE_MALLOC(buffer_capacity,
char *);
95 for (
size_t i = 0; i < config->num_examples; i++) {
96 const example_descriptor_t *example = &config->examples[i];
100 size_t num_modes = 0;
101 const char **mode_names = get_all_mode_names_from_bitmask(example->mode_bitmask, &num_modes);
104 if (offset + 512 >= buffer_capacity) {
105 buffer_capacity *= 2;
106 buffer = SAFE_REALLOC(buffer, buffer_capacity,
char *);
109 offset +=
safe_snprintf(buffer + offset, buffer_capacity - offset,
".TP\n");
110 offset +=
safe_snprintf(buffer + offset, buffer_capacity - offset,
".B ascii-chat");
114 size_t selected_mode = (size_t)rand() % num_modes;
115 if (mode_names[selected_mode]) {
116 offset +=
safe_snprintf(buffer + offset, buffer_capacity - offset,
" %s", mode_names[selected_mode]);
121 offset +=
safe_snprintf(buffer + offset, buffer_capacity - offset,
" %s", example->args);
123 offset +=
safe_snprintf(buffer + offset, buffer_capacity - offset,
"\n");
125 if (example->description) {
132 SAFE_FREE(mode_names);
136 offset +=
safe_snprintf(buffer + offset, buffer_capacity - offset,
"\n");
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.