commit 497869c8d92d90d1012f517a153d10bd16cae41d
parent 3aaf690adcd8fbbbcfa5ff37d9bb47df6995b550
Author: nibo <nibo@relim.de>
Date: Sat, 12 Apr 2025 09:34:48 +0200
Parse grid start directive
e.g.: {sog: label=some shape="5+2x8+2"}
Diffstat:
2 files changed, 19 insertions(+), 33 deletions(-)
diff --git a/src/chordpro.c b/src/chordpro.c
@@ -4824,6 +4824,14 @@ cho_grid_shape_parse_and_set(struct ChoContext *ctx, const char *str)
return true;
}
+static void
+cho_grid_shape_set_default(struct ChoContext *ctx)
+{
+ ctx->grid_shape.cells = 8;
+ ctx->grid_shape.left = 1;
+ ctx->grid_shape.right = 1;
+}
+
static bool
cho_context_init(
struct ChoContext *ctx,
@@ -4866,9 +4874,7 @@ cho_context_init(
ctx->line_no = 1;
ctx->tags = NULL;
ctx->image_assets = NULL;
- ctx->grid_shape.cells = 8;
- ctx->grid_shape.left = 1;
- ctx->grid_shape.right = 1;
+ cho_grid_shape_set_default(ctx);
ctx->transpose_history = emalloc((ctx->th+1) * sizeof(int *));
ctx->transpose_history[ctx->th] = 0;
@@ -4893,7 +4899,7 @@ struct ChoSong **
cho_songs_parse(const char *str, const char *chordpro_filepath, struct Config *config)
{
enum AttrValueSyntax avs = AVS_UNINITIALIZED;
- struct Attr **attrs;
+ struct Attr **attrs = NULL;
struct ChoStyle *tag_style;
struct StyleProperty sprop;
struct ChoChord *tmp_chord;
@@ -4904,7 +4910,8 @@ cho_songs_parse(const char *str, const char *chordpro_filepath, struct Config *c
struct ChoMetadata *metadata;
struct ChoLine ***lines;
struct ChoContext ctx;
- char *label, *metadata_value, *stripped_directive_value, *shape;
+ char *metadata_value, *stripped_directive_value, *shape;
+ char *label = NULL;
char directive_name[128];
char directive_value[4096];
char chord[15];
@@ -5077,6 +5084,9 @@ cho_songs_parse(const char *str, const char *chordpro_filepath, struct Config *c
break;
}
}
+ if (directive->stype == ST_GRID) {
+ cho_grid_shape_set_default(&ctx);
+ }
cho_line_item_free((*lines)[ctx.li]->items[ctx.lii]);
free((*lines)[ctx.li]->items);
ctx.lii = 0;
@@ -5394,34 +5404,10 @@ cho_songs_parse(const char *str, const char *chordpro_filepath, struct Config *c
ctx.current_ttype = TT_LABEL;
ctx.songs[ctx.so]->sections[ctx.se]->label->style = cho_style_new_default(&ctx);
ctx.current_ttype = ctx.prev_ttype;
+ label = NULL;
}
- /* if (directive->stype == ST_GRID) {
- if (strstr(directive_value, "=")) {
- struct Attr **the_attrs = cho_attrs_parse(&ctx, directive_value);
- struct Attr **tala;
- for (tala = the_attrs; *tala; tala++) {
- printf("attr %s = %s\n", (*tala)->name, (*tala)->value);
- }
- if (!the_attrs) {
- LOG_DEBUG("cho_attrs_parse failed.");
- return NULL;
- }
- cho_tag_attrs_free(the_attrs);
- } else {
- }
- } else {
- if (strstr(directive_value, "=")) {
- label = cho_directive_label_parse(&ctx, directive_name, directive_value);
- if (!label) {
- LOG_DEBUG("cho_directive_label_parse failed.");
- cho_log(&ctx, LOG_ERR, "Failed to parse the section label. You have to ways of specifying a label:\n\t\t\t1. {start_of_*: label=\"Label name\"}\n\t\t\t2. {start_of*: Label name}");
- return NULL;
- }
- ctx.songs[ctx.so]->sections[ctx.se]->label->text = label;
- } else {
- ctx.songs[ctx.so]->sections[ctx.se]->label->text = strdup(stripped_directive_value);
- }
- } */
+ cho_tag_attrs_free(attrs);
+ attrs = NULL;
if (ctx.directive_has_tag) {
cho_style_complement(ctx.songs[ctx.so]->sections[ctx.se]->label->style, ctx.tags[ctx.ta]->style, &ctx.tags[ctx.ta]->style_presence);
ctx.directive_has_tag = false;
diff --git a/src/config.c b/src/config.c
@@ -687,7 +687,7 @@ config_load_style(
#ifdef DEBUG
static void
-presence_print(const char *name, struct ChoStylePresence *presence)
+debug_presence_print(const char *name, struct ChoStylePresence *presence)
{
printf("---- BEGIN PRESENCE ----\n");
printf("style '%s'\n", name);