Sindbad~EG File Manager

Current Path : /usr/home/beeson/MathXpert/prover/
Upload File :
Current File : /usr/home/beeson/MathXpert/prover/reset.c

/* M. Beeson, for Mathpert */
/* save_and_reset */
/* Originally written using using alloca and termstr */
/* 9.9.94 corrected for the idiosyncracies of alloca */
/* 3.9.95 Because Borland's alloca is buggy, this hasn't been in use.
   Now I rewrite it using calloc and free, so it will not make
   explicit reference to Windows functions, but will work. */
/* 11.28.95  modified */
/* 1.29.95 last modified 
   3.20.06 removed duplicate include heap.h
   5.5.13 changed malloc.h to stdlib.h
*/   

#include <stdlib.h>
#include <stdlib.h>  /* NULL */

#include "terms.h"
#include "termstr.h"
#include "reset.h"

void save_and_reset(term t, void  *startnode, term *destination)
/* stash term t temporarily on the C-language managed heap, reset the heap to
startnode, and  return t again in *destination */
{ unsigned k = termsize(t);  /* space required in bytes */
  unsigned short *rest;
  unsigned short *buffer = (unsigned short *) calloc(k,sizeof(char));
  if(buffer == NULL)
      return;  /* heap is not reset because couldn't get space to store t
                  temporarily */
  termstr(t,k,buffer);
  reset_heap(startnode);
  *destination = strterm(buffer,&rest);
  free(buffer);
}

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists