Exemple #1
0
void Solver::main(const char *filename, const char* outfile){
    readFile(filename);
    findDroneAssignment();
    std::ofstream out(outfile);
    if (!out.good())
    {
        std::cerr << "Error opening the output file " << outfile << std::endl;
        std::cerr << "Displaying results in terminal!" << std::endl;
        displayResult(std::cout);
    }
    else
        displayResult(out);
    out.close();
}
Exemple #2
0
bool NormalizeData::execute(PlugInArgList* pInArgList, PlugInArgList* pOutArgList)
{
   if (pInArgList == NULL || pOutArgList == NULL)
   {
      return false;
   }
   if (!extractInputArgs(pInArgList))
   {
      return false;
   }

   mProgress.report("Begin normalization conversion.", 1, NORMAL);

   { // scope the lifetime
      RasterElement *pResult = static_cast<RasterElement*>(
         Service<ModelServices>()->getElement(mResultName, TypeConverter::toString<RasterElement>(), NULL));
      if (pResult != NULL)
      {
         Service<ModelServices>()->destroyElement(pResult);
      }
   }
   ModelResource<RasterElement> pResult(RasterUtilities::createRasterElement(mResultName,
      mInput.mpDescriptor->getRowCount(), mInput.mpDescriptor->getColumnCount(), mInput.mpDescriptor->getBandCount(),
      FLT8BYTES, mInput.mpDescriptor->getInterleaveFormat(), mInput.mpDescriptor->getProcessingLocation() == IN_MEMORY));
   mInput.mpResult = pResult.get();
   if (mInput.mpResult == NULL)
   {
      mProgress.report("Unable to create result data set.", 0, ERRORS, true);
      return false;
   }
   mInput.mpResultDescriptor = static_cast<const RasterDataDescriptor*>(mInput.mpResult->getDataDescriptor());
   mInput.mpAbortFlag = &mAbortFlag;
   NormalizeDataThreadOutput outputData;
   mta::ProgressObjectReporter reporter("Normalizing", mProgress.getCurrentProgress());
   mta::MultiThreadedAlgorithm<NormalizeDataThreadInput, NormalizeDataThreadOutput, NormalizeDataThread>     
          alg(Service<ConfigurationSettings>()->getSettingThreadCount(), mInput, outputData, &reporter);
   switch(alg.run())
   {
   case mta::SUCCESS:
      if (!mAbortFlag)
      {
         mProgress.report("Normalization complete.", 100, NORMAL);
         if (!displayResult())
         {
            return false;
         }
         pResult.release();
         mProgress.upALevel();
         return true;
      }
      // fall through
   case mta::ABORT:
      mProgress.report("Normalization aborted.", 0, ABORT, true);
      return false;
   case mta::FAILURE:
      mProgress.report("Normalization failed.", 0, ERRORS, true);
      return false;
   }
   return true; // make the compiler happy
}
int main(void){
	
	int numDays;
	int i;
	float sum = 0;
	float dailyHigh;
	float dailyLow;
	char conditions;
	float dailyAvg = 0;

	printf("\nWeather Analyzer 2.0\n");
	printf("=====================\n");

	printf("\nHow many days of data? \n");

	numDays = getInteger (1, 14);

	for(i = 0; i < numDays; i++) { 

		getDailyData (&dailyHigh, &dailyLow, &conditions);
		dailyAvg = average (dailyHigh, dailyLow);
		printf("Today's average temperature is: %.2f\n", dailyAvg);
		sum += dailyAvg;
		draw(symbolToDraw(conditions, dailyAvg), 20);

	}

	displayResult (numDays, (sum/numDays));

	return 0;

}
Exemple #4
0
int main(){
	char allStar = '\0', regularMVP = '\0', worldMVP = '\0', goldGlove = '\0', silverSlug = '\0',
		homeRun = '\0', battingAve = '\0', gender = '\0';
	int bonus = 0, num1 = 0, num2 = 0, num3 = 0, num4 = 0, num5 = 0, 
		 activityLevel = 0, menuChoice = 0, i = 0;
	double weight = 0, height = 0, age = 0, bmr = 0, calories = 0, result = 0;
	FILE *inputFile = NULL;

	
	//PROBLEM 1
	inputFile = openInputFile();
	/*
	gender = readCharacter(inputFile);
	age = readNumber(inputFile);
	weight = readNumber(inputFile);
	height = readNumber(inputFile);

	bmr = computeBMR(gender, weight, height, age);
	activityLevel = determineActivityLevel();
	calories = computeCalories(bmr, activityLevel);
	printf("Calories needed per day are: %.0lf\n", calories);

	//PROBLEM 2
	allStar = getBaseballAchievements("All-Star Game appearance");
	bonus += determineBonus(allStar, 25000);
	regularMVP = getBaseballAchievements("Regular Season MVP");
	bonus += determineBonus(regularMVP, 75000);
	worldMVP = getBaseballAchievements("World Series MVP");
	bonus += determineBonus(worldMVP, 100000);
	goldGlove = getBaseballAchievements("Gold Glove award");
	bonus += determineBonus(goldGlove, 50000);
	silverSlug = getBaseballAchievements("Silver Slugger award");
	bonus += determineBonus(silverSlug, 35000);
	homeRun = getBaseballAchievements("Home run champ");
	bonus += determineBonus(homeRun, 25000);
	battingAve = getBaseballAchievements("Batting average champ");
	bonus += determineBonus(battingAve, 25000);

	printf("Total player bonus is %d\n", bonus);
		int i = 0;*/
	//PROBLEM 3
	num1 = readInteger(inputFile);
	num2 = readInteger(inputFile);
	num3 = readInteger(inputFile);
	num4 = readInteger(inputFile);
	num5 = readInteger(inputFile);

	
	while (i < 3){
		menuChoice = displayMenu();
		result = calculateResult(menuChoice, num1, num2, num3, num4, num5);
		displayResult(menuChoice, result);
		i++;
	}
	
	return 0;
}
Exemple #5
0
/**
 *  Main function.
 */
