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 fatal(args*) When something goes wrong
43 getcore(size) Core allocation
47 extern char *getcore();
52 enum { routine, string } v_type;
61 static struct vars *v_first ;
63 static struct vars *newvar(name) char *name; {
64 register struct vars *new ;
66 for ( new=v_first ; new ; new= new->v_next ) {
67 if ( strcmp(name,new->v_name)==0 ) {
69 if ( new->v_type== string ) {
70 throws(new->v_value.v_string) ;
75 new= (struct vars *)getcore( (unsigned)sizeof (struct vars));
77 new->v_next= v_first ;
82 setsvar(name,str) char *name, *str ; {
83 register struct vars *new ;
87 if ( debug>=2 ) vprint("%s=%s\n", name, str) ;
90 new->v_value.v_string= str;
93 setpvar(name,rout) char *name, *(*rout)() ; {
94 register struct vars *new ;
98 if ( debug>=2 ) vprint("%s= (*%o)()\n",name,rout) ;
100 new->v_type= routine;
101 new->v_value.v_routine= rout;
104 char *getvar(name) char *name ; {
105 register struct vars *scan ;
107 for ( scan=v_first ; scan ; scan= scan->v_next ) {
108 if ( strcmp(name,scan->v_name)==0 ) {
109 switch ( scan->v_type ) {
111 return scan->v_value.v_string ;
113 return (*scan->v_value.v_routine)() ;