Example #1
0
long numIter(int n){
	long count = 0;
	while (n != 1){
		n = nextNum(n);
		count++;
	}
	return count;
}
Example #2
0
static Nfa_t Re_thompsonDoit (Nfa_t nfa,Re_t e)
{
  assert (e);
  switch (e->kind){
  case RE_KIND_EPS:{
    int from = nextNum();
    int to = nextNum();
    Nfa_addEdge (nfa, from, to, EPS);
    nfa->start = from;
    nfa->accept = to;
    break;
  }
  case RE_KIND_CHAR:{
    Re_Char_t p = (Re_Char_t)e;
    int from = nextNum();
    int to = nextNum();
    Nfa_addEdge (nfa, from, to, p->c);
    nfa->start = from;
    nfa->accept = to;
    break;
  }
  case RE_KIND_ALT:{
    TODO();
    break;
  }
  case RE_KIND_CONCAT:{
    Re_Concat_t p = (Re_Concat_t)e;
    Re_thompsonDoit (nfa, p->left);
    int oldStart = nfa->start;
    int oldAccept = nfa->accept;
    Re_thompsonDoit (nfa, p->right);
    Nfa_addEdge(nfa, oldAccept, nfa->start,
                EPS);
    nfa->start = oldStart;
    break;
  }
  case RE_KIND_CLOSURE:{
    TODO();
    break;
  }
  default:
    break;
  }
  return;
}
Example #3
0
// fills a buffer with "random" (the same every time) data we can
// test for after some manipulation (e.g. BitBlt)
void MemDebug::randomFill(BYTE* const buf, const int pitch, const int row_size, const int height)
{  
  for(int x=0; x<height; ++x)
  {
    for(int y=0; y<row_size; ++y)
    {
      buf[x*pitch + y] = nextNum();
    }
  }
}
Example #4
0
// checks a buffer to see if "random" data is intact or copied correctly
// return value == offset of first discrepancy, or 0 if all's well
int MemDebug::randomCheck(BYTE* const buf, const int pitch, const int row_size, const int height)
{  
  for(int x=0; x<height; ++x)
  {
    for(int y=0; y<row_size; ++y)
    {
      int n = nextNum();
      if (buf[x*pitch + y] != n) return x*pitch + y;
    }
  }
  
  return 0;
}
Example #5
0
 void produce(int sleep){
     tlog("Started to produce");
     int prod = nextNum();
     while (active){
         if (mainQueue->timedPush(prod, 50000)){
             prod++;
             tlog("Produced: "<<prod);
         } else {
             tlog("Full. Can't produce!");
         }
         ThreadBase::sleep(sleep);
     }
 }
Example #6
0
/* 
 getresult(char *line);
 input: array of charecters line[], holds stdin from user or file
 output: returns interger evaluations of input expression or long min-long as error 
 overview: this function is basically a state machine with cases: no nums found, first num found, oporator found, seccond num found
 if cant find one then an error message with print and will wait for next input
 */
int getresult (char *line){
        numLen = 0, numLen2 = 0;i = 0; //reset globals for each itteration
        int firstN = 0, seccondN = 0;
        char oporator;
        short error = 0, neg = 1;
        short pass = 0;
        while(line[i] >= ' '  && error == 0){
                c = line[i];
                //if first interger has not been found either find valid integer or return error
                if(pass == 0){
                    if((c < '0' || c > '9') && c != ' ' && c != '-'|| (c == '-' && neg == -1)){
                        error = 1;
                        printf("calc Usage Error input %d: calc arguments are integer, operator(+-*/), integer\n",(pass+1));
                    }
		    else if(c == '-'){
			neg = -1;
			i++;
	            }
                    else if(c == ' '){
                        i++;;
                    }
                    else{
                        pass = 1;
			firstN = nextNum(line, pass);
                        firstN = reverse(firstN, numLen) * neg;
                    }
                }
                //if first integer has been found either find valid oporator or return error
                else if(pass == 1){
                    if(c != '+' && c != '-' && c != '*' && c != '/' && c != ' '){
                        error = 1;
                        printf("calc Usage Error input %d: calc arguments are integer, operator(+-*/), integer\n",(pass+1));
                    }
                    else if(c == ' '){
                        i++;
                    }
                    else{
                        pass = 2;
                        oporator = c;
                        i++;
                        c = line[i];
		        neg = 1;
                    }
                }
                //if oporator found either find valid integer or return error
                else if(pass == 2){
                   if((c < '0' || c > '9') && c != ' ' && c != '-'|| (c == '-' && neg == -1)){
                        error = 1;
                        printf("calc Usage Error input %d: calc arguments are integer, operator(+-*/), integer\n",(pass+1));
                    }
		    else if(c == '-'){
			neg = -1;
                        i++;
		    }
                    else if(c == ' '){
                        i++;
                    }
                    else{
                        pass = 3;
			seccondN = nextNum(line, pass);
                        seccondN = reverse(seccondN, numLen2);

                    }
                }
                //if seccond num foundcontinue to end of line make sure nothing else there
                else{
                   if(c != ' ' && c != '\0'){
                        error = 1;
                        printf("calc Usage Error3: calc arguments are integer, operator(+-*/), integer\n");
                    }
                    i++;
                }
        }
    return returnResult(firstN,seccondN,oporator,error,pass);
}