lorid

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

commit 6536b38812bb414f1304e00934feede28f0a922e
parent d5287903db5d14f56f94795b8f1988014a096317
Author: nibo <nibo@relim.de>
Date:   Sun, 19 Jan 2025 20:02:07 +0100

Make -1 the error/empty/unknown value for any enum

For this to work I now compile width -std=c23.

Diffstat:
MMakefile | 2+-
Mchordpro.c | 324+++++++++++++++++++++++++++++++++++++++----------------------------------------
Mchordpro.h | 82++++++++++++++++++++++++++++++++++---------------------------------------------
Mconfig.c | 197++++++++++++++++++++++++++++++++++++++++---------------------------------------
Mconfig.h | 5++---
Dlorid.h | 297-------------------------------------------------------------------------------
Mout_pdf.c | 14++++++++------
Mutil.c | 6+++---
8 files changed, 310 insertions(+), 617 deletions(-)

diff --git a/Makefile b/Makefile @@ -3,7 +3,7 @@ PREFIX = /usr/local MANPREFIX = ${PREFIX}/share/man COLOR = 0 VARS = -DVERSION=\"${VERSION}\" -DCOLOR=${COLOR} -DPREFIX=\"${PREFIX}\" -CFLAGS = -pedantic -Wall -Wextra +CFLAGS = -std=c23 -pedantic -Wall -Wextra LDFLAGS = -lpdfio -ltoml -lfontconfig -lgrapheme -lm SRC = util.c config.c chordpro.c chord_diagram.c out_pdf.c lorid.c diff --git a/chordpro.c b/chordpro.c @@ -4,19 +4,20 @@ #include <stdarg.h> #include <unistd.h> #include <string.h> +#include <strings.h> #include <ctype.h> #include <errno.h> #include <limits.h> #include "chordpro.h" -#include "config.h" +// #include "config.h" #include "util.h" #include "chord_diagram.h" -static const char *font_families[] = { "normal", "sans", "serif", "monospace", "empty" }; -static const char *font_styles[] = { "normal", "oblique", "italic", "empty" }; -static const char *font_weights[] = { "normal", "bold", "empty" }; -static const char *line_styles[] = { "single", "double", "none", "empty" }; -static const char *chord_qualifiers[] = { "", "m", "", "+", "°" }; +static const char *font_families[] = { "normal", "sans", "serif", "monospace" }; +static const char *font_styles[] = { "normal", "oblique", "italic" }; +static const char *font_weights[] = { "normal", "bold" }; +static const char *line_styles[] = { "single", "double", "none" }; +static const char *chord_qualifiers[] = { "m", "", "+", "°" }; static const char *state_enums[] = { "STATE_LYRICS", @@ -34,27 +35,27 @@ static const char *state_enums[] = { struct StyleProperty default_style_properties[] = { // TODO: label and footer are missing - { SF_CHORD, SPT_FONT, { .font_name = NULL } }, - { SF_CHORD, SPT_SIZE, { .font_size = EMPTY_DOUBLE } }, - { SF_CHORD, SPT_COLOR, { .foreground_color = NULL } }, - { SF_CHORUS, SPT_FONT, { .font_name = NULL } }, - { SF_CHORUS, SPT_SIZE, { .font_size = EMPTY_DOUBLE } }, - { SF_CHORUS, SPT_COLOR, { .foreground_color = NULL } }, - { SF_GRID, SPT_FONT, { .font_name = NULL } }, - { SF_GRID, SPT_SIZE, { .font_size = EMPTY_DOUBLE } }, - { SF_GRID, SPT_COLOR, { .foreground_color = NULL } }, - { SF_TAB, SPT_FONT, { .font_name = NULL } }, - { SF_TAB, SPT_SIZE, { .font_size = EMPTY_DOUBLE } }, - { SF_TAB, SPT_COLOR, { .foreground_color = NULL } }, - { SF_TEXT, SPT_FONT, { .font_name = NULL } }, - { SF_TEXT, SPT_SIZE, { .font_size = EMPTY_DOUBLE } }, - { SF_TEXT, SPT_COLOR, { .foreground_color = NULL } }, - { SF_TITLE, SPT_FONT, { .font_name = NULL } }, - { SF_TITLE, SPT_SIZE, { .font_size = EMPTY_DOUBLE } }, - { SF_TITLE, SPT_COLOR, { .foreground_color = NULL } }, - { SF_TOC, SPT_FONT, { .font_name = NULL } }, - { SF_TOC, SPT_SIZE, { .font_size = EMPTY_DOUBLE } }, - { SF_TOC, SPT_COLOR, { .foreground_color = NULL } }, + { TT_CHORD, SPT_FONT, { .font_name = NULL } }, + { TT_CHORD, SPT_SIZE, { .font_size = EMPTY_DOUBLE } }, + { TT_CHORD, SPT_COLOR, { .foreground_color = NULL } }, + { TT_CHORUS, SPT_FONT, { .font_name = NULL } }, + { TT_CHORUS, SPT_SIZE, { .font_size = EMPTY_DOUBLE } }, + { TT_CHORUS, SPT_COLOR, { .foreground_color = NULL } }, + { TT_GRID, SPT_FONT, { .font_name = NULL } }, + { TT_GRID, SPT_SIZE, { .font_size = EMPTY_DOUBLE } }, + { TT_GRID, SPT_COLOR, { .foreground_color = NULL } }, + { TT_TAB, SPT_FONT, { .font_name = NULL } }, + { TT_TAB, SPT_SIZE, { .font_size = EMPTY_DOUBLE } }, + { TT_TAB, SPT_COLOR, { .foreground_color = NULL } }, + { TT_TEXT, SPT_FONT, { .font_name = NULL } }, + { TT_TEXT, SPT_SIZE, { .font_size = EMPTY_DOUBLE } }, + { TT_TEXT, SPT_COLOR, { .foreground_color = NULL } }, + { TT_TITLE, SPT_FONT, { .font_name = NULL } }, + { TT_TITLE, SPT_SIZE, { .font_size = EMPTY_DOUBLE } }, + { TT_TITLE, SPT_COLOR, { .foreground_color = NULL } }, + { TT_TOC, SPT_FONT, { .font_name = NULL } }, + { TT_TOC, SPT_SIZE, { .font_size = EMPTY_DOUBLE } }, + { TT_TOC, SPT_COLOR, { .foreground_color = NULL } }, }; static const char *chord_extensions_major[] = { @@ -137,8 +138,8 @@ static const char *chord_extensions_minor[] = { }; static bool g_show_info_logs = false; -static enum TextType g_current_ttype = SF_TEXT; -static enum TextType g_prev_ttype = SF_TEXT; +static enum TextType g_current_ttype = TT_TEXT; +static enum TextType g_prev_ttype = TT_TEXT; static struct Config *g_config = NULL; static const char *g_chordpro_filepath = NULL; static int *g_transpose_history = NULL; @@ -164,7 +165,6 @@ static const char *anchor_enums[] = { }; static const char *chord_qualifier_enums[] = { - "CQ_EMPTY", "CQ_MIN", "CQ_MAJ", "CQ_AUG", @@ -172,7 +172,6 @@ static const char *chord_qualifier_enums[] = { }; static const char *directive_type_enums[] = { - "DT_EMPTY", "DT_ENVIRONMENT", "DT_METADATA", "DT_FORMATTING", @@ -185,7 +184,6 @@ static const char *directive_type_enums[] = { }; static const char *section_type_enums[] = { - "ST_EMPTY", "ST_NEWSONG", "ST_CHORUS", "ST_VERSE", @@ -196,31 +194,30 @@ static const char *section_type_enums[] = { }; static const char *position_enums[] = { - "POS_EMPTY", "POS_START", - "POS_END" + "POS_END", + "POS_NO" }; static const char *text_type_enums[] = { - "SF_EMPTY", - "SF_CHORD", - "SF_ANNOT", - "SF_CHORUS", - "SF_FOOTER", - "SF_GRID", - "SF_TAB", - "SF_TOC", - "SF_TEXT", - "SF_TITLE", - "SF_SUBTITLE", - "SF_LABEL", - "SF_COMMENT", - "SF_COMMENT_ITALIC", - "SF_COMMENT_BOX" + "TT_CHORD", + "TT_ANNOT", + "TT_CHORUS", + "TT_FOOTER", + "TT_GRID", + "TT_TAB", + "TT_TOC", + "TT_TOC_TITLE", + "TT_TEXT", + "TT_TITLE", + "TT_SUBTITLE", + "TT_LABEL", + "TT_COMMENT", + "TT_COMMENT_ITALIC", + "TT_COMMENT_BOX" }; static const char *style_property_type_enums[] = { - "SPT_EMPTY", "SPT_FONT", "SPT_SIZE", "SPT_COLOR" @@ -617,7 +614,7 @@ cho_font_family_parse(const char *str) } else if (!strcmp(str, font_families[FF_NORMAL])) { return FF_NORMAL; } else { - return FF_EMPTY; + return -1; } } @@ -637,7 +634,7 @@ cho_font_style_parse(const char *str) } else if (!strcmp(str, font_styles[FS_ROMAN])) { return FS_ROMAN; } else { - return FS_EMPTY; + return -1; } } @@ -655,7 +652,7 @@ cho_font_weight_parse(const char *str) } else if (!strcmp(str, "normal")) { return FW_REGULAR; } else { - return FW_EMPTY; + return -1; } } @@ -701,7 +698,7 @@ cho_linestyle_parse(const char *str) } else if (!strcmp(str, "none")) { return LS_NONE; } else { - return LS_EMPTY; + return -1; } } @@ -818,15 +815,15 @@ cho_style_property_apply_default(enum TextType current_ttype, enum StyleProperty static void cho_style_apply_default(enum TextType current_ttype, struct ChoStyle *style) { - if (current_ttype == SF_CHORUS) { - if (!cho_style_property_apply_default(SF_CHORUS, SPT_FONT, style)) { - cho_style_property_apply_default(SF_TEXT, SPT_FONT, style); + if (current_ttype == TT_CHORUS) { + if (!cho_style_property_apply_default(TT_CHORUS, SPT_FONT, style)) { + cho_style_property_apply_default(TT_TEXT, SPT_FONT, style); } - if (!cho_style_property_apply_default(SF_CHORUS, SPT_SIZE, style)) { - cho_style_property_apply_default(SF_TEXT, SPT_SIZE, style); + if (!cho_style_property_apply_default(TT_CHORUS, SPT_SIZE, style)) { + cho_style_property_apply_default(TT_TEXT, SPT_SIZE, style); } - if (!cho_style_property_apply_default(SF_CHORUS, SPT_COLOR, style)) { - cho_style_property_apply_default(SF_TEXT, SPT_COLOR, style); + if (!cho_style_property_apply_default(TT_CHORUS, SPT_COLOR, style)) { + cho_style_property_apply_default(TT_TEXT, SPT_COLOR, style); } } else { cho_style_property_apply_default(current_ttype, SPT_FONT, style); @@ -1316,7 +1313,7 @@ cho_style_print_as_toml(struct ChoStyle *style, const char *section) static bool cho_style_change_default(struct StyleProperty sprop) { - if (sprop.type == SPT_EMPTY) + if (sprop.type == -1) return false; unsigned int i; for (i = 0; i<LENGTH(default_style_properties); i++) { @@ -1650,7 +1647,7 @@ cho_chord_new(void) chord->name = NULL; chord->is_canonical = false; chord->root = NULL; - chord->qual = CQ_EMPTY; + chord->qual = -1; chord->ext = NULL; chord->bass = NULL; return chord; @@ -2319,7 +2316,7 @@ cho_image_directive_parse(const char *str) struct ChoImage *asset; char c; enum OptionState state = OS_NAME; - enum AttrValueSyntax avs = AVS_NO; + enum AttrValueSyntax avs = -1; char name[6+1]; char value[URL_MAX_LEN+1]; int n = 0; @@ -2354,7 +2351,7 @@ cho_image_directive_parse(const char *str) n++; break; case OS_VALUE: - if (avs == AVS_NO) { + if (avs == -1) { if (is_whitespace(c)) { cho_log(LOG_ERR, "Whitespace character after equals sign in image directive is invalid."); return NULL; @@ -2389,7 +2386,7 @@ cho_image_directive_parse(const char *str) memset(value, 0, v); n = 0; v = 0; - avs = AVS_NO; + avs = -1; state = OS_NAME; break; } @@ -2447,11 +2444,11 @@ cho_image_tag_parse(struct Attr **attrs) size = size_create(attrs[a]->value); if (!size) { cho_log(LOG_ERR, "Invalid value in attribute 'width' in 'img' tag."); - return false; + return NULL; } if (size->type == ST_PERCENT) { cho_log(LOG_ERR, "Invalid type of value in attribute 'width' in 'img' tag. Allowed types are: point, em, ex."); - return false; + return NULL; } image->width = size; } else @@ -2459,11 +2456,11 @@ cho_image_tag_parse(struct Attr **attrs) size = size_create(attrs[a]->value); if (!size) { cho_log(LOG_ERR, "Invalid value in attribute 'height' in 'img' tag."); - return false; + return NULL; } if (size->type == ST_PERCENT) { cho_log(LOG_ERR, "Invalid type of value in attribute 'height' in 'img' tag. Allowed types are: point, em, ex."); - return false; + return NULL; } image->height = size; } else @@ -2471,11 +2468,11 @@ cho_image_tag_parse(struct Attr **attrs) size = size_create(attrs[a]->value); if (!size) { cho_log(LOG_ERR, "Invalid value in attribute 'dx' in 'img' tag."); - return false; + return NULL; } if (size->type == ST_PERCENT) { cho_log(LOG_ERR, "Invalid type of value in attribute 'dx' in 'img' tag. Allowed types are: point, em, ex."); - return false; + return NULL; } image->dx = size; } else @@ -2483,11 +2480,11 @@ cho_image_tag_parse(struct Attr **attrs) size = size_create(attrs[a]->value); if (!size) { cho_log(LOG_ERR, "Invalid value in attribute 'dy' in 'img' tag."); - return false; + return NULL; } if (size->type == ST_PERCENT) { cho_log(LOG_ERR, "Invalid type of value in attribute 'dy' in 'img' tag. Allowed types are: point, em, ex."); - return false; + return NULL; } image->dy = size; } else @@ -2498,32 +2495,32 @@ cho_image_tag_parse(struct Attr **attrs) size = size_create(attrs[a]->value); if (!size) { cho_log(LOG_ERR, "Invalid value in attribute 'scale' in 'img' tag."); - return false; + return NULL; } if (size->type == ST_EM || size->type == ST_EX) { cho_log(LOG_ERR, "Invalid type of value in attribute 'scale' in 'img' tag. Allowed types are: point, percent"); - return false; + return NULL; } image->width_scale = size; size = size_create(++comma); if (!size) { cho_log(LOG_ERR, "Invalid value in attribute 'scale' in 'img' tag."); - return false; + return NULL; } if (size->type == ST_EM || size->type == ST_EX) { cho_log(LOG_ERR, "Invalid type of value in attribute 'scale' in 'img' tag. Allowed types are: point, percent"); - return false; + return NULL; } image->height_scale = size; } else { size = size_create(attrs[a]->value); if (!size) { cho_log(LOG_ERR, "Invalid value in attribute 'scale' in 'img' tag."); - return false; + return NULL; } if (size->type == ST_EM || size->type == ST_EX) { cho_log(LOG_ERR, "Invalid type of value in attribute 'scale' in 'img' tag. Allowed types are: point, percent"); - return false; + return NULL; } image->width_scale = size; image->height_scale = size_copy(size); @@ -2558,11 +2555,11 @@ cho_image_tag_parse(struct Attr **attrs) size = size_create(attrs[a]->value); if (!size) { cho_log(LOG_ERR, "Invalid value in attribute 'w' in 'img' tag."); - return false; + return NULL; } if (size->type != ST_POINT) { cho_log(LOG_ERR, "Invalid type of value in attribute 'w' in 'img' tag. Allowed type is: point"); - return false; + return NULL; } image->w = size; } else @@ -2570,11 +2567,11 @@ cho_image_tag_parse(struct Attr **attrs) size = size_create(attrs[a]->value); if (!size) { cho_log(LOG_ERR, "Invalid value in attribute 'h' in 'img' tag."); - return false; + return NULL; } if (size->type != ST_POINT) { cho_log(LOG_ERR, "Invalid type of value in attribute 'h' in 'img' tag. Allowed type is: point"); - return false; + return NULL; } image->h = size; } else { @@ -2632,8 +2629,8 @@ cho_chord_diagram_parse(const char *str) { struct ChordDiagram *diagram = NULL; enum ChordDiagramState state = CDS_NAME; - enum ChordDiagramContent current_content = CDC_EMPTY; - enum ChordDiagramContent future_content = CDC_EMPTY; + enum ChordDiagramContent current_content = -1; + enum ChordDiagramContent future_content = -1; bool is_maybe_minus_one = false; char c; char name[20]; @@ -2698,7 +2695,7 @@ cho_chord_diagram_parse(const char *str) } memset(option, 0, o); o = 0; - if (current_content == CDC_EMPTY) { + if (current_content == -1) { current_content = future_content; switch (future_content) { case CDC_STRING: @@ -3018,7 +3015,7 @@ static struct ChoSection * cho_section_new(void) { struct ChoSection *section = emalloc(sizeof(struct ChoSection)); - section->type = ST_EMPTY; + section->type = -1; section->label = NULL; section->lines = NULL; return section; @@ -3082,7 +3079,7 @@ cho_song_new(void) song->metadata = NULL; song->sections = NULL; song->diagrams = NULL; - memset(song->present_text_types, 0, SF_LENGTH); + memset(song->present_text_types, 0, TT_LENGTH); return song; } @@ -3176,12 +3173,12 @@ static struct ChoDirective * cho_directive_new(void) { struct ChoDirective *directive = emalloc(sizeof(struct ChoDirective)); - directive->dtype = DT_EMPTY; - directive->stype = ST_EMPTY; - directive->position = POS_EMPTY; - directive->sprop = SPT_EMPTY; - directive->ttype = SF_EMPTY; - directive->btype = BT_EMPTY; + directive->dtype = -1; + directive->stype = -1; + directive->position = -1; + directive->sprop = -1; + directive->ttype = -1; + directive->btype = -1; directive->meta = -1; directive->ctype = -1; directive->style = cho_style_new_default(); @@ -3209,7 +3206,7 @@ cho_directive_parse(const char *name) directive->dtype = DT_ENVIRONMENT; directive->position = POS_START; directive->stype = ST_CHORUS; - directive->ttype = SF_CHORUS; + directive->ttype = TT_CHORUS; return directive; } else if ( !strcmp(name, "end_of_chorus") || @@ -3218,11 +3215,12 @@ cho_directive_parse(const char *name) directive->dtype = DT_ENVIRONMENT; directive->position = POS_END; directive->stype = ST_CHORUS; - directive->ttype = SF_TEXT; + directive->ttype = TT_TEXT; return directive; } else if (!strcmp(name, "chorus")) { directive->dtype = DT_ENVIRONMENT; - directive->ttype = SF_LABEL; + directive->position = POS_NO; + directive->ttype = TT_LABEL; return directive; } else if ( !strcmp(name, "start_of_verse") || @@ -3231,7 +3229,7 @@ cho_directive_parse(const char *name) directive->dtype = DT_ENVIRONMENT; directive->position = POS_START; directive->stype = ST_VERSE; - directive->ttype = SF_TEXT; + directive->ttype = TT_TEXT; return directive; } else if ( !strcmp(name, "end_of_verse") || @@ -3240,7 +3238,7 @@ cho_directive_parse(const char *name) directive->dtype = DT_ENVIRONMENT; directive->position = POS_END; directive->stype = ST_VERSE; - directive->ttype = SF_TEXT; + directive->ttype = TT_TEXT; return directive; } else if ( !strcmp(name, "start_of_bridge") || @@ -3249,7 +3247,7 @@ cho_directive_parse(const char *name) directive->dtype = DT_ENVIRONMENT; directive->position = POS_START; directive->stype = ST_BRIDGE; - directive->ttype = SF_TEXT; + directive->ttype = TT_TEXT; return directive; } else if ( !strcmp(name, "end_of_bridge") || @@ -3258,7 +3256,7 @@ cho_directive_parse(const char *name) directive->dtype = DT_ENVIRONMENT; directive->position = POS_END; directive->stype = ST_BRIDGE; - directive->ttype = SF_TEXT; + directive->ttype = TT_TEXT; return directive; } else if ( !strcmp(name, "start_of_tab") || @@ -3267,7 +3265,7 @@ cho_directive_parse(const char *name) directive->dtype = DT_ENVIRONMENT; directive->position = POS_START; directive->stype = ST_TAB; - directive->ttype = SF_TAB; + directive->ttype = TT_TAB; return directive; } else if ( !strcmp(name, "end_of_tab") || @@ -3276,7 +3274,7 @@ cho_directive_parse(const char *name) directive->dtype = DT_ENVIRONMENT; directive->position = POS_END; directive->stype = ST_TAB; - directive->ttype = SF_TEXT; + directive->ttype = TT_TEXT; return directive; } else if ( !strcmp(name, "start_of_grid") || @@ -3285,7 +3283,7 @@ cho_directive_parse(const char *name) directive->dtype = DT_ENVIRONMENT; directive->position = POS_START; directive->stype = ST_GRID; - directive->ttype = SF_GRID; + directive->ttype = TT_GRID; return directive; } else if ( !strcmp(name, "end_of_grid") || @@ -3294,7 +3292,7 @@ cho_directive_parse(const char *name) directive->dtype = DT_ENVIRONMENT; directive->position = POS_END; directive->stype = ST_GRID; - directive->ttype = SF_TEXT; + directive->ttype = TT_TEXT; return directive; } if ( @@ -3305,7 +3303,7 @@ cho_directive_parse(const char *name) directive->meta = TITLE; cho_style_free(directive->style); g_prev_ttype = g_current_ttype; - g_current_ttype = SF_TITLE; + g_current_ttype = TT_TITLE; directive->style = cho_style_new_default(); g_current_ttype = g_prev_ttype; return directive; @@ -3318,7 +3316,7 @@ cho_directive_parse(const char *name) directive->meta = SUBTITLE; cho_style_free(directive->style); g_prev_ttype = g_current_ttype; - g_current_ttype = SF_SUBTITLE; + g_current_ttype = TT_SUBTITLE; directive->style = cho_style_new_default(); g_current_ttype = g_prev_ttype; return directive; @@ -3349,11 +3347,11 @@ cho_directive_parse(const char *name) ) { directive->dtype = DT_FORMATTING; g_prev_ttype = g_current_ttype; - g_current_ttype = SF_COMMENT; + g_current_ttype = TT_COMMENT; cho_style_free(directive->style); directive->style = cho_style_new_default(); g_current_ttype = g_prev_ttype; - directive->ttype = SF_COMMENT; + directive->ttype = TT_COMMENT; return directive; } else if ( !strcmp(name, "comment_italic") || @@ -3361,11 +3359,11 @@ cho_directive_parse(const char *name) ) { directive->dtype = DT_FORMATTING; g_prev_ttype = g_current_ttype; - g_current_ttype = SF_COMMENT_ITALIC; + g_current_ttype = TT_COMMENT_ITALIC; cho_style_free(directive->style); directive->style = cho_style_new_default(); g_current_ttype = g_prev_ttype; - directive->ttype = SF_COMMENT_ITALIC; + directive->ttype = TT_COMMENT_ITALIC; return directive; } else if ( !strcmp(name, "comment_box") || @@ -3373,11 +3371,11 @@ cho_directive_parse(const char *name) ) { directive->dtype = DT_FORMATTING; g_prev_ttype = g_current_ttype; - g_current_ttype = SF_COMMENT_BOX; + g_current_ttype = TT_COMMENT_BOX; cho_style_free(directive->style); directive->style = cho_style_new_default(); g_current_ttype = g_prev_ttype; - directive->ttype = SF_COMMENT_BOX; + directive->ttype = TT_COMMENT_BOX; return directive; } if (!strcmp(name, "image")) { @@ -3398,7 +3396,7 @@ cho_directive_parse(const char *name) ) { directive->dtype = DT_FONT; directive->sprop = SPT_FONT; - directive->ttype = SF_CHORD; + directive->ttype = TT_CHORD; return directive; } else if ( !strcmp(name, "chordsize") || @@ -3406,57 +3404,57 @@ cho_directive_parse(const char *name) ) { directive->dtype = DT_FONT; directive->sprop = SPT_SIZE; - directive->ttype = SF_CHORD; + directive->ttype = TT_CHORD; return directive; } else if (!strcmp(name, "chordcolour")) { directive->dtype = DT_FONT; directive->sprop = SPT_COLOR; - directive->ttype = SF_CHORD; + directive->ttype = TT_CHORD; return directive; } else if (!strcmp(name, "chorusfont")) { directive->dtype = DT_FONT; directive->sprop = SPT_FONT; - directive->ttype = SF_CHORUS; + directive->ttype = TT_CHORUS; return directive; } else if (!strcmp(name, "chorussize")) { directive->dtype = DT_FONT; directive->sprop = SPT_SIZE; - directive->ttype = SF_CHORUS; + directive->ttype = TT_CHORUS; return directive; } else if (!strcmp(name, "choruscolour")) { directive->dtype = DT_FONT; directive->sprop = SPT_COLOR; - directive->ttype = SF_CHORUS; + directive->ttype = TT_CHORUS; return directive; } else if (!strcmp(name, "gridfont")) { directive->dtype = DT_FONT; directive->sprop = SPT_FONT; - directive->ttype = SF_GRID; + directive->ttype = TT_GRID; return directive; } else if (!strcmp(name, "gridsize")) { directive->dtype = DT_FONT; directive->sprop = SPT_SIZE; - directive->ttype = SF_GRID; + directive->ttype = TT_GRID; return directive; } else if (!strcmp(name, "gridcolour")) { directive->dtype = DT_FONT; directive->sprop = SPT_COLOR; - directive->ttype = SF_GRID; + directive->ttype = TT_GRID; return directive; } else if (!strcmp(name, "tabfont")) { directive->dtype = DT_FONT; directive->sprop = SPT_FONT; - directive->ttype = SF_TAB; + directive->ttype = TT_TAB; return directive; } else if (!strcmp(name, "tabsize")) { directive->dtype = DT_FONT; directive->sprop = SPT_SIZE; - directive->ttype = SF_TAB; + directive->ttype = TT_TAB; return directive; } else if (!strcmp(name, "tabcolour")) { directive->dtype = DT_FONT; directive->sprop = SPT_COLOR; - directive->ttype = SF_TAB; + directive->ttype = TT_TAB; return directive; } else if ( !strcmp(name, "textfont") || @@ -3464,7 +3462,7 @@ cho_directive_parse(const char *name) ) { directive->dtype = DT_FONT; directive->sprop = SPT_FONT; - directive->ttype = SF_TEXT; + directive->ttype = TT_TEXT; return directive; } else if ( !strcmp(name, "textsize") || @@ -3472,40 +3470,40 @@ cho_directive_parse(const char *name) ) { directive->dtype = DT_FONT; directive->sprop = SPT_SIZE; - directive->ttype = SF_TEXT; + directive->ttype = TT_TEXT; return directive; } else if (!strcmp(name, "textcolour")) { directive->dtype = DT_FONT; directive->sprop = SPT_COLOR; - directive->ttype = SF_TEXT; + directive->ttype = TT_TEXT; return directive; } else if (!strcmp(name, "titlefont")) { directive->dtype = DT_FONT; directive->sprop = SPT_FONT; - directive->ttype = SF_TITLE; + directive->ttype = TT_TITLE; return directive; } else if (!strcmp(name, "titlesize")) { directive->dtype = DT_FONT; directive->sprop = SPT_SIZE; - directive->ttype = SF_TITLE; + directive->ttype = TT_TITLE; return directive; } else if (!strcmp(name, "titlecolour")) { directive->dtype = DT_FONT; directive->sprop = SPT_COLOR; - directive->ttype = SF_TITLE; + directive->ttype = TT_TITLE; return directive; } else if (!strcmp(name, "tocfont")) { directive->dtype = DT_FONT; directive->sprop = SPT_FONT; - directive->ttype = SF_TOC; + directive->ttype = TT_TOC; } else if (!strcmp(name, "tocsize")) { directive->dtype = DT_FONT; directive->sprop = SPT_SIZE; - directive->ttype = SF_TOC; + directive->ttype = TT_TOC; } else if (!strcmp(name, "toccolour")) { directive->dtype = DT_FONT; directive->sprop = SPT_COLOR; - directive->ttype = SF_TOC; + directive->ttype = TT_TOC; } /* else if (!strcmp(name, "footerfont")) { } else if (!strcmp(name, "footersize")) { } else if (!strcmp(name, "footercolour")) { @@ -3542,13 +3540,13 @@ cho_directive_parse(const char *name) directive->dtype = DT_ENVIRONMENT; directive->position = POS_START; directive->stype = ST_CUSTOM; - directive->ttype = SF_TEXT; + directive->ttype = TT_TEXT; return directive; } else if (str_starts_with(name, "end_of_")) { directive->dtype = DT_ENVIRONMENT; directive->position = POS_END; directive->stype = ST_CUSTOM; - directive->ttype = SF_TEXT; + directive->ttype = TT_TEXT; return directive; } directive->dtype = DT_CUSTOM; @@ -3561,7 +3559,7 @@ cho_directive_label_parse(const char *directive_name, const char *str) char *label_name = NULL; char c; enum OptionState state = OS_NAME; - enum AttrValueSyntax avs = AVS_NO; + enum AttrValueSyntax avs = -1; char name[5+1]; char value[URL_MAX_LEN+1]; int n = 0; @@ -3600,7 +3598,7 @@ cho_directive_label_parse(const char *directive_name, const char *str) n++; break; case OS_VALUE: - if (avs == AVS_NO) { + if (avs == -1) { if (is_whitespace(c)) { cho_log(LOG_ERR, "Whitespace character after equals sign in environment directive '%s' is invalid.", directive_name); return NULL; @@ -3629,7 +3627,7 @@ cho_directive_label_parse(const char *directive_name, const char *str) label_name = strdup(value); memset(value, 0, v); v = 0; - avs = AVS_NO; + avs = -1; state = OS_NAME; break; } @@ -3687,7 +3685,7 @@ cho_songs_parse(FILE *fp, const char *chordpro_filepath, struct Config *config) g_transpose_history[th] = 0; g_transpose = &g_transpose_history[th]; th++; - enum AttrValueSyntax avs = AVS_NO; + enum AttrValueSyntax avs = -1; struct ChoDirective *directive = NULL; struct ChoMetadata *metadata = NULL; struct ChoLine ***lines; @@ -3700,7 +3698,7 @@ cho_songs_parse(FILE *fp, const char *chordpro_filepath, struct Config *config) lines = &songs[so]->sections[se]->lines; (*lines)[li]->items = emalloc(sizeof(struct ChoLineItem *)); (*lines)[li]->items[ly] = cho_line_item_new(); - songs[so]->present_text_types[SF_TOC] = config->output->toc->show; + songs[so]->present_text_types[TT_TOC] = config->output->toc->show; struct Tag **tags = NULL; struct ChoStyle *tag_style; struct StyleProperty sprop; @@ -3863,7 +3861,7 @@ cho_songs_parse(FILE *fp, const char *chordpro_filepath, struct Config *config) (*lines)[li]->items[ly] = cho_line_item_new(); } break; - case POS_EMPTY: + case POS_NO: /* INFO: {chorus} */ chorus = cho_find_previous_chorus(songs[so]->sections, se); if (chorus) { @@ -3914,7 +3912,7 @@ cho_songs_parse(FILE *fp, const char *chordpro_filepath, struct Config *config) (*lines)[li]->items = erealloc((*lines)[li]->items, (ly+1) * sizeof(struct ChoLineItem *)); (*lines)[li]->items[ly] = cho_line_item_new(); cho_style_free((*lines)[li]->items[ly]->u.text->style); - g_current_ttype = SF_LABEL; + g_current_ttype = TT_LABEL; (*lines)[li]->items[ly]->u.text->style = cho_style_new_default(); (*lines)[li]->items[ly]->u.text->text = label; te += strlen(label); @@ -3938,7 +3936,7 @@ cho_songs_parse(FILE *fp, const char *chordpro_filepath, struct Config *config) (*lines)[li]->items = erealloc((*lines)[li]->items, (ly+1) * sizeof(struct ChoLineItem *)); (*lines)[li]->items[ly] = cho_line_item_new(); cho_style_free((*lines)[li]->items[ly]->u.text->style); - g_current_ttype = SF_LABEL; + g_current_ttype = TT_LABEL; (*lines)[li]->items[ly]->u.text->style = cho_style_new_default(); (*lines)[li]->items[ly]->u.text->text = label; te += strlen(label); @@ -4025,7 +4023,7 @@ cho_songs_parse(FILE *fp, const char *chordpro_filepath, struct Config *config) } break; case DT_OUTPUT: - if (directive->btype != BT_EMPTY) { + if (directive->btype != -1) { (*lines)[li]->btype = directive->btype; } break; @@ -4072,7 +4070,7 @@ cho_songs_parse(FILE *fp, const char *chordpro_filepath, struct Config *config) switch (directive->dtype) { case DT_ENVIRONMENT: if (strlen(stripped_directive_value) > 0) { - songs[so]->present_text_types[SF_LABEL] = true; + songs[so]->present_text_types[TT_LABEL] = true; } g_current_ttype = directive->ttype; switch (directive->position) { @@ -4102,7 +4100,7 @@ cho_songs_parse(FILE *fp, const char *chordpro_filepath, struct Config *config) } else { songs[so]->sections[se]->label->text = strdup(stripped_directive_value); } - songs[so]->sections[se]->label->style = cho_style_new_from_config(SF_LABEL); + songs[so]->sections[se]->label->style = cho_style_new_from_config(TT_LABEL); li = 0; lines = &songs[so]->sections[se]->lines; *lines = emalloc(sizeof(struct ChoLine *)); @@ -4129,7 +4127,7 @@ cho_songs_parse(FILE *fp, const char *chordpro_filepath, struct Config *config) (*lines)[li]->items[ly] = cho_line_item_new(); } break; - case POS_EMPTY: + case POS_NO: /* INFO: {chorus: ...} */ label = strdup(stripped_directive_value); chorus = cho_find_previous_chorus(songs[so]->sections, se); @@ -4159,7 +4157,7 @@ cho_songs_parse(FILE *fp, const char *chordpro_filepath, struct Config *config) songs[so]->sections[se]->label->text = label; } else { songs[so]->sections[se]->label = emalloc(sizeof(struct ChoText)); - g_current_ttype = SF_LABEL; + g_current_ttype = TT_LABEL; songs[so]->sections[se]->label->style = cho_style_new_default(); } se++; @@ -4185,7 +4183,7 @@ cho_songs_parse(FILE *fp, const char *chordpro_filepath, struct Config *config) (*lines)[li]->items = erealloc((*lines)[li]->items, (ly+1) * sizeof(struct ChoLineItem *)); (*lines)[li]->items[ly] = cho_line_item_new(); cho_style_free((*lines)[li]->items[ly]->u.text->style); - g_current_ttype = SF_LABEL; + g_current_ttype = TT_LABEL; (*lines)[li]->items[ly]->u.text->style = cho_style_new_default(); (*lines)[li]->items[ly]->u.text->text = label; te += strlen(label); @@ -4208,7 +4206,7 @@ cho_songs_parse(FILE *fp, const char *chordpro_filepath, struct Config *config) (*lines)[li]->items = erealloc((*lines)[li]->items, (ly+1) * sizeof(struct ChoLineItem *)); (*lines)[li]->items[ly] = cho_line_item_new(); cho_style_free((*lines)[li]->items[ly]->u.text->style); - g_current_ttype = SF_LABEL; + g_current_ttype = TT_LABEL; (*lines)[li]->items[ly]->u.text->style = cho_style_new_default(); (*lines)[li]->items[ly]->u.text->text = label; te += strlen(label); @@ -4235,7 +4233,7 @@ cho_songs_parse(FILE *fp, const char *chordpro_filepath, struct Config *config) cho_style_free(songs[so]->metadata[m]->style); songs[so]->metadata[m]->style = cho_style_copy(directive->style); m++; - songs[so]->present_text_types[SF_TITLE] = true; + songs[so]->present_text_types[TT_TITLE] = true; break; case SUBTITLE: songs[so]->metadata = erealloc(songs[so]->metadata, (m+1) * sizeof(struct ChoMetadata *)); @@ -4245,7 +4243,7 @@ cho_songs_parse(FILE *fp, const char *chordpro_filepath, struct Config *config) cho_style_free(songs[so]->metadata[m]->style); songs[so]->metadata[m]->style = cho_style_copy(directive->style); m++; - songs[so]->present_text_types[SF_SUBTITLE] = true; + songs[so]->present_text_types[TT_SUBTITLE] = true; break; default: if (!strcmp(directive_name, "meta")) { @@ -4423,7 +4421,7 @@ cho_songs_parse(FILE *fp, const char *chordpro_filepath, struct Config *config) chord[ch] = 0; ch = 0; g_prev_ttype = g_current_ttype; - g_current_ttype = SF_CHORD; + g_current_ttype = TT_CHORD; if (is_chord_already_initialized) { text_above_pos = cho_line_compute_text_above_position(songs[so]->sections[se]->lines[li], ly, te); (*lines)[li]->text_above[c]->position = text_above_pos; @@ -4445,7 +4443,7 @@ cho_songs_parse(FILE *fp, const char *chordpro_filepath, struct Config *config) cho_log(LOG_INFO, "Didn't recognize the chord '%s'.", (*lines)[li]->text_above[c]->u.chord->name); } } - songs[so]->present_text_types[SF_CHORD] = true; + songs[so]->present_text_types[TT_CHORD] = true; memset(chord, 0, strlen(chord)); c++; g_current_ttype = g_prev_ttype; @@ -4454,7 +4452,7 @@ cho_songs_parse(FILE *fp, const char *chordpro_filepath, struct Config *config) } if (prev_buf == '[' && buf == '*') { g_prev_ttype = g_current_ttype; - g_current_ttype = SF_ANNOT; + g_current_ttype = TT_ANNOT; (*lines)[li]->text_above = erealloc((*lines)[li]->text_above, (c+1) * sizeof(struct ChoLineItemAbove *)); (*lines)[li]->text_above[c] = emalloc(sizeof(struct ChoLineItemAbove)); (*lines)[li]->text_above[c]->is_chord = false; @@ -4491,7 +4489,7 @@ cho_songs_parse(FILE *fp, const char *chordpro_filepath, struct Config *config) if (buf == ']') { (*lines)[li]->text_above[c]->u.annot->text = erealloc((*lines)[li]->text_above[c]->u.annot->text, (ann+1) * sizeof(char)); (*lines)[li]->text_above[c]->u.annot->text[ann] = 0; - songs[so]->present_text_types[SF_ANNOT] = true; + songs[so]->present_text_types[TT_ANNOT] = true; ann = 0; c++; g_current_ttype = g_prev_ttype; @@ -4710,7 +4708,7 @@ cho_songs_parse(FILE *fp, const char *chordpro_filepath, struct Config *config) cho_log(LOG_ERR, "Newline character inside an attribute value is invalid."); return NULL; } - if (avs == AVS_NO) { + if (avs == -1) { if (is_whitespace(buf)) { cho_log(LOG_ERR, "Whitespace character after equals sign is invalid."); return NULL; @@ -4776,7 +4774,7 @@ cho_songs_parse(FILE *fp, const char *chordpro_filepath, struct Config *config) } } at = 0; - avs = AVS_NO; + avs = -1; memset(tag_start, 0, strlen(tag_start)); state = prev_state; break; @@ -4792,7 +4790,7 @@ cho_songs_parse(FILE *fp, const char *chordpro_filepath, struct Config *config) at++; tags[ta]->attrs = erealloc(tags[ta]->attrs, (at+1) * sizeof(struct Attr *)); tags[ta]->attrs[at] = cho_tag_attr_new(); - avs = AVS_NO; + avs = -1; state = STATE_MARKUP_ATTR_NAME; break; } @@ -4852,8 +4850,8 @@ cho_songs_parse(FILE *fp, const char *chordpro_filepath, struct Config *config) so++; songs = erealloc(songs, (so+1) * sizeof(struct ChoSong *)); songs[so] = NULL; - g_current_ttype = SF_TEXT; - g_prev_ttype = SF_TEXT; + g_current_ttype = TT_TEXT; + g_prev_ttype = TT_TEXT; g_config = NULL; g_chordpro_filepath = NULL; free(g_transpose_history); diff --git a/chordpro.h b/chordpro.h @@ -3,27 +3,26 @@ #ifndef _CHORDPRO_H_ #define _CHORDPRO_H_ -enum TextType { - SF_EMPTY, - SF_CHORD, - SF_ANNOT, - SF_CHORUS, - SF_FOOTER, - SF_GRID, - SF_TAB, - SF_TOC, - SF_TOC_TITLE, - SF_TEXT, - SF_TITLE, - SF_SUBTITLE, - SF_LABEL, - SF_COMMENT, - SF_COMMENT_ITALIC, - SF_COMMENT_BOX, - SF_LENGTH -}; - -enum Alignment { +enum TextType : int8_t { + TT_CHORD, + TT_ANNOT, + TT_CHORUS, + TT_FOOTER, + TT_GRID, + TT_TAB, + TT_TOC, + TT_TOC_TITLE, + TT_TEXT, + TT_TITLE, + TT_SUBTITLE, + TT_LABEL, + TT_COMMENT, + TT_COMMENT_ITALIC, + TT_COMMENT_BOX, + TT_LENGTH +}; + +enum Alignment : int8_t { A_LEFT, A_CENTER, A_RIGHT @@ -49,22 +48,19 @@ enum Anchor { AN_FLOAT }; -enum AttrValueSyntax { - AVS_NO, +enum AttrValueSyntax : int8_t { AVS_QUOTATION_MARK, AVS_APOSTROPHE, AVS_UNQUOTED }; -enum BreakType { - BT_EMPTY, +enum BreakType : int8_t { BT_LINE, BT_PAGE, BT_COLUMN }; -enum ChordDiagramContent { - CDC_EMPTY, +enum ChordDiagramContent : int8_t { CDC_STRING, CDC_KEYBOARD }; @@ -83,7 +79,6 @@ enum ChordDirective { }; enum ChordQualifier { - CQ_EMPTY, CQ_MIN, CQ_MAJ, CQ_AUG, @@ -91,7 +86,6 @@ enum ChordQualifier { }; enum DirectiveType { - DT_EMPTY, DT_ENVIRONMENT, DT_METADATA, DT_FORMATTING, @@ -103,32 +97,28 @@ enum DirectiveType { DT_CUSTOM }; -enum FontFamily { +enum FontFamily : int8_t { FF_NORMAL, FF_SANS, FF_SERIF, - FF_MONOSPACE, - FF_EMPTY, + FF_MONOSPACE }; -enum FontStyle { +enum FontStyle : int8_t { FS_ROMAN, FS_OBLIQUE, - FS_ITALIC, - FS_EMPTY + FS_ITALIC }; -enum FontWeight { +enum FontWeight : int8_t { FW_REGULAR, - FW_BOLD, - FW_EMPTY + FW_BOLD }; -enum LineStyle { +enum LineStyle : int8_t { LS_SINGLE, LS_DOUBLE, - LS_NONE, - LS_EMPTY + LS_NONE }; enum MetadataDirective { @@ -142,13 +132,12 @@ enum OptionState { }; enum Position { - POS_EMPTY, POS_START, - POS_END + POS_END, + POS_NO }; enum SectionType { - ST_EMPTY, ST_NEWSONG, ST_CHORUS, ST_VERSE, @@ -172,8 +161,7 @@ enum State { STATE_COMMENT }; -enum StylePropertyType { - SPT_EMPTY, +enum StylePropertyType : int8_t { SPT_FONT, SPT_SIZE, SPT_COLOR @@ -307,7 +295,7 @@ struct ChoSong { struct ChoMetadata **metadata; struct ChoSection **sections; struct ChordDiagram **diagrams; - bool present_text_types[SF_LENGTH]; + bool present_text_types[TT_LENGTH]; }; union StylePropertyValue { diff --git a/config.c b/config.c @@ -26,12 +26,11 @@ static const char *instruments[] = { "guitar", "keyboard", "mandolin", - "ukulele", - "unknown" + "ukulele" }; static const char *text_types[] = { - "empty", "chord", "annotation", "chorus", + "chord", "annotation", "chorus", "footer", "grid", "tab", "toc", "toc_title", "text", "title", "subtitle", "label", "comment", "comment_italic", "comment_box" @@ -126,52 +125,52 @@ static struct Note notes_nashville[] = { static enum TextType config_text_type_parse(const char *str) { - if (!strcmp(str, text_types[SF_CHORD])) { - return SF_CHORD; + if (!strcmp(str, text_types[TT_CHORD])) { + return TT_CHORD; } else - if (!strcmp(str, text_types[SF_ANNOT])) { - return SF_ANNOT; + if (!strcmp(str, text_types[TT_ANNOT])) { + return TT_ANNOT; } else - if (!strcmp(str, text_types[SF_CHORUS])) { - return SF_CHORUS; + if (!strcmp(str, text_types[TT_CHORUS])) { + return TT_CHORUS; } else - if (!strcmp(str, text_types[SF_FOOTER])) { - return SF_FOOTER; + if (!strcmp(str, text_types[TT_FOOTER])) { + return TT_FOOTER; } else - if (!strcmp(str, text_types[SF_GRID])) { - return SF_GRID; + if (!strcmp(str, text_types[TT_GRID])) { + return TT_GRID; } else - if (!strcmp(str, text_types[SF_TAB])) { - return SF_TAB; + if (!strcmp(str, text_types[TT_TAB])) { + return TT_TAB; } else - if (!strcmp(str, text_types[SF_TOC])) { - return SF_TOC; + if (!strcmp(str, text_types[TT_TOC])) { + return TT_TOC; } else - if (!strcmp(str, text_types[SF_TOC_TITLE])) { - return SF_TOC_TITLE; + if (!strcmp(str, text_types[TT_TOC_TITLE])) { + return TT_TOC_TITLE; } else - if (!strcmp(str, text_types[SF_TEXT])) { - return SF_TEXT; + if (!strcmp(str, text_types[TT_TEXT])) { + return TT_TEXT; } else - if (!strcmp(str, text_types[SF_TITLE])) { - return SF_TITLE; + if (!strcmp(str, text_types[TT_TITLE])) { + return TT_TITLE; } else - if (!strcmp(str, text_types[SF_SUBTITLE])) { - return SF_SUBTITLE; + if (!strcmp(str, text_types[TT_SUBTITLE])) { + return TT_SUBTITLE; } else - if (!strcmp(str, text_types[SF_LABEL])) { - return SF_LABEL; + if (!strcmp(str, text_types[TT_LABEL])) { + return TT_LABEL; } else - if (!strcmp(str, text_types[SF_COMMENT])) { - return SF_COMMENT; + if (!strcmp(str, text_types[TT_COMMENT])) { + return TT_COMMENT; } else - if (!strcmp(str, text_types[SF_COMMENT_ITALIC])) { - return SF_COMMENT_ITALIC; + if (!strcmp(str, text_types[TT_COMMENT_ITALIC])) { + return TT_COMMENT_ITALIC; } else - if (!strcmp(str, text_types[SF_COMMENT_BOX])) { - return SF_COMMENT_BOX; + if (!strcmp(str, text_types[TT_COMMENT_BOX])) { + return TT_COMMENT_BOX; } - return SF_EMPTY; + return -1; } static enum NamingSystem @@ -213,8 +212,9 @@ config_instrument_parse(const char *str) return INS_MANDOLIN; } else if (!strcmp(str, "ukulele")) { + return INS_UKULELE; } - return INS_UNKNOWN; + return -1; } static const char * @@ -403,7 +403,7 @@ config_alignment_parse(const char *str) if (!strcmp(str, "right")) { return A_RIGHT; } - return ENUM_UNKNOWN; + return -1; } static const char * @@ -428,53 +428,52 @@ config_load_default(void) config->output->diagram->instrument = INS_GUITAR; config->output->system = NS_COMMON; config->output->page_no_position = A_CENTER; - config->output->styles = emalloc(SF_LENGTH * sizeof(struct ChoStyle *)); + config->output->styles = emalloc(TT_LENGTH * sizeof(struct ChoStyle *)); - config->output->styles[SF_EMPTY] = NULL; - config->output->styles[SF_CHORD] = cho_style_new(); - config->output->styles[SF_CHORD]->font->name = strdup(DEFAULT_FONT_FAMILY); - config->output->styles[SF_CHORD]->font->weight = FW_BOLD; - config->output->styles[SF_ANNOT] = cho_style_new(); - config->output->styles[SF_ANNOT]->font->name = strdup(DEFAULT_FONT_FAMILY); - config->output->styles[SF_ANNOT]->font->style = FS_ITALIC; - config->output->styles[SF_CHORUS] = cho_style_new(); - config->output->styles[SF_CHORUS]->font->name = strdup(DEFAULT_FONT_FAMILY); - config->output->styles[SF_FOOTER] = cho_style_new(); - config->output->styles[SF_GRID] = cho_style_new(); - config->output->styles[SF_GRID]->font->name = strdup(DEFAULT_FONT_FAMILY); - config->output->styles[SF_GRID]->font->weight = FW_BOLD; - config->output->styles[SF_TAB] = cho_style_new(); - config->output->styles[SF_TAB]->font->name = strdup(DEFAULT_FONT_FAMILY); - config->output->styles[SF_TOC] = cho_style_new(); - config->output->styles[SF_TOC]->font->name = strdup(DEFAULT_FONT_FAMILY); - config->output->styles[SF_TOC]->font->size = 12.0; - config->output->styles[SF_TOC_TITLE] = cho_style_new(); - config->output->styles[SF_TOC_TITLE]->font->name = strdup(DEFAULT_FONT_FAMILY); - config->output->styles[SF_TOC_TITLE]->font->weight = FW_BOLD; - config->output->styles[SF_TOC_TITLE]->font->size = 18.0; - config->output->styles[SF_TEXT] = cho_style_new(); - config->output->styles[SF_TEXT]->font->name = strdup(DEFAULT_FONT_FAMILY); - config->output->styles[SF_TITLE] = cho_style_new(); - config->output->styles[SF_TITLE]->font->name = strdup(DEFAULT_FONT_FAMILY); - config->output->styles[SF_TITLE]->font->weight = FW_BOLD; - config->output->styles[SF_TITLE]->font->size = 18.0; - config->output->styles[SF_SUBTITLE] = cho_style_new(); - config->output->styles[SF_SUBTITLE]->font->name = strdup(DEFAULT_FONT_FAMILY); - config->output->styles[SF_SUBTITLE]->font->size = 12.0; - config->output->styles[SF_LABEL] = cho_style_new(); - config->output->styles[SF_LABEL]->font->name = strdup(DEFAULT_FONT_FAMILY); - config->output->styles[SF_LABEL]->font->style = FS_ITALIC; - config->output->styles[SF_COMMENT] = cho_style_new(); - config->output->styles[SF_COMMENT]->font->name = strdup(DEFAULT_FONT_FAMILY); - config->output->styles[SF_COMMENT]->background_color->red = 228; - config->output->styles[SF_COMMENT]->background_color->green = 228; - config->output->styles[SF_COMMENT]->background_color->blue = 228; - config->output->styles[SF_COMMENT_ITALIC] = cho_style_new(); - config->output->styles[SF_COMMENT_ITALIC]->font->name = strdup(DEFAULT_FONT_FAMILY); - config->output->styles[SF_COMMENT_ITALIC]->font->style = FS_ITALIC; - config->output->styles[SF_COMMENT_BOX] = cho_style_new(); - config->output->styles[SF_COMMENT_BOX]->font->name = strdup(DEFAULT_FONT_FAMILY); - config->output->styles[SF_COMMENT_BOX]->boxed = true; + config->output->styles[TT_CHORD] = cho_style_new(); + config->output->styles[TT_CHORD]->font->name = strdup(DEFAULT_FONT_FAMILY); + config->output->styles[TT_CHORD]->font->weight = FW_BOLD; + config->output->styles[TT_ANNOT] = cho_style_new(); + config->output->styles[TT_ANNOT]->font->name = strdup(DEFAULT_FONT_FAMILY); + config->output->styles[TT_ANNOT]->font->style = FS_ITALIC; + config->output->styles[TT_CHORUS] = cho_style_new(); + config->output->styles[TT_CHORUS]->font->name = strdup(DEFAULT_FONT_FAMILY); + config->output->styles[TT_FOOTER] = cho_style_new(); + config->output->styles[TT_GRID] = cho_style_new(); + config->output->styles[TT_GRID]->font->name = strdup(DEFAULT_FONT_FAMILY); + config->output->styles[TT_GRID]->font->weight = FW_BOLD; + config->output->styles[TT_TAB] = cho_style_new(); + config->output->styles[TT_TAB]->font->name = strdup(DEFAULT_FONT_FAMILY); + config->output->styles[TT_TOC] = cho_style_new(); + config->output->styles[TT_TOC]->font->name = strdup(DEFAULT_FONT_FAMILY); + config->output->styles[TT_TOC]->font->size = 12.0; + config->output->styles[TT_TOC_TITLE] = cho_style_new(); + config->output->styles[TT_TOC_TITLE]->font->name = strdup(DEFAULT_FONT_FAMILY); + config->output->styles[TT_TOC_TITLE]->font->weight = FW_BOLD; + config->output->styles[TT_TOC_TITLE]->font->size = 18.0; + config->output->styles[TT_TEXT] = cho_style_new(); + config->output->styles[TT_TEXT]->font->name = strdup(DEFAULT_FONT_FAMILY); + config->output->styles[TT_TITLE] = cho_style_new(); + config->output->styles[TT_TITLE]->font->name = strdup(DEFAULT_FONT_FAMILY); + config->output->styles[TT_TITLE]->font->weight = FW_BOLD; + config->output->styles[TT_TITLE]->font->size = 18.0; + config->output->styles[TT_SUBTITLE] = cho_style_new(); + config->output->styles[TT_SUBTITLE]->font->name = strdup(DEFAULT_FONT_FAMILY); + config->output->styles[TT_SUBTITLE]->font->size = 12.0; + config->output->styles[TT_LABEL] = cho_style_new(); + config->output->styles[TT_LABEL]->font->name = strdup(DEFAULT_FONT_FAMILY); + config->output->styles[TT_LABEL]->font->style = FS_ITALIC; + config->output->styles[TT_COMMENT] = cho_style_new(); + config->output->styles[TT_COMMENT]->font->name = strdup(DEFAULT_FONT_FAMILY); + config->output->styles[TT_COMMENT]->background_color->red = 228; + config->output->styles[TT_COMMENT]->background_color->green = 228; + config->output->styles[TT_COMMENT]->background_color->blue = 228; + config->output->styles[TT_COMMENT_ITALIC] = cho_style_new(); + config->output->styles[TT_COMMENT_ITALIC]->font->name = strdup(DEFAULT_FONT_FAMILY); + config->output->styles[TT_COMMENT_ITALIC]->font->style = FS_ITALIC; + config->output->styles[TT_COMMENT_BOX] = cho_style_new(); + config->output->styles[TT_COMMENT_BOX]->font->name = strdup(DEFAULT_FONT_FAMILY); + config->output->styles[TT_COMMENT_BOX]->boxed = true; // config->output->styles[15] = NULL; config->output->notes = config_notes_new_default(NS_COMMON); @@ -511,7 +510,7 @@ config_print_default(void) printf("quote = false\n\n"); printf("[output.styles]\n"); int i; - for (i = 1; i<SF_LENGTH; i++) { + for (i = 1; i<TT_LENGTH; i++) { printf("[output.styles.%s]\n\n", text_types[i]); cho_style_print_as_toml(config->output->styles[i], text_types[i]); } @@ -539,7 +538,7 @@ config_load_font(struct Font *font, toml_table_t *table, const char *key_name, s if (value.ok) { presence->font.family = true; family = cho_font_family_parse(value.u.s); - if (family != FF_EMPTY) { + if (family != -1) { font->family = family; } else { util_log(LOG_ERR, "Config section [output.styles.%s.font] family value is invalid.", key_name); @@ -551,7 +550,7 @@ config_load_font(struct Font *font, toml_table_t *table, const char *key_name, s if (value.ok) { presence->font.style = true; style = cho_font_style_parse(value.u.s); - if (style != FS_EMPTY) { + if (style != -1) { font->style = style; } else { util_log(LOG_ERR, "Config section [output.styles.%s.font] style value is invalid.", key_name); @@ -563,7 +562,7 @@ config_load_font(struct Font *font, toml_table_t *table, const char *key_name, s if (value.ok) { presence->font.weight = true; weight = cho_font_weight_parse(value.u.s); - if (weight != FW_EMPTY) { + if (weight != -1) { font->weight = weight; } else { util_log(LOG_ERR, "Config section [output.styles.%s.font] weight value is invalid.", key_name); @@ -627,7 +626,7 @@ config_load_style( if (value.ok) { presence->underline_style = true; line_style = cho_linestyle_parse(value.u.s); - if (line_style != LS_EMPTY) { + if (line_style != -1) { style->underline_style = line_style; } else { util_log(LOG_ERR, "Config section [output.styles.%s] underline style value is invalid.", key_name); @@ -652,7 +651,7 @@ config_load_style( if (value.ok) { presence->overline_style = true; line_style = cho_linestyle_parse(value.u.s); - if (line_style != LS_EMPTY) { + if (line_style != -1) { style->overline_style = line_style; } else { util_log(LOG_ERR, "Config section [output.styles.%s] overline style value is invalid.", key_name); @@ -722,6 +721,8 @@ config_load_style( return true; } +#ifdef DEBUG + static void presence_print(const char *name, struct ChoStylePresence *presence) { @@ -747,6 +748,8 @@ presence_print(const char *name, struct ChoStylePresence *presence) printf("---- END PRESENCE ------\n"); } +#endif /* DEBUG */ + static void set_text_style( struct ChoStylePresence *text_presence, @@ -827,11 +830,11 @@ lyrics_set_text_style_as_default( struct ChoStyle *style, *text_style; struct ChoStylePresence *presence, *text_presence; enum TextType lyric_types[] = { - SF_CHORUS, SF_COMMENT, - SF_COMMENT_ITALIC, SF_COMMENT_BOX + TT_CHORUS, TT_COMMENT, + TT_COMMENT_ITALIC, TT_COMMENT_BOX }; - text_presence = &presences[SF_TEXT]; - text_style = styles[SF_TEXT]; + text_presence = &presences[TT_TEXT]; + text_style = styles[TT_TEXT]; size_t i; for (i = 0; i<LENGTH(lyric_types); i++) { presence = &presences[lyric_types[i]]; @@ -903,7 +906,7 @@ config_load(const char *filepath) value = toml_table_string(diagram, "instrument"); if (value.ok) { instrument = config_instrument_parse(value.u.s); - if (instrument == INS_UNKNOWN) { + if (instrument == -1) { util_log(LOG_ERR, "Unknown instrument '%s' in [output.chord_diagram].", value.u.s); return NULL; } @@ -938,7 +941,7 @@ config_load(const char *filepath) value = toml_table_string(output, "page_no_position"); if (value.ok) { position = config_alignment_parse(value.u.s); - if (position == ENUM_UNKNOWN) { + if (position == -1) { LOG_DEBUG("config_alignment_parse failed."); return NULL; } @@ -951,12 +954,12 @@ config_load(const char *filepath) const char *key_name; enum TextType ttype; struct ChoStyle *style; - struct ChoStylePresence presences[SF_LENGTH] = {0}; + struct ChoStylePresence presences[TT_LENGTH] = {0}; toml_table_t *key; for (i = 0; i<toml_table_len(styles); i++) { key_name = toml_table_key(styles, i, &unused); ttype = config_text_type_parse(key_name); - if (ttype != SF_EMPTY) { + if (ttype != -1) { key = toml_table_table(styles, key_name); if (key) { style = config->output->styles[ttype]; @@ -1026,7 +1029,7 @@ config_free(struct Config *config) free(config->output->chorus->label); free(config->output->chorus); int i; - for (i = 0; i<SF_LENGTH; i++) { + for (i = 0; i<TT_LENGTH; i++) { cho_style_free(config->output->styles[i]); } free(config->output->styles); diff --git a/config.h b/config.h @@ -29,12 +29,11 @@ enum NoteType { NT_FLAT }; -enum Instrument { +enum Instrument : int8_t { INS_GUITAR, INS_KEYBOARD, INS_MANDOLIN, - INS_UKULELE, - INS_UNKNOWN + INS_UKULELE }; struct FontPresence { diff --git a/lorid.h b/lorid.h @@ -1,297 +0,0 @@ -#include <stdint.h> -#include <stdbool.h> -#include <stdlib.h> - -enum FontFamily { - FF_EMPTY = -1, - FF_NORMAL, - FF_SANS, - FF_SERIF, - FF_MONOSPACE -}; - -enum FontStyle { - FS_EMPTY = -1, - FS_ROMAN, - FS_OBLIQUE, - FS_ITALIC -}; - -enum FontWeight { - FW_EMPTY = -1, - FW_REGULAR, - FW_BOLD -}; - -struct Font { - char *name; - enum FontFamily family; - enum FontStyle style; - enum FontWeight weight; - double size; -}; - -enum LineStyle { - LS_EMPTY = -1, - LS_SINGLE, - LS_DOUBLE, - LS_NONE -}; - -struct RGBColor { - uint8_t red; - uint8_t green; - uint8_t blue; -}; - -struct Style { - struct Font *font; - struct RGBColor *foreground_color; - struct RGBColor *background_color; - enum LineStyle underline_style; - struct RGBColor *underline_color; - enum LineStyle overline_style; - struct RGBColor *overline_color; - bool strikethrough; - struct RGBColor *strikethrough_color; - bool boxed; - struct RGBColor *boxed_color; - double rise; - char *href; -}; - -struct Attr { - char *name; - char *value; -}; - -struct Tag { - char *name; - struct Style *style; - struct Attr **attrs; - bool is_closed; -}; - -enum AttrValueSyntax { - AVS_NO, - AVS_QUOTATION_MARK, - AVS_APOSTROPHE, - AVS_UNQUOTED -}; - -enum State { - STATE_LYRICS, - STATE_DIRECTIVE_NAME, - STATE_DIRECTIVE_VALUE, - STATE_CHORD, - STATE_ANNOTATION, - STATE_MARKUP_TAG_BEGIN, - STATE_MARKUP_TAG_END, - STATE_MARKUP_TAG, - STATE_MARKUP_ATTR_NAME, - STATE_MARKUP_ATTR_VALUE, - STATE_COMMENT -}; - -/* Similar to SectionType but different enough for a separate type */ -enum SongFragmentType { - SF_EMPTY = -1, - SF_CHORD, - SF_ANNOT, - SF_CHORUS, - SF_FOOTER, - SF_GRID, - SF_TAB, - SF_TOC, - SF_TEXT, - SF_TITLE, - SF_LABEL -}; - -enum StylePropertyType { - SPT_EMPTY = -1, - SPT_FONT, - SPT_SIZE, - SPT_COLOR -}; - -union StylePropertyValue { - char *font_name; - double font_size; - struct RGBColor *foreground_color; -}; - -struct StyleProperty { - enum SongFragmentType ftype; - enum StylePropertyType type; - union StylePropertyValue u; -}; - -enum DirectiveType { - DT_EMPTY = -1, - DT_ENVIRONMENT, - DT_METADATA, - DT_FORMATTING, - DT_PREAMBLE, - DT_FONT, - DT_OUTPUT, - DT_CUSTOM -}; - -enum SectionType { - ST_EMPTY = -1, - ST_NEWSONG, - ST_CHORUS, - ST_VERSE, - ST_BRIDGE, - ST_TAB, - ST_GRID, - ST_CUSTOM -}; - -enum Position { - POS_EMPTY = -1, - POS_START, - POS_END -}; - -enum ChordQualifier { - CQ_EMPTY = -1, - CQ_MIN, - CQ_MAJ, - CQ_AUG, - CQ_DIM -}; - -enum BreakType { - BT_EMPTY = -1, - BT_LINE, - BT_PAGE, - BT_COLUMN -}; - -struct ChoDirective { - enum DirectiveType dtype; - enum SectionType stype; - enum Position position; - enum StylePropertyType sprop; - enum SongFragmentType ftype; - enum BreakType btype; - struct Style *style; -}; - -struct ChoMetadata { - char *name; - char *value; - struct Style *style; -}; - -struct ChoChord { - struct Style *style; - bool is_canonical; - char *name; - char *root; - enum ChordQualifier qual; - char *ext; - char *bass; -}; - -struct ChoAnnotation { - struct Style *style; - char *text; -}; - -struct ChoLineItem { - struct Style *style; - char *text; -}; - -struct ChoLineItemAbove { - int position; - bool is_chord; - union { - struct ChoChord *chord; - struct ChoAnnotation *annot; - } u; -}; - -struct ChoLine { - struct ChoLineItemAbove **text_above; - struct ChoLineItem **lyrics; - enum BreakType btype; -}; - -struct ChoLabel { - char *name; - struct Style *style; -}; - -struct ChoSection { - enum SectionType type; - struct ChoLabel *label; - struct ChoLine **lines; -}; - -struct ChoSong { - struct ChoMetadata **metadata; - struct ChoSection **sections; -}; - -struct PrintableItem { - char *name; - struct Style *style; -}; - -enum NamingSystem { - NS_COMMON, - NS_GERMAN, - NS_SCANDINAVIAN, - NS_LATIN, - NS_ROMAN, - NS_NASHVILLE, - NS_CUSTOM -}; - -enum ParseMode { - PM_STRICT, - PM_RELAXED -}; - -struct Note { - char *note; - char *sharp; - char *flat; -}; - -struct ConfigChords { - enum NamingSystem system; - enum ParseMode mode; - // struct Note **notes; -}; - -/* struct Config { - struct PrintableItem **printable_items; - struct ConfigChords *chords; -}; */ - -struct ConfigParser { - struct ConfigChords *chords; - struct Note **notes; -}; - -struct ConfigOutput { - enum NamingSystem system; - struct PrintableItem **printable_items; - struct Note **notes; -}; - -struct Config { - struct ConfigOutput *output; - struct ConfigParser *parser; -}; - -extern struct ChoSong **cho_songs_parse(FILE *fp, struct Config *config); -extern void cho_songs_free(struct ChoSong **song); -extern char *out_pdf_new(const char *cho_filename, const char *output_folder_or_file, struct ChoSong **songs, struct Config *config); -extern struct Config *config_load(const char *filepath); -extern void config_free(struct Config *config); diff --git a/out_pdf.c b/out_pdf.c @@ -108,6 +108,7 @@ out_pdf_fnt_obj_get_by_name(const char *name) return g_fonts[i]->value; } } + printf("name '%s'\n", name); return NULL; } @@ -186,7 +187,7 @@ fonts_get_all(struct ChoSong **songs, struct Config *config) bool added; int i; for (so = songs; *so; so++) { - for (i = 0; i < SF_LENGTH; i++) { + for (i = 0; i < TT_LENGTH; i++) { if ((*so)->present_text_types[i]) { font = cho_font_copy(config->output->styles[i]->font); added = fonts_add_if_not_in(&fonts, font); @@ -1688,8 +1689,6 @@ pdf_page_add_page_no(struct PDFContext *ctx, enum NumeralSystem numeral_system) const char *page_no; double width, x; - printf("page no position %d\n", g_config->output->page_no_position); - style = cho_style_new(); style->font->name = strdup(DEFAULT_FONT_FAMILY); texts = &ctx->content->pages[ctx->page]->texts; @@ -1720,6 +1719,9 @@ pdf_page_add_page_no(struct PDFContext *ctx, enum NumeralSystem numeral_system) case A_RIGHT: x = MEDIABOX_WIDTH - MARGIN_HORIZONTAL / 2 - width; break; + default: + util_log(LOG_ERR, "Invalid Alignment enum value '%d'.", g_config->output->page_no_position); + return false; } (*texts)[ctx->text]->x = x; ctx->text++; @@ -2134,7 +2136,7 @@ pdf_toc_create( LOG_DEBUG("pdf_page_add_page_no failed."); return false; } - toc_style = config->output->styles[SF_TOC]; + toc_style = config->output->styles[TT_TOC]; toc = pdf_content->toc; max_song_title_width = LINE_WIDTH * 0.85; toc_page_count = pdf_toc_page_count(toc, toc_style, max_song_title_width); @@ -2142,7 +2144,7 @@ pdf_toc_create( LOG_DEBUG("pdf_toc_page_count failed."); return false; } - title_style = config->output->styles[SF_TOC_TITLE]; + title_style = config->output->styles[TT_TOC_TITLE]; if (!pdf_texts_add_text(&ctx, config->output->toc->title, title_style, A_CENTER, NUS_ROMAN)) { LOG_DEBUG("pdf_texts_add_text failed."); return false; @@ -2256,7 +2258,7 @@ pdf_content_create( config file */ struct ChoStyle *output_style; - output_style = config->output->styles[SF_SUBTITLE]; + output_style = config->output->styles[TT_SUBTITLE]; if (!pdf_texts_add_text(&ctx, (*m)->value, output_style, A_CENTER, NUS_WESTERN_ARABIC)) { LOG_DEBUG("pdf_texts_add_text failed."); return false; diff --git a/util.c b/util.c @@ -269,10 +269,10 @@ file_type(const char *path) if (stat(path, &s) != 0) { return F_ERROR; } - switch (s.st_mode & S_IFMT) { - case S_IFDIR: + if (S_ISDIR(s.st_mode)) { return F_FOLDER; - case S_IFREG: + } + if (S_ISREG(s.st_mode)) { return F_REG_FILE; } return F_OTHER;