/* $Id: brew.h,v 1.1 2004/02/28 05:22:09 grog Exp grog $ */

#include <ctype.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/file.h>
#include <sys/param.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <sys/types.h>
#include <unistd.h>
#include "beer.h"
#include <setjmp.h>					    /* XXX */
#include <signal.h>
#ifdef LIBEDIT
#include <histedit.h>
#else
#include <readline/history.h>
#include <readline/readline.h>
#endif

#define BUFSIZE	256					    /* length of input buffer */
#define MAXARGS  64					    /* maximum number of tokens */
#define DEFAULT_HISTORYFILE "brew_history"		    /* default name for history stuff */
#define MAXDATETEXT 128					    /* date text in history (far too much) */

extern int verbose;

void timestamp (void);
void setsigs (void);
void catchsig (int ignore);

/* parser stuff */
enum keyword 
{
  kw_sugar,
  kw_hops,
  kw_brix,
  kw_brix2fg,
  kw_decoct,
  kw_debug,
  kw_invalid_keyword = -1
  };

struct _keywords
  {
  char *name;
  enum keyword keyword;
  };

struct keywordset 
{
  int size;
  struct _keywords *k;
  };

#define FUNKEY(x) { kw_##x, &x##_command }		    /* create pair "kw_foo", foo_command */
#define keypair(x) { #x, kw_##x }			    /* create pair "foo", kw_foo */
#define flagkeypair(x) { "-"#x, x##_command }		    /* create pair "-foo", kw_foo */

#define KEYWORDSET(x) {sizeof (x) / sizeof (struct _keywords), x}

extern struct _keywords keywords [];
extern struct _keywords flag_keywords [];

extern struct keywordset keyword_set;
extern struct keywordset flag_set;

void parseline(int c, char *args[]);			    /* parse a line with c parameters at args */
int tokenize (char *, char * [], int);
enum keyword get_keyword (char *name, struct keywordset *keywordset);

/* scaling functions */
float percentage (float);
float kgs (float);
float densityval (float);

void sugar_command (int argc, char *argv [], char *arg0 []);
void hops_command (int argc, char *argv [], char *arg0 []);
void brix_command (int argc, char *argv [], char *arg0 []);
void brix2fg_command (int argc, char *argv [], char *arg0 []);
void decoct_command (int argc, char *argv [], char *arg0 []);
void debug_command (int argc, char *argv [], char *arg0 []);
