/************************************************************************
 * 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.						*
 ************************************************************************/

/* Termcap/terminfo definitions */

#ifndef _TERMCAP_H_
#define _TERMCAP_H_

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

#ifdef Extern
RCS_H(termcap, "$Id: termcap.h,v 14.32.0.7 1993/10/29 02:43:04 tom Exp tom $")
#endif

#ifdef VMS_TERMCAP
#   define tgetent	vms_tgetent
#   define tgetflag	vms_tgetflag
#   define tgetstr	vms_tgetstr
#   define tgetnum	vms_tgetnum
#   define tgoto	vms_tgoto
#endif

/* The next trick allows us to use this file for both definition (in term.c)
   as external declaration (all others) */

#ifdef Extern
#   ifndef VARS_DEFINED_IN_TERMCAP
	/* Some termcap libraries define BC, UP, PC, and ospeed themselves,
	   (most) others expect the application to define them. */
#	define TCPExtern	Extern
#   endif
#   define is(initval)	= {initval}
#else
#   define is(initval)
#   define Extern	extern
#endif

#ifndef TCPExtern
#   define TCPExtern	extern
#endif

#ifdef TGETSTR_BUG	/* oh dear! */
#   define tgetstr	Jtgetstr
#endif

/* Max. size of tty buffer */

#if ((TTBUFSIZ - 0) < 512)	/* so can be defined elsewhere */
#   undef TTBUFSIZ
#   define TTBUFSIZ	512
#endif

#ifdef TERMCAP
#   if (TERMCAP-0 >= 0)		/* tiny compiler kludge. */
Extern const char
	*LE,	/* Move cursor left. */
	*BL,	/* audible bell */
	*CE,	/* Clear to end of line */
	*CL,	/* Clear screen */
	*CM,	/* The cursor motion string */
	*KE,	/* Keypad mode end */
	*KS,	/* Keypad mode start */
	*MM,	/* meta key mode on */
	*MO,	/* meta key mode off */
	*SE,	/* End standout */
	*SO,	/* Start standout */
	*TE,	/* Cursor addressing end */
	*TI,	/* Cursor addressing start */
	*VB,	/* visible bell */
	*VE,	/* Visual end */
	*VI,	/* cursor invisible */
	*VS,	/* Visual start */
#ifdef ANSICODES
	*SP,	/* Send cursor position */
#endif
#ifdef CURSOPT
	*HO,	/* Home cursor */
	*LL,	/* Last line, first column */
#endif
#ifndef FAST_IDLINE
	*AL,	/* Addline (insert line) */
	*M_AL,	/* Insert line with arg */
	*DL,	/* Delete line */
	*M_DL,	/* Delete line with arg */
	*SF,	/* Scroll forward */
	*M_SF,	/* Scroll forward with arg */
	*SR,	/* Scroll reverse */
	*M_SR,	/* Scroll reverse with arg */
	*CS,	/* scrolling region (vt100) */
#endif
#ifdef ID_CHAR
	*IC,	/* Insert char */
	*M_IC,	/* Insert char with arg */
	*DC,	/* Delete char */
	*M_DC,	/* Delete char with arg */
	*IM,	/* Insert mode */
	*EI,	/* End insert mode */
	*IP,	/* insert pad after character inserted */
#endif
#ifdef LSRHS
	*RS,	/* reverse video start */
	*RE,	/* reverse video end */
#endif
#if (HIGHLIGHT)
	*BO,	/* Start bold */
	*MR,	/* Start reverse video */
	*ME,	/* End all attributes */
#endif
#ifdef COLOR
	*COlor,	/* Set text + background color. (TRH) */
	*CObg,	/* Set background color. (SCO) */
	*COfg,	/* Set foreground color. (SCO) */
	*COpair,	/* Set color pair, for HP-like terminals. (SCO) */
	*CObgmap,	/* Remap background color description. (TRH) */
	*COfgmap,	/* Remap foreground color description. (TRH) */
	*COorig,	/* Set original color pair (SCO) */
#endif
	*lPC;	/* pad character string */
#   endif
#endif /* TERMCAP */

Extern int
	ILI;		/* number of internal lines */
extern int
	LI,		/* number of lines */
	CO;		/* number of columns */

#ifdef TERMCAP

Extern int
#ifdef DUMBTERMS
	UL,		/* underscores don't replace chars already on screen */
	Hz,		/* (*not* HZ!) hazeltines can't display '~' */
