modified for inclusion in GNO base build

This commit is contained in:
gdr 1997-10-30 03:35:21 +00:00
parent e04dacb065
commit fbcef9625a
16 changed files with 171 additions and 260 deletions

11
bin/tee/Makefile Normal file
View File

@ -0,0 +1,11 @@
#
# This makefile is intended for use with dmake(1).
#
# $Id: Makefile,v 1.1 1997/10/30 03:32:44 gdr Exp $
PROG = tee
# Use -D__STACK_CHECK__ to measure stack usage (currently requires 1024 bytes).
CFLAGS +=
.INCLUDE: /src/gno/prog.mk

View File

@ -1,30 +1,29 @@
tee v1.2 for Gno
$Id: README,v 1.4 1997/10/30 03:32:45 gdr Exp $
The tee that ships with Gno (and hereforth designated v1.0) seems to have
fully buffered output, making it next to useless. This version of tee
has no buffering on stdin/stdout by default, so you see the output as
tee v1.3 for GNO
The tee that shiped with GNO v2.0.4 (and hereforth designated v1.0) seems
to have fully buffered output, making it next to useless. This version of
tee has no buffering on stdin/stdout by default, so you see the output as
it's being read. This version also allows multiple output files, appending,
and ignoring of SIGINT.
To install copy tee to /bin and tee.1 to /usr/man/man1, or just type
"dmake install".
This program contains material from the Orca/C Run-Time Libraries,
copyright 1987-1994 by Byte Works, Inc. Used with Permission.
Devin Reade
<gdr@myrias.ab.ca>
$Id: README,v 1.3 1996/09/09 06:12:14 gdr Exp $
<gdr@eddore.myrias.com>
Change Log
==========
v1.0 Designated as the version shipped with GNO v2.0.4
v1.3 Slight changes to incorporate it into the GNO v2.0.6.
v1.2 Added -b (line buffering) option. STDIN_FILENO is no longer
directly read; stdio is used.
v1.1 Rewrite from scratch by Devin Reade. Default changed from
full buffering to no buffering. Added options for multiple
output files, appending and ignoring of SIGINT.
v1.2 Added -b (line buffering) option. STDIN_FILENO is no longer
directly read; stdio is used.
v1.0 Designated as the version shipped with GNO v2.0.4

View File

@ -1,34 +0,0 @@
#
# This makefile is intended for use with dmake(1)
#
# $Id: makefile.mk,v 1.3 1996/09/09 06:12:15 gdr Exp $
#
INSTALL = /usr/bin/install
BINDIR = /bin
MANDIR = /man/man1
DEFINES = -D_POSIX_SOURCE
# CFLAGS = -w -i -G25 -v -DCHECK_STACK=1 $(DEFINES)
# LDFLAGS = -l/usr/lib/gnulib -l/usr/lib/stack
CFLAGS = -w -i -O -s768 $(DEFINES)
LDFLAGS = -l/usr/lib/gnulib -s768
tee: tee.o tee.r
@purge
$(CC) $(LDFLAGS) tee.o $(LDLIBS) -o $@
copyfork tee.r tee -r
testtee: testtee.c
@purge
$(CC) -v -w $< -o $@
install:
$(INSTALL) -m755 -obin -gsys -d $(BINDIR) $(MANDIR)
$(INSTALL) -m755 -obin -gsys tee $(BINDIR)
$(INSTALL) -m644 -obin -gsys tee.1 $(MANDIR)
clean clobber:
$(RM) -f tee.r tee.o tee.root testtee testtee.o testtee.root

View File

