/************************************************************************
 * This program is Copyright (C) 1986 by Jonathan Payne.  JOVE is	*
 * provided to you without charge, and with no warranty.  You may give	*
 * away copies of JOVE, including sources, provided that this notice is *
 * included in all the files.						*
 ************************************************************************/

/* jove.h header file to be included by EVERYONE */

#ifndef _JOVE_H_
#define _JOVE_H_

#ifndef TUNED
#   include "tune.h"
#endif

#ifdef Extern
RCS_H(jove, "$Id: jove.h,v 14.32.0.11 1994/06/11 21:35:54 tom Exp tom $")
#endif

#ifndef Extern
#   define Extern	extern
#endif

#include <setjmp.h>
#include <errno.h>
#undef ERROR		/* Minix's errno defines it (booh!) */

#if _ANSI_HEADERS_
#   include <limits.h>
#else
#   ifndef errno
extern int	errno;
#   endif
#endif

#define private static
#define public

#undef EOF
#define EOF	(-1)
#define NIL	0

/* return codes for command completion (all < 0 because >= 0 are
   legitimate offsets into array of strings */

#define AMBIGUOUS	-2	/* matches more than one at this point */
/*- #define UNIQUE	-3	/* matches only one string NEVER! */
#define ORIGINAL	-4	/* matches no strings at all! */
#define NULLSTRING	-5	/* just hit return without typing anything */

/* values for the `flags' argument to complete */
#define NOTHING 	0	/* opposite of RET_STATE */
#define RET_STATE	1	/* return state when we hit return */
/*- #define RCOMMAND	2	/* we are reading a joverc file NEVER! */
#define CASEIND 	4	/* map all to lower case */

#if (LBSIZE > BLKSIZ)		/* Size of linebuffer, if configured elsewhere,
				   should not exceed disk block size. */
#   undef LBSIZE
#endif

#ifndef LBSIZE			/* Provide default for size of line buffers. */
#   if (BLKSIZ <= 1024)
#	define LBSIZE	BLKSIZ	/* same as a logical disk block */
#   else
#	define LBSIZE	1024
#   endif
#endif

#ifndef FILESIZE		/* Provide default for size of filename buffers. */
#   ifdef PATH_MAX
#	define FILESIZE	(PATH_MAX+1)
#   else
#	ifdef DOS
#	    define FILESIZE	128	/* max. file name length */
#	else
#	    ifdef SMALL
#		define FILESIZE	128
#	    else
#		ifndef BSD4_2
#		    define FILESIZE	256
#		else
#		    define FILESIZE	1024
#		endif
#	    endif
#	endif
#   endif
#endif

#define BNAMESIZE	128	/* max. size of buffer names */
#ifndef MAXCOLS
#   define MAXCOLS	132
#endif

#define FORWARD 	1
#define BACKWARD	(-1)

#define CTL(c)		((c)^'@')
#define RUBOUT		'\177'
#define LF		'\n'
#define CR		'\r'
#define BS		'\b'
#define ESC		'\033'

#if OBSOLETE			/* only available when FUNCKEYS defined */
#define UPARROW		0200
#define DOWNARROW	0201
#define RIGHTARROW	0202
#define LEFTARROW	0203
#endif

/* tab handling */
#define TabIncr(pos)	(tabstop-(pos)%tabstop)
#define UpdVisPos(pos,c)(pos += (!isctrl(c))? 1: ((c)=='\t')? TabIncr(pos): 2)

/* Bit(set) handling. */
#define Bit(i)		(1<<(i))

#define BITSET_OP(set,OP,i)	(((char *)(set))[(i)>>3] OP Bit((i)&7))
#define BITSET_SIZE(nbits)	(((nbits)+7)>>3)

#define DoTimes(f, n)	(exp_p=YES, exp=(n), f)

/* command types */
#define ARG_CMD 	1
#define LINECMD 	2
#define KILLCMD 	3	/* so we can merge kills */
#define YANKCMD 	4	/* so we can do ESC Y (yank-pop) */

/* Buffer type */
#define B_SCRATCH	1	/* for internal things, e.g. minibuffer ... */
#define B_FILE		2	/* normal file (We Auto-save these.) */
#define B_PROCESS	3	/* process output in this buffer */
#ifdef IPROCS
#   define B_IPROCESS	4	/* interactive process attached to buffer */
#   define B_NTYPES	4	/* # of buffer types */
#else
#   define B_NTYPES	3
#endif

/* Major modes */
#define FUNDAMENTAL	0	/* Fundamental mode */
#define TEXT		1	/* Text mode */
#define CMODE		2	/* C mode */
#ifdef LISP
#   define LISPMODE	3	/* Lisp mode */
#   define if_LISP(x)	(x)	/* handy conditional-code macro */
#else
#   define if_LISP(x)	0
#endif
#ifdef PERL
#   define PERLMODE	(3 + if_LISP(1))	/* Perl mode */
#   define if_PERL(x)	(x)	/* handy conditional-code macro */
#else
#   define if_PERL(x)	0
#endif
#define	NMAJORS		(3 + if_LISP(1) + if_PERL(1))


/* Minor Modes */
#define Indent		(1<<0)	/* indent same as previous line after return */
#define ShowMatch	(1<<1)	/* paren flash mode */
#define Fill		(1<<2)	/* text fill mode */
#define OverWrite	(1<<3)	/* over write mode */
#define Abbrev		(1<<4)	/* abbrev mode */
#define View		(1<<5)	/* view (readonly) mode */

