[gnumeric] Testing: code to dump all function samples from docs.
- From: Morten Welinder <mortenw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnumeric] Testing: code to dump all function samples from docs.
- Date: Thu, 19 Mar 2015 13:11:18 +0000 (UTC)
commit 6d792fbb99d64f33ab7db336a7e4c298c595e362
Author: Morten Welinder <terra gnome org>
Date: Thu Mar 19 09:10:48 2015 -0400
Testing: code to dump all function samples from docs.
ChangeLog | 3 ++
src/func.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++
src/main-application.c | 9 ++++++
3 files changed, 80 insertions(+), 0 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index d8f58b2..ee1ed9e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
2015-03-19 Morten Welinder <terra gnome org>
+ * src/func.c (dump_samples): New function to dump all sample in
+ help documentation to csv format.
+
* src/sf-gamma.c (qbetaf): Return zero as result when a+b is a
non-positive integer, but neither a nor b is.
diff --git a/src/func.c b/src/func.c
index 221397b..8a8112d 100644
--- a/src/func.c
+++ b/src/func.c
@@ -211,6 +211,66 @@ dump_externals (GPtrArray *defs, FILE *out)
fprintf (out, "<!--#include virtual=\"footer.shtml\" -->\n");
}
+static void
+csv_quoted_print (FILE *out, const char *s)
+{
+ char quote = '"';
+ fputc (quote, out);
+ while (*s) {
+ if (*s == quote) {
+ fputc (quote, out);
+ fputc (quote, out);
+ s++;
+ } else {
+ int len = g_utf8_skip[(unsigned char)*s];
+ fprintf (out, "%-.*s", len, s);
+ s += len;
+ }
+ }
+ fputc ('"', out);
+}
+
+static void
+dump_samples (GPtrArray *defs, FILE *out)
+{
+ unsigned ui;
+ GnmFuncGroup *last_group = NULL;
+
+ for (ui = 0; ui < defs->len; ui++) {
+ GnmFunc const *fd = g_ptr_array_index (defs, ui);
+ int j;
+ const char *last = NULL;
+
+ if (last_group != fd->fn_group) {
+ last_group = fd->fn_group;
+ csv_quoted_print (out, last_group->display_name->str);
+ fputc ('\n', out);
+ }
+
+ for (j = 0; fd->help[j].type != GNM_FUNC_HELP_END; j++) {
+ const char *s = fd->help[j].text;
+
+ /*
+ * Some of the random numbers functions have duplicate
+ * samples. We don't want the duplicates here.
+ */
+ if (fd->help[j].type != GNM_FUNC_HELP_EXAMPLES ||
+ s[0] != '=' ||
+ (last && strcmp (last, s) == 0))
+ continue;
+
+ fputc (',', out);
+ if (!last)
+ csv_quoted_print (out, fd->name);
+ last = s;
+
+ fputc (',', out);
+ csv_quoted_print (out, s);
+ fputc ('\n', out);
+ }
+ }
+}
+
/**
* function_dump_defs :
* @filename:
@@ -224,6 +284,7 @@ dump_externals (GPtrArray *defs, FILE *out)
* 2 : generate_po
* 3 : dump function usage count
* 4 : external refs
+ * 5 : all sample expressions
**/
void
function_dump_defs (char const *filename, int dump_type)
@@ -270,6 +331,13 @@ function_dump_defs (char const *filename, int dump_type)
return;
}
+ if (dump_type == 5) {
+ dump_samples (ordered, output_file);
+ g_ptr_array_free (ordered, TRUE);
+ fclose (output_file);
+ return;
+ }
+
if (dump_type == 0) {
int unique = 0;
for (i = 0; i < ordered->len; i++) {
diff --git a/src/main-application.c b/src/main-application.c
index 561561c..36167b7 100644
--- a/src/main-application.c
+++ b/src/main-application.c
@@ -53,6 +53,7 @@ static gboolean gnumeric_no_warnings = FALSE;
static gchar *func_def_file = NULL;
static gchar *func_state_file = NULL;
static gchar *ext_refs_file = NULL;
+static gchar *samples_file = NULL;
static gchar *geometry = NULL;
static gchar **startup_files;
@@ -91,6 +92,12 @@ static const GOptionEntry gnumeric_options [] = {
N_("FILE")
},
{
+ "samples-file", 0,
+ G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_FILENAME, &samples_file,
+ N_("Dumps list of samples in function help"),
+ N_("FILE")
+ },
+ {
"split-func", 0,
G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE, &split_funcdocs,
N_("Generate new help and po files"),
@@ -287,6 +294,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 (samples_file)
+ return gnm_dump_func_defs (samples_file, 5);
if (with_gui) {
go_component_set_default_command_context (cc = gnm_cmd_context_stderr_new ());
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]