int main(int argc, char *argv[])
{
   char *fileName;
   const char fileMode[] = "r+";
   unsigned int baud;
   int fd;

   fileName = getDeviceFileName(argc, argv);
   fd = openDeviceFile(fileName, fileMode);
   baud = getBaudRate(argc, argv);
   setAttr(fd, baud);
   displayResult(fd);
   sendCommand(fd, "?");
   displayResult(fd);
   sound(fd*10);
   printf("\n");
   nosound();
   close(fd);
   return EXIT_SUCCESS;
}
void main (void)
{
double radius, area;
char continu;

clrscr();
radius = getRadius ();
area = circArea(radius);
clrscr();
displayResult (radius, area);
getch ();
}
Exemple #7
0
Fichier : 2947.c Projet : saki45/OJ
int main(){
	char buf1[60], buf2[60], ch1, ch2;
	int N, N1, N2, p1, p2, isSame;
	scanf("%d", &N);

	while(N > 0){
		scanf("%d\n", &N1);
		fgets(buf1, sizeof(buf1), stdin);
		scanf("%d\n", &N2);
		fgets(buf2, sizeof(buf2), stdin);

		if(N1 != N2){
			displayResult(0);
		}
		else{
			p1 = 0;
			p2 = 0;
			ch1 = buf1[p1];
			ch2 = buf2[p2];
			isSame = 1;

			if(ch1 != ch2)
				displayResult(0);
			else{
				N1--;
				while(N1 > 0){
					ch1 = findNext(buf1, &p1);
					ch2 = findNext(buf2, &p2);
					if(ch1 != ch2){
						isSame = 0;
						break;
					}
					N1 --;
				}
				displayResult(isSame);
			}
		}
		N--;
	}
}
Exemple #8
0
void FullRun::perform() {
    Run::perform(); // process common data

    verifyData();
    setup();
    loadPTable(pTableFile);


    Interface::instance() << Interface::SEPARATOR << endl;
    Interface::instance().showLog(true);

    progress();

    Interface::instance() << Interface::SEPARATOR << endl;
    Interface::instance().showLog(true);

    if (!cloAllBpCalculated && !cloNoBpCalculated && !cloNo3sRecFile) {
        /* We calculate breakpoints for the best triplets */
        for (unsigned long i = 0; i < childDataset->getSize(); i++) {
            Genome* child = childDataset->getGenome(i);
            Triplet* bestRecTriplet = child->getBestRecombinantTriplet();
            if (bestRecTriplet != NULL) {
                recordRecombinantTriplet(bestRecTriplet);
            }
        }
    }


    if (isRandomMode && randomLoopNum > 1) {
        Interface::instance() << "Recombination sensitivity: "
                << recombinationSensitivity << "/" << randomLoopNum << "\n";
        Interface::instance().showOutput(true);
        
    } else {
        displayResult();
        Interface::instance() << Interface::SEPARATOR << endl;
        Interface::instance().showLog(true);
        savePValHistogram();
    }


    /* Close all files */
    if (fileSkippedTriplets)
        fileSkippedTriplets->close();
    if (fileRecombinants)
        fileRecombinants->close();
    if (fileLongRecombinants != NULL)
        fileLongRecombinants->close();
}
Exemple #9
0
bool AoiLogical::execute(PlugInArgList* pInArgList, PlugInArgList* pOutArgList)
{
    if (pInArgList == NULL || pOutArgList == NULL)
    {
        return false;
    }
    if (!extractInputArgs(pInArgList))
    {
        return false;
    }

    mProgress.report("Begin AOI set operation.", 1, NORMAL);

    if (isBatch())
    {
        mProgress.report("Batch mode is not supported.", 0, ERRORS, true);
        return false;
    }

    FactoryResource<BitMask> pResultMask;
    if (pResultMask.get() == NULL)
    {
        mProgress.report("Unable to create result AOI.", 0, ERRORS, true);
        return false;
    }
    mpResult = pResultMask.get();

    if (mOperation == "Union")
    {
        mpResult->merge(*mpSet1);
        mpResult->merge(*mpSet2);
    }
    else if (mOperation == "Intersection")
    {
        mpResult->merge(*mpSet1);
        mpResult->intersect(*mpSet2);
    }
    else
    {
        mProgress.report("Invalid operation: " + mOperation, 0, ERRORS, true);
        return false;
    }
    if (!displayResult())
    {
        return false;
    }
    mProgress.upALevel();
    return true;
}
Exemple #10
0
int CronSqlDriver::execQuery(QString userQuery){
    QSqlQuery dbQuery;

    if( dbhandle.isOpen()){
        dbQuery.prepare (userQuery);
        if( !dbQuery.exec() ){
            qDebug()<< dbQuery.lastError ()<<endl;
        }
      displayResult(dbQuery);

    }
    else{
        qDebug()<< dbQuery.lastError ();
    }

    return 0;
}
Exemple #11
0
// Display the result from SSCE_CheckBlock or SSCE_CheckWord.
static void displayCheckResult(HWND win, const char *funcName,
  SSCE_S16 result) {
	if (result <= 0) {
		displayResult(win, funcName, result);
	}
	else {
		int i;
		char msg[256];

		wsprintf(msg, "%s returned:", funcName);
		appendMsg(win, msg);
		for (i = 0; i < sizeof(checkResults) / sizeof(checkResults[0]); ++i) {
			if ((checkResults[i].mask & result) != 0) {
				appendMsg(win, checkResults[i].name);
			}
		}
	}
}
bool ConvolutionFilterShell::execute(PlugInArgList* pInArgList, PlugInArgList* pOutArgList)
{
   if (pInArgList == NULL || pOutArgList == NULL)
   {
      return false;
   }
   if (!extractInputArgs(pInArgList))
   {
      return false;
   }
   if (!populateKernel() || mInput.mKernel.Nrows() % 2 == 0 || mInput.mKernel.Ncols() % 2 == 0)
   {
      mProgress.report("Invalid kernel.", 0, ERRORS, true);
      return false;
   }
   BitMaskIterator iterChecker((mpAoi == NULL) ? NULL : mpAoi->getSelectedPoints(), 0, 0,
      mInput.mpDescriptor->getColumnCount() - 1, mInput.mpDescriptor->getRowCount() - 1);
   EncodingType resultType = mInput.mForceFloat ? EncodingType(FLT8BYTES) : mInput.mpDescriptor->getDataType();
   if (resultType == INT4SCOMPLEX)
   {
      resultType = INT4SBYTES;
   }
   else if (resultType == FLT8COMPLEX)
   {
      resultType = FLT8BYTES;
   }
   if (!isBatch())
   {
      RasterElement* pResult = static_cast<RasterElement*>(
         Service<ModelServices>()->getElement(mResultName, TypeConverter::toString<RasterElement>(), NULL));
      if (pResult != NULL)
      {
         if (QMessageBox::question(Service<DesktopServices>()->getMainWidget(), "Result data set exists",
            "The result data set already exists. Would you like to replace it?",
            QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes) == QMessageBox::No)
         {
            return false;
         }
         Service<ModelServices>()->destroyElement(pResult);
      }
   }
   mProgress.report("Begin convolution matrix execution.", 0, NORMAL);

   ModelResource<RasterElement> pResult(RasterUtilities::createRasterElement(
      mResultName, iterChecker.getNumSelectedRows(), iterChecker.getNumSelectedColumns(),
      mInput.mBands.size(), resultType, mInput.mpDescriptor->getInterleaveFormat(),
      mInput.mpDescriptor->getProcessingLocation() == IN_MEMORY));
   pResult->copyClassification(mInput.mpRaster);
   pResult->getMetadata()->merge(mInput.mpDescriptor->getMetadata()); //copy original metadata
   //chip metadata by bands
   vector<DimensionDescriptor> orgBands = mInput.mpDescriptor->getBands();
   vector<DimensionDescriptor> newBands;
   newBands.reserve(mInput.mBands.size());
   for (unsigned int index = 0; index < mInput.mBands.size(); ++index)
   {
      unsigned int selectedBand = mInput.mBands[index];
      if (selectedBand < orgBands.size())
      {
         newBands.push_back(orgBands[selectedBand]);
      }
   }
   RasterUtilities::chipMetadata(pResult->getMetadata(), mInput.mpDescriptor->getRows(),
      mInput.mpDescriptor->getColumns(), newBands);
   mInput.mpResult = pResult.get();
   if (mInput.mpResult == NULL)
   {
      mProgress.report("Unable to create result data set.", 0, ERRORS, true);
      return false;
   }
   mInput.mpAbortFlag = &mAborted;
   mInput.mpIterCheck = &iterChecker;
   ConvolutionFilterThreadOutput outputData;
   mta::ProgressObjectReporter reporter("Convolving", mProgress.getCurrentProgress());
   mta::MultiThreadedAlgorithm<ConvolutionFilterThreadInput,
                               ConvolutionFilterThreadOutput,
                               ConvolutionFilterThread>
          alg(mta::getNumRequiredThreads(iterChecker.getNumSelectedRows()), mInput, outputData, &reporter);
   switch(alg.run())
   {
   case mta::SUCCESS:
      if (!isAborted())
      {
         mProgress.report("Convolution filter complete.", 100, NORMAL);
         SpatialDataView* pView = displayResult();
         if (Service<ApplicationServices>()->isInteractive() && pView == NULL)
         {
            return false;
         }
         pOutArgList->setPlugInArgValue("View", pView);

         pResult.release();
         mProgress.upALevel();
         return true;
      }
      // fall through
   case mta::ABORT:
      mProgress.report("Convolution filter aborted.", 0, ABORT, true);
      return false;
   case mta::FAILURE:
      mProgress.report("Convolution filter failed.", 0, ERRORS, true);
      return false;
   default:
      VERIFY(false); // can't happen
   }
}
static void tcp_server_thread_main(wiced_thread_arg_t arg)
{
    wiced_bool_t wwepSecurity = (wiced_bool_t)arg;

    wiced_result_t result;
    wiced_tcp_stream_t stream;                      // The TCP stream
    wiced_tcp_socket_t socket;
    platform_dct_security_t *dct_security;
    wiced_tls_identity_t tls_identity;
    wiced_tls_context_t tls_context;
    uint8_t rbuffer[MAX_LEGAL_MSG];

    char returnMessage[128]; // better use less than 128 bytes
    // setup the server by creating the socket and hooking it to the correct TCP Port
    result = wiced_tcp_create_socket(&socket, INTERFACE);
    if(WICED_SUCCESS != result)
    {
        WPRINT_APP_INFO(("Create socket failed\n"));
        return; // this is a bad outcome
    }

    if(wwepSecurity == WICED_TRUE)
    {
        WPRINT_APP_INFO(("Starting secure\n"));

    }
    else
    {
        WPRINT_APP_INFO(("Starting non-secure\n"));
    }

    result = wiced_tcp_listen( &socket, (wwepSecurity == WICED_TRUE)?TCP_SERVER_SECURE_LISTEN_PORT:TCP_SERVER_NONSECURE_LISTEN_PORT );
    if(WICED_SUCCESS != result)
    {
        WPRINT_APP_INFO(("Listen socket failed\n"));
        return;
    }

    if(wwepSecurity == WICED_TRUE)
    {
        /* Lock the DCT to allow us to access the certificate and key */
        WPRINT_APP_INFO(( "Read the certificate Key from DCT\n" ));
        result = wiced_dct_read_lock( (void**) &dct_security, WICED_FALSE, DCT_SECURITY_SECTION, 0, sizeof( *dct_security ) );
        if ( result != WICED_SUCCESS )
        {
            WPRINT_APP_INFO(("Unable to lock DCT to read certificate\n"));
            return;
        }

        /* Setup TLS identity */
        result = wiced_tls_init_identity( &tls_identity, dct_security->private_key, strlen( dct_security->private_key ), (uint8_t*) dct_security->certificate, strlen( dct_security->certificate ) );
        if ( result != WICED_SUCCESS )
        {
            WPRINT_APP_INFO(( "Unable to initialize TLS identity. Error = [%d]\n", result ));
            return;
        }

    }
    else
    {
        wiced_tcp_stream_init(&stream,&socket);
        if(WICED_SUCCESS != result)
        {
            WPRINT_APP_INFO(("Init stream failed\n"));
            return; // this is a bad outcome
        }
    }

    while (1 )
    {
        if(wwepSecurity == WICED_TRUE)
        {
            result = wiced_tls_init_context( &tls_context, &tls_identity, NULL );
            if(result != WICED_SUCCESS)
            {
                WPRINT_APP_INFO(("Init context failed %d",result));
                return;
            }

            result = wiced_tcp_enable_tls(&socket,&tls_context);

            if(result != WICED_SUCCESS)
            {
                WPRINT_APP_INFO(("Enabling TLS failed %d",result));
                return;
            }

            wiced_tcp_stream_init(&stream,&socket);
            if(WICED_SUCCESS != result)
            {
                WPRINT_APP_INFO(("Init stream failed\n"));
                return; // this is a bad outcome
            }
        }

        result = wiced_tcp_accept( &socket ); // this halts the thread until there is a connection

        if(result != WICED_SUCCESS) // this occurs if the accept times out
            continue;

        if(wwepSecurity == WICED_TRUE)
            secureConnectionCount += 1;
        else
            nonsecureConnectionCount += 1;

        /// Figure out which client is talking to us... and on which port
        wiced_ip_address_t peerAddress;
        uint16_t	peerPort;
        wiced_tcp_server_peer(&socket,&peerAddress,&peerPort);

        uint32_t dataReadCount;
        wiced_tcp_stream_read_with_count(&stream,&rbuffer,MAX_LEGAL_MSG,100,&dataReadCount); // timeout in 100 ms
        processClientCommand(rbuffer, dataReadCount ,returnMessage);

        displayResult(peerAddress,peerPort,returnMessage);


        // send response and close things up
        wiced_tcp_stream_write(&stream,returnMessage,strlen(returnMessage));
        wiced_tcp_stream_flush(&stream);
        wiced_tcp_disconnect(&socket); // disconnect the connection

        if(wwepSecurity == WICED_TRUE)
        {
            wiced_tls_deinit_context(&tls_context);
        }

        wiced_tcp_stream_deinit(&stream); // clear the stream if any crap left
        wiced_tcp_stream_init(&stream,&socket); // setup for next connection

    }
}
Exemple #14
0
void displayResult(Solution solution){
	displayResult(displ,map_image,solution);
}
Exemple #15
0
// Respond to an Invoke button press
static void onInvokeBtn(HWND win) {
	int idx = ListBox_GetCurSel(GetDlgItem(win, IDC_FUNCTION_LST));
	int id;
	int i;
	char str[256];
	char path[MAX_PATH];
	SSCE_S16 s16, s16_1, s16_2, s16_3;
	SSCE_S32 s32, s32_1, s32_2, s32_3, s32_4;
	SSCE_CHAR word[SSCE_MAX_WORD_SZ];
	SSCE_CHAR otherWord[SSCE_MAX_WORD_SZ];
	SSCE_CHAR *bfr;
	SSCE_CHAR *p;
	const char *fmt, *lang;
	SSCE_S16 scores[16];

	if (LB_ERR == idx) {
		return;
	}

	id = (int)ListBox_GetItemData(GetDlgItem(win, IDC_FUNCTION_LST), idx);

	// Invoke the selected function.
	switch (id) {
	case AddToLex:
		GetDlgItemText(win, IDC_PARAM1_EDT, word, sizeof(word));
		GetDlgItemText(win, IDC_PARAM3_EDT, otherWord, sizeof(otherWord));
		s16 = SSCE_AddToLex(getS16(win, IDC_SESSION_ID_EDT),
		  getS16(win, IDC_LEXICON_ID_EDT), word,
		  getS16(win, IDC_PARAM2_EDT), otherWord);
		displayResult(win, "SSCE_AddToLex", s16);
		break;
	case CheckBlock:
		s16 = SSCE_CheckBlock(getS16(win, IDC_SESSION_ID_EDT),
		  getS16(win, IDC_BLOCK_ID_EDT), word, sizeof(word),
		  otherWord, sizeof(otherWord));
		displayCheckResult(win, "SSCE_CheckBlock", s16);
		if (s16 >= 0) {
			wsprintf(str, "errWord: %s; otherWord: %s", word, otherWord);
		}
		appendMsg(win, str);
		break;
	case CheckBlockDlg:
		s32_1 = getS32(win, IDC_PARAM1_EDT);
		bfr = (SSCE_CHAR *)malloc((size_t)s32_1);
		GetDlgItemText(win, IDC_TEXT_EDT, bfr, (int)s32_1);
		s32 = SSCE_CheckBlockDlg(win, bfr, strlen(bfr), s32_1,
		  getS16(win, IDC_PARAM2_EDT));
		wsprintf(str, "SSCE_CheckBlockDlg returned %ld", s32);
		appendMsg(win, str);
		if (s32 >= 0) {
			SetDlgItemText(win, IDC_TEXT_EDT, bfr);
		}
		free(bfr);
		break;
	case CheckCtrlDlg:
		s16 = SSCE_CheckCtrlDlg(win, GetDlgItem(win, IDC_TEXT_EDT),
		  getS16(win, IDC_PARAM1_EDT));
		displayResult(win, "SSCE_CheckCtrlDlg", s16);
		break;
	case CheckWord:
		GetDlgItemText(win, IDC_PARAM1_EDT, word, sizeof(word));
		s16 = SSCE_CheckWord(getS16(win, IDC_SESSION_ID_EDT),
		  word, otherWord, sizeof(otherWord));
		displayCheckResult(win, "SSCE_CheckWord", s16);
		if (s16 >= 0) {
			wsprintf(str, "otherWord: %s", otherWord);
		}
		appendMsg(win, str);
		break;
	case ClearLex:
		s16 = SSCE_ClearLex(getS16(win, IDC_SESSION_ID_EDT),
		  getS16(win, IDC_LEXICON_ID_EDT));
		displayResult(win, "SSCE_ClearLex", s16);
		break;
	case CloseBlock:
		s16 = SSCE_CloseBlock(getS16(win, IDC_SESSION_ID_EDT),
		  getS16(win, IDC_BLOCK_ID_EDT));
		displayResult(win, "SSCE_CloseBlock", s16);
		break;
	case CloseLex:
		s16 = SSCE_CloseLex(getS16(win, IDC_SESSION_ID_EDT),
		  getS16(win, IDC_LEXICON_ID_EDT));
		displayResult(win, "SSCE_CloseLex", s16);
		break;
	case CloseSession:
		s16 = SSCE_CloseSession(getS16(win, IDC_SESSION_ID_EDT));
		displayResult(win, "SSCE_CloseSession", s16);
		break;
	case CreateLex:
		GetDlgItemText(win, IDC_PARAM1_EDT, path, sizeof(path));
		s16 = SSCE_CreateLex(getS16(win, IDC_SESSION_ID_EDT),
		  path, getS16(win, IDC_PARAM2_EDT));
		if (s16 >= 0) {
			wsprintf(str, "%hd", s16);
			SetDlgItemText(win, IDC_LEXICON_ID_EDT, str);
		}
		wsprintf(str, "SSCE_CreateLex(%s) returned %hd", path, s16);
		appendMsg(win, str);
		break;
	case DelBlockText:
		s16 = SSCE_DelBlockText(getS16(win, IDC_SESSION_ID_EDT),
		  getS16(win, IDC_BLOCK_ID_EDT), getS32(win, IDC_PARAM1_EDT));
		displayResult(win, "SSCE_DelBlockText", s16);
		break;
	case DelBlockWord:
		s32 = SSCE_DelBlockWord(getS16(win, IDC_SESSION_ID_EDT),
		  getS16(win, IDC_BLOCK_ID_EDT), word, sizeof(word));
		wsprintf(str, "SSCE_DelBlockWord returned %ld; deleted text = %s",
		  s32, word);
		appendMsg(win, str);
		break;
	case DelFromLex:
		GetDlgItemText(win, IDC_PARAM1_EDT, word, sizeof(word));
		s16 = SSCE_DelFromLex(getS16(win, IDC_SESSION_ID_EDT),
		  getS16(win, IDC_LEXICON_ID_EDT), word);
		displayResult(win, "SSCE_DelFromLex", s16);
		break;
	case EditLexDlg:
		s16 = SSCE_EditLexDlg(win);
		displayResult(win, "SSCE_EditLexDlg", s16);
		break;
	case FindLexWord:
		GetDlgItemText(win, IDC_PARAM1_EDT, word, sizeof(word));
		s16 = SSCE_FindLexWord(getS16(win, IDC_SESSION_ID_EDT),
		  getS16(win, IDC_LEXICON_ID_EDT), word, otherWord, sizeof(otherWord));
		if (s16 < 0) {
			displayResult(win, "SSCE_FindLexWord", s16);
		}
		else {
			int i;
			const char *actionName = "(unknown)";

			for (i = 0; i < sizeof(actions) / sizeof(actions[0]); ++i) {
				if (actions[i].action == s16) {
					actionName = actions[i].name;
					break;
				}
			}
			wsprintf(str, "SSCE_FindLexWord returned %s", actionName);
			appendMsg(win, str);
			if (otherWord[0] != '\0') {
				wsprintf(str, "otherWord: %s", otherWord);
				appendMsg(win, str);
			}
		}
		break;
	case GetAutoCorrect:
		s16 = SSCE_GetAutoCorrect();
		displayResult(win, "SSCE_GetAutoCorrect", s16);
		break;
	case GetBlock:
		s16 = SSCE_GetBlockInfo(getS16(win, IDC_SESSION_ID_EDT),
		  getS16(win, IDC_BLOCK_ID_EDT), &s32_1, NULL, NULL, NULL);
		if (s16 < 0) {
			displayResult(win, "SSCE_GetBlockInfo", s16);
			break;
		}
		bfr = (SSCE_CHAR *)malloc((size_t)s32_1 + 1);
		if (NULL == bfr) {
			appendMsg(win, "Out of memory");
			break;
		}
		s16 = (SSCE_S16)SSCE_GetBlock(getS16(win, IDC_SESSION_ID_EDT),
		  getS16(win, IDC_BLOCK_ID_EDT), bfr, s32_1 + 1);
		bfr[s32_1] = '\0';
		displayResult(win, "SSCE_GetBlock", s16);
		appendMsg(win, "Block contents:");
		appendMsg(win, bfr);
		free(bfr);
		break;
	case GetBlockInfo:
		s16 = SSCE_GetBlockInfo(getS16(win, IDC_SESSION_ID_EDT),
		  getS16(win, IDC_BLOCK_ID_EDT), &s32_1, &s32_2, &s32_3, &s32_4);
		displayResult(win, "SSCE_GetBlockInfo", s16);
		wsprintf(str,
		  "textLen = %ld; blkSz = %ld; curPos = %ld; wordCount = %ld",
		  s32_1, s32_2, s32_3, s32_4);
		appendMsg(win, str);
		break;
	case GetBlockWord:
		s16 = SSCE_GetBlockWord(getS16(win, IDC_SESSION_ID_EDT),
		  getS16(win, IDC_BLOCK_ID_EDT), word, sizeof(word));
		displayResult(win, "SSCE_GetBlockWord", s16);
		wsprintf(str, "word: %s", word);
		appendMsg(win, str);
		break;
	case GetHelpFile:
		SSCE_GetHelpFile(path, sizeof(path));
		wsprintf(str, "help file: %s", path);
		appendMsg(win, str);
		break;
	case GetLex:
		s16 = SSCE_GetLexInfo(getS16(win, IDC_SESSION_ID_EDT),
		  getS16(win, IDC_LEXICON_ID_EDT), &s32_1, NULL, NULL);
		if (s16 < 0) {
			displayResult(win, "SSCE_GetLexInfo", s16);
			break;
		}
		bfr = (SSCE_CHAR *)malloc((size_t)s32_1);
		if (NULL == bfr) {
			appendMsg(win, "Out of memory");
			break;
		}
		s32 = SSCE_GetLex(getS16(win, IDC_SESSION_ID_EDT),
		  getS16(win, IDC_LEXICON_ID_EDT), bfr, s32_1);
		wsprintf(str, "SSCE_GetLex returned %ld", s32);
		appendMsg(win, str);
		for (p = bfr; *p != '\0'; p += strlen(p) + 1) {
			appendMsg(win, p);
		}
		free(bfr);
		break;
	case GetLexId:
		GetDlgItemText(win, IDC_PARAM1_EDT, path, sizeof(path));
		s16 = SSCE_GetLexId(path);
		displayResult(win, "SSCE_GetLexId", s16);
		break;
	case GetLexInfo:
		s16 = SSCE_GetLexInfo(getS16(win, IDC_SESSION_ID_EDT),
		  getS16(win, IDC_LEXICON_ID_EDT), &s32_1, &s16_2, &s16_3);
		displayResult(win, "SSCE_GetLexInfo", s16);
		fmt = "(unknown)";
		for (i = 0; i < sizeof(lexFormats) / sizeof(lexFormats[0]); ++i) {
			if (lexFormats[i].format == s16_2) {
				fmt = lexFormats[i].name;
				break;
			}
		}
		lang = "(unknown)";
		for (i = 0; i < sizeof(languages) / sizeof(languages[0]); ++i) {
			if (languages[i].lang == s16_3) {
				lang = languages[i].name;
				break;
			}
		}
		wsprintf(str, "size = %ld; format = %s; language = %s", s32_1,
		  fmt, lang);
		appendMsg(win, str);
		break;
	case GetMainLexFiles:
		SSCE_GetMainLexFiles(path, sizeof(path));
		wsprintf(str, "MainLexFiles: %s", path);
		appendMsg(win, str);
		break;
	case GetMainLexPath:
		SSCE_GetMainLexPath(path, sizeof(path));
		wsprintf(str, "MainLexPath: %s", path);
		appendMsg(win, str);
		break;
	case GetMinSuggestDepth:
		s16 = SSCE_GetMinSuggestDepth();
		displayResult(win, "SSCE_GetMinSuggestDepth", s16);
		break;
	case GetOption:
		s32 = (SSCE_S32)SSCE_GetOption(getS16(win, IDC_SESSION_ID_EDT),
		  (SSCE_U32)getS32(win, IDC_PARAM1_EDT));
		if (s32 < 0) {
			displayResult(win, "SSCE_GetOption", (SSCE_S16)s32);
		}
		else {
			wsprintf(str, "SSCE_GetOption returned %ld", s32);
			appendMsg(win, str);
		}
		break;
	case GetRegTreeName:
		SSCE_GetRegTreeName(path, sizeof(path));
		wsprintf(str, "RegTreeName: %s", path);
		appendMsg(win, str);
		break;
	case GetSid:
		s16 = SSCE_GetSid();
		displayResult(win, "SSCE_GetSid", s16);
		if (s16 >= 0) {
			wsprintf(str, "%hd", s16);
			SetDlgItemText(win, IDC_SESSION_ID_EDT, str);
		}
		break;
	case GetStatistics:
		SSCE_GetStatistics((SSCE_U32 *)&s32_1, (SSCE_U32 *)&s32_2,
		  (SSCE_U32 *)&s32_3);
		wsprintf(str,
		  "wordsChecked = %lu; wordsChanged = %lu; errorsDetected = %lu",
		  s32_1, s32_2, s32_3);
		appendMsg(win, str);
		break;
	case GetStringTableName:
		SSCE_GetStringTableName(path, sizeof(path));
		wsprintf(str, "StringTableName: %s", path);
		appendMsg(win, str);
		break;
	case GetUserLexFiles:
		SSCE_GetUserLexFiles(path, sizeof(path));
		wsprintf(str, "UserLexFiles: %s", path);
		appendMsg(win, str);
		break;
	case GetUserLexPath:
		SSCE_GetUserLexPath(path, sizeof(path));
		wsprintf(str, "UserLexPath: %s", path);
		appendMsg(win, str);
		break;
	case InsertBlockText:
		GetDlgItemText(win, IDC_PARAM1_EDT, word, sizeof(word));
		s16 = SSCE_InsertBlockText(getS16(win, IDC_SESSION_ID_EDT),
		  getS16(win, IDC_BLOCK_ID_EDT), word);
		displayResult(win, "SSCE_InsertBlockText", s16);
		break;
	case NextBlockWord:
		s16 = SSCE_NextBlockWord(getS16(win, IDC_SESSION_ID_EDT),
		  getS16(win, IDC_BLOCK_ID_EDT));
		displayResult(win, "SSCE_NextBlockWord", s16);
		break;
	case OpenBlock:
		s32_1 = getS32(win, IDC_PARAM1_EDT);
		bfr = (SSCE_CHAR *)malloc((size_t)s32_1);
		if (NULL == bfr) {
			appendMsg(win, "Out of memory");
			break;
		}
		GetDlgItemText(win, IDC_TEXT_EDT, bfr, (int)s32_1);
		s16 = SSCE_OpenBlock(getS16(win, IDC_SESSION_ID_EDT),
		  bfr, strlen(bfr), s32_1, TRUE);
		if (s16 >= 0) {
			wsprintf(str, "%hd", s16);
			SetDlgItemText(win, IDC_BLOCK_ID_EDT, str);
		}
		displayResult(win, "SSCE_OpenBlock", s16);
		free(bfr);
		break;
	case OpenLex:
		GetDlgItemText(win, IDC_PARAM1_EDT, path, sizeof(path));
		s16 = SSCE_OpenLex(getS16(win, IDC_SESSION_ID_EDT),
		  path, getS32(win, IDC_PARAM2_EDT));
		if (s16 >= 0) {
			wsprintf(str, "%hd", s16);
			SetDlgItemText(win, IDC_LEXICON_ID_EDT, str);
		}
		wsprintf(str, "SSCE_OpenLex(%s) returned %hd", path, s16);
		appendMsg(win, str);
		break;
	case OpenSession:
		s16 = SSCE_OpenSession();
		if (s16 >= 0) {
			wsprintf(str, "%hd", s16);
			SetDlgItemText(win, IDC_SESSION_ID_EDT, str);
		}
		displayResult(win, "SSCE_OpenSession", s16);
		break;
	case OptionsDlg:
		s16 = SSCE_OptionsDlg(win);
		displayResult(win, "SSCE_OptionsDlg", s16);
		break;
	case ReplaceBlockWord:
		GetDlgItemText(win, IDC_PARAM1_EDT, word, sizeof(word));
		s16 = SSCE_ReplaceBlockWord(getS16(win, IDC_SESSION_ID_EDT),
		  getS16(win, IDC_BLOCK_ID_EDT), word);
		displayResult(win, "SSCE_ReplaceBlockWord", s16);
		break;
	case ResetLex:
		s16 = SSCE_ResetLex();
		displayResult(win, "SSCE_ResetLex", s16);
		break;
	case SetAutoCorrect:
		s16 = SSCE_SetAutoCorrect(getS16(win, IDC_PARAM1_EDT));
		displayResult(win, "SSCE_SetAutoCorrect", s16);
		break;
	case SetBlockCursor:
		s16 = SSCE_SetBlockCursor(getS16(win, IDC_SESSION_ID_EDT),
		  getS16(win, IDC_BLOCK_ID_EDT), getS32(win, IDC_PARAM1_EDT));
		displayResult(win, "SSCE_SetBlockCursor", s16);
		break;
	case SetDebugFile:
		GetDlgItemText(win, IDC_PARAM1_EDT, path, sizeof(path));
		SSCE_SetDebugFile(path);
		wsprintf(str, "Diagnostic file set to %s", path);
		break;
	case SetDialogOrigin:
		SSCE_SetDialogOrigin(getS16(win, IDC_PARAM1_EDT),
		  getS16(win, IDC_PARAM2_EDT));
		appendMsg(win, "Dialog origin set");
		break;
	case SetHelpFile:
		GetDlgItemText(win, IDC_PARAM1_EDT, path, sizeof(path));
		s16 = SSCE_SetHelpFile(path);
		displayResult(win, "SSCE_SetHelpFile", s16);
		break;
	case SetIniFile:
		GetDlgItemText(win, IDC_PARAM1_EDT, path, sizeof(path));
		s16 = SSCE_SetIniFile(path);
		displayResult(win, "SSCE_SetIniFile", s16);
		break;
	case SetKey:
		s32 = SSCE_SetKey(getU32(win, IDC_PARAM1_EDT));
		wsprintf(str, "SSCE_SetKey returned %ld", s32);
		appendMsg(win, str);
		break;
	case SetMainLexFiles:
		GetDlgItemText(win, IDC_PARAM1_EDT, path, sizeof(path));
		s16 = SSCE_SetMainLexFiles(path);
		displayResult(win, "SSCE_SetMainLexFiles", s16);
		break;
	case SetMainLexPath:
		GetDlgItemText(win, IDC_PARAM1_EDT, path, sizeof(path));
		s16 = SSCE_SetMainLexPath(path);
		displayResult(win, "SSCE_SetMainLexPath", s16);
		break;
	case SetMinSuggestDepth:
		s16 = SSCE_SetMinSuggestDepth(getS16(win, IDC_PARAM1_EDT));
		displayResult(win, "SSCE_SetMinSuggestDepth", s16);
		break;
	case SetOption:
		s32 = (SSCE_S32)SSCE_SetOption(getS16(win, IDC_SESSION_ID_EDT),
		  (SSCE_U32)getS32(win, IDC_PARAM1_EDT),
		  (SSCE_U32)getS32(win, IDC_PARAM2_EDT));
		wsprintf(str, "SSCE_SetOption returned %ld", s32);
		appendMsg(win, str);
		break;
	case SetRegTreeName:
		GetDlgItemText(win, IDC_PARAM1_EDT, path, sizeof(path));
		s16 = SSCE_SetRegTreeName(path);
		displayResult(win, "SSCE_SetRegTreeName", s16);
		break;
	case SetStringTableName:
		GetDlgItemText(win, IDC_PARAM1_EDT, path, sizeof(path));
		s16 = SSCE_SetStringTableName(path);
		displayResult(win, "SSCE_SetStringTableName", s16);
		break;
	case SetUserLexFiles:
		GetDlgItemText(win, IDC_PARAM1_EDT, path, sizeof(path));
		s16 = SSCE_SetUserLexFiles(path);
		displayResult(win, "SSCE_SetUserLexFiles", s16);
		break;
	case SetUserLexPath:
		GetDlgItemText(win, IDC_PARAM1_EDT, path, sizeof(path));
		s16 = SSCE_SetUserLexPath(path);
		displayResult(win, "SSCE_SetUserLexPath", s16);
		break;
	case Suggest:
		s16_1 = SSCE_MAX_WORD_SZ * 16;
		bfr = (SSCE_CHAR *)malloc((size_t)s16_1);
		if (NULL == bfr) {
			appendMsg(win, "Out of memory");
			break;
		}
		GetDlgItemText(win, IDC_PARAM1_EDT, word, sizeof(word));
		s16 = SSCE_Suggest(getS16(win, IDC_SESSION_ID_EDT),
		  word, getS16(win, IDC_PARAM2_EDT), bfr, (SSCE_S32)s16_1,
		  scores, sizeof(scores) / sizeof(scores[0]));
		displayResult(win, "SSCE_Suggest", s16);
		if (s16 >= 0) {
			for (p = bfr, i = 0; *p != '\0'; p += strlen(p) + 1, ++i) {
				wsprintf(str, "%s [%hd]", p, scores[i]);
				appendMsg(win, str);
			}
		}
		free(bfr);
		break;
	case Version:
		SSCE_Version(word, sizeof(word));
		wsprintf(str, "Version: %s", word);
		appendMsg(win, str);
		break;
	}
}
// The nonsecure server thread
static void tcp_server_nonsecure_thread_main(wiced_thread_arg_t arg)
{
    wiced_result_t result;
    wiced_tcp_stream_t stream;                      // The TCP stream
    wiced_tcp_socket_t socket;
    uint8_t rbuffer[MAX_LEGAL_MSG];

    char returnMessage[128]; // better use less than 128 bytes
    // setup the server by creating the socket and hooking it to the correct TCP Port
    result = wiced_tcp_create_socket(&socket, INTERFACE);
    if(WICED_SUCCESS != result)
    {
        WPRINT_APP_INFO(("Create socket failed\n"));
        return; // this is a bad outcome
    }

    wiced_tcp_stream_init(&stream,&socket);
    if(WICED_SUCCESS != result)
    {
        WPRINT_APP_INFO(("Init stream failed\n"));
        return; // this is a bad outcome
    }

    result = wiced_tcp_listen( &socket, TCP_SERVER_NONSECURE_LISTEN_PORT );
    if(WICED_SUCCESS != result)
    {
        WPRINT_APP_INFO(("Listen socket failed\n"));
        return;
    }


    while (1 )
    {

        result = wiced_tcp_accept( &socket ); // this halts the thread until there is a connection

        if(result != WICED_SUCCESS) // this occurs if the accept times out
            continue;

        nonsecureConnectionCount += 1;

        /// Figure out which client is talking to us... and on which port
        wiced_ip_address_t peerAddress;
        uint16_t	peerPort;
        wiced_tcp_server_peer(&socket,&peerAddress,&peerPort);

        uint32_t dataReadCount;
        wiced_tcp_stream_read_with_count(&stream,&rbuffer,MAX_LEGAL_MSG,100,&dataReadCount); // timeout in 100 ms

        processClientCommand(rbuffer, dataReadCount ,returnMessage);

        displayResult(peerAddress,peerPort,returnMessage);


        // send response and close things up
        wiced_tcp_stream_write(&stream,returnMessage,strlen(returnMessage));
        wiced_tcp_stream_flush(&stream);
        wiced_tcp_disconnect(&socket); // disconnect the connection

        wiced_tcp_stream_deinit(&stream); // clear the stream if any crap left
        wiced_tcp_stream_init(&stream,&socket); // setup for next connection

    }
}
Exemple #17
0
/******************************************************************************************
 * Function: main
 *
 * Description:
 *	This function reads the config. file for six input parameters,
 *	finds the frequent 1-itemsets, builds the initial FP-tree
 *	using the frequent 1-itemsets and
 *	peforms the FP-growth algorithm of the paper.
 *	It measure both CPU and I/O time for build tree and mining.
 *
 * Functions to be invoked:
 *	input()		-> Read config. file
 *	pass1()		-> Scan DB and find frquent 1-itemsets
 *	buildTree()	-> Build the initial FP-tree
 *	FPgrowth()	-> Start mining
 *
 * Parameters:
 *	Config. file name
 */
