Commit 3dda226a authored by JP Rosevear's avatar JP Rosevear Committed by JP Rosevear

Use new value_compare API

2000-06-15  JP Rosevear  <jpr@arcavia.com>

	* src/expr.c (eval_expr_real): Use new value_compare API

2000-06-14  JP Rosevear  <jpr@arcavia.com>

	* src/value.h: Update value_compare prototype.

	* src/value.c (value_compare): Make it take a new case
	sensitive flag for string comparisons.

	* src/sort.c (sort_compare_cells): Use value_compare to do the
	comparisons.  Handle the special cases of blanks (always at
	bottom, whether asc or desc) and errors (after booleans).


2000-06-15  JP Rosevear  <jpr@arcavia.com>

	* cell-sort.glade: Tidy the UI

	* dialog-cell-sort.c (order_box_new): Make the clause boxes look
	a little nicer.
parent 005d94c6
2000-06-15 JP Rosevear <jpr@arcavia.com>
* src/expr.c (eval_expr_real): Use new value_compare API
2000-06-14 JP Rosevear <jpr@arcavia.com>
* src/value.h: Update value_compare prototype.
* src/value.c (value_compare): Make it take a new case
sensitive flag for string comparisons.
* src/sort.c (sort_compare_cells): Use value_compare to do the
comparisons. Handle the special cases of blanks (always at
bottom, whether asc or desc) and errors (after booleans).
2000-06-14 Morten Welinder <terra@diku.dk>
* src/history.c (history_item_label): Change "_" to "-", fixing
......
2000-06-15 JP Rosevear <jpr@arcavia.com>
* src/expr.c (eval_expr_real): Use new value_compare API
2000-06-14 JP Rosevear <jpr@arcavia.com>
* src/value.h: Update value_compare prototype.
* src/value.c (value_compare): Make it take a new case
sensitive flag for string comparisons.
* src/sort.c (sort_compare_cells): Use value_compare to do the
comparisons. Handle the special cases of blanks (always at
bottom, whether asc or desc) and errors (after booleans).
2000-06-14 Morten Welinder <terra@diku.dk>
* src/history.c (history_item_label): Change "_" to "-", fixing
......
2000-06-15 JP Rosevear <jpr@arcavia.com>
* src/expr.c (eval_expr_real): Use new value_compare API
2000-06-14 JP Rosevear <jpr@arcavia.com>
* src/value.h: Update value_compare prototype.
* src/value.c (value_compare): Make it take a new case
sensitive flag for string comparisons.
* src/sort.c (sort_compare_cells): Use value_compare to do the
comparisons. Handle the special cases of blanks (always at
bottom, whether asc or desc) and errors (after booleans).
2000-06-14 Morten Welinder <terra@diku.dk>
* src/history.c (history_item_label): Change "_" to "-", fixing
......
2000-06-15 JP Rosevear <jpr@arcavia.com>
* src/expr.c (eval_expr_real): Use new value_compare API
2000-06-14 JP Rosevear <jpr@arcavia.com>
* src/value.h: Update value_compare prototype.
* src/value.c (value_compare): Make it take a new case
sensitive flag for string comparisons.
* src/sort.c (sort_compare_cells): Use value_compare to do the
comparisons. Handle the special cases of blanks (always at
bottom, whether asc or desc) and errors (after booleans).
2000-06-14 Morten Welinder <terra@diku.dk>
* src/history.c (history_item_label): Change "_" to "-", fixing
......
2000-06-15 JP Rosevear <jpr@arcavia.com>
* src/expr.c (eval_expr_real): Use new value_compare API
2000-06-14 JP Rosevear <jpr@arcavia.com>
* src/value.h: Update value_compare prototype.
* src/value.c (value_compare): Make it take a new case
sensitive flag for string comparisons.
* src/sort.c (sort_compare_cells): Use value_compare to do the
comparisons. Handle the special cases of blanks (always at
bottom, whether asc or desc) and errors (after booleans).
2000-06-14 Morten Welinder <terra@diku.dk>
* src/history.c (history_item_label): Change "_" to "-", fixing
......
2000-06-15 JP Rosevear <jpr@arcavia.com>
* src/expr.c (eval_expr_real): Use new value_compare API
2000-06-14 JP Rosevear <jpr@arcavia.com>
* src/value.h: Update value_compare prototype.
* src/value.c (value_compare): Make it take a new case
sensitive flag for string comparisons.
* src/sort.c (sort_compare_cells): Use value_compare to do the
comparisons. Handle the special cases of blanks (always at
bottom, whether asc or desc) and errors (after booleans).
2000-06-14 Morten Welinder <terra@diku.dk>
* src/history.c (history_item_label): Change "_" to "-", fixing
......
2000-06-15 JP Rosevear <jpr@arcavia.com>
* src/expr.c (eval_expr_real): Use new value_compare API
2000-06-14 JP Rosevear <jpr@arcavia.com>
* src/value.h: Update value_compare prototype.
* src/value.c (value_compare): Make it take a new case
sensitive flag for string comparisons.
* src/sort.c (sort_compare_cells): Use value_compare to do the
comparisons. Handle the special cases of blanks (always at
bottom, whether asc or desc) and errors (after booleans).
2000-06-14 Morten Welinder <terra@diku.dk>
* src/history.c (history_item_label): Change "_" to "-", fixing
......
No preview for this file type
2000-06-15 JP Rosevear <jpr@arcavia.com>
* cell-sort.glade: Tidy the UI
* dialog-cell-sort.c (order_box_new): Make the clause boxes look
a little nicer.
2000-06-13 Morten Welinder <terra@diku.dk>
* dialog-stf-format-page.c (format_page_format_changed): Plug
......
......@@ -134,6 +134,7 @@
<widget>
<class>GtkFrame</class>
<name>frame2</name>
<border_width>5</border_width>
<label>Selection has</label>
<label_xalign>0</label_xalign>
<shadow_type>GTK_SHADOW_ETCHED_IN</shadow_type>
......@@ -146,6 +147,7 @@
<widget>
<class>GtkCheckButton</class>
<name>cell_sort_header_check</name>
<border_width>5</border_width>
<can_focus>True</can_focus>
<label>A header</label>
<active>False</active>
......@@ -156,6 +158,7 @@
<widget>
<class>GtkFrame</class>
<name>frame3</name>
<border_width>5</border_width>
<label>Sort</label>
<label_xalign>0</label_xalign>
<shadow_type>GTK_SHADOW_ETCHED_IN</shadow_type>
......@@ -168,6 +171,7 @@
<widget>
<class>GtkHBox</class>
<name>hbox2</name>
<border_width>5</border_width>
<homogeneous>True</homogeneous>
<spacing>0</spacing>
......
......@@ -214,6 +214,8 @@ order_box_new (GtkWidget * parent, const gchar *frame_text,
OrderBox *orderbox;
GtkWidget *hbox = gtk_hbox_new (FALSE, 2);
gtk_container_set_border_width (GTK_CONTAINER (hbox), 5);
orderbox = g_new (OrderBox, 1);
orderbox->parent = parent;
orderbox->main_frame = gtk_frame_new (frame_text);
......@@ -232,7 +234,7 @@ order_box_new (GtkWidget * parent, const gchar *frame_text,
orderbox->asc = 1;
orderbox->asc_desc = gtk_hbox_new (FALSE, 0);
item = gtk_radio_button_new_with_label (group, _("Ascending"));
gtk_box_pack_start (GTK_BOX (orderbox->asc_desc), item, FALSE, FALSE, 0);
group = gtk_radio_button_group (GTK_RADIO_BUTTON (item));
......@@ -247,8 +249,14 @@ order_box_new (GtkWidget * parent, const gchar *frame_text,
/* Advanced button */
orderbox->cs = FALSE;
orderbox->val = TRUE;
orderbox->adv_button = gtk_button_new_with_label(_("Advanced..."));
gtk_box_pack_start (GTK_BOX (hbox), orderbox->adv_button, FALSE, FALSE, 0);
{
GtkWidget *pm = gnome_stock_new_with_icon (GNOME_STOCK_PIXMAP_PROPERTIES);
orderbox->adv_button = gnome_pixmap_button (pm, _("Advanced..."));
}
gtk_box_pack_start (GTK_BOX (hbox), orderbox->adv_button,
FALSE, FALSE, 0);
gtk_signal_connect (GTK_OBJECT (orderbox->adv_button), "clicked",
GTK_SIGNAL_FUNC (dialog_cell_sort_adv), orderbox);
......
......@@ -482,7 +482,7 @@ eval_expr_real (EvalPos const *pos, ExprTree const *tree,
}
}
comp = value_compare (a, b);
comp = value_compare (a, b, FALSE);
if (a != NULL)
value_release (a);
......
......@@ -53,102 +53,42 @@ sort_data_length (const SortData *data)
static int
sort_compare_cells (const Cell *ca, const Cell *cb, SortClause *clause)
{
Value *a, *b;
int ans = 0, fans = 0;
Value *a, *b;
ValueType ta, tb;
ValueCompare comp = IS_EQUAL;
int ans = 0;
if (!ca)
a = value_new_int (0);
a = NULL;
else
a = ca->value;
if (!cb)
b = value_new_int (0);
b = NULL;
else
b = cb->value;
if (clause->val) {
switch (a->type) {
case VALUE_EMPTY:
case VALUE_BOOLEAN:
case VALUE_FLOAT:
case VALUE_INTEGER:
switch (b->type) {
case VALUE_EMPTY:
case VALUE_BOOLEAN:
case VALUE_FLOAT:
case VALUE_INTEGER:
{
float_t fa, fb;
fa = value_get_as_float (a);
fb = value_get_as_float (b);
if (fa < fb)
ans = -1;
else if (fa == fb)
ans = 0;
else
ans = 1;
break;
}
default:
ans = -1;
break;
}
break;
default: {
switch (b->type) {
case VALUE_EMPTY:
case VALUE_BOOLEAN:
case VALUE_FLOAT:
case VALUE_INTEGER:
ans = 1;
break;
default: {
char *sa, *sb;
sa = value_get_as_string (a);
sb = value_get_as_string (b);
if (clause->cs)
ans = strcmp (sa, sb);
else
ans = g_strcasecmp (sa, sb);
g_free (sa);
g_free (sb);
break;
}
}
break;
}
}
ta = VALUE_IS_EMPTY (a) ? VALUE_EMPTY : a->type;
tb = VALUE_IS_EMPTY (b) ? VALUE_EMPTY : b->type;
if (ta == VALUE_EMPTY && tb != VALUE_EMPTY) {
comp = clause->asc ? IS_LESS : IS_GREATER;
} else if (tb == VALUE_EMPTY && ta != VALUE_EMPTY) {
comp = clause->asc ? IS_GREATER : IS_LESS;
} else if (ta == VALUE_ERROR && tb != VALUE_ERROR) {
comp = IS_GREATER;
} else if (tb == VALUE_ERROR && ta != VALUE_ERROR) {
comp = IS_LESS;
} else {
char *sa, *sb;
if (ca)
sa = cell_get_entered_text (ca);
else
sa = g_strdup ("0");
if (cb)
sb = cell_get_entered_text (cb);
else
sb = g_strdup ("0");
if (clause->cs)
ans = strcmp (sa, sb);
else
ans = g_strcasecmp (sa, sb);
g_free (sa);
g_free (sb);
comp = value_compare (a, b, clause->cs);
}
if (comp == IS_LESS) {
ans = clause->asc ? 1 : -1;
} else if (comp == IS_GREATER) {
ans = clause->asc ? -1 : 1;
}
if (ans == 0)
fans = ans;
else if (ans < 0)
fans = clause->asc ? 1 : -1;
else
fans = clause->asc ? -1 : 1;
if (!ca)
value_release (a);
if (!cb)
value_release (b);
return fans;
return ans;
}
static int
......
......@@ -636,10 +636,11 @@ compare_float_float (Value const *va, Value const *vb)
* Compares two (Value *) and returns one of ValueCompare
*
* if pos is non null it will perform implict intersection for
* cellranges.
* cellranges. if cs is true, be case sensitive on string
* comparisons.
*/
ValueCompare
value_compare (Value const *a, Value const *b)
value_compare (Value const *a, Value const *b, gboolean cs)
{
ValueType ta, tb;
......@@ -668,7 +669,16 @@ value_compare (Value const *a, Value const *b)
/* If both are strings compare as string */
case VALUE_STRING :
{
int const t = g_strcasecmp (a->v_str.val->str, b->v_str.val->str);
int t;
if (cs) {
t = strcmp (a->v_str.val->str,
b->v_str.val->str);
} else {
t = g_strcasecmp (a->v_str.val->str,
b->v_str.val->str);
}
if (t == 0)
return IS_EQUAL;
else if (t > 0)
......
......@@ -95,7 +95,8 @@ Value *value_new_array_non_init (guint cols, guint rows);
void value_release (Value *value);
void value_dump (Value const *value);
Value *value_duplicate (Value const *value);
ValueCompare value_compare (const Value *a, const Value *b);
ValueCompare value_compare (const Value *a, const Value *b,
gboolean cs);
gboolean value_get_as_bool (Value const *v, gboolean *err);
char *value_get_as_string (const Value *value);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment