Need utils: head,yes,& nroff (-man) for SysV2 (CCI 2.21or2.22)
Keith Bostic
bostic at OKEEFFE.BERKELEY.EDU
Sat Jul 2 02:11:20 AEST 1988
The BSD version of head(1), while not PD, is freely redistributable. And
has just recently been cleaned up. Enjoy. Forget about sed.
--keith
# This is a shell archive. Save it in a file, remove anything before
# this line, and then unpack it by entering "sh file". Note, it may
# create directories; files and directories will be owned by you and
# have default permissions.
#
# This archive contains:
#
# head.c
#
echo x - head.c
sed 's/^X//' >head.c << 'END-of-head.c'
X/*
X * Copyright (c) 1980, 1987 Regents of the University of California.
X * All rights reserved.
X *
X * Redistribution and use in source and binary forms are permitted
X * provided that the above copyright notice and this paragraph are
X * duplicated in all such forms and that any documentation,
X * advertising materials, and other materials related to such
X * distribution and use acknowledge that the software was developed
X * by the University of California, Berkeley. The name of the
X * University may not be used to endorse or promote products derived
X * from this software without specific prior written permission.
X * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
X * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
X * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
X */
X
X#ifndef lint
Xchar copyright[] =
X"@(#) Copyright (c) 1980, 1987 Regents of the University of California.\n\
X All rights reserved.\n";
X#endif /* not lint */
X
X#ifndef lint
Xstatic char sccsid[] = "@(#)head.c 5.4 (Berkeley) 6/29/88";
X#endif /* not lint */
X
X#include <stdio.h>
X#include <ctype.h>
X/*
X * head - give the first few lines of a stream or of each of a set of files
X *
X * Bill Joy UCB August 24, 1977
X */
X
Xmain(argc, argv)
X int argc;
X char **argv;
X{
X register int ch, cnt;
X int firsttime, linecnt = 10;
X
X if (argc > 1 && argv[1][0] == '-') {
X if (!isdigit(argv[1][1])) {
X fprintf(stderr, "head: illegal option -- %c\n", argv[1][1]);
X goto usage;
X }
X if ((linecnt = atoi(argv[1] + 1)) < 0) {
Xusage: fputs("usage: head [-line_count] [file ...]\n", stderr);
X exit(1);
X }
X --argc; ++argv;
X }
X /* setlinebuf(stdout); */
X for (firsttime = 1, --argc, ++argv;; firsttime = 0) {
X if (!*argv) {
X if (!firsttime)
X exit(0);
X }
X else {
X if (!freopen(*argv, "r", stdin)) {
X fprintf(stderr, "head: can't read %s.\n", *argv);
X exit(1);
X }
X if (argc > 1) {
X if (!firsttime)
X putchar('\n');
X printf("==> %s <==\n", *argv);
X }
X ++argv;
X }
X for (cnt = linecnt; cnt; --cnt)
X while ((ch = getchar()) != EOF)
X if (putchar(ch) == '\n')
X break;
X }
X /*NOTREACHED*/
X}
END-of-head.c
exit
More information about the Comp.sys.tahoe
mailing list