65 lines
2.2 KiB
C
65 lines
2.2 KiB
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <strings.h>
|
|
#include "libs/fileLoader.h"
|
|
#include "structs.h"
|
|
|
|
#define MAX_STR_LEN 1024
|
|
|
|
const char *SEED_TXT = "seeds";
|
|
const char *SEEDTOSOIL_TXT = "seed-to-soil map:";
|
|
const char *SOILTOFERI_TXT = "soil-to-fertilizer map";
|
|
const char *FERTITOWATER_TXT = "fertilizer-to-water map";
|
|
const char *WATERTOLIGHT_TXT = "water-to-light map";
|
|
const char *LIGHTTOTEMP_TXT = "light-to-temperature map";
|
|
const char *TEMPTOHUMID_TXT = "temperature-to-humidity map";
|
|
const char *HUMIDTOLOC_TXT = "humidity-to-location map";
|
|
|
|
Almanac *parseFile(OpenFile *file)
|
|
{
|
|
Almanac *data = (Almanac *)malloc(sizeof(Almanac));
|
|
for (int iterator = 0; iterator < file->fileSize; iterator++)
|
|
{
|
|
// Initialize the data
|
|
data->seeds = (Seeds *)malloc(sizeof(Seeds));
|
|
data->seedtosoil = (SeedToSoilMap *)malloc(sizeof(SeedToSoilMap));
|
|
data->soiltoferti = (SoilToFertiMap *)malloc(sizeof(SoilToFertiMap));
|
|
data->ferttowater = (FertiToWaterMap *)malloc(sizeof(FertiToWaterMap));
|
|
data->watertplight = (WaterToLightMap *)malloc(sizeof(WaterToLightMap));
|
|
data->lighttotemp = (LightToTempMap *)malloc(sizeof(LightToTempMap));
|
|
data->temptohumid = (TempToHumidMap *)malloc(sizeof(TempToHumidMap));
|
|
data->humidtoloc = (HumidToLocMap *)malloc(sizeof(HumidToLocMap));
|
|
|
|
const char DELIM[2] = ":";
|
|
char *token;
|
|
char *save_ptr;
|
|
|
|
for (int i = 0; i < file->fileSize; i++)
|
|
{
|
|
char *tmpString = (char *)malloc(MAX_STR_LEN);
|
|
if (file->fileData[i] == '\n')
|
|
{
|
|
token = strtok_r(tmpString, DELIM, &save_ptr);
|
|
continue;
|
|
}
|
|
tmpString[i] = file->fileData[i];
|
|
}
|
|
|
|
// const char NEWLN_DELIM[2] = "\n";
|
|
// char *line_token;
|
|
// char *line_save_ptr;
|
|
|
|
// line_token = strtok_r(file->fileData, NEWLN_DELIM, &line_save_ptr);
|
|
// while (line_token != NULL)
|
|
// {
|
|
// if (strcmp(line_token, SEED_TXT) == 0)
|
|
// {
|
|
// printf("We looking at seeds");
|
|
// }
|
|
|
|
// line_token = strtok_r(NULL, file->fileData, &line_save_ptr);
|
|
// }
|
|
}
|
|
|
|
return data;
|
|
} |