<commit_before>#include "fileio.h"

#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include "board.h"
#include "game.h"
#include "hiscore.h"

char *configDir;

void getConfigDir()
{
	char *homeDir = getenv("HOME");

	if(homeDir != NULL)
	{
		configDir = (char *)malloc(strlen(homeDir) + strlen("/.shisen-seki") + 1);
		if(configDir != NULL)
		{
			sprintf(configDir, "%s/.shisen-seki", homeDir);
			mkdir(configDir, 0755); // create the directory if doesn't exist
		}
	}
}

void getConfig()
{
	FILE *f;
	char *config;
	char line[15];

	if(!configDir)
	{
		printf("Config directory doesn't exist.\n");
		return;
	}

	config = (char *)malloc(strlen(configDir) + strlen("/game.cfg") + 1);

	if(!config)
	{
		return;
	}

	sprintf(config, "%s/game.cfg", configDir);

	f = fopen(config, "r");

	if(f == NULL)
	{
		printf("Failed to open config file: \"%s\" for reading.\n", config);
		return;
	}

	while(fgets(line, sizeof(line), f))
	{
		char *arg = strchr(line, ' ');

		if(!arg)
		{
			continue;
		}
		*arg = '\0';
		arg++;
	}

	fclose(f);
	free(config);
}

void storeConfig()
{
	FILE *f;
	char *config;

	if(!configDir)
	{
		printf("Config directory doesn't exist.\n");
		return;
	}

	config = (char *)malloc(strlen(configDir) + strlen("/game.cfg") + 1);

	if(!config)
	{
		return;
	}

	sprintf(config, "%s/game.cfg", configDir);

	f = fopen(config, "w");

	if(f == NULL)
	{
		printf("Failed to open config file: \"%s\" for writing.\n", config);
		return;
	}

	fclose(f);
	free(config);
}<commit_msg>Add flags to the game config<commit_after>#include "fileio.h"

#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include "board.h"
#include "game.h"
#include "hiscore.h"

char *configDir;

void getConfigDir()
{
	char *homeDir = getenv("HOME");

	if(homeDir != NULL)
	{
		configDir = (char *)malloc(strlen(homeDir) + strlen("/.shisen-seki") + 1);
		if(configDir != NULL)
		{
			sprintf(configDir, "%s/.shisen-seki", homeDir);
			mkdir(configDir, 0755); // create the directory if doesn't exist
		}
	}
}

void getConfig()
{
	FILE *f;
	char *config;
	char line[15];

	if(!configDir)
	{
		printf("Config directory doesn't exist.\n");
		return;
	}

	config = (char *)malloc(strlen(configDir) + strlen("/game.cfg") + 1);

	if(!config)
	{
		return;
	}

	sprintf(config, "%s/game.cfg", configDir);

	f = fopen(config, "r");

	if(f == NULL)
	{
		printf("Failed to open config file: \"%s\" for reading.\n", config);
		return;
	}

	while(fgets(line, sizeof(line), f))
	{
		char *arg = strchr(line, ' ');

		if(!arg)
		{
			continue;
		}
		*arg = '\0';
		arg++;

	if (!strcmp(line, "GAME_MODE"))
		sscanf(arg, "%d", (int *)&newGameMode);
	else if (!strcmp(line, "ALGORITHM"))
		sscanf(arg, "%d", (int *)&currentAlgorithm);
	else if (!strcmp(line, "ANIMATIONS"))
		sscanf(arg, "%d", &showAnimations);
	}

	fclose(f);
	free(config);
}

void storeConfig()
{
	FILE *f;
	char *config;

	if(!configDir)
	{
		printf("Config directory doesn't exist.\n");
		return;
	}

	config = (char *)malloc(strlen(configDir) + strlen("/game.cfg") + 1);

	if(!config)
	{
		return;
	}

	sprintf(config, "%s/game.cfg", configDir);

	f = fopen(config, "w");

	if(f == NULL)
	{
		printf("Failed to open config file: \"%s\" for writing.\n", config);
		return;
	}

	fprintf(f, "GAME_MODE %d\nALGORITHM %d\nANIMATIONS %d\n", newGameMode, currentAlgorithm, showAnimations);

	fclose(f);
	free(config);
}
{'fraction_non_alphanumeric': 0.2025974025974026, 'fraction_numerical': 0.005772005772005772, 'mean_word_length': 3.8475524475524474, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6761139', 'n_tokens_mistral': 1507, 'n_tokens_neox': 1406, 'n_words': 307}