Esempio n. 1
0
// WINDOWS load library function.
// Does nothing if using a linked shared library.
void loadLibrary()
{
#ifdef ASTYLE_DYLIB
#ifdef NDEBUG
	AStyleLib = LoadLibrary(".\\AStyle-2.06.dll");
#else
	AStyleLib = LoadLibrary(".\\AStyle-2.06d.dll");
#endif
	if (!AStyleLib)
	{
		cout << "Cannot load dll library for AStyle!" << endl;
		systemPause();
		exit(EXIT_FAILURE);
	}
	// get AStyleMain function
	AStyleMain = reinterpret_cast<fpASMain>(
	                 GetProcAddress(reinterpret_cast<HMODULE>(AStyleLib), "AStyleMain"));
	if (!AStyleMain)
	{
		cout << "Cannot get dll address for AStyleMain!" << endl;
		systemPause();
		exit(EXIT_FAILURE);
	}
#endif
}
Esempio n. 2
0
int adjustForSkippedRows (const int* palList, short numPalindrome, int state){
	
	short low = -1, high = numPalindrome, middle = numPalindrome/2;
	while(high - low != 1){
    	if(palList[middle] - state > 0){
    		#ifdef DEBUGADJUSTFORSKIPPEDROWS
				printf("(palList[middle]: %d - state: %d ): %d > 0\n", palList[middle], state, palList[middle] - state);
				#ifdef ENABLEPAUSE
					systemPause();
				#endif
			#endif
    		high = middle;
    		middle = (high - low)/2 + low;
		} else {
			#ifdef DEBUGADJUSTFORSKIPPEDROWS
				printf("(palList[middle]: %d - state: %d ): %d < 0\n", palList[middle], state, palList[middle] - state);
				#ifdef ENABLEPAUSE
					systemPause();
				#endif
			#endif
    		low = middle;
    		middle = (high - low)/2 + low;
		}
	}
	state = state - high;
	
	#ifdef DEBUGADJUSTFORSKIPPEDROWS
		printf("adjustForSkippedRows Result: %d", state);
	#endif
	
	return state;
}
Esempio n. 3
0
/*!
 * \fn void loadGame()
 *  Load a game from a file and run the play function.
 */
void loadGame()
{
    csuStruct *ptr_csu_struct;
    char file_name[SIZE_MAX_FILE_NAME];

    clearScreen();
    menuFileName(file_name);

    #ifndef PORTABLE
    if(readSystemPath(file_name)==false)
        return;
    #endif // PORTABLE

    ptr_csu_struct=readCsuFile(file_name);

    if (ptr_csu_struct == NULL)
    {
        systemPause();
        return;
    }

    printCsuStruct(ptr_csu_struct);

    if(exceedMaxNumber(ptr_csu_struct))
    {
        printGameOver(ptr_csu_struct);
        systemPause();
    }

    else
    {
        systemPause();
        play(ptr_csu_struct,file_name);
    }
}
Esempio n. 4
0
/*!
 * \fn void loadGameLocale(char *file_name)
 *  Load the file and run the play function
 * \param[in] file_name the filename
 */
void loadGameLocale(char *file_name)
{
    csuStruct *ptr_csu_struct;

    clearScreen();

    ptr_csu_struct=readCsuFile(file_name);

    if (ptr_csu_struct == NULL)
    {
        systemPause();
        return;
    }

    printCsuStruct(ptr_csu_struct);

    if(exceedMaxNumber(ptr_csu_struct))
    {
        printGameOver(ptr_csu_struct);
        systemPause();
    }

    else
    {
        systemPause();
        play(ptr_csu_struct,file_name);
    }
}
Esempio n. 5
0
/*!
 * \fn void preferencesMenu()
 *  Preferences menu of csuper.
 */
