Example #1
0
int main(int argc, char **argv)
{
	int loadonly = 0, pageNo = -1;
	parsecmdargs(argc, argv, &loadonly, &pageNo);
	/* for simplicity assume the file to parse is always the last */
	benchfile(argv[argc-1], loadonly, pageNo);
	return 0;
}
Example #2
0
int main(int argc, char *argv[])

{
  speed_t baud = B57600;  // default baudrate
  stdinfd = fileno(stdin);
  stdoutfd = fileno(stdout);
  serialfd = -1;
  erlpipefd = -1;
  struct termios oldserial, oldstdin;
 
 
 //saveterminal(stdinfd,oldstdin);
 // check(tcgetattr(stdinfd,&oldstdin) == 0, "Failed to backup stdin");

 // if erlang mode is set then redirect stderr to erlerr.txt

   

  //read command line arguments
  check(parsecmdargs(argc, argv) != -1,"Command Line Argument Failure");


  if(erlang == TRUE)
     {
       freopen("erlerr.txt", "w", stderr);
     }  
 debug("pid is %d", getpid());
  //setup pipe if require doesn't work yet 
   if(pipedebug == 1) //
   {
  
     check(makepipe(ERLPIPE) == 0, "Pipe creation or opening failed for: ");
     debug("Pipe created:");
     debug("Process %d opening erlpipe", getpid());
     erlpipefd = open(ERLPIPE, O_WRONLY|O_NONBLOCK); 
     check(erlpipefd > 0, "Erlpipe failed to open pipe: %s\nSetup reader in second terminal\n tail -f erlpipe",ERLPIPE);
     debug("Erlpipe opened");
     /*
     check(makepipe(ERLPIPEIN) == 0, "Erlpipein  creation or opening failed for: "); 
     debug("Pipe created:");
     debug("Process %d opening erlpipein", getpid());
     erlpipeinfd = open(ERLPIPEIN);
     check(erlpipeinfd > 0, "Erlpipein: Failed to open pipe: %s\nSetup reader in second terminal\n tail -f erlpipe",ERLPIPEIN);
     debug("Erlpipe opened"); */
    }
    
   // save terminal settings
 
 
  //get baud rate from command line arguments
  baud = getbaud(baudrate);
  check(baud != B0, "Illegal baud rate"); 
  
  if(serial == TRUE){

  //open serial port
  serialfd = open(serialport, O_RDWR);
  check(serialfd > 0,"Can't open serial port\n Try dmesg | grep tty from shell \n");    
  debug("Opened serial port: %s",serialport);
 
  //set serial port to raw mode
  check(makeraw(serialfd)==0,"Failed to set serial port raw mode");
 //set baudrate serial
  check(setspeed(serialfd,baud)==0,"Failed to set baud rate");
  debug("Baud rate set to: %d", baudrate);
  }

  //set stdin to raw mode
  // check(makeraw(stdinfd)==0, "Failed to set stdin to raw mode");
  // debug("Not Entered raw mode:");

 
  
  //send acknowledge to erlang???

 /* Watch stdinfd and serialfd
       if input is available process then output
       Serial -> Erlang
       Erlang -> Serial
    */ 
  
  /*
  int numbytes;
  while(1){
  numbytes = read_erlang(erlmesg.mesg);
  check(numbytes > 0, "Read error from erlang");
	debug("Read %d bytes from Erlang", numbytes);
	write_serial(numbytes, erlmesg.mesg);
	debug("Wrote %d bytes to serial:", numbytes);
  }
  //main loop
  */
	
  {
    fd_set readfds;
    int maxfd;
    int is, numbytes;
    FD_ZERO(&readfds);
    
    maxfd = (stdinfd > serialfd) ? stdinfd : serialfd;
    maxfd = (maxfd > erlpipeinfd) ? maxfd : erlpipeinfd;

      
    while(1){
      if(serial){
      FD_SET(serialfd, &readfds);
      }
      
      if(pipedebug){
	  FD_SET(erlpipeinfd, &readfds);
	}

      FD_SET(stdinfd, &readfds);
      
      
      is = select(maxfd+1, &readfds, NULLFDS, NULLFDS, NULLTV);
      check(is>0,"Select error -"); 
      
      if (serial && FD_ISSET(serialfd,&readfds)){ // Serial porth ready to read
	FD_CLR(serialfd,&readfds);
	

	numbytes = read(serialfd, erlmesg.mesg, MAXMESG);
	check(numbytes > 0, "Read error from serial port");
	write_erlang(numbytes, erlmesg.mesg);

      }

      if (FD_ISSET(stdinfd,&readfds)){  //Stdin-Erlang ready to read
 	FD_CLR(stdinfd, &readfds);
	
        numbytes = read_erlang(erlmesg.mesg);
	check(numbytes > 0, "Read error from erlang");
	debug("Read %d bytes from Erlang", numbytes);
	write_serial(numbytes, erlmesg.mesg);
	debug("Wrote %d bytes to serial:", numbytes);

      }
      // input pipe
      /*
      if (pipedebug && (FD_ISSET(erlpipeinfd,&readfds)){  
	FD_CLR(erlpipeinfd, &readfds);

    }
      */
    }
  
}	  
  //hanldle input from erlang
  //handle input from serial port
  // restoreterminal(stdinfd,&oldstdin);

	//  tcsetattr(stdinfd,TCSANOW,&oldstdin);
    return 0;

 error:
    //restoreterminal(stdinfd,&oldstdin);
    //    tcsetattr(stdinfd,TCSANOW,&oldstdin);;
    debug("Restored terminal");
    exit(1);
   
    }