home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / bsd_srcs / usr.bin / window / ww.h < prev    next >
Encoding:
C/C++ Source or Header  |  1991-04-18  |  10.4 KB  |  311 lines

  1. /*
  2.  * Copyright (c) 1983 Regents of the University of California.
  3.  * All rights reserved.
  4.  *
  5.  * This code is derived from software contributed to Berkeley by
  6.  * Edward Wang at The University of California, Berkeley.
  7.  *
  8.  * Redistribution and use in source and binary forms, with or without
  9.  * modification, are permitted provided that the following conditions
  10.  * are met:
  11.  * 1. Redistributions of source code must retain the above copyright
  12.  *    notice, this list of conditions and the following disclaimer.
  13.  * 2. Redistributions in binary form must reproduce the above copyright
  14.  *    notice, this list of conditions and the following disclaimer in the
  15.  *    documentation and/or other materials provided with the distribution.
  16.  * 3. All advertising materials mentioning features or use of this software
  17.  *    must display the following acknowledgement:
  18.  *    This product includes software developed by the University of
  19.  *    California, Berkeley and its contributors.
  20.  * 4. Neither the name of the University nor the names of its contributors
  21.  *    may be used to endorse or promote products derived from this software
  22.  *    without specific prior written permission.
  23.  *
  24.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  25.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  26.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  27.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  28.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  29.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  30.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  31.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  32.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  33.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  34.  * SUCH DAMAGE.
  35.  *
  36.  *    @(#)ww.h    3.63 (Berkeley) 3/2/91
  37.  */
  38.  
  39. #ifdef OLD_TTY
  40. #include <sgtty.h>
  41. #else
  42. #include <termios.h>
  43. #endif
  44. #include <setjmp.h>
  45. #include <machine/endian.h>
  46.  
  47. #define NWW    30        /* maximum number of windows */
  48.  
  49.     /* a rectangle */
  50. struct ww_dim {
  51.     int nr;            /* number of rows */
  52.     int nc;            /* number of columns */
  53.     int t, b;        /* top, bottom */
  54.     int l, r;        /* left, right */
  55. };
  56.  
  57.     /* a coordinate */
  58. struct ww_pos {
  59.     int r;            /* row */
  60.     int c;            /* column */
  61. };
  62.  
  63.     /* the window structure */
  64. struct ww {
  65.         /* general flags and states */
  66.     char ww_state;        /* state of window */
  67.     char ww_oflags;        /* wwopen flags */
  68.  
  69.         /* information for overlap */
  70.     struct ww *ww_forw;    /* doubly linked list, for overlapping info */
  71.     struct ww *ww_back;
  72.     char ww_index;        /* the window index, for wwindex[] */
  73.     char ww_order;        /* the overlapping order */
  74.  
  75.         /* sizes and positions */
  76.     struct ww_dim ww_w;    /* window size and pos */
  77.     struct ww_dim ww_b;    /* buffer size and pos */
  78.     struct ww_dim ww_i;    /* the part inside the screen */
  79.     struct ww_pos ww_cur;    /* the cursor position, relative to ww_w */
  80.  
  81.         /* arrays */
  82.     char **ww_win;        /* the window */
  83.     union ww_char **ww_buf;    /* the buffer */
  84.     char **ww_fmap;        /* map for frame and box windows */
  85.     short *ww_nvis;        /* how many ww_buf chars are visible per row */
  86.  
  87.         /* information for wwwrite() and company */
  88.     char ww_wstate;        /* state for outputting characters */
  89.     char ww_modes;        /* current display modes */
  90.     char ww_insert;        /* insert mode */
  91.     char ww_mapnl;        /* map \n to \r\n */
  92.     char ww_noupdate;    /* don't do updates in wwwrite() */
  93.     char ww_unctrl;        /* expand control characters */
  94.     char ww_nointr;        /* wwwrite() not interruptable */
  95.     char ww_hascursor;    /* has fake cursor */
  96.  
  97.         /* things for the window process and io */
  98.     char ww_ispty;        /* ww_pty is really a pty, not socket pair */
  99.     char ww_stopped;    /* output stopped */
  100.     int ww_pty;        /* file descriptor of pty or socket pair */
  101.     int ww_socket;        /* other end of socket pair */
  102.     int ww_pid;        /* pid of process, if WWS_HASPROC true */
  103.     char ww_ttyname[11];    /* "/dev/ttyp?" */
  104.     char *ww_ob;        /* output buffer */
  105.     char *ww_obe;        /* end of ww_ob */
  106.     char *ww_obp;        /* current read position in ww_ob */
  107.     char *ww_obq;        /* current write position in ww_ob */
  108.  
  109.         /* things for the user, they really don't belong here */
  110.     char ww_id;        /* the user window id */
  111.     char ww_center;        /* center the label */
  112.     char ww_hasframe;    /* frame it */
  113.     char ww_keepopen;    /* keep it open after the process dies */
  114.     char *ww_label;        /* the user supplied label */
  115.     struct ww_dim ww_alt;    /* alternate position and size */
  116. };
  117.  
  118.     /* state of a tty */
  119. struct ww_tty {
  120. #ifdef OLD_TTY
  121.     struct sgttyb ww_sgttyb;
  122.     struct tchars ww_tchars;
  123.     struct ltchars ww_ltchars;
  124.     int ww_lmode;
  125.     int ww_ldisc;
  126. #else
  127.     struct termios ww_termios;
  128. #endif
  129.     int ww_fflags;
  130. };
  131.  
  132. union ww_char {
  133.     short c_w;        /* as a word */
  134.     struct {
  135. #if BYTE_ORDER == LITTLE_ENDIAN || BYTE_ORDER == PDP_ENDIAN
  136.         char C_c;    /* the character part */
  137.         char C_m;    /* the mode part */
  138. #endif
  139. #if BYTE_ORDER == BIG_ENDIAN
  140.         char C_m;    /* the mode part */
  141.         char C_c;    /* the character part */
  142. #endif
  143.     } c_un;
  144. };
  145. #define c_c c_un.C_c
  146. #define c_m c_un.C_m
  147.  
  148.     /* for display update */
  149. struct ww_update {
  150.     int best_gain;
  151.     int best_col;
  152.     int gain;
  153. };
  154.  
  155.     /* parts of ww_char */
  156. #define WWC_CMASK    0x00ff
  157. #define WWC_MMASK    0xff00
  158. #define WWC_MSHIFT    8
  159.  
  160.     /* c_m bits */
  161. #define WWM_REV        0x01    /* reverse video */
  162. #define WWM_BLK        0x02    /* blinking */
  163. #define WWM_UL        0x04    /* underlined */
  164. #define WWM_GRP        0x08    /* graphics */
  165. #define WWM_DIM        0x10    /* half intensity */
  166. #define WWM_USR        0x20    /* user specified mode */
  167. #define WWM_GLS        0x40    /* window only, glass, i.e., transparent */
  168.  
  169.     /* ww_state values */
  170. #define WWS_INITIAL    0    /* just opened */
  171. #define WWS_HASPROC    1    /* has process on pty */
  172. #define WWS_DEAD    3    /* child died */
  173.  
  174.     /* flags for ww_fmap */
  175. #define WWF_U        0x01
  176. #define WWF_R        0x02
  177. #define WWF_D        0x04
  178. #define WWF_L        0x08
  179. #define WWF_MASK    (WWF_U|WWF_R|WWF_D|WWF_L)
  180. #define WWF_LABEL    0x40
  181. #define WWF_TOP        0x80
  182.  
  183.     /* flags to wwopen() */
  184. #define WWO_PTY        0x01        /* want pty */
  185. #define WWO_SOCKET    0x02        /* want socket pair */
  186. #define WWO_REVERSE    0x04        /* make it all reverse video */
  187. #define WWO_GLASS    0x08        /* make it all glass */
  188. #define WWO_FRAME    0x10        /* this is a frame window */
  189.  
  190.     /* special ww_index value */
  191. #define WWX_NOBODY    NWW
  192.  
  193.     /* error codes */
  194. #define WWE_NOERR    0
  195. #define WWE_SYS        1        /* system error */
  196. #define WWE_NOMEM    2        /* out of memory */
  197. #define WWE_TOOMANY    3        /* too many windows */
  198. #define WWE_NOPTY    4        /* no more ptys */
  199. #define WWE_SIZE    5        /* bad window size */
  200. #define WWE_BADTERM    6        /* bad terminal type */
  201. #define WWE_CANTDO    7        /* dumb terminal */
  202.  
  203.     /* wwtouched[] bits, there used to be more than one */
  204. #define WWU_TOUCHED    0x01        /* touched */
  205.  
  206.     /* the window structures */
  207. struct ww wwhead;
  208. struct ww *wwindex[NWW + 1];        /* last location is for wwnobody */
  209. struct ww wwnobody;
  210.  
  211.     /* tty things */
  212. struct ww_tty wwoldtty;        /* the old (saved) terminal settings */
  213. struct ww_tty wwnewtty;        /* the new (current) terminal settings */
  214. struct ww_tty wwwintty;        /* the terminal settings for windows */
  215. char *wwterm;            /* the terminal name */
  216. char wwtermcap[1024];        /* place for the termcap */
  217.  
  218.     /* generally useful variables */
  219. int wwnrow, wwncol;        /* the screen size */
  220. char wwavailmodes;        /* actually supported modes */
  221. char wwcursormodes;        /* the modes for the fake cursor */
  222. char wwwrap;            /* terminal has auto wrap around */
  223. int wwdtablesize;        /* result of getdtablesize() call */
  224. char **wwsmap;            /* the screen map */
  225. union ww_char **wwos;        /* the old (current) screen */
  226. union ww_char **wwns;        /* the new (desired) screen */
  227. char *wwtouched;        /* wwns changed flags */
  228. struct ww_update *wwupd;    /* for display update */
  229. int wwospeed;            /* output baud rate, copied from wwoldtty */
  230. int wwbaud;            /* wwospeed converted into actual number */
  231. int wwcursorrow, wwcursorcol;    /* where we want the cursor to be */
  232. int wwerrno;            /* error number */
  233.  
  234.     /* statistics */
  235. int wwnflush, wwnwr, wwnwre, wwnwrz, wwnwrc;
  236. int wwnwwr, wwnwwra, wwnwwrc;
  237. int wwntokdef, wwntokuse, wwntokbad, wwntoksave, wwntokc;
  238. int wwnupdate, wwnupdline, wwnupdmiss;
  239. int wwnupdscan, wwnupdclreol, wwnupdclreos, wwnupdclreosmiss, wwnupdclreosline;
  240. int wwnread, wwnreade, wwnreadz, wwnreadc;
  241. int wwnwread, wwnwreade, wwnwreadz, wwnwreadd, wwnwreadc, wwnwreadp;
  242. int wwnselect, wwnselecte, wwnselectz;
  243.  
  244.     /* quicky macros */
  245. #define wwsetcursor(r,c) (wwcursorrow = (r), wwcursorcol = (c))
  246. #define wwcurtowin(w)    wwsetcursor((w)->ww_cur.r, (w)->ww_cur.c)
  247. #define wwunbox(w)    wwunframe(w)
  248. #define wwclreol(w,r,c)    wwclreol1((w), (r), (c), 0)
  249. #define wwredrawwin(w)    wwredrawwin1((w), (w)->ww_i.t, (w)->ww_i.b, 0)
  250. #define wwupdate()    wwupdate1(0, wwnrow);
  251.  
  252.     /* things for handling input */
  253. void wwrint();        /* interrupt handler */
  254. struct ww *wwcurwin;    /* window to copy input into */
  255. char *wwib;        /* input (keyboard) buffer */
  256. char *wwibe;        /* wwib + sizeof buffer */
  257. char *wwibp;        /* current read position in buffer */
  258. char *wwibq;        /* current write position in buffer */
  259. #define wwgetc()    (wwibp < wwibq ? *wwibp++ & 0x7f : -1)
  260. #define wwpeekc()    (wwibp < wwibq ? *wwibp & 0x7f : -1)
  261. #define wwungetc(c)    (wwibp > wwib ? *--wwibp = (c) : -1)
  262.  
  263.     /* things for short circuiting wwiomux() */
  264. char wwintr;        /* interrupting */
  265. char wwsetjmp;        /* want a longjmp() from wwrint() and wwchild() */
  266. jmp_buf wwjmpbuf;    /* jmpbuf for above */
  267. #define wwinterrupt()    wwintr
  268. #define wwsetintr()    do { wwintr = 1; if (wwsetjmp) longjmp(wwjmpbuf, 1); } \
  269.             while (0)
  270. #define wwclrintr()    (wwintr = 0)
  271.  
  272.     /* the window virtual terminal */
  273. #define WWT_TERM    "window-v2"
  274. #define WWT_TERMCAP    "WW|window-v2|window program version 2:\
  275.     :am:bs:da:db:ms:pt:cr=^M:nl=^J:bl=^G:ta=^I:\
  276.     :cm=\\EY%+ %+ :le=^H:nd=\\EC:up=\\EA:do=\\EB:ho=\\EH:\
  277.     :cd=\\EJ:ce=\\EK:cl=\\EE:me=\\Er^?:"
  278. #define WWT_REV        "se=\\ErA:so=\\EsA:mr=\\EsA:"
  279. #define WWT_BLK        "BE=\\ErB:BS=\\EsB:mb=\\EsB:"
  280. #define WWT_UL        "ue=\\ErD:us=\\EsD:"
  281. #define WWT_GRP        "ae=\\ErH:as=\\EsH:"
  282. #define WWT_DIM        "HE=\\ErP:HS=\\EsP:mh=\\EsP:"
  283. #define WWT_USR        "XE=\\Er`:XS=\\Es`:"
  284. #define WWT_ALDL    "al=\\EL:dl=\\EM:"
  285. #define WWT_IMEI    "im=\\E@:ei=\\EO:ic=:mi:" /* XXX, ic for emacs bug */
  286. #define WWT_IC        "ic=\\EP:"
  287. #define WWT_DC        "dc=\\EN:"
  288. char wwwintermcap[1024];    /* terminal-specific but window-independent
  289.                    part of the window termcap */
  290.  
  291.     /* our functions */
  292. struct ww *wwopen();
  293. void wwchild();
  294. void wwsuspend();
  295. char **wwalloc();
  296. char *wwerror();
  297.  
  298.     /* c library functions */
  299. char *malloc();
  300. char *calloc();
  301. char *getenv();
  302. char *tgetstr();
  303. char *rindex();
  304. char *strcpy();
  305. char *strcat();
  306.  
  307. #undef MIN
  308. #undef MAX
  309. #define MIN(x, y)    ((x) > (y) ? (y) : (x))
  310. #define MAX(x, y)    ((x) > (y) ? (x) : (y))
  311.