ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/meta/sort.c
(Generate patch)

Comparing ray/src/meta/sort.c (file contents):
Revision 1.1 by greg, Sat Feb 22 02:07:26 2003 UTC vs.
Revision 1.6 by schorsch, Mon Jul 14 20:02:29 2003 UTC

# Line 5 | Line 5 | static const char      RCSid[] = "$Id$";
5   *   Sorting routines for meta-files
6   */
7  
8 + #include  "rtprocess.h" /* getpid() */
9 + #include  "rterror.h"
10 + #include  "meta.h"
11  
12 +
13   #define  PBSIZE  1000           /* max size of sort block */
14                                  /* maxalloc must be >= this */
15  
12
16   #define  NFILES  4              /* number of sort files */
17  
18  
19 + static void treemerge(int height, int nt, int nf, PLIST *pl,
20 +                int (*pcmp)(), FILE *ofp);
21 + static void sendsort( PLIST  *pl, int  (*pcmp)());
22 + static void order(PRIMITIVE  *pa[], int  n, PLIST  *pl);
23 + static char * tfname( int  lvl, int num);
24  
17 #include  "meta.h"
18
19
20
21
22
23
24
25   /*
26   *   This sort routine does a combination quicksort and
27   *   n-ary mergesort
28   */
29  
30  
31 < sort(infp, pcmp)                /* sort primitives according to pcmp */
32 <
33 < FILE  *infp;
34 < int  (*pcmp)();         /* compares pointers to pointers to primitives! */
35 <
31 > void
32 > sort(           /* sort primitives according to pcmp */
33 > FILE  *infp,
34 > int  (*pcmp)()          /* compares pointers to pointers to primitives! */
35 > )
36   {
37   PRIMITIVE  *prims[PBSIZE];             /* pointers to primitives */
38   PLIST  primlist;                       /* our primitives list */
# Line 79 | Line 79 | int  (*pcmp)();                /* compares pointers to pointers to p
79   *     0 or 1 global commands.
80   */
81  
82 < mergesort(fi, nf, pl, pcmp, ofp)        /* merge sorted files with list */
82 > void
83 > pmergesort(     /* merge sorted files with list */
84  
85 < FILE  *fi[];            /* array of input files */
86 < int  nf;                /* number of input files */
87 < PLIST  *pl;             /* sorted list */
88 < int  (*pcmp)();         /* comparison function, takes primitive handles */
89 < FILE  *ofp;             /* output file */
90 <
85 > FILE  *fi[],            /* array of input files */
86 > int  nf,                /* number of input files */
87 > PLIST  *pl,             /* sorted list */
88 > int  (*pcmp)(),         /* comparison function, takes primitive handles */
89 > FILE  *ofp              /* output file */
90 > )
91   {
92      PRIMITIVE  *plp;            /* position in list */
93      PRIMITIVE  *pp[NFILES];     /* input primitives */
# Line 101 | Line 102 | FILE  *ofp;            /* output file */
102  
103      for (i = 0; i < nf; i++) {          /* initialize input files */
104          if ((pp[i] = palloc()) == NULL)
105 <            error(SYSTEM, "memory exhausted in mergesort");
105 >            error(SYSTEM, "memory exhausted in pmergesort");
106          readp(pp[i], fi[i]);
107      }
108  
# Line 143 | Line 144 | FILE  *ofp;            /* output file */
144  
145  
146  
147 < static
148 < treemerge(height, nt, nf, pl, pcmp, ofp)        /* merge into one file */
147 > static void
148 > treemerge(      /* merge into one file */
149  
150 < int  height, nt, nf;
151 < PLIST  *pl;
152 < int  (*pcmp)();
153 < FILE  *ofp;
154 <
150 > int  height, int nt, int nf,
151 > PLIST  *pl,
152 > int  (*pcmp)(),
153 > FILE  *ofp
154 > )
155   {
155    char  *tfname();
156      FILE  *fi[NFILES], *fp;
157      int  i;
158      
# Line 164 | Line 164 | FILE  *ofp;
164          if ((fp = ofp) == NULL)
165              fp = efopen(tfname(height + 1, nt), "w");
166          
167 <        mergesort(fi, nf, pl, pcmp, fp);
167 >        pmergesort(fi, nf, pl, pcmp, fp);
168          
169          for (i = 0; i < nf; i++) {
170              fclose(fi[i]);
# Line 191 | Line 191 | FILE  *ofp;
191  
192  
193  
194 < static
195 < sendsort(pl, pcmp)              /* send a sorted list */
194 > static void
195 > sendsort(               /* send a sorted list */
196  
197 < PLIST  *pl;
198 < int  (*pcmp)();
199 <
197 > PLIST  *pl,
198 > int  (*pcmp)()
199 > )
200   {
201      static int  nf = 0,
202                  intree = FALSE;
# Line 247 | Line 247 | int  (*pcmp)();
247  
248  
249  
250 + static void
251 + order(  /* order the first n array primitives into list */
252  
253 < static
254 < order(pa, n, pl)        /* order the first n array primitives into list */
255 <
256 < PRIMITIVE  *pa[];
255 < int  n;
256 < PLIST  *pl;
257 <
253 > PRIMITIVE  *pa[],
254 > int  n,
255 > PLIST  *pl
256 > )
257   {
258   register int  i;
259  
# Line 271 | Line 270 | PLIST  *pl;
270  
271  
272   static char *
273 < tfname(lvl, num)                /* create temporary file name */
273 > tfname(         /* create temporary file name */
274  
275 < int  lvl, num;
276 <
275 > int  lvl, int num
276 > )
277   {
278 <    static char  fnbuf[32];
278 >        static char  pathbuf[PATH_MAX];
279 >    static char  fnbuf[PATH_MAX];
280 >        static size_t psiz;
281  
282 <    sprintf(fnbuf, "%sS%d%c%d", TDIR, getpid(), lvl+'A', num);
282 >        if (pathbuf[0] == '\0') { /* first time */
283 >                temp_directory(pathbuf, sizeof(pathbuf));
284 >                psiz = strlen(pathbuf);
285 >        }
286 >        snprintf(fnbuf, sizeof(pathbuf)-psiz,
287 >                        "%s/S%d%c%d", pathbuf, getpid(), lvl+'A', num);
288 >    /*sprintf(fnbuf, "%sS%d%c%d", TDIR, getpid(), lvl+'A', num);*/
289  
290      return(fnbuf);
291   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines