1 /* 2 * Copyright (c) 1987 Regents of the University of California. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms are permitted 6 * provided that this notice is preserved and that due credit is given 7 * to the University of California at Berkeley. The name of the University 8 * may not be used to endorse or promote products derived from this 9 * software without specific prior written permission. This software 10 * is provided ``as is'' without express or implied warranty. 11 */ 12 13 #ifndef lint 14 char copyright[] = 15 "@(#) Copyright (c) 1987 Regents of the University of California.\n\ 16 All rights reserved.\n"; 17 #endif /* not lint */ 18 19 #ifndef lint 20 static char sccsid[] = "@(#)rev.c 4.3 (Berkeley) 12/13/87"; 21 #endif /* not lint */ 22 23 #include <stdio.h> 24 25 main(argc, argv) 26 int argc; 27 char **argv; 28 { 29 register char *t, *bp; 30 char buf[BUFSIZ]; 31 32 bp = buf; 33 do { 34 if (argc > 1 && !freopen(*++argv, "r", stdin)) { 35 fprintf(stderr, "rev: cannot open %s.\n", *argv); 36 exit(1); 37 } 38 while (fgets(bp, sizeof(buf), stdin)) { 39 for (t = bp; *t; ++t); 40 if (*--t == '\n') 41 --t; 42 for (; t >= bp; --t) 43 putchar(*t); 44 putchar('\n'); 45 } 46 } while(--argc > 1); 47 exit(0); 48 } 49