commit 2de25cb64b5b5bc338e8f9de6f80e4892b5c4a06
parent 3eaa9537cfaea42ccd343ed2ad4247ddff4b85c6
Author: nibo <nibo@relim.de>
Date: Fri, 1 Aug 2025 21:18:23 +0200
Improve logging
Diffstat:
9 files changed, 275 insertions(+), 391 deletions(-)
diff --git a/Makefile b/Makefile
@@ -26,7 +26,7 @@ lorid: ${OBJS}
standalone:
$(CC) ${CFLAGS} ${VARS} -O2 ${SRC} -o lorid -Wl,-Bstatic -lpdfio -lgrapheme -ltoml -lz -Wl,-Bdynamic -lfontconfig -lpng16 -lm
debug:
- $(CC) ${CFLAGS} ${VARS} -DDEBUG -g ${SRC} -o lorid ${LDFLAGS}
+ $(CC) ${CFLAGS} ${VARS} -DENABLE_DEBUG -g ${SRC} -o lorid ${LDFLAGS}
clean:
rm *.o
rm lorid
diff --git a/src/chord_diagram.c b/src/chord_diagram.c
@@ -506,7 +506,7 @@ string_diagram_draw(
double name_width, centered_x;
font_obj = out_pdf_fnt_obj_get_by_name(ctx, "chord-diagram-regular-font");
if (!font_obj) {
- LOG_DEBUG("out_pdf_fnt_obj_get_by_name failed.");
+ DEBUG("out_pdf_fnt_obj_get_by_name failed.");
return false;
}
name_width = pdfioContentTextMeasure(font_obj, diagram->name, field_width*2.0);
@@ -683,7 +683,7 @@ chord_diagrams_free(struct ChordDiagram **diagrams)
free(diagrams);
}
-#ifdef DEBUG
+#ifdef ENABLE_DEBUG
void
debug_chord_diagram_print(struct ChordDiagram *diagram)
{
@@ -729,7 +729,7 @@ debug_chord_diagram_print(struct ChordDiagram *diagram)
}
printf("---- CHORD DIAGRAM END ------\n");
}
-#endif /* DEBUG */
+#endif /* ENABLE_DEBUG */
struct ChordDiagram **
chord_diagrams_create(
@@ -766,7 +766,7 @@ chord_diagrams_create(
diagrams = erealloc(diagrams, (d+1) * sizeof(struct ChordDiagram *));
diagrams[d] = chord_diagram_copy_all_but_name(*cd);
if (!diagrams[d]) {
- LOG_DEBUG("chord_diagram_copy_all_but_name failed.");
+ DEBUG("chord_diagram_copy_all_but_name failed.");
goto ERR;
}
diagrams[d]->u.sd->name = strdup(chord_name);
@@ -833,17 +833,19 @@ chord_diagram_draw(
switch (diagram->type) {
case CHORD_DIAGRAM_CONTENT_STRING:
if (!string_diagram_draw(ctx, stream, diagram->u.sd, x, y, width)) {
- LOG_DEBUG("draw_string_chord_diagram failed.");
+ DEBUG("draw_string_chord_diagram failed.");
return false;
}
break;
- case CHORD_DIAGRAM_CONTENT_KEYBOARD:
+ /* case CHORD_DIAGRAM_CONTENT_KEYBOARD:
util_log(NULL, 0, LOG_TODO, "draw_keyboard_chord_diagram()");
break;
case CHORD_DIAGRAM_CONTENT_CHORD_MAP:
util_log(NULL, 0, LOG_TODO, "well");
- break;
+ break; */
default:
+ util_log(NULL, 0, LOG_ERR, "These 'enum ChordDiagramContent' values are not yet implemented.");
+ return false;
}
return true;
}
diff --git a/src/chordpro.c b/src/chordpro.c
@@ -149,7 +149,7 @@ static const char *chord_extensions_minor[] = {
static bool g_show_info_logs = false;
-#ifdef DEBUG
+#ifdef ENABLE_DEBUG
static const char *alignment_enums[] = {
"ALIGNMENT_LEFT",
@@ -251,7 +251,7 @@ cho_debug_chord_print(struct ChoChord *chord)
printf("---- END CHORD ------\n");
}
-#endif /* DEBUG */
+#endif /* ENABLE_DEBUG */
void
cho_log_enable_info_logs(void)
@@ -259,96 +259,14 @@ cho_log_enable_info_logs(void)
g_show_info_logs = true;
}
-#if COLOR == 1
static void
cho_log(struct ChoContext *ctx, enum LogLevel level, const char *msg, ...)
{
- if (level == LOG_INFO && !g_show_info_logs) {
- return;
- }
- va_list va;
- va_start(va, msg);
- const char *log_level;
- const char *color;
- switch (level) {
- case LOG_INFO:
- log_level = "INFO";
- color = COLOR_BOLD_WHITE;
- break;
- case LOG_WARN:
- log_level = "WARN";
- color = COLOR_BOLD_ORANGE;
- break;
- case LOG_ERR:
- log_level = " ERR";
- color = COLOR_BOLD_RED;
- break;
- case LOG_TODO:
- log_level = "TODO";
- color = COLOR_BOLD_BLUE;
- break;
- }
- if (isatty(2)) {
- if (ctx->chordpro_filepath) {
- fprintf(stderr, COLOR_BOLD_WHITE"%s:%ld:"COLOR_RESET" %s%s"COLOR_RESET": ",
- ctx->chordpro_filepath, ctx->line_no, color, log_level);
- vfprintf(stderr, msg, va);
- fprintf(stderr, "\n");
- } else {
- fprintf(stderr, "line "COLOR_BOLD_WHITE"%ld:"COLOR_RESET" %s%s"COLOR_RESET": ",
- ctx->line_no, color, log_level);
- vfprintf(stderr, msg, va);
- fprintf(stderr, "\n");
- }
- } else {
- if (ctx->chordpro_filepath) {
- fprintf(stderr, "%s:%ld: %s: ", ctx->chordpro_filepath, ctx->line_no,
- log_level);
- vfprintf(stderr, msg, va);
- fprintf(stderr, "\n");
- } else {
- fprintf(stderr, "line %ld: %s: ", ctx->line_no, log_level);
- vfprintf(stderr, msg, va);
- fprintf(stderr, "\n");
- }
- }
-}
-#else
-static void
-cho_log(struct ChoContext *ctx, enum LogLevel level, const char *msg, ...)
-{
- if (level == LOG_INFO && !g_show_info_logs) {
- return;
- }
va_list va;
+
va_start(va, msg);
- const char *log_level;
- switch (level) {
- case LOG_INFO:
- log_level = "INFO";
- break;
- case LOG_WARN:
- log_level = "WARN";
- break;
- case LOG_ERR:
- log_level = " ERR";
- break;
- case LOG_TODO:
- log_level = "TODO";
- break;
- }
- if (ctx->chordpro_filepath) {
- fprintf(stderr, "%s:%ld: %s: ", ctx->chordpro_filepath, ctx->line_no,
- log_level);
- vfprintf(stderr, msg, va);
- fprintf(stderr, "\n");
- } else {
- fprintf(stderr, "line %ld: %s: ", ctx->line_no, log_level);
- vfprintf(stderr, msg, va);
- fprintf(stderr, "\n");
- }
+ util_vlog(ctx->chordpro_filepath, ctx->line_no, level, msg, va);
}
-#endif /* COLOR */
static inline bool
is_whitespace(char c)
@@ -488,7 +406,7 @@ cho_color_parse(const char *str)
if (str[0] == '#') {
color = cho_rgbcolor_parse(str);
if (!color) {
- LOG_DEBUG("cho_rgbcolor_parse failed.");
+ DEBUG("cho_rgbcolor_parse failed.");
return NULL;
}
} else {
@@ -674,7 +592,7 @@ cho_linestyle_to_config_string(enum LineStyle linestyle)
return line_styles[linestyle];
}
-#ifdef DEBUG
+#ifdef ENABLE_DEBUG
static void
cho_debug_the_default_style_properties(void)
@@ -731,7 +649,7 @@ cho_debug_style_print(struct ChoStyle *style)
printf("---- END STYLE ------\n\n");
}
-#endif /* DEBUG */
+#endif /* ENABLE_DEBUG */
static bool
cho_style_property_apply_default(
@@ -915,7 +833,7 @@ cho_style_new_default(struct ChoContext *ctx)
{
struct ChoStyle *style = cho_style_new_from_config(ctx, ctx->current_ttype);
if (!style) {
- LOG_DEBUG("cho_style_new_from_config failed.");
+ DEBUG("cho_style_new_from_config failed.");
return NULL;
}
cho_style_apply_default(ctx->current_ttype, style);
@@ -1182,7 +1100,7 @@ cho_style_parse(
} else if (!strcmp((*a)->name, "foreground")) {
rgb_color = cho_color_parse((*a)->value);
if (!rgb_color) {
- LOG_DEBUG("cho_color_parse failed.");
+ DEBUG("cho_color_parse failed.");
cho_log(ctx, LOG_ERR, "Attribute 'foreground' of markup tag '%s' has an invalid value '%s'.", tag_name, (*a)->value);
goto ERR;
} else {
@@ -1193,7 +1111,7 @@ cho_style_parse(
} else if (!strcmp((*a)->name, "background")) {
rgb_color = cho_color_parse((*a)->value);
if (!rgb_color) {
- LOG_DEBUG("cho_color_parse failed.");
+ DEBUG("cho_color_parse failed.");
cho_log(ctx, LOG_ERR, "Attribute 'background' of markup tag '%s' has an invalid value '%s'.", tag_name, (*a)->value);
goto ERR;
} else {
@@ -1218,7 +1136,7 @@ cho_style_parse(
} else if (!strcmp((*a)->name, "underline_colour")) {
rgb_color = cho_color_parse((*a)->value);
if (!rgb_color) {
- LOG_DEBUG("cho_color_parse failed.");
+ DEBUG("cho_color_parse failed.");
cho_log(ctx, LOG_ERR, "Attribute 'underline_colour' of markup tag '%s' has an invalid value '%s'.", tag_name, (*a)->value);
goto ERR;
} else {
@@ -1243,7 +1161,7 @@ cho_style_parse(
} else if (!strcmp((*a)->name, "overline_colour")) {
rgb_color = cho_color_parse((*a)->value);
if (!rgb_color) {
- LOG_DEBUG("cho_color_parse failed.");
+ DEBUG("cho_color_parse failed.");
cho_log(ctx, LOG_ERR, "Attribute 'overline_colour' of markup tag '%s' has an invalid value '%s'.", tag_name, (*a)->value);
goto ERR;
} else {
@@ -1323,7 +1241,7 @@ cho_style_parse(
} else if (!strcmp((*a)->name, "strikethrough_colour")) {
rgb_color = cho_color_parse((*a)->value);
if (!rgb_color) {
- LOG_DEBUG("cho_color_parse failed.");
+ DEBUG("cho_color_parse failed.");
cho_log(ctx, LOG_ERR, "Attribute 'strikethrough_colour' of markup tag '%s' has an invalid value '%s'.", tag_name, (*a)->value);
goto ERR;
} else {
@@ -1657,13 +1575,13 @@ cho_metadata_load_default(struct ChoContext *ctx)
logged_in_user = getenv("USER");
if (!logged_in_user) {
- LOG_DEBUG("getenv(USER) failed.");
+ DEBUG("getenv(USER) failed.");
return NULL;
}
t = time(NULL);
tt = localtime(&t);
if (strftime((char *)&time_str, 64, "%a, %d. %b %H:%M", tt) == 0) {
- LOG_DEBUG("strftime failed.");
+ DEBUG("strftime failed.");
return NULL;
}
ins_info = config_instrument_get(ctx->config->output->diagram->instrument);
@@ -2075,7 +1993,7 @@ cho_metadata_substitution_parse(
if (name_index[0] != 0) {
index = atoi(name_index);
if (index == 0) {
- LOG_DEBUG("atoi failed.");
+ DEBUG("atoi failed.");
goto ERR;
}
}
@@ -2389,7 +2307,7 @@ cho_chord_root_parse(struct ChoContext *ctx, const char *str, struct ChoChord *c
if (sharp && str_starts_with(str, sharp)) {
transposed_root = transposition_calc_chord_root(ctx, i, NOTE_TYPE_SHARP);
if (!transposed_root) {
- LOG_DEBUG("transposition_calc_chord_root failed.");
+ DEBUG("transposition_calc_chord_root failed.");
return 0;
}
chord->root = transposed_root;
@@ -2399,7 +2317,7 @@ cho_chord_root_parse(struct ChoContext *ctx, const char *str, struct ChoChord *c
if (flat && str_starts_with(str, flat)) {
transposed_root = transposition_calc_chord_root(ctx, i, NOTE_TYPE_FLAT);
if (!transposed_root) {
- LOG_DEBUG("transposition_calc_chord_root failed.");
+ DEBUG("transposition_calc_chord_root failed.");
return 0;
}
chord->root = transposed_root;
@@ -2409,7 +2327,7 @@ cho_chord_root_parse(struct ChoContext *ctx, const char *str, struct ChoChord *c
if (str_starts_with(str, note)) {
transposed_root = transposition_calc_chord_root(ctx, i, NOTE_TYPE_NOTE);
if (!transposed_root) {
- LOG_DEBUG("transposition_calc_chord_root failed.");
+ DEBUG("transposition_calc_chord_root failed.");
return 0;
}
chord->root = transposed_root;
@@ -2752,7 +2670,7 @@ cho_image_find_asset(struct ChoContext *ctx, const char *id)
return NULL;
}
-#ifdef DEBUG
+#ifdef ENABLE_DEBUG
void
cho_debug_image_print(struct ChoImage *image)
{
@@ -2834,7 +2752,7 @@ cho_debug_image_print(struct ChoImage *image)
printf("bbox: %d\n", image->bbox);
printf("---- END IMAGE ------\n");
}
-#endif /* DEBUG */
+#endif /* ENABLE_DEBUG */
static bool
cho_image_option_parse(struct ChoContext *ctx, struct ChoImage *image, const char *name, const char *value)
@@ -2848,7 +2766,7 @@ cho_image_option_parse(struct ChoContext *ctx, struct ChoImage *image, const cha
if (!strcmp(name, "src")) {
image->src = filepath_resolve_tilde(value);
if (!image->src) {
- LOG_DEBUG("filepath_resolve_tilde failed.");
+ DEBUG("filepath_resolve_tilde failed.");
goto ERR;
}
} else
@@ -2931,7 +2849,7 @@ cho_image_option_parse(struct ChoContext *ctx, struct ChoImage *image, const cha
if (!strcmp(name, "border")) {
image->border = strtod(value, &endptr);
if (value == endptr || errno == ERANGE) {
- LOG_DEBUG("strtod failed.");
+ DEBUG("strtod failed.");
goto ERR;
}
} else
@@ -3070,7 +2988,7 @@ cho_image_directive_parse(struct ChoContext *ctx, const char *str)
) {
value[v] = 0;
if (!cho_image_option_parse(ctx, image, name, value)) {
- LOG_DEBUG("cho_image_option_parse failed.");
+ DEBUG("cho_image_option_parse failed.");
goto ERR;
}
option_count++;
@@ -3090,7 +3008,7 @@ cho_image_directive_parse(struct ChoContext *ctx, const char *str)
if (avs == ATTRIBUTE_VALUE_SYNTAX_UNQUOTED) {
value[v] = 0;
if (!cho_image_option_parse(ctx, image, name, value)) {
- LOG_DEBUG("cho_image_option_parse failed.");
+ DEBUG("cho_image_option_parse failed.");
goto ERR;
}
option_count++;
@@ -3129,7 +3047,7 @@ cho_image_tag_parse(struct ChoContext *ctx, struct Attr **attrs)
if (!strcmp(attrs[a]->name, "src")) {
image->src = filepath_resolve_tilde(attrs[a]->value);
if (!image->src) {
- LOG_DEBUG("filepath_resolve_tilde failed.");
+ DEBUG("filepath_resolve_tilde failed.");
goto ERR;
}
} else
@@ -3433,7 +3351,7 @@ cho_chord_diagram_parse(
diagram->u.cm->name = strdup(name);
break;
default:
- LOG_DEBUG("'future_content' cannot be empty at this point.\n");
+ DEBUG("'future_content' cannot be empty at this point.\n");
goto ERR;
}
}
@@ -3456,7 +3374,7 @@ cho_chord_diagram_parse(
i = 0;
l = str_to_number(base_fret);
if (l == -1) {
- LOG_DEBUG("str_to_number failed.");
+ DEBUG("str_to_number failed.");
cho_log(ctx, LOG_ERR, "Invalid base-fret value '%s' in chord diagram.", base_fret);
goto ERR;
}
@@ -3506,7 +3424,7 @@ cho_chord_diagram_parse(
if (number == -2) {
number = char_to_positive_int(*c);
if (number == -1) {
- LOG_DEBUG("char_to_positive_int failed.");
+ DEBUG("char_to_positive_int failed.");
cho_log(ctx, LOG_ERR, "Invalid frets value '%c' in chord diagram.", *c);
goto ERR;
}
@@ -3553,7 +3471,7 @@ cho_chord_diagram_parse(
i = 0;
l = str_to_number(key);
if (l == -1) {
- LOG_DEBUG("str_to_number failed.");
+ DEBUG("str_to_number failed.");
cho_log(ctx, LOG_ERR, "Invalid number in keys in chord diagram.");
goto ERR;
}
@@ -3594,7 +3512,7 @@ cho_chord_diagram_parse(
} else {
diagram->color = cho_color_parse(diagram_value);
if (!diagram->color) {
- LOG_DEBUG("cho_color_parse failed.");
+ DEBUG("cho_color_parse failed.");
goto ERR;
}
}
@@ -3651,7 +3569,7 @@ cho_chord_diagram_parse(
i = 0;
l = str_to_number(base_fret);
if (l == -1) {
- LOG_DEBUG("str_to_number failed.");
+ DEBUG("str_to_number failed.");
cho_log(ctx, LOG_ERR, "Invalid base-fret value '%s' in chord diagram.", base_fret);
goto ERR;
}
@@ -3667,7 +3585,7 @@ cho_chord_diagram_parse(
if (strlen(key) > 0) {
l = str_to_number(key);
if (l == -1) {
- LOG_DEBUG("str_to_number failed.");
+ DEBUG("str_to_number failed.");
cho_log(ctx, LOG_ERR, "Invalid number in keys in chord diagram.");
goto ERR;
}
@@ -3691,7 +3609,7 @@ cho_chord_diagram_parse(
free(diagram->color);
diagram->color = cho_color_parse(diagram_value);
if (!diagram->color) {
- LOG_DEBUG("cho_color_parse failed.");
+ DEBUG("cho_color_parse failed.");
goto ERR;
}
}
@@ -3966,7 +3884,7 @@ cho_song_new(struct ChoContext *ctx)
struct ChoSong *song = emalloc(sizeof(struct ChoSong));
song->metadata = cho_metadata_load_default(ctx);
if (!song->metadata) {
- LOG_DEBUG("cho_metadata_load_default failed.");
+ DEBUG("cho_metadata_load_default failed.");
free(song);
return NULL;
}
@@ -4587,7 +4505,7 @@ cho_grid_shape_parse_and_set(struct ChoContext *ctx, const char *str)
tmp[t] = 0;
i = atoi(tmp);
if (i == 0) {
- LOG_DEBUG("atoi failed.");
+ DEBUG("atoi failed.");
return false;
}
ctx->grid.left = i;
@@ -4600,7 +4518,7 @@ cho_grid_shape_parse_and_set(struct ChoContext *ctx, const char *str)
tmp[t] = 0;
i = atoi(tmp);
if (i == 0) {
- LOG_DEBUG("atoi failed.");
+ DEBUG("atoi failed.");
return false;
}
measures = i;
@@ -4621,7 +4539,7 @@ cho_grid_shape_parse_and_set(struct ChoContext *ctx, const char *str)
tmp[t] = 0;
i = atoi(tmp);
if (i == 0) {
- LOG_DEBUG("atoi failed.");
+ DEBUG("atoi failed.");
return false;
}
ctx->grid.cells = i;
@@ -4634,7 +4552,7 @@ cho_grid_shape_parse_and_set(struct ChoContext *ctx, const char *str)
tmp[t] = 0;
i = atoi(tmp);
if (i == 0) {
- LOG_DEBUG("atoi failed.");
+ DEBUG("atoi failed.");
return false;
}
measures = i;
@@ -4655,7 +4573,7 @@ cho_grid_shape_parse_and_set(struct ChoContext *ctx, const char *str)
tmp[t] = 0;
i = atoi(tmp);
if (i == 0) {
- LOG_DEBUG("atoi failed.");
+ DEBUG("atoi failed.");
return false;
}
beats = i;
@@ -4673,7 +4591,7 @@ cho_grid_shape_parse_and_set(struct ChoContext *ctx, const char *str)
tmp[t] = 0;
i = atoi(tmp);
if (i == 0) {
- LOG_DEBUG("atoi failed.");
+ DEBUG("atoi failed.");
return false;
}
switch (state) {
@@ -4835,7 +4753,7 @@ cho_context_init(
ctx->songs = emalloc(sizeof(struct ChoSong *));
ctx->songs[ctx->so] = cho_song_new(ctx);
if (!ctx->songs[ctx->so]) {
- LOG_DEBUG("cho_song_new failed.");
+ DEBUG("cho_song_new failed.");
free(ctx->songs);
return false;
}
@@ -4915,7 +4833,7 @@ cho_songs_parse(const char *str, const char *chordpro_filepath, struct Config *c
int transpose;
if (!cho_context_init(&ctx, config, chordpro_filepath)) {
- LOG_DEBUG("cho_context_init failed.");
+ DEBUG("cho_context_init failed.");
return NULL;
}
@@ -4977,8 +4895,8 @@ cho_songs_parse(const char *str, const char *chordpro_filepath, struct Config *c
break;
}
if (ctx.ta > -1 && !ctx.tags[ctx.ta]->is_closed && strcmp(ctx.tags[ctx.ta]->name, "img")) {
- // TODO: This seems to be unreachable
cho_log(&ctx, LOG_ERR, "Tag has to be closed on same line.");
+ DEBUG("Tag has to be closed on same line.");
goto ERR;
}
if ((*lines)[ctx.li]->items[ctx.lii]->is_text) {
@@ -5225,7 +5143,7 @@ cho_songs_parse(const char *str, const char *chordpro_filepath, struct Config *c
ctx.songs[ctx.so]->diagrams = erealloc(ctx.songs[ctx.so]->diagrams, (ctx.dia+1) * sizeof(struct ChordDiagram *));
ctx.songs[ctx.so]->diagrams[ctx.dia] = NULL;
if (!cho_style_reset_default()) {
- LOG_DEBUG("cho_style_reset_default failed.");
+ DEBUG("cho_style_reset_default failed.");
goto ERR;
}
for (int e = 0; e<ctx.ia; e++) {
@@ -5238,7 +5156,7 @@ cho_songs_parse(const char *str, const char *chordpro_filepath, struct Config *c
ctx.songs = erealloc(ctx.songs, (ctx.so+1) * sizeof(struct ChoSong *));
ctx.songs[ctx.so] = cho_song_new(&ctx);
if (!ctx.songs[ctx.so]) {
- LOG_DEBUG("cho_song_new failed.");
+ DEBUG("cho_song_new failed.");
goto ERR;
}
free(ctx.transpose_history);
@@ -5276,7 +5194,7 @@ cho_songs_parse(const char *str, const char *chordpro_filepath, struct Config *c
break;
}
if (!cho_style_change_default(sprop)) {
- LOG_DEBUG("cho_style_change_default failed.");
+ DEBUG("cho_style_change_default failed.");
goto ERR;
}
break;
@@ -5371,7 +5289,7 @@ cho_songs_parse(const char *str, const char *chordpro_filepath, struct Config *c
if (strchr(stripped_directive_value, '=')) {
directive_attrs = cho_attrs_parse(&ctx, stripped_directive_value, directive_name);
if (!directive_attrs) {
- LOG_DEBUG("cho_attrs_parse failed.");
+ DEBUG("cho_attrs_parse failed.");
goto ERR;
}
label = cho_attrs_get(directive_attrs, "label");
@@ -5379,7 +5297,7 @@ cho_songs_parse(const char *str, const char *chordpro_filepath, struct Config *c
shape = cho_attrs_get(directive_attrs, "shape");
if (shape) {
if (!cho_grid_shape_parse_and_set(&ctx, shape)) {
- LOG_DEBUG("cho_grid_parse_and_set_shape failed.");
+ DEBUG("cho_grid_parse_and_set_shape failed.");
goto ERR;
}
}
@@ -5392,7 +5310,7 @@ cho_songs_parse(const char *str, const char *chordpro_filepath, struct Config *c
label = &stripped_directive_value[index+1];
}
if (!cho_grid_shape_parse_and_set(&ctx, stripped_directive_value)) {
- LOG_DEBUG("cho_grid_parse_and_set_shape failed.");
+ DEBUG("cho_grid_parse_and_set_shape failed.");
goto ERR;
}
} else {
@@ -5557,7 +5475,7 @@ cho_songs_parse(const char *str, const char *chordpro_filepath, struct Config *c
if (!strcmp(directive_name, "meta")) {
metadata = cho_metadata_split(&ctx, directive_value);
if (!metadata) {
- LOG_DEBUG("cho_metadata_split failed.");
+ DEBUG("cho_metadata_split failed.");
goto ERR;
}
ctx.songs[ctx.so]->metadata = erealloc(ctx.songs[ctx.so]->metadata, (ctx.m+1) * sizeof(struct ChoMetadata *));
@@ -5607,7 +5525,7 @@ cho_songs_parse(const char *str, const char *chordpro_filepath, struct Config *c
if (strchr(directive_value, '=')) {
image = cho_image_directive_parse(&ctx, directive_value);
if (!image) {
- LOG_DEBUG("cho_image_directive_parse failed.");
+ DEBUG("cho_image_directive_parse failed.");
goto ERR;
}
} else {
@@ -5662,7 +5580,7 @@ cho_songs_parse(const char *str, const char *chordpro_filepath, struct Config *c
break;
}
if (!cho_style_change_default(sprop)) {
- LOG_DEBUG("cho_style_change_default failed.");
+ DEBUG("cho_style_change_default failed.");
goto ERR;
}
if (sprop.type == STYLE_PROPERTY_TYPE_FONT) {
@@ -5676,7 +5594,7 @@ cho_songs_parse(const char *str, const char *chordpro_filepath, struct Config *c
switch (directive->ctype) {
case CHORD_DIRECTIVE_TRANSPOSE:
if (!transposition_parse(directive_value, &transpose)) {
- LOG_DEBUG("transposition_parse failed.");
+ DEBUG("transposition_parse failed.");
cho_log(&ctx, LOG_ERR, "Directive 'transpose' has an invalid value.");
goto ERR;
}
@@ -5688,7 +5606,7 @@ cho_songs_parse(const char *str, const char *chordpro_filepath, struct Config *c
case CHORD_DIRECTIVE_DEFINE:
diagram = cho_chord_diagram_parse(&ctx, directive_value, ctx.songs[ctx.so]->diagrams, ctx.dia);
if (!diagram) {
- LOG_DEBUG("cho_chord_diagram_parse failed.");
+ DEBUG("cho_chord_diagram_parse failed.");
goto ERR;
}
// debug_chord_diagram_print(diagram);
@@ -6142,7 +6060,7 @@ cho_songs_parse(const char *str, const char *chordpro_filepath, struct Config *c
ctx.tags[ctx.ta]->name = strdup(tag_start);
tag_style = cho_style_parse(&ctx, tag_start, NULL, cho_tag_style_inherit(ctx.tags, ctx.ta-1), &ctx.tags[ctx.ta]->style_presence);
if (!tag_style) {
- LOG_DEBUG("cho_style_parse failed.");
+ DEBUG("cho_style_parse failed.");
goto ERR;
}
ctx.tags[ctx.ta]->style = tag_style;
@@ -6214,7 +6132,7 @@ cho_songs_parse(const char *str, const char *chordpro_filepath, struct Config *c
tag_end[ctx.t] = 0;
ctx.t = 0;
if (!cho_tag_close_last_unclosed(&ctx, tag_end, ctx.tags, ctx.ta)) {
- LOG_DEBUG("cho_tag_close_last_unclosed failed.");
+ DEBUG("cho_tag_close_last_unclosed failed.");
goto ERR;
}
memset(tag_end, 0, strlen(tag_end));
@@ -6295,7 +6213,7 @@ cho_songs_parse(const char *str, const char *chordpro_filepath, struct Config *c
(*lines)[ctx.li]->items[ctx.lii]->is_text = false;
image = cho_image_tag_parse(&ctx, ctx.tags[ctx.ta]->attrs);
if (!image) {
- LOG_DEBUG("cho_image_tag_parse failed.");
+ DEBUG("cho_image_tag_parse failed.");
goto ERR;
}
(*lines)[ctx.li]->items[ctx.lii]->u.image = image;
@@ -6305,7 +6223,7 @@ cho_songs_parse(const char *str, const char *chordpro_filepath, struct Config *c
} else {
tag_style = cho_style_parse(&ctx, tag_start, ctx.tags[ctx.ta]->attrs, cho_tag_style_inherit(ctx.tags, ctx.ta-1), &ctx.tags[ctx.ta]->style_presence);
if (!tag_style) {
- LOG_DEBUG("cho_style_parse failed.");
+ DEBUG("cho_style_parse failed.");
goto ERR;
}
ctx.tags[ctx.ta]->style = tag_style;
@@ -6423,7 +6341,7 @@ cho_songs_parse(const char *str, const char *chordpro_filepath, struct Config *c
(*lines)[ctx.li]->items[ctx.lii]->is_text = false;
image = cho_image_tag_parse(&ctx, ctx.tags[ctx.ta]->attrs);
if (!image) {
- LOG_DEBUG("cho_image_tag_parse failed.");
+ DEBUG("cho_image_tag_parse failed.");
goto ERR;
}
(*lines)[ctx.li]->items[ctx.lii]->u.image = image;
@@ -6433,7 +6351,7 @@ cho_songs_parse(const char *str, const char *chordpro_filepath, struct Config *c
} else {
tag_style = cho_style_parse(&ctx, tag_start, ctx.tags[ctx.ta]->attrs, cho_tag_style_inherit(ctx.tags, ctx.ta-1), &ctx.tags[ctx.ta]->style_presence);
if (!tag_style) {
- LOG_DEBUG("cho_style_parse failed.");
+ DEBUG("cho_style_parse failed.");
goto ERR;
}
ctx.tags[ctx.ta]->style = tag_style;
@@ -6540,7 +6458,7 @@ cho_songs_parse(const char *str, const char *chordpro_filepath, struct Config *c
ctx.state_before_metadata_substitution
);
if (!substituted) {
- LOG_DEBUG("cho_metadata_substitution_parse failed.");
+ DEBUG("cho_metadata_substitution_parse failed.");
goto ERR;
}
char *ch;
@@ -6588,7 +6506,7 @@ cho_songs_parse(const char *str, const char *chordpro_filepath, struct Config *c
prev_c = c;
}
if (!cho_style_reset_default()) {
- LOG_DEBUG("cho_style_reset_default failed.");
+ DEBUG("cho_style_reset_default failed.");
goto ERR;
}
cho_songs_close(&ctx, lines);
@@ -6626,7 +6544,7 @@ cho_songs_parse(const char *str, const char *chordpro_filepath, struct Config *c
return NULL;
}
-#ifdef DEBUG
+#ifdef ENABLE_DEBUG
void
cho_debug_songs_print(struct ChoSong **songs)
{
@@ -6667,4 +6585,4 @@ cho_debug_songs_print(struct ChoSong **songs)
}
}
}
-#endif /* DEBUG */
+#endif /* ENABLE_DEBUG */
diff --git a/src/config.c b/src/config.c
@@ -198,9 +198,9 @@ config_instrument_parse(const char *str, bool *error)
if (!strcmp(str, instruments[INSTRUMENT_GUITAR].name)) {
return INSTRUMENT_GUITAR;
} else
- if (!strcmp(str, instruments[INSTRUMENT_KEYBOARD].name)) {
+ /* if (!strcmp(str, instruments[INSTRUMENT_KEYBOARD].name)) {
return INSTRUMENT_KEYBOARD;
- } else
+ } else */
if (!strcmp(str, instruments[INSTRUMENT_MANDOLIN].name)) {
return INSTRUMENT_MANDOLIN;
} else
@@ -554,7 +554,7 @@ config_load_style(
if (font_section) {
char err[25];
if (!config_load_font(style->font, font_section, presence, &err)) {
- LOG_DEBUG("config_load_font failed.");
+ DEBUG("config_load_font failed.");
snprintf((char *)err_buf, 38, "font.%s", err);
return false;
}
@@ -692,7 +692,7 @@ config_load_style(
return true;
}
-#ifdef DEBUG
+#ifdef ENABLE_DEBUG
static void
debug_presence_print(const char *name, struct ChoStylePresence *presence)
@@ -718,7 +718,7 @@ debug_presence_print(const char *name, struct ChoStylePresence *presence)
printf("---- END PRESENCE ------\n");
}
-#endif /* DEBUG */
+#endif /* ENABLE_DEBUG */
static void
set_text_style(
@@ -949,7 +949,7 @@ config_load(toml_table_t *toml, const char *filepath)
if (value.ok) {
instrument = config_instrument_parse(value.u.s, &error);
if (error) {
- LOG_DEBUG("config_instrument_parse failed.");
+ DEBUG("config_instrument_parse failed.");
config_log(&ctx, LOG_ERR, "[output.chord_diagram]", "Unknown instrument '%s'.", value.u.s);
free(value.u.s);
goto ERR;
@@ -973,7 +973,7 @@ config_load(toml_table_t *toml, const char *filepath)
config_notes_free(config->output->notes);
config->output->notes = custom_notes;
} else {
- LOG_DEBUG("config_notes_load failed.");
+ DEBUG("config_notes_load failed.");
config_log(&ctx, LOG_ERR, "[output]", "Couldn't load custom notation system '%s' from [notation_systems] section.", value.u.s);
free(value.u.s);
goto ERR;
@@ -998,7 +998,7 @@ config_load(toml_table_t *toml, const char *filepath)
if (value.ok) {
align = config_alignment_parse(value.u.s, &error);
if (error) {
- LOG_DEBUG("config_alignment_parse failed.");
+ DEBUG("config_alignment_parse failed.");
free(value.u.s);
goto ERR;
}
@@ -1027,7 +1027,7 @@ config_load(toml_table_t *toml, const char *filepath)
char err[38];
snprintf((char *)&toml_section_name, size, "[output.styles.%s]", key_name);
if (!config_load_style(style, key, &presences[ttype], &err)) {
- LOG_DEBUG("config_load_style failed.");
+ DEBUG("config_load_style failed.");
config_log(&ctx, LOG_ERR, toml_section_name, err);
goto ERR;
}
@@ -1060,7 +1060,7 @@ config_load(toml_table_t *toml, const char *filepath)
config_notes_free(config->parser->notes);
config->parser->notes = custom_notes;
} else {
- LOG_DEBUG("config_notes_load failed.");
+ DEBUG("config_notes_load failed.");
config_log(&ctx, LOG_ERR, "[parser.chords]", "Couldn't load custom notation system '%s' from [notation_systems] section.", value.u.s);
free(value.u.s);
goto ERR;
@@ -1099,21 +1099,21 @@ config_load_from_file(const char *filepath)
fp = fopen(filepath, "r");
if (!fp) {
- LOG_DEBUG("fopen failed.");
+ DEBUG("fopen failed.");
util_log(NULL, 0, LOG_ERR, "Cannot open file '%s': %s", filepath, strerror(errno));
return NULL;
}
char errbuf[200];
table = toml_parse_file(fp, (char *)&errbuf, sizeof(errbuf));
if (!table) {
- LOG_DEBUG("toml_parse_file failed.");
+ DEBUG("toml_parse_file failed.");
util_log(NULL, 0, LOG_ERR, "Config file '%s' is not a valid toml file: %s.", filepath, (char *)&errbuf);
fclose(fp);
return NULL;
}
config = config_load(table, filepath);
if (!config) {
- LOG_DEBUG("config_load failed.");
+ DEBUG("config_load failed.");
fclose(fp);
toml_free(table);
return NULL;
@@ -1132,13 +1132,13 @@ config_load_from_data(const char *data)
table = toml_parse((char *)data, (char *)&errbuf, sizeof(errbuf));
if (!table) {
- LOG_DEBUG("toml_parse failed.");
+ DEBUG("toml_parse failed.");
util_log(NULL, 0, LOG_ERR, "Config data is not valid toml: %s.", (char *)&errbuf);
return NULL;
}
config = config_load(table, NULL);
if (!config) {
- LOG_DEBUG("config_load failed.");
+ DEBUG("config_load failed.");
}
toml_free(table);
return config;
diff --git a/src/config.h b/src/config.h
@@ -4,11 +4,11 @@
#ifndef _CONFIG_H_
#define _CONFIG_H_
-#ifdef DEBUG
+#ifdef ENABLE_DEBUG
#define SYMBOLS_FILEPATH "./misc/ChordProSymbols.ttf"
#else
#define SYMBOLS_FILEPATH PREFIX"/share/lorid/ChordProSymbols.ttf"
-#endif /* DEBUG */
+#endif /* ENABLE_DEBUG */
struct ConfigContext {
char *config_filepath;
diff --git a/src/core.c b/src/core.c
@@ -17,6 +17,8 @@ const struct InstrumentInfo instruments[] = {
{ .name = "ukulele", .description = "Ukulele, 4 strings, standard tuning", .tuning = "G C E A" }
};
+static const char *log_levels[] = { "INFO", "WARN", " ERR", "DEBUG" };
+static const uint8_t log_level_colors[] = { 37, 33, 31, 34 };
static bool g_show_info_logs = false;
void
@@ -56,30 +58,13 @@ log_without_color(
va_list va
)
{
- if (file) {
- fprintf(stderr, "%s", file);
- }
- if (line_no > 0) {
- fprintf(stderr, ":%ld", line_no);
- }
- const char *log_level = "";
- switch (level) {
- case LOG_INFO:
- log_level = "INFO";
- break;
- case LOG_WARN:
- log_level = "WARN";
- break;
- case LOG_ERR:
- log_level = " ERR";
- break;
- case LOG_TODO:
- log_level = "TODO";
- break;
- }
- fprintf(stderr, "%s: ", log_level);
- // va_list va;
- // va_start(va, msg);
+ if (file && line_no > 0) {
+ fprintf(stderr, "%s:%ld ", file, line_no);
+ } else
+ if (!file && line_no > 0) {
+ fprintf(stderr, "line %ld ", line_no);
+ }
+ fprintf(stderr, "%s: ", log_levels[level]);
vfprintf(stderr, msg, va);
fprintf(stderr, "\n");
}
@@ -94,34 +79,13 @@ log_with_color(
va_list va
)
{
- if (file) {
- fprintf(stderr, "\033[1m%s\033[0m", file);
- if (line_no > 0) {
- fprintf(stderr, "\033[1;:%ld\033[0m", line_no);
- }
- fprintf(stderr, " ");
- }
- const char *log_level = "";
- const char *color = "";
- switch (level) {
- case LOG_INFO:
- log_level = "INFO";
- color = "37";
- break;
- case LOG_WARN:
- log_level = "WARN";
- color = "33";
- break;
- case LOG_ERR:
- log_level = " ERR";
- color = "31";
- break;
- case LOG_TODO:
- log_level = "TODO";
- color = "34";
- break;
- }
- fprintf(stderr, "\033[1;%sm%s\033[0m: ", color, log_level);
+ if (file && line_no > 0) {
+ fprintf(stderr, "\033[1m%s:%ld\033[0m ", file, line_no);
+ } else
+ if (!file && line_no > 0) {
+ fprintf(stderr, "\033[1mline %ld\033[0m ", line_no);
+ }
+ fprintf(stderr, "\033[1;%dm%s\033[0m: ", log_level_colors[level], log_levels[level]);
vfprintf(stderr, msg, va);
fprintf(stderr, "\n");
}
@@ -512,7 +476,7 @@ filepath_resolve_tilde(const char *path)
if (*path == '~') {
home = getenv("HOME");
if (!home) {
- LOG_DEBUG("getenv failed.");
+ DEBUG("getenv failed.");
return NULL;
}
str = erealloc(str, (strlen(home)+strlen(path)) * sizeof(char));
@@ -573,7 +537,7 @@ size_create(const char *str)
double d;
d = strtod(str, &endptr);
if (str == endptr || errno == ERANGE) {
- LOG_DEBUG("strtod failed.");
+ DEBUG("strtod failed.");
goto ERR;
}
size->d = d;
diff --git a/src/core.h b/src/core.h
@@ -4,10 +4,10 @@
#ifndef _CORE_H_
#define _CORE_H_
-#ifdef DEBUG
-#define LOG_DEBUG(msg) fprintf(stderr, msg"\n")
+#ifdef ENABLE_DEBUG
+#define DEBUG(msg) util_log(__FILE__, __LINE__, LOG_DEBUG, msg);
#else
-#define LOG_DEBUG(msg)
+#define DEBUG(msg)
#endif
#define LENGTH(x) (sizeof x / sizeof x[0])
@@ -89,7 +89,7 @@ enum LogLevel {
LOG_INFO,
LOG_WARN,
LOG_ERR,
- LOG_TODO
+ LOG_DEBUG
};
enum NotationSystem {
diff --git a/src/lorid.c b/src/lorid.c
@@ -67,7 +67,7 @@ main(int argc, char *argv[])
} else {
char *home = getenv("HOME");
if (!home) {
- LOG_DEBUG("getenv failed.");
+ DEBUG("getenv failed.");
util_log(NULL, 0, LOG_ERR, "Failed to read the environment variable 'HOME'.");
goto ERR;
}
@@ -85,20 +85,20 @@ main(int argc, char *argv[])
input = file_read(fp);
all_songs = cho_songs_parse(input, NULL, config);
if (!all_songs) {
- LOG_DEBUG("cho_songs_parse failed.");
+ DEBUG("cho_songs_parse failed.");
goto ERR;
}
} else if (argc == optind+1) {
fp = fopen(argv[argc-1], "r");
if (!fp) {
- LOG_DEBUG("fopen failed.");
+ DEBUG("fopen failed.");
goto ERR;
}
input = file_read(fp);
chordpro_filepath = argv[argc-1];
all_songs = cho_songs_parse(input, chordpro_filepath, config);
if (!all_songs) {
- LOG_DEBUG("cho_songs_parse failed.");
+ DEBUG("cho_songs_parse failed.");
goto ERR;
}
} else {
@@ -107,13 +107,13 @@ main(int argc, char *argv[])
for (i = argc-file_count; i<argc; i++) {
fp = fopen(argv[i], "r");
if (!fp) {
- LOG_DEBUG("fopen failed.");
+ DEBUG("fopen failed.");
goto ERR;
}
input = file_read(fp);
songs = cho_songs_parse(input, argv[i], config);
if (!songs) {
- LOG_DEBUG("cho_songs_parse failed.");
+ DEBUG("cho_songs_parse failed.");
goto ERR;
}
for (so = songs; *so; s++, so++) {
@@ -134,7 +134,7 @@ main(int argc, char *argv[])
qsort(all_songs, cho_song_count(all_songs), sizeof(struct ChoSong *), cho_song_compare);
pdf_filename = out_pdf_create(chordpro_filepath, output, all_songs, config);
if (!pdf_filename) {
- LOG_DEBUG("out_pdf_create failed.");
+ DEBUG("out_pdf_create failed.");
goto ERR;
}
util_log(NULL, 0, LOG_INFO, "Writing pdf to file: '%s'.", pdf_filename);
diff --git a/src/out_pdf.c b/src/out_pdf.c
@@ -226,7 +226,7 @@ fontpath_count_fonts(FcChar8 *path)
set = FcFontSetCreate();
if (!FcFileScan(set, NULL, NULL, NULL, path, false)) {
- LOG_DEBUG("fontpath_count_fonts failed.");
+ DEBUG("fontpath_count_fonts failed.");
FcFontSetDestroy(set);
return -1;
}
@@ -243,7 +243,7 @@ fontconfig_pattern_create(struct Font *font, enum FontType font_type)
pattern = FcPatternCreate();
if (!pattern) {
- LOG_DEBUG("FcPatternCreate failed.\n");
+ DEBUG("FcPatternCreate failed.\n");
return NULL;
}
family.type = FcTypeString;
@@ -293,7 +293,7 @@ fontpath_find(struct Font *font, enum FontType font_type)
pattern = fontconfig_pattern_create(font, font_type);
if (!pattern) {
- LOG_DEBUG("fontconfig_pattern_create failed.\n");
+ DEBUG("fontconfig_pattern_create failed.\n");
return NULL;
}
if (
@@ -357,7 +357,7 @@ pdf_load_chord_diagram_fonts(struct PDFContext *ctx)
if (!fontpath) {
fontpath = fontpath_find(&font, FONT_TYPE_OTF);
if (!fontpath) {
- LOG_DEBUG("fontpath_find failed.");
+ DEBUG("fontpath_find failed.");
obj_free(fnt);
return false;
}
@@ -404,7 +404,7 @@ pdf_load_fonts(struct PDFContext *ctx, struct Font **needed_fonts)
if (index == -1) {
fnt->value = pdfioFileCreateFontObjFromFile(ctx->pdf_file, fontpath, true);
if (!fnt->value) {
- LOG_DEBUG("pdfioFileCreateFontObjFromFile failed.");
+ DEBUG("pdfioFileCreateFontObjFromFile failed.");
goto ERR;
}
strs_add(&fontpaths, fontpath);
@@ -421,7 +421,7 @@ pdf_load_fonts(struct PDFContext *ctx, struct Font **needed_fonts)
fnt->name = fnt_name_create(*f);
fnt->value = pdfioFileCreateFontObjFromBase(ctx->pdf_file, name);
if (!fnt->value) {
- LOG_DEBUG("pdfioFileCreateFontObjFromBase failed.");
+ DEBUG("pdfioFileCreateFontObjFromBase failed.");
goto ERR;
}
objs_add_obj(&ctx->fonts, fnt);
@@ -434,7 +434,7 @@ pdf_load_fonts(struct PDFContext *ctx, struct Font **needed_fonts)
if (index == -1) {
fnt->value = pdfioFileCreateFontObjFromFile(ctx->pdf_file, fontpath, true);
if (!fnt->value) {
- LOG_DEBUG("pdfioFileCreateFontObjFromFile failed.");
+ DEBUG("pdfioFileCreateFontObjFromFile failed.");
goto ERR;
}
strs_add(&fontpaths, fontpath);
@@ -454,7 +454,7 @@ pdf_load_fonts(struct PDFContext *ctx, struct Font **needed_fonts)
if (index == -1) {
fnt->value = pdfioFileCreateFontObjFromFile(ctx->pdf_file, fontpath, true);
if (!fnt->value) {
- LOG_DEBUG("pdfioFileCreateFontObjFromFile failed.");
+ DEBUG("pdfioFileCreateFontObjFromFile failed.");
goto ERR;
}
strs_add(&fontpaths, fontpath);
@@ -475,7 +475,7 @@ pdf_load_fonts(struct PDFContext *ctx, struct Font **needed_fonts)
}
if (ctx->config->output->diagram->show) {
if (!pdf_load_chord_diagram_fonts(ctx)) {
- LOG_DEBUG("pdf_load_chord_diagram_fonts failed.");
+ DEBUG("pdf_load_chord_diagram_fonts failed.");
goto ERR;
}
}
@@ -502,7 +502,7 @@ pdf_filename_generate_from_songs(struct PDFContext *ctx, struct ChoSong **songs)
}
if (len == 1) {
if (!cho_metadata_value(songs[0]->metadata, "title", ctx->config->metadata_separator, &title, &unused)) {
- LOG_DEBUG("cho_metadata_value failed.");
+ DEBUG("cho_metadata_value failed.");
return NULL;
}
normalized_title = str_normalize(title);
@@ -534,7 +534,7 @@ pdf_filepath_create(
} else {
filename = pdf_filename_generate_from_songs(ctx, songs);
if (!filename) {
- LOG_DEBUG("pdf_filename_generate_from_songs failed.");
+ DEBUG("pdf_filename_generate_from_songs failed.");
return NULL;
}
}
@@ -595,7 +595,7 @@ pdf_font_set(struct PDFContext *ctx, pdfio_stream_t *stream, struct Font *font)
return true;
}
if (!pdfioContentSetTextFont(stream, name, font->size)) {
- LOG_DEBUG("pdfioContentSetTextFont failed.");
+ DEBUG("pdfioContentSetTextFont failed.");
free(name);
return false;
}
@@ -612,7 +612,7 @@ text_width(struct PDFContext *ctx, const char *text, struct ChoStyle *style)
char *name = fnt_name_create(style->font);
pdfio_obj_t *font_obj = out_pdf_fnt_obj_get_by_name(ctx, name);
if (!font_obj) {
- LOG_DEBUG("out_pdf_fnt_obj_get_by_name failed.");
+ DEBUG("out_pdf_fnt_obj_get_by_name failed.");
free(name);
return -1.0;
}
@@ -629,7 +629,7 @@ text_above_width(struct PDFContext *ctx, struct ChoLineItemAbove *above)
name = cho_chord_name_generate(above->u.chord);
width = text_width(ctx, name, above->u.chord->style);
if (width == ERROR) {
- LOG_DEBUG("text_width failed.");
+ DEBUG("text_width failed.");
free(name);
return ERROR;
}
@@ -637,7 +637,7 @@ text_above_width(struct PDFContext *ctx, struct ChoLineItemAbove *above)
} else {
width = text_width(ctx, above->u.annot->text, above->u.annot->style);
if (width == ERROR) {
- LOG_DEBUG("text_width failed.");
+ DEBUG("text_width failed.");
return ERROR;
}
}
@@ -681,7 +681,7 @@ text_find_fitting(
tmp[i] = 0;
width = text_width(ctx, (const char *)&tmp, style);
if (width == ERROR) {
- LOG_DEBUG("text_width failed.");
+ DEBUG("text_width failed.");
return -1;
}
start = i - 1;
@@ -721,19 +721,19 @@ pdf_draw_line(
break;
}
if (!pdfioContentPathMoveTo(stream, text->x, y)) {
- LOG_DEBUG("pdfioContentPathMoveTo failed.");
+ DEBUG("pdfioContentPathMoveTo failed.");
return false;
}
if (!pdfioContentPathLineTo(stream, text->x + width, y)) {
- LOG_DEBUG("pdfioContentPathLineTo failed.");
+ DEBUG("pdfioContentPathLineTo failed.");
return false;
}
if (!pdfioContentSetStrokeColorRGB(stream, red, green, blue)) {
- LOG_DEBUG("pdfioContentSetStrokeColorRGB failed.");
+ DEBUG("pdfioContentSetStrokeColorRGB failed.");
return false;
}
if (!pdfioContentStroke(stream)) {
- LOG_DEBUG("pdfioContentStroke failed.");
+ DEBUG("pdfioContentStroke failed.");
return false;
}
return true;
@@ -783,13 +783,13 @@ pdf_text_show(struct PDFContext *ctx, pdfio_stream_t *stream, struct PDFText *te
bool unicode;
if (!pdf_font_set(ctx, stream, text->style->font)) {
- LOG_DEBUG("pdf_font_set failed.");
+ DEBUG("pdf_font_set failed.");
return false;
}
unicode = !is_base_font(text->style->font);
if (!is_purest_white(text->style->background_color)) {
if (!pdf_draw_rectangle(stream, text)) {
- LOG_DEBUG("draw_rectangle failed.");
+ DEBUG("draw_rectangle failed.");
return false;
}
}
@@ -797,27 +797,27 @@ pdf_text_show(struct PDFContext *ctx, pdfio_stream_t *stream, struct PDFText *te
green = text->style->foreground_color->green / 255.0;
blue = text->style->foreground_color->blue / 255.0;
if (!pdfioContentSetFillColorRGB(stream, red, green, blue)) {
- LOG_DEBUG("pdfioContentSetFillColorRGB failed.");
+ DEBUG("pdfioContentSetFillColorRGB failed.");
return false;
}
if (!pdfioContentTextBegin(stream)) {
- LOG_DEBUG("pdfioContentTextBegin failed.");
+ DEBUG("pdfioContentTextBegin failed.");
return false;
}
if (!pdfioContentTextMoveTo(stream, text->x, text->y)) {
- LOG_DEBUG("pdfioContentTextMoveTo failed.");
+ DEBUG("pdfioContentTextMoveTo failed.");
return false;
}
if (!pdfioContentSetTextRise(stream, text->style->rise)) {
- LOG_DEBUG("pdfioContentSetTextRise failed.");
+ DEBUG("pdfioContentSetTextRise failed.");
return false;
}
if (!pdfioContentTextShow(stream, unicode, text->text)) {
- LOG_DEBUG("pdfioContentTextShow failed.");
+ DEBUG("pdfioContentTextShow failed.");
return false;
}
if (!pdfioContentTextEnd(stream)) {
- LOG_DEBUG("pdfioContentTextEnd failed.");
+ DEBUG("pdfioContentTextEnd failed.");
return false;
}
if (text->style->underline_style == LINE_STYLE_SINGLE) {
@@ -840,7 +840,7 @@ pdf_text_show(struct PDFContext *ctx, pdfio_stream_t *stream, struct PDFText *te
green = text->style->boxed_color->green / 255.0;
blue = text->style->boxed_color->blue / 255.0;
if (!pdfioContentSetStrokeColorRGB(stream, red, green, blue)) {
- LOG_DEBUG("pdfioContentSetFillColorRGB failed.");
+ DEBUG("pdfioContentSetFillColorRGB failed.");
return false;
}
if (!pdfioContentPathRect(
@@ -850,11 +850,11 @@ pdf_text_show(struct PDFContext *ctx, pdfio_stream_t *stream, struct PDFText *te
text->width + 4.0,
text->style->font->size * 0.8 + 4.0
)) {
- LOG_DEBUG("pdfioContentPathRect failed.");
+ DEBUG("pdfioContentPathRect failed.");
return false;
}
if (!pdfioContentStroke(stream)) {
- LOG_DEBUG("pdfioContentStroke failed.");
+ DEBUG("pdfioContentStroke failed.");
return false;
}
}
@@ -882,34 +882,34 @@ annot_page_link_add(
page_index = entry->page_index + toc_page_count;
annot = pdfioDictCreate(ctx->pdf_file);
if (!pdfioDictSetName(annot, "Subtype", "Link")) {
- LOG_DEBUG("pdfioDictSetName failed.");
+ DEBUG("pdfioDictSetName failed.");
return false;
}
if (!pdfioDictSetRect(annot, "Rect", &rect)) {
- LOG_DEBUG("pdfioDictSetRect failed.");
+ DEBUG("pdfioDictSetRect failed.");
return false;
}
destination = pdfioArrayCreate(ctx->pdf_file);
if (!pdfioArrayAppendNumber(destination, page_index)) {
- LOG_DEBUG("pdfioArrayAppendNumber failed.");
+ DEBUG("pdfioArrayAppendNumber failed.");
return false;
}
if (!pdfioArrayAppendName(destination, "FitH")) {
- LOG_DEBUG("pdfioArrayAppendName failed.");
+ DEBUG("pdfioArrayAppendName failed.");
return false;
}
// TODO: Is this constant '30.0' correct with different font sizes, etc. ?
// clicking the annotation should show the song including the song title at the top
if (!pdfioArrayAppendNumber(destination, entry->page_y + 30.0)) {
- LOG_DEBUG("pdfioArrayAppendNumber failed.");
+ DEBUG("pdfioArrayAppendNumber failed.");
return false;
}
if (!pdfioDictSetArray(annot, "Dest", destination)) {
- LOG_DEBUG("pdfioDictSetArray failed.");
+ DEBUG("pdfioDictSetArray failed.");
return false;
}
if (!pdfioArrayAppendDict(ctx->t_ctx.content->pages[ctx->t_ctx.page]->annots, annot)) {
- LOG_DEBUG("pdfioArrayAppendDict failed.");
+ DEBUG("pdfioArrayAppendDict failed.");
return false;
}
return true;
@@ -932,28 +932,28 @@ annot_url_link_add(
rect.y2 = c_ctx->y + style->font->size * 0.8;
annot = pdfioDictCreate(ctx->pdf_file);
if (!pdfioDictSetName(annot, "Subtype", "Link")) {
- LOG_DEBUG("pdfioDictSetName failed.");
+ DEBUG("pdfioDictSetName failed.");
return false;
}
if (!pdfioDictSetRect(annot, "Rect", &rect)) {
- LOG_DEBUG("pdfioDictSetRect failed.");
+ DEBUG("pdfioDictSetRect failed.");
return false;
}
action = pdfioDictCreate(ctx->pdf_file);
if (!pdfioDictSetName(action, "S", "URI")) {
- LOG_DEBUG("pdfioDictSetName failed.");
+ DEBUG("pdfioDictSetName failed.");
return false;
}
if (!pdfioDictSetString(action, "URI", style->href)) {
- LOG_DEBUG("pdfioDictSetString failed.");
+ DEBUG("pdfioDictSetString failed.");
return false;
}
if (!pdfioDictSetDict(annot, "A", action)) {
- LOG_DEBUG("pdfioDictSetDict failed.");
+ DEBUG("pdfioDictSetDict failed.");
return false;
}
if (!pdfioArrayAppendDict(c_ctx->content->pages[c_ctx->page]->annots, annot)) {
- LOG_DEBUG("pdfioArrayAppendDict failed.");
+ DEBUG("pdfioArrayAppendDict failed.");
return false;
}
return true;
@@ -967,7 +967,7 @@ pdf_set_title(struct PDFContext *ctx, struct ChoSong **songs)
char *title;
struct ChoStyle *unused;
if (!cho_metadata_value(songs[0]->metadata, "title", ctx->config->metadata_separator, &title, &unused)) {
- LOG_DEBUG("cho_metadata_value failed.");
+ DEBUG("cho_metadata_value failed.");
return false;
}
pdfioFileSetTitle(ctx->pdf_file, title);
@@ -992,34 +992,34 @@ pdf_page_create(
color_array = pdfioArrayCreateColorFromStandard(ctx->pdf_file, 3, PDFIO_CS_ADOBE);
page_dict = pdfioDictCreate(ctx->pdf_file);
if (!pdfioPageDictAddColorSpace(page_dict, "rgbcolorspace", color_array)) {
- LOG_DEBUG("pdfioPageDictAddColorSpace failed.");
+ DEBUG("pdfioPageDictAddColorSpace failed.");
return NULL;
}
if (!pdfioDictSetArray(page_dict, "Annots", annots)) {
- LOG_DEBUG("pdfioDictSetArray failed.");
+ DEBUG("pdfioDictSetArray failed.");
return NULL;
}
if (imgs) {
for (i = imgs; *i; i++) {
if (!pdfioPageDictAddImage(page_dict, (*i)->name, (*i)->obj)) {
- LOG_DEBUG("pdfioPageDictAddImage failed.");
+ DEBUG("pdfioPageDictAddImage failed.");
return NULL;
}
}
}
for (f = ctx->fonts; *f; f++) {
if (!pdfioPageDictAddFont(page_dict, (*f)->name, (*f)->value)) {
- LOG_DEBUG("pdfioPageDictAddFont failed.");
+ DEBUG("pdfioPageDictAddFont failed.");
return NULL;
}
}
page_stream = pdfioFileCreatePage(ctx->pdf_file, page_dict);
if (!pdfioContentSetFillColorSpace(page_stream, "rgbcolorspace")) {
- LOG_DEBUG("pdfioContentSetFillColorSpace failed.");
+ DEBUG("pdfioContentSetFillColorSpace failed.");
return NULL;
}
if (!pdfioContentSetStrokeColorSpace(page_stream, "rgbcolorspace")) {
- LOG_DEBUG("pdfioContentSetStrokeColorSpace failed.");
+ DEBUG("pdfioContentSetStrokeColorSpace failed.");
return NULL;
}
return page_stream;
@@ -1081,7 +1081,7 @@ image_name(struct PDFContext *ctx, struct ChoImage *image)
image_path = (char *)&tmp;
}
if (stat(image_path, &s)) {
- LOG_DEBUG("stat failed.");
+ DEBUG("stat failed.");
util_log(NULL, 0, LOG_ERR, "%s: %s", image_path, strerror(errno));
return NULL;
}
@@ -1113,7 +1113,7 @@ pdf_load_images(struct PDFContext *ctx, struct Obj ***images, struct ChoSong **s
strcat((char *)&filepath, (*it)->u.image->src);
name = image_name(ctx, (*it)->u.image);
if (!name) {
- LOG_DEBUG("image_name failed.");
+ DEBUG("image_name failed.");
return false;
}
if (!objs_get_obj(*images, name)) {
@@ -1127,7 +1127,7 @@ pdf_load_images(struct PDFContext *ctx, struct Obj ***images, struct ChoSong **s
}
(*images)[i]->value = pdfioFileCreateImageObjFromFile(ctx->pdf_file, image_filepath, true);
if (!(*images)[i]->value) {
- LOG_DEBUG("pdfioFileCreateImageObjFromFile failed.");
+ DEBUG("pdfioFileCreateImageObjFromFile failed.");
free(name);
return false;
}
@@ -1210,7 +1210,7 @@ line_width_until_text_above(
name = fnt_name_create(text->style->font);
font_obj = out_pdf_fnt_obj_get_by_name(ctx, name);
if (!font_obj) {
- LOG_DEBUG("out_pdf_fnt_obj_get_by_name failed.");
+ DEBUG("out_pdf_fnt_obj_get_by_name failed.");
free(name);
return ERROR;
}
@@ -1226,12 +1226,12 @@ line_width_until_text_above(
} else {
name = image_name(ctx, items[i]->u.image);
if (!name) {
- LOG_DEBUG("image_name failed.");
+ DEBUG("image_name failed.");
return ERROR;
}
obj = objs_get_obj(img_objs, name);
if (!obj) {
- LOG_DEBUG("objs_get_obj failed.");
+ DEBUG("objs_get_obj failed.");
free(name);
return ERROR;
}
@@ -1427,18 +1427,18 @@ calc_space_between_text_above(
double prev_width;
width_until_cur = line_width_until_text_above(ctx, items, text_above[i], img_objs, NULL);
if (width_until_cur == ERROR) {
- LOG_DEBUG("line_width_until_text_above failed.");
+ DEBUG("line_width_until_text_above failed.");
return false;
}
i--;
width_until_prev = line_width_until_text_above(ctx, items, text_above[i], img_objs, &space);
if (width_until_prev == ERROR) {
- LOG_DEBUG("line_width_until_text_above failed.");
+ DEBUG("line_width_until_text_above failed.");
return false;
}
prev_width = text_above_width(ctx, text_above[i]);
if (prev_width == ERROR) {
- LOG_DEBUG("text_above_width failed.");
+ DEBUG("text_above_width failed.");
return false;
}
i++;
@@ -1475,7 +1475,7 @@ item_width(
if (item->is_text) {
width = text_width(ctx, item->u.text->text, item->u.text->style);
if (width == ERROR) {
- LOG_DEBUG("text_width failed.");
+ DEBUG("text_width failed.");
return ERROR;
}
if (spaces) {
@@ -1488,12 +1488,12 @@ item_width(
} else {
name = image_name(ctx, item->u.image);
if (!name) {
- LOG_DEBUG("image_name failed.");
+ DEBUG("image_name failed.");
return ERROR;
}
obj = objs_get_obj(img_objs, name);
if (!obj) {
- LOG_DEBUG("objs_get_obj failed.");
+ DEBUG("objs_get_obj failed.");
free(name);
return ERROR;
}
@@ -1522,7 +1522,7 @@ items_find_position_to_break_line(
for (i = 0; items[i]; i++) {
d = item_width(ctx, items[i], i, spaces, img_objs);
if (d == ERROR) {
- LOG_DEBUG("item_width failed.");
+ DEBUG("item_width failed.");
goto ERR;
}
if (width + d > LINE_WIDTH) {
@@ -1536,7 +1536,7 @@ items_find_position_to_break_line(
LINE_WIDTH
);
if (pos->text_index == EMPTY_INT) {
- LOG_DEBUG("text_find_fitting failed.");
+ DEBUG("text_find_fitting failed.");
goto ERR;
}
} else {
@@ -1578,12 +1578,12 @@ images_find_biggest_height(
if (!(*it)->is_text) {
name = image_name(ctx, (*it)->u.image);
if (!name) {
- LOG_DEBUG("image_name failed.");
+ DEBUG("image_name failed.");
return ERROR;
}
obj = objs_get_obj(img_objs, name);
if (!obj) {
- LOG_DEBUG("objs_get_obj failed.");
+ DEBUG("objs_get_obj failed.");
free(name);
return ERROR;
}
@@ -1757,7 +1757,7 @@ numeral_system_number_to_str(enum NumeralSystem system, int n)
if (system == NUMERAL_SYSTEM_ROMAN) {
const char *str = numeral_system_western_arabic_to_roman((unsigned int)n);
if (!str) {
- LOG_DEBUG("numeral_system_western_arabic_to_roman failed.");
+ DEBUG("numeral_system_western_arabic_to_roman failed.");
return NULL;
}
return str;
@@ -1785,13 +1785,13 @@ pdf_page_add_page_no(
texts = &c_ctx->content->pages[c_ctx->page]->texts;
page_no = numeral_system_number_to_str(numeral_system, c_ctx->page+1);
if (!page_no) {
- LOG_DEBUG("numeral_system_number_to_str failed.");
+ DEBUG("numeral_system_number_to_str failed.");
cho_style_free(style);
return false;
}
width = text_width(ctx, page_no, style);
if (width == ERROR) {
- LOG_DEBUG("text_width failed.");
+ DEBUG("text_width failed.");
cho_style_free(style);
return false;
}
@@ -1852,7 +1852,7 @@ pdf_page_close_then_add(
c_ctx->y = MEDIABOX_HEIGHT - MARGIN_TOP;
if (ctx->config->output->page_no->show) {
if (!pdf_page_add_page_no(ctx, c_ctx, numeral_system)) {
- LOG_DEBUG("pdf_page_add_page_no failed.");
+ DEBUG("pdf_page_add_page_no failed.");
return false;
}
}
@@ -1884,7 +1884,7 @@ pdf_toc_page_count(
strcpy((char *)&tmp, (*toc)->title);
width = text_width(ctx, (*toc)->title, style);
if (width == ERROR) {
- LOG_DEBUG("text_width failed.");
+ DEBUG("text_width failed.");
return -1;
}
width += MARGIN_HORIZONTAL;
@@ -1893,7 +1893,7 @@ pdf_toc_page_count(
while (width > max_title_width) {
index = text_find_fitting(ctx, t, style, MARGIN_HORIZONTAL, max_title_width);
if (index == EMPTY_INT) {
- LOG_DEBUG("text_find_fitting failed.");
+ DEBUG("text_find_fitting failed.");
return -1;
}
t[index] = 0;
@@ -1901,7 +1901,7 @@ pdf_toc_page_count(
t += index + 1;
width = text_width(ctx, t, style);
if (width == ERROR) {
- LOG_DEBUG("text_width failed.");
+ DEBUG("text_width failed.");
return -1;
}
}
@@ -1951,7 +1951,7 @@ pdf_texts_add_toc_entry(
strcpy((char *)&tmp, entry->title);
width = text_width(ctx, entry->title, style);
if (width == ERROR) {
- LOG_DEBUG("text_width failed.");
+ DEBUG("text_width failed.");
return false;
}
if (width+MARGIN_HORIZONTAL > max_song_title_width) {
@@ -1960,14 +1960,14 @@ pdf_texts_add_toc_entry(
while (width+MARGIN_HORIZONTAL > max_song_title_width) {
if (ctx->t_ctx.y < MARGIN_BOTTOM) {
if (!pdf_page_close_then_add(ctx, &ctx->t_ctx, NUMERAL_SYSTEM_ROMAN)) {
- LOG_DEBUG("pdf_page_close_then_add failed.");
+ DEBUG("pdf_page_close_then_add failed.");
return false;
}
texts = &ctx->t_ctx.content->pages[ctx->t_ctx.page]->texts;
}
index = text_find_fitting(ctx, t, style, MARGIN_HORIZONTAL, max_song_title_width);
if (index == EMPTY_INT) {
- LOG_DEBUG("text_find_fitting failed.");
+ DEBUG("text_find_fitting failed.");
return false;
}
t[index] = 0;
@@ -1981,21 +1981,21 @@ pdf_texts_add_toc_entry(
line_count++;
width = text_width(ctx, t, style);
if (width == ERROR) {
- LOG_DEBUG("text_width failed.");
+ DEBUG("text_width failed.");
return false;
}
(*texts)[ctx->t_ctx.text]->width = width;
t += index + 1;
width = text_width(ctx, t, style);
if (width == ERROR) {
- LOG_DEBUG("text_width failed.");
+ DEBUG("text_width failed.");
return false;
}
ctx->t_ctx.text++;
}
if (ctx->t_ctx.y < MARGIN_BOTTOM) {
if (!pdf_page_close_then_add(ctx, &ctx->t_ctx, NUMERAL_SYSTEM_ROMAN)) {
- LOG_DEBUG("pdf_page_close_then_add failed.");
+ DEBUG("pdf_page_close_then_add failed.");
return false;
}
texts = &ctx->t_ctx.content->pages[ctx->t_ctx.page]->texts;
@@ -2012,7 +2012,7 @@ pdf_texts_add_toc_entry(
snprintf((char *)&page_no, page_no_size, "%d", entry->page_index+1);
width = text_width(ctx, page_no, style);
if (width == ERROR) {
- LOG_DEBUG("text_width failed.");
+ DEBUG("text_width failed.");
return false;
}
@@ -2021,7 +2021,7 @@ pdf_texts_add_toc_entry(
available_dots_width = width_between_title_and_page_no - TOC_DOTS_GAP_WIDTH*2;
const char *dots = toc_dots_create(available_dots_width, dot_width);
if (!dots) {
- LOG_DEBUG("toc_dots_create failed.");
+ DEBUG("toc_dots_create failed.");
return false;
}
@@ -2042,7 +2042,7 @@ pdf_texts_add_toc_entry(
(*texts)[ctx->t_ctx.text]->width = width;
line_count++;
if (!annot_page_link_add(ctx, entry, toc_page_count, line_count, style->font->size)) {
- LOG_DEBUG("annot_page_link_add");
+ DEBUG("annot_page_link_add");
return false;
}
ctx->t_ctx.text++;
@@ -2050,7 +2050,7 @@ pdf_texts_add_toc_entry(
} else {
if (ctx->t_ctx.y < MARGIN_BOTTOM) {
if (!pdf_page_close_then_add(ctx, &ctx->t_ctx, NUMERAL_SYSTEM_ROMAN)) {
- LOG_DEBUG("pdf_page_close_then_add failed.");
+ DEBUG("pdf_page_close_then_add failed.");
return false;
}
texts = &ctx->t_ctx.content->pages[ctx->t_ctx.page]->texts;
@@ -2064,7 +2064,7 @@ pdf_texts_add_toc_entry(
(*texts)[ctx->t_ctx.text]->y = ctx->t_ctx.y;
width = text_width(ctx, entry->title, style);
if (width == ERROR) {
- LOG_DEBUG("text_width failed.");
+ DEBUG("text_width failed.");
return false;
}
(*texts)[ctx->t_ctx.text]->width = width;
@@ -2072,7 +2072,7 @@ pdf_texts_add_toc_entry(
snprintf((char *)&page_no, page_no_size, "%d", entry->page_index+1);
page_no_width = text_width(ctx, page_no, style);
if (page_no_width == ERROR) {
- LOG_DEBUG("text_width failed.");
+ DEBUG("text_width failed.");
return false;
}
@@ -2081,12 +2081,12 @@ pdf_texts_add_toc_entry(
available_dots_width = width_between_title_and_page_no - TOC_DOTS_GAP_WIDTH*2;
const char *dots = toc_dots_create(available_dots_width, dot_width);
if (!dots) {
- LOG_DEBUG("toc_dots_create failed.");
+ DEBUG("toc_dots_create failed.");
return false;
}
dots_width = text_width(ctx, dots, style);
if (dots_width == ERROR) {
- LOG_DEBUG("text_width failed.");
+ DEBUG("text_width failed.");
return false;
}
@@ -2107,7 +2107,7 @@ pdf_texts_add_toc_entry(
(*texts)[ctx->t_ctx.text]->y = ctx->t_ctx.y;
(*texts)[ctx->t_ctx.text]->width = page_no_width;
if (!annot_page_link_add(ctx, entry, toc_page_count, 1, style->font->size)) {
- LOG_DEBUG("annot_page_link_add");
+ DEBUG("annot_page_link_add");
return false;
}
ctx->t_ctx.text++;
@@ -2139,13 +2139,13 @@ pdf_texts_add_lyrics(
(*texts)[ctx->b_ctx.text]->y = ctx->b_ctx.y;
width = text_width(ctx, item->u.text->text, item->u.text->style);
if (width == ERROR) {
- LOG_DEBUG("text_width failed.");
+ DEBUG("text_width failed.");
return false;
}
(*texts)[ctx->b_ctx.text]->width = width;
if (item->u.text->style->href) {
if (!annot_url_link_add(ctx, &ctx->b_ctx, item->u.text->style, width)) {
- LOG_DEBUG("annot_url_link_add failed.");
+ DEBUG("annot_url_link_add failed.");
return false;
}
}
@@ -2177,13 +2177,13 @@ pdf_texts_add_lyrics(
(*texts)[ctx->b_ctx.text]->y = ctx->b_ctx.y;
width = text_width(ctx, (*texts)[ctx->b_ctx.text]->text, item->u.text->style);
if (width == ERROR) {
- LOG_DEBUG("text_width failed.");
+ DEBUG("text_width failed.");
return false;
}
(*texts)[ctx->b_ctx.text]->width = width;
if (item->u.text->style->href) {
if (!annot_url_link_add(ctx, &ctx->b_ctx, item->u.text->style, width)) {
- LOG_DEBUG("annot_url_link_add failed.");
+ DEBUG("annot_url_link_add failed.");
return false;
}
}
@@ -2204,13 +2204,13 @@ pdf_texts_add_lyrics(
(*texts)[ctx->b_ctx.text]->y = ctx->b_ctx.y;
width = text_width(ctx, (*texts)[ctx->b_ctx.text]->text, item->u.text->style);
if (width == ERROR) {
- LOG_DEBUG("text_width failed.");
+ DEBUG("text_width failed.");
return false;
}
(*texts)[ctx->b_ctx.text]->width = width;
if (item->u.text->style->href) {
if (!annot_url_link_add(ctx, &ctx->b_ctx, item->u.text->style, width)) {
- LOG_DEBUG("annot_url_link_add failed.");
+ DEBUG("annot_url_link_add failed.");
return false;
}
}
@@ -2242,7 +2242,7 @@ pdf_texts_add_text(
texts = &c_ctx->content->pages[c_ctx->page]->texts;
width = text_width(ctx, text, style);
if (width == ERROR) {
- LOG_DEBUG("text_width failed.");
+ DEBUG("text_width failed.");
return false;
}
if (width > LINE_WIDTH) {
@@ -2250,20 +2250,20 @@ pdf_texts_add_text(
while (width > LINE_WIDTH) {
if (c_ctx->y < c_ctx->margin_bottom) {
if (!pdf_page_close_then_add(ctx, c_ctx, numeral_system)) {
- LOG_DEBUG("pdf_page_close_then_add failed.");
+ DEBUG("pdf_page_close_then_add failed.");
return false;
}
texts = &c_ctx->content->pages[c_ctx->page]->texts;
}
index = text_find_fitting(ctx, t, style, 0.0, LINE_WIDTH);
if (index == EMPTY_INT) {
- LOG_DEBUG("text_find_fitting failed.");
+ DEBUG("text_find_fitting failed.");
return false;
}
t[index] = 0;
width = text_width(ctx, t, style);
if (width == ERROR) {
- LOG_DEBUG("text_width failed.");
+ DEBUG("text_width failed.");
return false;
}
c_ctx->x = calc_x(width, align);
@@ -2276,7 +2276,7 @@ pdf_texts_add_text(
(*texts)[c_ctx->text]->width = width;
if (style->href) {
if (!annot_url_link_add(ctx, c_ctx, style, width)) {
- LOG_DEBUG("annot_url_link_add failed.");
+ DEBUG("annot_url_link_add failed.");
return false;
}
}
@@ -2285,13 +2285,13 @@ pdf_texts_add_text(
t += index+1;
width = text_width(ctx, t, style);
if (width == ERROR) {
- LOG_DEBUG("text_width failed.");
+ DEBUG("text_width failed.");
return false;
}
}
width = text_width(ctx, t, style);
if (width == ERROR) {
- LOG_DEBUG("text_width failed.");
+ DEBUG("text_width failed.");
return false;
}
c_ctx->x = calc_x(width, align);
@@ -2304,7 +2304,7 @@ pdf_texts_add_text(
(*texts)[c_ctx->text]->width = width;
if (style->href) {
if (!annot_url_link_add(ctx, c_ctx, style, width)) {
- LOG_DEBUG("annot_url_link_add failed.");
+ DEBUG("annot_url_link_add failed.");
return false;
}
}
@@ -2313,7 +2313,7 @@ pdf_texts_add_text(
} else {
if (c_ctx->y < c_ctx->margin_bottom) {
if (!pdf_page_close_then_add(ctx, c_ctx, numeral_system)) {
- LOG_DEBUG("pdf_page_close_then_add failed.");
+ DEBUG("pdf_page_close_then_add failed.");
return false;
}
texts = &c_ctx->content->pages[c_ctx->page]->texts;
@@ -2328,7 +2328,7 @@ pdf_texts_add_text(
(*texts)[c_ctx->text]->width = width;
if (style->href) {
if (!annot_url_link_add(ctx, c_ctx, style, width)) {
- LOG_DEBUG("annot_url_link_add failed.");
+ DEBUG("annot_url_link_add failed.");
return false;
}
}
@@ -2350,7 +2350,7 @@ find_biggest_line_item_width(struct PDFContext *ctx, struct ChoLine **lines)
for (lii = (*li)->items; *lii; lii++) {
width = text_width(ctx, (*lii)->u.text->text, (*lii)->u.text->style);
if (width == -1) {
- LOG_DEBUG("text_width failed.");
+ DEBUG("text_width failed.");
return -1;
}
if (width > biggest) {
@@ -2381,7 +2381,7 @@ pdf_toc_create(
texts = &ctx->t_ctx.content->pages[ctx->t_ctx.page]->texts;
if (ctx->config->output->page_no->show) {
if (!pdf_page_add_page_no(ctx, &ctx->t_ctx, NUMERAL_SYSTEM_ROMAN)) {
- LOG_DEBUG("pdf_page_add_page_no failed.");
+ DEBUG("pdf_page_add_page_no failed.");
return false;
}
}
@@ -2390,23 +2390,23 @@ pdf_toc_create(
max_song_title_width = LINE_WIDTH * 0.85;
toc_page_count = pdf_toc_page_count(ctx, toc, toc_style, max_song_title_width);
if (toc_page_count == -1) {
- LOG_DEBUG("pdf_toc_page_count failed.");
+ DEBUG("pdf_toc_page_count failed.");
return false;
}
title_style = ctx->config->output->styles[TEXT_TYPE_TOC_TITLE];
if (!pdf_texts_add_text(ctx, &ctx->t_ctx, ctx->config->output->toc->title, title_style, ALIGNMENT_CENTER, NUMERAL_SYSTEM_ROMAN)) {
- LOG_DEBUG("pdf_texts_add_text(toctitle) failed.");
+ DEBUG("pdf_texts_add_text(toctitle) failed.");
return false;
}
ctx->t_ctx.y -= 30.0;
dot_width = text_width(ctx, ".", toc_style);
if (dot_width == ERROR) {
- LOG_DEBUG("text_width failed.");
+ DEBUG("text_width failed.");
return false;
}
for (; *toc; toc++) {
if (!pdf_texts_add_toc_entry(ctx, *toc, toc_style, max_song_title_width, toc_page_count, dot_width)) {
- LOG_DEBUG("pdf_texts_add_toc_entry failed.");
+ DEBUG("pdf_texts_add_toc_entry failed.");
return false;
}
}
@@ -2451,7 +2451,7 @@ pdf_body_create(
diagrams = &ctx->b_ctx.content->pages[ctx->b_ctx.page]->diagrams;
if (ctx->config->output->page_no->show) {
if (!pdf_page_add_page_no(ctx, &ctx->b_ctx, NUMERAL_SYSTEM_WESTERN_ARABIC)) {
- LOG_DEBUG("pdf_page_add_page_no failed.");
+ DEBUG("pdf_page_add_page_no failed.");
return false;
}
}
@@ -2473,7 +2473,7 @@ pdf_body_create(
}
}
if (!cho_metadata_value(songs[s]->metadata, "title", ctx->config->metadata_separator, &metadata, &metadata_style)) {
- LOG_DEBUG("cho_metadata_value failed.");
+ DEBUG("cho_metadata_value failed.");
return false;
}
ctx->b_ctx.content->toc = erealloc(ctx->b_ctx.content->toc, (ctx->b_ctx.toc_entry+1) * sizeof(struct TocEntry *));
@@ -2483,14 +2483,14 @@ pdf_body_create(
ctx->b_ctx.content->toc[ctx->b_ctx.toc_entry]->page_y = ctx->b_ctx.y;
ctx->b_ctx.toc_entry++;
if (!pdf_texts_add_text(ctx, &ctx->b_ctx, metadata, metadata_style, ALIGNMENT_CENTER, NUMERAL_SYSTEM_WESTERN_ARABIC)) {
- LOG_DEBUG("pdf_texts_add_text(title) failed.");
+ DEBUG("pdf_texts_add_text(title) failed.");
free(metadata);
return false;
}
free(metadata);
if (cho_metadata_value(songs[s]->metadata, "subtitle", ctx->config->metadata_separator, &metadata, &metadata_style)) {
if (!pdf_texts_add_text(ctx, &ctx->b_ctx, metadata, metadata_style, ALIGNMENT_CENTER, NUMERAL_SYSTEM_WESTERN_ARABIC)) {
- LOG_DEBUG("pdf_texts_add_text(subtitle) failed.");
+ DEBUG("pdf_texts_add_text(subtitle) failed.");
free(metadata);
return false;
}
@@ -2503,7 +2503,7 @@ pdf_body_create(
for (se = songs[s]->sections; *se; se++) {
if ((*se)->label) {
if (!pdf_texts_add_text(ctx, &ctx->b_ctx, (*se)->label->text, (*se)->label->style, ALIGNMENT_LEFT, NUMERAL_SYSTEM_WESTERN_ARABIC)) {
- LOG_DEBUG("pdf_texts_add_text(label) failed.");
+ DEBUG("pdf_texts_add_text(label) failed.");
return false;
}
texts = &ctx->b_ctx.content->pages[ctx->b_ctx.page]->texts;
@@ -2517,7 +2517,7 @@ pdf_body_create(
biggest_line_item_width = find_biggest_line_item_width(ctx, (*se)->lines);
if (biggest_line_item_width == -1) {
- LOG_DEBUG("find_biggest_line_item_width failed.");
+ DEBUG("find_biggest_line_item_width failed.");
return false;
}
for (li = (*se)->lines; *li; li++) {
@@ -2557,7 +2557,7 @@ pdf_body_create(
ctx->b_ctx.biggest_font_size = 0.0;
ctx->b_ctx.prev_added_space = 0.0;
if (!calc_space_between_text_above(ctx, left_items, left_aboves, img_objs, &ctx->b_ctx.spaces)) {
- LOG_DEBUG("calc_space_between_text_above failed.");
+ DEBUG("calc_space_between_text_above failed.");
return false;
}
pos = items_find_position_to_break_line(ctx, left_items, ctx->b_ctx.spaces, img_objs);
@@ -2568,7 +2568,7 @@ pdf_body_create(
item_index = pos->line_item_index;
text_above_index = text_above_find_index_to_break_line(left_items, left_aboves, pos);
if (text_above_index == -2) {
- LOG_DEBUG("text_above_find_index_to_break_line failed.");
+ DEBUG("text_above_find_index_to_break_line failed.");
return false;
}
if (text_above_index == -1) {
@@ -2580,7 +2580,7 @@ pdf_body_create(
width = line_width_until_text_above(ctx, left_items, left_aboves[i], img_objs, NULL);
if (width == ERROR) {
- LOG_DEBUG("line_width_until_text_above failed.");
+ DEBUG("line_width_until_text_above failed.");
return false;
}
ctx->b_ctx.x = MARGIN_HORIZONTAL + width + ctx->b_ctx.prev_added_space;
@@ -2605,12 +2605,12 @@ pdf_body_create(
(*texts)[ctx->b_ctx.text]->style = style;
(*texts)[ctx->b_ctx.text]->width = text_width(ctx, string, style);
if ((*texts)[ctx->b_ctx.text]->width == ERROR) {
- LOG_DEBUG("text_width failed.");
+ DEBUG("text_width failed.");
return false;
}
if (style->href) {
if (!annot_url_link_add(ctx, &ctx->b_ctx, style, (*texts)[ctx->b_ctx.text]->width)) {
- LOG_DEBUG("annot_url_link_add failed.");
+ DEBUG("annot_url_link_add failed.");
return false;
}
}
@@ -2621,7 +2621,7 @@ pdf_body_create(
}
height = images_find_biggest_height(ctx, left_items, pos->line_item_index, img_objs);
if (height == ERROR) {
- LOG_DEBUG("images_find_biggest_height failed.");
+ DEBUG("images_find_biggest_height failed.");
return false;
}
text_above_exist = i > 0;
@@ -2656,7 +2656,7 @@ pdf_body_create(
}
}
if (!pdf_page_close_then_add(ctx, &ctx->b_ctx, NUMERAL_SYSTEM_WESTERN_ARABIC)) {
- LOG_DEBUG("pdf_page_close_then_add failed.");
+ DEBUG("pdf_page_close_then_add failed.");
free(tmp);
return false;
}
@@ -2687,7 +2687,7 @@ pdf_body_create(
while (*left_items && i < item_index) {
if ((*left_items)->is_text) {
if (!pdf_texts_add_lyrics(ctx, *left_items, i)) {
- LOG_DEBUG("pdf_texts_add_lyrics failed.");
+ DEBUG("pdf_texts_add_lyrics failed.");
return false;
}
texts = &ctx->b_ctx.content->pages[ctx->b_ctx.page]->texts;
@@ -2698,12 +2698,12 @@ pdf_body_create(
(*imgs)[ctx->b_ctx.image] = pdf_image_new();
(*imgs)[ctx->b_ctx.image]->name = image_name(ctx, (*left_items)->u.image);
if (!(*imgs)[ctx->b_ctx.image]->name) {
- LOG_DEBUG("image_name failed.");
+ DEBUG("image_name failed.");
return false;
}
(*imgs)[ctx->b_ctx.image]->obj = objs_get_obj(img_objs, (*imgs)[ctx->b_ctx.image]->name);
if (!(*imgs)[ctx->b_ctx.image]->obj) {
- LOG_DEBUG("objs_get_obj failed.");
+ DEBUG("objs_get_obj failed.");
return false;
}
(*imgs)[ctx->b_ctx.image]->width = image_width((*left_items)->u.image, (*imgs)[ctx->b_ctx.image]->obj);
@@ -2723,7 +2723,7 @@ pdf_body_create(
(*left_items)->u.text->text[pos->text_index] = 0;
tmp = strdup(&(*left_items)->u.text->text[pos->text_index+1]);
if (!pdf_texts_add_lyrics(ctx, *left_items, i)) {
- LOG_DEBUG("pdf_texts_add_lyrics failed.");
+ DEBUG("pdf_texts_add_lyrics failed.");
free(tmp);
return false;
}
@@ -2740,12 +2740,12 @@ pdf_body_create(
(*imgs)[ctx->b_ctx.image] = pdf_image_new();
(*imgs)[ctx->b_ctx.image]->name = image_name(ctx, (*left_items)->u.image);
if (!(*imgs)[ctx->b_ctx.image]->name) {
- LOG_DEBUG("image_name failed.");
+ DEBUG("image_name failed.");
return false;
}
(*imgs)[ctx->b_ctx.image]->obj = objs_get_obj(img_objs, (*imgs)[ctx->b_ctx.image]->name);
if (!(*imgs)[ctx->b_ctx.image]->obj) {
- LOG_DEBUG("objs_get_obj failed.");
+ DEBUG("objs_get_obj failed.");
return false;
}
(*imgs)[ctx->b_ctx.image]->width = image_width((*left_items)->u.image, (*imgs)[ctx->b_ctx.image]->obj);
@@ -2759,7 +2759,7 @@ pdf_body_create(
ctx->b_ctx.y -= 8.0 + ctx->b_ctx.biggest_font_size;
if (ctx->b_ctx.y < ctx->b_ctx.margin_bottom) {
if (!pdf_page_close_then_add(ctx, &ctx->b_ctx, NUMERAL_SYSTEM_WESTERN_ARABIC)) {
- LOG_DEBUG("pdf_page_close_then_add failed.");
+ DEBUG("pdf_page_close_then_add failed.");
return false;
}
texts = &ctx->b_ctx.content->pages[ctx->b_ctx.page]->texts;
@@ -2774,7 +2774,7 @@ pdf_body_create(
}
if ((*li)->btype == BREAK_TYPE_PAGE) {
if (!pdf_page_close_then_add(ctx, &ctx->b_ctx, NUMERAL_SYSTEM_WESTERN_ARABIC)) {
- LOG_DEBUG("pdf_page_close_then_add failed.");
+ DEBUG("pdf_page_close_then_add failed.");
return false;
}
texts = &ctx->b_ctx.content->pages[ctx->b_ctx.page]->texts;
@@ -2786,7 +2786,7 @@ pdf_body_create(
}
if (start_song_on_new_page) {
if (!pdf_page_close_then_add(ctx, &ctx->b_ctx, NUMERAL_SYSTEM_WESTERN_ARABIC)) {
- LOG_DEBUG("pdf_page_close_then_add failed.");
+ DEBUG("pdf_page_close_then_add failed.");
return false;
}
texts = &ctx->b_ctx.content->pages[ctx->b_ctx.page]->texts;
@@ -2827,17 +2827,17 @@ pdf_toc_render(struct PDFContext *ctx, struct PDFContent *content)
ctx->current_page_index = p;
stream = pdf_page_create(ctx, NULL, pages[p]->annots);
if (!stream) {
- LOG_DEBUG("pdf_page_create failed.");
+ DEBUG("pdf_page_create failed.");
return false;
}
for (texts = pages[p]->texts; *texts; texts++) {
if (!pdf_text_show(ctx, stream, *texts)) {
- LOG_DEBUG("pdf_text_show failed.");
+ DEBUG("pdf_text_show failed.");
return false;
}
}
if (!pdfioStreamClose(stream)) {
- LOG_DEBUG("pdfioStreamClose failed.");
+ DEBUG("pdfioStreamClose failed.");
return false;
}
}
@@ -2858,12 +2858,12 @@ pdf_body_render(struct PDFContext *ctx, struct PDFContent *content)
ctx->current_page_index = p;
stream = pdf_page_create(ctx, pages[p]->images, pages[p]->annots);
if (!stream) {
- LOG_DEBUG("pdf_page_create failed.");
+ DEBUG("pdf_page_create failed.");
return false;
}
for (texts = pages[p]->texts; *texts; texts++) {
if (!pdf_text_show(ctx, stream, *texts)) {
- LOG_DEBUG("pdf_text_show failed.");
+ DEBUG("pdf_text_show failed.");
return false;
}
}
@@ -2878,7 +2878,7 @@ pdf_body_render(struct PDFContext *ctx, struct PDFContent *content)
(*imgs)->height
)
) {
- LOG_DEBUG("pdfioContentDrawImage failed.");
+ DEBUG("pdfioContentDrawImage failed.");
return false;
}
}
@@ -2892,7 +2892,7 @@ pdf_body_render(struct PDFContext *ctx, struct PDFContent *content)
for (d = pages[p]->diagrams; *d; d++) {
if ((*d)->show) {
if (!chord_diagram_draw(ctx, stream, *d, x, y, size)) {
- LOG_DEBUG("chord_diagram_draw failed.");
+ DEBUG("chord_diagram_draw failed.");
return false;
}
x += size + padding;
@@ -2900,7 +2900,7 @@ pdf_body_render(struct PDFContext *ctx, struct PDFContent *content)
}
}
if (!pdfioStreamClose(stream)) {
- LOG_DEBUG("pdfioStreamClose failed.");
+ DEBUG("pdfioStreamClose failed.");
return false;
}
}
@@ -2943,56 +2943,56 @@ out_pdf_create(
free(dirpath);
pdf_filepath = pdf_filepath_create(&ctx, songs, cho_filepath, output_folder_or_file);
if (!pdf_filepath) {
- LOG_DEBUG("pdf_filepath_create failed.");
+ DEBUG("pdf_filepath_create failed.");
goto ERR;
}
pdf_dot_filepath = filepath_as_dot_file(pdf_filepath);
ctx.pdf_file = pdfioFileCreate(pdf_dot_filepath, "2.0", &media_box_a4, &crop_box, NULL, NULL);
if (!ctx.pdf_file) {
- LOG_DEBUG("pdfioFileCreateTemporary failed.");
+ DEBUG("pdfioFileCreateTemporary failed.");
goto ERR;
}
if (!pdf_set_title(&ctx, songs)) {
- LOG_DEBUG("pdf_set_title failed.");
+ DEBUG("pdf_set_title failed.");
goto ERR;
}
needed_fonts = fonts_get_all(songs, ctx.config);
if (!pdf_load_fonts(&ctx, needed_fonts)) {
- LOG_DEBUG("pdf_load_fonts failed.");
+ DEBUG("pdf_load_fonts failed.");
goto ERR;
}
cho_fonts_free(needed_fonts);
if (!pdf_load_images(&ctx, &img_objs, songs)) {
- LOG_DEBUG("pdf_load_images failed.");
+ DEBUG("pdf_load_images failed.");
goto ERR;
}
if (!pdf_body_create(&ctx, songs, img_objs, &pdf_body)) {
- LOG_DEBUG("pdf_body_create failed.");
+ DEBUG("pdf_body_create failed.");
goto ERR;
}
if (ctx.config->output->toc->show) {
if (!pdf_toc_create(&ctx, pdf_body, &pdf_toc)) {
- LOG_DEBUG("pdf_toc_create failed.");
+ DEBUG("pdf_toc_create failed.");
goto ERR;
}
if (!pdf_toc_render(&ctx, pdf_toc)) {
- LOG_DEBUG("pdf_toc_render failed.");
+ DEBUG("pdf_toc_render failed.");
goto ERR;
}
}
if (!pdf_body_render(&ctx, pdf_body)) {
- LOG_DEBUG("pdf_body_render failed.");
+ DEBUG("pdf_body_render failed.");
goto ERR;
}
objs_free(img_objs);
pdf_content_free(pdf_toc);
pdf_content_free(pdf_body);
if (!pdfioFileClose(ctx.pdf_file)) {
- LOG_DEBUG("pdfioFileClose failed.");
+ DEBUG("pdfioFileClose failed.");
}
objs_free(ctx.fonts);
if (rename(pdf_dot_filepath, pdf_filepath)) {
- LOG_DEBUG("rename failed.");
+ DEBUG("rename failed.");
util_log(
NULL,
0,
@@ -3011,12 +3011,12 @@ out_pdf_create(
pdf_content_free(pdf_toc);
pdf_content_free(pdf_body);
if (!pdfioFileClose(ctx.pdf_file)) {
- LOG_DEBUG("pdfioFileClose failed.");
+ DEBUG("pdfioFileClose failed.");
}
objs_free(ctx.fonts);
free(pdf_filepath);
if (unlink(pdf_dot_filepath)) {
- LOG_DEBUG("unlink failed.");
+ DEBUG("unlink failed.");
}
free(pdf_dot_filepath);
FcFini();