void main(int argc, char *argv[])
{
 float  userTime, sysTime;
 struct rusage myTime1, myTime2, myTime3;
 int headerTableSize;

 /* Usage ------------------------------------------*/
 printf("\nFP-tree: Mining large itemsets using user support threshold\n\n");
 if (argc != 2) {
        printf("Usage: %s <config. file>\n\n", argv[0]);
	printf("Content of config. file:\n");
	printf("  Line 1: Upper limit of large itemsets size to be mined\n");
	printf("  Line 2: Support threshold (normalized to [0, 1])\n");
	printf("  Line 3: No. of different items in the DB\n");
	printf("  Line 4: No. of transactions in the DB\n");
	printf("  Line 5: File name of the DB\n");
	printf("  Line 6: Result file name to store the large itemsets\n\n");
        exit(1);
 }

 /* read input parameters --------------------------*/
 printf("input\n");
 input(argv[1]);

 getrusage(RUSAGE_SELF,&myTime1);

 /* pass 1 : Mine the large 1-itemsets -------------*/
 printf("\npass1\n");
 pass1();

 /* Mine the large k-itemsets (k = 2 to realK) -----*/
 if (numLarge[0] > 0) {

	/* create FP-tree --------------------------*/
 	printf("\nbuildTree\n");
 	buildTree();

	getrusage(RUSAGE_SELF,&myTime2);

	/* mining frequent patterns ----------------*/
 	printf("\npassK\n");
	headerTableSize = numLarge[0];
	numLarge[0] = 0;
 	FPgrowth(root, headerTableLink, headerTableSize, NULL, 0);

 	getrusage(RUSAGE_SELF,&myTime3);

 	/* output result of large itemsets ---------*/
 	printf("\nresult\n");
 	displayResult();

 	/* output execution time ---------------------*/
 	printf("Build tree time:\n");
 	userTime =
       		((float) (myTime2.ru_utime.tv_sec  - myTime1.ru_utime.tv_sec)) +
       		((float) (myTime2.ru_utime.tv_usec - myTime1.ru_utime.tv_usec)) * 1e-6;
 	sysTime =
       		((float) (myTime2.ru_stime.tv_sec  - myTime1.ru_stime.tv_sec)) +
       		((float) (myTime2.ru_stime.tv_usec - myTime1.ru_stime.tv_usec)) * 1e-6;

 	printf("User time : %f seconds\n", userTime);
 	printf("System time : %f seconds\n\n", sysTime);

 	printf("FP-tree growth time:\n");
 	userTime =
       		((float) (myTime3.ru_utime.tv_sec  - myTime2.ru_utime.tv_sec)) +
       		((float) (myTime3.ru_utime.tv_usec - myTime2.ru_utime.tv_usec)) * 1e-6;
 	sysTime =
       		((float) (myTime3.ru_stime.tv_sec  - myTime2.ru_stime.tv_sec)) +
       		((float) (myTime3.ru_stime.tv_usec - myTime2.ru_stime.tv_usec)) * 1e-6;

 	printf("User time : %f seconds\n", userTime);
 	printf("System time : %f seconds\n\n", sysTime);

	printf("Total execution time:\n");
 	userTime =
       		((float) (myTime3.ru_utime.tv_sec  - myTime1.ru_utime.tv_sec)) +
       		((float) (myTime3.ru_utime.tv_usec - myTime1.ru_utime.tv_usec)) * 1e-6;
 	sysTime =
       		((float) (myTime3.ru_stime.tv_sec  - myTime1.ru_stime.tv_sec)) +
       		((float) (myTime3.ru_stime.tv_usec - myTime1.ru_stime.tv_usec)) * 1e-6;

 	printf("User time : %f seconds\n", userTime);
 	printf("System time : %f seconds\n", sysTime);
	printf("Total time: %f seconds\n\n", userTime + sysTime);

 }

 /* free memory ------------------------------------*/
 printf("\ndestroy\n");
 destroy();

 return;
}
Exemple #18
0
void FlowShower::draw()
{
	update();
	setOrthoView();
	glClear(GL_COLOR_BUFFER_BIT);

	float invRatio = float(game->getResY()) / float(game->getResX());
	float hs = 0.02f; //mouse horizontal size
	//float vs = hs * invRatio; //mouse vertical size
	float x = float(game->getMouseX()) / float(game->getResX());
	float y = 1.0f - float(game->getMouseY()) / float(game->getResY());
	float left = (1.0f - invRatio) / 2.0f;
	float right = 1.0f - left;
	float osx = (x - left) / (right - left);

	if (painting && (game->isLeftDown() || game->isMiddleDown()
			|| game->isKeyDown('n') || game->isRightDown()))
	{
		flower.bindMat();

		glDisable(GL_TEXTURE_2D);

		if (game->isLeftDown())
			glColor3f(0.1, 0.0f, 0.0f);
		else if (game->isMiddleDown() || game->isKeyDown('m'))
			glColor3f(0.2, 0.0f, 0.0f);
		else if (game->isRightDown())
			glColor3f(0.0, 0.0f, 0.0f);

		/*glBegin(GL_QUADS);
		osx -= 1.0f;
		oldMouseOSX -= 1.0f;
		for (int j = 0; j < 3; j++)
		{
			glVertex2f(osx - hs, y - hs);
			glVertex2f(osx + hs, y - hs);
			glVertex2f(osx + hs, y + hs);
			glVertex2f(osx - hs, y + hs);

			glVertex2f(osx + hs, y - hs);
			glVertex2f(osx - hs, y - hs);
			glVertex2f(oldMouseOSX - hs, oldMouseY - hs);
			glVertex2f(oldMouseOSX + hs, oldMouseY - hs);

			glVertex2f(osx + vs, y + hs);
			glVertex2f(osx + vs, y - hs);
			glVertex2f(oldMouseOSX + hs, oldMouseY - hs);
			glVertex2f(oldMouseOSX + hs, oldMouseY + hs);

			glVertex2f(osx - vs, y + hs);
			glVertex2f(osx + vs, y + hs);
			glVertex2f(oldMouseOSX + hs, oldMouseY + hs);
			glVertex2f(oldMouseOSX - hs, oldMouseY + hs);

			glVertex2f(osx - vs, y - hs);
			glVertex2f(osx - vs, y + hs);
			glVertex2f(oldMouseOSX - hs, oldMouseY + hs);
			glVertex2f(oldMouseOSX - hs, oldMouseY - hs);
			osx += 1.0f;
			oldMouseOSX += 1.0f;
		}
		glEnd();*/

		drawMouseOffScreen();

		osx -= 2.0f;
		oldMouseOSX -= 2.0f;
		Fbo::unbind();
	}
	if (game->isKeyDown('g'))
	{
		flower.bindMat();
		glColor3f(0.0f, 0.0f, 0.0f);
		glDisable(GL_BLEND);
		glBegin(GL_QUADS);
		glTexCoord2f(0.0f, 0.0f);
		glVertex2f(0.0f, 0.0f);
		glTexCoord2f(1.0f, 0.0f);
		glVertex2f(1.0f, 0.0f);
		glTexCoord2f(1.0f, 1.0f);
		glVertex2f(1.0f, 1.0f);
		glTexCoord2f(0.0f, 1.0f);
		glVertex2f(0.0f, 1.0f);
		glEnd();

		Fbo::unbind();
	}
	if (!paused)
		flower.iterate(iterations, this);

	if (streamlining)
	{
		flower.bindVel();
		float sx = float(game->getMouseX()) / float(game->getResY());
		float sy = 1.0f - float(game->getMouseY()) / float(game->getResY());
		float x = (sx-0.5* float(game->getResX())/ float(game->getResY()))/scale+ viewX;
		float y = (sy-0.5)/scale+ viewY;
		if(x>0)
			x=x-static_cast<int>(x);
		else
			x=x-static_cast<int>(x)+1.0f;
		if(y>0)
			y=y-static_cast<int>(y);
		else
			y=y-static_cast<int>(y)+1.0f;

		slx[0] = x;
		sly[0] = y;
		while (slx[0] < 0.0f)
			slx[0] += 1.0f;
		while (sly[0] < 0.0f)
			sly[0] += 1.0f;
		while (slx[0] >= 1.0f)
			slx[0] -= 1.0f;
		while (sly[0] >= 1.0f)
			sly[0] -= 1.0f;
		for (int i = 1; i < slpnum; i++)
		{
			float pixel[3], xv, yv;
			float px = slx[i - 1], py = sly[i - 1];
			while (px < 0.0f)
				px += 1.0f;
			while (py < 0.0f)
				py += 1.0f;
			while (px >= 1.0f)
				px -= 1.0f;
			while (py >= 1.0f)
				py -= 1.0f;
			//glReadPixels(int(px*float(size)),int(py*float(size)),1,1,GL_RGB,GL_FLOAT,(void *)pixel);
			getSpeed(size, pixel, px, py);
			xv = pixel[0];
			yv = pixel[1];
			float v = sqrt(xv * xv + yv * yv);
			if (v == 0.0f)
				v = 1.0f;
			float dl = 0.005f/scale;

			getSpeed(size, pixel, px + dl * xv / v / 2.0f, py + dl * yv / v
					/ 2.0f);
			xv = pixel[0];
			yv = pixel[1];
			v = sqrt(xv * xv + yv * yv);
			if (v == 0.0f)
				v = 1.0f;

			slx[i] = slx[i - 1] + dl * xv / v;
			sly[i] = sly[i - 1] + dl * yv / v;

		}
		Fbo::unbind();
	}

	if (game->isRightDown() && !painting)
	{
		flower.bindInk();
		Shader::disable();
		glActiveTextureARB(GL_TEXTURE2_ARB);
		glDisable(GL_TEXTURE_2D);
		glActiveTextureARB(GL_TEXTURE1_ARB);
		glDisable(GL_TEXTURE_2D);
		glActiveTextureARB(GL_TEXTURE0_ARB);
		glDisable(GL_TEXTURE_2D);

		glColor3f(inkRed*(1.0f-inkNew)+inkRedNew*inkNew,inkGreen*(1.0f-inkNew)+inkGreenNew*inkNew,inkBlue*(1.0f-inkNew)+inkBlueNew*inkNew);
		//	glColor3f(1.0,1.0,1.0);
		drawMouseOffScreen();
		Fbo::unbind();
	}
	if (game->isKeyDown('t'))
	{
		if(!coordInk)
		{
			flower.bindInk();
			Shader::disable();
			glActiveTextureARB(GL_TEXTURE2_ARB);
			glDisable(GL_TEXTURE_2D);
			glActiveTextureARB(GL_TEXTURE1_ARB);
			glDisable(GL_TEXTURE_2D);
			glActiveTextureARB(GL_TEXTURE0_ARB);
			glDisable(GL_TEXTURE_2D);

			glColor3f(0.0f, 0.0f, 0.0f);
			glBegin(GL_QUADS);
			glVertex2f(0.0f, 0.0f);
			glVertex2f(1.0f, 0.0f);
			glVertex2f(1.0f, 1.0f);
			glVertex2f(0.0f, 1.0f);
			glEnd();
			Fbo::unbind();
		}
		else
		{
			TexGroup::getSingleton()->bind(flowerTex, 0);
			initFromFGMat.enable();
			flower.bindInk();

			glBegin(GL_QUADS);
			glTexCoord2f(0.0f, 0.0f);
			glVertex2f(0.0f, 0.0f);
			glTexCoord2f(1.0f, 0.0f);
			glVertex2f(1.0f, 0.0f);
			glTexCoord2f(1.0f, 1.0f);
			glVertex2f(1.0f, 1.0f);
			glTexCoord2f(0.0f, 1.0f);
			glVertex2f(0.0f, 1.0f);
			glEnd();
			Fbo::unbind();
			Shader::disable();
		}
	}
	if (game->isKeyDown('r'))
	{
		flower.bindVel();
		Shader::disable();
		glActiveTextureARB(GL_TEXTURE2_ARB);
		glDisable(GL_TEXTURE_2D);
		glActiveTextureARB(GL_TEXTURE1_ARB);
		glDisable(GL_TEXTURE_2D);
		glActiveTextureARB(GL_TEXTURE0_ARB);
		glDisable(GL_TEXTURE_2D);

		glColor3f(0.0f, 0.0f, 0.0f);
		glBegin(GL_QUADS);
		glVertex2f(0.0f, 0.0f);
		glVertex2f(1.0f, 0.0f);
		glVertex2f(1.0f, 1.0f);
		glVertex2f(0.0f, 1.0f);
		glEnd();
		Fbo::unbind();
	}
	displayResult();


	float sx = float(game->getMouseX()) / float(game->getResY());
	float sy = 1.0f - float(game->getMouseY()) / float(game->getResY());
	x = (sx-0.5* float(game->getResX())/ float(game->getResY()))/scale+ viewX;
	y = (sy-0.5)/scale+ viewY;
	if(x>0)
		x=x-static_cast<int>(x);
	else
		x=x-static_cast<int>(x)+1.0f;
	if(y>0)
		y=y-static_cast<int>(y);
	else
		y=y-static_cast<int>(y)+1.0f;
	float s = 0.02/scale;
	oldx1=x - s;
	oldx2=x + s;
	oldy1=y - s;
	oldy2=y + s;
}
Exemple #19
0
void HistoryDlg::edb_finished()
{
	const EDBResult *r = d->h->result();
	if(d->h->lastRequestType() == EDBHandle::Read && r) {
		//printf("EDB: retrieved %d events:\n", r->count());
		if(r->count() > 0) {
			if(d->reqtype == 0 || d->reqtype == 1) {
				// events are in backward order
				// first entry is the end event
				EDBItem* it = r->first();
				d->id_end = it->id();
				d->id_next = it->nextId();
				// last entry is the begin event
				it = r->last();
				d->id_begin = it->id();
				d->id_prev = it->prevId();
				displayResult(r, EDB::Backward);
				//printf("[%s],[%s],[%s],[%s]\n", d->id_prev.latin1(), d->id_begin.latin1(), d->id_end.latin1(), d->id_next.latin1());
			}
			else if(d->reqtype == 2) {
				// events are in forward order
				// last entry is the end event
				EDBItem* it = r->last();
				d->id_end = it->id();
				d->id_next = it->nextId();
				// first entry is the begin event
				it = r->first();
				d->id_begin = it->id();
				d->id_prev = it->prevId();
				displayResult(r, EDB::Forward);
			}
			else if(d->reqtype == 3) {
				// should only be one entry
				EDBItem *ei = r->first();
				d->reqtype = 1;
				d->h->get(d->jid, ei->id(), EDB::Backward, 50);
				//printf("EDB: requesting 50 events backward, starting at %s\n", d->id_prev.latin1());
				return;
			}
		}
		else {
			if(d->reqtype == 3) {
				QMessageBox::information(this, tr("Find"), tr("Search string '%1' not found.").arg(d->findStr));
				return;
			}
		}
	}
	else if (d->h->lastRequestType() == EDBHandle::Erase) {
		if (d->h->writeSuccess()) {
			d->lv->clear();
			d->id_prev = "";
			d->id_begin = "";
			d->id_end = "";
			d->id_next = "";
		}
		else {
			QMessageBox::critical(this, tr("Error"), tr("Unable to delete history file."));
		}
	}
	else {
		//printf("EDB: error\n");
	}

	if(d->lv->firstChild())
		d->lv->setSelected(d->lv->firstChild(), true);

	//d->busy->stop();
	d->pb_refresh->setEnabled(true);
	setButtons();
}
int main() {

        char box[10]={' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',};
        char currentPlayer='O';
        int index,i,j,x;

        /* Choose first move */
        printf("You are Mr. O\n");
        printf("Who will start game ? ( Enter 'O' or 'X') : ");
        scanf("%c",&currentPlayer);

        /* Continue game until result declares */
        while(gameOver(box)==-1 && filled<9) {
            printMatrix(box);

            /* If all the boxes are filled then game is over */
            if(filled == 9) {
                printf("...DRAW...\n");
                printMatrix(box);
                return 0;
            }

            printf("Player %c :: ",currentPlayer=='O'?'O':'X');

            if(currentPlayer=='X') {  // Computer 'X'
                    int *a;

                    /* Check immediate state if winning is possible or not ? */
                    for(i=1;i<10;i++) {
                       if(box[i]==' ') {
                           box[i]='X';
                           x=gameOver(box);
                           if(x==10) {
                               box[i]='X';
                               system("cls");
                               displayResult(box);
                               system("pause");
                               return 0;
                           }
                           box[i]=' ';
                       }
                    }

                    a=miniMax(box , true);
                    index=a[0];
            }
            else {                    // You  'O'
                while(1) {
                    scanf("%d",&index);
                    if(box[index]!=' ')
                        printf("Enter valid index : ");
                    else
                        break;
                }
            }

            /* Fill the BOX */
            box[index]=(currentPlayer=='O'?'O':'X');
            filled++;

            currentPlayer= (currentPlayer=='O'?'X':'O') ;

            system("cls");
        }

        displayResult(box);

    return 0;
}