File:  [CSRG BSD Unix] / 43BSD / usr.bin / rev.c
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Tue Apr 24 16:12:54 2018 UTC (8 years, 1 month ago) by root
Branches: MAIN, BSD
CVS tags: HEAD, BSD43
BSD 4.3

static char *sccsid = "@(#)rev.c	4.1 (Berkeley) 10/1/80";
#include <stdio.h>

/* reverse lines of a file */

#define N 256
char line[N];
FILE *input;

main(argc,argv)
char **argv;
{
	register i,c;
	input = stdin;
	do {
		if(argc>1) {
			if((input=fopen(argv[1],"r"))==NULL) {
				fprintf(stderr,"rev: cannot open %s\n",
					argv[1]);
				exit(1);
			}
		}
		for(;;){
			for(i=0;i<N;i++) {
				line[i] = c = getc(input);
				switch(c) {
				case EOF:
					goto eof;
				default:
					continue;
				case '\n':
					break;
				}
				break;
			}
			while(--i>=0)
				putc(line[i],stdout);
			putc('\n',stdout);
		}
eof:
		fclose(input);
		argc--;
		argv++;
	} while(argc>1);
}

unix.superglobalmegacorp.com

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