ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/meta/psort.c
Revision: 1.1
Committed: Sat Feb 22 02:07:26 2003 UTC (21 years, 2 months ago) by greg
Content type: text/plain
Branch: MAIN
CVS Tags: rad3R5
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 /*
5 * Program to sort a meta-file
6 *
7 * cc psort.c sort.o palloc.o mfio.o syscalls.o misc.o
8 */
9
10
11 #define MAXALLOC 1100 /* must be >= PBSIZE in sort.c */
12
13
14 #include "meta.h"
15
16
17
18 char *progname;
19
20 int maxalloc = MAXALLOC;
21
22
23
24 static int val[5], extrema[5];
25
26
27
28 main(argc, argv)
29
30 int argc;
31 char **argv;
32
33 {
34 FILE *fp;
35 int i, pcompare();
36
37 #ifdef CPM
38 fixargs("psort", &argc, &argv);
39 #endif
40
41 progname = *argv++;
42 argc--;
43
44 for (i = 0; i < 4 && argc && (**argv == '+' || **argv == '-'); i++) {
45 val[i] = (**argv == '+') ? 1 : -1;
46 switch (*(*argv+1)) {
47 case 'x':
48 extrema[i] = XMN;
49 break;
50 case 'y':
51 extrema[i] = YMN;
52 break;
53 case 'X':
54 extrema[i] = XMX;
55 break;
56 case 'Y':
57 extrema[i] = YMX;
58 break;
59 default:
60 sprintf(errmsg, "unknown option \"%s\"", *argv);
61 error(USER, errmsg);
62 break;
63 }
64 argv++;
65 argc--;
66 }
67
68 val[i] = 0;
69
70 if (argc)
71 while (argc) {
72 fp = efopen(*argv, "r");
73 sort(fp, pcompare);
74 fclose(fp);
75 argv++;
76 argc--;
77 }
78 else
79 sort(stdin, pcompare);
80
81 writeof(stdout);
82
83 return(0);
84 }
85
86
87
88
89
90 pcompare(pp1, pp2)
91
92 PRIMITIVE **pp1, **pp2;
93
94 {
95 register PRIMITIVE *p1 = *pp1, *p2 = *pp2;
96 register int i;
97
98 for (i = 0; val[i]; i++)
99 if (p1->xy[extrema[i]] > p2->xy[extrema[i]])
100 return(val[i]);
101 else if (p1->xy[extrema[i]] < p2->xy[extrema[i]])
102 return(-val[i]);
103
104 return(0);
105 }