Пример #1
0
//------------------------------------------------------------------------------
Solver::SolverState Solver::AdvanceState()
{
   switch (currentState) {
      case INITIALIZING:
         CompleteInitialization();
         break;
        
      case NOMINAL:
         RunNominal();
         break;
        
      case PERTURBING:
         RunPerturbation();
         break;
        
      case ITERATING:
         RunIteration();
         break;
        
      case CALCULATING:
         CalculateParameters();
         break;
        
      case CHECKINGRUN:
         CheckCompletion();
         break;
        
      case RUNEXTERNAL:
         RunExternal();
         break;
        
      case FINISHED:
         RunComplete();
         break;
        
      default:
         throw SolverException(wxT("Undefined Solver state"));
    };
    
    ReportProgress();
    return currentState; 
}
Пример #2
0
int
main(int argc, char *argv[])
{
	char command[20];        // the command either internal or external.
	parameters_t parameters; // all other parameters.
	char outpath[1024];      // the path of output redirection.
	char inpath[1024];       // the path of input redirection.
	int flags[2];            // mark if there is any I/O redirection.

	// Check if there is a batch file.
	if (argc == 2)
	{
		commands = fopen(argv[1], "r");
		if (commands == NULL)
		{
			printf("Can't open the file \"%s\"!\n", argv[1]);
			commands = stdin;
		}
	}
	else
		commands = stdin;

	// Set the environment variable SHELL.
	SetMyshell();

	for (Prompt(); fscanf(commands, "%s", command) != EOF; Prompt()) // Initially get the command.
	{
		// Get all other parameters.
		GetParameters(command, &parameters, flags, inpath, outpath);

		// Check if there is a stdout redirection.
		switch (flags[0]) {
		case 1:
			freopen(outpath, "w", stdout);
			break;
		case 2:
			freopen(outpath, "a", stdout);
			break;
		}
		// Check if there is a stdin redirection.
		if (flags[1])
			freopen(inpath, "r", stdin);

		// Run different command correspondingly.
		if (!strcmp(command, "cd"))
			Cd(&parameters);
		else if (!strcmp(command, "clr"))
			Clr();
		else if (!strcmp(command, "cmp"))
			Cmp(&parameters);
		else if (!strcmp(command, "dir"))
			Dir(&parameters);
		else if (!strcmp(command, "echo"))
			Echo(&parameters);
		else if (!strcmp(command, "environ"))
			Environ();
		else if (!strcmp(command, "fgrep"))
			Fgrep(&parameters);
		else if (!strcmp(command, "help"))
			Help();
		else if (!strcmp(command, "pause"))
			Pause();
		else if (!strcmp(command, "pwd"))
			Pwd();
		else if (!strcmp(command, "quit"))
			Quit();
		else if (!strcmp(command, "wc"))
			Wc(&parameters);
		else
			RunExternal(command, &parameters, flags, inpath, outpath);

		// If there was an I/O redirection, restore the stdin/stdout.
		if (flags[0])
			freopen("/dev/tty", "w", stdout);
		if (flags[1])
			freopen("/dev/tty", "r", stdin);
	}

	return 0;
}