projects
/
pspp
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Made src/language into one big library. Closes patch #5633
[pspp]
/
src
/
language
/
stats
/
rank.q
diff --git
a/src/language/stats/rank.q
b/src/language/stats/rank.q
index 59846c85bf20f27903bb280a87a0ae769db55163..f64778ae78fa4add452f969b64505220f25a198a 100644
(file)
--- a/
src/language/stats/rank.q
+++ b/
src/language/stats/rank.q
@@
-24,6
+24,8
@@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
#include "sort-criteria.h"
#include <data/dictionary.h>
#include "sort-criteria.h"
#include <data/dictionary.h>
+#include <data/format.h>
+#include <data/missing-values.h>
#include <data/procedure.h>
#include <data/variable.h>
#include <data/case.h>
#include <data/procedure.h>
#include <data/variable.h>
#include <data/case.h>
@@
-117,7
+119,7
@@
static const struct fmt_spec dest_format[n_RANK_FUNCS] = {
{FMT_F, 8, 4} /* savage */
};
{FMT_F, 8, 4} /* savage */
};
-static const char *function_name[n_RANK_FUNCS] = {
+static const char *
const
function_name[n_RANK_FUNCS] = {
"RANK",
"NORMAL",
"PERCENT",
"RANK",
"NORMAL",
"PERCENT",
@@
-128,7
+130,7
@@
static const char *function_name[n_RANK_FUNCS] = {
"SAVAGE"
};
"SAVAGE"
};
-static rank_function_t rank_func[n_RANK_FUNCS] = {
+static
const
rank_function_t rank_func[n_RANK_FUNCS] = {
rank_rank,
rank_normal,
rank_percent,
rank_rank,
rank_normal,
rank_percent,
@@
-148,7
+150,7
@@
struct rank_spec
/* Function to use for testing for missing values */
/* Function to use for testing for missing values */
-static is_missing_func *value_is_missing;
+static
mv_
is_missing_func *value_is_missing;
static struct rank_spec *rank_specs;
static size_t n_rank_specs;
static struct rank_spec *rank_specs;
static size_t n_rank_specs;
@@
-168,6
+170,7
@@
static struct cmd_rank cmd;
static struct casefile *rank_sorted_casefile (struct casefile *cf,
const struct sort_criteria *,
static struct casefile *rank_sorted_casefile (struct casefile *cf,
const struct sort_criteria *,
+ const struct dictionary *,
const struct rank_spec *rs,
int n_rank_specs,
int idx,
const struct rank_spec *rs,
int n_rank_specs,
int idx,
@@
-215,44
+218,45
@@
create_var_label (struct variable *dest_var,
for (g = 0 ; g < n_group_vars ; ++g )
{
if ( g > 0 ) ds_put_cstr (&group_var_str, " ");
for (g = 0 ; g < n_group_vars ; ++g )
{
if ( g > 0 ) ds_put_cstr (&group_var_str, " ");
- ds_put_cstr (&group_var_str,
group_vars[g]->name
);
+ ds_put_cstr (&group_var_str,
var_get_name (group_vars[g])
);
}
ds_put_format (&label, _("%s of %s by %s"), function_name[f],
}
ds_put_format (&label, _("%s of %s by %s"), function_name[f],
-
src_var->name
, ds_cstr (&group_var_str));
+
var_get_name (src_var)
, ds_cstr (&group_var_str));
ds_destroy (&group_var_str);
}
else
ds_destroy (&group_var_str);
}
else
- ds_put_format (&label,_("%s of %s"), function_name[f], src_var->name);
+ ds_put_format (&label, _("%s of %s"),
+ function_name[f], var_get_name (src_var));
-
dest_var->label = strdup (ds_cstr (&label)
);
+
var_set_label (dest_var, ds_cstr (&label)
);
ds_destroy (&label);
}
static bool
ds_destroy (&label);
}
static bool
-rank_cmd (const struct sort_criteria *sc,
- const struct rank_spec *rank_specs, int n_rank_specs)
+rank_cmd (
struct dataset *ds,
const struct sort_criteria *sc,
+
const struct rank_spec *rank_specs, int n_rank_specs)
{
struct sort_criteria criteria;
bool result = true;
int i;
{
struct sort_criteria criteria;
bool result = true;
int i;
- const int n_splits = dict_get_split_cnt (d
efault_dict
);
+ const int n_splits = dict_get_split_cnt (d
ataset_dict (ds)
);
criteria.crit_cnt = n_splits + n_group_vars + 1;
criteria.crits = xnmalloc (criteria.crit_cnt, sizeof *criteria.crits);
for (i = 0; i < n_splits ; i++)
{
criteria.crit_cnt = n_splits + n_group_vars + 1;
criteria.crits = xnmalloc (criteria.crit_cnt, sizeof *criteria.crits);
for (i = 0; i < n_splits ; i++)
{
- struct variable *v = dict_get_split_vars (d
efault_dict
)[i];
- criteria.crits[i].fv = v
->fv
;
- criteria.crits[i].width = v
->width
;
+ struct variable *v = dict_get_split_vars (d
ataset_dict (ds)
)[i];
+ criteria.crits[i].fv = v
ar_get_case_index (v)
;
+ criteria.crits[i].width = v
ar_get_width (v)
;
criteria.crits[i].dir = SRT_ASCEND;
}
for (i = 0; i < n_group_vars; i++)
{
criteria.crits[i].dir = SRT_ASCEND;
}
for (i = 0; i < n_group_vars; i++)
{
- criteria.crits[i + n_splits].fv =
group_vars[i]->fv
;
- criteria.crits[i + n_splits].width =
group_vars[i]->width
;
+ criteria.crits[i + n_splits].fv =
var_get_case_index (group_vars[i])
;
+ criteria.crits[i + n_splits].width =
var_get_width (group_vars[i])
;
criteria.crits[i + n_splits].dir = SRT_ASCEND;
}
for (i = 0 ; i < sc->crit_cnt ; ++i )
criteria.crits[i + n_splits].dir = SRT_ASCEND;
}
for (i = 0 ; i < sc->crit_cnt ; ++i )
@@
-263,28
+267,29
@@
rank_cmd (const struct sort_criteria *sc,
struct casefile *sorted_cf ;
/* Obtain active file in CF. */
struct casefile *sorted_cf ;
/* Obtain active file in CF. */
- if (!procedure (NULL, NULL))
+ if (!procedure (
ds,
NULL, NULL))
goto error;
goto error;
- cf = proc_capture_output ();
+ cf = proc_capture_output (
ds
);
/* Sort CF into SORTED_CF. */
reader = casefile_get_destructive_reader (cf) ;
criteria.crits[criteria.crit_cnt - 1] = sc->crits[i];
/* Sort CF into SORTED_CF. */
reader = casefile_get_destructive_reader (cf) ;
criteria.crits[criteria.crit_cnt - 1] = sc->crits[i];
- assert ( sc->crits[i].fv ==
src_vars[i]->fv
);
+ assert ( sc->crits[i].fv ==
var_get_case_index (src_vars[i])
);
sorted_cf = sort_execute (reader, &criteria);
casefile_destroy (cf);
out = rank_sorted_casefile (sorted_cf, &criteria,
sorted_cf = sort_execute (reader, &criteria);
casefile_destroy (cf);
out = rank_sorted_casefile (sorted_cf, &criteria,
+ dataset_dict (ds),
rank_specs, n_rank_specs,
rank_specs, n_rank_specs,
- i,
&src_vars[i]->miss)
;
+ i,
var_get_missing_values (src_vars[i]))
;
if ( NULL == out )
{
result = false ;
continue ;
}
if ( NULL == out )
{
result = false ;
continue ;
}
- proc_set_source (storage_source_create (out));
+ proc_set_source (
ds,
storage_source_create (out));
}
free (criteria.crits);
}
free (criteria.crits);
@@
-487,6
+492,7
@@
rank_savage (double c, double cc, double cc_1,
static void
rank_cases (struct casereader *cr,
unsigned long end,
static void
rank_cases (struct casereader *cr,
unsigned long end,
+ const struct dictionary *dict,
const struct sort_criterion *criterion,
const struct missing_values *mv,
double w,
const struct sort_criterion *criterion,
const struct missing_values *mv,
double w,
@@
-515,15
+521,15
@@
rank_cases (struct casereader *cr,
if (!casereader_read_xfer (cr, &this_case))
break;
if (!casereader_read_xfer (cr, &this_case))
break;
- this_value = case_data (&this_case, fv);
- c = dict_get_case_weight (d
efault_d
ict, &this_case, &warn);
+ this_value = case_data
_idx
(&this_case, fv);
+ c = dict_get_case_weight (dict, &this_case, &warn);
lookahead = casereader_clone (cr);
n = 0;
while (casereader_cnum (lookahead) < end
&& casereader_read_xfer (lookahead, &lookahead_case))
{
lookahead = casereader_clone (cr);
n = 0;
while (casereader_cnum (lookahead) < end
&& casereader_read_xfer (lookahead, &lookahead_case))
{
- const union value *lookahead_value = case_data (&lookahead_case, fv);
+ const union value *lookahead_value = case_data
_idx
(&lookahead_case, fv);
int diff = compare_values (this_value, lookahead_value, width);
if (diff != 0)
int diff = compare_values (this_value, lookahead_value, width);
if (diff != 0)
@@
-535,7
+541,7
@@
rank_cases (struct casereader *cr,
break;
}
break;
}
- c += dict_get_case_weight (d
efault_d
ict, &lookahead_case, &warn);
+ c += dict_get_case_weight (dict, &lookahead_case, &warn);
case_destroy (&lookahead_case);
n++;
}
case_destroy (&lookahead_case);
n++;
}
@@
-549,12
+555,12
@@
rank_cases (struct casereader *cr,
{
for (i = 0; i < n_rank_specs; ++i)
{
{
for (i = 0; i < n_rank_specs; ++i)
{
- const
int dest_idx = rs[i].destvars[dest_var_index]->fv
;
+ const
struct variable *dst_var = rs[i].destvars[dest_var_index]
;
if ( value_is_missing (mv, this_value) )
if ( value_is_missing (mv, this_value) )
- case_data_rw (&this_case, d
est_idx
)->f = SYSMIS;
+ case_data_rw (&this_case, d
st_var
)->f = SYSMIS;
else
else
- case_data_rw (&this_case, d
est_idx
)->f =
+ case_data_rw (&this_case, d
st_var
)->f =
rank_func[rs[i].rfunc](c, cc, cc_1, iter, w);
}
casefile_append_xfer (dest, &this_case);
rank_func[rs[i].rfunc](c, cc, cc_1, iter, w);
}
casefile_append_xfer (dest, &this_case);
@@
-578,8
+584,8
@@
same_group (const struct ccase *a, const struct ccase *b,
for (i = 0; i < crit->crit_cnt - 1; i++)
{
struct sort_criterion *c = &crit->crits[i];
for (i = 0; i < crit->crit_cnt - 1; i++)
{
struct sort_criterion *c = &crit->crits[i];
- if (compare_values (case_data
(a, c->fv), case_data (b
, c->fv),
- c->width) != 0)
+ if (compare_values (case_data
_idx (a
, c->fv),
+ c
ase_data_idx (b, c->fv), c
->width) != 0)
return false;
}
return false;
}
@@
-589,13
+595,14
@@
same_group (const struct ccase *a, const struct ccase *b,
static struct casefile *
rank_sorted_casefile (struct casefile *cf,
const struct sort_criteria *crit,
static struct casefile *
rank_sorted_casefile (struct casefile *cf,
const struct sort_criteria *crit,
+ const struct dictionary *dict,
const struct rank_spec *rs,
int n_rank_specs,
int dest_idx,
const struct missing_values *mv)
{
struct casefile *dest = fastfile_create (casefile_get_value_cnt (cf));
const struct rank_spec *rs,
int n_rank_specs,
int dest_idx,
const struct missing_values *mv)
{
struct casefile *dest = fastfile_create (casefile_get_value_cnt (cf));
- struct casereader *lookahead = casefile_get_reader (cf);
+ struct casereader *lookahead = casefile_get_reader (cf
, NULL
);
struct casereader *pos = casereader_clone (lookahead);
struct ccase group_case;
bool warn = true;
struct casereader *pos = casereader_clone (lookahead);
struct ccase group_case;
bool warn = true;
@@
-607,31
+614,35
@@
rank_sorted_casefile (struct casefile *cf,
struct ccase this_case;
const union value *this_value ;
double w = 0.0;
struct ccase this_case;
const union value *this_value ;
double w = 0.0;
- this_value = case_data( &group_case, ultimate_crit->fv);
+ this_value = case_data
_idx
( &group_case, ultimate_crit->fv);
if ( !value_is_missing(mv, this_value) )
if ( !value_is_missing(mv, this_value) )
- w = dict_get_case_weight (d
efault_d
ict, &group_case, &warn);
+ w = dict_get_case_weight (dict, &group_case, &warn);
while (casereader_read (lookahead, &this_case))
{
const union value *this_value =
while (casereader_read (lookahead, &this_case))
{
const union value *this_value =
- case_data(&this_case, ultimate_crit->fv);
- double c = dict_get_case_weight (d
efault_d
ict, &this_case, &warn);
+ case_data
_idx
(&this_case, ultimate_crit->fv);
+ double c = dict_get_case_weight (dict, &this_case, &warn);
if (!same_group (&group_case, &this_case, crit))
{
rank_cases (pos, casereader_cnum (lookahead) - 1,
if (!same_group (&group_case, &this_case, crit))
{
rank_cases (pos, casereader_cnum (lookahead) - 1,
+ dict,
ultimate_crit,
mv, w,
rs, n_rank_specs,
dest_idx, dest);
w = 0.0;
ultimate_crit,
mv, w,
rs, n_rank_specs,
dest_idx, dest);
w = 0.0;
+ case_destroy (&group_case);
case_move (&group_case, &this_case);
}
if ( !value_is_missing (mv, this_value) )
w += c;
case_move (&group_case, &this_case);
}
if ( !value_is_missing (mv, this_value) )
w += c;
+ case_destroy (&this_case);
}
}
- rank_cases (pos, ULONG_MAX, ultimate_crit, mv, w,
+ case_destroy (&group_case);
+ rank_cases (pos, ULONG_MAX, dict, ultimate_crit, mv, w,
rs, n_rank_specs, dest_idx, dest);
}
rs, n_rank_specs, dest_idx, dest);
}
@@
-648,11
+659,11
@@
rank_sorted_casefile (struct casefile *cf,
/* Transformation function to enumerate all the cases */
static int
/* Transformation function to enumerate all the cases */
static int
-create_resort_key (void *key_var_, struct ccase *cc, casenum
_t
case_num)
+create_resort_key (void *key_var_, struct ccase *cc, casenum
ber
case_num)
{
struct variable *key_var = key_var_;
{
struct variable *key_var = key_var_;
- case_data_rw(cc, key_var
->fv
)->f = case_num;
+ case_data_rw(cc, key_var)->f = case_num;
return TRNS_CONTINUE;
}
return TRNS_CONTINUE;
}
@@
-664,7
+675,7
@@
create_resort_key (void *key_var_, struct ccase *cc, casenum_t case_num)
If VNAME is NULL, then a name will be automatically chosen.
*/
static struct variable *
If VNAME is NULL, then a name will be automatically chosen.
*/
static struct variable *
-create_rank_variable (enum RANK_FUNC f,
+create_rank_variable (
struct dictionary *dict,
enum RANK_FUNC f,
const struct variable *src_var,
const char *vname)
{
const struct variable *src_var,
const char *vname)
{
@@
-673,14
+684,14
@@
create_rank_variable (enum RANK_FUNC f,
char name[SHORT_NAME_LEN + 1];
if ( vname )
char name[SHORT_NAME_LEN + 1];
if ( vname )
- var = dict_create_var(d
efault_d
ict, vname, 0);
+ var = dict_create_var(dict, vname, 0);
if ( NULL == var )
{
if ( NULL == var )
{
- snprintf(name, SHORT_NAME_LEN + 1, "%c%s",
-
function_name[f][0], src_var->name
);
+ snprintf
(name, SHORT_NAME_LEN + 1, "%c%s",
+
function_name[f][0], var_get_name (src_var)
);
- var = dict_create_var(d
efault_d
ict, name, 0);
+ var = dict_create_var(dict, name, 0);
}
i = 1;
}
i = 1;
@@
-691,7
+702,7
@@
create_rank_variable (enum RANK_FUNC f,
snprintf(name, SHORT_NAME_LEN + 1, "%s%03d", func_abb,
i);
snprintf(name, SHORT_NAME_LEN + 1, "%s%03d", func_abb,
i);
- var = dict_create_var(d
efault_d
ict, name, 0);
+ var = dict_create_var(dict, name, 0);
if (i++ >= 999)
break;
}
if (i++ >= 999)
break;
}
@@
-705,7
+716,7
@@
create_rank_variable (enum RANK_FUNC f,
snprintf(name, SHORT_NAME_LEN + 1,
"RNK%s%02d", func_abb, i);
snprintf(name, SHORT_NAME_LEN + 1,
"RNK%s%02d", func_abb, i);
- var = dict_create_var(d
efault_d
ict, name, 0);
+ var = dict_create_var(dict, name, 0);
if ( i++ >= 99 )
break;
}
if ( i++ >= 99 )
break;
}
@@
-716,12
+727,11
@@
create_rank_variable (enum RANK_FUNC f,
return NULL;
}
return NULL;
}
- var
->write = var->print = dest_format[f];
+ var
_set_both_formats (var, &dest_format[f]);
return var;
}
return var;
}
-int cmd_rank(void);
static void
rank_cleanup(void)
static void
rank_cleanup(void)
@@
-750,14
+760,14
@@
rank_cleanup(void)
}
int
}
int
-cmd_rank
(void
)
+cmd_rank
(struct lexer *lexer, struct dataset *ds
)
{
bool result;
struct variable *order;
size_t i;
n_rank_specs = 0;
{
bool result;
struct variable *order;
size_t i;
n_rank_specs = 0;
- if ( !parse_rank
(
&cmd, NULL) )
+ if ( !parse_rank
(lexer, ds,
&cmd, NULL) )
{
rank_cleanup ();
return CMD_FAILURE;
{
rank_cleanup ();
return CMD_FAILURE;
@@
-799,7
+809,7
@@
cmd_rank(void)
if ( rank_specs[i].destvars[v] == NULL )
{
rank_specs[i].destvars[v] =
if ( rank_specs[i].destvars[v] == NULL )
{
rank_specs[i].destvars[v] =
- create_rank_variable (rank_specs[i].rfunc, src_vars[v], NULL);
+ create_rank_variable (
dataset_dict(ds),
rank_specs[i].rfunc, src_vars[v], NULL);
}
create_var_label ( rank_specs[i].destvars[v],
}
create_var_label ( rank_specs[i].destvars[v],
@@
-827,7
+837,7
@@
cmd_rank(void)
ds_init_empty (&varlist);
for ( g = 0 ; g < n_group_vars ; ++g )
{
ds_init_empty (&varlist);
for ( g = 0 ; g < n_group_vars ; ++g )
{
- ds_put_cstr (&varlist,
group_vars[g]->name
);
+ ds_put_cstr (&varlist,
var_get_name (group_vars[g])
);
if ( g < n_group_vars - 1)
ds_put_cstr (&varlist, " ");
if ( g < n_group_vars - 1)
ds_put_cstr (&varlist, " ");
@@
-837,10
+847,10
@@
cmd_rank(void)
rank_specs[i].rfunc == PROPORTION )
tab_output_text (TAT_PRINTF,
_("%s into %s(%s of %s using %s BY %s)"),
rank_specs[i].rfunc == PROPORTION )
tab_output_text (TAT_PRINTF,
_("%s into %s(%s of %s using %s BY %s)"),
-
src_vars[v]->name
,
-
rank_specs[i].destvars[v]->name
,
+
var_get_name (src_vars[v])
,
+
var_get_name (rank_specs[i].destvars[v])
,
function_name[rank_specs[i].rfunc],
function_name[rank_specs[i].rfunc],
-
src_vars[v]->name
,
+
var_get_name (src_vars[v])
,
fraction_name(),
ds_cstr (&varlist)
);
fraction_name(),
ds_cstr (&varlist)
);
@@
-848,10
+858,10
@@
cmd_rank(void)
else
tab_output_text (TAT_PRINTF,
_("%s into %s(%s of %s BY %s)"),
else
tab_output_text (TAT_PRINTF,
_("%s into %s(%s of %s BY %s)"),
-
src_vars[v]->name
,
-
rank_specs[i].destvars[v]->name
,
+
var_get_name (src_vars[v])
,
+
var_get_name (rank_specs[i].destvars[v])
,
function_name[rank_specs[i].rfunc],
function_name[rank_specs[i].rfunc],
-
src_vars[v]->name
,
+
var_get_name (src_vars[v])
,
ds_cstr (&varlist)
);
ds_destroy (&varlist);
ds_cstr (&varlist)
);
ds_destroy (&varlist);
@@
-862,20
+872,20
@@
cmd_rank(void)
rank_specs[i].rfunc == PROPORTION )
tab_output_text (TAT_PRINTF,
_("%s into %s(%s of %s using %s)"),
rank_specs[i].rfunc == PROPORTION )
tab_output_text (TAT_PRINTF,
_("%s into %s(%s of %s using %s)"),
-
src_vars[v]->name
,
-
rank_specs[i].destvars[v]->name
,
+
var_get_name (src_vars[v])
,
+
var_get_name (rank_specs[i].destvars[v])
,
function_name[rank_specs[i].rfunc],
function_name[rank_specs[i].rfunc],
-
src_vars[v]->name
,
+
var_get_name (src_vars[v])
,
fraction_name()
);
else
tab_output_text (TAT_PRINTF,
_("%s into %s(%s of %s)"),
fraction_name()
);
else
tab_output_text (TAT_PRINTF,
_("%s into %s(%s of %s)"),
-
src_vars[v]->name
,
-
rank_specs[i].destvars[v]->name
,
+
var_get_name (src_vars[v])
,
+
var_get_name (rank_specs[i].destvars[v])
,
function_name[rank_specs[i].rfunc],
function_name[rank_specs[i].rfunc],
- src_vars[v]->name
+ var_get_name (src_vars[v])
);
}
}
);
}
}
@@
-888,29
+898,29
@@
cmd_rank(void)
/* Add a variable which we can sort by to get back the original
order */
/* Add a variable which we can sort by to get back the original
order */
- order = dict_create_var_assert (d
efault_dict
, "$ORDER_", 0);
+ order = dict_create_var_assert (d
ataset_dict (ds)
, "$ORDER_", 0);
- add_transformation (create_resort_key, 0, order);
+ add_transformation (
ds,
create_resort_key, 0, order);
/* Do the ranking */
/* Do the ranking */
- result = rank_cmd (sc, rank_specs, n_rank_specs);
+ result = rank_cmd (
ds,
sc, rank_specs, n_rank_specs);
/* Put the active file back in its original order */
{
struct sort_criteria criteria;
struct sort_criterion restore_criterion ;
/* Put the active file back in its original order */
{
struct sort_criteria criteria;
struct sort_criterion restore_criterion ;
- restore_criterion.fv =
order->fv
;
+ restore_criterion.fv =
var_get_case_index (order)
;
restore_criterion.width = 0;
restore_criterion.dir = SRT_ASCEND;
criteria.crits = &restore_criterion;
criteria.crit_cnt = 1;
restore_criterion.width = 0;
restore_criterion.dir = SRT_ASCEND;
criteria.crits = &restore_criterion;
criteria.crit_cnt = 1;
- sort_active_file_in_place (&criteria);
+ sort_active_file_in_place (
ds,
&criteria);
}
/* ... and we don't need our sort key anymore. So delete it */
}
/* ... and we don't need our sort key anymore. So delete it */
- dict_delete_var (d
efault_dict
, order);
+ dict_delete_var (d
ataset_dict (ds)
, order);
rank_cleanup();
rank_cleanup();
@@
-921,27
+931,28
@@
cmd_rank(void)
/* Parser for the variables sub command
Returns 1 on success */
static int
/* Parser for the variables sub command
Returns 1 on success */
static int
-rank_custom_variables
(
struct cmd_rank *cmd UNUSED, void *aux UNUSED)
+rank_custom_variables
(struct lexer *lexer, struct dataset *ds,
struct cmd_rank *cmd UNUSED, void *aux UNUSED)
{
static const int terminators[2] = {T_BY, 0};
{
static const int terminators[2] = {T_BY, 0};
- lex_match
(
'=');
+ lex_match
(lexer,
'=');
- if ((
token != T_ID || dict_lookup_var (default_dict, tokid
) == NULL)
- &&
token
!= T_ALL)
+ if ((
lex_token (lexer) != T_ID || dict_lookup_var (dataset_dict (ds), lex_tokid (lexer)
) == NULL)
+ &&
lex_token (lexer)
!= T_ALL)
return 2;
return 2;
- sc = sort_parse_criteria (
default_dict
,
+ sc = sort_parse_criteria (
lexer, dataset_dict (ds)
,
&src_vars, &n_src_vars, 0, terminators);
&src_vars, &n_src_vars, 0, terminators);
- if ( lex_match
(
T_BY) )
+ if ( lex_match
(lexer,
T_BY) )
{
{
- if ((
token != T_ID || dict_lookup_var (default_dict, tokid
) == NULL))
+ if ((
lex_token (lexer) != T_ID || dict_lookup_var (dataset_dict (ds), lex_tokid (lexer)
) == NULL))
{
return 2;
}
{
return 2;
}
- if (!parse_variables (default_dict, &group_vars, &n_group_vars,
+ if (!parse_variables (lexer, dataset_dict (ds),
+ &group_vars, &n_group_vars,
PV_NO_DUPLICATE | PV_NUMERIC | PV_NO_SCRATCH) )
{
free (group_vars);
PV_NO_DUPLICATE | PV_NUMERIC | PV_NO_SCRATCH) )
{
free (group_vars);
@@
-955,7
+966,7
@@
rank_custom_variables(struct cmd_rank *cmd UNUSED, void *aux UNUSED)
/* Parse the [/rank INTO var1 var2 ... varN ] clause */
static int
/* Parse the [/rank INTO var1 var2 ... varN ] clause */
static int
-parse_rank_function
(
struct cmd_rank *cmd UNUSED, enum RANK_FUNC f)
+parse_rank_function
(struct lexer *lexer, struct dictionary *dict,
struct cmd_rank *cmd UNUSED, enum RANK_FUNC f)
{
int var_count = 0;
{
int var_count = 0;
@@
-967,16
+978,16
@@
parse_rank_function(struct cmd_rank *cmd UNUSED, enum RANK_FUNC f)
rank_specs[n_rank_specs - 1].destvars =
xcalloc (sc->crit_cnt, sizeof (struct variable *));
rank_specs[n_rank_specs - 1].destvars =
xcalloc (sc->crit_cnt, sizeof (struct variable *));
- if (lex_match_id
(
"INTO"))
+ if (lex_match_id
(lexer,
"INTO"))
{
struct variable *destvar;
{
struct variable *destvar;
- while(
token
== T_ID )
+ while(
lex_token (lexer)
== T_ID )
{
{
- if ( dict_lookup_var (d
efault_dict, tokid
) != NULL )
+ if ( dict_lookup_var (d
ict, lex_tokid (lexer)
) != NULL )
{
{
- msg(SE, _("Variable %s already exists."),
tokid
);
+ msg(SE, _("Variable %s already exists."),
lex_tokid (lexer)
);
return 0;
}
if ( var_count >= sc->crit_cnt )
return 0;
}
if ( var_count >= sc->crit_cnt )
@@
-985,10
+996,10
@@
parse_rank_function(struct cmd_rank *cmd UNUSED, enum RANK_FUNC f)
return 0;
}
return 0;
}
- destvar = create_rank_variable (
f, src_vars[var_count], tokid
);
+ destvar = create_rank_variable (
dict, f, src_vars[var_count], lex_tokid (lexer)
);
rank_specs[n_rank_specs - 1].destvars[var_count] = destvar ;
rank_specs[n_rank_specs - 1].destvars[var_count] = destvar ;
- lex_get
(
);
+ lex_get
(lexer
);
++var_count;
}
}
++var_count;
}
}
@@
-998,58
+1009,74
@@
parse_rank_function(struct cmd_rank *cmd UNUSED, enum RANK_FUNC f)
static int
static int
-rank_custom_rank
(
struct cmd_rank *cmd, void *aux UNUSED )
+rank_custom_rank
(struct lexer *lexer, struct dataset *ds,
struct cmd_rank *cmd, void *aux UNUSED )
{
{
- return parse_rank_function(cmd, RANK);
+ struct dictionary *dict = dataset_dict (ds);
+
+ return parse_rank_function (lexer, dict, cmd, RANK);
}
static int
}
static int
-rank_custom_normal
(
struct cmd_rank *cmd, void *aux UNUSED )
+rank_custom_normal
(struct lexer *lexer, struct dataset *ds,
struct cmd_rank *cmd, void *aux UNUSED )
{
{
- return parse_rank_function(cmd, NORMAL);
+ struct dictionary *dict = dataset_dict (ds);
+
+ return parse_rank_function (lexer, dict, cmd, NORMAL);
}
static int
}
static int
-rank_custom_percent
(
struct cmd_rank *cmd, void *aux UNUSED )
+rank_custom_percent
(struct lexer *lexer, struct dataset *ds,
struct cmd_rank *cmd, void *aux UNUSED )
{
{
- return parse_rank_function (cmd, PERCENT);
+ struct dictionary *dict = dataset_dict (ds);
+
+ return parse_rank_function (lexer, dict, cmd, PERCENT);
}
static int
}
static int
-rank_custom_rfraction
(
struct cmd_rank *cmd, void *aux UNUSED )
+rank_custom_rfraction
(struct lexer *lexer, struct dataset *ds,
struct cmd_rank *cmd, void *aux UNUSED )
{
{
- return parse_rank_function(cmd, RFRACTION);
+ struct dictionary *dict = dataset_dict (ds);
+
+ return parse_rank_function (lexer, dict, cmd, RFRACTION);
}
static int
}
static int
-rank_custom_proportion
(
struct cmd_rank *cmd, void *aux UNUSED )
+rank_custom_proportion
(struct lexer *lexer, struct dataset *ds,
struct cmd_rank *cmd, void *aux UNUSED )
{
{
- return parse_rank_function(cmd, PROPORTION);
+ struct dictionary *dict = dataset_dict (ds);
+
+ return parse_rank_function (lexer, dict, cmd, PROPORTION);
}
static int
}
static int
-rank_custom_n
(
struct cmd_rank *cmd, void *aux UNUSED )
+rank_custom_n
(struct lexer *lexer, struct dataset *ds,
struct cmd_rank *cmd, void *aux UNUSED )
{
{
- return parse_rank_function(cmd, N);
+ struct dictionary *dict = dataset_dict (ds);
+
+ return parse_rank_function (lexer, dict, cmd, N);
}
static int
}
static int
-rank_custom_savage
(
struct cmd_rank *cmd, void *aux UNUSED )
+rank_custom_savage
(struct lexer *lexer, struct dataset *ds,
struct cmd_rank *cmd, void *aux UNUSED )
{
{
- return parse_rank_function(cmd, SAVAGE);
+ struct dictionary *dict = dataset_dict (ds);
+
+ return parse_rank_function (lexer, dict, cmd, SAVAGE);
}
static int
}
static int
-rank_custom_ntiles
(
struct cmd_rank *cmd, void *aux UNUSED )
+rank_custom_ntiles
(struct lexer *lexer, struct dataset *ds,
struct cmd_rank *cmd, void *aux UNUSED )
{
{
- if ( lex_force_match('(') )
+ struct dictionary *dict = dataset_dict (ds);
+
+ if ( lex_force_match (lexer, '(') )
{
{
- if ( lex_force_int
(
) )
+ if ( lex_force_int
(lexer
) )
{
{
- k_ntiles = lex_integer ();
- lex_get
(
);
- lex_force_match
(
')');
+ k_ntiles = lex_integer (
lexer
);
+ lex_get
(lexer
);
+ lex_force_match
(lexer,
')');
}
else
return 0;
}
else
return 0;
@@
-1057,5
+1084,5
@@
rank_custom_ntiles(struct cmd_rank *cmd, void *aux UNUSED )
else
return 0;
else
return 0;
- return parse_rank_function
(
cmd, NTILES);
+ return parse_rank_function
(lexer, dict,
cmd, NTILES);
}
}