[gnumeric] Docs: add option to sanity check help texts.



commit eff417e31a545846ef1f07284f98550e894988c5
Author: Morten Welinder <terra gnome org>
Date:   Fri Aug 14 10:21:48 2009 -0400

    Docs: add option to sanity check help texts.

 ChangeLog              |    8 +++++
 NEWS                   |    1 +
 src/func.c             |   70 ++++++++++++++++++++++++++++++++++++++++++++++++
 src/func.h             |    1 +
 src/main-application.c |    8 +++++
 5 files changed, 88 insertions(+), 0 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index f0488a5..ec8c2c2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2009-08-14  Morten Welinder  <terra gnome org>
+
+	* src/main-application.c (main): Add new --func-sanity-check
+	option.
+
+	* src/func.c (gnm_func_sanity_check, gnm_func_sanity_check1): New
+	functions.
+
 2009-08-13  Morten Welinder  <terra gnome org>
 
 	* src/func.c (func_def_cmp, function_category_compare): Take
diff --git a/NEWS b/NEWS
index ff9afb1..db3c4f4 100644
--- a/NEWS
+++ b/NEWS
@@ -41,6 +41,7 @@ Morten:
 	* Avoid using gtk_tree_view_column_get_cell_renderers.  [#589105]
 	* Fix DEC2HEX and friends for large values.  [#588997]
 	* Make undo/redo visible for vertical toolbar.
+	* Add some checking of help texts' sanity.
 
 --------------------------------------------------------------------------
 Gnumeric 1.9.9
diff --git a/src/func.c b/src/func.c
index 3415288..4a76782 100644
--- a/src/func.c
+++ b/src/func.c
@@ -27,6 +27,8 @@
 #include "value.h"
 #include "number-match.h"
 #include "func-builtin.h"
+#include "command-context-stderr.h"
+#include "gnm-plugin.h"
 
 #include <goffice/goffice.h>
 #include <glib.h>
@@ -520,6 +522,74 @@ function_dump_defs (char const *filename, int dump_type)
 
 /* ------------------------------------------------------------------------- */
 
+static int
+gnm_func_sanity_check1 (GnmFunc const *fd)
+{
+	GnmFuncHelp const *h;
+	int counts[(int)GNM_FUNC_HELP_ODF + 1];
+	int res = 0;
+
+	memset (counts, 0, sizeof (counts));
+	for (h = fd->help; h->type != GNM_FUNC_HELP_END; h++) {
+		g_assert (h->type <= GNM_FUNC_HELP_ODF);
+		counts[h->type]++;
+
+		switch (h->type) {
+		case GNM_FUNC_HELP_NAME: {
+			size_t nlen = strlen (fd->name);
+			if (g_ascii_strncasecmp (fd->name, h->text, nlen) ||
+			    h->text[nlen] != ':') {
+				g_printerr ("%s: Invalid NAME record\n",
+					    fd->name);
+				res = 1;
+			}
+			break;
+		}
+		case GNM_FUNC_HELP_ARG:
+			break;
+		default:
+			; /* Nothing */
+		}
+	}
+
+	return res;
+}
+
+int
+gnm_func_sanity_check (void)
+{
+	int res;
+	GOCmdContext *cc = cmd_context_stderr_new ();
+	GPtrArray *ordered;
+	unsigned ui;
+
+	gnm_plugins_init (cc);
+	res = cmd_context_stderr_get_status (COMMAND_CONTEXT_STDERR (cc));
+	if (res)
+		goto out;
+	
+	ordered = g_ptr_array_new ();
+	g_hash_table_foreach (global_symbol_table->hash,
+			      copy_hash_table_to_ptr_array, ordered);
+	if (ordered->len > 0)
+		qsort (&g_ptr_array_index (ordered, 0),
+		       ordered->len, sizeof (gpointer),
+		       func_def_cmp);
+
+	for (ui = 0; ui < ordered->len; ui++) {
+		GnmFunc const *fd = g_ptr_array_index (ordered, ui);
+		if (gnm_func_sanity_check1 (fd))
+			res = 1;
+	}
+
+	g_ptr_array_free (ordered, TRUE);
+
+ out:
+	return res;
+}
+
+/* ------------------------------------------------------------------------- */
+
 static void
 gnm_func_group_free (GnmFuncGroup *fn_group)
 {
diff --git a/src/func.h b/src/func.h
index 664a2ae..becc5fa 100644
--- a/src/func.h
+++ b/src/func.h
@@ -12,6 +12,7 @@ void functions_init     (void);
 void functions_shutdown (void);
 
 void function_dump_defs (char const *filename, int dump_type);
+int gnm_func_sanity_check (void);
 
 /******************************************************************************/
 /* Function group support */
diff --git a/src/main-application.c b/src/main-application.c
index c317c6c..a151bc2 100644
--- a/src/main-application.c
+++ b/src/main-application.c
@@ -35,6 +35,7 @@
 #include "gutils.h"
 #include "gnm-plugin.h"
 #include "application.h"
+#include "func.h"
 
 #include <gtk/gtk.h>
 #include <glib/gstdio.h>
@@ -61,6 +62,7 @@ static gboolean split_funcdocs = FALSE;
 static gboolean immediate_exit_flag = FALSE;
 static gboolean gnumeric_no_splash = FALSE;
 static gboolean gnumeric_no_warnings = FALSE;
+static gboolean func_sanity_check = FALSE;
 static gchar  *func_def_file = NULL;
 static gchar  *func_state_file = NULL;
 static gchar  *ext_refs_file = NULL;
@@ -107,6 +109,10 @@ static const GOptionEntry gnumeric_options [] = {
 		N_("Generate new help and po files"),
 		NULL
 	},
+	{ "func-sanity-check", 0, 0, G_OPTION_ARG_NONE, &func_sanity_check,
+		N_("Sanity check functions' help texts"),
+		NULL
+	},
 	{
 		"quit", 0,
 		G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE, &immediate_exit_flag,
@@ -368,6 +374,8 @@ main (int argc, char const **argv)
 		return gnm_dump_func_defs (NULL, 2);
 	if (ext_refs_file)
 		return gnm_dump_func_defs (ext_refs_file, 4);
+	if (func_sanity_check)
+		return gnm_func_sanity_check ();
 
 	/* Keep in sync with .desktop file */
 	g_set_application_name (_("Gnumeric Spreadsheet"));



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