ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/meta/psort.c
Revision: 1.3
Committed: Sat Nov 15 02:13:37 2003 UTC (20 years, 5 months ago) by schorsch
Content type: text/plain
Branch: MAIN
CVS Tags: rad5R4, rad5R2, rad4R2P2, rad5R0, rad5R1, rad3R7P2, rad3R7P1, rad4R2, rad4R1, rad4R0, rad3R6, rad3R6P1, rad3R8, rad3R9, rad4R2P1, rad5R3, HEAD
Changes since 1.2: +13 -14 lines
Log Message:
Continued ANSIfication, and reduced other compile warnings.

File Contents

# User Rev Content
1 greg 1.1 #ifndef lint
2 schorsch 1.3 static const char RCSid[] = "$Id: psort.c,v 1.2 2003/08/01 14:14:24 schorsch Exp $";
3 greg 1.1 #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     char *progname;
18    
19     int maxalloc = MAXALLOC;
20    
21     static int val[5], extrema[5];
22    
23    
24 schorsch 1.3 static int pcompare(PRIMITIVE **pp1, PRIMITIVE **pp2);
25 greg 1.1
26    
27 schorsch 1.3 int
28     main(
29     int argc,
30     char **argv
31     )
32 greg 1.1 {
33     FILE *fp;
34 schorsch 1.3 int i;
35 greg 1.1
36     progname = *argv++;
37     argc--;
38    
39     for (i = 0; i < 4 && argc && (**argv == '+' || **argv == '-'); i++) {
40     val[i] = (**argv == '+') ? 1 : -1;
41     switch (*(*argv+1)) {
42     case 'x':
43     extrema[i] = XMN;
44     break;
45     case 'y':
46     extrema[i] = YMN;
47     break;
48     case 'X':
49     extrema[i] = XMX;
50     break;
51     case 'Y':
52     extrema[i] = YMX;
53     break;
54     default:
55     sprintf(errmsg, "unknown option \"%s\"", *argv);
56     error(USER, errmsg);
57     break;
58     }
59     argv++;
60     argc--;
61     }
62    
63     val[i] = 0;
64    
65     if (argc)
66     while (argc) {
67     fp = efopen(*argv, "r");
68     sort(fp, pcompare);
69     fclose(fp);
70     argv++;
71     argc--;
72     }
73     else
74     sort(stdin, pcompare);
75    
76     writeof(stdout);
77    
78     return(0);
79     }
80    
81    
82    
83    
84 schorsch 1.3 int
85     pcompare(
86     PRIMITIVE **pp1,
87     PRIMITIVE **pp2
88     )
89 greg 1.1 {
90     register PRIMITIVE *p1 = *pp1, *p2 = *pp2;
91     register int i;
92    
93     for (i = 0; val[i]; i++)
94     if (p1->xy[extrema[i]] > p2->xy[extrema[i]])
95     return(val[i]);
96     else if (p1->xy[extrema[i]] < p2->xy[extrema[i]])
97     return(-val[i]);
98    
99     return(0);
100     }