void preferencesMenu()
{
    int choice;
    int stop = false;

    do
    {
        choice=-1;

        clearScreen();

        printf(_("\nWhat do you want to do?\n"));
        #ifndef PORTABLE
        printf(_("\n (%d) Change the folder where files will be saved\n (%d) Display the folder where files will be saved"),newPath,readPath);
        #endif
        printf(_("\n (%d) Make a new game configuration\n (%d) Delete an existing game configuration"
        "\n (%d) Display the list of game configurations\n (%d) Display a game configuration"
        "\n (%d) Export game configurations\n (%d) Import game configurations\n (%d) Change pdf export preferences"
        "\n (%d) Back to main menu\n\nYour choice : ")
               ,newGameConf,removeGameConf,printListGameConf,printGameConf,exportGameConf,importGameConf,pdfPreferences,backMainMenu);

        intKey(&choice);

        switch (choice) {
            #ifndef PORTABLE
            case newPath   :   changeFilePath();
                                break;
            case readPath :     readFilePath();
                                break;
            #endif
            case backMainMenu  :   stop=true;
                                break;
            case newGameConf :  newGameConfig();
                                break;
            case removeGameConf:removeGameConfig();
                                break;
            case printListGameConf:printListGameConfig();
                                break;
            case printGameConf: printGameConfigFile();
                                break;
            case easterEggs2 :  printf(_("\nYes, it's the correct answer, but that doesn't help me to know what you want to do.\n"));
                                systemPause();
                                break;
            case exportGameConf:exportListGameConfig();
                                break;
            case importGameConf:importListGameConfig();
                                break;
            case pdfPreferences:changePdfPreferences();
                                break;
            default :           wrongChoice();
                                systemPause();
        }

        clearScreen();

	} while (stop==false);
}
Esempio n. 6
0
/*!
 * \fn void mainMenu()
 *  Main menu of csuper.
 */
void mainMenu()
{
    int choice;
    int stop = false;

    do
    {
        choice=-1;

        clearScreen();

        printf(_("Csuper - Universal points counter allowing a dispense with reflection v"));
        printf(_("%s"),CSUPER_VERSION);
        printf(_("\n\nWhat do you want to do?\n "
            "(%d) Play a new game\n (%d) Load an existing game\n (%d) Display the results of an existing game"
            "\n (%d) Delete a game\n (%d) Display all existing games\n (%d) Export a file\n"
            " (%d) Display the preferences menu\n (%d) Quit the program\n\nYour choice : ")
            ,newMatch,loadMatch,printFile,deleteFiles,listFile,export_file,pref,quit);

        intKey(&choice);

        switch (choice) {
            case newMatch  :    newGame();
                                break;
            case loadMatch  :   loadGame();
                                break;
            case printFile  :   displayFile();
                                break;
            case deleteFiles  : deleteCsuFileNom();
                                break;
            case listFile  :    listCsuFiles();
                                break;
            case export_file  : exportCsu();
                                break;
            case pref :         preferencesMenu();
                                break;
            case quit  :        printf(_("\nSee you.\n"));
                                systemPause();
                                stop=true;
                                break;
            case easterEggs :   printf(_("\nYes, it's the correct answer, but that doesn't help me to know what you want to do.\n"));
                                systemPause();
                                break;
            default :           wrongChoice();
                                systemPause();
        }

        clearScreen();

	} while (stop==false);
}
Esempio n. 7
0
/*!
 * \fn void importListGameConfig()
 *  Import all game configuration in one file.
 */
void importListGameConfig()
{
    char home_path[SIZE_MAX_FILE_NAME]="";
    char filename[SIZE_MAX_FILE_NAME]="";
    int *id;
    int nb_id=0;

    clearScreen();

    menuFileName(filename);

    #ifndef PORTABLE
    readHomePathSlash(home_path);
    if(readSystemPath(filename)==false)
        return;
    #endif // PORTABLE

    if (!menuImportListGameConfig(&id,&nb_id,filename))
        return;

    if(importConfigFile(home_path,filename,id,nb_id) == true)
        printf(_("\nGame configurations were successfully imported from %s\n"),filename);

    free(id);
    systemPause();
}
Esempio n. 8
0
/*!
 * \fn void listCsuFiles()
 *  List all the files with csu extension
 */
