gnumeric r16679 - in branches/gnumeric-1-8: . plugins/derivatives plugins/fn-date plugins/fn-eng plugins/fn-info plugins/fn-string src src/dialogs src/tools src/widgets



Author: mortenw
Date: Sat Jun 28 16:32:27 2008
New Revision: 16679
URL: http://svn.gnome.org/viewvc/gnumeric?rev=16679&view=rev

Log:
Backporting the easy stuff.

	* Fix EOMONTH issue.  [#540069]
	* Fix phyper hang.  [#540211]
	* Fix text export problem for times with fractional seconds.  [#534514]
	* Fix openoffice -pedantic problem.  [#540180]
	* Fix OPT_RGW hang.  [#534132]
	* Fix BESSELI and BESSELK aborts.  [#534475]
	* Fix BESSELI issue.  [#323784]
	* Fix UMR in WORKDAY.  [#539808]
	* Plug leaks in GROWTH.  [#539827]
	* Plug leak in NETWORKDAYS.
	* Add missing "return" in CODE.
	* Fix EDATE issue.  [#539868]
	* Fix DAYS360 and NETWORKDAYS for invalid dates.  [#540055]



Modified:
   branches/gnumeric-1-8/NEWS
   branches/gnumeric-1-8/configure.in
   branches/gnumeric-1-8/plugins/derivatives/ChangeLog
   branches/gnumeric-1-8/plugins/derivatives/options.c
   branches/gnumeric-1-8/plugins/fn-date/ChangeLog
   branches/gnumeric-1-8/plugins/fn-date/functions.c
   branches/gnumeric-1-8/plugins/fn-eng/ChangeLog
   branches/gnumeric-1-8/plugins/fn-eng/functions.c
   branches/gnumeric-1-8/plugins/fn-info/functions.c
   branches/gnumeric-1-8/plugins/fn-string/functions.c
   branches/gnumeric-1-8/src/clipboard.c
   branches/gnumeric-1-8/src/dialogs/dao-gui-utils.c
   branches/gnumeric-1-8/src/dialogs/dialog-analysis-tools.c
   branches/gnumeric-1-8/src/dialogs/dialog-printer-setup.c
   branches/gnumeric-1-8/src/dialogs/tool-dialogs.h
   branches/gnumeric-1-8/src/gnm-datetime.c
   branches/gnumeric-1-8/src/gnm-datetime.h
   branches/gnumeric-1-8/src/mathfunc.c
   branches/gnumeric-1-8/src/sheet-autofill.c
   branches/gnumeric-1-8/src/tools/fill-series.c
   branches/gnumeric-1-8/src/tools/simulation.c
   branches/gnumeric-1-8/src/widgets/gnumeric-lazy-list.c
   branches/gnumeric-1-8/src/widgets/widget-font-selector.c

Modified: branches/gnumeric-1-8/NEWS
==============================================================================
--- branches/gnumeric-1-8/NEWS	(original)
+++ branches/gnumeric-1-8/NEWS	Sat Jun 28 16:32:27 2008
@@ -4,8 +4,19 @@
 	* Fix ODS import failure on win32. [#536552]
 
 Morten:
+	* Fix EOMONTH issue.  [#540069]
+	* Fix phyper hang.  [#540211]
 	* Fix text export problem for times with fractional seconds.  [#534514]
 	* Fix openoffice -pedantic problem.  [#540180]
+	* Fix OPT_RGW hang.  [#534132]
+	* Fix BESSELI and BESSELK aborts.  [#534475]
+	* Fix BESSELI issue.  [#323784]
+	* Fix UMR in WORKDAY.  [#539808]
+	* Plug leaks in GROWTH.  [#539827]
+	* Plug leak in NETWORKDAYS.
+	* Add missing "return" in CODE.
+	* Fix EDATE issue.  [#539868]
+	* Fix DAYS360 and NETWORKDAYS for invalid dates.  [#540055]
 
 --------------------------------------------------------------------------
 Gnumeric 1.8.3

Modified: branches/gnumeric-1-8/configure.in
==============================================================================
--- branches/gnumeric-1-8/configure.in	(original)
+++ branches/gnumeric-1-8/configure.in	Sat Jun 28 16:32:27 2008
@@ -147,25 +147,8 @@
 dnl execution.  Thus we need an explicit call:
 PKG_PROG_PKG_CONFIG(0.18)
 
-libgoffice=
-goffice_ver=
-dnl Only 0.6.x, or really late 0.5.x will work
-for ver in 0.6 0.5 ; do
-  if test "x$libgoffice" = x; then
-    AC_MSG_CHECKING([libgoffice-$ver])
-    if pkg-config --exists libgoffice-$ver; then
-      libgoffice=libgoffice-$ver
-      goffice_ver=`pkg-config --modversion libgoffice-$ver`
-      AC_MSG_RESULT([found])
-    else
-      AC_MSG_RESULT([not found])
-    fi
-  fi
-done
-if test "x$libgoffice" = x; then
-  # Not important.  Things will fail below.
-  libgoffice=libgoffice-0.4
-fi
+libgoffice=libgoffice-0.6
+goffice_ver=`pkg-config --modversion $libgoffice`
 AC_SUBST(LIBGOFFICE,$libgoffice)
 AC_SUBST(GOFFICE_VERSION,$goffice_ver)
 

Modified: branches/gnumeric-1-8/plugins/derivatives/options.c
==============================================================================
--- branches/gnumeric-1-8/plugins/derivatives/options.c	(original)
+++ branches/gnumeric-1-8/plugins/derivatives/options.c	Sat Jun 28 16:32:27 2008
@@ -981,6 +981,9 @@
 	gnm_float ci, infinity;
 	gnm_float gfresult;
 
+	if (!(s > 0))
+		return gnm_nan;
+
 	infinity = 100000000;
 	epsilon = 0.00001;
 	sx = s - d * gnm_exp (-r * t1);

Modified: branches/gnumeric-1-8/plugins/fn-date/functions.c
==============================================================================
--- branches/gnumeric-1-8/plugins/fn-date/functions.c	(original)
+++ branches/gnumeric-1-8/plugins/fn-date/functions.c	Sat Jun 28 16:32:27 2008
@@ -145,24 +145,11 @@
         g_date_clear (&date, 1);
 
 	g_date_set_dmy (&date, 1, 1, (int)year);
-	if (!g_date_valid (&date))
-		goto error;
-
-	if ((int)month > 0)
-		g_date_add_months (&date, (int)month - 1);
-	else
-		g_date_subtract_months (&date, 1 - (int)month);
-	if (!g_date_valid (&date))
-		goto error;
-
-	if ((int)day > 0)
-                g_date_add_days (&date, (int)day - 1);
-	else
-		g_date_subtract_days (&date, 1 - (int)day);
-	if (!g_date_valid (&date))
-		goto error;
+	gnm_date_add_months (&date, (int)month);
+	gnm_date_add_days (&date, (int)day);
 
-	if (g_date_get_year (&date) < gnm_date_convention_base (conv) ||
+	if (!g_date_valid (&date) ||
+	    g_date_get_year (&date) < gnm_date_convention_base (conv) ||
 	    g_date_get_year (&date) >= 11900)
 		goto error;
 
@@ -321,8 +308,8 @@
 
 	day = g_date_get_day (gdate1);
 
-	g_date_add_years (gdate1,
-			  datetime_g_years_between (gdate1, gdate2));
+	gnm_date_add_years (gdate1,
+			    datetime_g_years_between (gdate1, gdate2));
 	/* according to glib.h, feb 29 turns to feb 28 if necessary */
 
 	if (excel_compat) {
@@ -360,8 +347,8 @@
 
 	day = g_date_get_day (gdate1);
 
-	g_date_add_months (gdate1,
-			   datetime_g_months_between (gdate1, gdate2));
+	gnm_date_add_months (gdate1,
+			     datetime_g_months_between (gdate1, gdate2));
 	/* according to glib.h, days>28 decrease if necessary */
 
 	if (excel_compat) {
@@ -377,11 +364,11 @@
 		g_date_set_year (gdate2, new_year2);
 
 		/* add back the days if they were decreased by
-		   g_date_add_months */
+		   gnm_date_add_months */
 		/* ( i feel this is inferior because it reports e.g.:
 		     datedif(1/31/95,3/1/95,"d") == -2 ) */
-		g_date_add_days (gdate1,
-				 day - g_date_get_day (gdate1));
+		gnm_date_add_days (gdate1,
+				   day - g_date_get_day (gdate1));
 	}
 
 	return g_date_days_between (gdate1, gdate2);
@@ -462,13 +449,7 @@
                   return value_new_error_NUM (ei->pos);
 
 	datetime_serial_to_g (&date, (int)serial, conv);
-	if (!g_date_valid (&date))
-                  return value_new_error_VALUE (ei->pos);
-
-	if (months > 0)
-		g_date_add_months (&date, (int)months);
-	else
-		g_date_subtract_months (&date, (int)-months);
+	gnm_date_add_months (&date, (int)months);
 
 	if (!g_date_valid (&date) ||
 	    g_date_get_year (&date) < 1900 ||
@@ -919,6 +900,9 @@
 
 	datetime_serial_to_g (&date1, serial1, date_conv);
 	datetime_serial_to_g (&date2, serial2, date_conv);
+	if (!g_date_valid (&date1) || !g_date_valid (&date2))
+		return value_new_error_VALUE (ei->pos);
+
 	return value_new_int (days_between_basis (&date1, &date2, basis));
 }
 
@@ -959,11 +943,7 @@
 	if (months > INT_MAX / 2 || -months > INT_MAX / 2)
                   return value_new_error_NUM (ei->pos);
 
-	if (months > 0)
-		g_date_add_months (&date, (int)months);
-	else if (months < 0)
-		g_date_subtract_months (&date, (int)-months);
-
+	gnm_date_add_months (&date, (int)months);
 	if (!g_date_valid (&date) ||
 	    g_date_get_year (&date) < 1900 ||
 	    g_date_get_year (&date) > 9999)
@@ -1254,15 +1234,21 @@
 	/* Move to mondays, and check for problems */
 	start_serial = get_serial_weekday (start_serial, &start_offset, conv);
 	end_serial = get_serial_weekday (end_serial, &end_offset, conv);
-	if (start_serial < 0 || end_serial < 0)
+	if (!g_date_valid (&start_date) || start_serial < 0 || end_serial < 0)
                   return value_new_error_NUM (ei->pos);
 
 	res = end_serial - start_serial;
 	res -= ((res/7)*2);	/* Remove weekends */
 
-	if (argv[2] != NULL)
-		value_area_foreach (argv[2], ei->pos, CELL_ITER_IGNORE_BLANK,
-			(GnmValueIterFunc) &cb_networkdays_holiday, &close);
+	if (argv[2] != NULL) {
+		GnmValue *e =
+			value_area_foreach (argv[2], ei->pos,
+					    CELL_ITER_IGNORE_BLANK,
+					    (GnmValueIterFunc)&cb_networkdays_holiday,
+					    &close);
+		if (e)
+			return e;
+	}
 
 	res = res - start_offset + end_offset - close.res;
 

Modified: branches/gnumeric-1-8/plugins/fn-eng/functions.c
==============================================================================
--- branches/gnumeric-1-8/plugins/fn-eng/functions.c	(original)
+++ branches/gnumeric-1-8/plugins/fn-eng/functions.c	Sat Jun 28 16:32:27 2008
@@ -654,12 +654,12 @@
 	   "BESSELI function returns the Neumann, Weber or Bessel "
 	   "function.\n\n"
 	   "@x is where the function is evaluated. "
-	   "@y is the order of the Bessel function, if non-integer it is "
-	   "truncated.\n"
+	   "@y is the order of the Bessel function.\n"
 	   "\n"
 	   "* If @x or @y are not numeric a #VALUE! error is returned.\n"
 	   "* If @y < 0 a #NUM! error is returned.\n"
-	   "* This function is Excel compatible.\n"
+	   "* This function extends the Excel function of the same name to "
+	   "non-integer orders.\n"
 	   "\n"
 	   "@EXAMPLES=\n"
 	   "BESSELI(0.7,3) equals 0.007367374.\n"
@@ -675,15 +675,23 @@
 {
 	gnm_float x = value_get_as_float (argv[0]);	/* value to evaluate I_n at. */
 	gnm_float order = value_get_as_float (argv[1]);	/* the order */
+	gnm_float r;
 
 	if (order < 0)
 		return value_new_error_NUM (ei->pos);
 
-	/* It seems that XL uses abs value of x */
-	if (x < 0.)
-		x = -x;
+	/* This, or something like it, ought to be moved into a proper bessel_i.  */
+	if (x < 0) {
+		if (order != gnm_floor (order))
+			return value_new_error_NUM (ei->pos);
+		else if (gnm_fmod (order, 2) == 0)
+			r = bessel_i (-x, order, 1);  /* Even for even order */
+		else
+			r = -bessel_i (-x, order, 1);  /* Odd for odd order */
+	} else
+		r = bessel_i (x, order, 1);
 
-	return value_new_float (bessel_i (x, order, 1.0));
+	return value_new_float (r);
 }
 
 /***************************************************************************/
@@ -697,12 +705,12 @@
 	   "BESSELK function returns the Neumann, Weber or Bessel "
 	   "function. "
 	   "@x is where the function is evaluated. "
-	   "@y is the order of the Bessel function, if non-integer it is "
-	   "truncated.\n"
+	   "@y is the order of the Bessel function.\n"
 	   "\n"
 	   "* If @x or @y are not numeric a #VALUE! error is returned.\n"
 	   "* If @y < 0 a #NUM! error is returned.\n"
-	   "* This function is Excel compatible.\n"
+	   "* This function extends the Excel function of the same name to "
+	   "non-integer orders.\n"
 	   "\n"
 	   "@EXAMPLES=\n"
 	   "BESSELK(3,9) equals 397.95880.\n"
@@ -718,9 +726,6 @@
 	gnm_float x = value_get_as_float (argv[0]);	/* value to evaluate K_n at. */
 	gnm_float order = value_get_as_float (argv[1]);	/* the order */
 
-	if (order < 0)
-		return value_new_error_NUM (ei->pos);
-
 	return value_new_float (bessel_k (x, order, 1.0));
 }
 

Modified: branches/gnumeric-1-8/plugins/fn-info/functions.c
==============================================================================
--- branches/gnumeric-1-8/plugins/fn-info/functions.c	(original)
+++ branches/gnumeric-1-8/plugins/fn-info/functions.c	Sat Jun 28 16:32:27 2008
@@ -1204,6 +1204,52 @@
 
 	return value_new_empty ();
 }
+/***************************************************************************/
+
+static GnmFuncHelp const help_get_formula[] = {
+	{ GNM_FUNC_HELP_OLD,
+	F_("@FUNCTION=GET.FORMULA\n"
+	   "@SYNTAX=GET.FORMULA(cell)\n"
+	   "@DESCRIPTION="
+	   "EXPRESSION returns expression in @cell as a string, or "
+	   "empty if the cell is not an expression.\n"
+	   "@EXAMPLES=\n"
+	   "entering '=GET.FORMULA(A3)' in A2 = empty (assuming there is nothing in A3).\n"
+	   "entering '=GET.FORMULA(A2)' in A1 = '=GET.FORMULA(A3)'.\n"
+	   "\n"
+	   "@SEEALSO=EXPRESSION")
+	},
+	{ GNM_FUNC_HELP_END }
+};
+
+static GnmValue *
+gnumeric_get_formula (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
+{
+	GnmValue const * const v = argv[0];
+	if (v->type == VALUE_CELLRANGE) {
+		GnmCell *cell;
+		GnmCellRef const * a = &v->v_range.cell.a;
+		GnmCellRef const * b = &v->v_range.cell.b;
+
+		if (a->col != b->col || a->row != b->row || a->sheet !=b->sheet)
+			return value_new_error_REF (ei->pos);
+
+		cell = sheet_cell_get (eval_sheet (a->sheet, ei->pos->sheet),
+				       a->col, a->row);
+
+		if (cell && gnm_cell_has_expr (cell)) {
+			GnmConventionsOut out;
+			GnmParsePos	  pp;
+			out.accum = g_string_new ("=");
+			out.pp    = parse_pos_init_cell (&pp, cell);
+			out.convs = gnm_conventions_default;
+			gnm_expr_top_as_gstring (cell->base.texpr, &out);
+			return value_new_string_nocopy (g_string_free (out.accum, FALSE));
+		}
+	}
+
+	return value_new_empty ();
+}
 
 
 /***************************************************************************/
@@ -1943,12 +1989,19 @@
 	{ "error",	"s",  N_("text"), help_error,
 	  gnumeric_error, NULL, NULL, NULL, NULL,
 	  GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_UNIQUE_TO_GNUMERIC, GNM_FUNC_TEST_STATUS_NO_TESTSUITE },
+
 	{ "expression",	"r",   N_("cell"), help_expression,
 	  gnumeric_expression, NULL, NULL, NULL, NULL,
 	  GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_UNIQUE_TO_GNUMERIC, GNM_FUNC_TEST_STATUS_NO_TESTSUITE },
+/* XLM : looks common in charts */
+	{ "get.formula", "r",   N_("cell"), help_get_formula,
+	  gnumeric_get_formula, NULL, NULL, NULL, NULL,
+	  GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_NO_TESTSUITE },
+
 	{ "getenv",	"s", N_("string"), help_getenv,
 	  gnumeric_getenv, NULL, NULL, NULL, NULL,
 	  GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_UNIQUE_TO_GNUMERIC, GNM_FUNC_TEST_STATUS_NO_TESTSUITE },
 
+
         {NULL}
 };

Modified: branches/gnumeric-1-8/plugins/fn-string/functions.c
==============================================================================
--- branches/gnumeric-1-8/plugins/fn-string/functions.c	(original)
+++ branches/gnumeric-1-8/plugins/fn-string/functions.c	Sat Jun 28 16:32:27 2008
@@ -164,7 +164,7 @@
 	GnmValue *res;
 
 	if (*us == 0)
-		value_new_error_VALUE (ei->pos);
+		return value_new_error_VALUE (ei->pos);
 
 	if (*us <= 127)
 		return value_new_int (*us);

Modified: branches/gnumeric-1-8/src/clipboard.c
==============================================================================
--- branches/gnumeric-1-8/src/clipboard.c	(original)
+++ branches/gnumeric-1-8/src/clipboard.c	Sat Jun 28 16:32:27 2008
@@ -2,7 +2,7 @@
 /*
  * clipboard.c: A temporary store for contents from a worksheet
  *
- * Copyright (C) 2000-2007 Jody Goldberg   (jody gnome org)
+ * Copyright (C) 2000-2008 Jody Goldberg   (jody gnome org)
  *		 1999      Miguel de Icaza (miguel gnu org)
  *
  * This program is free software; you can redistribute it and/or

Modified: branches/gnumeric-1-8/src/dialogs/dao-gui-utils.c
==============================================================================
--- branches/gnumeric-1-8/src/dialogs/dao-gui-utils.c	(original)
+++ branches/gnumeric-1-8/src/dialogs/dao-gui-utils.c	Sat Jun 28 16:32:27 2008
@@ -83,7 +83,7 @@
  *
  **/
 void
-dialog_tool_init_outputs (GenericToolState *state, GtkSignalFunc sensitivity_cb)
+dialog_tool_init_outputs (GenericToolState *state, GCallback sensitivity_cb)
 {
 	GtkWidget *dao_box;
 

Modified: branches/gnumeric-1-8/src/dialogs/dialog-analysis-tools.c
==============================================================================
--- branches/gnumeric-1-8/src/dialogs/dialog-analysis-tools.c	(original)
+++ branches/gnumeric-1-8/src/dialogs/dialog-analysis-tools.c	Sat Jun 28 16:32:27 2008
@@ -242,8 +242,8 @@
  **/
 void
 dialog_tool_init_buttons (GenericToolState *state,
-			  GtkSignalFunc ok_function,
-			  GtkSignalFunc close_function)
+			  GCallback ok_function,
+			  GCallback close_function)
 {
 	state->ok_button = glade_xml_get_widget (state->gui, "okbutton");
 	g_signal_connect (G_OBJECT (state->ok_button),
@@ -300,9 +300,9 @@
 		  char const *dialog_name,
 		  char const *error_str,
 		  char const *key,
-		  GtkSignalFunc ok_function,
-		  GtkSignalFunc close_function,
-		  GtkSignalFunc sensitivity_cb,
+		  GCallback ok_function,
+		  GCallback close_function,
+		  GCallback sensitivity_cb,
 		  GnmExprEntryFlags flags)
 {
 	GtkTable  *table;

Modified: branches/gnumeric-1-8/src/dialogs/dialog-printer-setup.c
==============================================================================
--- branches/gnumeric-1-8/src/dialogs/dialog-printer-setup.c	(original)
+++ branches/gnumeric-1-8/src/dialogs/dialog-printer-setup.c	Sat Jun 28 16:32:27 2008
@@ -2776,7 +2776,8 @@
 {
 	if (page_setup) {
 		PrinterSetupState *state = data;
-		print_info_set_page_setup (state->pi, page_setup);
+		print_info_set_page_setup (state->pi,
+			gtk_page_setup_copy (page_setup));
 		do_update_page (state);
 	}
 }

Modified: branches/gnumeric-1-8/src/dialogs/tool-dialogs.h
==============================================================================
--- branches/gnumeric-1-8/src/dialogs/tool-dialogs.h	(original)
+++ branches/gnumeric-1-8/src/dialogs/tool-dialogs.h	Sat Jun 28 16:32:27 2008
@@ -60,9 +60,9 @@
 			   char const *dialog_name,
 			   char const *error_str,
 			   char const *key,
-			   GtkSignalFunc ok_function, 
-			   GtkSignalFunc close_function, 
-			   GtkSignalFunc sensitivity_cb,
+			   GCallback ok_function, 
+			   GCallback close_function, 
+			   GCallback sensitivity_cb,
 			   GnmExprEntryFlags flags);
 
 #endif

Modified: branches/gnumeric-1-8/src/gnm-datetime.c
==============================================================================
--- branches/gnumeric-1-8/src/gnm-datetime.c	(original)
+++ branches/gnumeric-1-8/src/gnm-datetime.c	Sat Jun 28 16:32:27 2008
@@ -64,8 +64,10 @@
 datetime_value_to_g (GDate *res, GnmValue const *v, GODateConventions const *conv)
 {
 	int serial = datetime_value_to_serial (v, conv);
-	if (serial == 0)
+	if (serial == 0) {
+		g_date_clear (res, 1);
 		return FALSE;
+	}
 	datetime_serial_to_g (res, serial, conv);
 	return g_date_valid (res);
 }
@@ -133,7 +135,7 @@
 		int feb29s, years;
 
 		d1 = *from;
-		g_date_add_years (&d1, 1);
+		gnm_date_add_years (&d1, 1);
 		if (g_date_compare (to, &d1) > 0) {
 			/* More than one year.  */
 			years = y2 + 1 - y1;
@@ -169,3 +171,107 @@
 
 	return days / peryear;
 }
+
+/* ------------------------------------------------------------------------- */
+/* Like g_date_add_days, but...
+ *
+ * 1. Do not spew criticals.
+ * 2. Number of days is signed.
+ */
+
+void
+gnm_date_add_days (GDate *d, int n)
+{
+	if (!g_date_valid (d))
+		return;
+
+	if (n >= 0) {
+		guint32 lim = 23936166;  /* 31-Dec-65535 */
+		guint32 j = g_date_get_julian (d);
+
+		if (j > lim || (unsigned)n > lim - j)
+			goto bad;
+
+		g_date_add_days (d, n);
+	} else {
+		int m = g_date_get_julian (d) - 1;
+
+		if (m + n <= 0)
+			goto bad;
+
+		g_date_subtract_days (d, -n);
+	}
+
+	return;
+
+ bad:
+	g_date_clear (d, 1);
+}
+
+/* Like g_date_add_months, but...
+ *
+ * 1. Do not spew criticals.
+ * 2. Number of months is signed.
+ */
+void
+gnm_date_add_months (GDate *d, int n)
+{
+	if (!g_date_valid (d))
+		return;
+
+	if (n >= 0) {
+		int m = (65535 - g_date_get_year (d)) * 12 +
+			(12 - g_date_get_month (d));
+
+		if (n > m)
+			goto bad;
+
+		g_date_add_months (d, n);
+	} else {
+		int m = (g_date_get_year (d) - 1) * 12 +
+			(g_date_get_month (d) - 1);
+
+		if (m + n <= 0)
+			goto bad;
+
+		g_date_subtract_months (d, -n);
+	}
+
+	return;
+
+ bad:
+	g_date_clear (d, 1);
+}
+
+/* Like g_date_add_years, but...
+ *
+ * 1. Do not spew criticals.
+ * 2. Number of years is signed.
+ */
+void
+gnm_date_add_years (GDate *d, int n)
+{
+	if (!g_date_valid (d))
+		return;
+
+	if (n >= 0) {
+		int m = 65535 - g_date_get_year (d);
+
+		if (n > m)
+			goto bad;
+
+		g_date_add_years (d, n);
+	} else {
+		int m = g_date_get_year (d) - 1;
+
+		if (m + n <= 0)
+			goto bad;
+
+		g_date_subtract_years (d, -n);
+	}
+
+	return;
+
+ bad:
+	g_date_clear (d, 1);
+}

Modified: branches/gnumeric-1-8/src/gnm-datetime.h
==============================================================================
--- branches/gnumeric-1-8/src/gnm-datetime.h	(original)
+++ branches/gnumeric-1-8/src/gnm-datetime.h	Sat Jun 28 16:32:27 2008
@@ -19,6 +19,9 @@
 			    GODateConventions const *date_conv);
 gnm_float yearfrac (GDate const *from, GDate const *to, basis_t basis);
 
+void gnm_date_add_days (GDate *d, int n);
+void gnm_date_add_months (GDate *d, int n);
+void gnm_date_add_years (GDate *d, int n);
 
 G_END_DECLS
 

Modified: branches/gnumeric-1-8/src/mathfunc.c
==============================================================================
--- branches/gnumeric-1-8/src/mathfunc.c	(original)
+++ branches/gnumeric-1-8/src/mathfunc.c	Sat Jun 28 16:32:27 2008
@@ -82,7 +82,7 @@
 
 #define ML_UNDERFLOW (GNM_EPSILON * GNM_EPSILON)
 #define ML_ERROR(cause) /* Nothing */
-#define MATHLIB_ERROR g_error
+#define MATHLIB_ERROR(_a,_b) return gnm_nan;
 #define MATHLIB_WARNING g_warning
 #define MATHLIB_WARNING2 g_warning
 #define MATHLIB_WARNING4 g_warning
@@ -3372,6 +3372,9 @@
 
     if (x < 0)
 	return R_DT_0;
+    /* Warning: the following line is not in R: */
+    if (x >= NR)
+	return R_DT_1;
 
     d  = dhyper (x, NR, NB, n, log_p);
     pd = pdhyper(x, NR, NB, n, log_p);

Modified: branches/gnumeric-1-8/src/sheet-autofill.c
==============================================================================
--- branches/gnumeric-1-8/src/sheet-autofill.c	(original)
+++ branches/gnumeric-1-8/src/sheet-autofill.c	Sat Jun 28 16:32:27 2008
@@ -590,10 +590,7 @@
 	GDate d = afm->base;
 	GnmValue *v;
 
-	if (afm->nmonths >= 0)
-		g_date_add_months (&d, n * afm->nmonths);
-	else
-		g_date_subtract_months (&d, n * -afm->nmonths);
+	gnm_date_add_months (&d, n * afm->nmonths);
 
 	if (!g_date_valid (&d) || g_date_get_year (&d) > 9999)
 		return NULL;

Modified: branches/gnumeric-1-8/src/tools/fill-series.c
==============================================================================
--- branches/gnumeric-1-8/src/tools/fill-series.c	(original)
+++ branches/gnumeric-1-8/src/tools/fill-series.c	Sat Jun 28 16:32:27 2008
@@ -37,6 +37,7 @@
 #include "workbook.h"
 #include "tools.h"
 #include "numbers.h"
+#include "gnm-datetime.h"
 
 #include "mathfunc.h"
 #include "fill-series.h"
@@ -62,10 +63,7 @@
 		wd = g_date_get_weekday (&date);
 		if (wd + (steps % 5) > G_DATE_FRIDAY)
 				days += 2;
-		if (days > 0)
-			g_date_add_days (&date, days);
-		else
-			g_date_subtract_days (&date, - days);
+		gnm_date_add_days (&date, days);
 		
 		dao_set_cell_float (dao, i, 0, 
 				    datetime_g_to_serial (&date, conv));
@@ -92,10 +90,7 @@
 		wd = g_date_get_weekday (&date);
 		if (wd + (steps % 5) > G_DATE_FRIDAY)
 				days += 2;
-		if (days > 0)
-			g_date_add_days (&date, days);
-		else
-			g_date_subtract_days (&date, - days);
+		gnm_date_add_days (&date, days);
 		
 		dao_set_cell_float (dao, 0,i, 
 				    datetime_g_to_serial (&date, conv));
@@ -116,10 +111,7 @@
 	
 	for (i = 0; i < info->n; i++) {
 		datetime_serial_to_g (&date, start, conv);
-		if (info->step_value > 0)
-			g_date_add_months (&date, i * info->step_value);
-		else
-			g_date_subtract_months (&date,- i * info->step_value);
+		gnm_date_add_months (&date, i * info->step_value);
 		
 		dao_set_cell_float (dao, i, 0, 
 				    datetime_g_to_serial (&date, conv));
@@ -138,10 +130,7 @@
 	
 	for (i = 0; i < info->n; i++) {
 		datetime_serial_to_g (&date, start, conv);
-		if (info->step_value > 0)
-			g_date_add_months (&date, i * info->step_value);
-		else
-			g_date_subtract_months (&date,- i * info->step_value);
+		gnm_date_add_months (&date, i * info->step_value);
 		
 		dao_set_cell_float (dao, 0, i, 
 				    datetime_g_to_serial (&date, conv));
@@ -160,10 +149,7 @@
 	
 	for (i = 0; i < info->n; i++) {
 		datetime_serial_to_g (&date, start, conv);
-		if (info->step_value > 0)
-			g_date_add_years (&date, i * info->step_value);
-		else
-			g_date_subtract_years (&date,- i * info->step_value);
+		gnm_date_add_years (&date, i * info->step_value);
 		
 		dao_set_cell_float (dao, i, 0, 
 				    datetime_g_to_serial (&date, conv));
@@ -182,10 +168,7 @@
 	
 	for (i = 0; i < info->n; i++) {
 		datetime_serial_to_g (&date, start, conv);
-		if (info->step_value > 0)
-			g_date_add_years (&date, i * info->step_value);
-		else
-			g_date_subtract_years (&date,- i * info->step_value);
+		gnm_date_add_years (&date, i * info->step_value);
 		
 		dao_set_cell_float (dao, 0, i, 
 				    datetime_g_to_serial (&date, conv));

Modified: branches/gnumeric-1-8/src/tools/simulation.c
==============================================================================
--- branches/gnumeric-1-8/src/tools/simulation.c	(original)
+++ branches/gnumeric-1-8/src/tools/simulation.c	Sat Jun 28 16:32:27 2008
@@ -44,7 +44,6 @@
 	stats->max        = g_new (gnm_float, sim->n_vars);
 	stats->mean       = g_new (gnm_float, sim->n_vars);
 	stats->median     = g_new (gnm_float, sim->n_vars);
-	stats->median     = g_new (gnm_float, sim->n_vars);
 	stats->mode       = g_new (gnm_float, sim->n_vars);
 	stats->stddev     = g_new (gnm_float, sim->n_vars);
 	stats->var        = g_new (gnm_float, sim->n_vars);

Modified: branches/gnumeric-1-8/src/widgets/gnumeric-lazy-list.c
==============================================================================
--- branches/gnumeric-1-8/src/widgets/gnumeric-lazy-list.c	(original)
+++ branches/gnumeric-1-8/src/widgets/gnumeric-lazy-list.c	Sat Jun 28 16:32:27 2008
@@ -217,7 +217,7 @@
 	iface->iter_parent = lazy_list_iter_parent;
 }
 
-GtkType
+GType
 gnumeric_lazy_list_get_type (void)
 {
 	static GType lazy_list_type = 0;

Modified: branches/gnumeric-1-8/src/widgets/widget-font-selector.c
==============================================================================
--- branches/gnumeric-1-8/src/widgets/widget-font-selector.c	(original)
+++ branches/gnumeric-1-8/src/widgets/widget-font-selector.c	Sat Jun 28 16:32:27 2008
@@ -197,7 +197,7 @@
 
 	g_signal_connect (
 		 G_OBJECT (gtk_tree_view_get_selection (fs->font_name_list)), "changed",
-		 GTK_SIGNAL_FUNC (font_selected), fs);
+		 G_CALLBACK (font_selected), fs);
 }
 
 static char const *styles[] = {
@@ -260,7 +260,7 @@
 	}
 	g_signal_connect (
 		G_OBJECT (gtk_tree_view_get_selection (fs->font_style_list)), "changed",
-		GTK_SIGNAL_FUNC (style_selected), fs);
+		G_CALLBACK (style_selected), fs);
 }
 
 static void
@@ -349,11 +349,11 @@
 	}
 	g_signal_connect (
 		G_OBJECT (gtk_tree_view_get_selection (fs->font_size_list)), "changed",
-		GTK_SIGNAL_FUNC (size_selected), fs);
+		G_CALLBACK (size_selected), fs);
 
 	g_signal_connect (
 		G_OBJECT (fs->font_size_entry), "changed",
-		GTK_SIGNAL_FUNC (size_changed), fs);
+		G_CALLBACK (size_changed), fs);
 }
 
 static void
@@ -413,7 +413,7 @@
 
 	g_signal_connect (G_OBJECT (fs->font_preview_canvas),
 		"size-allocate",
-		GTK_SIGNAL_FUNC (canvas_size_changed), fs);
+		G_CALLBACK (canvas_size_changed), fs);
 
 	fs_fill_font_name_list (fs);
 	fs_fill_font_style_list (fs);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]