2001-02-19 21:15:25 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include <config.h>
|
|
|
|
#endif
|
|
|
|
#include <stdlib.h>
|
2001-05-25 16:09:14 +00:00
|
|
|
|
2001-05-09 20:50:38 +00:00
|
|
|
#include "QF/gib.h"
|
2001-05-25 16:09:14 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
#include "gib_stack.h"
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
gib_var_t *
|
|
|
|
GIB_Var_FindLocal (char *key)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
gib_var_t *var;
|
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
if (!(GIB_LOCALS))
|
|
|
|
return 0;
|
2001-02-26 06:48:02 +00:00
|
|
|
for (var = GIB_LOCALS; strcmp (key, var->key); var = var->next)
|
2001-02-19 21:15:25 +00:00
|
|
|
if (!(var->next))
|
|
|
|
return 0;
|
|
|
|
return var;
|
|
|
|
}
|
2001-02-26 06:48:02 +00:00
|
|
|
gib_var_t *
|
|
|
|
GIB_Var_FindGlobal (char *key)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
gib_var_t *var;
|
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
if (!(GIB_CURRENTMOD->vars))
|
|
|
|
return 0;
|
2001-02-26 06:48:02 +00:00
|
|
|
for (var = GIB_CURRENTMOD->vars; strcmp (key, var->key); var = var->next)
|
2001-02-19 21:15:25 +00:00
|
|
|
if (!(var->next))
|
|
|
|
return 0;
|
|
|
|
return var;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
GIB_Var_Set (char *key, char *value)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
gib_var_t *var;
|
|
|
|
|
|
|
|
if ((var = GIB_Var_FindLocal (key))) {
|
|
|
|
free (var->value);
|
|
|
|
} else {
|
|
|
|
var = malloc (sizeof (gib_var_t));
|
|
|
|
var->key = malloc (strlen (key) + 1);
|
|
|
|
strcpy (var->key, key);
|
2001-02-19 21:15:25 +00:00
|
|
|
var->next = GIB_LOCALS;
|
|
|
|
GIB_LOCALS = var;
|
|
|
|
}
|
2001-02-26 06:48:02 +00:00
|
|
|
var->value = malloc (strlen (value) + 1);
|
|
|
|
strcpy (var->value, value);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
GIB_Var_FreeAll (gib_var_t * var)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
gib_var_t *temp;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
for (; var; var = temp) {
|
2001-02-19 21:15:25 +00:00
|
|
|
temp = var->next;
|
2001-02-26 06:48:02 +00:00
|
|
|
free (var->key);
|
|
|
|
free (var->value);
|
|
|
|
free (var);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
}
|