// _____________________________________________________________________________ bool parseObjFile( const string& filename, vector<vec3>* vertices, vector<vec3>* normals, vector<vec2>* uvCoords) { // opengl-tutorial.org like obj parser. // Open the file. #ifdef WINDOWS FILE* file = nullptr; fopen_s(&file, filename.c_str(), "rb"); #else FILE* file = fopen(filename.c_str(), "r"); #endif // WINDOWS // Is the file ready to be read? if (!file) { fprintf(stderr, "ERROR: could not open file %s\n", filename.c_str()); return false; } // Tmp variables to store read informations. vector<unsigned int> vIndices, nIndices, uvIndices; vector<vec3> tmpVertices; vector<vec3> tmpNormals; vector<vec2> tmpUVCoords; // stores the line. vector<char> buffer; // Read the file line by line into buffer. while (readLine(file, &buffer) != EOF) { // The line is now stored in buffer. interpretLine(buffer, &tmpVertices, &tmpNormals, &tmpUVCoords, &vIndices, &nIndices, &uvIndices); } // Last line of the file is parsed here. interpretLine(buffer, &tmpVertices, &tmpNormals, &tmpUVCoords, &vIndices, &nIndices, &uvIndices); // We are done reading the file. fclose(file); // Now we remove the indeces and store every face in the output vectors. size_t numIndices = vIndices.size(); // Resize the output vectors. vertices->clear(); vertices->reserve(numIndices); normals->clear(); normals->reserve(numIndices); uvCoords->clear(); uvCoords->reserve(numIndices); for (size_t i = 0; i < numIndices; ++i) { vertices->push_back(tmpVertices[vIndices[i] - 1]); if (tmpNormals.size() > nIndices[i] - 1) normals->push_back(tmpNormals[nIndices[i] - 1]); // If file has no tex coordinates defined ignore them! if (uvIndices[i] != 0) uvCoords->push_back(tmpUVCoords[uvIndices[i] - 1]); } printf("parsed a obj file with %lu faces\n", numIndices / 3); return true; }
void Network::parseLines(void) { QStringList cmds = this->_rbuffer.split('\n', QString::SkipEmptyParts); // Interpret each lines. for (int i = 0; i < cmds.size(); ++i) interpretLine(cmds[i]); // Remove read lines. int last = this->_rbuffer.lastIndexOf('\n'); this->_rbuffer = this->_rbuffer.remove(0, last + 1); }
void Interpreter::interpretScript(ifstream &inputFile, ofstream &outputFile) { string lineFromFile; int lineNumber = 0; //std::cout << "Interpret script"; while (getline(inputFile, lineFromFile)) { lineNumber++; interpretLine(lineFromFile, outputFile, inputFile, true); } }
/*----------------------------------------------------------------------------*/ static int readStream(FILE* inStream, struct EldritchConfig* conf) { int index; char* buffer = malloc(sizeof(char) * MAX_LINE_LENGTH + 1); config = conf; while(NULL != fgets(buffer, MAX_LINE_LENGTH, inStream)) { if(0 != interpretLine(buffer)) { free(buffer); configuration_error = "Malformed configuration file"; return -1; } } free(buffer); if(0 == feof(inStream)) { configuration_error = strerror(errno); return -1; } return 0; }
void Console::run() { mRun = true; while(mRun) { interpretLine(); } }