lorid

convert chordpro to pdf
git clone git://git.relim.de/lorid.git
Log | Files | Refs | README | LICENSE

commit 1372caa85cb72bba0e6d5e45153207fc102521e8
parent 7f3022b69d1a31feaa8343a5a28d60c0178b8e20
Author: nibo <nibo@relim.de>
Date:   Sat, 28 Dec 2024 19:29:41 +0100

Improve --print-default-config

Diffstat:
Mchordpro.c | 7++-----
Mconfig.c | 84++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------
2 files changed, 66 insertions(+), 25 deletions(-)

diff --git a/chordpro.c b/chordpro.c @@ -648,13 +648,11 @@ void cho_font_print_as_toml(struct Font *font, const char *section) { printf("[output.styles.%s.font]\n", section); - printf("\n"); printf("name = \"%s\"\n", font->name); printf("family = \"%s\"\n", cho_font_family_to_config_string(font->family)); printf("style = \"%s\"\n", cho_font_style_to_config_string(font->style)); printf("weight = \"%s\"\n", cho_font_weight_to_config_string(font->weight)); - printf("size = %.1f\n", font->size); - printf("\n"); + printf("size = %.1f\n\n", font->size); } void @@ -1317,8 +1315,7 @@ cho_style_print_as_toml(struct ChoStyle *style, const char *section) printf("boxed = %s\n", style->boxed ? "true" : "false"); printf("boxed_color = \"%s\"\n", cho_rgbcolor_to_string(style->boxed_color)); printf("rise = %.1f\n", style->rise); - printf("href = \"%s\"\n", style->href ? style->href : ""); - printf("\n"); + printf("href = \"%s\"\n\n", style->href ? style->href : ""); cho_font_print_as_toml(style->font, section); } diff --git a/config.c b/config.c @@ -7,7 +7,7 @@ #include "util.h" #include "chord_diagram.h" -static char *naming_systems[] = { +static const char *naming_systems[] = { "common", "german", "scandinavian", @@ -17,11 +17,19 @@ static char *naming_systems[] = { "custom" // TODO: Is this needed }; -static char *parse_modes[] = { +static const char *parse_modes[] = { "strict", "relaxed" }; +static const char *instruments[] = { + "guitar", + "keyboard", + "mandolin", + "ukulele", + "unknown" +}; + static const char *g_valid_styles[] = { "title", "subtitle", @@ -177,6 +185,12 @@ config_instrument_parse(const char *str) return INS_UNKNOWN; } +static const char * +config_instrument_to_config_string(enum Instrument ins) +{ + return instruments[ins]; +} + static struct Note * config_note_new(void) { @@ -300,18 +314,40 @@ config_notes_load(toml_table_t *notes, const char *system) } static void -config_notes_print_as_toml(enum NamingSystem system, struct Note **notes) +config_notes_print_as_toml(enum NamingSystem system) { + struct Note *notes; + switch (system) { + case NS_COMMON: + notes = (struct Note *)&notes_common; + break; + case NS_GERMAN: + notes = (struct Note *)&notes_german; + break; + case NS_SCANDINAVIAN: + notes = (struct Note *)&notes_scandinavian; + break; + case NS_LATIN: + notes = (struct Note *)&notes_latin; + break; + case NS_ROMAN: + notes = (struct Note *)&notes_roman; + break; + case NS_NASHVILLE: + notes = (struct Note *)&notes_nashville; + break; + case NS_CUSTOM: + return; + } printf("%s = [\n", config_naming_system_to_config_string(system)); int i; - // TODO: handle NULL cases - for (i = 0; notes[i]; i++) { - printf("\t{ note = \"%s\",", notes[i]->note); - if (notes[i]->sharp) { - printf(" sharp = \"%s\",", notes[i]->sharp); + for (i = 0; i<7; i++) { + printf("\t{ note = \"%s\",", notes[i].note); + if (notes[i].sharp) { + printf(" sharp = \"%s\",", notes[i].sharp); } - if (notes[i]->flat) { - printf(" flat = \"%s\"", notes[i]->flat); + if (notes[i].flat) { + printf(" flat = \"%s\"", notes[i].flat); } printf(" },\n"); } @@ -386,7 +422,7 @@ config_load_default(void) static void config_output_style_print_as_toml(struct OutputStyle *item) { - printf("[output.styles.%s]\n\n", item->name); + printf("[output.styles.%s]\n", item->name); cho_style_print_as_toml(item->style, item->name); } @@ -394,26 +430,34 @@ void config_print_default(void) { struct Config *config = config_load_default(); - printf("[notes]\n\n"); - config_notes_print_as_toml(config->output->system, config->output->notes); - printf("[output]\n\n"); + printf("[notes]\n"); + config_notes_print_as_toml(NS_COMMON); + config_notes_print_as_toml(NS_GERMAN); + config_notes_print_as_toml(NS_SCANDINAVIAN); + config_notes_print_as_toml(NS_LATIN); + config_notes_print_as_toml(NS_ROMAN); + config_notes_print_as_toml(NS_NASHVILLE); + printf("[output]\n"); printf("system = \"%s\"\n\n", config_naming_system_to_config_string(config->output->system)); - printf("[output.toc]\n\n"); + printf("[output.toc]\n"); printf("show = %s\n", config->output->toc->show ? "true" : "false"); printf("title = \"%s\"\n\n", config->output->toc->title); - printf("[output.chorus]\n\n"); + printf("[output.chord_diagram]\n"); + printf("show = %s\n", config->output->diagram->show ? "true" : "false"); + printf("instrument = \"%s\"\n\n", config_instrument_to_config_string(config->output->diagram->instrument)); + printf("[output.chorus]\n"); printf("label = \"Chorus\"\n"); printf("quote = false\n\n"); - printf("[output.styles]\n\n"); + printf("[output.styles]\n"); int i = 0; while (config->output->styles[i] != NULL) { config_output_style_print_as_toml(config->output->styles[i]); i++; } - printf("[parser]\n\n"); - printf("[parser.chords]\n\n"); + printf("[parser]\n"); + printf("[parser.chords]\n"); printf("mode = \"%s\"\n", config_parse_mode_to_config_string(config->parser->chords->mode)); - printf("system = \"%s\"\n\n", config_naming_system_to_config_string(config->parser->chords->system)); + printf("system = \"%s\"\n", config_naming_system_to_config_string(config->parser->chords->system)); config_free(config); }