#include "tiledef.hpp"
tile_t* ParseTileData(std::string tile) {
tile_t* t;
size_t blocksize = 512;
char* buf = new char[blocksize];
if(tile.size() == 0) {
std::printf("[ERROR]: Tile data corrupt or empty!\n");
std::exit(1);
}
// Parsing the tile data
while(std::fgets(buf, sizeof buf, stdin)) {
uint32_t id = std::strtol(buf, NULL, 0);
t->id = id;
std::printf("[DATA]: \nTileID: \t%d\n", id);
}
// Check if buffer still contains some data
delete buf;
return t;
}
// Opens the tile table, reads it line-by-line,
// Removes newlines from read string and saves it to the string table;
std::vector<std::string> LoadTiles() {
std::vector<std::string> tileids;
std::ifstream file;
std::string line;
char c = '\0';
size_t len = 0;
size_t lines = 0;
size_t read = 0;
// Open the file as text
file.open("tileids.txt", std::ios::in);
// Check whether the file exists, is corrupt or empty
if(file.bad()) {
std::printf("[ERROR]: TileID table corrupt or empty!\n");
file.close();
std::exit(1);
} else {
// Count the number of lines in the file
lines = CountLines(file);
std::printf("[DEBUG]: Lines: [%zu]\n", lines);
// Reset the position of the file
file.seekg(std::ios::beg);
// Read the file line by line
while(std::getline(file, line)) {
// Remove any unnecessary newlines
if(line[line.size()-1] == '\n') {
line[line.size()-1] = '\0';
}
// Print the content and the length
std::printf("[DATA]: \n\t[%s]", line);
std::printf("\t[LENGTH]: [%zu]\n", read);
// Save the content of the line into a string array
tileids.push_back(line);
std::printf("\t[TILEID]: \t[%s]\n", tileids.at(read++));
}
// Close the file
file.close();
}
return tileids;
}
int main() {
std::printf("[DEBUG]: Initialized!\n\n");
std::vector<std::string> tmp;
tmp = LoadTiles();
std::printf("\n[TILEID LIST]: \n");
for(auto &i: tmp) {
std::printf("\t[%s]\n", i);
}
std::printf("\n");
return 0;
}
/* The output:
* [DEBUG]: Initialized!
* [DEBUG]: Lines: [2]
* [TILEID LIST]:
*
* Process returned 0 (0x0) execution time : 0.010 s
* Press any key to continue.
*/
{"html5":"htmlmixed","css":"css","javascript":"javascript","php":"php","python":"python","ruby":"ruby","lua":"text\/x-lua","bash":"text\/x-sh","go":"go","c":"text\/x-csrc","cpp":"text\/x-c++src","diff":"diff","latex":"stex","sql":"sql","xml":"xml","apl":"apl","asterisk":"asterisk","c_loadrunner":"text\/x-csrc","c_mac":"text\/x-csrc","coffeescript":"text\/x-coffeescript","csharp":"text\/x-csharp","d":"d","ecmascript":"javascript","erlang":"erlang","groovy":"text\/x-groovy","haskell":"text\/x-haskell","haxe":"text\/x-haxe","html4strict":"htmlmixed","java":"text\/x-java","java5":"text\/x-java","jquery":"javascript","mirc":"mirc","mysql":"sql","ocaml":"text\/x-ocaml","pascal":"text\/x-pascal","perl":"perl","perl6":"perl","plsql":"sql","properties":"text\/x-properties","q":"text\/x-q","scala":"scala","scheme":"text\/x-scheme","tcl":"text\/x-tcl","vb":"text\/x-vb","verilog":"text\/x-verilog","yaml":"text\/x-yaml","z80":"text\/x-z80"}