lorid

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

commit 56243a4c30ca1172edba725bd1e0e7f4064afdaa
parent 21fabeb3250c5aafc8e7e77a57ee50b520cb5a13
Author: nibo <nibo@relim.de>
Date:   Fri, 21 Mar 2025 21:21:52 +0100

Improve enum handling

- Remove enum type specifiers
- Decrease size of struct ChoStyle
  by reordering members

Diffstat:
Msrc/chord_diagram.c | 4++++
Msrc/chordpro.c | 118+++++++++++++++++++++++++++++++++++++++++--------------------------------------
Msrc/chordpro.h | 20++++++++++++--------
Msrc/config.c | 91+++++++++++++++++++++++++++++++++++++++++++------------------------------------
Msrc/types.h | 32+++++++++++++++-----------------
5 files changed, 142 insertions(+), 123 deletions(-)

diff --git a/src/chord_diagram.c b/src/chord_diagram.c @@ -575,6 +575,7 @@ chord_diagram_free(struct ChordDiagram *d) case CDC_CHORD_MAP: chord_map_free(d->u.cm); break; + default: } free(d); } @@ -638,6 +639,7 @@ chord_diagram_duplicate( return CDC_CHORD_MAP; } break; + default: } } switch (instrument) { @@ -720,6 +722,7 @@ debug_chord_diagram_print(struct ChordDiagram *diagram) printf("name: %s\n", diagram->u.cm->name); printf("display: %s\n", diagram->u.cm->display); break; + default: } printf("---- CHORD DIAGRAM END ------\n"); } @@ -826,6 +829,7 @@ chord_diagram_draw( case CDC_CHORD_MAP: util_log(NULL, 0, LOG_TODO, "well"); break; + default: } return true; } diff --git a/src/chordpro.c b/src/chordpro.c @@ -597,8 +597,9 @@ cho_fonts_free(struct Font **fonts) } enum FontFamily -cho_font_family_parse(const char *str) +cho_font_family_parse(const char *str, bool *error) { + *error = false; if (!strcmp(str, font_families[FF_SANS])) { return FF_SANS; } else if (!strcmp(str, font_families[FF_SERIF])) { @@ -607,9 +608,9 @@ cho_font_family_parse(const char *str) return FF_MONOSPACE; } else if (!strcmp(str, font_families[FF_NORMAL])) { return FF_NORMAL; - } else { - return -1; } + *error = true; + return FF_SANS; // unused } const char * @@ -619,17 +620,18 @@ cho_font_family_to_config_string(enum FontFamily font_family) } enum FontStyle -cho_font_style_parse(const char *str) +cho_font_style_parse(const char *str, bool *error) { + *error = false; if (!strcmp(str, font_styles[FS_ITALIC])) { return FS_ITALIC; } else if (!strcmp(str, font_styles[FS_OBLIQUE])) { return FS_OBLIQUE; } else if (!strcmp(str, font_styles[FS_ROMAN])) { return FS_ROMAN; - } else { - return -1; } + *error = true; + return FS_ITALIC; // unused } const char * @@ -639,15 +641,16 @@ cho_font_style_to_config_string(enum FontStyle style) } enum FontWeight -cho_font_weight_parse(const char *str) +cho_font_weight_parse(const char *str, bool *error) { - if (!strcmp(str, "bold")) { + *error = false; + if (!strcmp(str, font_weights[FW_BOLD])) { return FW_BOLD; - } else if (!strcmp(str, "normal")) { + } else if (!strcmp(str, font_weights[FW_REGULAR])) { return FW_REGULAR; - } else { - return -1; } + *error = true; + return FW_BOLD; // unused } const char * @@ -683,17 +686,18 @@ cho_font_print(struct Font *font) } enum LineStyle -cho_linestyle_parse(const char *str) +cho_linestyle_parse(const char *str, bool *error) { - if (!strcmp(str, "single")) { + *error = false; + if (!strcmp(str, line_styles[LS_SINGLE])) { return LS_SINGLE; - } else if (!strcmp(str, "double")) { + } else if (!strcmp(str, line_styles[LS_DOUBLE])) { return LS_DOUBLE; - } else if (!strcmp(str, "none")) { + } else if (!strcmp(str, line_styles[LS_NONE])) { return LS_NONE; - } else { - return -1; } + *error = true; + return LS_SINGLE; // unused } const char * @@ -1453,8 +1457,6 @@ cho_style_print_as_toml(struct ChoStyle *style, const char *section) static bool cho_style_change_default(struct ChoContext *ctx, struct StyleProperty sprop) { - if (sprop.type == -1) - return false; unsigned int i; for (i = 0; i<LENGTH(default_style_properties); i++) { if ( @@ -1900,6 +1902,7 @@ cho_metadata_substitution_replace( Handle the following metadata item names specially: 'chordpro.version', 'instrument.type', 'instrument.description', 'user.name' and 'user.fullname'. */ +// TODO: %{lang=""|yes|no} prints langs' value and the string 'yes', that's wrong. static char * cho_metadata_substitution_parse( struct ChoContext *ctx, @@ -1923,7 +1926,7 @@ cho_metadata_substitution_parse( } enum MetadataSubstitutionState state = MSS_NAME; - enum AttrValueSyntax avs = -1; + enum AttrValueSyntax avs = AVS_UNINITIALIZED; char name[128]; char name_index[8]; char value[4096]; @@ -1998,7 +2001,7 @@ cho_metadata_substitution_parse( break; } case MSS_VALUE: { - if (avs == -1) { + if (avs == AVS_UNINITIALIZED) { if (is_whitespace(c)) { cho_log(ctx, LOG_ERR, "Whitespace character after equals sign is invalid."); return NULL; @@ -2033,7 +2036,7 @@ cho_metadata_substitution_parse( state = MSS_TRUE_TEXT; break; } - if (avs == -1) { + if (avs == AVS_UNINITIALIZED) { state = MSS_TRUE_TEXT; break; } @@ -2100,6 +2103,7 @@ cho_metadata_substitution_parse( case AVS_UNQUOTED: value[n] = 0; break; + default: } break; case MSS_TRUE_TEXT: @@ -3040,7 +3044,7 @@ cho_image_directive_parse(struct ChoContext *ctx, const char *str) struct ChoImage *asset; char c; enum OptionState state = OS_NAME; - enum AttrValueSyntax avs = -1; + enum AttrValueSyntax avs = AVS_UNINITIALIZED; char name[6+1]; char value[URL_MAX_LEN+1]; int n = 0; @@ -3075,7 +3079,7 @@ cho_image_directive_parse(struct ChoContext *ctx, const char *str) n++; break; case OS_VALUE: - if (avs == -1) { + if (avs == AVS_UNINITIALIZED) { if (is_whitespace(c)) { cho_log(ctx, LOG_ERR, "Whitespace character after equals sign in image directive is invalid."); return NULL; @@ -3110,7 +3114,7 @@ cho_image_directive_parse(struct ChoContext *ctx, const char *str) memset(value, 0, v); n = 0; v = 0; - avs = -1; + avs = AVS_UNINITIALIZED; state = OS_NAME; break; } @@ -3358,8 +3362,8 @@ cho_chord_diagram_parse( { struct ChordDiagram *diagram = chord_diagram_new(); enum ChordDiagramState state = CDS_NAME; - enum ChordDiagramContent current_content = -1; - enum ChordDiagramContent future_content = -1; + enum ChordDiagramContent current_content = CDC_UNINITIALIZED; + enum ChordDiagramContent future_content = CDC_UNINITIALIZED; bool is_maybe_minus_one = false; char name[20]; char option[10]; @@ -3402,7 +3406,7 @@ cho_chord_diagram_parse( break; } option[i] = 0; - future_content = -1; + future_content = CDC_UNINITIALIZED; if (!strcmp(option, "base-fret")) { state = CDS_BASE_FRET; future_content = CDC_STRING; @@ -3434,7 +3438,7 @@ cho_chord_diagram_parse( } memset(option, 0, i); i = 0; - if (current_content == -1 && future_content != -1) { + if (current_content == CDC_UNINITIALIZED && future_content != CDC_UNINITIALIZED) { current_content = future_content; switch (future_content) { case CDC_STRING: @@ -3632,13 +3636,13 @@ cho_chord_diagram_parse( break; } chord_to_copy[i] = 0; - if (current_content != -1) { + if (current_content != CDC_UNINITIALIZED) { cho_log(ctx, LOG_ERR, "The define options 'base-fret', 'frets', 'fingers' and 'keys' are not allowed before the 'copy' option."); return NULL; } enum Instrument ins = ctx->config->output->diagram->instrument; current_content = chord_diagram_duplicate(diagram, custom_diagrams, custom_diagrams_len, name, chord_to_copy, ins); - if (current_content == -1) { + if (current_content == CDC_UNINITIALIZED) { cho_log(ctx, LOG_ERR, "Can't copy the diagram for the chord '%s'" "because no previous definition was found and also" "no predefined chord diagram for the instrument '%s'" @@ -3720,7 +3724,7 @@ cho_chord_diagram_parse( } case CDS_COPY: { chord_to_copy[i] = 0; - if (current_content != -1) { + if (current_content != CDC_UNINITIALIZED) { cho_log(ctx, LOG_ERR, "The define options 'base-fret', 'frets'," "'fingers' and 'keys' are not allowed before the 'copy'" "option."); @@ -3728,7 +3732,7 @@ cho_chord_diagram_parse( } enum Instrument ins = ctx->config->output->diagram->instrument; current_content = chord_diagram_duplicate(diagram, custom_diagrams, custom_diagrams_len, name, chord_to_copy, ins); - if (current_content == -1) { + if (current_content == CDC_UNINITIALIZED) { cho_log(ctx, LOG_ERR, "Can't copy the diagram for the chord '%s' because" "no previous definition was found and also no predefined" "chord diagram for the instrument '%s' was found.", @@ -3753,7 +3757,7 @@ cho_chord_diagram_parse( cho_log(ctx, LOG_ERR, "The number of frets (%d) and fingers (%d) in the chord diagram must be equal.", fret_count, finger_count); return NULL; } - if (current_content == -1) { + if (current_content == CDC_UNINITIALIZED) { cho_log(ctx, LOG_ERR, "The chord diagram is invalid."); return NULL; } @@ -4080,14 +4084,14 @@ static struct ChoDirective * cho_directive_new(struct ChoContext *ctx) { struct ChoDirective *directive = emalloc(sizeof(struct ChoDirective)); - 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->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(ctx); return directive; } @@ -4207,7 +4211,7 @@ cho_directive_parse(struct ChoContext *ctx, const char *name) !strcmp(name, "t") ) { directive->dtype = DT_METADATA; - directive->meta = TITLE; + directive->meta = MD_TITLE; cho_style_free(directive->style); ctx->prev_ttype = ctx->current_ttype; ctx->current_ttype = TT_TITLE; @@ -4220,7 +4224,7 @@ cho_directive_parse(struct ChoContext *ctx, const char *name) !strcmp(name, "st") ) { directive->dtype = DT_METADATA; - directive->meta = SUBTITLE; + directive->meta = MD_SUBTITLE; cho_style_free(directive->style); ctx->prev_ttype = ctx->current_ttype; ctx->current_ttype = TT_SUBTITLE; @@ -4245,6 +4249,7 @@ cho_directive_parse(struct ChoContext *ctx, const char *name) !strcmp(name, "arranger") ) { directive->dtype = DT_METADATA; + directive->meta = MD_OTHER; return directive; } if ( @@ -4485,7 +4490,7 @@ cho_directive_label_parse(struct ChoContext *ctx, const char *directive_name, co char *label_name = NULL; char c; enum OptionState state = OS_NAME; - enum AttrValueSyntax avs = -1; + enum AttrValueSyntax avs = AVS_UNINITIALIZED; char name[5+1]; char value[URL_MAX_LEN+1]; int n = 0; @@ -4524,7 +4529,7 @@ cho_directive_label_parse(struct ChoContext *ctx, const char *directive_name, co n++; break; case OS_VALUE: - if (avs == -1) { + if (avs == AVS_UNINITIALIZED) { if (is_whitespace(c)) { cho_log(ctx, LOG_ERR, "Whitespace character after equals sign in environment directive '%s' is invalid.", directive_name); return NULL; @@ -4553,7 +4558,7 @@ cho_directive_label_parse(struct ChoContext *ctx, const char *directive_name, co label_name = strdup(value); memset(value, 0, v); v = 0; - avs = -1; + avs = AVS_UNINITIALIZED; state = OS_NAME; break; } @@ -4634,7 +4639,7 @@ cho_context_init( struct ChoSong ** cho_songs_parse(const char *str, const char *chordpro_filepath, struct Config *config) { - enum AttrValueSyntax avs = -1; + enum AttrValueSyntax avs = AVS_UNINITIALIZED; struct ChoStyle *tag_style; struct StyleProperty sprop; struct ChoChord *tmp_chord; @@ -5018,9 +5023,7 @@ cho_songs_parse(const char *str, const char *chordpro_filepath, struct Config *c break; } case DT_OUTPUT: - if (directive->btype != -1) { - (*lines)[ctx.li]->btype = directive->btype; - } + (*lines)[ctx.li]->btype = directive->btype; break; case DT_EXTENSION: // INFO: Such a directive should not be logged. @@ -5256,7 +5259,7 @@ cho_songs_parse(const char *str, const char *chordpro_filepath, struct Config *c break; } switch (directive->meta) { - case TITLE: + case MD_TITLE: ctx.songs[ctx.so]->metadata = erealloc(ctx.songs[ctx.so]->metadata, (ctx.m+1) * sizeof(struct ChoMetadata *)); ctx.songs[ctx.so]->metadata[ctx.m] = cho_metadata_new(&ctx); ctx.songs[ctx.so]->metadata[ctx.m]->name = strdup("title"); @@ -5265,7 +5268,7 @@ cho_songs_parse(const char *str, const char *chordpro_filepath, struct Config *c ctx.songs[ctx.so]->metadata[ctx.m]->style = cho_style_copy(directive->style); ctx.songs[ctx.so]->present_text_types[TT_TITLE] = true; break; - case SUBTITLE: + case MD_SUBTITLE: ctx.songs[ctx.so]->metadata = erealloc(ctx.songs[ctx.so]->metadata, (ctx.m+1) * sizeof(struct ChoMetadata *)); ctx.songs[ctx.so]->metadata[ctx.m] = cho_metadata_new(&ctx); ctx.songs[ctx.so]->metadata[ctx.m]->name = strdup("subtitle"); @@ -5274,7 +5277,7 @@ cho_songs_parse(const char *str, const char *chordpro_filepath, struct Config *c ctx.songs[ctx.so]->metadata[ctx.m]->style = cho_style_copy(directive->style); ctx.songs[ctx.so]->present_text_types[TT_SUBTITLE] = true; break; - default: + case MD_OTHER: { if (!strcmp(directive_name, "meta")) { metadata = cho_metadata_split(&ctx, directive_value); if (!metadata) { @@ -5291,6 +5294,7 @@ cho_songs_parse(const char *str, const char *chordpro_filepath, struct Config *c ctx.songs[ctx.so]->metadata[ctx.m]->value = metadata_value; } } + } if (ctx.directive_has_tag) { cho_style_complement(ctx.songs[ctx.so]->metadata[ctx.m]->style, ctx.tags[ctx.ta]->style, &ctx.tags[ctx.ta]->style_presence); ctx.directive_has_tag = false; @@ -5949,7 +5953,7 @@ cho_songs_parse(const char *str, const char *chordpro_filepath, struct Config *c cho_log(&ctx, LOG_ERR, "Newline character inside an attribute value is invalid."); return NULL; } - if (avs == -1) { + if (avs == AVS_UNINITIALIZED) { if (is_whitespace(c)) { cho_log(&ctx, LOG_ERR, "Whitespace character after equals sign is invalid."); return NULL; @@ -6023,7 +6027,7 @@ cho_songs_parse(const char *str, const char *chordpro_filepath, struct Config *c } } ctx.at = 0; - avs = -1; + avs = AVS_UNINITIALIZED; memset(tag_start, 0, strlen(tag_start)); ctx.state = ctx.state_before_tag; break; @@ -6039,7 +6043,7 @@ cho_songs_parse(const char *str, const char *chordpro_filepath, struct Config *c ctx.at++; ctx.tags[ctx.ta]->attrs = erealloc(ctx.tags[ctx.ta]->attrs, (ctx.at+1) * sizeof(struct Attr *)); ctx.tags[ctx.ta]->attrs[ctx.at] = cho_tag_attr_new(); - avs = -1; + avs = AVS_UNINITIALIZED; ctx.state = STATE_MARKUP_ATTR_NAME; break; } diff --git a/src/chordpro.h b/src/chordpro.h @@ -13,7 +13,8 @@ #define URL_MAX_LEN 2000 #define FONT_NAME_MAX 100 -enum AttrValueSyntax : int8_t { +enum AttrValueSyntax { + AVS_UNINITIALIZED, AVS_QUOTATION_MARK, AVS_APOSTROPHE, AVS_UNQUOTED @@ -58,8 +59,9 @@ enum DirectiveType { }; enum MetadataDirective { - TITLE, - SUBTITLE + MD_TITLE, + MD_SUBTITLE, + MD_OTHER }; enum OptionState { @@ -91,7 +93,7 @@ enum State { STATE_METADATA_SUBSTITUTION }; -enum StylePropertyType : int8_t { +enum StylePropertyType { SPT_FONT, SPT_SIZE, SPT_COLOR @@ -139,6 +141,8 @@ struct Tag { bool is_closed; }; +typedef int index_t; + struct ChoContext { bool is_chord_already_initialized; bool is_maybe_end_of_tab_directive; @@ -211,7 +215,7 @@ void cho_style_print_as_toml(struct ChoStyle *style, const char *section); struct RGBColor *cho_rgbcolor_new(uint8_t red, uint8_t green, uint8_t blue); struct RGBColor *cho_color_parse(const char *str); struct RGBColor *cho_color_copy(struct RGBColor *color); -enum LineStyle cho_linestyle_parse(const char *str); +enum LineStyle cho_linestyle_parse(const char *str, bool *error); // const char *cho_image_name_create(struct ChoImage *image, const char *dirname); @@ -220,11 +224,11 @@ void cho_font_print(struct Font *font); struct Font *cho_font_copy(struct Font *font); void cho_fonts_free(struct Font **fonts); char *cho_font_name_normalize(const char *name); -enum FontFamily cho_font_family_parse(const char *str); +enum FontFamily cho_font_family_parse(const char *str, bool *error); const char *cho_font_family_to_config_string(enum FontFamily font_family); -enum FontStyle cho_font_style_parse(const char *str); +enum FontStyle cho_font_style_parse(const char *str, bool *error); const char *cho_font_style_to_config_string(enum FontStyle style); -enum FontWeight cho_font_weight_parse(const char *str); +enum FontWeight cho_font_weight_parse(const char *str, bool *error); const char *cho_font_weight_to_config_string(enum FontWeight weight); void cho_debug_chord_print(struct ChoChord *chord); diff --git a/src/config.c b/src/config.c @@ -120,8 +120,9 @@ config_log( } static enum TextType -config_text_type_parse(const char *str) +config_text_type_parse(const char *str, bool *error) { + *error = false; if (!strcmp(str, text_types[TT_CHORD])) { return TT_CHORD; } else @@ -167,7 +168,8 @@ config_text_type_parse(const char *str) if (!strcmp(str, text_types[TT_COMMENT_BOX])) { return TT_COMMENT_BOX; } - return -1; + *error = true; + return TT_CHORD; // unused } static enum NotationSystem @@ -185,9 +187,8 @@ config_notation_system_parse(const char *str) return NS_ROMAN; } else if (!strcmp(str, notation_systems[NS_NASHVILLE])) { return NS_NASHVILLE; - } else { - return NS_CUSTOM; } + return NS_CUSTOM; } static const char * @@ -197,21 +198,23 @@ config_notation_system_to_config_string(enum NotationSystem system) } static enum Instrument -config_instrument_parse(const char *str) +config_instrument_parse(const char *str, bool *error) { - if (!strcmp(str, "guitar")) { + *error = false; + if (!strcmp(str, instruments[INS_GUITAR].name)) { return INS_GUITAR; } else - if (!strcmp(str, "keyboard")) { + if (!strcmp(str, instruments[INS_KEYBOARD].name)) { return INS_KEYBOARD; } else - if (!strcmp(str, "mandolin")) { + if (!strcmp(str, instruments[INS_MANDOLIN].name)) { return INS_MANDOLIN; } else - if (!strcmp(str, "ukulele")) { + if (!strcmp(str, instruments[INS_UKULELE].name)) { return INS_UKULELE; } - return -1; + *error = true; + return INS_GUITAR; } static const char * @@ -402,18 +405,20 @@ config_parse_mode_to_config_string(enum ParseMode mode) } static enum Alignment -config_alignment_parse(const char *str) +config_alignment_parse(const char *str, bool *error) { - if (!strcmp(str, "left")) { + *error = false; + if (!strcmp(str, alignments[A_LEFT])) { return A_LEFT; } else - if (!strcmp(str, "center")) { + if (!strcmp(str, alignments[A_CENTER])) { return A_CENTER; } else - if (!strcmp(str, "right")) { + if (!strcmp(str, alignments[A_RIGHT])) { return A_RIGHT; } - return -1; + *error = true; + return A_LEFT; // unused } static const char * @@ -553,6 +558,7 @@ config_load_font( enum FontStyle style; enum FontWeight weight; toml_value_t value; + bool error; value = toml_table_string(table, "name"); if (value.ok) { presence->font.name = true; @@ -562,42 +568,42 @@ config_load_font( value = toml_table_string(table, "family"); if (value.ok) { presence->font.family = true; - family = cho_font_family_parse(value.u.s); - if (family != -1) { - font->family = family; - } else { + family = cho_font_family_parse(value.u.s, &error); + if (error) { if (err_buf) { strcpy((char *)err_buf, "family value is invalid."); } return false; + } else { + font->family = family; } free(value.u.s); } value = toml_table_string(table, "style"); if (value.ok) { presence->font.style = true; - style = cho_font_style_parse(value.u.s); - if (style != -1) { - font->style = style; - } else { + style = cho_font_style_parse(value.u.s, &error); + if (error) { if (err_buf) { strcpy((char *)err_buf, "style value is invalid."); } return false; + } else { + font->style = style; } free(value.u.s); } value = toml_table_string(table, "weight"); if (value.ok) { presence->font.weight = true; - weight = cho_font_weight_parse(value.u.s); - if (weight != -1) { - font->weight = weight; - } else { + weight = cho_font_weight_parse(value.u.s, &error); + if (error) { if (err_buf) { strcpy((char *)err_buf, "weight value is invalid."); } return false; + } else { + font->weight = weight; } free(value.u.s); } @@ -620,6 +626,7 @@ config_load_style( toml_value_t value; struct RGBColor *color; enum LineStyle line_style; + bool error; toml_table_t *font_section = toml_table_table(table, "font"); if (font_section) { char err[25]; @@ -658,12 +665,12 @@ config_load_style( value = toml_table_string(table, "underline_style"); if (value.ok) { presence->underline_style = true; - line_style = cho_linestyle_parse(value.u.s); - if (line_style != -1) { - style->underline_style = line_style; - } else { + line_style = cho_linestyle_parse(value.u.s, &error); + if (error) { strcpy((char *)err_buf, "underline style value is invalid."); return false; + } else { + style->underline_style = line_style; } free(value.u.s); } @@ -683,12 +690,12 @@ config_load_style( value = toml_table_string(table, "overline_style"); if (value.ok) { presence->overline_style = true; - line_style = cho_linestyle_parse(value.u.s); - if (line_style != -1) { - style->overline_style = line_style; - } else { + line_style = cho_linestyle_parse(value.u.s, &error); + if (error) { strcpy((char *)err_buf, "overline style value is invalid."); return false; + } else { + style->overline_style = line_style; } free(value.u.s); } @@ -906,6 +913,7 @@ config_load(const char *filepath) config->metadata_separator = value.u.s; } toml_table_t *output = toml_table_table(table, "output"); + bool error; if (output) { toml_table_t *styles, *notes, *chorus, *diagram, *toc, *page_no; enum NotationSystem notation_system; @@ -944,8 +952,9 @@ config_load(const char *filepath) } value = toml_table_string(diagram, "instrument"); if (value.ok) { - instrument = config_instrument_parse(value.u.s); - if (instrument == -1) { + instrument = config_instrument_parse(value.u.s, &error); + if (error) { + LOG_DEBUG("config_instrument_parse failed."); config_log(LOG_ERR, "[output.chord_diagram]", "Unknown instrument '%s'.", value.u.s); return NULL; } @@ -989,8 +998,8 @@ config_load(const char *filepath) } value = toml_table_string(page_no, "alignment"); if (value.ok) { - align = config_alignment_parse(value.u.s); - if (align == -1) { + align = config_alignment_parse(value.u.s, &error); + if (error) { LOG_DEBUG("config_alignment_parse failed."); return NULL; } @@ -1008,8 +1017,8 @@ config_load(const char *filepath) 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 != -1) { + ttype = config_text_type_parse(key_name, &error); + if (!error) { key = toml_table_table(styles, key_name); if (key) { style = config->output->styles[ttype]; diff --git a/src/types.h b/src/types.h @@ -3,10 +3,7 @@ #ifndef _TYPES_H_ #define _TYPES_H_ -// used as an index in an array -typedef int index_t; - -enum TextType : int8_t { +enum TextType { TT_CHORD, TT_ANNOT, TT_CHORUS, @@ -25,7 +22,7 @@ enum TextType : int8_t { TT_LENGTH }; -enum Alignment : int8_t { +enum Alignment { A_LEFT, A_CENTER, A_RIGHT @@ -39,13 +36,14 @@ enum Anchor { AN_FLOAT }; -enum BreakType : int8_t { +enum BreakType { BT_LINE, BT_PAGE, BT_COLUMN }; -enum ChordDiagramContent : int8_t { +enum ChordDiagramContent { + CDC_UNINITIALIZED, CDC_STRING, CDC_KEYBOARD, CDC_CHORD_MAP @@ -75,25 +73,25 @@ enum SizeType { ST_EX }; -enum FontFamily : int8_t { +enum FontFamily { FF_NORMAL, FF_SANS, FF_SERIF, FF_MONOSPACE }; -enum FontStyle : int8_t { +enum FontStyle { FS_ROMAN, FS_OBLIQUE, FS_ITALIC }; -enum FontWeight : int8_t { +enum FontWeight { FW_REGULAR, FW_BOLD }; -enum LineStyle : int8_t { +enum LineStyle { LS_SINGLE, LS_DOUBLE, LS_NONE @@ -147,16 +145,16 @@ struct ChoStyle { 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; + enum LineStyle underline_style; + enum LineStyle overline_style; + bool strikethrough; + bool boxed; + double rise; }; struct ChoChord { @@ -287,7 +285,7 @@ enum ParseMode { PM_RELAXED }; -enum Instrument : int8_t { +enum Instrument { INS_GUITAR, INS_KEYBOARD, INS_MANDOLIN,