forward.c revision 209e49b2ff611e7d61ff58e13756ae67f51be550
/*
* Copyright (c) 1991, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Edward Sze-Tyan Wang.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
/*
* Solaris porting notes: the original FreeBSD version made use of the
* BSD kqueue event notification framework; this
* was changed to use the Solaris event completion
* framework: port_create(), port_associate(),
* and port_get().
*/
#include <port.h>
#include <err.h>
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "extern.h"
static int show(file_info_t *);
/* defines for inner loop actions */
#define USE_SLEEP 0
#define USE_PORT 1
#define ADD_EVENTS 2
int port;
static const file_info_t *last;
/*
* forward -- display the file, from an offset, forward.
*
* There are eight separate cases for this -- regular and non-regular
* files, by bytes or lines and from the beginning or end of the file.
*
* FBYTES byte offset from the beginning of the file
* REG seek
* NOREG read, counting bytes
*
* FLINES line offset from the beginning of the file
* REG read, counting lines
* NOREG read, counting lines
*
* RBYTES byte offset from the end of the file
* REG seek
* NOREG cyclically read characters into a wrap-around buffer
*
* RLINES
* REG mmap the file and step back until reach the correct offset.
* NOREG cyclically read lines into a wrap-around array of buffers
*/
void
{
int ch;
switch (style) {
case FBYTES:
if (off == 0)
break;
return;
}
} else while (off--)
return;
}
break;
}
break;
case FLINES:
if (off == 0)
break;
for (;;) {
return;
}
break;
}
break;
}
break;
case RBYTES:
return;
}
} else if (off == 0) {
;
return;
}
} else
return;
break;
case RLINES:
if (!off) {
return;
}
} else
else if (off == 0) {
;
return;
}
} else
return;
break;
default:
break;
}
oerr();
return;
}
}
/*
* rlines -- display the last offset lines of the file.
*/
static void
{
int i;
return;
/*
* Last char is special, ignore whether newline or not. Note that
* size == 0 is dealt with above, and size == 1 sets curoff to -1.
*/
while (curoff >= 0) {
return;
}
break;
/* `i' is either the map offset of a '\n', or -1. */
if (i >= 0)
break;
}
curoff++;
exit(1);
}
/* Set the file pointer to reflect the length displayed. */
return;
}
return;
}
}
static int
{
int ch;
if (!qflag)
(void) printf("\n==> %s <==\n",
}
oerr();
}
return (0);
}
return (1);
}
static void
{
int i;
continue;
/* For -f or -F will both use Solaris port interface */
}
}
}
/*
* follow -- display the file, from an offset, forward.
*
*/
void
{
/* Position each of the files */
active = 0;
n = 0;
active = 1;
n++;
(void) printf("\n==> %s <==\n",
n++;
}
}
return;
port = port_create();
for (;;) {
ev_change = 0;
if (Fflag) {
== -1) {
}
ev_change++;
continue;
}
continue;
ev_change++;
continue;
}
sizeof (struct stat));
ev_change++;
}
}
}
ev_change++;
if (ev_change)
switch (action) {
case USE_PORT:
/*
* In the -F case we set a timeout to ensure that
* we re-stat the file at least once every second.
*/
if (n == 0) {
}
break;
case USE_SLEEP:
(void) usleep(250000);
break;
}
}
}