mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-03-31 07:11:09 -04:00
config: rename str_to_double() -> value_to_double()
* str_to_double() -> value_to_double() * str_to_pt_or_px() -> value_to_pt_or_px()
This commit is contained in:
parent
922490217e
commit
5fb86859df
1 changed files with 22 additions and 28 deletions
50
config.c
50
config.c
|
|
@ -450,8 +450,10 @@ value_to_ulong(struct context *ctx, int base, unsigned long *res)
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool NOINLINE
|
static bool NOINLINE
|
||||||
str_to_double(const char *s, double *res)
|
value_to_double(struct context *ctx, double *res)
|
||||||
{
|
{
|
||||||
|
const char *s = ctx->value;
|
||||||
|
|
||||||
if (s == NULL)
|
if (s == NULL)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
|
@ -545,9 +547,13 @@ out:
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool NOINLINE
|
static bool NOINLINE
|
||||||
str_to_pt_or_px(const char *s, struct pt_or_px *res, struct config *conf,
|
value_to_pt_or_px(struct context *ctx, struct pt_or_px *res)
|
||||||
const char *path, int lineno, const char *section, const char *key)
|
|
||||||
{
|
{
|
||||||
|
/* TODO: remove! */
|
||||||
|
struct config *conf = ctx->conf;
|
||||||
|
|
||||||
|
const char *s = ctx->value;
|
||||||
|
|
||||||
size_t len = s != NULL ? strlen(s) : 0;
|
size_t len = s != NULL ? strlen(s) : 0;
|
||||||
if (len >= 2 && s[len - 2] == 'p' && s[len - 1] == 'x') {
|
if (len >= 2 && s[len - 2] == 'p' && s[len - 1] == 'x') {
|
||||||
errno = 0;
|
errno = 0;
|
||||||
|
|
@ -558,17 +564,17 @@ str_to_pt_or_px(const char *s, struct pt_or_px *res, struct config *conf,
|
||||||
LOG_AND_NOTIFY_ERR(
|
LOG_AND_NOTIFY_ERR(
|
||||||
"%s:%d: [%s].%s: %s: invalid px value "
|
"%s:%d: [%s].%s: %s: invalid px value "
|
||||||
"(must be on the form 12px)",
|
"(must be on the form 12px)",
|
||||||
path, lineno, section, key, s);
|
ctx->path, ctx->lineno, ctx->section, ctx->key, ctx->value);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
res->pt = 0;
|
res->pt = 0;
|
||||||
res->px = value;
|
res->px = value;
|
||||||
} else {
|
} else {
|
||||||
double value;
|
double value;
|
||||||
if (!str_to_double(s, &value)) {
|
if (!value_to_double(ctx, &value)) {
|
||||||
LOG_AND_NOTIFY_ERR(
|
LOG_AND_NOTIFY_ERR(
|
||||||
"%s:%d: [%s].%s: %s: invalid decimal value",
|
"%s:%d: [%s].%s: %s: invalid decimal value",
|
||||||
path, lineno, section, key, s);
|
ctx->path, ctx->lineno, ctx->section, ctx->key, ctx->value);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
res->pt = value;
|
res->pt = value;
|
||||||
|
|
@ -941,35 +947,27 @@ parse_section_main(struct context *ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (strcmp(key, "line-height") == 0) {
|
else if (strcmp(key, "line-height") == 0) {
|
||||||
if (!str_to_pt_or_px(value, &conf->line_height,
|
if (!value_to_pt_or_px(ctx, &conf->line_height))
|
||||||
conf, path, lineno, "main", "line-height"))
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (strcmp(key, "letter-spacing") == 0) {
|
else if (strcmp(key, "letter-spacing") == 0) {
|
||||||
if (!str_to_pt_or_px(value, &conf->letter_spacing,
|
if (!value_to_pt_or_px(ctx, &conf->letter_spacing))
|
||||||
conf, path, lineno, "main", "letter-spacing"))
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (strcmp(key, "horizontal-letter-offset") == 0) {
|
else if (strcmp(key, "horizontal-letter-offset") == 0) {
|
||||||
if (!str_to_pt_or_px(
|
if (!value_to_pt_or_px(ctx, &conf->horizontal_letter_offset))
|
||||||
value, &conf->horizontal_letter_offset,
|
|
||||||
conf, path, lineno, "main", "horizontal-letter-offset"))
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (strcmp(key, "vertical-letter-offset") == 0) {
|
else if (strcmp(key, "vertical-letter-offset") == 0) {
|
||||||
if (!str_to_pt_or_px(
|
if (!value_to_pt_or_px(ctx, &conf->vertical_letter_offset))
|
||||||
value, &conf->vertical_letter_offset,
|
|
||||||
conf, path, lineno, "main", "vertical-letter-offset"))
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (strcmp(key, "underline-offset") == 0) {
|
else if (strcmp(key, "underline-offset") == 0) {
|
||||||
if (!str_to_pt_or_px(
|
if (!value_to_pt_or_px(ctx, &conf->underline_offset))
|
||||||
value, &conf->underline_offset,
|
|
||||||
conf, path, lineno, "main", "underline-offset"))
|
|
||||||
return false;
|
return false;
|
||||||
conf->use_custom_underline_offset = true;
|
conf->use_custom_underline_offset = true;
|
||||||
}
|
}
|
||||||
|
|
@ -1180,7 +1178,7 @@ parse_section_scrollback(struct context *ctx)
|
||||||
|
|
||||||
else if (strcmp(key, "multiplier") == 0) {
|
else if (strcmp(key, "multiplier") == 0) {
|
||||||
double multiplier;
|
double multiplier;
|
||||||
if (!str_to_double(value, &multiplier)) {
|
if (!value_to_double(ctx, &multiplier)) {
|
||||||
LOG_AND_NOTIFY_ERR(
|
LOG_AND_NOTIFY_ERR(
|
||||||
"%s:%d: [scrollback].multiplier: %s: invalid decimal value",
|
"%s:%d: [scrollback].multiplier: %s: invalid decimal value",
|
||||||
path, lineno, value);
|
path, lineno, value);
|
||||||
|
|
@ -1394,7 +1392,7 @@ parse_section_colors(struct context *ctx)
|
||||||
|
|
||||||
else if (strcmp(key, "alpha") == 0) {
|
else if (strcmp(key, "alpha") == 0) {
|
||||||
double alpha;
|
double alpha;
|
||||||
if (!str_to_double(value, &alpha) || alpha < 0. || alpha > 1.) {
|
if (!value_to_double(ctx, &alpha) || alpha < 0. || alpha > 1.) {
|
||||||
LOG_AND_NOTIFY_ERR(
|
LOG_AND_NOTIFY_ERR(
|
||||||
"%s:%d: [colors].alpha: %s: "
|
"%s:%d: [colors].alpha: %s: "
|
||||||
"invalid decimal value, or not in range 0.0-1.0",
|
"invalid decimal value, or not in range 0.0-1.0",
|
||||||
|
|
@ -1463,16 +1461,12 @@ parse_section_cursor(struct context *ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (strcmp(key, "beam-thickness") == 0) {
|
else if (strcmp(key, "beam-thickness") == 0) {
|
||||||
if (!str_to_pt_or_px(
|
if (!value_to_pt_or_px(ctx, &conf->cursor.beam_thickness))
|
||||||
value, &conf->cursor.beam_thickness,
|
|
||||||
conf, path, lineno, "cursor", "beam-thickness"))
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (strcmp(key, "underline-thickness") == 0) {
|
else if (strcmp(key, "underline-thickness") == 0) {
|
||||||
if (!str_to_pt_or_px(
|
if (!value_to_pt_or_px(ctx, &conf->cursor.underline_thickness))
|
||||||
value, &conf->cursor.underline_thickness,
|
|
||||||
conf, path, lineno, "cursor", "underline-thickness"))
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -2610,7 +2604,7 @@ parse_section_tweak(struct context *ctx)
|
||||||
|
|
||||||
else if (strcmp(key, "box-drawing-base-thickness") == 0) {
|
else if (strcmp(key, "box-drawing-base-thickness") == 0) {
|
||||||
double base_thickness;
|
double base_thickness;
|
||||||
if (!str_to_double(value, &base_thickness)) {
|
if (!value_to_double(ctx, &base_thickness)) {
|
||||||
LOG_AND_NOTIFY_ERR(
|
LOG_AND_NOTIFY_ERR(
|
||||||
"%s:%d: [tweak].box-drawing-base-thickness: %s: "
|
"%s:%d: [tweak].box-drawing-base-thickness: %s: "
|
||||||
"invalid decimal value", path, lineno, value);
|
"invalid decimal value", path, lineno, value);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue