Beispiel #1
0
/* < saveconfig */
void saveconfig( struct menuInfo* theSelectedInfo)
{
  if (isInstalled())
    {
      return;
    }
  say( Saysaveconfig);
  say( PleasePressKey);

  if (getAnswer() != MENU_Yes)
    {
      return;
    }

  // This menu requires yasr
  buildConfigurationYasr(&(theSelectedInfo->myTextToSpeech), 1);
  
  char* aCommand=TheLine;
  //  sprintf(aCommand, "/usr/sbin/saveconfig");
  sprintf(aCommand, "/usr/sbin/knoppix-mkimage");
	    
  runYasr( &(theSelectedInfo->myTextToSpeech), 
	   theSelectedInfo->myMenuLanguage, 
	   aCommand);
}
Beispiel #2
0
/* < setPersistentStorage */
void setPersistentStorage( struct menuInfo* theSelectedInfo)
{
  say( sayPersistentStorage);
  say( PleasePressKey);

  if (getAnswer() != MENU_Yes)
    {
      return;
    }


  // This menu requires yasr
  buildConfigurationYasr(&(theSelectedInfo->myTextToSpeech), 1);
  
  // Set the expected LANG
  char* aLang=getStringLanguage( theSelectedInfo->myTextToSpeech.myLanguage);

  char* aCommand=TheLine;
  sprintf(aCommand, "%s/main/persistentStorage.sh", 
	  ORALUX_RUNTIME);

  runYasr( & (theSelectedInfo->myTextToSpeech), 
	   theSelectedInfo->myMenuLanguage, 
	   aCommand);
}
Beispiel #3
0
void simSetTextInput(){
	uart_puts("AT+CMGF=1");
	sendCRLF();
	delay(commDelay);
	if (strncmp( getAnswer(), successResp, 2 ) != 0){
	 //sendError
	}
}
Beispiel #4
0
std::string ChineseTest::getTestAns() const {
    char ans = getAnswerChoice() + 1 + '0';
    std::string ret = "";
    ret = ret + "Correct Answer is [";
    ret = ret + ans;
    ret = ret + "]" + getAnswer() + " " + getAnswerMeaning() + "\n";
    return ret;
}
int main()
{
    input();
    initCost();
    getCost();
    getAnswer();
    output();
    return 0;
}
Beispiel #6
0
void simSendMessage(){
	uart_puts("sim900 test");
	sendCRLF();
	delay(commDelay);
	uart_putc(inputEnd);
	if (strncasecmp( getAnswer(), messageSendResp, 7) != 0){
	 //sendError
	}	
}
Beispiel #7
0
void *searchContact(char * contact, size_t len){
	buffer[30] = "AT+CPBF=\"";
	buffer[30] = strncat(buffer, contact, len);
	buffer[30] = strncat(buffer, "\"", 1);
	uart_puts(buffer);
	sendCRLF();
	delay(commDelay);
	return getAnswer();
}
Beispiel #8
0
int main()
{
	int x;
	scanf("%d",&x);
	int n = 4000000007;
	int resp = getAnswer(x,n);
	printf("%d\n",resp);
	return 0;
}
Beispiel #9
0
bool cli::framework::YesNoPrompt::prompt(const std::string &message) const
{
	LogEnterExit logging(__FUNCTION__, __FILE__, __LINE__);

	std::string question = buildQuestion(message);
	askQuestion(question);
	std::string answer = getAnswer();
	return isAnswerCorrect(answer);
}
Beispiel #10
0
void waitForReg(){
	while(1){
		uart_puts("AT+CREG?");
		sendCRLF();
		delay(regDelay);
		if (strncmp( getAnswer(), inNetResp, 10 ) == 0){
			break;
		}	
	}
}
Beispiel #11
0
void simCommInit(){
	uart_init( UART_BAUD_SELECT(UART_BAUD_RATE,F_CPU) );
	delay(commDelay);
	uart_puts("AT+IPR=9600");
	sendCRLF();
	delay(commDelay);
	if (strncmp( getAnswer(), successResp, 2 ) != 0){
	 //sendError
	}
}
Beispiel #12
0
enum ShutdownStatus askIfShutdownIsRequired()
{
  ENTER("askIfShutdownIsRequired");
  enum ShutdownStatus aStatus=StatusUndefined;

  say(DoYouWantToShutdown);
  say(PleasePressKey);
  if (MENU_Yes == getAnswer()) 
    {
      // RAF GC
      /*       say(ToEjectCD); */
      /*       if (MENU_Yes == getAnswer())  */
      /* 	{ */
      if (!isInstalled())
	{
	  sayForce(ThenReturnOnceEjected);
	}
      aStatus=StatusEjectCDROMAndShutdown;
      SHOW("StatusEjectCDROMAndShutdown");
      /* 	} */
      /*       else */
      /* 	{ */
      /* 	  aStatus=StatusKeepCDROMAndShutdown; */
      /* 	  SHOW("StatusKeepCDROMAndShutdown");	      */
      /* 	} */
    }
  else
    {
      say(DoYouWantToReboot);
      if (MENU_Yes == getAnswer()) 
	{
	  if (!isInstalled())
	    {
	      sayForce(ThenReturnOnceEjected);
	    }
	  aStatus=StatusReboot;
	  SHOW("StatusReboot");	     
	}
    }
  clearStoredSentences();
  return aStatus;
}
Beispiel #13
0
bool DnsLayer::removeAnswer(const std::string& answerNameToRemove, bool exactMatch)
{
	DnsResource* answerToRemove = getAnswer(answerNameToRemove, exactMatch);
	if (answerToRemove == NULL)
	{
		LOG_DEBUG("Answer record not found");
		return false;
	}

	return removeAnswer(answerToRemove);
}
void AP_UnixDialog_Lists::runModal( XAP_Frame * pFrame)
{
	FL_ListType  savedListType;
	setModal();
	
	GtkWidget * mainWindow = _constructWindow();
	UT_return_if_fail(mainWindow);
	
	clearDirty();

	// Populate the dialog
	m_bDontUpdate = false;
	loadXPDataIntoLocal();

	// Need this to stop this being stomped during the contruction of preview widget
	savedListType = getNewListType();

	// *** this is how we add the gc for Lists Preview ***
	// attach a new graphics context to the drawing area
	XAP_UnixApp * unixapp = static_cast<XAP_UnixApp *> (m_pApp);
	UT_ASSERT(unixapp);

	// Now Display the dialog, so m_wPreviewArea->window exists
	gtk_widget_show(m_wMainWindow);	
	UT_ASSERT(m_wPreviewArea && m_wPreviewArea->window);

	// make a new Unix GC
	GR_UnixCairoAllocInfo ai(m_wPreviewArea);
	m_pPreviewWidget =
	    (GR_CairoGraphics*) XAP_App::getApp()->newGraphics(ai);

	// let the widget materialize
	_createPreviewFromGC(m_pPreviewWidget,
						 static_cast<UT_uint32>(m_wPreviewArea->allocation.width),
						 static_cast<UT_uint32>(m_wPreviewArea->allocation.height));

	// Restore our value
	setNewListType(savedListType);
	
	gint response;
	do {
		response = abiRunModalDialog (GTK_DIALOG(mainWindow), pFrame, this, BUTTON_CANCEL, false);		
	} while (response == BUTTON_RESET);
	AP_Dialog_Lists::tAnswer res = getAnswer();
	m_glFonts.clear();
	abiDestroyWidget ( mainWindow ) ;
	setAnswer(res);
	DELETEP (m_pPreviewWidget);
}
Beispiel #15
0
bool DuoXuanDlg::insertExamInfo(int i)
{
	CString sql,answer1;
	answer1=getAnswer();
	sql.Format("insert into tb_examinfo values(%d,'%s','%s','%s','%s')",i,subject,question,answer1,rightanswer);	
//	MessageBox(sql);
	ADOConn m_ado;
	m_ado.OnInitADOConn();
	if(m_ado.ExecuteSQL((_bstr_t)sql))
	{
		m_ado.ExitConn();
		return true;
	}	
	return false;
}
Beispiel #16
0
signed char loop( const opt_t * pstr_argsDest, etherPacket_t * pstr_packet, struct sockaddr_ll * pstr_device, long l_socket )
{
    signed char c_retValue;
    unsigned char uc_received;
    unsigned long ul_noReply;
    struct timeval str_sendingMoment;

    ul_noReply = 0;
    c_retValue = 0;
    /* --- */
    while ( ( ul_NbProbes + 1 <= pstr_argsDest->ul_count ) || ( !( pstr_argsDest->ul_count ) ) )/* infinite loop if no count specified */
    {
        /* If we don't take care to the number of retries => jmp to the else, else check for actual number of retries */
        if ( ( pstr_argsDest->uc_unlimitedRetries ) ? 0 : ( ul_noReply == pstr_argsDest->ul_maximumRetries ) )
        {
            fprintf( stdout, "\nNo answer received after %lu tries\n", pstr_argsDest->ul_maximumRetries );
            c_retValue = -2;
            break;
        }
        else
        {
            if ( sendProbe( l_socket, pstr_packet, pstr_device ) != 1 )
            {
                fprintf( stderr, "Can't send request #%ld\n", ul_NbProbes++ );
            }
            else
            {
                ul_NbProbes++; /* Total probes sent */

                gettimeofday( &str_sendingMoment, NULL ); /* Record of sending timestamp */
#ifdef DEBUG
                fprintf( stderr, "Request #%ld sent\n", ul_NbProbes );
#endif
                /* the getAnswer function returns the number of replies received for each request (boolean value) */
                uc_received = getAnswer( l_socket, pstr_device, str_sendingMoment ); /* wait for an answer and parse it */
                ul_ReceivedReplies += uc_received; /* Total replies received */
                ul_noReply = ( uc_received ) ? 0 : ul_noReply + 1; /* Number of probes without answer */

                if ( pstr_argsDest->uc_exitOnReply && ul_ReceivedReplies )
                    break;
            }
            usleep( pstr_argsDest->ul_waitingMilliSeconds * 1000 ); /* Inter probes pause */
        }
    }

    return c_retValue;
}
Beispiel #17
0
void getAnswer(int x){
	vis[x] = 1;
	for(int i = 0; i < int(treeEdge[x].size()); ++i) if(!vis[treeEdge[x][i]]){
		getAnswer(treeEdge[x][i]);
		if(toDecide[treeEdge[x][i]].size() > toDecide[x].size()){
			std::swap(toDecide[treeEdge[x][i]], toDecide[x]);
		}
		while(toDecide[treeEdge[x][i]].size()){
			toDecide[x].push_back(toDecide[treeEdge[x][i]].back());
			toDecide[treeEdge[x][i]].pop_back();
		}
	}
	if(!decided[x]){
		ans[toDecide[x].back()] = x;
		toDecide[x].pop_back();
	}
}
Beispiel #18
0
void UDPServer::processPendingDatagrams()
{
	pQuery pq;
	QHostAddress sFromAddress;

	DEBUG_MSG_INFO(QString("has datagrams..."), CMsg::eMT_Info1);

	while (m_pobjUDPInSocket->hasPendingDatagrams()) {

		QByteArray datagram;

		datagram.resize(m_pobjUDPInSocket->pendingDatagramSize());
		m_pobjUDPInSocket->readDatagram(datagram.data(), datagram.size(), &sFromAddress);

		pq.setDatagram(datagram.data());

		QStringList lstr;
		if(pq.verifyChecksum()) {

			lstr.clear();
			lstr << QString("query  | %1 | %2").arg(sFromAddress.toString(), 15).arg(pq.print());
			DEBUG_MSG_INFO(lstr, CMsg::eMT_Info1);

			pAnswer pa;
			pa.setID(pq.getID());
			pa.setDateTime(QDateTime::currentDateTime());
			pa.setSID( m_usSId );
			if( !getAnswer(pa, pq.getType(), pq.getIDC(), sFromAddress.toString() ) ) {

				sendAnswer( pa, sFromAddress, pq.getIDC() );

				lstr.erase(lstr.begin(), lstr.end());
				lstr << QString("answer | %1 | %2").arg(sFromAddress.toString(), 15).arg(pa.print());
				DEBUG_MSG_INFO(lstr, CMsg::eMT_Info1);

				if(pa.getVariableCount())
					DEBUG_MSG_INFO(pa.print_vars(), CMsg::eMT_Info1);
			}
		}
		else {
			DEBUG_MSG_INFO(QString().sprintf("received corrupted datagram from %s\n", sFromAddress.toString().toAscii().data()), CMsg::eMT_Info1);
		}
	}
}
Beispiel #19
0
// mustSetPreferences
// If the preferences were already set, we ask if the menu must be run again.
//
// Return: 1=yes, 0= false
int mustSetPreferences()
{
  ENTER("mustSetPreferences");
  int aStatus=1;

  // Testing if the .aumixrc is present
  sprintf(TheLine,"%s/.aumixrc",getenv("HOME"));
  FILE* fd=fopen(TheLine,"r");
  if (fd!=0)
    {
      // Preferences were already set.
      // Asking if we must enter again the menu
      say(enterAgainMenu);
      say(PleasePressKey);

      if (getAnswer()!=MENU_Yes)
	{
	  aStatus=0;
	}
      fclose(fd);
    }
  return aStatus;
}
Beispiel #20
0
void BPN::completenessTest(NNDatabase& db)
{
	LogWriter log;
	string message;
	char buffer[50];

	log.println("Running training completeness test.");

	vector<Matrix<float> >& input = db.getTrainingInput();
	vector<Matrix<float> >& output = db.getTrainingOutput();
	int correct = 0;
	for(int i=0;i<input.size();i++)
	{
		getAnswer(input[i]);
		if(outputs[outputs.size()-1]==output[i])
			correct++;
		//delete bpnOutput;
		if(i%100==0)
		{
			log.print(".");
		}
	}

	log.print("\n");
	sprintf(buffer, "%d", correct);
	message+=buffer;
	message+= " correct out of ";
	sprintf(buffer, "%d", input.size());
	message+=buffer;
	log.println(message);
	int percent = ((float)correct/(float)input.size())*(float)100;
	sprintf(buffer, "%d", percent);
	message+=buffer;
	message+="% correct";
	log.println(message);
	log.println("Completeness test finished.");
}
//This functions allows the user to set some of the main settings via the serial monitor
//serial monitor setup menu will execute the first time you start the module. After that settings are remembered in EEPROM next time you power module
//To adjust settings again reset the module and hold down the non-reset toggle switch to enter setting menu
//When just using settings from EEPROM this function just gets the setting from EEPROM and stores them in global variables
void WSNode::getSettings()
{
    pinMode(8, INPUT_PULLUP); //set pin 8 as an input
    int val; //variable to store node address
    byte cAddr = 128; //this variable is used to see if this is the first time the module is being used
    byte tInterval; //set the transmit time interval
    byte mode; //set to router or end device mode
    //The following strings are used by serial monitor more than once so to save memory they are made into variables
    String enter = F("Enter 'Y' for yes or any other character for no:"); //F() macro tells IDE to store string in flash memory and not SRAM
    String invalid = F("Invalid entry, default to ");
    String would = F("Would you like to update the ");

    //if this is either the first time the module is used or if pin 8 is connecting to ground enter settings mode
    if (EEPROM.get(0, cAddr) != 128 || !digitalRead(8)) {
        digitalWrite(7, HIGH); //in settings mode so turn on status LED
        Serial.begin(57600); //start serial communication, need to turn off before using sleep and WDT
        //the following code reads the current settings from EEPROM and puts them in local variables
        Serial.println(F("Current settings in EEPROM"));
        Serial.print("Node address: ");
        Serial.println(EEPROM.get(1, val), OCT);
        Serial.print("Time interval: ");
        Serial.println(getInterval());
        Serial.print("Mode: ");
        Serial.println(getMode());
        //This following gives you the option to set each setting and if you change a setting it is stored in EEPROM
        Serial.print(would);
        Serial.print("Node Address? ");
        Serial.println(enter);
        if (getAnswer()) {
            Serial.println(F("Enter Node address to store in EEPROM"));
            while (!Serial.available()) {}
            val = Serial.parseInt();
            if (val >= 0) {
                EEPROM.put(1, val);
            }
            else { //if zero is entered it is invalid since coordinator is zero
                Serial.print(invalid);
                Serial.println("01");
                val = 01;
                EEPROM.put(1, val);
            }
        }

        Serial.print(would);
        Serial.print("time interval? ");
        Serial.println(enter);
        if (getAnswer()) {
            Serial.println(F("Enter: 0 for 1 sec, 1 for 1 min, 2 for 10 min, 3 for 15 min"));
            while (!Serial.available()) {}
            tInterval = Serial.parseInt();
            if (tInterval >= 0 || tInterval < 4) { //check that entry was valid
                EEPROM.put(7, tInterval);
            }
            else {
                Serial.print(invalid);
                Serial.println("3");
                tInterval = 3;
                EEPROM.put(7, tInterval);
            }
        }
        Serial.print(would);
        Serial.print("mode setting? ");
        Serial.println(enter);
        if (getAnswer()) {
            Serial.println(F("Enter 0 for end device and 1 for router"));
            while (!Serial.available()) {}
            mode = Serial.parseInt();
            if (mode == 0 || mode == 1) { //check that entry was valid
                EEPROM.put(8, mode);
            }
            else {
                Serial.print(invalid);
                Serial.println("0");
                mode = 0;
                EEPROM.put(8, mode);
            }
        }
        getEEPROMValues(); //gets settings from EEPROM and stor in global variables
        //the following code prints out current settings from global variables
        Serial.print("Node address: ");
        Serial.println(thisNode,OCT);
        Serial.print("Time interval: ");
        Serial.println(sInterval);
        Serial.print("Mode setting: ");
        Serial.println(mMode);
        cAddr = 128; //write '128' to EEPROM to show that settings have been entered at least once
        EEPROM.put(0, cAddr);
        Serial.end(); //need to end serial communication before using the WDT and sleep functions
    }
    else {
        //not in settings mode so just get settings from EEPROM and store in global variables
        getEEPROMValues();
    }
}
Beispiel #22
0
int main(void)
{
	initRandom();
	warmGreeting();
	const unsigned int numberOfQuestions = getNumberOfQuestions();
	const difficulty difficulty = getDifficulty();
	unsigned int correctAnswers = 0;
	string q, answer, userAnswer;

	for (unsigned int i = 1; i <= numberOfQuestions; i++)
	{
		puts(LINE_DIVIDER);
		printf("Question #%d\n", i);
		puts(LINE_DIVIDER);
		generateQuestion(q, 3 * difficulty, 25 * difficulty);
		getAnswer(q, answer);
		printf("%s = ", q);
		scanf("%s", userAnswer);

		if (strcmp(answer, userAnswer))
		{
			printf("WRONG! answer=%s\n", answer);
		}
		else
		{
			correctAnswers++;
			printf("CORRECT!\n");
		}
	}
	puts(LINE_DIVIDER);
	int p = (100 * correctAnswers) / numberOfQuestions;
	printf("TOTAL CORRECT ANSWERS = %d (%d%%)\n", correctAnswers, p);
	if (p >= 75)
	{
		switch (difficulty)
		{
			case EASY:
				puts("Good job, keep it up :)");
				break;
			case MEDIUM:
				puts("Great job, you're on the way!");
				break;
			case HARD:
				if (numberOfQuestions > 10)
				{
					puts("OMG! Amazing job! You are truly good at arithmetics! (unless you cheated...:P)");
				}
				else
				{
					puts("WOW! Amazing job! I salute you");
				}
				break;
		}
	}
	else if (p >= 50)
	{
		puts("Nice going, practice makes perfect ;)");
	}
	else if (p >= 25)
	{
		puts("Keep practicing, don't give up!");
	}
	else
	{
		puts("Better luck next time.");
	}
	
	standby();
	return 0;
}
Beispiel #23
0
int main(){
	scanf("%d", &N);
	S = 0, T = 2 * N + 1;
	for(int i = 1; i < N; ++i){
		int x, y;
		scanf("%d%d", &x, &y);
		treeEdge[x].push_back(y);
		treeEdge[y].push_back(x);
	}
	
	getMark();
	for(int i = N; i > 1; --i){
		addedge(i, fa[i], T);
	}
	std::vector<std::pair<int, std::pair<int, int> > > rems;
	for(int i = 1; i <= N; ++i){
		int x, y;
		scanf("%d%d", &x, &y);
		if(depth[x] > depth[y]) std::swap(x, y);
		if(x == 1 || mark[x] == mark[y]){
			preQ[y].push(std::make_pair(depth[x], i));
		}
		else{
			addedge(S, N + i, 1);
			addedge(N + i, x, 1);
			addedge(N + i, y, 1);
			rems.push_back(std::make_pair(i, std::make_pair(x, y)));
		}
	}
	
	memset(vis, 0, sizeof(vis));
	if(!getPreDecide(1) || preQ[1].size()){
		printf("No\n");
		return 0;
	}
	for(int i = 1; i <= N; ++i){
		if(!decided[i]){
			addedge(i, T, 1);
		}
	}
	
	maxflow = 0;
	while(modlabel()){
		maxflow += aug(S, T);
	}
	if(maxflow != N - preDecide){
		printf("No\n");
		return 0;
	}
	for(int i = 1; i <= N; ++i){
		for(edge *ii = V[N + i]; ii; ii = ii -> nxt){
			if(ii -> u == 0 && ii -> t > 0 && ii -> t <= N){
				toDecide[ii -> t].push_back(i);
			}
		}
	}
	
	memset(vis, 0, sizeof(vis));
	getAnswer(1);
	
	printf("Yes\n");
	for(int i = 1; i <= N; ++i){
		printf("%d%c", ans[i], i == N ? '\n' : ' ');
	}
	
	return 0;
}
Beispiel #24
0
static int setKeyboardFeatures(struct keyboardStruct * theKeyboardFeatures)
{
  ENTER("setKeyboardFeatures");
  int aKeyboardRequest=1;
  int aStickyKeyStage=1;
  struct keyboardStruct aOldKeyboardFeatures;

  if (!theKeyboardFeatures)
    {
      return 0;
    }

  memcpy(&aOldKeyboardFeatures, theKeyboardFeatures, sizeof(struct keyboardStruct));

  say( changeKeyboardFeatures);
  say( PleasePressKey);

  if (getAnswer() != MENU_Yes)
    {
      aKeyboardRequest=0;
    }

  while( aKeyboardRequest)
  {
    if (aStickyKeyStage)
      {

	if (theKeyboardFeatures->myStickyKeysAreAvailable)
	  {
	    say( stickyKey);
	  }
	else
	  {
	    say( noStickyKey);
	  }
	
	say( PleasePressKey);
	
	switch(getAnswer())
	  {
	  case MENU_Yes:
	    break;
	    
	  case MENU_No:
	    theKeyboardFeatures->myStickyKeysAreAvailable=(theKeyboardFeatures->myStickyKeysAreAvailable) ? 0:1;
	    break;
	    
	  case MENU_Previous:
	    aKeyboardRequest=0;
	    break;
	    
	  default:
	    break;
	  }
	aStickyKeyStage=0;
      }
    else
      {
	if (theKeyboardFeatures->myRepeatKeysAreAvailable)
	  {
	    say( repeatKey);
	  }
	else
	  {
	    say( noRepeatKey);
	  }
	
	say( PleasePressKey);
	
	aKeyboardRequest=0;
	switch(getAnswer())
	  {
	  case MENU_Yes:
	    break;
	    
	  case MENU_No:
	    theKeyboardFeatures->myRepeatKeysAreAvailable=(theKeyboardFeatures->myRepeatKeysAreAvailable) ? 0:1;
	    break;
	    
	  case MENU_Previous:
	    aKeyboardRequest=1;
	    aStickyKeyStage=1;
	    break;
	    
	  default:
	    break;
	  }
      }
  }
  return (0 != memcmp(&aOldKeyboardFeatures, theKeyboardFeatures, sizeof(struct keyboardStruct)));
}
Beispiel #25
0
static int setKeyboard( enum keyboard *theKeyboard, enum language theCurrentLanguage)
{
  ENTER("setKeyboard");
  int aKeyboardRequest=1;
  int i=0;
  enum keyboard aKeyboard;
  int aKeyboardIsChanged=0;
  int aMaxKeyboard=0;

  if (!theKeyboard)
    {
      return 0;
    }

  if (theCurrentLanguage == Russian)
    {
      aMaxKeyboard = (MaxCyrillicKeyboard - FirstCyrillicKeyboard);
      // atm, Russian language implies a cyrillic keyboard 
      if ((*theKeyboard < FirstCyrillicKeyboard) 
	  || (MaxCyrillicKeyboard >= *theKeyboard)) 
	{
	  *theKeyboard = russianKeyboard;
	  aKeyboardIsChanged=1;
	}
    }
  else
    {
      aMaxKeyboard = MaxKeyboard;
      // atm, if language is not Russian, then no cyrillic keyboard
      if ((FirstCyrillicKeyboard <= *theKeyboard) 
	  && (*theKeyboard < MaxCyrillicKeyboard)) 
	{
	  *theKeyboard = americanKeyboard;
	  aKeyboardIsChanged=1;
	}
    }

  aKeyboard = *theKeyboard;

  say( keyboardIs);
  say( aKeyboard);

  say( changeKeyboard);
  say( PleasePressKey);

  if (getAnswer() != MENU_Yes)
    {
      return aKeyboardIsChanged;
    }

  say( whichKeyboard);

  aMaxKeyboard = (theCurrentLanguage == Russian) ?
    (MaxCyrillicKeyboard - FirstCyrillicKeyboard) : MaxKeyboard;

  // The distinct keyboards are sorting in alphabetical order
  if (TheLanguageForSorting != theCurrentLanguage)
    {
      if (theCurrentLanguage == Russian)
	{
	  for (i=FirstCyrillicKeyboard;i<MaxCyrillicKeyboard;i++)
	    {
	      TheKeyboards[ i - FirstCyrillicKeyboard] = i;
	      SHOW3("i - FirstCyrillicKeyboard=%d, i=%d\n",i - FirstCyrillicKeyboard, i);
	    }       
	}
      else
	{
	  for (i=0;i<MaxKeyboard;i++)
	    {
	      TheKeyboards[i] = i;
	    }
	  aMaxKeyboard = i;
	  
	  qsort( TheKeyboards, MaxKeyboard, sizeof(enum keyboard), sortKeyboardMessages);
	}
      
      TheLanguageForSorting = theCurrentLanguage;
    }

  // Looking for the index which matches aKeyboard
  for (i=0; i<aMaxKeyboard; i++)
    {
      if (TheKeyboards[i] == aKeyboard)
	{
	  break;
	}
    }

  if (i >= aMaxKeyboard)
    {
      SHOW("Keyboard: Unexpected value");
      return 0;
    }

  while( aKeyboardRequest)
  {
    SHOW3("say TheKeyboards[%d]=%d\n",i, TheKeyboards[i]);
    say( TheKeyboards[i]); // works because the enum values are the same!

    switch(getAnswer())
      {
	case MENU_Yes:
	  aKeyboardRequest=0;
	  break;

	case MENU_Previous:
	  i = (i > 0) ? i-1 : aMaxKeyboard-1;
	  break;

	default:
	  i = (i >= aMaxKeyboard-1) ? 0 : i+1;
	  break;
      }
  }

  aKeyboardIsChanged = (TheKeyboards[i] != *theKeyboard);
  *theKeyboard = TheKeyboards[i];
  return aKeyboardIsChanged;
}
Beispiel #26
0
/* < setPersistentStorage */
int setQuitExpected()
{
  say( sayQuitExpected);
  say( PleasePressKey);
  return (getAnswer() == MENU_Yes);
}
int main(){
	int t,sum,ahead,mid,ahd,bk,n,i,j,k,gotA;
	int **boolArr,*aux,*a;
	scanf("%d\n\n",&t);
	while(t--){
		scanf("%d\n",&n);
		sum=0;
		a=malloc(n*sizeof(int));
		for(i=0;i<n;i++){
			scanf("%d\n",&a[i]);
			sum+=a[i];
		}
		boolArr=malloc(n*sizeof(int));
		aux=malloc((sum+1)*sizeof(int));
      	for (i=0; i<n; i++){
        	boolArr[i] = malloc((sum+1)*sizeof(boolArr[i]));
      	}
		aux[0]=1;
		for(i=0;i<n;i++){
			for(j=sum;j>=a[i];j--){
				if(aux[j-a[i]]==1){
					//printf("here %d %d\n",j,a[i]);
					boolArr[i][j]=1;
					aux[j]=1;
					for(k=0;k<i;k++){
						boolArr[k][j]=boolArr[k][j-a[i]];
					}
				}
			}
		}
		for(j=20;j<=30;j++)
			printf("%d ",j);
		printf("\n");
		for(i=0;i<n;i++){
			for(j=20;j<=30;j++){
				printf("%d ",boolArr[i][j]);
			}
			printf("\n");
		}
		mid=ceil((float)sum/2);
		printf("mid is %d\n",mid);
		ahead=1;
		ahd=0;
		bk=1;
		while(1){
			if(ahead){
				gotA = getAnswer(mid+ahd,n,boolArr);
				ahd++;
				ahead=0;
			}
			else{
				gotA = getAnswer(mid-bk,n,boolArr);
				bk++;
				ahead=1;
			}
			if(gotA){
				printf("Ye! Got the answer!\n");
				break;
			}
		}
	}
}
Beispiel #28
0
static int setMenuLanguage(enum language *theLanguage)
{
  ENTER("setMenuLanguage");
  static int aMenu[] = {
    MenuInEnglish, 
    MenuInFrench,
    MenuInGerman,
    MenuInSpanish,
    MenuInBrazilian,
    MenuInRussian,
  }; // Index= enum language
  int aLanguageRequest=1;
  int aLanguageMax=sizeof(aMenu)/sizeof(aMenu[0]);
  enum language aLanguage=English;
  int aMenuIsModified=0;
  
  if (!theLanguage)
    {
      return aMenuIsModified;
    }

  aLanguage = *theLanguage;

  setLanguage( aLanguage);
  say( aMenu[ aLanguage]);
  say( PleasePressKey);
  int aQuestion=1;
  
  // Is this language correct ?
  if(getAnswer() != MENU_No) 
    {
      aLanguageRequest=0;
    }
  else
    {
      aLanguage = (aLanguage >= aLanguageMax-1) ? 0 : aLanguage+1;
    }

  while(aLanguageRequest)
  {
    setLanguage( aLanguage);
    say( aMenu[ aLanguage]);
    if (aQuestion<aLanguageMax)
      {
	aQuestion++;
	say( PleasePressKey);
      }
    
    switch(getAnswer())
      {
	case MENU_Yes:
	  aLanguageRequest=0;
	  break;

	case MENU_Previous:
	  aLanguage = (aLanguage > 0) ? aLanguage-1 : aLanguageMax-1;
	  break;

	default:
	  aLanguage = (aLanguage >= aLanguageMax-1) ? 0 : aLanguage+1;
	  break;
      }
  }
  
  aMenuIsModified = (aLanguage != *theLanguage);
  *theLanguage = aLanguage;

  return aMenuIsModified;
}
/**
 * Get a copy of this OpenQuestion
 * @return a copy
 */