void listCsuFiles()
{
    struct dirent *lecture;
    DIR *rep;
    char jeu[4]=FILE_EXTENSION_CSU;
    char ext[4]="abc";
    char folder[SIZE_MAX_FILE_NAME]=".";
    int i;

    clearScreen();

    #ifndef PORTABLE
    if(readSystemPath(folder)==false)
        return;
    #endif // PORTABLE

    rep = opendir(folder);

    printf(_("Here are all your csu files:\n"));

    while ((lecture = readdir(rep))) {
        for (i=0 ; i<3 ; i++)
            ext[i]='a';

        for (i=strlen(lecture->d_name)-3 ; i<strlen(lecture->d_name) ; i++)
            ext[-strlen(lecture->d_name)+i+3]=lecture->d_name[i];

        if (strcmp(jeu,ext)==0)
            printf("\t- %s\n", lecture->d_name);
    }

    closedir(rep);
    systemPause();
}
Esempio n. 9
0
/*!
 * \fn void displayFile()
 *  Ask a filename and display it.
 */
void displayFile()
{
    char file_name[SIZE_MAX_FILE_NAME];
    csuStruct *ptr_csu_struct;

    clearScreen();

    menuFileName(file_name);

    #ifndef PORTABLE
    if(readSystemPath(file_name)==false)
        return;
    #endif // PORTABLE

    ptr_csu_struct=readCsuFile(file_name);

    if (ptr_csu_struct != NULL)
    {
        printCsuStruct(ptr_csu_struct);

        if(exceedMaxNumber(ptr_csu_struct))
            printGameOver(ptr_csu_struct);

        closeCsuStruct(ptr_csu_struct);
    }

    systemPause();
}
Esempio n. 10
0
void systemPause(const string& message)
// accept keyboard input to continue
// assures a console message is noticed
{
	cout << message << endl;
	systemPause();
}
int main(int argc, char** argv)
{
	// set global variable g_testDirectory
	setTestDirectory();
	// the following statement will be printed at beginning of job
	// and before a death test
//	printf("Test directory: %s.\n", (*g_testDirectory).c_str());
	// parse command line BEFORE InitGoogleTest
	bool useTersePrinter = true;	// ALWAYS true (for testing only)
	bool useTerseOutput = false;	// option for terse (true) or all (false)
	bool useColor = true;
	bool noClose = false;
	for (int i = 1; i < argc; i++)
	{
		if (strcmp(argv[i], "--terse_output") == 0)
			useTerseOutput = true;
		else if (strcmp(argv[i], "--no_close") == 0)
			noClose = true;
		else if (strcmp(argv[i], "--gtest_color=no") == 0)
			useColor = false;
	}
	// do this after parsing the command line but before changing printer
	testing::InitGoogleTest(&argc, argv);
	// change to TersePrinter
	if (useTersePrinter)
	{
		UnitTest& unit_test = *UnitTest::GetInstance();
		testing::TestEventListeners& listeners = unit_test.listeners();
		delete listeners.Release(listeners.default_result_printer());
		listeners.Append(new TersePrinter(useTerseOutput, useColor));
	}
	// Begin unit testing.
	// The default options file is renamed to avoid errors in testing.
	createTestDirectory(getTestDirectory());
	renameDefaultOptionsFile();
	int retval = RUN_ALL_TESTS();
	restoreDefaultOptionsFile();
	// Print verification if terse_printer.
	// Verify that all tests were run. This can occur if a source file
	// is missing from the project. The UnitTest reflection API in
	// example 9 will not work here because of user modifications.
	if (g_isI18nTest)
		// Change the following value to the number of tests (within 20).
		TersePrinter::PrintTestTotals(40, __FILE__, __LINE__);
	else
		// Change the following value to the number of tests (within 20).
		TersePrinter::PrintTestTotals(140, __FILE__, __LINE__);
	if (g_isI18nTest)
		printI18nMessage();
#ifdef _WIN32
	printf("%c", '\n');
#endif
	// end of unit testing
	removeTestDirectory(getTestDirectory());
	if (noClose)			// command line option
		systemPause();

	return retval;
}
Esempio n. 12
0
/*!
 * \fn void play(csuStruct *ptr_csu_struct, char *file_name)
 *  Count the points
 * \param[in,out] *ptr_csu_struct a pointer on a csu structure
 * \param[in] *file_name the filename
 */
