X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Flanguage%2Fxforms%2Fcount.c;h=371f2ecbada1a33d34efea3b97019766985d3244;hb=b0ce74cb9ee2ac59e87bddb46122b63ae0b6cdf0;hp=284cdeebb5556e87b30305b9271ef99d6ee9269d;hpb=b74d09af5e07f954c18e7cdb8aca3af47fa10208;p=pspp diff --git a/src/language/xforms/count.c b/src/language/xforms/count.c index 284cdeebb5..371f2ecbad 100644 --- a/src/language/xforms/count.c +++ b/src/language/xforms/count.c @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -92,11 +93,11 @@ struct count_trns static trns_proc_func count_trns_proc; static trns_free_func count_trns_free; -static bool parse_numeric_criteria (struct pool *, struct criteria *); -static bool parse_string_criteria (struct pool *, struct criteria *); +static bool parse_numeric_criteria (struct lexer *, struct pool *, struct criteria *); +static bool parse_string_criteria (struct lexer *, struct pool *, struct criteria *); int -cmd_count (void) +cmd_count (struct lexer *lexer, struct dataset *ds) { struct dst_var *dv; /* Destination var being parsed. */ struct count_trns *trns; /* Transformation. */ @@ -114,9 +115,9 @@ cmd_count (void) dv->crit = NULL; /* Get destination variable, or at least its name. */ - if (!lex_force_id ()) + if (!lex_force_id (lexer)) goto fail; - dv->var = dict_lookup_var (default_dict, tokid); + dv->var = dict_lookup_var (dataset_dict (ds), lex_tokid (lexer)); if (dv->var != NULL) { if (dv->var->type == ALPHA) @@ -126,10 +127,10 @@ cmd_count (void) } } else - dv->name = pool_strdup (trns->pool, tokid); + dv->name = pool_strdup (trns->pool, lex_tokid (lexer)); - lex_get (); - if (!lex_force_match ('=')) + lex_get (lexer); + if (!lex_force_match (lexer, '=')) goto fail; crit = dv->crit = pool_alloc (trns->pool, sizeof *crit); @@ -139,32 +140,32 @@ cmd_count (void) crit->next = NULL; crit->vars = NULL; - if (!parse_variables (default_dict, &crit->vars, &crit->var_cnt, + if (!parse_variables (lexer, dataset_dict (ds), &crit->vars, &crit->var_cnt, PV_DUPLICATE | PV_SAME_TYPE)) goto fail; pool_register (trns->pool, free, crit->vars); - if (!lex_force_match ('(')) + if (!lex_force_match (lexer, '(')) goto fail; crit->value_cnt = 0; if (crit->vars[0]->type == NUMERIC) - ok = parse_numeric_criteria (trns->pool, crit); + ok = parse_numeric_criteria (lexer, trns->pool, crit); else - ok = parse_string_criteria (trns->pool, crit); + ok = parse_string_criteria (lexer, trns->pool, crit); if (!ok) goto fail; - if (token == '/' || token == '.') + if (lex_token (lexer) == '/' || lex_token (lexer) == '.') break; crit = crit->next = pool_alloc (trns->pool, sizeof *crit); } - if (token == '.') + if (lex_token (lexer) == '.') break; - if (!lex_force_match ('/')) + if (!lex_force_match (lexer, '/')) goto fail; dv = dv->next = pool_alloc (trns->pool, sizeof *dv); } @@ -175,13 +176,13 @@ cmd_count (void) { /* It's valid, though motivationally questionable, to count to the same dest var more than once. */ - dv->var = dict_lookup_var (default_dict, dv->name); + dv->var = dict_lookup_var (dataset_dict (ds), dv->name); if (dv->var == NULL) - dv->var = dict_create_var_assert (default_dict, dv->name, 0); + dv->var = dict_create_var_assert (dataset_dict (ds), dv->name, 0); } - add_transformation (count_trns_proc, count_trns_free, trns); + add_transformation (ds, count_trns_proc, count_trns_free, trns); return CMD_SUCCESS; fail: @@ -191,7 +192,7 @@ fail: /* Parses a set of numeric criterion values. Returns success. */ static bool -parse_numeric_criteria (struct pool *pool, struct criteria *crit) +parse_numeric_criteria (struct lexer *lexer, struct pool *pool, struct criteria *crit) { size_t allocated = 0; @@ -202,11 +203,11 @@ parse_numeric_criteria (struct pool *pool, struct criteria *crit) { double low, high; - if (lex_match_id ("SYSMIS")) + if (lex_match_id (lexer, "SYSMIS")) crit->count_system_missing = true; - else if (lex_match_id ("MISSING")) + else if (lex_match_id (lexer, "MISSING")) crit->count_user_missing = true; - else if (parse_num_range (&low, &high, NULL)) + else if (parse_num_range (lexer, &low, &high, NULL)) { struct num_value *cur; @@ -222,8 +223,8 @@ parse_numeric_criteria (struct pool *pool, struct criteria *crit) else return false; - lex_match (','); - if (lex_match (')')) + lex_match (lexer, ','); + if (lex_match (lexer, ')')) break; } return true; @@ -231,7 +232,7 @@ parse_numeric_criteria (struct pool *pool, struct criteria *crit) /* Parses a set of string criteria values. Returns success. */ static bool -parse_string_criteria (struct pool *pool, struct criteria *crit) +parse_string_criteria (struct lexer *lexer, struct pool *pool, struct criteria *crit) { int len = 0; size_t allocated = 0; @@ -250,15 +251,15 @@ parse_string_criteria (struct pool *pool, struct criteria *crit) &allocated, sizeof *crit->values.str); - if (!lex_force_string ()) + if (!lex_force_string (lexer)) return false; cur = &crit->values.str[crit->value_cnt++]; *cur = pool_alloc (pool, len + 1); - str_copy_rpad (*cur, len + 1, ds_cstr (&tokstr)); - lex_get (); + str_copy_rpad (*cur, len + 1, ds_cstr (lex_tokstr (lexer))); + lex_get (lexer); - lex_match (','); - if (lex_match (')')) + lex_match (lexer, ','); + if (lex_match (lexer, ')')) break; } @@ -324,7 +325,7 @@ count_string (struct criteria *crit, struct ccase *c) /* Performs the COUNT transformation T on case C. */ static int count_trns_proc (void *trns_, struct ccase *c, - int case_num UNUSED) + casenumber case_num UNUSED) { struct count_trns *trns = trns_; struct dst_var *dv;