/* PSPPIRE - a graphical user interface for PSPP.
- Copyright (C) 2007, 2009, 2011, 2012, 2015 Free Software Foundation
+ Copyright (C) 2007, 2009, 2011, 2012, 2015, 2020 Free Software Foundation
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
#include <regex.h>
#include <stdlib.h>
#include <sys/types.h>
+#include <math.h>
#include "data/data-in.h"
#include "data/datasheet.h"
#include "ui/gui/psppire-data-window.h"
#include "ui/gui/psppire-dialog.h"
#include "ui/gui/psppire-selector.h"
+#include <ssw-sheet.h>
#include "gl/xalloc.h"
{
casenumber x = -1;
gint column = -1;
- glong row;
-
-
- row = 10;
+ glong row = -1;
find_value (fd, row, &x, &column);
- if ( x != -1)
+ if (x != -1)
{
+ SswSheet *sheet = SSW_SHEET (fd->de->data_editor->data_sheet);
gtk_notebook_set_current_page (GTK_NOTEBOOK (fd->de->data_editor),
PSPPIRE_DATA_EDITOR_DATA_VIEW);
+ ssw_sheet_scroll_to (sheet, column, x);
+ ssw_sheet_set_active_cell (sheet, column, x, NULL);
}
}
static void
forward_wrap (casenumber *i, struct datasheet *data)
{
- if ( ++*i >= datasheet_get_n_rows (data) ) *i = 0;
+ if (++*i >= datasheet_get_n_rows (data)) *i = 0;
}
static void
static void
backward_wrap (casenumber *i, struct datasheet *data)
{
- if ( --*i < 0 )
+ if (--*i < 0)
*i = datasheet_get_n_rows (data) - 1;
}
gboolean reverse = gtk_toggle_button_get_active
(GTK_TOGGLE_BUTTON (get_widget_assert (fd->xml, "find-backwards")));
- if ( wrap )
+ if (wrap)
{
- if ( reverse )
+ if (reverse)
return &ip[REVERSE_WRAP];
else
return &ip[FORWARD_WRAP];
}
else
{
- if ( reverse )
+ if (reverse)
return &ip[REVERSE];
else
return &ip[FORWARD];
};
-/* A comparator which operates on the unadulterated union values */
-struct value_comparator
+/* A comparator which operates on the numerical values,
+ rounded to the number of decimal places indicated by
+ the variable's format. */
+struct numeric_comparator
{
struct comparator parent;
- union value pattern;
+ double rounded_ref;
};
/* A comparator which matches string values or parts thereof */
value_compare (const struct comparator *cmptr,
const union value *v)
{
- const struct value_comparator *vc = (const struct value_comparator *) cmptr;
- return 0 == value_compare_3way (v, &vc->pattern, var_get_width (cmptr->var));
+ const struct numeric_comparator *nc = (const struct numeric_comparator *) cmptr;
+ const struct fmt_spec *fs = var_get_print_format (cmptr->var);
+
+ double c = nearbyint (v->f * exp10 (fs->d));
+
+ return c == nc->rounded_ref;
}
width = strlen (text);
- assert ( cmptr->flags & STR_CMP_LABELS);
+ assert (cmptr->flags & STR_CMP_LABELS);
g_return_val_if_fail (width > 0, false);
- if ( cmptr->flags & STR_CMP_SUBSTR)
+ if (cmptr->flags & STR_CMP_SUBSTR)
return (NULL != g_strstr_len (text, width, ssc->pattern));
else
return (0 == strncmp (text, ssc->pattern, width));
int width = var_get_width (cmptr->var);
g_return_val_if_fail (width > 0, false);
- assert ( ! (cmptr->flags & STR_CMP_LABELS));
+ assert (! (cmptr->flags & STR_CMP_LABELS));
text = value_to_text (*val, cmptr->var);
- if ( cmptr->flags & STR_CMP_SUBSTR)
+ if (cmptr->flags & STR_CMP_SUBSTR)
found = (NULL != g_strstr_len (text, width, ssc->pattern));
else
found = (0 == strncmp (text, ssc->pattern, width));
int width = var_get_width (cmptr->var);
- assert ( ! (cmptr->flags & STR_CMP_LABELS) );
+ assert (! (cmptr->flags & STR_CMP_LABELS));
g_return_val_if_fail (width > 0, false);
int width ;
- assert ( cmptr->flags & STR_CMP_LABELS);
+ assert (cmptr->flags & STR_CMP_LABELS);
text = var_lookup_value_label (cmptr->var, val);
width = strlen (text);
regfree (&rec->re);
}
-static void
-cmptr_value_destroy (struct comparator *cmptr)
-{
- struct value_comparator *vc
- = UP_CAST (cmptr, struct value_comparator, parent);
- value_destroy (&vc->pattern, var_get_width (cmptr->var));
-}
-
-
static struct comparator *
-value_comparator_create (const struct variable *var, const char *target)
+numeric_comparator_create (const struct variable *var, const char *target)
{
- struct value_comparator *vc = xzalloc (sizeof (*vc));
- struct comparator *cmptr = &vc->parent;
+ struct numeric_comparator *nc = xzalloc (sizeof (*nc));
+ struct comparator *cmptr = &nc->parent;
cmptr->flags = 0;
cmptr->var = var;
- cmptr->compare = value_compare ;
- cmptr->destroy = cmptr_value_destroy;
+ cmptr->compare = value_compare;
+ const struct fmt_spec *fs = var_get_write_format (var);
- text_to_value (target, var, &vc->pattern);
+ union value val;
+ text_to_value (target, var, &val);
+ nc->rounded_ref = nearbyint (val.f * exp10 (fs->d));
+ value_destroy (&val, var_get_width (var));
return cmptr;
}
cmptr->flags = flags;
cmptr->var = var;
- if ( flags & STR_CMP_LABELS)
+ if (flags & STR_CMP_LABELS)
cmptr->compare = string_label_compare;
else
cmptr->compare = string_value_compare;
cmptr->destroy = regexp_destroy;
code = regcomp (&rec->re, target, 0);
- if ( code != 0 )
+ if (code != 0)
{
char *errbuf = NULL;
size_t errbuf_size = regerror (code, &rec->re, errbuf, 0);
msg (ME, _("Bad regular expression: %s"), errbuf);
- free ( cmptr);
+ free (cmptr);
free (errbuf);
return NULL;
}
static void
comparator_destroy (struct comparator *cmptr)
{
- if ( ! cmptr )
+ if (! cmptr)
return ;
- if ( cmptr->destroy )
+ if (cmptr->destroy)
cmptr->destroy (cmptr);
free (cmptr);
comparator_factory (const struct variable *var, const char *str,
enum string_cmp_flags flags)
{
- if ( flags & STR_CMP_REGEXP )
+ if (flags & STR_CMP_REGEXP)
return regexp_comparator_create (var, str, flags);
- if ( flags & (STR_CMP_SUBSTR | STR_CMP_LABELS) )
+ if (flags & (STR_CMP_SUBSTR | STR_CMP_LABELS))
return string_comparator_create (var, str, flags);
- return value_comparator_create (var, str);
+ return numeric_comparator_create (var, str);
}
enum string_cmp_flags flags = 0;
var = dict_lookup_var (fd->dict->dict, var_name);
- if ( ! var )
+ if (! var)
return ;
width = var_get_width (var);
*column = var_get_dict_index (var);
*row = -1;
- if ( gtk_toggle_button_get_active
+ if (gtk_toggle_button_get_active
(GTK_TOGGLE_BUTTON (fd->match_substring_checkbox)))
flags |= STR_CMP_SUBSTR;
- if ( gtk_toggle_button_get_active
+ if (gtk_toggle_button_get_active
(GTK_TOGGLE_BUTTON (fd->match_regexp_checkbox)))
flags |= STR_CMP_REGEXP;
- if ( gtk_toggle_button_get_active
+ if (gtk_toggle_button_get_active
(GTK_TOGGLE_BUTTON (fd->value_labels_checkbox)))
flags |= STR_CMP_LABELS;
comparator_factory (var, target_string, flags);
value_init (&val, width);
- if ( ! cmptr)
+ if (! cmptr)
goto finish;
for (i = ip->start (current_row, fd->data);
{
datasheet_get_value (fd->data, i, var_get_case_index (var), &val);
- if ( comparator_compare (cmptr, &val))
+ if (comparator_compare (cmptr, &val))
{
*row = i;
break;