void play(csuStruct *ptr_csu_struct, char *file_name)
{
    ContinueChangeDistributorOrQuit choice;
    bool continuer=true;

    clearScreen();
    printPoints(ptr_csu_struct);

    do
    {
        menuPlayersPoints(ptr_csu_struct);

        if (!writeFileNewTurn(file_name,ptr_csu_struct))
            systemPause();

        clearScreen();
        printPoints(ptr_csu_struct);

        if (exceedMaxNumber(ptr_csu_struct))
            continuer=false;

        else
        {
            choice=menuContinueChangeDistributorOrQuit();
            if (choice == Quit)
                continuer = false;
            if (choice == ChangeDistributor)
                menuChangeDistributor(ptr_csu_struct);
        }

    } while (continuer==true);

    printGameOver(ptr_csu_struct);

    if (menuDelete())
    {
        deleteFile(file_name);
        systemPause();
    }

    clearScreen();
    printCsuStruct(ptr_csu_struct);
    closeCsuStruct(ptr_csu_struct);
    systemPause();
}
Esempio n. 13
0
void deleteConsoleGlobalObject()
// deletes the g_console object
{
	delete g_console;
	g_console = NULL;
	// check global error display
	if (_err != &cerr)
		systemPause("_err ostream not replaced");
	_err = &cerr;
}
Esempio n. 14
0
void createConsoleGlobalObject(ASFormatter& formatter)
// creates the g_console object
{
	if (g_console)
	{
		systemPause("Global object not deleted by previous test.");
		deleteConsoleGlobalObject();
	}
	g_console = new ASConsole(formatter);
}
Esempio n. 15
0
/*!
 * \fn void changeFilePath()
 *  Change the path which the file are saved.
 */
void changeFilePath()
{
    char new_path[SIZE_MAX_FILE_NAME];

    clearScreen();

    menuNewPath(new_path);
    changeSystemPath(new_path);

    systemPause();
}
Esempio n. 16
0
/*!
 * \fn void readFilePath()
 *  Read the file path and display it.
 */
void readFilePath()
{
    char path[SIZE_MAX_FILE_NAME]="";

    clearScreen();

    #ifndef PORTABLE
    readSystemPath(path);
    #endif // PORTABLE

    printf(_("Your files are saved in %s\n"),path);
    systemPause();
}
Esempio n. 17
0
bool writeOptionsFile(const string& optionsFileName, const char* fileIn)
// write a test options file
{
	// write the file
	ofstream fileOut(optionsFileName.c_str(), ios::binary);
	if (!fileOut)
	{
		systemPause("Cannot write options test file: " + optionsFileName);
		return false;
	}
	fileOut << fileIn;
	fileOut.close();
	return true;
}
Esempio n. 18
0
/*!
 * \fn void newGameConfig()
 *  Add a new game configuration
 */
void newGameConfig()
{
    game_config config;
    char home_path[SIZE_MAX_FILE_NAME]="";

    clearScreen();
    menuFileName(config.name);
    menuGameConfig(&config);
    #ifndef PORTABLE
    readHomePathSlash(home_path);
    #endif // PORTABLE
    if (newConfigFile(config,home_path) == false);
        systemPause();
}
Esempio n. 19
0
/*!
 * \fn void deleteCsuFileNom()
 *  Ask a filename and deleted the file.
 */
