commit 8284135c6a93fa5726998f7ee5c2da78f38a320a
parent b4dea9cfd642340bc38ba4ddd71bfe3f8ce41394
Author: nibo <nibo@relim.de>
Date: Thu, 8 Aug 2024 18:40:48 +0200
Separate stderr messages into ERR, WARN and INFO
Diffstat:
5 files changed, 169 insertions(+), 103 deletions(-)
diff --git a/chordpro.c b/chordpro.c
@@ -412,7 +412,7 @@ struct RGBColor *cho_color_parse(const char *str)
color->green = 0;
color->blue = 0;
} else {
- fprintf(stderr, "INFO: Invalid color value '%s'.\n", str);
+ fprintf(stderr, "ERR: Invalid color value '%s'.\n", str);
free(color);
return NULL;
}
@@ -631,7 +631,7 @@ static bool cho_style_property_apply_default(enum SongFragmentType current_ftype
}
break;
default:
- fprintf(stderr, "INFO: Invalid style property type '%d'.\n", ptype);
+ fprintf(stderr, "WARN: Invalid style property type '%d'.\n", ptype);
return false;
}
}
@@ -888,7 +888,8 @@ struct Style *cho_style_get(const char *tag_name, struct Attr **attrs, struct St
} else if (strcmp(attrs[a]->value, "monospace") == 0) {
style->font->family = FF_MONOSPACE;
} else {
- fprintf(stderr, "INFO: Invalid value in attribute 'font_family/face'.\n");
+ fprintf(stderr, "ERR: Invalid value in attribute 'font_family/face'.\n");
+ return NULL;
}
} else if (strcmp(attrs[a]->name, "size") == 0) {
value_len = strlen(attrs[a]->value);
@@ -900,17 +901,21 @@ struct Style *cho_style_get(const char *tag_name, struct Attr **attrs, struct St
if (percentage != 0 && percentage <= 100) {
style->font->size *= percentage / 100.0;
} else {
- fprintf(stderr, "INFO: Invalid percentage in attribute 'size'.\n");
+ fprintf(stderr, "ERR: Invalid percentage in attribute 'size'.\n");
+ return NULL;
}
} else {
- fprintf(stderr, "INFO: Invalid percentage in attribute 'size'.\n");
+ fprintf(stderr, "ERR: Invalid percentage in attribute 'size'.\n");
+ return NULL;
}
} else if (isdigit(attrs[a]->value[0]) != 0) {
double size = strtod(attrs[a]->value, NULL);
- if (size != 0.0)
+ if (size != 0.0) {
style->font->size = size;
- else
- fprintf(stderr, "INFO: Invalid number in attribute 'size'.\n");
+ } else {
+ fprintf(stderr, "ERR: Invalid number in attribute 'size'.\n");
+ return NULL;
+ }
} else if (strcmp(attrs[a]->value, "xx-small") == 0) {
style->font->size *= 0.8;
style->font->size *= 0.8;
@@ -935,7 +940,8 @@ struct Style *cho_style_get(const char *tag_name, struct Attr **attrs, struct St
} else if (strcmp(attrs[a]->value, "smaller") == 0) {
style->font->size *= 0.8;
} else {
- fprintf(stderr, "INFO: Invalid value '%s' for the attribute 'size'.\n", attrs[a]->value);
+ fprintf(stderr, "ERR: Invalid value '%s' for the attribute 'size'.\n", attrs[a]->value);
+ return NULL;
}
} else if (strcmp(attrs[a]->name, "style") == 0) {
if (strcmp(attrs[a]->value, "normal") == 0) {
@@ -945,7 +951,8 @@ struct Style *cho_style_get(const char *tag_name, struct Attr **attrs, struct St
} else if (strcmp(attrs[a]->value, "italic") == 0) {
style->font->style = FS_ITALIC;
} else {
- fprintf(stderr, "INFO: Invalid value in attribute 'style'.\n");
+ fprintf(stderr, "ERR: Invalid value in attribute 'style'.\n");
+ return NULL;
}
} else if (strcmp(attrs[a]->name, "weight") == 0) {
if (strcmp(attrs[a]->value, "normal") == 0) {
@@ -953,20 +960,23 @@ struct Style *cho_style_get(const char *tag_name, struct Attr **attrs, struct St
} else if (strcmp(attrs[a]->value, "bold") == 0) {
style->font->weight = FW_BOLD;
} else {
- fprintf(stderr, "INFO: Invalid value in attribute 'weight'.\n");
+ fprintf(stderr, "ERR: Invalid value in attribute 'weight'.\n");
+ return NULL;
}
} else if (strcmp(attrs[a]->name, "foreground") == 0) {
rgb_color = cho_color_parse(attrs[a]->value);
- if (rgb_color == NULL) {
+ if (!rgb_color) {
fprintf(stderr, "cho_color_parse failed.\n");
+ return NULL;
} else {
free(style->foreground_color);
style->foreground_color = rgb_color;
}
} else if (strcmp(attrs[a]->name, "background") == 0) {
rgb_color = cho_color_parse(attrs[a]->value);
- if (rgb_color == NULL) {
+ if (!rgb_color) {
fprintf(stderr, "cho_color_parse failed.\n");
+ return NULL;
} else {
free(style->background_color);
style->background_color = rgb_color;
@@ -979,12 +989,14 @@ struct Style *cho_style_get(const char *tag_name, struct Attr **attrs, struct St
} else if (strcmp(attrs[a]->value, "none") == 0) {
style->underline_style = LS_NONE;
} else {
- fprintf(stderr, "INFO: Invalid value in attribute 'underline'.\n");
+ fprintf(stderr, "ERR: Invalid value in attribute 'underline'.\n");
+ return NULL;
}
} else if (strcmp(attrs[a]->name, "underline_colour") == 0) {
rgb_color = cho_color_parse(attrs[a]->value);
- if (rgb_color == NULL) {
+ if (!rgb_color) {
fprintf(stderr, "cho_color_parse failed.\n");
+ return NULL;
} else {
free(style->underline_color);
style->underline_color = rgb_color;
@@ -997,12 +1009,14 @@ struct Style *cho_style_get(const char *tag_name, struct Attr **attrs, struct St
} else if (strcmp(attrs[a]->value, "none") == 0) {
style->overline_style = LS_NONE;
} else {
- fprintf(stderr, "INFO: Invalid value in attribute 'overline'.\n");
+ fprintf(stderr, "ERR: Invalid value in attribute 'overline'.\n");
+ return NULL;
}
} else if (strcmp(attrs[a]->name, "overline_colour") == 0) {
rgb_color = cho_color_parse(attrs[a]->value);
- if (rgb_color == NULL) {
+ if (!rgb_color) {
fprintf(stderr, "cho_color_parse failed.\n");
+ return NULL;
} else {
free(style->overline_color);
style->overline_color = rgb_color;
@@ -1018,17 +1032,21 @@ struct Style *cho_style_get(const char *tag_name, struct Attr **attrs, struct St
if (percentage != 0 && percentage <= 100) {
style->rise = (style->font->size / 2) * percentage / 100.0;
} else {
- fprintf(stderr, "INFO: Invalid percentage in attribute 'rise'.\n");
+ fprintf(stderr, "ERR: Invalid percentage in attribute 'rise'.\n");
+ return NULL;
}
}
} else if (isdigit(attrs[a]->value[1]) != 0) {
double rise = strtod(attrs[a]->value, NULL);
- if (rise != 0.0)
+ if (rise != 0.0) {
style->rise = rise;
- else
- fprintf(stderr, "INFO: Invalid number in attribute 'rise'.\n");
+ } else {
+ fprintf(stderr, "ERR: Invalid number in attribute 'rise'.\n");
+ return NULL;
+ }
} else {
- fprintf(stderr, "INFO: Invalid value '%s' for the attribute 'rise'.\n", attrs[a]->value);
+ fprintf(stderr, "ERR: Invalid value '%s' for the attribute 'rise'.\n", attrs[a]->value);
+ return NULL;
}
} else {
if (attrs[a]->value[last_char] == '%') {
@@ -1040,17 +1058,21 @@ struct Style *cho_style_get(const char *tag_name, struct Attr **attrs, struct St
double more = style->font->size / 2.0 * percentage / 100.0;
style->rise += more;
} else {
- fprintf(stderr, "INFO: Invalid percentage in attribute 'rise'.\n");
+ fprintf(stderr, "ERR: Invalid percentage in attribute 'rise'.\n");
+ return NULL;
}
}
} else if (isdigit(attrs[a]->value[1]) != 0) {
double rise = strtod(attrs[a]->value, NULL);
- if (rise != 0.0)
+ if (rise != 0.0) {
style->rise = rise;
- else
- fprintf(stderr, "INFO: Invalid number in attribute 'rise'.\n");
+ } else {
+ fprintf(stderr, "ERR: Invalid number in attribute 'rise'.\n");
+ return NULL;
+ }
} else {
- fprintf(stderr, "INFO: Invalid value '%s' for the attribute 'rise'.\n", attrs[a]->value);
+ fprintf(stderr, "ERR: Invalid value '%s' for the attribute 'rise'.\n", attrs[a]->value);
+ return NULL;
}
}
} else if (strcmp(attrs[a]->name, "strikethrough") == 0) {
@@ -1059,12 +1081,14 @@ struct Style *cho_style_get(const char *tag_name, struct Attr **attrs, struct St
} else if (strcmp(attrs[a]->value, "false") == 0) {
style->strikethrough = false;
} else {
- fprintf(stderr, "INFO: Invalid value '%s' in attribute 'strikethrough'.\n", attrs[a]->value);
+ fprintf(stderr, "ERR: Invalid value '%s' in attribute 'strikethrough'.\n", attrs[a]->value);
+ return NULL;
}
} else if (strcmp(attrs[a]->name, "strikethrough_colour") == 0) {
rgb_color = cho_color_parse(attrs[a]->value);
- if (rgb_color == NULL) {
+ if (!rgb_color) {
fprintf(stderr, "cho_color_parse failed.\n");
+ return NULL;
} else {
free(style->strikethrough_color);
style->strikethrough_color = rgb_color;
@@ -1072,7 +1096,8 @@ struct Style *cho_style_get(const char *tag_name, struct Attr **attrs, struct St
} else if (strcmp(attrs[a]->name, "href") == 0) {
style->href = strdup(attrs[a]->value);
} else {
- fprintf(stderr, "INFO: Invalid attribute '%s'.\n", attrs[a]->name);
+ fprintf(stderr, "ERR: Invalid attribute '%s'.\n", attrs[a]->name);
+ return NULL;
}
a++;
}
@@ -1097,7 +1122,7 @@ struct Style *cho_style_get(const char *tag_name, struct Attr **attrs, struct St
} else if (strcmp(tag_name, "u") == 0) {
style->underline_style = LS_SINGLE;
} else {
- fprintf(stderr, "ERROR: Invalid tag name '%s'.\n", tag_name);
+ fprintf(stderr, "ERR: Invalid tag name '%s'.\n", tag_name);
cho_style_free(style);
return NULL;
}
@@ -1122,10 +1147,10 @@ void cho_style_print_as_toml(struct Style *style, const char *section)
cho_font_print_as_toml(style->font, section);
}
-static void cho_style_change_default(struct StyleProperty sprop)
+static bool cho_style_change_default(struct StyleProperty sprop)
{
if (sprop.type == SPT_EMPTY)
- return;
+ return false;
unsigned int i;
for (i = 0; i<LENGTH(default_style_properties); i++) {
if (
@@ -1140,10 +1165,10 @@ static void cho_style_change_default(struct StyleProperty sprop)
} else {
default_style_properties[i].u.font_name = NULL;
}
- break;
+ return true;
case SPT_SIZE:
default_style_properties[i].u.font_size = sprop.u.font_size;
- break;
+ return true;
case SPT_COLOR:
free(default_style_properties[i].u.foreground_color);
if (sprop.u.foreground_color) {
@@ -1151,15 +1176,17 @@ static void cho_style_change_default(struct StyleProperty sprop)
} else {
default_style_properties[i].u.foreground_color = NULL;
}
- break;
+ return true;
default:
- fprintf(stderr, "INFO: Invalid style property type '%d'.\n", sprop.type);
+ fprintf(stderr, "ERR: Invalid style property type '%d'.\n", sprop.type);
+ return false;
}
}
}
+ return false;
}
-static void cho_style_reset_default(void)
+static bool cho_style_reset_default(void)
{
unsigned int i;
for (i = 0; i<LENGTH(default_style_properties); i++) {
@@ -1167,18 +1194,20 @@ static void cho_style_reset_default(void)
case SPT_FONT:
free(default_style_properties[i].u.font_name);
default_style_properties[i].u.font_name = NULL;
- break;
+ return true;
case SPT_SIZE:
default_style_properties[i].u.font_size = EMPTY;
- break;
+ return true;
case SPT_COLOR:
free(default_style_properties[i].u.foreground_color);
default_style_properties[i].u.foreground_color = NULL;
- break;
+ return true;
default:
- fprintf(stderr, "INFO: Invalid style property type '%d'.\n", default_style_properties[i].type);
+ fprintf(stderr, "ERR: Invalid style property type '%d'.\n", default_style_properties[i].type);
+ return false;
}
}
+ return false;
}
static struct Attr *cho_tag_attr_new(void)
@@ -1225,17 +1254,18 @@ static void cho_tag_free(struct Tag *tag)
free(tag);
}
-static void cho_tag_close_last_unclosed(const char *tag_name, struct Tag **tags, int last_index)
+static bool cho_tag_close_last_unclosed(const char *tag_name, struct Tag **tags, int last_index)
{
int i = last_index;
while (i >= 0) {
if (strcmp(tags[i]->name, tag_name) == 0 && !tags[i]->is_closed) {
tags[i]->is_closed = true;
- return;
+ return true;
}
i--;
}
- fprintf(stderr, "INFO: Didn't find a start tag for the end tag '%s'.\n", tag_name);
+ fprintf(stderr, "ERR: Didn't find a start tag for the end tag '%s'.\n", tag_name);
+ return false;
}
static struct Style *cho_tag_style_inherit(struct Tag **tags, int prev_index)
@@ -1316,7 +1346,7 @@ static struct ChoMetadata *cho_metadata_split(const char *directive_value)
free(meta->name);
free(meta->value);
free(meta);
- fprintf(stderr, "INFO: Failed to parse directive 'meta'.\n");
+ fprintf(stderr, "ERR: Failed to parse directive 'meta'.\n");
return NULL;
}
}
@@ -2048,7 +2078,8 @@ struct ChoSong **cho_songs_parse(FILE *fp, struct Config *config)
}
break;
default:
- fprintf(stderr, "INFO: Invalid position value '%d'.\n", directive->position);
+ fprintf(stderr, "ERR: Invalid position value '%d'.\n", directive->position);
+ return NULL;
}
break;
case DT_METADATA:
@@ -2060,7 +2091,7 @@ struct ChoSong **cho_songs_parse(FILE *fp, struct Config *config)
memset(directive_name, 0, strlen(directive_name));
break;
case DT_FORMATTING:
- fprintf(stderr, "INFO: Formatting directive '%s' has no value.\n", directive_name);
+ fprintf(stderr, "WARN: Formatting directive '%s' has no value.\n", directive_name);
break;
case DT_PREAMBLE:
// The only preamble directive is 'new_song'
@@ -2073,7 +2104,10 @@ struct ChoSong **cho_songs_parse(FILE *fp, struct Config *config)
se++;
songs[so]->sections = realloc(songs[so]->sections, (se+1) * sizeof(struct ChoSection *));
songs[so]->sections[se] = NULL;
- cho_style_reset_default();
+ if (!cho_style_reset_default()) {
+ fprintf(stderr, "cho_style_reset_default failed.\n");
+ return NULL;
+ }
so++;
songs = realloc(songs, (so+1) * sizeof(struct ChoSong *));
songs[so] = cho_song_new();
@@ -2103,15 +2137,21 @@ struct ChoSong **cho_songs_parse(FILE *fp, struct Config *config)
sprop.u.foreground_color = NULL;
break;
default:
- fprintf(stderr, "INFO: Ignoring invalid style property type '%s'.\n", cho_style_property_type_to_string(directive->sprop));
+ fprintf(stderr, "ERR: Invalid style property type '%d'.\n", directive->sprop);
+ return NULL;
+ }
+ if (!cho_style_change_default(sprop)) {
+ fprintf(stderr, "cho_style_change_default failed.\n");
+ return NULL;
}
- cho_style_change_default(sprop);
break;
case DT_CUSTOM:
+ // TODO: Implement {start_of_*} and {end_of_*} custom directives
fprintf(stderr, "INFO: Ignoring custom directive '%s'.\n", directive_name);
break;
default:
- fprintf(stderr, "INFO: Ignoring invalid directive '%s'.\n", directive_name);
+ fprintf(stderr, "ERR: Invalid directive '%s'.\n", directive_name);
+ return NULL;
}
cho_directive_free(directive);
directive = NULL;
@@ -2177,7 +2217,8 @@ struct ChoSong **cho_songs_parse(FILE *fp, struct Config *config)
}
break;
default:
- fprintf(stderr, "INFO: Invalid position value '%d'.\n", directive->position);
+ fprintf(stderr, "ERR: Invalid position value '%d'.\n", directive->position);
+ return NULL;
}
break;
case DT_METADATA:
@@ -2187,6 +2228,9 @@ struct ChoSong **cho_songs_parse(FILE *fp, struct Config *config)
songs[so]->metadata = realloc(songs[so]->metadata, (m+1) * sizeof(struct ChoMetadata *));
songs[so]->metadata[m] = metadata;
m++;
+ } else {
+ fprintf(stderr, "cho_metadata_split failed.\n");
+ return NULL;
}
} else {
songs[so]->metadata = realloc(songs[so]->metadata, (m+1) * sizeof(struct ChoMetadata *));
@@ -2219,7 +2263,8 @@ struct ChoSong **cho_songs_parse(FILE *fp, struct Config *config)
te += strlen(trimmed_directive_value);
break;
case DT_PREAMBLE:
- fprintf(stderr, "INFO: Preamble directive '%s' can't have a value.\n", directive_name);
+ fprintf(stderr, "ERR: Preamble directive '%s' can't have a value.\n", directive_name);
+ return NULL;
break;
case DT_FONT:
sprop.ftype = directive->ftype;
@@ -2233,25 +2278,27 @@ struct ChoSong **cho_songs_parse(FILE *fp, struct Config *config)
case SPT_SIZE:
sprop.u.font_size = strtod(dir_value, NULL);
if (sprop.u.font_size == 0.0) {
- fprintf(stderr, "INFO: Font directive '%s' has an invalid value. Ignoring directive.\n", directive_name);
- sprop.type = SPT_EMPTY;
- break;
+ fprintf(stderr, "ERR: Font directive '%s' has an invalid value.\n", directive_name);
+ return NULL;
}
sprop.type = SPT_SIZE;
break;
case SPT_COLOR:
sprop.u.foreground_color = cho_color_parse(dir_value);
if (sprop.u.foreground_color == NULL) {
- fprintf(stderr, "INFO: Font directive '%s' has an invalid value. Ignoring directive.\n", directive_name);
- sprop.type = SPT_EMPTY;
- break;
+ fprintf(stderr, "ERR: Font directive '%s' has an invalid value.\n", directive_name);
+ return NULL;
}
sprop.type = SPT_COLOR;
break;
default:
- fprintf(stderr, "INFO: Ignoring invalid style property type '%d'.\n", directive->sprop);
+ fprintf(stderr, "ERR: Invalid style property type '%d'.\n", directive->sprop);
+ return NULL;
+ }
+ if (!cho_style_change_default(sprop)) {
+ fprintf(stderr, "cho_style_change_default failed.\n");
+ return NULL;
}
- cho_style_change_default(sprop);
if (sprop.type == SPT_FONT) {
free(sprop.u.font_name);
} else if (sprop.type == SPT_COLOR) {
@@ -2263,7 +2310,8 @@ struct ChoSong **cho_songs_parse(FILE *fp, struct Config *config)
fprintf(stderr, "INFO: Ignoring custom directive '%s'.\n", directive_name);
break;
default:
- fprintf(stderr, "INFO: Ignoring invalid directive '%d'.\n", directive->dtype);
+ fprintf(stderr, "ERR: Invalid directive '%d'.\n", directive->dtype);
+ return NULL;
}
memset(directive_value, 0, strlen(directive_value));
cho_directive_free(directive);
@@ -2285,6 +2333,10 @@ struct ChoSong **cho_songs_parse(FILE *fp, struct Config *config)
songs[so]->sections[se]->lines[li]->text_above[c]->position = chord_pos;
tmp_chord = cho_chord_parse(chord);
songs[so]->sections[se]->lines[li]->text_above[c]->u.chord->name = strdup(tmp_chord->name);
+ songs[so]->sections[se]->lines[li]->text_above[c]->u.chord->is_canonical = tmp_chord->is_canonical;
+ if (!songs[so]->sections[se]->lines[li]->text_above[c]->u.chord->is_canonical) {
+ fprintf(stderr, "INFO: Didn't recognize the chord '%s' in line %d.\n", songs[so]->sections[se]->lines[li]->text_above[c]->u.chord->name, line_number);
+ }
if (songs[so]->sections[se]->lines[li]->text_above[c]->u.chord->root) {
songs[so]->sections[se]->lines[li]->text_above[c]->u.chord->root = strdup(tmp_chord->root);
}
@@ -2304,6 +2356,9 @@ struct ChoSong **cho_songs_parse(FILE *fp, struct Config *config)
chord_pos = cho_line_compute_chord_position(songs[so]->sections[se]->lines[li], ly, te);
songs[so]->sections[se]->lines[li]->text_above[c]->position = chord_pos;
songs[so]->sections[se]->lines[li]->text_above[c]->u.chord = cho_chord_parse(chord);
+ if (!songs[so]->sections[se]->lines[li]->text_above[c]->u.chord->is_canonical) {
+ fprintf(stderr, "INFO: Didn't recognize the chord '%s' in line %d.\n", songs[so]->sections[se]->lines[li]->text_above[c]->u.chord->name, line_number);
+ }
// cho_debug_chord_print(songs[so]->sections[se]->lines[li]->text_above[c]->u.chord);
}
memset(chord, 0, strlen(chord));
@@ -2377,7 +2432,8 @@ struct ChoSong **cho_songs_parse(FILE *fp, struct Config *config)
case STATE_ANNOTATION:
break;
default:
- fprintf(stderr, "INFO: Invalid prev_state '%s'.\n", cho_state_to_string(prev_state));
+ fprintf(stderr, "ERR: Invalid prev_state '%s'.\n", cho_state_to_string(prev_state));
+ return NULL;
}
memset(tag_begin, 0, strlen(tag_begin));
state = prev_state;
@@ -2393,7 +2449,8 @@ struct ChoSong **cho_songs_parse(FILE *fp, struct Config *config)
break;
}
if (t == 5) {
- fprintf(stderr, "ERROR: Begin tag name is too long.\n");
+ tag_begin[t] = 0;
+ fprintf(stderr, "ERR: Begin tag name '%s' is too long.\n", tag_begin);
return NULL;
}
tag_begin[t] = buf;
@@ -2414,13 +2471,17 @@ struct ChoSong **cho_songs_parse(FILE *fp, struct Config *config)
if (buf == '>') {
tag_end[t] = 0;
t = 0;
- cho_tag_close_last_unclosed(tag_end, tags, ta);
+ if (!cho_tag_close_last_unclosed(tag_end, tags, ta)) {
+ fprintf(stderr, "cho_tag_close_last_unclosed failed.\n");
+ return NULL;
+ }
memset(tag_end, 0, strlen(tag_end));
state = prev_state;
break;
}
if (t == 5) {
- fprintf(stderr, "ERROR: End tag name is too long.\n");
+ tag_end[t] = 0;
+ fprintf(stderr, "ERR: End tag name '%s' is too long.\n", tag_end);
return NULL;
}
tag_end[t] = buf;
@@ -2441,7 +2502,7 @@ struct ChoSong **cho_songs_parse(FILE *fp, struct Config *config)
} else {
tags[ta]->attrs[at]->name = realloc(tags[ta]->attrs[at]->name, (atn+1) * sizeof(char));
tags[ta]->attrs[at]->name[atn] = 0;
- fprintf(stderr, "' ' ERROR: Attribute name '%s' of tag '%s' has no value.\n", tags[ta]->attrs[at]->name, tag_begin);
+ fprintf(stderr, "ERR: Attribute with name '%s' of tag '%s' in line '%d' has no value.\n", tags[ta]->attrs[at]->name, tag_begin, line_number);
return NULL;
}
}
@@ -2453,7 +2514,7 @@ struct ChoSong **cho_songs_parse(FILE *fp, struct Config *config)
}
tags[ta]->attrs[at]->name = realloc(tags[ta]->attrs[at]->name, (atn+1) * sizeof(char));
tags[ta]->attrs[at]->name[atn] = 0;
- fprintf(stderr, "' ' ERROR: Attribute name '%s' of tag '%s' has no value.\n", tags[ta]->attrs[at]->name, tag_begin);
+ fprintf(stderr, "ERR: Attribute with name '%s' of tag '%s' in line '%d' has no value.\n", tags[ta]->attrs[at]->name, tag_begin, line_number);
return NULL;
}
if (buf == '>') {
@@ -2478,7 +2539,8 @@ struct ChoSong **cho_songs_parse(FILE *fp, struct Config *config)
case STATE_ANNOTATION:
break;
default:
- fprintf(stderr, "INFO: Invalid prev_state '%s'.\n", cho_state_to_string(prev_state));
+ fprintf(stderr, "ERR: Invalid prev_state '%s'.\n", cho_state_to_string(prev_state));
+ return NULL;
}
at = 0;
memset(tag_begin, 0, strlen(tag_begin));
@@ -2488,7 +2550,7 @@ struct ChoSong **cho_songs_parse(FILE *fp, struct Config *config)
tags[ta]->attrs[at]->name = realloc(tags[ta]->attrs[at]->name, (atn+1) * sizeof(char));
tags[ta]->attrs[at]->name[atn] = 0;
atn = 0;
- fprintf(stderr, "> ERROR: Attribute name '%s' of tag '%s' has no value.\n", tags[ta]->attrs[at]->name, tag_begin);
+ fprintf(stderr, "ERR: Attribute with name '%s' of tag '%s' in line '%d' has no value.\n", tags[ta]->attrs[at]->name, tag_begin, line_number);
return NULL;
}
}
@@ -2499,11 +2561,11 @@ struct ChoSong **cho_songs_parse(FILE *fp, struct Config *config)
case STATE_MARKUP_ATTR_VALUE:
if (avs == AVS_NO) {
if (is_whitespace(buf)) {
- fprintf(stderr, "ERROR: Whitespace character after equals sign in line '%d' is invalid.\n", line_number);
+ fprintf(stderr, "ERR: Whitespace character after equals sign in line '%d' is invalid.\n", line_number);
return NULL;
}
if (buf == '>') {
- fprintf(stderr, "ERROR: Attribute name '%s' of tag '%s' in line '%d' has no value.\n", tags[ta]->attrs[at]->name, tag_begin, line_number);
+ fprintf(stderr, "ERR: Attribute with name '%s' of tag '%s' in line '%d' has no value.\n", tags[ta]->attrs[at]->name, tag_begin, line_number);
return NULL;
}
if (buf == '\'') {
@@ -2519,7 +2581,7 @@ struct ChoSong **cho_songs_parse(FILE *fp, struct Config *config)
break;
}
if (buf == '\n') {
- fprintf(stderr, "ERROR: Newline character inside an attribute value in line '%d' is invalid.\n", line_number);
+ fprintf(stderr, "ERR: Newline character inside an attribute value in line '%d' is invalid.\n", line_number);
return NULL;
}
if (avs == AVS_UNQUOTED && buf == '>') {
@@ -2547,7 +2609,8 @@ struct ChoSong **cho_songs_parse(FILE *fp, struct Config *config)
case STATE_ANNOTATION:
break;
default:
- fprintf(stderr, "INFO: Invalid prev_state '%s'.\n", cho_state_to_string(prev_state));
+ fprintf(stderr, "ERR: Invalid prev_state '%s'.\n", cho_state_to_string(prev_state));
+ return NULL;
}
at = 0;
avs = AVS_NO;
@@ -2599,7 +2662,10 @@ struct ChoSong **cho_songs_parse(FILE *fp, struct Config *config)
free(songs[so]->sections[se]->lines[li]->lyrics);
free(songs[so]->sections[se]->lines[li]->text_above);
free(songs[so]->sections[se]->lines[li]);
- cho_style_reset_default();
+ if (!cho_style_reset_default()) {
+ fprintf(stderr, "cho_style_reset_default failed.\n");
+ return NULL;
+ }
songs[so]->sections[se]->lines[li] = NULL;
songs[so]->metadata = realloc(songs[so]->metadata, (m+1) * sizeof(struct ChoMetadata *));
songs[so]->metadata[m] = NULL;
diff --git a/config.c b/config.c
@@ -152,8 +152,8 @@ static struct Note **config_notes_load(toml_table_t *notes, const char *system)
toml_array_t *arr = toml_table_array(notes, system);
int arr_len = toml_array_len(arr);
if (arr_len != 7) {
- fprintf(stderr, "INFO: Custom naming system '%s' in [chords.notes] has to have exactly 7 items.\n", system);
- fprintf(stderr, "INFO: For an example see `lorid --print-default-config`\n");
+ fprintf(stderr, "ERR: Custom naming system '%s' in [chords.notes] has to have exactly 7 items.\n", system);
+ fprintf(stderr, "ERR: For an example see `lorid --print-default-config`\n");
free(notes);
return NULL;
}
@@ -172,7 +172,7 @@ static struct Note **config_notes_load(toml_table_t *notes, const char *system)
if (value.ok) {
custom_notes[i]->sharp = value.u.s;
if (i == 2 || i == 6) {
- fprintf(stderr, "INFO: Custom naming system '%s' in [chords.notes] can't have sharp value at array index '%d'.\n", system, i);
+ fprintf(stderr, "ERR: Custom naming system '%s' in [chords.notes] can't have sharp value at array index '%d'.\n", system, i);
goto CLEAN;
}
}
@@ -180,7 +180,7 @@ static struct Note **config_notes_load(toml_table_t *notes, const char *system)
if (value.ok) {
custom_notes[i]->flat = value.u.s;
if (i == 0 || i == 3) {
- fprintf(stderr, "INFO: Custom naming system '%s' in [chords.notes] can't have flat value at array index '%d'.\n", system, i);
+ fprintf(stderr, "ERR: Custom naming system '%s' in [chords.notes] can't have flat value at array index '%d'.\n", system, i);
goto CLEAN;
}
}
@@ -309,7 +309,7 @@ static bool config_load_font(struct Font *font, toml_table_t *table, const char
if (family != FF_EMPTY) {
font->family = family;
} else {
- fprintf(stderr, "INFO: Config section [styles.%s.font] family value is invalid.\n", key_name);
+ fprintf(stderr, "ERR: Config section [styles.%s.font] family value is invalid.\n", key_name);
return false;
}
free(value.u.s);
@@ -320,7 +320,7 @@ static bool config_load_font(struct Font *font, toml_table_t *table, const char
if (style != FS_EMPTY) {
font->style = style;
} else {
- fprintf(stderr, "INFO: Config section [styles.%s.font] style value is invalid.\n", key_name);
+ fprintf(stderr, "ERR: Config section [styles.%s.font] style value is invalid.\n", key_name);
return false;
}
free(value.u.s);
@@ -331,7 +331,7 @@ static bool config_load_font(struct Font *font, toml_table_t *table, const char
if (weight != FW_EMPTY) {
font->weight = weight;
} else {
- fprintf(stderr, "INFO: Config section [styles.%s.font] weight value is invalid.\n", key_name);
+ fprintf(stderr, "ERR: Config section [styles.%s.font] weight value is invalid.\n", key_name);
return false;
}
free(value.u.s);
@@ -362,7 +362,7 @@ static bool config_load_style(struct Style *style, toml_table_t *table, const ch
free(style->foreground_color);
style->foreground_color = color;
} else {
- fprintf(stderr, "INFO: Config section [styles.%s] foreground color value is invalid.\n", key_name);
+ fprintf(stderr, "ERR: Config section [styles.%s] foreground color value is invalid.\n", key_name);
return false;
}
free(value.u.s);
@@ -374,7 +374,7 @@ static bool config_load_style(struct Style *style, toml_table_t *table, const ch
free(style->background_color);
style->background_color = color;
} else {
- fprintf(stderr, "INFO: Config section [styles.%s] background color value is invalid.\n", key_name);
+ fprintf(stderr, "ERR: Config section [styles.%s] background color value is invalid.\n", key_name);
return false;
}
free(value.u.s);
@@ -385,7 +385,7 @@ static bool config_load_style(struct Style *style, toml_table_t *table, const ch
if (line_style != LS_EMPTY) {
style->underline_style = line_style;
} else {
- fprintf(stderr, "INFO: Config section [styles.%s] underline style value is invalid.\n", key_name);
+ fprintf(stderr, "ERR: Config section [styles.%s] underline style value is invalid.\n", key_name);
return false;
}
free(value.u.s);
@@ -397,7 +397,7 @@ static bool config_load_style(struct Style *style, toml_table_t *table, const ch
free(style->underline_color);
style->underline_color = color;
} else {
- fprintf(stderr, "INFO: Config section [styles.%s] underline color value is invalid.\n", key_name);
+ fprintf(stderr, "ERR: Config section [styles.%s] underline color value is invalid.\n", key_name);
return false;
}
free(value.u.s);
@@ -408,7 +408,7 @@ static bool config_load_style(struct Style *style, toml_table_t *table, const ch
if (line_style != LS_EMPTY) {
style->overline_style = line_style;
} else {
- fprintf(stderr, "INFO: Config section [styles.%s] overline style value is invalid.\n", key_name);
+ fprintf(stderr, "ERR: Config section [styles.%s] overline style value is invalid.\n", key_name);
return false;
}
free(value.u.s);
@@ -420,7 +420,7 @@ static bool config_load_style(struct Style *style, toml_table_t *table, const ch
free(style->overline_color);
style->overline_color = color;
} else {
- fprintf(stderr, "INFO: Config section [styles.%s] overline color value is invalid.\n", key_name);
+ fprintf(stderr, "ERR: Config section [styles.%s] overline color value is invalid.\n", key_name);
return false;
}
free(value.u.s);
@@ -436,7 +436,7 @@ static bool config_load_style(struct Style *style, toml_table_t *table, const ch
free(style->strikethrough_color);
style->strikethrough_color = color;
} else {
- fprintf(stderr, "INFO: Config section [styles.%s] strikethrough color value is invalid.\n", key_name);
+ fprintf(stderr, "ERR: Config section [styles.%s] strikethrough color value is invalid.\n", key_name);
return false;
}
free(value.u.s);
@@ -452,7 +452,7 @@ static bool config_load_style(struct Style *style, toml_table_t *table, const ch
free(style->boxed_color);
style->boxed_color = color;
} else {
- fprintf(stderr, "INFO: Config section [styles.%s] boxed color value is invalid.\n", key_name);
+ fprintf(stderr, "ERR: Config section [styles.%s] boxed color value is invalid.\n", key_name);
return false;
}
free(value.u.s);
@@ -490,14 +490,14 @@ struct Config *config_load(const char *filepath)
}
FILE *fp = fopen(filepath, "r");
if (!fp) {
- fprintf(stderr, "INFO: Couldn't open config file '%s'. Using default configuration.\n", filepath);
+ fprintf(stderr, "WARN: Couldn't open config file '%s'. Using default configuration.\n", filepath);
return config;
}
char errbuf[200];
toml_table_t *table = toml_parse_file(fp, (char *)&errbuf, sizeof(errbuf));
if (!table) {
fprintf(stderr, "toml_parse_file failed.\n");
- fprintf(stderr, "INFO: Config file is not a valid toml file.\n");
+ fprintf(stderr, "ERR: Config file is not a valid toml file.\n");
return NULL;
}
toml_table_t *styles = toml_table_table(table, "styles");
@@ -542,7 +542,7 @@ struct Config *config_load(const char *filepath)
notes_custom = config_notes_load(notes, value.u.s);
if (!notes_custom) {
fprintf(stderr, "config_notes_load failed.\n");
- fprintf(stderr, "INFO: Continuing with default naming system 'common'.\n");
+ fprintf(stderr, "WARN: Continuing with default naming system 'common'.\n");
}
}
}
diff --git a/fontconfig.c b/fontconfig.c
@@ -54,7 +54,7 @@ char *fontconfig_fontpath_find(struct Font *font, enum FontType font_type)
style.u.i = FC_SLANT_ITALIC;
break;
default:
- fprintf(stderr, "INFO: Invalid font style value '%d'.\n", font->style);
+ fprintf(stderr, "ERR: Invalid font style value '%d'.\n", font->style);
return NULL;
}
FcPatternAdd(pattern, FC_SLANT, style, FcFalse);
@@ -68,7 +68,7 @@ char *fontconfig_fontpath_find(struct Font *font, enum FontType font_type)
weight.u.i = FC_WEIGHT_BOLD;
break;
default:
- fprintf(stderr, "INFO: Invalid font weight value '%d'.\n", font->weight);
+ fprintf(stderr, "ERR: Invalid font weight value '%d'.\n", font->weight);
return NULL;
}
FcPatternAdd(pattern, FC_WEIGHT, weight, FcFalse);
diff --git a/out_pdf.c b/out_pdf.c
@@ -179,7 +179,7 @@ static char *out_pdf_filename_generate_from_songs(struct ChoSong **songs)
if (len == 1) {
title = cho_metadata_get(songs[0]->metadata, "title");
if (!title) {
- fprintf(stderr, "INFO: Song has no title.\n");
+ fprintf(stderr, "ERR: Song has no title.\n");
return NULL;
}
normalized_title = str_normalize(title);
@@ -216,7 +216,7 @@ static char *out_pdf_filename_create(struct ChoSong **songs, const char *cho_fil
return strdup(out);
} else {
free(tmp);
- fprintf(stderr, "INFO: Invalid argument --output/-o value.\n");
+ fprintf(stderr, "ERR: Invalid argument --output/-o value.\n");
return NULL;
}
break;
@@ -232,10 +232,10 @@ static char *out_pdf_filename_create(struct ChoSong **songs, const char *cho_fil
free(pdf_filepath);
return tmp;
case F_OTHER:
- fprintf(stderr, "INFO: Invalid argument --output/-o value. It doesn't refer to a folder or regular file.\n");
+ fprintf(stderr, "ERR: Invalid argument --output/-o value. It doesn't refer to a folder or regular file.\n");
return NULL;
default:
- fprintf(stderr, "INFO: Invalid enum FileType value.\n");
+ fprintf(stderr, "ERR: Invalid enum FileType value.\n");
return NULL;
}
} else {
@@ -423,7 +423,6 @@ static bool out_pdf_text_show(pdfio_stream_t *stream, struct TextLineItem *item,
red = item->style->foreground_color->red / 255.0;
green = item->style->foreground_color->green / 255.0;
blue = item->style->foreground_color->blue / 255.0;
- // printf("foreground_color: %s\n", the_rgb_color(item->style->foreground_color));
if (!pdfioContentSetFillColorRGB(stream, red, green, blue)) {
fprintf(stderr, "pdfioContentSetFillColorRGB failed.\n");
return false;
@@ -963,7 +962,7 @@ bool out_pdf_new(const char *cho_filepath, const char *output_folder_or_file, st
}
free(fontpath);
} else {
- fprintf(stderr, "INFO: Didn't find font file for following font:\n");
+ fprintf(stderr, "ERR: Didn't find font file for following font:\n");
cho_font_print(needed_fonts[f]);
return false;
}
diff --git a/todo b/todo
@@ -9,8 +9,9 @@ chords
transpose
define chords
chord diagrams
-introduce parse errors
+introduce parse errors: make parser bulletproof
still very unclear to me when the parser should warn
and continue execution and when it should fail and
stop execution
*_to_string functions sometimes return stringified enum and sometimes config value
+allow {start_of_*},{end_of_*} custom directives