--- ray/src/px/pflip.c 2003/02/22 02:07:27 2.5 +++ ray/src/px/pflip.c 2012/05/17 17:36:14 2.10 @@ -1,20 +1,16 @@ #ifndef lint -static const char RCSid[] = "$Id: pflip.c,v 2.5 2003/02/22 02:07:27 greg Exp $"; +static const char RCSid[] = "$Id: pflip.c,v 2.10 2012/05/17 17:36:14 greg Exp $"; #endif /* * flip picture file horizontally and/or vertically */ #include - -#ifdef MSDOS -#include -#endif - #include +#include +#include "platform.h" #include "color.h" - #include "resolu.h" int order; /* input orientation */ @@ -31,8 +27,13 @@ FILE *fin; /* input file */ char *progname; -int -neworder() /* figure out new order from old */ +static void memerr(void); +static void scanfile(void); +static void flip(void); + + +static int +neworder(void) /* figure out new order from old */ { register int no; @@ -48,18 +49,16 @@ neworder() /* figure out new order from old */ return(no); } - -main(argc, argv) -int argc; -char *argv[]; +int +main( + int argc, + char *argv[] +) { static char picfmt[LPICFMT+1] = PICFMT; int i, rval; -#ifdef MSDOS - extern int _fmode; - _fmode = O_BINARY; - setmode(fileno(stdout), O_BINARY); -#endif + SET_DEFAULT_BINARY(); + SET_FILE_BINARY(stdout); progname = argv[0]; for (i = 1; i < argc; i++) @@ -71,15 +70,19 @@ char *argv[]; correctorder++; else break; + if (i < argc-2) + goto userr; + if (!fhoriz && !fvert) + fprintf(stderr, "%s: warning - no operation\n", argv[0]); if (i >= argc || argv[i][0] == '-') { - fprintf(stderr, "Usage: %s [-h][-v][-c] infile [outfile]\n", - progname); + if (fvert) + goto userr; + SET_FILE_BINARY(stdin); + fin = stdin; + } else if ((fin = fopen(argv[i], "r")) == NULL) { + fprintf(stderr, "%s: cannot open\n", argv[i]); exit(1); } - if ((fin = fopen(argv[i], "r")) == NULL) { - fprintf(stderr, "%s: cannot open\n", argv[1]); - exit(1); - } if (i < argc-1 && freopen(argv[i+1], "w", stdout) == NULL) { fprintf(stderr, "%s: cannot open\n", argv[i+1]); exit(1); @@ -107,17 +110,23 @@ char *argv[]; scanfile(); flip(); /* flip the image */ exit(0); +userr: + fprintf(stderr, "Usage: %s [-h][-v][-c] infile [outfile]\n", + progname); + exit(1); } -memerr() +static void +memerr(void) { fprintf(stderr, "%s: out of memory\n", progname); exit(1); } -scanfile() /* scan to the end of file */ +static void +scanfile(void) /* scan to the end of file */ { extern long ftell(); COLR *scanin; @@ -139,7 +148,8 @@ scanfile() /* scan to the end of file */ } -flip() /* flip the picture */ +static void +flip(void) /* flip the picture */ { COLR *scanin, *scanout; int y;