void deleteCsuFileNom()
{
    char file_name[SIZE_MAX_FILE_NAME];

    clearScreen();
    menuFileName(file_name);
    addFileCsuExtension(file_name);

    #ifndef PORTABLE
    if(readSystemPath(file_name)==false)
        return;
    #endif // PORTABLE

    deleteFile(file_name);
    systemPause();
}
Esempio n. 20
0
/*!
 * \fn void exportToPdfLocale(char *filename, char *export_filename)
 *  Export the csu file named filename into a pdf file named export_filename
 * \param[in] filename the csu filename
 * \param[in] export_filename the pdf filename
 */
void exportToPdfLocale(char *filename, char *export_filename)
{
    csuStruct *ptr_csu_struct;

    ptr_csu_struct=readCsuFile(filename);

    if (ptr_csu_struct == NULL)
    {
        systemPause();
        return;
    }

    if (exportToPdf(ptr_csu_struct,export_filename))
        printf(_("The file was well export to %s\n"),export_filename);
    else
        printf(_("There is an error when exporting the file %s into a pdf file.\n"),filename);
}
Esempio n. 21
0
/*!
 * \fn void printListGameConfig()
 *  Print the list of game configuration
 */
void printListGameConfig()
{
    int i;
    list_game_config *ptr_list_config;
    char home_path[SIZE_MAX_FILE_NAME]="";

    clearScreen();

    #ifndef PORTABLE
    readHomePathSlash(home_path);
    #endif // PORTABLE
    ptr_list_config = readConfigListFile(home_path);
    printf(_("\nHere are all your game configurations:\n"));
    for (i=0 ; i<ptr_list_config->nb_config ; i++)
        printf("(%d) %s\n",i+1,ptr_list_config->name_game_config[i]);
    closeListGameConfig(ptr_list_config);
    systemPause();
}
Esempio n. 22
0
int main(int argc, char** argv)
{
	// Parse command line BEFORE InitGoogleTest.
	bool useTersePrinter = true;	// ALWAYS true (for testing only)
	bool useTerseOutput = false;	// option for terse (true) or all (false)
	bool useColor = true;
	bool noClose = false;
	for (int i = 1; i < argc; i++)
	{
		if (strcmp(argv[i], "--terse_output") == 0 )
			useTerseOutput = true;
		else if (strcmp(argv[i], "--no_close") == 0 )
			noClose = true;
		else if (strcmp(argv[i], "--gtest_color=no") == 0)
			useColor = false;
	}
	// Do this after parsing the command line but before changing printer.
	testing::InitGoogleTest(&argc, argv);
	// ALWAYS uses TersePrinter.
	if (useTersePrinter)
	{
		UnitTest& unit_test = *UnitTest::GetInstance();
		TestEventListeners& listeners = unit_test.listeners();
		delete listeners.Release(listeners.default_result_printer());
		listeners.Append(new TersePrinter(useTerseOutput, useColor));
	}
	// run the tests
	loadLibrary();
	int retval = RUN_ALL_TESTS();
	freeLibrary();
	// Verify that all tests were run. This can occur if a source file
	// is missing from the project. The UnitTest reflection API in
	// example 9 will not work here because of user modifications.
	// Change the following value to the number of tests (within 20).
	TersePrinter::PrintTestTotals(2340, __FILE__, __LINE__);

#ifdef __WIN32
	printf("%c", '\n');
#endif
	if (noClose)			// command line option
		systemPause();

	return retval;
}
Esempio n. 23
0
/*!
 * \fn void displayFileLocale(char *file_name)
 *  Display the file.
 */
void displayFileLocale(char *file_name)
{
    csuStruct *ptr_csu_struct;

    clearScreen();

    ptr_csu_struct=readCsuFile(file_name);

    if (ptr_csu_struct != NULL)
    {
        printCsuStruct(ptr_csu_struct);

        if(exceedMaxNumber(ptr_csu_struct))
            printGameOver(ptr_csu_struct);

        closeCsuStruct(ptr_csu_struct);
    }

    systemPause();
}
Esempio n. 24
0
/*!
 * \fn void printGameConfig()
 *  Ask and print a game configuration
 */
