internal u32 LoadCSV(char *Filename, r32 **ArrayRef) { FILE *File; fopen_s(&File, Filename, "r"); u32 ArraySize = 10; r32 *Values = (r32 *)malloc(sizeof(r32) * 10); AssertAligned(Values); u32 ArrayUsed = 0; if(File) { s32 Character = fgetc(File); char FloatString[6]; while(Character != EOF) { u32 i = 0; char *String = FloatString; while(Character != ',' && Character != '\n' && Character != EOF) { Assert(i++ < 6); *String++ = (char)Character; Character = fgetc(File); } *String = 0; r32 FloatValue = (r32)atof((char *)FloatString); Values[ArrayUsed++] = FloatValue; if(ArrayUsed == ArraySize) { ArraySize *= 2; Values = (r32 *)realloc(Values, sizeof(r32) * ArraySize); AssertAligned(Values); } Character = fgetc(File); } fclose(File); } *ArrayRef = Values; return ArrayUsed; }
BOOL StoreLine( char *line, int lineLen, int *offset, BYTE *prevLength, LPBLOCKDEF * pCurBlock ) { LPLINEREC pl; if ((*offset + (LHD + lineLen)) > BLOCK_SIZE) { //We arrived at the end of the block. Allocates a new one. if (!AllocateBlock(*pCurBlock, NULL, pCurBlock)) return FALSE; ((*pCurBlock)->PrevBlock)->NextBlock = *pCurBlock; *offset = 0; if ((*pCurBlock)->PrevBlock == NULL) *prevLength = 0; } (*pCurBlock)->LastLineOffset = *offset; pl = (LPLINEREC)((*pCurBlock)->Data + *offset); AssertAligned(pl); pl->PrevLength = *prevLength; pl->Length = (BYTE)(LHD + lineLen); pl->Status = 0; memmove((LPSTR)(pl->Text), (LPSTR)line, lineLen); *prevLength = (BYTE)(LHD + lineLen); *offset += LHD + lineLen; #ifdef ALIGN *offset = (*offset + 3) & ~3; #endif return TRUE; } /* StoreLine() */