#define BufMinorMode(b, x)	(b->b_minor&(x))
#define BufMajorMode(b, x)	(b->b_major==(x))
#define MinorMode(x)	BufMinorMode(curbuf,x)
#define MajorMode(x)	BufMajorMode(curbuf,x)
#define SetMajor(x)	(UpdModLine++, ModeMask=(1<<(x)), curbuf->b_major=(x))

#define C_like_Mode(b)	(BufMajorMode(b,CMODE)||/* This occurs a lot */\
			 if_PERL(BufMajorMode(b,PERLMODE)))

/* setjmp/longjmp args for DoKeys() mainjmp */
#define FIRSTCALL	0
#define ERROR		1
#define COMPLAIN	2	/* do the error without a getDOT */
#define QUIT		3	/* leave this level of recursion */

#define QUIET		1	/* sure, why not? */

#define YES		1
#define NO		0
#define TRUE		1
#define FALSE		0
#define ON		1
#define OFF		0
#define YES_NODIGIT	2

#define READ		0
#define WRITE		1


extern const char
		Mainbuf[],
		NoName[],
		NullStr[],
		ProcFmt[],
		ProcDefFmt[],
		ProcArgFmt[];

extern char	*HomeDir,	/* home directory */
		*Inputp;

extern int	HomeLen;	/* length of home directory */

extern char	linebuf[LBSIZE];/* buffer holding current line */
#ifdef BIG
extern char	genbuf[],
		iobuff[];
#else
extern char	*genbuf,	/* scratch pad points at s_genbuf (see main()) */
		*iobuff;	/* for file reading ... points at s_iobuff */
#endif

extern int	OkayAbort,	/* okay to abort redisplay */
		InJoverc,	/* executing a .joverc command file */
		Interactive;	/* interactive macro argument? */

/* Error handling. */

typedef struct {
	jmp_buf	*sj_savenv;
	jmp_buf sj_newenv;
} Savejmp;

extern jmp_buf	*mainjmp;

#if _ANSI_ARRAY_
#   define push_env(s)	(s.sj_savenv=mainjmp, \
			 setjmp(*(mainjmp=&s.sj_newenv)))
    /* some (supposedly) ANSI compilers still don't like the `&'! */
#else
#   define push_env(s)	(s.sj_savenv=mainjmp, \
			 setjmp(*(mainjmp=(jmp_buf*)s.sj_newenv)))
#endif
#define jump_env(st)	(longjmp(*mainjmp,(st)))
#define pop_env(s)	(mainjmp=s.sj_savenv)

#define CATCH \
{				\
	Savejmp sav_jmp;	\
	if (push_env(sav_jmp)==0) {

#define ONERROR \
	} else {

#define ENDCATCH \
	}			\
	pop_env(sav_jmp);	\
}

/* Data objects. */

#define FUNCTION	1
#define VARIABLE	2
#define MACRO		3
#define KEYMAP		4

#ifdef MENUS
#   define BUFFER	6	/* to simplify menu handler */
#   define STRING	7	/* Menu string / divider */
#endif
#define TYPEMASK	0177	/* object-type + flags */
#define REALTYPEMASK	07	/* object type only */

typedef struct {
	int	Type;
  const	char	*Name;
} data_obj;	/* points to cmd, macro, or variable */

#define ARG(val)	((val)<<8)		/* define object argument */
#define ObjArg(dp)	((dp)->Type>>8)		/* ... and retrieve it */

/* Object definition macros (these are redefined in vars.c and funcdefs.c) */
#define DEF_CMD(Name,Func,Type)		void Func __((void))
#define DEF_MAJ(Name,Major,Desc)	Desc
#define DEF_MIN(Name,Minor,Desc)	Desc
#define DEF_MAP(Name,Map,Num)
#define DEF_INT(Name,Var,Type)		int Var
#define DEF_STR(Name,Var,Len,Type)	char *Var /* `Len' is obsolete */

#define DEF_REF(Name, ref)		extern data_obj *ref

/* dummy conditional for DEF_XXX extraction */
#define _IF(x)

typedef struct {
	int	Type;		/* FUNCTION | subtype | ARGuments */
  const	char	*Name;
	void	(*c_proc)__(( void ));
} Command;

extern const Command	commands[];

/* function subtypes/argument values (ORed in with FUNCTION) */
#define MAJOR_MODE	010
#define MINOR_MODE	020
#define EDIT		030	/* command modifies buffer */
#define NEGATE		040	/* negate numeric argument */
#define PREFIX		0100

typedef struct {
	int	Type;		/* VARIABLE | sub_type | flags | arguments */
  const	char	*Name;		/* name is always second */
	int	*v_value;
} Variable;

extern const Variable	variables[];

/* Variable subtypes/flags (packed into Type). */
#define V_BOOL		0	/* is a boolean */
#define V_BASE10	1	/* is integer in base 10 */
#define V_BASE8 	2	/* is integer in base 8 */
#define V_CHAR		3	/* is a character */
#define V_STRING	4	/* is a string */
#define V_FILENAME	5	/* a file name (implies V_STRING) */
#define V_REGEXP	6	/* a regular expression (implies V_STRING) */
#ifdef COLOR
#   define V_COLOR	7	/* a color pair */
#endif
#define V_CLRSCREEN	(1<<6)	/* clear and redraw screen */
#define V_TTY_RESET	(2<<6)	/* redo the tty modes */
#define V_MODELINE	(3<<6)	/* update modeline */
#define V_CONST		(4<<6)	/* this is a constant */
#define V_FLAGS(vp)	((vp)->Type&(7<<6))		/* get flags */
#define V_LENGTH(vp)	(((unsigned)(vp)->Type>>8)&~1)	/* unpack string size */
#define V_TYPE(vp)	(((vp)->Type>>3)&07)		/* unpack var type */