void printGameConfigFile()
{
    int i;
    int game_config_choice;
    list_game_config *ptr_list_config;
    game_config config;
    char home_path[SIZE_MAX_FILE_NAME]="";

    clearScreen();

    /*Affichage des diffrentes configurations*/
    #ifndef PORTABLE
    readHomePathSlash(home_path);
    #endif // PORTABLE
    ptr_list_config = readConfigListFile(home_path);
    if (ptr_list_config->nb_config > 0)
    {
        printf(_("\nWhich game configuration would you like to display?\n"));
        for (i=0 ; i<ptr_list_config->nb_config ; i++)
            printf("(%d) %s\n",i+1,ptr_list_config->name_game_config[i]);

        /*Demande du choice*/
        do
        {
            printf(_("\nYour choice: "));
            intKey(&game_config_choice);
            printf(_("You chose %d\n"),game_config_choice);
        } while (game_config_choice <1 || game_config_choice >i);

        readConfigFile(game_config_choice-1,ptr_list_config,&config,home_path);
        printGameConfig(config);
        closeListGameConfig(ptr_list_config);
    }

    else
        printf(_("\nYou do not have any game configuration file.\n"));

    systemPause();
}
Esempio n. 25
0
/*!
 * \fn void newGame()
 *  Initialize a new game and run the play function.
 */