#endif
#ifdef ID_CHAR
 	MI,		/* okay to move while in insert mode */
#endif
	SG,		/* number of magic cookies left by SO and SE */
	XS,		/* whether standout mode is braindamaged */

	AM,		/* terminal has auto-margins enabled? */
	XN;		/* ignore newline at right-margin (vt100,concept) */
Extern int
#ifdef CURSOPT
	TABS,		/* whether we are in tabs mode */
	HOlen is(1000),	/* length of Home string */
	LLlen is(1000),	/* length of lower string */
#endif
	UPlen is(1000);	/* length of the UP string */

#else /* !TERMCAP */

/* we hardwire the termcap capabilities for micros as constants so that the
   compiler has a chance to remove dead code. */

#   ifdef ATARIST			/* vt52 emulation */
#	define LE	"\b"
#	define BL	"\7"
#	define CE	"\033K"
#	define CL	"\033E"
	Extern char CM[] is("\033Yyx");	/* Yes this is a cheat! */
#	define HO	"\033H"
#	define KE	NULL
#	define KS	NULL
#	define LL	NULL
#	define MM	NULL
#	define MO	NULL
#	define SE	"\033q"
#	define SO	"\033p"
#	define TE	"\033v"
#	define TI	"\033w"	/* i.e. !am */
#	define VE	"\033f"	/* turn off cursor on exit */
#	define VI	"\033f"
#	define VS	"\033e"
#	define VB	NULL
#ifdef ID_CHAR
#	define IC	NULL
#	define M_IC	NULL
#	define DC	NULL
#	define M_DC	NULL
#	define IM	NULL
#	define EI	NULL
#	define IP	NULL
#endif
#	define AL	"\033L"
#	define M_AL	NULL
#	define DL	"\033M"
#	define M_DL	NULL
#	define SF	"\033I"
#	define M_SF	NULL
#	define SR	"\n"
#	define M_SR	NULL
#	define CS	NULL
#ifdef ANSICODES
#	define SP	NULL
#endif
#ifdef LSRHS
#	define RS	NULL
#	define RE	NULL
#endif
#if (HIGHLIGHT)
#	define BO	SO
#	define ME	SE
#endif
#ifdef COLOR
#	define COorig	NULL
#endif

#ifdef DUMB_TERMS
#	define UL	0
#endif
#ifdef ID_CHAR
#	define MI	0
#endif
#	define SG	0
#	define XS	0

#	define AM	0
#	define XN	0

#ifdef CURSOPT
#	define TABS	0
#	define HOlen	2
#	define LLlen	1000
#endif
#	define UPlen	2

#	define BC	NULL
#	define UP	"\033A"
#	define PC	'\0'

#	define tgoto(cm,c,l)	(cm[2]=(l)+' ', cm[3]=(c)+' ', cm)

#   else /* !ATARIST, i.e., MSDOS or MAC */	/* ANSI.SYS emulation */

#	define LE	"\b"
#	define BL	"\7"
#	define CE	"\033[K"
#	define CL	"\033[2J"
#	define CM	"\033[%d;%dH"	/* Yes this is a cheat! */
#	define KE	NULL
#	define KS	NULL
#	define MM	NULL
#	define MO	NULL
#	define SE	"\033[m"
#	define SO	"\033[7m"
#	define TE	"\033[?7h"
#	define TI	"\033[?7l"	/* i.e. !am */
#	define VB	NULL
#ifdef VIDEO
#	define VE	"\033[?25h"
#	define VS	VE
#	define VI	"\033[?25l"
#else
#	define VE	NULL
#	define VI	NULL
#	define VS	NULL
#endif
#ifdef ANSICODES
#	define SP	NULL
#endif
#ifdef CURSOPT
#	define HO	"\033[H"
#	define LL	NULL
#endif
#ifdef ID_CHAR
#	define IC	NULL
#	define M_IC	NULL
#	define DC	NULL
#	define M_DC	NULL
#	define IM	NULL
#	define EI	NULL
#	define IP	NULL
#endif
#ifndef FAST_IDLINE
#	define AL	NULL
#	define M_AL	NULL
#	define DL	NULL
#	define M_DL	NULL
#	define SF	"\n"
#	define M_SF	NULL
#	define SR	NULL
#	define M_SR	NULL
#	define CS	NULL
#endif
#ifdef LSRHS
#	define RS	NULL
#	define RE	NULL
#endif
#if (HIGHLIGHT)
#	define BO	"\033[1m"
#	define ME	"\033[m"
#endif
#ifdef COLOR
#	define COorig	NULL
#endif

