186d7f5d3SJohn Marino /* $NetBSD: tt.h,v 1.9 2009/04/14 08:50:06 lukem Exp $ */ 286d7f5d3SJohn Marino 386d7f5d3SJohn Marino /* 486d7f5d3SJohn Marino * Copyright (c) 1983, 1993 586d7f5d3SJohn Marino * The Regents of the University of California. All rights reserved. 686d7f5d3SJohn Marino * 786d7f5d3SJohn Marino * This code is derived from software contributed to Berkeley by 886d7f5d3SJohn Marino * Edward Wang at The University of California, Berkeley. 986d7f5d3SJohn Marino * 1086d7f5d3SJohn Marino * Redistribution and use in source and binary forms, with or without 1186d7f5d3SJohn Marino * modification, are permitted provided that the following conditions 1286d7f5d3SJohn Marino * are met: 1386d7f5d3SJohn Marino * 1. Redistributions of source code must retain the above copyright 1486d7f5d3SJohn Marino * notice, this list of conditions and the following disclaimer. 1586d7f5d3SJohn Marino * 2. Redistributions in binary form must reproduce the above copyright 1686d7f5d3SJohn Marino * notice, this list of conditions and the following disclaimer in the 1786d7f5d3SJohn Marino * documentation and/or other materials provided with the distribution. 1886d7f5d3SJohn Marino * 3. Neither the name of the University nor the names of its contributors 1986d7f5d3SJohn Marino * may be used to endorse or promote products derived from this software 2086d7f5d3SJohn Marino * without specific prior written permission. 2186d7f5d3SJohn Marino * 2286d7f5d3SJohn Marino * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 2386d7f5d3SJohn Marino * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2486d7f5d3SJohn Marino * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2586d7f5d3SJohn Marino * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2686d7f5d3SJohn Marino * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2786d7f5d3SJohn Marino * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2886d7f5d3SJohn Marino * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2986d7f5d3SJohn Marino * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 3086d7f5d3SJohn Marino * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3186d7f5d3SJohn Marino * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3286d7f5d3SJohn Marino * SUCH DAMAGE. 3386d7f5d3SJohn Marino * 3486d7f5d3SJohn Marino * @(#)tt.h 8.1 (Berkeley) 6/6/93 3586d7f5d3SJohn Marino */ 3686d7f5d3SJohn Marino 3786d7f5d3SJohn Marino #include <unistd.h> 3886d7f5d3SJohn Marino 3986d7f5d3SJohn Marino #ifndef EXTERN 4086d7f5d3SJohn Marino #define EXTERN extern 4186d7f5d3SJohn Marino #endif 4286d7f5d3SJohn Marino 4386d7f5d3SJohn Marino /* 4486d7f5d3SJohn Marino * Interface structure for the terminal drivers. 4586d7f5d3SJohn Marino */ 4686d7f5d3SJohn Marino struct tt { 4786d7f5d3SJohn Marino /* startup and cleanup */ 4886d7f5d3SJohn Marino void (*tt_start)(void); 4986d7f5d3SJohn Marino void (*tt_reset)(void); 5086d7f5d3SJohn Marino void (*tt_end)(void); 5186d7f5d3SJohn Marino 5286d7f5d3SJohn Marino /* terminal functions */ 5386d7f5d3SJohn Marino void (*tt_move)(int, int); 5486d7f5d3SJohn Marino void (*tt_insline)(int); 5586d7f5d3SJohn Marino void (*tt_delline)(int); 5686d7f5d3SJohn Marino void (*tt_inschar)(char); 5786d7f5d3SJohn Marino void (*tt_insspace)(int); 5886d7f5d3SJohn Marino void (*tt_delchar)(int); 5986d7f5d3SJohn Marino void (*tt_write)(const char *, int); /* write a whole block */ 6086d7f5d3SJohn Marino void (*tt_putc)(char); /* write one character */ 6186d7f5d3SJohn Marino void (*tt_clreol)(void); 6286d7f5d3SJohn Marino void (*tt_clreos)(void); 6386d7f5d3SJohn Marino void (*tt_clear)(void); 6486d7f5d3SJohn Marino void (*tt_scroll_down)(int); 6586d7f5d3SJohn Marino void (*tt_scroll_up)(int); 6686d7f5d3SJohn Marino void (*tt_setscroll)(int, int);/* set scrolling region */ 6786d7f5d3SJohn Marino void (*tt_setmodes)(int); /* set display modes */ 6886d7f5d3SJohn Marino void (*tt_set_token)(int, char *, int); 6986d7f5d3SJohn Marino /* define a token */ 7086d7f5d3SJohn Marino void (*tt_put_token)(int, const char *, int); 7186d7f5d3SJohn Marino /* refer to a defined token */ 7286d7f5d3SJohn Marino void (*tt_compress)(int); /* begin, end compression */ 7386d7f5d3SJohn Marino void (*tt_checksum)(char *, int); 7486d7f5d3SJohn Marino /* compute checksum */ 7586d7f5d3SJohn Marino void (*tt_checkpoint)(void); /* checkpoint protocol */ 7686d7f5d3SJohn Marino int (*tt_rint)(char *, int); /* input processing */ 7786d7f5d3SJohn Marino 7886d7f5d3SJohn Marino /* internal variables */ 7986d7f5d3SJohn Marino char tt_modes; /* the current display modes */ 8086d7f5d3SJohn Marino char tt_nmodes; /* the new modes for next write */ 8186d7f5d3SJohn Marino char tt_insert; /* currently in insert mode */ 8286d7f5d3SJohn Marino int tt_row; /* cursor row */ 8386d7f5d3SJohn Marino int tt_col; /* cursor column */ 8486d7f5d3SJohn Marino int tt_scroll_top; /* top of scrolling region */ 8586d7f5d3SJohn Marino int tt_scroll_bot; /* bottom of scrolling region */ 8686d7f5d3SJohn Marino 8786d7f5d3SJohn Marino /* terminal info */ 8886d7f5d3SJohn Marino int tt_nrow; /* number of display rows */ 8986d7f5d3SJohn Marino int tt_ncol; /* number of display columns */ 9086d7f5d3SJohn Marino char tt_availmodes; /* the display modes supported */ 9186d7f5d3SJohn Marino char tt_wrap; /* has auto wrap around */ 9286d7f5d3SJohn Marino char tt_retain; /* can retain below (db flag) */ 9386d7f5d3SJohn Marino short tt_padc; /* the pad character */ 9486d7f5d3SJohn Marino int tt_ntoken; /* number of compression tokens */ 9586d7f5d3SJohn Marino int tt_token_min; /* minimun token size */ 9686d7f5d3SJohn Marino int tt_token_max; /* maximum token size */ 9786d7f5d3SJohn Marino int tt_set_token_cost; /* cost in addition to string */ 9886d7f5d3SJohn Marino int tt_put_token_cost; /* constant cost */ 9986d7f5d3SJohn Marino int tt_ack; /* checkpoint ack-nack flag */ 10086d7f5d3SJohn Marino 10186d7f5d3SJohn Marino /* the frame characters */ 10286d7f5d3SJohn Marino short *tt_frame; 10386d7f5d3SJohn Marino 10486d7f5d3SJohn Marino /* ttflush() hook */ 10586d7f5d3SJohn Marino void (*tt_flush)(void); 10686d7f5d3SJohn Marino }; 10786d7f5d3SJohn Marino EXTERN struct tt tt; 10886d7f5d3SJohn Marino 10986d7f5d3SJohn Marino /* 11086d7f5d3SJohn Marino * tt_padc is used by the compression routine. 11186d7f5d3SJohn Marino * It is a short to allow the driver to indicate that there is no padding. 11286d7f5d3SJohn Marino */ 11386d7f5d3SJohn Marino #define TT_PADC_NONE 0x100 11486d7f5d3SJohn Marino 11586d7f5d3SJohn Marino /* 11686d7f5d3SJohn Marino * List of terminal drivers. 11786d7f5d3SJohn Marino */ 11886d7f5d3SJohn Marino struct tt_tab { 11986d7f5d3SJohn Marino const char *tt_name; 12086d7f5d3SJohn Marino int tt_len; 12186d7f5d3SJohn Marino int (*tt_func)(void); 12286d7f5d3SJohn Marino }; 12386d7f5d3SJohn Marino EXTERN struct tt_tab tt_tab[]; 12486d7f5d3SJohn Marino 12586d7f5d3SJohn Marino /* 12686d7f5d3SJohn Marino * Clean interface to termcap routines. 12786d7f5d3SJohn Marino * Too may t's. 12886d7f5d3SJohn Marino */ 12986d7f5d3SJohn Marino EXTERN char tt_strings[1024]; /* string buffer */ 13086d7f5d3SJohn Marino EXTERN char *tt_strp; /* pointer for it */ 13186d7f5d3SJohn Marino 13286d7f5d3SJohn Marino struct tt_str { 13386d7f5d3SJohn Marino const char *ts_str; 13486d7f5d3SJohn Marino int ts_n; 13586d7f5d3SJohn Marino }; 13686d7f5d3SJohn Marino 13786d7f5d3SJohn Marino struct tt_str *tttgetstr(const char *); 13886d7f5d3SJohn Marino struct tt_str *ttxgetstr(const char *); /* tgetstr() and expand delays */ 13986d7f5d3SJohn Marino 14086d7f5d3SJohn Marino int tt_f100(void); 14186d7f5d3SJohn Marino int tt_generic(void); 14286d7f5d3SJohn Marino int tt_h19(void); 14386d7f5d3SJohn Marino int tt_h29(void); 14486d7f5d3SJohn Marino int tt_tvi925(void); 14586d7f5d3SJohn Marino int tt_wyse60(void); 14686d7f5d3SJohn Marino int tt_wyse75(void); 14786d7f5d3SJohn Marino int tt_zapple(void); 14886d7f5d3SJohn Marino int tt_zentec(void); 14986d7f5d3SJohn Marino void ttflush(void); 15086d7f5d3SJohn Marino int ttinit(void); 15186d7f5d3SJohn Marino void ttpgoto(struct tt_str *, int, int, int); 15286d7f5d3SJohn Marino void ttputs(const char *); 15386d7f5d3SJohn Marino int ttstrcmp(struct tt_str *, struct tt_str *); 15486d7f5d3SJohn Marino void tttgoto(struct tt_str *, int, int); 15586d7f5d3SJohn Marino int tttputc(int); 15686d7f5d3SJohn Marino void ttwrite(const char *, int); 15786d7f5d3SJohn Marino int ttxputc(int); 15886d7f5d3SJohn Marino 15986d7f5d3SJohn Marino #define tttputs(s, n) tputs((s)->ts_str, (n), tttputc) 16086d7f5d3SJohn Marino #define ttxputs(s) ttwrite((s)->ts_str, (s)->ts_n) 16186d7f5d3SJohn Marino 16286d7f5d3SJohn Marino /* 16386d7f5d3SJohn Marino * Buffered output without stdio. 16486d7f5d3SJohn Marino * These variables have different meanings from the ww_ob* variables. 16586d7f5d3SJohn Marino * But I'm too lazy to think up different names. 16686d7f5d3SJohn Marino */ 16786d7f5d3SJohn Marino EXTERN char *tt_ob; 16886d7f5d3SJohn Marino EXTERN char *tt_obp; 16986d7f5d3SJohn Marino EXTERN char *tt_obe; 17086d7f5d3SJohn Marino #define ttputc(c) (tt_obp < tt_obe ? (*tt_obp++ = (c)) \ 17186d7f5d3SJohn Marino : (ttflush(), *tt_obp++ = (c))) 17286d7f5d3SJohn Marino 17386d7f5d3SJohn Marino /* 17486d7f5d3SJohn Marino * Convenience macros for the drivers 17586d7f5d3SJohn Marino * They require char.h 17686d7f5d3SJohn Marino */ 17786d7f5d3SJohn Marino #define ttctrl(c) ttputc(ctrl(c)) 17886d7f5d3SJohn Marino #define ttesc(c) (ttctrl('['), ttputc(c)) 179