home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 1 / 1740 / cled.h next >
Encoding:
C/C++ Source or Header  |  1990-12-28  |  5.9 KB  |  201 lines

  1. /*
  2.     $Id: cled.h,v 2.5 90/08/26 11:33:56 sw Exp $
  3. */
  4. /*
  5.     This should be set, if compiling as line discipline, in the command line
  6. */
  7.  
  8. #ifndef M_KERNEL
  9. #   define M_KERNEL    0
  10. #endif
  11.  
  12. /*
  13.     These are booleans and describe the environment in which CLED
  14.     is compiled and run. Even if you are on a 386 with a Unix that
  15.     has sptalloc()/sptfree() you will normally not want to use it,
  16.     because it allocates memory in page (4096 bytes) chunks.
  17. */
  18.  
  19. #define M_I386        1    /* Running on a 386 ?            */
  20. #define M_UNIX        1    /* System V/SCO Unix ? (or Xenix?)    */
  21. #define M_ATT        1    /* AT&T flavour of System V ?        */
  22. #define M_SPTALLOC    0    /* Kernel has, and we should use, it    */
  23.  
  24. /*
  25.     These are boolean options.  DEBUG should normally be 0.  The code
  26.     compiled in if CLEDIO is true is large; if you don't need to change
  27.     the default terminal capabilities and key bindings, set it to 0.
  28.     BREAKTHRU compiles in a nother large chunk of code that will
  29.     automatically reprint the current line if a write to the tty garbles
  30.     it.  You should normally set this to 0 and just explicitly request a
  31.     redraw in the rare event this happens.  MULTILB will dynamically
  32.     allocate a separate history buffer per process, not just one per
  33.     tty.  This is usually not what you want, and makes code and data
  34.     space grow.
  35. */
  36.  
  37. #define DEBUG        0    /* Compile in debugging helps        */
  38.  
  39. #define CLEDIO        1    /* Include ioctls to change defaults ?    */
  40. #define BREAKTHRU    0    /* Auto reprint on broadcasts ?        */
  41. #define MULTILB        0    /* Separate history per process ?    */
  42. #define VERBOSE        0    /* Print a msg each time CLED opens    */
  43.  
  44. #define COLUMNS        80    /* Default number of columns        */
  45.  
  46. /*
  47.     These set sizes of various buffers. Suitable values depend on the
  48.     amount of memory you want to devote to CLED, and its availability.
  49.     For a 386 you may want these to be 1024,32,134,64, and for a 286
  50.     they may be 256,16,82,64.
  51. */
  52.  
  53. #define MAXPROMPT    16    /* Size of prompt buffer        */
  54. #define MAXLINE        132    /* Size of command line buffer        */
  55. #define MAXHISTORY    1024    /* Size of history buffer        */
  56. #if !M_SPTALLOC
  57. #   define TCAP_SIZE    64    /* max length of all terminal escapes    */
  58. #endif
  59.  
  60. /* End of user adjustable parameters */
  61.  
  62. /*
  63.     Under which termio conditions CLED will operate
  64. */
  65.  
  66. #define CLEDOFF(flags)    (((flags) & CLEDFLAGS) != CLEDFLAGS)
  67.  
  68. #if 0
  69. #if M_KERNEL
  70. #   undef MULTILB
  71. #   undef M_SPTALLOC
  72. #   define M_SPTALLOC    0
  73. #   define MULTILB    0
  74. #   if !defined(TCAP_SIZE)
  75. #    define TCAP_SIZE    64
  76. #   endif
  77. #endif
  78. #endif
  79.  
  80. #define LD_DONE        0x0001    /* flag indicating read complete    */
  81. #define LD_QUIT        0x0002    /* completed under QUIT char        */
  82. #define LD_INTR     0x0004    /* completed under INTR char        */
  83. #define LD_EOF        0x0008    /* completed under EOF            */
  84. #define LD_DIRTY    0x0010    /* command buffer has been changed    */
  85. #define LD_INSERT   0x0020    /* insert mode                */
  86.  
  87. #define TB_NOLINE   0x0001    /* not using this discipline        */
  88. #define TB_OPEN        0x0002    /* tty buff is open            */
  89. #define TB_READING  0x0004    /* read currently in progress        */
  90. #define TB_WRITING  0x0008    /* write currently in progress        */
  91. #define TB_INSERT   0x0010    /* insert mode                */
  92. #define TB_OVERUN   0x0020    /* input buffer overrun            */
  93. #define TB_OPENING  0x0040    /* tty buf is opening            */
  94. #define TB_FLUSHIT  0x0080    /* flush the input que            */
  95.  
  96. /*
  97.     if last flag is greater than 0x8000, change flags from short to long
  98. */
  99.  
  100. #ifdef M_I386
  101. #   pragma pack(1)
  102. #endif
  103.  
  104. struct led_buf
  105. {
  106. #if MULTILB
  107.     struct led_buf          *next;
  108.     struct led_buf          *last;
  109.     struct proc             *proc;
  110. #endif
  111.  
  112.     struct tty_buf          *tbp;    /* Tty buf that owns us        */
  113.  
  114.     unchar                  prompt[MAXPROMPT+1]; /* +1: Final '\0'    */
  115.     unchar                  promptlen;    /* Current length of prompt    */
  116.  
  117.     unchar            line[MAXLINE+2]; /* +2: Left&right mark    */
  118.     unchar                  *lineend;    /* End of line in buf        */
  119.     unchar                  *lcurs;    /* Start of gap in buf        */
  120.     unchar                  *rcurs;    /* End of gap in buf        */
  121.     unchar                  *owed;    /* Part of line left over    */
  122.  
  123.     int                current;    /* Cursor position        */
  124.     int                lastchar;    /* Last char in line buf    */
  125.  
  126.     unchar                  history[MAXHISTORY+1]; /* +1: Final '\0'    */
  127.     unchar                  *historyend;/* End of history buffer    */
  128.     int                     lastline;    /* Last line in history buf    */
  129.     int                     matchlen;    /* Length of match string    */
  130.  
  131.     unsigned            flags;
  132.     unsigned            state;
  133.  
  134.     unchar                  c;        /* Character being input    */
  135.  
  136. #if MULTILB
  137.     int                pid;
  138.     int                ppid;
  139. #endif
  140. };
  141.  
  142. #ifdef M_I386
  143. #   pragma pack()
  144. #endif
  145.  
  146. struct tty_buf
  147. {
  148.     struct tty_buf          *next;
  149.     struct tty_buf          *last;
  150.  
  151.     struct led_buf          *lbp;    /* Pointer to line buffer    */
  152.     struct tty              *ttyp;    /* The tty we are serving    */
  153.  
  154.     int                cols;    /* Terminal line width        */
  155.  
  156.     unsigned            iflag;
  157.     unsigned            oflag;
  158.     unsigned            lflag;
  159.     unsigned            cflag;
  160.     char            cc[NCC + 2];
  161.  
  162.     unsigned            flags;
  163.     char            dorefresh;    /* Refresh current line soon    */
  164.     char            readsleep;    /* Sleeping while reading    */
  165.  
  166.     struct clist        broadcast;
  167.  
  168.     /*
  169.     Keyboard map, and terminal capability index and table
  170.     for this tty.
  171.     */
  172.     unchar            keymap[CLEKEY_MAX];
  173.  
  174.     char            *tcap[TCAP_COUNT];
  175.  
  176.     int                tclen;
  177. #if M_SPTALLOC
  178.     unchar            *tcstrings;
  179. #else
  180.     unchar            tcstrings[TCAP_SIZE];
  181. #endif
  182. };
  183.  
  184. #if M_SPTALLOC && M_KERNEL
  185. #   if M_UNIX
  186.     extern caddr_t    *sptalloc(/* int pages,int mode,int base,int flag */);
  187.     extern void    sptfree(/* char *va,int npages,int freeflag */);
  188.  
  189. #    define Sptalloc(bytes)        sptalloc(btopt(bytes),PG_P,0,0)
  190. #    define Sptfree(addr,bytes)  sptfree(addr,btopt(bytes),1)
  191. #   else
  192. #    define Sptalloc(bytes)        sptalloc(bytes)
  193. #    define Sptfree(addr,bytes)  sptfree(addr,bytes,1)
  194. #   endif
  195. #else
  196. #   if !M_KERNEL
  197. #    define Sptalloc(size)        malloc(size)
  198. #    define Sptfree(addr,size)   free(addr)
  199. #   endif
  200. #endif
  201.