/**
 | File: sort.h - v1.00 MLO 911226.
 | See sort.c and tree.c for comments.
**/

#ifdef SIMPLE
#undef BALANCED_TREE
#else
#define TERM_LEN      16
typedef enum eSortType {
  ALPHABETICAL = 1,
  CASE_FOLDED,
  NUMERICAL,
  FIELD,
  COLUMN
} SortType;
#endif

#define LINE_LENGTH   256

#define BREAK_DETECTED  0x1
#define WARNING_PRINTED 0x2

#ifdef BALANCED_TREE

  typedef struct sNode {
    struct sNode *left;         /* Left branch */
    struct sNode *right;        /* Right branch */
    short int balance;          /* Binary tree balance factor */
    short int count;            /* Number of occurrences */
    char line[1];               /* Input line */
  } Node;

#else

  typedef struct sNode {
    struct sNode *left;
    struct sNode *right;
    short int count;
    char line[1];
  } Node;

#endif

#ifdef BALANCED_TREE
void BalanceTree(char *key);
#endif

#ifndef SIMPLE
int   Compare(char *p1, char *p2);
void  GetTokBlk(char *string, int i, char *token);
void  GetTokDel(char *string, char *delim, int i, char *token);
#endif

void  CheckBreak(Boolean exitprog);
int   CXBRK(void);
void  FreeTree(Node *pN);
Node *InsertTree(char *buffer, Node *pN);
void  PrintTree(Node *pN);
