root/opal/mca/base/mca_base_parse_paramfile.c

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

DEFINITIONS

This source file includes following definitions.
  1. mca_base_parse_paramfile
  2. 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$
  16  *
  17  * Additional copyrights may follow
  18  *
  19  * $HEADER$
  20  */
  21 
  22 #include "opal_config.h"
  23 
  24 #include <stdio.h>
  25 #include <string.h>
  26 
  27 #include "opal/class/opal_list.h"
  28 #include "opal/mca/mca.h"
  29 #include "opal/mca/base/base.h"
  30 #include "opal/mca/base/mca_base_vari.h"
  31 #include "opal/util/keyval_parse.h"
  32 #include "opal/util/output.h"
  33 static void save_value(const char *name, const char *value);
  34 
  35 static char * file_being_read;
  36 static opal_list_t * _param_list;
  37 
  38 int mca_base_parse_paramfile(const char *paramfile, opal_list_t *list)
  39 {
  40     file_being_read = (char*)paramfile;
  41     _param_list = list;
  42 
  43     return opal_util_keyval_parse(paramfile, save_value);
  44 }
  45 
  46 int mca_base_internal_env_store(void)
  47 {
  48     return opal_util_keyval_save_internal_envars(save_value);
  49 }
  50 
  51 static void save_value(const char *name, const char *value)
  52 {
  53     mca_base_var_file_value_t *fv;
  54     bool found = false;
  55 
  56     /* First traverse through the list and ensure that we don't
  57        already have a param of this name.  If we do, just replace the
  58        value. */
  59 
  60     OPAL_LIST_FOREACH(fv, _param_list, mca_base_var_file_value_t) {
  61         if (0 == strcmp(name, fv->mbvfv_var)) {
  62             if (NULL != fv->mbvfv_value) {
  63                 free (fv->mbvfv_value);
  64             }
  65             found = true;
  66             break;
  67         }
  68     }
  69 
  70     if (!found) {
  71         /* We didn't already have the param, so append it to the list */
  72         fv = OBJ_NEW(mca_base_var_file_value_t);
  73         if (NULL == fv) {
  74             return;
  75         }
  76 
  77         fv->mbvfv_var = strdup(name);
  78         opal_list_append(_param_list, &fv->super);
  79     }
  80 
  81     fv->mbvfv_value = value ? strdup(value) : NULL;
  82     fv->mbvfv_file  = file_being_read;
  83     fv->mbvfv_lineno = opal_util_keyval_parse_lineno;
  84 }

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