Add frontend helper
This commit is contained in:
parent
765c742f08
commit
716a3dda38
7 changed files with 105 additions and 173 deletions
87
frontend_helper.h
Normal file
87
frontend_helper.h
Normal file
|
@ -0,0 +1,87 @@
|
|||
/** @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
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue