/* El main solo define las variables necesarias para la funcion * PrintToken, crea el archivo de errores y por medio del loop * se toma cada token y su salida es por el stdout si no hay errores * o por stderr si los hay. */ int main() { TokenType token; OpenErrorFile(); while ((token = (TokenType)yylex()) != 0) PrintToken(token, yytext, yylval); CloseErrorFile(); return 0; }
/* * InitGame: * Initializes core game components */ void InitGame() { // open the error file, useful for debugging OpenErrorFile("error.dat"); WriteError("\n ====== INITIALIZATION ======"); // Generate trig lookup tables WriteError("\n Generating trig lookup tables..."); GenerateTabs(); WriteError("\n Trig lookups generated..."); // Initialize directdraw #ifdef WINDOWED WriteError("\n Initializing DirectDraw Windowed mode..."); DDInitWindowed(640, 480, 16, g_hWnd, RestoreGraphics); WriteError("\n DirectDraw Windowed mode initialized..."); #else WriteError("\n Initializing DirectDraw FullScreen mode..."); DDInitFullscreen(640, 480, 16, g_hWnd, RestoreGraphics); WriteError("\n DirectDraw FullScreen mode initialized..."); #endif // initialize Digital FX WriteError("\n Initializing DigitalFX..."); DFXInit(lpDDSPrimary); WriteError("\n DigitalFX Initialized..."); // initialize directsound WriteError("\n Initializing DirectSound..."); DSInit(g_hWnd); WriteError("\n DirectSound Initialized..."); // initialize Directinput WriteError("\n Initializing DirectInput..."); DIInit(g_hInstance); WriteError("\n DirectInput Initialized..."); // initialize all input devices WriteError("\n Initializing Keyboard Input Device..."); DIInitKeyboard(g_hWnd); WriteError("\n Keyboard initialized..."); WriteError("\n Initializing Joystick Input Device..."); DIInitJoystick(g_hWnd); WriteError("\n Joystick initialized..."); // Pick which memcpy we should use WriteError("\n Determining fastest Memcpy() method..."); Pickmemcpy(); // Initialize the pixel shade table WriteError("\n Initializing Pixel Shade lookup..."); InitPixelShade(); WriteError("\n Pixel Shade lookup initialized..."); // Initialize game stuff InitStuff(); WriteError("\n ====== END INITIALIZATION ======"); // Hide the mouse cursor ShowCursor(FALSE); }
int main(int argc, char *argv[]) { int opt; struct option longopts[] = { {"help", 0, NULL, 'h'}, {"version", 0, NULL, 'v'}, {"about", 0, NULL, 'a'}, {"error", 1, NULL, 'e'}, {"log", 1, NULL, 'l'}, {"output", 1, NULL, 'o'}, {"test0", 1, NULL, '0'}, {"test1", 1, NULL, '1'}, {"test2", 1, NULL, '2'}, {"test3", 1, NULL, '3'}, {"test4", 1, NULL, '4'}, {0, 0, 0, 0} }; simulator_ *simulator = NULL; char *outFileName = NULL; FILE *outFile = stdout; double R, dc, Z0, Td, loss; double *data; char **variables; int numPoints, numVariables, i; double pulseD[7] = { 0, 10, 10e-9, 2e-9, 3e-9, 5e-9, 20e-9 }; double *pulse[7] = { &pulseD[0], &pulseD[1], &pulseD[2], &pulseD[3], &pulseD[4], &pulseD[5], &pulseD[6] }; double gaussD[7] = { 0, 3.3, 2e-9, 1e-9, 0.5e-9, 5e-9, 12e-9 }; double *gauss[7] = { &gaussD[0], &gaussD[1], &gaussD[2], &gaussD[3], &gaussD[4], &gaussD[5], &gaussD[6] }; /* Process the command line options */ while((opt = getopt_long(argc,argv,"hvae:l:01234o:",longopts,NULL)) != -1) { switch(opt) { case '0': /* Create a new simulator object */ simulator = simulatorNew(simulator); ExitFailureIf(simulator == NULL); R = 10; dc = 10; ExitFailureIf(simulatorAddResistor(simulator, "R1", "n1", "0", &R)); ExitFailureIf(simulatorAddSource(simulator, "V1", "n1", "0",'v', &dc, 0x0, NULL)); ExitFailureIf(simulatorRunOperatingPoint(simulator, &data, &variables, &numPoints, &numVariables)); print(outFile, data, variables, numVariables); /* Destroy the Scripter Object */ if(simulatorDestroy(&simulator)) { Warn("Failed to close simulator"); } free(data); free(variables); break; case '1': /* Create a new simulator object */ simulator = simulatorNew(simulator); ExitFailureIf(simulator == NULL); R = 10; Z0 = 50; Td = 15e-9; loss = 0.2; ExitFailureIf(simulatorAddResistor(simulator, "R1", "n1", "n2", &R)); ExitFailureIf(simulatorAddSource(simulator, "V1", "n1", "0",'v', NULL, 'p', pulse)); ExitFailureIf(simulatorAddTLine(simulator, "T2", "n2", "0", "n3", "0", &Z0, &Td, &loss)); ExitFailureIf(simulatorRunTransient(simulator, 0.1e-9, 50e-9, 0.0, 0, &data, &variables, &numPoints, &numVariables)); plot(outFile, data, variables, numPoints, numVariables); /* Destroy the Scripter Object */ if(simulatorDestroy(&simulator)) { Warn("Failed to close simulator"); } free(data); free(variables); break; case '2': /* Create a new simulator object */ simulator = simulatorNew(simulator); ExitFailureIf(simulator == NULL); R = 10; Z0 = 50; Td = 15e-9; loss = 0.2; ExitFailureIf(simulatorAddResistor(simulator, "R1", "n1", "n2", &R)); ExitFailureIf(simulatorAddSource(simulator, "V1", "n1", "0",'v', NULL, 'p', pulse)); ExitFailureIf(simulatorAddTLine(simulator, "T2", "n2", "0", "n3", "0", &Z0, &Td, &loss)); for(i = 0; i < 100; i++) { ExitFailureIf(simulatorRunTransient(simulator, 0.1e-9, 50e-9, 0.0, 0, &data, &variables, &numPoints, &numVariables)); } //plot(outFile, data, variables, numPoints, numVariables); /* Destroy the Scripter Object */ if(simulatorDestroy(&simulator)) { Warn("Failed to close simulator"); } free(data); free(variables); break; case '3': /* Create a new simulator object */ simulator = simulatorNew(simulator); ExitFailureIf(simulator == NULL); double L0[4] = {231.832e-9, 38.1483e-9, 38.1483e-9, 231.819e-9}; double *L0p = L0; double C0[4] = {156.163e-12, -8.60102e-12,-8.60102e-12, 156.193e-12}; double *C0p = C0; double R0[4] = {0.861113, 0, 0, 0.861113}; double *R0p = R0; double G0[4] = {0,0,0,0}; double *G0p = G0; double Rs[4] = {0.368757e-3, 0,0, 0.368757e-3}; double *Rsp = Rs; double Gd[4] = {0,0,0,0}; double *Gdp = Gd; char *nodes[6] = {"1", "3", "0", "2", "4", "0"}; int M = 9; double len = 0.0265; double fgd = 1e100; double fK = 1e9; ExitFailureIf(simulatorAddResistor(simulator, "R1", "n1", "n2", &R)); ExitFailureIf(simulatorAddSource(simulator, "V1", "n1", "0",'v', NULL, 'p', pulse)); ExitFailureIf(simulatorAddTLineW(simulator, "T1", nodes, 6, &M, &len, &L0p, &C0p, &R0p, &G0p, &Rsp, &Gdp, &fgd, &fK)); /* Destroy the Scripter Object */ if(simulatorDestroy(&simulator)) { Warn("Failed to close simulator"); } //free(data); //free(variables); break; case '4': /* Create a new simulator object */ simulator = simulatorNew(simulator); ExitFailureIf(simulator == NULL); ExitFailureIf(simulatorAddSource(simulator, "V1", "n1", "0",'v', NULL, 'g', gauss)); ExitFailureIf(simulatorRunTransient(simulator, 0.01e-9, 50e-9, 0.0, 0, &data, &variables, &numPoints, &numVariables)); plot(outFile, data, variables, numPoints, numVariables); /* Destroy the Scripter Object */ if(simulatorDestroy(&simulator)) { Warn("Failed to close simulator"); } free(data); free(variables); break; case 'a': case 'v': version(); ExitSuccess; case 'o': outFileName = optarg; outFile = fopen(outFileName, "wb"); ExitFailureIf(outFile == NULL, "Failed to open %s for output", outFileName); break; case 'e': OpenErrorFile(optarg); break; case 'l': OpenLogFile(optarg); break; case 'h': help(); ExitSuccess; case '?': ExitFailure("Unkown option"); case ':': ExitFailure("Option needs a value"); default: help(); ExitFailure("Invalid option"); } } if(outFileName != NULL) { fclose(outFile); } CloseErrorFile; CloseLogFile; ExitSuccess; }