From a11bf8bb6c1baaef51c25d441f5348567280967b Mon Sep 17 00:00:00 2001 From: frosty Date: Tue, 10 Mar 2026 02:32:51 -0400 Subject: those who commit --- src/Infobox/Calculator.c | 41 ++++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 19 deletions(-) (limited to 'src/Infobox/Calculator.c') diff --git a/src/Infobox/Calculator.c b/src/Infobox/Calculator.c index 22563f7..16bc4fa 100644 --- a/src/Infobox/Calculator.c +++ b/src/Infobox/Calculator.c @@ -1,9 +1,9 @@ #include "Calculator.h" +#include +#include #include #include #include -#include -#include static char logic_log[4096]; @@ -15,7 +15,8 @@ typedef struct { static double parse_expression(Parser *p); static void skip_ws(Parser *p) { - while (p->buffer[p->pos] == ' ') p->pos++; + while (p->buffer[p->pos] == ' ') + p->pos++; } static double parse_factor(Parser *p) { @@ -27,7 +28,8 @@ static double parse_factor(Parser *p) { if (p->buffer[p->pos] == '(') { p->pos++; double res = parse_expression(p); - if (p->buffer[p->pos] == ')') p->pos++; + if (p->buffer[p->pos] == ')') + p->pos++; return res; } char *endptr; @@ -50,7 +52,7 @@ static double parse_term(Parser *p) { char step[256]; snprintf(step, sizeof(step), "
%g %c %g = %g
", old, op, - right, left); + right, left); strncat(logic_log, step, sizeof(logic_log) - strlen(logic_log) - 1); } else break; @@ -72,7 +74,7 @@ static double parse_expression(Parser *p) { char step[256]; snprintf(step, sizeof(step), "
%g %c %g = %g
", old, op, - right, left); + right, left); strncat(logic_log, step, sizeof(logic_log) - strlen(logic_log) - 1); } else break; @@ -82,33 +84,34 @@ static double parse_expression(Parser *p) { double evaluate(const char *expr) { logic_log[0] = '\0'; - if (!expr || strlen(expr) == 0) return 0.0; + if (!expr || strlen(expr) == 0) + return 0.0; Parser p = {expr, 0}; return parse_expression(&p); } InfoBox fetch_calc_data(char *math_input) { InfoBox info = {NULL, NULL, NULL, NULL}; - if (!math_input) return info; + if (!math_input) + return info; double result = evaluate(math_input); char html_output[5120]; snprintf(html_output, sizeof(html_output), - "
" - "%s" - "
" - "%g" - "
" - "
", - strlen(logic_log) > 0 ? logic_log : "
Constant value
", - result); + "
" + "%s" + "
" + "%g" + "
" + "
", + strlen(logic_log) > 0 ? logic_log : "
Constant value
", + result); info.title = strdup("Calculation"); info.extract = strdup(html_output); - info.thumbnail_url = - strdup("/static/calculation.svg"); + info.thumbnail_url = strdup("/static/calculation.svg"); info.url = strdup("#"); return info; -- cgit v1.2.3