aboutsummaryrefslogtreecommitdiff
path: root/expr.c
diff options
context:
space:
mode:
authorAgney Lopes Roth Ferraz <agney@debian.org>2009-03-28 22:55:02 -0300
committerSimon Quigley <tsimonq2@ubuntu.com>2017-06-19 14:38:48 -0500
commit1b6665085f47e0a86e4bebd5e313a2ab63600eb4 (patch)
tree6b7dedc1886b42d07cc48359470fe3f595500cc8 /expr.c
parent819c0c3382b06fc0f0a1679465966f811aa2e0f8 (diff)
parent4979bb6cbbbe39eb44c32530cd13f86bf44e5d77 (diff)
Import Debian changes 0.5c-1
hardinfo (0.5c-1) unstable; urgency=low * New upstream version. (Closes: #517591, #511237, #457703, #519256, #449250, #457820, #497758)
Diffstat (limited to 'expr.c')
-rw-r--r--expr.c35
1 files changed, 23 insertions, 12 deletions
diff --git a/expr.c b/expr.c
index d204859d..32e303d7 100644
--- a/expr.c
+++ b/expr.c
@@ -1,6 +1,6 @@
/*
* HardInfo - Displays System Information
- * Copyright (C) 2003-2007 Leandro A. F. Pereira <leandro@linuxmag.com.br>
+ * Copyright (C) 2003-2007 Leandro A. F. Pereira <leandro@hardinfo.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -25,7 +25,9 @@
#include <stdio.h>
#include <ctype.h>
#include <math.h>
-#include <expr.h>
+
+#include "expr.h"
+#include "config.h"
static MathToken *new_operator(gchar op)
{
@@ -90,8 +92,9 @@ GSList *math_infix_to_postfix(GSList * infix)
stack[++t_sp] = t;
} else if (t->type == TOKEN_OPERATOR && t->val.op == ')') {
for (top = stack[t_sp]; t_sp != 0 && top->val.op != '(';
- top = stack[t_sp])
- postfix = g_slist_append(postfix, stack[t_sp--]);
+ top = stack[t_sp]) {
+ postfix = g_slist_append(postfix, stack[t_sp--]);
+ }
t_sp--;
} else if (t->type != TOKEN_OPERATOR) {
postfix = g_slist_append(postfix, t);
@@ -107,7 +110,7 @@ GSList *math_infix_to_postfix(GSList * infix)
while (t_sp)
postfix = g_slist_append(postfix, stack[t_sp--]);
-
+
return postfix;
}
@@ -149,11 +152,11 @@ gfloat math_postfix_eval(GSList * postfix, gfloat at_value)
op2 = stack[sp--];
op1 = stack[sp];
-
+
stack[sp] = __result(op1, op2, t->val.op);
}
}
-
+
return stack[sp];
}
@@ -161,17 +164,25 @@ GSList *math_string_to_infix(gchar * string)
{
GSList *infix = NULL;
gchar *expr = string;
-
+
for (; *expr; expr++) {
if (strchr("+-/*^()", *expr)) {
infix = g_slist_append(infix, new_operator(*expr));
} else if (strchr("@", *expr)) {
infix = g_slist_append(infix, new_variable(*expr));
} else if (strchr("-.1234567890", *expr)) {
- gfloat value;
-
- expr += sscanf(expr, "%f", &value);
- infix = g_slist_append(infix, new_value(value));
+ gchar value[32], *v = value;
+ gfloat floatval;
+
+ do {
+ *v++ = *expr++;
+ } while (*expr && strchr("-.1234567890", *expr));
+ expr--;
+ *v = '\0';
+
+ sscanf(value, "%f", &floatval);
+
+ infix = g_slist_append(infix, new_value(floatval));
} else if (!isspace(*expr)) {
g_print("Invalid token: [%c][%d]\n", *expr, *expr);
math_infix_free(infix, TRUE);