projects
/
pspp
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Change explicit variable name checks into use of dict_class_from_id().
[pspp]
/
src
/
vars-prs.c
diff --git
a/src/vars-prs.c
b/src/vars-prs.c
index 2377d538a52a81da67fc0dcf3a3ecc3f315e2d24..6f3d7f3e279b3fd6745cc6dead6154ac98bf72b9 100644
(file)
--- a/
src/vars-prs.c
+++ b/
src/vars-prs.c
@@
-30,6
+30,9
@@
#include "misc.h"
#include "str.h"
#include "misc.h"
#include "str.h"
+/* Parses a name as a variable within VS and returns the variable
+ if successful. On failure emits an error message and returns
+ a null pointer. */
static struct variable *
parse_vs_variable (struct var_set *vs)
{
static struct variable *
parse_vs_variable (struct var_set *vs)
{
@@
-49,6
+52,9
@@
parse_vs_variable (struct var_set *vs)
return vp;
}
return vp;
}
+/* Parses a variable name in dictionary D and returns the
+ variable if successful. On failure emits an error message and
+ returns a null pointer. */
struct variable *
parse_dict_variable (struct dictionary *d)
{
struct variable *
parse_dict_variable (struct dictionary *d)
{
@@
-58,13
+64,17
@@
parse_dict_variable (struct dictionary *d)
return var;
}
return var;
}
+/* Parses a variable name in default_dict and returns the
+ variable if successful. On failure emits an error message and
+ returns a null pointer. */
struct variable *
parse_variable (void)
{
return parse_dict_variable (default_dict);
}
struct variable *
parse_variable (void)
{
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)
{
enum dict_class
dict_class_from_id (const char *name)
{
@@
-81,22
+91,26
@@
dict_class_from_id (const char *name)
}
}
}
}
+/* 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:
const char *
dict_class_to_name (enum dict_class dict_class)
{
switch (dict_class)
{
case DC_ORDINARY:
- return
"ordinary"
;
+ return
_("ordinary")
;
case DC_SYSTEM:
case DC_SYSTEM:
- return
"system"
;
+ return
_("system")
;
case DC_SCRATCH:
case DC_SCRATCH:
- return
"scratch"
;
+ return
_("scratch")
;
default:
assert (0);
}
}
default:
assert (0);
}
}
+/* Parses a set of variables from dictionary D given options
+ OPTS. Resulting list of variables stored in *VAR and the
+ number of variables into *CNT. */
int
parse_variables (struct dictionary *d, struct variable ***var, int *cnt,
int opts)
int
parse_variables (struct dictionary *d, struct variable ***var, int *cnt,
int opts)
@@
-124,7
+138,7
@@
parse_var_set_vars (struct var_set *vs,
{
size_t vs_var_cnt;
int i;
{
size_t vs_var_cnt;
int i;
- char *included;
+ char *included
= NULL
;
struct variable *v1, *v2;
int count, mv;
struct variable *v1, *v2;
int count, mv;
@@
-297,6
+311,9
@@
fail:
return 0;
}
return 0;
}
+/* Extracts a numeric suffix from variable name S, copying it
+ into string R. Sets *D to the length of R and *N to its
+ value. */
static int
extract_num (char *s, char *r, int *n, int *d)
{
static int
extract_num (char *s, char *r, int *n, int *d)
{
@@
-375,7
+392,8
@@
parse_DATA_LIST_vars (char ***names, int *nnames, int pv_opts)
lex_error ("expecting variable name");
goto fail;
}
lex_error ("expecting variable name");
goto fail;
}
- if (tokid[0] == '#' && (pv_opts & PV_NO_SCRATCH))
+ if (dict_class_from_id (tokid) == DC_SCRATCH
+ && (pv_opts & PV_NO_SCRATCH))
{
msg (SE, _("Scratch variables not allowed here."));
goto fail;
{
msg (SE, _("Scratch variables not allowed here."));
goto fail;
@@
-502,6
+520,7
@@
fail:
return 0;
}
\f
return 0;
}
\f
+/* A set of variables. */
struct var_set
{
size_t (*get_cnt) (struct var_set *);
struct var_set
{
size_t (*get_cnt) (struct var_set *);
@@
-511,6
+530,7
@@
struct var_set
void *aux;
};
void *aux;
};
+/* Returns the number of variables in VS. */
size_t
var_set_get_cnt (struct var_set *vs)
{
size_t
var_set_get_cnt (struct var_set *vs)
{
@@
-519,6
+539,8
@@
var_set_get_cnt (struct var_set *vs)
return vs->get_cnt (vs);
}
return vs->get_cnt (vs);
}
+/* Return variable with index IDX in VS.
+ IDX must be less than the number of variables in VS. */
struct variable *
var_set_get_var (struct var_set *vs, size_t idx)
{
struct variable *
var_set_get_var (struct var_set *vs, size_t idx)
{
@@
-528,6
+550,8
@@
var_set_get_var (struct var_set *vs, size_t idx)
return vs->get_var (vs, idx);
}
return vs->get_var (vs, idx);
}
+/* Returns the variable in VS named NAME, or a null pointer if VS
+ contains no variable with that name. */
struct variable *
var_set_lookup_var (struct var_set *vs, const char *name)
{
struct variable *
var_set_lookup_var (struct var_set *vs, const char *name)
{
@@
-538,6
+562,7
@@
var_set_lookup_var (struct var_set *vs, const char *name)
return vs->lookup_var (vs, name);
}
return vs->lookup_var (vs, name);
}
+/* Destroys VS. */
void
var_set_destroy (struct var_set *vs)
{
void
var_set_destroy (struct var_set *vs)
{
@@
-545,6
+570,7
@@
var_set_destroy (struct var_set *vs)
vs->destroy (vs);
}
\f
vs->destroy (vs);
}
\f
+/* Returns the number of variables in VS. */
static size_t
dict_var_set_get_cnt (struct var_set *vs)
{
static size_t
dict_var_set_get_cnt (struct var_set *vs)
{
@@
-553,6
+579,8
@@
dict_var_set_get_cnt (struct var_set *vs)
return dict_get_var_cnt (d);
}
return dict_get_var_cnt (d);
}
+/* Return variable with index IDX in VS.
+ IDX must be less than the number of variables in VS. */
static struct variable *
dict_var_set_get_var (struct var_set *vs, size_t idx)
{
static struct variable *
dict_var_set_get_var (struct var_set *vs, size_t idx)
{
@@
-561,6
+589,8
@@
dict_var_set_get_var (struct var_set *vs, size_t idx)
return dict_get_var (d, idx);
}
return dict_get_var (d, idx);
}
+/* Returns the variable in VS named NAME, or a null pointer if VS
+ contains no variable with that name. */
static struct variable *
dict_var_set_lookup_var (struct var_set *vs, const char *name)
{
static struct variable *
dict_var_set_lookup_var (struct var_set *vs, const char *name)
{
@@
-569,12
+599,14
@@
dict_var_set_lookup_var (struct var_set *vs, const char *name)
return dict_lookup_var (d, name);
}
return dict_lookup_var (d, name);
}
+/* Destroys VS. */
static void
dict_var_set_destroy (struct var_set *vs)
{
free (vs);
}
static void
dict_var_set_destroy (struct var_set *vs)
{
free (vs);
}
+/* Returns a variable set based on D. */
struct var_set *
var_set_create_from_dict (struct dictionary *d)
{
struct var_set *
var_set_create_from_dict (struct dictionary *d)
{
@@
-587,13
+619,15
@@
var_set_create_from_dict (struct dictionary *d)
return vs;
}
\f
return vs;
}
\f
+/* A variable set based on an array. */
struct array_var_set
{
struct array_var_set
{
- struct variable **var;
- size_t var_cnt;
- struct hsh_table *name_tab;
+ struct variable **var;
/* Array of variables. */
+ size_t var_cnt;
/* Number of elements in var. */
+ struct hsh_table *name_tab;
/* Hash from variable names to variables. */
};
};
+/* Returns the number of variables in VS. */
static size_t
array_var_set_get_cnt (struct var_set *vs)
{
static size_t
array_var_set_get_cnt (struct var_set *vs)
{
@@
-602,6
+636,8
@@
array_var_set_get_cnt (struct var_set *vs)
return avs->var_cnt;
}
return avs->var_cnt;
}
+/* Return variable with index IDX in VS.
+ IDX must be less than the number of variables in VS. */
static struct variable *
array_var_set_get_var (struct var_set *vs, size_t idx)
{
static struct variable *
array_var_set_get_var (struct var_set *vs, size_t idx)
{
@@
-610,6
+646,8
@@
array_var_set_get_var (struct var_set *vs, size_t idx)
return avs->var[idx];
}
return avs->var[idx];
}
+/* Returns the variable in VS named NAME, or a null pointer if VS
+ contains no variable with that name. */
static struct variable *
array_var_set_lookup_var (struct var_set *vs, const char *name)
{
static struct variable *
array_var_set_lookup_var (struct var_set *vs, const char *name)
{
@@
-621,6
+659,7
@@
array_var_set_lookup_var (struct var_set *vs, const char *name)
return hsh_find (avs->name_tab, &v);
}
return hsh_find (avs->name_tab, &v);
}
+/* Destroys VS. */
static void
array_var_set_destroy (struct var_set *vs)
{
static void
array_var_set_destroy (struct var_set *vs)
{
@@
-631,6
+670,8
@@
array_var_set_destroy (struct var_set *vs)
free (vs);
}
free (vs);
}
+/* Returns a variable set based on the VAR_CNT variables in
+ VAR. */
struct var_set *
var_set_create_from_array (struct variable **var, size_t var_cnt)
{
struct var_set *
var_set_create_from_array (struct variable **var, size_t var_cnt)
{