<commit_before>#include "GEDCOMparser.h"
#include "LinkedListAPI.h"
#include "BinarySearchTreeAPI.h"


Header * initializeHeader(char* source, char* gedcVersion, char* encodingType, char* submitterName, char* address);
// GEDCOMobject * initializeGEDCOMobject();
Submitter * initializeSubmitter(char* submitterName, char* address);
Field * initializeOtherField(char* tag, char* value);
Event * initializeEvent(char* type, char* date, char* place);

GEDCOMerror createGEDCOM(char* fileName, GEDCOMobject** obj)
{

    FILE *fp;
    char line[256];
    char lineStorage[256][500];
    char eventOtherFieldTagStorage[256][500];
    char eventOtherFieldValueStorage[256][500];
    char submitterOtherFieldTagStorage[256][500];
    char submitterOtherFieldValueStorage[256][500];
    char headerOtherFieldTagStorage[256][500];
    char headerOtherFieldValueStorage[256][500];
    char individualOtherFieldTagStorage[256][500];
    char individualOtherFieldValueStorage[256][500];
    char familyOtherFieldTagStorage[256][500];
    char familyOtherFieldValueStorage[256][500];
    char gedcomObjectOtherFieldTagStorage[256][500];
    char gedcomObjectOtherFieldValueStorage[256][500];
    char sourceStore[256];
    char gedcVersionStore[64];
    char encodingTypeStore[64];
    char submitterNameStore[61];
    char submitterAddress[256];
    int totalIndividualOtherFieldArray[500];
    int totalEventOtherFieldArray[500];
    int totalFamilyOtherFieldArray[500];
    int individualOtherFieldCount = 0;
    int eventOtherFieldCount = 0;
    int familyOtherFieldCount = 0;
    int headFlag = 0;
    int indiFlag = 0;
    int submFlag = 0;
    int famFlag = 0;
    int endFlag = 0;

    int count = 0;


    if(fileName != NULL && fileName[0] != '\0')
    {
        if(strcasestr(fileName, ".ged"))
        {
            if((fp = fopen(fileName, "r")))
            {
                while(fgets(line, sizeof(line), fp) != NULL)
                {
                    strcpy(lineStorage[count], line);
                    count++;
                }

                fclose(fp);
            }
            else
            {
                GEDCOMerror err;
                err.type = INV_FILE;
                err.line = count;
                return err;
            }
        }
        else
        {
            GEDCOMerror err;
            err.type = INV_FILE;
            err.line = count;
            return err;
        }
    }
    else
    {
        GEDCOMerror err;
        err.type = INV_FILE;
        err.line = count;
        return err;
    }


    for(int i = 0; i < count; i++)
    {

        //start of thing
        if(lineStorage[i][0] == '0')
        {
            if(strcasestr(lineStorage[i], 'HEAD'))
            {
                headFlag = 1;
            }
            else if(strcasestr(lineStorage[i], 'INDI'))
            {
                indiFlag = 1;
            }
            else if(strcasestr(lineStorage[i], 'FAM'))
            {
                famFlag = 1;
            }
            else if(strcasestr(lineStorage[i], 'SUBM'))
            {
                submFlag = 1;
            }
            else if(strcasestr(lineStorage[i], 'TRLR'))
            {
                endFlag = 1;
            }
        }
        //stuff in thing
        else
        {
            if(headFlag == 1)
            {
                while(lineStorage[i+1][0] != '0')
                {


                    i++;
                }

                headFlag = 0;
            }
            else if(indiFlag == 1)
            {
                while(lineStorage[i+1][0] != '0')
                {
                    

                    i++;
                }

                indiFlag = 0;

            }
            else if(famFlag == 1)
            {
                while(lineStorage[i+1][0] != '0')
                {
                    
                    
                    i++;
                }

                famFlag = 0;

            }
            else if(submFlag == 1)<commit_msg>more work on parser, so many small details jesus<commit_after>#include "GEDCOMparser.h"
#include "LinkedListAPI.h"
#include "BinarySearchTreeAPI.h"


Header * initializeHeader(char* source, char* gedcVersion, char* encodingType, char* submitterName, char* address);
// GEDCOMobject * initializeGEDCOMobject();
Submitter * initializeSubmitter(char* submitterName, char* address);
Field * initializeOtherField(char* tag, char* value);
Event * initializeEvent(char* type, char* date, char* place);

GEDCOMerror createGEDCOM(char* fileName, GEDCOMobject** obj)
{

    FILE *fp;
    char line[256];
    char lineStorage[256][500];
    char *tempFieldStorage = malloc(sizeof(char) * 1000);
    char *tempDataStorage = malloc(sizeof(char) * 1000);
    char eventOtherFieldTagStorage[256][500];
    char eventOtherFieldValueStorage[256][500];
    char submitterOtherFieldTagStorage[256][500];
    char submitterOtherFieldValueStorage[256][500];
    char headerOtherFieldTagStorage[256][500];
    char headerOtherFieldValueStorage[256][500];
    char individualOtherFieldTagStorage[256][500];
    char individualOtherFieldValueStorage[256][500];
    char familyOtherFieldTagStorage[256][500];
    char familyOtherFieldValueStorage[256][500];
    char gedcomObjectOtherFieldTagStorage[256][500];
    char gedcomObjectOtherFieldValueStorage[256][500];
    char individualGivenNameStorage[256][500];
    char individualSurNameStorage[256][500];
    char sourceStore[256];
    char gedcVersionStore[64];
    char encodingTypeStore[64];
    char submitterNameStore[61];
    char submitterAddress[256];
    int totalIndividualOtherFieldArray[500];
    int totalEventOtherFieldArray[500];
    int totalFamilyOtherFieldArray[500];
    int totalIndividaulCount = 0;
    int individualOtherFieldCount = 0;
    int eventOtherFieldCount = 0;
    int familyOtherFieldCount = 0;
    int headerOtherFieldCount = 0;
    int tempSize = 0;
    int tempSizeTwo = 0;
    int headFlag = 0;
    int indiFlag = 0;
    int submFlag = 0;
    int famFlag = 0;
    int endFlag = 0;

    int count = 0;


    if(fileName != NULL && fileName[0] != '\0')
    {
        if(strcasestr(fileName, ".ged"))
        {
            if((fp = fopen(fileName, "r")))
            {
                while(fgets(line, sizeof(line), fp) != NULL)
                {
                    strcpy(lineStorage[count], line);
                    count++;
                }

                fclose(fp);
            }
            else
            {
                GEDCOMerror err;
                err.type = INV_FILE;
                err.line = count;
                return err;
            }
        }
        else
        {
            GEDCOMerror err;
            err.type = INV_FILE;
            err.line = count;
            return err;
        }
    }
    else
    {
        GEDCOMerror err;
        err.type = INV_FILE;
        err.line = count;
        return err;
    }


    for(int i = 0; i < count; i++)
    {

        //start of thing
        if(lineStorage[i][0] == '0')
        {
            if(strcasestr(lineStorage[i], 'HEAD'))
            {
                headFlag = 1;
            }
            else if(strcasestr(lineStorage[i], 'INDI'))
            {
                indiFlag = 1;
            }
            else if(strcasestr(lineStorage[i], 'FAM'))
            {
                famFlag = 1;
            }
            else if(strcasestr(lineStorage[i], 'SUBM'))
            {
                submFlag = 1;
            }
            else if(strcasestr(lineStorage[i], 'TRLR'))
            {
                endFlag = 1;
            }
        }
        //stuff in thing
        else
        {
            if(headFlag == 1)
            {
                while(lineStorage[i+1][0] != '0')
                {
                    if(strcasestr(lineStorage[i], 'SOUR'))
                    {
                        for(int j = 7; j < strlen(lineStorage[i]); j++)
                        {

                                // while(lineStorage[i][j+1] != '\0')
                                // {
                                    tempFieldStorage[tempSize] = lineStorage[i][j];
                                    tempSize++;
                                    // j++;
                                // }
                        }


                        strcpy(sourceStore, tempFieldStorage);
                        memset(tempFieldStorage, '\0', 1000);
                        tempSize = 0;
                    }
                    else if(strcasestr(lineStorage[i], 'GEDC'))
                    {
                        i++;
                        for(int j = 7; j < strlen(lineStorage[i]); j++)
                        {
                            tempFieldStorage[tempSize] = lineStorage[i][j];
                            tempSize++;   
                        }

                        strcpy(gedcVersionStore, tempFieldStorage);
                        memset(tempFieldStorage, '\0', 1000);
                        tempSize = 0;

                    }
                    else if(strcasestr(lineStorage[i], 'CHAR'))
                    {
                        for(int j = 7; j < strlen(lineStorage[i]); j++)
                        {
                            tempFieldStorage[tempSize] = lineStorage[i][j];
                            tempSize++;   
                        }

                        strcpy(encodingTypeStore, tempFieldStorage);
                        memset(tempFieldStorage, '\0', 1000);
                        tempSize = 0;
                    }
                    else
                    {

                        for(int j = 1; j < strlen(lineStorage[i]); j++)
                        {
                            tempFieldStorage[tempSize] = lineStorage[i][j];
                            tempSize++;
                            if(lineStorage[i][j+1] == ' ')
                            {
                                while(lineStorage[i][j+1] != '\0')
                                {
                                    tempDataStorage[tempSizeTwo] = lineStorage[i][j];
                                    tempSizeTwo++;
                                }
                            }
                        }

                        strcpy(headerOtherFieldTagStorage[headerOtherFieldCount], tempFieldStorage);
                        strcpy(headerOtherFieldValueStorage[headerOtherFieldCount], tempDataStorage);
                        headerOtherFieldCount++;
                        memset(tempFieldStorage, '\0', 1000);
                        memset(tempDataStorage, '\0', 1000);
                        tempSize = 0;
                        tempSizeTwo = 0;

                    }

                    i++;
                }

                headFlag = 0;
            }
            else if(indiFlag == 1)
            {
                while(lineStorage[i+1][0] != '0')
                {
                    
                    if(strcasestr(lineStorage[i], 'NAME'))
                    {
                        for(int j = 7; j < strlen(lineStorage[i]) ; j++)
                        {
                            while(lineStorage[i][j+1] != ' ')
                            {
                                tempFieldStorage[tempSize] = lineStorage[i][j];
                                tempSize++;
                                j++;
                            }

                            j++;
                            while(lineStorage[i][j+1] != '/')
                            {
                                tempDataStorage[tempSizeTwo] lineStorage[i][j];
                                tempSizeTwo++;
                                j++;
                            }
                        }

                        strcpy(individualGivenNameStorage[totalIndividaulCount], tempFieldStorage);
                        strcpy(individualSurNameStorage[totalIndividaulCount], tempDataStorage);
                        memset(tempFieldStorage, '\0', 1000);
                        memset(tempDataStorage, '\0', 1000);
                        tempSize = 0;
                        tempSizeTwo = 0;
                    }
                    // else if(strcasestr(lineStorage[i], ''))
                    i++;
                }

                indiFlag = 0;

            }
            else if(famFlag == 1)
            {
                while(lineStorage[i+1][0] != '0')
                {
                    
                    
                    i++;
                }

                famFlag = 0;

            }
            else if(submFlag == 1)
{'fraction_non_alphanumeric': 0.10364256805015475, 'fraction_numerical': 0.027934290929291325, 'mean_word_length': 1.1757596685082874, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '399623', 'n_tokens_mistral': 3622, 'n_tokens_neox': 3222, 'n_words': 603}