/* we want variable types shifted 3 bits left,
   size shifted 8 bits left, and other bits left alone... */

#define V_SET(tp,siz)	(((tp)&07)<<3|((tp)&~077)|((siz)&~1)<<8)

#define True(bool)	((bool) > 0)	/* V_BOOL True test */
#define False(bool)	(!True(bool))	/* V_BOOL False test */

typedef struct Macro	Macro;
struct Macro {
	int	Type;		/* in this case a macro--also used for flags */
  const	char	*Name;		/* name is always second ... */
	int	m_len;		/* length of macro so we can use ^@ */
	char	*m_body;	/* actual body of the macro */
	Macro	*m_nextm;
};

extern Macro	*macros;

#ifndef TINY
#   define IMMEDIATE	0x8000
/* ORed in with macro Type to indicate immediate macro execution. */
#else
#   define IMMEDIATE	0
#endif

/* A linked list of `Frame's implements the macro execution stack.
   the variable `MacStkPtr' points to the top of this stack. */

typedef struct Frame	Frame;
struct Frame {
	Macro	*mf_macro;	/* the macro being executed */
	int	mf_ntimes,	/* number of times to execute */
		mf_offset,	/* index */
		mf_interactive;	/* saved Interactive state */
	Frame	*mf_return;	/* link to previous stack frame */
};

extern Frame	*MacStkPtr;

/* fast inline */
#define in_macro()	(MacStkPtr != NULL)


extern const data_obj *LastCmd;		/* last command invoked */


typedef struct Line	Line;
struct Line {
	Line		*l_prev,	/* pointer to prev */
			*l_next;	/* pointer to next */
	disk_line	l_dline;	/* pointer to disk location */
};


typedef struct Mark	Mark;
struct Mark {
	Line	*m_line;
	int	m_char;
	Mark	*m_next;	/* list of marks */
#define FLOATER 2
	char	m_floater;	/* FLOATERing mark? */
	char	m_alloced;	/* created by MakeMark? */
};

/* fast inline */
#define MarkSet(m,l,c)		((m)->m_line=(l),(m)->m_char=(c))
#define init_mark(m,b,l,c,f)	(MarkSet((m),(l),(c)),\
				 (m)->m_next=(b)->b_marks,\
				 (b)->b_marks=(m),\
				 (m)->m_floater=(f),\
				 (m)->m_alloced=NO)

#ifdef IPROCS
typedef struct Process	Process;
struct Process {
	Process *p_next;
	int	p_outfd,	/* Connection to child (w pipe or r/w pty) */
#define p_fd	p_outfd		/* (temporary) compatibility kludge... */
#ifndef PIPEPROCS
		p_infd,		/* Connection to child (r pipe or r/w pty) */
#else
		p_portpid,	/* Pid of child (the portsrv) */
#endif
		p_pid;		/* Pid of real child (i.e. not portsrv) */
	struct Buffer
		*p_buffer;	/* Add output to end of this buffer */
	char	*p_name;	/* ... */
	char	p_state,	/* State */
		p_howdied,	/* Killed? or Exited? */
		p_reason,	/* If signaled, p_reason is the signal; else
				   it is the the exit code */
		p_dbx_mode;	/* parse output for file/lineno pairs */
	Mark	*p_mark;	/* Where output left us. */
#ifdef IPARSE
	data_obj *p_terminate;	/* command to invoke on process termination */
#endif
};
#endif /* IPROCS */

typedef struct Buffer	Buffer;
struct Buffer {
#ifdef MENUS
	int	Type;			/* i.e., BUFFER */
  const char	*Name;			/* buffer name */
#   define	b_name	Name		/* cheat... */
#endif
	Buffer	*b_next;		/* next buffer in chain */
#ifndef b_name
  const	char	*b_name;		/* buffer name */
#endif
  const	char	*b_fname;		/* file name associated with buffer */
	INO_T	b_ino;			/* inode of file name */
	dev_t	b_dev;			/* device of file name */
	time_t	b_mtime;		/* last modify time ...
					   to detect two people writing
					   to the same file */
	long/*off_t*/	b_statsize;	/* last file size...
					   to detect lies about mtime */
	Line	*b_first,		/* pointer to first line in list */
		*b_dot, 		/* current line */
		*b_last;		/* last line in list */
	int	b_char; 		/* current character in line */
#ifdef SMALL
#   define NMARKS	8		/* number of marks in the ring */
#else
#   define NMARKS	16
#endif
	Mark	*b_markring[NMARKS],	/* new marks are pushed saved here */
		*b_marks;		/* all the marks for this buffer */
	char	b_themark,		/* current mark (in b_markring) */
		b_type, 		/* file, scratch, process, iprocess */
		b_ntbf, 		/* needs to be found when we
					   first select? */
		b_modified;		/* is the buffer modified? */
	int	b_major,		/* major mode */
		b_minor;		/* and minor mode */
	void	*b_keymap;		/* local bindings (if any) */
#ifdef IPROCS
	Process *b_process;		/* process we're attached to */
#endif
#ifdef COLOR
	char	b_color;
#endif
	Line	*b_top;			/* remembered topline in window. */
};

