gnumeric r16544 - in trunk: . doc/C plugins/excel src



Author: jody
Date: Fri May  2 14:29:33 2008
New Revision: 16544
URL: http://svn.gnome.org/viewvc/gnumeric?rev=16544&view=rev

Log:
2008-05-02  Jody Goldberg <jody gnome org>

	* configure.in : add ssgrep.
	* src/Makefile.am : ditto.
	* src/.gitignore : ditto.

	* src/str.c (gnm_string_foreach) : new wrapper to make it easier to
	  walk all available strings.

	* src/workbook-view.c (wb_view_new_from_uri) : turn off the info spew.


Added:
   trunk/doc/C/ssgrep.1
   trunk/src/ssgrep.c
Modified:
   trunk/ChangeLog
   trunk/INSTALL
   trunk/NEWS
   trunk/configure.in
   trunk/doc/C/Makefile.am
   trunk/plugins/excel/ChangeLog
   trunk/plugins/excel/ms-excel-read.c
   trunk/src/.gitignore
   trunk/src/Makefile.am
   trunk/src/str.c
   trunk/src/str.h
   trunk/src/workbook-view.c

Modified: trunk/INSTALL
==============================================================================
--- trunk/INSTALL	(original)
+++ trunk/INSTALL	Fri May  2 14:29:33 2008
@@ -2,7 +2,7 @@
 *************************
 
 Copyright (C) 1994, 1995, 1996, 1999, 2000, 2001, 2002, 2004, 2005,
-2006 Free Software Foundation, Inc.
+2006, 2007 Free Software Foundation, Inc.
 
 This file is free documentation; the Free Software Foundation gives
 unlimited permission to copy, distribute and modify it.
@@ -67,6 +67,9 @@
      all sorts of other programs in order to regenerate files that came
      with the distribution.
 
