rem: mergefps (char **files, register int nfiles, FILE *ofp, const char *output_file)
add: mergefps (char **files, size_t ntemps, size_t nfiles, FILE *ofp, char const *output_file)
context: mergefps (char **files, register int nfiles,	  FILE *ofp, const char *output_file){  FILE *fps[NMERGE];		/* Input streams for each file.  */  struct buffer buffer[NMERGE];	/* Input buffers for each file. */  struct line saved;		/* Saved line storage for unique check. */  struct line const *savedline = NULL;				/* &saved if there is a saved line. */  size_t savealloc = 0;		/* Size allocated for the saved line. */  struct line const *cur[NMERGE]; /* Current line in each line table. */  struct line const *base[NMERGE]; /* Base of each line table.  */  int ord[NMERGE];		/* Table representing a permutation of fps,				   such that cur[ord[0]] is the smallest line				   and will be next output. */  register int i, j, t;  struct keyfield *key = keylist;  saved.text = NULL;  /* Read initial lines from each input file. */  for (i = 0; i < nfiles; )    {      fps[i] = xfopen (files[i], "r");      initbuf (&buffer[i], sizeof (struct line),	       MAX (merge_buffer_size, sort_size / nfiles));      if (fillbuf (&buffer[i], fps[i], files[i]))	{	  struct line const *linelim = buffer_linelim (&buffer[i]);	  cur[i] = linelim - 1;	  base[i] = linelim - buffer[i].nlines;	  i++;	}      else	{	  /* fps[i] is empty; eliminate it from future consideration.  */	  xfclose (fps[i], files[i]);	  zaptemp (files[i]);	  free (buffer[i].buf);	  --nfiles;	  for (j = i; j < nfiles; ++j)	    files[j] = files[j + 1];	}    }  if (! ofp)    ofp = xfopen (output_file, "w");  /* Set up the ord table according to comparisons among input lines.     Since this only reorders two items if one is strictly greater than     the other, it is stable. */  for (i = 0; i < nfiles; ++i)    ord[i] = i;  for (i = 1; i < nfiles; ++i)    if (0 < compare (cur[ord[i - 1]], cur[ord[i]]))      t = ord[i - 1], ord[i - 1] = ord[i], ord[i] = t, i = 0;  /* Repeatedly output the smallest line until no input remains. */  while (nfiles)    {      struct line const *smallest = cur[ord[0]];      /* If uniquified output is turned on, output only the first of	 an identical series of lines. */      if (unique)	{	  if (savedline && compare (savedline, smallest))	    {	      savedline = 0;	      write_bytes (saved.text, saved.length, ofp, output_file);	    }	  if (!savedline)	    {	      savedline = &saved;	      if (savealloc < smallest->length)		{		  do		    if (! savealloc)		      {			savealloc = smallest->length;			break;		      }		  while ((savealloc *= 2) < smallest->length);		  saved.text = xrealloc (saved.text, savealloc);		}	      saved.length = smallest->length;	      memcpy (saved.text, smallest->text, saved.length);	      if (key)		{		  saved.keybeg =		    saved.text + (smallest->keybeg - smallest->text);		  saved.keylim =		    saved.text + (smallest->keylim - smallest->text);		}	    }	}      else	write_bytes (smallest->text, smallest->length, ofp, output_file);      /* Check if we need to read more lines into core. */      if (base[ord[0]] < smallest)	cur[ord[0]] = smallest - 1;      else	{	  if (fillbuf (&buffer[ord[0]], fps[ord[0]], files[ord[0]]))	    {	      struct line const *linelim = buffer_linelim (&buffer[ord[0]]);	      cur[ord[0]] = linelim - 1;	      base[ord[0]] = linelim - buffer[ord[0]].nlines;	    }	  else	    {	      /* We reached EOF on fps[ord[0]]. */	      for (i = 1; i < nfiles; ++i)		if (ord[i] > ord[0])		  --ord[i];	      --nfiles;	      xfclose (fps[ord[0]], files[ord[0]]);	      zaptemp (files[ord[0]]);	      free (buffer[ord[0]].buf);	      for (i = ord[0]; i < nfiles; ++i)		{		  fps[i] = fps[i + 1];		  files[i] = files[i + 1];		  buffer[i] = buffer[i + 1];		  cur[i] = cur[i + 1];		  base[i] = base[i + 1];		}	      for (i = 0; i < nfiles; ++i)		ord[i] = ord[i + 1];	      continue;	    }	}      /* The new line just read in may be larger than other lines	 already in core; push it back in the queue until we encounter	 a line larger than it. */      for (i = 1; i < nfiles; ++i)	{	  t = compare (cur[ord[0]], cur[ord[i]]);	  if (!t)	    t = ord[0] - ord[i];	  if (t < 0)	    break;	}      t = ord[0];      for (j = 1; j < i; ++j)	ord[j - 1] = ord[j];      ord[i - 1] = t;    }  if (unique && savedline)    {      write_bytes (saved.text, saved.length, ofp, output_file);      free (saved.text);    }  xfclose (ofp, output_file);}