int main(int argc, char *argv[]) { if (argc > 1) { solid_object *mainfunc = parse_tree(parse_file(argv[1])); solid_vm *vm = make_solid_vm(); set_namespace(get_current_namespace(vm), solid_str("compile"), define_c_function(solid_compile)); set_namespace(get_current_namespace(vm), solid_str("import"), define_c_function(solid_import)); solid_call_func(vm, mainfunc); } else { solid_repl(); } return 0; }
void solid_repl() { size_t n = 256; char *buffer = (char *) malloc(sizeof(char) * n); solid_vm *vm = make_solid_vm(); set_namespace(get_current_namespace(vm), solid_str("compile"), define_c_function(solid_compile)); set_namespace(get_current_namespace(vm), solid_str("import"), define_c_function(solid_import)); while (printf("%s", "solid> "), getline(&buffer, &n, stdin) != -1) { solid_object *curexpr = parse_tree(parse_expr(buffer)); solid_call_func(vm, curexpr); push_stack(vm, vm->regs[255]); solid_print(vm); } }
Destructor& Destructor::operator<<(const NamespaceSPtr& namespace_) { return set_namespace(namespace_); }
int launch_clients(int num_procs, char *binary, char *** client_env, char ***base_argv) { int n; uid_t myuid; gid_t mygid; char *ranks = NULL; char digit[MAX_DIGIT_LEN]; int rc; static int counter = 0; static int num_ns = 0; pmix_proc_t proc; TEST_VERBOSE(("Setting job info")); fill_seq_ranks_array(num_procs, counter, &ranks); if (NULL == ranks) { PMIx_server_finalize(); TEST_ERROR(("fill_seq_ranks_array failed")); return PMIX_ERROR; } (void)snprintf(proc.nspace, PMIX_MAX_NSLEN, "%s-%d", TEST_NAMESPACE, num_ns); set_namespace(num_procs, ranks, proc.nspace); if (NULL != ranks) { free(ranks); } myuid = getuid(); mygid = getgid(); /* fork/exec the test */ for (n = 0; n < num_procs; n++) { proc.rank = counter; if (PMIX_SUCCESS != (rc = PMIx_server_setup_fork(&proc, client_env))) {//n TEST_ERROR(("Server fork setup failed with error %d", rc)); PMIx_server_finalize(); cli_kill_all(); return rc; } if (PMIX_SUCCESS != (rc = PMIx_server_register_client(&proc, myuid, mygid, NULL, NULL, NULL))) {//n TEST_ERROR(("Server fork setup failed with error %d", rc)); PMIx_server_finalize(); cli_kill_all(); return rc; } cli_info[counter].pid = fork(); if (cli_info[counter].pid < 0) { TEST_ERROR(("Fork failed")); PMIx_server_finalize(); cli_kill_all(); return -1; } cli_info[counter].rank = counter;//n cli_info[counter].ns = strdup(proc.nspace); char **client_argv = pmix_argv_copy(*base_argv); /* add two last arguments: -r <rank> */ sprintf(digit, "%d", counter);//n pmix_argv_append_nosize(&client_argv, "-r"); pmix_argv_append_nosize(&client_argv, digit); pmix_argv_append_nosize(&client_argv, "-s"); pmix_argv_append_nosize(&client_argv, proc.nspace); sprintf(digit, "%d", num_procs); pmix_argv_append_nosize(&client_argv, "--ns-size"); pmix_argv_append_nosize(&client_argv, digit); sprintf(digit, "%d", num_ns); pmix_argv_append_nosize(&client_argv, "--ns-id"); pmix_argv_append_nosize(&client_argv, digit); sprintf(digit, "%d", (counter-n)); pmix_argv_append_nosize(&client_argv, "--base-rank"); pmix_argv_append_nosize(&client_argv, digit); if (cli_info[counter].pid == 0) { if( !TEST_VERBOSE_GET() ){ // Hide clients stdout // TODO: on some systems stdout is a constant, address this fclose(stdout); stdout = fopen("/dev/null","w"); } execve(binary, client_argv, *client_env); /* Does not return */ exit(0); } cli_info[counter].state = CLI_FORKED; pmix_argv_free(client_argv); counter++; } num_ns++; return PMIX_SUCCESS; }
// ------------------------------------------------------------------ int main(int argc,char *argv[]) { bool info = false; bool usage = false; setup_configuration(); for (int i = 1; i < argc; i++) if (!strcmp(argv[i], "-info")) info = true; else if (!strncmp(argv[i], "--enable-", 9)) set(&argv[i][9], true); else if (!strncmp(argv[i], "--disable-", 10)) set(&argv[i][10], false); else if (!strncmp(argv[i], "--platform=", 11)) set_platform(&argv[i][11]); else if (!strncmp(argv[i], "--name=", 7)) replace_makefile("NAME", &argv[i][7]); else if (!strncmp(argv[i], "--prefix=", 9)) replace_makefile("PREFIX", &argv[i][9]); else if (!strncmp(argv[i], "--namespace=", 12)) set_namespace(&argv[i][12]); else if (!strcmp(argv[i], "-v")) any_set = true; else if (!strcmp(argv[i], "-q")) quiet = true; else if (*argv[i] == '-') { fprintf(stderr, "Unknown command line option: %s\n", argv[i]); usage = true; } else usage = true; if (usage) { fprintf(stderr, "Usage: %s [-info] [-v] [-h] [--platform=PLATFORM] [--prefix=<path>] [--name=<Name>] [--namespace=<ns>] [--enable-OPTION] [--disable-OPTION]\n", *argv); fprintf(stderr, "\n"); fprintf(stderr, "Options (default value)\n"); fprintf(stderr, "\n"); fprintf(stderr, " -info Show compiled options\n"); fprintf(stderr, " -v Show configuration options\n"); fprintf(stderr, " -q Don't show extra info\n"); fprintf(stderr, " -h Show this help\n"); fprintf(stderr, "\n"); fprintf(stderr, " --platform= Select target platform\n"); fprintf(stderr, " --prefix= Set installation path (/usr/local/$NAME)\n"); fprintf(stderr, " --name= Set library name (Sockets)\n"); fprintf(stderr, " --namespace= Set C++ namespace for entire library\n"); fprintf(stderr, "\n"); fprintf(stderr, "Defined platforms\n"); fprintf(stderr, "\n"); fprintf(stderr, " linux-x86-32\n"); fprintf(stderr, " linux-x86-64\n"); fprintf(stderr, " win32-cygwin\n"); fprintf(stderr, " solaris9-sparc-64\n"); fprintf(stderr, " macosx\n"); fprintf(stderr, " solaris8\n"); fprintf(stderr, "\n"); fprintf(stderr, "Possible OPTION values:\n"); fprintf(stderr, "\n"); fprintf(stderr, " openssl Enable openssl library\n"); fprintf(stderr, " ipv6 Add ipv6 support\n"); fprintf(stderr, " sctp Add SCTP support\n"); fprintf(stderr, " no_addrinfo Do not use addrinfo API for dns requests\n"); fprintf(stderr, " pool Enable client connection pool\n"); fprintf(stderr, " socks4 Enable socks4 client support\n"); fprintf(stderr, " resolver Enable asynchronous dns\n"); fprintf(stderr, " reconnect Enable tcp reconnect\n"); fprintf(stderr, " detach Enable detach functionality\n"); fprintf(stderr, " exceptions Enable C++ exceptions on some error conditions\n"); fprintf(stderr, " xml2 Enable libxml2 support\n"); fprintf(stderr, "\n"); fprintf(stderr, "Use with no options to show platform configuration options in CFLAGS format.\n"); return 0; } if (argc > 1 && info) { show_info(); return 0; } if (any_set) { if (!quiet) show_configuration(); return 0; } printf(" -D_VERSION='\"%s\"'", _VERSION); #ifdef LINUX printf(" -DLINUX"); #endif #ifdef MACOSX printf(" -DMACOSX"); #endif #ifdef SOLARIS printf(" -DSOLARIS"); #endif #ifdef SOLARIS8 printf(" -DSOLARIS8"); #endif #ifdef _WIN32 printf(" -D_WIN32"); #endif #ifdef __CYGWIN__ printf(" -D__CYGWIN__"); #endif #ifdef SOCKETS_NAMESPACE printf(" -DSOCKETS_NAMESPACE=%s", SOCKETS_NAMESPACE_STR); #endif #ifdef _DEBUG printf(" -D_DEBUG"); #endif }