OpenQuestion* OpenQuestion::copy() {
	OpenQuestion *q = new OpenQuestion(question_);
	q->answer_ = getAnswer();
	return q;
}
Beispiel #30
0
void main() {


	int serv_sock;
	int cli_sock;
	int rval;
	int length;
	int control;
	int src_file;
	int r_size;
	
	char* buff;
	char f_name[DIM];
	char* answer;	
	int ans;
	pthread_t* tid;
	struct sockaddr_in server;
	struct sockaddr client;
	
	puts("Welcome to Such Chatz server!");
	

	answer=malloc(ANSWER_LENGTH);
	do{
		puts("Do you want to restore connected Users from log file?");
		fgets(answer, ANSWER_LENGTH, stdin);
		
		#ifdef DEBUG
		puts("Risposta presa in input:");
		puts(answer);
		#endif

	} while (ans = getAnswer(answer)==-1);
	answer[strlen(answer) -1] = '\0';

	
	//Inizializzo il semaforo per l'accesso all'hashmap

	hashmap_sem = semget(SEMAPHORE_KEY,SEMAPHORE_SIZE,IPC_CREAT|IPC_EXCL|0666);
	if(hashmap_sem==-1)
	{
		puts("Fallimento durante la creazione del semaforo");
		exit(-1);
	}

	//Creo l'hashmap

	hashmap=createHashmap();	
	
	//Compie l'azione corrispondente alla scelta del sistemista.

	if(ans==1)
	{
		restoreConnectedUsers(hashmap);
	}
	else
	{
		clearLog();	
	}

//open the server socket to accept connections
	if ((serv_sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) == -1){
		perror("Could not Open socket");
		exit(EXIT_FAILURE);
	}
	puts("We created the new socket");

//fills in the sockaddr struct 
	server.sin_family = AF_INET;
	server.sin_port = htons(SERVICE_PORT);
	server.sin_addr.s_addr = INADDR_ANY;

//binds the socket with the sockaddr_in struct previously filled
	if (bind(serv_sock, (struct sockaddr*)&server, sizeof(server)) == -1){
		perror("Could not Bind socket");
		exit(EXIT_FAILURE);
	}
	puts("The binding has been done");

//allows the process to listen for connections
	if(listen(serv_sock, 5) == -1){
		perror("Could not Listen on socket");
		exit(EXIT_FAILURE);
	}
	puts("The process is now listening");

/*
//asks the user for the list file name and opens it
	while(control != 1){
		puts("Please insert the name of the list file");
		fgets(f_name, DIM, stdin);
		int slen = strlen(f_name);
		f_name[slen-1] = '\0';
		if ((src_file = open(f_name, O_RDONLY)) == -1) {
			printf("Couldn not open file\n");
		}else
			control = 1;
	}
	
	length = sizeof(client);*/
	
//accept incoming connections

tid=(pthread_t*)malloc(MAX_PENDING_CONNECTIONS*sizeof(pthread_t));
int i=0;

while(1)
{
	
	while ((cli_sock = accept(serv_sock, &client, & length)) == -1);

	pthread_create(&(tid[i]),NULL,(void*)&clientConnection,(void *) &cli_sock);
	i++;
}	



//Wait user's login
	
	
	
	
	
	
}