commit 35ea8f898f3d437ecb47b5dde1e44a2e09c84f30
parent 4af09ce456b6fff07ea961a5117f3ef1e119a5c1
Author: nibo <nibo@relim.de>
Date: Sun, 6 Oct 2024 17:25:39 +0200
Improve stderr messages
Diffstat:
| M | README | | | 8 | +++++--- |
| M | chordpro.c | | | 180 | ++++++++++++++++++++++++++++++++++++++++---------------------------------------- |
| M | config.c | | | 12 | +++++++----- |
| M | lorid.c | | | 14 | +++++--------- |
| M | out_pdf.c | | | 132 | ++++++++++++++++++++++++++++++++++++++++---------------------------------------- |
| M | util.h | | | 6 | ++++++ |
6 files changed, 179 insertions(+), 173 deletions(-)
diff --git a/README b/README
@@ -1,8 +1,10 @@
-## stderr
+## stderr messages
-There are four types of messages printed to stderr.
Text of the form '* failed' is a message for the developer.
-The text before the word 'failed' is always a function name.
+The text before ' failed' is always a function name.
+These messages will be printed by the macro DEBUG_MSG and
+are only enabled when compiling with 'make debug'.
+
Furthermore text printed to stderr is either an ERR, WARN or INFO.
An ERR means the program can't continue execution.
A WARN means the program continues execution but recommends changing something.
diff --git a/chordpro.c b/chordpro.c
@@ -179,6 +179,7 @@ static enum SongFragmentType g_prev_ftype = SF_TEXT;
static struct Config *g_config = NULL;
static int *g_transpose_history = NULL;
static int *g_transpose = NULL;
+static size_t g_line_number = 1;
#ifdef DEBUG
@@ -322,7 +323,7 @@ struct RGBColor *cho_rgbcolor_parse(const char *str)
tmp[1] = str[2];
primary_color = strtol((char *)&tmp, NULL, 16);
if (primary_color == 0) {
- fprintf(stderr, "ERROR: Invalid primary color in rgb color.\n");
+ fprintf(stderr, "ERR: Invalid primary color in rgb color, line '%ld'.\n", g_line_number);
free(color);
return NULL;
} else {
@@ -336,7 +337,7 @@ struct RGBColor *cho_rgbcolor_parse(const char *str)
tmp[1] = str[4];
primary_color = strtol((char *)&tmp, NULL, 16);
if (primary_color == 0) {
- fprintf(stderr, "ERROR: Invalid primary color in rgb color.\n");
+ fprintf(stderr, "ERR: Invalid primary color in rgb color, line '%ld'.\n", g_line_number);
free(color);
return NULL;
} else {
@@ -350,7 +351,7 @@ struct RGBColor *cho_rgbcolor_parse(const char *str)
tmp[1] = str[6];
primary_color = strtol((char *)&tmp, NULL, 16);
if (primary_color == 0) {
- fprintf(stderr, "ERROR: Invalid primary color in rgb color.\n");
+ fprintf(stderr, "ERR: Invalid primary color in rgb color, line '%ld'.\n", g_line_number);
free(color);
return NULL;
} else {
@@ -366,7 +367,7 @@ struct RGBColor *cho_rgbcolor_parse(const char *str)
tmp[1] = str[1];
primary_color = strtol((char *)&tmp, NULL, 16);
if (primary_color == 0) {
- fprintf(stderr, "ERROR: Invalid primary color in rgb color.\n");
+ fprintf(stderr, "ERR: Invalid primary color in rgb color, line '%ld'.\n", g_line_number);
free(color);
return NULL;
} else {
@@ -380,7 +381,7 @@ struct RGBColor *cho_rgbcolor_parse(const char *str)
tmp[1] = str[2];
primary_color = strtol((char *)&tmp, NULL, 16);
if (primary_color == 0) {
- fprintf(stderr, "ERROR: Invalid primary color in rgb color.\n");
+ fprintf(stderr, "ERR: Invalid primary color in rgb color, line '%ld'.\n", g_line_number);
free(color);
return NULL;
} else {
@@ -394,7 +395,7 @@ struct RGBColor *cho_rgbcolor_parse(const char *str)
tmp[1] = str[3];
primary_color = strtol((char *)&tmp, NULL, 16);
if (primary_color == 0) {
- fprintf(stderr, "ERROR: Invalid primary color in rgb color.\n");
+ fprintf(stderr, "ERR: Invalid primary color in rgb color, line '%ld'.\n", g_line_number);
free(color);
return NULL;
} else {
@@ -402,7 +403,7 @@ struct RGBColor *cho_rgbcolor_parse(const char *str)
}
}
} else {
- fprintf(stderr, "ERROR: Invalid rgb color.\n");
+ fprintf(stderr, "ERR: Invalid rgb color, line '%ld'.\n", g_line_number);
free(color);
return NULL;
}
@@ -419,7 +420,7 @@ struct RGBColor *cho_color_parse(const char *str)
color = rgb_color;
} else {
free(color);
- fprintf(stderr, "cho_rgbcolor_parse failed.\n");
+ DEBUG_MSG("cho_rgbcolor_parse failed.");
return NULL;
}
} else if (!strcmp(str, "red")) {
@@ -459,7 +460,7 @@ struct RGBColor *cho_color_parse(const char *str)
color->green = 0;
color->blue = 0;
} else {
- fprintf(stderr, "ERR: Invalid color value '%s'.\n", str);
+ fprintf(stderr, "ERR: Invalid color value '%s', line '%ld'.\n", str, g_line_number);
free(color);
return NULL;
}
@@ -698,7 +699,7 @@ static bool cho_style_property_apply_default(enum SongFragmentType current_ftype
}
break;
default:
- fprintf(stderr, "WARN: Invalid style property type '%d'.\n", ptype);
+ fprintf(stderr, "WARN: Invalid style property type '%d', line '%ld'.\n", ptype, g_line_number);
return false;
}
}
@@ -958,7 +959,7 @@ struct Style *cho_style_parse(const char *tag_name, struct Attr **attrs, struct
} else if (!strcmp(attrs[a]->value, "monospace")) {
style->font->family = FF_MONOSPACE;
} else {
- fprintf(stderr, "ERR: Invalid value in attribute 'font_family/face'.\n");
+ fprintf(stderr, "ERR: Invalid value in attribute 'font_family/face', line '%ld'.\n", g_line_number);
return NULL;
}
} else if (!strcmp(attrs[a]->name, "size")) {
@@ -971,11 +972,11 @@ struct Style *cho_style_parse(const char *tag_name, struct Attr **attrs, struct
if (percentage != 0 && percentage <= 100) {
style->font->size *= percentage / 100.0;
} else {
- fprintf(stderr, "ERR: Invalid percentage in attribute 'size'.\n");
+ fprintf(stderr, "ERR: Invalid percentage in attribute 'size', line '%ld'.\n", g_line_number);
return NULL;
}
} else {
- fprintf(stderr, "ERR: Invalid percentage in attribute 'size'.\n");
+ fprintf(stderr, "ERR: Invalid percentage in attribute 'size', line '%ld'.\n", g_line_number);
return NULL;
}
} else if (isdigit(attrs[a]->value[0]) != 0) {
@@ -983,7 +984,7 @@ struct Style *cho_style_parse(const char *tag_name, struct Attr **attrs, struct
if (size != 0.0) {
style->font->size = size;
} else {
- fprintf(stderr, "ERR: Invalid number in attribute 'size'.\n");
+ fprintf(stderr, "ERR: Invalid number in attribute 'size', line '%ld'.\n", g_line_number);
return NULL;
}
} else if (!strcmp(attrs[a]->value, "xx-small")) {
@@ -1010,7 +1011,7 @@ struct Style *cho_style_parse(const char *tag_name, struct Attr **attrs, struct
} else if (!strcmp(attrs[a]->value, "smaller")) {
style->font->size *= 0.8;
} else {
- fprintf(stderr, "ERR: Invalid value '%s' for the attribute 'size'.\n", attrs[a]->value);
+ fprintf(stderr, "ERR: Invalid value '%s' for the attribute 'size', line '%ld'.\n", attrs[a]->value, g_line_number);
return NULL;
}
} else if (!strcmp(attrs[a]->name, "style")) {
@@ -1021,7 +1022,7 @@ struct Style *cho_style_parse(const char *tag_name, struct Attr **attrs, struct
} else if (!strcmp(attrs[a]->value, "italic")) {
style->font->style = FS_ITALIC;
} else {
- fprintf(stderr, "ERR: Invalid value in attribute 'style'.\n");
+ fprintf(stderr, "ERR: Invalid value in attribute 'style', line '%ld'.\n", g_line_number);
return NULL;
}
} else if (!strcmp(attrs[a]->name, "weight")) {
@@ -1030,13 +1031,13 @@ struct Style *cho_style_parse(const char *tag_name, struct Attr **attrs, struct
} else if (!strcmp(attrs[a]->value, "bold")) {
style->font->weight = FW_BOLD;
} else {
- fprintf(stderr, "ERR: Invalid value in attribute 'weight'.\n");
+ fprintf(stderr, "ERR: Invalid value in attribute 'weight', line '%ld'.\n", g_line_number);
return NULL;
}
} else if (!strcmp(attrs[a]->name, "foreground")) {
rgb_color = cho_color_parse(attrs[a]->value);
if (!rgb_color) {
- fprintf(stderr, "cho_color_parse failed.\n");
+ DEBUG_MSG("cho_color_parse failed.");
return NULL;
} else {
free(style->foreground_color);
@@ -1045,7 +1046,7 @@ struct Style *cho_style_parse(const char *tag_name, struct Attr **attrs, struct
} else if (!strcmp(attrs[a]->name, "background")) {
rgb_color = cho_color_parse(attrs[a]->value);
if (!rgb_color) {
- fprintf(stderr, "cho_color_parse failed.\n");
+ DEBUG_MSG("cho_color_parse failed.");
return NULL;
} else {
free(style->background_color);
@@ -1059,13 +1060,13 @@ struct Style *cho_style_parse(const char *tag_name, struct Attr **attrs, struct
} else if (!strcmp(attrs[a]->value, "none")) {
style->underline_style = LS_NONE;
} else {
- fprintf(stderr, "ERR: Invalid value in attribute 'underline'.\n");
+ fprintf(stderr, "ERR: Invalid value in attribute 'underline', line '%ld'.\n", g_line_number);
return NULL;
}
} else if (!strcmp(attrs[a]->name, "underline_colour")) {
rgb_color = cho_color_parse(attrs[a]->value);
if (!rgb_color) {
- fprintf(stderr, "cho_color_parse failed.\n");
+ DEBUG_MSG("cho_color_parse failed.");
return NULL;
} else {
free(style->underline_color);
@@ -1079,13 +1080,13 @@ struct Style *cho_style_parse(const char *tag_name, struct Attr **attrs, struct
} else if (!strcmp(attrs[a]->value, "none")) {
style->overline_style = LS_NONE;
} else {
- fprintf(stderr, "ERR: Invalid value in attribute 'overline'.\n");
+ fprintf(stderr, "ERR: Invalid value in attribute 'overline', line '%ld'.\n", g_line_number);
return NULL;
}
} else if (!strcmp(attrs[a]->name, "overline_colour")) {
rgb_color = cho_color_parse(attrs[a]->value);
if (!rgb_color) {
- fprintf(stderr, "cho_color_parse failed.\n");
+ DEBUG_MSG("cho_color_parse failed.");
return NULL;
} else {
free(style->overline_color);
@@ -1102,7 +1103,7 @@ struct Style *cho_style_parse(const char *tag_name, struct Attr **attrs, struct
if (percentage != 0 && percentage <= 100) {
style->rise = (style->font->size / 2) * percentage / 100.0;
} else {
- fprintf(stderr, "ERR: Invalid percentage in attribute 'rise'.\n");
+ fprintf(stderr, "ERR: Invalid percentage in attribute 'rise', line '%ld'.\n", g_line_number);
return NULL;
}
}
@@ -1111,11 +1112,11 @@ struct Style *cho_style_parse(const char *tag_name, struct Attr **attrs, struct
if (rise != 0.0) {
style->rise = rise;
} else {
- fprintf(stderr, "ERR: Invalid number in attribute 'rise'.\n");
+ fprintf(stderr, "ERR: Invalid number in attribute 'rise', line '%ld'.\n", g_line_number);
return NULL;
}
} else {
- fprintf(stderr, "ERR: Invalid value '%s' for the attribute 'rise'.\n", attrs[a]->value);
+ fprintf(stderr, "ERR: Invalid value '%s' for the attribute 'rise', line '%ld'.\n", attrs[a]->value, g_line_number);
return NULL;
}
} else {
@@ -1128,7 +1129,7 @@ struct Style *cho_style_parse(const char *tag_name, struct Attr **attrs, struct
double more = style->font->size / 2.0 * percentage / 100.0;
style->rise += more;
} else {
- fprintf(stderr, "ERR: Invalid percentage in attribute 'rise'.\n");
+ fprintf(stderr, "ERR: Invalid percentage in attribute 'rise', line '%ld'.\n", g_line_number);
return NULL;
}
}
@@ -1137,11 +1138,11 @@ struct Style *cho_style_parse(const char *tag_name, struct Attr **attrs, struct
if (rise != 0.0) {
style->rise = rise;
} else {
- fprintf(stderr, "ERR: Invalid number in attribute 'rise'.\n");
+ fprintf(stderr, "ERR: Invalid number in attribute 'rise', line '%ld'.\n", g_line_number);
return NULL;
}
} else {
- fprintf(stderr, "ERR: Invalid value '%s' for the attribute 'rise'.\n", attrs[a]->value);
+ fprintf(stderr, "ERR: Invalid value '%s' for the attribute 'rise', line '%ld'.\n", attrs[a]->value, g_line_number);
return NULL;
}
}
@@ -1151,13 +1152,13 @@ struct Style *cho_style_parse(const char *tag_name, struct Attr **attrs, struct
} else if (!strcmp(attrs[a]->value, "false")) {
style->strikethrough = false;
} else {
- fprintf(stderr, "ERR: Invalid value '%s' in attribute 'strikethrough'.\n", attrs[a]->value);
+ fprintf(stderr, "ERR: Invalid value '%s' in attribute 'strikethrough', line '%ld'.\n", attrs[a]->value, g_line_number);
return NULL;
}
} else if (!strcmp(attrs[a]->name, "strikethrough_colour")) {
rgb_color = cho_color_parse(attrs[a]->value);
if (!rgb_color) {
- fprintf(stderr, "cho_color_parse failed.\n");
+ DEBUG_MSG("cho_color_parse failed.");
return NULL;
} else {
free(style->strikethrough_color);
@@ -1166,7 +1167,7 @@ struct Style *cho_style_parse(const char *tag_name, struct Attr **attrs, struct
} else if (!strcmp(attrs[a]->name, "href")) {
style->href = strdup(attrs[a]->value);
} else {
- fprintf(stderr, "ERR: Invalid attribute '%s'.\n", attrs[a]->name);
+ fprintf(stderr, "ERR: Invalid attribute '%s', line '%ld'.\n", attrs[a]->name, g_line_number);
return NULL;
}
a++;
@@ -1192,7 +1193,7 @@ struct Style *cho_style_parse(const char *tag_name, struct Attr **attrs, struct
} else if (!strcmp(tag_name, "u")) {
style->underline_style = LS_SINGLE;
} else {
- fprintf(stderr, "ERR: Invalid tag name '%s'.\n", tag_name);
+ fprintf(stderr, "ERR: Invalid tag name '%s', line '%ld'.\n", tag_name, g_line_number);
cho_style_free(style);
return NULL;
}
@@ -1248,7 +1249,7 @@ static bool cho_style_change_default(struct StyleProperty sprop)
}
return true;
default:
- fprintf(stderr, "ERR: Invalid style property type '%d'.\n", sprop.type);
+ fprintf(stderr, "ERR: Invalid style property type '%d', line '%ld'.\n", sprop.type, g_line_number);
return false;
}
}
@@ -1273,7 +1274,7 @@ static bool cho_style_reset_default(void)
default_style_properties[i].u.foreground_color = NULL;
return true;
default:
- fprintf(stderr, "ERR: Invalid style property type '%d'.\n", default_style_properties[i].type);
+ fprintf(stderr, "ERR: Invalid style property type '%d', line '%ld'.\n", default_style_properties[i].type, g_line_number);
return false;
}
}
@@ -1334,7 +1335,7 @@ static bool cho_tag_close_last_unclosed(const char *tag_name, struct Tag **tags,
}
i--;
}
- fprintf(stderr, "ERR: 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', line '%ld'.\n", tag_name, g_line_number);
return false;
}
@@ -1410,7 +1411,7 @@ static struct ChoMetadata *cho_metadata_split(const char *directive_value)
free(meta->name);
free(meta->value);
free(meta);
- fprintf(stderr, "ERR: Failed to parse directive 'meta'.\n");
+ fprintf(stderr, "ERR: Failed to parse directive 'meta', line '%ld'.\n", g_line_number);
return NULL;
}
}
@@ -1506,7 +1507,7 @@ static char *transposition_calc_chord_root(int index, enum NoteType type)
case NT_FLAT:
return strdup(g_config->output->notes[new_index]->flat);
}
- fprintf(stderr, "ERR: Invalid NoteType '%d'.\n", note_type);
+ fprintf(stderr, "ERR: Invalid NoteType '%d', line '%ld'.\n", note_type, g_line_number);
return NULL;
}
@@ -1564,7 +1565,7 @@ static int cho_chord_root_parse(const char *str, struct ChoChord *chord)
if (sharp && str_starts_with(str, sharp)) {
transposed_root = transposition_calc_chord_root(i, NT_SHARP);
if (!transposed_root) {
- fprintf(stderr, "transposition_calc_chord_root failed.\n");
+ DEBUG_MSG("transposition_calc_chord_root failed.");
return 0;
}
chord->root = transposed_root;
@@ -1574,7 +1575,7 @@ static int cho_chord_root_parse(const char *str, struct ChoChord *chord)
if (flat && str_starts_with(str, flat)) {
transposed_root = transposition_calc_chord_root(i, NT_FLAT);
if (!transposed_root) {
- fprintf(stderr, "transposition_calc_chord_root failed.\n");
+ DEBUG_MSG("transposition_calc_chord_root failed.");
return 0;
}
chord->root = transposed_root;
@@ -1584,7 +1585,7 @@ static int cho_chord_root_parse(const char *str, struct ChoChord *chord)
if (str_starts_with(str, note)) {
transposed_root = transposition_calc_chord_root(i, NT_NOTE);
if (!transposed_root) {
- fprintf(stderr, "transposition_calc_chord_root failed.\n");
+ DEBUG_MSG("transposition_calc_chord_root failed.");
return 0;
}
chord->root = transposed_root;
@@ -1950,7 +1951,7 @@ enum OptionState {
OS_VALUE
};
-static struct ChoImage *cho_image_directive_parse(const char *str, size_t line_number)
+static struct ChoImage *cho_image_directive_parse(const char *str)
{
struct ChoImage *image = cho_image_new();
int i = 0;
@@ -1975,7 +1976,7 @@ static struct ChoImage *cho_image_directive_parse(const char *str, size_t line_n
break;
} else {
name[n] = 0;
- fprintf(stderr, "ERR: Option with name '%s' in image directive in line '%ld' has no value.\n", name, line_number);
+ fprintf(stderr, "ERR: Option with name '%s' in image directive has no value, line '%ld'.\n", name, g_line_number);
return NULL;
}
}
@@ -1987,7 +1988,7 @@ static struct ChoImage *cho_image_directive_parse(const char *str, size_t line_n
break;
}
if (n > 5) {
- fprintf(stderr, "ERR: Option name in image directive in line '%ld' is too long.\n", line_number);
+ fprintf(stderr, "ERR: Option name in image directive is too long, line '%ld'.\n", g_line_number);
return NULL;
}
name[n] = c;
@@ -1996,7 +1997,7 @@ static struct ChoImage *cho_image_directive_parse(const char *str, size_t line_n
case OS_VALUE:
if (avs == AVS_NO) {
if (is_whitespace(c)) {
- fprintf(stderr, "ERR: Whitespace character after equals sign in image directive in line '%ld' is invalid.\n", line_number);
+ fprintf(stderr, "ERR: Whitespace character after equals sign in image directive is invalid, line '%ld'.\n", g_line_number);
return NULL;
}
if (c == '\'') {
@@ -2011,7 +2012,7 @@ static struct ChoImage *cho_image_directive_parse(const char *str, size_t line_n
break;
}
if (c == '\n') {
- fprintf(stderr, "ERR: Newline character inside an option value in image directive in line '%ld' is invalid.\n", line_number);
+ fprintf(stderr, "ERR: Newline character inside an option value in image directive is invalid, line '%ld'.\n", g_line_number);
return NULL;
}
if (
@@ -2352,7 +2353,6 @@ struct ChoSong **cho_songs_parse(FILE *fp, struct Config *config)
char custom_directive[64];
enum State state = STATE_LYRICS;
enum State prev_state = STATE_LYRICS;
- size_t line_number = 1;
int dn = 0;
int dv = 0;
int ch = 0;
@@ -2530,12 +2530,12 @@ struct ChoSong **cho_songs_parse(FILE *fp, struct Config *config)
}
break;
default:
- fprintf(stderr, "ERR: Invalid position value '%d'.\n", directive->position);
+ fprintf(stderr, "ERR: Invalid position value '%d', line '%ld'.\n", directive->position, g_line_number);
return NULL;
}
break;
case DT_METADATA:
- fprintf(stderr, "INFO: Metadata directive '%s' has no value.\n", directive_name);
+ fprintf(stderr, "INFO: Metadata directive '%s' has no value, line '%ld'.\n", directive_name, g_line_number);
songs[so]->metadata = realloc(songs[so]->metadata, (m+1) * sizeof(struct ChoMetadata *));
songs[so]->metadata[m] = cho_metadata_new();
songs[so]->metadata[m]->name = strdup(directive_name);
@@ -2543,10 +2543,10 @@ struct ChoSong **cho_songs_parse(FILE *fp, struct Config *config)
memset(directive_name, 0, strlen(directive_name));
break;
case DT_FORMATTING:
- fprintf(stderr, "WARN: Formatting directive '%s' has no value.\n", directive_name);
+ fprintf(stderr, "WARN: Formatting directive '%s' has no value, line '%ld'.\n", directive_name, g_line_number);
break;
case DT_IMAGE:
- fprintf(stderr, "ERR: Directive 'image' has no value.\n");
+ fprintf(stderr, "ERR: Directive 'image' has no value, line '%ld'.\n", g_line_number);
return NULL;
case DT_PREAMBLE:
// INFO: The only preamble directive is 'new_song'
@@ -2560,7 +2560,7 @@ struct ChoSong **cho_songs_parse(FILE *fp, struct Config *config)
songs[so]->sections = realloc(songs[so]->sections, (se+1) * sizeof(struct ChoSection *));
songs[so]->sections[se] = NULL;
if (!cho_style_reset_default()) {
- fprintf(stderr, "cho_style_reset_default failed.\n");
+ DEBUG_MSG("cho_style_reset_default failed.");
return NULL;
}
so++;
@@ -2591,11 +2591,11 @@ struct ChoSong **cho_songs_parse(FILE *fp, struct Config *config)
sprop.u.foreground_color = NULL;
break;
default:
- fprintf(stderr, "ERR: Invalid style property type '%d'.\n", directive->sprop);
+ fprintf(stderr, "ERR: Invalid style property type '%d', line '%ld'.\n", directive->sprop, g_line_number);
return NULL;
}
if (!cho_style_change_default(sprop)) {
- fprintf(stderr, "cho_style_change_default failed.\n");
+ DEBUG_MSG("cho_style_change_default failed.");
return NULL;
}
break;
@@ -2611,10 +2611,10 @@ struct ChoSong **cho_songs_parse(FILE *fp, struct Config *config)
break;
case DT_CUSTOM:
// TODO: Implement {start_of_*} and {end_of_*} custom directives
- fprintf(stderr, "INFO: Ignoring custom directive '%s'.\n", directive_name);
+ fprintf(stderr, "INFO: Ignoring custom directive '%s', line '%ld'.\n", directive_name, g_line_number);
break;
default:
- fprintf(stderr, "ERR: Invalid directive '%s'.\n", directive_name);
+ fprintf(stderr, "ERR: Invalid directive '%s', line '%ld'.\n", directive_name, g_line_number);
return NULL;
}
cho_directive_free(directive);
@@ -2685,7 +2685,7 @@ struct ChoSong **cho_songs_parse(FILE *fp, struct Config *config)
}
break;
default:
- fprintf(stderr, "ERR: Invalid position value '%d'.\n", directive->position);
+ fprintf(stderr, "ERR: Invalid position value '%d', line '%ld'.\n", directive->position, g_line_number);
return NULL;
}
break;
@@ -2697,7 +2697,7 @@ struct ChoSong **cho_songs_parse(FILE *fp, struct Config *config)
songs[so]->metadata[m] = metadata;
m++;
} else {
- fprintf(stderr, "cho_metadata_split failed.\n");
+ DEBUG_MSG("cho_metadata_split failed.");
return NULL;
}
} else {
@@ -2736,15 +2736,15 @@ struct ChoSong **cho_songs_parse(FILE *fp, struct Config *config)
te += strlen(trimmed_directive_value);
break;
case DT_IMAGE:
- image = cho_image_directive_parse(directive_value, line_number);
+ image = cho_image_directive_parse(directive_value);
if (!image) {
- fprintf(stderr, "cho_image_directive_parse failed.\n");
+ DEBUG_MSG("cho_image_directive_parse failed.");
return NULL;
}
cho_image_free(image);
break;
case DT_PREAMBLE:
- fprintf(stderr, "ERR: Preamble directive '%s' can't have a value.\n", directive_name);
+ fprintf(stderr, "ERR: Preamble directive '%s' can't have a value, line '%ld'.\n", directive_name, g_line_number);
return NULL;
case DT_FONT:
sprop.ftype = directive->ftype;
@@ -2758,7 +2758,7 @@ 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, "ERR: Font directive '%s' has an invalid value.\n", directive_name);
+ fprintf(stderr, "ERR: Font directive '%s' has an invalid value, line '%ld'.\n", directive_name, g_line_number);
return NULL;
}
sprop.type = SPT_SIZE;
@@ -2766,17 +2766,17 @@ struct ChoSong **cho_songs_parse(FILE *fp, struct Config *config)
case SPT_COLOR:
sprop.u.foreground_color = cho_color_parse(dir_value);
if (sprop.u.foreground_color == NULL) {
- fprintf(stderr, "ERR: Font directive '%s' has an invalid value.\n", directive_name);
+ fprintf(stderr, "ERR: Font directive '%s' has an invalid value, line '%ld'.\n", directive_name, g_line_number);
return NULL;
}
sprop.type = SPT_COLOR;
break;
default:
- fprintf(stderr, "ERR: Invalid style property type '%d'.\n", directive->sprop);
+ fprintf(stderr, "ERR: Invalid style property type '%d', line '%ld'.\n", directive->sprop, g_line_number);
return NULL;
}
if (!cho_style_change_default(sprop)) {
- fprintf(stderr, "cho_style_change_default failed.\n");
+ DEBUG_MSG("cho_style_change_default failed.");
return NULL;
}
if (sprop.type == SPT_FONT) {
@@ -2789,8 +2789,8 @@ struct ChoSong **cho_songs_parse(FILE *fp, struct Config *config)
case DT_CHORD:
/* INFO: The only chord directive is currently 'transpose' */
if (!transposition_parse(directive_value, &transpose)) {
- fprintf(stderr, "transposition_parse failed.\n");
- fprintf(stderr, "ERR: Directive 'transpose' has an invalid value.\n");
+ DEBUG_MSG("transposition_parse failed.");
+ fprintf(stderr, "ERR: Directive 'transpose' has an invalid value, line '%ld'.\n", g_line_number);
return NULL;
}
g_transpose_history = realloc(g_transpose_history, (th+1) * sizeof(int *));
@@ -2799,13 +2799,13 @@ struct ChoSong **cho_songs_parse(FILE *fp, struct Config *config)
th++;
break;
case DT_OUTPUT:
- fprintf(stderr, "ERR: Directive '%s' can't have a value.\n", directive_name);
+ fprintf(stderr, "ERR: Directive '%s' can't have a value, line '%ld'.\n", directive_name, g_line_number);
return NULL;
case DT_CUSTOM:
- fprintf(stderr, "INFO: Ignoring custom directive '%s'.\n", directive_name);
+ fprintf(stderr, "INFO: Ignoring custom directive '%s', line '%ld'.\n", directive_name, g_line_number);
break;
default:
- fprintf(stderr, "ERR: Invalid directive '%d'.\n", directive->dtype);
+ fprintf(stderr, "ERR: Invalid directive '%d', line '%ld'.\n", directive->dtype, g_line_number);
return NULL;
}
memset(directive_value, 0, strlen(directive_value));
@@ -2829,7 +2829,7 @@ struct ChoSong **cho_songs_parse(FILE *fp, struct Config *config)
tmp_chord = cho_chord_parse(chord);
cho_chord_complete(songs[so]->sections[se]->lines[li]->text_above[c]->u.chord, tmp_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 %ld.\n", songs[so]->sections[se]->lines[li]->text_above[c]->u.chord->name, line_number);
+ fprintf(stderr, "INFO: Didn't recognize the chord '%s', line '%ld'.\n", songs[so]->sections[se]->lines[li]->text_above[c]->u.chord->name, g_line_number);
}
cho_chord_free(tmp_chord);
is_chord_already_initialized = false;
@@ -2842,7 +2842,7 @@ struct ChoSong **cho_songs_parse(FILE *fp, struct Config *config)
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 %ld.\n", songs[so]->sections[se]->lines[li]->text_above[c]->u.chord->name, line_number);
+ fprintf(stderr, "INFO: Didn't recognize the chord '%s', line '%ld'.\n", songs[so]->sections[se]->lines[li]->text_above[c]->u.chord->name, g_line_number);
}
// cho_debug_chord_print(songs[so]->sections[se]->lines[li]->text_above[c]->u.chord);
}
@@ -2917,7 +2917,7 @@ struct ChoSong **cho_songs_parse(FILE *fp, struct Config *config)
tags[ta]->name = strdup(tag_begin);
tag_style = cho_style_parse(tag_begin, NULL, cho_tag_style_inherit(tags, ta-1));
if (!tag_style) {
- fprintf(stderr, "cho_style_parse failed.\n");
+ DEBUG_MSG("cho_style_parse failed.");
return NULL;
}
tags[ta]->style = tag_style;
@@ -2935,7 +2935,7 @@ struct ChoSong **cho_songs_parse(FILE *fp, struct Config *config)
songs[so]->sections[se]->lines[li]->text_above[c]->u.annot->style = cho_style_duplicate(tag_style);
break;
default:
- fprintf(stderr, "ERR: Invalid prev_state '%s'.\n", state_enums[prev_state]);
+ fprintf(stderr, "ERR: Invalid prev_state '%s', line '%ld'.\n", state_enums[prev_state], g_line_number);
return NULL;
}
memset(tag_begin, 0, strlen(tag_begin));
@@ -2953,7 +2953,7 @@ struct ChoSong **cho_songs_parse(FILE *fp, struct Config *config)
}
if (t == 5) {
tag_begin[t] = 0;
- fprintf(stderr, "ERR: Begin tag name '%s' is too long.\n", tag_begin);
+ fprintf(stderr, "ERR: Begin tag name '%s' is too long, line '%ld'.\n", tag_begin, g_line_number);
return NULL;
}
tag_begin[t] = buf;
@@ -2975,7 +2975,7 @@ struct ChoSong **cho_songs_parse(FILE *fp, struct Config *config)
tag_end[t] = 0;
t = 0;
if (!cho_tag_close_last_unclosed(tag_end, tags, ta)) {
- fprintf(stderr, "cho_tag_close_last_unclosed failed.\n");
+ DEBUG_MSG("cho_tag_close_last_unclosed failed.");
return NULL;
}
memset(tag_end, 0, strlen(tag_end));
@@ -2984,7 +2984,7 @@ struct ChoSong **cho_songs_parse(FILE *fp, struct Config *config)
}
if (t == 5) {
tag_end[t] = 0;
- fprintf(stderr, "ERR: End tag name '%s' is too long.\n", tag_end);
+ fprintf(stderr, "ERR: End tag name '%s' is too long, line '%ld'.\n", tag_end, g_line_number);
return NULL;
}
tag_end[t] = buf;
@@ -3005,7 +3005,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, "ERR: Attribute with name '%s' of tag '%s' in line '%ld' has no value.\n", tags[ta]->attrs[at]->name, tag_begin, line_number);
+ fprintf(stderr, "ERR: Attribute with name '%s' of tag '%s' has no value, line '%ld'.\n", tags[ta]->attrs[at]->name, tag_begin, g_line_number);
return NULL;
}
}
@@ -3017,7 +3017,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, "ERR: Attribute with name '%s' of tag '%s' in line '%ld' has no value.\n", tags[ta]->attrs[at]->name, tag_begin, line_number);
+ fprintf(stderr, "ERR: Attribute with name '%s' of tag '%s' has no value, line '%ld'.\n", tags[ta]->attrs[at]->name, tag_begin, g_line_number);
return NULL;
}
if (buf == '>') {
@@ -3026,7 +3026,7 @@ struct ChoSong **cho_songs_parse(FILE *fp, struct Config *config)
tags[ta]->attrs[at] = NULL;
tag_style = cho_style_parse(tag_begin, tags[ta]->attrs, cho_tag_style_inherit(tags, ta-1));
if (!tag_style) {
- fprintf(stderr, "cho_style_parse failed.\n");
+ DEBUG_MSG("cho_style_parse failed.");
return NULL;
}
tags[ta]->style = tag_style;
@@ -3044,7 +3044,7 @@ struct ChoSong **cho_songs_parse(FILE *fp, struct Config *config)
songs[so]->sections[se]->lines[li]->text_above[c]->u.annot->style = cho_style_duplicate(tag_style);
break;
default:
- fprintf(stderr, "ERR: Invalid prev_state '%s'.\n", state_enums[prev_state]);
+ fprintf(stderr, "ERR: Invalid prev_state '%s', line '%ld'.\n", state_enums[prev_state], g_line_number);
return NULL;
}
at = 0;
@@ -3055,7 +3055,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, "ERR: Attribute with name '%s' of tag '%s' in line '%ld' has no value.\n", tags[ta]->attrs[at]->name, tag_begin, line_number);
+ fprintf(stderr, "ERR: Attribute with name '%s' of tag '%s' has no value, line '%ld'.\n", tags[ta]->attrs[at]->name, tag_begin, g_line_number);
return NULL;
}
}
@@ -3066,11 +3066,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, "ERR: Whitespace character after equals sign in line '%ld' is invalid.\n", line_number);
+ fprintf(stderr, "ERR: Whitespace character after equals sign is invalid, line '%ld'.\n", g_line_number);
return NULL;
}
if (buf == '>') {
- fprintf(stderr, "ERR: Attribute with name '%s' of tag '%s' in line '%ld' has no value.\n", tags[ta]->attrs[at]->name, tag_begin, line_number);
+ fprintf(stderr, "ERR: Attribute with name '%s' of tag '%s' has no value, line '%ld'.\n", tags[ta]->attrs[at]->name, tag_begin, g_line_number);
return NULL;
}
if (buf == '\'') {
@@ -3086,7 +3086,7 @@ struct ChoSong **cho_songs_parse(FILE *fp, struct Config *config)
break;
}
if (buf == '\n') {
- fprintf(stderr, "ERR: Newline character inside an attribute value in line '%ld' is invalid.\n", line_number);
+ fprintf(stderr, "ERR: Newline character inside an attribute value is invalid, line '%ld'.\n", g_line_number);
return NULL;
}
if (avs == AVS_UNQUOTED && buf == '>') {
@@ -3098,7 +3098,7 @@ struct ChoSong **cho_songs_parse(FILE *fp, struct Config *config)
tags[ta]->attrs[at] = NULL;
tag_style = cho_style_parse(tag_begin, tags[ta]->attrs, cho_tag_style_inherit(tags, ta-1));
if (!tag_style) {
- fprintf(stderr, "cho_style_parse failed.\n");
+ DEBUG_MSG("cho_style_parse failed.");
return NULL;
}
tags[ta]->style = tag_style;
@@ -3116,7 +3116,7 @@ struct ChoSong **cho_songs_parse(FILE *fp, struct Config *config)
songs[so]->sections[se]->lines[li]->text_above[c]->u.annot->style = cho_style_duplicate(tag_style);
break;
default:
- fprintf(stderr, "ERR: Invalid prev_state '%s'.\n", state_enums[prev_state]);
+ fprintf(stderr, "ERR: Invalid prev_state '%s', line '%ld'.\n", state_enums[prev_state], g_line_number);
return NULL;
}
at = 0;
@@ -3153,11 +3153,11 @@ struct ChoSong **cho_songs_parse(FILE *fp, struct Config *config)
}
prev_buf = buf;
} else if (ferror(fp) != 0) {
- fprintf(stderr, "fread failed.\n");
+ DEBUG_MSG("fread failed.");
return NULL;
}
if (buf == '\n') {
- line_number++;
+ g_line_number++;
}
}
int e = 0;
@@ -3185,7 +3185,7 @@ struct ChoSong **cho_songs_parse(FILE *fp, struct Config *config)
songs[so]->sections[se]->lines[li] = NULL;
}
if (!cho_style_reset_default()) {
- fprintf(stderr, "cho_style_reset_default failed.\n");
+ DEBUG_MSG("cho_style_reset_default failed.");
return NULL;
}
songs[so]->metadata = realloc(songs[so]->metadata, (m+1) * sizeof(struct ChoMetadata *));
diff --git a/config.c b/config.c
@@ -4,6 +4,7 @@
#include <toml.h>
#include "chordpro.h"
#include "config.h"
+#include "util.h"
static char *naming_systems[] = {
"common",
@@ -424,7 +425,7 @@ static bool config_load_style(struct Style *style, toml_table_t *table, const ch
toml_table_t *font_section = toml_table_table(table, "font");
if (font_section) {
if (!config_load_font(style->font, font_section, key_name)) {
- fprintf(stderr, "config_load_font failed.\n");
+ DEBUG_MSG("config_load_font failed.");
return false;
}
}
@@ -569,8 +570,9 @@ struct Config *config_load(const char *filepath)
char errbuf[200];
toml_table_t *table = toml_parse_file(fp, (char *)&errbuf, sizeof(errbuf));
if (!table) {
- fprintf(stderr, "toml_parse_file failed.\n");
+ DEBUG_MSG("toml_parse_file failed.");
fprintf(stderr, "ERR: Config file is not a valid toml file.\n");
+ fprintf(stderr, "%s\n", (char *)&errbuf);
return NULL;
}
toml_table_t *output = toml_table_table(table, "output");
@@ -593,7 +595,7 @@ struct Config *config_load(const char *filepath)
config_notes_free(config->output->notes);
config->output->notes = custom_notes;
} else {
- fprintf(stderr, "config_notes_load failed.\n");
+ DEBUG_MSG("config_notes_load failed.");
fprintf(stderr, "ERR: Couldn't load custom notes '%s' from [notes] section.\n", value.u.s);
return NULL;
}
@@ -617,7 +619,7 @@ struct Config *config_load(const char *filepath)
item = config_printable_item_get(config->output->printable_items, key_name);
if (item) {
if (!config_load_style(item->style, key, key_name)) {
- fprintf(stderr, "config_load_style failed.\n");
+ DEBUG_MSG("config_load_style failed.");
return NULL;
}
}
@@ -648,7 +650,7 @@ struct Config *config_load(const char *filepath)
config_notes_free(config->parser->notes);
config->parser->notes = custom_notes;
} else {
- fprintf(stderr, "config_notes_load failed.\n");
+ DEBUG_MSG("config_notes_load failed.");
fprintf(stderr, "ERR: Couldn't load custom notes '%s' from [notes] section.\n", value.u.s);
return NULL;
}
diff --git a/lorid.c b/lorid.c
@@ -46,7 +46,7 @@ int main(int argc, char *argv[])
}
struct Config *config = config_load(config_filepath);
if (!config) {
- fprintf(stderr, "config_load failed.\n");
+ DEBUG_MSG("config_load failed.");
return 1;
}
free(config_filepath);
@@ -55,29 +55,25 @@ int main(int argc, char *argv[])
} else if (argc == optind+1) {
fp = fopen(argv[argc-1], "r");
if (!fp) {
- fprintf(stderr, "fopen failed.\n");
+ DEBUG_MSG("fopen failed.");
return 1;
}
} else {
- fprintf(stderr, "Provide only one file.\n");
+ fprintf(stderr, "ERR: Provide only one file.\n");
return 1;
}
struct ChoSong **songs = cho_songs_parse(fp, config);
if (!songs) {
- fprintf(stderr, "cho_parse failed.\n");
+ DEBUG_MSG("cho_parse failed.");
return 1;
}
char *pdf_filename = out_pdf_new(argc == optind+1 ? argv[argc-1] : NULL, output ? output : NULL, songs, config);
if (!pdf_filename) {
- fprintf(stderr, "out_pdf_new failed.\n");
+ DEBUG_MSG("out_pdf_new failed.");
return 1;
}
fprintf(stderr, "INFO: Writing pdf to file: '%s'\n", pdf_filename);
free(pdf_filename);
- /* if (!out_pdf_new(argc == optind+1 ? argv[argc-1] : NULL, output ? output : NULL, songs, config)) {
- fprintf(stderr, "out_pdf_new failed.\n");
- return 1;
- } */
free(output);
cho_songs_free(songs);
config_free(config);
diff --git a/out_pdf.c b/out_pdf.c
@@ -181,7 +181,7 @@ static char *out_pdf_filename_create(struct ChoSong **songs, const char *cho_fil
} else {
pdf_filename = out_pdf_filename_generate_from_songs(songs);
if (!pdf_filename) {
- fprintf(stderr, "out_pdf_filename_generate_from_songs failed.\n");
+ DEBUG_MSG("out_pdf_filename_generate_from_songs failed.");
return NULL;
}
}
@@ -318,12 +318,12 @@ static bool out_pdf_font_set(pdfio_stream_t *stream, struct Font *font)
return true;
}
if (!pdfioContentSetTextFont(stream, name, font->size)) {
- fprintf(stderr, "pdfioContentSetTextFont failed.\n");
+ DEBUG_MSG("pdfioContentSetTextFont failed.");
return false;
}
pdfio_obj_t *font_obj = out_pdf_fnt_obj_get_by_name(name);
if (!font_obj) {
- fprintf(stderr, "out_pdf_fnt_obj_get_by_name failed.\n");
+ DEBUG_MSG("out_pdf_fnt_obj_get_by_name failed.");
return false;
}
strcpy(g_current_font_name, name);
@@ -371,7 +371,7 @@ static double text_width(struct TextLineItem *item)
char *name = out_pdf_fnt_name_create(item->style->font);
pdfio_obj_t *font_obj = out_pdf_fnt_obj_get_by_name(name);
if (!font_obj) {
- fprintf(stderr, "out_pdf_fnt_obj_get_by_name failed.\n");
+ DEBUG_MSG("out_pdf_fnt_obj_get_by_name failed.");
return -1.0;
}
free(name);
@@ -384,7 +384,7 @@ static enum Bool text_fits(const char *str, struct Style *style)
char *name = out_pdf_fnt_name_create(style->font);
pdfio_obj_t *font_obj = out_pdf_fnt_obj_get_by_name(name);
if (!font_obj) {
- fprintf(stderr, "out_pdf_fnt_obj_get_by_name failed.\n");
+ DEBUG_MSG("out_pdf_fnt_obj_get_by_name failed.");
return B_ERROR;
}
free(name);
@@ -423,7 +423,7 @@ static char *text_find_fitting(const char *str, struct Style *style)
tmp[i] = 0;
fits = text_fits((const char *)&tmp, style);
if (fits == B_ERROR) {
- fprintf(stderr, "text_fits failed.\n");
+ DEBUG_MSG("text_fits failed.");
return NULL;
}
start = i - 1;
@@ -445,7 +445,7 @@ static struct TextLine **text_split_by_whitespace(const char *str, struct Style
while (1) {
fits = text_fits(text, style);
if (fits == B_ERROR) {
- fprintf(stderr, "text_fits failed.\n");
+ DEBUG_MSG("text_fits failed.");
return NULL;
}
if (fits) {
@@ -461,7 +461,7 @@ static struct TextLine **text_split_by_whitespace(const char *str, struct Style
}
fitting = text_find_fitting(text, style);
if (!fitting) {
- fprintf(stderr, "text_find_fitting failed.\n");
+ DEBUG_MSG("text_find_fitting failed.");
return NULL;
}
line = text_line_create(fitting, style);
@@ -487,7 +487,7 @@ static enum Bool text_line_fits(struct TextLine *line)
}
width = text_width(line->items[i-1]);
if (width == EMPTY) {
- fprintf(stderr, "text_width failed.\n");
+ DEBUG_MSG("text_width failed.");
return B_ERROR;
}
if (line->items[i-1]->x + width > LINE_WIDTH) {
@@ -520,19 +520,19 @@ static bool out_pdf_draw_line(pdfio_stream_t *stream, struct TextLineItem *item,
break;
}
if (!pdfioContentPathMoveTo(stream, item->x, y)) {
- fprintf(stderr, "pdfioContentPathMoveTo failed.\n");
+ DEBUG_MSG("pdfioContentPathMoveTo failed.");
return false;
}
if (!pdfioContentPathLineTo(stream, item->x + width, y)) {
- fprintf(stderr, "pdfioContentPathLineTo failed.\n");
+ DEBUG_MSG("pdfioContentPathLineTo failed.");
return false;
}
if (!pdfioContentSetStrokeColorRGB(stream, red, green, blue)) {
- fprintf(stderr, "pdfioContentSetStrokeColorRGB failed.\n");
+ DEBUG_MSG("pdfioContentSetStrokeColorRGB failed.");
return false;
}
if (!pdfioContentStroke(stream)) {
- fprintf(stderr, "pdfioContentStroke failed.\n");
+ DEBUG_MSG("pdfioContentStroke failed.");
return false;
}
return true;
@@ -544,38 +544,38 @@ static bool out_pdf_text_show(pdfio_stream_t *stream, struct TextLineItem *item,
// TODO: Maybe store the width in TextLineItem
width = text_width(item);
if (width == EMPTY) {
- fprintf(stderr, "text_width failed.\n");
+ DEBUG_MSG("text_width failed.");
return false;
}
if (!out_pdf_font_set(stream, item->style->font)) {
- fprintf(stderr, "out_pdf_font_set failed.\n");
+ DEBUG_MSG("out_pdf_font_set failed.");
return false;
}
red = item->style->foreground_color->red / 255.0;
green = item->style->foreground_color->green / 255.0;
blue = item->style->foreground_color->blue / 255.0;
if (!pdfioContentSetFillColorRGB(stream, red, green, blue)) {
- fprintf(stderr, "pdfioContentSetFillColorRGB failed.\n");
+ DEBUG_MSG("pdfioContentSetFillColorRGB failed.");
return false;
}
if (!pdfioContentTextBegin(stream)) {
- fprintf(stderr, "pdfioContentTextBegin failed.\n");
+ DEBUG_MSG("pdfioContentTextBegin failed.");
return false;
}
if (!pdfioContentTextMoveTo(stream, item->x, y)) {
- fprintf(stderr, "pdfioContentTextMoveTo failed.\n");
+ DEBUG_MSG("pdfioContentTextMoveTo failed.");
return false;
}
if (!pdfioContentSetTextRise(stream, item->style->rise)) {
- fprintf(stderr, "pdfioContentSetTextRise failed.\n");
+ DEBUG_MSG("pdfioContentSetTextRise failed.");
return false;
}
if (!pdfioContentTextShow(stream, true, item->text)) {
- fprintf(stderr, "pdfioContentTextShow failed.\n");
+ DEBUG_MSG("pdfioContentTextShow failed.");
return false;
}
if (!pdfioContentTextEnd(stream)) {
- fprintf(stderr, "pdfioContentTextEnd failed.\n");
+ DEBUG_MSG("pdfioContentTextEnd failed.");
return false;
}
if (item->style->underline_style == LS_SINGLE) {
@@ -598,15 +598,15 @@ static bool out_pdf_text_show(pdfio_stream_t *stream, struct TextLineItem *item,
green = item->style->boxed_color->green / 255.0;
blue = item->style->boxed_color->blue / 255.0;
if (!pdfioContentSetStrokeColorRGB(stream, red, green, blue)) {
- fprintf(stderr, "pdfioContentSetFillColorRGB failed.\n");
+ DEBUG_MSG("pdfioContentSetFillColorRGB failed.");
return false;
}
if (!pdfioContentPathRect(stream, item->x - 2.0, y - 2.0, width + 4.0, item->style->font->size * 0.8 + 4.0)) {
- fprintf(stderr, "pdfioContentPathRect failed.\n");
+ DEBUG_MSG("pdfioContentPathRect failed.");
return false;
}
if (!pdfioContentStroke(stream)) {
- fprintf(stderr, "pdfioContentStroke failed.\n");
+ DEBUG_MSG("pdfioContentStroke failed.");
return false;
}
}
@@ -644,7 +644,7 @@ static double line_width_until_chord(struct ChoLine *line, struct ChoLineItemAbo
name = out_pdf_fnt_name_create(line->lyrics[ly]->style->font);
font_obj = out_pdf_fnt_obj_get_by_name(name);
if (!font_obj) {
- fprintf(stderr, "out_pdf_fnt_obj_get_by_name failed.\n");
+ DEBUG_MSG("out_pdf_fnt_obj_get_by_name failed.");
return EMPTY;
}
if (ly == last_ly) {
@@ -678,7 +678,7 @@ static enum Bool out_pdf_text_above_is_enough_space(struct ChoLine *line, struct
name = out_pdf_fnt_name_create(prev_text_above->u.chord->style->font);
font_obj = out_pdf_fnt_obj_get_by_name(name);
if (!font_obj) {
- fprintf(stderr, "out_pdf_fnt_obj_get_by_name failed.\n");
+ DEBUG_MSG("out_pdf_fnt_obj_get_by_name failed.");
return B_ERROR;
}
free(name);
@@ -687,7 +687,7 @@ static enum Bool out_pdf_text_above_is_enough_space(struct ChoLine *line, struct
name = out_pdf_fnt_name_create(prev_text_above->u.annot->style->font);
font_obj = out_pdf_fnt_obj_get_by_name(name);
if (!font_obj) {
- fprintf(stderr, "out_pdf_fnt_obj_get_by_name failed.\n");
+ DEBUG_MSG("out_pdf_fnt_obj_get_by_name failed.");
return B_ERROR;
}
free(name);
@@ -740,7 +740,7 @@ static struct Text **text_create(struct ChoSong **songs, struct Config *config)
if (!strcmp(songs[so]->metadata[m]->name, "title")) {
fits = text_fits(songs[so]->metadata[m]->value, songs[so]->metadata[m]->style);
if (fits == B_ERROR) {
- fprintf(stderr, "text_fits failed.\n");
+ DEBUG_MSG("text_fits failed.");
return NULL;
}
if (fits) {
@@ -752,7 +752,7 @@ static struct Text **text_create(struct ChoSong **songs, struct Config *config)
text[t]->lines[tl]->items[0]->style = cho_style_duplicate(songs[so]->metadata[m]->style);
width = text_width(text[t]->lines[tl]->items[0]);
if (width == EMPTY) {
- fprintf(stderr, "text_width failed.\n");
+ DEBUG_MSG("text_width failed.");
return NULL;
}
text[t]->lines[tl]->items[0]->x = MARGIN_HORIZONTAL + (LINE_WIDTH - width) / 2;
@@ -771,7 +771,7 @@ static struct Text **text_create(struct ChoSong **songs, struct Config *config)
for (int i = 0; text_lines[i]; i++) {
width = text_width(text_lines[i]->items[0]);
if (width == EMPTY) {
- fprintf(stderr, "text_width failed.\n");
+ DEBUG_MSG("text_width failed.");
return NULL;
}
text_lines[i]->items[0]->x = MARGIN_HORIZONTAL + (LINE_WIDTH - width) / 2;
@@ -787,13 +787,13 @@ static struct Text **text_create(struct ChoSong **songs, struct Config *config)
if (!strcmp(songs[so]->metadata[m]->name, "subtitle")) {
fits = text_fits(songs[so]->metadata[m]->value, songs[so]->metadata[m]->style);
if (fits == B_ERROR) {
- fprintf(stderr, "text_fits failed.\n");
+ DEBUG_MSG("text_fits failed.");
return NULL;
}
if (fits) {
printable_item = config_printable_item_get(config->output->printable_items, "subtitle");
if (!printable_item) {
- fprintf(stderr, "config_printable_item_get failed.\n");
+ DEBUG_MSG("config_printable_item_get failed.");
return NULL;
}
text[t]->lines = realloc(text[t]->lines, (tl+1) * sizeof(struct TextLine *));
@@ -804,7 +804,7 @@ static struct Text **text_create(struct ChoSong **songs, struct Config *config)
text[t]->lines[tl]->items[0]->style = cho_style_duplicate(printable_item->style);
width = text_width(text[t]->lines[tl]->items[0]);
if (width == EMPTY) {
- fprintf(stderr, "text_width failed.\n");
+ DEBUG_MSG("text_width failed.");
return NULL;
}
text[t]->lines[tl]->items[0]->x = MARGIN_HORIZONTAL + (LINE_WIDTH - width) / 2;
@@ -823,7 +823,7 @@ static struct Text **text_create(struct ChoSong **songs, struct Config *config)
for (int i = 0; text_lines[i]; i++) {
width = text_width(text_lines[i]->items[0]);
if (width == EMPTY) {
- fprintf(stderr, "text_width failed.\n");
+ DEBUG_MSG("text_width failed.");
return NULL;
}
text_lines[i]->items[0]->x = MARGIN_HORIZONTAL + (LINE_WIDTH - width) / 2;
@@ -845,7 +845,7 @@ static struct Text **text_create(struct ChoSong **songs, struct Config *config)
if (songs[so]->sections[se]->label) {
fits = text_fits(songs[so]->sections[se]->label->name, songs[so]->sections[se]->label->style);
if (fits == B_ERROR) {
- fprintf(stderr, "text_fits failed.\n");
+ DEBUG_MSG("text_fits failed.");
return NULL;
}
if (fits) {
@@ -871,7 +871,7 @@ static struct Text **text_create(struct ChoSong **songs, struct Config *config)
for (int i = 0; text_lines[i]; i++) {
width = text_width(text_lines[i]->items[0]);
if (width == EMPTY) {
- fprintf(stderr, "text_width failed.\n");
+ DEBUG_MSG("text_width failed.");
return NULL;
}
// text_lines[i]->items[0]->x = MARGIN_HORIZONTAL + (LINE_WIDTH - width) / 2;
@@ -904,7 +904,7 @@ static struct Text **text_create(struct ChoSong **songs, struct Config *config)
text[t]->lines[tl]->items[tli] = malloc(sizeof(struct TextLineItem));
double width_until = line_width_until_chord(lines[li], text_above[ch], NULL);
if (width_until == EMPTY) {
- fprintf(stderr, "line_width_until_chord failed.\n");
+ DEBUG_MSG("line_width_until_chord failed.");
return NULL;
}
if (tli == 0) {
@@ -925,7 +925,7 @@ static struct Text **text_create(struct ChoSong **songs, struct Config *config)
tmp.text = text_above[b]->u.annot->text;
width = text_width(&tmp);
if (width == EMPTY) {
- fprintf(stderr, "text_width failed.\n");
+ DEBUG_MSG("text_width failed.");
return NULL;
}
text[t]->lines[tl]->items[tli]->x += width;
@@ -948,7 +948,7 @@ static struct Text **text_create(struct ChoSong **songs, struct Config *config)
}
enough_space = out_pdf_text_above_is_enough_space(songs[so]->sections[se]->lines[li], text_above[ch], text_above[ch+1], &space);
if (enough_space == B_ERROR) {
- fprintf(stderr, "out_pdf_text_above_is_enough_space failed.\n");
+ DEBUG_MSG("out_pdf_text_above_is_enough_space failed.");
return NULL;
}
if (!enough_space) {
@@ -968,7 +968,7 @@ static struct Text **text_create(struct ChoSong **songs, struct Config *config)
text[t]->lines[tl]->items[tli] = NULL;
fits = text_line_fits(text[t]->lines[tl]);
if (fits == B_ERROR) {
- fprintf(stderr, "text_line_fits failed.\n");
+ DEBUG_MSG("text_line_fits failed.");
return NULL;
}
if (!fits) {
@@ -1009,7 +1009,7 @@ static struct Text **text_create(struct ChoSong **songs, struct Config *config)
} else {
last_text_line_item_width = text_width(text[t]->lines[tl]->items[tli-1]);
if (last_text_line_item_width == EMPTY) {
- fprintf(stderr, "text_width failed.\n");
+ DEBUG_MSG("text_width failed.");
return NULL;
}
text[t]->lines[tl]->items[tli]->x = text[t]->lines[tl]->items[tli-1]->x + last_text_line_item_width;
@@ -1030,7 +1030,7 @@ static struct Text **text_create(struct ChoSong **songs, struct Config *config)
text[t]->lines[tl]->items[tli]->style = cho_style_duplicate(lines[li]->lyrics[ly]->style);
last_text_line_item_width = text_width(text[t]->lines[tl]->items[tli-1]);
if (last_text_line_item_width == EMPTY) {
- fprintf(stderr, "text_width failed.\n");
+ DEBUG_MSG("text_width failed.");
return NULL;
}
text[t]->lines[tl]->items[tli]->x = text[t]->lines[tl]->items[tli-1]->x + last_text_line_item_width + sp->amount;
@@ -1048,7 +1048,7 @@ static struct Text **text_create(struct ChoSong **songs, struct Config *config)
text[t]->lines[tl]->items[tli] = NULL;
fits = text_line_fits(text[t]->lines[tl]);
if (fits == B_ERROR) {
- fprintf(stderr, "text_line_fits failed.\n");
+ DEBUG_MSG("text_line_fits failed.");
return NULL;
}
if (!fits) {
@@ -1119,24 +1119,24 @@ static pdfio_dict_t *annot_create(pdfio_file_t *pdf, const char *uri, pdfio_rect
{
pdfio_dict_t *annot = pdfioDictCreate(pdf);
if (!pdfioDictSetName(annot, "Subtype", "Link")) {
- fprintf(stderr, "pdfioDictSetName failed.\n");
+ DEBUG_MSG("pdfioDictSetName failed.");
return NULL;
}
if (!pdfioDictSetRect(annot, "Rect", rect)) {
- fprintf(stderr, "pdfioDictSetRect failed.\n");
+ DEBUG_MSG("pdfioDictSetRect failed.");
return NULL;
}
pdfio_dict_t *action = pdfioDictCreate(pdf);
if (!pdfioDictSetName(action, "S", "URI")) {
- fprintf(stderr, "pdfioDictSetName failed.\n");
+ DEBUG_MSG("pdfioDictSetName failed.");
return NULL;
}
if (!pdfioDictSetString(action, "URI", uri)) {
- fprintf(stderr, "pdfioDictSetString failed.\n");
+ DEBUG_MSG("pdfioDictSetString failed.");
return NULL;
}
if (!pdfioDictSetDict(annot, "A", action)) {
- fprintf(stderr, "pdfioDictSetDict failed.\n");
+ DEBUG_MSG("pdfioDictSetDict failed.");
return NULL;
}
return annot;
@@ -1152,7 +1152,7 @@ static bool annots_create(pdfio_file_t *pdf, pdfio_array_t *annots, struct Text
int t, tl, tli;
pdfio_array_t *page_annots = pdfioArrayCreate(pdf);
if (!page_annots) {
- fprintf(stderr, "pdfioArrayCreate failed.\n");
+ DEBUG_MSG("pdfioArrayCreate failed.");
return false;
}
for (t = 0; text[t]; t++) {
@@ -1168,11 +1168,11 @@ static bool annots_create(pdfio_file_t *pdf, pdfio_array_t *annots, struct Text
rect.y2 = y + item->style->font->size * 0.8;
annot = annot_create(pdf, item->style->href, &rect);
if (!annot) {
- fprintf(stderr, "annot_create failed.\n");
+ DEBUG_MSG("annot_create failed.");
return false;
}
if (!pdfioArrayAppendDict(page_annots, annot)) {
- fprintf(stderr, "pdfioArrayAppendDict failed.\n");
+ DEBUG_MSG("pdfioArrayAppendDict failed.");
return false;
}
}
@@ -1180,12 +1180,12 @@ static bool annots_create(pdfio_file_t *pdf, pdfio_array_t *annots, struct Text
}
if (text[t]->lines[tl]->btype == BT_PAGE) {
if (!pdfioArrayAppendArray(annots, page_annots)) {
- fprintf(stderr, "pdfioArrayAppendArray failed.\n");
+ DEBUG_MSG("pdfioArrayAppendArray failed.");
return false;
}
page_annots = pdfioArrayCreate(pdf);
if (!page_annots) {
- fprintf(stderr, "pdfioArrayCreate failed.\n");
+ DEBUG_MSG("pdfioArrayCreate failed.");
return false;
}
y = MEDIABOX_HEIGHT - MARGIN_TOP;
@@ -1195,7 +1195,7 @@ static bool annots_create(pdfio_file_t *pdf, pdfio_array_t *annots, struct Text
}
}
if (!pdfioArrayAppendArray(annots, page_annots)) {
- fprintf(stderr, "pdfioArrayAppendArray failed.\n");
+ DEBUG_MSG("pdfioArrayAppendArray failed.");
return false;
}
return true;
@@ -1225,27 +1225,27 @@ static pdfio_stream_t *out_pdf_page_create(pdfio_file_t *pdf, pdfio_array_t *ann
pdfio_array_t *color_array = pdfioArrayCreateColorFromStandard(pdf, 3, PDFIO_CS_ADOBE);
page_dict = pdfioDictCreate(pdf);
if (!pdfioPageDictAddColorSpace(page_dict, "rgbcolorspace", color_array)) {
- fprintf(stderr, "pdfioPageDictAddColorSpace failed.\n");
+ DEBUG_MSG("pdfioPageDictAddColorSpace failed.");
return false;
}
for (f = 0; g_fonts[f]; f++) {
if (!pdfioPageDictAddFont(page_dict, g_fonts[f]->name, g_fonts[f]->font)) {
- fprintf(stderr, "pdfioPageDictAddFont failed.\n");
+ DEBUG_MSG("pdfioPageDictAddFont failed.");
return false;
}
}
page_annots = pdfioArrayGetArray(annots, page_no);
if (!pdfioDictSetArray(page_dict, "Annots", page_annots)) {
- fprintf(stderr, "pdfioDictSetArray failed.\n");
+ DEBUG_MSG("pdfioDictSetArray failed.");
return false;
}
page_stream = pdfioFileCreatePage(pdf, page_dict);
if (!pdfioContentSetFillColorSpace(page_stream, "rgbcolorspace")) {
- fprintf(stderr, "pdfioContentSetFillColorSpace failed.\n");
+ DEBUG_MSG("pdfioContentSetFillColorSpace failed.");
return false;
}
if (!pdfioContentSetStrokeColorSpace(page_stream, "rgbcolorspace")) {
- fprintf(stderr, "pdfioContentSetStrokeColorSpace failed.\n");
+ DEBUG_MSG("pdfioContentSetStrokeColorSpace failed.");
return false;
}
return page_stream;
@@ -1256,14 +1256,14 @@ char *out_pdf_new(const char *cho_filepath, const char *output_folder_or_file, s
memset(&g_current_font_name, 0, sizeof(g_current_font_name));
char *pdf_filename = out_pdf_filename_create(songs, cho_filepath, output_folder_or_file);
if (!pdf_filename) {
- fprintf(stderr, "out_pdf_filename_create failed.\n");
+ DEBUG_MSG("out_pdf_filename_create failed.");
return NULL;
}
pdfio_rect_t media_box_a4 = { 0.0, 0.0, MEDIABOX_WIDTH, MEDIABOX_HEIGHT };
pdfio_rect_t crop_box = { 36.0, 36.0, MEDIABOX_WIDTH, MEDIABOX_HEIGHT };
pdfio_file_t *pdf = pdfioFileCreate(pdf_filename, "2.0", &media_box_a4, &crop_box, NULL, NULL);
if (!out_pdf_set_title(pdf, songs)) {
- fprintf(stderr, "out_pdf_set_title failed.\n");
+ DEBUG_MSG("out_pdf_set_title failed.");
return NULL;
}
struct Font **needed_fonts = out_pdf_font_get_all(songs, config);
@@ -1297,12 +1297,12 @@ char *out_pdf_new(const char *cho_filepath, const char *output_folder_or_file, s
cho_fonts_free(needed_fonts);
struct Text **text = text_create(songs, config);
if (!text) {
- fprintf(stderr, "text_create failed.\n");
+ DEBUG_MSG("text_create failed.");
return NULL;
}
pdfio_array_t *annots = pdfioArrayCreate(pdf);
if (!annots_create(pdf, annots, text)) {
- fprintf(stderr, "annotations_create failed.\n");
+ DEBUG_MSG("annotations_create failed.");
return NULL;
}
pdfio_stream_t *page_stream;
@@ -1319,7 +1319,7 @@ char *out_pdf_new(const char *cho_filepath, const char *output_folder_or_file, s
}
if (text[t]->lines[tl]->btype == BT_PAGE) {
if (!pdfioStreamClose(page_stream)) {
- fprintf(stderr, "pdfioStreamClose failed.\n");
+ DEBUG_MSG("pdfioStreamClose failed.");
return NULL;
}
p++;
@@ -1331,11 +1331,11 @@ char *out_pdf_new(const char *cho_filepath, const char *output_folder_or_file, s
}
}
if (!pdfioStreamClose(page_stream)) {
- fprintf(stderr, "pdfioStreamClose failed.\n");
+ DEBUG_MSG("pdfioStreamClose failed.");
return NULL;
}
if (!pdfioFileClose(pdf)) {
- fprintf(stderr, "pdfioFileClose failed.\n");
+ DEBUG_MSG("pdfioFileClose failed.");
return NULL;
}
text_free(text);
diff --git a/util.h b/util.h
@@ -1,3 +1,9 @@
+#ifdef DEBUG
+#define DEBUG_MSG(msg) fprintf(stderr, msg"\n")
+#else
+#define DEBUG_MSG(msg)
+#endif
+
enum FileType {
F_ERROR,
F_FOLDER,