CFileReader::CFileReader(std::string filename){
  m_Filename = filename;
  std::string line;
  m_NumberOfLines = 0;
  
  std::ifstream file(filename.c_str());
  if(file.is_open()){
    m_bFileExists = true;

    while(!file.eof()){
      getline (file, line);
      line = RemoveSpaces(line);
      line = RemoveComments(line);

      if(line.size() != 0){
        m_NumberOfLines++;
        m_Lines.push_back(line);
      }
    }

    file.close();
  }
  else
    m_bFileExists = false;

}
Exemple #2
0
vector<string> StringUtils::TokenizeLine(string line, char delimiter) {
	//cout << "  tokenizing(" << delimiter << ") " << line << " -> ";
	vector<string> tokens;

	size_t delim, prev_delim;
	string str;

	delim = prev_delim = line.find(delimiter);
	str = line.substr(0, delim);
	tokens.push_back(str);
	//cout << "str = '" << str << "'" << endl;

	while ((delim = line.find(delimiter, ++delim)) != string::npos) {
		str = line.substr(prev_delim + 1, delim - prev_delim);
		tokens.push_back(str);
		prev_delim = delim;
	}

	str = line.substr(prev_delim + 1, delim - prev_delim);
	if (!str.empty())
		tokens.push_back(str);

	unsigned int i;
//	for (i = 0; i < tokens.size(); i++) {
//		cout << "    [" << tokens[i] << "] ";
//	}
//	cout << endl;
	for (i = 0; i < tokens.size(); i++) {
		//cout << "  will remove spaces " << tokens[i] << endl;
		//cout << "   ";
		RemoveSpaces(tokens[i]);
	}

	return tokens;
}
Exemple #3
0
void Table::AlignFields()
{
	RemoveSpaces();
	int l_Columns = GetColumns();
	Content l_Content = GetContent();
	Content l_ResultContent = l_Content;

	for (int l_Itr = 0; l_Itr < l_Columns; ++l_Itr)
	{
		int l_FieldSize = 0;
		for (Row l_Row : l_ResultContent)
			l_FieldSize = l_Row[l_Itr].size() > l_FieldSize ? l_Row[l_Itr].size() : l_FieldSize;

		l_FieldSize += 3;

		for (Row& l_Row : l_ResultContent)
		{
			int l_WhitespaceNumber = l_FieldSize - l_Row[l_Itr].size();
			for (int l_ThirdItr = 0; l_ThirdItr < l_WhitespaceNumber; ++l_ThirdItr)
			{
				if (!l_Itr && GetStructure(true) && !(l_ThirdItr < 2))
					l_Row[l_Itr] = " " + l_Row[l_Itr];
				else
					l_Row[l_Itr] += " ";
			}
		}
	}
	SetContent(l_ResultContent);
}
void Game::SaveMap(string PathToMap)
{
    ofstream File(PathToMap + "Enemies.txt");
    File.clear();
    for(auto itr = Enemies.begin(); itr != Enemies.end(); ++itr)
    {
        File << itr->ID << " " << itr->GetAttack() << " " << itr->GetDefense() 
            << " " << itr->GetHealth() << " " << itr->GetLevel() << " "
            << RemoveSpaces(itr->GetName()) << " " << itr->GetWealth() << " " << itr->GetX() << " "
            << itr->GetY() << " " << itr->MapTextureFileName << " " << itr->Combat << endl;
    }
    File.close();

    File.open(PathToMap + "RandomEncounters.txt");
    File.clear();
    for(auto itr = RandomEncounters.begin(); itr != RandomEncounters.end(); ++itr)
    {
        File << itr->ID << " " << itr->GetAttack() << " " << itr->GetDefense() 
            << " " << itr->GetHealth() << " " << itr->GetLevel() << " "
            << RemoveSpaces(itr->GetName()) << " " << itr->GetWealth() << " " << itr->Combat << endl;
    }
    File.close();

    File.open(PathToMap + "QuestGivers.txt");
    File.clear();
    for(auto itr = QuestGivers.begin(); itr != QuestGivers.end(); ++itr)
    {
        File << itr->ID << " " << itr->x << " " << itr->y << " " << itr->TextureFileName << " " << itr->Quests.size();
        for(auto iitr = itr->Quests.begin(); iitr != itr->Quests.end(); ++iitr)
        {
            File << " " << iitr->ID;
        }
        File << endl;
    }
    File.close();
}
Exemple #5
0
TEquationPtr ParseString( const char* cstr ) {
	std::string str(cstr);
	RemoveSpaces(str);
	try {
		TStrIter itBegin = str.begin();
		TEquationPtr result = ReadEquation(itBegin, str.end());
		if(itBegin != str.end()) throw EParseException("Training characters after equation");
		return result;
	} catch(EParseException e) {
		std::cout << "in string: \"" << str << "\" ";
		std::cout << "error: " << e.what();
		std::cout << "\n";
		return TEquationPtr();
	}
}
Exemple #6
0
void WaveFrontObj_WriteMaterial(const char *texelName, const char *texelFilename, const Material * const mat)
{
   char texelNameCopy[MAX_PATH];
   strcpy_s(texelNameCopy, texelName);
   RemoveSpaces(texelNameCopy);
   fprintf_s(matFile, "newmtl %s\n", texelNameCopy);
   fprintf_s(matFile, "Ns 7.843137\n");
   D3DXVECTOR4 color = convertColor(mat->m_cBase);
   fprintf_s(matFile, "Ka 0.000000 0.000000 0.000000\n");
   fprintf_s(matFile, "Kd %f %f %f\n", color.x, color.y, color.z);
   color = convertColor(mat->m_cGlossy);
   fprintf_s(matFile, "Ks %f %f %f\n", color.x, color.y, color.z);
   fprintf_s(matFile, "Ni 1.500000\n");
   fprintf_s(matFile, "d %f\n", mat->m_fOpacity);
   fprintf_s(matFile, "illum 5\n");
   if (texelFilename != NULL)
   {
      strcpy_s(texelNameCopy, texelFilename);
      RemoveSpaces(texelNameCopy);

      fprintf_s(matFile, "map_kd %s\n", texelNameCopy);
      fprintf_s(matFile, "map_ka %s\n\n", texelNameCopy);
   }
}
Exemple #7
0
macI *createList(macI *first, char *makeString[], int counter)
{
	macI *previous = first;	

	char *macName;
	char *macVal;
	int sIndex;
	int valIndex;

	for(int i = 0; i < counter; i++)
	{
		if((strchr(makeString[i], '=')) == NULL) continue;

		sIndex = 0;
		valIndex = 0;

		macName = malloc(strlen(makeString[i]) + 1);
		macVal = malloc(strlen(makeString[i]) + 1);

		while(makeString[i][sIndex] != '=')
		{
			macName[sIndex] = makeString[i][sIndex];
			sIndex = sIndex + 1;
		}

		macName[sIndex++] = '\0';

		while(makeString[i][sIndex] != '\n' )
			macVal[valIndex++] = makeString[i][sIndex++];

		macVal[valIndex] = '\0';

		RemoveSpaces(macName);

		macI *newMacro = insertMacro(previous, macName, macVal);
		previous = newMacro;
		free(macName);
		free(macVal);	
	}	

	first = first->next;
	

	return first;
}
Exemple #8
0
void Table::Shift()
{
	Content l_NewContent; 
	for (int l_Itr = 0; l_Itr < m_Columns; ++l_Itr)
	{
		l_NewContent.push_back(null);
		for (Row l_Row : m_Content)
		{
			l_NewContent[l_Itr].push_back(l_Row[l_Itr]);
		}
	}
	m_Content = l_NewContent;
	if (GetStructure(true))
	{
		TableStruct l_NewStruct;
		l_NewStruct.first = m_Struct.second;
		l_NewStruct.second = m_Struct.first;
		m_Struct = l_NewStruct;
	}
	RemoveSpaces();
	UpdateRowsAndColumns();
}
Exemple #9
0
void Cmd_AutoRecord_f(edict_t * ent)
{
    char rec_date[20], recstr[MAX_QPATH];
    time_t clock;

    time( &clock );
    strftime( rec_date, sizeof(rec_date)-1, "%Y_%b_%d_%H%M", localtime(&clock));

    if (matchmode->value)
    {
        if(use_3teams->value)
            Com_sprintf(recstr, sizeof(recstr), "%s-%s_vs_%s_vs_%s-%s", rec_date, teams[TEAM1].name, teams[TEAM2].name, teams[TEAM3].name, level.mapname);
        else
            Com_sprintf(recstr, sizeof(recstr), "%s-%s_vs_%s-%s", rec_date, teams[TEAM1].name, teams[TEAM2].name, level.mapname);

        RemoveSpaces(recstr); //Remove spaces -M
    } else {
        Com_sprintf(recstr, sizeof(recstr), "%s-%s", rec_date, level.mapname);
    }

    stuffcmd(ent, va("record \"%s\"\n", recstr));
}
Exemple #10
0
void Table::SetStructure(TableStruct p_Struct)
{
	if (p_Struct.first.size() == m_Columns)
	{
		if (m_Struct.first.size())
			m_Content.pop_front();

		m_Struct.first = p_Struct.first;
		m_Content.push_front(m_Struct.first);
	}
	if (m_Struct.first.size() ? p_Struct.second.size() + 1 == m_Content.size() : p_Struct.second.size() == m_Content.size())
	{
		bool l_NeedRemove = false;
		if (m_Struct.second.size())
			l_NeedRemove = true;

		m_Struct.second = p_Struct.second;
		int l_Itr = 0;
		for (Row& l_row : m_Content)
		{
			if (l_NeedRemove)
				l_row.pop_front();
			if (!l_Itr)
				l_row.push_front("");
			else
				l_row.push_front(p_Struct.second[l_Itr - 1]);
			l_Itr++;
		}
	}
	if (GetStructure(true))
	{
		RemoveSpaces();
		AlignFields();
	}
	UpdateRowsAndColumns();
}
void Game::SavePlayer()
{
    ofstream File(World + "/Player.txt");
    File.clear();
    //Basic info
    File << Player.Map << " " << Player.GetX() << " " << Player.GetY() << " " << Player.GetWealth() << " " << RemoveSpaces(Player.GetName()) << " ";
    if(Player.GetClass() == CLASS_WARRIOR)
        File << "0 ";
    else
        File << "1 ";
    //Stats
    File << Player.GetLevel() << " " << Player.GetExp() << " " << Player.GetTalentPoints() << " " << Player.GetIntStr() << " " << Player.GetMaxHealth()
        << " " << Player.GetMaxPower() << " " << Player.GetAttack() << " " << Player.GetDefense() << " " << Player.GetItems().size();
    //Backpack
    for(unsigned i=0; i<Player.GetItems().size(); ++i)
    {
        File << " " << Player.GetItems()[i].ID;
    }
    //Equiped Items
    File << " " << Player.GetEquipedItems().size();
    for(unsigned i=0; i<Player.GetEquipedItems().size(); ++i)
    {
        File << " " << Player.GetEquipedItems()[i].ID;
    }
    //Spells
    File << " " << Player.GetSpells().size();
    for(unsigned i=0; i<Player.GetSpells().size(); ++i)
    {
        File << " " << Player.GetSpells()[i].ID;
    }
    //Quests
    File << " " << Player.GetQuests().size();
    for(unsigned i=0; i<Player.GetQuests().size(); ++i)
    {
        File << " " << Player.GetQuests()[i].ID;
        File << " " << Player.GetQuests()[i].Objective.CurrentProgress;
    }
    //Completed quests
    File << " " << Player.GetCompletedQuests().size();
    for(unsigned i=0; i<Player.GetCompletedQuests().size(); ++i)
    {
        File << " " << Player.GetCompletedQuests()[i];
    }
    File.close();
}
ObjectRenderer::pShapeStruct    ObjectRenderer::LoadShape(const pXmlTree tree){
    if(tree==NULL) return NULL;

    REALTYPE *array;

    pXmlTree tmpTree = tree;

    pShapeStruct shape  = NULL;

    if((tmpTree->GetName()=="Shape")){
        gLOG.Append("Setting up Shape : %s",tmpTree->GetData().c_str());
        gLOG.SetDeltaIndent(2);

        int size;
        Matrix3 scale;
        scale.Identity();
        if(tmpTree->Find("Scale")){
            size=tmpTree->GetArray("Scale",&array);
            if(size==3){
                                scale.Diag(Vector3(array));
                                scale.RefNoCheck(0,0) = array[0];
                                scale.RefNoCheck(1,1) = array[1];
                                scale.RefNoCheck(2,2) = array[2];
            }else{
                                gLOG.Append("Error: Bad <Scale> array size (should be 3)");
            }
        }


        string params = tmpTree->Get("Params",string(""));
        vector<string> ptokens = Tokenize(RemoveSpaces(params));

        shape               = new ShapeStruct;
        shape->shape        = new GL3DObject();
        shape->strShapeName = tmpTree->GetData();
        shape->scale[0] = scale.At(0,0);
        shape->scale[1] = scale.At(1,1);
        shape->scale[2] = scale.At(2,2);

              if(tmpTree->GetData().length()==0){
                    gLOG.Append("Error: No shape specified");
        }else if(tmpTree->GetData() == "Cube"){
                shape->shape->GenerateCube();
        }else if(tmpTree->GetData() == "Cylinder"){
                if(ptokens.size()>=1){
                    shape->shape->GenerateCylinder(atoi(ptokens[0].c_str()));
                }else{
                    shape->shape->GenerateCylinder(16);
                }
        }else if(tmpTree->GetData() == "Sphere"){
                if(ptokens.size()>=2){
                    shape->shape->GenerateSphere(atoi(ptokens[0].c_str()),atoi(ptokens[1].c_str()));
                }else{
                    shape->shape->GenerateSphere(16,12);
                }
        }else if(tmpTree->GetData() == "Capsule"){
                if(ptokens.size()==1){
                    shape->shape->GenerateCapsule(atof(ptokens[0].c_str()),16,6);
                }else if(ptokens.size()>=3){
                    shape->shape->GenerateCapsule(atof(ptokens[0].c_str()),atoi(ptokens[1].c_str()),atoi(ptokens[2].c_str()));
                }else{
                    shape->shape->GenerateCapsule(0.5*(scale.RefNoCheck(0,0)+scale.RefNoCheck(1,1)),16,6);
                }
        }else if(tmpTree->GetData() == "HeightField"){
                if(tmpTree->Find("DataFile")){
                    string filename = tmpTree->GetBasePath()+string("/")+tmpTree->Find("DataFile")->GetData();
                    Matrix hf;
                    if(hf.Load(filename.c_str())){
                        shape->shape->GenerateHeightField(hf,1,1,1);
                    }else{
                        delete shape->shape; shape->shape=NULL;
                        gLOG.Append("Error: Height field file %s failed to open",filename.c_str());
                    }
                }else{
                    delete shape->shape; shape->shape=NULL;
                    gLOG.Append("Error: Height field: No <DataFile> specified...");
                }



                /*if(ptokens.size()==1){
                    shape->shape->GenerateCapsule(atof(ptokens[0].c_str()),16,6);
                }else if(ptokens.size()>=3){
                    shape->shape->GenerateCapsule(atof(ptokens[0].c_str()),atoi(ptokens[1].c_str()),atoi(ptokens[2].c_str()));
                }else{
                    shape->shape->GenerateCapsule(0.5*(scale.RefNoCheck(0,0)+scale.RefNoCheck(1,1)),16,6);
                }*/
        }else{
            bool bShapeFound = false;
            string shapeFile;
            if(!bShapeFound){
                shapeFile = tmpTree->GetData();
                bShapeFound = FileFinder::Find(shapeFile);
                if(bShapeFound) shapeFile = FileFinder::GetString();
            }
            if(!bShapeFound){
                shapeFile = mBasePath+"/"+tmpTree->GetData();
                bShapeFound = FileFinder::Find(shapeFile);
                if(bShapeFound) shapeFile = FileFinder::GetString();
            }
            if(!bShapeFound){
                shapeFile = tmpTree->GetBasePath()+"/"+tmpTree->GetData();
                bShapeFound = FileFinder::Find(shapeFile);
                if(bShapeFound) shapeFile = FileFinder::GetString();
            }
            if(bShapeFound){
                if(!shape->shape->LoadFromObjFile(shapeFile.c_str())){
                    delete shape->shape; shape->shape=NULL;
                    gLOG.Append("Error: Unable to load shape file: %s",shapeFile.c_str());
                }
            }else{
                gLOG.Append("Error: Unable to find shape file: %s",shapeFile.c_str());
            }
        }

        if(tmpTree->Find("Origin")){
            size=tmpTree->GetArray("Origin",&array);
            if(size==3){            shape->refShape.SetOrigin().Set(array);
            }else{                  shape->refShape.SetOrigin().Zero();
                                    gLOG.Append("Error: Bad <Origin> array size (should be 3)");
            }
        }else{
                                    shape->refShape.SetOrigin().Zero();
                                    gLOG.Append("Warning: No <Origin> defined");
        }

        if(tmpTree->Find("Orient")){
            size=tmpTree->GetArray("Orient",&array);
            if(size==9){            shape->refShape.SetOrient().Set(array);
                                    shape->refShape.SetOrient().Normalize();
            }else if(size==3){      shape->refShape.SetOrient().SRotationV(Vector3(array));
            }else{                  shape->refShape.SetOrient().Identity();
                                    gLOG.Append("Error: Bad <Orient> array size (should be 3(axis*angle) or 9(full rotation matrix))");
            }
        }else{
                                    shape->refShape.SetOrient().Identity();
                                    gLOG.Append("Warning: No <Orient> defined");
        }
        shape->refShape.Update();

        if(tmpTree->Find("Color")){
            size=tmpTree->GetArray("Color",&array);
            if(size==3){            memcpy(shape->color,array,3*sizeof(REALTYPE));
                                    shape->color[3] = 1.0;
            }else if(size==4){      memcpy(shape->color,array,4*sizeof(REALTYPE));
            }else{                  shape->color[0] = 1.0;
                                    shape->color[1] = 1.0;
                                    shape->color[2] = 1.0;
                                    shape->color[3] = 1.0;
                                    gLOG.Append("Error: Bad <Color> array size (should be 3 or 4)");
            }
        }else{
                                    shape->color[0] = 1.0;
                                    shape->color[1] = 1.0;
                                    shape->color[2] = 1.0;
                                    shape->color[3] = 1.0;
                                    gLOG.Append("Warning: No <Color> defined");
        }
        if(tmpTree->Find("DoubleFace")){
        	shape->culling = tmpTree->Get("DoubleFace",false);
        }
        else
        {
        	shape->culling = false;
        }

        if(shape->shape!=NULL){
            shape->shape->Transform(scale);
            shape->shape->Transform(shape->refShape.GetHMatrix());

            /*
            pXmlTree tmpShadowTree;
            if((tmpShadowTree=tmpTree->Find("Shadow"))!=NULL){
                string params = tmpShadowTree->Get("Params",string(""));
                vector<string> ptokens = Tokenize(RemoveSpaces(params));

                GL3DObject *shadow = new GL3DObject();
                      if(tmpShadowTree->GetData() == "Cube"){
                        shadow->GenerateCube();
                }else if(tmpShadowTree->GetData() == "Cylinder"){
                        if(ptokens.size()>=1){
                            shadow->GenerateCylinder(atoi(ptokens[0].c_str()));
                        }else{
                            shadow->GenerateCylinder(8);
                        }
                }else if(tmpShadowTree->GetData() == "Sphere"){
                        if(ptokens.size()>=2){
                            shadow->GenerateSphere(atoi(ptokens[0].c_str()),atoi(ptokens[1].c_str()));
                        }else{
                            shadow->GenerateSphere(4,4);
                        }
                }else if(tmpShadowTree->GetData() == "Clone"){
                        delete shadow;
                        shadow=shape->shape->Clone();
                }else{
                    if(!shadow->LoadFromObjFile(tmpShadowTree->GetData().c_str(),true)){
                        delete shadow; shadow=NULL;
                    }
                }
                if(shadow!=NULL){
                    shadow->Transform(shape->refShape.GetHMatrix());

                    if(tmpShadowTree->Find("Origin")){
                        Vector3 origin;
                        origin.Set(Vector(array,tmpShadowTree->GetArray("Origin",&array)));
                        shadow->AddOffset(origin);
                    }
                    if(tmpShadowTree->Find("Orient")){
                        Matrix3 orient;
                        orient.Set(Matrix(array,tmpShadowTree->GetArray("Orient",&array)/3,3));
                        shadow->Transform(orient);
                    }
                    shape->shape->SetShadow(shadow);
                }
            }
            */
        }
        gLOG.SetDeltaIndent(-2);

    }


    return shape;
}
void escanearFormatearParticion(char *ingreso){

    /*Remuevo los espacios en blanco de la sentencia*/
    RemoveSpaces(ingreso);

    int x = strlen(ingreso);
    int i;
    int estado = 0;
    char c;

    char id[10];
    char type[5];
    limpiar(id, 10);
    limpiar(type, 5);


    char auxlex[200];
    limpiar(auxlex, 200);

    for(i = 0; i < x; i++)
    {
        c = ingreso[i];

        switch(estado){

            case 0:

                if(isalpha(c)){
                    estado = 1;
                    auxlex[jnx] = c;
                    jnx++;
                    break;
                }else{
                    if(c == '#'){
                        printf("Analisis realizado satisfactoriamente!\n");

                        printf("********************************************************************\n");
                        printf("Informacion recopilada:\n");
                        printf("%s %s %s", "Id: ", id, "\n");
                        printf("%s %s %s", "Type: ", type, "\n");
                        printf("********************************************************************\n");

                        jnx = 0;

                        /*Si no existe algun error*/
                        if(_banderaError == 0){
                            /*Si el type viene vacio significa que será tomado como full*/
                            if(type[0] == '\0'){
                                strcpy(type, "full");

                                /*Verifico si la particion se encuentra montada*/
                                xnode **z = NULL;

                                /*Busco en la lista si ya existe alguna particion montada con ese nombre*/
                                z = xx_list_search(&m, id);

                                if(z == NULL){
                                    /*Significa que la particion no existe*/
                                    printf("No se puede formatear la particion. Esta no se encuentra montada!\n");
                                    printf("***********************************************************************\n");
                                }else{
                                    formatearParticion(id, type);
                                }

                            }else{
                                /*Verifico si la particion se encuentra montada*/
                                xnode **z = NULL;

                                /*Busco en la lista si ya existe alguna particion montada con ese nombre*/
                                z = xx_list_search(&m, id);

                                if(z == NULL){
                                    /*Significa que la particion no existe*/
                                    printf("No se puede formatear la particion. Esta no se encuentra montada!\n");
                                    printf("***********************************************************************\n");
                                }else{
                                    formatearParticion(id, type);
                                }
                            }
                        }else{
                            printf("Existen errores en la sentencia, no se ejecuto codigo.\n");
                            printf("********************************************************************\n");
                        }


                        limpiar(id, 10);
                        limpiar(type, 5);

                        break;
                    }
                }

            case 1:

                if(isalpha(c)){

                    estado = 1;
                    auxlex[jnx] = c;
                    jnx++;
                    break;

                }else if(c == '-'){

                    if(strcmp(auxlex, "mkfs") == 0){
                        /*Esto signfica que lo recien leido es valido, por lo que procedemos con el analisis*/
                        estado = 0;
                        vaciarArreglo(auxlex);
						jnx = 0;
                        printf("encontro el mkfs\n");
                        break;
                    }else{
                        printf("Error sintactico con: %s\n", auxlex);
                        _banderaError = 1;
                    }

                }else if(c == ':'){

                    if(strcmp(auxlex, "id") == 0){
                        /*Esto signfica que lo recien leido es valido, por lo que procedemos con el analisis*/
                        estado = 2;
                        vaciarArreglo(auxlex);
                        jnx = 0;
                        printf("encontro el id\n");
                        break;
                    }else if(strcmp(auxlex, "type") == 0){
                        /*Esto signfica que lo recien leido es valido, por lo que procedemos con el analisis*/
                        estado = 3;
                        vaciarArreglo(auxlex);
						jnx = 0;
                        printf("encontro el type\n");
                        break;
                    }else{
                        printf("Error sintactico con: %s\n", auxlex);
                        _banderaError = 1;
                    }

                }else{
                    printf("Error lexico con: %c\n", c);
                    _banderaError = 1;
                }


             case 2:

                if(isalpha(c)){
                    estado = 2;
                    auxlex[jnx] = c;
                    jnx++;
                    break;
                }else if(isdigit(c)){
                    estado = 2;
                    auxlex[jnx] = c;
                    jnx++;
                    break;
                }else if(c == '-'){
                    strcpy(id, auxlex);
                    vaciarArreglo(auxlex);
					jnx = 0;
                    estado = 0;
                    break;
                }else if(c == '#'){
                    limpiar(id, 10);
                    strcpy(id, auxlex);
                    vaciarArreglo(auxlex);
					jnx = 0;
                    estado = 0;
                    i--;
                    break;
                }else{
                    printf("Error lexico con: %c\n", c);
                    _banderaError = 1;
                }


            case 3:

                if(isalpha(c)){
                    estado = 3;
                    auxlex[jnx] = c;
                    jnx++;
                }else if(c == '#'){
                    strcpy(type, auxlex);
                    vaciarArreglo(auxlex);
					jnx = 0;
                    estado = 0;
                    i--;
                    break;
                }else{
                    printf("Error lexico con: %c\n", c);
                    _banderaError = 1;
                }

        }

    }

}
Exemple #14
0
void CTabMap::OnBnClickedOk()
{
COziGenDlg	* pParent;
pParent = (COziGenDlg *)(this->GetParent()->GetParent());

	CString strWestNorth;
	CString strEastSouth;
	CString strMap;

	if (m_nMapType == 0) {
		GetExplorerExtents (m_nExplorerMap, strWestNorth, strEastSouth, strMap);
	} else if (m_nMapType == 1) {
		GetLandrangerExtents (m_nExplorerMap, strWestNorth, strEastSouth, strMap);
	} else if (m_nMapType == 2) {
		GetNationalParkExtents (m_nExplorerMap, strWestNorth, strEastSouth, strMap);
	} else if (m_nMapType == 3) {
		GetRegionalAreaExtents (m_nExplorerMap, strWestNorth, strEastSouth, strMap);
	} else if (m_nMapType == 4) {
		GetLargeRegionalAreaExtents (m_nExplorerMap, strWestNorth, strEastSouth, strMap);
	}

	UpdateData(true);

	CRect MyRect;

	if (OSref_to_easting_northing(strWestNorth, &MyRect.left, &MyRect.top) == 0) {

		pParent->AddToResultsWindow("Error: Invalid Westing\\Northing %s",strWestNorth);
		return;
	}

	if (OSref_to_easting_northing(strEastSouth, &MyRect.right, &MyRect.bottom) == 0) {

		pParent->AddToResultsWindow("Error: Invalid Easting\\Southing %s",strEastSouth);
		return;
	}

	// Ensure that Rectangle is West/North and East/South!
	if (MyRect.right < MyRect.left) {
		long tmp;
		tmp = MyRect.left;
		MyRect.left = MyRect.right;
		MyRect.right = tmp;
	}
	if (MyRect.bottom > MyRect.top) {
		long tmp;
		tmp = MyRect.bottom;
		MyRect.bottom = MyRect.top;
		MyRect.top = tmp;
	}

	pParent->m_mapBoundaries = MyRect;

	CString strMapName;
	
	if (m_bMapPrefix) {
		strMapName = strMap;
		if (m_bMapName) strMapName = strMapName + "_" + RemoveSpaces(m_strMapName);
	} else {
		if (m_bMapName) {
			strMapName.Format("%03d_%s", m_nExplorerMap, RemoveSpaces(m_strMapName));
		}  else {
			strMapName = strMap;
		}
	}

	pParent->m_strMapName = strMapName;

	pParent->m_nRadioCountry = COUNTRY_UK;
	pParent->m_nComboBoxCountry = COUNTRY_UK;
MyMap.UpdateCountry(COUNTRY_UK);


	pParent->UpdateData(false);

	pParent->UpdateDatum();
	pParent->UpdateData(false);

	pParent->DisplayMapData();

CRoute MyRoute;

MyRoute.Bound(strMap, MyRect.left, MyRect.top, MyRect.right, MyRect.bottom);

CString strFile;
strFile = strMap+".rxf";

WriteMaptechRoute(strFile, MyRoute);

	pParent->AddToResultsWindow("Determined Map Extents for %s",pParent->m_strMapName);
}
bool CConfigData::LoadConfigFile(std::string configFilename){
  CLog *pLog = CLog::Instance();

  //function variables
  std::string line;
  int equalCount = 0;
  std::ifstream file(configFilename.c_str());
  
  //open file for reading
  if(file.is_open()){

    //read one line at a time
    pLog->Log("Reading config file");
    while(!file.eof()){
      getline (file, line);
      line = RemoveSpaces(line);
      line = RemoveComments(line);
      equalCount = CountEqualSigns(line);
      if(line.size() != 0 && equalCount == 1){
        m_lines.push_back(line);
        equalCount = 0;
        pLog->Log("Config line", line);
      }
    }

    file.close();
  }

  //file doesn't exist
  else
    return false;

  //break string into key and value
  std::string key;
  std::string value;
  size_t equalPos = 0;
  bool bFound;
  
  pLog->Log("***************************************");
  pLog->Log("Configuration File Data (key = value)");
  pLog->Log("***************************************");

  for(size_t i = 0; i < m_lines.size(); ++i){
    
    equalPos = m_lines[i].find("=");
    if(equalPos > 0){
      key = m_lines[i].substr(0, equalPos);
      value = m_lines[i].substr(equalPos + 1);
      
      //load all config variables with values
      bFound = false;

      if(key == "ScreenLeft"){
        ScreenLeft = atoi(value.c_str());
        bFound = true;
      }
      else if(key == "ScreenTop"){
        ScreenTop = atoi(value.c_str());
        bFound = true;
      }
      else if(key == "ScreenWidth"){
        ScreenWidth = atoi(value.c_str());
        bFound = true;
      }
      else if(key == "ScreenHeight"){
        ScreenHeight = atoi(value.c_str());
        bFound = true;
      }
      else if(key == "FullScreen"){
        if(atoi(value.c_str()) == 1)
          FullScreen = true;
        else
          FullScreen = false;
        bFound = true;
      }
      else if(key == "DisplayDebugInfo"){
        if(atoi(value.c_str()) == 0)
          DisplayDebugInfo = false;
        else if(atoi(value.c_str()) == 1)
          DisplayDebugInfo = true;
        bFound = true;
      }
      else if(key == "LogDebugInfo"){
        if(atoi(value.c_str()) == 0)
          LogDebugInfo = false;
        else if(atoi(value.c_str()) == 1)
          LogDebugInfo = true;
        bFound = true;
      }
      else if(key == "PlaySounds"){
        if(atoi(value.c_str()) == 0)
          PlaySounds = false;
        else if(atoi(value.c_str()) == 1)
          PlaySounds = true;
        bFound = true;
      }
      else if(key == "PlayMusic"){
        if(atoi(value.c_str()) == 0)
          PlayMusic = false;
        else if(atoi(value.c_str()) == 1)
          PlayMusic = true;
        bFound = true;
      }
      else if(key == "FrameworkAssetFile"){
        FrameworkAssetFile = value;
        bFound = true;
      }
      else if(key == "GamePlayAssetFile"){
        GamePlayAssetFile = value;
        bFound = true;
      }
      else if(key == "SoundAssetFile"){
        SoundAssetFile = value;
        bFound = true;
      }

      else if(key == "ObjectsFile"){
        ObjectsFile = value;
        bFound = true;
      }
      else if(key == "EffectsFile"){
        EffectsFile = value;
        bFound = true;
      }
      else if(key == "EffectsFileI"){
        EffectsFileI = value;
        bFound = true;
      }
      else if(key == "CreditsFile"){
        CreditsFile = value;
        bFound = true;
      }
      else if(key == "TilesFile"){
        TilesFile = value;
        bFound = true;
      }
      else if(key == "ProgramName"){
        ProgramName = value;
        bFound = true;
      }
      else if(key == "ProgramVersion"){
        ProgramVersion = value;
        bFound = true;
      }     
      else if(key == "RootPath"){
        RootPath = value;
        bFound = true;
      }     

      /*
      else if(key == "Level1"){
        Level1 = value;
        bFound = true;
      }
      else if(key == "Level2"){
        Level2 = value;
        bFound = true;
      }
      else if(key == "Level3"){
        Level3 = value;
        bFound = true;
      }
      else if(key == "Level4"){
        Level4 = value;
        bFound = true;
      }
      else if(key == "Level5"){
        Level5 = value;
        bFound = true;
      }
      else if(key == "Level6"){
        Level6 = value;
        bFound = true;
      }
      else if(key == "Level7"){
        Level7 = value;
        bFound = true;
      }
      else if(key == "Level8"){
        Level8 = value;
        bFound = true;
      }
      else if(key == "Level9"){
        Level9 = value;
        bFound = true;
      }
      else if(key == "Level10"){
        Level10 = value;
        bFound = true;
      }
      */
      if(bFound == false)
        pLog->Log("No match for config file key", key);
    }
  }
}
Exemple #16
0
void vMeldTask( void *pvParameters ) {
  halt(1);
  //-------CREATE DATABASE-----------------------------
	struct database *databaseHead = NULL;
		

    //-------READ A LINE OF CODE-----------------------
		char line_of_code[100]="position(1,14.5,15.1)";
	 
	 	//-------REMOVE SPACES-------------------------------
	 	RemoveSpaces(line_of_code);

	 	//-------ADD TO DATABASE IF IT IS A RULE-------------
	 	if(type(line_of_code)==FACT){
	 		struct fact Fact;
	 		Fact = getFact(line_of_code);
	 		//printf("It's a FACT\n");
	 		add_to_database(&databaseHead,Fact);
	 		// print_database(databaseHead);
	 	}

	 	//------GET HEAD AND BODY IF IT IS A RULE------------
	 	if(type(line_of_code)==RULE){
	 	
	 		int i,state=0,headsize=0,bodysize=0;
	 		char head[50]={'\0'},body[50]={'\0'};

		 	for(i=0;line_of_code[i]!='\0';i++){
		 		
		 		if((line_of_code[i]=='-')&&(line_of_code[i+1]=='o')){
		 			state=1;
		 		}
		 		if(state==0){
		 			body[i]=line_of_code[i];
		 			bodysize++;
		 		}
		 		else{
		 			if(((line_of_code[i]=='-')&&(line_of_code[i+1]=='o')) || ((line_of_code[i-1]=='-')&&(line_of_code[i]=='o'))){
		 				continue;
		 			}
		 			head[i-bodysize-2]=line_of_code[i];
		 			headsize++;
		 		}
		 	}

		 	//printf("It's a RULE\nHead: %s\nBody: %s\n", head,body);
		 	struct fact Fact;
	 		Fact = getFact(body);
	 		// print_database(databaseHead);
	 		if(search_in_database(databaseHead, Fact)){
	 			Fact=getFact(head);
	 			add_to_database(&databaseHead,Fact);
	 			// print_database(databaseHead);
	 		}
		}


		strcpy(line_of_code,"position(1,14,15) -o move(1,100,150)");
	 
	 	//-------REMOVE SPACES-------------------------------
	 	RemoveSpaces(line_of_code);

	 	//-------ADD TO DATABASE IF IT IS A RULE-------------
	 	if(type(line_of_code)==FACT){
	 		struct fact Fact;
	 		Fact = getFact(line_of_code);
	 		//printf("It's a FACT\n");
	 		add_to_database(&databaseHead,Fact);
	 		// print_database(databaseHead);
	 	}

	 	//------GET HEAD AND BODY IF IT IS A RULE------------
	 	if(type(line_of_code)==RULE){
	 	
	 		int i,state=0,headsize=0,bodysize=0;
	 		char head[50]={'\0'},body[50]={'\0'};

		 	for(i=0;line_of_code[i]!='\0';i++){
		 		
		 		if((line_of_code[i]=='-')&&(line_of_code[i+1]=='o')){
		 			state=1;
		 		}
		 		if(state==0){
		 			body[i]=line_of_code[i];
		 			bodysize++;
		 		}
		 		else{
		 			if(((line_of_code[i]=='-')&&(line_of_code[i+1]=='o')) || ((line_of_code[i-1]=='-')&&(line_of_code[i]=='o'))){
		 				continue;
		 			}
		 			head[i-bodysize-2]=line_of_code[i];
		 			headsize++;
		 		}
		 	}

		 	//printf("It's a RULE\nHead: %s\nBody: %s\n", head,body);
		 	struct fact Fact;
	 		Fact = getFact(body);
	 		// print_database(databaseHead);
	 		if(search_in_database(databaseHead, Fact)){
	 			Fact=getFact(head);
	 			add_to_database(&databaseHead,Fact);
	 			// print_database(databaseHead);
	 		}
		}
	
}
Exemple #17
0
/*
 *	NAME
 *		ReadColornameDB - Read the Color Name Database
 *
 *	SYNOPSIS
 */