extern Buffer	*world, 	/* first buffer */
		*curbuf,	/* pointer into world for current buffer */
		*lastbuf;	/* last used (alternate) buffer */

#define curline		(curbuf->b_dot)
#define curchar		(curbuf->b_char)

#define bobp(b)		(firstp(b,(b)->b_dot)&&bolp(b))
#define bolp(b)		((b)->b_char==0)
#define eobp(b)		(lastp(b,(b)->b_dot)&&eolp(b))
#define eolp(b)		(linebuf[(b)->b_char]=='\0')	/* assuming b==curbuf */
#define firstp(b,line)	((line)==(b)->b_first)
#define lastp(b,line)	((line)==(b)->b_last)
#define b_empty(b)	(lastp(b,(b)->b_first)&&\
			 linebuf[0]=='\0')		/* assuming b==curbuf */
#if unix
#   define b_nofile(b)	((b)->b_ino==0)
#else
#   define b_nofile(b)	((b)->b_mtime==0)	/* kludge */
#endif

/* Check whether buffer `b' is linked to the file associated with
   struct stat *`s', with `r' as the result value of the stat() call. */
#define b_flink_p(b,r,s)\
	((r)==0 && ino_eq((b)->b_ino,(s)->st_ino) && (b)->b_dev==(s)->st_dev)

/* Check whether the file associated with buffer `b' is outdated
   compared to the file associated with struct stat *`s'. */
#define b_foutdated_p(b,s)\
	((b)->b_mtime!=(s)->st_mtime || (b)->b_statsize!=(s)->st_size)

#define b_curmark(b)	(b->b_markring[b->b_themark])
#define curmark 	(b_curmark(curbuf))

#define SetABuf(b)	(lastbuf=(b))

#define IsModified(b)	((b)->b_modified)

#define SavLine(line,b)	((line)->l_dline=putline(b))
#define SetLine(line)	DotTo(line,0)
#define getDOT()	getline(curline->l_dline,linebuf)
#define isdirty(line)	((line)->l_dline & DIRTY)
#define makedirty(line) ((line)->l_dline |= DIRTY)

#define DIRTY		1

#ifdef COLOR
#   define SETBUFTYPE(b,t)	((b)->b_color=Gcolor[t], (b)->b_type=(t))
#else
#   define SETBUFTYPE(b,t)	((b)->b_type=(t))
#endif


typedef struct Window	Window;
struct Window {
	Window	*w_prev,	/* circular list */
		*w_next;
	Buffer	*w_bufp;	/* buffer associated with this window */
	Line	*w_top, 	/* top line */
		*w_line;	/* current line */
	int	w_char,
		w_height,	/* window height */
		w_topnum,	/* line number of the topline */
		w_dotcol,	/* UpdWindow sets this ... */
		w_dotline,	/* ... and this */
		w_flags,
#define W_TOPGONE	01
#define W_CURGONE	02	/* topline (curline) of window has been deleted
				   since the last time a redisplay was called */
#define W_VISSPACE	04
#define W_NUMLINES	010
#define W_NOAUTOSCROLL	020	/* inhibit auto-scrolling */
#ifndef TINY
#   define W_TOPNUM	040	/* need topline calculation for mode line */
#   define HIGHLIGHT	0100	/* highlight current line */
#else
#   define W_TOPNUM	0
#   define HIGHLIGHT	0
#endif
		w_offset;	/* horizontal display offset */
#ifdef WINDOWS
	void	*w_control;	/* to hook up scroll bar */
#endif
#if (HIGHLIGHT)
	Line	*w_highlighted_line;
#	define WHighLight(w,lp)	((w)->w_highlighted_line=(lp))
#	define WUnHighLight(w)	WHighLight(w,NULL)
#endif
};

extern Window	*fwind, 	/* first window in list */
		*curwind;	/* current window */

#define one_windp(w)	((w)->w_prev==(w))
#define SIZE(w)		((w)->w_height-1)
#define HALF(w)		(SIZE(w)/2)


typedef struct {
	Line	*p_line;
	int	p_char;
} Bufpos;

#include "vars.h"	/* the user variables */

extern int
	exp,		/* argument count */
	exp_p,		/* argument count is supplied */

	TOabort,	/* flag set by Typeout() */
	errormsg,	/* last message was an error message
			   so don't erase the error before it
			   has been read */
	this_cmd,	/* ... */
	last_cmd,	/* last command ... to implement appending
			   to kill buffer */

	RecDepth,	/* recursion depth */
	InputPending,	/* nonzero if there is input waiting to be processed */
	CanScroll,	/* can this terminal scroll? */
	Asking, 	/* are we on read a string from the terminal? */
	Defining,	/* if we are defining the keyboard macro */
	inIOread,	/* so we know whether we can do a redisplay. */

	LastKeyStruck,

#ifdef FILESELECTOR
	FSelMode,	/* select files for READ or WRITE */
#endif
#ifdef MENUS
	Bufchange,	/* buffer has been changed? */
	Modechange,	/* Major/minor mode has been changed? */
#endif
#ifdef WINDOWS
	Windchange,	/* window has been changed? */
#endif
	UpdModLine,	/* whether we want to update the mode line */
	UpdMesg;	/* update the message line */

#define updmodline()	(UpdModLine++)
#define updmesg()	(UpdMesg++)

#define NUMKILLS	10	/* number of kills saved in the kill ring */

