예제 #1
0
파일: libconvert.cpp 프로젝트: hfr1988/DEye
void convert::replaceAllStringInFile(const std::string& oldfilename, const std::string& newfilename, const std::string& oldstring, const std::string& newstring)
{
    std::string s = readStringFromFile(oldfilename);
    if (s.length() <= 0) { return; }
    replaceAllString(s, oldstring, newstring);
    writeStringToFile(s, newfilename);
}
예제 #2
0
void cGame::InitQuestions()
{
	const char *kFileName = "database.txt";
	const Uint32 kDataPieces = 6;
	for(int questionNum = 0; questionNum < kAmountOfQuestions; ++questionNum)
	{
		cQuestion *pQuestion = new cQuestion();

		pQuestion->mQuestion = readStringFromFile(kFileName, questionNum, kDataPieces, 0);
		pQuestion->mAnswer1 = readStringFromFile(kFileName, questionNum, kDataPieces, 1);
		pQuestion->mAnswer2 = readStringFromFile(kFileName, questionNum, kDataPieces, 2);
		pQuestion->mAnswer3 = readStringFromFile(kFileName, questionNum, kDataPieces, 3);
		pQuestion->mAnswer4 = readStringFromFile(kFileName, questionNum, kDataPieces, 4);
		pQuestion->mCorrectAnswer = readNumberFromFile(kFileName, questionNum, kDataPieces, 5);

		mList.push_back( pQuestion );
	}
}
예제 #3
0
bool normalizedSleepers()
{
    char value[256] = {0,};

    if (readStringFromFile(kSchedFeatures, value, sizeof(value)) == -1)
    {
        printErrno(kDebugfsWarningMsg, kSchedFeatures);
        return false;
    }
    return strstr(value, "NO_NEW_FAIR_SLEEPERS") == NULL;
}
예제 #4
0
char *maybeReadFile(const char *filename)
{
    if (filename == NULL)
        return NULL;
    char *str = readStringFromFile(filename);
    if (str == NULL) {
        perror(filename);
        exit(1);
    }
    return str;
}
예제 #5
0
void App::readPreferences() {
	if (!preferences_filepath) return;
	char *preferences_str = readStringFromFile(preferences_filepath);
	if (!preferences_str) return;

	IniVar preferences_vars[] = {
		{"shader_file_autoreload", INI_VAR_BOOL, &shader_file_autoreload},
		{"single_triangle_mode", INI_VAR_BOOL, &single_triangle_mode}
	};
	parseIniString(preferences_str, preferences_vars, ARRAY_COUNT(preferences_vars));

	delete [] preferences_str;
}
예제 #6
0
Error extractVariables(const FilePath& file, Variables* pVariables)
{
   // read in the file
   std::string contents;
   Error error = readStringFromFile(file,
                                    &contents,
                                    string_utils::LineEndingPosix);
   if (error)
      return error;

   extractVariables(contents, pVariables);

   return Success();
}
예제 #7
0
	void readMaterialsFromMaxFile(const Lump &materialLump, std::vector<std::shared_ptr<Material> >& materials, std::ifstream& in)
	{
		unsigned int offset = materialLump.Offset;
		unsigned int offsetEnd = offset + materialLump.Length;

		while(offset < offsetEnd)
		{
			Material newMaterial;
			offset += readStringFromFile(newMaterial.m_name, in, offset) + sizeof(unsigned int);

			// read diffuse texture
			//
			std::string diffuse;
			offset += readStringFromFile(diffuse, in, offset) + sizeof(unsigned int);

			if(diffuse.length() > 0)
				newMaterial.m_diffuseTexture = Texture::CreateOrGetTexture("Textures\\" + diffuse);
			else
				newMaterial.m_diffuseTexture = nullptr;

			std::string normal;
			offset += readStringFromFile(normal, in, offset) + sizeof(unsigned int);

			if(normal.length() > 0)
				newMaterial.m_normalMap = Texture::CreateOrGetTexture("Textures\\" + normal);
			else
				newMaterial.m_normalMap = nullptr;



	


			materials.push_back(std::make_shared<Material>(newMaterial) );
		}
	}
