BSD 4_3_Reno release
[unix-history] / usr / src / lib / libcurses / curses.h
index 2cd0db4..33a07a2 100644 (file)
@@ -2,40 +2,49 @@
  * Copyright (c) 1981 Regents of the University of California.
  * All rights reserved.
  *
  * Copyright (c) 1981 Regents of the University of California.
  * All rights reserved.
  *
- * Redistribution and use in source and binary forms are permitted
- * provided that this notice is preserved and that due credit is given
- * to the University of California at Berkeley. The name of the University
- * may not be used to endorse or promote products derived from this
- * software without specific prior written permission. This software
- * is provided ``as is'' without express or implied warranty.
+ * Redistribution and use in source and binary forms are permitted provided
+ * that: (1) source distributions retain this entire copyright notice and
+ * comment, and (2) distributions including binaries display the following
+ * acknowledgement:  ``This product includes software developed by the
+ * University of California, Berkeley and its contributors'' in the
+ * documentation or other materials provided with the distribution and in
+ * all advertising materials mentioning features or use of this software.
+ * Neither the name of the University nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  *
  *
- *     @(#)curses.h    5.3 (Berkeley) %G%
+ *     @(#)curses.h    5.9 (Berkeley) 7/1/90
  */
 
  */
 
-# ifndef WINDOW
+#ifndef WINDOW
 
 
-# include      <stdio.h>
+#include       <stdio.h>
  
  
-# include      <sgtty.h>
+#define USE_OLD_TTY
+#include       <sys/ioctl.h>
+#undef USE_OLD_TTY
 
 
-# define       bool    char
-# define       reg     register
+#define        bool    char
+#define        reg     register
 
 
-# define       TRUE    (1)
-# define       FALSE   (0)
-# define       ERR     (0)
-# define       OK      (1)
+#define        TRUE    (1)
+#define        FALSE   (0)
+#define        ERR     (0)
+#define        OK      (1)
 
 
-# define       _ENDLINE        001
-# define       _FULLWIN        002
-# define       _SCROLLWIN      004
-# define       _FLUSH          010
-# define       _FULLLINE       020
-# define       _IDLINE         040
-# define       _STANDOUT       0200
-# define       _NOCHANGE       -1
+#define        _ENDLINE        001
+#define        _FULLWIN        002
+#define        _SCROLLWIN      004
+#define        _FLUSH          010
+#define        _FULLLINE       020
+#define        _IDLINE         040
+#define        _STANDOUT       0200
+#define        _NOCHANGE       -1
 
 
-# define       _puts(s)        tputs(s, 0, _putchar)
+#define        _puts(s)        tputs(s, 0, _putchar)
 
 typedef        struct sgttyb   SGTTY;
 
 
 typedef        struct sgttyb   SGTTY;
 
@@ -75,7 +84,7 @@ struct _win_st {
        struct _win_st  *_nextp, *_orig;
 };
 
        struct _win_st  *_nextp, *_orig;
 };
 
-# define       WINDOW  struct _win_st
+#define        WINDOW  struct _win_st
 
 extern bool    My_term, _echoit, _rawmode, _endwin;
 
 
 extern bool    My_term, _echoit, _rawmode, _endwin;
 
@@ -91,34 +100,34 @@ extern WINDOW      *stdscr, *curscr;
  *     Define VOID to stop lint from generating "null effect"
  * comments.
  */
  *     Define VOID to stop lint from generating "null effect"
  * comments.
  */
-# ifdef lint
+#ifdef lint
 int    __void__;
 int    __void__;
-# define       VOID(x) (__void__ = (int) (x))
-# else
-# define       VOID(x) (x)
-# endif
+#define        VOID(x) (__void__ = (int) (x))
+#else
+#define        VOID(x) (x)
+#endif
 
 /*
  * psuedo functions for standard screen
  */
 
 /*
  * psuedo functions for standard screen
  */
-# define       addch(ch)       VOID(waddch(stdscr, ch))
-# define       getch()         VOID(wgetch(stdscr))
-# define       addbytes(da,co) VOID(waddbytes(stdscr, da,co))
-# define       addstr(str)     VOID(waddbytes(stdscr, str, strlen(str)))
-# define       getstr(str)     VOID(wgetstr(stdscr, str))
-# define       move(y, x)      VOID(wmove(stdscr, y, x))
-# define       clear()         VOID(wclear(stdscr))
-# define       erase()         VOID(werase(stdscr))
-# define       clrtobot()      VOID(wclrtobot(stdscr))
-# define       clrtoeol()      VOID(wclrtoeol(stdscr))
-# define       insertln()      VOID(winsertln(stdscr))
-# define       deleteln()      VOID(wdeleteln(stdscr))
-# define       refresh()       VOID(wrefresh(stdscr))
-# define       inch()          VOID(winch(stdscr))
-# define       insch(c)        VOID(winsch(stdscr,c))
-# define       delch()         VOID(wdelch(stdscr))
-# define       standout()      VOID(wstandout(stdscr))
-# define       standend()      VOID(wstandend(stdscr))
+#define        addch(ch)       VOID(waddch(stdscr, ch))
+#define        getch()         VOID(wgetch(stdscr))
+#define        addbytes(da,co) VOID(waddbytes(stdscr, da,co))
+#define        addstr(str)     VOID(waddbytes(stdscr, str, strlen(str)))
+#define        getstr(str)     VOID(wgetstr(stdscr, str))
+#define        move(y, x)      VOID(wmove(stdscr, y, x))
+#define        clear()         VOID(wclear(stdscr))
+#define        erase()         VOID(werase(stdscr))
+#define        clrtobot()      VOID(wclrtobot(stdscr))
+#define        clrtoeol()      VOID(wclrtoeol(stdscr))
+#define        insertln()      VOID(winsertln(stdscr))
+#define        deleteln()      VOID(wdeleteln(stdscr))
+#define        refresh()       VOID(wrefresh(stdscr))
+#define        inch()          VOID(winch(stdscr))
+#define        insch(c)        VOID(winsch(stdscr,c))
+#define        delch()         VOID(wdelch(stdscr))
+#define        standout()      VOID(wstandout(stdscr))
+#define        standend()      VOID(wstandend(stdscr))
 
 /*
  * mv functions
 
 /*
  * mv functions
@@ -153,18 +162,31 @@ int       __void__;
 #define        getyx(win,y,x)   y = win->_cury, x = win->_curx
 #define        winch(win)       (win->_y[win->_cury][win->_curx] & 0177)
 
 #define        getyx(win,y,x)   y = win->_cury, x = win->_curx
 #define        winch(win)       (win->_y[win->_cury][win->_curx] & 0177)
 
-#define raw()   (_tty.sg_flags|=RAW, _pfast=_rawmode=TRUE, stty(_tty_ch,&_tty))
-#define noraw()         (_tty.sg_flags&=~RAW,_rawmode=FALSE,_pfast=!(_tty.sg_flags&CRMOD),stty(_tty_ch,&_tty))
-#define cbreak() (_tty.sg_flags |= CBREAK, _rawmode = TRUE, stty(_tty_ch,&_tty))
-#define nocbreak() (_tty.sg_flags &= ~CBREAK,_rawmode=FALSE,stty(_tty_ch,&_tty))
+#define raw()   (_tty.sg_flags|=RAW, _pfast=_rawmode=TRUE, \
+       ioctl(_tty_ch, TIOCSETP, &_tty))
+#define noraw()         (_tty.sg_flags&=~RAW,_rawmode=FALSE,\
+       _pfast=!(_tty.sg_flags&CRMOD),ioctl(_tty_ch, TIOCSETP, &_tty))
+#define cbreak() (_tty.sg_flags |= CBREAK, _rawmode = TRUE, \
+       ioctl(_tty_ch, TIOCSETP, &_tty))
+#define nocbreak() (_tty.sg_flags &= ~CBREAK,_rawmode=FALSE, \
+       ioctl(_tty_ch, TIOCSETP, &_tty))
 #define crmode() cbreak()      /* backwards compatability */
 #define nocrmode() nocbreak()  /* backwards compatability */
 #define crmode() cbreak()      /* backwards compatability */
 #define nocrmode() nocbreak()  /* backwards compatability */
-#define echo()  (_tty.sg_flags |= ECHO, _echoit = TRUE, stty(_tty_ch, &_tty))
-#define noecho() (_tty.sg_flags &= ~ECHO, _echoit = FALSE, stty(_tty_ch, &_tty))
-#define nl()    (_tty.sg_flags |= CRMOD,_pfast = _rawmode,stty(_tty_ch, &_tty))
-#define nonl()  (_tty.sg_flags &= ~CRMOD, _pfast = TRUE, stty(_tty_ch, &_tty))
-#define        savetty() ((void) gtty(_tty_ch, &_tty), _res_flg = _tty.sg_flags)
-#define        resetty() (_tty.sg_flags = _res_flg, (void) stty(_tty_ch, &_tty))
+#define echo()  (_tty.sg_flags |= ECHO, _echoit = TRUE, \
+       ioctl(_tty_ch, TIOCSETP, &_tty))
+#define noecho() (_tty.sg_flags &= ~ECHO, _echoit = FALSE, \
+       ioctl(_tty_ch, TIOCSETP, &_tty))
+#define nl()    (_tty.sg_flags |= CRMOD,_pfast = _rawmode, \
+       ioctl(_tty_ch, TIOCSETP, &_tty))
+#define nonl()  (_tty.sg_flags &= ~CRMOD, _pfast = TRUE, \
+       ioctl(_tty_ch, TIOCSETP, &_tty))
+#define        savetty() ((void) ioctl(_tty_ch, TIOCGETP, &_tty), \
+       _res_flg = _tty.sg_flags)
+#define        resetty() (_tty.sg_flags = _res_flg, \
+       _echoit = ((_res_flg & ECHO) == ECHO), \
+       _rawmode = ((_res_flg & (CBREAK|RAW)) != 0), \
+       _pfast = ((_res_flg & CRMOD) ? _rawmode : TRUE), \
+       (void) ioctl(_tty_ch, TIOCSETP, &_tty))
 
 #define        erasechar()     (_tty.sg_erase)
 #define        killchar()      (_tty.sg_kill)
 
 #define        erasechar()     (_tty.sg_erase)
 #define        killchar()      (_tty.sg_kill)
@@ -178,4 +200,4 @@ char        *longname(), *getcap();
  */
 #define        unctrl(c)       _unctrl[(c) & 0177]
 extern char *_unctrl[];
  */
 #define        unctrl(c)       _unctrl[(c) & 0177]
 extern char *_unctrl[];
-# endif
+#endif