pager.c revision afc2ba1deb75b323afde536f2dd18bcafdaa308d
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * Copyright (c) 1998 Michael Smith <msmith@freebsd.org>
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * All rights reserved.
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * Redistribution and use in source and binary forms, with or without
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * modification, are permitted provided that the following conditions
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * 1. Redistributions of source code must retain the above copyright
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * notice, this list of conditions and the following disclaimer.
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * 2. Redistributions in binary form must reproduce the above copyright
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * notice, this list of conditions and the following disclaimer in the
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * documentation and/or other materials provided with the distribution.
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * SUCH DAMAGE.
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * Simple paged-output and paged-viewing functions
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soomestatic char *pager_prompt1 = \
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome " --more-- <space> page down <enter> line down <q> quit ";
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soomestatic char *pager_blank = \
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * 'open' the pager
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome if (ioctl(1, TIOCGWINSZ, &ws) == -1 || ws.ws_row == 0) {
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * 'close' the pager
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * Emit lines to the pager; may not return until the user
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * has responded to the prompt.
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * Will return nonzero if the user enters 'q' or 'Q' at the prompt.
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * XXX note that this watches outgoing newlines (and eats them), but
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * does not handle wrap detection (req. count of columns).
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome while (action == 0) {
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * Display from (fd).
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome printf("can't open '%s': %s\n", fname, strerror(errno));
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome return (-1);