void newGame()
{
    csuStruct *ptr_csu_struct;
    float nb_players;
    game_config config;
    int writting_file;
    char distributor_name[SIZE_MAX_NAME];
    char file_name[SIZE_MAX_FILE_NAME];

    clearScreen();
    menuFileName(file_name);
    addFileCsuExtension(file_name);

    #ifndef PORTABLE
    if(readSystemPath(file_name)==false)
        return;
    #endif // PORTABLE

    menuStartGame(&nb_players,&config);

    ptr_csu_struct=newCsuStruct(nb_players,config);
    menuPlayersName(ptr_csu_struct);

    if (config.use_distributor)
    {
        menuDistributor(distributor_name);
        addDistributorCsuStruct(ptr_csu_struct,distributor_name);
    }

    writting_file=writeCsuFile(file_name,ptr_csu_struct);

    systemPause();

    if (writting_file)
        play(ptr_csu_struct,file_name);
    else
        closeCsuStruct(ptr_csu_struct);
}
Esempio n. 26
0
/*determines the number of steps a given state[] is away from the "minimal state" based on the given freq[].
The "minimal state" is the state created by step 0. Example: Freq[2,2,2,1] => Result[a,a,b,b,c,c,d].
*/
int state2steps(const short freq[], short freqSize, short state[], short stateSize){
	
	#ifdef DEBUGSTATE2STEPS
		fputs("state2steps(freq: ", stdout);
		printShortArray(freq, freqSize);
		printf(",freqSize: %d, state: ", freqSize);
		printShortArray(state, stateSize);
		printf(", stateSize: %d)\n", stateSize);
	#endif
	
	short copy[freqSize];
	short i = 0;
	for(i = 0; i < freqSize; ++i){
		copy[i] = freq[i];
	}
	--copy[0];
	
	short zeroState[stateSize];
	steps2state(freq, freqSize, zeroState, stateSize, 0);
	
	int steps = 0;
	short sigSize = stateSize - 1;
	int sig[sigSize];
	promotionSignature(copy, freqSize, sig, sigSize, 0);
	
	#ifdef DEBUGSTATE2STEPS
		fputs("After initial pSig: ", stdout);
		fputs("state2steps(copy: ", stdout);
		printShortArray(copy, freqSize);
		printf(",freqSize: %d, sig: ", freqSize);
		printIntArray(sig, sigSize);
		printf(", sigSize: %d)\n", sigSize);
	#endif
	
	for(i = 0; i < sigSize;){
		if(state[i] == zeroState[i]){
			--copy[zeroState[++i]];
		} else {
			#ifdef DEBUGSTATE2STEPS
				printTitledShortArray("state: ", state, stateSize, 1);
				printTitledShortArray("zeroState: ", zeroState, stateSize, 1);
				printf("%d != %d\n", state[i], zeroState[i]);
			#endif
			steps += sig[i];
			++copy[zeroState[i]];
    		++zeroState[i];
			while(copy[zeroState[i]] == 0){
				++zeroState[i];
			}
    		--copy[zeroState[i]];
			promotionSignature(copy, freqSize, sig, sigSize, i);
			
			#ifdef DEBUGSTATE2STEPS
				fputs("After following pSig: ", stdout);
				fputs("promotionSignature(copy: ", stdout);
				printShortArray(copy, freqSize);
				printf(",freqSize: %d, pSig: ", freqSize);
				printIntArray(sig, sigSize);
				printf(", sigSize: %d, i: %d)\n", sigSize, i);
				#ifdef ENABLEPAUSE
					systemPause();
				#endif
			#endif
			
			short k = i, l, m;
			for(l = 0; l < freqSize; ++l){
				for(m = 0; m < copy[l]; ++m){
					zeroState[++k] = l;
				}
			}
		}
	}
	
	return steps;
};
Esempio n. 27
0
void invertMatrix (double** matrix, int rows, int columns, int* statesToTrackPtr, int sttSize){

	#ifdef DEBUGINVERTMATRIX
		printDoubleArrayAs2D("Fundamental matrix: ", matrix, rows, columns, 2);
		printTitledIntArray("Target states: ", statesToTrackPtr, sttSize, 1);
		#ifdef ENABLEPAUSE
			systemPause();
		#endif
		putchar('\n');
	#endif
	
	int i, j, pivot, max, stopPivot = rows - 1, subtractor, rowAbove;
	double* tempPtr;
	for (pivot = 0; pivot < stopPivot; ++pivot){
		max = pivot;
		#ifdef DEBUGINVERTMATRIX
			printf("step %d\n", pivot);
		#endif
		
		for(i = pivot + 1; i < rows; ++i){
			if(abs(matrix[i][pivot]) > abs(matrix[max][pivot])){
				max = i;
			}
		}
		
		#ifdef DEBUGINVERTMATRIX
			printf("max found: %d\n", max);
		#endif
		
		for(i = 0; i < sttSize; ++i){
			if(statesToTrackPtr[i] == max)
				statesToTrackPtr[i] = pivot;
			else if (statesToTrackPtr[i] == pivot)
				statesToTrackPtr[i] = max;
		}
		
		if(max != pivot){
			tempPtr = matrix[pivot];
			matrix[pivot] = matrix[max];
			matrix[max] = tempPtr;
		}
		
		for(i = pivot + 1; i < rows; ++i){
			for(j = pivot + 1; j < columns; ++j){
				matrix[i][j] = matrix[i][j] - matrix[pivot][j] * (matrix[i][pivot] / matrix[pivot][pivot]);
			}
			matrix[i][pivot] = 0;
		}
		
		#ifdef DEBUGINVERTMATRIX
			printDoubleArrayAs2D("Fundamental matrix after step: ", matrix, rows, columns, 2);
			printTitledIntArray("Target states: ", statesToTrackPtr, sttSize, 1);
				#ifdef ENABLEPAUSE
					systemPause();
				#endif
			putchar('\n');
		#endif
	}
	
	for(; pivot > 0; --pivot){
		rowAbove = pivot - 1;
		if(matrix[pivot][pivot] != 1){
			for(i = rows; i < columns; ++i)
				matrix[pivot][i] /= matrix[pivot][pivot];
			matrix[pivot][pivot] = 1;
		}
		
		for(subtractor = pivot; subtractor < rows; ++subtractor){
			if(matrix[rowAbove][subtractor] != 0)
				for(i = rows; i < columns; ++i)
					matrix[rowAbove][i] -= matrix[subtractor][i] * matrix[rowAbove][subtractor];
			matrix[rowAbove][subtractor] = 0;
		}
		
		#ifdef DEBUGINVERTMATRIX
			printDoubleArrayAs2D("Fundamental matrix after step: ", matrix, rows, columns, 2);
			printTitledIntArray("Target states: ", statesToTrackPtr, sttSize, 1);
				#ifdef ENABLEPAUSE
					systemPause();
				#endif
			putchar('\n');
		#endif

	}
	
	for(i = rows; i < columns; ++i)
		matrix[pivot][i] /= matrix[pivot][pivot];
	matrix[pivot][pivot] = 1;
	
	#ifdef MILESTONES
		double matrixRowTotal = 0;
		puts("Inverted Fundamental matrix: ");
		for(i = 0; i < rows; ++i){
			intOutput(i);
			fputs(": ", stdout);
			printDoubleArray (matrix[i], columns, 4);
			for (j = rows; j < columns; ++j)
				matrixRowTotal += matrix[i][j];
			printf(": %f ", matrixRowTotal);
			matrixRowTotal = 0;
		}
		printTitledIntArray("Modified target states: ", statesToTrackPtr, sttSize, 1);
		#ifdef ENABLEPAUSE
			systemPause();
		#endif
	#endif
}
Esempio n. 28
0
// Error handler for the Artistic Style formatter.
// Pause so the error will be noticed.
// Linux calls "sh -c", not bash.
void  STDCALL errorHandler(int errorNumber, const char* errorMessage)
{
	cout << "AStyle error " << errorNumber << ".\n" << errorMessage << endl;
	systemPause();
}
Esempio n. 29
0
/*!
 * \fn void exportCsu()
 *  Export a csu file into a csv or pdf file
 */
