aboutsummaryrefslogtreecommitdiff
path: root/gnu/lib/libreadline/doc
diff options
context:
space:
mode:
authorAndrey A. Chernov <ache@FreeBSD.org>1994-05-13 15:48:04 +0000
committerAndrey A. Chernov <ache@FreeBSD.org>1994-05-13 15:48:04 +0000
commit9e9eefe9588ed8e4459b308c21e65781f9cab85d (patch)
treeb88d5c25249bf0f2b44192dc7b0e94c38d6f30ac /gnu/lib/libreadline/doc
parentbc5acff79009f57c794b9a4f144a51820948315a (diff)
Notes
Diffstat (limited to 'gnu/lib/libreadline/doc')
-rw-r--r--gnu/lib/libreadline/doc/hsuser.texinfo76
-rw-r--r--gnu/lib/libreadline/doc/rluser.texinfo519
-rw-r--r--gnu/lib/libreadline/doc/texindex.c896
3 files changed, 947 insertions, 544 deletions
diff --git a/gnu/lib/libreadline/doc/hsuser.texinfo b/gnu/lib/libreadline/doc/hsuser.texinfo
index a460165e73c8..44f7fa093203 100644
--- a/gnu/lib/libreadline/doc/hsuser.texinfo
+++ b/gnu/lib/libreadline/doc/hsuser.texinfo
@@ -2,7 +2,7 @@
This file documents the user interface to the GNU History library.
Copyright (C) 1988, 1991 Free Software Foundation, Inc.
-Authored by Brian Fox.
+Authored by Brian Fox and Chet Ramey.
Permission is granted to make and distribute verbatim copies of this manual
provided the copyright notice and this permission notice are preserved on
@@ -48,8 +48,8 @@ information on using the GNU History Library in your own programs,
@cindex expansion
The History library provides a history expansion feature that is similar
-to the history expansion in Csh. The following text describes the sytax
-that you use to manipulate the history information.
+to the history expansion in @code{csh}. The following text describes
+the syntax used to manipulate the history information.
History expansion takes place in two parts. The first is to determine
which line from the previous history should be used during substitution.
@@ -57,13 +57,13 @@ The second is to select portions of that line for inclusion into the
current one. The line selected from the previous history is called the
@dfn{event}, and the portions of that line that are acted upon are
called @dfn{words}. The line is broken into words in the same fashion
-that the Bash shell does, so that several English (or Unix) words
+that Bash does, so that several English (or Unix) words
surrounded by quotes are considered as one word.
@menu
* Event Designators:: How to specify which history line to use.
* Word Designators:: Specifying which words are of interest.
-* Modifiers:: Modifying the results of susbstitution.
+* Modifiers:: Modifying the results of substitution.
@end menu
@node Event Designators
@@ -76,8 +76,8 @@ history list.
@table @asis
@item @code{!}
-Start a history subsititution, except when followed by a space, tab, or
-the end of the line... @key{=} or @key{(}.
+Start a history substitution, except when followed by a space, tab,
+the end of the line, @key{=} or @key{(}.
@item @code{!!}
Refer to the previous command. This is a synonym for @code{!-1}.
@@ -94,6 +94,14 @@ Refer to the most recent command starting with @var{string}.
@item @code{!?string}[@code{?}]
Refer to the most recent command containing @var{string}.
+@item @code{!#}
+The entire command line typed so far.
+
+@item @code{^string1^string2^}
+Quick Substitution. Repeat the last command, replacing @var{string1}
+with @var{string2}. Equivalent to
+@code{!!:s/string1/string2/}.
+
@end table
@node Word Designators
@@ -107,13 +115,13 @@ with the first word being denoted by a 0 (zero).
@table @code
@item 0 (zero)
-The zero'th word. For many applications, this is the command word.
+The @code{0}th word. For many applications, this is the command word.
@item n
-The @var{n}'th word.
+The @var{n}th word.
@item ^
-The first argument. that is, word 1.
+The first argument; that is, word 1.
@item $
The last argument.
@@ -122,12 +130,18 @@ The last argument.
The word matched by the most recent @code{?string?} search.
@item x-y
-A range of words; @code{-@var{y}} Abbreviates @code{0-@var{y}}.
+A range of words; @code{-@var{y}} abbreviates @code{0-@var{y}}.
@item *
-All of the words, excepting the zero'th. This is a synonym for @code{1-$}.
-It is not an error to use @key{*} if there is just one word in the event.
-The empty string is returned in that case.
+All of the words, except the @code{0}th. This is a synonym for @code{1-$}.
+It is not an error to use @key{*} if there is just one word in the event;
+the empty string is returned in that case.
+
+@item x*
+Abbreviates @code{x-$}
+
+@item x-
+Abbreviates @code{x-$} like @code{x*}, but omits the last word.
@end table
@@ -139,11 +153,6 @@ of the following modifiers, each preceded by a @key{:}.
@table @code
-@item #
-The entire command line typed so far. This means the current command,
-not the previous command, so it really isn't a word designator, and doesn't
-belong in this section.
-
@item h
Remove a trailing pathname component, leaving only the head.
@@ -151,11 +160,38 @@ Remove a trailing pathname component, leaving only the head.
Remove a trailing suffix of the form @samp{.}@var{suffix}, leaving the basename.
@item e
-Remove all but the suffix.
+Remove all but the trailing suffix.
@item t
Remove all leading pathname components, leaving the tail.
@item p
Print the new command but do not execute it.
+
+@ifset BashFeatures
+@item q
+Quote the substituted words, escaping further substitutions.
+
+@item x
+Quote the substituted words as with @code{q},
+but break into words at spaces, tabs, and newlines.
+@end ifset
+
+@item s/old/new/
+Substitute @var{new} for the first occurrence of @var{old} in the
+event line. Any delimiter may be used in place of @key{/}.
+The delimiter may be quoted in @var{old} and @var{new}
+with a single backslash. If @key{&} appears in @var{new},
+it is replaced by @var{old}. A single backslash will quote
+the @key{&}. The final delimiter is optional if it is the last
+character on the input line.
+
+@item &
+Repeat the previous substitution.
+
+@item g
+Cause changes to be applied over the entire event line. Used in
+conjunction with @code{s}, as in @code{gs/old/new/}, or with
+@code{&}.
+
@end table
diff --git a/gnu/lib/libreadline/doc/rluser.texinfo b/gnu/lib/libreadline/doc/rluser.texinfo
index 553c88ed1576..36a65b8fc94d 100644
--- a/gnu/lib/libreadline/doc/rluser.texinfo
+++ b/gnu/lib/libreadline/doc/rluser.texinfo
@@ -5,14 +5,14 @@
@ignore
This file documents the end user interface to the GNU command line
-editing feautres. It is to be an appendix to manuals for programs which
+editing features. It is to be an appendix to manuals for programs which
use these features. There is a document entitled "readline.texinfo"
which contains both end-user and programmer documentation for the GNU
Readline Library.
Copyright (C) 1988 Free Software Foundation, Inc.
-Authored by Brian Fox.
+Authored by Brian Fox and Chet Ramey.
Permission is granted to process this file through Tex and print the
results, provided the printed document carries copying permission notice
@@ -39,18 +39,23 @@ into another language, under the above conditions for modified versions.
@node Command Line Editing
@chapter Command Line Editing
-This text describes GNU's command line editing interface.
+This chapter describes the basic features of the GNU
+command line editing interface.
@menu
* Introduction and Notation:: Notation used in this text.
* Readline Interaction:: The minimum set of commands for editing a line.
* Readline Init File:: Customizing Readline from a user's view.
+* Bindable Readline Commands:: A description of most of the Readline commands
+ available for binding
+* Readline vi Mode:: A short description of how to make Readline
+ behave line the vi editor.
@end menu
@node Introduction and Notation
@section Introduction to Line Editing
-The following paragraphs describe the notation we use to represent
+The following paragraphs describe the notation used to represent
keystrokes.
The text @key{C-k} is read as `Control-K' and describes the character
@@ -97,19 +102,19 @@ regardless of the location of the cursor within the line.
In order to enter characters into the line, simply type them. The typed
character appears where the cursor was, and then the cursor moves one
-space to the right. If you mistype a character, you can use @key{DEL} to
-back up, and delete the mistyped character.
+space to the right. If you mistype a character, you can use your
+erase character to back up and delete the mistyped character.
Sometimes you may miss typing a character that you wanted to type, and
not notice your error until you have typed several other characters. In
that case, you can type @key{C-b} to move the cursor to the left, and then
-correct your mistake. Aftwerwards, you can move the cursor to the right
+correct your mistake. Afterwards, you can move the cursor to the right
with @key{C-f}.
When you add text in the middle of a line, you will notice that characters
-to the right of the cursor get `pushed over' to make room for the text
+to the right of the cursor are `pushed over' to make room for the text
that you have inserted. Likewise, when you delete text behind the cursor,
-characters to the right of the cursor get `pulled back' to fill in the
+characters to the right of the cursor are `pulled back' to fill in the
blank space created by the removal of the text. A list of the basic bare
essentials for editing the text of an input line follows.
@@ -123,7 +128,7 @@ Delete the character to the left of the cursor.
@item @key{C-d}
Delete the character underneath the cursor.
@item @w{Printing characters}
-Insert itself into the line at the cursor.
+Insert the character into the line at the cursor.
@item @key{C-_}
Undo the last thing that you did. You can undo all the way back to an
empty line.
@@ -160,11 +165,19 @@ operate on characters while meta keystrokes operate on words.
@subsection Readline Killing Commands
@dfn{Killing} text means to delete the text from the line, but to save
-it away for later use, usually by @dfn{yanking} it back into the line.
+it away for later use, usually by @dfn{yanking} (re-inserting)
+it back into the line.
If the description for a command says that it `kills' text, then you can
be sure that you can get the text back in a different (or the same)
place later.
+When you use a kill command, the text is saved in a @dfn{kill-ring}.
+Any number of consecutive kills save all of the killed text together, so
+that when you yank it back, you get it all. The kill
+ring is not line specific; the text that you killed on a previously
+typed line is available to be yanked back later, when you are typing
+another line.
+
Here is the list of commands for killing text.
@table @key
@@ -186,7 +199,7 @@ Kill from the cursor to the previous whitespace. This is different than
@end table
And, here is how to @dfn{yank} the text back into the line. Yanking
-is
+means to copy the most-recently-killed text from the kill buffer.
@table @key
@item C-y
@@ -197,13 +210,6 @@ Rotate the kill-ring, and yank the new top. You can only do this if
the prior command is @key{C-y} or @key{M-y}.
@end table
-When you use a kill command, the text is saved in a @dfn{kill-ring}.
-Any number of consecutive kills save all of the killed text together, so
-that when you yank it back, you get it in one clean sweep. The kill
-ring is not line specific; the text that you killed on a previously
-typed line is available to be yanked back later, when you are typing
-another line.
-
@node Readline Arguments
@subsection Readline Arguments
@@ -226,81 +232,155 @@ the @key{C-d} command an argument of 10, you could type @key{M-1 0 C-d}.
@section Readline Init File
Although the Readline library comes with a set of Emacs-like
-keybindings, it is possible that you would like to use a different set
+keybindings installed by default,
+it is possible that you would like to use a different set
of keybindings. You can customize programs that use Readline by putting
commands in an @dfn{init} file in your home directory. The name of this
-file is @file{~/.inputrc}.
+file is taken from the value of the shell variable @code{INPUTRC}. If
+that variable is unset, the default is @file{~/.inputrc}.
When a program which uses the Readline library starts up, the
-@file{~/.inputrc} file is read, and the keybindings are set.
+init file is read, and the key bindings are set.
In addition, the @code{C-x C-r} command re-reads this init file, thus
incorporating any changes that you might have made to it.
@menu
-* Readline Init Syntax:: Syntax for the commands in @file{~/.inputrc}.
-* Readline Vi Mode:: Switching to @code{vi} mode in Readline.
+* Readline Init Syntax:: Syntax for the commands in the inputrc file.
+* Conditional Init Constructs:: Conditional key bindings in the inputrc file.
@end menu
@node Readline Init Syntax
@subsection Readline Init Syntax
-There are only four constructs allowed in the @file{~/.inputrc}
-file:
+There are only a few basic constructs allowed in the
+Readline init file. Blank lines are ignored.
+Lines beginning with a @key{#} are comments.
+Lines beginning with a @key{$} indicate conditional
+constructs (@pxref{Conditional Init Constructs}). Other lines
+denote variable settings and key bindings.
@table @asis
@item Variable Settings
-You can change the state of a few variables in Readline. You do this by
+You can change the state of a few variables in Readline by
using the @code{set} command within the init file. Here is how you
-would specify that you wish to use Vi line editing commands:
+would specify that you wish to use @code{vi} line editing commands:
@example
set editing-mode vi
@end example
-Right now, there are only a few variables which can be set; so few in
-fact, that we just iterate them here:
+Right now, there are only a few variables which can be set;
+so few, in fact, that we just list them here:
@table @code
@item editing-mode
@vindex editing-mode
The @code{editing-mode} variable controls which editing mode you are
-using. By default, GNU Readline starts up in Emacs editing mode, where
-the keystrokes are most similar to Emacs. This variable can either be
-set to @code{emacs} or @code{vi}.
+using. By default, Readline starts up in Emacs editing mode, where
+the keystrokes are most similar to Emacs. This variable can be
+set to either @code{emacs} or @code{vi}.
@item horizontal-scroll-mode
@vindex horizontal-scroll-mode
-This variable can either be set to @code{On} or @code{Off}. Setting it
+This variable can be set to either @code{On} or @code{Off}. Setting it
to @code{On} means that the text of the lines that you edit will scroll
-horizontally on a single screen line when they are larger than the width
+horizontally on a single screen line when they are longer than the width
of the screen, instead of wrapping onto a new screen line. By default,
this variable is set to @code{Off}.
@item mark-modified-lines
@vindex mark-modified-lines
-This variable when set to @code{On}, says to display an asterisk
-(@samp{*}) at the starts of history lines which have been modified.
-This variable is off by default.
+This variable, when set to @code{On}, says to display an asterisk
+(@samp{*}) at the start of history lines which have been modified.
+This variable is @code{off} by default.
+
+@item bell-style
+@vindex bell-style
+Controls what happens when Readline wants to ring the terminal bell.
+If set to @code{none}, Readline never rings the bell. If set to
+@code{visible}, Readline uses a visible bell if one is available.
+If set to @code{audible} (the default), Readline attempts to ring
+the terminal's bell.
+
+@item comment-begin
+@vindex comment-begin
+The string to insert at the beginning of the line when the
+@code{vi-comment} command is executed. The default value
+is @code{"#"}.
+
+@item meta-flag
+@vindex meta-flag
+If set to @code{on}, Readline will enable eight-bit input (it
+will not strip the eighth bit from the characters it reads),
+regardless of what the terminal claims it can support. The
+default value is @code{off}.
+
+@item convert-meta
+@vindex convert-meta
+If set to @code{on}, Readline will convert characters with the
+eigth bit set to an ASCII key sequence by stripping the eigth
+bit and prepending an @key{ESC} character, converting them to a
+meta-prefixed key sequence. The default value is @code{on}.
+
+@item output-meta
+@vindex output-meta
+If set to @code{on}, Readline will display characters with the
+eighth bit set directly rather than as a meta-prefixed escape
+sequence. The default is @code{off}.
+
+@item completion-query-items
+@vindex completion-query-items
+The number of possible completions that determines when the user is
+asked whether he wants to see the list of possibilities. If the
+number of possible completions is greater than this value,
+Readline will ask the user whether or not he wishes to view
+them; otherwise, they are simply listed. The default limit is
+@code{100}.
+
+@item keymap
+@vindex keymap
+Sets Readline's idea of the current keymap for key binding commands.
+Acceptable @code{keymap} names are
+@code{emacs},
+@code{emacs-standard},
+@code{emacs-meta},
+@code{emacs-ctlx},
+@code{vi},
+@code{vi-move},
+@code{vi-command}, and
+@code{vi-insert}.
+@code{vi} is equivalent to @code{vi-command}; @code{emacs} is
+equivalent to @code{emacs-standard}. The default value is @code{emacs}.
+The value of the @code{editing-mode} variable also affects the
+default keymap.
+
+@item show-all-if-ambiguous
+@vindex show-all-if-ambiguous
+This alters the default behavior of the completion functions. If
+set to @code{on},
+words which have more than one possible completion cause the
+matches to be listed immediately instead of ringing the bell.
+The default value is @code{off}.
+
+@item expand-tilde
+@vindex expand-tilde
+If set to @code{on}, tilde expansion is performed when Readline
+attempts word completion. The default is @code{off}.
-@item prefer-visible-bell
-@vindex prefer-visible-bell
-If this variable is set to @code{On} it means to use a visible bell if
-one is available, rather than simply ringing the terminal bell. By
-default, the value is @code{Off}.
@end table
@item Key Bindings
-The syntax for controlling keybindings in the @file{~/.inputrc} file is
-simple. First you have to know the @i{name} of the command that you
+The syntax for controlling key bindings in the init file is
+simple. First you have to know the name of the command that you
want to change. The following pages contain tables of the command name,
the default keybinding, and a short description of what the command
does.
Once you know the name of the command, simply place the name of the key
you wish to bind the command to, a colon, and then the name of the
-command on a line in the @file{~/.inputrc} file. The name of the key
+command on a line in the init file. The name of the key
can be expressed in different ways, depending on which is most
comfortable for you.
@@ -319,10 +399,11 @@ expressed on the right hand side (that is, to insert the text
@samp{>&output} into the line).
@item @w{"@var{keyseq}": @var{function-name} or @var{macro}}
-@var{keyseq} differs from @var{keyname} above in that strings denoting
-an entire key sequence can be specified. Simply place the key sequence
-in double quotes. GNU Emacs style key escapes can be used, as in the
-following example:
+@var{keyseq} differs from @var{keyname} above in that strings
+denoting an entire key sequence can be specified, by placing
+the key sequence in double quotes. Some GNU Emacs style key
+escapes can be used, as in the following example, but the
+special character names are not recognized.
@example
"\C-u": universal-argument
@@ -334,10 +415,98 @@ In the above example, @samp{C-u} is bound to the function
@code{universal-argument} (just as it was in the first example),
@samp{C-x C-r} is bound to the function @code{re-read-init-file}, and
@samp{ESC [ 1 1 ~} is bound to insert the text @samp{Function Key 1}.
+The following escape sequences are available when specifying key
+sequences:
+
+@table @code
+@item @kbd{\C-}
+control prefix
+@item @kbd{\M-}
+meta prefix
+@item @kbd{\e}
+an escape character
+@item @kbd{\\}
+backslash
+@item @kbd{\"}
+@key{"}
+@item @kbd{\'}
+@key{'}
+@end table
+
+When entering the text of a macro, single or double quotes should
+be used to indicate a macro definition. Unquoted text
+is assumed to be a function name. Backslash
+will quote any character in the macro text, including @key{"}
+and @key{'}.
+For example, the following binding will make @kbd{C-x \}
+insert a single @key{\} into the line:
+@example
+"\C-x\\": "\\"
+@end example
@end table
@end table
+@node Conditional Init Constructs
+@subsection Conditional Init Constructs
+
+Readline implements a facility similar in spirit to the conditional
+compilation features of the C preprocessor which allows key
+bindings and variable settings to be performed as the result
+of tests. There are three parser directives used.
+
+@ftable @code
+@item $if
+The @code{$if} construct allows bindings to be made based on the
+editing mode, the terminal being used, or the application using
+Readline. The text of the test extends to the end of the line;
+no characters are required to isolate it.
+
+@table @code
+@item mode
+The @code{mode=} form of the @code{$if} directive is used to test
+whether Readline is in @code{emacs} or @code{vi} mode.
+This may be used in conjunction
+with the @samp{set keymap} command, for instance, to set bindings in
+the @code{emacs-standard} and @code{emacs-ctlx} keymaps only if
+Readline is starting out in @code{emacs} mode.
+
+@item term
+The @code{term=} form may be used to include terminal-specific
+key bindings, perhaps to bind the key sequences output by the
+terminal's function keys. The word on the right side of the
+@samp{=} is tested against the full name of the terminal and the
+portion of the terminal name before the first @samp{-}. This
+allows @var{sun} to match both @var{sun} and @var{sun-cmd},
+for instance.
+
+@item application
+The @var{application} construct is used to include
+application-specific settings. Each program using the Readline
+library sets the @var{application name}, and you can test for it.
+This could be used to bind key sequences to functions useful for
+a specific program. For instance, the following command adds a
+key sequence that quotes the current or previous word in Bash:
+@example
+$if bash
+# Quote the current or previous word
+"\C-xq": "\eb\"\ef\""
+$endif
+@end example
+@end table
+
+@item $endif
+This command, as you saw in the previous example, terminates an
+@code{$if} command.
+
+@item $else
+Commands in this branch of the @code{$if} directive are executed if
+the test fails.
+@end ftable
+
+@node Bindable Readline Commands
+@section Bindable Readline Commands
+
@menu
* Commands For Moving:: Moving about the line.
* Commands For History:: Getting at previous lines.
@@ -345,11 +514,12 @@ In the above example, @samp{C-u} is bound to the function
* Commands For Killing:: Commands for killing and yanking.
* Numeric Arguments:: Specifying numeric arguments, repeat counts.
* Commands For Completion:: Getting Readline to do the typing for you.
-* Miscellaneous Commands:: Other miscillaneous commands.
+* Keyboard Macros:: Saving and re-executing typed characters
+* Miscellaneous Commands:: Other miscellaneous commands.
@end menu
@node Commands For Moving
-@subsubsection Commands For Moving
+@subsection Commands For Moving
@ftable @code
@item beginning-of-line (C-a)
Move to the start of the current line.
@@ -364,24 +534,38 @@ Move forward a character.
Move back a character.
@item forward-word (M-f)
-Move forward to the end of the next word.
+Move forward to the end of the next word. Words are composed of
+letters and digits.
@item backward-word (M-b)
-Move back to the start of this, or the previous, word.
+Move back to the start of this, or the previous, word. Words are
+composed of letters and digits.
@item clear-screen (C-l)
-Clear the screen leaving the current line at the top of the screen.
+Clear the screen and redraw the current line,
+leaving the current line at the top of the screen.
+
+@item redraw-current-line ()
+Refresh the current line. By default, this is unbound.
@end ftable
@node Commands For History
-@subsubsection Commands For Manipulating The History
+@subsection Commands For Manipulating The History
@ftable @code
@item accept-line (Newline, Return)
+@ifset BashFeatures
+Accept the line regardless of where the cursor is. If this line is
+non-empty, add it to the history list according to the setting of
+the @code{HISTCONTROL} variable. If this line was a history
+line, then restore the history line to its original state.
+@end ifset
+@ifclear BashFeatures
Accept the line regardless of where the cursor is. If this line is
non-empty, add it to the history list. If this line was a history
line, then restore the history line to its original state.
+@end ifclear
@item previous-history (C-p)
Move `up' through the history list.
@@ -393,7 +577,7 @@ Move `down' through the history list.
Move to the first line in the history.
@item end-of-history (M->)
-Move to the end of the input history, i.e., the line you are entering!
+Move to the end of the input history, i.e., the line you are entering.
@item reverse-search-history (C-r)
Search backward starting at the current line and moving `up' through
@@ -401,17 +585,44 @@ the history as necessary. This is an incremental search.
@item forward-search-history (C-s)
Search forward starting at the current line and moving `down' through
-the the history as neccessary.
+the the history as necessary. This is an incremental search.
+
+@item non-incremental-reverse-search-history (M-p)
+Search backward starting at the current line and moving `up'
+through the history as necessary using a non-incremental search
+for a string supplied by the user.
+
+@item non-incremental-forward-search-history (M-n)
+Search forward starting at the current line and moving `down'
+through the the history as necessary using a non-incremental search
+for a string supplied by the user.
+
+@item history-search-forward ()
+Search forward through the history for the string of characters
+between the start of the current line and the current point. This
+is a non-incremental search. By default, this command is unbound.
+
+@item history-search-backward ()
+Search backward through the history for the string of characters
+between the start of the current line and the current point. This
+is a non-incremental search. By default, this command is unbound.
+
+@item yank-nth-arg (M-C-y)
+Insert the first argument to the previous command (usually
+the second word on the previous line). With an argument @var{n},
+insert the @var{n}th word from the previous command (the words
+in the previous command begin with word 0). A negative argument
+inserts the @var{n}th word from the end of the previous command.
@end ftable
@node Commands For Text
-@subsubsection Commands For Changing Text
+@subsection Commands For Changing Text
@ftable @code
@item delete-char (C-d)
Delete the character under the cursor. If the cursor is at the
-beginning of the line, and there are no characters in the line, and
+beginning of the line, there are no characters in the line, and
the last character typed was not C-d, then return EOF.
@item backward-delete-char (Rubout)
@@ -420,7 +631,7 @@ the characters instead of deleting them.
@item quoted-insert (C-q, C-v)
Add the next character that you type to the line verbatim. This is
-how to insert things like C-q for example.
+how to insert key sequences like @key{C-q}, for example.
@item tab-insert (M-TAB)
Insert a tab character.
@@ -429,9 +640,12 @@ Insert a tab character.
Insert yourself.
@item transpose-chars (C-t)
-Drag the character before point forward over the character at point.
-Point moves forward as well. If point is at the end of the line, then
-transpose the two characters before point. Negative args don't work.
+Drag the character before the cursor forward over
+the character at the cursor, moving the
+cursor forward as well. If the insertion point
+is at the end of the line, then this
+transposes the last two characters of the line.
+Negative argumentss don't work.
@item transpose-words (M-t)
Drag the word behind the cursor past the word in front of the cursor
@@ -439,47 +653,56 @@ moving the cursor over that word as well.
@item upcase-word (M-u)
Uppercase the current (or following) word. With a negative argument,
-do the previous word, but do not move point.
+do the previous word, but do not move the cursor.
@item downcase-word (M-l)
Lowercase the current (or following) word. With a negative argument,
-do the previous word, but do not move point.
+do the previous word, but do not move the cursor.
@item capitalize-word (M-c)
-Uppercase the current (or following) word. With a negative argument,
-do the previous word, but do not move point.
+Capitalize the current (or following) word. With a negative argument,
+do the previous word, but do not move the cursor.
@end ftable
@node Commands For Killing
-@subsubsection Killing And Yanking
+@subsection Killing And Yanking
@ftable @code
@item kill-line (C-k)
Kill the text from the current cursor position to the end of the line.
-@item backward-kill-line ()
-Kill backward to the beginning of the line. This is normally unbound.
+@item backward-kill-line (C-x Rubout)
+Kill backward to the beginning of the line.
+
+@item unix-line-discard (C-u)
+Kill backward from the cursor to the beginning of the current line.
+Save the killed text on the kill-ring.
+
+@item kill-whole-line ()
+Kill all characters on the current line, no matter where the
+cursor is. By default, this is unbound.
@item kill-word (M-d)
Kill from the cursor to the end of the current word, or if between
-words, to the end of the next word.
+words, to the end of the next word. Word boundaries are the same
+as @code{forward-word}.
@item backward-kill-word (M-DEL)
-Kill the word behind the cursor.
-
-@item unix-line-discard (C-u)
-Do what C-u used to do in Unix line input. We save the killed text on
-the kill-ring, though.
+Kill the word behind the cursor. Word boundaries are the same
+as @code{backward-word}.
@item unix-word-rubout (C-w)
-Do what C-w used to do in Unix line input. The killed text is saved
-on the kill-ring. This is different than backward-kill-word because
-the word boundaries differ.
+Kill the word behind the cursor, using white space as a word
+boundary. The killed text is saved on the kill-ring.
+
+@item delete-horizontal-space ()
+Delete all spaces and tabs around point. By default, this is unbound.
@item yank (C-y)
-Yank the top of the kill ring into the buffer at point.
+Yank the top of the kill ring into the buffer at the current
+cursor position.
@item yank-pop (M-y)
Rotate the kill-ring, and yank the new top. You can only do this if
@@ -487,7 +710,7 @@ the prior command is yank or yank-pop.
@end ftable
@node Numeric Arguments
-@subsubsection Specifying Numeric Arguments
+@subsection Specifying Numeric Arguments
@ftable @code
@item digit-argument (M-0, M-1, ... M--)
@@ -495,64 +718,148 @@ Add this digit to the argument already accumulating, or start a new
argument. M-- starts a negative argument.
@item universal-argument ()
-Do what C-u does in emacs. By default, this is not bound.
+Each time this is executed, the argument count is multiplied by four.
+The argument count is initially one, so executing this function the
+first time makes the argument count four. By default, this is not
+bound to a key.
@end ftable
-
@node Commands For Completion
-@subsubsection Letting Readline Type For You
+@subsection Letting Readline Type For You
@ftable @code
@item complete (TAB)
-Attempt to do completion on the text before point. This is
+Attempt to do completion on the text before the cursor. This is
implementation defined. Generally, if you are typing a filename
argument, you can do filename completion; if you are typing a command,
you can do command completion, if you are typing in a symbol to GDB, you
can do symbol name completion, if you are typing in a variable to Bash,
-you can do variable name completion...
+you can do variable name completion, and so on.
+@ifset BashFeatures
+See the Bash manual page for a complete list of available completion
+functions.
+@end ifset
@item possible-completions (M-?)
-List the possible completions of the text before point.
+List the possible completions of the text before the cursor.
+
+@item insert-completions ()
+Insert all completions of the text before point that would have
+been generated by @code{possible-completions}. By default, this
+is not bound to a key.
+
+@end ftable
+
+@node Keyboard Macros
+@subsection Keyboard Macros
+@ftable @code
+
+@item start-kbd-macro (C-x ()
+Begin saving the characters typed into the current keyboard macro.
+
+@item end-kbd-macro (C-x ))
+Stop saving the characters typed into the current keyboard macro
+and save the definition.
+
+@item call-last-kbd-macro (C-x e)
+Re-execute the last keyboard macro defined, by making the characters
+in the macro appear as if typed at the keyboard.
+
@end ftable
@node Miscellaneous Commands
-@subsubsection Some Miscellaneous Commands
+@subsection Some Miscellaneous Commands
@ftable @code
@item re-read-init-file (C-x C-r)
-Read in the contents of your @file{~/.inputrc} file, and incorporate
-any bindings found there.
+Read in the contents of your init file, and incorporate
+any bindings or variable assignments found there.
@item abort (C-g)
-Ding! Stops things.
+Abort the current editing command and
+ring the terminal's bell (subject to the setting of
+@code{bell-style}).
@item do-uppercase-version (M-a, M-b, ...)
-Run the command that is bound to your uppercase brother.
+Run the command that is bound to the corresoponding uppercase
+character.
@item prefix-meta (ESC)
Make the next character that you type be metafied. This is for people
without a meta key. Typing @samp{ESC f} is equivalent to typing
@samp{M-f}.
-@item undo (C-_)
+@item undo (C-_, C-x C-u)
Incremental undo, separately remembered for each line.
@item revert-line (M-r)
-Undo all changes made to this line. This is like typing the `undo'
+Undo all changes made to this line. This is like typing the @code{undo}
command enough times to get back to the beginning.
+
+@item tilde-expand (M-~)
+Perform tilde expansion on the current word.
+
+@item dump-functions ()
+Print all of the functions and their key bindings to the
+readline output stream. If a numeric argument is supplied,
+the output is formatted in such a way that it can be made part
+of an @var{inputrc} file.
+
+@ifset BashFeatures
+@item display-shell-version (C-x C-v)
+Display version information about the current instance of Bash.
+
+@item shell-expand-line (M-C-e)
+Expand the line the way the shell does when it reads it. This
+performs alias and history expansion as well as all of the shell
+word expansions.
+
+@item history-expand-line (M-^)
+Perform history expansion on the current line.
+
+@item insert-last-argument (M-., M-_)
+Insert the last argument to the previous command (the last word on
+the previous line). With an argument @var{n},
+insert the @var{n}th word from the previous command (the words
+in the previous command begin with word 0). A negative argument
+inserts the @var{n}th word from the end of the previous command.
+
+@item operate-and-get-next (C-o)
+Accept the current line for execution and fetch the next line
+relative to the current line from the history for editing. Any
+argument is ignored.
+
+@item emacs-editing-mode (C-e)
+When in @code{vi} editing mode, this causes a switch back to
+emacs editing mode, as if the command @code{set -o emacs} had
+been executed.
+
+@end ifset
+
@end ftable
-@node Readline Vi Mode
-@subsection Readline Vi Mode
+@node Readline vi Mode
+@section Readline vi Mode
-While the Readline library does not have a full set of Vi editing
-functions, it does contain enough to allow simple editing of the line.
+While the Readline library does not have a full set of @code{vi}
+editing functions, it does contain enough to allow simple editing
+of the line. The Readline @code{vi} mode behaves as specified in
+the Posix 1003.2 standard.
-In order to switch interactively between Emacs and Vi editing modes, use
-the command M-C-j (toggle-editing-mode).
+@ifset BashFeatures
+In order to switch interactively between @code{Emacs} and @code{Vi}
+editing modes, use the @code{set -o emacs} and @code{set -o vi}
+commands (@pxref{The Set Builtin}).
+@end ifset
+@ifclear BashFeatures
+In order to switch interactively between @code{Emacs} and @code{Vi}
+editing modes, use the command M-C-j (toggle-editing-mode).
+@end ifclear
+The Readline default is @code{emacs} mode.
-When you enter a line in Vi mode, you are already placed in `insertion'
-mode, as if you had typed an `i'. Pressing @key{ESC} switches you into
-`edit' mode, where you can edit the text of the line with the standard
-Vi movement keys, move to previous history lines with `k', and following
-lines with `j', and so forth.
+When you enter a line in @code{vi} mode, you are already placed in
+`insertion' mode, as if you had typed an @samp{i}. Pressing @key{ESC}
+switches you into `command' mode, where you can edit the text of the
+line with the standard @code{vi} movement keys, move to previous
+history lines with @samp{k}, and following lines with @samp{j}, and
+so forth.
diff --git a/gnu/lib/libreadline/doc/texindex.c b/gnu/lib/libreadline/doc/texindex.c
index cb979da7afac..9233bab12690 100644
--- a/gnu/lib/libreadline/doc/texindex.c
+++ b/gnu/lib/libreadline/doc/texindex.c
@@ -1,9 +1,12 @@
-/* Prepare Tex index dribble output into an actual index.
- Copyright (C) 1987 Free Software Foundation, Inc.
+/* Prepare TeX index dribble output into an actual index.
+
+ Version 1.45
+
+ Copyright (C) 1987, 1991, 1992 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 1, or (at your option)
+ the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
@@ -13,137 +16,124 @@
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., 675 Mass Ave, Cambridge, MA 02139, USA. */
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
+
#include <stdio.h>
#include <ctype.h>
#include <errno.h>
-extern int errno;
+#include "getopt.h"
+#include "bashansi.h"
-#ifdef VMS
-#ifndef VAX11C
-#define noshare
+#if !defined (errno)
+extern int errno;
#endif
-#include <perror.h>
-#include <file.h>
+#if defined (HAVE_UNISTD_H)
+# include <unistd.h>
+#else /* !HAVE_UNISTD_H */
+extern long lseek ();
+#endif /* !HAVE_UNISTD_H */
-#define EXIT_SUCCESS ((1 << 28) | 1)
-#define EXIT_FATAL ((1 << 28) | 4)
-#define unlink delete
-#define tell(fd) lseek(fd, 0L, 1)
-
-#else /* Not VMS */
+extern char *mktemp ();
-#ifdef USG
-#include <sys/types.h>
-#include <sys/fcntl.h>
+#if !defined (HAVE_STRERROR)
+extern int sys_nerr;
+extern char *sys_errlist[];
#endif
-#include <sys/file.h>
-#define EXIT_SUCCESS 0
-#define EXIT_FATAL 1
+#include <sys/types.h>
-#endif /* Not VMS */
+#if defined (_AIX) || !defined (_POSIX_VERSION)
+# include <sys/file.h>
+#endif
+#include <fcntl.h>
-#ifndef L_XTND
-#define L_XTND 2
-#endif
+#define TI_NO_ERROR 0
+#define TI_FATAL_ERROR 1
-#ifdef VMS
-extern noshare int sys_nerr;
-extern noshare char *sys_errlist[];
-#else
-extern int sys_nerr;
-extern char *sys_errlist[];
-#endif
+#if !defined (SEEK_SET)
+# define SEEK_SET 0
+# define SEEK_CUR 1
+# define SEEK_END 2
+#endif /* !SEEK_SET */
/* When sorting in core, this structure describes one line
- and the position and length of its first keyfield. */
-
+ and the position and length of its first keyfield. */
struct lineinfo
- {
- char *text; /* The actual text of the line */
- union
- { /* The start of the key (for textual comparison) */
- char *text;
- long number; /* or the numeric value (for numeric comparison) */
- } key;
- long keylen; /* Length of key field */
- };
-
-/* This structure describes a field to use as a sort key */
+{
+ 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). */
+ } key;
+ long keylen; /* Length of KEY field. */
+};
+/* This structure describes a field to use as a sort key. */
struct keyfield
- {
- int startwords; /* # words to skip */
- int startchars; /* and # additional chars to skip, to start of field */
- int endwords; /* similar, from beg (or end) of line, to find end of field */
- int endchars;
- char ignore_blanks; /* Ignore spaces and tabs within the field */
- char fold_case; /* Convert upper case to lower before comparing */
- char reverse; /* Compare in reverse order */
- char numeric; /* Parse text as an integer and compare the integers */
- char positional; /* Sort according to position within the file */
- char braced; /* Count balanced-braced groupings as fields */
- };
-
-/* Vector of keyfields to use */
+{
+ 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. */
struct keyfield keyfields[3];
/* Number of keyfields stored in that vector. */
-
int num_keyfields = 3;
-/* Vector of input file names, terminated with a zero (null pointer) */
-
+/* Vector of input file names, terminated with a null pointer. */
char **infiles;
-/* Vector of corresponding output file names, or zero meaning default it */
-
+/* Vector of corresponding output file names, or NULL, meaning default it
+ (add an `s' to the end). */
char **outfiles;
-/* Length of `infiles' */
-
+/* Length of `infiles'. */
int num_infiles;
-/* Pointer to the array of pointers to lines being sorted */
-
+/* Pointer to the array of pointers to lines being sorted. */
char **linearray;
/* The allocated length of `linearray'. */
-
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;
/* Number of last temporary file already deleted.
- Temporary files are deleted by `flush_tempfiles' in order of creation. */
-
+ Temporary files are deleted by `flush_tempfiles' in order of creation. */
int last_deleted_tempcount;
/* During in-core sort, this points to the base of the data block
- which contains all the lines of data. */
-
+ which contains all the lines of data. */
char *text_base;
-/* Additional command switches */
+/* Additional command switches .*/
-int keep_tempfiles; /* Nonzero means do not delete tempfiles -- for debugging */
+/* Nonzero means do not delete tempfiles -- for debugging. */
+int keep_tempfiles;
-/* Forward declarations of functions in this file */
+/* The name this program was run with. */
+char *program_name;
+
+/* Forward declarations of functions in this file. */
void decode_command ();
void sort_in_core ();
@@ -155,20 +145,23 @@ long find_value ();
char *find_braced_pos ();
char *find_braced_end ();
void writelines ();
+int compare_field ();
int compare_full ();
long readline ();
int merge_files ();
int merge_direct ();
+void pfatal_with_name ();
+void fatal ();
+void error ();
+void *xmalloc (), *xrealloc ();
char *concat ();
char *maketempname ();
void flush_tempfiles ();
char *tempcopy ();
-
-extern char *mktemp ();
#define MAX_IN_CORE_SORT 500000
-int
+void
main (argc, argv)
int argc;
char **argv;
@@ -177,21 +170,24 @@ main (argc, argv)
tempcount = 0;
last_deleted_tempcount = 0;
+ program_name = argv[0];
/* Describe the kind of sorting to do. */
- /* The first keyfield uses the first braced field and folds case */
+ /* The first keyfield uses the first braced field and folds case. */
keyfields[0].braced = 1;
keyfields[0].fold_case = 1;
keyfields[0].endwords = -1;
keyfields[0].endchars = -1;
- /* The second keyfield uses the second braced field, numerically */
+
+ /* The second keyfield uses the second braced field, numerically. */
keyfields[1].braced = 1;
keyfields[1].numeric = 1;
keyfields[1].startwords = 1;
keyfields[1].endwords = -1;
keyfields[1].endchars = -1;
+
/* The third keyfield (which is ignored while discarding duplicates)
- compares the whole line */
+ compares the whole line. */
keyfields[2].endwords = -1;
keyfields[2].endchars = -1;
@@ -206,12 +202,13 @@ main (argc, argv)
int desc;
long ptr;
char *outfile;
- char *p;
- desc = open (infiles[i], 0, 0);
- if (desc < 0) pfatal_with_name (infiles[i]);
- lseek (desc, 0, L_XTND);
- ptr = tell (desc);
+ desc = open (infiles[i], O_RDONLY, 0);
+ if (desc < 0)
+ pfatal_with_name (infiles[i]);
+ lseek (desc, 0L, SEEK_END);
+ ptr = lseek (desc, 0L, SEEK_CUR);
+
close (desc);
outfile = outfiles[i];
@@ -221,107 +218,84 @@ main (argc, argv)
}
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 (EXIT_SUCCESS);
+ exit (TI_NO_ERROR);
}
-/* This page decodes the command line arguments to set the parameter variables
- and set up the vector of keyfields and the vector of input files */
+void
+usage ()
+{
+ fprintf (stderr, "\
+Usage: %s [-k] infile [-o outfile] ...\n", program_name);
+ exit (1);
+}
+
+/* Decode the command line arguments to set the parameter variables
+ and set up the vector of keyfields and the vector of input files. */
void
decode_command (argc, argv)
int argc;
char **argv;
{
- int i;
+ int optc;
char **ip;
char **op;
- /* Store default values into parameter variables */
+ /* Store default values into parameter variables. */
-#ifdef VMS
- tempdir = "sys$scratch:";
-#else
- tempdir = "/tmp/";
-#endif
+ tempdir = getenv ("TMPDIR");
+ if (tempdir == NULL)
+ tempdir = "/tmp/";
+ else
+ tempdir = concat (tempdir, "/", "");
keep_tempfiles = 0;
- /* Allocate argc input files, which must be enough. */
+ /* Allocate ARGC input files, which must be enough. */
infiles = (char **) xmalloc (argc * sizeof (char *));
outfiles = (char **) xmalloc (argc * sizeof (char *));
ip = infiles;
op = outfiles;
- /* First find all switches that control the default kind-of-sort */
-
- for (i = 1; i < argc; i++)
+ while ((optc = getopt (argc, argv, "-ko:")) != EOF)
{
- int tem = classify_arg (argv[i]);
- char c;
- char *p;
-
- if (tem <= 0)
+ switch (optc)
{
- *ip++ = argv[i];
- *op++ = 0;
- continue;
- }
- if (tem > 1)
- {
- if (i + 1 == argc)
- fatal ("switch %s given with no argument following it", argv[i]);
- else if (!strcmp (argv[i], "-T"))
- tempdir = argv[i + 1];
- else if (!strcmp (argv[i], "-o"))
- *(op - 1) = argv[i + 1];
- i += tem - 1;
- continue;
- }
+ case 1: /* Non-option filename. */
+ *ip++ = optarg;
+ *op++ = NULL;
+ break;
- p = &argv[i][1];
- while (c = *p++)
- switch (c)
- {
- case 'k':
- keep_tempfiles = 1;
- break;
+ case 'k':
+ keep_tempfiles = 1;
+ break;
- default:
- fatal ("invalid command switch %c", c);
- }
- switchdone: ;
- }
+ case 'o':
+ if (op > outfiles)
+ *(op - 1) = optarg;
+ break;
- /* Record number of keyfields, terminate list of filenames */
+ default:
+ usage ();
+ }
+ }
+ /* Record number of keyfields and terminate list of filenames. */
num_infiles = ip - infiles;
*ip = 0;
-}
-
-/* Return 0 for an argument that is not a switch;
- for a switch, return 1 plus the number of following arguments that the switch swallows.
-*/
-
-int
-classify_arg (arg)
- char *arg;
-{
- if (!strcmp (arg, "-T") || !strcmp (arg, "-o"))
- return 2;
- if (arg[0] == '-')
- return 1;
- return 0;
+ if (num_infiles == 0)
+ usage ();
}
-/* Create a name for a temporary file */
+/* Return a name for a temporary file. */
char *
maketempname (count)
@@ -332,18 +306,20 @@ maketempname (count)
return concat (tempdir, tempbase, tempsuffix);
}
-/* Delete all temporary files up to the specified count */
+/* Delete all temporary files up to TO_COUNT. */
void
flush_tempfiles (to_count)
int to_count;
{
- if (keep_tempfiles) return;
+ if (keep_tempfiles)
+ return;
while (last_deleted_tempcount < to_count)
unlink (maketempname (++last_deleted_tempcount));
}
-/* Copy an input file into a temporary file, and return the temporary file name */
+/* Copy the input file open on IDESC into a temporary file
+ and return the temporary file name. */
#define BUFSIZE 1024
@@ -357,13 +333,15 @@ tempcopy (idesc)
odesc = open (outfile, O_WRONLY | O_CREAT, 0666);
- if (odesc < 0) pfatal_with_name (outfile);
+ if (odesc < 0)
+ pfatal_with_name (outfile);
while (1)
{
int nread = read (idesc, buffer, BUFSIZE);
write (odesc, buffer, nread);
- if (!nread) break;
+ if (!nread)
+ break;
}
close (odesc);
@@ -371,8 +349,7 @@ tempcopy (idesc)
return outfile;
}
-/* Compare two lines, provided as pointers to pointers to text,
- according to the specified set of keyfields */
+/* Compare LINE1 and LINE2 according to the specified set of keyfields. */
int
compare_full (line1, line2)
@@ -381,7 +358,8 @@ compare_full (line1, line2)
int i;
/* Compare using the first keyfield;
- if that does not distinguish the lines, try the second keyfield; and so on. */
+ if that does not distinguish the lines, try the second keyfield;
+ and so on. */
for (i = 0; i < num_keyfields; i++)
{
@@ -389,22 +367,22 @@ 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;
+ return -tem;
+ return tem;
}
}
- return 0; /* Lines match exactly */
+ return 0; /* Lines match exactly. */
}
-/* Compare two lines described by structures
- in which the first keyfield is identified in advance.
- For positional sorting, assumes that the order of the lines in core
- reflects their nominal order. */
+/* Compare LINE1 and LINE2, described by structures
+ in which the first keyfield is identified in advance.
+ For positional sorting, assumes that the order of the lines in core
+ reflects their nominal order. */
int
compare_prepared (line1, line2)
@@ -414,7 +392,7 @@ compare_prepared (line1, line2)
int tem;
char *text1, *text2;
- /* Compare using the first keyfield, which has been found for us already */
+ /* Compare using the first keyfield, which has been found for us already. */
if (keyfields->positional)
{
if (line1->text - text_base > line2->text - text_base)
@@ -425,11 +403,12 @@ compare_prepared (line1, line2)
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);
+ tem = compare_field (keyfields, line1->key.text, line1->keylen, 0,
+ line2->key.text, line2->keylen, 0);
if (tem)
{
if (keyfields->reverse)
- return - tem;
+ return -tem;
return tem;
}
@@ -437,7 +416,8 @@ compare_prepared (line1, line2)
text2 = line2->text;
/* Compare using the second keyfield;
- if that does not distinguish the lines, try the third keyfield; and so on. */
+ if that does not distinguish the lines, try the third keyfield;
+ and so on. */
for (i = 1; i < num_keyfields; i++)
{
@@ -445,22 +425,22 @@ 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;
+ return -tem;
+ return tem;
}
}
- return 0; /* Lines match exactly */
+ return 0; /* Lines match exactly. */
}
/* Like compare_full but more general.
- You can pass any strings, and you can say how many keyfields to use.
- `pos1' and `pos2' should indicate the nominal positional ordering of
- the two lines in the input. */
+ You can pass any strings, and you can say how many keyfields to use.
+ POS1 and POS2 should indicate the nominal positional ordering of
+ the two lines in the input. */
int
compare_general (str1, str2, pos1, pos2, use_keyfields)
@@ -471,28 +451,30 @@ compare_general (str1, str2, pos1, pos2, use_keyfields)
int i;
/* Compare using the first keyfield;
- if that does not distinguish the lines, try the second keyfield; and so on. */
+ if that does not distinguish the lines, try the second keyfield;
+ and so on. */
for (i = 0; i < use_keyfields; i++)
{
long length1, length2;
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);
+ int tem = compare_field (&keyfields[i], start1, length1, pos1,
+ start2, length2, pos2);
if (tem)
{
if (keyfields[i].reverse)
- return - tem;
- return tem;
+ 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'.
- A pointer to the starting character is returned, and the length
- is stored into the int that `lengthptr' points to. */
+/* Find the start and length of a field in STR according to KEYFIELD.
+ A pointer to the starting character is returned, and the length
+ is stored into the int that LENGTHPTR points to. */
char *
find_field (keyfield, str, lengthptr)
@@ -504,11 +486,13 @@ find_field (keyfield, str, lengthptr)
char *end;
char *(*fun) ();
- if (keyfield->braced) fun = find_braced_pos;
- else fun = find_pos;
+ if (keyfield->braced)
+ fun = find_braced_pos;
+ else
+ fun = find_pos;
- start = ( *fun )(str, keyfield->startwords, keyfield->startchars,
- keyfield->ignore_blanks);
+ start = (*fun) (str, keyfield->startwords, keyfield->startchars,
+ keyfield->ignore_blanks);
if (keyfield->endwords < 0)
{
if (keyfield->braced)
@@ -516,22 +500,24 @@ find_field (keyfield, str, lengthptr)
else
{
end = start;
- while (*end && *end != '\n') end++;
+ while (*end && *end != '\n')
+ end++;
}
}
else
{
- end = ( *fun )(str, keyfield->endwords, keyfield->endchars, 0);
- if (end - str < start - str) end = start;
+ end = (*fun) (str, keyfield->endwords, keyfield->endchars, 0);
+ if (end - str < start - str)
+ end = start;
}
*lengthptr = end - start;
return start;
}
-/* Find a pointer to a specified place within `str',
- skipping (from the beginning) `words' words and then `chars' chars.
- If `ignore_blanks' is nonzero, we skip all blanks
- after finding the specified word. */
+/* Return a pointer to a specified place within STR,
+ skipping (from the beginning) WORDS words and then CHARS chars.
+ If IGNORE_BLANKS is nonzero, we skip all blanks
+ after finding the specified word. */
char *
find_pos (str, words, chars, ignore_blanks)
@@ -546,23 +532,28 @@ find_pos (str, words, chars, ignore_blanks)
{
char c;
/* Find next bunch of nonblanks and skip them. */
- while ((c = *p) == ' ' || c == '\t') p++;
- while ((c = *p) && c != '\n' && !(c == ' ' || c == '\t')) p++;
- if (!*p || *p == '\n') return p;
+ while ((c = *p) == ' ' || c == '\t')
+ p++;
+ while ((c = *p) && c != '\n' && !(c == ' ' || c == '\t'))
+ p++;
+ if (!*p || *p == '\n')
+ return p;
}
- while (*p == ' ' || *p == '\t') p++;
+ while (*p == ' ' || *p == '\t')
+ p++;
for (i = 0; i < chars; i++)
{
- if (!*p || *p == '\n') break;
+ if (!*p || *p == '\n')
+ break;
p++;
}
return p;
}
/* Like find_pos but assumes that each field is surrounded by braces
- and that braces within fields are balanced. */
+ and that braces within fields are balanced. */
char *
find_braced_pos (str, words, chars, ignore_blanks)
@@ -578,39 +569,43 @@ find_braced_pos (str, words, chars, ignore_blanks)
for (i = 0; i < words; i++)
{
bracelevel = 1;
- while ((c = *p++) != '{' && c != '\n' && c);
+ while ((c = *p++) != '{' && c != '\n' && c)
+ /* Do nothing. */ ;
if (c != '{')
return p - 1;
while (bracelevel)
{
c = *p++;
- if (c == '{') bracelevel++;
- if (c == '}') bracelevel--;
-#if 0
- if (c == '\\' || c == '@') c = *p++; /* \ quotes braces and \ */
-#endif
- if (c == 0 || c == '\n') return p-1;
+ if (c == '{')
+ bracelevel++;
+ if (c == '}')
+ bracelevel--;
+ if (c == 0 || c == '\n')
+ return p - 1;
}
}
- while ((c = *p++) != '{' && c != '\n' && c);
+ while ((c = *p++) != '{' && c != '\n' && c)
+ /* Do nothing. */ ;
if (c != '{')
- return p-1;
+ return p - 1;
if (ignore_blanks)
- while ((c = *p) == ' ' || c == '\t') p++;
-
+ while ((c = *p) == ' ' || c == '\t')
+ p++;
+
for (i = 0; i < chars; i++)
{
- if (!*p || *p == '\n') break;
+ if (!*p || *p == '\n')
+ break;
p++;
}
return p;
}
-/* Find the end of the balanced-brace field which starts at `str'.
- The position returned is just before the closing brace. */
+/* Find the end of the balanced-brace field which starts at STR.
+ The position returned is just before the closing brace. */
char *
find_braced_end (str)
@@ -624,12 +619,12 @@ find_braced_end (str)
while (bracelevel)
{
c = *p++;
- if (c == '{') bracelevel++;
- if (c == '}') bracelevel--;
-#if 0
- if (c == '\\' || c == '@') c = *p++;
-#endif
- if (c == 0 || c == '\n') return p-1;
+ if (c == '{')
+ bracelevel++;
+ if (c == '}')
+ bracelevel--;
+ if (c == 0 || c == '\n')
+ return p - 1;
}
return p - 1;
}
@@ -639,12 +634,13 @@ find_value (start, length)
char *start;
long length;
{
- while (length != 0L) {
- if (isdigit(*start))
- return atol(start);
- length--;
- start++;
- }
+ while (length != 0L)
+ {
+ if (isdigit (*start))
+ return atol (start);
+ length--;
+ start++;
+ }
return 0l;
}
@@ -653,6 +649,7 @@ find_value (start, length)
and ignore case in the first sorting. */
int char_order[256];
+void
init_char_order ()
{
int i;
@@ -662,14 +659,16 @@ init_char_order ()
for (i = '0'; i <= '9'; i++)
char_order[i] += 512;
- for (i = 'a'; i <= 'z'; i++) {
- char_order[i] = 512 + i;
- char_order[i + 'A' - 'a'] = 512 + i;
- }
+ for (i = 'a'; i <= 'z'; i++)
+ {
+ char_order[i] = 512 + i;
+ char_order[i + 'A' - 'a'] = 512 + i;
+ }
}
/* Compare two fields (each specified as a start pointer and a character count)
- according to `keyfield'. The sign of the value reports the relation between the fields */
+ according to KEYFIELD.
+ The sign of the value reports the relation between the fields. */
int
compare_field (keyfield, start1, length1, pos1, start2, length2, pos2)
@@ -690,9 +689,11 @@ compare_field (keyfield, start1, length1, pos1, start2, length2, pos2)
}
if (keyfield->numeric)
{
- long value = find_value (start1, length1) - find_value (start2, length2);
- if (value > 0) return 1;
- if (value < 0) return -1;
+ long value = find_value (start1, length1) - find_value (start2, length2);
+ if (value > 0)
+ return 1;
+ if (value < 0)
+ return -1;
return 0;
}
else
@@ -702,20 +703,23 @@ compare_field (keyfield, start1, length1, pos1, start2, length2, pos2)
char *e1 = start1 + length1;
char *e2 = start2 + length2;
- int fold_case = keyfield->fold_case;
-
while (1)
{
int c1, c2;
- if (p1 == e1) c1 = 0;
- else c1 = *p1++;
- if (p2 == e2) c2 = 0;
- else c2 = *p2++;
+ 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;
+ if (!c1)
+ break;
}
/* Strings are equal except possibly for case. */
@@ -725,15 +729,20 @@ compare_field (keyfield, start1, length1, pos1, start2, length2, pos2)
{
int c1, c2;
- if (p1 == e1) c1 = 0;
- else c1 = *p1++;
- if (p2 == e2) c2 = 0;
- else c2 = *p2++;
+ 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;
+ if (!c1)
+ break;
}
return 0;
@@ -741,16 +750,16 @@ compare_field (keyfield, start1, length1, pos1, start2, length2, pos2)
}
/* A `struct linebuffer' is a structure which holds a line of text.
- `readline' reads a line from a stream into a linebuffer
- and works regardless of the length of the line. */
+ `readline' reads a line from a stream into a linebuffer
+ and works regardless of the length of the line. */
struct linebuffer
- {
- long size;
- char *buffer;
- };
+{
+ long size;
+ char *buffer;
+};
-/* Initialize a linebuffer for use */
+/* Initialize LINEBUFFER for use. */
void
initbuffer (linebuffer)
@@ -760,8 +769,8 @@ initbuffer (linebuffer)
linebuffer->buffer = (char *) xmalloc (200);
}
-/* Read a line of text from `stream' into `linebuffer'.
- Return the length of the line. */
+/* Read a line of text from STREAM into LINEBUFFER.
+ Return the length of the line. */
long
readline (linebuffer, stream)
@@ -798,10 +807,12 @@ readline (linebuffer, stream)
void
sort_offline (infile, nfiles, total, outfile)
char *infile;
+ int nfiles;
long total;
char *outfile;
{
- int ntemps = 2 * (total + MAX_IN_CORE_SORT - 1) / MAX_IN_CORE_SORT; /* More than enough */
+ /* More than enough. */
+ int ntemps = 2 * (total + MAX_IN_CORE_SORT - 1) / MAX_IN_CORE_SORT;
char **tempfiles = (char **) xmalloc (ntemps * sizeof (char *));
FILE *istream = fopen (infile, "r");
int i;
@@ -822,7 +833,7 @@ sort_offline (infile, nfiles, total, outfile)
}
/* Split up the input into `ntemps' temporary files, or maybe fewer,
- and put the new files' names into `tempfiles' */
+ and put the new files' names into `tempfiles' */
for (i = 0; i < ntemps; i++)
{
@@ -830,11 +841,12 @@ sort_offline (infile, nfiles, total, outfile)
FILE *ostream = fopen (outname, "w");
long tempsize = 0;
- if (!ostream) pfatal_with_name (outname);
+ if (!ostream)
+ 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. */
+ /* Copy lines into this temp file as long as it does not make file
+ "too big" or until there are no more lines. */
while (tempsize + linelength + 1 <= MAX_IN_CORE_SORT)
{
@@ -845,7 +857,8 @@ sort_offline (infile, nfiles, total, outfile)
/* Read another line of input data. */
linelength = readline (&lb, istream);
- if (!linelength && feof (istream)) break;
+ if (!linelength && feof (istream))
+ break;
if (lb.buffer[0] != '\\' && lb.buffer[0] != '@')
{
@@ -855,39 +868,41 @@ sort_offline (infile, nfiles, total, outfile)
}
}
fclose (ostream);
- if (feof (istream)) break;
+ if (feof (istream))
+ break;
}
free (lb.buffer);
- fail:
+fail:
/* Record number of temp files we actually needed. */
ntemps = i;
/* Sort each tempfile into another tempfile.
- Delete the first set of tempfiles and put the names of the second into `tempfiles' */
+ Delete the first set of tempfiles and put the names of the second
+ into `tempfiles'. */
for (i = 0; i < ntemps; i++)
{
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;
}
if (failure)
return;
- /* Merge the tempfiles together and indexify */
+ /* Merge the tempfiles together and indexify. */
merge_files (tempfiles, ntemps, outfile);
}
-/* Sort `infile', whose size is `total',
- assuming that is small enough to be done in-core,
- then indexify it and send the output to `outfile' (or to stdout). */
+/* Sort INFILE, whose size is TOTAL,
+ assuming that is small enough to be done in-core,
+ then indexify it and send the output to OUTFILE (or to stdout). */
void
sort_in_core (infile, total, outfile)
@@ -903,15 +918,16 @@ sort_in_core (infile, total, outfile)
FILE *ostream = stdout;
struct lineinfo *lineinfo;
- /* Read the contents of the file into the moby array `data' */
+ /* Read the contents of the file into the moby array `data'. */
- int desc = open (infile, 0, 0);
+ int desc = open (infile, O_RDONLY, 0);
if (desc < 0)
fatal ("failure reopening %s", infile);
- for (file_size = 0; ; )
+ for (file_size = 0;;)
{
- if ((i = read (desc, data + file_size, total - file_size)) <= 0)
+ i = read (desc, data + file_size, total - file_size);
+ if (i <= 0)
break;
file_size += i;
}
@@ -928,14 +944,16 @@ sort_in_core (infile, total, outfile)
init_char_order ();
- /* Sort routines want to know this address */
+ /* Sort routines want to know this address. */
text_base = data;
- /* Create the array of pointers to lines, with a default size frequently enough. */
+ /* Create the array of pointers to lines, with a default size
+ frequently enough. */
nlines = total / 50;
- if (!nlines) nlines = 2;
+ if (!nlines)
+ nlines = 2;
linearray = (char **) xmalloc (nlines * sizeof (char *));
/* `nextline' points to the next free slot in this array.
@@ -952,11 +970,11 @@ sort_in_core (infile, total, outfile)
return;
}
- /* Sort the lines */
+ /* Sort the lines. */
/* If we have enough space, find the first keyfield of each line in advance.
- Make a `struct lineinfo' for each line, which records the keyfield
- as well as the line, and sort them. */
+ Make a `struct lineinfo' for each line, which records the keyfield
+ as well as the line, and sort them. */
lineinfo = (struct lineinfo *) malloc ((nextline - linearray) * sizeof (struct lineinfo));
@@ -983,7 +1001,7 @@ sort_in_core (infile, total, outfile)
else
qsort (linearray, nextline - linearray, sizeof (char *), compare_full);
- /* Open the output file */
+ /* Open the output file. */
if (outfile)
{
@@ -993,7 +1011,8 @@ sort_in_core (infile, total, outfile)
}
writelines (linearray, nextline - linearray, ostream);
- if (outfile) fclose (ostream);
+ if (outfile)
+ fclose (ostream);
free (linearray);
free (data);
@@ -1025,8 +1044,10 @@ parsefile (filename, nextline, data, size)
return 0;
*line = p;
- while (*p && *p != '\n') p++;
- if (p != end) p++;
+ while (*p && *p != '\n')
+ p++;
+ if (p != end)
+ p++;
line++;
if (line == linearray + nlines)
@@ -1041,42 +1062,42 @@ parsefile (filename, nextline, data, size)
}
/* Indexification is a filter applied to the sorted lines
- as they are being written to the output file.
- Multiple entries for the same name, with different page numbers,
- get combined into a single entry with multiple page numbers.
- The first braced field, which is used for sorting, is discarded.
- However, its first character is examined, folded to lower case,
- and if it is different from that in the previous line fed to us
- a \initial line is written with one argument, the new initial.
+ as they are being written to the output file.
+ Multiple entries for the same name, with different page numbers,
+ get combined into a single entry with multiple page numbers.
+ The first braced field, which is used for sorting, is discarded.
+ However, its first character is examined, folded to lower case,
+ and if it is different from that in the previous line fed to us
+ a \initial line is written with one argument, the new initial.
- If an entry has four braced fields, then the second and third
- constitute primary and secondary names.
- In this case, each change of primary name
- generates a \primary line which contains only the primary name,
- and in between these are \secondary lines which contain
- just a secondary name and page numbers.
-*/
+ If an entry has four braced fields, then the second and third
+ constitute primary and secondary names.
+ In this case, each change of primary name
+ generates a \primary line which contains only the primary name,
+ and in between these are \secondary lines which contain
+ just a secondary name and page numbers. */
/* The last primary name we wrote a \primary entry for.
- If only one level of indexing is being done, this is the last name seen */
+ If only one level of indexing is being done, this is the last name seen. */
char *lastprimary;
-int lastprimarylength; /* Length of storage allocated for lastprimary */
+/* Length of storage allocated for lastprimary. */
+int lastprimarylength;
/* Similar, for the secondary name. */
char *lastsecondary;
int lastsecondarylength;
/* Zero if we are not in the middle of writing an entry.
- One if we have written the beginning of an entry but have not
- yet written any page numbers into it.
- Greater than one if we have written the beginning of an entry
- plus at least one page number. */
+ One if we have written the beginning of an entry but have not
+ yet written any page numbers into it.
+ Greater than one if we have written the beginning of an entry
+ plus at least one page number. */
int pending;
/* The initial (for sorting purposes) of the last primary entry written.
- When this changes, a \initial {c} line is written */
+ When this changes, a \initial {c} line is written */
-char * lastinitial;
+char *lastinitial;
int lastinitiallength;
@@ -1085,7 +1106,17 @@ int lastinitiallength;
char lastinitial1[2];
-/* Initialize static storage for writing an index */
+/* Initialize static storage for writing an index. */
+
+static void
+xbzero(s, n)
+ char *s;
+ int n;
+{
+ register char *p;
+ for (p = s; n--; )
+ *p++ = '\0';
+}
void
init_index ()
@@ -1097,35 +1128,35 @@ init_index ()
lastinitiallength = 0;
lastprimarylength = 100;
lastprimary = (char *) xmalloc (lastprimarylength + 1);
- bzero (lastprimary, lastprimarylength + 1);
+ xbzero (lastprimary, lastprimarylength + 1);
lastsecondarylength = 100;
lastsecondary = (char *) xmalloc (lastsecondarylength + 1);
- bzero (lastsecondary, lastsecondarylength + 1);
+ xbzero (lastsecondary, lastsecondarylength + 1);
}
/* Indexify. Merge entries for the same name,
- insert headers for each initial character, etc. */
+ insert headers for each initial character, etc. */
+void
indexify (line, ostream)
char *line;
FILE *ostream;
{
char *primary, *secondary, *pagenumber;
- int primarylength, secondarylength, pagelength;
- int len = strlen (line);
+ int primarylength, secondarylength = 0, pagelength;
int nosecondary;
int initiallength;
char *initial;
char initial1[2];
register char *p;
- /* First, analyze the parts of the entry fed to us this time */
+ /* First, analyze the parts of the entry fed to us this time. */
p = find_braced_pos (line, 0, 0, 0);
if (*p == '{')
{
initial = p;
- /* Get length of inner pair of braces starting at p,
+ /* Get length of inner pair of braces starting at `p',
including that inner pair of braces. */
initiallength = find_braced_end (p + 1) + 1 - p;
}
@@ -1153,17 +1184,18 @@ indexify (line, ostream)
if (!nosecondary)
secondarylength = find_braced_end (secondary) - secondary;
- /* If the primary is different from before, make a new primary entry */
+ /* If the primary is different from before, make a new primary entry. */
if (strncmp (primary, lastprimary, primarylength))
{
- /* Close off current secondary entry first, if one is open */
+ /* Close off current secondary entry first, if one is open. */
if (pending)
{
fputs ("}\n", ostream);
pending = 0;
}
- /* If this primary has a different initial, include an entry for the initial */
+ /* If this primary has a different initial, include an entry for
+ the initial. */
if (initiallength != lastinitiallength ||
strncmp (initial, lastinitial, initiallength))
{
@@ -1196,26 +1228,26 @@ indexify (line, ostream)
else
fputs ("}\n", ostream);
- /* Record name of most recent primary */
+ /* Record name of most recent primary. */
if (lastprimarylength < primarylength)
{
- lastprimarylength = primarylength + 100;
+ lastprimarylength = primarylength + 100;
lastprimary = (char *) xrealloc (lastprimary,
1 + lastprimarylength);
}
strncpy (lastprimary, primary, primarylength);
lastprimary[primarylength] = 0;
- /* There is no current secondary within this primary, now */
+ /* There is no current secondary within this primary, now. */
lastsecondary[0] = 0;
}
- /* Should not have an entry with no subtopic following one with a subtopic */
+ /* 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);
- /* Start a new secondary entry if necessary */
+ /* Start a new secondary entry if necessary. */
if (!nosecondary && strncmp (secondary, lastsecondary, secondarylength))
{
if (pending)
@@ -1230,24 +1262,24 @@ indexify (line, ostream)
fputs ("}{", ostream);
pending = 1;
- /* Record name of most recent secondary */
+ /* Record name of most recent secondary. */
if (lastsecondarylength < secondarylength)
{
- lastsecondarylength = secondarylength + 100;
+ lastsecondarylength = secondarylength + 100;
lastsecondary = (char *) xrealloc (lastsecondary,
- 1 + lastsecondarylength);
+ 1 + lastsecondarylength);
}
strncpy (lastsecondary, secondary, secondarylength);
lastsecondary[secondarylength] = 0;
}
- /* Here to add one more page number to the current entry */
+ /* 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);
}
-/* Close out any unfinished output entry */
+/* Close out any unfinished output entry. */
void
finish_index (ostream)
@@ -1260,7 +1292,7 @@ finish_index (ostream)
}
/* Copy the lines in the sorted order.
- Each line is copied out of the input file it was found in. */
+ Each line is copied out of the input file it was found in. */
void
writelines (linearray, nlines, ostream)
@@ -1273,19 +1305,22 @@ writelines (linearray, nlines, ostream)
init_index ();
- /* Output the text of the lines, and free the buffer space */
+ /* Output the text of the lines, and free the buffer space. */
for (next_line = linearray; next_line != stop_line; next_line++)
{
/* If -u was specified, output the line only if distinct from previous one. */
if (next_line == linearray
- /* Compare previous line with this one, using only the explicitly specd keyfields */
+ /* 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');
- *(p-1) = 0;
+
+ while ((c = *p++) && c != '\n')
+ /* Do nothing. */ ;
+ *(p - 1) = 0;
indexify (*next_line, ostream);
}
}
@@ -1294,10 +1329,11 @@ writelines (linearray, nlines, ostream)
}
/* Assume (and optionally verify) that each input file is sorted;
- merge them and output the result.
- Returns nonzero if any input file fails to be sorted.
+ merge them and output the result.
+ Returns nonzero if any input file fails to be sorted.
- This is the high-level interface that can handle an unlimited number of files. */
+ This is the high-level interface that can handle an unlimited
+ number of files. */
#define MAX_DIRECT_MERGE 10
@@ -1342,15 +1378,15 @@ merge_files (infiles, nfiles, outfile)
free (tempfiles);
return value;
-}
+}
/* Assume (and optionally verify) that each input file is sorted;
- merge them and output the result.
- Returns nonzero if any input file fails to be sorted.
+ merge them and output the result.
+ Returns nonzero if any input file fails to be sorted.
- This version of merging will not work if the number of
- input files gets too high. Higher level functions
- use it only with a bounded number of input files. */
+ This version of merging will not work if the number of
+ input files gets too high. Higher level functions
+ use it only with a bounded number of input files. */
int
merge_direct (infiles, nfiles, outfile)
@@ -1358,7 +1394,6 @@ merge_direct (infiles, nfiles, outfile)
int nfiles;
char *outfile;
{
- char **ip = infiles;
struct linebuffer *lb1, *lb2;
struct linebuffer **thisline, **prevline;
FILE **streams;
@@ -1373,14 +1408,15 @@ merge_direct (infiles, nfiles, outfile)
{
ostream = fopen (outfile, "w");
}
- if (!ostream) pfatal_with_name (outfile);
+ if (!ostream)
+ pfatal_with_name (outfile);
init_index ();
if (nfiles == 0)
{
if (outfile)
- fclose (ostream);
+ fclose (ostream);
return 0;
}
@@ -1392,22 +1428,26 @@ merge_direct (infiles, nfiles, outfile)
while `prevline' holds the last file line used,
which is remembered so that we can verify that the file is properly sorted. */
- /* lb1 and lb2 contain one buffer each per file */
+ /* lb1 and lb2 contain one buffer each per file. */
lb1 = (struct linebuffer *) xmalloc (nfiles * sizeof (struct linebuffer));
lb2 = (struct linebuffer *) xmalloc (nfiles * sizeof (struct linebuffer));
/* thisline[i] points to the linebuffer holding the next available line in file i,
or is zero if there are no lines left in that file. */
- thisline = (struct linebuffer **) xmalloc (nfiles * sizeof (struct linebuffer *));
- /* prevline[i] points to the linebuffer holding the last used line from file i.
- This is just for verifying that file i is properly sorted. */
- prevline = (struct linebuffer **) xmalloc (nfiles * sizeof (struct linebuffer *));
+ thisline = (struct linebuffer **)
+ xmalloc (nfiles * sizeof (struct linebuffer *));
+ /* prevline[i] points to the linebuffer holding the last used line
+ from file i. This is just for verifying that file i is properly
+ sorted. */
+ prevline = (struct linebuffer **)
+ xmalloc (nfiles * sizeof (struct linebuffer *));
/* streams[i] holds the input stream for file i. */
streams = (FILE **) xmalloc (nfiles * sizeof (FILE *));
- /* file_lossage[i] is nonzero if we already know file i is not properly sorted. */
+ /* file_lossage[i] is nonzero if we already know file i is not
+ properly sorted. */
file_lossage = (int *) xmalloc (nfiles * sizeof (int));
- /* Allocate and initialize all that storage */
+ /* Allocate and initialize all that storage. */
for (i = 0; i < nfiles; i++)
{
@@ -1423,7 +1463,7 @@ merge_direct (infiles, nfiles, outfile)
readline (thisline[i], streams[i]);
}
- /* Keep count of number of files not at eof */
+ /* Keep count of number of files not at eof. */
nleft = nfiles;
while (nleft)
@@ -1440,21 +1480,24 @@ merge_direct (infiles, nfiles, outfile)
if (thisline[i] &&
(!best ||
0 < compare_general (best->buffer, thisline[i]->buffer,
- (long) bestfile, (long) i, num_keyfields)))
+ (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 */
+ /* Output that line, unless it matches the previous one and we
+ don't want duplicates. */
if (!(prev_out &&
- !compare_general (prev_out->buffer, best->buffer, 0L, 1L, num_keyfields - 1)))
+ !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 */
+ /* Now make the line the previous of its file, and fetch a new
+ line from that file. */
exch = prevline[bestfile];
prevline[bestfile] = thisline[bestfile];
@@ -1462,22 +1505,24 @@ merge_direct (infiles, nfiles, outfile)
while (1)
{
- /* If the file has no more, mark it empty */
+ /* If the file has no more, mark it empty. */
if (feof (streams[bestfile]))
{
thisline[bestfile] = 0;
- nleft--; /* Update the number of files still not empty */
+ /* 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 (thisline[bestfile]->buffer[0] || !feof (streams[bestfile]))
+ break;
}
}
finish_index (ostream);
- /* Free all storage and close all input streams */
+ /* Free all storage and close all input streams. */
for (i = 0; i < nfiles; i++)
{
@@ -1500,48 +1545,64 @@ merge_direct (infiles, nfiles, outfile)
/* Print error message and exit. */
+void
fatal (s1, s2)
char *s1, *s2;
{
error (s1, s2);
- exit (EXIT_FATAL);
+ exit (TI_FATAL_ERROR);
}
-/* Print error message. `s1' is printf control string, `s2' is arg for it. */
+/* Print error message. S1 is printf control string, S2 is arg for it. */
+void
error (s1, s2)
char *s1, *s2;
{
- printf ("texindex: ");
+ printf ("%s: ", program_name);
printf (s1, s2);
printf ("\n");
}
+#if !defined (HAVE_STRERROR)
+static char *
+strerror (n)
+ int n;
+{
+ static char ebuf[40];
+
+ if (n < sys_nerr)
+ return sys_errlist[n];
+ else
+ {
+ sprintf (ebuf, "Unknown error %d", n);
+ return ebuf;
+ }
+}
+#endif
+
+void
perror_with_name (name)
char *name;
{
char *s;
- if (errno < sys_nerr)
- s = concat ("", sys_errlist[errno], " for %s");
- else
- s = "cannot open %s";
+ s = concat ("", strerror (errno), " for %s");
error (s, name);
}
+void
pfatal_with_name (name)
char *name;
{
char *s;
- if (errno < sys_nerr)
- s = concat ("", sys_errlist[errno], " for %s");
- else
- s = "cannot open %s";
+ s = concat ("", strerror (errno), " for %s");
fatal (s, name);
}
-/* Return a newly-allocated string whose contents concatenate those of s1, s2, s3. */
+/* Return a newly-allocated string whose contents concatenate those of
+ S1, S2, S3. */
char *
concat (s1, s2, s3)
@@ -1558,49 +1619,48 @@ concat (s1, s2, s3)
return result;
}
-/* Like malloc but get fatal error if memory is exhausted. */
-
-int
-xmalloc (size)
- int size;
+/* Just like malloc, but kills the program in case of fatal error. */
+void *
+xmalloc (nbytes)
+ int nbytes;
{
- int result = malloc (size);
- if (!result)
- fatal ("virtual memory exhausted", 0);
- return result;
-}
+ void *temp = (void *) malloc (nbytes);
+ if (nbytes && temp == (void *)NULL)
+ memory_error ("xmalloc", nbytes);
-int
-xrealloc (ptr, size)
- char *ptr;
- int size;
+ return (temp);
+}
+
+/* Like realloc (), but barfs if there isn't enough memory. */
+void *
+xrealloc (pointer, nbytes)
+ void *pointer;
+ int nbytes;
{
- int result = realloc (ptr, size);
- if (!result)
- fatal ("virtual memory exhausted");
- return result;
+ void *temp;
+
+ if (!pointer)
+ temp = (void *)xmalloc (nbytes);
+ else
+ temp = (void *)realloc (pointer, nbytes);
+
+ if (nbytes && !temp)
+ memory_error ("xrealloc", nbytes);
+
+ return (temp);
}
-bzero (b, length)
- register char *b;
- register int length;
+memory_error (callers_name, bytes_wanted)
+ char *callers_name;
+ int bytes_wanted;
{
-#ifdef VMS
- short zero = 0;
- long max_str = 65535;
- long len;
+ char printable_string[80];
- while (length > max_str)
- {
- (void) LIB$MOVC5 (&zero, &zero, &zero, &max_str, b);
- length -= max_str;
- b += max_str;
- }
- len = length;
- (void) LIB$MOVC5 (&zero, &zero, &zero, &len, b);
-#else
- while (length-- > 0)
- *b++ = 0;
-#endif /* not VMS */
+ sprintf (printable_string,
+ "Virtual memory exhausted in %s ()! Needed %d bytes.",
+ callers_name, bytes_wanted);
+
+ error (printable_string, "");
+ abort ();
}