| 1 |
#include <libconfig.h> |
| 2 |
#include <uthash.h> |
| 3 |
#include "compiler.h" |
| 4 |
#include "transition/script.h" |
| 5 |
#include "transition/script_internal.h" |
| 6 |
#include "utils/dynarr.h" |
| 7 |
#include "wm/win.h" |
| 8 |
|
| 9 |
enum knob_type { |
| 10 |
KNOB_NUMBER, |
| 11 |
KNOB_CHOICE, |
| 12 |
}; |
| 13 |
|
| 14 |
struct knob { |
| 15 |
UT_hash_handle hh; |
| 16 |
const char *name; |
| 17 |
enum knob_type type; |
| 18 |
|
| 19 |
union { |
| 20 |
struct { |
| 21 |
double default_value; |
| 22 |
} number; |
| 23 |
struct { |
| 24 |
char **choices; |
| 25 |
unsigned n_choices; |
| 26 |
unsigned default_choice; |
| 27 |
}; |
| 28 |
}; |
| 29 |
bool emitted; |
| 30 |
}; |
| 31 |
|
| 32 |
struct placeholder { |
| 33 |
struct knob *source; |
| 34 |
double *value_for_choices; |
| 35 |
}; |
| 36 |
|
| 37 |
bool config_extra_get_float(config_setting_t *setting, double *value) { |
| 38 |
if (config_setting_type(setting) != CONFIG_TYPE_FLOAT && |
| 39 |
config_setting_type(setting) != CONFIG_TYPE_INT && |
| 40 |
config_setting_type(setting) != CONFIG_TYPE_INT64) { |
| 41 |
return false; |
| 42 |
} |
| 43 |
*value = config_setting_get_float(setting); |
| 44 |
return true; |
| 45 |
} |
| 46 |
|
| 47 |
bool config_extra_get_int(config_setting_t *setting, int *value) { |
| 48 |
if (config_setting_type(setting) != CONFIG_TYPE_INT && |
| 49 |
config_setting_type(setting) != CONFIG_TYPE_INT64) { |
| 50 |
return false; |
| 51 |
} |
| 52 |
*value = config_setting_get_int(setting); |
| 53 |
return true; |
| 54 |
} |
| 55 |
|
| 56 |
char *sanitized_name(const char *name) { |
| 57 |
char *ret = strdup(name); |
| 58 |
for (char *p = ret; *p; p++) { |
| 59 |
if (*p == '-') { |
| 60 |
*p = '_'; |
| 61 |
} |
| 62 |
} |
| 63 |
return ret; |
| 64 |
} |
| 65 |
|
| 66 |
void free_charp(void *p) { |
| 67 |
free(*(char **)p); |
| 68 |
} |
| 69 |
|
| 70 |
#define scopedp(type) cleanup(free_##type##p) type * |
| 71 |
|
| 72 |
#define MAX_PLACEHOLDERS 10 |
| 73 |
|
| 74 |
void codegen(const char *name, const char *body, const struct placeholder *placeholders) { |
| 75 |
auto ident = sanitized_name(name); |
| 76 |
printf("static struct script *script_template__%s(int *output_slots)\n%s\n", |
| 77 |
ident, body); |
| 78 |
printf("static bool win_script_preset__%s(struct win_script *output, " |
| 79 |
"config_setting_t *setting) {\n", |
| 80 |
ident); |
| 81 |
printf(" output->script = script_template__%s(output->output_indices);\n", ident); |
| 82 |
for (size_t i = 0; i < MAX_PLACEHOLDERS; i++) { |
| 83 |
if (placeholders[i].source == NULL || placeholders[i].source->emitted) { |
| 84 |
continue; |
| 85 |
} |
| 86 |
|
| 87 |
auto knob = placeholders[i].source; |
| 88 |
scopedp(char) knob_ident = sanitized_name(knob->name); |
| 89 |
knob->emitted = true; |
| 90 |
if (knob->type == KNOB_NUMBER) { |
| 91 |
printf(" double knob_%s = %a;\n", knob_ident, |
| 92 |
knob->number.default_value); |
| 93 |
printf(" config_setting_lookup_float(setting, \"%s\", " |
| 94 |
"&knob_%s);\n", |
| 95 |
knob->name, knob_ident); |
| 96 |
continue; |
| 97 |
} |
| 98 |
printf(" const char *knob_%s = \"%s\";\n", knob_ident, |
| 99 |
knob->choices[knob->default_choice]); |
| 100 |
printf(" config_setting_lookup_string(setting, \"%s\", &knob_%s);\n", |
| 101 |
knob->name, knob_ident); |
| 102 |
for (unsigned j = 0; j < MAX_PLACEHOLDERS; j++) { |
| 103 |
if (placeholders[j].source != knob) { |
| 104 |
continue; |
| 105 |
} |
| 106 |
printf(" double placeholder%u_%s;\n", j, knob_ident); |
| 107 |
} |
| 108 |
for (unsigned j = 0; j < knob->n_choices; j++) { |
| 109 |
printf(" if (strcmp(knob_%s, \"%s\") == 0) {\n", knob_ident, |
| 110 |
knob->choices[j]); |
| 111 |
for (unsigned k = 0; k < MAX_PLACEHOLDERS; k++) { |
| 112 |
if (placeholders[k].source != knob) { |
| 113 |
continue; |
| 114 |
} |
| 115 |
printf(" placeholder%u_%s = %a;\n", k, knob_ident, |
| 116 |
placeholders[k].value_for_choices[j]); |
| 117 |
} |
| 118 |
printf(" } else "); |
| 119 |
} |
| 120 |
printf("{\n"); |
| 121 |
printf(" log_error(\"Invalid choice \\\"%%s\\\" for " |
| 122 |
"option \\\"%s\\\". Line %%d.\", knob_%s, " |
| 123 |
"config_setting_source_line(config_setting_get_member(setting, " |
| 124 |
"\"%s\")));\n", |
| 125 |
knob->name, knob_ident, knob->name); |
| 126 |
printf(" log_error(\" Valid ones are: "); |
| 127 |
for (unsigned j = 0; j < knob->n_choices; j++) { |
| 128 |
printf("%s\\\"%s\\\"", j ? ", " : "", knob->choices[j]); |
| 129 |
} |
| 130 |
printf("\");\n"); |
| 131 |
printf(" script_free(output->script);\n"); |
| 132 |
printf(" output->script = NULL;\n"); |
| 133 |
printf(" return false;\n"); |
| 134 |
printf(" }\n"); |
| 135 |
} |
| 136 |
printf(" struct script_specialization_context spec[] = {\n"); |
| 137 |
for (size_t i = 0; i < 10; i++) { |
| 138 |
if (placeholders[i].source == NULL) { |
| 139 |
continue; |
| 140 |
} |
| 141 |
auto knob = placeholders[i].source; |
| 142 |
auto knob_ident = sanitized_name(knob->name); |
| 143 |
if (knob->type == KNOB_NUMBER) { |
| 144 |
printf(" {.offset = SCRIPT_CTX_PLACEHOLDER_BASE + %zu, " |
| 145 |
".value = knob_%s},\n", |
| 146 |
i * 4, knob_ident); |
| 147 |
} else { |
| 148 |
printf(" {.offset = SCRIPT_CTX_PLACEHOLDER_BASE + %zu, " |
| 149 |
".value = placeholder%zu_%s},\n", |
| 150 |
i * 4, i, knob_ident); |
| 151 |
} |
| 152 |
free(knob_ident); |
| 153 |
} |
| 154 |
printf(" };\n"); |
| 155 |
printf(" script_specialize(output->script, spec, ARR_SIZE(spec));\n"); |
| 156 |
printf(" return true;\n"); |
| 157 |
printf("}\n"); |
| 158 |
free(ident); |
| 159 |
} |
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
ce |
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
er |
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
static bool parse_knobs(const char *preset_name, config_setting_t *knob_settings, |
| 187 |
config_setting_t *placeholder_settings, struct knob *knobs, |
| 188 |
struct placeholder *placeholders) { |
| 189 |
struct knob *knobs_by_name = NULL; |
| 190 |
if (config_setting_length(knob_settings) > MAX_PLACEHOLDERS) { |
| 191 |
fprintf(stderr, "Too many knobs in %s, max %d allowed\n", preset_name, |
| 192 |
MAX_PLACEHOLDERS); |
| 193 |
return false; |
| 194 |
} |
| 195 |
if (config_setting_length(placeholder_settings) > MAX_PLACEHOLDERS) { |
| 196 |
fprintf(stderr, "Too many placeholders in %s, max %d allowed\n", |
| 197 |
preset_name, MAX_PLACEHOLDERS); |
| 198 |
return false; |
| 199 |
} |
| 200 |
unsigned n_knobs = 0; |
| 201 |
for (unsigned i = 0; i < (unsigned)config_setting_length(knob_settings); i++) { |
| 202 |
auto config = config_setting_get_elem(knob_settings, i); |
| 203 |
const char *name = config_setting_name(config); |
| 204 |
double default_value; |
| 205 |
auto knob = &knobs[n_knobs++]; |
| 206 |
knob->name = strdup(name); |
| 207 |
if (config_extra_get_float(config, &default_value)) { |
| 208 |
knob->type = KNOB_NUMBER; |
| 209 |
knob->number.default_value = default_value; |
| 210 |
HASH_ADD_STR(knobs_by_name, name, knob); |
| 211 |
n_knobs++; |
| 212 |
continue; |
| 213 |
} |
| 214 |
if (!config_setting_is_list(config) || config_setting_length(config) != 2) { |
| 215 |
fprintf(stderr, |
| 216 |
"Invalid placeholder %s in %s, line %d. It must be a " |
| 217 |
"list of length 2.\n", |
| 218 |
name, preset_name, config_setting_source_line(config)); |
| 219 |
continue; |
| 220 |
} |
| 221 |
|
| 222 |
int default_choice; |
| 223 |
config_setting_t *choices = config_setting_get_elem(config, 1); |
| 224 |
if (!config_extra_get_int(config_setting_get_elem(config, 0), &default_choice) || |
| 225 |
choices == NULL || !config_setting_is_array(choices)) { |
| 226 |
fprintf(stderr, |
| 227 |
"Invalid placeholder %s in %s, line %d. Failed to get " |
| 228 |
"elements.\n", |
| 229 |
name, preset_name, config_setting_source_line(config)); |
| 230 |
continue; |
| 231 |
} |
| 232 |
|
| 233 |
auto n_choices = (unsigned)config_setting_length(choices); |
| 234 |
if (default_choice < 0 || (unsigned)default_choice >= n_choices) { |
| 235 |
fprintf(stderr, |
| 236 |
"Invalid knob choice in %s, knob %s line %d. Default " |
| 237 |
"choice out of range.\n", |
| 238 |
preset_name, name, config_setting_source_line(config)); |
| 239 |
continue; |
| 240 |
} |
| 241 |
knob->type = KNOB_CHOICE; |
| 242 |
knob->n_choices = 0; |
| 243 |
knob->choices = malloc(n_choices * sizeof(char *)); |
| 244 |
knob->default_choice = (unsigned)default_choice; |
| 245 |
|
| 246 |
bool has_error = false; |
| 247 |
for (unsigned j = 0; j < n_choices; j++) { |
| 248 |
auto choice = |
| 249 |
config_setting_get_string(config_setting_get_elem(choices, j)); |
| 250 |
if (choice == NULL) { |
| 251 |
fprintf(stderr, |
| 252 |
"Invalid knob choice in %s, knob %s line %d. " |
| 253 |
"Failed to get choice.\n", |
| 254 |
preset_name, name, |
| 255 |
config_setting_source_line(config)); |
| 256 |
has_error = true; |
| 257 |
break; |
| 258 |
} |
| 259 |
for (unsigned k = 0; k < j; k++) { |
| 260 |
if (strcmp(knob->choices[k], choice) == 0) { |
| 261 |
fprintf(stderr, |
| 262 |
"Invalid knob choice in %s, knob %s line " |
| 263 |
"%d. Duplicate choice %s.\n", |
| 264 |
preset_name, name, |
| 265 |
config_setting_source_line(config), choice); |
| 266 |
has_error = true; |
| 267 |
break; |
| 268 |
} |
| 269 |
} |
| 270 |
if (has_error) { |
| 271 |
break; |
| 272 |
} |
| 273 |
knob->choices[knob->n_choices++] = strdup(choice); |
| 274 |
} |
| 275 |
if (has_error) { |
| 276 |
for (unsigned j = 0; j < knob->n_choices; j++) { |
| 277 |
free(knob->choices[j]); |
| 278 |
} |
| 279 |
free(knob->choices); |
| 280 |
free((void *)knob->name); |
| 281 |
knob->choices = NULL; |
| 282 |
knob->name = NULL; |
| 283 |
continue; |
| 284 |
} |
| 285 |
HASH_ADD_STR(knobs_by_name, name, knob); |
| 286 |
n_knobs++; |
| 287 |
} |
| 288 |
|
| 289 |
for (unsigned i = 0; i < (unsigned)config_setting_length(placeholder_settings); i++) { |
| 290 |
auto config = config_setting_get_elem(placeholder_settings, i); |
| 291 |
if (!config_setting_is_list(config) || config_setting_length(config) < 2) { |
| 292 |
fprintf(stderr, |
| 293 |
"Invalid placeholder in preset %s, line %d. Must be a " |
| 294 |
"non-empty list.\n", |
| 295 |
preset_name, config_setting_source_line(config)); |
| 296 |
continue; |
| 297 |
} |
| 298 |
|
| 299 |
int index; |
| 300 |
if (!config_extra_get_int(config_setting_get_elem(config, 0), &index)) { |
| 301 |
fprintf(stderr, |
| 302 |
"Invalid placeholder in preset %s, line %d. Index must " |
| 303 |
"be an integer.\n", |
| 304 |
preset_name, config_setting_source_line(config)); |
| 305 |
continue; |
| 306 |
} |
| 307 |
|
| 308 |
auto placeholder = &placeholders[index]; |
| 309 |
if (placeholder->source) { |
| 310 |
fprintf(stderr, |
| 311 |
"Invalid placeholder in preset %s, line %d. Placeholder " |
| 312 |
"with index %d already defined.\n", |
| 313 |
preset_name, config_setting_source_line(config), index); |
| 314 |
continue; |
| 315 |
} |
| 316 |
BUG_ON(placeholder->value_for_choices != NULL); |
| 317 |
const char *source = |
| 318 |
config_setting_get_string(config_setting_get_elem(config, 1)); |
| 319 |
struct knob *knob; |
| 320 |
HASH_FIND_STR(knobs_by_name, source, knob); |
| 321 |
if (!knob) { |
| 322 |
fprintf(stderr, |
| 323 |
"Invalid placeholder%d definition in %s, line " |
| 324 |
"%d. Source knob %s not found.\n", |
| 325 |
index, preset_name, config_setting_source_line(config), |
| 326 |
source); |
| 327 |
continue; |
| 328 |
} |
| 329 |
|
| 330 |
if (config_setting_length(config) == 2) { |
| 331 |
if (knob->type != KNOB_NUMBER) { |
| 332 |
fprintf(stderr, |
| 333 |
"Invalid placeholder%d definition in %s, line " |
| 334 |
"%d. Source knob %s is not a number.\n", |
| 335 |
index, preset_name, |
| 336 |
config_setting_source_line(config), source); |
| 337 |
continue; |
| 338 |
} |
| 339 |
placeholder->source = knob; |
| 340 |
} else if (config_setting_length(config) == 3) { |
| 341 |
config_setting_t *value_for_choices = |
| 342 |
config_setting_get_elem(config, 2); |
| 343 |
if (value_for_choices == NULL || |
| 344 |
!config_setting_is_array(value_for_choices)) { |
| 345 |
fprintf(stderr, |
| 346 |
"Invalid placeholder%d definition in %s, line " |
| 347 |
"%d. Failed to get elements.\n", |
| 348 |
index, preset_name, |
| 349 |
config_setting_source_line(config)); |
| 350 |
continue; |
| 351 |
} |
| 352 |
if (knob->type != KNOB_CHOICE) { |
| 353 |
fprintf(stderr, |
| 354 |
"Invalid placeholder%d definition in %s, line " |
| 355 |
"%d. Source knob %s is not a choice.\n", |
| 356 |
index, preset_name, |
| 357 |
config_setting_source_line(config), source); |
| 358 |
continue; |
| 359 |
} |
| 360 |
if (knob->n_choices != |
| 361 |
(unsigned)config_setting_length(value_for_choices)) { |
| 362 |
fprintf(stderr, |
| 363 |
"Invalid placeholder%d definition in %s, line " |
| 364 |
"%d. Number of choices doesn't match.\n", |
| 365 |
index, preset_name, |
| 366 |
config_setting_source_line(config)); |
| 367 |
continue; |
| 368 |
} |
| 369 |
placeholder->value_for_choices = |
| 370 |
malloc(sizeof(double) * knob->n_choices); |
| 371 |
for (unsigned j = 0; j < knob->n_choices; j++) { |
| 372 |
double value; |
| 373 |
if (!config_extra_get_float( |
| 374 |
config_setting_get_elem(value_for_choices, j), &value)) { |
| 375 |
fprintf(stderr, |
| 376 |
"Invalid placeholder%d definition in %s, " |
| 377 |
"line %d. Failed to get value.\n", |
| 378 |
index, preset_name, |
| 379 |
config_setting_source_line(config)); |
| 380 |
free(placeholder->value_for_choices); |
| 381 |
placeholder->value_for_choices = NULL; |
| 382 |
break; |
| 383 |
} |
| 384 |
placeholder->value_for_choices[j] = value; |
| 385 |
} |
| 386 |
if (placeholder->value_for_choices == NULL) { |
| 387 |
continue; |
| 388 |
} |
| 389 |
placeholder->source = knob; |
| 390 |
} else { |
| 391 |
fprintf(stderr, |
| 392 |
"Invalid placeholder%d definition in %s, line %d. " |
| 393 |
"Excessive elements.\n", |
| 394 |
index, preset_name, config_setting_source_line(config)); |
| 395 |
continue; |
| 396 |
} |
| 397 |
} |
| 398 |
struct knob *k, *nk; |
| 399 |
HASH_ITER(hh, knobs_by_name, k, nk) { |
| 400 |
HASH_DEL(knobs_by_name, k); |
| 401 |
} |
| 402 |
return true; |
| 403 |
} |
| 404 |
|
| 405 |
int main(int argc, const char **argv) { |
| 406 |
if (argc != 2) { |
| 407 |
return 1; |
| 408 |
} |
| 409 |
|
| 410 |
log_init_tls(); |
| 411 |
|
| 412 |
char **presets = dynarr_new(char *, 10); |
| 413 |
|
| 414 |
config_t cfg; |
| 415 |
config_init(&cfg); |
| 416 |
config_set_auto_convert(&cfg, 1); |
| 417 |
|
| 418 |
if (!config_read_file(&cfg, argv[1])) { |
| 419 |
fprintf(stderr, "Failed to read config file %s: %s\n", argv[1], |
| 420 |
config_error_text(&cfg)); |
| 421 |
config_destroy(&cfg); |
| 422 |
return 1; |
| 423 |
} |
| 424 |
|
| 425 |
auto settings = config_root_setting(&cfg); |
| 426 |
|
| 427 |
|
| 428 |
|
| 429 |
static const ptrdiff_t base = SCRIPT_CTX_PLACEHOLDER_BASE; |
| 430 |
struct script_context_info context_info[ARR_SIZE(win_script_context_info) + MAX_PLACEHOLDERS] = { |
| 431 |
{"placeholder0", base}, {"placeholder1", base + 4}, |
| 432 |
{"placeholder2", base + 8}, {"placeholder3", base + 12}, |
| 433 |
{"placeholder4", base + 16}, {"placeholder5", base + 20}, |
| 434 |
{"placeholder6", base + 24}, {"placeholder7", base + 28}, |
| 435 |
{"placeholder8", base + 32}, {"placeholder9", base + 36}, |
| 436 |
}; |
| 437 |
memcpy(context_info + 10, win_script_context_info, sizeof(win_script_context_info)); |
| 438 |
|
| 439 |
struct script_output_info outputs[ARR_SIZE(win_script_outputs)]; |
| 440 |
memcpy(outputs, win_script_outputs, sizeof(win_script_outputs)); |
| 441 |
|
| 442 |
struct script_parse_config parse_config = { |
| 443 |
.context_info = context_info, |
| 444 |
.output_info = NULL, |
| 445 |
}; |
| 446 |
printf("// This file is generated by tools/animgen.c from %s\n", argv[1]); |
| 447 |
printf("// This file is included in git repository for " |
| 448 |
"convenience only.\n"); |
| 449 |
printf("// DO NOT EDIT THIS FILE!\n\n"); |
| 450 |
|
| 451 |
printf("#include <libconfig.h>\n"); |
| 452 |
printf("#include \"../script.h\"\n"); |
| 453 |
printf("#include \"../curve.h\"\n"); |
| 454 |
printf("#include \"../script_internal.h\"\n"); |
| 455 |
printf("#include \"utils/misc.h\"\n"); |
| 456 |
printf("#include \"config.h\"\n"); |
| 457 |
for (unsigned i = 0; i < (unsigned)config_setting_length(settings); i++) { |
| 458 |
auto sub = config_setting_get_elem(settings, i); |
| 459 |
auto name = config_setting_name(sub); |
| 460 |
struct knob knobs[MAX_PLACEHOLDERS] = {}; |
| 461 |
struct placeholder placeholders[MAX_PLACEHOLDERS] = {}; |
| 462 |
|
| 463 |
auto knob_settings = config_setting_get_member(sub, "*knobs"); |
| 464 |
if (knob_settings) { |
| 465 |
auto placeholder_settings = |
| 466 |
config_setting_get_member(sub, "*placeholders"); |
| 467 |
BUG_ON(!placeholder_settings); |
| 468 |
parse_knobs(name, knob_settings, placeholder_settings, knobs, |
| 469 |
placeholders); |
| 470 |
config_setting_remove(sub, "*knobs"); |
| 471 |
config_setting_remove(sub, "*placeholders"); |
| 472 |
knob_settings = NULL; |
| 473 |
} |
| 474 |
|
| 475 |
char *err = NULL; |
| 476 |
auto script = script_compile(sub, parse_config, &err); |
| 477 |
if (!script) { |
| 478 |
fprintf(stderr, "Failed to compile script %s: %s\n", name, err); |
| 479 |
free(err); |
| 480 |
continue; |
| 481 |
} |
| 482 |
bool has_err = false; |
| 483 |
for (size_t j = 0; j < script->len; j++) { |
| 484 |
if (script->instrs[j].type != INST_LOAD_CTX) { |
| 485 |
continue; |
| 486 |
} |
| 487 |
if (script->instrs[j].ctx < base) { |
| 488 |
continue; |
| 489 |
} |
| 490 |
size_t index = (size_t)(script->instrs[j].ctx - base) / 4; |
| 491 |
BUG_ON(index >= ARR_SIZE(knobs)); |
| 492 |
if (placeholders[index].source == NULL) { |
| 493 |
fprintf(stderr, "Placeholder %zu used, but not defined\n", |
| 494 |
index); |
| 495 |
has_err = true; |
| 496 |
break; |
| 497 |
} |
| 498 |
} |
| 499 |
|
| 500 |
if (!has_err) { |
| 501 |
char *code = script_to_c(script, outputs); |
| 502 |
codegen(name, code, placeholders); |
| 503 |
free(code); |
| 504 |
|
| 505 |
dynarr_push(presets, strdup(name)); |
| 506 |
} |
| 507 |
for (size_t j = 0; j < MAX_PLACEHOLDERS; j++) { |
| 508 |
if (placeholders[j].value_for_choices) { |
| 509 |
free(placeholders[j].value_for_choices); |
| 510 |
} |
| 511 |
} |
| 512 |
for (size_t j = 0; j < MAX_PLACEHOLDERS; j++) { |
| 513 |
if (knobs[j].type == KNOB_CHOICE) { |
| 514 |
for (unsigned k = 0; k < knobs[j].n_choices; k++) { |
| 515 |
free(knobs[j].choices[k]); |
| 516 |
} |
| 517 |
free(knobs[j].choices); |
| 518 |
} |
| 519 |
free((void *)knobs[j].name); |
| 520 |
} |
| 521 |
script_free(script); |
| 522 |
} |
| 523 |
|
| 524 |
config_destroy(&cfg); |
| 525 |
|
| 526 |
printf("struct {\n" |
| 527 |
" const char *name;\n" |
| 528 |
" bool (*func)(struct win_script *output, " |
| 529 |
"config_setting_t *setting);\n" |
| 530 |
"} win_script_presets[] = {\n"); |
| 531 |
dynarr_foreach(presets, p) { |
| 532 |
auto ident = sanitized_name(*p); |
| 533 |
printf(" {\"%s\", win_script_preset__%s},\n", *p, ident); |
| 534 |
free(*p); |
| 535 |
free(ident); |
| 536 |
} |
| 537 |
printf(" {NULL, NULL},\n};\n"); |
| 538 |
dynarr_free_pod(presets); |
| 539 |
return 0; |
| 540 |
} |