//------------------------------------------------------------------------------ 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; }
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, ¶meters, 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(¶meters); else if (!strcmp(command, "clr")) Clr(); else if (!strcmp(command, "cmp")) Cmp(¶meters); else if (!strcmp(command, "dir")) Dir(¶meters); else if (!strcmp(command, "echo")) Echo(¶meters); else if (!strcmp(command, "environ")) Environ(); else if (!strcmp(command, "fgrep")) Fgrep(¶meters); 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(¶meters); else RunExternal(command, ¶meters, 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; }