extern Line	*killbuf[NUMKILLS],	/* array of pointers to killed stuff */
		**killptr;		/* pointer into killbuf */

#define MESG_SIZE	(MAXCOLS+2)

/* This assumes that heap and stack are allocated above static data,
   AND last.c is linked as the last module. */
extern char	last_static_variable;
#define	ISSTATIC(p)	((char*)(p) < (char*)&last_static_variable)

extern char
	mesgbuf[MESG_SIZE],
	Minibuf[LBSIZE];

extern void_
	*malloc __(( size_t _(size) )),
	*realloc __(( void *_(buf), size_t _(size) )),
	*emalloc __(( size_t _(size) ));

extern char	*index __(( const char *_(str), int _(c) )),
		*rindex __(( const char *_(str), int _(c) )),
		*getenv __(( const char *_(env_var) )),
		*mktemp __(( char *_(template) )),
#if !unix
		*mktmpe __(( char *_(result), const char *_(template) )),
#endif
		*strcpy __(( char *_(dest), const char *_(src) )),

		*copystr __(( const char *_(str) )),
		*set_str __(( char **_(strptr), const char *_(value) )),
		*basename __(( const char *_(file) )),
		*make_filename __(( char *_(buf), const char *_(path),
				    const char *_(name) ));


#ifndef NOT_JOVE

/* Don't include function prototypes if we're not compiling for JOVE. */

/* abbrev.c */

#ifdef ABBREV
#   ifndef NO_TRIV_PROTO
extern void	AbbrevExpand __(( void ));
#   endif /* NO_TRIV_PROTO */
#endif /* ABBREV */

/* ask.c */

#ifndef NO_TRIV_PROTO
extern void	minib_add __(( const char *_(str), int _(movedown) ));
extern int	env_expand __(( char *_(buf) ));
#endif /* NO_TRIV_PROTO */
extern char	*ask __(( const char *_(def), const char *_(fmt), ... ));
#ifndef NO_PROCDECL
extern char	*do_ask __(( const char *_(delim), int (*_(d_proc))(int _(c)),
			     const char *_(def), const char *_(fmt), ... )),
#ifdef FILESELECTOR
		*FileSelector __(( const char *_(prompt), const char *_(def),
				   char *_(buf) )),
#endif
#ifdef ARG_EXPAND
		*arg_expand __(( const char *_(name) )),
#endif
		*ask_file __(( const char *_(prompt), const char *_(def),
			       char *_(buf) ));
extern int	yes_or_no_p __(( int _(def), const char *_(fmt), ... ));
#ifdef F_COMPLETION
extern int	bad_extension __(( const char *_(name) )),
		isdir __(( const char *_(name) ));
#endif

/* buf.c */

extern void	initlist __(( Buffer *_(b) )),
		SetBuf __(( Buffer *_(b) ));
#ifndef NO_TRIV_PROTO
extern void	TogMinor __(( int _(bit) )),
		kill_buf __(( Buffer *_(delbuf) )),
		setfname __(( Buffer *_(b), const char *_(name) )),
		set_ino __(( Buffer *_(b) ));
extern int	bufno __(( Buffer *_(buf) ));
#endif /* NO_TRIV_PROTO */
extern const char
		*def_bfile __(( void )),
		*ask_buf __(( const Buffer *_(def) ));

extern const Buffer
		*def_buf __(( const Buffer *_(b) ));

extern Buffer	*getNMbuf __(( void )),
		*buf_exists __(( const char *_(name) )),
		*file_exists __(( const char *_(fname) )),
		*do_find __(( Window *_(w), const char *_(fname), int _(force) )),
		*do_select __(( Window *_(w), const char *_(name) ));

/* c.c */

#ifndef NO_TRIV_PROTO
extern void	mp_error __(( void )),
		FSexpr __(( void ));
extern int	backslashed __(( const char *_(base), const char *_(cp) ));
#endif /* NO_TRIV_PROTO */
extern Bufpos	*m_paren __(( _PI_(char) _(p_type), int _(dir), int _(mode),
			      Bufpos *_(start) )),
#define MP_CAN_STOP	1
#define MP_CAN_MISMATCH	2
		*c_indent __(( int _(incrmt) ));

/* delete.c */

#ifndef NO_TRIV_PROTO
extern void	reg_delete __(( Line *_(l1), int _(char1),
				Line *_(l2), int _(char2) )),
		reg_kill __(( Line *_(line2), int _(char2), int _(dot_moved) ));

extern void	DelReg __(( void )),
		DelNChar __(( void )),
		del_whitespace __(( int _(direction) )),
		CopyRegion __(( void ));
#endif /* NO_TRIV_PROTO */
#endif /* NO_PROCDECL */

/* disp.c */

extern void	DrawMesg __(( int _(abortable) )),
		DoScroll __(( int _(numlines), int _(page) )),
		UpdWindow __(( Window *_(w), int _(start) ));

#define		unbell() do { extern int RingBell; RingBell = NO; } while (0)

#ifndef NO_PROCDECL
#ifndef NO_TRIV_PROTO
extern void	rbell __(( void )),
		redisplay __(( void )),
		ChkWindows __(( Line *_(line1), Line *_(line2) )),
		ClrWindow __(( Window *_(w) )),
		RedrawDisplay __(( void )),
		ClAndRedraw __(( void )),
		NextPage __(( void )),
		UpScroll __(( void )),
		message __(( const char *_(str) )),
		TOstart __(( const char *_(name), int _(auto_newline) )),
		Typeout __(( const char *_(fmt), ... )),
		TOstop __(( void ));