void exportCsu()
{
    csuStruct *ptr_csu_struct;
    char filename[SIZE_MAX_FILE_NAME];
    char export_filename[SIZE_MAX_FILE_NAME];
    FileType type;

    clearScreen();

    // Get the filename
    menuFileName(filename);
    #ifndef PORTABLE
    if(readSystemPath(filename)==false)
        return;
    #endif // PORTABLE
    ptr_csu_struct=readCsuFile(filename);

    // Read the file
    if (ptr_csu_struct == NULL)
    {
        systemPause();
        return;
    }

    // Prepare the exportation
    strcpy(export_filename,filename);
    removeFileExtension(export_filename);
    type = menuChooseExportFileType();

    if (type == pdf_file)
    {
        addFilePdfExtension(export_filename);
        if (exportToPdf(ptr_csu_struct,export_filename))
            printf(_("The file was well export to %s\n"),export_filename);
        else
            printf(_("There is an error when exporting the file %s into a pdf file.\n"),filename);
    }
    else if (type == gnuplot_file)
    {
        if (exportToGnuplotFile(ptr_csu_struct,export_filename))
            printf(_("The file was well export to %s\n"),export_filename);
        else
            printf(_("There is an error when exporting the file %s into gnuplot files.\n"),filename);
    }
    else if (type == csv_file)
    {
        addFileCsvExtension(export_filename);
        if (exportToCsv(ptr_csu_struct,export_filename))
            printf(_("The file was well export to %s\n"),export_filename);
        else
        printf(_("There is an error when exporting the file %s into a csv file.\n"),filename);
    }
    else
    {
        addFileExtension(export_filename,"m");
        if (exportToM(ptr_csu_struct,export_filename))
            printf(_("The file was well export to %s\n"),export_filename);
        else
        printf(_("There is an error when exporting the file %s into a m file.\n"),filename);
    }

    closeCsuStruct(ptr_csu_struct);
    systemPause();
}