209e49b2ff611e7d61ff58e13756ae67f51be550Chris Love * Copyright (c) 1991, 1993
209e49b2ff611e7d61ff58e13756ae67f51be550Chris Love * The Regents of the University of California. All rights reserved.
209e49b2ff611e7d61ff58e13756ae67f51be550Chris Love * This code is derived from software contributed to Berkeley by
209e49b2ff611e7d61ff58e13756ae67f51be550Chris Love * Edward Sze-Tyan Wang.
209e49b2ff611e7d61ff58e13756ae67f51be550Chris Love * Redistribution and use in source and binary forms, with or without
209e49b2ff611e7d61ff58e13756ae67f51be550Chris Love * modification, are permitted provided that the following conditions
209e49b2ff611e7d61ff58e13756ae67f51be550Chris Love * 1. Redistributions of source code must retain the above copyright
209e49b2ff611e7d61ff58e13756ae67f51be550Chris Love * notice, this list of conditions and the following disclaimer.
209e49b2ff611e7d61ff58e13756ae67f51be550Chris Love * 2. Redistributions in binary form must reproduce the above copyright
209e49b2ff611e7d61ff58e13756ae67f51be550Chris Love * notice, this list of conditions and the following disclaimer in the
209e49b2ff611e7d61ff58e13756ae67f51be550Chris Love * documentation and/or other materials provided with the distribution.
209e49b2ff611e7d61ff58e13756ae67f51be550Chris Love * 4. Neither the name of the University nor the names of its contributors
209e49b2ff611e7d61ff58e13756ae67f51be550Chris Love * may be used to endorse or promote products derived from this software
209e49b2ff611e7d61ff58e13756ae67f51be550Chris Love * without specific prior written permission.
209e49b2ff611e7d61ff58e13756ae67f51be550Chris Love * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
209e49b2ff611e7d61ff58e13756ae67f51be550Chris Love * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
209e49b2ff611e7d61ff58e13756ae67f51be550Chris Love * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
209e49b2ff611e7d61ff58e13756ae67f51be550Chris Love * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
209e49b2ff611e7d61ff58e13756ae67f51be550Chris Love * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
209e49b2ff611e7d61ff58e13756ae67f51be550Chris Love * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
209e49b2ff611e7d61ff58e13756ae67f51be550Chris Love * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
209e49b2ff611e7d61ff58e13756ae67f51be550Chris Love * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
209e49b2ff611e7d61ff58e13756ae67f51be550Chris Love * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
209e49b2ff611e7d61ff58e13756ae67f51be550Chris Love * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
209e49b2ff611e7d61ff58e13756ae67f51be550Chris Love * SUCH DAMAGE.
209e49b2ff611e7d61ff58e13756ae67f51be550Chris Love * bytes -- read bytes to an offset from the end and display.
209e49b2ff611e7d61ff58e13756ae67f51be550Chris Love * This is the function that reads to a byte offset from the end of the input,
209e49b2ff611e7d61ff58e13756ae67f51be550Chris Love * storing the data in a wrap-around buffer which is then displayed. If the
209e49b2ff611e7d61ff58e13756ae67f51be550Chris Love * rflag is set, the data is displayed in lines in reverse order, and this
209e49b2ff611e7d61ff58e13756ae67f51be550Chris Love * routine has the usual nastiness of trying to find the newlines. Otherwise,
209e49b2ff611e7d61ff58e13756ae67f51be550Chris Love * it is displayed from the character closest to the beginning of the input to
209e49b2ff611e7d61ff58e13756ae67f51be550Chris Love for (wrap = 0, ep = p + off; (ch = getc(fp)) != EOF; ) {
209e49b2ff611e7d61ff58e13756ae67f51be550Chris Love if (++p == ep) {
209e49b2ff611e7d61ff58e13756ae67f51be550Chris Love if (*t == '\n') {
209e49b2ff611e7d61ff58e13756ae67f51be550Chris Love * lines -- read lines to an offset from the end and display.
209e49b2ff611e7d61ff58e13756ae67f51be550Chris Love * This is the function that reads to a line offset from the end of the input,
209e49b2ff611e7d61ff58e13756ae67f51be550Chris Love * storing the data in an array of buffers which is then displayed. If the
209e49b2ff611e7d61ff58e13756ae67f51be550Chris Love * rflag is set, the data is displayed in lines in reverse order, and this
209e49b2ff611e7d61ff58e13756ae67f51be550Chris Love * routine has the usual nastiness of trying to find the newlines. Otherwise,
209e49b2ff611e7d61ff58e13756ae67f51be550Chris Love * it is displayed from the line closest to the beginning of the input to
209e49b2ff611e7d61ff58e13756ae67f51be550Chris Love if ((llines = malloc(off * sizeof (*llines))) == NULL)