#ifndef	DEF_H
#define DEF_H
/*
 * This file is the general header file for all parts of the MicroEMACS
 * display editor. It contains all of the general definitions and macros. It
 * _must_ be included in any source file after all the option include files.
 */
#include	"sysdef.h"	/* Order is critical.		 */
#include	"ttydef.h"
#include	"chrdef.h"

/*
 * If your system and/or compiler does not support the "void" type then
 * define NO_VOID_TYPE in sysdef.h.  In the absence of some other definition
 * for VOID, the default in that case will be to turn it into an int, which
 * works with most compilers that don't support void.  In the absence of any
 * definition of VOID or NO_VOID_TYPE, the default is to assume void is
 * supported, which should be the case for most modern C compilers.
 */

#ifdef NO_VOID_TYPE
#  undef VOID
#  define VOID int		/* Default for no void is int */
#else
#ifndef VOID
#  define VOID void		/* Just use normal void */
#endif				/* VOID */
#endif				/* NO_VOID_TYPE */

/*
 * If your system and/or compiler doesn't support prototypes, NO_PROTO in
 * sysdef.h. This will cause all parameters to vanish.
 */

#ifdef	NO_PROTO
#define PROTO(a)	()
#else
#define PROTO(a)	a
#endif

/*
 * Table sizes, etc.
 */
#define NFILEN	80		/* Length, file name.		 */
#define NBUFN	24		/* Length, buffer name.		 */
#define NMACN	80		/* Length, macro name.		 */
#define NLINE	256		/* Length, line.		 */
#define PBMODES 4		/* modes per buffer		 */
#define NKBDM	256		/* Length, keyboard macro.	 */
#define NPAT	80		/* Length, pattern.		 */
#define HUGE	1000		/* A rather large number.	 */
#define NSRCH	128		/* Undoable search commands.	 */
#define NXNAME	128		/* Length, extended command.	 */
#define NKNAME	20		/* Length, key names		 */
/*
 * Universal.
 */
#define FALSE	0		/* False, no, bad, etc.		 */
#define TRUE	1		/* True, yes, good, etc.	 */
#define ABORT	2		/* Death, ^G, abort, etc.	 */

#define ERASE	ABORT		/* epresf -> erase _now_	 */

/*
 * These flag bits keep track of some aspects of the last command. The CFCPCN
 * flag controls goal column setting. The CFKILL flag controls the clearing
 * versus appending of data in the kill buffer.
 */
#define CFCPCN	0x0001		/* Last command was C-P, C-N	 */
#define CFKILL	0x0002		/* Last command was a kill	 */
#define CFINS	0x0004		/* Last command was self-insert */

/*
 * File I/O.
 */
#define FIOSUC	0		/* Success.			 */
#define FIOFNF	1		/* File not found.		 */
#define FIOEOF	2		/* End of file.			 */
#define FIOERR	3		/* Error.			 */
#define FIOLONG 4		/* long line partially read	 */

/*
 * Directory I/O.
 */
#define DIOSUC	0		/* Success.			 */
#define DIOEOF	1		/* End of file.			 */
#define DIOERR	2		/* Error.			 */

/*
 * Display colors.
 */
#define CNONE	0		/* Unknown color.		 */
#define CTEXT	1		/* Text color.			 */
#define CMODE	2		/* Mode line color.		 */

/* Flags for keyboard invoked functions */

#define FFUNIV		1	/* universal argument		 */
#define FFNEGARG	2	/* negitive only argument	 */
#define FFOTHARG	4	/* other argument		 */
#define FFARG		7	/* any argument			 */
#define FFRAND		8	/* Called by other function	 */

/*
 * Flags for "getkey". SOFTCR first. It should be a KCHAR that's not
 * otherwise used. If the defualt won't work, set it in ttydef.h. SOFTCR is
 * used to tag the end of strings in macros. You should use SEESCR if you
 * want to get a real string, including carriage returns; SOFTCR will be the
 * end of string marker. If you're getting some number of keys that
 * terminates based on the keys (keymap searches, or some such), you should
 * use DISSCR. It will throw out the SOFTCR that follows the argument you're
 * reading in the macro (or startup buffer, which uses the same code). If the
 * argument doesn't terminate correctly, the next argument read will have
 * bogus values (either the end of your arg, or with you getting part of
 * theirs). Setting niether causes the SOFTCR to turn into a CR. This is what
 * eread and friends do.
 */
