lorid

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

commit e50e80b8700cdb60c19e1b349f531acb6a9b4015
parent 85c18bb7a27e89e81540859ae616e80e2544bad3
Author: nibo <nibo@relim.de>
Date:   Fri, 11 Oct 2024 17:41:48 +0200

Start implementing 'image' directive

Diffstat:
Mchordpro.c | 69++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------
Mchordpro.h | 5+++++
2 files changed, 61 insertions(+), 13 deletions(-)

diff --git a/chordpro.c b/chordpro.c @@ -2007,18 +2007,50 @@ static void cho_image_free(struct ChoImage *image) free(image); } -enum OptionState { - OS_NAME, - OS_VALUE -}; +static bool cho_image_option_check(struct ChoImage *image, const char *name, const char *value) +{ + size_t value_len = strlen(value); + if (!strcmp(name, "id")) { + image->id = strdup(value); + } else + if (!strcmp(name, "src")) { + image->src = strdup(value); + } else + if (!strcmp(name, "width")) { + if (value[value_len-1] == '%') { + short p = str_parse_as_percent(value); + if (p == -1) { + LOG_DEBUG("str_parse_as_percent failed."); + cho_log(LOG_ERR, "Invalid percentage."); + return false; + } + printf("p: %d\n", p); + } + } else + if (!strcmp(name, "height")) { + } else + if (!strcmp(name, "scale")) { + } else + if (!strcmp(name, "align")) { + } else + if (!strcmp(name, "border")) { + } else + if (!strcmp(name, "spread")) { + } else + if (!strcmp(name, "href")) { + } else + if (!strcmp(name, "x")) { + } else + if (!strcmp(name, "y")) { + } else + if (!strcmp(name, "anchor")) { + } + return true; +} static struct ChoImage *cho_image_directive_parse(const char *str) { struct ChoImage *image = cho_image_new(); - int i = 0; - while (is_whitespace(str[i])) { - i++; - } char c; enum OptionState state = OS_NAME; enum AttrValueSyntax avs = AVS_NO; @@ -2028,7 +2060,8 @@ static struct ChoImage *cho_image_directive_parse(const char *str) int v = 0; memset(name, 0, sizeof(name)); memset(value, 0, sizeof(value)); - for (; str[i] != 0; i++) { + int i; + for (i = 0; str[i] != 0; i++) { c = str[i]; switch (state) { case OS_NAME: @@ -2043,8 +2076,8 @@ static struct ChoImage *cho_image_directive_parse(const char *str) } if (c == '=') { name[n] = 0; - memset(name, 0, n); - n = 0; + // memset(name, 0, n); + // n = 0; state = OS_VALUE; break; } @@ -2082,8 +2115,14 @@ static struct ChoImage *cho_image_directive_parse(const char *str) (avs == AVS_UNQUOTED && (c == ' ' || c == '\t')) ) { value[v] = 0; - printf("value: '%s'\n", value); + printf("'%s' -> '%s'\n", name, value); + if (!cho_image_option_check(image, name, value)) { + LOG_DEBUG("cho_image_option_check failed."); + return NULL; + } + memset(name, 0, n); memset(value, 0, v); + n = 0; v = 0; avs = AVS_NO; state = OS_NAME; @@ -2096,7 +2135,11 @@ static struct ChoImage *cho_image_directive_parse(const char *str) } if (avs == AVS_UNQUOTED) { value[v] = 0; - printf("value: '%s'\n", value); + printf("'%s' -> '%s'\n", name, value); + if (!cho_image_option_check(image, name, value)) { + LOG_DEBUG("cho_image_option_check failed."); + return NULL; + } } return image; } diff --git a/chordpro.h b/chordpro.h @@ -133,6 +133,11 @@ enum Anchor { AN_FLOAT }; +enum OptionState { + OS_NAME, + OS_VALUE +}; + struct ChoImage { char *id; char *src;