diff options
Diffstat (limited to 'gnu/usr.bin/texinfo/util')
-rw-r--r-- | gnu/usr.bin/texinfo/util/Makefile.am | 2 | ||||
-rw-r--r-- | gnu/usr.bin/texinfo/util/gen-dir-node | 18 | ||||
-rw-r--r-- | gnu/usr.bin/texinfo/util/install-info.c | 92 | ||||
-rw-r--r-- | gnu/usr.bin/texinfo/util/texi2dvi | 467 | ||||
-rw-r--r-- | gnu/usr.bin/texinfo/util/texindex.c | 726 |
5 files changed, 710 insertions, 595 deletions
diff --git a/gnu/usr.bin/texinfo/util/Makefile.am b/gnu/usr.bin/texinfo/util/Makefile.am index 4326f08c0d4..c4e691329bb 100644 --- a/gnu/usr.bin/texinfo/util/Makefile.am +++ b/gnu/usr.bin/texinfo/util/Makefile.am @@ -1,5 +1,5 @@ ## Makefile.am for texinfo/util. -## $Id: Makefile.am,v 1.1 1997/08/01 22:01:03 kstailey Exp $ +## $Id: Makefile.am,v 1.2 1999/01/11 16:38:15 espie Exp $ ## Run automake in .. to produce Makefile.in from this. bin_PROGRAMS = install-info texindex diff --git a/gnu/usr.bin/texinfo/util/gen-dir-node b/gnu/usr.bin/texinfo/util/gen-dir-node index 09574f83a00..9d7c92b9bed 100644 --- a/gnu/usr.bin/texinfo/util/gen-dir-node +++ b/gnu/usr.bin/texinfo/util/gen-dir-node @@ -1,8 +1,8 @@ #!/bin/sh - +# $Id: gen-dir-node,v 1.2 1999/01/11 16:38:15 espie Exp $ # Generate the top-level Info node, given a directory of Info files # and (optionally) a skeleton file. The output will be suitable for a -# dir.info file. The skeleton file contains info topic names in the +# top-level dir file. The skeleton file contains info topic names in the # order they should appear in the output. There are three special # lines that alter the behavior: a line consisting of just "--" causes # the next line to be echoed verbatim to the output. A line @@ -42,9 +42,9 @@ if [ ! -d ${INFODIR} ] ; then exit 1 fi -### output the dir.info header +### output the dir header echo "-*- Text -*-" -echo "This file was generated automatically by the gen-dir-node script." +echo "This file was generated automatically by $0." echo "This version was generated on `date`" echo "by `whoami`@`hostname` for `(cd ${INFODIR}; pwd)`" @@ -164,9 +164,14 @@ else fi for file in ${infofiles}; do + case $file in + *.gz) zcat=zcat; file=`echo $file|sed 's/\.gz$//'`; gz=.gz;; + *) zcat=cat; gz=;; + esac infoname=`echo $file | sed 's/\.info$//'` - entry=`sed -e '1,/START-INFO-DIR-ENTRY/d' \ - -e '/END-INFO-DIR-ENTRY/,$d' ${INFODIR}/${file}` + entry=`$zcat ${INFODIR}/${file}$gz \ + |sed -e '1,/START-INFO-DIR-ENTRY/d' \ + -e '/END-INFO-DIR-ENTRY/,$d'` if [ ! -z "${entry}" ] ; then echo "${entry}" @@ -174,4 +179,3 @@ for file in ${infofiles}; do echo "* ${infoname}: (${file})." fi done - diff --git a/gnu/usr.bin/texinfo/util/install-info.c b/gnu/usr.bin/texinfo/util/install-info.c index 1ff309f0fa9..9106ee7c698 100644 --- a/gnu/usr.bin/texinfo/util/install-info.c +++ b/gnu/usr.bin/texinfo/util/install-info.c @@ -1,7 +1,7 @@ /* install-info -- create Info directory entry(ies) for an Info file. - $Id: install-info.c,v 1.4 1997/08/01 22:37:47 kstailey Exp $ + $Id: install-info.c,v 1.5 1999/01/11 16:38:15 espie Exp $ - Copyright (C) 1996, 97 Free Software Foundation, Inc. + Copyright (C) 1996, 97, 98 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 @@ -20,6 +20,10 @@ #include "system.h" #include <getopt.h> +#ifdef HAVE_LIBZ +#include <zlib.h> +#endif + /* Name this program was invoked with. */ char *progname; @@ -283,8 +287,9 @@ suggest_asking_for_help () void print_help () { - printf (_("%s [OPTION]... [INFO-FILE [DIR-FILE]]\n\ - Install INFO-FILE in the Info directory file DIR-FILE.\n\ + printf (_("Usage: %s [OPTION]... [INFO-FILE [DIR-FILE]]\n\ +\n\ +Install INFO-FILE in the Info directory file DIR-FILE.\n\ \n\ Options:\n\ --delete Delete existing entries in INFO-FILE;\n\ @@ -312,12 +317,14 @@ Options:\n\ from information in the Info file itself.\n\ --version Display version information and exit.\n\ \n\ -Email bug reports to bug-texinfo@prep.ai.mit.edu.\n\ +Email bug reports to bug-texinfo@gnu.org.\n\ "), progname); } + /* If DIRFILE does not exist, create a minimal one (or abort). If it already exists, do nothing. */ + void ensure_dirfile_exists (dirfile) char *dirfile; @@ -335,7 +342,7 @@ ensure_dirfile_exists (dirfile) topmost node of the Info hierarchy, called (dir)Top.\n\ The first time you invoke Info you start off looking at this node.\n\ \n\ -File: dir Node: Top This is the top of the INFO tree\n\ +File: dir,\tNode: Top,\tThis is the top of the INFO tree\n\ \n\ This (the Directory node) gives a menu of major topics.\n\ Typing \"q\" exits, \"?\" lists all Info commands, \"d\" returns here,\n\ @@ -368,19 +375,20 @@ File: dir Node: Top This is the top of the INFO tree\n\ struct option longopts[] = { - { "delete", no_argument, NULL, 'r' }, - { "dir-file", required_argument, NULL, 'd' }, - { "entry", required_argument, NULL, 'e' }, - { "help", no_argument, NULL, 'h' }, - { "info-dir", required_argument, NULL, 'D' }, - { "info-file", required_argument, NULL, 'i' }, - { "item", required_argument, NULL, 'e' }, - { "quiet", no_argument, NULL, 'q' }, - { "remove", no_argument, NULL, 'r' }, - { "section", required_argument, NULL, 's' }, - { "version", no_argument, NULL, 'V' }, + { "delete", no_argument, NULL, 'r' }, + { "dir-file", required_argument, NULL, 'd' }, + { "entry", required_argument, NULL, 'e' }, + { "help", no_argument, NULL, 'h' }, + { "info-dir", required_argument, NULL, 'D' }, + { "info-file", required_argument, NULL, 'i' }, + { "item", required_argument, NULL, 'e' }, + { "quiet", no_argument, NULL, 'q' }, + { "remove", no_argument, NULL, 'r' }, + { "section", required_argument, NULL, 's' }, + { "version", no_argument, NULL, 'V' }, { 0 } }; + int main (argc, argv) @@ -518,11 +526,12 @@ main (argc, argv) break; case 'V': - printf (_("install-info (GNU %s) %s\n"), PACKAGE, VERSION); -puts (_("Copyright (C) 1996 Free Software Foundation, Inc.\n\ + printf ("install-info (GNU %s) %s\n", PACKAGE, VERSION); + printf (_("Copyright (C) %s Free Software Foundation, Inc.\n\ 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.")); +For more information about these matters, see the files named COPYING.\n"), + "1998"); exit (0); default: @@ -955,18 +964,49 @@ readfile (filename, sizep) char *filename; int *sizep; { + int desc; int data_size = 1024; char *data = (char *) xmalloc (data_size); int filled = 0; int nread = 0; +#ifdef HAVE_LIBZ + int isGZ = 0; + gzFile zdesc; +#endif - int desc = open (filename, O_RDONLY); + desc = open (filename, O_RDONLY); if (desc < 0) pfatal_with_name (filename); +#ifdef HAVE_LIBZ + /* The file should always be two bytes long. */ + if (read (desc, data, 2) != 2) + pfatal_with_name (filename); + + /* Undo that read. */ + lseek (desc, 0, SEEK_SET); + + /* If we see gzip magic, use gzdopen. */ + if (data[0] == '\x1f' && data[1] == '\x8b') + { + isGZ = 1; + zdesc = gzdopen (desc, "r"); + if (zdesc == NULL) { + close (desc); + pfatal_with_name (filename); + } + } +#endif /* HAVE_LIBZ */ + while (1) { - nread = read (desc, data + filled, data_size - filled); +#ifdef HAVE_LIBZ + if (isGZ) + nread = gzread (zdesc, data + filled, data_size - filled); + else +#endif + nread = read (desc, data + filled, data_size - filled); + if (nread < 0) pfatal_with_name (filename); if (nread == 0) @@ -981,6 +1021,14 @@ readfile (filename, sizep) } *sizep = filled; + +#ifdef HAVE_LIBZ + if (isGZ) + gzclose (zdesc); + else +#endif + close(desc); + return data; } diff --git a/gnu/usr.bin/texinfo/util/texi2dvi b/gnu/usr.bin/texinfo/util/texi2dvi index 480967cfebf..6f196887fdf 100644 --- a/gnu/usr.bin/texinfo/util/texi2dvi +++ b/gnu/usr.bin/texinfo/util/texi2dvi @@ -1,10 +1,9 @@ #! /bin/sh # texi2dvi --- smartly produce DVI files from texinfo sources - -# Copyright (C) 1992, 1993, 1994, 1995 Free Software Foundation, Inc. - -# $Id: texi2dvi,v 1.1 1995/12/22 16:47:17 niklas Exp $ - +# $Id: texi2dvi,v 1.2 1999/01/11 16:38:15 espie Exp $ +# +# Copyright (C) 1992, 93, 94, 95, 96, 97, 98 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 # the Free Software Foundation; either version 2, or (at your option) @@ -19,65 +18,73 @@ # along with this program; if not, you can either send email to this # program's maintainer or write to: The Free Software Foundation, # Inc.; 59 Temple Place, Suite 330; Boston, MA 02111-1307, USA. - +# # Commentary: - -# Author: Noah Friedman <friedman@prep.ai.mit.edu> - -# Please send bug reports, etc. to bug-texinfo@prep.ai.mit.edu +# +# Author: Noah Friedman <friedman@gnu.org> +# +# Please send bug reports, etc. to bug-texinfo@gnu.org. # If possible, please send a copy of the output of the script called with # the `--debug' option when making a bug report. - +# # In the interest of general portability, some common bourne shell # constructs were avoided because they weren't guaranteed to be available # in some earlier implementations. I've tried to make this program as # portable as possible. Welcome to unix, where the lowest common # denominator is rapidly diminishing. # -# Among the more interesting lossages I noticed with some bourne shells -# are: +# Among the more interesting lossages I noticed among Bourne shells: # * No shell functions. # * No `unset' builtin. # * `shift' cannot take a numeric argument, and signals an error if # there are no arguments to shift. - +# # Code: # Name by which this script was invoked. progname=`echo "$0" | sed -e 's/[^\/]*\///g'` # This string is expanded by rcs automatically when this file is checked out. -rcs_revision='$Revision: 1.1 $' +rcs_revision='$Revision: 1.2 $' version=`set - $rcs_revision; echo $2` # To prevent hairy quoting and escaping later. bq='`' eq="'" -usage="Usage: $progname {options} [file1] {file2 {...}} -(version $version) +usage="Usage: $0 [OPTION]... FILE... +Run a Texinfo document through TeX. -Options are: +Options: +-b, --batch No interaction (\nonstopmode in TeX). +-c, --clean Remove all auxiliary files. -D, --debug Turn on shell debugging ($bq${bq}set -x$eq$eq). --h, --help You're looking at it. --v, --version Print version number. +-t, --texinfo CMD Insert CMD after @setfilename before running TeX. +--verbose Report on what is done. +-h, --help Display this help and exit. +-v, --version Display version information and exit. -Arguments in brackets are required. Those in braces are optional. -" +The values of the TEX, TEXINDEX, and MAKEINFO environment variables are +used to run those commands, if they are set. + +Email bug reports to bug-texinfo@gnu.org." # Initialize variables. # Don't use `unset' since old bourne shells don't have this command. # Instead, assign them an empty value. -# Some of these, like TEX and TEXINDEX, may be inherited from the environment -backup_extension=.bak +# Some of these, like TEX and TEXINDEX, may be inherited from the environment. +backup_extension=.bak # these files get deleted if all goes well. +batch= +clean= debug= orig_pwd="`pwd`" -verbose= +textra= +verbose=false +makeinfo="${MAKEINFO-makeinfo}" texindex="${TEXINDEX-texindex}" tex="${TEX-tex}" -# Save this so we can construct a new TEXINPUTS path for each file to be -# processed. +# Save this so we can construct a new TEXINPUTS path for each file. TEXINPUTS_orig="$TEXINPUTS" export TEXINPUTS @@ -86,190 +93,270 @@ export TEXINPUTS # It's a good idea to document the full long option name in each case. # Long options which take arguments will need a `*' appended to the # canonical name to match the value appended after the `=' character. -while : ; do - case $# in 0) break ;; esac +while :; do + test $# -eq 0 && break + case "$1" in - -D | --debug | --d* ) - debug=t - shift - ;; - -h | --help | --h* ) - echo "$usage" 1>&2 - exit 0 - ;; - -v | --version | --v* ) - echo "texi2dvi version $version" 1>&2 - exit 0 - ;; + -b | --batch | --b* ) batch=t; shift ;; + -c | --clean | --c* ) clean=t; shift ;; + -D | --debug | --d* ) debug=t; shift ;; + -h | --help | --h* ) echo "$usage"; exit 0 ;; + # OK, we should do real option parsing here, but be lazy for now. + -t | --texinfo | --t*) shift; textra="$textra $1"; shift ;; + -v | --vers* ) + echo "$progname (GNU Texinfo 3.12) $version" + echo "Copyright (C) 1998 Free Software Foundation, Inc. +There is NO warranty. You may redistribute this software +under the terms of the GNU General Public License. +For more information about these matters, see the files named COPYING." + exit 0 ;; + --verb* ) verbose=echo; shift ;; -- ) # Stop option processing shift - break - ;; + break ;; -* ) case "$1" in --*=* ) arg=`echo "$1" | sed -e 's/=.*//'` ;; * ) arg="$1" ;; esac exec 1>&2 - echo "$progname: unknown or ambiguous option $bq$arg$eq" - echo "$progname: Use $bq--help$eq for a list of options." - exit 1 - ;; - * ) - break - ;; + echo "$progname: Unknown or ambiguous option $bq$arg$eq." + echo "$progname: Try $bq--help$eq for more information." + exit 1 ;; + * ) break ;; esac done # See if there are any command line args left (which will be interpreted as -# filename arguments) -case $# in - 0 ) - exec 1>&2 - echo "$progname: at least one file name is required as an argument." - echo "$progname: Use $bq--help$eq for a description of command syntax." - exit 2 - ;; -esac - -case "$debug" in t ) set -x ;; esac +# filename arguments). +if test $# -eq 0; then + exec 1>&2 + echo "$progname: At least one file name is required as an argument." + echo "$progname: Try $bq--help$eq for more information." + exit 2 +fi + +test "$debug" = t && set -x # Texify files -for command_line_filename in ${1+"$@"} ; do - # Roughly equivalent to `dirname ...`, but more portable - directory="`echo ${command_line_filename} | sed 's/\/[^\/]*$//'`" - filename_texi="`basename ${command_line_filename}`" - # Strip off the last extension part (probably .texinfo or .texi) - filename_noext="`echo ${filename_texi} | sed 's/\.[^.]*$//'`" - - # If directory and file are the same, then it's probably because there's - # no pathname component. Set dirname to `.', the current directory. - if test "z${directory}" = "z${command_line_filename}" ; then - directory="." - fi - - # Source file might @include additional texinfo sources. Put `.' and - # directory where source file(s) reside in TEXINPUTS before anything - # else. `.' goes first to ensure that any old .aux, .cps, etc. files in - # ${directory} don't get used in preference to fresher files in `.'. - TEXINPUTS=".:${directory}:${TEXINPUTS_orig}" - - # "Unset" variables that might have values from previous iterations and - # which won't be completely reset later. - definite_index_files="" - - # See if file exists here. If it doesn't we're in trouble since, even - # though the user may be able to reenter a valid filename at the tex - # prompt (assuming they're attending the terminal), this script won't be - # able to find the right index files and so forth. - if test ! -r "${command_line_filename}" ; then - echo "${progname}: ${command_line_filename}: No such file or permission denied." 1>&2 - continue; - fi - - # Find all files having root filename with a two-letter extension, - # determine whether they're really index files, and save them. Foo.aux - # is actually the cross-references file, but we need to keep track of - # that too. - possible_index_files="`eval echo ${filename_noext}.?? ${filename_noext}.aux`" - for this_file in ${possible_index_files} ; do +for command_line_filename in ${1+"$@"}; do + $verbose "Processing $command_line_filename ..." + + # See if file exists. If it doesn't we're in trouble since, even + # though the user may be able to reenter a valid filename at the tex + # prompt (assuming they're attending the terminal), this script won't + # be able to find the right index files and so forth. + if test ! -r "${command_line_filename}"; then + echo "$0: Could not read ${command_line_filename}." >&2 + continue + fi + + # Roughly equivalent to `dirname ...`, but more portable + directory="`echo ${command_line_filename} | sed 's/\/[^\/]*$//'`" + filename_texi="`basename ${command_line_filename}`" + # Strip off the last extension part (probably .texinfo or .texi) + filename_noext="`echo ${filename_texi} | sed 's/\.[^.]*$//'`" + + # Use same basename since we want to generate aux files with the same + # basename as the manual. Use extension .texi for the temp file so + # that TeX will ignore it. Thus, we must use a subdirectory. + # + # Output the macro-expanded file to here. The vastly abbreviated + # temporary directory name is so we don't have collisions on 8.3 or + # 14-character filesystems. + tmp_dir=${TMPDIR-/tmp}/txi2d.$$ + filename_tmp=$tmp_dir/$filename_noext.texi + # Output the file with the user's extra commands to here. + tmp_dir2=${tmp_dir}.2 + filename_tmp2=$tmp_dir2/$filename_noext.texi + mkdir $tmp_dir $tmp_dir2 + # Always remove the temporary directories. + trap "rm -rf $tmp_dir $tmp_dir2" 1 2 15 + + # If directory and file are the same, then it's probably because there's + # no pathname component. Set dirname to `.', the current directory. + if test "z${directory}" = "z${command_line_filename}"; then + directory=. + fi + + # Source file might @include additional texinfo sources. Put `.' and + # directory where source file(s) reside in TEXINPUTS before anything + # else. `.' goes first to ensure that any old .aux, .cps, etc. files in + # ${directory} don't get used in preference to fresher files in `.'. + TEXINPUTS=".:${directory}:${TEXINPUTS_orig}" + + # Expand macro commands in the original source file using Makeinfo; + # the macro syntax bfox implemented is impossible to implement in TeX. + # Always use `end' footnote style, since the `separate' style + # generates different output (arguably this is a bug in -E). + # Discard main info output, the user asked to run TeX, not makeinfo. + # Redirect output to /dev/null to throw away `Making info file...' msg. + $verbose "Macro-expanding $command_line_filename to $filename_tmp ..." + $makeinfo --footnote-style=end -E $filename_tmp -o /dev/null \ + $command_line_filename >/dev/null + + # But if there were no macros, or makeinfo failed for some reason, + # just use the original file. (It shouldn't make any difference, but + # let's be safe.) + if test $? -ne 0 || cmp -s $filename_tmp $command_line_filename; then + $verbose "Reverting to $command_line_filename ..." + cp -p $command_line_filename $filename_tmp + fi + filename_input=$filename_tmp + dirname_input=$tmp_dir + + # Used most commonly for @finalout, @smallbook, etc. + if test -n "$textra"; then + $verbose "Inserting extra commands: $textra." + sed '/^@setfilename/a\ +'"$textra" $filename_input >$filename_tmp2 + filename_input=$filename_tmp2 + dirname_input=$tmp_dir2 + fi + + # If clean mode was specified, then move to the temporary directory. + if test "$clean" = t; then + $verbose "cd $dirname_input" + cd $dirname_input || exit 1 + filename_input=`basename $filename_input` + fi + + while true; do # will break out of loop below + # "Unset" variables that might have values from previous iterations and + # which won't be completely reset later. + definite_index_files= + + # Find all files having root filename with a two-letter extension, + # determine whether they're really index files, and save them. Foo.aux + # is actually the cross-references file, but we need to keep track of + # that too. + possible_index_files="`eval echo ${filename_noext}.?? ${filename_noext}.aux`" + for this_file in ${possible_index_files}; do # If file is empty, forget it. - if test ! -s "${this_file}" ; then - continue; - fi + test -s "${this_file}" || continue - # Examine first character of file. If it's not a backslash or - # single quote, then it's definitely not an index or xref file. + # Examine first character of file. If it's not suitable to be an + # index or xref file, don't process it. first_character="`sed -n '1s/^\(.\).*$/\1/p;q' ${this_file}`" - if test "${first_character}" = "\\" -o "${first_character}" = "'" ; then - definite_index_files="${definite_index_files} ${this_file}" + if test "x${first_character}" = "x\\" \ + || test "x${first_character}" = "x'"; then + definite_index_files="${definite_index_files} ${this_file}" fi - done - orig_index_files="${definite_index_files}" - orig_index_files_sans_aux="`echo ${definite_index_files} \ - | sed 's/'${filename_noext}'\.aux//; - s/^[ ]*//;s/[ ]*$//;'`" - - # Now save copies of original index files so we have some means of - # comparison later. - for index_file_to_save in ${orig_index_files} ; do - cp "${index_file_to_save}" "${index_file_to_save}${backup_extension}" - done - - # Run texindex on current index files. If they already exist, and - # after running TeX a first time the index files don't change, then - # there's no reason to run TeX again. But we won't know that if the - # index files are out of date or nonexistent. - if test "${orig_index_files_sans_aux}" ; then + done + orig_index_files="${definite_index_files}" + orig_index_files_sans_aux="`echo ${definite_index_files} \ + | sed 's/'${filename_noext}'\.aux//; + s/^[ ]*//;s/[ ]*$//;'`" + + # Now save copies of original index files so we have some means of + # comparison later. + $verbose "Backing up current index files: $orig_index_files ..." + for index_file_to_save in ${orig_index_files}; do + cp "${index_file_to_save}" "${index_file_to_save}${backup_extension}" + done + + # Run texindex on current index files. If they already exist, and + # after running TeX a first time the index files don't change, then + # there's no reason to run TeX again. But we won't know that if the + # index files are out of date or nonexistent. + if test -n "${orig_index_files_sans_aux}"; then + $verbose "Running $texindex $orig_index_files_sans_aux ..." ${texindex} ${orig_index_files_sans_aux} - fi - - if ${tex} ${command_line_filename} ; then # TeX run first time - definite_index_files="" - # Get list of new index files - possible_index_files="`eval echo ${filename_noext}.?? ${filename_noext}.aux`" - for this_file in ${possible_index_files} ; do - # If file is empty, forget it. - if test ! -s ${this_file} ; then - continue; - fi - - # Examine first character of file. If it's not a backslash or - # single quote, then it's definitely not an index or xref file. - first_character="`sed -n '1s/^\(.\).*$/\1/p;q' ${this_file}`" - if test "${first_character}" = "\\" -o "${first_character}" = "'" ; then - definite_index_files="${definite_index_files} ${this_file}" - fi + fi + + # Finally, run TeX. + if test "$batch" = t; then + tex_mode='\nonstopmode' + else + tex_mode= + fi + $verbose "Running $tex $filename_input ..." + cmd="$tex $tex_mode \\input $filename_input" + $cmd + + # Check if index files changed. + # + definite_index_files= + # Get list of new index files. + possible_index_files="`eval echo ${filename_noext}.?? ${filename_noext}.aux`" + for this_file in ${possible_index_files}; do + # If file is empty, forget it. + test -s "${this_file}" || continue + + # Examine first character of file. If it's not a backslash or + # single quote, then it's definitely not an index or xref file. + # (Will have to check for @ when we switch to Texinfo syntax in + # all these files...) + first_character="`sed -n '1s/^\(.\).*$/\1/p;q' ${this_file}`" + if test "x${first_character}" = "x\\" \ + || test "x${first_character}" = "x'"; then + definite_index_files="${definite_index_files} ${this_file}" + fi + done + new_index_files="${definite_index_files}" + new_index_files_sans_aux="`echo ${definite_index_files} \ + | sed 's/'${filename_noext}'\.aux//; + s/^[ ]*//;s/[ ]*$//;'`" + + # If old and new list don't at least have the same file list, then one + # file or another has definitely changed. + $verbose "Original index files =$orig_index_files" + $verbose "New index files =$new_index_files" + if test "z${orig_index_files}" != "z${new_index_files}"; then + index_files_changed_p=t + else + # File list is the same. We must compare each file until we find a + # difference. + index_files_changed_p= + for this_file in ${new_index_files}; do + $verbose "Comparing index file $this_file ..." + # cmp -s will return nonzero exit status if files differ. + cmp -s "${this_file}" "${this_file}${backup_extension}" + if test $? -ne 0; then + # We only need to keep comparing until we find *one* that + # differs, because we'll have to run texindex & tex no + # matter what. + index_files_changed_p=t + $verbose "Index file $this_file differed:" + test $verbose = echo \ + && diff -c "${this_file}${backup_extension}" "${this_file}" + break + fi done - new_index_files="${definite_index_files}" - new_index_files_sans_aux="`echo ${definite_index_files} \ - | sed 's/'${filename_noext}'\.aux//; - s/^[ ]*//;s/[ ]*$//;'`" - - # If old and new list don't at least have the same file list, then one - # file or another has definitely changed. - if test "${orig_index_files}" != "${new_index_files}" ; then - index_files_changed_p=t - else - # File list is the same. We must compare each file until we find a - # difference. - index_files_changed_p="" - for this_file in ${new_index_files} ; do - # cmp -s will return nonzero exit status if files differ. - cmp -s "${this_file}" "${this_file}${backup_extension}" - if test $? -ne 0 ; then - # We only need to keep comparing until we find *one* that - # differs, because we'll have to run texindex & tex no - # matter what. - index_files_changed_p=t - break - fi - done - fi + fi - # If index files have changed since TeX has been run, or if the aux - # file wasn't present originally, run texindex and TeX again. - if test "${index_files_changed_p}" ; then - retval=0 - if test "${new_index_files_sans_aux}" ; then - ${texindex} ${new_index_files_sans_aux} - retval=$? - fi - if test ${retval} -eq 0 ; then - ${tex} "${command_line_filename}" - fi - fi - fi - - # Generate list of files to delete, then call rm once with the entire - # list. This is significantly faster than multiple executions of rm. - file_list="" - for file in ${orig_index_files} ; do - file_list="${file_list} ${file}${backup_extension}" - done - if test "${file_list}" ; then - rm -f ${file_list} - fi + # If index files have changed since TeX has been run, or if the aux + # file wasn't present originally, run texindex and TeX again. + if test "${index_files_changed_p}"; then :; else + # Nothing changed. We're done with TeX. + break + fi + done + + # If we were in clean mode, compilation was in a tmp directory. + # Copy the DVI file into the directory where the compilation + # has been done. (The temp dir is about to get removed anyway.) + # We also return to the original directory so that + # - the next file is processed in correct conditions + # - the temporary file can be removed + if test -n "$clean"; then + $verbose "Copying DVI file from `pwd` to $orig_pwd" + cp -p $filename_noext.dvi $orig_pwd + cd $orig_pwd || exit 1 + fi + + # Generate list of files to delete, then call rm once with the entire + # list. This is significantly faster than multiple executions of rm. + file_list= + for file in ${orig_index_files}; do + file_list="${file_list} ${file}${backup_extension}" + done + if test -n "${file_list}"; then + $verbose "Removing $file_list $tmp_dir $tmp_dir2 ..." + rm -f ${file_list} + rm -rf $tmp_dir $tmp_dir2 + fi done -# texi2dvi ends here +$verbose "$0 done." +true # exit successfully. diff --git a/gnu/usr.bin/texinfo/util/texindex.c b/gnu/usr.bin/texinfo/util/texindex.c index f9a3003dc3b..b1017555ee4 100644 --- a/gnu/usr.bin/texinfo/util/texindex.c +++ b/gnu/usr.bin/texinfo/util/texindex.c @@ -1,8 +1,7 @@ /* Prepare TeX index dribble output into an actual index. + $Id: texindex.c,v 1.2 1999/01/11 16:38:15 espie Exp $ - Version 1.45 - - Copyright (C) 1987, 1991, 1992 Free Software Foundation, Inc. + Copyright (C) 1987, 91, 92, 96, 97, 98 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 @@ -17,14 +16,9 @@ You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307. */ - - -#include <stdio.h> -#include <ctype.h> -#include <errno.h> -#include "getopt.h" -#define TEXINDEX_VERSION_STRING "GNU Texindex 2.0 for Texinfo release 3.4" +#include "system.h" +#include <getopt.h> #if defined (emacs) # include "../src/config.h" @@ -35,26 +29,6 @@ # undef open #endif -#if defined (HAVE_STRING_H) -# include <string.h> -#endif /* HAVE_STRING_H */ - -#if !defined (HAVE_STRCHR) -char *strrchr (); -#endif /* !HAVE_STRCHR */ - -#if defined (STDC_HEADERS) -# include <stdlib.h> -#else /* !STDC_HEADERS */ -char *getenv (), *malloc (), *realloc (); -#endif /* !STDC_HEADERS */ - -#if defined (HAVE_UNISTD_H) -# include <unistd.h> -#else /* !HAVE_UNISTD_H */ -off_t lseek (); -#endif /* !HAVE_UNISTD_H */ - #if !defined (HAVE_MEMSET) #undef memset #define memset(ptr, ignore, count) bzero (ptr, count) @@ -69,18 +43,6 @@ char *mktemp (); # define TI_FATAL_ERROR ((1 << 28) | 4) # define unlink delete #else /* !VMS */ -# if defined (HAVE_SYS_FCNTL_H) -# include <sys/types.h> -# include <sys/fcntl.h> -# endif /* HAVE_SYS_FCNTL_H */ - -# if defined (_AIX) || !defined (_POSIX_VERSION) -# include <sys/file.h> -# else /* !AIX && _POSIX_VERSION */ -# if !defined (HAVE_SYS_FCNTL_H) -# include <fcntl.h> -# endif /* !HAVE_FCNTL_H */ -# endif /* !_AIX && _POSIX_VERSION */ # define TI_NO_ERROR 0 # define TI_FATAL_ERROR 1 #endif /* !VMS */ @@ -91,36 +53,31 @@ char *mktemp (); # define SEEK_END 2 #endif /* !SEEK_SET */ -#if !defined (errno) -extern int errno; -#endif -char *strerror (); - /* When sorting in core, this structure describes one line and the position and length of its first keyfield. */ struct lineinfo { - char *text; /* The actual text of the line. */ + char *text; /* The actual text of the line. */ union { - char *text; /* The start of the key (for textual comparison). */ - long number; /* The numeric value (for numeric comparison). */ + char *text; /* The start of the key (for textual comparison). */ + long number; /* The numeric value (for numeric comparison). */ } key; - long keylen; /* Length of KEY field. */ + long keylen; /* Length of KEY field. */ }; /* This structure describes a field to use as a sort key. */ struct keyfield { - int startwords; /* Number of words to skip. */ - int startchars; /* Number of additional chars to skip. */ - int endwords; /* Number of words to ignore at end. */ - int endchars; /* Ditto for characters of last word. */ - char ignore_blanks; /* Non-zero means ignore spaces and tabs. */ - char fold_case; /* Non-zero means case doesn't matter. */ - char reverse; /* Non-zero means compare in reverse order. */ - char numeric; /* Non-zeros means field is ASCII numeric. */ - char positional; /* Sort according to file position. */ - char braced; /* Count balanced-braced groupings as fields. */ + int startwords; /* Number of words to skip. */ + int startchars; /* Number of additional chars to skip. */ + int endwords; /* Number of words to ignore at end. */ + int endchars; /* Ditto for characters of last word. */ + char ignore_blanks; /* Non-zero means ignore spaces and tabs. */ + char fold_case; /* Non-zero means case doesn't matter. */ + char reverse; /* Non-zero means compare in reverse order. */ + char numeric; /* Non-zeros means field is ASCII numeric. */ + char positional; /* Sort according to file position. */ + char braced; /* Count balanced-braced groupings as fields. */ }; /* Vector of keyfields to use. */ @@ -198,7 +155,7 @@ char *tempcopy (); #define MAX_IN_CORE_SORT 500000 -void +int main (argc, argv) int argc; char **argv; @@ -214,6 +171,15 @@ main (argc, argv) else program_name = argv[0]; +#ifdef HAVE_SETLOCALE + /* Set locale via LC_ALL. */ + setlocale (LC_ALL, ""); +#endif + + /* Set the text message domain. */ + bindtextdomain (PACKAGE, LOCALEDIR); + textdomain (PACKAGE); + /* Describe the kind of sorting to do. */ /* The first keyfield uses the first braced field and folds case. */ keyfields[0].braced = 1; @@ -247,7 +213,7 @@ main (argc, argv) desc = open (infiles[i], O_RDONLY, 0); if (desc < 0) - pfatal_with_name (infiles[i]); + pfatal_with_name (infiles[i]); lseek (desc, (off_t) 0, SEEK_END); ptr = (long) lseek (desc, (off_t) 0, SEEK_CUR); @@ -255,19 +221,21 @@ main (argc, argv) outfile = outfiles[i]; if (!outfile) - { - outfile = concat (infiles[i], "s", ""); - } + { + outfile = concat (infiles[i], "s", ""); + } if (ptr < MAX_IN_CORE_SORT) - /* Sort a small amount of data. */ - sort_in_core (infiles[i], ptr, outfile); + /* Sort a small amount of data. */ + sort_in_core (infiles[i], ptr, outfile); else - sort_offline (infiles[i], ptr, outfile); + sort_offline (infiles[i], ptr, outfile); } flush_tempfiles (tempcount); exit (TI_NO_ERROR); + + return 0; /* Avoid bogus warnings. */ } typedef struct @@ -282,14 +250,15 @@ typedef struct TEXINDEX_OPTION texindex_options[] = { { "--keep", "-k", &keep_tempfiles, 1, (char *)NULL, - "Keep temporary files around after processing" }, + N_("keep temporary files around after processing") }, { "--no-keep", 0, &keep_tempfiles, 0, (char *)NULL, - "Do not keep temporary files around after processing (default)" }, + N_("do not keep temporary files around after processing (default)") }, { "--output", "-o", (int *)NULL, 0, "FILE", - "Send output to FILE" }, + N_("send output to FILE") }, { "--version", (char *)NULL, (int *)NULL, 0, (char *)NULL, - "Show version information" }, - { "--help", "-h", (int *)NULL, 0, (char *)NULL, "Produce this listing" }, + N_("display version information and exit") }, + { "--help", "-h", (int *)NULL, 0, (char *)NULL, + N_("display this help and exit") }, { (char *)NULL, (char *)NULL, (int *)NULL, 0, (char *)NULL } }; @@ -298,26 +267,28 @@ usage (result_value) int result_value; { register int i; + FILE *f = result_value ? stderr : stdout; - fprintf (stderr, "Usage: %s [OPTIONS] FILE...\n", program_name); - fprintf (stderr, " Generate a permuted index for the TeX files given.\n"); - fprintf (stderr, " Usually FILE... is `foo.??' for the source file `foo.tex'.\n"); - fprintf (stderr, " The OPTIONS are:\n"); + fprintf (f, _("Usage: %s [OPTION]... FILE...\n"), program_name); + fprintf (f, _("Generate a sorted index for each TeX output FILE.\n")); + /* Avoid trigraph nonsense. */ + fprintf (f, _("Usually FILE... is `foo.??\' for a document `foo.texi'.\n")); + fprintf (f, _("\nOptions:\n")); for (i = 0; texindex_options[i].long_name; i++) { - fprintf (stderr, " %s %s", - texindex_options[i].long_name, - texindex_options[i].arg_name ? - texindex_options[i].arg_name : ""); - if (texindex_options[i].short_name) - fprintf (stderr, " \n or %s %s", - texindex_options[i].short_name, - texindex_options[i].arg_name ? - texindex_options[i].arg_name : ""); - fprintf (stderr, "\t%s\n", texindex_options[i].doc_string); + fprintf (f, "%s, ", texindex_options[i].short_name); + + fprintf (f, "%s %s", + texindex_options[i].long_name, + texindex_options[i].arg_name + ? texindex_options[i].arg_name : ""); + + fprintf (f, "\t%s\n", _(texindex_options[i].doc_string)); } + puts (_("\nEmail bug reports to bug-texinfo@gnu.org.")); + exit (result_value); } @@ -330,7 +301,6 @@ decode_command (argc, argv) char **argv; { int arg_index = 1; - int optc; char **ip; char **op; @@ -361,42 +331,47 @@ decode_command (argc, argv) char *arg = argv[arg_index++]; if (*arg == '-') - { - if (strcmp (arg, "--version") == 0) - { - fprintf (stderr, "%s\n", TEXINDEX_VERSION_STRING); - exit (0); - } - else if ((strcmp (arg, "--keep") == 0) || - (strcmp (arg, "-k") == 0)) - { - keep_tempfiles = 1; - } - else if ((strcmp (arg, "--help") == 0) || - (strcmp (arg, "-h") == 0)) - { - usage (0); - } - else if ((strcmp (arg, "--output") == 0) || - (strcmp (arg, "-o") == 0)) - { - if (argv[arg_index] != (char *)NULL) - { - arg_index++; - if (op > outfiles) - *(op - 1) = argv[arg_index]; - } - else - usage (1); - } - else - usage (1); - } + { + if (strcmp (arg, "--version") == 0) + { + printf ("texindex (GNU %s) %s\n", PACKAGE, VERSION); + printf (_("Copyright (C) %s Free Software Foundation, Inc.\n\ +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"), + "1998"); + exit (0); + } + else if ((strcmp (arg, "--keep") == 0) || + (strcmp (arg, "-k") == 0)) + { + keep_tempfiles = 1; + } + else if ((strcmp (arg, "--help") == 0) || + (strcmp (arg, "-h") == 0)) + { + usage (0); + } + else if ((strcmp (arg, "--output") == 0) || + (strcmp (arg, "-o") == 0)) + { + if (argv[arg_index] != (char *)NULL) + { + arg_index++; + if (op > outfiles) + *(op - 1) = argv[arg_index]; + } + else + usage (1); + } + else + usage (1); + } else - { - *ip++ = arg; - *op++ = (char *)NULL; - } + { + *ip++ = arg; + *op++ = (char *)NULL; + } } /* Record number of keyfields and terminate list of filenames. */ @@ -452,7 +427,7 @@ tempcopy (idesc) int nread = read (idesc, buffer, BUFSIZE); write (odesc, buffer, nread); if (!nread) - break; + break; } close (odesc); @@ -478,16 +453,16 @@ compare_full (line1, line2) char *start1 = find_field (&keyfields[i], *line1, &length1); char *start2 = find_field (&keyfields[i], *line2, &length2); int tem = compare_field (&keyfields[i], start1, length1, *line1 - text_base, - start2, length2, *line2 - text_base); + start2, length2, *line2 - text_base); if (tem) - { - if (keyfields[i].reverse) - return -tem; - return tem; - } + { + if (keyfields[i].reverse) + return -tem; + return tem; + } } - return 0; /* Lines match exactly. */ + return 0; /* Lines match exactly. */ } /* Compare LINE1 and LINE2, described by structures @@ -507,19 +482,19 @@ compare_prepared (line1, line2) if (keyfields->positional) { if (line1->text - text_base > line2->text - text_base) - tem = 1; + tem = 1; else - tem = -1; + tem = -1; } else if (keyfields->numeric) tem = line1->key.number - line2->key.number; else tem = compare_field (keyfields, line1->key.text, line1->keylen, 0, - line2->key.text, line2->keylen, 0); + line2->key.text, line2->keylen, 0); if (tem) { if (keyfields->reverse) - return -tem; + return -tem; return tem; } @@ -536,16 +511,16 @@ compare_prepared (line1, line2) char *start1 = find_field (&keyfields[i], text1, &length1); char *start2 = find_field (&keyfields[i], text2, &length2); int tem = compare_field (&keyfields[i], start1, length1, text1 - text_base, - start2, length2, text2 - text_base); + start2, length2, text2 - text_base); if (tem) - { - if (keyfields[i].reverse) - return -tem; - return tem; - } + { + if (keyfields[i].reverse) + return -tem; + return tem; + } } - return 0; /* Lines match exactly. */ + return 0; /* Lines match exactly. */ } /* Like compare_full but more general. @@ -571,16 +546,16 @@ compare_general (str1, str2, pos1, pos2, use_keyfields) char *start1 = find_field (&keyfields[i], str1, &length1); char *start2 = find_field (&keyfields[i], str2, &length2); int tem = compare_field (&keyfields[i], start1, length1, pos1, - start2, length2, pos2); + start2, length2, pos2); if (tem) - { - if (keyfields[i].reverse) - return -tem; - return tem; - } + { + if (keyfields[i].reverse) + return -tem; + return tem; + } } - return 0; /* Lines match exactly. */ + return 0; /* Lines match exactly. */ } /* Find the start and length of a field in STR according to KEYFIELD. @@ -603,23 +578,23 @@ find_field (keyfield, str, lengthptr) fun = find_pos; start = (*fun) (str, keyfield->startwords, keyfield->startchars, - keyfield->ignore_blanks); + keyfield->ignore_blanks); if (keyfield->endwords < 0) { if (keyfield->braced) - end = find_braced_end (start); + end = find_braced_end (start); else - { - end = start; - while (*end && *end != '\n') - end++; - } + { + end = start; + while (*end && *end != '\n') + end++; + } } else { end = (*fun) (str, keyfield->endwords, keyfield->endchars, 0); if (end - str < start - str) - end = start; + end = start; } *lengthptr = end - start; return start; @@ -644,11 +619,11 @@ find_pos (str, words, chars, ignore_blanks) char c; /* Find next bunch of nonblanks and skip them. */ while ((c = *p) == ' ' || c == '\t') - p++; + p++; while ((c = *p) && c != '\n' && !(c == ' ' || c == '\t')) - p++; + p++; if (!*p || *p == '\n') - return p; + return p; } while (*p == ' ' || *p == '\t') @@ -657,7 +632,7 @@ find_pos (str, words, chars, ignore_blanks) for (i = 0; i < chars; i++) { if (!*p || *p == '\n') - break; + break; p++; } return p; @@ -681,19 +656,19 @@ find_braced_pos (str, words, chars, ignore_blanks) { bracelevel = 1; while ((c = *p++) != '{' && c != '\n' && c) - /* Do nothing. */ ; + /* Do nothing. */ ; if (c != '{') - return p - 1; + return p - 1; while (bracelevel) - { - c = *p++; - if (c == '{') - bracelevel++; - if (c == '}') - bracelevel--; - if (c == 0 || c == '\n') - return p - 1; - } + { + c = *p++; + if (c == '{') + bracelevel++; + if (c == '}') + bracelevel--; + if (c == 0 || c == '\n') + return p - 1; + } } while ((c = *p++) != '{' && c != '\n' && c) @@ -709,7 +684,7 @@ find_braced_pos (str, words, chars, ignore_blanks) for (i = 0; i < chars; i++) { if (!*p || *p == '\n') - break; + break; p++; } return p; @@ -731,11 +706,11 @@ find_braced_end (str) { c = *p++; if (c == '{') - bracelevel++; + bracelevel++; if (c == '}') - bracelevel--; + bracelevel--; if (c == 0 || c == '\n') - return p - 1; + return p - 1; } return p - 1; } @@ -748,7 +723,7 @@ find_value (start, length) while (length != 0L) { if (isdigit (*start)) - return atol (start); + return atol (start); length--; start++; } @@ -794,17 +769,17 @@ compare_field (keyfield, start1, length1, pos1, start2, length2, pos2) if (keyfields->positional) { if (pos1 > pos2) - return 1; + return 1; else - return -1; + return -1; } if (keyfield->numeric) { long value = find_value (start1, length1) - find_value (start2, length2); if (value > 0) - return 1; + return 1; if (value < 0) - return -1; + return -1; return 0; } else @@ -815,46 +790,46 @@ compare_field (keyfield, start1, length1, pos1, start2, length2, pos2) char *e2 = start2 + length2; while (1) - { - int c1, c2; - - if (p1 == e1) - c1 = 0; - else - c1 = *p1++; - if (p2 == e2) - c2 = 0; - else - c2 = *p2++; - - if (char_order[c1] != char_order[c2]) - return char_order[c1] - char_order[c2]; - if (!c1) - break; - } + { + int c1, c2; + + if (p1 == e1) + c1 = 0; + else + c1 = *p1++; + if (p2 == e2) + c2 = 0; + else + c2 = *p2++; + + if (char_order[c1] != char_order[c2]) + return char_order[c1] - char_order[c2]; + if (!c1) + break; + } /* Strings are equal except possibly for case. */ p1 = start1; p2 = start2; while (1) - { - int c1, c2; - - if (p1 == e1) - c1 = 0; - else - c1 = *p1++; - if (p2 == e2) - c2 = 0; - else - c2 = *p2++; - - if (c1 != c2) - /* Reverse sign here so upper case comes out last. */ - return c2 - c1; - if (!c1) - break; - } + { + int c1, c2; + + if (p1 == e1) + c1 = 0; + else + c1 = *p1++; + if (p2 == e2) + c2 = 0; + else + c2 = *p2++; + + if (c1 != c2) + /* Reverse sign here so upper case comes out last. */ + return c2 - c1; + if (!c1) + break; + } return 0; } @@ -896,17 +871,17 @@ readline (linebuffer, stream) { int c = getc (stream); if (p == end) - { - buffer = (char *) xrealloc (buffer, linebuffer->size *= 2); - p += buffer - linebuffer->buffer; - end += buffer - linebuffer->buffer; - linebuffer->buffer = buffer; - } + { + buffer = (char *) xrealloc (buffer, linebuffer->size *= 2); + p += buffer - linebuffer->buffer; + end += buffer - linebuffer->buffer; + linebuffer->buffer = buffer; + } if (c < 0 || c == '\n') - { - *p = 0; - break; - } + { + *p = 0; + break; + } *p++ = c; } @@ -939,7 +914,7 @@ sort_offline (infile, nfiles, total, outfile) if (lb.buffer[0] != '\\' && lb.buffer[0] != '@') { - error ("%s: not a texinfo index file", infile); + error (_("%s: not a texinfo index file"), infile); return; } @@ -953,34 +928,34 @@ sort_offline (infile, nfiles, total, outfile) long tempsize = 0; if (!ostream) - pfatal_with_name (outname); + pfatal_with_name (outname); tempfiles[i] = outname; /* Copy lines into this temp file as long as it does not make file - "too big" or until there are no more lines. */ + "too big" or until there are no more lines. */ while (tempsize + linelength + 1 <= MAX_IN_CORE_SORT) - { - tempsize += linelength + 1; - fputs (lb.buffer, ostream); - putc ('\n', ostream); - - /* Read another line of input data. */ - - linelength = readline (&lb, istream); - if (!linelength && feof (istream)) - break; - - if (lb.buffer[0] != '\\' && lb.buffer[0] != '@') - { - error ("%s: not a texinfo index file", infile); - failure = 1; - goto fail; - } - } + { + tempsize += linelength + 1; + fputs (lb.buffer, ostream); + putc ('\n', ostream); + + /* Read another line of input data. */ + + linelength = readline (&lb, istream); + if (!linelength && feof (istream)) + break; + + if (lb.buffer[0] != '\\' && lb.buffer[0] != '@') + { + error (_("%s: not a texinfo index file"), infile); + failure = 1; + goto fail; + } + } fclose (ostream); if (feof (istream)) - break; + break; } free (lb.buffer); @@ -999,7 +974,7 @@ fail: char *newtemp = maketempname (++tempcount); sort_in_core (&tempfiles[i], MAX_IN_CORE_SORT, newtemp); if (!keep_tempfiles) - unlink (tempfiles[i]); + unlink (tempfiles[i]); tempfiles[i] = newtemp; } @@ -1034,12 +1009,12 @@ sort_in_core (infile, total, outfile) int desc = open (infile, O_RDONLY, 0); if (desc < 0) - fatal ("failure reopening %s", infile); + fatal (_("failure reopening %s"), infile); for (file_size = 0;;) { i = read (desc, data + file_size, total - file_size); if (i <= 0) - break; + break; file_size += i; } file_data = data; @@ -1049,7 +1024,7 @@ sort_in_core (infile, total, outfile) if (file_size > 0 && data[0] != '\\' && data[0] != '@') { - error ("%s: not a texinfo index file", infile); + error (_("%s: not a texinfo index file"), infile); return; } @@ -1077,7 +1052,7 @@ sort_in_core (infile, total, outfile) nextline = parsefile (infile, nextline, file_data, file_size); if (nextline == 0) { - error ("%s: not a texinfo index file", infile); + error (_("%s: not a texinfo index file"), infile); return; } @@ -1095,17 +1070,18 @@ sort_in_core (infile, total, outfile) char **p; for (lp = lineinfo, p = linearray; p != nextline; lp++, p++) - { - lp->text = *p; - lp->key.text = find_field (keyfields, *p, &lp->keylen); - if (keyfields->numeric) - lp->key.number = find_value (lp->key.text, lp->keylen); - } + { + lp->text = *p; + lp->key.text = find_field (keyfields, *p, &lp->keylen); + if (keyfields->numeric) + lp->key.number = find_value (lp->key.text, lp->keylen); + } - qsort (lineinfo, nextline - linearray, sizeof (struct lineinfo), compare_prepared); + qsort (lineinfo, nextline - linearray, sizeof (struct lineinfo), + compare_prepared); for (lp = lineinfo, p = linearray; p != nextline; lp++, p++) - *p = lp->text; + *p = lp->text; free (lineinfo); } @@ -1118,7 +1094,7 @@ sort_in_core (infile, total, outfile) { ostream = fopen (outfile, "w"); if (!ostream) - pfatal_with_name (outfile); + pfatal_with_name (outfile); } writelines (linearray, nextline - linearray, ostream); @@ -1152,21 +1128,21 @@ parsefile (filename, nextline, data, size) while (p != end) { if (p[0] != '\\' && p[0] != '@') - return 0; + return 0; *line = p; while (*p && *p != '\n') - p++; + p++; if (p != end) - p++; + p++; line++; if (line == linearray + nlines) - { - char **old = linearray; - linearray = (char **) xrealloc (linearray, sizeof (char *) * (nlines *= 4)); - line += linearray - old; - } + { + char **old = linearray; + linearray = (char **) xrealloc (linearray, sizeof (char *) * (nlines *= 4)); + line += linearray - old; + } } return line; @@ -1258,7 +1234,7 @@ indexify (line, ostream) { initial = p; /* Get length of inner pair of braces starting at `p', - including that inner pair of braces. */ + including that inner pair of braces. */ initiallength = find_braced_end (p + 1) + 1 - p; } else @@ -1269,7 +1245,7 @@ indexify (line, ostream) initiallength = 1; if (initial1[0] >= 'a' && initial1[0] <= 'z') - initial1[0] -= 040; + initial1[0] -= 040; } pagenumber = find_braced_pos (line, 1, 0, 0); @@ -1290,52 +1266,52 @@ indexify (line, ostream) { /* Close off current secondary entry first, if one is open. */ if (pending) - { - fputs ("}\n", ostream); - pending = 0; - } + { + fputs ("}\n", ostream); + pending = 0; + } /* If this primary has a different initial, include an entry for - the initial. */ + the initial. */ if (initiallength != lastinitiallength || - strncmp (initial, lastinitial, initiallength)) - { - fprintf (ostream, "\\initial {"); - fwrite (initial, 1, initiallength, ostream); - fprintf (ostream, "}\n", initial); - if (initial == initial1) - { - lastinitial = lastinitial1; - *lastinitial1 = *initial1; - } - else - { - lastinitial = initial; - } - lastinitiallength = initiallength; - } + strncmp (initial, lastinitial, initiallength)) + { + fprintf (ostream, "\\initial {"); + fwrite (initial, 1, initiallength, ostream); + fputs ("}\n", ostream); + if (initial == initial1) + { + lastinitial = lastinitial1; + *lastinitial1 = *initial1; + } + else + { + lastinitial = initial; + } + lastinitiallength = initiallength; + } /* Make the entry for the primary. */ if (nosecondary) - fputs ("\\entry {", ostream); + fputs ("\\entry {", ostream); else - fputs ("\\primary {", ostream); + fputs ("\\primary {", ostream); fwrite (primary, primarylength, 1, ostream); if (nosecondary) - { - fputs ("}{", ostream); - pending = 1; - } + { + fputs ("}{", ostream); + pending = 1; + } else - fputs ("}\n", ostream); + fputs ("}\n", ostream); /* Record name of most recent primary. */ if (lastprimarylength < primarylength) - { - lastprimarylength = primarylength + 100; - lastprimary = (char *) xrealloc (lastprimary, - 1 + lastprimarylength); - } + { + lastprimarylength = primarylength + 100; + lastprimary = (char *) xrealloc (lastprimary, + 1 + lastprimarylength); + } strncpy (lastprimary, primary, primarylength); lastprimary[primarylength] = 0; @@ -1346,16 +1322,16 @@ indexify (line, ostream) /* Should not have an entry with no subtopic following one with a subtopic. */ if (nosecondary && *lastsecondary) - error ("entry %s follows an entry with a secondary name", line); + error (_("entry %s follows an entry with a secondary name"), line); /* Start a new secondary entry if necessary. */ if (!nosecondary && strncmp (secondary, lastsecondary, secondarylength)) { if (pending) - { - fputs ("}\n", ostream); - pending = 0; - } + { + fputs ("}\n", ostream); + pending = 0; + } /* Write the entry for the secondary. */ fputs ("\\secondary {", ostream); @@ -1365,18 +1341,18 @@ indexify (line, ostream) /* Record name of most recent secondary. */ if (lastsecondarylength < secondarylength) - { - lastsecondarylength = secondarylength + 100; - lastsecondary = (char *) xrealloc (lastsecondary, - 1 + lastsecondarylength); - } + { + lastsecondarylength = secondarylength + 100; + lastsecondary = (char *) xrealloc (lastsecondary, + 1 + lastsecondarylength); + } strncpy (lastsecondary, secondary, secondarylength); lastsecondary[secondarylength] = 0; } /* Here to add one more page number to the current entry. */ if (pending++ != 1) - fputs (", ", ostream); /* Punctuate first, if this is not the first. */ + fputs (", ", ostream); /* Punctuate first, if this is not the first. */ fwrite (pagenumber, pagelength, 1, ostream); } @@ -1414,16 +1390,16 @@ writelines (linearray, nlines, ostream) if (next_line == linearray /* Compare previous line with this one, using only the explicitly specd keyfields. */ - || compare_general (*(next_line - 1), *next_line, 0L, 0L, num_keyfields - 1)) - { - char *p = *next_line; - char c; - - while ((c = *p++) && c != '\n') - /* Do nothing. */ ; - *(p - 1) = 0; - indexify (*next_line, ostream); - } + || compare_general (*(next_line - 1), *next_line, 0L, 0L, num_keyfields - 1)) + { + char *p = *next_line; + char c; + + while ((c = *p++) && c != '\n') + /* Do nothing. */ ; + *(p - 1) = 0; + indexify (*next_line, ostream); + } } finish_index (ostream); @@ -1462,7 +1438,7 @@ merge_files (infiles, nfiles, outfile) { int nf = MAX_DIRECT_MERGE; if (i + 1 == ntemps) - nf = nfiles - i * MAX_DIRECT_MERGE; + nf = nfiles - i * MAX_DIRECT_MERGE; tempfiles[i] = maketempname (++tempcount); value |= merge_direct (&infiles[i * MAX_DIRECT_MERGE], nf, tempfiles[i]); } @@ -1517,7 +1493,7 @@ merge_direct (infiles, nfiles, outfile) if (nfiles == 0) { if (outfile) - fclose (ostream); + fclose (ostream); return 0; } @@ -1559,7 +1535,7 @@ merge_direct (infiles, nfiles, outfile) file_lossage[i] = 0; streams[i] = fopen (infiles[i], "r"); if (!streams[i]) - pfatal_with_name (infiles[i]); + pfatal_with_name (infiles[i]); readline (thisline[i], streams[i]); } @@ -1577,48 +1553,48 @@ merge_direct (infiles, nfiles, outfile) /* Look at the next avail line of each file; choose the least one. */ for (i = 0; i < nfiles; i++) - { - if (thisline[i] && - (!best || - 0 < compare_general (best->buffer, thisline[i]->buffer, - (long) bestfile, (long) i, num_keyfields))) - { - best = thisline[i]; - bestfile = i; - } - } + { + if (thisline[i] && + (!best || + 0 < compare_general (best->buffer, thisline[i]->buffer, + (long) bestfile, (long) i, num_keyfields))) + { + best = thisline[i]; + bestfile = i; + } + } /* Output that line, unless it matches the previous one and we - don't want duplicates. */ + don't want duplicates. */ if (!(prev_out && - !compare_general (prev_out->buffer, - best->buffer, 0L, 1L, num_keyfields - 1))) - indexify (best->buffer, ostream); + !compare_general (prev_out->buffer, + best->buffer, 0L, 1L, num_keyfields - 1))) + indexify (best->buffer, ostream); prev_out = best; /* Now make the line the previous of its file, and fetch a new - line from that file. */ + line from that file. */ exch = prevline[bestfile]; prevline[bestfile] = thisline[bestfile]; thisline[bestfile] = exch; while (1) - { - /* If the file has no more, mark it empty. */ - - if (feof (streams[bestfile])) - { - thisline[bestfile] = 0; - /* Update the number of files still not empty. */ - nleft--; - break; - } - readline (thisline[bestfile], streams[bestfile]); - if (thisline[bestfile]->buffer[0] || !feof (streams[bestfile])) - break; - } + { + /* If the file has no more, mark it empty. */ + + if (feof (streams[bestfile])) + { + thisline[bestfile] = 0; + /* Update the number of files still not empty. */ + nleft--; + break; + } + readline (thisline[bestfile], streams[bestfile]); + if (thisline[bestfile]->buffer[0] || !feof (streams[bestfile])) + break; + } } finish_index (ostream); @@ -1684,7 +1660,7 @@ pfatal_with_name (name) s = strerror (errno); printf ("%s: ", program_name); - printf ("%s; for file `%s'.\n", s, name); + printf (_("%s; for file `%s'.\n"), s, name); exit (TI_FATAL_ERROR); } @@ -1737,6 +1713,21 @@ strrchr (string, character) } #endif /* HAVE_STRCHR */ +void +memory_error (callers_name, bytes_wanted) + char *callers_name; + int bytes_wanted; +{ + char printable_string[80]; + + sprintf (printable_string, + _("Virtual memory exhausted in %s ()! Needed %d bytes."), + callers_name, bytes_wanted); + + error (printable_string); + abort (); +} + /* Just like malloc, but kills the program in case of fatal error. */ void * xmalloc (nbytes) @@ -1768,18 +1759,3 @@ xrealloc (pointer, nbytes) return (temp); } - -memory_error (callers_name, bytes_wanted) - char *callers_name; - int bytes_wanted; -{ - char printable_string[80]; - - sprintf (printable_string, - "Virtual memory exhausted in %s ()! Needed %d bytes.", - callers_name, bytes_wanted); - - error (printable_string); - abort (); -} - |