int main(int argc, char **argv) { if (argc != 4) usage(); depfile = argv[1]; target = argv[2]; cmdline = argv[3]; print_cmdline(); print_deps(); return 0; }
int main(int argc, char *argv[]) { traps(); if (argc == 5 && !strcmp(argv[1], "-e")) { insert_extra_deps = 1; argv++; } else if (argc != 4) usage(); depfile = argv[1]; target = argv[2]; cmdline = argv[3]; print_cmdline(); print_deps(); return 0; }
int main(int argc, char *argv[]) { traps(); if (argc != 4) usage(); depfile = argv[1]; target = argv[2]; cmdline = argv[3]; /* hack for U-Boot */ if (!strncmp(target, "spl/", 4) || !strncmp(target, "tpl/", 4)) is_spl_build = 1; print_cmdline(); print_deps(); return 0; }
/* * run on gateway host to make another ssh connection, to "real" mercurial * server. it sends its command line unmodified to far end. * * never called if HG_GATEWAY is NULL. */ static void forward_through_gateway(int argc, char **argv) { char *ssh = SSH; char *hg_host = HG_HOST; char *hg_user = HG_USER; char **nargv = alloca((10 + argc) * sizeof(char *)); int i = 0, j; nargv[i++] = ssh; nargv[i++] = "-q"; nargv[i++] = "-T"; nargv[i++] = "-x"; if (hg_user) { nargv[i++] = "-l"; nargv[i++] = hg_user; } nargv[i++] = hg_host; /* * sshd called us with added "-c", because it thinks we are a shell. * drop it if we find it. */ j = 1; if (j < argc && strcmp(argv[j], "-c") == 0) { j++; } for (; j < argc; i++, j++) { nargv[i] = argv[j]; } nargv[i] = NULL; if (debug) { print_cmdline(i, nargv); } execv(ssh, nargv); perror(ssh); exit(EX_UNAVAILABLE); }
int main(void){ struct passwd *pw; struct stat st; char filename[32]; pid_t *pids, pid; if((pids = getpids()) == NULL){ perror("getpids()"); return 1; } printf("USER\tPID\tCOMMAND\n"); while((pid = *pids++)){ sprintf(filename, "/proc/%d", pid); if(stat(filename, &st) == -1){ continue; } if((pw = getpwuid(st.st_uid)) == NULL){ continue; } printf("%s\t", pw->pw_name); printf("%d\t", pid); if(!print_cmdline(pid)){ print_status(pid); } putchar('\n'); } return 0; }
/* * run shell. let administrator "su" to mercurial user's account to do * administrative works. * * never called if HG_SHELL is NULL. */ static void run_shell(int argc, char **argv) { char *hg_shell = HG_SHELL; char **nargv; char *c; int i; nargv = alloca((argc + 3) * sizeof(char *)); c = strrchr(hg_shell, '/'); /* tell "real" shell it is login shell, if needed. */ if (argv[0][0] == '-' && c) { nargv[0] = strdup(c); if (nargv[0] == NULL) { perror("malloc"); exit(EX_OSERR); } nargv[0][0] = '-'; } else { nargv[0] = hg_shell; } for (i = 1; i < argc; i++) { nargv[i] = argv[i]; } nargv[i] = NULL; if (debug) { print_cmdline(i, nargv); } execv(hg_shell, nargv); perror(hg_shell); exit(EX_OSFILE); }
int main( int argc , char ** argv ) { int comm_rank = 0 ; #if defined( KOKKOS_ENABLE_MPI ) MPI_Init( & argc , & argv ); MPI_Comm comm = MPI_COMM_WORLD ; MPI_Comm_rank( comm , & comm_rank ); #else MPI_Comm comm = 0 ; (void) comm ; // suppress warning #endif int cmdline[ CMD_COUNT ] ; for ( int i = 0 ; i < CMD_COUNT ; ++i ) cmdline[i] = 0 ; if ( 0 == comm_rank ) { for ( int i = 1 ; i < argc ; ++i ) { if ( 0 == strcasecmp( argv[i] , "threads" ) ) { cmdline[ CMD_USE_THREADS ] = atoi( argv[++i] ); } else if ( 0 == strcasecmp( argv[i] , "openmp" ) ) { cmdline[ CMD_USE_OPENMP ] = atoi( argv[++i] ); } else if ( 0 == strcasecmp( argv[i] , "cores" ) ) { sscanf( argv[++i] , "%dx%d" , cmdline + CMD_USE_NUMA , cmdline + CMD_USE_CORE_PER_NUMA ); } else if ( 0 == strcasecmp( argv[i] , "cuda" ) ) { cmdline[ CMD_USE_CUDA ] = 1 ; } else if ( 0 == strcasecmp( argv[i] , "cuda-dev" ) ) { cmdline[ CMD_USE_CUDA ] = 1 ; cmdline[ CMD_USE_CUDA_DEV ] = atoi( argv[++i] ) ; } else if ( 0 == strcasecmp( argv[i] , "fixture" ) ) { sscanf( argv[++i] , "%dx%dx%d" , cmdline + CMD_USE_FIXTURE_X , cmdline + CMD_USE_FIXTURE_Y , cmdline + CMD_USE_FIXTURE_Z ); } else if ( 0 == strcasecmp( argv[i] , "fixture-range" ) ) { sscanf( argv[++i] , "%d..%d" , cmdline + CMD_USE_FIXTURE_BEGIN , cmdline + CMD_USE_FIXTURE_END ); } else if ( 0 == strcasecmp( argv[i] , "fixture-quadratic" ) ) { cmdline[ CMD_USE_FIXTURE_QUADRATIC ] = 1 ; } else if ( 0 == strcasecmp( argv[i] , "atomic" ) ) { cmdline[ CMD_USE_ATOMIC ] = 1 ; } else if ( 0 == strcasecmp( argv[i] , "trials" ) ) { cmdline[ CMD_USE_TRIALS ] = atoi( argv[++i] ) ; } else if ( 0 == strcasecmp( argv[i] , "vtune" ) ) { cmdline[ CMD_VTUNE ] = 1 ; } else if ( 0 == strcasecmp( argv[i] , "print" ) ) { cmdline[ CMD_PRINT ] = 1 ; } else if ( 0 == strcasecmp( argv[i] , "echo" ) ) { cmdline[ CMD_ECHO ] = 1 ; } else { cmdline[ CMD_ERROR ] = 1 ; std::cerr << "Unrecognized command line argument #" << i << ": " << argv[i] << std::endl ; } } if ( cmdline[ CMD_ECHO ] && 0 == comm_rank ) { print_cmdline( std::cout , cmdline ); } } #if defined( KOKKOS_ENABLE_MPI ) MPI_Bcast( cmdline , CMD_COUNT , MPI_INT , 0 , comm ); #endif if ( cmdline[ CMD_VTUNE ] ) { std::stringstream cmd; pid_t my_os_pid=getpid(); const std::string vtune_loc = "/usr/local/intel/vtune_amplifier_xe_2013/bin64/amplxe-cl"; const std::string output_dir = "./vtune/vtune."; const int p_rank = comm_rank; cmd << vtune_loc << " -collect hotspots -result-dir " << output_dir << p_rank << " -target-pid " << my_os_pid << " &"; if (p_rank == 0) std::cout << cmd.str() << std::endl; system(cmd.str().c_str()); system("sleep 10"); } if ( ! cmdline[ CMD_ERROR ] && ! cmdline[ CMD_ECHO ] ) { if ( ! cmdline[ CMD_USE_TRIALS ] ) { cmdline[ CMD_USE_TRIALS ] = 1 ; } if ( ! cmdline[ CMD_USE_FIXTURE_X ] && ! cmdline[ CMD_USE_FIXTURE_BEGIN ] ) { cmdline[ CMD_USE_FIXTURE_X ] = 2 ; cmdline[ CMD_USE_FIXTURE_Y ] = 2 ; cmdline[ CMD_USE_FIXTURE_Z ] = 2 ; } #if defined( KOKKOS_ENABLE_PTHREAD ) if ( cmdline[ CMD_USE_THREADS ] ) { if ( cmdline[ CMD_USE_NUMA ] && cmdline[ CMD_USE_CORE_PER_NUMA ] ) { Kokkos::Threads::initialize( cmdline[ CMD_USE_THREADS ] , cmdline[ CMD_USE_NUMA ] , cmdline[ CMD_USE_CORE_PER_NUMA ] ); } else { Kokkos::Threads::initialize( cmdline[ CMD_USE_THREADS ] ); } run< Kokkos::Threads , Kokkos::Example::BoxElemPart::ElemLinear >( comm , cmdline ); Kokkos::Threads::finalize(); } #endif #if defined( KOKKOS_ENABLE_OPENMP ) if ( cmdline[ CMD_USE_OPENMP ] ) { if ( cmdline[ CMD_USE_NUMA ] && cmdline[ CMD_USE_CORE_PER_NUMA ] ) { Kokkos::OpenMP::initialize( cmdline[ CMD_USE_OPENMP ] , cmdline[ CMD_USE_NUMA ] , cmdline[ CMD_USE_CORE_PER_NUMA ] ); } else { Kokkos::OpenMP::initialize( cmdline[ CMD_USE_OPENMP ] ); } run< Kokkos::OpenMP , Kokkos::Example::BoxElemPart::ElemLinear >( comm , cmdline ); Kokkos::OpenMP::finalize(); } #endif #if defined( KOKKOS_ENABLE_CUDA ) if ( cmdline[ CMD_USE_CUDA ] ) { // Use the last device: Kokkos::HostSpace::execution_space::initialize(); Kokkos::Cuda::initialize( Kokkos::Cuda::SelectDevice( cmdline[ CMD_USE_CUDA_DEV ] ) ); run< Kokkos::Cuda , Kokkos::Example::BoxElemPart::ElemLinear >( comm , cmdline ); Kokkos::Cuda::finalize(); Kokkos::HostSpace::execution_space::finalize(); } #endif } #if defined( KOKKOS_ENABLE_MPI ) MPI_Finalize(); #endif return cmdline[ CMD_ERROR ] ? -1 : 0 ; }
int main(int argc, char **argv) { char ruby_code[1024] = { 0 }; char last_code_line[1024] = { 0 }; #ifndef ENABLE_READLINE int last_char; int char_index; #else char *home = NULL; #endif mrbc_context *cxt; struct mrb_parser_state *parser; mrb_state *mrb; mrb_value result; struct _args args; int n; mrb_bool code_block_open = FALSE; mrb_value MIRB_BIN; int ai; unsigned int stack_keep = 0; /* new interpreter instance */ mrb = mrb_open(); if (mrb == NULL) { fputs("Invalid mrb interpreter, exiting mirb\n", stderr); return EXIT_FAILURE; } mrb_define_global_const(mrb, "ARGV", mrb_ary_new_capa(mrb, 0)); n = parse_args(mrb, argc, argv, &args); if (n == EXIT_FAILURE) { cleanup(mrb, &args); usage(argv[0]); return n; } print_hint(); cxt = mrbc_context_new(mrb); cxt->capture_errors = 1; cxt->lineno = 1; mrbc_filename(mrb, cxt, "(mirb)"); if (args.verbose) cxt->dump_result = 1; MIRB_BIN= mrb_str_new(mrb, argv[0], strlen(argv[0])); mrb_define_global_const(mrb, "MIRB_BIN", MIRB_BIN); #ifdef ENABLE_REQUIRE mrb_value LOAD_PATH = mrb_gv_get(mrb, mrb_intern(mrb, "$:")); if (mrb_str_cmp(mrb, MIRB_BIN, mrb_str_new2(mrb, "mirb")) != 0) { int len = strrchr(RSTRING_PTR(MIRB_BIN), '/') - RSTRING_PTR(MIRB_BIN); mrb_value extdir = mrb_str_substr(mrb, mrb_str_dup(mrb, MIRB_BIN), 0, len); mrb_str_cat2(mrb, extdir, "/../ext"); if (mrb_obj_eq(mrb, mrb_file_exist(mrb, extdir), mrb_true_value())) { mrb_ary_push(mrb, LOAD_PATH, extdir); } } #endif /* ENABLE_REQUIRE */ ai = mrb_gc_arena_save(mrb); #ifdef ENABLE_READLINE MIRB_USING_HISTORY(); home = getenv("HOME"); #ifdef _WIN32 if (!home) home = getenv("USERPROFILE"); #endif if (home) { strcpy(history_path, home); strcat(history_path, "/"); strcat(history_path, history_file_name); MIRB_READ_HISTORY(history_path); } #endif while (TRUE) { #ifndef ENABLE_READLINE print_cmdline(code_block_open); char_index = 0; while ((last_char = getchar()) != '\n') { if (last_char == EOF) break; last_code_line[char_index++] = last_char; } if (last_char == EOF) { fputs("\n", stdout); break; } last_code_line[char_index] = '\0'; #else char* line = MIRB_READLINE(code_block_open ? "* " : "> "); if (line == NULL) { printf("\n"); break; } strncpy(last_code_line, line, sizeof(last_code_line)-1); MIRB_ADD_HISTORY(line); free(line); #endif if (code_block_open) { strcat(ruby_code, "\n"); strcat(ruby_code, last_code_line); } else { if ((strcmp(last_code_line, "quit") == 0) || (strcmp(last_code_line, "exit") == 0)) { break; } strcpy(ruby_code, last_code_line); } /* parse code */ parser = mrb_parser_new(mrb); parser->s = ruby_code; parser->send = ruby_code + strlen(ruby_code); parser->lineno = cxt->lineno; mrb_parser_parse(parser, cxt); code_block_open = is_code_block_open(parser); if (code_block_open) { /* no evaluation of code */ } else { if (0 < parser->nerr) { /* syntax error */ printf("line %d: %s\n", parser->error_buffer[0].lineno, parser->error_buffer[0].message); } else { /* generate bytecode */ struct RProc *proc = mrb_generate_code(mrb, parser); if (args.verbose) { mrb_codedump_all(mrb, proc); } /* pass a proc for evaulation */ /* evaluate the bytecode */ result = mrb_context_run(mrb, proc, mrb_top_self(mrb), stack_keep); stack_keep = proc->body.irep->nlocals; /* did an exception occur? */ if (mrb->exc) { p(mrb, mrb_obj_value(mrb->exc), 0); mrb->exc = 0; } else { /* no */ if (!mrb_respond_to(mrb, result, mrb_intern_lit(mrb, "inspect"))){ result = mrb_any_to_s(mrb,result); } p(mrb, result, 1); } } ruby_code[0] = '\0'; last_code_line[0] = '\0'; mrb_gc_arena_restore(mrb, ai); } mrb_parser_free(parser); cxt->lineno++; } mrbc_context_free(mrb, cxt); mrb_close(mrb); #ifdef ENABLE_READLINE MIRB_WRITE_HISTORY(history_path); #endif return 0; }
int main( int argc , char ** argv ) { int comm_rank = 0 ; int comm_size = 1 ; #if defined( KOKKOS_HAVE_MPI ) MPI_Init( & argc , & argv ); MPI_Comm comm = MPI_COMM_WORLD ; MPI_Comm_rank( comm , & comm_rank ); MPI_Comm_size( comm , & comm_size ); #else MPI_Comm comm = 0 ; #endif int cmdline[ CMD_COUNT ] ; for ( int i = 0 ; i < CMD_COUNT ; ++i ) cmdline[i] = 0 ; if ( 0 == comm_rank ) { for ( int i = 1 ; i < argc ; ++i ) { if ( 0 == strcasecmp( argv[i] , "threads" ) ) { cmdline[ CMD_USE_THREADS ] = atoi( argv[++i] ); } else if ( 0 == strcasecmp( argv[i] , "cores" ) ) { sscanf( argv[++i] , "%dx%d" , cmdline + CMD_USE_NUMA , cmdline + CMD_USE_CORE_PER_NUMA ); } else if ( 0 == strcasecmp( argv[i] , "cuda" ) ) { cmdline[ CMD_USE_CUDA ] = 1 ; } else if ( 0 == strcasecmp( argv[i] , "cuda-dev" ) ) { cmdline[ CMD_USE_CUDA ] = 1 ; cmdline[ CMD_USE_CUDA_DEV ] = atoi( argv[++i] ) ; } else if ( 0 == strcasecmp( argv[i] , "fixture" ) ) { sscanf( argv[++i] , "%dx%dx%d" , cmdline + CMD_USE_FIXTURE_X , cmdline + CMD_USE_FIXTURE_Y , cmdline + CMD_USE_FIXTURE_Z ); } else if ( 0 == strcasecmp( argv[i] , "fixture-range" ) ) { sscanf( argv[++i] , "%d..%d" , cmdline + CMD_USE_FIXTURE_BEGIN , cmdline + CMD_USE_FIXTURE_END ); } else if ( 0 == strcasecmp( argv[i] , "fixture-quadratic" ) ) { cmdline[ CMD_USE_FIXTURE_QUADRATIC ] = 1 ; } else if ( 0 == strcasecmp( argv[i] , "atomic" ) ) { cmdline[ CMD_USE_ATOMIC ] = 1 ; } else if ( 0 == strcasecmp( argv[i] , "trials" ) ) { cmdline[ CMD_USE_TRIALS ] = atoi( argv[++i] ) ; } else if ( 0 == strcasecmp( argv[i] , "print" ) ) { cmdline[ CMD_PRINT ] = 1 ; } else if ( 0 == strcasecmp( argv[i] , "echo" ) ) { cmdline[ CMD_ECHO ] = 1 ; } else { cmdline[ CMD_ERROR ] = 1 ; std::cerr << "Unrecognized command line argument #" << i << ": " << argv[i] << std::endl ; } } if ( cmdline[ CMD_ECHO ] ) { print_cmdline( std::cout , cmdline ); } } #if defined( KOKKOS_HAVE_MPI ) MPI_Bcast( cmdline , CMD_COUNT , MPI_INT , 0 , comm ); #endif if ( ! cmdline[ CMD_ERROR ] && ! cmdline[ CMD_ECHO ] ) { if ( ! cmdline[ CMD_USE_TRIALS ] ) { cmdline[ CMD_USE_TRIALS ] = 1 ; } if ( ! cmdline[ CMD_USE_FIXTURE_X ] && ! cmdline[ CMD_USE_FIXTURE_BEGIN ] ) { cmdline[ CMD_USE_FIXTURE_X ] = 2 ; cmdline[ CMD_USE_FIXTURE_Y ] = 2 ; cmdline[ CMD_USE_FIXTURE_Z ] = 2 ; } #if defined( KOKKOS_HAVE_PTHREAD ) if ( cmdline[ CMD_USE_THREADS ] ) { if ( cmdline[ CMD_USE_NUMA ] && cmdline[ CMD_USE_CORE_PER_NUMA ] ) { Kokkos::Threads::initialize( cmdline[ CMD_USE_THREADS ] , cmdline[ CMD_USE_NUMA ] , cmdline[ CMD_USE_CORE_PER_NUMA ] ); } else { Kokkos::Threads::initialize( cmdline[ CMD_USE_THREADS ] ); } run< Kokkos::Threads , Kokkos::Example::BoxElemPart::ElemLinear >( comm , cmdline ); Kokkos::Threads::finalize(); } #endif #if defined( KOKKOS_HAVE_CUDA ) if ( cmdline[ CMD_USE_CUDA ] ) { // Use the last device: Kokkos::Cuda::host_mirror_device_type::initialize(); Kokkos::Cuda::initialize( Kokkos::Cuda::SelectDevice( cmdline[ CMD_USE_CUDA_DEV ] ) ); run< Kokkos::Cuda , Kokkos::Example::BoxElemPart::ElemLinear >( comm , cmdline ); Kokkos::Cuda::finalize(); Kokkos::Cuda::host_mirror_device_type::finalize(); } #endif } #if defined( KOKKOS_HAVE_MPI ) MPI_Finalize(); #endif return cmdline[ CMD_ERROR ] ? -1 : 0 ; }
int main(void) { char last_char, ruby_code[1024], last_code_line[1024]; int char_index; struct mrb_parser_state *parser; mrb_state *mrb_interpreter; mrb_value mrb_return_value; int byte_code; int code_block_open = FALSE; print_hint(); /* new interpreter instance */ mrb_interpreter = mrb_open(); /* new parser instance */ parser = mrb_parser_new(mrb_interpreter); memset(ruby_code, 0, sizeof(*ruby_code)); memset(last_code_line, 0, sizeof(*last_code_line)); while (TRUE) { print_cmdline(code_block_open); char_index = 0; while ((last_char = getchar()) != '\n') { if (last_char == EOF) break; last_code_line[char_index++] = last_char; } if (last_char == EOF) { printf("\n"); break; } last_code_line[char_index] = '\0'; if ((strcmp(last_code_line, "quit") == 0) || (strcmp(last_code_line, "exit") == 0)) { if (code_block_open) { /* cancel the current block and reset */ code_block_open = FALSE; memset(ruby_code, 0, sizeof(*ruby_code)); memset(last_code_line, 0, sizeof(*last_code_line)); continue; } else { /* quit the program */ break; } } else { if (code_block_open) { strcat(ruby_code, "\n"); strcat(ruby_code, last_code_line); } else { memset(ruby_code, 0, sizeof(*ruby_code)); strcat(ruby_code, last_code_line); } /* parse code */ parser->s = ruby_code; parser->send = ruby_code + strlen(ruby_code); parser->capture_errors = 1; parser->lineno = 1; mrb_parser_parse(parser); code_block_open = is_code_block_open(parser); if (code_block_open) { /* no evaluation of code */ } else { if (0 < parser->nerr) { /* syntax error */ printf("line %d: %s\n", parser->error_buffer[0].lineno, parser->error_buffer[0].message); } else { /* generate bytecode */ byte_code = mrb_generate_code(mrb_interpreter, parser->tree); /* evaluate the bytecode */ mrb_return_value = mrb_run(mrb_interpreter, /* pass a proc for evaulation */ mrb_proc_new(mrb_interpreter, mrb_interpreter->irep[byte_code]), mrb_top_self(mrb_interpreter)); /* did an exception occur? */ if (mrb_interpreter->exc) { mrb_p(mrb_interpreter, mrb_obj_value(mrb_interpreter->exc)); mrb_interpreter->exc = 0; } else { /* no */ printf(" => "); mrb_p(mrb_interpreter, mrb_return_value); } } memset(ruby_code, 0, sizeof(*ruby_code)); memset(ruby_code, 0, sizeof(*last_code_line)); } } } mrb_close(mrb_interpreter); return 0; }
int main(int argc, char **argv) { char ruby_code[1024] = { 0 }; char last_code_line[1024] = { 0 }; #ifndef ENABLE_READLINE int last_char; int char_index; #else char *home = NULL; #endif mrbc_context *cxt; struct mrb_parser_state *parser; mrb_state *mrb; mrb_value result; struct _args args; int n; mrb_bool code_block_open = FALSE; int ai; mrb_bool first_command = TRUE; unsigned int nregs; /* new interpreter instance */ mrb = mrb_open(); if (mrb == NULL) { fputs("Invalid mrb interpreter, exiting mirb\n", stderr); return EXIT_FAILURE; } mrb_define_global_const(mrb, "ARGV", mrb_ary_new_capa(mrb, 0)); n = parse_args(mrb, argc, argv, &args); if (n == EXIT_FAILURE) { cleanup(mrb, &args); usage(argv[0]); return n; } print_hint(); cxt = mrbc_context_new(mrb); cxt->capture_errors = 1; cxt->lineno = 1; mrbc_filename(mrb, cxt, "(mirb)"); if (args.verbose) cxt->dump_result = 1; ai = mrb_gc_arena_save(mrb); #ifdef ENABLE_READLINE using_history(); home = getenv("HOME"); #ifdef _WIN32 if (!home) home = getenv("USERPROFILE"); #endif if (home) { strcpy(history_path, home); strcat(history_path, "/"); strcat(history_path, history_file_name); read_history(history_path); } #endif while (TRUE) { #ifndef ENABLE_READLINE print_cmdline(code_block_open); char_index = 0; while ((last_char = getchar()) != '\n') { if (last_char == EOF) break; last_code_line[char_index++] = last_char; } if (last_char == EOF) { fputs("\n", stdout); break; } last_code_line[char_index] = '\0'; #else char* line = readline(code_block_open ? "* " : "> "); if (line == NULL) { printf("\n"); break; } strncpy(last_code_line, line, sizeof(last_code_line)-1); add_history(line); free(line); #endif if ((strcmp(last_code_line, "quit") == 0) || (strcmp(last_code_line, "exit") == 0)) { if (!code_block_open) { break; } else{ /* count the quit/exit commands as strings if in a quote block */ strcat(ruby_code, "\n"); strcat(ruby_code, last_code_line); } } else { if (code_block_open) { strcat(ruby_code, "\n"); strcat(ruby_code, last_code_line); } else { strcpy(ruby_code, last_code_line); } } /* parse code */ parser = mrb_parser_new(mrb); parser->s = ruby_code; parser->send = ruby_code + strlen(ruby_code); parser->lineno = cxt->lineno; mrb_parser_parse(parser, cxt); code_block_open = is_code_block_open(parser); if (code_block_open) { /* no evaluation of code */ } else { if (0 < parser->nerr) { /* syntax error */ printf("line %d: %s\n", parser->error_buffer[0].lineno, parser->error_buffer[0].message); } else { /* generate bytecode */ struct RProc *proc = mrb_generate_code(mrb, parser); if (args.verbose) { mrb_codedump_all(mrb, proc); } /* pass a proc for evaulation */ nregs = first_command ? 0: proc->body.irep->nregs; /* evaluate the bytecode */ result = mrb_context_run(mrb, proc, mrb_top_self(mrb), nregs); /* did an exception occur? */ if (mrb->exc) { p(mrb, mrb_obj_value(mrb->exc), 0); mrb->exc = 0; } else { /* no */ if (!mrb_respond_to(mrb, result, mrb_intern_lit(mrb, "inspect"))){ result = mrb_any_to_s(mrb,result); } p(mrb, result, 1); } } ruby_code[0] = '\0'; last_code_line[0] = '\0'; mrb_gc_arena_restore(mrb, ai); } mrb_parser_free(parser); cxt->lineno++; first_command = FALSE; } mrbc_context_free(mrb, cxt); mrb_close(mrb); #ifdef ENABLE_READLINE write_history(history_path); #endif return 0; }
// Parse command line clp_return_type parse_cmdline( int argc , char ** argv, CMD & cmdline, const Teuchos::Comm<int>& comm, const bool uq ) { Teuchos::ParameterList params; Teuchos::CommandLineProcessor clp(false); const int num_grouping_types = 4; const GroupingType grouping_values[] = { GROUPING_NATURAL, GROUPING_MAX_ANISOTROPY, GROUPING_MORTAN_Z, GROUPING_TASMANIAN_SURROGATE }; const char *grouping_names[] = { "natural", "max-anisotropy", "mortan-z", "tasmanian-surrogate" }; const int num_sampling_types = 3; const SamplingType sampling_values[] = { SAMPLING_STOKHOS, SAMPLING_TASMANIAN, SAMPLING_FILE }; const char *sampling_names[] = { "stokhos", "tasmanian", "file" }; clp.setOption("serial", "no-serial", &cmdline.USE_SERIAL, "use the serial device"); clp.setOption("threads", &cmdline.USE_THREADS, "number of pthreads threads"); clp.setOption("openmp", &cmdline.USE_OPENMP, "number of openmp threads"); clp.setOption("numa", &cmdline.USE_NUMA, "number of numa nodes"); clp.setOption("cores", &cmdline.USE_CORE_PER_NUMA, "cores per numa node"); clp.setOption("cuda", "no-cuda", &cmdline.USE_CUDA, "use the CUDA device"); clp.setOption("device", &cmdline.USE_CUDA_DEV, "CUDA device ID. Set to default of -1 to use the default device as determined by the local node MPI rank and --ngpus"); clp.setOption("ngpus", &cmdline.USE_NGPUS, "Number of GPUs per node for multi-GPU runs via MPI"); std::string fixtureSpec="2x2x2"; clp.setOption("fixture", &fixtureSpec, "fixture string: \"XxYxZ\""); clp.setOption("fixture-x", &cmdline.USE_FIXTURE_X, "fixture"); clp.setOption("fixture-y", &cmdline.USE_FIXTURE_Y, "fixture"); clp.setOption("fixture-z", &cmdline.USE_FIXTURE_Z, "fixture"); clp.setOption("fixture-quadratic", "no-fixture-quadratic", &cmdline.USE_FIXTURE_QUADRATIC, "quadratic"); clp.setOption("atomic", "no-atomic", &cmdline.USE_ATOMIC , "atomic"); clp.setOption("trials", &cmdline.USE_TRIALS, "trials"); clp.setOption("xml-file", &cmdline.USE_FENL_XML_FILE, "XML file containing solver parameters"); clp.setOption("belos", "no-belos", &cmdline.USE_BELOS , "use Belos solver"); clp.setOption("muelu", "no-muelu", &cmdline.USE_MUELU, "use MueLu preconditioner"); clp.setOption("mean-based", "no-mean-based", &cmdline.USE_MEANBASED, "use mean-based preconditioner"); if(cmdline.USE_MUELU || cmdline.USE_MEANBASED) cmdline.USE_BELOS = true; clp.setOption("sampling", &cmdline.USE_UQ_SAMPLING, num_sampling_types, sampling_values, sampling_names, "UQ sampling method"); clp.setOption("uq-fake", &cmdline.USE_UQ_FAKE, "setup a fake UQ problem of this size"); clp.setOption("uq-dim", &cmdline.USE_UQ_DIM, "UQ dimension"); clp.setOption("uq-order", &cmdline.USE_UQ_ORDER, "UQ order"); clp.setOption("uq-init-level", &cmdline.USE_UQ_INIT_LEVEL, "Initial adaptive sparse grid level"); clp.setOption("uq-max-level", &cmdline.USE_UQ_MAX_LEVEL, "Max adaptive sparse grid level"); clp.setOption("uq-max-samples", &cmdline.USE_UQ_MAX_SAMPLES, "Max number of samples to run"); clp.setOption("uq-tol", &cmdline.USE_UQ_TOL, "Adaptive sparse grid tolerance"); clp.setOption("diff-coeff-linear", &cmdline.USE_DIFF_COEFF_LINEAR, "Linear term in diffusion coefficient"); clp.setOption("diff-coeff-constant", &cmdline.USE_DIFF_COEFF_CONSTANT, "Constant term in diffusion coefficient"); clp.setOption("mean", &cmdline.USE_MEAN, "KL diffusion mean"); clp.setOption("var", &cmdline.USE_VAR, "KL diffusion variance"); clp.setOption("cor", &cmdline.USE_COR, "KL diffusion correlation"); clp.setOption("exponential", "no-exponential", &cmdline.USE_EXPONENTIAL, "take exponential of KL diffusion coefficient"); clp.setOption("exp-shift", &cmdline.USE_EXP_SHIFT, "Linear shift of exponential of KL diffusion coefficient"); clp.setOption("exp-scale", &cmdline.USE_EXP_SCALE, "Multiplicative scale of exponential of KL diffusion coefficient"); clp.setOption("discontinuous-exp-scale", "continuous-exp-scale", &cmdline.USE_DISC_EXP_SCALE, "use discontinuous scale factor on exponential"); clp.setOption("isotropic", "anisotropic", &cmdline.USE_ISOTROPIC, "use isotropic or anisotropic diffusion coefficient"); clp.setOption("coeff-src", &cmdline.USE_COEFF_SRC, "Coefficient for source term"); clp.setOption("coeff-adv", &cmdline.USE_COEFF_ADV, "Coefficient for advection term"); clp.setOption("sparse", "tensor", &cmdline.USE_SPARSE , "use sparse or tensor grid"); clp.setOption("ensemble", &cmdline.USE_UQ_ENSEMBLE, "UQ ensemble size. This needs to be a valid choice based on available instantiations."); clp.setOption("grouping", &cmdline.USE_GROUPING, num_grouping_types, grouping_values, grouping_names, "Sample grouping method for ensemble propagation"); clp.setOption("surrogate-grouping-level", &cmdline.TAS_GROUPING_INITIAL_LEVEL, "Starting level for surrogate-based grouping"); clp.setOption("vtune", "no-vtune", &cmdline.VTUNE , "connect to vtune"); clp.setOption("verbose", "no-verbose", &cmdline.VERBOSE, "print verbose intialization info"); clp.setOption("print", "no-print", &cmdline.PRINT, "print detailed test output"); clp.setOption("print-its", "no-print-its",&cmdline.PRINT_ITS, "print solver iterations after each sample"); clp.setOption("summarize", "no-summarize",&cmdline.SUMMARIZE, "summarize Teuchos timers at end of run"); bool doDryRun = false; clp.setOption("echo", "no-echo", &doDryRun, "dry-run only"); switch (clp.parse(argc, argv)) { case Teuchos::CommandLineProcessor::PARSE_HELP_PRINTED: return CLP_HELP; case Teuchos::CommandLineProcessor::PARSE_ERROR: case Teuchos::CommandLineProcessor::PARSE_UNRECOGNIZED_OPTION: return CLP_ERROR; case Teuchos::CommandLineProcessor::PARSE_SUCCESSFUL: break; } #if defined( KOKKOS_HAVE_CUDA ) // Set CUDA device based on local node rank if (cmdline.USE_CUDA && cmdline.USE_CUDA_DEV == -1) { int local_rank = 0; char *str; if ((str = std::getenv("MV2_COMM_WORLD_LOCAL_RANK"))) local_rank = std::atoi(str); else if ((str = getenv("OMPI_COMM_WORLD_LOCAL_RANK"))) local_rank = std::atoi(str); else if ((str = std::getenv("SLURM_LOCALID"))) local_rank = std::atoi(str); cmdline.USE_CUDA_DEV = local_rank % cmdline.USE_NGPUS; // Check device is valid int num_device; cudaGetDeviceCount(&num_device); TEUCHOS_TEST_FOR_EXCEPTION( cmdline.USE_CUDA_DEV >= cmdline.USE_NGPUS, std::logic_error, "Invalid device ID " << cmdline.USE_CUDA_DEV << ". You probably are trying" << " to run with too many GPUs per node"); } #endif sscanf( fixtureSpec.c_str() , "%dx%dx%d" , &cmdline.USE_FIXTURE_X , &cmdline.USE_FIXTURE_Y , &cmdline.USE_FIXTURE_Z ); cmdline.USE_UQ = uq; if (doDryRun) { print_cmdline( std::cout , cmdline ); cmdline.ECHO = 1; } else { cmdline.ECHO = 0; } cmdline.ERROR = 0 ; return CLP_OK; }
void loop() { if (Serial.available() > 0) { char_index = 0; while (true) { if (Serial.available() > 0) { incommingByte = Serial.read(); if (incommingByte == 13) { // New Line last_code_line[char_index] = '\0'; break; } else { last_code_line[char_index++] = incommingByte; Serial.write(incommingByte); } } } Serial.println(""); Serial.flush(); is_exit = false; if ((strcmp(last_code_line, "quit") == 0) || (strcmp(last_code_line, "exit") == 0)) { // Exit Interactive Mode if (!code_block_open) { is_exit = true; } else { /* count the quit/exit commands as strings if in a quote block */ strcat(ruby_code, "\n"); strcat(ruby_code, last_code_line); is_exit = false; } } else { if (code_block_open) { strcat(ruby_code, "\n"); strcat(ruby_code, last_code_line); is_exit = false; } else { strcpy(ruby_code, last_code_line); is_exit = false; } } if (!is_exit) { // Not Exit or Quit! /* parse code */ parser = mrb_parser_new(mrb); parser->s = ruby_code; parser->send = ruby_code + strlen(ruby_code); parser->lineno = 1; mrb_parser_parse(parser, cxt); code_block_open = is_code_block_open(parser); if (code_block_open) { /* no evaluation of code */ } else { if (0 < parser->nerr) { /* syntax error */ Serial.write("Syntax Error: "); Serial.println(parser->error_buffer[0].message); } else { /* generate bytecode */ n = mrb_generate_code(mrb, parser); /* evaluate the bytecode */ result = mrb_run(mrb, /* pass a proc for evaulation */ mrb_proc_new(mrb, mrb->irep[n]), mrb_top_self(mrb)); /* did an exception occur? */ if (mrb->exc) { /* yes */ p(mrb, mrb_obj_value(mrb->exc), 0); mrb->exc = 0; } else { /* no */ if (!mrb_respond_to(mrb,result,mrb_intern(mrb, "inspect"))){ result = mrb_any_to_s(mrb,result); } p(mrb, result, 1); } } ruby_code[0] = '\0'; last_code_line[0] = '\0'; mrb_gc_arena_restore(mrb, ai); } mrb_parser_free(parser); } else { // User Enter 'exit' or 'quit' Serial.println("quit IAS"); ruby_code[0] = '\0'; last_code_line[0] = '\0'; mrb_parser_free(parser); mrbc_context_free(mrb, cxt); mrb_close(mrb); mrb_setup_arduino(); } print_cmdline(code_block_open); } }
/* * paranoid wrapper, runs hg executable in server mode. */ static void serve_data(int argc, char **argv) { char *hg_root = HG_ROOT; char *repo, *repo_root; enum cmdline cmd; char *nargv[6]; size_t repolen; int i; /* * check argv for looking okay. we should be invoked with argv * resembling like this: * * hgsh * -c * hg -R some/path serve --stdio * * the "-c" is added by sshd, because it thinks we are login shell. */ if (argc != 3) { goto badargs; } if (strcmp(argv[1], "-c") != 0) { goto badargs; } if (sscanf(argv[2], "hg init %as", &repo) == 1) { cmd = hg_init; } else if (sscanf(argv[2], "hg -R %as serve --stdio", &repo) == 1) { cmd = hg_serve; } else { goto badargs; } repolen = repo ? strlen(repo) : 0; if (repolen == 0) { goto badargs; } if (hg_root) { if (asprintf(&repo_root, "%s/%s/", hg_root, repo) == -1) { goto badargs; } /* * attempt to stop break out from inside the * repository tree. could do something more clever * here, because e.g. we could traverse a symlink that * looks safe, but really breaks us out of tree. */ if (strstr(repo_root, "/../") != NULL) { goto badargs; } /* only hg init expects no repo. */ if (cmd != hg_init) { int valid; valid = validate_repo(repo_root, "data"); if (valid == -1) { goto badargs; } if (valid == 0) { valid = validate_repo(repo_root, "store"); if (valid == -1) { goto badargs; } } if (valid == 0) { perror(repo); exit(EX_DATAERR); } } if (chdir(hg_root) == -1) { perror(hg_root); exit(EX_SOFTWARE); } } i = 0; switch (cmd) { case hg_serve: nargv[i++] = HG; nargv[i++] = "-R"; nargv[i++] = repo; nargv[i++] = "serve"; nargv[i++] = "--stdio"; break; case hg_init: nargv[i++] = HG; nargv[i++] = "init"; nargv[i++] = repo; break; } nargv[i] = NULL; if (debug) { print_cmdline(i, nargv); } execv(HG, nargv); perror(HG); exit(EX_UNAVAILABLE); badargs: /* print useless error message. */ usage("invalid arguments", EX_DATAERR); }
int main(void) { char ruby_code[1024] = { 0 }; char last_code_line[1024] = { 0 }; #ifndef ENABLE_READLINE int last_char; int char_index; #endif mrbc_context *cxt; struct mrb_parser_state *parser; mrb_state *mrb; mrb_value result; int n; int code_block_open = FALSE; int ai; print_hint(); /* new interpreter instance */ mrb = mrb_open(); if (mrb == NULL) { fprintf(stderr, "Invalid mrb interpreter, exiting mirb"); return EXIT_FAILURE; } cxt = mrbc_context_new(mrb); cxt->capture_errors = 1; ai = mrb_gc_arena_save(mrb); while (TRUE) { #ifndef ENABLE_READLINE print_cmdline(code_block_open); char_index = 0; while ((last_char = getchar()) != '\n') { if (last_char == EOF) break; last_code_line[char_index++] = last_char; } if (last_char == EOF) { printf("\n"); break; } last_code_line[char_index] = '\0'; #else char* line = readline(code_block_open ? "* " : "> "); strncat(last_code_line, line, sizeof(last_code_line)-1); add_history(line); free(line); #endif if ((strcmp(last_code_line, "quit") == 0) || (strcmp(last_code_line, "exit") == 0)) { if (!code_block_open) { break; } else{ /* count the quit/exit commands as strings if in a quote block */ strcat(ruby_code, "\n"); strcat(ruby_code, last_code_line); } } else { if (code_block_open) { strcat(ruby_code, "\n"); strcat(ruby_code, last_code_line); } else { strcpy(ruby_code, last_code_line); } } /* parse code */ parser = mrb_parser_new(mrb); parser->s = ruby_code; parser->send = ruby_code + strlen(ruby_code); parser->lineno = 1; mrb_parser_parse(parser, cxt); code_block_open = is_code_block_open(parser); if (code_block_open) { /* no evaluation of code */ } else { if (0 < parser->nerr) { /* syntax error */ printf("line %d: %s\n", parser->error_buffer[0].lineno, parser->error_buffer[0].message); } else { /* generate bytecode */ n = mrb_generate_code(mrb, parser); /* evaluate the bytecode */ result = mrb_run(mrb, /* pass a proc for evaulation */ mrb_proc_new(mrb, mrb->irep[n]), mrb_top_self(mrb)); /* did an exception occur? */ if (mrb->exc) { p(mrb, mrb_obj_value(mrb->exc)); mrb->exc = 0; } else { /* no */ printf(" => "); p(mrb, result); } } ruby_code[0] = '\0'; last_code_line[0] = '\0'; mrb_parser_free(parser); mrb_gc_arena_restore(mrb, ai); } } mrbc_context_free(mrb, cxt); mrb_close(mrb); return 0; }
/* The main function */ int main(int argc, char *argv[]) { struct utsname system; FILE *infile, *outfile; unsigned short int i, n, filesize; unsigned char buffer, optiondefs = 0; unsigned char programData[28000]; unsigned short int checksum; /* --- Header File Values --- */ /* The header will be modified if your destcalc_id is not 3... */ unsigned char header[11] = { '*', '*', 'T', 'I', '8', '3', '*', '*', 0x1A, 0x0A, 0x00 }; unsigned char comment[42] = "File created under "; unsigned char fileLenLL = 0x00; unsigned char fileLenHH = 0x00; unsigned char varHeadLL = 0x00; unsigned char varHeadHH = 0x00; unsigned char dataLenLL = 0x00; unsigned char dataLenHH = 0x00; unsigned char programLenLL = 0x00; unsigned char programLenHH = 0x00; if (uname(&system) == -1) strcat(comment, "unknown system"); else strncat(comment, system.sysname, 20); /* --- Header File Values --- */ /* Parse all arguments */ struct CmdLineArgs *cmdline = (CmdLineArgs *) malloc(sizeof(CmdLineArgs)); cmdline_init(cmdline); /* set to null or default values all the fields of the struct */ getargs(argc, argv, cmdline); /* Get cmdline args */ cmdline_finalize(cmdline); /* Set to uppercase (or not). Add inverted a for crash (only 82p) */ /* At this point, all cmdline args should be parsed correctly */ if(cmdline->verbose) { puts("Bin8x v1.3 Ti-82/83/83+ squisher"); puts("Copyright (C) 2001 Peter Martijn Kuipers <*****@*****.**>"); puts("Copyright (C) 2003 Tijl Coosemans <*****@*****.**>"); puts("Copyright (C) 2004 Guillaume Hoffman <*****@*****.**>"); puts("Copyright (C) 2011 Thibault Duponchelle <*****@*****.**>"); } /* Concat extension */ switch(cmdline->destcalc_id) { case EXT_82P: header[5] = '2'; strcat(cmdline->output, ext82); break; case EXT_83P: strcat(cmdline->output, ext83); break; case EXT_8XP: header[6] = 'F'; strcat(cmdline->output, ext8x); break; default: puts("\nError : not a valid extension!"); exit(2); break; } /* At this point, all the informations are correct, we can do the real job */ if(cmdline->verbose) print_cmdline(cmdline); /* Unsquish the code if user asked for it (option -q) */ if(cmdline->unsquish) { if((strcmp(cmdline->input, "__temp__.bin") == 0) || strcmp(cmdline->output, "__temp__.bin") == 0) { printf("You must use another input/output filename...\n"); exit(2); } int ret = unsquish(cmdline->input); if(ret == 1) return 1; } /* Unsquisher use a different file */ if (cmdline->input) { if(cmdline->unsquish){ if(!(infile = fopen("__temp__.bin", "r"))) { puts("Error opening inputfile!"); printf("File: __temp__.bin\n"); return (2); } } else { if (!(infile = fopen(cmdline->input, "r"))) { puts("Error opening inputfile!"); printf("File: %s\n", cmdline->input); return (2); } } printf("Using inputfile : %s\n", cmdline->input); } if (!(outfile = fopen(cmdline->output, "w"))) { puts("Error opening outputfile!"); return (3); } printf("Using outputfile : %s\n", cmdline->output); printf("Filename on calculator : %s\n", cmdline->name); filesize = -1; if (cmdline->executable && cmdline->destcalc_id == EXT_8XP) { filesize++; programData[filesize] = 0xBB; filesize++; programData[filesize] = 0x6D; } // UNTESTED : (works only for CrASH(19006)) if (cmdline->destcalc_id == EXT_82P) { filesize++; programData[filesize] = 0xD5; filesize++; programData[filesize] = 0x00; filesize++; programData[filesize] = 0x11; } while (!feof(infile)) { filesize++; buffer = fgetc(infile); programData[filesize] = buffer; /* put this byte in the data * array, and increase the count */ } //printf("dcid : %c\n", cmdline->destcalc_id); switch(cmdline->destcalc_id) { case EXT_82P: // THAT IT WORKS printf("Size on calculator : %u bytes\n", filesize + strlen(cmdline->name) + 6); fileLenHH = HH(filesize + 0x11); /* the file length = the size of the data array + 17 (0x11) */ fileLenLL = LL(filesize + 0x11); varHeadLL = 0x0B; break; case EXT_83P: printf("Size on calculator : %u bytes\n", filesize + strlen(cmdline->name) + 6); fileLenHH = HH(filesize + 0x11); /* the file length = the size of the data array + 17 (0x11) */ fileLenLL = LL(filesize + 0x11); varHeadLL = 0x0B; break; default: //EXT_8XP: printf("Size on calculator : %u bytes\n", filesize + strlen(cmdline->name) + 8); fileLenHH = HH(filesize + 0x13); /* the file length = the size of the data array + 19 (0x13) */ fileLenLL = LL(filesize + 0x13); varHeadLL = 0x0D; break; } dataLenHH = HH(filesize + 2); /* the length of the data includes the 2 checksum bytes */ dataLenLL = LL(filesize + 2); programLenHH = HH(filesize); programLenLL = LL(filesize); checksum = 0x00; /* begin with the checksum set on zero */ for (i = 0; i < 11; i++) /* write the static header */ fputc(header[i], outfile); for (i = 0; i < 42; i++) fputc(comment[i], outfile); fputc(fileLenLL, outfile); /* file length */ fputc(fileLenHH, outfile); fputc(varHeadLL, outfile); /* length of variable header */ checksum += varHeadLL; /* checksum calculs start here */ fputc(varHeadHH, outfile); checksum += varHeadHH; fputc(dataLenLL, outfile); /* length of data */ checksum += dataLenLL; fputc(dataLenHH, outfile); checksum += dataLenHH; fputc(cmdline->progtype, outfile); /* protected program */ checksum += cmdline->progtype; for (i = 0; i < 8; i++) { /* write the name of the variable */ fputc(cmdline->name[i], outfile); checksum += cmdline->name[i]; } switch(cmdline->destcalc_id) { case EXT_8XP: puts("\nTI-83 Plus file made!!"); fputc(0x01, outfile); checksum += 0x01; fputc(0x00, outfile); break; /* checksum += 0x00; */ case EXT_83P: puts("\nPlain TI-83 file made!!"); break; case EXT_82P: puts("\nTI-82 file made!!"); break; default: puts("\nError : not a valid extension!"); exit(2); break; } fputc(dataLenLL, outfile); checksum += dataLenLL; fputc(dataLenHH, outfile); checksum += dataLenHH; fputc(programLenLL, outfile); /* length of program */ checksum += programLenLL; fputc(programLenHH, outfile); checksum += programLenHH; for (i = 0; i < filesize; i++) { /* now write the data array to the * file */ fputc(programData[i], outfile); checksum += programData[i]; /* and add it to the checksum */ } fputc(LL(checksum), outfile); /* write the checksum to the file */ fputc(HH(checksum), outfile); /* * Close all Handles */ fclose(infile); fclose(outfile); free(cmdline); return (0); }