150428Sbostic /*- 2*63075Sbostic * Copyright (c) 1987, 1992, 1993 3*63075Sbostic * The Regents of the University of California. All rights reserved. 433044Sbostic * 550428Sbostic * %sccs.include.redist.c% 633044Sbostic */ 71079Sbill 833044Sbostic #ifndef lint 9*63075Sbostic static char copyright[] = 10*63075Sbostic "@(#) Copyright (c) 1987, 1992, 1993\n\ 11*63075Sbostic The Regents of the University of California. All rights reserved.\n"; 1233044Sbostic #endif /* not lint */ 131079Sbill 1433044Sbostic #ifndef lint 15*63075Sbostic static char sccsid[] = "@(#)rev.c 8.1 (Berkeley) 06/09/93"; 1633044Sbostic #endif /* not lint */ 171079Sbill 1853038Sbostic #include <sys/types.h> 1960164Sbostic 2060164Sbostic #include <err.h> 2153038Sbostic #include <errno.h> 2233044Sbostic #include <stdio.h> 2353038Sbostic #include <stdlib.h> 2453038Sbostic #include <string.h> 2533044Sbostic 2653038Sbostic void usage __P((void)); 2753038Sbostic 2853038Sbostic int 2933044Sbostic main(argc, argv) 3033044Sbostic int argc; 3153038Sbostic char *argv[]; 321079Sbill { 3353038Sbostic register char *filename, *p, *t; 3453038Sbostic FILE *fp; 3553038Sbostic size_t len; 3653038Sbostic int ch, rval; 3733044Sbostic 3853038Sbostic while ((ch = getopt(argc, argv, "")) != EOF) 3953038Sbostic switch(ch) { 4053038Sbostic case '?': 4153038Sbostic default: 4253038Sbostic usage(); 4353038Sbostic } 4453038Sbostic 4553038Sbostic argc -= optind; 4653038Sbostic argv += optind; 4753038Sbostic 4853038Sbostic fp = stdin; 4953038Sbostic filename = "stdin"; 5053038Sbostic rval = 0; 511079Sbill do { 5253038Sbostic if (*argv) { 5353038Sbostic if ((fp = fopen(*argv, "r")) == NULL) { 5460164Sbostic warn("%s", *argv); 5553038Sbostic rval = 1; 5653038Sbostic ++argv; 5753038Sbostic continue; 5853038Sbostic } 5953038Sbostic filename = *argv++; 601079Sbill } 6160164Sbostic while ((p = fgetline(fp, &len)) != NULL) { 6253038Sbostic t = p + len - 1; 6353038Sbostic for (t = p + len - 1; t >= p; --t) 6433044Sbostic putchar(*t); 6533044Sbostic putchar('\n'); 661079Sbill } 6753038Sbostic if (ferror(fp)) { 6860164Sbostic warn("%s", filename); 6953038Sbostic rval = 1; 7053038Sbostic } 7153038Sbostic (void)fclose(fp); 7253038Sbostic } while(*argv); 7353039Sbostic exit(rval); 741079Sbill } 7553038Sbostic 7653038Sbostic void 7753038Sbostic usage() 7853038Sbostic { 7953038Sbostic (void)fprintf(stderr, "usage: rev [file ...]\n"); 8053038Sbostic exit(1); 8153038Sbostic } 82