#ifndef _DM_H_
#define _DM_H_

#define MAX_COLS 150       /* maximum number of column headings in DB   */
#define MAX_ROWS 1000      /* maximum number of returnable rows from DB */
#define MAX_STR_LENGTH 128
#define	MAX_SLOT	40
#define	MAX_NET		500
#define MAX_LEG	4
#define MAX_FORM 10
#define MAX_FIELDS	100  /* maximum fields in single form */
#define MAX_FRAME_STACK	100  /* maximum active frames in a session */

#define get_slot(tree, slot)   sscanf(tree, "%[^.\n]", slot)

#include <pconf.h>

typedef struct date_time {
	int	month;
	int	day;
	int	year;
	int	dow;
	int	start_time;
	int	end_time;
} DateTime;

typedef struct slot_def {
	char	*key;
	char	*prompt;
	char	*sql;
	char	*conf_prompt;
	char	required;
} Slot;

typedef struct aframe_def {
	char	*name;
	int	n_slot;
	Slot	*slot;
} aFrameDef;

typedef struct aframe {
	char	*name;
	char	**value;
	char	*confirmed;
	char	*consistent;
	char	*prompt_count;
} aFrame;


typedef struct prmpt {
	aFrame	*frame;	/* frame prompted for */
	char	*key;	/* key prompted for */
	char	*type;	/* type of prompt, "value", "yes", "confirm" */
} Prompt;



/* Structures for db interface */


struct db_row {
   int  num_cols;
   char **headings;
   char **item;
};

struct db_query {

   int  num_rows;           /* number of rows returned from DB query     */
   int  num_cols;           /* number of columns returns from DB query   */

   char headings[MAX_COLS][MAX_STR_LENGTH];
   char item[MAX_ROWS][MAX_COLS][MAX_STR_LENGTH];

};



/*-----------------------------------------------------------------------*
 * Structure for passing input/output results from Phoenix        *
 *-----------------------------------------------------------------------*/

struct parse_item {
  char parse_in[3000];    /* input string sent to Phoenix        */
  char parse_out[3000];   /* output string returned from Phoenix */
};

//void nl_request();
//void nl_request(char *spch_act, char *prompt, char *task,
//  int enable_input_after_prompt, void *server_data, char *voice);
//void query_database();
//void query_database(char *sql_query, aFrame *frame, void *server_data,
//		    int access_web);
//void hangup_phone();
//void hangup_phone(void *server_data);

// defined in frames.cc
void setKey(aFrame *frame, char *key, char *val);

aFrame *createFrame(char *name);

void activateFrame(aFrame *frame);

void addFrame(aFrame **list, aFrame *frame);

aFrame *get_current_frame(char *name);

char **getKeyPtr(aFrame *frame, char *key);

char *getVal(aFrame *frame, char *key);

int cmpVal(aFrame *frame, char *key, char *val);
void clear_all_frames(); //fine

char *frame_done( aFrame *frame, int *node_idx );

aFrame *getFrame(aFrame **list, char *name, char *ctl, int *fidx);

aFrame *findFrame(char *name, char *key, char *val);

aFrameDef *getFrameDef( char *name );

void print_frame( aFrame *frame );

char *missing_info( aFrame *frame, aFrameDef *fd, int *node);

void skip( aFrame *frame, aFrameDef *fd, int *node);



void config(int argc, char **argv);

void init_dm(char *dir);

void set_task(char *name);

void check_transform( char *tree);

void get_leaf_val(char *str, char *tok, char *val);

void check_function(char *frame_name, char *key,  char *val);

void pusage (char *prog, Config_t *cp);

void set_today(DateTime *dt);

void set_ref_date(DateTime *dt);

void read_task(char *dir, char *task_file);
void read_script(char *dir, char *script_file);
void init_dbq();
void reset_dm(); //fine
void free_form();
void free_db_row();

void cp_str(char **to, char *from);

void clear_dt( DateTime *dt);

void inc_date( DateTime *dt, int inc);

void fill_prompted(char *str);

int get_token(char *str, char *tok);

int find_fun(char *slot);
char *verify_frame();

void print_date( char *str, char *mon, char *dy);
void set_prompted(aFrame *frame, char *key, char *type);
void expand_prompt(aFrame *frame, char *prompt, char *buf);
void setConfirm(aFrame *frame, char *key, int val);
char *prompt_for_key( aFrame *frame, char *key, char *type);
char *confirm_values( aFrame *frame);
char *complete_frame( char *frame_name );
char *frame_complete( aFrame *frame );
char *complete_active_frames(aFrame **frame_p);
char *get_best_parse(char *parse_str);
int frame_empty(aFrame *frame);
void cp_frame(aFrame *to, aFrame *from);
void cp_values(aFrame *to, aFrame *from);
void cp_key_values(aFrame *to, aFrame *from);
void free_list(aFrame **list);
int extract_values(char *parse_string);
int scmp(char *s1, char *s2);
int key_confirmed(aFrame *frame, char *key);
void execute_script(); //fine
void cp_to_hist(aFrame **from);

void xcopy_frame(aFrame *to, aFrame *from);
aFrame *getContext(char *name_a);
int overlap(aFrame *f1, aFrame *f2);
void print_context(aFrame **context);
aFrame *findContext(aFrame *extract);
aFrame *getActiveFrame();


//defined in data_manip.cc
void str2upper(char *text);
void cCreateMatrix(char ***m, int a, int b);
void cFreeMatrix(char **m, int a);
void free_db_row(struct db_row *row);
void get_column_info(struct db_row *row, char *heading_name, char *out);

#endif