@ -1,7 +1,7 @@
.\" $Id: tee.1,v 1.3 1996/09/09 06:12:15 gdr Exp $
.\"
.\" .TH TEE 1 "8 September 1996" "Version 1.2" "Commands and Applications"
.TH TEE 1 "Commands and Applications" "8 September 1996" "Version 1.2"
.\" $Id: tee.1,v 1.4 1997/10/30 03:32:46 gdr Exp $
.\"
.TH TEE 1 "5 October 1997" GNO "Commands and Applications"
.SH NAME
tee \- Pipe fitting.
.SH SYNOPSIS
@ -53,9 +53,13 @@ will contain the output up to that point.
.LP
The return value is 0 on success, and 1 if an error
occurs.
.SH VERSION
This manual page documents
.BR tee
version 1.3.
.SH STANDARDS
.B Tee
is POSIX p1003.2 compatible.
.SH HISTORY
.B Tee
first appeared in Gno v1.x. Version 1.1 and later written by Devin Reade.
first appeared in GNO v1.x. Version 1.1 and later were written by Devin Reade.

View File

@ -3,12 +3,12 @@
*
* Version 1.1 and later by Devin Reade <gdr@myrias.ab.ca>
*
* tee originally appeared with Gno v1.x, but was fully buffered.
* tee originally appeared with GNO v1.x, but was fully buffered.
* This is a complete re-write which by default uses full buffering
* for the output file, but _no_ buffering on stdin and stdout.
* This buffering behavior can be changed slightly by the -b flag.
*
* $Id: tee.c,v 1.3 1996/09/09 06:12:16 gdr Exp $
* $Id: tee.c,v 1.4 1997/10/30 03:32:46 gdr Exp $
*/
#include <sys/types.h>
@ -17,41 +17,33 @@
#include <signal.h>
#include <fcntl.h>
#include <unistd.h>
#include "getopt.h"
#include <err.h>
#ifdef CHECK_STACK
void begin_stack_check(void);
int end_stack_check(void);
#define STACKSTART begin_stack_check()
#define STACKEND(n) { \
fprintf(stderr,"stack usage: %d bytes\n",end_stack_check()); \
return n; \
#ifdef __STACK_CHECK__
#include <gno/gno.h>
static void
showstack (void) {
fprintf(stderr,"stack usage: %d bytes\n", _endStackCheck());
return;
}
#else
#define STACKSTART
#define STACKEND(n) return n
#endif
#endif /* __STACK_CHECK__ */
#define BUFFERSIZE 512
#define USAGE { \
fprintf(stderr,"%s %s\nUsage:\t%s %s\n",argv[0],versionstr,argv[0], \
usagestr); \
STACKEND(-1); \
}
char *versionstr = "version 1.2 by Devin Reade";
char *versionstr = "version 1.3 by Devin Reade";
char *usagestr = "[ -abiV ] filename\n\
\t-a\tappend to filename\n\
\t-i\tignore SIGINT\n";
char buf2[BUFFERSIZE];
static void usage(const char *pname);
int
main(int argc, char **argv)
{
int c, b_flag;
char *mode;
char *mode, *master;
FILE *fp, *fp2;
int characters;
@ -60,7 +52,10 @@ main(int argc, char **argv)
/*
* initialization
*/
STACKSTART;
#ifdef __STACK_CHECK__
_beginStackCheck();
atexit(showstack);
#endif
mode = "w+";
b_flag = 0;
@ -87,20 +82,20 @@ main(int argc, char **argv)
case 'V':
/* FALLTHROUGH */
default:
USAGE;
usage(argv[0]);
/* NOTREACHED */
}
}
if ((argc - optind) < 1) {
USAGE;
usage(argv[0]);
}
/*
* open the output file
*/
if ((fp = fopen(argv[optind], mode)) == NULL) {
perror("opening master file");
STACKEND(1);
master = argv[optind];
if ((fp = fopen(master, mode)) == NULL) {
err(1, "couldn't open master file %s", master);
}
/*
@ -111,17 +106,27 @@ main(int argc, char **argv)
setvbuf(stdin, NULL, _IOLBF, 1024);
setvbuf(stdout, NULL, _IOLBF, 1024);
characters = BUFFERSIZE;
/* poll until EOF seen on input or an error occurs */
while (fgets(buf2, characters, stdin) != NULL &&
fputs(buf2, stdout) != EOF &&
fputs(buf2, fp) != EOF);
} else {
/* no buffering */
setvbuf(stdin, NULL, _IONBF, 0);
setvbuf(stdout, NULL, _IONBF, 0);
characters = 2; /* a value of 2 gives one character reads */
}
/* poll until EOF seen on input or an error occurs */
while (fgets(buf2, characters, stdin) != NULL &&
fputs(buf2, stdout) != EOF &&
fputs(buf2, fp) != EOF);
/* avoid ORCA/C v2.1.1b2 optimization problem */
#undef fgetc
#undef fputc
/* poll until EOF seen on input or an error occurs */
while (((c = fgetc(stdin)) != EOF) &&
(fputc(c, stdout) != EOF) &&
(fputc(c, fp) != EOF));
}
fflush(fp);
fflush(stdout);
@ -131,7 +136,7 @@ main(int argc, char **argv)
optind++;
if (argc <= optind) {
fclose(fp);
STACKEND(0);
exit(0);
}
while (argc > optind) {
size_t count;
@ -141,9 +146,7 @@ main(int argc, char **argv)
/* open the new file */
if ((fp2 = fopen(argv[optind], mode)) == NULL) {
perror("opening duplicate file");
fclose(fp);
STACKEND(1);
err(1, "couldn't open duplicate file %s", argv[optind]);
}
/* make the copy */
@ -154,22 +157,24 @@ main(int argc, char **argv)
fwrite(buf2, sizeof(char), count, fp2);
if (ferror(fp2)) {
perror("writing duplicate file");
fclose(fp);
fclose(fp2);
STACKEND(1);
err(1, "error writing duplicate file %s", argv[optind]);
}
}
}
fclose(fp2);
if (ferror(fp)) {
perror("reading master file");
fclose(fp);
STACKEND(1);
err(1, "error reading master file %s", master);
}
optind++;
}
fclose(fp);
STACKEND(0);
exit(0);
}
static void
usage (const char *pname) {
fprintf(stderr,"%s %s\nUsage:\t%s %s\n", pname, versionstr,
pname, usagestr);
exit(1);
}

