diff --git a/Makefile.am b/Makefile.am index 165d3b7e44..2ecc616743 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,5 +1,5 @@ -SUBDIRS = macros debian doc intl lib src po rpm accounts +SUBDIRS = macros debian doc-tools doc intl lib src po rpm accounts docdir = ${GNC_DOC_INSTALL_DIR} diff --git a/build-help-index.pl b/build-help-index.pl deleted file mode 100755 index efd80d1747..0000000000 --- a/build-help-index.pl +++ /dev/null @@ -1,38 +0,0 @@ -#! /usr/bin/perl - -use DB_File; - -tie %contents, 'DB_File', $ARGV[0]; - -shift @ARGV; - -foreach my $file (@ARGV) { - my %filewords; - - open(HELPFILE, $file) or die "Bad help file $file specified.\n"; - my $size = (stat($file))[7]; - my $data; - read HELPFILE,$data,$size; - $data =~ s/<[^>]*>/ /gs; # get rid of HTML tags - $data =~ tr/\",();&<>!$*/ /; # get rid of extra punct - $data =~ tr/[A-Z]/[a-z]/; # lowercase everything - $data =~ tr/ \012\011/ /s; # crunch whitespace - $data =~ s/[\.,\'\":\;\+|-]+ / /gs; # get rid of terminal punct - $data =~ s/ [.,\'\":;+|-]+/ /gs; # get rid of initial punct - $data =~ s/ [^ ] / /gs; # remove 1-letter words - $data =~ s/ [^ ][^ ] / /gs; # remove 2-letter words - $data =~ tr/ \012\011/ /s; # crunch whitespace again - my @words = split(' ', $data); - @words = sort(@words); - foreach my $w (@words) { - $filewords{$w} = ' '; - } - foreach my $w (keys(%filewords)) { - my $flist = $contents{$w}; - $contents{$w} = "$flist$file\012"; - } -} - -untie %contents; - - diff --git a/configure.in b/configure.in index d89b363a26..4ac9f8c7ed 100644 --- a/configure.in +++ b/configure.in @@ -398,6 +398,7 @@ AC_OUTPUT( doc/sgml/Makefile doc/sgml/C/Makefile doc/sgml/C/image/Makefile + doc-tools/Makefile intl/Makefile lib/Makefile macros/Makefile diff --git a/doc-tools/.cvsignore b/doc-tools/.cvsignore new file mode 100644 index 0000000000..164f765282 --- /dev/null +++ b/doc-tools/.cvsignore @@ -0,0 +1,4 @@ +Makefile +Makefile.in +build-help-index +dbadd diff --git a/doc-tools/Makefile.am b/doc-tools/Makefile.am new file mode 100644 index 0000000000..c68c1e1b2c --- /dev/null +++ b/doc-tools/Makefile.am @@ -0,0 +1,27 @@ + +noinst_PROGRAMS = dbadd + +LDADD = \ + ${DB_LIBS} + +dbadd_SOURCES = \ + dbadd.c + +EXTRA_DIST = \ + .cvsignore \ + build-help-index.in + +noinst_DATA = build-help-index + +## We borrow guile's convention and use @-...-@ as the substitution +## brackets here, instead of the usual @...@. This prevents autoconf +## from substituting the values directly into the left-hand sides of +## the sed substitutions. +build-help-index: build-help-index.in + rm -f $@.tmp + sed < $@.in > $@.tmp \ + -e 's:@-PERL-@:${PERL}:g' + chmod +x $@.tmp + mv $@.tmp $@ + +CLEANFILES += build-help-index diff --git a/doc-tools/build-help-index.in b/doc-tools/build-help-index.in new file mode 100644 index 0000000000..f941237fe3 --- /dev/null +++ b/doc-tools/build-help-index.in @@ -0,0 +1,62 @@ +#!@-PERL-@ -w +# -*- perl -*- + +use strict; + +my %contents; + +my $dbadd = $ARGV[0]; +shift @ARGV; + +my $db_file = $ARGV[0]; +shift @ARGV; + +foreach my $file (@ARGV) { + my %filewords; + + open (HELPFILE, $file) or die "Bad help file $file specified.\n"; + + my $size = (stat($file))[7]; + my $data; + + read HELPFILE, $data, $size; + + $data =~ s/<[^>]*>/ /gs; # get rid of HTML tags + $data =~ tr/\",();&<>!$*/ /; # get rid of extra punct + $data =~ tr/[A-Z]/[a-z]/; # lowercase everything + $data =~ tr/ \012\011/ /s; # crunch whitespace + $data =~ s/[\.,\'\":\;\+|-]+ / /gs; # get rid of terminal punct + $data =~ s/ [.,\'\":;+|-]+/ /gs; # get rid of initial punct + $data =~ s/ [^ ] / /gs; # remove 1-letter words + $data =~ s/ [^ ][^ ] / /gs; # remove 2-letter words + $data =~ tr/ \012\011/ /s; # crunch whitespace again + + my @words = split (' ', $data); + @words = sort (@words); + + foreach my $w (@words) { + $filewords{$w} = ' '; + } + + foreach my $w (keys(%filewords)) { + my $flist = $contents{$w}; + $flist = "" unless $flist; + $contents{$w} = "$flist$file\012"; + } +} + +my @keys = keys (%contents); +my @prefix; + +# we don't store all the keys at once in case there +# are limits on the size of argv. But do more than +# one at a time for efficiency. +while (@prefix = splice (@keys, 0, 32)) { + my @args = (); + + foreach my $w (@prefix) { + unshift (@args, $w, $contents{$w}); + } + + system ($dbadd, $db_file, @args); +} diff --git a/doc-tools/dbadd.c b/doc-tools/dbadd.c new file mode 100644 index 0000000000..02c3f96961 --- /dev/null +++ b/doc-tools/dbadd.c @@ -0,0 +1,116 @@ +/********************************************************************\ + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation; either version 2 of * + * the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License* + * along with this program; if not, contact: * + * * + * Free Software Foundation Voice: +1-617-542-5942 * + * 59 Temple Place - Suite 330 Fax: +1-617-542-2652 * + * Boston, MA 02111-1307, USA gnu@gnu.org * + * * +\********************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include + +/* needed for db.h with 'gcc -ansi -pedantic' */ +#ifndef _BSD_SOURCE +# define _BSD_SOURCE 1 +#endif + +#ifdef PREFER_DB1 +#ifdef HAVE_DB1_DB_H +# include +#else +# ifdef HAVE_DB_185_H +# include +# else +# include +# endif +#endif +#else +#ifdef HAVE_DB_185_H +# include +#else +# ifdef HAVE_DB_H +# include +# else +# include +# endif +#endif +#endif + + +#define ZERO(Dbt) memset (&(Dbt), sizeof (DBT), 0) + +static DB *database; + + +static void +usage (const char *name) +{ + fprintf (stderr, "Usage: %s database key1 value1 key2 value2 ...\n", name); + exit(1); +} + +int +main (int argc, char *argv[]) +{ + const char *db_name; + int i; + + if (argc < 2) + usage (argv[0]); + + if (argc % 2 != 0) + usage (argv[0]); + + db_name = argv[1]; + + database = dbopen (db_name, O_CREAT | O_RDWR, 0644, DB_HASH, NULL); + if (!database) + { + fprintf (stderr, "Error opening database %s: %s\n", + db_name, strerror (errno)); + exit (1); + } + + for (i = 2; i < argc; i += 2) + { + DBT key; + DBT value; + + ZERO (key); + ZERO (value); + + key.data = argv[i]; + key.size = strlen (key.data); + + value.data = argv[i + 1]; + value.size = strlen (value.data); + + if (database->put (database, &key, &value, 0)) + { + fprintf (stderr, "Error writing data.\n"); + exit (1); + } + } + + database->close (database); + + return 0; +} diff --git a/doc/sgml/C/Makefile.am b/doc/sgml/C/Makefile.am index b166ec3a3a..e88cfcd1ae 100644 --- a/doc/sgml/C/Makefile.am +++ b/doc/sgml/C/Makefile.am @@ -113,8 +113,10 @@ gnucash/index.html: $(GNUCASH_SGML_FILES) $(GNUCASH_HTML_FILES) && cp $(srcdir)/image/*.png gnucash/image || exit 1) gnucash/help-search-index.db: $(GNUCASH_SGML_FILES) $(GNUCASH_HTML_FILES) - -(chmod a+x $(top_srcdir)/build-help-index.pl && cd gnucash \ - && ../$(top_srcdir)/build-help-index.pl help-search-index.db *.html) + -(cd gnucash && \ + rm -f help-search-index.db && \ + ../$(top_srcdir)/doc-tools/build-help-index \ + ../$(top_srcdir)/doc-tools/dbadd help-search-index.db *.html) dist-hook: mkdir $(distdir)/gnucash