window.c
上传用户:tianjinjs
上传日期:2007-01-05
资源大小:309k
文件大小:41k
- /*
- * window.c Very portable window routines.
- * Currently this code is used in _both_ the BBS
- * system and minicom.
- *
- * This file is part of the minicom communications package,
- * Copyright 1991-1996 Miquel van Smoorenburg.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version
- * 2 of the License, or (at your option) any later version.
- *
- * 01.01.98 dickey@clark.net: fix for a history window closing bug
- * fmg 8/20/97: Added support for Search of History Buffer
- */
- #include "port.h"
- #include "window.h"
- #include "charmap.h"
- #include "intl.h"
- /* Status line code on/off. */
- #define ST_LINE 1
- /* fmg 2/20/94 macros - Length of Macros */
- #ifndef MAC_LEN
- #define MAC_LEN 257
- #endif
- /* Don't want to include all header stuff for three prototypes from sysdep.c */
- #if __STDC__
- int setcbreak(int);
- int wxgetch(void);
- void getrowcols(int *rows, int *cols);
- #else
- int setcbreak();
- int wxgetch();
- void getrowcols();
- #endif
- #ifndef BBS
- #include "config.h"
- #endif
- #define BUFFERSIZE 2048
- #define swap(x, y) { int d = (x); (x) = (y); (y) = d; }
- /* Terminal capabilities */
- static char *CM, *IS, *RS, *AC, *EA;
- static char *ME, *SE, *UE, *AE;
- static char *AS, *MB, *MD, *MR, *SO, *US;
- static char *CE, *Al, *Dl, *AL, *DL;
- static char *CS, *SF, *SR, *VB, *BL;
- static char *VE, *VI, *KS, *KE;
- static char *CD, *CL, *IC, *DC;
- static char *BC, *CR, *NL;
- #if ST_LINE
- static char *TS, *FS, *DS;
- #endif
- /* Special characters */
- static char D_UL;
- static char D_HOR;
- static char D_UR;
- static char D_LL;
- static char D_VER;
- static char D_LR;
- static char S_UL;
- static char S_HOR;
- static char S_UR;
- static char S_LL;
- static char S_VER;
- static char S_LR;
- static char _bufstart[BUFFERSIZE];
- static char *_bufpos = _bufstart;
- static char *_buffend;
- static ELM *gmap;
- static char curattr = -1;
- static char curcolor = -1;
- static int curx = -1;
- static int cury = -1;
- static int _intern = 0;
- static int _curstype = CNORMAL;
- static int _has_am = 0;
- static int _mv_standout = 0;
- static ELM oldc;
- static int sflag = 0;
- /*
- * Smooth is only defined for slow machines running Minicom.
- * With this defined, Minicom will buffer only per-line
- * and the output will look much less 'jerky'. (I hope :-)
- */
- #ifdef SMOOTH
- static WIN *curwin = NIL_WIN;
- extern WIN *us;
- #endif
- int useattr = 1;
- int dirflush = 1;
- extern int LINES, COLS;
- int usecolor = 0;
- WIN *stdwin;
- char *_tptr = CNULL;
- int screen_ibmpc = 0;
- int screen_iso = 0;
- int w_init = 0;
- #if ST_LINE
- int use_status = 0; /* Turned on in main() */
- #else
- int use_status = 0;
- #endif
- /* Standard vt100 map (ac cpability) */
- static char *def_ac = "+273,253aaffggjjkkllmmnnooqqssttuuvvwwxx";
- #if DEBUG
- /*
- * Debug to stdout
- */
- int debug(s, a1, a2, a3, a4)
- char *s;
- int a1, a2, a3, a4;
- {
- char lala[80];
- snprintf(lala, sizeof(lala), s, a1, a2, a3, a4);
- write(2, lala, strlen(lala));
- return(0);
- }
- #endif
- /* ===== Low level routines ===== */
- /*
- * Flush the screen buffer
- */
- void wflush()
- {
- int todo, done;
- todo = _bufpos - _bufstart;
- _bufpos = _bufstart;
- while(todo > 0) {
- done = write(1, _bufpos, todo);
- if (done > 0) {
- todo -= done;
- _bufpos += done;
- }
- if (done < 0 && errno != EINTR) break;
- }
- _bufpos = _bufstart;
- }
- /*
- * Output a raw character to the screen
- */
- static int outchar(c)
- int c;
- {
- *_bufpos++ = c;
- if (_bufpos >= _buffend) wflush();
- #if defined(SMOOTH)
- if (curwin == us && (c == 'n' || c == 'r')) wflush();
- #endif
- return(0);
- }
- /*
- * Output a raw string to the screen.
- */
- static void outstr(s)
- char *s;
- {
- tputs(s, 1, outchar);
- }
- /*
- * Turn off all attributes
- */
- static void _attroff()
- {
- if (ME != CNULL)
- outstr(ME);
- else {
- if (SE != CNULL) outstr(SE);
- if (UE != CNULL) outstr(UE);
- }
- if (AE != CNULL) outstr(AE);
- }
- /*
- * Turn some attributes on
- */
- static void _attron(attr)
- char attr;
- {
- if (!usecolor || (attr & XA_REVERSE) == 0) {
- /* Reverse standout does not look too good.. */
- if (attr & XA_BOLD && MD != CNULL) outstr(MD);
- if (attr & XA_STANDOUT && SO != CNULL) outstr(SO);
- if (attr & XA_UNDERLINE && US != CNULL) outstr(US);
- }
- if (attr & XA_REVERSE && MR != CNULL) outstr(MR);
- if (attr & XA_BLINK && MB != CNULL) outstr(MB);
- if (attr & XA_ALTCHARSET && AS != CNULL) outstr(AS);
- }
- /*
- * Set the colors
- */
- static void _colson(color)
- char color;
- {
- char buf[12];
- sprintf(buf, "