projects
/
pspp
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
exp10 replaced with pow when exp10 is not available
[pspp]
/
src
/
ui
/
gui
/
find-dialog.c
diff --git
a/src/ui/gui/find-dialog.c
b/src/ui/gui/find-dialog.c
index c8f8451bd85be1cf8492ddc3391320afeb77d9c9..01abc0c81644c2a7d6c8e07a83050bbc641f9428 100644
(file)
--- a/
src/ui/gui/find-dialog.c
+++ b/
src/ui/gui/find-dialog.c
@@
-1,5
+1,5
@@
/* PSPPIRE - a graphical user interface for PSPP.
/* 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
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
@@
-25,6
+25,7
@@
which match particular strings */
#include <regex.h>
#include <stdlib.h>
#include <sys/types.h>
#include <regex.h>
#include <stdlib.h>
#include <sys/types.h>
+#include <math.h>
#include "data/data-in.h"
#include "data/datasheet.h"
#include "data/data-in.h"
#include "data/datasheet.h"
@@
-40,6
+41,7
@@
which match particular strings */
#include "ui/gui/psppire-data-window.h"
#include "ui/gui/psppire-dialog.h"
#include "ui/gui/psppire-selector.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"
#include "gl/xalloc.h"
@@
-47,6
+49,13
@@
which match particular strings */
#define _(msgid) gettext (msgid)
#define N_(msgid) msgid
#define _(msgid) gettext (msgid)
#define N_(msgid) msgid
+/* Some systems like MacOS do not have exp10 */
+#ifndef HAVE_EXP10
+inline static double exp10(double x)
+{
+ return pow(10.0, x);
+}
+#endif
struct find_dialog
{
struct find_dialog
{
@@
-101,18
+110,18
@@
do_find (GObject *obj, const struct find_dialog *fd)
{
casenumber x = -1;
gint column = -1;
{
casenumber x = -1;
gint column = -1;
- glong row;
-
-
- row = 10;
+ glong row = -1;
find_value (fd, row, &x, &column);
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);
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);
}
}
}
}
@@
-268,7
+277,7
@@
forward (casenumber *i, struct datasheet *data UNUSED)
static void
forward_wrap (casenumber *i, struct datasheet *data)
{
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
@@
-281,7
+290,7
@@
backward (casenumber *i, struct datasheet *data UNUSED)
static void
backward_wrap (casenumber *i, struct datasheet *data)
{
static void
backward_wrap (casenumber *i, struct datasheet *data)
{
- if (
--*i < 0
)
+ if (
--*i < 0
)
*i = datasheet_get_n_rows (data) - 1;
}
*i = datasheet_get_n_rows (data) - 1;
}
@@
-386,16
+395,16
@@
get_iteration_params (const struct find_dialog *fd)
gboolean reverse = gtk_toggle_button_get_active
(GTK_TOGGLE_BUTTON (get_widget_assert (fd->xml, "find-backwards")));
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
{
return &ip[REVERSE_WRAP];
else
return &ip[FORWARD_WRAP];
}
else
{
- if (
reverse
)
+ if (
reverse
)
return &ip[REVERSE];
else
return &ip[FORWARD];
return &ip[REVERSE];
else
return &ip[FORWARD];
@@
-427,11
+436,13
@@
struct comparator
};
};
-/* 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;
{
struct comparator parent;
-
union value pattern
;
+
double rounded_ref
;
};
/* A comparator which matches string values or parts thereof */
};
/* A comparator which matches string values or parts thereof */
@@
-453,8
+464,12
@@
static bool
value_compare (const struct comparator *cmptr,
const union value *v)
{
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;
}
}
@@
-474,11
+489,11
@@
string_label_compare (const struct comparator *cmptr,
width = strlen (text);
width = strlen (text);
- assert (
cmptr->flags & STR_CMP_LABELS);
+ assert (cmptr->flags & STR_CMP_LABELS);
g_return_val_if_fail (width > 0, false);
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));
return (NULL != g_strstr_len (text, width, ssc->pattern));
else
return (0 == strncmp (text, ssc->pattern, width));
@@
-496,11
+511,11
@@
string_value_compare (const struct comparator *cmptr,
int width = var_get_width (cmptr->var);
g_return_val_if_fail (width > 0, false);
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);
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));
found = (NULL != g_strstr_len (text, width, ssc->pattern));
else
found = (0 == strncmp (text, ssc->pattern, width));
@@
-523,7
+538,7
@@
regexp_value_compare (const struct comparator *cmptr,
int width = var_get_width (cmptr->var);
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);
g_return_val_if_fail (width > 0, false);
@@
-550,7
+565,7
@@
regexp_label_compare (const struct comparator *cmptr,
int width ;
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);
text = var_lookup_value_label (cmptr->var, val);
width = strlen (text);
@@
-571,27
+586,21
@@
regexp_destroy (struct comparator *cmptr)
regfree (&rec->re);
}
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 *
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 (*v
c));
- struct comparator *cmptr = &
v
c->parent;
+ struct
numeric_comparator *nc = xzalloc (sizeof (*n
c));
+ struct comparator *cmptr = &
n
c->parent;
cmptr->flags = 0;
cmptr->var = var;
cmptr->flags = 0;
cmptr->var = var;
- cmptr->compare = value_compare
;
- c
mptr->destroy = cmptr_value_destroy
;
+ cmptr->compare = value_compare;
+ c
onst 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;
}
return cmptr;
}
@@
-606,7
+615,7
@@
string_comparator_create (const struct variable *var, const char *target,
cmptr->flags = flags;
cmptr->var = var;
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->compare = string_label_compare;
else
cmptr->compare = string_value_compare;
@@
-633,7
+642,7
@@
regexp_comparator_create (const struct variable *var, const char *target,
cmptr->destroy = regexp_destroy;
code = regcomp (&rec->re, target, 0);
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);
{
char *errbuf = NULL;
size_t errbuf_size = regerror (code, &rec->re, errbuf, 0);
@@
-644,7
+653,7
@@
regexp_comparator_create (const struct variable *var, const char *target,
msg (ME, _("Bad regular expression: %s"), errbuf);
msg (ME, _("Bad regular expression: %s"), errbuf);
- free (
cmptr);
+ free (cmptr);
free (errbuf);
return NULL;
}
free (errbuf);
return NULL;
}
@@
-665,10
+674,10
@@
comparator_compare (const struct comparator *cmptr,
static void
comparator_destroy (struct comparator *cmptr)
{
static void
comparator_destroy (struct comparator *cmptr)
{
- if (
! cmptr
)
+ if (
! cmptr
)
return ;
return ;
- if (
cmptr->destroy
)
+ if (
cmptr->destroy
)
cmptr->destroy (cmptr);
free (cmptr);
cmptr->destroy (cmptr);
free (cmptr);
@@
-679,13
+688,13
@@
static struct comparator *
comparator_factory (const struct variable *var, const char *str,
enum string_cmp_flags flags)
{
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);
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 string_comparator_create (var, str, flags);
- return
value
_comparator_create (var, str);
+ return
numeric
_comparator_create (var, str);
}
}
@@
-705,7
+714,7
@@
find_value (const struct find_dialog *fd, casenumber current_row,
enum string_cmp_flags flags = 0;
var = dict_lookup_var (fd->dict->dict, var_name);
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);
return ;
width = var_get_width (var);
@@
-713,15
+722,15
@@
find_value (const struct find_dialog *fd, casenumber current_row,
*column = var_get_dict_index (var);
*row = -1;
*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;
(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;
(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;
(GTK_TOGGLE_BUTTON (fd->value_labels_checkbox)))
flags |= STR_CMP_LABELS;
@@
-733,7
+742,7
@@
find_value (const struct find_dialog *fd, casenumber current_row,
comparator_factory (var, target_string, flags);
value_init (&val, width);
comparator_factory (var, target_string, flags);
value_init (&val, width);
- if (
! cmptr)
+ if (! cmptr)
goto finish;
for (i = ip->start (current_row, fd->data);
goto finish;
for (i = ip->start (current_row, fd->data);
@@
-742,7
+751,7
@@
find_value (const struct find_dialog *fd, casenumber current_row,
{
datasheet_get_value (fd->data, i, var_get_case_index (var), &val);
{
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;
{
*row = i;
break;