2 * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
3 * See the copyright notice in the ACK home directory, in the file "Copyright".
10 static char rcs_id[] = "$Id: svars.c,v 2.3 1994/06/24 10:13:12 ceriel Exp $" ;
13 /* The processing of string valued variables,
14 this is an almost self contained module.
16 Five externally visible routines:
19 Associate the name with the result.
22 result a string pointer
25 Associate the name with the routine.
30 The parameters name and result are supposed to be pointing to
31 non-volatile string storage used only for this call.
34 returns the pointer to a string associated with name,
35 the pointer is produced by returning result or the
36 value returned by calling the routine.
42 getcore(size) Core allocation
46 extern char *getcore();
50 enum { routine, string } v_type;
59 static struct vars *v_first ;
61 static struct vars *newvar(name) char *name; {
62 register struct vars *new ;
64 for ( new=v_first ; new ; new= new->v_next ) {
65 if ( strcmp(name,new->v_name)==0 ) {
67 if ( new->v_type== string ) {
68 throws(new->v_value.v_string) ;
73 new= (struct vars *)getcore( (unsigned)sizeof (struct vars));
75 new->v_next= v_first ;
80 setsvar(name,str) char *name, *str ; {
81 register struct vars *new ;
85 if ( debug>=2 ) vprint("%s=%s\n", name, str) ;
88 new->v_value.v_string= str;
91 setpvar(name,rout) char *name, *(*rout)() ; {
92 register struct vars *new ;
96 if ( debug>=2 ) vprint("%s= (*%o)()\n",name,rout) ;
99 new->v_value.v_routine= rout;
102 char *getvar(name) char *name ; {
103 register struct vars *scan ;
105 for ( scan=v_first ; scan ; scan= scan->v_next ) {
106 if ( strcmp(name,scan->v_name)==0 ) {
107 switch ( scan->v_type ) {
109 return scan->v_value.v_string ;
111 return (*scan->v_value.v_routine)() ;