File: params.c

package info (click to toggle)
vflib3 3.6.14.dfsg-3+nmu3
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 11,536 kB
  • ctags: 3,710
  • sloc: ansic: 35,811; sh: 10,357; asm: 3,290; makefile: 962; lisp: 123; perl: 109; awk: 43
file content (137 lines) | stat: -rw-r--r-- 3,183 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/*
 * param.c - handling vflibcap parameters
 * by Hirotsugu Kakugawa
 *
 * Edition History
 *  22 Mar 1997  First implementation
 *   9 Jan 1998  For VFlib 3.4.
 */
/*
 * Copyright (C) 1997-1998 Hirotsugu Kakugawa. 
 * All rights reserved.
 *
 * This file is part of the VFlib Library.  This library is free
 * software; you can redistribute it and/or modify it under the terms of
 * the GNU Library General Public License as published by the Free
 * Software Foundation; either version 2 of the License, or (at your
 * option) any later version.  This library is distributed in the hope
 * that it will be useful, but WITHOUT ANY WARRANTY; without even the
 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
 * PURPOSE.  See the GNU Library General Public License for more details.
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#ifdef HAVE_UNISTD_H
#  include <unistd.h>
#endif
#include <sys/param.h>
#include <ctype.h>

#include "VFlib-3_6.h"
#include "VFsys.h"
#include "params.h"
#include "sexp.h"



/* Default values given at VF_Init(). */
Private SEXP_ALIST   parameters_args    = NULL;

/* Default values given in vflibcap. */
Private SEXP_ALIST   parameters_default = NULL;


/*
 * Parse default values given at VF_Init(). 
 */
Glocal int
vf_params_init(char *params)
{
  if (parameters_args != NULL)
    vf_sexp_free(&parameters_args);

  if (params == NULL)
    return 0;

  if ((parameters_args = vf_sexp_cstring2alist(params)) == NULL)
    return -1;
  if (vf_dbg_parameters == 1){
    printf(">> Parameter by VF_Init(): ");
    vf_sexp_pp(parameters_args);
  }
  
  return 0;
}


/*
 * Parse default values given in vflibcap. 
 */
Glocal int
vf_params_default(SEXP_ALIST params)
{
  if ((params != NULL) && !vf_sexp_alistp(params)){
    fprintf(stderr, "VFlib Warning: %s: ", 
	    "variable value list in vflibcap must be an alist. ignored.\n");
    vf_sexp_pp(params);
    return -1;
  }

  if (parameters_default != NULL)
    vf_sexp_free(&parameters_default);

  if (params == NULL)
    return 0;

  parameters_default = params;

  if (vf_dbg_parameters == 1){
    printf(">> Parameters in vflibcap: ");
    vf_sexp_pp(params);
  }

  return 0;
}


/*
 * Lookup default values 
 */
Glocal SEXP
vf_params_lookup(char *param)
{
  SEXP  as, v;

  /* First, check values given at VF_Init(). */
  if (parameters_args != NULL){
    if ((as = vf_sexp_assoc(param, parameters_args)) != NULL){
      v = vf_sexp_cdr(as);
      if (vf_dbg_parameters == 1){
	printf(">> Parameter lookup (#1): %s ==> ", param);
	vf_sexp_pp(v);
      }
      return vf_sexp_copy(v);
    }
  }

  /* Next, check values given in vflibcap. */
  if ((parameters_default != NULL)
      && ((as = vf_sexp_assoc(param, parameters_default)) != NULL)){
    v = vf_sexp_cdr(as);
    if (vf_dbg_parameters == 1){
      printf(">> Parameter lookup (#2): %s ==> ", param);
      vf_sexp_pp(v);
    }
    return vf_sexp_copy(v);
  }

  return NULL;
}


/*EOF*/