#ifdef DUMB_TERMS
#	define UL	0
#endif
#ifdef ID_CHAR
#	define MI	0
#endif
#	define SG	0
#	define XS	0

#	define AM	0
#	define XN	0

#ifdef CURSOPT
#	define TABS	0
#	define HOlen	3
#	define LLlen	1000
#endif
#	define UPlen	3

#	define BC	NULL
#	define UP	"\33[A"
#	define PC	'\0'

	Extern  char		CMbuf[12];
#	define tgoto(cm,c,l)	(sprintf(CMbuf, cm, (l)+1, (c)+1), CMbuf)

#	ifdef MSDOS
#	    ifndef VIDEO
#		define ColorStandoutGlitch	1
#	    endif
#	endif

#   endif /* !ATARIST */

#   define putpad(cap,lines)	putp(cap)

#endif /* TERMCAP */

#ifdef TERMCAP		/* these are needed by some termcap packages */

TCPExtern const char
	*BC,	/* Backspace if not '\b' (OBSOLETE!) */
	*UP;	/* Scroll reverse, or up */
TCPExtern char
	PC;	/* pad character */

TCPExtern short	ospeed;

extern char	*tgoto __(( const char *_(cm), int _(col), int _(line) )),
		*tgetstr __(( const char *_(id), char **_(bufp) ));
#   ifndef NO_TRIV_PROTO
extern int	tgetflag __(( const char *_(id) )),
		tgetnum __(( const char *_(id) )),
		tgetent __(( const char *_(tname), char _(buf)[2048] ));
extern void	tputs __(( const char *_(cap), int _(naffected),
			   int (*_(outc))(int _(c)) ));
#   endif /* NO_TRIV_PROTO */
#endif /* TERMCAP */

/* term.c */

#ifndef NO_TRIV_PROTO
#   ifdef VARTERM
extern int	set_tdim __(( int _(how), int _(which) ));
#   endif
extern void	getTERM __(( void )),
#ifndef putpad	/* may be #defined above */
		putpad __(( const char *_(str), int _(lines) )),
#endif
		putp __(( const char *_(str) )),
		Nputpad __(( const char *_(single), const char *_(multi),
			     int _(num), int _(naffected) )),
		settout __(( char *_(ttbuf) )),

/* fkeys.c -- initialization routine */

#ifdef FUNCKEYS
#   ifdef TERMCAP
		FKeyInit __(( void )),
#   endif
#endif

/* screen.c -- initialization routines */

#ifdef ID_CHAR
		disp_opt_init __(( void )),
#endif
#ifdef COLOR
#   ifdef TERMCAP
		COLOR_setup __(( const char *_(termname) )),
#   endif
#endif
		IDline_setup __(( const char *_(termname) ));

/* from tty.c; fkeys needs this */
#ifdef FUNCKEYS
#   ifdef TERMCAP
extern int	rawchar __(( int _(time_out) ));
#   endif
#endif

#endif /* NO_TRIV_PROTO */

/* COLOR stuff moved to screen.h */

#endif /* _TERMCAP_H_ */

#undef Extern
#undef Const
#undef is


/*======================================================================
 * $Log: termcap.h,v $
 * Revision 14.32.0.7  1993/10/29  02:43:04  tom
 * ColorStandoutGlitch: define for MSDOS, non-VIDEO.
 *
 * Revision 14.32.0.1  1993/07/07  13:57:23  tom
 * fix Atari/DOS botches.
 *
 * Revision 14.32  1993/06/22  03:56:04  tom
 * incorporate new features of term.c.
 *
 * Revision 14.31  1993/02/15  03:04:41  tom
 * replace TINY with NO_TRIV_PROTO for clarity of intent.
 *
 * Revision 14.30  1993/01/26  18:43:06  tom
 * cleanup whitespace.
 *
 * Revision 14.28  1992/10/02  02:29:52  tom
 * add color-remap support through (non-standard) termcapabilities Mb, Mf.
 *
 * Revision 14.26  1992/08/26  23:56:49  tom
 * add RCS directives.
 *
 */