#ifndef	SOFTCR
#define SOFTCR		0x1000	/* Avoid the metabit */
#endif
#define	PROMPT		0x01	/* Delayed prompt, if supported */
#define	SEESCR		0x02	/* Pass SOFTCR unmodifed */
#define DISSCR		0x04	/* Discard SOFTCR (with lookahead) */
#define CRFLAGS		0x06	/* All the SOFTCR flags at once */

/*
 * Flags for "eread".
 */
#define EFFUNC	0x0001		/* Autocomplete functions.	 */
#define EFBUF	0x0002		/* Autocomplete buffers.	 */
#define EFFILE	0x0004		/* " files (maybe someday)	 */
#define EFMACRO	0x0008		/* Autocomplete only macros	 */
#define	EFFORCE	0x0009		/* Must complete to known name	 */
#define EFAUTO	0x000F		/* Some autocompleteion on	 */
#define EFNEW	0x0010		/* New prompt.			 */
#define EFCR	0x0020		/* Echo CR at end; last read.	 */

/*
 * Flags for kinsert
 */

#define KFORW	0
#define KBACK	1
/*
 * Externals.
 */
extern int      thisflag;
extern int      lastflag;
extern int      curgoal;
extern int      epresf;
extern int      sgarbf;
extern int      mode;
extern char     pat[];
extern int      nrow;
extern int      ncol;
extern int      ttrow;
extern int      ttcol;
extern int      tceeol;
extern int      tcinsl;
extern int      tcdell;
extern char     cinfo[];
extern char    *keystrings[];
#ifdef	NO_PROTO
extern VOID     ewprintf();
extern VOID     update();
extern char    *keyname();
extern char    *adjustname();
extern VOID     kdelete();
extern VOID     lchange();
#endif

#ifndef	ANSI
/*
 * Standard I/O.
 */
extern char    *strcpy();
extern char    *strcat();
extern char    *malloc();
#endif

/*
 * This is the beginnings of the prototype list for all externals. We give
 * prototypes for all external functions from all files that have arguments
 * that are standard C type and return standard C types. Functions that
 * return mg-specific types have prototypes in the .h files that define those
 * types. Things are set up so that if you take it out of the ifdef's, you
 * won't get the parameters unless your compiler can support them. I'm not
 * sure what will happen in that case.
 */

#ifndef	NO_PROTO
/* Prototypes for functions defined in help.c */
int             desckey
                PROTO((int f, int n));
int             wallchart
                PROTO((int f, int n));
int             help_help
                PROTO((int f, int n));
int             apropos_command
                PROTO((int f, int n));

/* Prototypes for functions defined in macro.c */
int             definemacro
                PROTO((int f, int n));
int             finishmacro
                PROTO((int f, int n));
int             executemacro
                PROTO((int f, int n));
int             insertmacro
                PROTO((int f, int n));
int             namemacro
                PROTO((int f, int n));
int             macroset
                PROTO((int f, int n));
int             macroquery
                PROTO((int f, int n));

/* Prototypes for functions defined in keymap.c */
int
                complete_function(char *fname, int c);
char           *function_name
                PROTO((int (*fpoint) ()));
int             (*
		                 name_function PROTO((char *fname))) ();

/* Prototypes for functions defined in display.c */
VOID            vtinit
                PROTO((VOID));
VOID            vttidy
                PROTO((VOID));
VOID            vtmove
                PROTO((int row, int col));
VOID            vtputc
                PROTO((int c));
VOID            vtpute
                PROTO((int c));
VOID            vteeol
                PROTO((VOID));
VOID            update
                PROTO((VOID));
VOID            updext
                PROTO((int currow, int curcol));
int             vtputs
                PROTO((char *s));

/* Prototypes for functions defined in version.c */
int             showversion
                PROTO((int f, int n));

/* Prototypes for functions defined in cinfo.c */
char           *keyname
                PROTO((char *cp, int k));

/* Prototypes for functions defined in dir.c */
VOID            dirinit
                PROTO((VOID));
int             changedir
                PROTO((int f, int n));
int             showcwdir
                PROTO((int f, int n));
int             filevisit
                PROTO((int f, int n));
int             filesave
                PROTO((int f, int n));
int             filewrite
                PROTO((int f, int n));
int             makebkfile
                PROTO((int f, int n));
VOID            makename
                PROTO((char bname[], char fname[]));
char           *adjustname
                PROTO((char *));

/* Prototypes for functions defined in extend.c */
int             load
                PROTO((char *));
int             extend
                PROTO((int f, int n));
int             evalexpr
                PROTO((int f, int n));
int             evalbuffer
                PROTO((int f, int n));
int             evalfile
                PROTO((int f, int n));
int             load
                PROTO((char *fname));
