--- ray/src/px/protate.c 2003/05/15 05:13:35 2.8 +++ ray/src/px/protate.c 2018/08/02 18:33:46 2.12 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: protate.c,v 2.8 2003/05/15 05:13:35 greg Exp $"; +static const char RCSid[] = "$Id: protate.c,v 2.12 2018/08/02 18:33:46 greg Exp $"; #endif /* * prot.c - program to rotate picture file 90 degrees clockwise. @@ -7,6 +7,7 @@ static const char RCSid[] = "$Id: protate.c,v 2.8 2003 * 2/26/88 */ +#include "platform.h" #include "standard.h" #include "color.h" @@ -34,33 +35,56 @@ int nrows; /* number of rows output at once */ char *progname; short ordertab[4][2] = { - {0,XDECR}, {XDECR,XDECR|YDECR}, {XDECR|YDECR,YDECR}, {YDECR,0} + {0,0}, {XDECR,XDECR|YDECR}, {XDECR|YDECR,YDECR}, {YDECR,XDECR} }; -int -neworder() /* return corrected order */ +static int neworder(void); +static void rotatecw(FILE *fp); +static void rotateccw(FILE *fp); + + + +static int +neworder(void) /* return corrected order */ { + static short ordercw[8]; register int i; if (correctorder) return(order); - for (i = 4; i--; ) - if ((order&~YMAJOR) == ordertab[i][ccw]) - return(ordertab[i][1-ccw] | ((order&YMAJOR)^YMAJOR)); + if (!ordercw[0]) { + ordercw[YMAJOR|YDECR] = 0; + ordercw[0] = YMAJOR|XDECR; + ordercw[YMAJOR|XDECR] = XDECR|YDECR; + ordercw[XDECR|YDECR] = YMAJOR|YDECR; + ordercw[YMAJOR|XDECR|YDECR] = XDECR; + ordercw[XDECR] = YMAJOR; + ordercw[YMAJOR] = YDECR; + ordercw[YDECR] = YMAJOR|XDECR|YDECR; + } + if (!ccw) + return(ordercw[order]); + for (i = 8; i--; ) + if (ordercw[i] == order) + return(i); fputs("Order botch!\n", stderr); exit(2); } - -main(argc, argv) -int argc; -char *argv[]; +int +main( + int argc, + char *argv[] +) { - static char picfmt[LPICFMT+1] = PICFMT; + static char picfmt[MAXFMTLEN] = PICFMT; int rval; FILE *fin; + SET_DEFAULT_BINARY(); + SET_FILE_BINARY(stdout); + progname = argv[0]; while (argc > 2 && argv[1][0] == '-') { @@ -118,8 +142,10 @@ userr: } -rotatecw(fp) /* rotate picture clockwise */ -FILE *fp; +static void +rotatecw( /* rotate picture clockwise */ + FILE *fp +) { register COLR *inln; register int xoff, inx, iny; @@ -154,8 +180,10 @@ FILE *fp; } -rotateccw(fp) /* rotate picture counter-clockwise */ -FILE *fp; +static void +rotateccw( /* rotate picture counter-clockwise */ + FILE *fp +) { register COLR *inln; register int xoff, inx, iny;