#ifdef AIX_PROD
/* @(#)45    1.4  src/examples/pubsex/strtree/client.c, examples.src, os2dce21.dss, 960602a.1 1/11/96 10:39:14 */
/*
 *   COMPONENT_NAME: examples.src
 *
 *   FUNCTIONS: main
 *              st_make_tree
 *              st_print_tree
 *
 *   ORIGINS: 72
 *
 */
#endif /* AIX_PROD */


#include <stdio.h>
#include <dce/dce_error.h>
#include "string_tree.h"

#include <string.h>
#include <stdlib.h>

extern void st_print_tree (st_node_t *tree, int indent);
extern st_node_t *st_make_tree(void);

/*
** Routine to print a depiction of the tree
*/
void st_print_tree (tree, indent)
  st_node_t *tree;
  int  indent;
{
  int i;
  if (tree == NULL) return;
  for (i = 0; i < indent; i++) printf("    ");
  printf("%s\n",tree->name);
  st_print_tree(tree->left, indent + 1);
  st_print_tree(tree->right, indent + 1);
}


/*
** Create a tree with a few nodes
*/
st_node_t *st_make_tree(void)
{
  st_node_t *root = (st_node_t *)malloc(sizeof(st_node_t));
  strcpy(root->name,"Root Node");

  /* left subtree node */
  root->left =  (st_node_t *)malloc(sizeof(st_node_t));
  strcpy(root->left->name,"Left subtree");

  /* left subtree children */
  root->left->right = NULL;
  root->left->left = (st_node_t *)malloc(sizeof(st_node_t));
  strcpy(root->left->left->name,"Child of left subtree");
  root->left->left->left = NULL;
  root->left->left->right = NULL;

  /* right subtree node */
  root->right =  (st_node_t *)malloc(sizeof(st_node_t));
  strcpy(root->right->name,"Right subtree");
  root->right->left = NULL;
  root->right->right = NULL;

  return root;
}

void main(void)
{
  st_node_t *tree;
  st_node_t *subtree;

  /* setup and print original tree */
  tree = st_make_tree();
  printf("Original Tree:\n");
  st_print_tree(tree, 1);

  /* call the prune routine */
  subtree = st_prune_left (tree);

  /* print the resulting trees */
  printf("Pruned Tree:\n");
  st_print_tree(tree, 1);

  printf("Pruned subtree:\n");
  st_print_tree(subtree, 1);
  }

