Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //============================================================================
- // Name : CheckSmth.cpp
- // Author :
- // Version :
- // Copyright : Your copyright notice
- // Description : Hello World in C++, Ansi-style
- //============================================================================
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <stdio.h>
- #include <ctype.h>
- #include <cctype>
- struct inst
- {
- std::string layer;
- std::string component;
- std::string instructions[10];
- static int counter;
- int cyclicTime;
- };
- class Parser
- {
- public:
- int checkNesting(std::string tab[], std::string nest)
- {
- int nestingLevel = 0;
- for(int iIndex = 0; iIndex < 20; iIndex++)
- {
- if(tab[iIndex][0] == '<' && tab[iIndex][1] == '/')
- {
- nestingLevel--;
- }
- else if(tab[iIndex][0] == '<')
- {
- nestingLevel++;
- }
- if(tab[iIndex] == nest)
- {
- break;
- }
- }
- return nestingLevel;
- }
- int valid(const char * path)
- {
- std::string buffer[10];
- std::fstream fileLoaded;
- fileLoaded.open("pare.txt", std::ios::in);
- if(fileLoaded.is_open() == true)
- {
- std::cout << "File have been opened successfully" << std::endl;
- for(int i = 0 ; i < 10; i ++)
- {
- fileLoaded >> buffer[i];
- std::cout << buffer[i] << std::endl;
- }
- for(int i = 0 ; i < 10; i ++)
- {
- int buffLength = buffer[i].length();
- //=======================================================================
- // Start reading a config
- //=======================================================================
- if(buffer[i] == "!start")
- {
- std::cout << "Beginning of the config" << std::endl;
- }
- //=======================================================================
- else if(buffer[i][0] == '/' && buffer[i][1] == '/')
- {
- continue;
- }
- else if(buffer[i][0] == '<')
- {
- if(buffer[i][buffLength-1] != '>')
- {
- std::cout << "Bad build of config, you forgot '>' in your " << i+1 << " line" << std::endl;
- }
- else
- {
- std::cout << "GOOD" << std::endl;
- }
- }
- else if(buffer[i][0] == '#')
- {
- int lineLenth = buffer[i].length();
- if(buffer[i][lineLenth-1] != ';')
- {
- std::cout << "Bad build of config, you forgot ';' in your " << i+1 << " line" << std::endl;
- }
- else if(buffer[i][lineLenth-1] == ';')
- {
- std::cout << "Good try to read commands" << std::endl;
- }
- }
- else if(buffer[i] == "!end")
- {
- std::cout << "End of the config" << std::endl;
- break;
- }
- else
- {
- std::cout << "Bad build of config, your line must start with '<>' or '#'" << std::endl;
- }
- }
- }
- else
- {
- std::cout << "File have not been opened successfully" << std::endl;
- }
- fileLoaded.close();
- }
- int parse(const char * path)
- {
- std::string buff[20];
- inst components[20];
- std::string layer = "";
- std::string compon = "";
- std::string instruction = "";
- std::fstream fileLoaded;
- fileLoaded.open("pare.txt", std::ios::in);
- for(int i = 0; i < 20; i++)
- {
- fileLoaded >> buff[i];
- if(buff[i][0] == '<' && buff[i][1] == '/')
- {
- }
- else if(buff[i][0] == '<')
- {
- if(this->checkNesting(buff, buff[i]) == 1)
- {
- buff[i] = buff[i] + '1';
- }
- if(this->checkNesting(buff, buff[i]) == 2)
- {
- buff[i] = buff[i] + '2';
- }
- }
- }
- for(int i = 0; i < 20; i++)
- {
- int buffLenght = buff[i].length();
- if(buff[i][buffLenght-1] == '1')
- {
- layer = buff[i];
- }
- else if(buff[i][buffLenght-1] == '2')
- {
- compon = buff[i];
- //components[i].layer = layer;
- //components[i].component = compon;
- }
- else if(buff[i][0] == '#')
- {
- instruction = buff[i];
- components[i].layer = layer;
- components[i].component = compon;
- components[i].instructions[inst::counter] = instruction;
- inst::counter++;
- }
- }
- for(int i = 0; i < 20; i++)
- {
- for(int j = 0; j < 10; j++)
- {
- if(components[i].instructions[j] != "")
- {
- std::cout << components[i].layer << components[i].component << components[i].instructions[j] << std::endl;
- }
- }
- }
- this->prepare(components);
- }
- int prepare(const inst tab[20])
- {
- for(int i = 0; i < 20; i++)
- {
- if(tab[i].layer == "<drivers>1")
- {
- this->driversLayer(tab[i]);
- }
- else if(tab[i].layer == "<service>1")
- {
- this->serviceLayer(tab[i]);
- }
- else if(tab[i].layer == "<rte>1")
- {
- this->rteLayer(tab[i]);
- }
- else if(tab[i].layer == "<swc>1")
- {
- this->swcLayer(tab[i]);
- }
- else if(tab[i].layer == "<os>1")
- {
- this->osLayer(tab[i]);
- }
- else
- {
- std::cout << "Error in read config in line " << i+1 << "." << std::endl;
- }
- }
- }
- int driversLayer(inst object)
- {
- if(object.component == "<udpDriver>2")
- {
- for(int i = 0; i < 10; i++)
- {
- if(object.instructions[i][0] == '#')
- {
- //checkInstr(object.instructions[i]);
- }
- }
- }
- }
- int rteLayer(inst object)
- {
- }
- int serviceLayer(inst object)
- {
- }
- int swcLayer(inst object)
- {
- }
- int osLayer(inst object)
- {
- }
- };
- int inst::counter = 0;
- int main()
- {
- const char * path = "par.txt";
- Parser obj;
- obj.parse(path);
- char z = '<';
- std::cout << isalpha(z);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement