2 * Copyright (C) 1993-2005 by Darren Reed.
3 * See the IPFILTER.LICENCE file for details on licencing.
10 typedef struct variable
{
11 struct variable
*v_next
;
16 static variable_t
*vtop
= NULL
;
18 static variable_t
*find_var
__P((char *));
19 static char *expand_string
__P((char *, int));
22 static variable_t
*find_var(name
)
27 for (v
= vtop
; v
!= NULL
; v
= v
->v_next
)
28 if (!strcmp(name
, v
->v_name
))
34 char *get_variable(string
, after
, line
)
35 char *string
, **after
;
38 char c
, *s
, *t
, *value
;
45 for (t
= s
; *t
!= '\0'; t
++)
49 fprintf(stderr
, "%d: { without }\n", line
);
52 } else if (ISALPHA(*s
)) {
53 for (t
= s
+ 1; *t
!= '\0'; t
++)
54 if (!ISALPHA(*t
) && !ISDIGIT(*t
) && (*t
!= '_'))
57 fprintf(stderr
, "%d: variables cannot start with '%c'\n",
69 fprintf(stderr
, "%d: unknown variable '%s'\n", line
, s
);
73 s
= strdup(v
->v_value
);
74 value
= expand_string(s
, line
);
81 static char *expand_string(oldstring
, line
)
85 char c
, *s
, *p1
, *p2
, *p3
, *newstring
, *value
;
89 newstring
= oldstring
;
91 for (s
= oldstring
; *s
!= '\0'; s
++)
99 bcopy(s
, s
- 1, strlen(s
));
106 value
= get_variable(s
, &p3
, line
);
110 p2
= expand_string(value
, line
);
114 len
= strlen(newstring
) + strlen(p2
);
116 if (c
== '{' && *p3
== '}')
120 p1
= malloc(len
+ 1);
125 strcpy(p1
, newstring
);
130 s
= p1
+ len
- strlen(p3
) - 1;
131 if (newstring
!= oldstring
)
141 void set_variable(name
, value
)
148 if (name
== NULL
|| value
== NULL
|| *name
== '\0')
154 v
->v_value
= strdup(value
);
160 if ((*value
== '"' && value
[len
- 1] == '"') ||
161 (*value
== '\'' && value
[len
- 1] == '\'')) {
162 value
[len
- 1] = '\0';
167 v
= (variable_t
*)malloc(sizeof(*v
));
170 v
->v_name
= strdup(name
);
171 v
->v_value
= strdup(value
);