XP(1)

NAME
xp - print a file in an X window

SYNOPSIS
xp [ -toolkitoption ] [ -option... ] [ file ... ]

DESCRIPTION
xp is a multi-file display program, based around the Athena Text widget, with useful searching facilities and a simple command language. If no file arguments are given it will display standard input; shell commands may be issued which use the whole file or the current selection as standard input with the result going to standard output.

xp accepts all of the standard X Toolkit command line options as well as the following (if the option begins with a `+' instead of a `-', the option is restored to its default value):

-c command
    Commence by executing command.

-m  Cause searches to look at multiple files, i.e. set resource searchMany true.

-i  Make searches case insensitive, i.e. set resource caseSensitive false.

-w  Cause searches not to wrap, i.e set resource searchWrap false.

See also the section on RESOURCES.

xp shows the first file and offers a menu (files) whereby any one of the other files may be displayed (in the same window). The files menu is activated by clicking button 2.

Clicking on button 1 of the files menu button displays the next file and button 3 the previous; this use of mouse buttons is designed to be analogous to that used in the scrollbar.

If no filename argument is given, or if the argument `-' is given, xp reads from the standard input. If the standard input is a terminal, input is terminated by an EOF condition. In all cases no output appears until EOF is detected, however if 0 or 1 filenames are given and EOF is detected immediately then xp exits silently.

xp normally obeys the standard -geometry argument or resource, treating the width & height as characters not usual pixels. However if no filename arguments are given then the height of the xp window will be adjusted to fit the input if less than the given geometry specification.

The split command button allows two views of the same file to be shown in separate panes. Selecting another file from the files menu leaves the upper pane showing the original file. If the display window has been split then input commands (see below) refer to the pane currently or most recently containing the pointer whereas options menu items apply to both panes. You may use the flip command to reverse the contents of the two panes.

Though displaying a file in a readonly text widget xp uses the caret as follows: A "split" is made just below the caret if possible. You can find the line number of the caret. Moving through the file via searching or line number sets the caret. The "reopen" button reopens the current file and trys to maintain the old position of the caret - you can use this to see if the file has grown.

The input command text widget (bottom right) accepts a few ed/sam like commands, you can type commands into it or select some ready made ones from the menu to its left. In the description of the commands which follows the line containing the caret is termed the current line. Commands which select text scroll to make the text visible if necessary, and may also centre the new current line.

The commands are:

nnn Select line nnn.

+nnn
    Select the line nnn lines beyond the current line. Remember nnn for subseqent default.

-nnn
    Select the line nnn lines before the current line. Remember nnn for subseqent default.

$   Select the last line.

,   Select the whole file.

.   Scroll text to centre the current line.

.=  Output the number of the current line.

=   Output the number of the lines in the file

/RE Forward full regular expression search, from caret, with optional wrap round at eof. Set the selection to the matched text, set the caret to the end of that selection. Use previous RE if RE empty

?RE Backward full regular expression search, from caret, with optional wrap around at start of file. Set the selection to the matched text, set the caret to the start of that selection. Use previous RE if RE empty.

!   Execute the rest of the line as a shell command. You may use $i to refer to the current file and $* to all files. (By default /bin/sh is used but you can override this with the useMyShell resource, see RESOURCES section.)

|   Execute the rest of the line as a shell command passing the currently displayed file as stdin.

>   Execute the rest of the line as a shell command passing the current selection as stdin.

b filename
    Display the file filename if it is in the files menu.

n   Display the next file in the files menu.

p   Display the previous file in the files menu.

q quit

All commands must be terminated by <return>.

A <return> by itself moves the caret one line on and scrolls forward one line.

REGULAR EXPRESSION SYNTAX
A regular expression is zero or more branches, separated by `|'. It matches anything that matches one of the branches.

A branch is zero or more pieces, concatenated. It matches a match for the first, followed by a match for the second, etc.

A piece is an atom possibly followed by `*', `+', or `?'. An atom followed by `*' matches a sequence of 0 or more matches of the atom. An atom followed by `+' matches a sequence of 1 or more matches of the atom. An atom followed by `?' matches a match of the atom, or the null string.

An atom is a regular expression in parentheses (matching a match for the regular expression), a range (see below), `.' (matching any single character), `^' (matching the null string at the beginning of the input string), `$' (matching the null string at the end of the input string), a `\' followed by a single character (matching that character), or a single character with no other significance (matching that character).

A range is a sequence of characters enclosed in `[]'. It normally matches any single character from the sequence. If the sequence begins with `^', it matches any single character not from the rest of the sequence. If two characters in the sequence are separated by `-', this is shorthand for the full list of ASCII characters between them (e.g. `[0-9]' matches any decimal digit) To include a literal `]' in the sequence, make it the first character (following a possible `^'). To include a literal `-', make it the first or last character.

AMBIGUITY
If a regular expression could match two different parts of the input string, it will match the one which begins earliest. If both begin in the same place but match different lengths, or match the same length in different ways, life gets messier, as follows.

In general, the possibilities in a list of branches are considered in left-to-right order, the possibilities for `*', `+', and `?' are considered longest-first, nested constructs are considered from the outermost in, and concatenated constructs are considered leftmost-first. The match that will be chosen is the one that uses the earliest possibility in the first choice that has to be made. If there is more than one choice, the next will be made in the same manner (earliest possibility) subject to the decision on the first choice. And so forth.

For example, `(ab|a)b*c' could match `abc' in one of two ways. The first choice is between `ab' and `a'; since `ab' is earlier, and does lead to a successful overall match, it is chosen. Since the `b' is already spoken for, the `b*' must match its last possibility—the empty string—since it must respect the earlier choice.

In the particular case where no `|'s are present and there is only one `*', `+', or `?', the net effect is that the longest possible match will be chosen. So `ab*', presented with `xabbbby', will match `abbbb'. Note that if `ab*' is tried against `xabyabbbz', it will match `ab' just after `x', due to the begins-earliest rule. (In effect, the decision on where to start the match is the first choice to be made, hence subsequent choices must respect it even if this leads them to less-preferred alternatives.)

EXAMPLE
man  | col -b | cat -s | xp -i  -geometry x40&
pops up the xp manual page in an xp window, 40 lines long with case insensitive searching enabled. The xpman shell script supplied with xp is a more elaborate version of this command.

TRANSLATIONS
xp contains 3 text widgets, two for output only (one of which may not be displayed) and one for command input. To make it easy to type commands without having the input widget (bottom right) take the input focus, and without introducing input modes, default translations are set up such that keyboard input within the output text widgets is redirected to the input widget apart from those standard Text widget translations that refer to vertical motion.

RESOURCES
xp has the following application specific resources:

autoExec (Class AutoExec)
    If true (not the default) then a command selected from the commands menu is executed immediately rather than being displayed for perusal or editing prior to execution.

caseSensitive (Class CaseSensitive)
    If true (the default) then regular expression searches are case sensitive.

cmndsList (Class CmndsList)
    A list of commands which appear in the commands menu.

command (Class Command)
    A command executed initially as if typed into the input command widget (but with no need of a trailing <return> ).

samDoubleClick (Class SamDoubleClick)
    Make a double click select text to the boundaries of words, lines, quoted strings or bracketed strings in the manner of Rob Pike's editor sam. (Unfortunately this currently stops button 1 drag selections from working).

searchWrap (Class SearchWrap)
    If true (default) then forward regular expression searches wrap around to beginning of file when reaching EOF and likewise for reverse searches.

searchMany (Class SearchMany)
    If true (not the default) then regular expression searches continue across file boundaries. If searchWrap is also true then rather than searches wrapping round at the end of file they wrap round from the end of the last file to the first and vice-versa, for forward and backward searches respectively.

setIconName (Class SetIconName)
    When true (default) causes xp to append the current filename to the xp icon name.

setTitle (Class SetTitle)
    When true (default) causes xp to append the current filename to the xp title.

terse (Class Terse)
    When true (not the default) prevents error message popups.

useMyShell (Class UseMyShell)
    When true (not the default) use $SHELL or $shell to execute commands with !,>,| rather than sh.

WIDGETS
In order to specify resources, it is useful to know the hierarchy of the widgets which compose xp. In the notation below, indentation indicates hierarchical structure. The widget class name is given first, followed by the widget instance name.

Xp  xp
	TopLevelShell  shell
		Paned  paned
			Paned  vpaned
				Text  textmain
				Grip  grip
				Text  textsplit
				Grip  grip
			Paned  hpaned
				Command  quit
				MenuButton  files
					SimpleMenu  filesmenu
                                                SmeBSB  file1
                                                SmeBSB  file2
                                                .
                                                .
                                                .
				MenuButton  options
					SimpleMenu  optionsmenu
						SmeBSB  wrap word
						SmeBSB  wrap line
						SmeBSB  horiz scroll
						SmeLine line
						SmeBSB  case insensitive
						SmeBSB  search wrap
						SmeBSB  search many
						SmeLine line
						SmeBSB  terse
				Command  help
				Command  reopen
				Toggle  split
				Command  flip
				Text  textinput
			Grip  grip
	TopLevelShell  helpshell
		Paned  helppaned
			Label  helplabel
			Text  helptext
			Command  helpdismiss
	TransientShell  errorshell
		Form  errorform
			Label  errorlabel
			Command  errordismiss

ENVIRONMENT

DISPLAY
    to get the default host and display number.

FILES
/usr/pkg/lib/X11/app-defaults/Xp - specifies required resources

SEE ALSO
cat(1), ed(1), egrep(1), sam(1), xpman(1), X(1) Athena Widget Set

AUTHOR
Gerry Tomlinson (gerry.tomlinson@newcastle.ac.uk)

COPYRIGHT
Copyright 1991-9, The Computing Laboratory, University of Newcastle Upon Tyne

ACKNOWLEDGMENTS
Regular expression code and description are by Henry Spencer @ U of Toronto Zoology, henry@zoo.toronto.edu. They are intended to be compatible with the Bell V8 regexp(3) but are not derived from Bell code.

BUGS
The regular expression syntax probably doesn't exactly match that of the egrep(1) on your system.

Doesn't handle binary files.

Menus popup over the previously selected item, except when the menu won't fit on the screen.

The samDoubleClick bracket matching facility stops button 1 drag selection working.