/*
 *  chainword.h --- Incomplete lecture version 4/6/2005
 *  Nadeem Abdul Hamid
 *
 *  (Based on Ch. 3, The Practice of Programming, Kernighan/Pike)
 */


#ifndef false
typedef enum { false, true } boolean;
#else
typedef int boolean;
#endif


/************************************************************************/
/* Type and constant definitions */
enum { NUMPREFS = 2,
       WORDSTOGEN = 500 };
typedef struct Entry Entry;
typedef struct Suffix Suffix;



/************************************************************************/
/* Data structures */

/* Structure representing a node in a list 
   of entries storing prefix and associated suffixes 
*/
struct Entry {
    char *pref[NUMPREFS];  /* array of prefix words */
    int num_sufs;          /* length of suffix list - this is
                              not strictly needed but used for efficiency */
    Suffix *suf;           /* pointer to beginning of suffix list */
    Entry *next_entry;     /* next Entry in the list */
};

/* Structure implementing a list of 
   words (strings) 
*/
struct Suffix {
    char *word;
    Suffix *next_suffix;
};



/************************************************************************/
/* Function prototypes ... we need to work on these */
void print_entry( Entry e );
void print_table( Entry* table );
char* input_word( void );
Entry* add( Entry **table_ptr, char* pref[NUMPREFS] );
void add_suffix( Entry *entry_ptr, char *word );
Entry* lookup( Entry *table, char* pref[NUMPREFS] );
char* pick_suffix( Entry entry );

Entry* build( void );
void generate( Entry *etable );