int             excline
                PROTO((char *line, int len));

/* Prototypes for functions defined in bind.c */
int             insert
                PROTO((int f, int n));
int             bindtokey
                PROTO((int f, int n));
int             localbind
                PROTO((int f, int n));
int             define_key
                PROTO((int f, int n));
int             unbindtokey
                PROTO((int f, int n));
int             localunbind
                PROTO((int f, int n));

/* Prototypes for functions defined in re_search.c */
int             re_forwsearch
                PROTO((int f, int n));
int             re_backsearch
                PROTO((int f, int n));
int             re_searchagain
                PROTO((int f, int n));
int             re_queryrepl
                PROTO((int f, int n));
int             setcasefold
                PROTO((int f, int n));
int             delmatchlines
                PROTO((int f, int n));
int             delnonmatchlines
                PROTO((int f, int n));
int             cntmatchlines
                PROTO((int f, int n));
int             cntnonmatchlines
                PROTO((int f, int n));

/*
 * Prototypes for functions defined in alloca.c Could well be wrong for your
 * system, but I dunno how else to deal with it.
 */
VOID           *alloca
                PROTO((unsigned));

/* Prototypes for functions defined in buffer.c */
int             usebuffer
                PROTO((int f, int n));
int             poptobuffer
                PROTO((int f, int n));
int             killbuffer
                PROTO((int f, int n));
int             savebuffers
                PROTO((int f, int n));
int             listbuffers
                PROTO((int f, int n));
int             anycb
                PROTO((int f));
int             bufferinsert
                PROTO((int f, int n));
int             notmodified
                PROTO((int f, int n));

/* Prototypes for functions defined in basic.c */
int             gotobol
                PROTO((int f, int n));
int             backchar
                PROTO((int f, int n));
int             gotoeol
                PROTO((int f, int n));
int             forwchar
                PROTO((int f, int n));
int             gotobob
                PROTO((int f, int n));
int             gotoeob
                PROTO((int f, int n));
int             forwline
                PROTO((int f, int n));
int             backline
                PROTO((int f, int n));
VOID            setgoal
                PROTO((VOID));
int             forwpage
                PROTO((int f, int n));
int             backpage
                PROTO((int f, int n));
int             forw1page
                PROTO((int f, int n));
int             back1page
                PROTO((int f, int n));
int             pagenext
                PROTO((int f, int n));
VOID            isetmark
                PROTO((VOID));
int             setmark
                PROTO((int f, int n));
int             swapmark
                PROTO((int f, int n));
int             gotoline
                PROTO((int f, int n));

/* Prototypes for functions defined in modes.c */
int             indentmode
                PROTO((int f, int n));
int             fillmode
                PROTO((int f, int n));
int             blinkparen
                PROTO((int f, int n));
int             overwrite
                PROTO((int f, int n));
int             set_default_mode
                PROTO((int f, int n));
int             notabmode
                PROTO((int f, int n));

/* Prototypes for functions defined in dired.c */
int             dired
                PROTO((int f, int n));
int             d_otherwindow
                PROTO((int f, int n));
int             d_del
                PROTO((int f, int n));
int             d_undel
                PROTO((int f, int n));
int             d_undelbak
                PROTO((int f, int n));
int             d_findfile
                PROTO((int f, int n));
int             d_ffotherwindow
                PROTO((int f, int n));
int             d_expunge
                PROTO((int f, int n));
int             d_copy
                PROTO((int f, int n));
int             d_rename
                PROTO((int f, int n));

/* Prototypes for functions defined in word.c */
int             backword
                PROTO((int f, int n));
int             forwword
                PROTO((int f, int n));
int             upperword
                PROTO((int f, int n));
int             lowerword
                PROTO((int f, int n));
int             capword
                PROTO((int f, int n));
int             delfword
                PROTO((int f, int n));
int             delbword
                PROTO((int f, int n));
int             inword
                PROTO((VOID));

/* Prototypes for functions defined in window.c */
int             reposition
                PROTO((int f, int n));
int             refresh
                PROTO((int f, int n));
int             nextwind
                PROTO((int f, int n));
int             prevwind
                PROTO((int f, int n));
int             onlywind
                PROTO((int f, int n));
int             splitwind
                PROTO((int f, int n));
int             enlargewind
                PROTO((int f, int n));
int             shrinkwind
                PROTO((int f, int n));
int             delwind
                PROTO((int f, int n));

/* Prototypes for functions defined in search.c */
int             forwsearch
                PROTO((int f, int n));
int             backsearch
                PROTO((int f, int n));