extern int	calc_pos __(( const char *_(cp), int _(c_char) )),
		HorWindow __(( int _(goal), int _(offset), int _(adjust) ));
#endif /* NO_TRIV_PROTO */

/* extend.c */

#ifndef NO_TRIV_PROTO
extern void	DoAutoExec __(( const char *_(newfile), const char *_(oldfile) )),
		DoSetVar __(( const Variable *_(vp) )),
		PutErrInBuf __(( const char *_(bufname), const char *_(filename),
				 int _(lno), const char *_(lbuf) ));
#ifdef CLIOPTIONS
extern void	CliDelete __(( void ));
extern int	CliLookup __(( char *_(opt), int _(argc), char **_(argv) ));
#endif
extern int	addgetc __(( void )),
		match __(( const char * const *_(possible), const char *_(what) )),
		find_binds __(( const data_obj *_(dp), char *_(buf) )),
		complete __(( const char * const _(possible)[], int _(flags),
			      const char *_(fmt), ... )),
		joverc __(( const char *_(file) ));
#endif /* NO_TRIV_PROTO */

/* fkeys.c: getchar in tty.h, FKeyInit in termcap.h */

/* fmt.c */

extern char	*sprint __(( const char *_(fmt), ... ));

	 /* `int' for compatibility with <stdio.h> */
extern int	printf __(( const char *_(fmt), ... )),
		sprintf __(( char *_(str), const char *_(fmt), ... ));
		/* fprintf in io.h */
#ifndef NO_TRIV_PROTO
extern void	s_mess __(( const char *_(fmt), ... )),
		f_mess __(( const char *_(fmt), ... )),
		add_mess __(( const char *_(fmt), ... ));
#endif /* NO_TRIV_PROTO */

/* fp.c */

#ifndef NO_TRIV_PROTO
extern void	flusho __(( void ));
#endif
#endif /* NO_PROCDECL */

/* funcdefs.c */

extern data_obj	*findcom __(( const char *_(prompt) ));

#ifndef NO_PROCDECL
#ifndef NO_TRIV_PROTO
extern void	NonExisting __(( void ));
#endif /* NO_TRIV_PROTO */

/* insert.c */

extern void	Insert __(( int _(c) )),
		AdjWtSpace __(( int _(goal) )),
		lfreereg __(( Line *_(line1), Line *_(line2) ));
#ifndef NO_TRIV_PROTO
extern void	LineInsert __(( int _(num) )),
		QuotChar __(( void )),
		Yank __(( void )),
		n_indent __(( int _(goal) )),
		Blink __(( Line *_(line), int _(col) )),
		ins_str __(( const char *_(str), int _(ok_nl) )),
		lfreelist __(( Line *_(first) ));
extern int	GCchunks __(( void ));
#endif /* NO_TRIV_PROTO */
extern Line	*listput __(( Buffer *_(buf), Line *_(after) )),
		*nbufline __(( void ));
extern Bufpos	*DoYank __(( Line *_(fline), int _(fchar),
			     Line *_(tline), int _(tchar),
			     Line *_(atline), int _(atchar),
			     Buffer *_(whatbuf) ));

/* io.c in io.h mostly */

#ifndef NO_TRIV_PROTO
extern void	lsave __(( void ));
extern int	getline __(( disk_line _(addr), char *_(buf) ));
#endif /* NO_TRIV_PROTO */
#endif /* NO_PROCDECL */
disk_line	putline __(( const char *_(buf) ));
#ifndef NO_PROCDECL
extern char	*pr_name __(( const char *_(file) )),
		*lbptr __(( const Line *_(line) ));

/* iproc in process.h */

/* jove.c */

extern sig_tp	finish __(( int _(code) ));
#ifndef NO_TRIV_PROTO
extern sig_tp	updmode __(( void ));
extern void	dispatch __(( int _(c) )),
		Ungetc __(( int _(c) )),
		confirm __(( const char *_(fmt), ... )),
		Recur __(( void ));
extern int	Peekc __(( void )),
		getch __(( void ));
#endif /* NO_TRIV_PROTO */
#endif /* NO_PROCDECL */
extern void	error __(( const char *_(fmt), ... )),
		complain __(( const char *_(fmt), ... ));

/* macros.c */

extern data_obj	*findmac __(( const char *_(prompt) ));

#ifndef NO_PROCDECL
#ifndef NO_TRIV_PROTO
extern void	fix_macros __(( void )),
		do_macro __(( Macro *_(m) )),
		mac_putc __(( int _(c) ));
extern int	mac_getc __(( void )),
		ModMacs __(( void ));
#endif /* NO_TRIV_PROTO */

/* marks.c */

extern void	DoSetMark __(( Line *_(line), int _(col) )),
		ToMark __(( Mark *_(m) )),
		to_mark __(( void )),
		PtToMark __(( void ));
#ifndef NO_TRIV_PROTO
extern int	del_mark __(( Mark *_(m), Buffer *_(b) ));
extern void	DelMark __(( Mark *_(m) )),
		PopMark __(( void )),
		SetMark __(( void )),
		set_mark __(( void )),
		ShowMark __(( void )),
		DFixMarks __(( Line *_(line1), int _(char1),
			       Line *_(line2), int _(char2) )),
		IFixMarks __(( Line *_(line1), int _(char1),
			       Line *_(line2), int _(char2) ));