static Status
ReadColornameDB(
    FILE *stream,
    XcmsPair *pRec,
    char *pString)
/*
 *	DESCRIPTION
 *		Loads the Color Name Database from a text file.
 *
 *	RETURNS
 *		XcmsSuccess if succeeded, otherwise XcmsFailure.
 *
 */
{
    char buf[XCMSDB_MAXLINELEN];
    char token[XCMSDB_MAXLINELEN];
    char token2[XCMSDB_MAXLINELEN];
    char *f1;
    char *f2;
    char *pBuf;

    /*
     * Advance to START_TOKEN
     *	 Anything before is just considered as comments.
     */

    while((pBuf = fgets(buf, XCMSDB_MAXLINELEN, stream)) != NULL) {
	if ((sscanf(buf, "%s %s", token, token2))
		&& (strcmp(token, START_TOKEN) == 0)) {
	    if (strcmp(token2, FORMAT_VERSION) != 0) {
		/* text file not in the right format */
		return(XcmsFailure);
	    }
	    break;
	} /* else it was just a blank line or comment */
    }

    if (pBuf == NULL) {
	return(XcmsFailure);
    }

    /*
     * Process lines between START_TOKEN to END_TOKEN
     */

    while ((fgets(buf, XCMSDB_MAXLINELEN, stream)) != NULL) {
	if ((sscanf(buf, "%s", token)) && (strcmp(token, END_TOKEN) == 0)) {
	    /*
	     * Found END_TOKEN so break out of for loop
	     */
	    break;
	}

	/*
	 * Get pairs
	 */
	if (field2(buf, DELIM_CHAR, &f1, &f2) != XcmsSuccess) {
	    /* Invalid line */
	    continue;
	}

	/*
	 * Add strings
	 */

	/* Left String */
	pRec->first = pString;
	_XcmsCopyISOLatin1Lowered(pString, f1);
	pString += (1 + RemoveSpaces(pString));
	pRec->second = pString;
	/* Right String */
	_XcmsCopyISOLatin1Lowered(pString, f2);
	pString += RemoveSpaces(pString) + 1;
	pRec++;

    }

    return(XcmsSuccess);
}
Exemple #18
0
void DOS_Drive_Cache::CreateShortName(CFileInfo* curDir, CFileInfo* info) {
	Bits	len			= 0;
	bool	createShort = false;

	char tmpNameBuffer[CROSS_LEN];

	char* tmpName = tmpNameBuffer;

	// Remove Spaces
	strcpy(tmpName,info->orgname);
	upcase(tmpName);
	createShort = RemoveSpaces(tmpName);

	// Get Length of filename
	char* pos = strchr(tmpName,'.');
	if (pos) {
		// ignore preceding '.' if extension is longer than "3"
		if (strlen(pos)>4) {
			while (*tmpName=='.') tmpName++;
			createShort = true;
		}
		pos = strchr(tmpName,'.');
		if (pos)	len = (Bits)(pos - tmpName);
		else		len = (Bits)strlen(tmpName);
	} else {
		len = (Bits)strlen(tmpName);
	}

	// Should shortname version be created ?
	createShort = createShort || (len>8);
	if (!createShort) {
		char buffer[CROSS_LEN];
		strcpy(buffer,tmpName);
		createShort = (GetLongName(curDir,buffer)>=0);
	}

	if (createShort) {
		// Create number
		char buffer[8];
		info->shortNr = CreateShortNameID(curDir,tmpName);
		sprintf(buffer,"%d",info->shortNr);
		// Copy first letters
		Bits tocopy = 0;
		size_t buflen = strlen(buffer);
		if (len+buflen+1>8)	tocopy = (Bits)(8 - buflen - 1);
		else				tocopy = len;
		safe_strncpy(info->shortname,tmpName,tocopy+1);
		// Copy number
		strcat(info->shortname,"~");
		strcat(info->shortname,buffer);
		// Add (and cut) Extension, if available
		if (pos) {
			// Step to last extension...
			pos = strrchr(tmpName, '.');
			// add extension
			strncat(info->shortname,pos,4);
			info->shortname[DOS_NAMELENGTH] = 0;
		}

		// keep list sorted for CreateShortNameID to work correctly
		if (curDir->longNameList.size()>0) {
			if (!(strcmp(info->shortname,curDir->longNameList.back()->shortname)<0)) {
				// append at end of list
				curDir->longNameList.push_back(info);
			} else {
				// look for position where to insert this element
				bool found=false;
				std::vector<CFileInfo*>::iterator it;
				for (it=curDir->longNameList.begin(); it!=curDir->longNameList.end(); ++it) {
					if (strcmp(info->shortname,(*it)->shortname)<0) {
						found = true;
						break;
					}
				}
				// Put it in longname list...
				if (found) curDir->longNameList.insert(it,info);
				else curDir->longNameList.push_back(info);
			}
		} else {
			// empty file list, append
			curDir->longNameList.push_back(info);
		}
	} else {
		strcpy(info->shortname,tmpName);
	}
	RemoveTrailingDot(info->shortname);
}