src/params.c

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

FUNCTIONS

This source file includes following functions.
  1. vf_params_init
  2. vf_params_default
  3. vf_params_lookup

   1 /*
   2  * param.c - handling vflibcap parameters
   3  * by Hirotsugu Kakugawa
   4  *
   5  * Edition History
   6  *  22 Mar 1997  First implementation
   7  *   9 Jan 1998  For VFlib 3.4.
   8  */
   9 /*
  10  * Copyright (C) 1997-1998 Hirotsugu Kakugawa. 
  11  * All rights reserved.
  12  *
  13  * This file is part of the VFlib Library.  This library is free
  14  * software; you can redistribute it and/or modify it under the terms of
  15  * the GNU Library General Public License as published by the Free
  16  * Software Foundation; either version 2 of the License, or (at your
  17  * option) any later version.  This library is distributed in the hope
  18  * that it will be useful, but WITHOUT ANY WARRANTY; without even the
  19  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  20  * PURPOSE.  See the GNU Library General Public License for more details.
  21  * You should have received a copy of the GNU Library General Public
  22  * License along with this library; if not, write to the Free Software
  23  * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  24  */
  25 
  26 #include "config.h"
  27 #include <stdio.h>
  28 #include <stdlib.h>
  29 #ifdef HAVE_UNISTD_H
  30 #  include <unistd.h>
  31 #endif
  32 #include <sys/param.h>
  33 #include <ctype.h>
  34 
  35 #include "VFlib-3_6.h"
  36 #include "VFsys.h"
  37 #include "params.h"
  38 #include "sexp.h"
  39 
  40 
  41 
  42 /* Default values given at VF_Init(). */
  43 Private SEXP_ALIST   parameters_args    = NULL;
  44 
  45 /* Default values given in vflibcap. */
  46 Private SEXP_ALIST   parameters_default = NULL;
  47 
  48 
  49 /*
  50  * Parse default values given at VF_Init(). 
  51  */
  52 Glocal int
  53 vf_params_init(char *params)
     /* [<][>][^][v][top][bottom][index][help] */
  54 {
  55   if (parameters_args != NULL)
  56     vf_sexp_free(&parameters_args);
  57 
  58   if (params == NULL)
  59     return 0;
  60 
  61   if ((parameters_args = vf_sexp_cstring2alist(params)) == NULL)
  62     return -1;
  63   if (vf_dbg_parameters == 1){
  64     printf(">> Parameter by VF_Init(): ");
  65     vf_sexp_pp(parameters_args);
  66   }
  67   
  68   return 0;
  69 }
  70 
  71 
  72 /*
  73  * Parse default values given in vflibcap. 
  74  */
  75 Glocal int
  76 vf_params_default(SEXP_ALIST params)
     /* [<][>][^][v][top][bottom][index][help] */
  77 {
  78   if ((params != NULL) && !vf_sexp_alistp(params)){
  79     fprintf(stderr, "VFlib Warning: %s: ", 
  80             "variable value list in vflibcap must be an alist. ignored.\n");
  81     vf_sexp_pp(params);
  82     return -1;
  83   }
  84 
  85   if (parameters_default != NULL)
  86     vf_sexp_free(&parameters_default);
  87 
  88   if (params == NULL)
  89     return 0;
  90 
  91   parameters_default = params;
  92 
  93   if (vf_dbg_parameters == 1){
  94     printf(">> Parameters in vflibcap: ");
  95     vf_sexp_pp(params);
  96   }
  97 
  98   return 0;
  99 }
 100 
 101 
 102 /*
 103  * Lookup default values 
 104  */
 105 Glocal SEXP
 106 vf_params_lookup(char *param)
     /* [<][>][^][v][top][bottom][index][help] */
 107 {
 108   SEXP  as, v;
 109 
 110   /* First, check values given at VF_Init(). */
 111   if (parameters_args != NULL){
 112     if ((as = vf_sexp_assoc(param, parameters_args)) != NULL){
 113       v = vf_sexp_cdr(as);
 114       if (vf_dbg_parameters == 1){
 115         printf(">> Parameter lookup (#1): %s ==> ", param);
 116         vf_sexp_pp(v);
 117       }
 118       return vf_sexp_copy(v);
 119     }
 120   }
 121 
 122   /* Next, check values given in vflibcap. */
 123   if ((parameters_default != NULL)
 124       && ((as = vf_sexp_assoc(param, parameters_default)) != NULL)){
 125     v = vf_sexp_cdr(as);
 126     if (vf_dbg_parameters == 1){
 127       printf(">> Parameter lookup (#2): %s ==> ", param);
 128       vf_sexp_pp(v);
 129     }
 130     return vf_sexp_copy(v);
 131   }
 132 
 133   return NULL;
 134 }
 135 
 136 
 137 /*EOF*/

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