WeltEnSTurm

Untitled

Feb 3rd, 2011
341
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.35 KB | None | 0 0
  1. //  ##### main.cpp
  2. //  ##### Used for IOTest
  3. //  ##### Created by WeltEnSTurm on Feb 2, 2011
  4.  
  5. #include <fstream>
  6. #include <string>
  7. #include <iostream>
  8. using namespace std;
  9.  
  10. typedef unsigned int uint;
  11.  
  12. bool processcmd(string cmd, string& data){
  13.     cout<<"CMD: "<<cmd<<endl;
  14.     if(cmd=="FMT"){
  15.         string tmp;
  16.         for(uint i=0; i<data.size(); i++){
  17.             char lc=data[i];
  18.             if(lc==' ' || lc=='/t' || lc=='/n' || lc=='{' || lc=='}' || lc==';')
  19.                 if(tmp.size()){
  20.                     cout<<tmp<<endl;
  21.                     data=data.substr(i,data.size()-i);
  22.                     return true;
  23.                 }
  24.             else
  25.                 tmp+=lc;
  26.         }
  27.     }if(cmd=="TRI"){
  28.         uint start=data.find_first_of('{');
  29.         uint end=data.find_first_of('}');
  30.         string tmp=data.substr(start, data.size()-end);
  31.         data=data.substr(end, data.size()-end);
  32.         cout<<tmp<<endl;
  33.         return true;
  34.     }
  35. }
  36.  
  37. int main(){
  38.     ifstream in;
  39.     cout<<"opening files/model.umf"<<endl;
  40.     in.open("files/model.umf");
  41.     string smdata;
  42.     char buf[1024];
  43.     while(in.good()){
  44.         in.getline(buf,1024);
  45.         smdata+=buf;
  46.     }
  47.     string tcmd;
  48.     for(uint i=0; i<smdata.size(); i++){
  49.         char lc=smdata[i];
  50.         if(lc==' ' || lc=='/t' || lc=='/n' || lc=='{' || lc=='}' || lc==';')
  51.             if(tcmd.size()){
  52.                 smdata=smdata.substr(i, smdata.size()-i);
  53.                 if(processcmd(tcmd, smdata)) i=0;
  54.             }
  55.         else{
  56.             tcmd+=lc;
  57.             cout<<lc<<endl;
  58.         }
  59.     }
  60.     in.close();
  61.     cout<<"done"<<endl;
  62.     return 0;
  63. }
Add Comment
Please, Sign In to add comment