+  6. Often, you can also type `make uninstall' to remove the installed
+     files again.
+
 Compilers and Options
 =====================
 

Modified: trunk/NEWS
==============================================================================
--- trunk/NEWS	(original)
+++ trunk/NEWS	Fri May  2 14:29:33 2008
@@ -20,6 +20,7 @@
 	* Fix ssconvert win32.
 	* Merge some cygwin build patches. [#506366]
 	* Enable the use of dolt.
+	* Add 'ssgrep'
 
 Jon KÃre:
         * Receive clipboard from broken apps. [#524756]

Modified: trunk/configure.in
==============================================================================
--- trunk/configure.in	(original)
+++ trunk/configure.in	Fri May  2 14:29:33 2008
@@ -411,15 +411,20 @@
 AC_SUBST(WARN_CFLAGS)
 
 AC_ARG_ENABLE(ssconvert,
-  [--disable-ssconvert		Do not build ssconvert (command line spreadsheet conversion tool)],
+  [--disable-ssconvert		Do nott build ssconvert (command line spreadsheet conversion tool)],
   [], [enable_ssconvert=yes])
 AM_CONDITIONAL(ENABLE_SSCONVERT, test x"$enable_ssconvert" = "xyes")
 
 AC_ARG_ENABLE(ssindex,
-  [--disable-ssindex		Do no build ssindex (spreadsheet indexer for beagle)],
+  [--disable-ssindex		Do not build ssindex (spreadsheet indexer for beagle)],
   [], [enable_ssindex=yes])
 AM_CONDITIONAL(ENABLE_SSINDEX, test x"$enable_ssindex" = "xyes")
 
+AC_ARG_ENABLE(ssgrep,
+  [--disable-ssgrep		Do not build ssgrep (search for supplied strings in spreadsheet)],
+  [], [enable_ssgrep=yes])
+AM_CONDITIONAL(ENABLE_SSGREP, test x"$enable_ssgrep" = "xyes")
+
 dnl ****************************
 dnl GDA Plugin
 dnl ****************************

Modified: trunk/doc/C/Makefile.am
==============================================================================
--- trunk/doc/C/Makefile.am	(original)
+++ trunk/doc/C/Makefile.am	Fri May  2 14:29:33 2008
@@ -85,6 +85,10 @@
 manpage_DATA += ssindex.1
 endif
 
+if ENABLE_SSGREP
+manpage_DATA += ssgrep.1
+endif
+
 # from gnumeric-doc.make
 dist-hook: validate
 

Added: trunk/doc/C/ssgrep.1
==============================================================================
--- (empty file)
+++ trunk/doc/C/ssgrep.1	Fri May  2 14:29:33 2008
@@ -0,0 +1,95 @@
+.de URL
+\\$2 \(laURL: \\$1 \(ra\\$3
+..
+.if \n[.g] .mso www.tmac
+.TH SSGREP 1 "May 2, 2008" gnumeric "GNOME"
+.SH NAME
+ssgrep \- search spreadsheets for strings
+
+.SH SYNOPSIS
+\fBssgrep \fR [\fIOPTIONS\fR] [\fIFILES\fR]
+
+.SH DESCRIPTION
+This manual page briefly documents the \fBssgrep\fR command.
+
+\fBssgrep\fR is a command line utility to search for strings in spreadsheets of
+any format supported by gnumeric.
+
+.\".SH "RETURN VALUE"
+.\".SH "EXIT STATUS"
+.\".SH ERRORS
+.SH OPTIONS
+This program follows the usual GNU command line syntax, with single
+letter options starting with a single dash (`-') and longer options
+starting with two dashes (`--').
+
+.SS "Main options"
+.TP
+.B \-f, \-\-keyword\-file=\fIFILE\fR
+The path to a text file containing one key per line
+.TP
+
+.SS "Help options"
+.TP
+.B \-v, \-\-version
+Display ssgrep's version
+.TP
+.B \-?, \-\-help
+Display the supported options
+.TP
+.B \-\-usage
+Display a brief usage message
+
+.SS "Path options"
+.TP
+.B \-L, \-\-lib\-dir=\fISTRING\fR
+Set the root library directory
+.TP
+.B \-D, \-\-data\-dir=\fISTRING\fR
+Adjust the root data directory
+
+.\".SH USAGE
+.SH EXAMPLE
+To search for the string "SUM" in the file \fIfoo.gnumeric\fR :
+.PP
+\fBssgrep\fR \fISUM\fR \fIfoo.gnumeric\fR
+.PP
+To search for the strings from the file \fIkeywords\R in the spreadsheet \fIfoo.xls\fR :
+.PP
+\fBssgrep\fR \fB\-\-keyword\-file=\fIkeywords\fR \fIfoo.xls\fR
+.PP
+
+.\".SH FILES
+.\".SH ENVIRONMENT
+.\".SH DIAGNOSTICS
+.\".SH SECURITY
+.\".SH CONFORMING TO
+.\".SH NOTES
+.\".SH BUGS
+
+.SH LICENSE
+
+\fBssgrep\fR is licensed under the terms of the General Public
+License (GPL), version 2. For information on this license look at the
+source code that came with the software or see the 
+.URL "http://www.gnu.org"; "GNU project page" .
+
+.SH COPYRIGHT
+
+The copyright on \fBssgrep\fR and the \fBgnumeric\fR software and source
+code is held by the individual authors as is documented in the source code.
+
+.SH AUTHOR
+
+\fBssgrep\fR's primary author is Jody Goldberg <jody gnome org>; 
+\fBssgrep\fR builds on the \fBgnumeric\fR codebase.
+
+The initial version of this manpage was based on ssindex.1 by J.H.M. Dassen
+(Ray) <jdassen debian org>.
+
+.SH SEE ALSO
+\fBbeagled\fR(1), \fBgnumeric\fR(1)
+
+.URL "http://www.gnome.org/projects/gnumeric/"; "The Gnumeric Homepage" .
+
+.URL "http://www.gnome.org/"; "The GNOME project page" .

Modified: trunk/plugins/excel/ms-excel-read.c
==============================================================================
--- trunk/plugins/excel/ms-excel-read.c	(original)
+++ trunk/plugins/excel/ms-excel-read.c	Fri May  2 14:29:33 2008
@@ -6467,6 +6467,8 @@
 	/* The first BOF seems to be OK, the rest lie ? */
 	MsBiffVersion vv = MS_BIFF_V_UNKNOWN;
 	MsBiffBofData *ver = *version;
+	char const *version_desc = NULL;
+
 	if (ver) {
 		vv = ver->version;
 		ms_biff_bof_data_destroy (ver);
@@ -6480,19 +6482,19 @@
 		if (ver->version >= MS_BIFF_V8) {
 			guint32 ver = GSF_LE_GET_GUINT32 (q->data + 4);
 			if (ver == 0x4107cd18)
-				g_printerr ("Excel 2000 ?\n");
+				version_desc = "Excel 2000 ?";
 			else
-				g_printerr ("Excel 97 +\n");
+				version_desc = "Excel 97 +";
 		} else if (ver->version >= MS_BIFF_V7)
-			g_printerr ("Excel 95\n");
+			version_desc = "Excel 95";
 		else if (ver->version >= MS_BIFF_V5)
-			g_printerr ("Excel 5.x\n");
+			version_desc = "Excel 5.x";
 		else if (ver->version >= MS_BIFF_V4)
-			g_printerr ("Excel 4.x\n");
+			version_desc = "Excel 4.x";
 		else if (ver->version >= MS_BIFF_V3)
-			g_printerr ("Excel 3.x - shouldn't happen\n");
+			version_desc = "Excel 3.x - shouldn't happen";
 		else if (ver->version >= MS_BIFF_V2)
-			g_printerr ("Excel 2.x - shouldn't happen\n");
+			version_desc = "Excel 2.x - shouldn't happen";
 	} else if (ver->type == MS_BIFF_TYPE_Worksheet ||
 		   ver->type == MS_BIFF_TYPE_Chart) {
 		BiffBoundsheetData *bs = g_hash_table_lookup (
@@ -6506,13 +6508,13 @@
 				/* Top level worksheets existed up to & including 4.x */
 				gnm_xl_importer_set_version (importer, ver->version);
 				if (ver->version >= MS_BIFF_V5)
-					g_printerr ( ">= Excel 5 with no BOUNDSHEET ?? - shouldn't happen\n");
+					version_desc = ">= Excel 5 with no BOUNDSHEET ?? - shouldn't happen";
 				else if (ver->version >= MS_BIFF_V4)
-					g_printerr ( "Excel 4.x single worksheet\n");
+					version_desc = "Excel 4.x single worksheet";
 				else if (ver->version >= MS_BIFF_V3)
-					g_printerr ( "Excel 3.x single worksheet\n");
+					version_desc = "Excel 3.x single worksheet";
 				else if (ver->version >= MS_BIFF_V2)
-					g_printerr ( "Excel 2.x single worksheet\n");
+					version_desc = "Excel 2.x single worksheet";
 			} else
 				esheet = g_ptr_array_index (importer->excel_sheets, *current_sheet);
 		} else
@@ -6535,10 +6537,10 @@
 		   ver->type == MS_BIFF_TYPE_Macrosheet) {
 		/* Skip contents of Module, or MacroSheet */
 		if (ver->type != MS_BIFF_TYPE_Macrosheet)
-			g_printerr ("VB Module.\n");
+			version_desc = "VB Module";
 		else {
 			(*current_sheet)++;
-			g_printerr ("XLM Macrosheet.\n");
+			version_desc = "XLM Macrosheet";
 		}
 
 		while (ms_biff_query_next (q) && q->opcode != BIFF_EOF)
@@ -6547,10 +6549,14 @@
 			g_warning ("EXCEL: file format error.  Missing BIFF_EOF");
 	} else if (ver->type == MS_BIFF_TYPE_Workspace) {
 		/* Multiple sheets, XLW format from Excel 4.0 */
-		g_printerr ("Excel 4.x workbook\n");
+		version_desc = "Excel 4.x workbook";
 		gnm_xl_importer_set_version (importer, ver->version);
 	} else
 		g_printerr ("Unknown BOF (%x)\n", ver->type);
+
+	if (NULL != version_desc) {
+		d (1, g_printerr ("%s\n", version_desc););
+	}
 }
 
 static void

Modified: trunk/src/.gitignore
==============================================================================
--- trunk/src/.gitignore	(original)
+++ trunk/src/.gitignore	Fri May  2 14:29:33 2008
@@ -15,6 +15,7 @@
 gnumeric-paths.h
 ssconvert
 ssindex
+ssgrep
 test-pango
 GNOME_Gnumeric-gtk.xml
 HILDON_Gnumeric-gtk.xml

Modified: trunk/src/Makefile.am
==============================================================================
--- trunk/src/Makefile.am	(original)
+++ trunk/src/Makefile.am	Fri May  2 14:29:33 2008
@@ -21,6 +21,9 @@
 if ENABLE_SSINDEX
   bin_PROGRAMS += ssindex
 endif
+if ENABLE_SSGREP
+  bin_PROGRAMS += ssgrep
+endif
 
 AM_CPPFLAGS = 								\
 	-I$(top_srcdir)							\
@@ -299,6 +302,10 @@
 ssindex_LDFLAGS = -export-dynamic
 ssindex_SOURCES =				\
 	ssindex.c
+ssgrep_LDADD   = $(gnumeric_LDADD)
+ssgrep_LDFLAGS = -export-dynamic
+ssgrep_SOURCES =				\
+	ssgrep.c
 
 test_pango_LDADD   = $(gnumeric_LDADD)
 test_pango_LDFLAGS = -export-dynamic
@@ -316,6 +323,7 @@
     gnumeric_LDFLAGS	+= -mwindows
     ssconvert_LDFLAGS	+= -mconsole
     ssindex_LDFLAGS	+= -mconsole
+    ssgrep_LDFLAGS	+= -mconsole
 
     libspreadsheet_la_DEPENDENCIES = libspreadsheet.def
     libspreadsheet_la_LDFLAGS += -no-undefined -export-symbols libspreadsheet.def

Added: trunk/src/ssgrep.c
==============================================================================
--- (empty file)
+++ trunk/src/ssgrep.c	Fri May  2 14:29:33 2008
@@ -0,0 +1,223 @@
+/* vim: set sw=8: -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * ssgrep.c: Search spreadsheets of selected strings
+ *
+ * Author:
+ *   Jody Goldberg <jody gnome org>
+ *
+ * Copyright (C) 2008 Jody Goldberg
+ */
+#include <gnumeric-config.h>
+#include "gnumeric.h"
+#include "libgnumeric.h"
+#include <goffice/app/go-plugin.h>
+#include "command-context-stderr.h"
+#include <goffice/app/io-context.h>
+#include "workbook-view.h"
+#include "workbook.h"
+#include "str.h"
+#include "func.h"
+#include "gutils.h"
+#include "gnm-plugin.h"
+
+#include <goffice/utils/go-file.h>
+#include <goffice/app/go-cmd-context.h>
+#include <gsf/gsf-input-stdio.h>
+#include <gsf/gsf-input-textline.h>
+#include <glib/gi18n.h>
+#include <string.h>
+
+static gboolean ssgrep_show_version = FALSE;
+static char *ssgrep_keyword_file = NULL;
+
+static GOptionEntry const ssgrep_options [] = {
+	{
+		"version", 'v',
+		0, G_OPTION_ARG_NONE, &ssgrep_show_version,
+		N_("Display program version"),
+		NULL
+	},
+
+	{
+		"keyword-file", 'f',
+		0, G_OPTION_ARG_STRING, &ssgrep_keyword_file,
+		N_("Optionally specify which importer to use"),
+		N_("KEYWORD_FILE")
+	},
+	/* ---------------------------------------- */
+
+	{ NULL }
+};
+
+typedef struct {
+	GHashTable *targets;
+	gboolean    found;
+	char const *file_name;
+	Workbook   *wb;
+} GrepState;
+
+static void
+cb_check_strings (G_GNUC_UNUSED gpointer key, gpointer str,
+		  gpointer user_data)
+{
+	GrepState *state = user_data;
+	char *clean = g_utf8_strdown (key, -1);
+	char const *target = g_hash_table_lookup (state->targets, clean);
+
+	if (NULL != target) {
+		if (!state->found) {
+			g_print ("%s\n", state->file_name);
+			state->found = TRUE;
+		}
+		g_print ("\t%s : %d (string)\n", target, ((GnmString *)str)->ref_count);
+	}
+}
+
+static void
+cb_check_func (gpointer clean, gpointer orig,
+	       gpointer user_data)
+{
+	GrepState *state = user_data;
+	GnmFunc	  *func = gnm_func_lookup (clean, state->wb);
+	if (NULL != func) {
+		if (!state->found) {
+			g_print ("%s\n", state->file_name);
+			state->found = TRUE;
+		}
+		g_print ("\t%s : %d (func)\n", (char const *)orig, func->ref_count);
+	}
+}
+
+static int
+ssgrep (char const *file_name, IOContext *ioc, GHashTable *targets)
+{
+	int res = 0;
+	char		*str;
+	WorkbookView	*wbv;
+	GrepState	 state;
+
+	str = go_shell_arg_to_uri (file_name);
+	wbv = wb_view_new_from_uri (str, NULL, ioc, NULL);
+	g_free (str);
+
+	if (wbv == NULL)
+		return 1;
+
+	state.wb	= wb_view_get_workbook (wbv);
+	state.targets	= targets;
+	state.file_name = file_name;
+	state.found	= FALSE;
+	gnm_string_foreach (&cb_check_strings, &state);
+	g_hash_table_foreach (targets, &cb_check_func, &state);
+
+	g_object_unref (state.wb);
+
+	return res;
+}
+
+static void
+add_target (GHashTable *targets, char const *target)
+{
+	char *orig = g_strstrip (g_strdup (target));
+	char *clean = g_utf8_strdown (orig, -1);
+	g_hash_table_insert (targets, clean, orig);
+}
+
+int
+main (int argc, char const **argv)
+{
+	ErrorInfo	*plugin_errs;
+	IOContext	*ioc;
+	GOCmdContext	*cc;
+	GOptionContext	*ocontext;
+	GError		*error = NULL;
+	GHashTable	*targets;
+	int		 i, res;
+
+	/* No code before here, we need to init threads */
+	argv = gnm_pre_parse_init (argc, argv);
+	gnm_init (FALSE);
+
+	ocontext = g_option_context_new (_("INFILE..."));
+	g_option_context_add_main_entries (ocontext, ssgrep_options, GETTEXT_PACKAGE);
+	g_option_context_add_group	  (ocontext, gnm_get_option_group ());
+	g_option_context_parse (ocontext, &argc, (gchar ***)&argv, &error);
+	g_option_context_free (ocontext);
+
+	if (error) {
+		g_printerr (_("%s\nRun '%s --help' to see a full list of available command line options.\n"),
+			    error->message, argv[0]);
+		g_error_free (error);
+		return 1;
+	}
+
+	if (ssgrep_show_version) {
+		g_printerr (_("version '%s'\ndatadir := '%s'\nlibdir := '%s'\n"),
+			    GNM_VERSION_FULL, gnm_sys_data_dir (), gnm_sys_lib_dir ());
+		return 0;
+	} 
+
+	targets = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
+	if (ssgrep_keyword_file) {
+		GsfInput     	 *input;
+		GsfInputTextline *textline;
+		GError       	 *err = NULL;
+		unsigned char	 *line;
+
+		if (NULL == (input = gsf_input_stdio_new (ssgrep_keyword_file, &err))) {
+			g_return_val_if_fail (err != NULL, 1);
+
+			g_printerr ("'%s' error: %s", ssgrep_keyword_file, err->message);
+			g_error_free (err);
+			return 1;
+		}
+
+		if (NULL == (textline = (GsfInputTextline *)gsf_input_textline_new (input))) {
+			g_printerr ("Unable to create a textline");	/* unexpected */
+			return 2;
+		}
+
+		while (NULL != (line = gsf_input_textline_ascii_gets (textline)))
+			add_target (targets, line);
+		g_object_unref (G_OBJECT (input));
+
+		i = 1;
+	} else if (argc > 2) {
+		add_target (targets, argv[1]);
+		i = 2;
+	} else {
+		g_hash_table_destroy (targets);
+		targets = NULL;
+	}
+
+	if (NULL == targets) {
+		g_printerr (_("Usage: %s [ keyword | -f keywordfile ] FILES...]\n"),
+			    g_get_prgname ());
+		return 1;
+	}
+
+	cc = cmd_context_stderr_new ();
+	gnm_plugins_init (GO_CMD_CONTEXT (cc));
+	go_plugin_db_activate_plugin_list (
+		go_plugins_get_available_plugins (), &plugin_errs);
+
+	ioc = gnumeric_io_context_new (cc);
+	gnm_io_context_set_num_files (ioc, argc - 1);
+
+	res = 0;
+	for (; i < argc; i++) {
+		char const *file_name = argv[i];
+		gnm_io_context_processing_file (ioc, file_name);
+		res |= ssgrep (file_name, ioc, targets);
+	}
+
+	g_hash_table_destroy (targets);
+
+	g_object_unref (ioc);
+
+	g_object_unref (cc);
+	gnm_shutdown ();
+	gnm_pre_parse_shutdown ();
+
+	return res;
+}

Modified: trunk/src/str.c
==============================================================================
--- trunk/src/str.c	(original)
+++ trunk/src/str.c	Fri May  2 14:29:33 2008
@@ -161,6 +161,12 @@
 }
 
 void
+gnm_string_foreach (GHFunc callback, gpointer data)
+{
+	g_hash_table_foreach (string_hash_table, callback, data);
+}
+
+void
 gnm_string_init (void)
 {
 	string_hash_table = g_hash_table_new (g_str_hash, g_str_equal);

Modified: trunk/src/str.h
==============================================================================
--- trunk/src/str.h	(original)
+++ trunk/src/str.h	Fri May  2 14:29:33 2008
@@ -14,6 +14,7 @@
 void gnm_string_init     (void);
 void gnm_string_shutdown (void);
 void gnm_string_dump     (void);
+void gnm_string_foreach	 (GHFunc callback, gpointer data);
 
 GnmString *gnm_string_get        (char const *s);
 GnmString *gnm_string_get_nocopy (char *s);

Modified: trunk/src/workbook-view.c
==============================================================================
--- trunk/src/workbook-view.c	(original)
+++ trunk/src/workbook-view.c	Fri May  2 14:29:33 2008
@@ -1272,7 +1272,9 @@
 	if (input != NULL) {
 		WorkbookView *res;
 
+#if 0
 		g_printerr ("Reading %s\n", uri);
+#endif
 		res = wb_view_new_from_input (input,
 					      optional_fmt, io_context,
 					      optional_enc);



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