#include <libpspp/str.h>
#include "intprops.h"
+#include "minmax.h"
#include "gettext.h"
#define _(msgid) gettext (msgid)
/* Parses and executes FLIP. */
int
-cmd_flip (struct dataset *ds)
+cmd_flip (struct lexer *lexer, struct dataset *ds)
{
struct flip_pgm *flip;
struct case_sink *sink;
flip->new_names_tail = NULL;
flip->file = NULL;
- lex_match ('/');
- if (lex_match_id ("VARIABLES"))
+ lex_match (lexer, '/');
+ if (lex_match_id (lexer, "VARIABLES"))
{
- lex_match ('=');
- if (!parse_variables (dict, &flip->var, &flip->var_cnt,
+ lex_match (lexer, '=');
+ if (!parse_variables (lexer, dict, &flip->var, &flip->var_cnt,
PV_NO_DUPLICATE))
goto error;
- lex_match ('/');
+ lex_match (lexer, '/');
}
else
dict_get_vars (dict, &flip->var, &flip->var_cnt, 1u << DC_SYSTEM);
pool_register (flip->pool, free, flip->var);
- lex_match ('/');
- if (lex_match_id ("NEWNAMES"))
+ lex_match (lexer, '/');
+ if (lex_match_id (lexer, "NEWNAMES"))
{
- lex_match ('=');
- flip->new_names = parse_variable (dict);
+ lex_match (lexer, '=');
+ flip->new_names = parse_variable (lexer, dict);
if (!flip->new_names)
goto error;
}
/* Set up flipped data for reading. */
proc_set_source (ds, flip_source_create (flip));
- return ok ? lex_end_of_command () : CMD_CASCADING_FAILURE;
+ return ok ? lex_end_of_command (lexer) : CMD_CASCADING_FAILURE;
error:
destroy_flip_pgm (flip);
for (i = 1; i < 10000000; i++)
{
- int ofs = min (7 - intlog10 (i), len);
+ int ofs = MIN (7 - intlog10 (i), len);
memcpy (n, name, ofs);
sprintf (&n[ofs], "%d", i);
/* Write variable names as first case. */
for (i = 0; i < flip->var_cnt; i++)
buf_copy_str_rpad (flip->output_buf[i].s, MAX_SHORT_STRING,
- flip->var[i]->name);
+ var_get_name (flip->var[i]));
if (fwrite (flip->output_buf, sizeof *flip->output_buf,
flip->var_cnt, flip->file) != (size_t) flip->var_cnt)
{
{
struct varname *v = pool_alloc (flip->pool, sizeof *v);
v->next = NULL;
- if (flip->new_names->type == NUMERIC)
+ if (var_is_numeric (flip->new_names))
{
double f = case_num (c, flip->idx_to_fv[flip->new_names->index]);
}
else
{
- int width = min (flip->new_names->width, MAX_SHORT_STRING);
+ int width = MIN (var_get_width (flip->new_names), MAX_SHORT_STRING);
memcpy (v->name, case_str (c, flip->idx_to_fv[flip->new_names->index]),
width);
v->name[width] = 0;
{
double out;
- if (flip->var[i]->type == NUMERIC)
+ if (var_is_numeric (flip->var[i]))
out = case_num (c, flip->idx_to_fv[flip->var[i]->index]);
else
out = SYSMIS;
for (case_idx = 0; case_idx < flip->case_cnt; )
{
- unsigned long read_cases = min (flip->case_cnt - case_idx,
+ unsigned long read_cases = MIN (flip->case_cnt - case_idx,
case_capacity);
size_t i;