Commit | Line | Data |
---|---|---|
4391e8e5 KB |
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 */ | |
e04fe8e4 | 18 | |
4391e8e5 KB |
19 | #ifndef lint |
20 | static char sccsid[] = "@(#)rev.c 4.3 (Berkeley) %G%"; | |
21 | #endif /* not lint */ | |
e04fe8e4 | 22 | |
4391e8e5 | 23 | #include <stdio.h> |
e04fe8e4 | 24 | |
4391e8e5 KB |
25 | main(argc, argv) |
26 | int argc; | |
27 | char **argv; | |
e04fe8e4 | 28 | { |
4391e8e5 KB |
29 | register char *t, *bp; |
30 | char buf[BUFSIZ]; | |
31 | ||
32 | bp = buf; | |
e04fe8e4 | 33 | do { |
4391e8e5 KB |
34 | if (argc > 1 && !freopen(*++argv, "r", stdin)) { |
35 | fprintf(stderr, "rev: cannot open %s.\n", *argv); | |
36 | exit(1); | |
e04fe8e4 | 37 | } |
4391e8e5 KB |
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'); | |
e04fe8e4 | 45 | } |
4391e8e5 | 46 | } while(--argc > 1); |
d8d7b75f | 47 | exit(0); |
e04fe8e4 | 48 | } |