/*                                                               -*- C -*-
 *  CVT.H
 *
 *  (c)Copyright 1993 by Tobias Ferber,  All Rights Reserved
 */

#ifndef CVT_H
#define CVT_H

#include <ctype.h>
#include <string.h>
#include <stdio.h>

#define VERSION "1.6"

#ifdef __GNUC__
/* suggested parentheses around assignment used as truth value */
#define if(assignment) if((assignment))
#endif /* __GNUC__ */

#ifndef MAXIMUM_PATHNAME_LENGTH
#define MAXIMUM_PATHNAME_LENGTH  256L
#endif

#define ENV_CVSCRIPTS   "CVSCRIPTS"    /* .cvt files home directory */
#define CVT_EXT         ".cvt"         /* default extension for .cvt files */
#define TEMPFILE_FORMAT "CVT%05ld.TMP" /* format of temporary filenames */

#if defined(AMIGA) || defined(unix)
#define PSLASH     '/'     /* concatenated to pathnames if needed */
#define PSEP       ','     /* seperator for pathnames in environment vars */

#elif defined(__MSDOS__)
#define PSLASH     '\\'
#define PSEP       ';'

#endif

#define CATSYM     ','     /* default concatenation symbol */
#define RTERM      ';'     /* default conversion rule terminal symbol */

#define XHSBUFSIZE   42L   /* This value indicates the initial buffer size
                            * of the lhs/rhs buffer of readcrule().
                            * Each time the buffer exceeds another
                            * XHSBUFSIZE bytes will be added. */

#define NIL(type) (type *)0L

typedef struct crule {  /* conversion rules: */
  struct crule *next;   /* next crule with same first lhs char */
  char *lhs, *rhs;      /* input text and output text */
  int l,r;              /* #of chars in the above arrays */
  int ln;               /* line # of this rule in the script file */
} crule_t;


typedef struct fnode {  /* filename node: */
  struct fnode *next;   /* next node (command line from left to right) */
  char *filename;       /* the input filename */
  char *hostname;       /* where `filename' appeared, 0==command-line */
} fnode_t;


/*** / PROTOTYPES / ***/

#ifndef __P

#if defined (__STDC__) || defined(__cplusplus)
#define __P(protos) protos
#else /* !(__STDC__ || __cplusplus) */
#define __P(protos) ()
#endif /* __STDC__ || __cplusplus */

#endif /* !__P */

#if defined(__cplusplus) || defined(cplusplus)
extern "C" {
#endif

/* rules.c */
extern crule_t *new __P( (void) );
extern crule_t *dispose __P( (crule_t *) );
extern int init_rules __P( (void) );
extern void exit_rules __P( (void) );
extern int addcrule __P( (crule_t *) );

#ifdef DEBUG
extern int maxlhs __P( (void) );
extern void print_crule __P( (crule_t *) );
extern void dump_crules __P( (void) );
#endif /* DEBUG */

/* echo.c */
extern void echo __P( (const char *fmt, ...) );

/* args.c */
extern char *convert_args __P( (char *) );
extern void display_args __P( (void) );

/* numdigits.c */
extern int numdigits __P( (int, int) );

/* tfname.c */
extern char *tfname __P( (char *) );

/* flist.c */
extern int chain_fname __P( (char *, char *) );
extern void purge_flist __P( (void) );
extern int get_fname __P( (FILE *, char *) );
extern int read_flist __P( (char *) );
#ifdef DEBUG
extern void print_flist __P( (void) );
#endif

/* cvtparse.c */
extern void lerror __P( (long, const char *, ...) );
extern crule_t *readcrule __P( (FILE *) );

#ifdef _DCC /* DICE */
/* getenv.c */
extern char *getenv __P( (const char *) );
#endif

/* cvt.c */
extern FILE *cvtopen __P( (char *) );
extern int parsefile __P( (FILE *) );
extern void putrhs __P( (crule_t *) );
extern void takeiteasy __P( (void) );
extern int dothehardpart __P( (void) );

#if defined(__cplusplus) || defined(cplusplus)
}
#endif /* C++ */


/*** / GLOBALS / ***/

/* flist.c */
extern fnode_t *flist;
extern int global_numfiles;

/* rules.c */
extern crule_t **crules;
extern long global_numrules;
extern int global_maxlhs;

/* main.c */
extern int global_numchars;
extern int global_maxhexdigits;
extern int global_maxoctdigits;
extern int global_numerrors;
extern int global_maxerrors;
extern int global_checkexists;

extern char *whoami;
extern FILE *fin, *fout, *ferr;

#ifdef DEBUG
extern int debuglevel;  /* main.c */
#endif

#endif /* !CVT_H */
