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