static void initialize() { struct ts_parsed_s *input_buffer; FILE *input; use_enthalpy = 1; constants_init(); time_increment = 1./5000.; ts_parse_init(); scio_init(scio_input, sizeof (scio_input) / sizeof (scio_input[0])); /* * Read until EOF */ input = stdin; input_buffer = NULL; for (;;) { input_buffer = ts_parse(input, input_buffer); if (!input_buffer) break; scio_input_line(input_buffer); } scio_term(); pressure_init += atmosphere_pressure; pressure_final += atmosphere_pressure; }
int main(int argc, char *argv[0]) { if(argc < 2 || argc > 4) { printf("Usage: xcsf inputfile [MaxTrials] [NumExp]\n"); exit(EXIT_FAILURE); } // initialise environment constants_init(argc, argv); random_init(); func_init(argv[1]); gen_outfname(argv[1]); // run experiments double err[PERF_AVG_TRIALS]; double terr[PERF_AVG_TRIALS]; for(int e = 1; e < NUM_EXPERIMENTS+1; e++) { printf("\nExperiment: %d\n", e); pop_init(); outfile_init(e); // each trial in an experiment for(int cnt = 0; cnt < MAX_TRIALS; cnt++) { trial(cnt, true, err); // train trial(cnt, false, terr);// test // display performance if(cnt%PERF_AVG_TRIALS == 0 && cnt > 0) disp_perf(err, terr, cnt, pop_num); } // clean up set_kill(&pset); outfile_close(); } func_free(); return EXIT_SUCCESS; }
static void initialize() { constants_init(); set_default_parameters(); parse_input(); parameter_setup(); sim_init(); simple_tank_fill(); }
int test_constants_new(void) { Constants * c = constants_new(); constants_set_defaults(c); constants_init(c,0.01); constants_print_xml(c,(PrintFunc)fprintf,stdout); constants_delete(c); return 1; }
static void initialize() { struct ts_parsed_s *input_buffer; FILE *input; constants_init(); fuel_init(); chamber_init(); ts_parse_init(); scio_init(scio_input, sizeof (scio_input) / sizeof (scio_input[0])); /* * Read until EOF */ input = stdin; input_buffer = NULL; for (;;) { input_buffer = ts_parse(input, input_buffer); if (!input_buffer) break; scio_input_line(input_buffer); } scio_term(); injector_area = pi/4. * injectordia * injectordia; injector_count = 1; nozzle_throat_area = pi/4. * noz_t_dia * noz_t_dia; nozzle_exit_area = pi/4. * noz_e_dia * noz_e_dia; /* * calculate the mass of fuel remaining. */ grain_diameter = grain_core + .002; fuel_mass = fuel_density * pi / 4. * grain_length * (grain_diameter * grain_diameter - grain_core * grain_core); /*xxx*/if(0)chamber_pressure = 240 * 6894.7573; }
int main( int argc, char * * argv, char * * arg_environ ) { int n; char * s; struct bjam_option optv[N_OPTS]; char const * all = "all"; int status; int arg_c = argc; char * * arg_v = argv; char const * progname = argv[0]; module_t * environ_module; #if defined(unix) || defined(__unix) sigset_t sigmask; struct sigaction sa; sigemptyset(&sigmask); sigaddset(&sigmask, SIGCHLD); sigprocmask(SIG_BLOCK, &sigmask, NULL); sa.sa_flags = 0; sa.sa_handler = child_sig_handler; sigemptyset(&sa.sa_mask); sigaction(SIGCHLD, &sa, NULL); sigemptyset(&empty_sigmask); #endif saved_argv0 = argv[0]; BJAM_MEM_INIT(); # ifdef OS_MAC InitGraf(&qd.thePort); # endif --argc; ++argv; if ( getoptions( argc, argv, "-:l:m:d:j:p:f:gs:t:ano:qv", optv ) < 0 ) { printf( "\nusage: %s [ options ] targets...\n\n", progname ); printf( "-a Build all targets, even if they are current.\n" ); printf( "-dx Set the debug level to x (0-9).\n" ); printf( "-fx Read x instead of Jambase.\n" ); /* printf( "-g Build from newest sources first.\n" ); */ printf( "-jx Run up to x shell commands concurrently.\n" ); printf( "-lx Limit actions to x number of seconds after which they are stopped.\n" ); printf( "-mx Limit action output buffer to x kb's of data, after which action output is read and ignored.\n" ); printf( "-n Don't actually execute the updating actions.\n" ); printf( "-ox Write the updating actions to file x.\n" ); printf( "-px x=0, pipes action stdout and stderr merged into action output.\n" ); printf( "-q Quit quickly as soon as a target fails.\n" ); printf( "-sx=y Set variable x=y, overriding environment.\n" ); printf( "-tx Rebuild x, even if it is up-to-date.\n" ); printf( "-v Print the version of jam and exit.\n" ); printf( "--x Option is ignored.\n\n" ); exit( EXITBAD ); } /* Version info. */ if ( ( s = getoptval( optv, 'v', 0 ) ) ) { printf( "Boost.Jam " ); printf( "Version %s. %s.\n", VERSION, OSMINOR ); printf( " Copyright 1993-2002 Christopher Seiwald and Perforce Software, Inc. \n" ); printf( " Copyright 2001 David Turner.\n" ); printf( " Copyright 2001-2004 David Abrahams.\n" ); printf( " Copyright 2002-2008 Rene Rivera.\n" ); printf( " Copyright 2003-2008 Vladimir Prus.\n" ); return EXITOK; } /* Pick up interesting options. */ if ( ( s = getoptval( optv, 'n', 0 ) ) ) globs.noexec++, globs.debug[2] = 1; if ( ( s = getoptval( optv, 'p', 0 ) ) ) { /* Undocumented -p3 (acts like both -p1 -p2) means separate pipe action * stdout and stderr. */ globs.pipe_action = atoi( s ); if ( ( 3 < globs.pipe_action ) || ( globs.pipe_action < 0 ) ) { printf( "Invalid pipe descriptor '%d', valid values are -p[0..3].\n", globs.pipe_action ); exit( EXITBAD ); } } if ( ( s = getoptval( optv, 'q', 0 ) ) ) globs.quitquick = 1; if ( ( s = getoptval( optv, 'a', 0 ) ) ) anyhow++; if ( ( s = getoptval( optv, 'j', 0 ) ) ) { globs.jobs = atoi( s ); if (globs.jobs == 0) { printf("Invalid value for the '-j' option.\n"); exit(EXITBAD); } } if ( ( s = getoptval( optv, 'g', 0 ) ) ) globs.newestfirst = 1; if ( ( s = getoptval( optv, 'l', 0 ) ) ) globs.timeout = atoi( s ); if ( ( s = getoptval( optv, 'm', 0 ) ) ) globs.maxbuf = atoi( s ) * 1024; /* Turn on/off debugging */ for ( n = 0; ( s = getoptval( optv, 'd', n ) ); ++n ) { int i; /* First -d, turn off defaults. */ if ( !n ) for ( i = 0; i < DEBUG_MAX; ++i ) globs.debug[i] = 0; i = atoi( s ); if ( ( i < 0 ) || ( i >= DEBUG_MAX ) ) { printf( "Invalid debug level '%s'.\n", s ); continue; } /* n turns on levels 1-n. */ /* +n turns on level n. */ if ( *s == '+' ) globs.debug[i] = 1; else while ( i ) globs.debug[i--] = 1; } constants_init(); { PROFILE_ENTER( MAIN ); #ifdef HAVE_PYTHON { PROFILE_ENTER( MAIN_PYTHON ); Py_Initialize(); { static PyMethodDef BjamMethods[] = { {"call", bjam_call, METH_VARARGS, "Call the specified bjam rule."}, {"import_rule", bjam_import_rule, METH_VARARGS, "Imports Python callable to bjam."}, {"define_action", bjam_define_action, METH_VARARGS, "Defines a command line action."}, {"variable", bjam_variable, METH_VARARGS, "Obtains a variable from bjam's global module."}, {"backtrace", bjam_backtrace, METH_VARARGS, "Returns bjam backtrace from the last call into Python."}, {"caller", bjam_caller, METH_VARARGS, "Returns the module from which the last call into Python is made."}, {NULL, NULL, 0, NULL} }; Py_InitModule( "bjam", BjamMethods ); } PROFILE_EXIT( MAIN_PYTHON ); } #endif #ifndef NDEBUG run_unit_tests(); #endif #if YYDEBUG != 0 if ( DEBUG_PARSE ) yydebug = 1; #endif /* Set JAMDATE. */ var_set( root_module(), constant_JAMDATE, list_new( L0, outf_time(time(0)) ), VAR_SET ); /* Set JAM_VERSION. */ var_set( root_module(), constant_JAM_VERSION, list_new( list_new( list_new( L0, object_new( VERSION_MAJOR_SYM ) ), object_new( VERSION_MINOR_SYM ) ), object_new( VERSION_PATCH_SYM ) ), VAR_SET ); /* Set JAMUNAME. */ #if defined(unix) || defined(__unix) { struct utsname u; if ( uname( &u ) >= 0 ) { var_set( root_module(), constant_JAMUNAME, list_new( list_new( list_new( list_new( list_new( L0, object_new( u.sysname ) ), object_new( u.nodename ) ), object_new( u.release ) ), object_new( u.version ) ), object_new( u.machine ) ), VAR_SET ); } } #endif /* unix */ /* Load up environment variables. */ /* First into the global module, with splitting, for backward * compatibility. */ var_defines( root_module(), use_environ, 1 ); environ_module = bindmodule( constant_ENVIRON ); /* Then into .ENVIRON, without splitting. */ var_defines( environ_module, use_environ, 0 ); /* * Jam defined variables OS & OSPLAT. We load them after environment, so * that setting OS in environment does not change Jam's notion of the * current platform. */ var_defines( root_module(), othersyms, 1 ); /* Load up variables set on command line. */ for ( n = 0; ( s = getoptval( optv, 's', n ) ); ++n ) { char *symv[2]; symv[ 0 ] = s; symv[ 1 ] = 0; var_defines( root_module(), symv, 1 ); var_defines( environ_module, symv, 0 ); } /* Set the ARGV to reflect the complete list of arguments of invocation. */ for ( n = 0; n < arg_c; ++n ) { var_set( root_module(), constant_ARGV, list_new( L0, object_new( arg_v[n] ) ), VAR_APPEND ); } /* Initialize built-in rules. */ load_builtins(); /* Add the targets in the command line to the update list. */ for ( n = 1; n < arg_c; ++n ) { if ( arg_v[ n ][ 0 ] == '-' ) { char * f = "-:l:d:j:f:gs:t:ano:qv"; for ( ; *f; ++f ) if ( *f == arg_v[ n ][ 1 ] ) break; if ( ( f[ 1 ] == ':' ) && ( arg_v[ n ][ 2 ] == '\0' ) ) ++n; } else { OBJECT * target = object_new( arg_v[ n ] ); mark_target_for_updating( target ); object_free( target ); } } if (!targets_to_update()) { mark_target_for_updating( constant_all ); } /* Parse ruleset. */ { FRAME frame[ 1 ]; frame_init( frame ); for ( n = 0; ( s = getoptval( optv, 'f', n ) ); ++n ) { OBJECT * filename = object_new( s ); parse_file( filename, frame ); object_free( filename ); } if ( !n ) { parse_file( constant_plus, frame ); } } status = yyanyerrors(); /* Manually touch -t targets. */ for ( n = 0; ( s = getoptval( optv, 't', n ) ); ++n ) { OBJECT * target = object_new( s ); touch_target( target ); object_free( target ); } /* If an output file is specified, set globs.cmdout to that. */ if ( ( s = getoptval( optv, 'o', 0 ) ) ) { if ( !( globs.cmdout = fopen( s, "w" ) ) ) { printf( "Failed to write to '%s'\n", s ); exit( EXITBAD ); } ++globs.noexec; } /* The build system may set the PARALLELISM variable to override -j options. */ { LIST *p = L0; p = var_get ( root_module(), constant_PARALLELISM ); if ( p ) { int j = atoi( object_str( p->value ) ); if ( j == -1 ) { printf( "Invalid value of PARALLELISM: %s\n", object_str( p->value ) ); } else { globs.jobs = j; } } } /* KEEP_GOING overrides -q option. */ { LIST *p = L0; p = var_get( root_module(), constant_KEEP_GOING ); if ( p ) { int v = atoi( object_str( p->value ) ); if ( v == 0 ) globs.quitquick = 1; else globs.quitquick = 0; } } /* Now make target. */ { PROFILE_ENTER( MAIN_MAKE ); LIST * targets = targets_to_update(); if (targets) { int targets_count = list_length( targets ); OBJECT * * targets2 = (OBJECT * *) BJAM_MALLOC( targets_count * sizeof( OBJECT * ) ); int n = 0; for ( ; targets; targets = list_next( targets ) ) targets2[ n++ ] = targets->value; status |= make( targets_count, targets2, anyhow ); BJAM_FREE( (void *)targets2 ); } else { status = last_update_now_status; } PROFILE_EXIT( MAIN_MAKE ); } PROFILE_EXIT( MAIN ); } if ( DEBUG_PROFILE ) profile_dump(); #ifdef OPT_HEADER_CACHE_EXT hcache_done(); #endif clear_targets_to_update(); /* Widely scattered cleanup. */ file_done(); rules_done(); stamps_done(); search_done(); class_done(); modules_done(); regex_done(); exec_done(); pwd_done(); path_done(); function_done(); list_done(); constants_done(); object_done(); /* Close cmdout. */ if ( globs.cmdout ) fclose( globs.cmdout ); #ifdef HAVE_PYTHON Py_Finalize(); #endif BJAM_MEM_CLOSE(); return status ? EXITBAD : EXITOK; }
void ddafile_read_original_analysis(void * userdata, char * af, int nfp, int pc, int nlp) { Analysisdata * adn = (Analysisdata*)userdata; FILE * analysisFile; int i, j, n7, n8; int jointmat; /* Loop counter to initialize joint materials matrix. */ double ** materialProps; double ** phiCohesion; double ** timeDeps; int i1; Constants * constants; int nFPoints = nfp; int pointCount = pc; int nLPoints = nlp; /**************************************************/ /* k5: index of u0 >=2 time points */ /* k5: 0 start of point i 1 end of point i */ /* k5[nFPoints+nLPoints+1][2] */ int **k5; /*------------------------------------------------*/ /* c : movement u v of fixed measured load points */ /* c[pointCount+1][3] */ double **c; /**************************************************/ /* k5: index of u0 >=2 time points */ /* k5: 0 start of point i 1 end of point i */ /* k5[nFPoints+nLPoints+1][2] */ adn->k5size1 = nFPoints+nLPoints+1; adn->k5size2 = 2; k5 = IntMat2DGetMem(adn->k5size1, adn->k5size2); /* c : movement u v of fixed measured load points */ /* c[pointCount+1][3] */ /* It appears that c[][] is used as a flag in * analysisreader(2) to indicate when to read in values * for time dependent properties, then later used to * record movement of measured, fixed, and load * points. */ n7=pointCount+1; n8=3; adn->csize1 = n7; c = DoubMat2DGetMem(n7, n8); analysisFile = fopen(af, "r"); fscanf(analysisFile,"%d",&adn->analysistype); fscanf(analysisFile,"%d", &adn->nTimeSteps); fscanf(analysisFile,"%d", &adn->nBlockMats); fscanf(analysisFile,"%d", &adn->nJointMats); fscanf(analysisFile,"%lf",&adn->maxdisplacement); fscanf(analysisFile,"%lf",&adn->maxtimestep); /* reads value but ignores it! */ /* Save the following for reimplementation of time- * dependent parameters. */ /* dynamic diplacement and loading input */ /* k5[i][0] >= 2 */ for (i=1; i<= nFPoints+nLPoints; i++) { /* What this means is that the c matrix is always set * to unity in the next loop. */ k5[i][0] = 0; /* no time-dependent loads or displacements */ } /* i */ /* (GHS: k5[i][0]=0 fixed points c[i][0]=1 flag) */ for (i=1; i<= nFPoints+nLPoints; i++) { if (k5[i][0] == 0) { c[i][0]=1; k5[i][0]=2; } else { c[i][0] = 0; } } /* (GHS: k5[i][0] start k5[i][1] end) */ i1=0; for (i=1; i<= nFPoints+nLPoints; i++) { i1 += k5[i][0]; k5[i][1] = i1; k5[i][0] = k5[i][1] - k5[i][0] + 1; } /* i */ /* Set nt to the accumulated value... */ adn->nt=k5[nFPoints+nLPoints][1]; /**************************************************/ /* u0: t x y of time dependent displacements */ /* u0: t x y of time dependent loading */ /* u0[nt+1][3] */ //n7=adn->nt+1; //n8=3; //timeDeps = DoubMat2DGetMem(n7, n8); adn->timedepsize1=adn->nt+1; adn->timedepsize2=3; timeDeps = DoubMat2DGetMem(adn->timedepsize1, adn->timedepsize1); /**************************************************/ /* ma we e0 u0 s11 s22 s12 t11 t22 t12 vx vy vr */ /* a0[nb+1][13] */ /* n7=adn->nBlockMats+1; n8=13; */ n7 = adn->materialpropsize1 = adn->nBlockMats + 1; n8 = adn->materialpropsize2 = 13; materialProps = DoubMat2DGetMem(n7,n8); /*------------------------------------------------*/ /* b0: 0 friction 1 cohesion 2 tension */ /* b0[nJointMats+1][3] */ n7=adn->nJointMats+1; n8=3; adn->phicohesionsize1 = n7; adn->phicohesionsize2 = n8; phiCohesion = DoubMat2DGetMem(n7, n8); /**************************************************/ /* u0: t x y of time dependent displacements */ /* u0: t x y of time dependent loading */ /* u0[nt+1][3] */ i1 = 0; for (i=1; i<=nFPoints+nLPoints; i++) { //if (c[i][0] < 0.5) // goto a201; /* Since displacement dependent properties are not * implemented in this version, the following if statement * is always evaluated, the else is never reached. */ if(c[i][0] >= 0.5) { i1 += 1; timeDeps[i1][0] = 0; timeDeps[i1][1] = 0; timeDeps[i1][2] = 0; i1 += 1; timeDeps[i1][0] = 100000; timeDeps[i1][1] = 0; timeDeps[i1][2] = 0; } else { for (j=k5[i][0]; j<=k5[i][1]; j++) { i1 += 1; fscanf(analysisFile,"%lf %lf %lf", &timeDeps[i1][0],&timeDeps[i1][1],&timeDeps[i1][2]); } /* j */ } } /* i */ /* ma we e0 u0 s11 s22 s12 t11 t22 t12 vx vy vr */ /* Note that the dimension of a is * [number of block (types?)][13]. */ for (i=1; i<= adn->nBlockMats; i++) { /* Read in the properties for a single block (type?). */ for (j=0; j < 13; j++) { fscanf(analysisFile,"%lf",&materialProps[i][j]); } /* j */ } /* i */ /* friction-angle cohesion tension-strength */ /* nJointMats probably is the number of JOINT TYPES, not the * number of JOINTS!!!! */ for (jointmat=1; jointmat<= adn->nJointMats; jointmat++) { fscanf(analysisFile,"%lf %lf %lf", &phiCohesion[jointmat][0], &phiCohesion[jointmat][1],&phiCohesion[jointmat][2]); } /* i */ fclose(analysisFile); adn->timeDeps = timeDeps; adn->materialProps = materialProps; adn->phiCohesion = phiCohesion; adn->tindex = k5; /* Get rid of c */ adn->c = c; /* Kludge kludge kludge: The original file format has no * notion of constant time step. */ adn->autotimestepflag = 1; adn->autopenaltyflag = 1; /* The ddaml file allows the penalty number to be * be adjusted. Since this one does not, we need * to set the multiplier explicitly. */ adn->pfactor = 50.0; adn->gravaccel = adn->materialProps[1][1]/adn->materialProps[1][0]; constants = constants_new(); constants_init(constants,adn->maxdisplacement); adn->constants = constants; } /* Close analysisReader1() */
int main( int argc, char *argv[] ) { time_t curtime; struct tm *loctime; int value, code; char * d, *d1; char * sourcefile = 0; char basepathname[__MAX_PATH] = ""; char dcbname[__MAX_PATH] = ""; char stubname[__MAX_PATH] = ""; char importname[__MAX_PATH] = ""; char compilerimport[__MAX_PATH] = ""; int i, j; char *ptr; /* get my executable name */ ptr = argv[0] + strlen( argv[0] ); while ( ptr > argv[0] && ptr[-1] != '\\' && ptr[-1] != '/' ) ptr-- ; appexename = strdup( ptr ); /* get executable full pathname */ appexefullpath = getfullpath( argv[0] ); if ( ( !strchr( argv[0], '\\' ) && !strchr( argv[0], '/' ) ) && !file_exists( appexefullpath ) ) { char *p = whereis( appexename ); if ( p ) { char * tmp = calloc( 1, strlen( p ) + strlen( appexename ) + 2 ); free( appexefullpath ); sprintf( tmp, "%s/%s", p, appexename ); appexefullpath = getfullpath( tmp ); free( tmp ); } } /* get pathname of executable */ ptr = strstr( appexefullpath, appexename ); appexepath = calloc( 1, ptr - appexefullpath + 1 ); strncpy( appexepath, appexefullpath, ptr - appexefullpath ); printf( BGDC_VERSION "\n" "Bennu Game Development Compiler\n" "\n" "Copyright (c) 2006-2016 SplinterGU (Fenix/BennuGD)\n" "Copyright (c) 2002-2006 Fenix Team (Fenix)\n" "Copyright (c) 1999-2002 José Luis Cebrián Pagüe (Fenix)\n" "\n" ); /* Default lang to EN */ strcpy( langinfo, "EN" ); /* LANG detect */ #ifdef WIN32 GetLocaleInfo( LOCALE_USER_DEFAULT, LOCALE_SABBREVCTRYNAME, langinfo, 64 ); strlwr( langinfo ); #else if ( getenv( "LANG" ) != NULL && strlen( getenv( "LANG" ) ) >= 2 ) strcpy( langinfo, getenv( "LANG" ) ); #endif langinfo[2] = 0; srand( time( NULL ) ); /* build error messages list */ err_buildErrorTable(); init_c_type(); identifier_init(); constants_init(); string_init(); compile_init(); mainproc = procdef_new( procdef_getid(), identifier_search_or_add( "MAIN" ) ) ; /* Init vars */ char tmp_version[ 32 ]; sprintf( tmp_version, "\"%s\"", VERSION ); add_simple_define( "COMPILER_VERSION", tmp_version ); add_simple_define( "__VERSION__", tmp_version ); curtime = time( NULL ); /* Get the current time. */ loctime = localtime( &curtime ); /* Convert it to local time representation. */ strftime( timebuff, sizeof( timebuff ), "%Y/%m/%d", loctime ); value = string_new( timebuff ); code = identifier_search_or_add( "__DATE__" ) ; constants_add( code, typedef_new( TYPE_STRING ), value ) ; strftime( timebuff, sizeof( timebuff ), "%H:%M:%S", loctime ); value = string_new( timebuff ); code = identifier_search_or_add( "__TIME__" ) ; constants_add( code, typedef_new( TYPE_STRING ), value ) ; /* value = string_new( VERSION ); code = identifier_search_or_add( "__VERSION__" ) ; constants_add( code, typedef_new( TYPE_STRING ), value ) ; code = identifier_search_or_add( "COMPILER_VERSION" ) ; constants_add( code, typedef_new( TYPE_STRING ), value ) ; */ strcpy( _tmp, VERSION ); d = strchr( _tmp, '.' ); *d = '\0'; add_simple_define( "__BGD__", _tmp ); d1 = d + 1; d = strchr( d1, '.' ); *d = '\0'; add_simple_define( "__BGD_MINOR__", d1 ); d1 = d + 1; add_simple_define( "__BGD_PATCHLEVEL__", d1 ); memset( &dcb, 0, sizeof( dcb ) ); core_init(); sysproc_init(); /* Get command line parameters */ for ( i = 1 ; i < argc ; i++ ) { if ( argv[i][0] == '-' ) { if ( !strcmp( argv[i], "--pedantic" ) ) { autodeclare = 0 ; continue; } if ( !strcmp( argv[i], "--libmode" ) ) { libmode = 1 ; continue; } j = 1; while ( argv[i][j] ) { if ( argv[i][j] == 'd' ) { if ( argv[i][j + 1] >= '0' && argv[i][j + 1] <= '9' ) { debug = atoi( &argv[i][j + 1] ); } else { debug = 1; } } if ( argv[i][j] == 'o' ) { if ( argv[i][j + 1] ) strncpy( dcbname, &argv[i][j + 1], sizeof( dcbname ) ); else if ( argv[i + 1] && argv[i + 1][0] != '-' ) strncpy( dcbname, argv[++i], sizeof( dcbname ) ); break; } if ( argv[i][j] == 'c' ) dos_chars = 1; if ( argv[i][j] == 'a' ) autoinclude = 1; if ( argv[i][j] == 'g' ) dcb_options |= DCB_DEBUG; if ( argv[i][j] == 'p' ) autodeclare = 0 ; if ( argv[i][j] == 's' ) { /* -s "stub": Use a stub */ if ( argv[i][j + 1] ) strncpy( stubname, &argv[i][j + 1], __MAX_PATH ); else if ( argv[i + 1] && argv[i + 1][0] != '-' ) strncpy( stubname, argv[++i], __MAX_PATH ); break; } if ( argv[i][j] == 'f' ) { /* -f "file": Embed a file to the DCB */ if ( argv[i][j + 1] ) dcb_add_file( &argv[i][j + 1] ); else while ( argv[i + 1] ) { if ( argv[i + 1][0] == '-' ) break; dcb_add_file( argv[i + 1] ); i++; } break; } if ( argv[i][j] == 'i' ) { /* -i "path": add a file to the path for include files */ if ( argv[i][j + 1] == 0 ) { if ( i == argc - 1 ) { printf( MSG_DIRECTORY_MISSING "\n" ); exit( 1 ); } file_addp( argv[i + 1] ); i++; break; } file_addp( &argv[i][j + 1] ); break; } if ( argv[i][j] == 'l' ) { /* -lLANG: Set the language for errors and messages */ if ( argv[i][j + 1] == 0 ) { if ( i != argc - 1 ) { strcpy( langinfo, argv[i + 1] ); } i++; break; } strcpy( langinfo, &argv[i][j + 1] ); break; } if ( argv[i][j] == 'D' ) { char * macro = NULL ; char * text = NULL ; /* -D<macro>=<text> */ if ( argv[i][j + 1] ) { macro = strdup( &argv[i][j + 1] ); } else { if ( argv[i + 1][0] == '-' ) break; macro = strdup( argv[i + 1] ); i++; } if (( text = strchr( macro, '=' ) ) ) { * text = '\0'; text++; } else { text = ""; } add_simple_define( macro, text ); free( macro ); break; } if ( argv[i][j] == 'C' ) { if ( argv[i][j + 1] == 'a' ) autodeclare = 1 ; break; } if ( argv[i][j] == 'L' ) { int r = 1; char * f; if ( argv[i][j + 1] ) r = dcb_load_lib( ( f = &argv[i][j + 1] ) ); else if ( argv[i + 1] && argv[i + 1][0] != '-' ) { r = dcb_load_lib( ( f = argv[i + 1] ) ); i++; } switch ( r ) { case 0: printf( "ERROR: %s doesn't exist or isn't version DCB compatible\n", f ) ; exit( -1 ); case -1: printf( "ERROR: %s isn't 7.10 DCB version, you need a 7.10 version or greater for use this feature\n", f ) ; exit( -1 ); } break; } j++; } } else { /* if ( sourcefile ) { printf( MSG_TOO_MANY_FILES "\n" ); return 0; } */ char * p, * pathend = NULL; sourcefile = argv[i]; p = main_path = strdup( argv[i] ); while ( p && *p ) { if ( *p == ':' || *p == '\\' || *p == '/' ) pathend = p; p++; } if ( pathend ) { *( pathend + 1 ) = '\0'; file_addp( main_path ); } else { free( main_path ); main_path = getcwd(malloc(__MAX_PATH), __MAX_PATH); strcat(main_path, PATH_SEP); } /* Files names */ strcpy( basepathname, sourcefile ); REMOVE_EXT( basepathname ); /* Default compiler imports */ strcpy( compilerimport, argv[0] ); #ifdef WIN32 REMOVE_EXT( compilerimport ); #endif strcat( compilerimport, ".imp" ); import_files( compilerimport ); strcat( compilerimport, "ort" ); /* name.import */ import_files( compilerimport ); /* Project imports */ strcpy( importname, basepathname ); strcat( importname, ".imp" ); import_files( importname ); strcat( importname, "ort" ); /* name.import */ import_files( importname ); /* Load Main Source File */ load_file( sourcefile ); if ( !dcbname[0] ) { strcpy( dcbname, basepathname ); strcat( dcbname, !libmode ? ".dcb" : ".dcl" ); } } } if ( !sourcefile ) { printf( MSG_USING MSG_OPTION_D MSG_OPTIONS MSG_LICENSE, argv[0] ); return 0; } compile_program(); if ( stubname[0] != 0 ) { if ( !file_exists( stubname ) ) { #ifdef WIN32 char exepath[__MAX_PATH]; GetModuleFileName( NULL, exepath, sizeof( exepath ) ); PathRemoveFileSpec( exepath ); strcat( exepath, "\\" ); memmove( stubname + strlen( exepath ), stubname, strlen( stubname ) + 1 ); memcpy( stubname, exepath, strlen( exepath ) ); #else const char * ptr = argv[0] + strlen( argv[0] ); while ( ptr > argv[0] && *ptr != '\\' && *ptr != '/' ) ptr--; if ( *ptr == '\\' || *ptr == '/' ) ptr++; if ( ptr > argv[0] ) { memmove( stubname + ( ptr - argv[0] ), stubname, strlen( stubname ) + 1 ); memcpy( stubname, argv[0], ptr - argv[0] ); } #endif if ( !file_exists( stubname ) ) { #ifdef WIN32 strcat( stubname, ".exe" ); if ( !file_exists( stubname ) ) { #endif compile_error( "Can't open stub file %s", stubname ); #ifdef WIN32 return -1; } #endif } } REMOVE_EXT( dcbname ); #ifdef WIN32 strcat( dcbname, ".exe" ); #endif dcb_save( dcbname, dcb_options, stubname ); } else { dcb_save( dcbname, dcb_options, NULL ); } /* destroy error messages list */ err_destroyErrorTable(); return 1; }
int main( int argc, char * * argv, char * * arg_environ ) { int n; char * s; struct bjam_option optv[ N_OPTS ]; char const * all = "all"; int status; int arg_c = argc; char * * arg_v = argv; char const * progname = argv[ 0 ]; module_t * environ_module; saved_argv0 = argv[ 0 ]; BJAM_MEM_INIT(); #ifdef OS_MAC InitGraf( &qd.thePort ); #endif --argc; ++argv; #ifdef HAVE_PYTHON #define OPTSTRING "-:l:m:d:j:p:f:gs:t:ano:qvz" #else #define OPTSTRING "-:l:m:d:j:p:f:gs:t:ano:qv" #endif if ( getoptions( argc, argv, OPTSTRING, optv ) < 0 ) { err_printf( "\nusage: %s [ options ] targets...\n\n", progname ); err_printf( "-a Build all targets, even if they are current.\n" ); err_printf( "-dx Set the debug level to x (0-9).\n" ); err_printf( "-fx Read x instead of Jambase.\n" ); /* err_printf( "-g Build from newest sources first.\n" ); */ err_printf( "-jx Run up to x shell commands concurrently.\n" ); err_printf( "-lx Limit actions to x number of seconds after which they are stopped.\n" ); err_printf( "-mx Maximum target output saved (kb), default is to save all output.\n" ); err_printf( "-n Don't actually execute the updating actions.\n" ); err_printf( "-ox Mirror all output to file x.\n" ); err_printf( "-px x=0, pipes action stdout and stderr merged into action output.\n" ); err_printf( "-q Quit quickly as soon as a target fails.\n" ); err_printf( "-sx=y Set variable x=y, overriding environment.\n" ); err_printf( "-tx Rebuild x, even if it is up-to-date.\n" ); err_printf( "-v Print the version of jam and exit.\n" ); #ifdef HAVE_PYTHON err_printf( "-z Disable Python Optimization and enable asserts\n" ); #endif err_printf( "--x Option is ignored.\n\n" ); exit( EXITBAD ); } /* Version info. */ if ( ( s = getoptval( optv, 'v', 0 ) ) ) { out_printf( "Boost.Jam Version %s. %s.\n", VERSION, OSMINOR ); out_printf( " Copyright 1993-2002 Christopher Seiwald and Perforce " "Software, Inc.\n" ); out_printf( " Copyright 2001 David Turner.\n" ); out_printf( " Copyright 2001-2004 David Abrahams.\n" ); out_printf( " Copyright 2002-2015 Rene Rivera.\n" ); out_printf( " Copyright 2003-2015 Vladimir Prus.\n" ); return EXITOK; } /* Pick up interesting options. */ if ( ( s = getoptval( optv, 'n', 0 ) ) ) { ++globs.noexec; globs.debug[ 2 ] = 1; } if ( ( s = getoptval( optv, 'p', 0 ) ) ) { /* Undocumented -p3 (acts like both -p1 -p2) means separate pipe action * stdout and stderr. */ globs.pipe_action = atoi( s ); if ( globs.pipe_action < 0 || 3 < globs.pipe_action ) { err_printf( "Invalid pipe descriptor '%d', valid values are -p[0..3]." "\n", globs.pipe_action ); exit( EXITBAD ); } } if ( ( s = getoptval( optv, 'q', 0 ) ) ) globs.quitquick = 1; if ( ( s = getoptval( optv, 'a', 0 ) ) ) anyhow++; if ( ( s = getoptval( optv, 'j', 0 ) ) ) { globs.jobs = atoi( s ); if ( globs.jobs < 1 || globs.jobs > MAXJOBS ) { err_printf( "Invalid value for the '-j' option, valid values are 1 " "through %d.\n", MAXJOBS ); exit( EXITBAD ); } } if ( ( s = getoptval( optv, 'g', 0 ) ) ) globs.newestfirst = 1; if ( ( s = getoptval( optv, 'l', 0 ) ) ) globs.timeout = atoi( s ); if ( ( s = getoptval( optv, 'm', 0 ) ) ) globs.max_buf = atoi( s ) * 1024; /* convert to kb */ #ifdef HAVE_PYTHON if ( ( s = getoptval( optv, 'z', 0 ) ) ) python_optimize = 0; /* disable python optimization */ #endif /* Turn on/off debugging */ for ( n = 0; ( s = getoptval( optv, 'd', n ) ); ++n ) { int i; /* First -d, turn off defaults. */ if ( !n ) for ( i = 0; i < DEBUG_MAX; ++i ) globs.debug[i] = 0; i = atoi( s ); if ( ( i < 0 ) || ( i >= DEBUG_MAX ) ) { out_printf( "Invalid debug level '%s'.\n", s ); continue; } /* n turns on levels 1-n. */ /* +n turns on level n. */ if ( *s == '+' ) globs.debug[ i ] = 1; else while ( i ) globs.debug[ i-- ] = 1; } /* If an output file is specified, set globs.out to that. */ if ( ( s = getoptval( optv, 'o', 0 ) ) ) { if ( !( globs.out = fopen( s, "w" ) ) ) { err_printf( "Failed to write to '%s'\n", s ); exit( EXITBAD ); } /* ++globs.noexec; */ } constants_init(); cwd_init(); { PROFILE_ENTER( MAIN ); #ifdef HAVE_PYTHON { PROFILE_ENTER( MAIN_PYTHON ); Py_OptimizeFlag = python_optimize; Py_Initialize(); { static PyMethodDef BjamMethods[] = { {"call", bjam_call, METH_VARARGS, "Call the specified bjam rule."}, {"import_rule", bjam_import_rule, METH_VARARGS, "Imports Python callable to bjam."}, {"define_action", bjam_define_action, METH_VARARGS, "Defines a command line action."}, {"variable", bjam_variable, METH_VARARGS, "Obtains a variable from bjam's global module."}, {"backtrace", bjam_backtrace, METH_VARARGS, "Returns bjam backtrace from the last call into Python."}, {"caller", bjam_caller, METH_VARARGS, "Returns the module from which the last call into Python is made."}, {NULL, NULL, 0, NULL} }; Py_InitModule( "bjam", BjamMethods ); } PROFILE_EXIT( MAIN_PYTHON ); } #endif #ifndef NDEBUG run_unit_tests(); #endif #if YYDEBUG != 0 if ( DEBUG_PARSE ) yydebug = 1; #endif /* Set JAMDATE. */ { timestamp current; timestamp_current( ¤t ); var_set( root_module(), constant_JAMDATE, list_new( outf_time( ¤t ) ), VAR_SET ); } /* Set JAM_VERSION. */ var_set( root_module(), constant_JAM_VERSION, list_push_back( list_push_back( list_new( object_new( VERSION_MAJOR_SYM ) ), object_new( VERSION_MINOR_SYM ) ), object_new( VERSION_PATCH_SYM ) ), VAR_SET ); /* Set JAMUNAME. */ #ifdef unix { struct utsname u; if ( uname( &u ) >= 0 ) { var_set( root_module(), constant_JAMUNAME, list_push_back( list_push_back( list_push_back( list_push_back( list_new( object_new( u.sysname ) ), object_new( u.nodename ) ), object_new( u.release ) ), object_new( u.version ) ), object_new( u.machine ) ), VAR_SET ); } } #endif /* unix */ /* Set JAM_TIMESTAMP_RESOLUTION. */ { timestamp fmt_resolution[ 1 ]; file_supported_fmt_resolution( fmt_resolution ); var_set( root_module(), constant_JAM_TIMESTAMP_RESOLUTION, list_new( object_new( timestamp_timestr( fmt_resolution ) ) ), VAR_SET ); } /* Load up environment variables. */ /* First into the global module, with splitting, for backward * compatibility. */ var_defines( root_module(), use_environ, 1 ); environ_module = bindmodule( constant_ENVIRON ); /* Then into .ENVIRON, without splitting. */ var_defines( environ_module, use_environ, 0 ); /* * Jam defined variables OS & OSPLAT. We load them after environment, so * that setting OS in environment does not change Jam's notion of the * current platform. */ var_defines( root_module(), othersyms, 1 ); /* Load up variables set on command line. */ for ( n = 0; ( s = getoptval( optv, 's', n ) ); ++n ) { char * symv[ 2 ]; symv[ 0 ] = s; symv[ 1 ] = 0; var_defines( root_module(), symv, 1 ); var_defines( environ_module, symv, 0 ); } /* Set the ARGV to reflect the complete list of arguments of invocation. */ for ( n = 0; n < arg_c; ++n ) var_set( root_module(), constant_ARGV, list_new( object_new( arg_v[ n ] ) ), VAR_APPEND ); /* Initialize built-in rules. */ load_builtins(); /* Add the targets in the command line to the update list. */ for ( n = 1; n < arg_c; ++n ) { if ( arg_v[ n ][ 0 ] == '-' ) { char * f = "-:l:d:j:f:gs:t:ano:qv"; for ( ; *f; ++f ) if ( *f == arg_v[ n ][ 1 ] ) break; if ( ( f[ 1 ] == ':' ) && ( arg_v[ n ][ 2 ] == '\0' ) ) ++n; } else { OBJECT * const target = object_new( arg_v[ n ] ); mark_target_for_updating( target ); object_free( target ); } } if ( list_empty( targets_to_update() ) ) mark_target_for_updating( constant_all ); /* Parse ruleset. */ { FRAME frame[ 1 ]; frame_init( frame ); for ( n = 0; ( s = getoptval( optv, 'f', n ) ); ++n ) { OBJECT * const filename = object_new( s ); parse_file( filename, frame ); object_free( filename ); } if ( !n ) parse_file( constant_plus, frame ); } status = yyanyerrors(); /* Manually touch -t targets. */ for ( n = 0; ( s = getoptval( optv, 't', n ) ); ++n ) { OBJECT * const target = object_new( s ); touch_target( target ); object_free( target ); } /* The build system may set the PARALLELISM variable to override -j * options. */ { LIST * const p = var_get( root_module(), constant_PARALLELISM ); if ( !list_empty( p ) ) { int const j = atoi( object_str( list_front( p ) ) ); if ( j < 1 || j > MAXJOBS ) out_printf( "Invalid value of PARALLELISM: %s. Valid values " "are 1 through %d.\n", object_str( list_front( p ) ), MAXJOBS ); else globs.jobs = j; } } /* KEEP_GOING overrides -q option. */ { LIST * const p = var_get( root_module(), constant_KEEP_GOING ); if ( !list_empty( p ) ) globs.quitquick = atoi( object_str( list_front( p ) ) ) ? 0 : 1; } /* Now make target. */ { PROFILE_ENTER( MAIN_MAKE ); LIST * const targets = targets_to_update(); if ( !list_empty( targets ) ) status |= make( targets, anyhow ); else status = last_update_now_status; PROFILE_EXIT( MAIN_MAKE ); } PROFILE_EXIT( MAIN ); } if ( DEBUG_PROFILE ) profile_dump(); #ifdef OPT_HEADER_CACHE_EXT hcache_done(); #endif clear_targets_to_update(); /* Widely scattered cleanup. */ property_set_done(); file_done(); rules_done(); timestamp_done(); search_done(); class_done(); modules_done(); regex_done(); cwd_done(); path_done(); function_done(); list_done(); constants_done(); object_done(); /* Close log out. */ if ( globs.out ) fclose( globs.out ); #ifdef HAVE_PYTHON Py_Finalize(); #endif BJAM_MEM_CLOSE(); return status ? EXITBAD : EXITOK; }