[gnumeric] docs: check all expressions in function docs examples.



commit 4c44a5e8b08566dacbcd745eaf12e0179dae3757
Author: Morten Welinder <terra gnome org>
Date:   Sun Jun 13 20:36:50 2010 -0400

    docs: check all expressions in function docs examples.

 ChangeLog                     |    2 ++
 plugins/fn-lookup/ChangeLog   |    5 +++++
 plugins/fn-lookup/functions.c |    3 ---
 src/func.c                    |   40 +++++++++++++++++++++++++++++++++++-----
 4 files changed, 42 insertions(+), 8 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index cecf094..9bd533d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,7 @@
 2010-06-13  Morten Welinder  <terra gnome org>
 
+	* src/func.c (check_help_expression): New function.
+
 	* src/parser.y (yylex): Fix parsing of calls to LOG2 and LOG10 in
 	sheets with more than ~8500 columns.
 
diff --git a/plugins/fn-lookup/ChangeLog b/plugins/fn-lookup/ChangeLog
index b468d00..3245448 100644
--- a/plugins/fn-lookup/ChangeLog
+++ b/plugins/fn-lookup/ChangeLog
@@ -1,3 +1,8 @@
+2010-06-13  Morten Welinder  <terra gnome org>
+
+	* functions.c (help_sheet, help_sheets): Remove help entries that
+	may not parse.
+
 2010-05-30  Morten Welinder <terra gnome org>
 
 	* Release 1.10.5
diff --git a/plugins/fn-lookup/functions.c b/plugins/fn-lookup/functions.c
index 5a553a2..b234e14 100644
--- a/plugins/fn-lookup/functions.c
+++ b/plugins/fn-lookup/functions.c
@@ -1554,7 +1554,6 @@ static GnmFuncHelp const help_sheets[] = {
         { GNM_FUNC_HELP_ARG, F_("reference:array, reference, or range, defaults to the maximum range")},
 	{ GNM_FUNC_HELP_NOTE, F_("If @{reference} is neither an array nor a reference nor a range, "
 				 "SHEETS returns #VALUE!")},
-        { GNM_FUNC_HELP_EXAMPLES, "=SHEETS(Sheet1!H7:Sheet2!I13)" },
         { GNM_FUNC_HELP_EXAMPLES, "=SHEETS()" },
         { GNM_FUNC_HELP_SEEALSO, "COLUMNS,ROWS"},
         { GNM_FUNC_HELP_END}
@@ -1593,8 +1592,6 @@ static GnmFuncHelp const help_sheet[] = {
         { GNM_FUNC_HELP_ARG, F_("reference:reference or literal sheet name, defaults to the current sheet")},
 	{ GNM_FUNC_HELP_NOTE, F_("If @{reference} is neither a reference nor a literal sheet name, "
 				 "SHEETS returns #VALUE!")},
-        { GNM_FUNC_HELP_EXAMPLES, "=SHEET(Sheet2!H7)" },
-        { GNM_FUNC_HELP_EXAMPLES, "=SHEET(Sheet2!H7:Z8)" },
         { GNM_FUNC_HELP_EXAMPLES, "=SHEET()" },
         { GNM_FUNC_HELP_EXAMPLES, "=SHEET(\"Sheet1\")" },
         { GNM_FUNC_HELP_SEEALSO, "SHEETS,ROW,COLUMNNUMBER"},
diff --git a/src/func.c b/src/func.c
index e17ad60..70d90c4 100644
--- a/src/func.c
+++ b/src/func.c
@@ -493,6 +493,40 @@ function_dump_defs (char const *filename, int dump_type)
 
 /* ------------------------------------------------------------------------- */
 
+gboolean
+check_help_expression (const char *text, GnmFunc const *fd)
+{
+	GnmConventions const *convs = gnm_conventions_default;
+	GnmParsePos pp;
+	GnmExprTop const *texpr;
+	Workbook *wb;
+	GnmParseError perr;
+
+	/* Create a dummy workbook with no sheets for interesting effects.  */
+	wb = workbook_new ();
+	parse_pos_init (&pp, wb, NULL, 0, 0);
+
+	parse_error_init (&perr);
+
+	texpr = gnm_expr_parse_str (text, &pp,
+				    GNM_EXPR_PARSE_DEFAULT,
+				    convs,
+				    &perr);
+	if (perr.err) {
+		g_printerr ("Error parsing %s: %s\n",
+			    text, perr.err->message);
+	}
+	parse_error_free (&perr);
+	g_object_unref (wb);
+
+	if (!texpr)
+		return TRUE;
+
+	gnm_expr_top_unref (texpr);
+	return FALSE;
+}
+
+
 static int
 gnm_func_sanity_check1 (GnmFunc const *fd)
 {
@@ -538,15 +572,11 @@ gnm_func_sanity_check1 (GnmFunc const *fd)
 		}
 		case GNM_FUNC_HELP_EXAMPLES:
 			if (h->text[0] == '=') {
-#if 0
-				if (g_ascii_strncasecmp (fd->name,
-							 h->text + 1, nlen) ||
-				    g_ascii_isalnum (h->text[nlen + 1])) {
+				if (check_help_expression (h->text + 1, fd)) {
 					g_printerr ("%s: Invalid EXAMPLES record\n",
 						    fd->name);
 					res = 1;
 				}
-#endif
 			}
 			break;
 		default:



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