/* Runs the RC_Load function on argv[1], and then spits out a node list as it
   sees it.

   Output format is as follows:
   This, ThisAddr, Parent, ParAddr, Left, LeftAddr, Right, RightAddr, Length
*/

#include <malloc.h>
#include <stdio.h>
#include "delay.h"

int main (int argc, char * argv[])
{
  FILE * fp = fopen(argv[1],"r");
  if (NULL == fp)
    {
      fprintf(stderr, "File %s couldn't be opened!\n",
	      argv[1]);
      return -1;
    }

  RC_Load(fp);

  int i;
  for (i=0; i< G_Nodecount; i++)
    {
      printf("%d %p %ld %p %ld %p %ld %p %g\n",
	     i+1,
	     &(G_Tree_Ptr[i]),
	     
	     G_Tree_Ptr[i].Parent_Ptr ?
	     (long int) (G_Tree_Ptr[i].Parent_Ptr - G_Tree_Ptr + 1): -1,
	     G_Tree_Ptr[i].Parent_Ptr,
	     
	     G_Tree_Ptr[i].Left_Ptr ?
	     (long int) (G_Tree_Ptr[i].Left_Ptr - G_Tree_Ptr + 1): -1,
	     G_Tree_Ptr[i].Left_Ptr,
	     
	     G_Tree_Ptr[i].Right_Ptr ?
	     (long int) (G_Tree_Ptr[i].Right_Ptr - G_Tree_Ptr + 1): -1,
	     G_Tree_Ptr[i].Right_Ptr,

	     G_Tree_Ptr[i].Length
	     );
    }

  free(G_Tree_Ptr);
  fclose(fp);

  return 0;
}
