ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/util/swaprasheader.c
Revision: 2.2
Committed: Sat Feb 22 02:07:30 2003 UTC (21 years, 1 month ago) by greg
Content type: text/plain
Branch: MAIN
CVS Tags: rad3R6P1, rad3R5, rad3R6
Changes since 2.1: +1 -4 lines
Log Message:
Changes and check-in for 3.5 release
Includes new source files and modifications not recorded for many years
See ray/doc/notes/ReleaseNotes for notes between 3.1 and 3.5 release

File Contents

# Content
1 #ifndef lint
2 static const char RCSid[] = "$Id$";
3 #endif
4 #include <stdio.h>
5 #include "rasterfile.h"
6
7 main(argc, argv)
8 int argc;
9 char *argv[];
10 {
11 int i;
12
13 for (i = 1; i < argc; i++)
14 fixfile(argv[i]);
15
16 if (argc == 1)
17 fixstream(stdin, stdout);
18
19 exit(0);
20 }
21
22
23 fixfile(name)
24 char *name;
25 {
26 struct rasterfile head;
27 FILE *fp;
28
29 if ((fp = fopen(name, "r+")) == NULL) {
30 fprintf(stderr, "%s: cannon open for read/write\n", name);
31 exit(1);
32 }
33 if (fread((char *)&head, sizeof(head), 1, fp) != 1) {
34 fprintf(stderr, "%s: read error\n", name);
35 exit(1);
36 }
37 swapbytes((char *)&head, sizeof(head), sizeof(int));
38 if (fseek(fp, 0L, 0) == -1) {
39 fprintf(stderr, "%s: seek error\n", name);
40 exit(1);
41 }
42 if (fwrite((char *)&head, sizeof(head), 1, fp) != 1
43 || fclose(fp) == -1) {
44 fprintf(stderr, "%s: write error\n", name);
45 exit(1);
46 }
47 }
48
49
50 fixstream(in, out)
51 register FILE *in, *out;
52 {
53 struct rasterfile head;
54 register int c;
55
56 if (fread((char *)&head, sizeof(head), 1, in) != 1) {
57 fprintf(stderr, "read error\n");
58 exit(1);
59 }
60 swapbytes((char *)&head, sizeof(head), sizeof(int));
61 fwrite((char *)&head, sizeof(head), 1, out);
62 while ((c = getc(in)) != EOF)
63 putc(c, out);
64 if (ferror(out)) {
65 fprintf(stderr, "write error\n");
66 exit(1);
67 }
68 }
69
70
71 swapbytes(top, size, width)
72 char *top;
73 int size, width;
74 {
75 register char *b, *e;
76 register int c;
77
78 for ( ; size > 0; size -= width, top += width) {
79 b = top; e = top+width-1;
80 while (b < e) {
81 c = *e;
82 *e-- = *b;
83 *b++ = c;
84 }
85 }
86 }