--- ray/src/meta/sort.c 2003/06/08 12:03:10 1.2 +++ ray/src/meta/sort.c 2003/11/15 02:13:37 1.8 @@ -1,11 +1,13 @@ #ifndef lint -static const char RCSid[] = "$Id: sort.c,v 1.2 2003/06/08 12:03:10 schorsch Exp $"; +static const char RCSid[] = "$Id: sort.c,v 1.8 2003/11/15 02:13:37 schorsch Exp $"; #endif /* * Sorting routines for meta-files */ -#include "paths.h" +#include "platform.h" /* [_]snprintf() */ +#include "rtprocess.h" /* getpid() */ +#include "rterror.h" #include "meta.h" @@ -79,7 +81,7 @@ int (*pcmp)() /* compares pointers to pointers to pr */ void -mergesort( /* merge sorted files with list */ +pmergesort( /* merge sorted files with list */ FILE *fi[], /* array of input files */ int nf, /* number of input files */ @@ -90,7 +92,7 @@ FILE *ofp /* output file */ { PRIMITIVE *plp; /* position in list */ PRIMITIVE *pp[NFILES]; /* input primitives */ - int minf; + int minf = 0; PRIMITIVE *minp; register int i; @@ -101,7 +103,7 @@ FILE *ofp /* output file */ for (i = 0; i < nf; i++) { /* initialize input files */ if ((pp[i] = palloc()) == NULL) - error(SYSTEM, "memory exhausted in mergesort"); + error(SYSTEM, "memory exhausted in pmergesort"); readp(pp[i], fi[i]); } @@ -152,7 +154,6 @@ int (*pcmp)(), FILE *ofp ) { - char *tfname(); FILE *fi[NFILES], *fp; int i; @@ -164,7 +165,7 @@ FILE *ofp if ((fp = ofp) == NULL) fp = efopen(tfname(height + 1, nt), "w"); - mergesort(fi, nf, pl, pcmp, fp); + pmergesort(fi, nf, pl, pcmp, fp); for (i = 0; i < nf; i++) { fclose(fi[i]); @@ -200,7 +201,6 @@ int (*pcmp)() { static int nf = 0, intree = FALSE; - FILE *fp; if (isglob(pl->pbot->com)) { @@ -276,12 +276,16 @@ int lvl, int num ) { static char pathbuf[PATH_MAX]; - static char fnbuf[32]; + static char fnbuf[PATH_MAX]; + static size_t psiz; + if (pathbuf[0] == '\0') { /* first time */ + temp_directory(pathbuf, sizeof(pathbuf)); + psiz = strlen(pathbuf); + } + snprintf(fnbuf, sizeof(pathbuf)-psiz, + "%s/S%d%c%d", pathbuf, getpid(), lvl+'A', num); /*sprintf(fnbuf, "%sS%d%c%d", TDIR, getpid(), lvl+'A', num);*/ - sprintf(fnbuf, "%c%d_XXXXXX", lvl+'A', num); - temp_filename(pathbuf, sizeof(pathbuf), fnbuf); - /*return(fnbuf);*/ - return pathbuf; + return(fnbuf); }