#endif /* NO_TRIV_PROTO */
extern Mark	*CurMark __(( void )),
		*MakeMark __(( Line *_(line), int _(column), int _(type) ));

/* misc.c */

#ifndef NO_TRIV_PROTO
extern void	Digit __(( void )),
		DefExp __(( int *_(pval) )),
		put_bufs __(( int _(askp), int _(advance) )),
		Leave __(( void )),
		skip_blanks __(( void )),
		ToIndent __(( void )),
		to_line __(( int _(lineno) )),
		EditParam __(( void (*_(save))(const char *_(file)),
			       void (*_(restore))(const char *_(file)),
			       const char *_(name) ));
extern int	chr_to_int __(( const char *_(cp), int _(base), int _(allints) )),
		schr_to_int __(( const char *_(cp), int _(base), int _(curval) )),
		ask_int __(( const char *_(prompt), int _(base), int _(curval) )),
		exp_ask_int __(( int _(curval) ));
#endif /* NO_TRIV_PROTO */

/* mouse.inc */

#ifdef MOUSE
extern void	mouseon __(( void )),
		mouseoff __(( void )),
		mouseinit __(( void )),
		mousefinish __(( void ));
extern int	mouse __(( void ));
#endif /* MOUSE */

/* move.c */

extern void	ForChar __(( void )),
#ifndef NO_TRIV_PROTO
		Bol __(( void )),
		Eol __(( void )),
		Bof __(( void )),
		Eof __(( void )),
		line_move __(( int _(num) )),
		NextLine __(( void )),
		Eos __(( void )),
#endif /* NO_TRIV_PROTO */
		ForWord __(( void ));
#ifndef NO_TRIV_PROTO
extern int	how_far __(( const char *_(base), int _(col) ));
#endif /* NO_TRIV_PROTO */

/* para.c */
extern void	DoJustify __((Line *_(l1), int _(c1), Line *_(l2), int _(c2),
			      int _(scrunch), int _(indent) ));
#ifndef NO_TRIV_PROTO
extern void	RegJustify __(( void ));
extern int	get_indent __(( Line *_(lp) ));
#endif /* NO_TRIV_PROTO */

/* proc.c in process.h */
/* re.c in re.h */
/* re1.c in re.h */
/* scandir.c in readdir.h */
/* screen.c in screen.h */
/* term.c in termcap.h */

/* tty.c */

#ifndef NO_TRIV_PROTO
extern int	getchar __(( void )),
		charp __(( void )),
#ifdef LOAD_AV
		get_la __(( void )),
#endif
#if unix || vms
		ttsigset __(( int _(state) )),
#endif
		DoSit __(( int _(tenth_sec_delay) )),
		SitFor __(( int _(tenth_sec_delay) ));

extern void	do_sgtty __(( void )),
		ttinit __(( void )),
#if !unix
		ttexit __(( void )),
#endif
		ttsize __(( void )),
		ttyset __(( int _(on) )),

		ResetTerm __(( void )),
		UnsetTerm __(( const char *_(mesg) )),
		tty_reset __(( void ));
#endif /* NO_TRIV_PROTO */

/* util.c */

extern void	DotTo __(( Line *_(line), int _(col) ));
#ifndef NO_TRIV_PROTO
extern void	ExecCmd __(( const data_obj *_(cp) )),
		ExecNow __(( const data_obj *_(cp) )),
		view_mode_check __(( void )),
		init_strokes __(( void )),
		add_stroke __(( int _(c) )),
		repl_strokes __(( const char *_(s) )),
		SetDot __(( Bufpos *_(pos) )),
		ToFirst __(( void )),
		ToLast __(( void )),
		PushPntp __(( Line *_(line) )),
		WordAtDot __(( char *_(buf), int _(size) )),
		tiewind __(( Window *_(w), Buffer *_(bp) )),
		DOTsave __(( Bufpos *_(bp) )),
		modify __(( void )),
		unmodify __(( void )),
		len_error __(( void (*_(how))(const char *, ...) )),
		ins_c __(( _PI_(char) _(c), char *_(buf), int _(atchar),
			   int _(num), int _(max) )),
		linecopy __(( char *_(onto), int _(atchar), const char *_(from) )),
#ifndef byte_copy
		byte_copy __(( const char *_(from), char *_(to), int _(count) )),
		bzero __(( char *_(p), int _(count) )),
		bcmp __(( const char *_(s), const char *_(t), int _(count) )),
#endif
		null_ncpy __(( char *_(to), const char *_(from), int _(n) ));
extern int	waitchar __(( void )),
		pop_stroke __(( void )),
		blnkp __(( const char *_(buf) )),
		LineDist __(( Line *_(nextp), Line *_(endp) )),
		inorder __(( Line *_(nextp), int _(char1),
			     Line *_(endp), int _(char2) )),
		length __(( Line *_(line) )),
		lineno __(( Line *_(line) )),
		ModBufs __(( int _(allp) )),
		ltobuf __(( Line *_(line), char *_(buf) )),
		fixorder __(( Line **_(line1), int *_(char1),
			      Line **_(line2), int *_(char2) )),
		CurRegion __(( Bufpos r[2] )),
		inlist __(( Line *_(first), Line *_(what) )),
		TwoBlank __(( void )),
		min __(( int _(a), int _(b) )),
		max __(( int _(a), int _(b) )),
		numcomp __(( const char *_(s1), const char *_(s2) )),
		casecmp __(( const char *_(str1), const char *_(str2) )),
		casencmp __(( const char *_(str1), const char *_(str2), int _(n) )),
		sindex __(( const char *_(pattern), const char *_(string) ));