예제 #8
0
int pidOutOfMemoryAdj()
{
    char filename[FILENAME_MAX];

    snprintf(filename, sizeof(filename), "/proc/%d/oom_adj", getpid());

    char value[16];
    if (readStringFromFile(filename, value, sizeof(value)) == -1)
    {
        return -127;
    }
    else
    {
        return atoi(value);
    }
}
예제 #9
0
Error extractVariables(const FilePath& file, Variables* pVariables)
{
   // read in the file
   std::string contents;
   Error error = readStringFromFile(file,
                                    &contents,
                                    string_utils::LineEndingPosix);
   if (error)
      return error;

   // scan for variables via regex iterator
   boost::regex var("^([A-Za-z0-9_]+=[^\n]+)$");
   boost::sregex_token_iterator it(contents.begin(), contents.end(), var, 0);
   boost::sregex_token_iterator end;
   std::for_each(it, end, boost::bind(extractToMap, _1, pVariables));

   return Success();
}
예제 #10
0
Error extractVariables(const FilePath& file, Variables* pVariables)
{
   // return path not found if necessary
   if (!file.exists())
      return core::pathNotFoundError(file.absolutePath(), ERROR_LOCATION);

   // read in the file
   std::string contents;
   Error error = readStringFromFile(file,
                                    &contents,
                                    string_utils::LineEndingPosix);
   if (error)
      return error;

   extractVariables(contents, pVariables);

   return Success();
}
예제 #11
0
void App::readSession() {
	if (!session_filepath) return;
	char *session_str = readStringFromFile(session_filepath);
	if (!session_str) return;

	char *recently_used_str = nullptr; // "filepath0","filepath1","filepath2"
	IniVar session_vars[] = {
		{"recently_used", INI_VAR_STRING, &recently_used_str},
		{"video_width", INI_VAR_INT, &video.width},
		{ "video_height", INI_VAR_INT, &video.height },
		{ "video_fullscreen", INI_VAR_INT, &video.fullscreen },
	};
	parseIniString(session_str, session_vars, ARRAY_COUNT(session_vars));

	if (recently_used_str) {
		// free old stuff
		clearRecentlyUsedFilepaths();

		int recently_used_count = 0;
		char *filepath = nullptr;
		for (char *c = recently_used_str; *c; c++) {
			if (*c == '"') { // TODO: what about quotes in path
				if (!filepath) filepath = c+1;
				else {
					size_t filepath_len = c-filepath;
					if (filepath_len > 0) {
						recently_used_filepaths[recently_used_count] = new char[filepath_len+1];
						strncpy(recently_used_filepaths[recently_used_count], filepath, filepath_len);
						recently_used_filepaths[recently_used_count][filepath_len] = '\0';
						recently_used_count++;
						if (recently_used_count == ARRAY_COUNT(recently_used_filepaths)) break;
					} // else ignore empty string
					filepath = nullptr;
				}
			}
		}

		delete [] recently_used_str;
	}

	delete [] session_str;
}
예제 #12
0
Error parseDcfFile(const FilePath& dcfFilePath,
                   bool preserveKeyCase,
                   DcfFieldRecorder recordField,
                   std::string* pUserErrMsg)
{
   // read the file
   std::string dcfFileContents;
   Error error = readStringFromFile(dcfFilePath,
                                    &dcfFileContents);
   if (error)
   {
      error.addProperty("dcf-file", dcfFilePath.absolutePath());
      *pUserErrMsg = error.summary();
      return error;
   }

   return parseDcfFile(dcfFileContents,
                       preserveKeyCase,
                       recordField,
                       pUserErrMsg);
}
예제 #13
0
void App::loadShader(const char *frag_shader_filepath, bool reload) {
	char *shader_src = readStringFromFile(frag_shader_filepath);
	if (!shader_src) return; // couldn't read from file TODO: feedback

	if (!reload) { // first time load
		// store filepath
		if (shader_filepath) delete [] shader_filepath;
		shader_filepath = new char[strlen(frag_shader_filepath)+1];
		strcpy(shader_filepath, frag_shader_filepath);

		addMostRecentlyUsedFilepath(shader_filepath);
	}

	// copy src into editor buffer
	strncpy(src_edit_buffer, shader_src, sizeof(src_edit_buffer));
	// zero terminate just in case so we don't overflow in writeStringToFile
	src_edit_buffer[sizeof(src_edit_buffer)-1] = '\0';

	compileShader(shader_src, /*recompile*/reload);

	delete [] shader_src;
}
예제 #14
0
void BigPotConfig::init(const string& filepath)
{
#ifdef USINGJSON
	_filename = _filepath + "/config.json";
	printf("try find config file: %s\n", _filename.c_str());
	
	Json::Reader reader;
	_content = readStringFromFile(_filename);
	reader.parse(_content, _value);

	if (_value["record"].isObject())
		_record = _value["record"];
#else
	_filename = filepath + "/config.xml";
	printf("try find config file: %s\n", _filename.c_str());
	_doc.LoadFile(_filename.c_str());
#ifdef _DEBUG
	//_doc.Print();
#endif
	//³õʼ»¯½á¹¹
	if (_doc.Error())
	{
		//_doc.DeleteChildren();
		_doc.LinkEndChild(_doc.NewDeclaration());
		_root = _doc.NewElement("root");
	}
	else
	{
		_root = _doc.FirstChildElement("root");
	}

	_record = _root->FirstChildElement("record");
	if (!_record)
		_record = _root->InsertFirstChild(_doc.NewElement("record"))->ToElement();
#endif
}
예제 #15
0
파일: util.cpp 프로젝트: Remscar/cpgf
bool isFileContentSameToString(const std::string & fileName, const std::string & s)
{
	string content;
	readStringFromFile(fileName, &content);
	return s == content;
}
예제 #16
0
void SGFileBefore::readObjFile(const char* fileName, SGDagNodeContainer& container )
{
	string stringData = readStringFromFile(fileName);

	vector<string> lineStrs = SGObj::splitStrByChar(stringData, '\n');

	vector<SGDagNodeMesh*> ptrDagNodeMeshs;
	vector<string> vertexLines, normalLines, uvLines, faceLines;
	vector<int> startIndicesVtx, startIndicesNormal, startIndicesUV, startIndicesFace;

	startIndicesVtx.push_back(0);
	startIndicesNormal.push_back(0);
	startIndicesUV.push_back(0);
	startIndicesFace.push_back(0);

	bool normalExists = false;
	bool uvExists = false;

	int  numMeshs = 0;
	bool faceStart = false;
	
	for (int i = 0; i < lineStrs.size(); i++)
	{
		string& lineStr = lineStrs[i];
		if (!lineStr.size())continue;
		if (lineStr.at(0) == 'v' && lineStr.at(1) == ' ')
		{
			if (faceStart)
			{
				numMeshs++;
				startIndicesVtx.push_back(vertexLines.size());
				startIndicesNormal.push_back(normalLines.size());
				startIndicesUV.push_back(uvLines.size());
				startIndicesFace.push_back(faceLines.size());
				faceStart = false;
			}
			vertexLines.push_back(lineStr);
		}
		else if (lineStr.at(0) == 'v' && lineStr.at(1) == 'n')
		{
			normalExists = true;
			normalLines.push_back(lineStr);
		}
		else if (lineStr.at(0) == 'v' && lineStr.at(1) == 't')
		{
			uvExists = true;
			uvLines.push_back(lineStr);
		}
		else if (lineStr.at(0) == 'f' && lineStr.at(1) == ' ')
		{
			faceLines.push_back(lineStr);
			faceStart = true;
		}
	}
	numMeshs++;

	startIndicesVtx.push_back(vertexLines.size());
	startIndicesNormal.push_back(normalLines.size());
	startIndicesUV.push_back(uvLines.size());
	startIndicesFace.push_back(faceLines.size());

	for (int i = 0; i < numMeshs; i++)
	{
		SGDagNodeMesh* newMesh = new SGDagNodeMesh;
		newMesh->m_numUVs = 1;
		delete[] newMesh->m_uvArrays;
		newMesh->m_uvArrays = new vector<vector2d>[1];
		newMesh->m_uvArrays[0].resize(0);
		newMesh->m_numUVArrays.resize(1);
		newMesh->m_numUVArrays[0] = 0;
		ptrDagNodeMeshs.push_back(newMesh);
	}

	for (int i = 0; i < ptrDagNodeMeshs.size(); i++)
	{
		SGDagNodeMesh*& ptrDagNodeMesh = ptrDagNodeMeshs[i];

		ptrDagNodeMesh->m_points.resize(startIndicesVtx[i + 1] - startIndicesVtx[i]);
		for (int k = startIndicesVtx[i]; k < startIndicesVtx[i + 1]; k++)
		{
			vector3d& point = ptrDagNodeMesh->m_points[k - startIndicesVtx[i]];
			vector<string> firstSplits = SGObj::splitStrByChar(vertexLines[k], ' ');
			vector<string> splits;

			for (int m = 0; m < firstSplits.size(); m++)
			{
				if (firstSplits[m].size() == 0)continue;
				splits.push_back(firstSplits[m]);
			}

			point.x = atof(splits[1].c_str());
			point.y = atof(splits[2].c_str());
			point.z = atof(splits[3].c_str());
		}

		ptrDagNodeMesh->m_normals.resize(startIndicesNormal[i + 1] - startIndicesNormal[i]);/**/
		for (int k = startIndicesNormal[i]; k < startIndicesNormal[i + 1]; k++)
		{
			vector3d& normal = ptrDagNodeMesh->m_normals[k - startIndicesNormal[i]];
			vector<string> firstSplits = SGObj::splitStrByChar(normalLines[k], ' ');
			vector<string> splits;

			for (int m = 0; m < firstSplits.size(); m++)
			{
				if (firstSplits[m].size() == 0)continue;
				splits.push_back(firstSplits[m]);
			}
			normal.x = atof(splits[1].c_str());
			normal.y = atof(splits[2].c_str());
			normal.z = atof(splits[3].c_str());
		}

		ptrDagNodeMesh->m_uvArrays[0].resize(startIndicesUV[i + 1] - startIndicesUV[i]);/**/
		for (int k = startIndicesUV[i]; k < startIndicesUV[i + 1]; k++)
		{
			vector2d& UV = ptrDagNodeMesh->m_uvArrays[0][k - startIndicesUV[i]];
			vector<string> firstSplits = SGObj::splitStrByChar(uvLines[k], ' ');
			vector<string> splits;

			for (int m = 0; m < firstSplits.size(); m++)
			{
				if (firstSplits[m].size() == 0)continue;
				splits.push_back(firstSplits[m]);
			}
			UV.u = atof(splits[1].c_str());
			UV.v = atof(splits[2].c_str());
		}
	}

	for (int i = 0; i<ptrDagNodeMeshs.size(); i++)
	{
		SGDagNodeMesh* ptrDagNodeMesh = ptrDagNodeMeshs[i];
		SGDagNodeMeshBuffer* ptrBuffer = ptrDagNodeMesh->m_buffer;

		vector< vector<string> > splitsForTriangles;
		vector< vector<string> > splitsForQuads;
		vector< vector<string> > splitsForOverQuads;

		vector<int> triangleToPolygonMap;
		vector<int> quadToPolygonMap;
		vector<int> overQuadToPolygonMap;

		for (int k = startIndicesFace[i]; k < startIndicesFace[i+1]; k++)
		{
			vector<string> firstSplits = SGObj::splitStrByChar(faceLines[k], ' ');
			vector<string> splits;

			int originIndex = k - startIndicesFace[i];

			for (int m = 1; m < firstSplits.size(); m++)
			{
				if (firstSplits[m].size() == 0)continue;
				splits.push_back(firstSplits[m]);
			}

			if (splits.size() == 3) {
				splitsForTriangles.push_back(splits);
				ptrBuffer->m_numTriangles++;
				triangleToPolygonMap.push_back(originIndex);
			}
			else if (splits.size() == 4) {
				splitsForQuads.push_back(splits);
				ptrBuffer->m_numQuads++;
				quadToPolygonMap.push_back(originIndex);
			}
			else {
				splitsForOverQuads.push_back(splits);
				ptrBuffer->m_numOverQuads++;
				overQuadToPolygonMap.push_back(originIndex);
			}
			ptrDagNodeMesh->m_countArrayVertices.push_back(splits.size());
		}

		ptrBuffer->m_countArrayOverQuad.setLength(ptrBuffer->m_numOverQuads);
		ptrBuffer->m_sizeOverQuads = 0;
		for (int k = 0; k < ptrBuffer->m_numOverQuads; k++)
		{
			ptrBuffer->m_countArrayOverQuad[k] = splitsForOverQuads[k].size();
			ptrBuffer->m_sizeOverQuads += splitsForOverQuads[k].size();
		}

		ptrBuffer->m_bufferTriangles = new SGVertexBuffer[ptrBuffer->m_numTriangles*3];
		ptrBuffer->m_bufferQuads = new SGVertexBuffer[ptrBuffer->m_numQuads*4];
		ptrBuffer->m_bufferOverQuads = new SGVertexBuffer[ptrBuffer->m_sizeOverQuads];
		
		ptrDagNodeMeshs[i]->m_numVertices = ptrDagNodeMeshs[i]->m_points.size();
		ptrDagNodeMeshs[i]->m_numPolygons = startIndicesFace[i + 1] - startIndicesFace[i];
		ptrDagNodeMesh->m_vertexToPolygonsMap.resize(ptrDagNodeMeshs[i]->m_numVertices);
		ptrDagNodeMesh->m_polygonToVerticesMap.resize(ptrDagNodeMeshs[i]->m_numPolygons);

		for (int k = 0; k < splitsForTriangles.size(); k++)
		{
			int polygonIndex = triangleToPolygonMap[k];
			for (int m = 0; m < 3; m++)
			{
				SGVertexBuffer& vtxBuffer = ptrBuffer->m_bufferTriangles[k *3 + m];
				vector<string> element = SGObj::splitStrByChar(splitsForTriangles[k][m], '/');

				int vtxIndex = atoi(element[0].c_str()) - startIndicesVtx[i] - 1;
				vector3d& point = ptrDagNodeMesh->m_points[vtxIndex];
				vtxBuffer.x = point.x; vtxBuffer.y = point.y; vtxBuffer.z = point.z;

				ptrDagNodeMesh->m_vertexToPolygonsMap[vtxIndex].append(polygonIndex);
				ptrDagNodeMesh->m_polygonToVerticesMap[polygonIndex].append(vtxIndex);

				if (element.size() == 2)
				{
					int uvIndex = atoi(element[1].c_str()) - startIndicesUV[i] - 1;
					vector2d& uv = ptrDagNodeMesh->m_uvArrays[0][uvIndex];
					vtxBuffer.u = uv.u; vtxBuffer.v = uv.v;
				}
				else if (element.size() == 3)
				{
					int normalIndex = atoi(element[2].c_str()) - startIndicesNormal[i] - 1;
					vector3d& normal = ptrDagNodeMesh->m_normals[normalIndex];
					vtxBuffer.nx = normal.x; vtxBuffer.ny = normal.y; vtxBuffer.nz = normal.z;
				}
			}
		}

		for (int k = 0; k < splitsForQuads.size(); k++)
		{
			int polygonIndex = quadToPolygonMap[k];
			for (int m = 0; m < 4; m++)
			{
				SGVertexBuffer& vtxBuffer = ptrBuffer->m_bufferQuads[k*4+m];
				vector<string> element = SGObj::splitStrByChar(splitsForQuads[k][m], '/');
				
				int vtxIndex = atoi(element[0].c_str()) - startIndicesVtx[i] - 1;
				vector3d& point = ptrDagNodeMesh->m_points[vtxIndex];
				vtxBuffer.x = point.x; vtxBuffer.y = point.y; vtxBuffer.z = point.z;

				ptrDagNodeMesh->m_vertexToPolygonsMap[vtxIndex].append(polygonIndex);
				ptrDagNodeMesh->m_polygonToVerticesMap[polygonIndex].append(vtxIndex);

				if (element.size() == 2)
				{
					int uvIndex = atoi(element[1].c_str()) - startIndicesUV[i] - 1;
					vector2d& uv = ptrDagNodeMesh->m_uvArrays[0][uvIndex];
					vtxBuffer.u = uv.u; vtxBuffer.v = uv.v;
				}
				else if (element.size() == 3)
				{
					int normalIndex = atoi(element[2].c_str()) - startIndicesNormal[i] - 1;
					vector3d& normal = ptrDagNodeMesh->m_normals[normalIndex];
					vtxBuffer.nx = normal.x; vtxBuffer.ny = normal.y; vtxBuffer.nz = normal.z;
				}
			}
		}

		int targetIndex = 0;
		for (int k = 0; k < splitsForOverQuads.size(); k++)
		{
			int polygonIndex = overQuadToPolygonMap[k];
			for (int m = 0; m < ptrBuffer->m_countArrayOverQuad[k]; m++)
			{
				SGVertexBuffer& vtxBuffer = ptrBuffer->m_bufferOverQuads[targetIndex];
				vector<string> element = SGObj::splitStrByChar(splitsForOverQuads[k][m], '/');

				int vtxIndex = atoi(element[0].c_str()) - startIndicesVtx[i] - 1;
				vector3d& point = ptrDagNodeMesh->m_points[vtxIndex];
				vtxBuffer.x = point.x; vtxBuffer.y = point.y; vtxBuffer.z = point.z;

				ptrDagNodeMesh->m_vertexToPolygonsMap[vtxIndex].append(polygonIndex);
				ptrDagNodeMesh->m_polygonToVerticesMap[polygonIndex].append(vtxIndex);

				if (element.size() == 2)
				{
					int uvIndex = atoi(element[1].c_str()) - startIndicesUV[i] - 1;
					vector2d& uv = ptrDagNodeMesh->m_uvArrays[0][uvIndex];
					vtxBuffer.u = uv.u; vtxBuffer.v = uv.v;
				}
				else if (element.size() == 3)
				{
					int normalIndex = atoi(element[2].c_str()) - startIndicesNormal[i] - 1;
					vector3d& normal = ptrDagNodeMesh->m_normals[normalIndex];
					vtxBuffer.nx = normal.x; vtxBuffer.ny = normal.y; vtxBuffer.nz = normal.z;
				}
				targetIndex++;
			}
		}
	}
	
	for (int i = 0; i < ptrDagNodeMeshs.size(); i++)
	{
		SGDagNodeMeshBuffer* buffer = ptrDagNodeMeshs[i]->m_buffer;
		if (!normalExists)
		{
			ptrDagNodeMeshs[i]->setVertexNormals();
			ptrDagNodeMeshs[i]->setBuffer();
		}
		container.append(ptrDagNodeMeshs[i]);
	}
}
예제 #17
0
	void readModelNodesFromMaxFile(const Lump &NodeLump,
		std::vector<std::shared_ptr<Model::ModelNode> >& nodes, 
		std::vector<std::shared_ptr<Model::ModelNode> >& topNodes,
		std::vector<std::shared_ptr<Model::ModelNode> >& Bones,
		std::vector< std::shared_ptr< TriangleBatch> >& batches, 
		std::ifstream& in)
	{
		std::vector<MaxModelNodeInfo> MaxInfos;


		//--!--approximation--!--
		MaxInfos.reserve( NodeLump.Length / sizeof(MaxModelNodeInfo) );

		unsigned int offset = NodeLump.Offset;
		unsigned int offsetEnd = offset + NodeLump.Length;


		in.seekg(offset, std::ios::beg);

		while( offset  < offsetEnd )
		{
			Model::ModelNode node;
			MaxModelNodeInfo nodeInfo;
			unsigned int numFrames;
			unsigned int numChildren;
			unsigned int numBatches;
			int BoneID;
			std::vector<unsigned int> batchIDs;

			offset += readStringFromFile(node.m_name, in, offset) + sizeof(unsigned int);

			in.read((char*)&nodeInfo.parent, sizeof(int));
			offset += sizeof(int);

			in.read((char*)&numFrames, sizeof(unsigned int));
			offset += sizeof(unsigned int);

			in.read((char*)&numChildren, sizeof(unsigned int));
			offset += sizeof(unsigned int);

			in.read((char*)&numBatches, sizeof(unsigned int));
			offset += sizeof(unsigned int);

			in.read((char*)&BoneID, sizeof(unsigned int));
			offset += sizeof(unsigned int);

			node.m_localTMs.resize( numFrames );
			in.read((char*)&node.m_localTMs[0], sizeof(float) * 16 * numFrames);
			offset += sizeof(float) * 16 * numFrames;


			in.read((char*)&node.m_inverseRestMatrix, sizeof(float) * 16);
			offset += sizeof(float) * 16;

			if(numChildren > 0)
			{
				nodeInfo.childrenIDs.resize(numChildren);
				in.read((char*)&nodeInfo.childrenIDs[0], sizeof(unsigned int) * numChildren);
				offset += sizeof(unsigned int) * numChildren;
			}

			if(numBatches > 0)
			{
				batchIDs.resize(numBatches);
				in.read((char*)&batchIDs[0], sizeof(unsigned int) * numBatches);
				offset += sizeof(unsigned int) * numBatches;

				node.m_batches.reserve(numBatches);
				for(unsigned int i = 0; i < numBatches; ++i)
				{
					node.m_batches.push_back( batches[batchIDs[i] ] );
				}

			}

			MaxInfos.push_back(nodeInfo);
			std::shared_ptr<Model::ModelNode> nodePtr = std::make_shared<Model::ModelNode>(node);
			nodes.push_back( nodePtr );

			if(BoneID >= 0 && BoneID < (int)Bones.size())
				Bones[BoneID] = nodePtr;

		}

		//make Node Tree
		size_t numNodes = MaxInfos.size();
		for(size_t i = 0; i < numNodes; ++i)
		{
			if(MaxInfos[i].parent == -1)
			{
				//this is a toplevelnode
				topNodes.push_back( nodes[i] );
				nodes[i]->m_parent = nullptr;
			}
			else
			{
				nodes[i]->m_parent = nodes[MaxInfos[i].parent];
			}

			//add its children
			size_t numChildren = MaxInfos[i].childrenIDs.size();
			for( size_t c = 0; c < numChildren; ++c)
			{
				nodes[i]->AddChildNode(nodes[ MaxInfos[i].childrenIDs[c] ] );
			}
		}
	}
