lorid

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

commit fae7c6227c961afe8c694c14d7a5511b58eb60bd
parent cbc4d406d23ad19a7804069c2a79667112f962d7
Author: nibo <nibo@relim.de>
Date:   Sun, 23 Feb 2025 10:47:38 +0100

Fix line no in case of reevaluating a character

Diffstat:
Msrc/chordpro.c | 30+++++++++++++++++++-----------
Msrc/chordpro.h | 2+-
2 files changed, 20 insertions(+), 12 deletions(-)

diff --git a/src/chordpro.c b/src/chordpro.c @@ -287,23 +287,23 @@ cho_log(struct ChoContext *ctx, enum LogLevel level, const char *msg, ...) 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_number, color, log_level); + 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_number, color, log_level); + 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_number, + 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_number, log_level); + fprintf(stderr, "line %ld: %s: ", ctx->line_no, log_level); vfprintf(stderr, msg, va); fprintf(stderr, "\n"); } @@ -334,12 +334,12 @@ cho_log(struct ChoContext *ctx, enum LogLevel level, const char *msg, ...) break; } if (ctx->chordpro_filepath) { - fprintf(stderr, "%s:%ld: %s: ", ctx->chordpro_filepath, ctx->line_number, + 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_number, log_level); + fprintf(stderr, "line %ld: %s: ", ctx->line_no, log_level); vfprintf(stderr, msg, va); fprintf(stderr, "\n"); } @@ -4289,7 +4289,7 @@ cho_context_init( ctx->te = 0; ctx->th = 0; ctx->nested_level = 0; - ctx->line_number = 1; + ctx->line_no = 1; ctx->tags = NULL; ctx->image_assets = NULL; @@ -4349,9 +4349,6 @@ cho_songs_parse(const char *str, const char *chordpro_filepath, struct Config *c ctx.songs[ctx.so]->present_text_types[TT_TOC] = config->output->toc->show; for (; *str; str++) { c = *str; - if (c == '\n') { - ctx.line_number++; - } // printf("state: %s, buf: %c\n", state_enums[state], buf); if (c == '\r') { continue; @@ -4396,6 +4393,7 @@ cho_songs_parse(const char *str, const char *chordpro_filepath, struct Config *c break; } if (c == '\n') { + ctx.line_no++; if (prev_c == '\\') { ctx.state_before_backslash = STATE_LYRICS; ctx.state = STATE_BACKSLASH; @@ -4729,6 +4727,7 @@ cho_songs_parse(const char *str, const char *chordpro_filepath, struct Config *c return NULL; } if (c == '\n') { + ctx.line_no++; if (prev_c == '\\') { ctx.state_before_backslash = STATE_DIRECTIVE_NAME; ctx.state = STATE_BACKSLASH; @@ -5132,6 +5131,7 @@ cho_songs_parse(const char *str, const char *chordpro_filepath, struct Config *c return NULL; } if (c == '\n') { + ctx.line_no++; if (prev_c == '\\') { ctx.state_before_backslash = STATE_DIRECTIVE_VALUE; ctx.state = STATE_BACKSLASH; @@ -5196,6 +5196,7 @@ cho_songs_parse(const char *str, const char *chordpro_filepath, struct Config *c break; } if (c == '\n') { + ctx.line_no++; if (prev_c == '\\') { ctx.state_before_backslash = STATE_CHORD; ctx.state = STATE_BACKSLASH; @@ -5242,6 +5243,7 @@ cho_songs_parse(const char *str, const char *chordpro_filepath, struct Config *c break; } if (c == '\n') { + ctx.line_no++; if (prev_c == '\\') { ctx.state_before_backslash = STATE_ANNOTATION; ctx.state = STATE_BACKSLASH; @@ -5327,6 +5329,7 @@ cho_songs_parse(const char *str, const char *chordpro_filepath, struct Config *c break; } if (c == '\n') { + ctx.line_no++; if (prev_c == '\\') { ctx.state_before_backslash = STATE_TAB; ctx.state = STATE_BACKSLASH; @@ -5454,6 +5457,7 @@ cho_songs_parse(const char *str, const char *chordpro_filepath, struct Config *c break; } if (c == '\n') { + ctx.line_no++; if (prev_c == '\\') { ctx.state_before_backslash = STATE_MARKUP_TAG_START; ctx.state = STATE_BACKSLASH; @@ -5484,6 +5488,7 @@ cho_songs_parse(const char *str, const char *chordpro_filepath, struct Config *c break; } if (c == '\n') { + ctx.line_no++; if (prev_c == '\\') { ctx.state_before_backslash = STATE_MARKUP_TAG_END; ctx.state = STATE_BACKSLASH; @@ -5589,6 +5594,7 @@ cho_songs_parse(const char *str, const char *chordpro_filepath, struct Config *c } } if (c == '\n') { + ctx.line_no++; if (prev_c == '\\') { ctx.state_before_backslash = STATE_MARKUP_ATTR_NAME; ctx.state = STATE_BACKSLASH; @@ -5605,6 +5611,7 @@ cho_songs_parse(const char *str, const char *chordpro_filepath, struct Config *c } case STATE_MARKUP_ATTR_VALUE: { if (c == '\n') { + ctx.line_no++; if (prev_c == '\\') { ctx.state_before_backslash = STATE_MARKUP_ATTR_VALUE; ctx.state = STATE_BACKSLASH; @@ -5710,6 +5717,7 @@ cho_songs_parse(const char *str, const char *chordpro_filepath, struct Config *c } case STATE_COMMENT: { if (c == '\n') { + ctx.line_no++; ctx.state = ctx.state_before_comment; break; } @@ -5836,7 +5844,7 @@ cho_songs_parse(const char *str, const char *chordpro_filepath, struct Config *c } if (!exist_title) { /* INFO: This cho_log() is not line specific. It's a workaround. */ - ctx.line_number = 0; + ctx.line_no = 0; cho_log(&ctx, LOG_ERR, "Song has no title."); return NULL; } diff --git a/src/chordpro.h b/src/chordpro.h @@ -172,7 +172,7 @@ struct ChoContext { index_t th; // transpose_history int text_above_pos; int nested_level; - size_t line_number; + size_t line_no; int *transpose_history; int *transpose; struct ChoSong **songs;