home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume25 / screen3 / part03 / screen.h < prev    next >
Encoding:
C/C++ Source or Header  |  1991-12-18  |  10.3 KB  |  496 lines

  1. /* Copyright (c) 1991
  2.  *      Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
  3.  *      Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
  4.  * Copyright (c) 1987 Oliver Laumann
  5.  *
  6.  * This program is free software; you can redistribute it and/or modify
  7.  * it under the terms of the GNU General Public License as published by
  8.  * the Free Software Foundation; either version 1, or (at your option)
  9.  * any later version.
  10.  *
  11.  * This program is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program (see the file COPYING); if not, write to the
  18.  * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  *
  20.  * Noteworthy contributors to screen's design and implementation:
  21.  *    Wayne Davison (davison@borland.com)
  22.  *    Patrick Wolfe (pat@kai.com, kailand!pat)
  23.  *    Bart Schaefer (schaefer@cse.ogi.edu)
  24.  *    Nathan Glasser (nathan@brokaw.lcs.mit.edu)
  25.  *    Larry W. Virden (lwv27%cas.BITNET@CUNYVM.CUNY.Edu)
  26.  *    Howard Chu (hyc@hanauma.jpl.nasa.gov)
  27.  *    Tim MacKenzie (tym@dibbler.cs.monash.edu.au)
  28.  *    Markku Jarvinen (mta@{cc,cs,ee}.tut.fi)
  29.  *    Marc Boucher (marc@CAM.ORG)
  30.  *
  31.  ****************************************************************
  32.  * $Id: screen.h,v 1.49 91/10/11 10:24:11 jnweiger Exp $ FAU
  33.  */
  34.  
  35. /* screen.h now includes enough to satisfy its own references.
  36.  * only config.h is still needed.
  37.  */
  38.  
  39. #include <stdio.h>
  40. #include <errno.h>
  41. #if defined(pyr)
  42. extern int errno;
  43. #endif
  44.  
  45. #ifdef sun
  46. # define getpgrp __getpgrp
  47. # define exit __exit
  48. #endif
  49.  
  50. #ifdef POSIX
  51. #include <unistd.h>
  52. # if defined(__STDC__)
  53. #  include <stdlib.h>
  54. # endif
  55. #endif
  56.  
  57. #ifdef sun
  58. # undef getpgrp
  59. # undef exit
  60. #endif
  61.  
  62. #ifdef POSIX
  63. # include <termios.h>
  64. # ifdef hpux
  65. #  include <bsdtty.h>
  66. # endif
  67. #else
  68. # ifdef TERMIO
  69. #  include <termio.h>
  70. # else
  71. #  include <sgtty.h>
  72. # endif /* TERMIO */
  73. #endif /* POSIX */
  74.  
  75. #ifdef SUIDROOT
  76. #  ifdef LOCKPTY
  77. #     undef LOCKPTY
  78. #  endif
  79. #endif
  80.  
  81. #ifndef UTMPOK
  82. #  ifdef USRLIMIT
  83. #     undef USRLIMIT
  84. #  endif
  85. #endif
  86.  
  87. #ifndef LOGINDEFAULT
  88. #  define LOGINDEFAULT 0
  89. #endif
  90.  
  91. #if defined(LOADAV_3DOUBLES) || defined(LOADAV_3LONGS) || defined(LOADAV_4LONGS)
  92. #  define LOADAV
  93. #endif
  94.  
  95. #ifndef FSCALE
  96. # ifdef MIPS
  97. #  define FSCALE 256            /* MIPS doesn't, and... */
  98. # else
  99. #  define FSCALE 1000.0     /* Sequent doesn't define FSCALE...grrrr */
  100. # endif    
  101. #endif
  102.  
  103. #ifndef F_OK
  104. #define F_OK 0
  105. #endif
  106. #ifndef X_OK
  107. #define X_OK 1
  108. #endif
  109. #ifndef W_OK
  110. #define W_OK 2
  111. #endif
  112. #ifndef R_OK
  113. #define R_OK 4
  114. #endif
  115.  
  116. #ifndef MAXPATH
  117. # define MAXPATH 1024
  118. #endif
  119.  
  120. #ifdef SIGVOID
  121. # if defined(ultrix)
  122. #  define sig_t void
  123. # else /* nice compilers: */
  124.    typedef void sig_t;
  125. # endif
  126. #else
  127.    typedef int sig_t;
  128. #endif
  129.  
  130. #ifdef SVR4
  131. #define SIGPROTOARG   (int)
  132. #define SIGDEFARG     int sigsig
  133. #define SIGARG        0
  134. #else
  135. #define SIGPROTOARG   (void)
  136. #define SIGDEFARG
  137. #define SIGARG
  138. #endif
  139.  
  140. #if (!defined(SYSV) && !defined(POSIX)) || defined(sysV68)
  141. typedef int pid_t;
  142. #endif
  143.  
  144. #if defined(M_XENIX)
  145. typedef int pid_t;
  146. typedef int gid_t;
  147. typedef int uid_t;
  148. #endif
  149.  
  150. #if defined(UTMPOK) && defined(_SEQUENT_)
  151. # define GETUTENT
  152. #endif
  153.  
  154. #ifdef GETUTENT
  155.   typedef char *slot_t;
  156. #else
  157.   typedef int slot_t;
  158. #endif
  159.  
  160. #if !defined(BSD) && !defined(sequent)
  161. # define index strchr
  162. # define rindex strrchr
  163. #endif
  164.  
  165. #ifdef SYSV /* jw. */
  166. # define bzero(poi,len) memset(poi,0,len)
  167. # define killpg(pgrp,sig) kill( -(pgrp), sig)
  168. #endif
  169.  
  170. /* here comes my own Free: jw. */
  171. #define Free(a) {if ((a) == 0) abort(); else free((void *)(a)); (a)=0;}
  172.  
  173. #define Ctrl(c) ((c)&037)
  174.  
  175. /* modes for markroutine 
  176.  */
  177. #define PLAIN 0
  178. #define TRICKY 1
  179.  
  180. /*typedef long off_t; */    /* Someone might need this */
  181.  
  182. enum state_t 
  183. {
  184.   LIT,                /* Literal input */
  185.   ESC,                /* Start of escape sequence */
  186.   ASTR,                /* Start of control string */
  187.   STRESC,            /* ESC seen in control string */
  188.   CSI,                /* Reading arguments in "CSI Pn ; Pn ; ... ; XXX" */
  189.   PRIN,                /* Printer mode */
  190.   PRINESC,            /* ESC seen in printer mode */
  191.   PRINCSI,            /* CSI seen in printer mode */
  192.   PRIN4            /* CSI 4 seen in printer mode */
  193. };
  194.  
  195. enum string_t 
  196. {
  197.   NONE,
  198.   DCS,                /* Device control string */
  199.   OSC,                /* Operating system command */
  200.   APC,                /* Application program command */
  201.   PM,                /* Privacy message */
  202.   AKA                /* a.k.a. for current screen */
  203. };
  204.  
  205. #define MAXSTR        256
  206. #define MAXARGS     64
  207. #define MSGWAIT     5
  208. #define MSGMINWAIT     1
  209.  
  210. /* 
  211.  * 4 <= IOSIZE <=1000
  212.  * you may try to vary this value. Use low values if your (VMS) system
  213.  * tends to choke when pasting. Use high values if you want to test
  214.  * how many characters your pty's can buffer.
  215.  */
  216. #define IOSIZE        80
  217.  
  218. /*
  219.  * if a nasty user really wants to try a history of 2000 lines on all 10
  220.  * windows, he will allocate 5 MegaBytes of memory, which is quite enough.
  221.  */
  222. #define MAXHISTHEIGHT 2000
  223. #define DEFAULTHISTHEIGHT 50
  224.  
  225. struct win 
  226. {
  227.   int wpid; /* process, that is connected to the other end of ptyfd */
  228.   int ptyfd; /* usually the master side of our pty pair */
  229.   int ttyflag; /* 1 if ptyfd is connected to a user specified tty. */
  230.   int aflag;
  231.   char outbuf[IOSIZE];
  232.   int outlen;
  233.   int autoaka, akapos;
  234.   char cmd[MAXSTR];
  235.   char tty[MAXSTR];
  236.   int args[MAXARGS];
  237.   int NumArgs;
  238.   slot_t slot;
  239.   char **image;
  240.   char **attr;
  241.   char **font;
  242.   int LocalCharset;
  243.   int charsets[4];
  244.   int ss;
  245.   int active;
  246.   int x, y;
  247.   char LocalAttr;
  248.   int saved;
  249.   int Saved_x, Saved_y;
  250.   char SavedLocalAttr;
  251.   int SavedLocalCharset;
  252.   int SavedCharsets[4];
  253.   int top, bot;
  254.   int wrap;
  255.   int origin;
  256.   int insert;
  257.   int keypad;
  258.   int width, height;    /* width AND height, as we have now resized wins. jw.*/
  259.   int histheight;       /* all histbases are malloced with width * histheight */
  260.   int histidx;          /* 0= < histidx < histheight; where we insert lines */
  261.   char **ihist;     /* the history buffer  image */
  262.   char **ahist;     /* attributes */
  263.   char **fhist;     /* fonts */
  264.   enum state_t state;
  265.   enum string_t StringType;
  266.   char string[MAXSTR];
  267.   char *stringp;
  268.   char *tabs;
  269.   int vbwait;            
  270.   int bell;
  271.   int flow;
  272.   int autoflow;
  273.   int WinLink;
  274.   FILE *logfp;
  275.   int monitor;
  276.   int cursor_invisible;
  277. };
  278.  
  279. #define D_DETACH    0
  280. #define D_STOP        1
  281. #define D_REMOTE    2
  282. #define D_POWER     3
  283. #define D_REMOTE_POWER    4
  284. #define D_LOCK        5
  285.  
  286. /*
  287.  * Here are the messages the attacher sends to the backend
  288.  */
  289.  
  290. #define MSG_CREATE    0
  291. #define MSG_ERROR    1
  292. #define MSG_ATTACH    2
  293. #define MSG_CONT    3
  294. #define MSG_DETACH    4
  295. #define MSG_POW_DETACH    5
  296. #define MSG_WINCH    6
  297. #define MSG_HANGUP    7
  298.  
  299. struct msg
  300. {
  301.   int type;
  302.   union
  303.     {
  304.       struct
  305.     {
  306.       int lflag;
  307.       int aflag;
  308.       int flowflag;
  309.       int hheight;  /* size of scrollback buffer */
  310.       int nargs;
  311.       char line[MAXPATH];
  312.       char dir[MAXPATH];
  313.       char screenterm[20]; /* is screen really "screen" ? */
  314.     }
  315.       create;
  316.       struct
  317.     {
  318.       int apid;
  319.       int adaptflag; /* do we wish to adapt window size? */
  320.       int lines, columns;
  321.       char tty[MAXPATH];
  322.       char password[20];
  323.       char envterm[MAXPATH];
  324.     }
  325.       attach;
  326.       struct 
  327.     {
  328.       char password[20];
  329.       int dpid;
  330.       char tty[MAXPATH];
  331.     }
  332.       detach;
  333.       char message[MAXPATH*2];
  334.     } m;
  335. };
  336.  
  337. /*
  338.  * And the signals the attacher receives from the backend
  339.  */
  340.  
  341. #define SIG_BYE        SIGHUP
  342. #define SIG_POWER_BYE    SIGUSR1
  343. #define SIG_LOCK    SIGUSR2
  344. #define SIG_STOP    SIGTSTP
  345. #define SIG_PW_OK    SIGUSR1
  346. #define SIG_PW_FAIL    SIG_BYE
  347.  
  348.  
  349. struct mode
  350. {
  351. #ifdef TIOCSWINSZ
  352.   struct winsize ws;
  353. #endif
  354. #ifdef POSIX
  355.   struct termios tio;
  356. # ifdef hpux
  357.   struct ltchars m_ltchars;
  358. # endif
  359. #else
  360. # ifdef TERMIO
  361.   struct termio tio;
  362. # else
  363.   struct sgttyb m_ttyb;
  364.   struct tchars m_tchars;
  365.   struct ltchars m_ltchars;
  366.   int m_ldisc;
  367.   int m_lmode;
  368. # endif                /* TERMIO */
  369. #endif                /* POSIX */
  370. };
  371.  
  372. #define BELL        7
  373. #define VBELLWAIT    1 /* No. of seconds a vbell will be displayed */
  374.  
  375. #define BELL_OFF    0 /* No bell has occurred in the window */
  376. #define BELL_ON     1 /* A bell has occurred, but user not yet notified */
  377. #define BELL_DONE    2 /* A bell has occured, user has been notified */
  378. #define BELL_VISUAL     3 /* A bell has occured in fore win, notify him visually */
  379.  
  380. #define MON_OFF     0 /* Monitoring is off in the window */
  381. #define MON_ON        1 /* No activity has occurred in the window */
  382. #define MON_FOUND    2 /* Activity has occured, but user not yet notified */
  383. #define MON_DONE    3 /* Activity has occured, user has been notified */
  384.  
  385. #define DUMP_TERMCAP    0 /* WriteFile() options */
  386. #define DUMP_HARDCOPY    1
  387. #define DUMP_EXCHANGE    2
  388.  
  389. #undef MAXWIN20
  390.  
  391. #ifdef MAXWIN20
  392. #define MAXWIN    20
  393. #else
  394. #define MAXWIN    10
  395. #endif
  396.  
  397. /* the key definitions are used in screen.c and help.c */
  398. /* keep this list synchronus with the names given in fileio.c */
  399. enum keytype
  400. {
  401.   KEY_IGNORE, /* Keep these first 2 at the start */
  402.   KEY_SCREEN,
  403.   KEY_0,  KEY_1,  KEY_2,  KEY_3,  KEY_4,
  404.   KEY_5,  KEY_6,  KEY_7,  KEY_8,  KEY_9,
  405. #ifdef MAXWIN20
  406.   KEY_10, KEY_11, KEY_12, KEY_13, KEY_14,
  407.   KEY_15, KEY_16, KEY_17, KEY_18, KEY_19,
  408. #endif
  409.   KEY_AKA,
  410.   KEY_AUTOFLOW,
  411.   KEY_CLEAR,
  412.   KEY_COLON,
  413.   KEY_COPY,
  414.   KEY_DETACH,
  415.   KEY_FLOW,
  416.   KEY_HARDCOPY,
  417.   KEY_HELP,
  418.   KEY_HISTORY,
  419.   KEY_INFO,
  420.   KEY_KILL,
  421.   KEY_LASTMSG,
  422.   KEY_LICENSE,
  423.   KEY_LOCK,
  424.   KEY_LOGTOGGLE,
  425.   KEY_LOGIN,
  426.   KEY_MONITOR,
  427.   KEY_NEXT,
  428.   KEY_OTHER,
  429.   KEY_PASTE,
  430.   KEY_POW_DETACH,
  431.   KEY_PREV,
  432.   KEY_QUIT,
  433.   KEY_READ_BUFFER,
  434.   KEY_REDISPLAY,
  435.   KEY_REMOVE_BUFFERS,
  436.   KEY_RESET,
  437.   KEY_SET,
  438.   KEY_SHELL,
  439.   KEY_SUSPEND,
  440.   KEY_TERMCAP,
  441.   KEY_TIME,
  442.   KEY_VBELL,
  443.   KEY_VERSION,
  444.   KEY_WIDTH,
  445.   KEY_WINDOWS,
  446.   KEY_WRAP,
  447.   KEY_WRITE_BUFFER,
  448.   KEY_XOFF,
  449.   KEY_XON,
  450.   KEY_EXTEND,
  451.   KEY_X_WINDOWS,
  452.   KEY_BONUSWINDOW,
  453.   KEY_CREATE,
  454. };
  455.  
  456. struct key 
  457. {
  458.   enum keytype type;
  459.   char **args;
  460. };
  461.  
  462. #ifdef NETHACK
  463. #    define Msg_nomem Msg(0, "You feel stupid.")
  464. #else
  465. #    define Msg_nomem Msg(0, "Out of memory.")
  466. #endif
  467.  
  468. #ifdef DEBUG
  469. #    define debug(x) {fprintf(dfp,x);fflush(dfp);}
  470. #    define debug1(x,a) {fprintf(dfp,x,a);fflush(dfp);}
  471. #    define debug2(x,a,b) {fprintf(dfp,x,a,b);fflush(dfp);}
  472. #    define debug3(x,a,b,c) {fprintf(dfp,x,a,b,c);fflush(dfp);}
  473.     extern FILE *dfp;
  474. #else
  475. #    define debug(x) {}
  476. #    define debug1(x,a) {}
  477. #    define debug2(x,a,b) {}
  478. #    define debug3(x,a,b,c) {}
  479. #endif
  480.  
  481. #if defined(__STDC__)
  482. # define __P(a) a
  483. #else
  484. # define __P(a) ()
  485. # define const
  486. #endif
  487.  
  488. #ifdef hpux
  489. # define setreuid(ruid, euid) setresuid(ruid, euid, -1)
  490. # define setregid(rgid, egid) setresgid(rgid, egid, -1)
  491. #endif
  492.  
  493. #if !defined(SYSV) || defined(sun) || defined(RENO) || defined(xelos)
  494. # define BSDWAIT
  495. #endif
  496.