| 5 |
|
* flip picture file horizontally and/or vertically |
| 6 |
|
*/ |
| 7 |
|
|
| 8 |
< |
#include <stdio.h> |
| 9 |
< |
|
| 10 |
< |
#ifdef MSDOS |
| 11 |
< |
#include <fcntl.h> |
| 12 |
< |
#endif |
| 13 |
< |
|
| 14 |
< |
#include <time.h> |
| 15 |
< |
|
| 8 |
> |
#include "rtio.h" |
| 9 |
> |
#include "platform.h" |
| 10 |
|
#include "color.h" |
| 17 |
– |
|
| 11 |
|
#include "resolu.h" |
| 12 |
|
|
| 13 |
|
int order; /* input orientation */ |
| 21 |
|
|
| 22 |
|
FILE *fin; /* input file */ |
| 23 |
|
|
| 31 |
– |
char *progname; |
| 24 |
|
|
| 25 |
+ |
static void memerr(void); |
| 26 |
+ |
static void scanfile(void); |
| 27 |
+ |
static void flip(void); |
| 28 |
|
|
| 29 |
< |
int |
| 30 |
< |
neworder() /* figure out new order from old */ |
| 29 |
> |
|
| 30 |
> |
static int |
| 31 |
> |
neworder(void) /* figure out new order from old */ |
| 32 |
|
{ |
| 33 |
|
register int no; |
| 34 |
|
|
| 44 |
|
return(no); |
| 45 |
|
} |
| 46 |
|
|
| 47 |
< |
|
| 48 |
< |
main(argc, argv) |
| 49 |
< |
int argc; |
| 50 |
< |
char *argv[]; |
| 47 |
> |
int |
| 48 |
> |
main( |
| 49 |
> |
int argc, |
| 50 |
> |
char *argv[] |
| 51 |
> |
) |
| 52 |
|
{ |
| 53 |
< |
static char picfmt[LPICFMT+1] = PICFMT; |
| 53 |
> |
static char picfmt[MAXFMTLEN] = PICFMT; |
| 54 |
|
int i, rval; |
| 55 |
< |
#ifdef MSDOS |
| 56 |
< |
extern int _fmode; |
| 57 |
< |
_fmode = O_BINARY; |
| 58 |
< |
setmode(fileno(stdout), O_BINARY); |
| 62 |
< |
#endif |
| 63 |
< |
progname = argv[0]; |
| 55 |
> |
|
| 56 |
> |
SET_DEFAULT_BINARY(); |
| 57 |
> |
SET_FILE_BINARY(stdout); |
| 58 |
> |
fixargv0(argv[0]); |
| 59 |
|
|
| 60 |
|
for (i = 1; i < argc; i++) |
| 61 |
|
if (!strcmp(argv[i], "-h")) |
| 66 |
|
correctorder++; |
| 67 |
|
else |
| 68 |
|
break; |
| 69 |
+ |
if (i < argc-2) |
| 70 |
+ |
goto userr; |
| 71 |
+ |
if (!fhoriz && !fvert) |
| 72 |
+ |
fprintf(stderr, "%s: warning - no operation\n", argv[0]); |
| 73 |
|
if (i >= argc || argv[i][0] == '-') { |
| 74 |
< |
fprintf(stderr, "Usage: %s [-h][-v][-c] infile [outfile]\n", |
| 75 |
< |
progname); |
| 74 |
> |
if (fvert) |
| 75 |
> |
goto userr; |
| 76 |
> |
SET_FILE_BINARY(stdin); |
| 77 |
> |
fin = stdin; |
| 78 |
> |
} else if ((fin = fopen(argv[i], "r")) == NULL) { |
| 79 |
> |
fprintf(stderr, "%s: cannot open\n", argv[i]); |
| 80 |
|
exit(1); |
| 81 |
|
} |
| 79 |
– |
if ((fin = fopen(argv[i], "r")) == NULL) { |
| 80 |
– |
fprintf(stderr, "%s: cannot open\n", argv[1]); |
| 81 |
– |
exit(1); |
| 82 |
– |
} |
| 82 |
|
if (i < argc-1 && freopen(argv[i+1], "w", stdout) == NULL) { |
| 83 |
|
fprintf(stderr, "%s: cannot open\n", argv[i+1]); |
| 84 |
|
exit(1); |
| 106 |
|
scanfile(); |
| 107 |
|
flip(); /* flip the image */ |
| 108 |
|
exit(0); |
| 109 |
+ |
userr: |
| 110 |
+ |
fprintf(stderr, "Usage: %s [-h][-v][-c] infile [outfile]\n", |
| 111 |
+ |
progname); |
| 112 |
+ |
exit(1); |
| 113 |
|
} |
| 114 |
|
|
| 115 |
|
|
| 116 |
< |
memerr() |
| 116 |
> |
static void |
| 117 |
> |
memerr(void) |
| 118 |
|
{ |
| 119 |
|
fprintf(stderr, "%s: out of memory\n", progname); |
| 120 |
|
exit(1); |
| 121 |
|
} |
| 122 |
|
|
| 123 |
|
|
| 124 |
< |
scanfile() /* scan to the end of file */ |
| 124 |
> |
static void |
| 125 |
> |
scanfile(void) /* scan to the end of file */ |
| 126 |
|
{ |
| 127 |
|
extern long ftell(); |
| 128 |
|
COLR *scanin; |
| 144 |
|
} |
| 145 |
|
|
| 146 |
|
|
| 147 |
< |
flip() /* flip the picture */ |
| 147 |
> |
static void |
| 148 |
> |
flip(void) /* flip the picture */ |
| 149 |
|
{ |
| 150 |
|
COLR *scanin, *scanout; |
| 151 |
|
int y; |