Adding float suppotr

This commit is contained in:
AnonymusRaccoon
2019-12-09 17:40:37 +01:00
parent 13a13b0e2d
commit 58cfb25971
4 changed files with 42 additions and 4 deletions
+7 -3
View File
@@ -12,7 +12,8 @@ SRC = src/xmlparser.c \
src/xmlproperties.c \ src/xmlproperties.c \
src/rawnode.c \ src/rawnode.c \
src/xml_destroy.c \ src/xml_destroy.c \
src/xmlget.c src/xmlget.c \
src/floatutils.c
OBJ = $(SRC:%.c=%.o) OBJ = $(SRC:%.c=%.o)
@@ -60,8 +61,11 @@ fclean: clean
re: fclean all re: fclean all
dbg: CFLAGS += -g dbg: CFLAGS += -g
dbg: fclean dbg: re
dbg: $(OBJ)
main-dbg: CFLAGS += -g
main-dbg: fclean
main-dbg: $(OBJ)
$(CC) -o $(FT) $(SRC) $(TEST_MAIN) $(CFLAGS) $(LDFLAGS) $(CC) -o $(FT) $(SRC) $(TEST_MAIN) $(CFLAGS) $(LDFLAGS)
.PHONY: all build clean fclean .PHONY: all build clean fclean
+2 -1
View File
@@ -16,4 +16,5 @@ char *trimstr(char *str);
int xml_getstringdata(node *n, char **nodestr); int xml_getstringdata(node *n, char **nodestr);
int xml_checkclosing(node *n, char **nodestr); int xml_checkclosing(node *n, char **nodestr);
dictionary *property_add(dictionary *list, dictionary *property); dictionary *property_add(dictionary *list, dictionary *property);
node *xml_parsenode(char **nodestr); node *xml_parsenode(char **nodestr);
int get_int_size(int n);
+20
View File
@@ -0,0 +1,20 @@
/*
** EPITECH PROJECT, 2019
** MUL_my_runner_2019
** File description:
** floatutils
*/
#include "my.h"
int get_int_size(int n)
{
int base_size = my_strlen("0123456789");
int i = 1;
while (n >= base_size) {
n /= base_size;
i++;
}
return (i);
}
+13
View File
@@ -6,6 +6,7 @@
*/ */
#include "xml.h" #include "xml.h"
#include "xml_internal.h"
#include "my.h" #include "my.h"
#include <stddef.h> #include <stddef.h>
@@ -30,9 +31,21 @@ int xml_getintprop(node *n, const char *key)
float xml_getfloatprop(node *n, const char *key) float xml_getfloatprop(node *n, const char *key)
{ {
char *prop = xml_getproperty(n, key); char *prop = xml_getproperty(n, key);
float nbr;
int deci;
if (!prop) if (!prop)
return (0); return (0);
for (int i = 0; prop[i]; i++) {
if (!is_num(prop[i]))
return (-1);
}
nbr = (float)my_getnbr(prop);
prop += get_int_size(nbr);
if (*prop) {
deci = my_getnbr(prop + 1);
nbr += deci / (float)(get_int_size(deci) + 1);
}
return (0); return (0);
} }