#endif /* NO_TRIV_PROTO */
#endif /* NO_PROCDECL */
#ifdef TINY
#   define ExecNow	ExecCmd
#   define min(a,b)	((a)<(b)?(a):(b))
#   define max(a,b)	((a)<(b)?(b):(a))
#endif

extern char	*key_strokes __(( void )),
		*filename __(( const Buffer *_(b) )),
		*itos __(( int _(num) )),
		*lcontents __(( const Line *_(line) )),
		*syserr __(( void )),
		*IOerr __(( const char *_(err), const char *_(file) )),
		*strlwr __(( char *_(str) )),
		*strupr __(( char *_(str) )),
		*appcpy __(( char *_(dest), const char *_(src) ));
#ifndef NO_PROCDECL
extern Line	*lastline __(( Line *_(lp) )),
		*next_line __(( Line *_(line), int _(num) ));
#endif /* NO_PROCDECL */
#define		prev_line(line, num)	next_line(line, -(num))

#ifdef TINY
/* This amusing bullshit is to accommodate wimpy pdp11's instruction space.
   In fact it is so cramped that we have to factor the ctime() call out
   to a separate program.  (the get_proc_line() comes (almost) for free,
   since we need it anyway to determine the cwd.)  This does not have a
   serious impact on overall performance since the "HH:MM" string needed for
   the modeline's %t format is cached, and, in effect, get_ctime() is called
   just once per minute. */
#   if unix
extern char	*get_proc_line __(( const char *_(process) ));
#	define	GET_PROC_LINE
#	define	get_ctime()	get_proc_line(ctimeProg)
#   endif
#endif
#ifndef get_ctime
extern char	*get_ctime __(( void ));
#endif

/* vars.c */

extern data_obj	*findvar __(( const char *_(prompt) ));

/* wind.c */

#ifndef NO_PROCDECL
#ifndef NO_TRIV_PROTO
extern void	SetTop __(( Window *_(w), Line *_(line) )),
		SetWind __(( Window *_(new) )),
		del_wind __(( Window *_(wp) )),
		winit __(( void )),
		CentWind __(( Window *_(w) )),
		CalcWind __(( Window *_(w) )),
		NextWindow __(( void )),
		pop_wind __(( const char *_(name), int _(clobber), int _(btype) )),
#ifdef RESHAPING
		win_reshape __(( void )),
#endif
		WindSize __(( Window *_(w), int _(inc) ));
extern int	FLine __(( const Window *_(w) )),
		in_window __(( Window *_(w), Line *_(line)  ));
#endif /* NO_TRIV_PROTO */

extern Window	*windbp __(( const Buffer *_(bp) )),
		*div_wind __(( Window *_(w), int _(n) ));

#endif /* NO_PROCDECL */

#endif /* NOT_JOVE */

/* Debugging aids. */

#ifdef DEBUG	/* request assertions. */
#   define ASSERTS
#   define CHECKS
#endif

#ifdef ASSERTS
#   define ASSERT_FMT	"BUG: (%s, line %d) assertion \"%s\" failed."
#   if _ANSI_CPP_
#	define ASSERT(x) ((x)||(complain(ASSERT_FMT,__FILE__,__LINE__,#x),0))
#   else
#	define ASSERT(x) ((x)||(complain(ASSERT_FMT,__FILE__,__LINE__,"x"),0))
#   endif
#else
#   define ASSERT(x)
#endif

#ifdef CHECKS
#   define CHECK(call, fail)	do if ((call) < 0) { fail; } while (0)
#else
#   define CHECK(call, fail)	(call)
#endif

#endif /* _JOVE_H_ */

#undef Extern

/*======================================================================
 * $Log: jove.h,v $
 * Revision 14.32.0.11  1994/06/11  21:35:54  tom
 * (view_mode_check,CurRegion): new function declarations;
 * (Buffer): change typeof(b_statsize) size_t -> long (for DOS).
 *
 * Revision 14.32.0.8  1993/11/11  05:54:16  tom
 * (pop_stroke): new prototype.
 *
 * Revision 14.32  1993/06/21  21:52:29  tom
 * (win_reshape): update prototype.
 *
 * Revision 14.31  1993/02/16  17:57:30  tom
 * replace TINY with NO_TRIV_PROTO for clarity of intent; simplify handling
 * of get_proc_line() for get_ctime; remove (void) casts.
 *
 * Revision 14.30  1993/02/05  14:53:19  tom
 * cleanup whitespace; add structured DEBUG/ASSERT/CHECK macros; allow
 * external definition of LBSIZE, FILESIZE; add BITSET_{OP,SIZE} macros;
 * add Proc{Def,Arg}Fmt[] strings; add b_flink_p(), b_foutdated_p() macros.
 *
 * Revision 14.28  1992/10/24  01:24:20  tom
 * convert to "port{ansi,defs}.h" conventions; move some system-dependencies
 * to "tune.h".
 *
 * Revision 14.27  1992/09/22  02:03:53  tom
 * add `b_statsize' field to struct Buffer; prepare struct Process to per-
 * process two-way pipes as an alternative to ptys;  some minor cleanup.
 *
 * Revision 14.26  1992/08/26  23:56:43  tom
 * some typographic changes; add `mf_interactive' field to Macro; add DEF_REF
 * macro for future use; add RCS directives.
 *
 */
