lorid

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

commit 994d27a8c96a4dbe0545f4b0bbc4f1ba6d55a27f
parent d2ed7d2819772fd65b44195bfb5dfe822772610c
Author: nibo <nibo@relim.de>
Date:   Sun, 23 Feb 2025 18:29:37 +0100

Support metadata subtitution inside directive values

Diffstat:
Msrc/chordpro.c | 18++++++++++++++++--
1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/src/chordpro.c b/src/chordpro.c @@ -5231,6 +5231,11 @@ cho_songs_parse(const char *str, const char *chordpro_filepath, struct Config *c ctx.state = STATE_LYRICS; break; } + if (c == '%') { + ctx.state_before_metadata_substitution = STATE_DIRECTIVE_VALUE; + ctx.state = STATE_MAYBE_METADATA_SUBSTITUTION; + break; + } if (c == '<') { ctx.state_before_tag = STATE_DIRECTIVE_VALUE; ctx.state = STATE_MARKUP_TAG; @@ -5848,6 +5853,10 @@ cho_songs_parse(const char *str, const char *chordpro_filepath, struct Config *c (*lines)[ctx.li]->items[ctx.lii]->u.text->text[ctx.te] = '%'; ctx.te++; break; + case STATE_DIRECTIVE_VALUE: + directive_value[ctx.dv] = '%'; + ctx.dv++; + break; default: } ctx.state = ctx.state_before_metadata_substitution; @@ -5871,16 +5880,21 @@ cho_songs_parse(const char *str, const char *chordpro_filepath, struct Config *c LOG_DEBUG("cho_metadata_substitution_parse failed."); return NULL; } - // Append 'substituted' to whatever text + char *ch; switch (ctx.state_before_metadata_substitution) { case STATE_LYRICS: - char *ch; for (ch = substituted; *ch; ch++) { (*lines)[ctx.li]->items[ctx.lii]->u.text->text = erealloc((*lines)[ctx.li]->items[ctx.lii]->u.text->text, (ctx.te+1) * sizeof(char)); (*lines)[ctx.li]->items[ctx.lii]->u.text->text[ctx.te] = *ch; ctx.te++; } break; + case STATE_DIRECTIVE_VALUE: + for (ch = substituted; *ch; ch++) { + directive_value[ctx.dv] = *ch; + ctx.dv++; + } + break; default: } free(substituted);