New naming conventions to avoid conflicts.
i don't know if it was such a great idea but at least it is a starting point.
This commit is contained in:
@@ -4,25 +4,25 @@
|
||||
#include "stdbool.h"
|
||||
#include "xmlUtil.h"
|
||||
|
||||
typedef struct FOModFlag {
|
||||
typedef struct fomod_Flag {
|
||||
char * name;
|
||||
char * value;
|
||||
} FOModFlag_t;
|
||||
} fomod_Flag_t;
|
||||
|
||||
typedef struct FOModFile {
|
||||
typedef struct fomod_File {
|
||||
char * source;
|
||||
char * destination;
|
||||
int priority;
|
||||
bool isFolder;
|
||||
} FOModFile_t;
|
||||
} fomod_File_t;
|
||||
|
||||
|
||||
|
||||
typedef struct FOModCondFile {
|
||||
FOModFlag_t * requiredFlags;
|
||||
typedef struct fomod_CondFile {
|
||||
fomod_Flag_t * requiredFlags;
|
||||
unsigned int flagCount;
|
||||
FOModFile_t * files;
|
||||
fomod_File_t * files;
|
||||
unsigned int fileCount;
|
||||
} FOModCondFile_t;
|
||||
} fomod_CondFile_t;
|
||||
|
||||
#endif
|
||||
|
||||
+30
-29
@@ -1,4 +1,5 @@
|
||||
#include "group.h"
|
||||
#include "fomodTypes.h"
|
||||
#include "xmlUtil.h"
|
||||
#include "string.h"
|
||||
#include <stdlib.h>
|
||||
@@ -35,11 +36,11 @@ static TypeDescriptor_t getDescriptor(const char * descriptor) {
|
||||
}
|
||||
}
|
||||
|
||||
void freeGroup(FOModGroup_t * group) {
|
||||
void grp_freeGroup(fomod_Group_t * group){
|
||||
free(group->name);
|
||||
if(group->pluginCount == 0) return;
|
||||
for(int pluginId = 0; pluginId < group->pluginCount; pluginId++) {
|
||||
FOModPlugin_t * plugin = &group->plugins[pluginId];
|
||||
fomod_Plugin_t * plugin = &group->plugins[pluginId];
|
||||
if(plugin->fileCount > 0) {
|
||||
for(int i = 0; i < plugin->fileCount; i++) {
|
||||
free(plugin->files[i].destination);
|
||||
@@ -65,10 +66,10 @@ void freeGroup(FOModGroup_t * group) {
|
||||
group->pluginCount = 0;
|
||||
}
|
||||
|
||||
static int parseConditionFlags(FOModPlugin_t * plugin, xmlNodePtr nodeElement) {
|
||||
static int parseConditionFlags(fomod_Plugin_t * plugin, xmlNodePtr nodeElement) {
|
||||
xmlNodePtr flagNode = nodeElement->children;
|
||||
while(flagNode != NULL) {
|
||||
if(!validateNode(&flagNode, true, "flag", NULL)) {
|
||||
if(!xml_validateNode(&flagNode, true, "flag", NULL)) {
|
||||
if(plugin->flagCount > 0) {
|
||||
free(plugin->flags);
|
||||
}
|
||||
@@ -77,12 +78,12 @@ static int parseConditionFlags(FOModPlugin_t * plugin, xmlNodePtr nodeElement) {
|
||||
if(flagNode == NULL)continue;
|
||||
|
||||
plugin->flagCount += 1;
|
||||
plugin->flags = realloc(plugin->flags, plugin->flagCount * sizeof(FOModFlag_t));
|
||||
plugin->flags = realloc(plugin->flags, plugin->flagCount * sizeof(fomod_Flag_t));
|
||||
|
||||
FOModFlag_t * flag = &plugin->flags[plugin->flagCount - 1];
|
||||
fomod_Flag_t * flag = &plugin->flags[plugin->flagCount - 1];
|
||||
|
||||
flag->name = freeAndDup(xmlGetProp(flagNode, (const xmlChar *) "name"));
|
||||
flag->value = freeAndDup(xmlNodeGetContent(flagNode));
|
||||
flag->name = xml_freeAndDup(xmlGetProp(flagNode, (const xmlChar *) "name"));
|
||||
flag->value = xml_freeAndDup(xmlNodeGetContent(flagNode));
|
||||
|
||||
flagNode = flagNode->next;
|
||||
}
|
||||
@@ -90,10 +91,10 @@ static int parseConditionFlags(FOModPlugin_t * plugin, xmlNodePtr nodeElement) {
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
static int parseGroupFiles(FOModPlugin_t * plugin, xmlNodePtr nodeElement) {
|
||||
static int parseGroupFiles(fomod_Plugin_t * plugin, xmlNodePtr nodeElement) {
|
||||
xmlNodePtr fileNode = nodeElement->children;
|
||||
while(fileNode != NULL) {
|
||||
if(!validateNode(&fileNode, true, "folder", "file", NULL)) {
|
||||
if(!xml_validateNode(&fileNode, true, "folder", "file", NULL)) {
|
||||
fprintf(stderr, "Unexpected node in files");
|
||||
//TODO: free
|
||||
return EXIT_FAILURE;
|
||||
@@ -103,11 +104,11 @@ static int parseGroupFiles(FOModPlugin_t * plugin, xmlNodePtr nodeElement) {
|
||||
|
||||
plugin->fileCount += 1;
|
||||
|
||||
plugin->files = realloc(plugin->files, (plugin->fileCount + 1) * sizeof(FOModFile_t));
|
||||
FOModFile_t * file = &plugin->files[plugin->fileCount - 1];
|
||||
plugin->files = realloc(plugin->files, (plugin->fileCount + 1) * sizeof(fomod_File_t));
|
||||
fomod_File_t * file = &plugin->files[plugin->fileCount - 1];
|
||||
|
||||
file->destination = freeAndDup(xmlGetProp(fileNode, (const xmlChar *) "destination"));
|
||||
file->source = freeAndDup(xmlGetProp(fileNode, (const xmlChar *) "source"));
|
||||
file->destination = xml_freeAndDup(xmlGetProp(fileNode, (const xmlChar *) "destination"));
|
||||
file->source = xml_freeAndDup(xmlGetProp(fileNode, (const xmlChar *) "source"));
|
||||
|
||||
//TODO: test if it's a number
|
||||
xmlChar * priority = xmlGetProp(fileNode, (const xmlChar *) "priority");
|
||||
@@ -123,18 +124,18 @@ static int parseGroupFiles(FOModPlugin_t * plugin, xmlNodePtr nodeElement) {
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
static int parseNodeElement(FOModPlugin_t * plugin, xmlNodePtr nodeElement) {
|
||||
static int parseNodeElement(fomod_Plugin_t * plugin, xmlNodePtr nodeElement) {
|
||||
if(xmlStrcmp(nodeElement->name, (const xmlChar *) "description") == 0) {
|
||||
plugin->description = freeAndDup(xmlNodeGetContent(nodeElement));
|
||||
plugin->description = xml_freeAndDup(xmlNodeGetContent(nodeElement));
|
||||
} else if(xmlStrcmp(nodeElement->name, (const xmlChar *) "image") == 0) {
|
||||
plugin->image = freeAndDup(xmlGetProp(nodeElement, (const xmlChar *) "path"));
|
||||
plugin->image = xml_freeAndDup(xmlGetProp(nodeElement, (const xmlChar *) "path"));
|
||||
} else if(xmlStrcmp(nodeElement->name, (const xmlChar *) "conditionFlags") == 0) {
|
||||
return parseConditionFlags(plugin, nodeElement);
|
||||
} else if(xmlStrcmp(nodeElement->name, (const xmlChar *) "files") == 0) {
|
||||
return parseGroupFiles(plugin, nodeElement);
|
||||
} else if(xmlStrcmp(nodeElement->name, (const xmlChar *) "typeDescriptor") == 0) {
|
||||
xmlNodePtr typeNode = nodeElement->children;
|
||||
if(!validateNode(&typeNode, true, "type", NULL)) {
|
||||
if(!xml_validateNode(&typeNode, true, "type", NULL)) {
|
||||
fprintf(stderr, "Unexpected node in typeDescriptor");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
@@ -145,29 +146,29 @@ static int parseNodeElement(FOModPlugin_t * plugin, xmlNodePtr nodeElement) {
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int parseGroup(xmlNodePtr groupNode, FOModGroup_t* group) {
|
||||
int grp_parseGroup(xmlNodePtr groupNode, fomod_Group_t* group) {
|
||||
xmlNodePtr pluginsNode = groupNode->children;
|
||||
if(!validateNode(&pluginsNode, true, "plugins", NULL)) {
|
||||
if(!xml_validateNode(&pluginsNode, true, "plugins", NULL)) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
|
||||
group->name = freeAndDup(xmlGetProp( groupNode, (const xmlChar *) "name"));
|
||||
group->name = xml_freeAndDup(xmlGetProp( groupNode, (const xmlChar *) "name"));
|
||||
|
||||
xmlChar * type = xmlGetProp(groupNode, (const xmlChar *) "type");
|
||||
group->type = getGroupType((const char *)type);
|
||||
xmlFree(type);
|
||||
|
||||
char * order = (char *) xmlGetProp(pluginsNode, (const xmlChar *) "order");
|
||||
group->order = getFOModOrder(order);
|
||||
group->order = fomod_getOrder(order);
|
||||
xmlFree(order);
|
||||
|
||||
FOModPlugin_t * plugins = NULL;
|
||||
fomod_Plugin_t * plugins = NULL;
|
||||
int pluginCount = 0;
|
||||
|
||||
xmlNodePtr currentPlugin = pluginsNode->children;
|
||||
while(currentPlugin != NULL) {
|
||||
if(!validateNode(¤tPlugin, true, "plugin", NULL)) {
|
||||
if(!xml_validateNode(¤tPlugin, true, "plugin", NULL)) {
|
||||
//TODO handle error;
|
||||
printf("%d\n", __LINE__);
|
||||
exit(EXIT_FAILURE);
|
||||
@@ -177,12 +178,12 @@ int parseGroup(xmlNodePtr groupNode, FOModGroup_t* group) {
|
||||
|
||||
|
||||
pluginCount += 1;
|
||||
plugins = realloc(plugins, pluginCount * sizeof(FOModPlugin_t));
|
||||
FOModPlugin_t * plugin = &plugins[pluginCount - 1];
|
||||
plugins = realloc(plugins, pluginCount * sizeof(fomod_Plugin_t));
|
||||
fomod_Plugin_t * plugin = &plugins[pluginCount - 1];
|
||||
//initialise everything to 0 and null pointers
|
||||
memset(plugin, 0, sizeof(FOModPlugin_t));
|
||||
memset(plugin, 0, sizeof(fomod_Plugin_t));
|
||||
|
||||
plugin->name = freeAndDup(xmlGetProp(currentPlugin, (const xmlChar *) "name"));
|
||||
plugin->name = xml_freeAndDup(xmlGetProp(currentPlugin, (const xmlChar *) "name"));
|
||||
|
||||
xmlNodePtr nodeElement = currentPlugin->children;
|
||||
while(nodeElement != NULL) {
|
||||
@@ -203,6 +204,6 @@ failure:
|
||||
//we need to free all of our allocations since we can't expect ou parent function to know what we allocated and what we haven't.
|
||||
group->plugins = plugins;
|
||||
group->pluginCount = pluginCount;
|
||||
freeGroup(group);
|
||||
grp_freeGroup(group);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
+11
-10
@@ -3,32 +3,33 @@
|
||||
|
||||
#include <libxml/parser.h>
|
||||
#include "fomodTypes.h"
|
||||
#include "xmlUtil.h"
|
||||
|
||||
typedef enum GroupType_t { ONE_ONLY, ANY, AT_LEAST_ONE, AT_MOST_ONE, ALL } GroupType_t;
|
||||
typedef enum TypeDescriptor { OPTIONAL, MAYBE_USABLE, NOT_USABLE, REQUIRED, RECOMMENDED } TypeDescriptor_t;
|
||||
|
||||
typedef struct FOModPlugin {
|
||||
typedef struct fomod_Plugin {
|
||||
char * description;
|
||||
char * image;
|
||||
FOModFlag_t * flags;
|
||||
fomod_Flag_t * flags;
|
||||
int flagCount;
|
||||
FOModFile_t * files;
|
||||
fomod_File_t * files;
|
||||
int fileCount;
|
||||
TypeDescriptor_t type;
|
||||
char * name;
|
||||
} FOModPlugin_t;
|
||||
} fomod_Plugin_t;
|
||||
|
||||
//combine group and "plugins"
|
||||
typedef struct FOModGroup {
|
||||
FOModPlugin_t * plugins;
|
||||
typedef struct fomod_Group {
|
||||
fomod_Plugin_t * plugins;
|
||||
int pluginCount;
|
||||
GroupType_t type;
|
||||
char * name;
|
||||
FOModOrder_t order;
|
||||
} FOModGroup_t;
|
||||
fomod_Order_t order;
|
||||
} fomod_Group_t;
|
||||
|
||||
int parseGroup(xmlNodePtr groupNode, FOModGroup_t* group);
|
||||
void freeGroup(FOModGroup_t * group);
|
||||
int grp_parseGroup(xmlNodePtr groupNode, fomod_Group_t* group);
|
||||
void grp_freeGroup(fomod_Group_t * group);
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
+35
-81
@@ -1,63 +1,17 @@
|
||||
#include "parser.h"
|
||||
#include "fomodTypes.h"
|
||||
#include "group.h"
|
||||
#include "libxml/tree.h"
|
||||
#include "xmlUtil.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
//Maybe integrate this into the rest of the code instead of freeing after the fact
|
||||
void freeFOMod(FOMod_t * fomod) {
|
||||
for(int i = 0; i < fomod->condFilesCount; i++) {
|
||||
FOModCondFile_t * condFile = &(fomod->condFiles[i]);
|
||||
for(long fileId = 0; fileId < condFile->fileCount; fileId++) {
|
||||
free(condFile->files[fileId].destination);
|
||||
free(condFile->files[fileId].source);
|
||||
}
|
||||
|
||||
for(long flagId = 0; flagId < condFile->flagCount; flagId++) {
|
||||
FOModFlag_t * flag = &(condFile->requiredFlags[flagId]);
|
||||
free(flag->name);
|
||||
free(flag->value);
|
||||
}
|
||||
free(condFile->files);
|
||||
free(condFile->requiredFlags);
|
||||
}
|
||||
free(fomod->condFiles);
|
||||
free(fomod->moduleImage);
|
||||
free(fomod->moduleName);
|
||||
|
||||
int size = countUntilNull(fomod->requiredInstallFiles, sizeof(char **));
|
||||
for(int i = 0; i < size; i++) {
|
||||
free(fomod->requiredInstallFiles[i]);
|
||||
}
|
||||
free(fomod->requiredInstallFiles);
|
||||
|
||||
for(int i = 0; i < fomod->stepCount; i++) {
|
||||
FOModStep_t * step = &fomod->steps[i];
|
||||
for(int groupId = 0; groupId < step->groupCount; groupId++) {
|
||||
FOModGroup_t * group = &step->groups[groupId];
|
||||
freeGroup(group);
|
||||
}
|
||||
for(int flagId = 0; flagId < step->flagCount; flagId++) {
|
||||
FOModFlag_t * flag = &(step->requiredFlags[flagId]);
|
||||
free(flag->name);
|
||||
free(flag->value);
|
||||
}
|
||||
free(step->groups);
|
||||
free(step->requiredFlags);
|
||||
free(step->name);
|
||||
}
|
||||
free(fomod->steps);
|
||||
|
||||
//set every counter to zero and every pointer to null
|
||||
memset(fomod, 0, sizeof(FOMod_t));
|
||||
}
|
||||
|
||||
static int parseVisibleNode(xmlNodePtr node, FOModStep_t * step) {
|
||||
xmlNodePtr requiredFlagsNode = node->children;
|
||||
|
||||
while (requiredFlagsNode != NULL) {
|
||||
|
||||
if(!validateNode(&requiredFlagsNode, true, "flagDependency", NULL)) {
|
||||
if(!xml_validateNode(&requiredFlagsNode, true, "flagDependency", NULL)) {
|
||||
//TODO: handle error
|
||||
printf("%d\n", __LINE__);
|
||||
return EXIT_FAILURE;
|
||||
@@ -66,10 +20,10 @@ static int parseVisibleNode(xmlNodePtr node, FOModStep_t * step) {
|
||||
if(requiredFlagsNode == NULL)break;
|
||||
|
||||
step->flagCount += 1;
|
||||
step->requiredFlags = realloc(step->requiredFlags, step->flagCount * sizeof(FOModFlag_t));
|
||||
FOModFlag_t * flag = &(step->requiredFlags[step->flagCount - 1]);
|
||||
flag->name = freeAndDup(xmlGetProp(requiredFlagsNode, (const xmlChar *) "flag"));
|
||||
flag->value = freeAndDup(xmlGetProp(requiredFlagsNode, (const xmlChar *) "value"));
|
||||
step->requiredFlags = realloc(step->requiredFlags, step->flagCount * sizeof(fomod_Flag_t));
|
||||
fomod_Flag_t * flag = &(step->requiredFlags[step->flagCount - 1]);
|
||||
flag->name = xml_freeAndDup(xmlGetProp(requiredFlagsNode, (const xmlChar *) "flag"));
|
||||
flag->value = xml_freeAndDup(xmlGetProp(requiredFlagsNode, (const xmlChar *) "value"));
|
||||
|
||||
requiredFlagsNode = requiredFlagsNode->next;
|
||||
}
|
||||
@@ -79,11 +33,11 @@ static int parseVisibleNode(xmlNodePtr node, FOModStep_t * step) {
|
||||
|
||||
static int parseOptionalFileGroup(xmlNodePtr node, FOModStep_t * step) {
|
||||
xmlChar * optionOrder = xmlGetProp(node, (const xmlChar *)"order");
|
||||
step->optionOrder = getFOModOrder((char *)optionOrder);
|
||||
step->optionOrder = fomod_getOrder((char *)optionOrder);
|
||||
xmlFree(optionOrder);
|
||||
xmlNodePtr group = node->children;
|
||||
while(group != NULL) {
|
||||
if(!validateNode(&group, true, "group", NULL)) {
|
||||
if(!xml_validateNode(&group, true, "group", NULL)) {
|
||||
//TODO: handle error
|
||||
printf("%d\n", __LINE__);
|
||||
return EXIT_FAILURE;
|
||||
@@ -92,8 +46,8 @@ static int parseOptionalFileGroup(xmlNodePtr node, FOModStep_t * step) {
|
||||
if(group == NULL)break;
|
||||
|
||||
step->groupCount += 1;
|
||||
step->groups = realloc(step->groups, step->groupCount * sizeof(FOModGroup_t));
|
||||
int status = parseGroup(group, &step->groups[step->groupCount - 1]);
|
||||
step->groups = realloc(step->groups, step->groupCount * sizeof(fomod_Group_t));
|
||||
int status = grp_parseGroup(group, &step->groups[step->groupCount - 1]);
|
||||
|
||||
if(status != EXIT_SUCCESS) {
|
||||
//TODO: handle error
|
||||
@@ -113,7 +67,7 @@ static FOModStep_t * parseInstallSteps(xmlNodePtr installStepsNode, int * stepCo
|
||||
xmlNodePtr stepNode = installStepsNode->children;
|
||||
while(stepNode != NULL) {
|
||||
//skipping the text node
|
||||
if(!validateNode(&stepNode, true, "installStep", NULL)) {
|
||||
if(!xml_validateNode(&stepNode, true, "installStep", NULL)) {
|
||||
//TODO: handle error
|
||||
printf("%d\n", __LINE__);
|
||||
exit(EXIT_FAILURE);
|
||||
@@ -125,7 +79,7 @@ static FOModStep_t * parseInstallSteps(xmlNodePtr installStepsNode, int * stepCo
|
||||
steps = realloc(steps, *stepCount * sizeof(FOModStep_t));
|
||||
|
||||
FOModStep_t * step = &steps[*stepCount - 1];
|
||||
step->name = freeAndDup(xmlGetProp(stepNode, (const xmlChar *)"name"));
|
||||
step->name = xml_freeAndDup(xmlGetProp(stepNode, (const xmlChar *)"name"));
|
||||
step->requiredFlags = NULL;
|
||||
step->flagCount = 0;
|
||||
step->groupCount = 0;
|
||||
@@ -147,10 +101,10 @@ static FOModStep_t * parseInstallSteps(xmlNodePtr installStepsNode, int * stepCo
|
||||
return steps;
|
||||
}
|
||||
|
||||
static int parseDependencies(xmlNodePtr node, FOModCondFile_t * condFile) {
|
||||
static int parseDependencies(xmlNodePtr node, fomod_CondFile_t * condFile) {
|
||||
xmlNodePtr flagNode = node->children;
|
||||
|
||||
if(!validateNode(&flagNode, true, "flagDependency", NULL)) {
|
||||
if(!xml_validateNode(&flagNode, true, "flagDependency", NULL)) {
|
||||
//TODO: handle error
|
||||
printf("%d\n", __LINE__);
|
||||
return EXIT_FAILURE;
|
||||
@@ -158,32 +112,32 @@ static int parseDependencies(xmlNodePtr node, FOModCondFile_t * condFile) {
|
||||
|
||||
while(flagNode != NULL) {
|
||||
condFile->flagCount += 1;
|
||||
condFile->requiredFlags = realloc(condFile->requiredFlags, condFile->flagCount * sizeof(FOModFlag_t));
|
||||
FOModFlag_t * flag = &(condFile->requiredFlags[condFile->flagCount - 1]);
|
||||
flag->name = freeAndDup(xmlGetProp(flagNode, (const xmlChar *) "flag"));
|
||||
flag->value = freeAndDup(xmlGetProp(flagNode, (const xmlChar *) "value"));
|
||||
condFile->requiredFlags = realloc(condFile->requiredFlags, condFile->flagCount * sizeof(fomod_Flag_t));
|
||||
fomod_Flag_t * flag = &(condFile->requiredFlags[condFile->flagCount - 1]);
|
||||
flag->name = xml_freeAndDup(xmlGetProp(flagNode, (const xmlChar *) "flag"));
|
||||
flag->value = xml_freeAndDup(xmlGetProp(flagNode, (const xmlChar *) "value"));
|
||||
|
||||
flagNode = flagNode->next;
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
static int parseFiles(xmlNodePtr node, FOModCondFile_t * condFile) {
|
||||
static int parseFiles(xmlNodePtr node, fomod_CondFile_t * condFile) {
|
||||
xmlNodePtr filesNode = node->children;
|
||||
|
||||
|
||||
while(filesNode != NULL) {
|
||||
if(!validateNode(&filesNode, true, "folder", "file", NULL)) {
|
||||
if(!xml_validateNode(&filesNode, true, "folder", "file", NULL)) {
|
||||
//TODO: handle error
|
||||
printf("%d\n", __LINE__);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
condFile->fileCount += 1;
|
||||
condFile->files = realloc(condFile->files, condFile->fileCount * sizeof(FOModFile_t));
|
||||
FOModFile_t * flag = &(condFile->files[condFile->fileCount - 1]);
|
||||
flag->source = freeAndDup(xmlGetProp(filesNode, (const xmlChar *) "source"));
|
||||
flag->destination = freeAndDup(xmlGetProp(filesNode, (const xmlChar *) "destination"));
|
||||
condFile->files = realloc(condFile->files, condFile->fileCount * sizeof(fomod_File_t));
|
||||
fomod_File_t * flag = &(condFile->files[condFile->fileCount - 1]);
|
||||
flag->source = xml_freeAndDup(xmlGetProp(filesNode, (const xmlChar *) "source"));
|
||||
flag->destination = xml_freeAndDup(xmlGetProp(filesNode, (const xmlChar *) "destination"));
|
||||
flag->priority = 0;
|
||||
flag->isFolder = xmlStrcmp(filesNode->name, (xmlChar *) "folder") == 0;
|
||||
|
||||
@@ -196,7 +150,7 @@ static int parseFiles(xmlNodePtr node, FOModCondFile_t * condFile) {
|
||||
static int parseConditionalInstalls(xmlNodePtr node, FOMod_t * fomod) {
|
||||
xmlNodePtr patterns = node->children;
|
||||
if(patterns != NULL) {
|
||||
if(!validateNode(&patterns, true, "patterns", NULL)) {
|
||||
if(!xml_validateNode(&patterns, true, "patterns", NULL)) {
|
||||
//TODO: handle error
|
||||
printf("%d\n", __LINE__);
|
||||
return EXIT_FAILURE;
|
||||
@@ -205,7 +159,7 @@ static int parseConditionalInstalls(xmlNodePtr node, FOMod_t * fomod) {
|
||||
while(currentPattern != NULL) {
|
||||
xmlNodePtr patternChild = currentPattern->children;
|
||||
|
||||
if(!validateNode(&patternChild, true, "pattern", NULL)) {
|
||||
if(!xml_validateNode(&patternChild, true, "pattern", NULL)) {
|
||||
//TODO: handle error
|
||||
printf("%d\n", __LINE__);
|
||||
return EXIT_FAILURE;
|
||||
@@ -213,8 +167,8 @@ static int parseConditionalInstalls(xmlNodePtr node, FOMod_t * fomod) {
|
||||
|
||||
while(patternChild != NULL) {
|
||||
fomod->condFilesCount += 1;
|
||||
fomod->condFiles = realloc(fomod->condFiles, fomod->condFilesCount * sizeof(FOModCondFile_t));
|
||||
FOModCondFile_t * condFile = &(fomod->condFiles[fomod->condFilesCount - 1]);
|
||||
fomod->condFiles = realloc(fomod->condFiles, fomod->condFilesCount * sizeof(fomod_CondFile_t));
|
||||
fomod_CondFile_t * condFile = &(fomod->condFiles[fomod->condFilesCount - 1]);
|
||||
|
||||
condFile->fileCount = 0;
|
||||
condFile->files = NULL;
|
||||
@@ -239,7 +193,7 @@ static int parseConditionalInstalls(xmlNodePtr node, FOMod_t * fomod) {
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
error_t parseFOMod(const char * fomodFile, FOMod_t* fomod) {
|
||||
error_t parser_parseFOMod(const char * fomodFile, FOMod_t* fomod) {
|
||||
xmlDocPtr doc;
|
||||
xmlNodePtr cur;
|
||||
|
||||
@@ -279,22 +233,22 @@ error_t parseFOMod(const char * fomodFile, FOMod_t* fomod) {
|
||||
//might cause some issues. when will c finally support utf-8
|
||||
fomod->moduleName = (char *)cur->content;
|
||||
} else if(xmlStrcmp(cur->name, (const xmlChar *) "moduleImage") == 0) {
|
||||
fomod->moduleImage = freeAndDup(xmlGetProp(cur, (const xmlChar *)"path"));
|
||||
fomod->moduleImage = xml_freeAndDup(xmlGetProp(cur, (const xmlChar *)"path"));
|
||||
} else if(xmlStrcmp(cur->name, (const xmlChar *)"requiredInstallFiles") == 0) {
|
||||
//TODO: support non empty destination.
|
||||
xmlNodePtr requiredInstallFile = cur->children;
|
||||
while(requiredInstallFile != NULL) {
|
||||
if(validateNode(&requiredInstallFile, true, "folder", "file", NULL)) {
|
||||
if(xml_validateNode(&requiredInstallFile, true, "folder", "file", NULL)) {
|
||||
//TODO: handle error
|
||||
printf("%d\n", __LINE__);
|
||||
exit(ERR_FAILURE);
|
||||
}
|
||||
|
||||
int size = countUntilNull(fomod->requiredInstallFiles, sizeof(char **)) + 2;
|
||||
int size = fomod_countUntilNull(fomod->requiredInstallFiles, sizeof(char **)) + 2;
|
||||
fomod->requiredInstallFiles = realloc(fomod->requiredInstallFiles, sizeof(char *) * size);
|
||||
//ensure it is null terminated
|
||||
fomod->requiredInstallFiles[size - 1] = NULL;
|
||||
fomod->requiredInstallFiles[size - 2] = freeAndDup(xmlGetProp(requiredInstallFile, (const xmlChar *)"source"));
|
||||
fomod->requiredInstallFiles[size - 2] = xml_freeAndDup(xmlGetProp(requiredInstallFile, (const xmlChar *)"source"));
|
||||
|
||||
requiredInstallFile = cur->children;
|
||||
}
|
||||
@@ -306,7 +260,7 @@ error_t parseFOMod(const char * fomodFile, FOMod_t* fomod) {
|
||||
}
|
||||
|
||||
xmlChar * stepOrder = xmlGetProp(cur, (xmlChar *)"order");
|
||||
fomod->stepOrder = getFOModOrder((char *)stepOrder);
|
||||
fomod->stepOrder = fomod_getOrder((char *)stepOrder);
|
||||
xmlFree(stepOrder);
|
||||
|
||||
int stepCount = 0;
|
||||
|
||||
+7
-12
@@ -2,16 +2,17 @@
|
||||
#define __FOMOD_PARSER_H__
|
||||
|
||||
|
||||
#include "fomodTypes.h"
|
||||
#include "group.h"
|
||||
#include "../main.h"
|
||||
|
||||
//combine installStep and optionalFileGroups
|
||||
typedef struct FOModStep {
|
||||
FOModOrder_t optionOrder;
|
||||
FOModGroup_t * groups;
|
||||
fomod_Order_t optionOrder;
|
||||
fomod_Group_t * groups;
|
||||
int groupCount;
|
||||
char * name;
|
||||
FOModFlag_t * requiredFlags;
|
||||
fomod_Flag_t * requiredFlags;
|
||||
int flagCount;
|
||||
} FOModStep_t;
|
||||
|
||||
@@ -19,10 +20,10 @@ typedef struct FOMod {
|
||||
char * moduleName;
|
||||
char * moduleImage;
|
||||
char ** requiredInstallFiles;
|
||||
FOModOrder_t stepOrder;
|
||||
fomod_Order_t stepOrder;
|
||||
FOModStep_t * steps;
|
||||
int stepCount;
|
||||
FOModCondFile_t * condFiles;
|
||||
fomod_CondFile_t * condFiles;
|
||||
int condFilesCount;
|
||||
} FOMod_t;
|
||||
|
||||
@@ -32,12 +33,6 @@ typedef struct FOMod {
|
||||
* @param fomodFile path to the moduleconfig.xml
|
||||
* @param fomod pointer to a new FOMod_t
|
||||
*/
|
||||
error_t parseFOMod(const char * fomodFile, FOMod_t* fomod);
|
||||
|
||||
/**
|
||||
* @brief Free content of a fomod file.
|
||||
* @param fomod
|
||||
*/
|
||||
void freeFOMod(FOMod_t * fomod);
|
||||
error_t parser_parseFOMod(const char * fomodFile, FOMod_t* fomod);
|
||||
|
||||
#endif
|
||||
|
||||
+5
-5
@@ -3,13 +3,13 @@
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
char * freeAndDup(xmlChar * line) {
|
||||
char * xml_freeAndDup(xmlChar * line) {
|
||||
char * free = strdup((const char *) line);
|
||||
xmlFree(line);
|
||||
return free;
|
||||
}
|
||||
|
||||
FOModOrder_t getFOModOrder(const char * order) {
|
||||
fomod_Order_t fomod_getOrder(const char * order) {
|
||||
if(order == NULL || strcmp(order, "Ascending") == 0) {
|
||||
return ASC;
|
||||
} else if(strcmp(order, "Explicit") == 0) {
|
||||
@@ -21,14 +21,14 @@ FOModOrder_t getFOModOrder(const char * order) {
|
||||
}
|
||||
|
||||
//replace \ in the path by /
|
||||
void fixPath(char * path) {
|
||||
void xml_fixPath(char * path) {
|
||||
while(*path != '\0') {
|
||||
if(*path == '\\')*path = '/';
|
||||
path++;
|
||||
}
|
||||
}
|
||||
|
||||
int countUntilNull(void * pointers, size_t typeSize) {
|
||||
int fomod_countUntilNull(void * pointers, size_t typeSize) {
|
||||
int i = 0;
|
||||
char * arithmetic = (char *)pointers;
|
||||
while(arithmetic != NULL) {
|
||||
@@ -40,7 +40,7 @@ int countUntilNull(void * pointers, size_t typeSize) {
|
||||
|
||||
//names cannot contain false
|
||||
//need to be null terminated
|
||||
bool validateNode(xmlNodePtr * node, bool skipText, const char * names, ...) {
|
||||
bool xml_validateNode(xmlNodePtr * node, bool skipText, const char * names, ...) {
|
||||
va_list namesPtr;
|
||||
|
||||
while(*node != NULL && xmlStrcmp((*node)->name, (const xmlChar *)"text") == 0) {
|
||||
|
||||
+6
-6
@@ -5,7 +5,7 @@
|
||||
#include <stdbool.h>
|
||||
|
||||
|
||||
typedef enum FOModOrder { ASC, DESC, ORD } FOModOrder_t;
|
||||
typedef enum FOModOrder { ASC, DESC, ORD } fomod_Order_t;
|
||||
|
||||
/**
|
||||
* @brief
|
||||
@@ -15,21 +15,21 @@ typedef enum FOModOrder { ASC, DESC, ORD } FOModOrder_t;
|
||||
* @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, ...);
|
||||
bool xml_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);
|
||||
char * xml_freeAndDup(xmlChar * line);
|
||||
|
||||
|
||||
FOModOrder_t getFOModOrder(const char * order);
|
||||
fomod_Order_t fomod_getOrder(const char * order);
|
||||
|
||||
/**
|
||||
* @brief replace / by \
|
||||
* @param path
|
||||
*/
|
||||
void fixPath(char * path);
|
||||
void xml_fixPath(char * path);
|
||||
|
||||
/**
|
||||
* @brief Count the number of step before null
|
||||
@@ -38,6 +38,6 @@ void fixPath(char * path);
|
||||
* @param typeSize size of each element of the list
|
||||
* @return size
|
||||
*/
|
||||
int countUntilNull(void * pointers, size_t typeSize);
|
||||
int fomod_countUntilNull(void * pointers, size_t typeSize);
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user