summaryrefslogtreecommitdiff
path: root/rushs/evalexpr/variant
diff options
context:
space:
mode:
authorMartial Simon <msimon_fr@hotmail.com>2025-10-11 22:19:00 +0200
committerMartial Simon <msimon_fr@hotmail.com>2025-10-11 22:19:00 +0200
commit73c2b00a10c5786ddeeacc915e233fd4df1c9321 (patch)
treee299ea4e8ac161b2b21170172ff8f182c1c3fe1a /rushs/evalexpr/variant
parentc9b6b9a5ca082fe7c1b6f58d7713f785a9eb6a5c (diff)
fix: evalexpr & tinyprintf contenaient toute la piscine
Diffstat (limited to 'rushs/evalexpr/variant')
-rw-r--r--rushs/evalexpr/variant/variant.c96
-rw-r--r--rushs/evalexpr/variant/variant.h35
2 files changed, 0 insertions, 131 deletions
diff --git a/rushs/evalexpr/variant/variant.c b/rushs/evalexpr/variant/variant.c
deleted file mode 100644
index eb2f8a8..0000000
--- a/rushs/evalexpr/variant/variant.c
+++ /dev/null
@@ -1,96 +0,0 @@
-#include "variant.h"
-
-#include <stdio.h>
-#include <string.h>
-
-void variant_display(const struct variant *e)
-{
- switch (e->type)
- {
- case (TYPE_INT):
- printf("%d\n", e->value.int_v);
- break;
- case (TYPE_FLOAT):
- printf("%f\n", e->value.float_v);
- break;
- case (TYPE_CHAR):
- printf("%c\n", e->value.char_v);
- break;
- default:
- printf("%s\n", e->value.str_v);
- break;
- }
-}
-
-bool variant_equal(const struct variant *left, const struct variant *right)
-{
- if (left == NULL || right == NULL)
- {
- return true;
- }
- switch (left->type)
- {
- case (TYPE_INT):
- if (right->type != TYPE_INT)
- {
- return false;
- }
- return left->value.int_v == right->value.int_v;
- case (TYPE_FLOAT):
- if (right->type != TYPE_FLOAT)
- {
- return false;
- }
- return left->value.float_v == right->value.float_v;
- case (TYPE_CHAR):
- if (right->type != TYPE_CHAR)
- {
- return false;
- }
- return left->value.char_v == right->value.char_v;
- default:
- if (right->type != TYPE_STRING)
- {
- return false;
- }
- return strcmp(left->value.str_v, right->value.str_v) == 0;
- }
-}
-
-int variant_find(const struct variant *array, size_t len, enum type type,
- union type_any value)
-{
- size_t i;
- struct variant cmp = { type, value };
- for (i = 0; i < len && variant_equal(array + i, &cmp) == false; i++)
- {
- continue;
- }
-
- if (i == len)
- {
- return -1;
- }
- return i;
-}
-
-float variant_sum(const struct variant *array, size_t len)
-{
- if (array == NULL)
- {
- return 0;
- }
- float sum = 0;
- for (size_t i = 0; i < len; i++)
- {
- if (array[i].type == TYPE_FLOAT)
- {
- sum += array[i].value.float_v;
- }
- else if (array[i].type == TYPE_INT)
- {
- sum += array[i].value.int_v;
- }
- }
- return sum;
-}
diff --git a/rushs/evalexpr/variant/variant.h b/rushs/evalexpr/variant/variant.h
deleted file mode 100644
index 9983bc1..0000000
--- a/rushs/evalexpr/variant/variant.h
+++ /dev/null
@@ -1,35 +0,0 @@
-#ifndef VARIANT_H
-#define VARIANT_H
-
-#include <stdbool.h>
-#include <stddef.h>
-
-enum type
-{
- TYPE_INT,
- TYPE_FLOAT,
- TYPE_CHAR,
- TYPE_STRING
-};
-
-union type_any
-{
- int int_v;
- float float_v;
- char char_v;
- const char *str_v;
-};
-
-struct variant
-{
- enum type type;
- union type_any value;
-};
-
-void variant_display(const struct variant *e);
-bool variant_equal(const struct variant *left, const struct variant *right);
-int variant_find(const struct variant *array, size_t len, enum type type,
- union type_any value);
-float variant_sum(const struct variant *array, size_t len);
-
-#endif /* !VARIANT_H */