예제 #18
0
AccountsList* loadAccountsFromFile(const char *filename)
{
	int file_descriptor = open(filename, O_RDONLY);

	if(file_descriptor < 0)
	{
		if(errno == ENOENT)
			errorMessage("File \"%s\" doesn't exist.", filename);
		else
			errorMessage("File \"%s\" can't be opened.", filename);
		return NULL;
	}

	unsigned int nb_accounts;
	int return_value = readUIntFromFile(file_descriptor, &nb_accounts, ';');
	if(return_value < 0)
	{
		if(return_value == -2)
			errorMessage("Number of accounts not found in file.");
		else
			errorMessage("An error has occurred while reading file.");

		close(file_descriptor);
		return NULL;
	}
	goAfterCharacterInFile(file_descriptor, ';');

	AccountsList *list = createAccountsList(nb_accounts);
	traceMessage("Accounts list of length %d created", (int) nb_accounts);
	char buffer1[50], buffer2[50], *login, *password;
	unsigned int tmp;
	int x, y;

	int i;
	for(i=0; i<nb_accounts; i++)
	{
		// lecture du login.
		if(readStringFromFile(file_descriptor, buffer1, 50, ':') < 0 || (login = extractStringWithoutSpace(buffer1)) == NULL)
		{
			destroyAccountsList(list);
			close(file_descriptor);
			return NULL;
		}
		if(!isCorrectLoginOrPassword(login))
		{
			warningMessage("Login \"%s\" readed in file is syntactically false. Accounts list can't be load from file.", login);
			destroyAccountsList(list);
			close(file_descriptor);
			return NULL;
		}
		goAfterCharacterInFile(file_descriptor, ':');

		// Lecture du mot de passe.
		if(readStringFromFile(file_descriptor, buffer2, 50, ':') < 0 || (password = extractStringWithoutSpace(buffer2)) == NULL)
		{
			destroyAccountsList(list);
			close(file_descriptor);
			return NULL;
		}
		if(!isCorrectLoginOrPassword(password))
		{
			warningMessage("Password \"%s\" readed in file is syntactically false. Accounts list can't be load from file.", password);
			destroyAccountsList(list);
			close(file_descriptor);
			return NULL;
		}
		goAfterCharacterInFile(file_descriptor, ':');

		// lecture de x.
		return_value = readUIntFromFile(file_descriptor, &tmp, ':');
		if(return_value == -1)
		{
			errorMessage("An error has occurred while reading file.");
			destroyAccountsList(list);
			close(file_descriptor);
			return NULL;
		}
		else if(return_value == -2)
			x = -1;
		else
			x = (int) tmp;
		goAfterCharacterInFile(file_descriptor, ':');

		// Lecture de y si necessaire.
		if(x != -1)
		{
			return_value = readUIntFromFile(file_descriptor, &tmp, ';');
			if(return_value == -1)
			{
				errorMessage("An error has occurred while reading file.");
				destroyAccountsList(list);
				close(file_descriptor);
				return NULL;
			}
			else if(return_value == -2)
				x = y = -1;
			else
				y = (int) tmp;
		}
		else
			y = -1;

		goAfterCharacterInFile(file_descriptor, ';');

		addAccountToList(list, login, password, x, y);
	}

	close(file_descriptor);
	return list;
}
예제 #19
0
int schedFeatures(char *str, size_t size)
{
    return readStringFromFile(kSchedFeatures, str, size);
}
예제 #20
0
Error parseDcfFile(const FilePath& dcfFilePath,
                   bool preserveKeyCase,
                   std::map<std::string,std::string>* pFields,
                   std::string* pUserErrMsg)
{
   // read the file
   std::string dcfFileContents;
   Error error = readStringFromFile(dcfFilePath,
                                    &dcfFileContents);
   if (error)
   {
      error.addProperty("dcf-file", dcfFilePath.absolutePath());
      *pUserErrMsg = error.summary();
      return error;
   }

   // split into lines
   std::vector<std::string> dcfLines;
   boost::algorithm::split(dcfLines,
                           dcfFileContents,
                           boost::algorithm::is_any_of("\r\n"));

   // iterate over lines
   int lineNumber = 0;
   std::string currentKey;
   std::string currentValue;
   for(std::vector<std::string>::const_iterator it = dcfLines.begin();
       it != dcfLines.end();
       ++it)
   {
      lineNumber++;

      // skip blank lines
      if (it->empty() || boost::algorithm::trim_copy(*it).empty())
         continue;

      // skip comment lines
      if (it->at(0) == '#')
         continue;

      // define regexes
      boost::regex keyValueRegx("([^\\s]+?)\\s*\\:\\s*(.*)$");
      boost::regex continuationRegex("[\t\\s](.*)");

       // look for a key-value pair line
      boost::smatch keyValueMatch, continuationMatch;
      if (regex_match(*it, keyValueMatch, keyValueRegx))
      {
         // if we have a pending key & value then resolve it
         if (!currentKey.empty())
         {
            pFields->insert(std::make_pair(currentKey,currentValue));
            currentKey.clear();
            currentValue.clear();
         }

         // update the current key and value
         currentKey = preserveKeyCase ?
                                 keyValueMatch[1] :
                                 string_utils::toLower(keyValueMatch[1]);
         currentValue = keyValueMatch[2];
      }

      // look for a continuation
      else if (!currentKey.empty() &&
               regex_match(*it, continuationMatch, continuationRegex))
      {
         currentValue.append("\n");
         currentValue.append(continuationMatch[1]);
      }

      // invalid line
      else
      {
         Error error = systemError(boost::system::errc::protocol_error,
                                   ERROR_LOCATION);
         boost::format fmt("file line number %1% is invalid");
         *pUserErrMsg = boost::str(fmt % lineNumber);
         error.addProperty("parse-error", *pUserErrMsg);
         error.addProperty("line-contents", *it);
         return error;
      }
   }

   // resolve any pending key and value
   if (!currentKey.empty())
      pFields->insert(std::make_pair(currentKey,currentValue));

   return Success();
}
예제 #21
0
int kernelVersion(char *str, size_t size)
{
    return readStringFromFile(kKernelVersion, str, size);
}