#include #include #include #define DEBUG typedef enum resourceType { FISH, TRASH, GOLD, DIAMOND }resource_t; typedef struct buildings { char *name; int level; int hitPoints; resource_t type; int resourceCost; int buildTime; int XPGain; struct buildings *next; }buildingTagContent_t; typedef struct players { // TODO complete this struct players *next; }playerTagContent_t; typedef struct tag { char *tagName; buildingTagContent_t *buildingProperties; playerTagContent_t *playerProperties; struct tag *next; }tag_t; int findString(const char *string, FILE *fp); //find string in given string FILE *openXML(const char *name); //Opens an XML file, if exists, if not, creates int createTag(const char *tagName, tag_t *p_tag); // int greets(); //utter bullshit int main(void) { const char header[] = "\n"; char filename[20]; FILE *xml; greets(); printf("Please specify file that you want to edit: \n"); gets(filename); xml = openXML(filename); //plain file, init header if(findString(header, xml) == 0) { rewind(xml); fprintf(xml, "%s", header); #ifdef DEBUG fprintf(stdout, "Header initialised in XML\n"); #endif } else //go ahead { } system("pause"); return 0; } int greets() { printf("\tXML Generator/Parser/Editor/Whatever\n"); printf("\tBy Citrus Lee, Red Datura/Dreamventory\n"); printf("\t2013-XXXX\n"); printf("\tLicensed under UFWTFYW license\n"); printf("\t(Use For What The Fuck You Want license)\n\n\n"); } int createTag(const char *tagName, tag_t *p_tag) { if(p_tag == NULL) { p_tag = (tag_t *) malloc(sizeof(tag_t)); strcpy(p_tag->tagName, tagName); } } int findString(const char *string, FILE *fp) { int lineNum = 0; char temp[514]; while(fgets(temp, 512, fp) != NULL) { if((strstr(temp, string)) != NULL) { printf("A match found on line: %d\n", lineNum); #ifdef DEBUG printf("\n%s\n", temp); #endif return 1; } lineNum++; } return 0; } FILE *openXML(const char *name) { FILE *xml = fopen(name, "r+"); if(xml == NULL) { xml = fopen(name, "w"); fprintf(stdout, "File %s does not exist, creating\n", name); if(xml == NULL) { fprintf(stdout, "Could not create/open file %s at line %d\n", name, __LINE__); exit(10); } } else { fprintf(stdout, "File %s opened successfully...\n", name); } return xml; }