BlueBear icon

XMLGenerator.c

BlueBear | PRO | 11/20/13 01:01:32 PM UTC | 0 ⭐ | 409 👁️ | Never ⏰ | []
C |

2.49 KB

|

None

|

0 👍

/

0 👎

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
#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[] = "<?xml version=\"1.0\"?>\n";
    char filename[20];
    FILE *xml;
    greets();
 
    printf("Please specify file that you want to edit: <example.xml>\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;
}

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  • Syutrsz icon
    03/31/26 10:25:48 PM UTC
    text |

    0 B

    |

    0 👍

    /

    0 👎

    Best t33n active cpx link daily updates!
     Copy and paste the link in a new browser tab and then hit enter!
     https://crazyporn.@xxx/members/157354/?asgtbndr=1&play=true&spon=adworld&zone=400
     Remove the @ 
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