
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>

#include "log.h"
#include "taccutil.h"

#include "debug.h"
#include "mmalloc.h"

/* NOTE: Some journals don't have volume/number info - particularly
   annuals, but also those funny dentistry ones.  This could cause
   a problem if naming files on the strength of the issue number. */


/* This is the type of objects passed around as $1, $0 etc. */
#define USERTYPE char

int exit_flag = FALSE;
int printing = TRUE;
extern int _debug; /* set to true for parser diags */

char *ProgName = "lextest";

int verbose = FALSE;

int valid = FALSE; /* True if a table of contents file */
int bibpending = FALSE; /* True when next item in toc is a bib start page */
char curmode[128] = { '\0' };
char section[128] = { '\0' };

char *copyof(char *text)
{
   char *s;
   s = stackmalloc(strlen(text)+1);
   if (s == NULL) {
      fprintf(stderr, "copyof: malloc fails - not enough room.\n");
      exit(EXIT_FAILURE);
   }
   strcpy(s, text);
   return(s);
}

void (*cur_handler)(char *s);

void ignore(char *s)
{
}


int main_1(YYTYPE *__arg);

int main_parse(YYTYPE **__arg);
static int SEEN_main_1 = FALSE;

int block_1(YYTYPE *__arg);

int block_parse(YYTYPE **__arg);
static int SEEN_block_1 = FALSE;

int block_2(YYTYPE *__arg);
static int SEEN_block_2 = FALSE;

int block_3(YYTYPE *__arg);
static int SEEN_block_3 = FALSE;

int block_4(YYTYPE *__arg);
static int SEEN_block_4 = FALSE;

int block_5(YYTYPE *__arg);
static int SEEN_block_5 = FALSE;

int middle_1(YYTYPE *__arg);

int middle_parse(YYTYPE **__arg);
static int SEEN_middle_1 = FALSE;


extern int debug(const char *fmt, ...);
extern int debug_enter(const char *fmt, ...);
extern int debug_exit(const char *fmt, ...);

extern FILE *yyin;

int eof_parse(YYTYPE **p)
{
  int c;
  c = fgetc(yyin);
  if (c == EOF) return(TRUE);
  ungetc(c, yyin);
  return(FALSE);
}

int setdebug_parse(YYTYPE **p)
{
  _debug = TRUE;
  return(TRUE);
}

int candebug_parse(YYTYPE **p)
{
  _debug = FALSE;
  return(TRUE);
}

#define MAX_RULES 5
static patpair savepat[11] = {
   {"^", NULL},
   {"^pqr[a-z]*stu[a-z]*", NULL},
   {"^$", NULL},
   {"^abc", NULL},
   {"^123def", NULL},
   {"^$", NULL},
   {"^Version.*Number.*", NULL},
   {"^$", NULL},
   {"^.*", NULL},
   {"^$", NULL},
   {"^123", NULL},
};
