Files
arounders/source/aux_textfile.cpp
Raimon Zamora bc59b74f15 - [NEW] jshader (shader fan cosa rara en fullscreen)
- [NEW] jfile convertit
- [NEW] jinput te en compte el ratio per a les coordenades en pantalla (falla en fullscreen, falta afegir offset)
- [NEW] F1 escala avall la finestra
- [NEW] F2 escala amunt la finestra
- [NEW] F3 togglecha la pantalla completa
- [NEW] F4 togglecha el shader
2025-07-01 13:46:58 +02:00

69 lines
1.3 KiB
C++

#include "aux_textfile.h"
#include "jgame.h"
#include <stdlib.h>
namespace textfile
{
char *buffer = nullptr;
int fsize = 0;
int p = 0;
const int toInt(std::string token)
{
int value = 0;
for (std::size_t i=0; i<token.length(); ++i)
{
if (token[i]<48 || token[i]>57) return 0;
value = (value*10) + (token[i]-48);
}
return value;
}
const bool open(std::string filename)
{
buffer = file::getFileBuffer(filename.c_str(), fsize);
p = 0;
return true;
}
void close()
{
free(buffer);
}
std::string getNextToken()
{
char token[255];
int tpos = 0;
// Ignore whitespace
while (p<fsize && buffer[p]<=32 ) p++;
// Grab token
while (p<fsize && buffer[p]>32 ) token[tpos++]=buffer[p++];
token[tpos]=0;
return std::string(token);
}
const bool searchToken(std::string token)
{
while (p<fsize && getNextToken() != token) p++;
return p<fsize;
}
std::string getStringValue(std::string token)
{
textfile::searchToken(token);
textfile::searchToken("=");
return textfile::getNextToken();
}
const int getIntValue(std::string token)
{
return toInt(getStringValue(token));
}
}