GLProgramming.com

home :: about :: development guides :: irc :: forums :: search :: paste :: links :: contribute :: code dump

-> Click here to learn how to get live help <-


New Paste :: Recent Pastes:: No Line Numbers


A Paste by baldurk
1
 
// I dare you to do this solely in std::string :P

        char init[256], test[256], incr[256];
        char lne[256];
        strcpy(lne, Line.c_str());
        
        char *c = strchr(lne, '(', ');
        if(!c)
        {
            if(error)
                Print("syntax error on line '%s'\n", Line.c_str());
            return byteLine;
        }
        c++;

        while(*c == ' ', ') c++;
        strcpy(init, c);
        char *d = strchr(init, ';', ');
        if(!d)
        {
            if(error)
                Print("syntax error on line '%s'\n", Line.c_str());
            return byteLine;
        }
        *d = 0;
        while(init[strlen(init)-1] == ' ', ') init[strlen(init)-1] = 0;

        c = strchr(lne, ';', ')+1;
        while(*c == ' ', ') c++;

        strcpy(test, c);
        strcpy(incr, strchr(c, ';', ')+1);
        while(incr[0] == ' ' || incr[0] == '\t', ')
        {
            for(int q=0; q < (signed)strlen(incr); q++)
                incr[q] = incr[q+1];
        }

        d = strchr(test, ';', ');
        if(!d)
        {
            if(error)
                Print("syntax error on line '%s'\n", Line.c_str());
            return byteLine;
        }
        *d = 0;
        d = strchr(incr, ', ')', ');
        if(!d)
        {
            if(error)
                Print("syntax error on line '%s'\n", Line.c_str());
            return byteLine;
        }
        *d = 0;
        while(incr[strlen(incr)-1] == ' ', ') incr[strlen(incr)-1] = 0;
        while(test[strlen(test)-1] == ' ', ') test[strlen(test)-1] = 0;

        byteLine.op = FOR;
        byteLine.par1 = init;
        byteLine.par2 = test;
        byteLine.par3 = incr;
        return byteLine;