lorid

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

commit 2ea90d7ba13dec5ab412b5669b4849f993bd17c1
parent 497869c8d92d90d1012f517a153d10bd16cae41d
Author: nibo <nibo@relim.de>
Date:   Thu,  8 May 2025 07:09:22 +0200

Parse optional label name after the grid shape

Diffstat:
Msrc/chordpro.c | 18+++++++++++-------
Msrc/core.c | 14++++++++++++--
Msrc/core.h | 1+
3 files changed, 24 insertions(+), 9 deletions(-)

diff --git a/src/chordpro.c b/src/chordpro.c @@ -382,9 +382,9 @@ cho_rgbcolor_copy(struct RGBColor *color) static const char * cho_rgbcolor_to_string(struct RGBColor *color) { - static char str[8]; - str[7] = 0; - snprintf((char *)&str, 8, "#%02X%02X%02X", color->red, color->green, color->blue); + constexpr int str_len = 8; + static char str[str_len]; + snprintf((char *)&str, str_len, "#%02X%02X%02X", color->red, color->green, color->blue); return (const char *)&str; } @@ -5370,8 +5370,8 @@ cho_songs_parse(const char *str, const char *chordpro_filepath, struct Config *c ctx.songs[ctx.so]->sections[ctx.se] = cho_section_new(); ctx.songs[ctx.so]->sections[ctx.se]->type = directive->stype; - if (strstr(directive_value, "=")) { - attrs = cho_attrs_parse(&ctx, directive_value); + if (strchr(stripped_directive_value, '=')) { + attrs = cho_attrs_parse(&ctx, stripped_directive_value); if (!attrs) { LOG_DEBUG("cho_attrs_parse failed."); return NULL; @@ -5388,7 +5388,11 @@ cho_songs_parse(const char *str, const char *chordpro_filepath, struct Config *c } } else { if (directive->stype == ST_GRID) { - // TODO: Parse the optional label name after the shape + int index = str_index_of(stripped_directive_value, ' '); + if (index != -1) { + stripped_directive_value[index] = 0; + 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."); return NULL; @@ -5620,7 +5624,7 @@ cho_songs_parse(const char *str, const char *chordpro_filepath, struct Config *c break; } case DT_IMAGE: { - if (strstr(directive_value, "=")) { + if (strchr(directive_value, '=')) { image = cho_image_directive_parse(&ctx, directive_value); if (!image) { LOG_DEBUG("cho_image_directive_parse failed."); diff --git a/src/core.c b/src/core.c @@ -7,7 +7,6 @@ #include <string.h> #include <sys/stat.h> #include <errno.h> -#include <assert.h> #include <limits.h> #include "core.h" @@ -271,7 +270,6 @@ str_compare(const char *a, const char *b) if (!a && b) { return -1; } - assert(false); } long @@ -289,6 +287,18 @@ str_to_number(const char *str) return n; } +int +str_index_of(const char *str, char c) +{ + const char *s; + for (s = str; *s; s++) { + if (*s == c) { + return s - str; + } + } + return -1; +} + bool strs_has(char **strs, const char *str) { diff --git a/src/core.h b/src/core.h @@ -394,6 +394,7 @@ char *str_trim(const char *str); char *str_remove_leading_whitespace(const char *str); int str_compare(const char *a, const char *b); long str_to_number(const char *str); +int str_index_of(const char *str, char c); bool strs_has(char **strs, const char *str); void strs_add(char ***strs, const char *str);