void Map::loadMapFromFile(const std::string& filename) { std::ifstream file(filename, std::ios::in); std::vector<Tile> mapLine; std::string line; if (!_map.empty()) { while (!_map.empty()) _map.pop_back(); } while (std::getline(file, line)) { mapLine = getFileLine(line); _map.push_back(mapLine); } this->printMap(); }
void pngtxt_addChunk(struct pngx * const pngxP, FILE * const tfP, bool const ztxt, bool const itxt, bool const verbose) { /*---------------------------------------------------------------------------- Add text chunks (tEXt, zTXt, or iTXt) to the PNG image represented by *pngxP as directed by file *tfP. 'itxt' means to make them international language (iTXt) chunks. Otherwise they are either tEXt or zTXt chunks, depending upon 'ztxt'. 'ztxt' means to make the text compressed. If the chunks are not international (i.e. 'itxt' is false), this means the chunks are zTXt chunks instead of 'tEXt' chunks. -----------------------------------------------------------------------------*/ bool noChunksYet; bool eof; png_textp text; /* An array; one chunk per element */ unsigned int chunkCt; /* Number of chunks we have completed in the 'text' array */ unsigned int allocatedChunkCt; /* Number of entries currently allocated for the PNG text array */ /* In an international text string file, the first entry tells the language of all of the chunks, by having key 'Language'. */ allocatedChunkCt = 256; /* initial value */ MALLOCARRAY(text, allocatedChunkCt); if (text == NULL) pm_error("unable to allocate memory for text chunk array"); for (chunkCt = 0, noChunksYet = true, eof = false; !eof; ) { const char * textline; unsigned int lineLength; getFileLine(tfP, &textline, &lineLength); if (textline == NULL) eof = true; else { if (lineLength == 0) { /* skip this empty line */ } else { handleArrayAllocation(&text, &allocatedChunkCt, chunkCt); if (!isContinuationLine(textline)) { png_text * textChunkP; if (noChunksYet) { /* No previous chunk to move past */ } else ++chunkCt; noChunksYet = false; textChunkP = &text[chunkCt]; if (itxt) startTextChunkIntl(textChunkP, textline, lineLength, ztxt, verbose); else startTextChunkEngl(textChunkP, textline, lineLength, ztxt, verbose); } else { png_text * const textChunkP = &text[chunkCt]; /* Line starts with whitespace, which means it is a continuation of the current text string. */ if (noChunksYet) pm_error("Invalid text string file format: " "first line is a continuation line! " "(It starts with whitespace)"); continueTextString(textChunkP, textline, lineLength); } } pm_strfree(textline); } } if (!noChunksYet) ++chunkCt; if (verbose) reportChunkCt(ztxt, itxt, chunkCt); if (chunkCt > 0) pngx_setText(pngxP, text, chunkCt); free(text); }
void ShaderBuild::parseLog(std::string* errStr, std::string log, int baseFile, bool readLineNumbers) { std::string line, first, second; std::stringstream reader(log); int prevFile = -1; int prevLine = -1; while (getline(reader, line)) { //attempt to read two ints - file ane line numbers int end = extractInt(line, first); if (readLineNumbers && end > 0) end = extractInt(line.substr(end), second); //if found, replace the error line with the file info if (end > 0) { //read/convert line numbers int filenum = stringToInt(first); //I could swear nvidia's compiler is reporting bad line numbers when #line is used int linenum = stringToInt(second); //stupid ATI drivers don't like #line before #version, so the root file never has a #line //this workaround replaces file 0 with the REAL file. thanks, AMD. real helpful if (filenum == 0) filenum = baseFile; //extract error message end = (int)line.find(":", end); std::string errormsg; if (end >= 0) errormsg = line.substr(end + 1); else errormsg = line; //add file/line number info if available line = ""; if (filenum >= 0 && filenum < (int)allfilebits.size()) line += allfilebits[filenum].filename + ":"; else line += "<unknown file " + intToString(filenum) + ">"; if (readLineNumbers && linenum >= 0) line += intToString(linenum) + ":"; //if both are available and valid, attempt to include the source line from the file int tabw = (int)line.size(); std::string faultline; if (filenum >= 0 && linenum >= 0 && filenum < (int)allfilebits.size()) { std::string sourceLine; if (!getFileLine(allfilebits[filenum].filename, linenum, sourceLine)) sourceLine = "<I'm stupid and can't read the source>"; if (sourceLine.size() == 0) sourceLine = "<empty line>"; faultline = " " + sourceLine; } else faultline = " <line not given>"; line += faultline; //add the actual error message to the end if (prevLine == linenum && prevFile == filenum) line = std::string(tabw, ' ') + errormsg; else line += "\n" + std::string(tabw, ' ') + errormsg; prevLine = linenum; //if this is the first time the file was mentioned, give the include path //FIXME: this is incorrect. each occurance of an include should be marked // as a separate file so as to distinguish the include path!!! if (prevFile != filenum) { if (filenum >= 0 && filenum < (int)allfilebits.size()) line = printPath(allfilebits[filenum].path) + line; else line = "<error in file number>\n" + line; prevFile = filenum; } } //print the line if (errStr) *errStr += line + "\n"; else std::cout << line << std::endl; } }