Adder the type alias error_t and refactored the code to use it. also extracted archive function from install.c to archives.c

This commit is contained in:
Marc
2022-10-07 10:47:14 +02:00
parent 091ab3894c
commit 4ce99996e8
15 changed files with 198 additions and 130 deletions
+9 -8
View File
@@ -239,7 +239,7 @@ static int parseConditionalInstalls(xmlNodePtr node, FOMod_t * fomod) {
return EXIT_SUCCESS;
}
int parseFOMod(const char * fomodFile, FOMod_t* fomod) {
error_t parseFOMod(const char * fomodFile, FOMod_t* fomod) {
xmlDocPtr doc;
xmlNodePtr cur;
@@ -256,7 +256,7 @@ int parseFOMod(const char * fomodFile, FOMod_t* fomod) {
if(doc == NULL) {
fprintf(stderr, "Document is not a valid xml file\n");
return EXIT_FAILURE;
return ERR_FAILURE;
}
@@ -264,12 +264,13 @@ int parseFOMod(const char * fomodFile, FOMod_t* fomod) {
if(cur == NULL) {
fprintf(stderr, "emptyDocument");
xmlFreeDoc(doc);
return EXIT_FAILURE;
return ERR_FAILURE;
}
if(xmlStrcmp(cur->name, (const xmlChar *) "config") != 0) {
fprintf(stderr, "document of the wrong type, root node is '%s' instead of config\n", cur->name);
return EXIT_FAILURE;
xmlFreeDoc(doc);
return ERR_FAILURE;
}
cur = cur->children;
@@ -286,7 +287,7 @@ int parseFOMod(const char * fomodFile, FOMod_t* fomod) {
if(validateNode(&requiredInstallFile, true, "folder", "file", NULL)) {
//TODO: handle error
printf("%d\n", __LINE__);
exit(EXIT_FAILURE);
exit(ERR_FAILURE);
}
int size = countUntilNull(fomod->requiredInstallFiles, sizeof(char **)) + 2;
@@ -301,7 +302,7 @@ int parseFOMod(const char * fomodFile, FOMod_t* fomod) {
if(fomod->steps != NULL) {
fprintf(stderr, "Multiple 'installSteps' tags");
//TODO: handle error
return EXIT_FAILURE;
return ERR_FAILURE;
}
xmlChar * stepOrder = xmlGetProp(cur, (xmlChar *)"order");
@@ -315,7 +316,7 @@ int parseFOMod(const char * fomodFile, FOMod_t* fomod) {
fprintf(stderr, "Failed to parse the install steps\n");
//TODO: manage the error properly
return EXIT_FAILURE;
return ERR_FAILURE;
}
fomod->steps = steps;
@@ -327,5 +328,5 @@ int parseFOMod(const char * fomodFile, FOMod_t* fomod) {
}
xmlFreeDoc(doc);
return EXIT_SUCCESS;
return ERR_SUCCESS;
}
+2 -2
View File
@@ -3,6 +3,7 @@
#include "group.h"
#include "../main.h"
//combine installStep and optionalFileGroups
typedef struct FOModStep {
@@ -30,9 +31,8 @@ typedef struct FOMod {
*
* @param fomodFile path to the moduleconfig.xml
* @param fomod pointer to a new FOMod_t
* @return error code.
*/
int parseFOMod(const char * fomodFile, FOMod_t* fomod);
error_t parseFOMod(const char * fomodFile, FOMod_t* fomod);
/**
* @brief Free content of a fomod file.
+12
View File
@@ -7,12 +7,24 @@
typedef enum FOModOrder { ASC, DESC, ORD } FOModOrder_t;
/**
* @brief
*
* @param node a pointer to the current node pointer (xmlNode **)
* @param skipText if a text element is found skip it.
* @param names variadic of the valid names.
* @return return true if it found a valid node
*/
bool validateNode(xmlNodePtr * node, bool skipText, const char * names, ...);
/**
* @brief Free memory of and xmlChar and return a strdup version. just to make sure there is nothing remaining in libxml
*/
char * freeAndDup(xmlChar * line);
FOModOrder_t getFOModOrder(const char * order);
/**
* @brief replace / by \
* @param path