/* * Look for and handle any -mca options on the command line */ int pmix_mca_base_cmd_line_process_args(pmix_cmd_line_t *cmd, char ***context_env, char ***global_env) { int i, num_insts, rc; char **params; char **values; /* If no relevant parameters were given, just return */ if (!pmix_cmd_line_is_taken(cmd, PMIX_MCA_CMD_LINE_ID) && !pmix_cmd_line_is_taken(cmd, "g"PMIX_MCA_CMD_LINE_ID)) { return PMIX_SUCCESS; } /* Handle app context-specific parameters */ num_insts = pmix_cmd_line_get_ninsts(cmd, PMIX_MCA_CMD_LINE_ID); params = values = NULL; for (i = 0; i < num_insts; ++i) { if (PMIX_SUCCESS != (rc = process_arg(pmix_cmd_line_get_param(cmd, PMIX_MCA_CMD_LINE_ID, i, 0), pmix_cmd_line_get_param(cmd, PMIX_MCA_CMD_LINE_ID, i, 1), ¶ms, &values))) { return rc; } } if (NULL != params) { add_to_env(params, values, context_env); pmix_argv_free(params); pmix_argv_free(values); } /* Handle global parameters */ num_insts = pmix_cmd_line_get_ninsts(cmd, "g"PMIX_MCA_CMD_LINE_ID); params = values = NULL; for (i = 0; i < num_insts; ++i) { if (PMIX_SUCCESS != (rc = process_arg(pmix_cmd_line_get_param(cmd, "g"PMIX_MCA_CMD_LINE_ID, i, 0), pmix_cmd_line_get_param(cmd, "g"PMIX_MCA_CMD_LINE_ID, i, 1), ¶ms, &values))) { return rc; } } if (NULL != params) { add_to_env(params, values, global_env); pmix_argv_free(params); pmix_argv_free(values); } /* All done */ return PMIX_SUCCESS; }
/* * Look for and handle any -mca options on the command line */ int mca_base_cmd_line_process_args(opal_cmd_line_t *cmd, char ***context_env, char ***global_env) { int i, num_insts; char **params; char **values; /* If no relevant parameters were given, just return */ if (!opal_cmd_line_is_taken(cmd, "mca") && !opal_cmd_line_is_taken(cmd, "gmca")) { return OPAL_SUCCESS; } /* Handle app context-specific parameters */ num_insts = opal_cmd_line_get_ninsts(cmd, "mca"); params = values = NULL; for (i = 0; i < num_insts; ++i) { process_arg(opal_cmd_line_get_param(cmd, "mca", i, 0), opal_cmd_line_get_param(cmd, "mca", i, 1), ¶ms, &values); } if (NULL != params) { add_to_env(params, values, context_env); opal_argv_free(params); opal_argv_free(values); } /* Handle global parameters */ num_insts = opal_cmd_line_get_ninsts(cmd, "gmca"); params = values = NULL; for (i = 0; i < num_insts; ++i) { process_arg(opal_cmd_line_get_param(cmd, "gmca", i, 0), opal_cmd_line_get_param(cmd, "gmca", i, 1), ¶ms, &values); } if (NULL != params) { add_to_env(params, values, global_env); opal_argv_free(params); opal_argv_free(values); } /* All done */ return OPAL_SUCCESS; }
void setenv_shell2(char **environ, char *str, t_sh *sh) { int ref_env; int i; i = 0; sh->temp2 = xmalloc(sizeof(char *) * 3); while (i < 3) sh->temp2[i++] = xmalloc(sizeof(char) * 100); sh->temp2 = set_temp2(sh->temp2, str); if (verif_ref(sh->temp2) == 3) { if ((ref_env = check_var_to_env(sh->temp2[1], environ)) != -1) change_env(sh->temp2, environ, ref_env); else add_to_env(sh->temp2, environ); } else my_putstr("Syntaxe error\n\n"); }
int _builtin_export(char **cmd, t_shenv *shenv) { int i; char *cmd_name; char *name; char *value; i = 1; if (cmd[1] == NULL) return (_builtin_env(cmd, shenv)); cmd_name = strdup("export"); while (cmd[i] != NULL) { name = strtok(strdup(cmd[i]), "="); if ((value = strtok(NULL, "=")) == NULL) export_var(cmd_name, name, shenv); else add_to_env(cmd_name, name, value, shenv); ++i; } xfree(1, &cmd_name); return (EXIT_SUCCESS); }
/** * Parse the command-line parameters, setting the various globals that are * affected by them. * * Parameters: * argc - argument count, as passed to main() * argv - argument vector, as passed to main() */ static void parse_params(int argc, char **argv) { int opt; int argsLeft; opterr = 0; /* NOTE: x_getopt() is the old public domain getopt(). The source lives in "getopt.c". The function's name has been changed to avoid conflicts with the native getopt() on the host operating system. So far, I've seen two kinds of conflicts: 1. GNU getopt() (e.g., on Linux systems) behaves differently from the old getopt(), unless POSIXLY_CORRECT is defined in the environment. Specifically, it insists on processing options even after the first non-option argument has been seen on the command line. Initially, I got around this problem by forcing the use of the included public domain getopt() function. 2. The types used in the included public domain getopt() conflict with the types of the native getopt() on some operating systems (e.g., Solaris 8). Using x_getopt() ensures that daemonize uses its own version, which always behaves consistently. */ while ( (opt = x_getopt(argc, argv, "ac:u:p:vo:e:E:l:")) != -1) { switch (opt) { case 'a': append = 1; break; case 'c': cwd = x_optarg; break; case 'p': pid_file = x_optarg; break; case 'v': be_verbose = TRUE; break; case 'u': user = x_optarg; break; case 'o': out_file = x_optarg; break; case 'e': err_file = x_optarg; break; case 'l': lock_file = x_optarg; break; case 'E': add_to_env('E', x_optarg); break; default: fprintf(stderr, "Bad option: -%c\n", x_optopt); usage(argv[0]); } } argsLeft = argc - x_optind; if (argsLeft < 1) usage(argv[0]); cmd = &argv[x_optind]; return; }