int             searchagain
                PROTO((int f, int n));
int             forwisearch
                PROTO((int f, int n));
int             backisearch
                PROTO((int f, int n));
int             isearch
                PROTO((int dir));
int             queryrepl
                PROTO((int f, int n));
int             forwsrch
                PROTO((VOID));
int             backsrch
                PROTO((VOID));
int             readpattern
                PROTO((char *prompt));

/* Prototypes for functions defined in region.c */
int             killregion
                PROTO((int f, int n));
int             copyregion
                PROTO((int f, int n));
int             lowerregion
                PROTO((int f, int n));
int             upperregion
                PROTO((int f, int n));
int             prefixregion
                PROTO((int f, int n));
int             setprefix
                PROTO((int f, int n));


/* Prototypes for functions defined in paragraph.c */
int             gotobop
                PROTO((int f, int n));
int             gotoeop
                PROTO((int f, int n));
int             fillpara
                PROTO((int f, int n));
int             killpara
                PROTO((int f, int n));
int             fillword
                PROTO((int f, int n));
int             setfillcol
                PROTO((int f, int n));

/* Prototypes for functions defined in match.c */
int             showmatch
                PROTO((int f, int n));

/* Prototypes for functions defined in main.c */
int             quit
                PROTO((int f, int n));
int             ctrlg
                PROTO((int f, int n));

/* Prototypes for functions defined in kbd.c */
int             do_meta
                PROTO((int f, int n));
int             bsmap
                PROTO((int f, int n));
int             selfinsert
                PROTO((int f, int n));
VOID            ungetkey
                PROTO((int c));
int             getkey
                PROTO((int flag));
int             doin
                PROTO((VOID));
int             rescan
                PROTO((int f, int n));
int             quote
                PROTO((int f, int n));
int             negative_argument
                PROTO((int f, int n));
int             digit_argument
                PROTO((int f, int n));
int             universal_argument
                PROTO((int f, int n));

/* Prototypes for functions defined in file.c */
int             fileinsert
                PROTO((int f, int n));
int             filevisit
                PROTO((int f, int n));
int             revertbuffer
                PROTO((int f, int n));
int             poptofile
                PROTO((int f, int n));
int             readin
                PROTO((char *fname));
int             insertfile
                PROTO((char *fname, char *newname));

/* Prototypes for functions defined in echo.c */
VOID            eerase
                PROTO((VOID));
int             eyorn
                PROTO((char *sp));
int             eyesno
                PROTO((char *sp));
#ifdef	LATTICE
int __stdargs   ereply
                PROTO((char *fp, char *buf, int nbuf,...));
int __stdargs   eread
                PROTO((char *fp, char *buf, int nbuf, int flag,...));
VOID __stdargs ewprintf PROTO((char *fp,...));
#else
int             ereply
                PROTO((char *fp, char *buf, int nbuf,...));
int             eread
                PROTO((char *fp, char *buf, int nbuf, int flag,...));
VOID            ewprintf
                PROTO((char *fp,...));
#endif

/* Prototypes for functions defined in random.c */
int             showcpos
                PROTO((int f, int n));
int             getcolpos
                PROTO((VOID));
int             twiddle
                PROTO((int f, int n));
int             openline
                PROTO((int f, int n));
int             newline
                PROTO((int f, int n));
int             deblank
                PROTO((int f, int n));
int             justone
                PROTO((int f, int n));
int             delwhite
                PROTO((int f, int n));
int             indent
                PROTO((int f, int n));
int             forwdel
                PROTO((int f, int n));
int             backdel
                PROTO((int f, int n));
int             killline
                PROTO((int f, int n));
int             yank
                PROTO((int f, int n));
int             space_to_tabstop
                PROTO((int f, int n));

/* Prototypes for functions defined in line.c */
VOID            lchange
                PROTO((int flag));
int             linsert
                PROTO((int n, int c));
int             lnewline
                PROTO((VOID));
int             fdelete
                PROTO((RSIZE n, int flag));
int             bdelete
                PROTO((RSIZE n, int flag));
int             ldelnewline
                PROTO((VOID));
int             lreplace
                PROTO((RSIZE plen, char *st, int f));
VOID            kdelete
                PROTO((VOID));
int             kinsert
                PROTO((int c, int dir));
char            kremove
                PROTO((RSIZE n));
int             klremove
                PROTO((char *str, RSIZE * n));

/* Prototypes for functions defined in regex.c */

#endif

#ifndef	NO_PROTO
#ifndef	LOCALPROTO_H
#include "localproto.h"
#endif
#endif

#endif
