root/opal/mca/pmix/pmix4x/pmix/src/mca/base/pmix_mca_base_parse_paramfile.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. pmix_mca_base_parse_paramfile
  2. pmix_mca_base_internal_env_store
  3. save_value

   1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
   2 /*
   3  * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
   4  *                         University Research and Technology
   5  *                         Corporation.  All rights reserved.
   6  * Copyright (c) 2004-2005 The University of Tennessee and The University
   7  *                         of Tennessee Research Foundation.  All rights
   8  *                         reserved.
   9  * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
  10  *                         University of Stuttgart.  All rights reserved.
  11  * Copyright (c) 2004-2005 The Regents of the University of California.
  12  *                         All rights reserved.
  13  * Copyright (c) 2013      Los Alamos National Security, LLC. All rights
  14  *                         reserved.
  15  * Copyright (c) 2016      Intel, Inc. All rights reserved
  16  * $COPYRIGHT$
  17  *
  18  * Additional copyrights may follow
  19  *
  20  * $HEADER$
  21  */
  22 
  23 #include <src/include/pmix_config.h>
  24 
  25 #include <stdio.h>
  26 #include <string.h>
  27 
  28 #include "src/class/pmix_list.h"
  29 #include "src/mca/mca.h"
  30 #include "src/mca/base/base.h"
  31 #include "src/mca/base/pmix_mca_base_vari.h"
  32 #include "src/util/keyval_parse.h"
  33 
  34 static void save_value(const char *name, const char *value);
  35 
  36 static char * file_being_read;
  37 static pmix_list_t * _param_list;
  38 
  39 int pmix_mca_base_parse_paramfile(const char *paramfile, pmix_list_t *list)
  40 {
  41     file_being_read = (char*)paramfile;
  42     _param_list = list;
  43 
  44     return pmix_util_keyval_parse(paramfile, save_value);
  45 }
  46 
  47 int pmix_mca_base_internal_env_store(void)
  48 {
  49     return pmix_util_keyval_save_internal_envars(save_value);
  50 }
  51 
  52 static void save_value(const char *name, const char *value)
  53 {
  54     pmix_mca_base_var_file_value_t *fv;
  55     bool found = false;
  56 
  57     /* First traverse through the list and ensure that we don't
  58        already have a param of this name.  If we do, just replace the
  59        value. */
  60 
  61     PMIX_LIST_FOREACH(fv, _param_list, pmix_mca_base_var_file_value_t) {
  62         if (0 == strcmp(name, fv->mbvfv_var)) {
  63             if (NULL != fv->mbvfv_value) {
  64                 free (fv->mbvfv_value);
  65             }
  66             found = true;
  67             break;
  68         }
  69     }
  70 
  71     if (!found) {
  72         /* We didn't already have the param, so append it to the list */
  73         fv = PMIX_NEW(pmix_mca_base_var_file_value_t);
  74         if (NULL == fv) {
  75             return;
  76         }
  77 
  78         fv->mbvfv_var = strdup(name);
  79         pmix_list_append(_param_list, &fv->super);
  80     }
  81 
  82     fv->mbvfv_value = value ? strdup(value) : NULL;
  83     fv->mbvfv_file  = file_being_read;
  84     fv->mbvfv_lineno = pmix_util_keyval_parse_lineno;
  85 }

/* [<][>][^][v][top][bottom][index][help] */