Coding style

This commit is contained in:
Tristan Roux
2019-12-09 10:41:56 +01:00
parent a2f4eec5fc
commit 235c9b5b34
7 changed files with 30 additions and 22 deletions
+2 -1
View File
@@ -11,7 +11,8 @@ SRC = src/xmlparser.c \
src/helper.c \
src/xmlproperties.c \
src/rawnode.c \
src/xml_destroy.c
src/xml_destroy.c \
src/xmlget.c
OBJ = $(SRC:%.c=%.o)
+1 -2
View File
@@ -28,6 +28,5 @@ struct node
};
node *xmlparse(char *path);
dictionary *property_add(dictionary *list, dictionary *property);
node *xml_parsenode(char **nodestr);
char *xml_getproperty(node *n, char *key);
void xml_destroy(node *n);
+3 -1
View File
@@ -14,4 +14,6 @@ char *xml_getname(char **nodestr, bool *has_parameters, bool *has_childs);
dictionary *xml_getproperties(char **nodestr, bool *can_have_child);
char *trimstr(char *str);
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);
node *xml_parsenode(char **nodestr);
+17 -15
View File
@@ -29,6 +29,14 @@ int xml_checkclosing(node *n, char **nodestr)
return (-1);
}
void xml_parsenext(node *n, char **nodestr, int depth)
{
if (depth != 0)
n->next = xml_parsenode(nodestr);
else
n->next = NULL;
}
int xml_parsechild(node *n, char **nodestr, bool has_child)
{
char endname[my_strlen(n->name + 3)];
@@ -50,10 +58,7 @@ int xml_parsechild(node *n, char **nodestr, bool has_child)
depth--;
} else
n->child = NULL;
if (depth != 0)
n->next = xml_parsenode(nodestr);
else
n->next = NULL;
xml_parsenext(n, nodestr, depth);
return (0);
}
@@ -74,24 +79,21 @@ node *xml_parseproperties(node *n, char **str, bool has_params, bool has_childs)
node *xml_parsenode(char **nodestr)
{
node *n = malloc(sizeof(node));
bool has_params;
bool has_param;
bool has_childs;
char *p = my_strchr(*nodestr, '>');
if (!n)
return (NULL);
if ((*nodestr)[0] == '<') {
if (!p || (*nodestr)[1] == '/') {
free(n);
return (NULL);
if (p && (*nodestr)[1] != '/') {
*p = '\0';
*nodestr += 1;
n->name = xml_getname(nodestr, &has_param, &has_childs);
if (n->name)
return (xml_parseproperties(n, nodestr, has_param, has_childs));
}
*p = '\0';
*nodestr += 1;
n->name = xml_getname(nodestr, &has_params, &has_childs);
if (n->name)
return (xml_parseproperties(n, nodestr, has_params, has_childs));
}
else if ((*nodestr)[1] != '/' && xml_getstringdata(n, nodestr) == 0) {
} else if ((*nodestr)[1] != '/' && xml_getstringdata(n, nodestr) == 0) {
n->next = xml_parsenode(nodestr);
return (n);
}
+3 -1
View File
@@ -7,11 +7,13 @@
#include "xml.h"
#include "my.h"
#include <stddef.h>
char *xml_getproperty(node *n, char *key)
{
for (dictionary *prop = n->properties; prop; prop = prop->next) {
if (!my_strcmp(key, prop->key));
if (!my_strcmp(key, prop->key))
return (prop->value);
}
return (NULL);
}
+3 -2
View File
@@ -7,6 +7,7 @@
#include "my.h"
#include "xml.h"
#include "xml_internal.h"
#include <stdlib.h>
#include <stdbool.h>
@@ -35,7 +36,7 @@ char *xml_getname(char **nodestr, bool *has_parameters, bool *has_childs)
return (name);
}
dictionary *xml_getproperty(char **nodestr)
dictionary *xml_parseproperty(char **nodestr)
{
dictionary *property = malloc(sizeof(dictionary));
char *p;
@@ -66,7 +67,7 @@ dictionary *xml_getproperties(char **nodestr, bool *can_have_child)
dictionary *property = NULL;
while ((*nodestr)[0] != '\0') {
property = xml_getproperty(nodestr);
property = xml_parseproperty(nodestr);
if (!property)
return (NULL);
properties = property_add(properties, property);
+1
View File
@@ -6,6 +6,7 @@
*/
#include "xml.h"
#include "xml_internal.h"
#include <criterion/criterion.h>
#include <string.h>