File:  [CSRG BSD Unix] / 3BSD / cmd / see.c
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Tue Apr 24 16:12:53 2018 UTC (8 years, 1 month ago) by root
Branches: MAIN, CSRG
CVS tags: HEAD, BSD3
BSD 3.0

#include <stdio.h>

/*
 * see - a cat like program which prints like the ex "print" command.
 * It always prints backspaces as "^H".
 *
 * Bill Joy UCB July 13, 1978
 *
 */
int	noeol;

main(argc, argv)
	int argc;
	char *argv[];
{
	register c;
	char obuf[BUFSIZ];

	setbuf(stdout, obuf);
	argc--, argv++;
	if (argc > 0 && argv[0][0] == '-')
		noeol++, argc--, argv++;
	do {
		if (argc > 0) {
			if (freopen(argv[0], "r", stdin) == 0) {
				perror(argv[0]);
				exit(1);
			}
			argc--, argv++;
		}
		for (;;) {
			c = getchar();
			if (c == -1)
				break;
			c &= 0177;
			if (c == 0177)
				putchar('^'), c = '?';
			if (c == 033)
				c = '$';
			if (c < ' ')
				switch (c) {

				case '\n':
					break;

				default:
					putchar('^');
					c |= 0100;
				}
			if (c == '\n' && !noeol)
				putchar('$');
			putchar(c);
			if (c == '\n')
				fflush(stdout);
		}
	} while (argc > 0);
	exit(0);
}

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.