1*84d9c625SLionel Sambuc /* $NetBSD: gs.h,v 1.3 2013/11/25 22:43:46 christos Exp $ */ 2*84d9c625SLionel Sambuc /*- 3*84d9c625SLionel Sambuc * Copyright (c) 1993, 1994 4*84d9c625SLionel Sambuc * The Regents of the University of California. All rights reserved. 5*84d9c625SLionel Sambuc * Copyright (c) 1993, 1994, 1995, 1996 6*84d9c625SLionel Sambuc * Keith Bostic. All rights reserved. 7*84d9c625SLionel Sambuc * 8*84d9c625SLionel Sambuc * See the LICENSE file for redistribution information. 9*84d9c625SLionel Sambuc * 10*84d9c625SLionel Sambuc * Id: gs.h,v 10.55 2001/11/01 10:28:25 skimo Exp (Berkeley) Date: 2001/11/01 10:28:25 11*84d9c625SLionel Sambuc */ 12*84d9c625SLionel Sambuc 13*84d9c625SLionel Sambuc #define TEMPORARY_FILE_STRING "/tmp" /* Default temporary file name. */ 14*84d9c625SLionel Sambuc 15*84d9c625SLionel Sambuc /* 16*84d9c625SLionel Sambuc * File reference structure (FREF). The structure contains the name of the 17*84d9c625SLionel Sambuc * file, along with the information that follows the name. 18*84d9c625SLionel Sambuc * 19*84d9c625SLionel Sambuc * !!! 20*84d9c625SLionel Sambuc * The read-only bit follows the file name, not the file itself. 21*84d9c625SLionel Sambuc */ 22*84d9c625SLionel Sambuc struct _fref { 23*84d9c625SLionel Sambuc TAILQ_ENTRY(_fref) q; /* Linked list of file references. */ 24*84d9c625SLionel Sambuc char *name; /* File name. */ 25*84d9c625SLionel Sambuc char *tname; /* Backing temporary file name. */ 26*84d9c625SLionel Sambuc 27*84d9c625SLionel Sambuc db_recno_t lno; /* 1-N: file cursor line. */ 28*84d9c625SLionel Sambuc size_t cno; /* 0-N: file cursor column. */ 29*84d9c625SLionel Sambuc 30*84d9c625SLionel Sambuc #define FR_CURSORSET 0x0001 /* If lno/cno values valid. */ 31*84d9c625SLionel Sambuc #define FR_DONTDELETE 0x0002 /* Don't delete the temporary file. */ 32*84d9c625SLionel Sambuc #define FR_EXNAMED 0x0004 /* Read/write renamed the file. */ 33*84d9c625SLionel Sambuc #define FR_NAMECHANGE 0x0008 /* If the name changed. */ 34*84d9c625SLionel Sambuc #define FR_NEWFILE 0x0010 /* File doesn't really exist yet. */ 35*84d9c625SLionel Sambuc #define FR_RECOVER 0x0020 /* File is being recovered. */ 36*84d9c625SLionel Sambuc #define FR_TMPEXIT 0x0040 /* Modified temporary file, no exit. */ 37*84d9c625SLionel Sambuc #define FR_TMPFILE 0x0080 /* If file has no name. */ 38*84d9c625SLionel Sambuc #define FR_UNLOCKED 0x0100 /* File couldn't be locked. */ 39*84d9c625SLionel Sambuc u_int16_t flags; 40*84d9c625SLionel Sambuc }; 41*84d9c625SLionel Sambuc 42*84d9c625SLionel Sambuc /* Action arguments to scr_exadjust(). */ 43*84d9c625SLionel Sambuc typedef enum { EX_TERM_CE, EX_TERM_SCROLL } exadj_t; 44*84d9c625SLionel Sambuc 45*84d9c625SLionel Sambuc /* Screen attribute arguments to scr_attr(). */ 46*84d9c625SLionel Sambuc typedef enum { SA_ALTERNATE, SA_INVERSE } scr_attr_t; 47*84d9c625SLionel Sambuc 48*84d9c625SLionel Sambuc /* Key type arguments to scr_keyval(). */ 49*84d9c625SLionel Sambuc typedef enum { KEY_VEOF, KEY_VERASE, KEY_VKILL, KEY_VWERASE } scr_keyval_t; 50*84d9c625SLionel Sambuc 51*84d9c625SLionel Sambuc /* 52*84d9c625SLionel Sambuc * GS: 53*84d9c625SLionel Sambuc * 54*84d9c625SLionel Sambuc * Structure that describes global state of the running program. 55*84d9c625SLionel Sambuc */ 56*84d9c625SLionel Sambuc struct _gs { 57*84d9c625SLionel Sambuc char *progname; /* Programe name. */ 58*84d9c625SLionel Sambuc 59*84d9c625SLionel Sambuc int id; /* Last allocated screen id. */ 60*84d9c625SLionel Sambuc TAILQ_HEAD(_dqh, _win) dq; /* Displayed windows. */ 61*84d9c625SLionel Sambuc TAILQ_HEAD(_hqh, _scr) hq; /* Hidden screens. */ 62*84d9c625SLionel Sambuc 63*84d9c625SLionel Sambuc void *perl_interp; /* Perl interpreter. */ 64*84d9c625SLionel Sambuc void *tcl_interp; /* Tcl_Interp *: Tcl interpreter. */ 65*84d9c625SLionel Sambuc 66*84d9c625SLionel Sambuc void *cl_private; /* Curses support private area. */ 67*84d9c625SLionel Sambuc void *tk_private; /* Tk/Tcl support private area. */ 68*84d9c625SLionel Sambuc 69*84d9c625SLionel Sambuc /* File references. */ 70*84d9c625SLionel Sambuc TAILQ_HEAD(_frefh, _fref) frefq; 71*84d9c625SLionel Sambuc /* File structures. */ 72*84d9c625SLionel Sambuc TAILQ_HEAD(_exfh, _exf) exfq; 73*84d9c625SLionel Sambuc 74*84d9c625SLionel Sambuc #define GO_COLUMNS 0 /* Global options: columns. */ 75*84d9c625SLionel Sambuc #define GO_LINES 1 /* Global options: lines. */ 76*84d9c625SLionel Sambuc #define GO_SECURE 2 /* Global options: secure. */ 77*84d9c625SLionel Sambuc #define GO_TERM 3 /* Global options: terminal type. */ 78*84d9c625SLionel Sambuc OPTION opts[GO_TERM + 1]; 79*84d9c625SLionel Sambuc 80*84d9c625SLionel Sambuc DB *msg; /* Message catalog DB. */ 81*84d9c625SLionel Sambuc MSGH msgq; /* User message list. */ 82*84d9c625SLionel Sambuc #define DEFAULT_NOPRINT '\1' /* Emergency non-printable character. */ 83*84d9c625SLionel Sambuc int noprint; /* Cached, unprintable character. */ 84*84d9c625SLionel Sambuc 85*84d9c625SLionel Sambuc char *c_option; /* Ex initial, command-line command. */ 86*84d9c625SLionel Sambuc 87*84d9c625SLionel Sambuc #ifdef DEBUG 88*84d9c625SLionel Sambuc FILE *tracefp; /* Trace file pointer. */ 89*84d9c625SLionel Sambuc #endif 90*84d9c625SLionel Sambuc 91*84d9c625SLionel Sambuc #define MAX_BIT_SEQ 0x7f /* Max + 1 fast check character. */ 92*84d9c625SLionel Sambuc LIST_HEAD(_seqh, _seq) seqq; /* Linked list of maps, abbrevs. */ 93*84d9c625SLionel Sambuc bitstr_t bit_decl(seqb, MAX_BIT_SEQ + 1); 94*84d9c625SLionel Sambuc 95*84d9c625SLionel Sambuc #define MAX_FAST_KEY 0xff /* Max fast check character.*/ 96*84d9c625SLionel Sambuc #define KEY_LEN(sp, ch) \ 97*84d9c625SLionel Sambuc (((ch) & ~MAX_FAST_KEY) == 0 ? \ 98*84d9c625SLionel Sambuc sp->gp->cname[(unsigned char)ch].len : v_key_len(sp, ch)) 99*84d9c625SLionel Sambuc #define KEY_NAME(sp, ch) \ 100*84d9c625SLionel Sambuc (((ch) & ~MAX_FAST_KEY) == 0 ? \ 101*84d9c625SLionel Sambuc sp->gp->cname[(unsigned char)ch].name : v_key_name(sp, ch)) 102*84d9c625SLionel Sambuc struct { 103*84d9c625SLionel Sambuc u_char name[MAX_CHARACTER_COLUMNS + 1]; 104*84d9c625SLionel Sambuc u_int8_t len; 105*84d9c625SLionel Sambuc } cname[MAX_FAST_KEY + 1]; /* Fast lookup table. */ 106*84d9c625SLionel Sambuc 107*84d9c625SLionel Sambuc #define KEY_VAL(sp, ch) \ 108*84d9c625SLionel Sambuc (((ch) & ~MAX_FAST_KEY) == 0 ? \ 109*84d9c625SLionel Sambuc sp->gp->special_key[(unsigned char)ch] : v_key_val(sp,ch)) 110*84d9c625SLionel Sambuc e_key_t /* Fast lookup table. */ 111*84d9c625SLionel Sambuc special_key[MAX_FAST_KEY + 1]; 112*84d9c625SLionel Sambuc 113*84d9c625SLionel Sambuc /* Flags. */ 114*84d9c625SLionel Sambuc #define G_ABBREV 0x0001 /* If have abbreviations. */ 115*84d9c625SLionel Sambuc #define G_BELLSCHED 0x0002 /* Bell scheduled. */ 116*84d9c625SLionel Sambuc #define G_INTERRUPTED 0x0004 /* Interrupted. */ 117*84d9c625SLionel Sambuc #define G_RECOVER_SET 0x0008 /* Recover system initialized. */ 118*84d9c625SLionel Sambuc #define G_SCRIPTED 0x0010 /* Ex script session. */ 119*84d9c625SLionel Sambuc #define G_SCRWIN 0x0020 /* Scripting windows running. */ 120*84d9c625SLionel Sambuc #define G_SNAPSHOT 0x0040 /* Always snapshot files. */ 121*84d9c625SLionel Sambuc #define G_SRESTART 0x0080 /* Screen restarted. */ 122*84d9c625SLionel Sambuc u_int32_t flags; 123*84d9c625SLionel Sambuc 124*84d9c625SLionel Sambuc /* Screen interface functions. */ 125*84d9c625SLionel Sambuc /* Add a string to the screen. */ 126*84d9c625SLionel Sambuc int (*scr_addstr) __P((SCR *, const char *, size_t)); 127*84d9c625SLionel Sambuc /* Add a string to the screen. */ 128*84d9c625SLionel Sambuc int (*scr_waddstr) __P((SCR *, const CHAR_T *, size_t)); 129*84d9c625SLionel Sambuc /* Toggle a screen attribute. */ 130*84d9c625SLionel Sambuc int (*scr_attr) __P((SCR *, scr_attr_t, int)); 131*84d9c625SLionel Sambuc /* Terminal baud rate. */ 132*84d9c625SLionel Sambuc int (*scr_baud) __P((SCR *, u_long *)); 133*84d9c625SLionel Sambuc /* Beep/bell/flash the terminal. */ 134*84d9c625SLionel Sambuc int (*scr_bell) __P((SCR *)); 135*84d9c625SLionel Sambuc /* Display a busy message. */ 136*84d9c625SLionel Sambuc void (*scr_busy) __P((SCR *, const char *, busy_t)); 137*84d9c625SLionel Sambuc /* Prepare child. */ 138*84d9c625SLionel Sambuc int (*scr_child) __P((SCR *)); 139*84d9c625SLionel Sambuc /* Clear to the end of the line. */ 140*84d9c625SLionel Sambuc int (*scr_clrtoeol) __P((SCR *)); 141*84d9c625SLionel Sambuc /* Return the cursor location. */ 142*84d9c625SLionel Sambuc int (*scr_cursor) __P((SCR *, size_t *, size_t *)); 143*84d9c625SLionel Sambuc /* Delete a line. */ 144*84d9c625SLionel Sambuc int (*scr_deleteln) __P((SCR *)); 145*84d9c625SLionel Sambuc /* Discard a screen. */ 146*84d9c625SLionel Sambuc int (*scr_discard) __P((SCR *, SCR **)); 147*84d9c625SLionel Sambuc /* Get a keyboard event. */ 148*84d9c625SLionel Sambuc int (*scr_event) __P((SCR *, EVENT *, u_int32_t, int)); 149*84d9c625SLionel Sambuc /* Ex: screen adjustment routine. */ 150*84d9c625SLionel Sambuc int (*scr_ex_adjust) __P((SCR *, exadj_t)); 151*84d9c625SLionel Sambuc int (*scr_fmap) /* Set a function key. */ 152*84d9c625SLionel Sambuc __P((SCR *, seq_t, CHAR_T *, size_t, CHAR_T *, size_t)); 153*84d9c625SLionel Sambuc /* Get terminal key value. */ 154*84d9c625SLionel Sambuc int (*scr_keyval) __P((SCR *, scr_keyval_t, CHAR_T *, int *)); 155*84d9c625SLionel Sambuc /* Insert a line. */ 156*84d9c625SLionel Sambuc int (*scr_insertln) __P((SCR *)); 157*84d9c625SLionel Sambuc /* Handle an option change. */ 158*84d9c625SLionel Sambuc int (*scr_optchange) __P((SCR *, int, const char *, u_long *)); 159*84d9c625SLionel Sambuc /* Move the cursor. */ 160*84d9c625SLionel Sambuc int (*scr_move) __P((SCR *, size_t, size_t)); 161*84d9c625SLionel Sambuc /* Refresh the screen. */ 162*84d9c625SLionel Sambuc int (*scr_refresh) __P((SCR *, int)); 163*84d9c625SLionel Sambuc /* Rename the file. */ 164*84d9c625SLionel Sambuc int (*scr_rename) __P((SCR *, char *, int)); 165*84d9c625SLionel Sambuc /* Reply to an event. */ 166*84d9c625SLionel Sambuc int (*scr_reply) __P((SCR *, int, char *)); 167*84d9c625SLionel Sambuc /* Set the screen type. */ 168*84d9c625SLionel Sambuc int (*scr_screen) __P((SCR *, u_int32_t)); 169*84d9c625SLionel Sambuc /* Split the screen. */ 170*84d9c625SLionel Sambuc int (*scr_split) __P((SCR *, SCR *)); 171*84d9c625SLionel Sambuc /* Suspend the editor. */ 172*84d9c625SLionel Sambuc int (*scr_suspend) __P((SCR *, int *)); 173*84d9c625SLionel Sambuc /* Print usage message. */ 174*84d9c625SLionel Sambuc void (*scr_usage) __P((void)); 175*84d9c625SLionel Sambuc 176*84d9c625SLionel Sambuc /* Threading stuff */ 177*84d9c625SLionel Sambuc void *th_private; 178*84d9c625SLionel Sambuc 179*84d9c625SLionel Sambuc int (*run) __P((WIN *, void *(*)(void*), void *)); 180*84d9c625SLionel Sambuc 181*84d9c625SLionel Sambuc int (*lock_init) __P((WIN *, void **)); 182*84d9c625SLionel Sambuc #define LOCK_INIT(wp,s) \ 183*84d9c625SLionel Sambuc wp->gp->lock_init(wp, &s->lock) 184*84d9c625SLionel Sambuc int (*lock_try) __P((WIN *, void **)); 185*84d9c625SLionel Sambuc #define LOCK_TRY(wp,s) \ 186*84d9c625SLionel Sambuc wp->gp->lock_try(wp, &s->lock) 187*84d9c625SLionel Sambuc int (*lock_unlock) __P((WIN *, void **)); 188*84d9c625SLionel Sambuc #define LOCK_UNLOCK(wp,s) \ 189*84d9c625SLionel Sambuc wp->gp->lock_unlock(wp, &s->lock) 190*84d9c625SLionel Sambuc int (*lock_end) __P((WIN *, void **)); 191*84d9c625SLionel Sambuc #define LOCK_END(wp,s) \ 192*84d9c625SLionel Sambuc wp->gp->lock_end(wp, &s->lock) 193*84d9c625SLionel Sambuc }; 194*84d9c625SLionel Sambuc 195*84d9c625SLionel Sambuc /* 196*84d9c625SLionel Sambuc * XXX 197*84d9c625SLionel Sambuc * Block signals if there are asynchronous events. Used to keep DB system calls 198*84d9c625SLionel Sambuc * from being interrupted and not restarted, as that will result in consistency 199*84d9c625SLionel Sambuc * problems. This should be handled by DB. 200*84d9c625SLionel Sambuc */ 201*84d9c625SLionel Sambuc #ifdef BLOCK_SIGNALS 202*84d9c625SLionel Sambuc #include <signal.h> 203*84d9c625SLionel Sambuc extern sigset_t __sigblockset; 204*84d9c625SLionel Sambuc #define SIGBLOCK \ 205*84d9c625SLionel Sambuc (void)sigprocmask(SIG_BLOCK, &__sigblockset, NULL) 206*84d9c625SLionel Sambuc #define SIGUNBLOCK \ 207*84d9c625SLionel Sambuc (void)sigprocmask(SIG_UNBLOCK, &__sigblockset, NULL); 208*84d9c625SLionel Sambuc #else 209*84d9c625SLionel Sambuc #define SIGBLOCK 210*84d9c625SLionel Sambuc #define SIGUNBLOCK 211*84d9c625SLionel Sambuc #endif 212