View File

@ -1,9 +1,10 @@
Name: tee
Version: 1.2 (8 Sep 96)
Version: 1.3 (5 Oct 97)
Shell: GNO
Author: Devin Reade
Contact: <gdr@myrias.ab.ca>
Contact: <gdr@eddore.myrias.com>
Where: /bin/tee
FTP: cco.caltech.edu, grind.isca.uiowa.edu.
FTP: cco.caltech.edu, grind.isca.uiowa.edu, trenco.myrias.com
Tee copies stdin to stdout, by default without buffering. It also makes
a copy of the data to a specified file(s). It is useful when you want to

View File

@ -1,18 +1,18 @@
/*
* $Id: tee.rez,v 1.1 1996/09/03 03:56:08 gdr Exp $
* $Id: tee.rez,v 1.2 1997/10/30 03:32:46 gdr Exp $
*/
#include "Types.Rez"
resource rVersion (0x1, purgeable3, nocrossbank) {
{ 1, 2, 0, /* version 1.2.0 */
{ 1, 3, 0, /* version 1.3.0 */
release, /* development|alpha|beta|final|release */
0 /* non-final release number */
},
verBritain, /* close enough */
verUS,
"tee",
"pipe fitting\n"
"Devin Reade <gdr@myrias.com>\n"
"Devin Reade <gdr@eddore.myrias.com>\n"
"Canada"
};

View File

@ -4,7 +4,7 @@
*
* Usage: ./testtee | ./tee [-b]
*
* $Id: testtee.c,v 1.1 1996/09/09 06:12:16 gdr Exp $
* $Id: testtee.c,v 1.1 1997/10/30 03:32:59 gdr Exp $
*/
#include <stdio.h>

20
bin/test/Makefile Normal file
View File

@ -0,0 +1,20 @@
#
# $Id: Makefile,v 1.1 1997/10/30 03:35:20 gdr Exp $
#
PROG = test
SRCS = test.c operators.c
# Use -D__STACK_CHECK__ to measure stack usage (currently requires 1280 bytes).
CFLAGS +=
STACK = 1280
#operators.c operators.h: unaryop binaryop
# $(MAKE) make_op
# use this rule to if you update binary_ops, or unary_ops
#make_op:
# @echo "$(MAKE) make_op invoked"
# sh ${.CURDIR}/mkops
.INCLUDE: /src/gno/prog.mk

View File

@ -1,4 +1,4 @@
This is test(1) for GNO/ME. For those of you familiar with it
This is test(1) for GNO. For those of you familiar with it
from other platforms, it is a minimal BSD version, not a code-bloated
GNU version. For those not familiar with it, read the man page.
@ -24,3 +24,13 @@ If you have problems with this, let me know. It was a two-hour port.
Devin Reade
February, 1996
<gdr@myrias.com>
CHANGE LOG
==========
v1.1 October, 1997.
- Updated to build with GNO v2.0.6 base release.
- Cleaned up stack check code a bit (use atexit(3)).
v1.0 February 1996.
- Initial release.

View File

@ -1,58 +0,0 @@
#
# This file is intended for use with dmake
#
# $Id: makefile.mk,v 1.2 1996/02/11 00:59:16 gdr Exp $
#
# VAFLAGS must use an optimization level of at least -O8, and no
# -g or -G* flag
#
# Include -DCHECK_STACK in DEFINES to get stack usage and debug info.
# If you use -DCHECK_STACK, you will also have to add the stack checking
# library. I keep mine in "/usr/lib/stack".
#
DEFINES = -Dlint -DGNO
STACK = -s1280
CFLAGS += $(DEFINES) $(STACK) -w -O
VAFLAGS += $(DEFINES) $(STACK) -w -O
LDFLAGS += -v
LDLIBS =
OBJS = test.o test2.o operators.o
ROOTS = test.root test2.root operators.root
BINDIR = /bin
MANDIR = /man
test: $(OBJS) test.r
@purge
$(CC) $(LDFLAGS) $(OBJS) $(LDLIBS) -o $@
copyfork test.r test -r
test.o: test.c operators.h
@purge
$(CC) -c $(CFLAGS) -o $@ test.c
test2.o: test2.c
@purge
$(CC) -c $(VAFLAGS) -o $@ test2.c
operators.o: operators.c operators.h
@purge
$(CC) -c $(CFLAGS) -o $@ operators.c
operators.c operators.h: unaryop binaryop
$(MAKE) make_op
clean:
$(RM) -f $(OBJS) $(ROOTS) test.r
clobber: clean
$(RM) -f test
install:
cp test $(BINDIR)
cp test.1 $(MANDIR)/man1
# use this rule to if you update binary_ops, or unary_ops
make_op:
@echo "$(MAKE) make_op invoked"
# sh ${.CURDIR}/mkops

View File

@ -1,15 +1,7 @@
/*
* $Id: operators.h,v 1.1 1996/02/10 08:27:31 gdr Exp $
* $Id: operators.h,v 1.2 1997/10/30 03:35:21 gdr Exp $
*/
#ifndef __P
#ifdef __STDC__
#define __P(a) a
#else
#define __P(a) ()
#endif
#endif
#define NOT 0
#define ISBLOCK 1
#define ISCHAR 2
@ -51,6 +43,3 @@ extern char *const binary_op[];
extern char *const andor_op[];
extern const char op_priority[];
extern const char op_argflag[];
extern void err __P((const char *, ...));

View File

@ -34,9 +34,9 @@
.\"
.\" @(#)test.1 6.6 (Berkeley) 6/8/92
.\"
.\" $Id: test.1,v 1.1 1996/02/10 08:27:32 gdr Exp $
.\" $Id: test.1,v 1.2 1997/10/30 03:35:21 gdr Exp $
.\"
.TH TEST 1 "Commands and Applications" "9 February 1996" "Version 1.0"
.TH TEST 1 "19 October 1997" GNO "Commands and Applications"
.SH NAME
test \- Condition evaluation utility.
.SH SYNOPSIS

View File

@ -1,5 +1,5 @@
/*
* $Id: test.c,v 1.2 1996/02/11 05:47:04 gdr Exp $
* $Id: test.c,v 1.3 1997/10/30 03:35:21 gdr Exp $
*/
/*-
@ -38,6 +38,7 @@
* SUCH DAMAGE.
*/
#ifndef __GNO__
#ifndef lint
char copyright[] =
"@(#) Copyright (c) 1992 The Regents of the University of California.\n\
@ -48,6 +49,8 @@ char copyright[] =
static char sccsid[] = "@(#)test.c 5.4 (Berkeley) 2/12/93";
#endif /* not lint */
#endif /* ! __GNO__ */
#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>
@ -56,6 +59,16 @@ static char sccsid[] = "@(#)test.c 5.4 (Berkeley) 2/12/93";
#include <stdio.h>
#include <unistd.h>
#include <ctype.h>
#include <err.h>
#if defined(__STACK_CHECK__)
#include <gno/gno.h>
#endif
#ifdef __ORCAC__ /* these are picked up in <types.h> */
#undef true
#undef false
#endif
#include "operators.h"
@ -69,11 +82,6 @@ static char sccsid[] = "@(#)test.c 5.4 (Berkeley) 2/12/93";
#define IS_BANG(s) (s[0] == '!' && s[1] == '\0')
#ifdef CHECK_STACK
void begin_stack_check(void);
int end_stack_check(void);
#endif
/*
* This structure hold a value. The type keyword specifies the type of
* the value, and the union u holds the value. The value of a boolean
@ -107,20 +115,13 @@ static int posix_binary_op __P((char **));
static int posix_unary_op __P((char **));
static void syntax __P((void));
#ifdef CHECK_STACK
#define RETURN(val) \
{ \
int i; \
i = (val); \
printf("DEBUG: test returning %d\n\n",i); \
printf("stack usage: %d bytes\n",end_stack_check()); \
return i; \
#ifdef __STACK_CHECK__
static void
printStack(void) {
printf("stack usage: %d bytes\n", _endStackCheck());
}
#else
#define RETURN(val) return val
#endif
int
main(int argc, char *argv[])
{
@ -132,18 +133,18 @@ main(int argc, char *argv[])
char c, **ap, *opname, *p;
int binary, nest, op, pri, ret_val, skipping;
#ifdef CHECK_STACK
begin_stack_check();
#ifdef __STACK_CHECK__
_beginStackCheck();
atexit(printStack);
#endif
if ((p = argv[0]) == NULL) {
err("test: argc is zero.\n");
exit(2);
errx(2, "argc is zero");
}
if (*p != '\0' && p[strlen(p) - 1] == '[') {
if (strcmp(argv[--argc], "]"))
err("missing ]");
errx(1, "missing ]");
argv[argc] = NULL;
}
ap = argv + 1;
@ -158,42 +159,42 @@ main(int argc, char *argv[])
*/
switch(argc - 1) {
case 0: /* % test */
RETURN(1);
return 1;
break;
case 1: /* % test arg */
/* MIPS machine returns NULL of '[ ]' is called. */
RETURN((argv[1] == NULL || *argv[1] == '\0') ? 1 : 0);
return (argv[1] == NULL || *argv[1] == '\0') ? 1 : 0;
break;
case 2: /* % test op arg */
opname = argv[1];
if (IS_BANG(opname)) {
RETURN((*argv[2] == '\0') ? 0 : 1);
} else {
return (*argv[2] == '\0') ? 0 : 1;
} else {
ret_val = posix_unary_op(&argv[1]);
if (ret_val >= 0) {
RETURN(ret_val);
}
return ret_val;
}
}
break;
case 3: /* % test arg1 op arg2 */
if (IS_BANG(argv[1])) {
ret_val = posix_unary_op(&argv[1]);
if (ret_val >= 0) {
RETURN(!ret_val);
}
return !ret_val;
}
} else if (lookup_op(argv[2], andor_op) < 0) {
ret_val = posix_binary_op(&argv[1]);
if (ret_val >= 0) {
RETURN(ret_val);
}
return ret_val;
}
}
break;
case 4: /* % test ! arg1 op arg2 */
if (IS_BANG(argv[1]) && lookup_op(argv[3], andor_op) < 0) {
ret_val = posix_binary_op(&argv[2]);
if (ret_val >= 0) {
RETURN(!ret_val);
}
return !ret_val;
}
}
break;
default:
@ -268,8 +269,7 @@ main(int argc, char *argv[])
/* OP_STRING or OP_FILE */
if (valsp->type == INTEGER) {
if ((p = malloc(32)) == NULL)
err("%s",
strerror(errno));
err(1, "malloc failed");
#ifdef SHELL
#error "gdr: is this supposed to be %ld ? "
fmtstr(p, 32, "%d",
@ -324,7 +324,7 @@ main(int argc, char *argv[])
opsp->op = op;
opsp->pri = pri;
}
done: { RETURN(expr_is_false(&valstack[0])); }
done: { return expr_is_false(&valstack[0]); }
}
static int
@ -364,7 +364,7 @@ expr_operator(int op, struct value *sp, struct filestat *fs)
goto false;
else
goto true;
#ifdef GNO
#ifdef __GNO__
case ISREAD:
i = S_IREAD;
goto filebit; /* true if (stat.st_mode & i) != 0 */
@ -374,7 +374,7 @@ expr_operator(int op, struct value *sp, struct filestat *fs)
case ISEXEC:
i = S_IEXEC;
goto filebit; /* true if (stat.st_mode & i) != 0 */
#else
#else /* ! __GNO__ */
case ISREAD:
i = S_IROTH;
goto permission;
@ -389,7 +389,7 @@ permission:
else if (fs->stat.st_gid == getegid())
i <<= 3;
goto filebit; /* true if (stat.st_mode & i) != 0 */
#endif /* not GNO */
#endif /* not __GNO__ */
case ISFILE:
i = S_IFREG;
goto filetype;
@ -561,22 +561,22 @@ chk_atol(char *v)
errno = 0;
r = strtol(v, &p, 10);
if (errno != 0)
err("\"%s\" -- out of range.", v);
errx(1, "\"%s\" -- out of range.", v);
while (isspace(*p))
p++;
if (*p != '\0')
err("illegal operand \"%s\" -- expected integer.", v);
errx(1, "illegal operand \"%s\" -- expected integer.", v);
return (r);
}
static void
syntax(void)
{
err("syntax error");
errx(1, "syntax error");
}
static void
overflow(void)
{
err("expression is too complex");
errx(1, "expression is too complex");
}

