#include "hash.h"
#include "lexer.h"
#include "misc.h"
+#include "pool.h"
#include "size_max.h"
#include "str.h"
return parse_dict_variable (default_dict);
}
-/* Returns the dictionary class corresponding to a variable named
- NAME. */
-enum dict_class
-dict_class_from_id (const char *name)
-{
- assert (name != NULL);
-
- switch (name[0])
- {
- default:
- return DC_ORDINARY;
- case '$':
- return DC_SYSTEM;
- case '#':
- return DC_SCRATCH;
- }
-}
-
-/* Returns the name of dictionary class DICT_CLASS. */
-const char *
-dict_class_to_name (enum dict_class dict_class)
-{
- switch (dict_class)
- {
- case DC_ORDINARY:
- return _("ordinary");
- case DC_SYSTEM:
- return _("system");
- case DC_SCRATCH:
- return _("scratch");
- default:
- assert (0);
- abort ();
- }
-}
/* Parses a set of variables from dictionary D given options
OPTS. Resulting list of variables stored in *VAR and the
if (*nv >= *mv)
{
*mv = 2 * (*nv + 1);
- *v = xrealloc (*v, *mv * sizeof **v);
+ *v = xnrealloc (*v, *mv, sizeof **v);
}
if ((pv_opts & PV_DUPLICATE) || !included[idx])
if (mvar < nvar + (n2 - n1 + 1))
{
mvar += ROUND_UP (n2 - n1 + 1, 16);
- *names = xrealloc (*names, mvar * sizeof **names);
+ *names = xnrealloc (*names, mvar, sizeof **names);
}
for (n = n1; n <= n2; n++)
if (nvar >= mvar)
{
mvar += 16;
- *names = xrealloc (*names, mvar * sizeof **names);
+ *names = xnrealloc (*names, mvar, sizeof **names);
}
(*names)[nvar++] = xstrdup (name1);
}
if (!parse_variables (default_dict, &v, &nv, PV_NONE))
goto fail;
- *names = xrealloc (*names, (*nnames + nv) * sizeof **names);
+ *names = xnrealloc (*names, *nnames + nv, sizeof **names);
for (i = 0; i < nv; i++)
(*names)[*nnames + i] = xstrdup (v[i]->name);
free (v);
fail:
for (i = 0; i < *nnames; i++)
- free ((*names)[*nnames]);
- free (names);
+ free ((*names)[i]);
+ free (*names);
*names = NULL;
*nnames = 0;
return 0;
}
+
+/* Parses a list of variables where some of the variables may be
+ existing and the rest are to be created. Same args as
+ parse_DATA_LIST_vars(), except that all allocations are taken
+ from the given POOL. */
+int
+parse_mixed_vars_pool (struct pool *pool,
+ char ***names, size_t *nnames, int pv_opts)
+{
+ int retval = parse_mixed_vars (names, nnames, pv_opts);
+ if (retval)
+ {
+ size_t i;
+
+ for (i = 0; i < *nnames; i++)
+ pool_register (pool, free, (*names)[i]);
+ pool_register (pool, free, *names);
+ }
+ return retval;
+}
+
\f
/* A set of variables. */
struct var_set