int main(){
 
	while( 0 == 0 ) {
		printMenu();
		printf("Enter command: ");
		
		scanf("%s", choice);

		if (choice[0]=='i'){
			interactive();
		}
		else if (choice[0]=='a'){
			automatic();		
		}
		else if (choice[0]=='e'){
			printf("exiting\n\n");
			break;
		}
		else
			printf("Please enter a valid option\n");
		
		if (status == 1){ //only print the final addresses if everything has gone accordingly
			printAddress();
			status=0; //reset status
		}
	}
	return EXIT_SUCCESS;
}
Esempio n. 2
0
//selected: automatic mode
void atmtc(void)
{
     
     //Color Selection
     int color[5]; 
     /* color[0]:green front
      * color[1]:green back
      * color[2]:red front
      * color[3]:red back
      * color[4]:null character
      */
     printf("\n\nPlease enter desired color code in sequence: \n(green light front, "
            "green light back, red light front, red light back)\n"
            "Code menu:\n"
            " 0: Black      1: Blue          2: Green         3: Cyan\n"
            " 4: Red        5: Purple        6: Yellow        7: Light Gray\n"
            " 8: Gray       9: Light Blue   10: Light Green  11: Light Cyan\n"
            "12: Light Red 13: Light Purple 14: Light Yellow 15: White \n");
     printf("Your choice?");
     _flushall();
     
     if(scanf("(%d, %d, %d, %d)", 
                           &color[0], &color[1], &color[2], &color[3])== 4){
          if(color[0]<16 && color[1]<16 && color[2]<16 && color[3]<16){
                   if(color[0]>=0 && color[1]>=0 && color[2]>=0 && color[3]>=0){
                        printf("Press any botton to continue...\n");
                        getch();
                   }
          }
     }
     
     else{
       printf("You didn't enter the correct form. Proceed with default value.");
       color[0]=2; color[1]=0; color[2]=4; color[3]=0;
       
       _flushall();
       getch();
     }
     
     //Prompt for time interval
     int time;
     printf("\n\nPlease enter a desired integer time period for green light:");
     fflush(stdin);
     scanf("%d", &time);
     
     //clear screen to show animate
     system("cls");
     
     //randomly select special function. odd 10%
     if((rand()%1000+1)>900)
          bingo();
     else
          automatic(time, color[0], color[1], color[2], color[3]);
     
     //Animation end; clear screen; return to menu.
     system("cls");
}
Esempio n. 3
0
Sound Sound_Formant_filter_noscale (Sound me, Formant formant) {
	Sound thee = NULL;
	try {
		automatic (FormantGrid) grid = Formant_downto_FormantGrid (formant);
		thee = Sound_FormantGrid_filter_noscale (me, grid);
	} catch (...) {
		forget (thee);
		throw;
	}
	return thee;
}
Esempio n. 4
0
void Background::run(void)
{
    timeout_t timeout, current;
    Timeslot *ts;
    unsigned tsid;
    time_t now;
    Timer expires;

    shell::debug(1, "starting background thread");
    expires = Timer::inf;
    bk.running = true;

    for(;;) {
        Conditional::lock();
        if(!bk.running) {
            Conditional::unlock();
            shell::debug(1, "stopping background thread");
            bk.signalled = false;
            return; // exit thread...
        }
        timeout = expires.get();
        if(!bk.signalled && timeout) {
            if(timeout > bk.slice)
                timeout = bk.slice;
            Conditional::wait(timeout);
        }
        timeout = expires.get();
        if(bk.signalled || !timeout) {
            bk.signalled = false;
            Conditional::unlock();
            tsid = Driver::getCount();
            timeout = Timer::inf;
            time(&now);
            while(tsid) {
                ts = Driver::get(--tsid);
                current = ts->getExpires(now);
                if(current && current < timeout)
                    timeout = current;
                ts->expire();
            }
            expires = timeout;
        }
        else {
            bk.signalled = false;
            Conditional::unlock();
        }
        automatic();
    }
}
SyntaxChecker::Result SyntaxChecker::checkSyntax(const QString &code)
{
  const int INITIAL_STATE = 0;
  QScript::Lexer lexer (/*engine=*/ 0);
  lexer.setCode(code, /*lineNo*/ 1);

  int yytoken = -1;
  int saved_yytoken = -1;
  QString error_message;
  int error_lineno = -1;
  int error_column = -1;
  State checkerState = Valid;

  reallocateStack();

  tos = 0;
  state_stack[++tos] = INITIAL_STATE;

  while (true)
    {
      const int state = state_stack [tos];
      if (yytoken == -1 && - TERMINAL_COUNT != action_index [state])
        {
          if (saved_yytoken == -1)
            yytoken = lexer.lex();
          else
            {
              yytoken = saved_yytoken;
              saved_yytoken = -1;
            }
        }

      int act = t_action (state, yytoken);

      if (act == ACCEPT_STATE) {
          if (lexer.error() == QScript::Lexer::UnclosedComment)
              checkerState = Intermediate;
          else
              checkerState = Valid;
          break;
      } else if (act > 0) {
          if (++tos == stack_size)
            reallocateStack();

          state_stack [tos] = act;
          yytoken = -1;
        }

      else if (act < 0)
        {
          int r = - act - 1;

          tos -= rhs [r];
          act = state_stack [tos++];

          if ((r == Q_SCRIPT_REGEXPLITERAL_RULE1)
              || (r == Q_SCRIPT_REGEXPLITERAL_RULE2)) {
              // Skip the rest of the RegExp literal
              bool rx = lexer.scanRegExp();
              if (!rx) {
                  checkerState = Intermediate;
                  break;
              }
          }

          state_stack [tos] = nt_action (act, lhs [r] - TERMINAL_COUNT);
        }

      else
        {
          if (saved_yytoken == -1 && automatic (&lexer, yytoken) && t_action (state, T_AUTOMATIC_SEMICOLON) > 0)
            {
              saved_yytoken = yytoken;
              yytoken = T_SEMICOLON;
              continue;
            }

          else if ((state == INITIAL_STATE) && (yytoken == 0)) {
              // accept empty input
              yytoken = T_SEMICOLON;
              continue;
          }

          int ers = state;
          int shifts = 0;
          int reduces = 0;
          int expected_tokens [3];
          for (int tk = 0; tk < TERMINAL_COUNT; ++tk)
            {
              int k = t_action (ers, tk);

              if (! k)
                continue;
              else if (k < 0)
                ++reduces;
              else if (spell [tk])
                {
                  if (shifts < 3)
                    expected_tokens [shifts] = tk;
                  ++shifts;
                }
            }

          error_message.clear ();
          if (shifts && shifts < 3)
            {
              bool first = true;

              for (int s = 0; s < shifts; ++s)
                {
                  if (first)
                    error_message += QLatin1String ("Expected ");
                  else
                    error_message += QLatin1String (", ");

                  first = false;
                  error_message += QLatin1Char('`');
                  error_message += QLatin1String (spell [expected_tokens [s]]);
                  error_message += QLatin1Char('\'');
                }
            }

          if (error_message.isEmpty())
              error_message = lexer.errorMessage();

          error_lineno = lexer.startLineNo();
          error_column = lexer.startColumnNo();
          checkerState = Error;
          break;
        }
    }

  if (checkerState == Error) {
      if (lexer.error() == QScript::Lexer::UnclosedComment)
          checkerState = Intermediate;
      else if (yytoken == 0)
          checkerState = Intermediate;
  }
  return Result(checkerState, error_lineno, error_column, error_message);
}
Esempio n. 6
0
Seiscomp::DataModel::Origin *Autoloc::convertToSC3(const Autoloc::Origin* origin, bool allPhases)
{
	Seiscomp::DataModel::Origin *sc3origin
	    = Seiscomp::DataModel::Origin::Create();

	Seiscomp::DataModel::TimeQuantity sc3tq;
	Seiscomp::DataModel::RealQuantity sc3rq;

	sc3origin->setTime(Seiscomp::DataModel::TimeQuantity(Autoloc::sc3time(origin->time), origin->timeerr, Seiscomp::Core::None, Seiscomp::Core::None, Seiscomp::Core::None));
	sc3origin->setLatitude(Seiscomp::DataModel::RealQuantity(origin->lat, origin->laterr, Seiscomp::Core::None, Seiscomp::Core::None, Seiscomp::Core::None));
	sc3origin->setLongitude(Seiscomp::DataModel::RealQuantity(origin->lon, origin->lonerr, Seiscomp::Core::None, Seiscomp::Core::None, Seiscomp::Core::None));
	sc3origin->setDepth(Seiscomp::DataModel::RealQuantity(origin->dep, origin->deperr, Seiscomp::Core::None, Seiscomp::Core::None, Seiscomp::Core::None));

	sc3origin->setMethodID(origin->methodID);
	sc3origin->setEarthModelID(origin->earthModelID);

	sc3origin->setEvaluationMode(Seiscomp::DataModel::EvaluationMode(Seiscomp::DataModel::AUTOMATIC));
	if ( origin->preliminary )
		sc3origin->setEvaluationStatus(Seiscomp::DataModel::EvaluationStatus(Seiscomp::DataModel::PRELIMINARY));

	switch ( origin->depthType ) {
	case Autoloc::Origin::DepthFree:
			sc3origin->setDepthType(Seiscomp::DataModel::OriginDepthType(Seiscomp::DataModel::FROM_LOCATION));
			break;

	case Autoloc::Origin::DepthMinimum:
			break;

	case Autoloc::Origin::DepthDefault:
			break;

	case Autoloc::Origin::DepthManuallyFixed:
			sc3origin->setDepthType(Seiscomp::DataModel::OriginDepthType(Seiscomp::DataModel::OPERATOR_ASSIGNED));
			break;
	default:
			break;
	}

	// This is a preliminary fix which prevents autoloc from producing
	// origins with fixed depth, as this caused some problems at BMG
	// where the fixed-depth checkbox was not unchecked and an incorrect
	// depth was retained. Need a better way, though.
//	sc3origin->setDepthType(Seiscomp::DataModel::OriginDepthType(Seiscomp::DataModel::FROM_LOCATION));


	// Store SC3 Picks/Stations here so that they can be found
	// via SC3 PublicObject lookup
	std::vector<Seiscomp::DataModel::PublicObjectPtr> sc3objects;

	int arrivalCount = origin->arrivals.size();

	for (int i=0; i<arrivalCount; i++) {
		const Autoloc::Arrival &arr = origin->arrivals[i];

		// If not all (automatic) phases are requested, only include P and PKP
		if ( !allPhases && automatic(arr.pick.get()) && arr.phase != "P" && arr.phase != "PKP") {
			SEISCOMP_DEBUG_S("SKIPPING 1  "+arr.pick->id);
			continue;
		}

		// Don't include arrivals with huge residuals as (unless by
		// accident) these are excluded from the location anyway.
/*
		if (arr.excluded && fabs(arr.residual) > 30.) { // FIXME: quick+dirty fix
			SEISCOMP_DEBUG_S("SKIPPING 1  "+arr.pick->id);
			continue;
		}
*/
		const Seiscomp::DataModel::Phase phase(arr.phase);
		Seiscomp::DataModel::ArrivalPtr sc3arr 
		    = new Seiscomp::DataModel::Arrival();
		sc3arr->setPickID(   arr.pick->id);
		sc3arr->setDistance( arr.distance);
		sc3arr->setAzimuth(  arr.azimuth);
		sc3arr->setTimeResidual( arr.residual);
		sc3arr->setWeight(   arr.excluded ? 0 : 1);
		sc3arr->setPhase(phase);

		Seiscomp::DataModel::PickPtr sc3pick
		    = Seiscomp::DataModel::Pick::Cast(
		        Seiscomp::DataModel::PublicObject::Find(arr.pick->id));

		if ( sc3pick == NULL ) {
			sc3pick = Seiscomp::DataModel::Pick::Create(arr.pick->id);
			const Autoloc::Station *sta = arr.pick->station();
			Seiscomp::DataModel::WaveformStreamID wfid(sta->net, sta->code, "", "XYZ", "");
			sc3pick->setWaveformID(wfid);
			sc3tq.setValue(Autoloc::sc3time(arr.pick->time));
			sc3pick->setTime(sc3tq);
			sc3pick->setPhaseHint(phase);

			if (arr.pick->status == Autoloc::Pick::Manual)
				sc3pick->setEvaluationMode(Seiscomp::DataModel::EvaluationMode(Seiscomp::DataModel::MANUAL));
			else
				sc3pick->setEvaluationMode(Seiscomp::DataModel::EvaluationMode(Seiscomp::DataModel::AUTOMATIC));
		}
		sc3objects.push_back(sc3pick);

		sc3origin->add(sc3arr.get());
	}

	Seiscomp::DataModel::OriginQuality oq;
	oq.setAssociatedPhaseCount(sc3origin->arrivalCount());
	oq.setUsedPhaseCount(origin->definingPhaseCount());
	oq.setAssociatedStationCount(origin->associatedStationCount());
	oq.setUsedStationCount(origin->definingStationCount());
	oq.setMedianDistance(origin->medianStationDistance());
	oq.setStandardError(origin->rms());

	double minDist, maxDist, aziGap;
	origin->geoProperties(minDist, maxDist, aziGap);

	oq.setMinimumDistance(minDist);
	oq.setMaximumDistance(maxDist);
	oq.setAzimuthalGap(aziGap);

	sc3origin->setQuality(oq);

	return sc3origin;
}