View File

@ -1,16 +1,16 @@
/*
* $Id: test.rez,v 1.1 1996/02/10 08:27:33 gdr Exp $
* $Id: test.rez,v 1.2 1997/10/30 03:35:21 gdr Exp $
*/
#include "Types.Rez"
resource rVersion (0x1, purgeable3, nocrossbank) {
{ 1, 0, 0, /* version 1.0.0 */
{ 1, 1, 0, /* version 1.1.0 */
release, /* development|alpha|beta|final|release */
0 /* non-final release number */
},
verBritain, /* close enough */
verUS,
"test",
"Condition evaluation utility\n"
"Devin Reade <gdr@myrias.com>\n"

View File

@ -1,36 +0,0 @@
/*
* $Id: test2.c,v 1.2 1996/02/11 05:47:05 gdr Exp $
*/
#include <stdio.h>
#include <stdlib.h>
#include "operators.h"
#if __STDC__
#include <stdarg.h>
#else
#include <varargs.h>
#endif
void
#if __STDC__
err(const char *fmt, ...)
#else
err(fmt, va_alist)
char *fmt;
va_dcl
#endif
{
va_list ap;
#if __STDC__
va_start(ap, fmt);
#else
va_start(ap);
#endif
(void)fprintf(stderr, "test: ");
(void)vfprintf(stderr, fmt, ap);
va_end(ap);
(void)fprintf(stderr, "\n");
exit(2);
/* NOTREACHED */
}