Licar/frontend_helper.h

88 lines
1.3 KiB
C
Raw Normal View History

2025-06-01 19:59:09 +02:00
/** @file frontend_helper.h
Helper file for generic PC frontends that can use the stdio library, to avoid
duplication of code.
*/
// TODO: quality presets?
#include <stdint.h>
#include <stdio.h>
#define DATA_FILE_NAME "data"
FILE *dataFile = 0;
char LCR_getNextDataFileChar(void)
{
#ifdef __EMSCRIPTEN__
return 0;
#else
if (!dataFile)
return 0;
int c = fgetc(dataFile);
if (c == EOF)
{
rewind(dataFile);
return 0;
}
return c;
#endif
}
void LCR_appendDataStr(const char *str)
{
#ifndef __EMSCRIPTEN__
if (!dataFile)
return;
if (str == 0 || *str == 0)
rewind(dataFile);
else
{
#if LCR_SETTING_LOG_LEVEL > 1
printf("SDL: appending data \"%s\"\n",str);
#endif
fclose(dataFile);
dataFile = fopen(DATA_FILE_NAME,"a");
if (dataFile)
{
fprintf(dataFile,"%s",str);
fclose(dataFile);
dataFile = fopen(DATA_FILE_NAME,"r");
}
}
#else
printf("%s",str);
#endif
}
void LCR_log(const char *str)
{
printf("%s\n",str);
}
void openDataFile(void)
{
#ifndef __EMSCRIPTEN__
dataFile = fopen(DATA_FILE_NAME,"r");
if (!dataFile)
puts("WARNING: couldn't open data file");
#endif
}
void closeDataFile(void)
{
#ifndef __EMSCRIPTEN__
if (dataFile)
fclose(dataFile);
#endif
}