less beta release (part 1 of 5)
Mark Nudelman
mark at unix386.Convergent.COM
Fri Sep 15 08:22:50 AEST 1989
#! /bin/sh
# This is a shell archive.
# Remove anything before this line, then unpack it
# by saving it into a file and typing "sh file".
echo shar: Extracting \"README\"
sed "s/^X//" >'README' <<'END_OF_FILE'
X===============================================================
X=== NOTE: THIS IS THE BETA DISTRIBUTION OF less. ===
X=== PLEASE REPORT ANY PROBLEMS TO THE AUTHOR. ===
X===============================================================
X
XThis is the distribution of "less", a paginator similar to "more" or "pg".
XThe manual page is in less.man (nroff source in less.nro).
XMajor changes made since the last posted version are in CHANGES.
X
XINSTALLATION:
X
X1. Move the distributed source to its own directory and
X unpack it by running "sh" on the distribution files,
X if you have not already done so.
X
X2. Type "sh linstall" and answer the questions it asks.
X This will generate a makefile and a defines.h.
X
X If you choose not to include some features in your version,
X you may wish to edit the manual page "less.nro" and the help
X page "less.help" to remove the references to the appropriate
X commands or options.
X
X3. It is a good idea to look over the generated makefile
X and make sure it looks ok.
X
X4. Type "make" and watch the fun.
X
X5. If the make succeeds, it will generate a program "less"
X in your current directory. Test the generated program.
X
X6. When satisfied that it works, if you wish to install it
X in a public place, type "make install".
X
XIf you have any problems building or running "less",
Xsuggestions, complaints, etc., you may mail to the
Xauthor via USENET at:
X sun \
X uunet } !pyramid!ctnews!unix386!mark
X hplabs /
X
X
XNote to hackers: comments noting possible improvements are enclosed
Xin double curly brackets {{ like this }}.
END_OF_FILE
echo shar: Extracting \"CHANGES\"
sed "s/^X//" >'CHANGES' <<'END_OF_FILE'
X
X Major changes between "less" versions 97 and 123
X
X* New option (-N) causes line numbers to be displayed in the
X text of the file (like vi "set nu").
X
X* New option (-?) prints help message immediately.
X
X* New option (-r) displays "raw" control characters, without
X mapping them to ^X notation.
X
X* New option (-f) forces less to open non-regular files
X (directories, etc).
X
X* New option (-k) can be used to specify lesskey files by name.
X
X* File marks (set by the m command) are now preserved when a new
X file is edited. The ' command can thus be used to switch files.
X
X* 8 bit characters are now supported. A new option (-g) can be
X used to strip off the eighth bit (the previous behavior).
X
X* Options which take a following string (like -t) may now
X optionally have a space between the option letter and the string.
X
X* The % command has been changed to do bracket matching, like
X vi % command. The old % command is still available via p.
X Six new commands { } ( ) [ and ] can also be used to match
X brackets of specific types.
X
X* New commands z and w move forward/backward one window and
X simultaneously set the window size.
X
X* New command ESC-/ searches the entire file for a pattern.
X
X* New command ESC-n repeats previous search in reverse direction.
X
X* Prompt string expansion now has %L for line number of the last
X line in the file, and %E for the name of the editor.
X
X* New environment variable EDITPROTO can be used to tailor the
X command string passed to the editor by the v command.
X
X* Examining a file which was previously examined will return
X to the same position in the file.
X
X* A "%" is expanded to the current filename and a "#" to the
X previous filename, in both shell commands and the E command.
X (Previously % worked only in shell commands and # worked
X only in the E command.)
X
X* New command ":ta" is equivalent to "-t".
X
X* New command "s" is equivalent to "-l".
X
X* Lesskey files may now use the action "toggle-option X" to
X give an alias for toggling a specific option X.
END_OF_FILE
echo shar: Extracting \"less.nro\"
sed "s/^X//" >'less.nro' <<'END_OF_FILE'
X.TH LESS 1
X.SH NAME
Xless \- opposite of more
X.SH SYNOPSIS
X.B "less -?"
X.br
X.B "less [-[+]aABcCdeEfgimMnNqQruUsw] [-b\fIN\fB] [-h\fIN\fB] [-x\fIN\fB] [-[z]\fIN\fB]"
X.br
X.B " [-P[mM=]\fIstring\fB] [-[lL]\fIlogfile\fB] [-k\fIkeyfile\fB]"
X.br
X.B " [+\fIcmd\fB] [-t\fItag\fB] [\fIfilename\fB]..."
X
X.SH DESCRIPTION
X.I Less
Xis a program similar to
X.I more
X(1), but which allows backwards movement
Xin the file as well as forward movement.
XAlso,
X.I less
Xdoes not have to read the entire input file before starting,
Xso with large input files it starts up faster than text editors like
X.I vi
X(1).
X.I Less
Xuses termcap (or terminfo on some systems),
Xso it can run on a variety of terminals.
XThere is even limited support for hardcopy terminals.
X(On a hardcopy terminal, lines which should be printed at the top
Xof the screen are prefixed with an up-arrow.)
X.PP
XCommands are based on both
X.I more
Xand
X.I vi.
XCommands may be preceded by a decimal number,
Xcalled N in the descriptions below.
XThe number is used by some commands, as indicated.
X
X.SH COMMANDS
XIn the following descriptions, ^X means control-X.
XESC stands for the ESCAPE key; for example ESC-v means the
Xtwo character sequence "ESCAPE", then "v".
X.IP "h or H"
XHelp: display a summary of these commands.
XIf you forget all the other commands, remember this one.
X.PP
X.IP "SPACE or ^V or f or ^F"
XScroll forward N lines, default one window (see option -z below).
XIf N is more than the screen size, only the final screenful is displayed.
XWarning: some systems use ^V as a special literalization character.
X.PP
X.IP "z"
XLike SPACE, but if N is specified, it becomes the new window size.
X.PP
X.IP "RETURN or ^N or e or ^E or j or ^J"
XScroll forward N lines, default 1.
XThe entire N lines are displayed, even if N is more than the screen size.
X.PP
X.IP "d or ^D"
XScroll forward N lines, default one half of the screen size.
XIf N is specified, it becomes the new default for
Xsubsequent d and u commands.
X.PP
X.IP "b or ^B or ESC-v"
XScroll backward N lines, default one window (see option -z below).
XIf N is more than the screen size, only the final screenful is displayed.
X.PP
X.IP "w"
XLike ESC-v, but if N is specified, it becomes the new window size.
X.PP
X.IP "y or ^Y or ^P or k or ^K"
XScroll backward N lines, default 1.
XThe entire N lines are displayed, even if N is more than the screen size.
XWarning: some systems use ^Y as a special job control character.
X.PP
X.IP "u or ^U"
XScroll backward N lines, default one half of the screen size.
XIf N is specified, it becomes the new default for
Xsubsequent d and u commands.
X.PP
X.IP "r or ^R or ^L"
XRepaint the screen.
X.PP
X.IP R
XRepaint the screen, discarding any buffered input.
XUseful if the file is changing while it is being viewed.
X.PP
X.IP "g or < or ESC-<"
XGo to line N in the file, default 1 (beginning of file).
X(Warning: this may be slow if N is large.)
X.PP
X.IP "G or > or ESC->"
XGo to line N in the file, default the end of the file.
X(Warning: this may be slow if N is large,
Xor if N is not specified and
Xstandard input, rather than a file, is being read.)
X.PP
X.IP "p"
XGo to a position N percent into the file.
XN should be between 0 and 100.
X(This works if standard input is being read, but only if
X.I less
Xhas already read to the end of the file.
XIt is always fast, but not always useful.)
X.PP
X.IP "%"
XIf a bracket appears in the top line displayed
Xon the screen,
Xthe % command will go to the matching bracket.
XA "bracket" is one of the characters "{ } [ ] ( )".
X.PP
X.IP "{"
XIf a left curly bracket appears in the top line displayed
Xon the screen,
Xthe { command will go to the matching right curly bracket.
XIf there is more than one left curly bracket on the top line,
Xa number N may be used to specify the N-th bracket on the line.
X.PP
X.IP "}"
XIf a right curly bracket appears in the top line displayed
Xon the screen,
Xthe } command will go to the matching left curly bracket.
XIf there is more than one right curly bracket on the top line,
Xa number N may be used to specify the N-th bracket on the line.
X.PP
X.IP "("
XLike {, but applies to parentheses rather than curly brackets.
X.PP
X.IP ")"
XLike }, but applies to parentheses rather than curly brackets.
X.PP
X.IP "["
XLike {, but applies to square brackets rather than curly brackets.
X.PP
X.IP "]"
XLike }, but applies to square brackets rather than curly brackets.
X.PP
X.IP m
XFollowed by any lowercase letter,
Xmarks the current position with that letter.
X.PP
X.IP "'"
X(Single quote.)
XFollowed by any lowercase letter, returns to the position which
Xwas previously marked with that letter.
XFollowed by another single quote, returns to the position at
Xwhich the last "large" movement command was executed.
XMarks are preserved when a new file is examined,
Xso the ' command can be used to switch between input files.
X.PP
X.IP "^X^X"
XSame as single quote.
X.PP
X.IP /pattern
XSearch forward in the file for the N-th line containing the pattern.
XN defaults to 1.
XThe pattern is a regular expression, as recognized by
X.I ed.
XThe search starts at the second line displayed
X(but see the -a option, which changes this).
X.PP
X.IP ?pattern
XSearch backward in the file for the N-th line containing the pattern.
XThe search starts at the line immediately before the top line displayed.
X.PP
X.IP "ESC-/pattern"
XSearch the entire file for the N-th line containing the pattern.
XThe search starts at the first line in the file,
Xregardless of what is displayed or the setting of the -a option.
X.PP
X.IP /!pattern
XLike /, but the search is for the N-th line
Xwhich does NOT contain the pattern.
X.PP
X.IP ?!pattern
XLike ?, but the search is for the N-th line
Xwhich does NOT contain the pattern.
X.PP
X.IP "ESC-/!pattern
XLike ESC-/, but the search is for the N-th line
Xwhich does NOT contain the pattern.
X.PP
X.IP n
XRepeat previous search, for N-th line containing the last pattern
X(or NOT containing the last pattern, if the previous search
Xwas /! or ?!).
X.PP
X.IP "ESC-n"
XRepeat previous search, but in the reverse direction.
X.PP
X.IP "E [filename]"
XExamine a new file.
XIf the filename is missing, the "current" file (see the N and P commands
Xbelow) from the list of files in the command line is re-examined.
XA percent sign (%) in the filename is replaced by the name of the
Xcurrent file.
XA pound sign (#) is replaced by the name of the previously examined file.
X.PP
X.IP "^X^V or :e"
XSame as E.
XWarning: some systems use ^V as a special literalization character.
X.PP
X.IP "N or :n"
XExamine the next file (from the list of files given in the command line).
XIf a number N is specified (not to be confused with the command N),
Xthe N-th next file is examined.
X.PP
X.IP "P or :p"
XExamine the previous file.
XIf a number N is specified, the N-th previous file is examined.
X.PP
X.IP "= or ^G or :f"
XPrints some information about the file being viewed,
Xincluding its name
Xand the line number and byte offset of the bottom line being displayed.
XIf possible, it also prints the length of the file,
Xthe number of lines in the file
Xand the percent of the file above the last displayed line.
X.PP
X.IP \-
XFollowed by one of the command line option letters (see below),
Xthis will change the setting of that option
Xand print a message describing the new setting.
XIf the option letter has a numeric value (such as -b or -h),
Xor a string value (such as -P or -t),
Xa new value may be entered after the option letter.
X.PP
X.IP \_
X(Underscore.)
XFollowed by one of the command line option letters (see below),
Xthis will print a message describing the current setting of that option.
XThe setting of the option is not changed.
X.PP
X.IP +cmd
XCauses the specified cmd to be executed each time a new file is examined.
XFor example, +G causes
X.I less
Xto initially display each file starting at the end
Xrather than the beginning.
X.PP
X.IP V
XPrints the version number of
X.I less
Xbeing run.
X.PP
X.IP "q or :q or :Q or ZZ"
XExits
X.I less.
X.PP
XThe following
Xtwo
Xcommands may or may not be valid, depending on your particular installation.
X.PP
X.IP v
XInvokes an editor to edit the current file being viewed.
XThe editor is taken from the environment variable EDITOR,
Xor defaults to "vi".
XSee also the discussion of EDITPROTO under the section on PROMPTS below.
X.PP
X.IP "! shell-command"
XInvokes a shell to run the shell-command given.
XA percent sign (%) in the command is replaced by the name of the
Xcurrent file.
XA pound sign (#) is replaced by the name of the previously examined file.
X"!!" repeats the last shell command.
X"!" with no shell command simply invokes a shell.
XIn all cases, the shell is taken from the environment variable SHELL,
Xor defaults to "sh".
X.PP
X.SH OPTIONS
XCommand line options are described below.
XMost options may be changed while
X.I less
Xis running, via the "\-" command.
X.PP
XOptions are also taken from the environment variable "LESS".
XFor example,
Xto avoid typing "less -options ..." each time
X.I less
Xis invoked, you might tell
X.I csh:
X.sp
Xsetenv LESS "-options"
X.sp
Xor if you use
X.I sh:
X.sp
XLESS="-options"; export LESS
X.sp
XThe environment variable is parsed before the command line,
Xso command line options override the LESS environment variable.
XIf an option appears in the LESS variable, it can be reset
Xto its default on the command line by beginning the command
Xline option with "-+".
X.sp
XA dollar sign ($) may be used to signal the end of an option string.
XThis is important only for options like -P which take a
Xfollowing string.
X.IP -?
XThis option displays a summary of the commands accepted by
X.I less
X(the same as the h command).
XIf this option is given, all other options are ignored, and
X.I less
Xexits after the help screen is viewed.
X(Depending on how your shell interprets the question mark,
Xit may be necessary to quote the question mark, thus: "-\\?".)
X.IP -a
XNormally, forward searches start just after
Xthe top displayed line (that is, at the second displayed line).
XThus, forward searches include the currently displayed screen.
XThe -a option causes forward searches to start
Xjust after the bottom line displayed,
Xthus skipping the currently displayed screen.
X.IP -A
XThe -A option causes searches to start at the second SCREEN line
Xdisplayed, as opposed to the default which is to start at the second
XREAL line displayed.
XFor example, suppose a long real line occupies the first three screen lines.
XThe default search will start at the second real line (the fourth
Xscreen line), while the -A option
Xwill cause the search to start at the second screen line (in the
Xmidst of the first real line).
X(This option is rarely useful.)
X.IP -b
XThe -b\fIn\fR option tells
X.I less
Xto use a non-standard number of buffers.
XBuffers are 1K, and normally 10 buffers are used
X(except if data in coming from standard input; see the -B option).
XThe number \fIn\fR specifies a different number of buffers to use.
X.IP -B
XNormally, when data is coming from standard input,
Xbuffers are allocated automatically as needed, to avoid loss of data.
XThe -B option disables this feature, so that only the default number
Xof buffers are used.
XIf more data is read than will fit in the buffers, the oldest
Xdata is discarded.
X.IP -c
XNormally,
X.I less
Xwill repaint the screen by scrolling from the bottom of the screen.
XIf the -c option is set, when
X.I less
Xneeds to change the entire display, it will paint from the top line down.
X.IP -C
XThe -C option is like -c, but the screen is cleared before it is repainted.
X.IP -d
XNormally,
X.I less
Xwill complain if the terminal is dumb; that is, lacks some important capability,
Xsuch as the ability to clear the screen or scroll backwards.
XThe -d option suppresses this complaint
X(but does not otherwise change the behavior of the program on a dumb terminal).
X.IP -e
XNormally the only way to exit
X.I less
Xis via the "q" command.
XThe -e option tells
X.I less
Xto automatically exit
Xthe second time it reaches end-of-file.
X.IP -E
XThe -E flag causes
X.I less
Xto exit the first time it reaches end-of-file.
X.IP -f
XNormally,
X.I less
Xwill refuse to open a non-regular file
X(that is, a file which is a directory or a device special file).
XThe -f flag forces
X.I less
Xto open such files.
X.IP -g
XForce input characters to 7 bits (that is, mask off the high order bit).
XThe default is to use full 8 bit characters.
X.IP -h
XNormally,
X.I less
Xwill scroll backwards when backwards movement is necessary.
XThe -h option specifies a maximum number of lines to scroll backwards.
XIf it is necessary to move backwards more than this many lines,
Xthe screen is repainted in a forward direction.
X(If the terminal does not have the ability to scroll
Xbackwards, -h0 is implied.)
X.IP -i
XThe -i option causes searches to ignore case; that is,
Xuppercase and lowercase are considered identical.
XAlso, text which is overstruck or underlined can be searched for.
X.IP -k
XThe -k option, followed immediately by a filename,
Xwill cause
X.I less
Xto open and interpret the file as a
X.I lesskey
X(1) file.
XMultiple -k options may be specified.
XIf a file called .less exists in the user's home directory, this
Xfile is also used as a
X.I lesskey
Xfile.
X.IP -l
XThe -l option, followed immediately by a filename,
Xwill cause
X.I less
Xto copy its input to the named file as it is being viewed.
XThis applies only when the input file is a pipe,
Xnot an ordinary file.
XIf the file already exists,
X.I less
Xwill ask for confirmation before overwriting it.
X.IP -L
XThe -L option is like -l, but it will overwrite an existing
Xfile without asking for confirmation.
X.sp
XIf no log file has been specified,
Xthe -l and -L options can be used from within
X.I less
Xto specify a log file.
XWithout a file name, they will simply report the name of the log file.
XThe "s" command is equivalent to specifying -l from within
X.I less.
X.IP -m
XNormally,
X.I less
Xprompts with a colon.
XThe -m option causes
X.I less
Xto prompt verbosely (like
X.I more),
Xwith the percent into the file.
X.IP -M
XThe -M option causes
X.I less
Xto prompt even more verbosely than
X.I more.
X.IP -n
XThe -n flag suppresses line numbers.
XThe default (to use line numbers) may cause
X.I less
Xto run more slowly in some cases, especially with a very large input file.
XSuppressing line numbers with the -n flag will avoid this problem.
XUsing line numbers means: the line number will be displayed in the verbose
Xprompt and in the = command,
Xand the v command will pass the current line number to the editor
X(see also the discussion of EDITPROTO in PROMPTS below).
X.IP -N
XThe -N flag causes a line number to be displayed at the beginning of
Xeach line in the display.
X.IP -P
XThe -P option provides a way to tailor the three prompt
Xstyles to your own preference.
XYou would normally put this option in your LESS environment
Xvariable, rather than type it in with each
X.I less
Xcommand.
XSuch an option must either be the last option in the LESS variable,
Xor be terminated by a dollar sign.
X-P followed by a string changes the default (short) prompt to that string.
X-Pm changes the medium (-m) prompt to the string, and
X-PM changes the long (-M) prompt.
XAlso, -P= changes the message printed by the = command to the given string.
XAll prompt strings consist of a sequence of
Xletters and special escape sequences.
XSee the section on PROMPTS for more details.
X.IP -q
XNormally, if an attempt is made to scroll past the end of the file
Xor before the beginning of the file, the terminal bell is rung to
Xindicate this fact.
XThe -q option tells
X.I less
Xnot to ring the bell at such times.
XIf the terminal has a "visual bell", it is used instead.
X.IP -Q
XEven if -q is given,
X.I less
Xwill ring the bell on certain other errors,
Xsuch as typing an invalid character.
XThe -Q option tells
X.I less
Xto be quiet all the time; that is, never ring the terminal bell.
XIf the terminal has a "visual bell", it is used instead.
X.IP -r
XNormally, control character are displayed using a carat and the
Xequivalent non-control character.
XFor example, a control-A (octal 001) is displayed as "^A".
XIf the -r flag is set, "raw" control characters are displayed,
Xwithout this translation.
XWarning: when this flag is used,
X.I less
Xcannot keep track of the actual appearance of the screen
X(since this depends on how the screen responds to
Xeach type of control character).
XThus, various display problems may result,
Xsuch as long lines being split in the wrong place.
X.IP -s
XThe -s option causes
Xconsecutive blank lines to be squeezed into a single blank line.
XThis is useful when viewing
X.I nroff
Xoutput.
X.IP -t
XThe -t option, followed immediately by a TAG,
Xwill edit the file containing that tag.
XFor this to work, there must be a file called "tags" in the
Xcurrent directory, which was previously built by the
X.I ctags
X(1) command.
XThis option may also be specified from within
X.I less
X(using the \- command) as a way of examining a new file.
XFor
X.I vi
Xcompatibility, the command ":ta" is equivalent to specifying -t from within
X.I less.
X.IP -u
XIf the -u option is given,
Xbackspaces are treated as printable characters;
Xthat is, they are sent to the terminal when they appear in the input.
X.IP -U
XIf the -U option is given,
Xbackspaces are printed as the two character sequence "^H".
X.sp
XIf neither -u nor -U is given,
Xbackspaces which appear adjacent to an underscore character
Xare treated specially:
Xthe underlined text is displayed
Xusing the terminal's hardware underlining capability.
XAlso, backspaces which appear between two identical characters
Xare treated specially:
Xthe overstruck text is printed
Xusing the terminal's hardware boldface capability.
XOther backspaces are deleted, along with the preceding character.
X.IP -w
XNormally,
X.I less
Xuses a tilde character to represent lines past the end of the file.
XThe -w option causes blank lines to be used instead.
X.IP -x
XThe -x\fIn\fR option sets tab stops every \fIn\fR positions.
XThe default for \fIn\fR is 8.
X.IP -[z]
XWhen given a backwards or forwards window command,
X.I less
Xwill by
Xdefault scroll backwards or forwards one screenful of lines.
XThe -z\fIn\fR option changes the default scrolling window size
Xto \fIn\fR lines.
XThe z and w commands can also be used to change the window size.
XNote that the "z" in "-z\fIn\fR" is optional for compatibility with
X.I more.
X.IP +
XIf a command line option begins with \fB+\fR,
Xthe remainder of that option is taken to be an initial command to
X.I less.
XFor example, +G tells
X.I less
Xto start at the end of the file rather than the beginning,
Xand +/xyz tells it to start at the first occurrence of "xyz" in the file.
XAs a special case, +<number> acts like +<number>g;
Xthat is, it starts the display at the specified line number
X(however, see the caveat under the "g" command above).
XIf the option starts with \fB++\fR, the initial command applies to
Xevery file being viewed, not just the first one.
XThe + command described previously
Xmay also be used to set (or change) an initial command for every file.
X
X.SH "KEY BINDINGS"
XYou may define your own
X.I less
Xcommands by using the program
X.I lesskey
X(1)
Xto create a file called ".less" in your home directory.
XThis file specifies a set of command keys and an action
Xassociated with each key.
XSee the
X.I lesskey
Xmanual page for more details.
X
X.SH "PROMPTS"
XThe -P option allows you to tailor the prompt to your preference.
XThe string given to the -P option replaces the specified prompt string.
XCertain characters in the string are interpreted specially.
XThe prompt mechanism is rather complicated to provide flexibility,
Xbut the ordinary user need not understand the details of constructing
Xpersonalized prompt strings.
X.sp
XA percent sign followed by a single character is expanded
Xaccording to what the following character is:
X.IP "%bX"
XReplaced by the byte offset into the current input file.
XThe b is followed by a single character (shown as X above)
Xwhich specifies the line whose byte offset is to be used.
XIf the character is a "t", the byte offset of the top line in the
Xdisplay is used,
Xan "m" means use the middle line,
Xa "b" means use the bottom line,
Xand a "B" means use the line just after the bottom line.
X.IP "%E"
XReplaced by the name of the editor (from the EDITOR environment variable).
XSee the discussion of the EDITPROTO feature below.
X.IP "%f"
XReplaced by the name of the current input file.
X.IP "%i"
XReplaced by the index of the current file in the list of
Xinput files.
X.IP "%lX"
XReplaced by the line number of a line in the input file.
XThe line to be used is determined by the X, as with the %b option.
X.IP "%L"
XReplaced by the line number of the last line in the input file.
X.IP "%m"
XReplaced by the total number of input files.
X.IP "%pX"
XReplaced by the percent into the current input file.
XThe line used is determined by the X as with the %b option.
X.IP "%s"
XReplaced by the size of the current input file.
X.IP "%t"
XCauses any trailing spaces to be removed.
XUsually used at the end of the string, but may appear anywhere.
X.IP "%x"
XReplaced by the name of the next input file in the list.
X.PP
XIf any item is unknown (for example, the file size if input
Xis a pipe), a question mark is printed instead.
X.PP
XThe format of the prompt string can be changed
Xdepending on certain conditions.
XA question mark followed by a single character acts like an "IF":
Xdepending on the following character, a condition is evaluated.
XIf the condition is true, any characters following the question mark
Xand condition character, up to a period, are included in the prompt.
XIf the condition is false, such characters are not included.
XA colon appearing between the question mark and the
Xperiod can be used to establish an "ELSE": any characters between
Xthe colon and the period are included in the string if and only if
Xthe IF condition is false.
XCondition characters (which follow a question mark) may be:
X.IP "?a"
XTrue if any characters have been included in the prompt so far.
X.IP "?bX"
XTrue if the byte offset of the specified line is known.
X.IP "?e"
XTrue if at end-of-file.
X.IP "?f"
XTrue if there is an input filename
X(that is, if input is not a pipe).
X.IP "?lX"
XTrue if the line number of the specified line is known.
X.IP "?L"
XTrue if the line number of the last line in the file is known.
X.IP "?m"
XTrue if there is more than one input file.
X.IP "?n"
XTrue if this is the first prompt in a new input file.
X.IP "?pX"
XTrue if the percent into the current input file
Xof the specified line is known.
X.IP "?s"
XTrue if the size of current input file is known.
X.IP "?x"
XTrue if there is a next input file
X(that is, if the current input file is not the last one).
X.PP
XAny characters other than the special ones
X(question mark, colon, period, percent, and backslash)
Xbecome literally part of the prompt.
XAny of the special characters may be included in the prompt literally
Xby preceding it with a backslash.
X.PP
XSome examples:
X.sp
X?f%f:Standard input.
X.sp
XThis prompt prints the filename, if known;
Xotherwise the string "Standard input".
X.sp
X?f%f .?ltLine %lt:?pt%pt\\%:?btByte %bt:-...
X.sp
XThis prompt would print the filename, if known.
XThe filename is followed by the line number, if known,
Xotherwise the percent if known, otherwise the byte offset if known.
XOtherwise, a dash is printed.
XNotice how each question mark has a matching period,
Xand how the % after the %pt
Xis included literally by escaping it with a backslash.
X.sp
X?n?f%f\ .?m(file\ %i\ of\ %m)\ ..?e(END)\ ?x-\ Next\\:\ %x..%t
X.sp
XThis prints the filename if this is the first prompt in a file,
Xfollowed by the "file N of N" message if there is more
Xthan one input file.
XThen, if we are at end-of-file, the string "(END)" is printed
Xfollowed by the name of the next file, if there is one.
XFinally, any trailing spaces are truncated.
XThis is the default prompt.
XFor reference, here are the defaults for
Xthe other two prompts (-m and -M respectively).
XEach is broken into two lines here for readability only.
X.nf
X.sp
X?n?f%f\ .?m(file\ %i\ of\ %m)\ ..?e(END)\ ?x-\ Next\\:\ %x.:
X ?pB%pB\\%:byte\ %bB?s/%s...%t
X.sp
X?f%f\ .?n?m(file\ %i\ of\ %m)\ ..?ltline\ %lt?L/%L.\ :byte\ %bB?s/%s.\ .
X ?e(END)\ ?x-\ Next\\:\ %x.:?pB%pB\\%..%t
X.sp
X.fi
XAnd here is the default message produced by the = command:
X.nf
X.sp
X?f%f\ .?m(file\ %i\ of\ %m)\ .?ltline\ %lt?L/%L.\ .
X byte\ %bB?s/%s.\ ?e(END)\ :?pB%pB\\%..%t
X.fi
X.PP
XThe prompt expansion features are also used for another purpose:
Xif an environment variable EDITPROTO is defined, it is used
Xas the command to be executed when the v command is invoked.
XThe EDITPROTO string is expanded in the same way as the prompt strings.
XThe default value for EDITPROTO is:
X.nf
X %E\ ?lm+%lm.\ %f
X.fi
XNote that this expands to the editor name, followed by a + and the
Xline number, followed by the file name.
XIf your editor does not accept the "+linenumber" syntax, or has other
Xdifferences in invocation syntax, the EDITPROTO variable can be
Xchanged to modify this default.
X
X.SH "ENVIRONMENT VARIABLES"
X.IP EDITOR
XThe name of the editor (used for the v command).
X.IP EDITPROTO
XEditor prototype string (used for the v command).
XSee discussion under PROMPTS.
X.IP HOME
XName of the user's home directory (used to find a .less file).
X.IP LESS
XFlags which are passed to
X.I less
Xautomatically.
X.IP SHELL
XThe shell used to execute the ! command, as well as to expand filenames.
X.IP TERM
XThe type of terminal on which
X.I less
Xis being run.
X
X.SH "SEE ALSO"
Xlesskey(1)
X
X.SH WARNINGS
XThe = command and prompts (unless changed by -P)
Xreport the line number of the line at the top of the screen,
Xbut the byte and percent of the line at the bottom of the screen.
END_OF_FILE
echo shar: Extracting \"lesskey.nro\"
sed "s/^X//" >'lesskey.nro' <<'END_OF_FILE'
X.TH LESSKEY 1
X.SH NAME
Xlesskey \- specify key bindings for less
X.SH SYNOPSIS
X.B "lesskey [-o output] [input]"
X.SH DESCRIPTION
X.I Lesskey
Xis used to specify a set of key bindings to be used by
X.I less.
XThe input file is a text file which describes the key bindings,
Xand the output file is a binary file which is used by
X.I less.
XIf no input file is specified, standard input is used.
XIf no output file is specified, $HOME/.less is used.
X.PP
XThe input file consists of lines of the form:
X.sp
X string <whitespace> action <newline>
X.sp
XWhitespace is any sequence of one or more spaces and/or tabs.
XThe "string" is the command key(s) which invoke the action.
XThe string may be a single command key, or a sequence of up to 15 keys.
XThe "action" is the name of the less action, from the list below.
XThe characters in the "string" may appear literally, or be
Xprefixed by a carat to indicate a control key.
XA backslash may be used to cause the following character
Xto be taken literally.
XCharacters which must be preceded by backslash include
Xcarat, space, tab and the backslash itself.
XA backslash followed by one to three octal digits may be used to
Xspecify a character by its octal value.
XBlank lines and lines which start with a pound sign (#) are ignored.
X.PP
XA special case is the "toggle-option" action.
XThis action may be followed by a single letter indicating the
Xoption to be toggled.
XSee the ":ta" command in the example below.
X.PP
XAs an example, the following input file describes the set of
Xdefault command keys used by less:
X.sp
X.nf
X k back-line
X y back-line
X ^K back-line
X ^Y back-line
X ^P back-line
X b back-screen
X ^B back-screen
X \\33v back-screen
X u back-scroll
X ^U back-scroll
X ? back-search
X w back-window
X { bracket-{
X } bracket-}
X ( bracket-(
X ) bracket-)
X [ bracket-[
X ] bracket-]
X % bracket-any
X E examine
X :e examine
X ^X^V examine
X \\33/ file-search
X + first-cmd
X e forw-line
X j forw-line
X ^E forw-line
X ^J forw-line
X ^M forw-line
X ^N forw-line
X f forw-screen
X ^F forw-screen
X \\40 forw-screen
X ^V forw-screen
X d forw-scroll
X ^D forw-scroll
X / forw-search
X z forw-window
X G goto-end
X > goto-end
X \\33> goto-end
X g goto-line
X < goto-line
X \\33< goto-line
X ' goto-mark
X ^X^X goto-mark
X h help
X H help
X N next-file
X :n next-file
X p percent
X P prev-file
X :p prev-file
X q quit
X :q quit
X :Q quit
X ZZ quit
X ^L repaint
X ^R repaint
X r repaint
X R flush-repaint
X n repeat-search
X \\33n reverse-search
X m set-mark
X ! shell
X = status
X ^G status
X :f status
X - toggle-option
X :ta toggle-option t
X s toggle-option l
X _ display-option
X V version
X v visual
X
X.fi
X.sp
XCommands specified by
X.I lesskey
Xtake precedence over the default commands.
XA default command key may be disabled by including it in the
Xkey file with the action "invalid".
X
X.SH "SEE ALSO"
Xless(1)
END_OF_FILE
echo shar: Extracting \"vecho.c\"
sed "s/^X//" >'vecho.c' <<'END_OF_FILE'
X/*
X * This dumb little program emulates the System V "echo" command,
X * to accommodate BSD systems which don't understand the \c escape,
X * meaning don't echo a newline. BSD uses "echo -n".
X */
X
X#include <stdio.h>
X
Xint putnl;
X
Xmain(argc, argv)
X int argc;
X char *argv[];
X{
X putnl = 1;
X while (--argc > 0)
X {
X vecho(*++argv);
X if (argc > 1)
X putchar(' ');
X }
X if (putnl)
X putchar('\n');
X exit(0);
X}
X
Xvecho(str)
X char *str;
X{
X register char *s;
X
X for (s = str; *s != '\0'; s++)
X {
X if (*s == '\\' && s[1] == 'c')
X {
X putnl = 0;
X return;
X }
X putchar(*s);
X }
X}
END_OF_FILE
echo shar: Extracting \"mkfuncs.awk\"
sed "s/^X//" >'mkfuncs.awk' <<'END_OF_FILE'
XBEGIN { FS="("; state = 0 }
X
X/^ public/ { ftype = $0; state = 1 }
X
X{ if (state == 1)
X state = 2
X else if (state == 2)
X { print ftype,$1,"();"; state = 0 }
X}
END_OF_FILE
echo shar: Extracting \"less.help\"
sed "s/^X//" >'less.help' <<'END_OF_FILE'
X
X SUMMARY OF COMMANDS
X
X Commands marked with * may be preceded by a number, N.
X Notes in parentheses indicate the behavior if N is given.
X
X h H Display this help.
X q :q :Q ZZ Exit.
X
X e ^E j ^N CR * Forward one line (or N lines).
X y ^Y k ^K ^P * Backward one line (or N lines).
X f ^F ^V SPACE * Forward one window (or N lines).
X b ^B ESC-v * Backward one window (or N lines).
X z * Forward one window (and set window to N).
X w * Backward one window (and set window to N).
X d ^D * Forward one half-window (and set half-window to N).
X u ^U * Backward one half-window (and set half-window to N).
X r ^R ^L Repaint screen.
X R Repaint screen, discarding buffered input.
X
X NOTE: default "window" is the screen height.
X default "half-window" is half of the screen height.
X
X /pattern * Search forward for (N-th) matching line.
X ?pattern * Search backward for (N-th) matching line.
X ESC-/pattern * Search from top of file for (N-th) matching line.
X
X /!pattern * Search forward for (N-th) NON-matching line.
X ?!pattern * Search backward for (N-th) NON-matching line.
X ESC-/!pattern * Search from top of file for (N-th) NON-matching line.
X
X n * Repeat previous search (for N-th occurrence).
X ESC-n * Repeat previous search in reverse direction.
X
X g < ESC-< * Go to first line in file (or line N).
X G > ESC-> * Go to last line in file (or line N).
X p * Go to beginning of file (or N percent into file).
X % Go to a matching bracket.
X { * Go to the } which matches the (N-th) { in the top line.
X } * Go to the { which matches the (N-th) } in the top line.
X ( * Go to the ) which matches the (N-th) ( in the top line.
X ) * Go to the ( which matches the (N-th) ) in the top line.
X [ * Go to the ] which matches the (N-th) [ in the top line.
X ] * Go to the [ which matches the (N-th) ] in the top line.
X m<letter> Mark the current position with <letter>.
X '<letter> Go to a previously marked position.
X '' Go to the previous position.
X ^X^X Same as '.
X
X E [file] Examine a new file.
X :e ^X^V Same as E.
X :n N * Examine the (N-th) next file from the command line.
X :p P * Examine the (N-th) previous file from the command line.
X = ^G :f Print current file name.
X V Print version number of "less".
X
X -<flag> Toggle a command line flag [see FLAGS below].
X _<flag> Display the setting of a command line flag.
X +cmd Execute the less cmd each time a new file is examined.
X
X !command Passes the command to $SHELL to be executed.
X v Edit the current file with $EDITOR.
X
X
X FLAGS
X
X Most flags may be changed either on the command line,
X or from within less by using the - command.
X
X -a -A Set forward search starting location.
X -b [N] Number of buffers.
X -B Automatically allocate buffers.
X -c -C Repaint by scrolling/clearing.
X -d Dumb terminal.
X -e -E Quit at end of file.
X -f Force open non-regular files.
X -g Use 7 bit characters.
X -h [N] Backwards scroll limit.
X -i Ignore case in searches.
X -k [file] Use a lesskey file.
X -l [file] Log file.
X -L [file] Log file (unconditionally overwrite).
X -m -M Set prompt style.
X -n -N Use line numbers.
X -P [prompt] Define new prompt.
X -q -Q Quiet the terminal bell.
X -r Translate control characters.
X -s Squeeze multiple blank lines.
X -t [tag] Find a tag.
X -u -U Change handling of backspaces.
X -w Display ~ for lines after end-of-file.
X -x [N] Set tab stops.
X -z [N] Set size of window.
X
END_OF_FILE
echo shar: Extracting \"less.h\"
sed "s/^X//" >'less.h' <<'END_OF_FILE'
X/*
X * Standard include file for "less".
X */
X
X/*
X * Include the file of compile-time options.
X */
X#include "defines.h"
X
X/*
X * Language details.
X */
X#if !VOID
X#define void int
X#endif
X#define public /* PUBLIC FUNCTION */
X
X/*
X * Special types and constants.
X */
Xtypedef long POSITION;
X/*
X * {{ Warning: if POSITION is changed to other than "long",
X * you may have to change some of the printfs which use "%ld"
X * to print a variable of type POSITION. }}
X */
X
X#define NULL_POSITION ((POSITION)(-1))
X
X/*
X * The type of signal handler functions.
X * Usually int, although it should be void.
X */
Xtypedef int HANDLER;
X
X/*
X * The type of a file handle.
X * (Unfortunate name: HANDLE has nothing to do with HANDLER!)
X */
Xtypedef int HANDLE;
X
X#define FILENAME 128 /* Max size of a filename */
X
X#define EOI (0)
X
X#ifndef NULL
X#define NULL (0)
X#endif
X
X#define READ_INTR (-2)
X
X/* How quiet should we be? */
X#define NOT_QUIET 0 /* Ring bell at eof and for errors */
X#define LITTLE_QUIET 1 /* Ring bell only for errors */
X#define VERY_QUIET 2 /* Never ring bell */
X
X/* How should we prompt? */
X#define PR_SHORT 0 /* Prompt with colon */
X#define PR_MEDIUM 1 /* Prompt with message */
X#define PR_LONG 2 /* Prompt with longer message */
X
X/* How should we handle backspaces? */
X#define BS_SPECIAL 0 /* Do special things for underlining and bold */
X#define BS_NORMAL 1 /* \b treated as normal char; actually output */
X#define BS_CONTROL 2 /* \b treated as control char; prints as ^H */
X
X/* How should we search? */
X#define SRCH_FORW 0 /* Search forward from current position */
X#define SRCH_BACK 1 /* Search backward from current position */
X#define SRCH_FILE 2 /* Search forward from beginning of file */
X#define SRCH_NOMATCH 0100 /* Search for non-matching lines */
X#define SRCH_TYPE(t) ((t) & 077)
X#define SRCH_FLAG(t) ((t) & 0100)
X
X/* Special chars used to tell put_line() to do something special */
X#define CARATBIT (0x100)
X#define UL_CHAR (0x201) /* Enter underline mode */
X#define UE_CHAR (0x202) /* Exit underline mode */
X#define BO_CHAR (0x203) /* Enter boldface mode */
X#define BE_CHAR (0x204) /* Exit boldface mode */
X
X#define CONTROL(c) ((c)&037)
X#define SIGNAL(sig,func) signal(sig,func)
X
X/* Library function declarations */
Xoffset_t lseek();
X#define BAD_LSEEK ((offset_t)-1)
Xchar *calloc(), *ecalloc();
X
X#include "funcs.h"
END_OF_FILE
echo shar: Extracting \"position.h\"
sed "s/^X//" >'position.h' <<'END_OF_FILE'
X/*
X * Include file for interfacing to position.c modules.
X */
X#define TOP (0)
X#define TOP_PLUS_ONE (1)
X#define BOTTOM (-1)
X#define BOTTOM_PLUS_ONE (-2)
X#define MIDDLE (-3)
END_OF_FILE
echo shar: Extracting \"funcs.h\"
sed "s/^X//" >'funcs.h' <<'END_OF_FILE'
X public void end_logfile ();
X public void sync_logfile ();
X public int ch_seek ();
X public int ch_end_seek ();
X public int ch_beg_seek ();
X public POSITION ch_length ();
X public POSITION ch_tell ();
X public int ch_forw_get ();
X public int ch_back_get ();
X public void ch_init ();
X public void commands ();
X public int cmd_decode ();
X public void noprefix ();
X public int add_cmdtable ();
X public void add_hometable ();
X public void help ();
X public POSITION forw_line ();
X public POSITION back_line ();
X public void prewind ();
X public void plinenum ();
X public int pappend ();
X public int gline ();
X public void null_line ();
X public POSITION forw_raw_line ();
X public POSITION back_raw_line ();
X public void clr_linenum ();
X public void add_lnum ();
X public int find_linenum ();
X public POSITION find_pos ();
X public int currline ();
X public void edit ();
X public void next_file ();
X public void prev_file ();
X public void strtcpy ();
X public char * save ();
X public char * ecalloc ();
X public char * skipsp ();
X public void quit ();
X public void scan_option ();
X public void toggle_option ();
X public int single_char_option ();
X public char * opt_prompt ();
X public int isoptpending ();
X public void nopendopt ();
X public int getnum ();
X public void opt_l ();
X public void opt__L ();
X public void opt_k ();
X public void opt_t ();
X public void opt_P ();
X public void opt_b ();
X public void opt_g ();
X public void opt_query ();
X public void init_option ();
X public struct option * findopt ();
X public void lsystem ();
X public int iread ();
X public void intread ();
X public long get_time ();
X public char * fexpand ();
X public char * glob ();
X public char * glob ();
X public char * bad_file ();
X public POSITION filesize ();
X public char * bad_file ();
X public POSITION filesize ();
X public char * errno_message ();
X public char * errno_message ();
X public void put_line ();
X public int control_char ();
X public int carat_char ();
X public void flush ();
X public void dropout ();
X public void putchr ();
X public void putstr ();
X public void error ();
X public void ierror ();
X public POSITION position ();
X public void add_forw_pos ();
X public void add_back_pos ();
X public void pos_clear ();
X public void pos_init ();
X public int onscreen ();
X public HANDLE get_handle ();
X public void save_handle ();
X public char * get_filename ();
X public void store_pos ();
X public POSITION recall_pos ();
X public void forward ();
X public void backward ();
X public void repaint ();
X public void jump_forw ();
X public void jump_back ();
X public void jump_loc ();
X public void jump_percent ();
X public void init_mark ();
X public void setmark ();
X public void lastmark ();
X public void gomark ();
X public int get_back_scroll ();
X public void match_brac ();
X public void search ();
X public void init_prompt ();
X public char * pr_expand ();
X public char * eq_message ();
X public char * pr_string ();
X public void raw_mode ();
X public void get_term ();
X public void init ();
X public void deinit ();
X public void home ();
X public void add_line ();
X public void lower_left ();
X public void bell ();
X public void vbell ();
X public void clear ();
X public void clear_eol ();
X public void so_enter ();
X public void so_exit ();
X public void ul_enter ();
X public void ul_exit ();
X public void bo_enter ();
X public void bo_exit ();
X public void backspace ();
X public void putbs ();
X public HANDLER winch ();
X public HANDLER winch ();
X public void init_signals ();
X public void psignals ();
X public int findtag ();
X public int tagsearch ();
X public void open_getchr ();
X public int getchr ();
END_OF_FILE
echo shar: Extracting \"cmd.h\"
sed "s/^X//" >'cmd.h' <<'END_OF_FILE'
X#define MAX_USERCMD 200
X#define MAX_CMDLEN 16
X
X#define A_AGAIN_SEARCH 1
X#define A_B_LINE 2
X#define A_B_SCREEN 3
X#define A_B_SCROLL 4
X#define A_B_SEARCH 5
X#define A_DIGIT 6
X#define A_DISP_OPTION 7
X#define A_DEBUG 8
X#define A_EXAMINE 9
X#define A_FIRSTCMD 10
X#define A_FREPAINT 11
X#define A_F_LINE 12
X#define A_F_SCREEN 13
X#define A_F_SCROLL 14
X#define A_F_SEARCH 15
X#define A_GOEND 16
X#define A_GOLINE 17
X#define A_GOMARK 18
X#define A_HELP 19
X#define A_NEXT_FILE 20
X#define A_PERCENT 21
X#define A_PREFIX 22
X#define A_PREV_FILE 23
X#define A_QUIT 24
X#define A_REPAINT 25
X#define A_SETMARK 26
X#define A_SHELL 27
X#define A_STAT 28
X#define A_REVERSE_SEARCH 29
X#define A_TOGGLE_OPTION 30
X#define A_VERSION 31
X#define A_VISUAL 32
X#define A_F_WINDOW 33
X#define A_B_WINDOW 34
X#define A_T_SEARCH 35
X#define A_ANYBRAC 36
X#define A_BRACLP 37
X#define A_BRACRP 38
X#define A_BRACLC 39
X#define A_BRACRC 40
X#define A_BRACLS 41
X#define A_BRACRS 42
X
X#define A_INVALID 100
X#define A_NOACTION 101
X
X#define A_1_TOGGLE_OPTION (0200)
END_OF_FILE
echo shar: Extracting \"option.h\"
sed "s/^X//" >'option.h' <<'END_OF_FILE'
X#define END_OPTION_STRING ('$')
X
X/*
X * Types of options.
X */
X#define BOOL 01 /* Boolean option: 0 or 1 */
X#define TRIPLE 02 /* Triple-valued option: 0, 1 or 2 */
X#define NUMBER 04 /* Numeric option */
X#define STRING 010 /* String-valued option */
X#define NOVAR 020 /* No associated variable */
X#define REPAINT 040 /* Repaint screen after toggling option */
X#define NO_TOGGLE 0100 /* Option cannot be toggled with "-" cmd */
X
X#define OTYPE (BOOL|TRIPLE|NUMBER|STRING|NOVAR)
X
X/*
X * Argument to a handling function tells what type of activity:
X */
X#define INIT 0 /* Initialization (from command line) */
X#define QUERY 1 /* Query (from _ or - command) */
X#define TOGGLE 2 /* Change value (from - command) */
X
Xstruct option
X{
X char oletter; /* The controlling letter (a-z) */
X char otype; /* Type of the option */
X int odefault; /* Default value */
X int *ovar; /* Pointer to the associated variable */
X void (*ofunc)(); /* Pointer to special handling function */
X char *odesc[3]; /* Description of each value */
X};
X
END_OF_FILE
echo shar: Extracting \"lesskey.c\"
sed "s/^X//" >'lesskey.c' <<'END_OF_FILE'
X/*
X * lesskey [-o output] [input]
X *
X * Make a .less file.
X * If no input file is specified, standard input is used.
X * If no output file is specified, $HOME/.less is used.
X *
X * The .less file is used to specify (to "less") user-defined
X * key bindings. Basically any sequence of 1 to MAX_CMDLEN
X * keystrokes may be bound to an existing less function.
X *
X * The input file is an ascii file consisting of a
X * sequence of lines of the form:
X * string <whitespace> action <newline>
X *
X * "string" is a sequence of command characters which form
X * the new user-defined command. The command
X * characters may be:
X * 1. The actual character itself.
X * 2. A character preceded by ^ to specify a
X * control character (e.g. ^X means control-X).
X * 3. Any character (other than an octal digit) preceded by
X * a \ to specify the character itself (characters which
X * must be preceded by \ include ^, \, and whitespace.
X * 4. A backslash followed by one to three octal digits
X * to specify a character by its octal value.
X * "action" is the name of a "less" action, from the table below.
X *
X * Blank lines and lines which start with # are ignored.
X *
X *
X * The output file is a non-ascii file, consisting of
X * zero or more byte sequences of the form:
X * string <0> <action>
X *
X * "string" is the command string.
X * "<0>" is one null byte.
X * "<action>" is one byte containing the action code (the A_xxx value).
X *
X *
X * Revision history
X *
X * v1: Initial version. 10/13/87 mark
X */
X
X#include <stdio.h>
X#include "less.h"
X#include "cmd.h"
X
Xchar usertable[MAX_USERCMD];
X
Xstruct cmdname
X{
X char *cn_name;
X int cn_action;
X} cmdnames[] =
X{
X "back-line", A_B_LINE,
X "back-screen", A_B_SCREEN,
X "back-scroll", A_B_SCROLL,
X "back-search", A_B_SEARCH,
X "back-window", A_B_WINDOW,
X "bracket-{", A_BRACLC,
X "bracket-}", A_BRACRC,
X "bracket-(", A_BRACLP,
X "bracket-)", A_BRACRP,
X "bracket-[", A_BRACLS,
X "bracket-]", A_BRACRS,
X "bracket-any", A_ANYBRAC,
X "debug", A_DEBUG,
X "display-flag", A_DISP_OPTION,
X "display-option", A_DISP_OPTION,
X "end", A_GOEND,
X "examine", A_EXAMINE,
X "file-search", A_T_SEARCH,
X "first-cmd", A_FIRSTCMD,
X "firstcmd", A_FIRSTCMD,
X "flush-repaint", A_FREPAINT,
X "forw-line", A_F_LINE,
X "forw-screen", A_F_SCREEN,
X "forw-scroll", A_F_SCROLL,
X "forw-search", A_F_SEARCH,
X "forw-window", A_F_WINDOW,
X "goto-end", A_GOEND,
X "goto-line", A_GOLINE,
X "goto-mark", A_GOMARK,
X "help", A_HELP,
X "invalid", A_NOACTION,
X "next-file", A_NEXT_FILE,
X "noaction", A_NOACTION,
X "percent", A_PERCENT,
X "prev-file", A_PREV_FILE,
X "quit", A_QUIT,
X "repaint", A_REPAINT,
X "repaint-flush", A_FREPAINT,
X "repeat-search", A_AGAIN_SEARCH,
X "reverse-search", A_REVERSE_SEARCH,
X "set-mark", A_SETMARK,
X "shell", A_SHELL,
X "status", A_STAT,
X "toggle-flag", A_TOGGLE_OPTION,
X "toggle-option", A_TOGGLE_OPTION,
X "version", A_VERSION,
X "visual", A_VISUAL,
X NULL, 0
X};
X
Xmain(argc, argv)
X int argc;
X char *argv[];
X{
X char *p; /* {{ Can't be register since we use &p }} */
X register char *up; /* Pointer into usertable */
X FILE *desc; /* Description file (input) */
X FILE *out; /* Output file */
X int linenum; /* Line number in input file */
X char *currcmd; /* Start of current command string */
X int errors;
X int i, j;
X char line[100];
X char *outfile;
X
X extern char *getenv();
X
X /*
X * Process command line arguments.
X */
X outfile = NULL;
X while (--argc > 0 && **(++argv) == '-')
X {
X switch (argv[0][1])
X {
X case 'o':
X outfile = &argv[0][2];
X if (*outfile == '\0')
X {
X if (--argc <= 0)
X usage();
X outfile = *(++argv);
X }
X break;
X default:
X usage();
X }
X }
X if (argc > 1)
X usage();
X
X
X /*
X * Open the input file, or use standard input if none specified.
X */
X if (argc > 0)
X {
X if ((desc = fopen(*argv, "r")) == NULL)
X {
X perror(*argv);
X exit(1);
X }
X } else
X desc = stdin;
X
X /*
X * Read the input file, one line at a time.
X * Each line consists of a command string,
X * followed by white space, followed by an action name.
X */
X linenum = 0;
X errors = 0;
X up = usertable;
X while (fgets(line, sizeof(line), desc) != NULL)
X {
X ++linenum;
X
X /*
X * Skip leading white space.
X * Replace the final newline with a null byte.
X * Ignore blank lines and comment lines.
X */
X p = line;
X while (*p == ' ' || *p == '\t')
X ++p;
X for (i = 0; p[i] != '\n' && p[i] != '\0'; i++)
X ;
X p[i] = '\0';
X if (*p == '#' || *p == '\0')
X continue;
X
X /*
X * Parse the command string and store it in the usertable.
X */
X currcmd = up;
X do
X {
X if (up >= usertable + MAX_USERCMD)
X {
X fprintf(stderr, "too many commands, line %d\n",
X linenum);
X exit(1);
X }
X if (up >= currcmd + MAX_CMDLEN)
X {
X fprintf(stderr, "command too long on line %d\n",
X linenum);
X errors++;
X break;
X }
X
X *up++ = tchar(&p);
X
X } while (*p != ' ' && *p != '\t' && *p != '\0');
X
X /*
X * Terminate the command string with a null byte.
X */
X *up++ = '\0';
X
X /*
X * Skip white space between the command string
X * and the action name.
X * Terminate the action name if it is followed
X * by whitespace or a # comment.
X */
X if (*p == '\0')
X {
X fprintf(stderr, "missing whitespace on line %d\n",
X linenum);
X errors++;
X continue;
X }
X while (*p == ' ' || *p == '\t')
X ++p;
X for (j = 0; p[j] != ' ' && p[j] != '\t' &&
X p[j] != '#' && p[j] != '\0'; j++)
X ;
X p[j] = '\0';
X
X /*
X * Parse the action name and store it in the usertable.
X */
X for (i = 0; cmdnames[i].cn_name != NULL; i++)
X if (strcmp(cmdnames[i].cn_name, p) == 0)
X break;
X if (cmdnames[i].cn_name == NULL)
X {
X fprintf(stderr, "unknown action <%s> on line %d\n",
X p, linenum);
X errors++;
X continue;
X }
X if (cmdnames[i].cn_action == A_TOGGLE_OPTION)
X {
X for (j = j+1; p[j] == ' ' || p[j] == '\t'; j++)
X ;
X if (p[j] != '\0')
X *up++ = A_1_TOGGLE_OPTION | p[j];
X else
X *up++ = A_TOGGLE_OPTION;
X } else
X *up++ = cmdnames[i].cn_action;
X }
X
X if (errors > 0)
X {
X fprintf(stderr, "%d errors; no output produced\n", errors);
X exit(1);
X }
X
X /*
X * Write the output file.
X * If no output file was specified, use "$HOME/.less"
X */
X if (outfile == NULL)
X {
X p = getenv("HOME");
X if (p == NULL)
X {
X fprintf(stderr, "cannot find $HOME\n");
X exit(1);
X }
X strcpy(line, p);
X strcat(line, "/.less");
X outfile = line;
X }
X if ((out = fopen(outfile, "w")) == NULL)
X perror(outfile);
X else
X fwrite((char *)usertable, 1, up-usertable, out);
X}
X
X/*
X * Parse one character of the command string.
X */
Xtchar(pp)
X char **pp;
X{
X register char *p;
X register char ch;
X register int i;
X
X p = *pp;
X switch (*p)
X {
X case '\\':
X if (*++p >= '0' && *p <= '7')
X {
X /*
X * Parse an octal number.
X */
X ch = 0;
X i = 0;
X do
X ch = 8*ch + (*p - '0');
X while (*++p >= '0' && *p <= '7' && ++i < 3);
X *pp = p;
X return (ch);
X }
X /*
X * Backslash followed by a char just means that char.
X */
X *pp = p+1;
X return (*p);
X case '^':
X /*
X * Carat means CONTROL.
X */
X *pp = p+2;
X return (CONTROL(p[1]));
X }
X *pp = p+1;
X return (*p);
X}
X
Xusage()
X{
X fprintf(stderr, "usage: lesskey [-o output] [input]\n");
X exit(1);
X}
END_OF_FILE
More information about the Alt.sources
mailing list