version 1.2, 1996/06/26 05:40:18 |
version 1.3, 1997/01/12 23:43:07 |
|
|
|
|
#include <sys/types.h> |
#include <sys/types.h> |
#include <sys/stat.h> |
#include <sys/stat.h> |
|
|
|
#include <err.h> |
#include <errno.h> |
#include <errno.h> |
#include <unistd.h> |
|
#include <stdio.h> |
#include <stdio.h> |
#include <stdlib.h> |
#include <stdlib.h> |
#include <string.h> |
#include <string.h> |
|
#include <unistd.h> |
|
|
#include "extern.h" |
#include "extern.h" |
|
|
int fflag, rflag, rval; |
int fflag, rflag, rval; |
|
|
{ |
{ |
struct stat sb; |
struct stat sb; |
FILE *fp; |
FILE *fp; |
long off; |
long off = 0; |
enum STYLE style; |
enum STYLE style; |
int ch, first; |
int ch, first; |
char *p; |
char *p; |
|
|
usage(); \ |
usage(); \ |
off = strtol(optarg, &p, 10) * (units); \ |
off = strtol(optarg, &p, 10) * (units); \ |
if (*p) \ |
if (*p) \ |
err(1, "illegal offset -- %s", optarg); \ |
errx(1, "illegal offset -- %s", optarg); \ |
switch(optarg[0]) { \ |
switch(optarg[0]) { \ |
case '+': \ |
case '+': \ |
if (off) \ |
if (off) \ |
|
|
argv += optind; |
argv += optind; |
|
|
if (fflag && argc > 1) |
if (fflag && argc > 1) |
err(1, "-f option only appropriate for a single file"); |
errx(1, "-f option only appropriate for a single file"); |
|
|
/* |
/* |
* If displaying in reverse, don't permit follow option, and convert |
* If displaying in reverse, don't permit follow option, and convert |
|
|
} |
} |
|
|
if (*argv) |
if (*argv) |
for (first = 1; fname = *argv++;) { |
for (first = 1; (fname = *argv++);) { |
if ((fp = fopen(fname, "r")) == NULL || |
if ((fp = fopen(fname, "r")) == NULL || |
fstat(fileno(fp), &sb)) { |
fstat(fileno(fp), &sb)) { |
ierr(); |
ierr(); |
|
|
int len; |
int len; |
char *start; |
char *start; |
|
|
while (ap = *++argv) { |
while ((ap = *++argv)) { |
/* Return if "--" or not an option of any form. */ |
/* Return if "--" or not an option of any form. */ |
if (ap[0] != '-') { |
if (ap[0] != '-') { |
if (ap[0] != '+') |
if (ap[0] != '+') |
|
|
/* Malloc space for dash, new option and argument. */ |
/* Malloc space for dash, new option and argument. */ |
len = strlen(*argv); |
len = strlen(*argv); |
if ((start = p = malloc(len + 3)) == NULL) |
if ((start = p = malloc(len + 3)) == NULL) |
err(1, "%s", strerror(errno)); |
err(1, NULL); |
*p++ = '-'; |
*p++ = '-'; |
|
|
/* |
/* |
|
|
*p++ = 'n'; |
*p++ = 'n'; |
break; |
break; |
default: |
default: |
err(1, "illegal option -- %s", *argv); |
errx(1, "illegal option -- %s", *argv); |
} |
} |
*p++ = *argv[0]; |
*p++ = *argv[0]; |
(void)strcpy(p, ap); |
(void)strcpy(p, ap); |