当前位置: 首页>>代码示例>>C++>>正文


C++ tokenizer::begin方法代码示例

本文整理汇总了C++中tokenizer::begin方法的典型用法代码示例。如果您正苦于以下问题:C++ tokenizer::begin方法的具体用法?C++ tokenizer::begin怎么用?C++ tokenizer::begin使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tokenizer的用法示例。


在下文中一共展示了tokenizer::begin方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

//=========================MAIN FUNCTION=======================
int main(int argc,char **argv){
    string home = getenv("HOME");
    string dir;
    //char cwd[BUFSIZ];
    //Loginv
    char host[200];//allocate memeory for host
    char* user;
    int hStat = gethostname(host, 200);
    if(hStat !=0){
        perror("Cannot get Host Name");
    }
    if(getlogin() != NULL){
        user = getlogin();
    }else{
        perror("Cannot get User Name");
    }

    struct sigaction newAction, oldAction;
    newAction.sa_handler = sigHandler;
    sigemptyset(&newAction.sa_mask);
    newAction.sa_flags = 0;
    
    //For handeling ^C and such
    if(oldAction.sa_handler != SIG_IGN){
        if(sigaction(SIGINT, &newAction, &oldAction )< 0){
            perror("sigaction");
        }
    }
    
    //Declarations
    string input;
    vector<string> args;
    vector<string> tempArgs;
    bool comment = false;

    //While loop that repeats $ and cin command
    while(true){
        cout << user << "@" << host << "$ ";
        /*if(getcwd(cwd,BUFSIZ) == NULL){
            perror("getcwd");
        }
        dir = cwd;
        if(home == "\0"){
            perror("getenv");
        }
        if(dir.find(home,0) != string::npos){
            dir.replace(0,home.size(),"~");
        }
        cout << dir <<"$ ";*/
        
        cout.flush();//flush just to be safe
        cin.clear();
        comment = false;
        getline(cin,input);

//================Tokenize the input into multiple parts==============
        char_separator<char> delim(" ",";#>|&");
        tokenizer<char_separator<char> > mytok(input, delim);//seperat the input

        for(mytok::iterator it = mytok.begin(); it != mytok.end(); ++it){
            //cout << "token: " << *it  << endl; 
            if(*it == "exit"){
                exit(0);
            }else if(*it == "#"){
                comment = true;
            }else if(!comment){
                args.push_back(*it);
            }
        }
        concatArg(args);
        //==============RUN THE COMMANDS======================
        /*for(unsigned int j=0; j<args.size();++j){
            cout << args[j] << endl;
        }               DEBUG PURPOSES*/ 
        if(properInput(args)){
            for(unsigned int i=0 ; i<args.size();++i){
                if(args[i]==";"){
                    singleCommand(tempArgs);
                    tempArgs.clear();
                }else if(args[i]!="&&" && args[i]!="||"){
                    tempArgs.push_back(args[i]);
                }else if(args[i]=="||"){
                    if(!singleCommand(tempArgs)){
                        tempArgs.clear();
                        break; 
                    }
                    tempArgs.clear();
                }else if(args[i]=="&&"){ 
                    if(singleCommand(tempArgs)){
                        tempArgs.clear();
                        break;
                    }
                    tempArgs.clear();
                }
            }
            singleCommand(tempArgs);
            tempArgs.clear();
        }
        args.clear();
//.........这里部分代码省略.........
开发者ID:TheBoop,项目名称:rShell,代码行数:101,代码来源:rshell.cpp


注:本文中的tokenizer::begin方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。