#include "error.h"
#include <stdlib.h>
#include "alloc.h"
+#include "case.h"
#include "command.h"
#include "error.h"
#include "file-handle.h"
static trns_proc_func save_trns_proc;
static trns_free_func save_trns_free;
-#if DEBUGGING
-void dump_dict_variables (struct dictionary *);
-#endif
-
/* Parses the GET command. */
int
cmd_get (void)
if (dict == NULL)
return CMD_FAILURE;
-#if DEBUGGING
- dump_dict_variables (dict);
-#endif
if (0 == trim_dictionary (dict, &options))
{
fh_close_handle (handle);
return CMD_FAILURE;
}
-#if DEBUGGING
- dump_dict_variables (dict);
-#endif
dict_compact_values (dict);
-#if DEBUGGING
- printf (_("GET translation table from file to memory:\n"));
- for (i = 0; i < dict->nvar; i++)
- {
- struct variable *v = dict->var[i];
-
- printf (_(" %8s from %3d,%3d to %3d,%3d\n"), v->name,
- v->get.fv, v->get.nv, v->fv, v->nv);
- }
-#endif
-
dict_destroy (default_dict);
default_dict = dict;
return CMD_FAILURE;
dict = dict_clone (default_dict);
-#if DEBUGGING
- dump_dict_variables (dict);
-#endif
for (i = 0; i < dict_get_var_cnt (dict); i++)
dict_get_var (dict, i)->aux = dict_get_var (default_dict, i);
if (0 == trim_dictionary (dict, &options))
return CMD_FAILURE;
}
-#if DEBUGGING
- dump_dict_variables (dict);
-#endif
-
/* Write dictionary. */
inf.h = handle;
inf.dict = dict;
struct variable *v = t->var[i];
if (v->type == NUMERIC)
{
- double src = c->data[v->fv].f;
+ double src = case_num (c, v->fv);
if (src == SYSMIS)
*p++ = -FLT64_MAX;
else
}
else
{
- memcpy (p, c->data[v->fv].s, v->width);
+ memcpy (p, case_str (c, v->fv), v->width);
memset (&((char *) p)[v->width], ' ',
REM_RND_UP (v->width, sizeof *p));
p += DIV_RND_UP (v->width, sizeof *p);
return success;
}
-
-#if DEBUGGING
-void
-dump_dict_variables (struct dictionary * dict)
-{
- int i;
-
- printf (_("\nVariables in dictionary:\n"));
- for (i = 0; i < dict->nvar; i++)
- printf ("%s, ", dict->var[i]->name);
- printf ("\n");
-}
-#endif
\f
/* Clears internal state related to GET input procedure. */
static void
{
struct get_pgm *pgm = source->aux;
- while (sfm_read_case (pgm->handle, c->data, default_dict)
+ while (sfm_read_case (pgm->handle, c, default_dict)
&& write_case (wc_data))
;
}
struct dictionary *dict; /* Dictionary from system file. */
char in[9]; /* Name of the variable from IN=. */
char first[9], last[9]; /* Name of the variables from FIRST=, LAST=. */
- union value *input; /* Input record. */
+ struct ccase input; /* Input record. */
};
/* MATCH FILES procedure. */
file->in[0] = file->first[0] = file->last[0] = '\0';
file->dict = NULL;
file->by = NULL;
- file->input = NULL;
+ case_nullify (&file->input);
if (lex_match_id ("FILE"))
file->type = MTF_FILE;
file->dict = sfm_read_dictionary (file->handle, NULL);
if (!file->dict)
goto lossage;
+ case_create (&file->input, dict_get_next_value_idx (file->dict));
}
else
file->dict = default_dict;
name = mtf.tail->last;
sbc = "LAST";
}
- else
- assert (0);
+ else
+ {
+ assert (0);
+ abort ();
+ }
lex_match ('=');
if (token != T_ID)
}
}
-#if DEBUGGING
- {
- /* From sfm-read.c. */
- extern void dump_dictionary (struct dictionary *);
-
- dump_dictionary (mtf.dict);
- }
-#endif
-
/* MATCH FILES performs an n-way merge on all its input files.
Abstract algorithm:
dict_destroy (file->dict);
free (file->by);
if (file->handle)
- free (file->input);
+ case_destroy (&file->input);
free (file);
}
for (i = 0; i < dict_get_var_cnt (f->dict); i++)
{
struct variable *v = dict_get_var (f->dict, i);
+ union value *out = case_data_rw (mtf->mtf_case, v->p.mtf.master->fv);
if (v->type == NUMERIC)
- mtf->mtf_case->data[v->p.mtf.master->fv].f = SYSMIS;
+ out->f = SYSMIS;
else
- memset (mtf->mtf_case->data[v->p.mtf.master->fv].s, ' ', v->width);
+ memset (out->s, ' ', v->width);
}
}
{
if (iter->handle)
{
- assert (iter->input == NULL);
- iter->input = xmalloc (dict_get_case_size (iter->dict));
-
- if (!sfm_read_case (iter->handle, iter->input, iter->dict))
+ if (!sfm_read_case (iter->handle, &iter->input, iter->dict))
mtf_delete_file_in_place (mtf, &iter);
else
iter = iter->next;
struct mtf_file *a, struct mtf_file *b,
struct ccase *c)
{
- union value *a_input, *b_input;
+ struct ccase *a_input, *b_input;
int i;
assert ((a == NULL) + (b == NULL) + (c == NULL) <= 1);
- a_input = a->input != NULL ? a->input : c->data;
- b_input = b->input != NULL ? b->input : c->data;
+ a_input = case_is_null (&a->input) ? c : &a->input;
+ b_input = case_is_null (&b->input) ? c : &b->input;
for (i = 0; i < mtf->by_cnt; i++)
{
assert (a->by[i]->type == b->by[i]->type);
if (a->by[i]->type == NUMERIC)
{
- double af = a_input[a->by[i]->fv].f;
- double bf = b_input[b->by[i]->fv].f;
+ double af = case_num (a_input, a->by[i]->fv);
+ double bf = case_num (b_input, b->by[i]->fv);
if (af < bf)
return -1;
int result;
assert (a->by[i]->type == ALPHA);
- result = memcmp (a_input[a->by[i]->fv].s,
- b_input[b->by[i]->fv].s,
+ result = memcmp (case_str (a_input, a->by[i]->fv),
+ case_str (b_input, b->by[i]->fv),
a->by[i]->width);
if (result < 0)
return -1;
case 1:
if (iter->handle == NULL)
return 1;
- if (sfm_read_case (iter->handle, iter->input, iter->dict))
+ if (sfm_read_case (iter->handle, &iter->input, iter->dict))
goto again;
mtf_delete_file_in_place (mtf, &iter);
break;
for (i = 0; i < dict_get_var_cnt (iter->dict); i++)
{
struct variable *v = dict_get_var (iter->dict, i);
- union value *record;
+ struct ccase *record;
+ union value *out;
if (mtf->seq_nums[v->p.mtf.master->index] == mtf->seq_num)
continue;
mtf->seq_nums[v->p.mtf.master->index] = mtf->seq_num;
- record = iter->input != NULL ? iter->input : c->data;
+ record = case_is_null (&iter->input) ? c : &iter->input;
assert (v->type == NUMERIC || v->type == ALPHA);
+ out = case_data_rw (mtf->mtf_case, v->p.mtf.master->fv);
if (v->type == NUMERIC)
- mtf->mtf_case->data[v->p.mtf.master->fv].f = record[v->fv].f;
+ out->f = case_num (record, v->fv);
else
- memcpy (mtf->mtf_case->data[v->p.mtf.master->fv].s,
- record[v->fv].s, v->width);
+ memcpy (out->s, case_str (record, v->fv), v->width);
}
}
for (i = 0; i < dict_get_var_cnt (iter->dict); i++)
{
struct variable *v = dict_get_var (iter->dict, i);
+ union value *out;
if (mtf->seq_nums[v->p.mtf.master->index] == mtf->seq_num)
continue;
mtf->seq_nums[v->p.mtf.master->index] = mtf->seq_num;
-#if 0
- printf ("%s/%s: dest-fv=%d\n",
- fh_handle_name (iter->handle),
- v->name,
- v->p.mtf.master->fv);
-#endif
+ out = case_data_rw (mtf->mtf_case, v->p.mtf.master->fv);
if (v->type == NUMERIC)
- mtf->mtf_case->data[v->p.mtf.master->fv].f = SYSMIS;
+ out->f = SYSMIS;
else
- memset (mtf->mtf_case->data[v->p.mtf.master->fv].s, ' ',
- v->width);
+ memset (out->s, ' ', v->width);
}
if (iter->handle == NULL)
if (iter->handle)
{
- assert (iter->input != NULL);
-
- if (!sfm_read_case (iter->handle, iter->input, iter->dict))
+ if (!sfm_read_case (iter->handle, &iter->input, iter->dict))
mtf_delete_file_in_place (mtf, &iter);
}
if (dict == NULL)
return CMD_FAILURE;
-#if DEBUGGING
- dump_dict_variables (dict);
-#endif
if (0 == trim_dictionary (dict, &options))
{
fh_close_handle (handle);
return CMD_FAILURE;
}
-#if DEBUGGING
- dump_dict_variables (dict);
-#endif
dict_compact_values (dict);
-#if DEBUGGING
- printf (_("IMPORT translation table from file to memory:\n"));
- for (i = 0; i < dict->nvar; i++)
- {
- struct variable *v = dict->var[i];
-
- printf (_(" %8s from %3d,%3d to %3d,%3d\n"), v->name,
- v->get.fv, v->get.nv, v->fv, v->nv);
- }
-#endif
-
dict_destroy (default_dict);
default_dict = dict;
{
struct get_pgm *pgm = source->aux;
- while (pfm_read_case (pgm->handle, c->data, default_dict))
+ while (pfm_read_case (pgm->handle, c, default_dict))
if (!write_case (wc_data))
break;
}
return CMD_FAILURE;
dict = dict_clone (default_dict);
-#if DEBUGGING
- dump_dict_variables (dict);
-#endif
for (i = 0; i < dict_get_var_cnt (dict); i++)
dict_get_var (dict, i)->aux = dict_get_var (default_dict, i);
if (0 == trim_dictionary (dict, &options))
return CMD_FAILURE;
}
-#if DEBUGGING
- dump_dict_variables (dict);
-#endif
-
/* Write dictionary. */
if (!pfm_write_dictionary (handle, dict))
{
struct variable *v = t->var[i];
if (v->type == NUMERIC)
- *p++ = c->data[v->fv];
+ (*p++).f = case_num (c, v->fv);
else
- (*p++).c = c->data[v->fv].s;
+ (*p++).c = (char *) case_str (c, v->fv);
}
pfm_write_case (t->f, (union value *) t->case_buf);