summaryrefslogtreecommitdiffstats
path: root/contrib/texinfo/util
diff options
context:
space:
mode:
authorru <ru@FreeBSD.org>2003-05-02 00:48:41 +0000
committerru <ru@FreeBSD.org>2003-05-02 00:48:41 +0000
commit97e8efa8f6d09766ed24f0d06f8c3321ba2c5e60 (patch)
treef8415845d58f365cb4e107a243356bf07108edd7 /contrib/texinfo/util
parenta954908b3534f6488e4e563f6d2912c3df9d750e (diff)
parent374ada20ea75e5e2d1945e7896180bea1f752477 (diff)
downloadFreeBSD-src-97e8efa8f6d09766ed24f0d06f8c3321ba2c5e60.zip
FreeBSD-src-97e8efa8f6d09766ed24f0d06f8c3321ba2c5e60.tar.gz
This commit was generated by cvs2svn to compensate for changes in r114472,
which included commits to RCS files with non-trunk default branches.
Diffstat (limited to 'contrib/texinfo/util')
-rw-r--r--contrib/texinfo/util/README14
-rw-r--r--contrib/texinfo/util/texindex.c82
2 files changed, 69 insertions, 27 deletions
diff --git a/contrib/texinfo/util/README b/contrib/texinfo/util/README
index 20d7bda..d3f8a75 100644
--- a/contrib/texinfo/util/README
+++ b/contrib/texinfo/util/README
@@ -1,10 +1,14 @@
+$Id: README,v 1.4 2002/12/29 17:47:20 karl Exp $
+texinfo/util/README
+
+ Copyright (C) 2002 Free Software Foundation, Inc.
+
+ Copying and distribution of this file, with or without modification,
+ are permitted in any medium without royalty provided the copyright
+ notice and this notice are preserved.
+
Assorted Texinfo-related programs and scripts.
texindex, texi2dvi, and install-info get installed.
The other items here are for your amusement and/or hacking pleasure.
-You may also be interested in a2ps, an ASCII->PostScript program which
-has a Texinfo style option. Available from
-http://www.inf.enst.fr/~demaille/a2ps/ and
-ftp://ftp.enst.fr/pub/unix/a2ps/.
-
diff --git a/contrib/texinfo/util/texindex.c b/contrib/texinfo/util/texindex.c
index 7f8ff59..c7dc64b 100644
--- a/contrib/texinfo/util/texindex.c
+++ b/contrib/texinfo/util/texindex.c
@@ -1,8 +1,8 @@
-/* Process TeX index dribble output into an actual index.
- $Id: texindex.c,v 1.41 2002/03/11 19:55:46 karl Exp $
+/* texindex -- sort TeX index dribble output into an actual index.
+ $Id: texindex.c,v 1.7 2003/01/19 18:47:15 karl Exp $
- Copyright (C) 1987, 91, 92, 96, 97, 98, 99, 2000, 01, 02
- Free Software Foundation, Inc.
+ Copyright (C) 1987, 1991, 1992, 1996, 1997, 1998, 1999, 2000, 2001,
+ 2002, 2003 Free Software Foundation, Inc.
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
@@ -97,9 +97,6 @@ long nlines;
/* Directory to use for temporary files. On Unix, it ends with a slash. */
char *tempdir;
-/* Start of filename to use for temporary files. */
-char *tempbase;
-
/* Number of last temporary file. */
int tempcount;
@@ -111,6 +108,13 @@ int last_deleted_tempcount;
which contains all the lines of data. */
char *text_base;
+/* Initially 0; changed to 1 if we want initials in this index. */
+int need_initials;
+
+/* Remembers the first initial letter seen in this index, so we can
+ determine whether we need initials in the sorted form. */
+char first_initial;
+
/* Additional command switches .*/
/* Nonzero means do not delete tempfiles -- for debugging. */
@@ -160,6 +164,9 @@ main (argc, argv)
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
+ /* In case we write to a redirected stdout that fails. */
+ /* not ready atexit (close_stdout); */
+
/* Describe the kind of sorting to do. */
/* The first keyfield uses the first braced field and folds case. */
keyfields[0].braced = 1;
@@ -181,8 +188,6 @@ main (argc, argv)
decode_command (argc, argv);
- tempbase = mktemp (concat ("txiXXXXXX", "", ""));
-
/* Process input files completely, one by one. */
for (i = 0; i < num_infiles; i++)
@@ -217,9 +222,12 @@ main (argc, argv)
outfile = concat (infiles[i], "s", "");
}
+ need_initials = 0;
+ first_initial = '\0';
+
if (ptr < MAX_IN_CORE_SORT)
/* Sort a small amount of data. */
- sort_in_core (infiles[i], ptr, outfile);
+ sort_in_core (infiles[i], (int)ptr, outfile);
else
sort_offline (infiles[i], ptr, outfile);
}
@@ -339,7 +347,7 @@ decode_command (argc, argv)
There is NO warranty. You may redistribute this software\n\
under the terms of the GNU General Public License.\n\
For more information about these matters, see the files named COPYING.\n"),
- "2002");
+ "2003");
xexit (0);
}
else if ((strcmp (arg, "--keep") == 0) ||
@@ -381,17 +389,33 @@ For more information about these matters, see the files named COPYING.\n"),
usage (1);
}
-/* Return a name for a temporary file. */
+/* Return a name for temporary file COUNT. */
static char *
maketempname (count)
int count;
{
+ static char *tempbase = NULL;
char tempsuffix[10];
+
+ if (!tempbase)
+ {
+ int fd;
+ char *tmpdir = getenv ("TEMPDIR");
+ if (!tmpdir)
+ tmpdir = "/tmp";
+ tempbase = concat (tmpdir, "/txidxXXXXXX");
+
+ fd = mkstemp (tempbase);
+ if (fd == -1)
+ pfatal_with_name (tempbase);
+ }
+
sprintf (tempsuffix, ".%d", count);
return concat (tempdir, tempbase, tempsuffix);
}
+
/* Delete all temporary files up to TO_COUNT. */
void
@@ -861,9 +885,8 @@ readline (linebuffer, stream)
/* Sort an input file too big to sort in core. */
void
-sort_offline (infile, nfiles, total, outfile)
+sort_offline (infile, total, outfile)
char *infile;
- int nfiles;
off_t total;
char *outfile;
{
@@ -942,7 +965,7 @@ fail:
for (i = 0; i < ntemps; i++)
{
char *newtemp = maketempname (++tempcount);
- sort_in_core (&tempfiles[i], MAX_IN_CORE_SORT, newtemp);
+ sort_in_core (tempfiles[i], MAX_IN_CORE_SORT, newtemp);
if (!keep_tempfiles)
unlink (tempfiles[i]);
tempfiles[i] = newtemp;
@@ -963,7 +986,7 @@ fail:
void
sort_in_core (infile, total, outfile)
char *infile;
- off_t total;
+ int total;
char *outfile;
{
char **nextline;
@@ -1101,6 +1124,23 @@ parsefile (filename, nextline, data, size)
return 0;
*line = p;
+
+ /* Find the first letter of the first field of this line. If it
+ is different from the first letter of the first field of the
+ first line, we need initial headers in the output index. */
+ while (*p && *p != '{')
+ p++;
+ if (p == end)
+ return 0;
+ p++;
+ if (first_initial)
+ {
+ if (first_initial != toupper (*p))
+ need_initials = 1;
+ }
+ else
+ first_initial = toupper (*p);
+
while (*p && *p != '\n')
p++;
if (p != end)
@@ -1210,12 +1250,9 @@ indexify (line, ostream)
else
{
initial = initial1;
- initial1[0] = *p;
+ initial1[0] = toupper (*p);
initial1[1] = 0;
initiallength = 1;
-
- if (initial1[0] >= 'a' && initial1[0] <= 'z')
- initial1[0] -= 040;
}
pagenumber = find_braced_pos (line, 1, 0, 0);
@@ -1243,8 +1280,9 @@ indexify (line, ostream)
/* If this primary has a different initial, include an entry for
the initial. */
- if (initiallength != lastinitiallength ||
- strncmp (initial, lastinitial, initiallength))
+ if (need_initials &&
+ (initiallength != lastinitiallength ||
+ strncmp (initial, lastinitial, initiallength)))
{
fprintf (ostream, "\\initial {");
fwrite (initial, 1, initiallength, ostream);
OpenPOWER on IntegriCloud