#ifndef _TACCUTIL_H
#define _TACCUTIL_H

#if defined(DOS386) || defined(__GCC__)
#ifndef __MSDOS__
#define __MSDOS__ 1
#endif
#endif

#include "regexp.h"

/* WARNING: because this mucks around with seeks in files, and because
   the regexp code has "$" (newline) as a special case, we have to know
   the number of bytes taken up by a newline in the file.  Because parsing
   CR/LF explicitly is a pain, we open files in *text* mode.  Therefore
   there is a horrid bodge somewhere which knows that a newline is 2 chars
   on __MSDOS__ and 1 elsewhere.
 */

#include <stdio.h>    
#include <stdarg.h>
#ifndef SEEK_SET
#define SEEK_SET 0
#endif

#ifndef EXIT_FAILURE
#define EXIT_FAILURE 1
#define EXIT_SUCCESS 0
#endif

#define REGEXP_BUFF_SIZE 16000

#define TYPE_EXEC 1
#define TYPE_PARSE 2
#define TYPE_REGEX 3

extern FILE *yyin;

typedef union _yytype YYTYPE;
union _yytype {
  struct {
    int       type; /* Pointer to array of arguments $1 $2 $3 etc. */
    int       nargs; /* No of args to this rule -- $1, $2 etc. $0 is the rule itself. */
    char     *name;
    char     *text;
    long      lineno; /* Source line */
    long      offset; /* Source seek pos */
    void     *user_value;
    int     (*action) (YYTYPE *args);
    YYTYPE   *self; /* Base of flex array, points to self */
  } record;
  struct {
    int       type;
    int       nargs; /* No of args to this rule -- $1, $2 etc. $0 is the rule itself. */
    char     *name;
    char     *text;
    long      lineno; /* Source line */
    long      offset; /* Source seek pos */
    void     *user_value;
    int     (*action) (YYTYPE *args);
    YYTYPE   *arg[50]; /* Actually a flex array determined by malloc() */
  } execute;
};

typedef struct patpair {
   char *pat;
   regexp *r;
} patpair;

/* extern patpair savepat[]; - now static */


extern int cover_testing;
extern int lev;
extern int _debug;
extern int _optimise;
  /* Current list of run-time optimisations:
     1) don't initialise args to NULL
     2) don't call debug entry or exit procedures
   */
extern int _execute_debug; /* If only execution trace wanted */
extern long tacc_bestpos; /* Of some dubious use in diagnostics... */

/* Headers for taccutil.c */
extern int taccutil_slen(const char *a, const int b, const char *c, const char *s);
extern int taccutil_strlen(const char *f, const int l, const char *n, const char *s);
extern char *ExeMassage(char *s);
extern int debug(const char *fmt, ...);
extern int debug(const char *fmt, ...);
extern int debug_enter(const char *fmt, ...);
extern int debug_execute_enter(const char *fmt, ...);
extern int debug_exit(const char *fmt, ...);
extern int debug_execute_exit(const char *fmt, ...);
extern int Dummy(YYTYPE args[]);
extern YYTYPE *makeparsetree(YYTYPE temp, int (*action )(YYTYPE __arg[]), int entries, char *name, int tag);
extern int _regexp_parse(patpair savepat[], int patno, YYTYPE **inf);
extern int execute_parsetree(YYTYPE *root);
extern int note_backtrack(long *pos);
extern void do_backtrack(long pos);
extern void dump_parsetree(YYTYPE *root);
extern void free_parsetree(YYTYPE *root);
extern int not(int (*_parse )(YYTYPE **inf ), YYTYPE **arg);
extern int is(int (*_parse )(YYTYPE **inf ), YYTYPE **arg);
/* End of headers for taccutil.c */

#endif /* _TACCUTIL_H */

