[comp.sys.atari.st] curses.mwc part2/2

cjp@stag.UUCP (Chuck) (02/17/88)

CURSES2.SRC                                            CJPurcell 15Feb'88
                                        some times:     como!cpurcell@eta
                                       other times:      cjp@stag.uucp

This document and the source code is shar'ed (skip down about 50 lines to
find it) and consists of:

     curses.man     both useful and necessary
     curses.c       curses source, as slightly modified for use with MWC   
     curses.h       include file, for inclusion in your various sources
     twinkle.c      demonstration of both practice and performance

Re:This version: The document was found stored in our club bbs-essentially
in a useless form. Somehow the doc/manual was stuffed with large strings of 
overbar characters(i.e. 0x00ff bytes) and the tab format utilized in the code 
was (is) equally strange. Who knows how many twisted(blue?) transformations
were required in order to arrive at my house.  TINYTOOL.ACC  to the rescue!
Poke by poke!  But, I wanted to learn about curses AND I wanted curses on
the ATARI-ST here in America.

MWC conversion notes are as located in the source. The only important note
is to avoid the use of the unportable PORTAB.H  (-) . The grubby note is
that many long lines in the source are(were) truncated during the compile
phase, as well as by the editors,so  SHOW.PRG  to the  rescue once, again,
so as to establish the intent of the original program. Possibly the source
was "beautified" before publication. It turned out to be a poor choice.

The program  TWINKLE.TOS  was prepared by the author to prove this version 
of curses. I get the same picture with MWC as was provided originally. No
other testing has been performed. I still don't know much about curses.
*************************************************************CJPurcell   

The following was garnered from a previous post by Mr. Turner...
>
>This is an emulation of the curses library in UNIX. It is a series of
>library routines which allows the user to control cursor positioning
>and output of characters in one or more 'windows'. A curses window is
>defined as a rectangular area of the screen whose size is as small as 1
>char or as large as the whole screen.
>
>Despite what Rene says in his comments, I have not been able to get
>this to work under anything but Alcyon C. MWC compiles but will not
>execute properly and Megamax aborts with compile errors. I'm afraid
>that I am too far behind as it is and can not spend any more time
>trying to port this. Perhaps some kind soul......

seems to work fine for MWC now...

>There is one change that needs to made for this to work under Alcyon C,
>the size of the stack in gemstart.s must be increased from 500 to
>10000. The place to do this is fairly easy to find since it is 
>commented in the sources. <<In MWC I set _stksize = 10280;  >>  

#--------------------------------CUT HERE-------------------------------------
#! /bin/sh
#
# This is a shell archive.  Save this into a file, edit it
# and delete all lines above this comment.  Then give this
# file to sh by executing the command "sh file".  The files
# will be extracted into the current directory owned by
# you with default permissions.
#
# The files contained herein are:
#
# -rw-r--r--  1 cjp         29129 Feb 16 18:08 curses.c
# -rw-r--r--  1 cjp          4033 Feb 16 18:08 curses.h
# -rw-r--r--  1 cjp          4953 Feb 16 18:05 curses.man
# -rw-r--r--  1 cjp          1620 Feb 16 18:09 twinkle.c
#
echo 'x - curses.c'
if test -f curses.c; then echo 'shar: not overwriting curses.c'; else
sed 's/^X//' << '________This_Is_The_END________' > curses.c
X/*This is Atari-curses, read the curses.doc file about installing first.
X
XThe archive should contain the following files :
X
XCURSES.C         Source for CURSES, compile once.
XCURSES.H         Include file for CURSES.C and any program using CURSES.
XCURSES.MAN       CURSES short docs, a manual page for UN*X-freaks.
XCURSES.DOC       CURSES long docs, this is what you will want to read when
X                 you are going to use CURSES.
XREADME.TXT       This file.
XTWINKLE.C        Sample application.
XTWINKLE.TOS      Ready to run sample application.
X
X
XThis is essentially a shareware program, its usage is subject to the following
Xconditions :
X
XPUBLIC-DOMAIN       : don't take the credit for it.
XCommercial purposes : Send 5 US-dollars or equivalent currency and return
X                      postage to me to get a written consent to use it.
X
XCURSES may be distributed to anyone, provided that all of the above files
Xremain in the archive, and the various copyright notices remain intact.
X
XBug reports and suggestions are welcome, send me e-mail.
X
XRene van't Veen                  ( ...!mcvax!nikhefh!u13 )
XDebussystraat 27
X1817 GL Alkmaar
XThe Netherlands                                                          */
X/* #[curses: simple-minded implementation of the curses package          */
X/* #[intro: introduction                                                 */
X/*                                                                       */
X/* This source and resulting object may be modified,used or distributed  */
X/* by anyone who so desires under the following conditions :             */
X/*                                                                       */
X/*  1) This notice and the copyright notice shall not be removed or      */
X/*     changed.                                                          */
X/*  2) No credit shall be taken for this source and resulting objects    */
X/*  3) This source or resulting objects is not to be traded, sold or     */
X/*     used for personal gain or profit.                                 */
X/*  4) Inclusion of this source or resulting objects in commercially     */
X/*     available packages is forbidden without written consent of the    */
X/*     author of this source.                                            */
X/*                                                                       */
X/* #]intro:                                                              */
X/* #[include: include files                                              */
X/* #include "portab.h"             No-No for MW C     CJPurcell          */
X
X#include "osbind.h"
X#include "curses.h"
X/* #]include:                                                            */
X/* define supervisor mode entry forgotten in osbind.h                    */
X/* #define Supexec(a) xbios(38,a) available in MW C                      */
X/* terminal states : cooked, cbreak and raw                              */
X#define COOKED 0
X#define CBREAK 1
X#define RAW    2
X/* define address of system-variable _conterm for kbshift return value   */
X#define CONTERM  (*((char *)0x484))
X/* #[globals: definition of global variables                             */
X/* #[curglob: define the following variables as external in curses.h     */
XWINDOW *curscr ;
XWINDOW *stdscr ;
Xchar *Def_term = "AtariST" ;
Xbool My_term = FALSE ;
Xchar *ttytype = "Atari ST-series computer, VT52/CURSES mode" ;
Xint  LINES = 25 ;
Xint  COLS = 80 ;
Xint  ERR = 0 ;
Xint  OK = 1 ;
X/* #]curglob:                */
Xbool   _doecho = FALSE ;
Xbool   _nlmap = FALSE ;
Xbool   _curini = FALSE ;
XBYTE _modinp = 0 ; /* set input to Un*x compatability, i.e only char's */
XBYTE _csry = 0 ;
XBYTE _csrx = 0 ;
Xchar *cpyrid = "Copyright, R. van't Veen. All rights reserved. 1987" ;
X/* #]globals:                */
X/* #[miscel: miscellaneous curses functions         */
X/* #[initscr: initialize the curses package         */
Xinitscr()
X{
X WORD i,j ;
X WINDOW *newwin() ;
X
X if ( _curini )
X  {
X  wrefresh(&curscr) ;
X  if ( cpyrid == NULL )
X   Pterm(-12L) ;
X  ERR = 1 ;
X  OK = 0 ;
X  return ;
X  } ;
X _curini = 1 ;
X curscr = newwin(0,0,0,0) ;
X if ( curscr == NULL )
X  {
X  ERR = 1 ;
X  OK = 0 ;
X  return ;
X  } ;
X stdscr = newwin(0,0,0,0) ;
X if ( stdscr == NULL )
X  {
X  ERR = 1 ;
X  OK = 0 ;
X  return ;
X  } ;
X Bconout(2,'\033') ;
X Bconout(2,'E') ;
X Bconout(2,'\033') ;
X Bconout(2,'w') ;
X Bconout(2,'\033') ;
X Bconout(2,'f') ;
X _csry = 0 ;
X _csrx = 0 ;
X ERR = 0 ;
X OK = 1 ;
X}
X/* #]initscr:                */
X/* #[endwin: end of curses package           */
Xendwin()
X{
X if ( !_curini )
X  {
X  ERR = 1 ;
X  OK = 0 ;
X  return ;
X  } ;
X _curini = 0 ;
X delwin(stdscr) ;
X delwin(curscr) ;
X _movcur(LINES,0) ;
X Bconout(2,'\033') ;
X Bconout(2,'e') ;
X ERR = 1 ;
X OK = 0 ;
X}
X/* #]endwin:                */
X/* #[newwin: create a new window for the user        */
XWINDOW *newwin(l,c,by,bx)
Xint l,c,bx,by ;
X{
X WINDOW *tmp ;
X WORD   i, j, nl, nc ;
X char *malloc() ;
X 
X tmp = ( WINDOW * ) malloc(sizeof(WINDOW)) ;
X if ( tmp == NULL )
X  {
X  ERR = 1 ;
X  OK = 0 ;
X  return(NULL) ;
X  } ;
X tmp->_curx = 0 ;
X tmp->_cury = 0 ;
X tmp->_clear = 0 ;
X tmp->_leave = 0 ;
X tmp->_scroll = 0 ;
X if ( l == 0 )
X  nl = LINES - by ;
X else
X  nl = l ;
X if ( c == 0 )
X  nc = COLS - bx ;
X else
X  nc = c ;
X if ( nl < 1 || nl > LINES || nc < 1 || nc > COLS )
X  {
X  free(tmp) ;
X  ERR = 1 ;
X  OK = 0 ;
X  return(NULL) ;
X  } ;
X tmp->_maxy = nl - 1 ;
X tmp->_maxx = nc - 1 ;
X if ( nl == LINES && nc == COLS )
X  tmp->_flags = _FULLWIN ;
X else
X  tmp->_flags = 0 ;
X if ( by < 0 || by >= LINES || bx < 0 || bx >= COLS )
X  {
X  free(tmp) ;
X  ERR = 1 ;
X  OK = 0 ;
X  return(NULL) ;
X  } ;
X tmp->_begy = by ;
X tmp->_begx = bx ;
X tmp->_y = ( WORD ** ) malloc(sizeof(WORD *)*(tmp->_maxy+1)) ;
X if ( tmp->_y == NULL )
X  {
X  free(tmp) ;
X  ERR = 1 ;
X  OK = 0 ;
X  return(NULL) ;
X  } ;
X tmp->_y[0] = ( WORD * ) malloc(sizeof(WORD)*(tmp->_maxy+1)*(tmp->_maxx+1)) ;
X if ( tmp->_y[0] == NULL )
X  {
X  free(tmp->_y) ;
X  free(tmp) ;
X  ERR = 1 ;
X  OK = 0 ;
X  return(NULL) ;
X  } ;
X for ( i = 1 ; i <= tmp->_maxy ; i++ )
X  tmp->_y[i] = tmp->_y[0] + i * ( tmp->_maxx + 1 ) ;
X for ( i = 0 ; i <= tmp->_maxy ; i++ )
X  {
X  for ( j = 0 ; j <= tmp->_maxx ; j++ )
X   tmp->_y[i][j] = ' ' ;
X  } ;
X/* make everything changed on first update of tmp       */
X touchwin(tmp) ;
X ERR = 0 ;
X OK = 1 ;
X return(tmp) ;
X}
X/* #]newwin:                */
X/* #[delwin: delete a window            */
Xdelwin(w)
XWINDOW *w ;
X{
X if ( w == NULL )
X  {
X  ERR = 1 ;
X  OK = 0 ;
X  return ;
X  } ;
X if ( w->_flags & _SUBWIN )
X  free(w->_y) ;
X else
X  {
X  free(w->_y[0]) ;
X  free(w->_y) ;
X  } ;
X free(w) ;
X ERR = 0 ;
X OK = 1 ;
X}
X/* #]delwin:                */
X/* #[mvwin: move window              */
Xmvwin(w,y,x)
XWINDOW *w ;
Xint y,x ;
X{
X if (y < 0 || x < 0||( y + w->_maxy + 1 )>LINES||( x + w->_maxx + 1 )>COLS) 
X  {
X  ERR = 1 ;
X  OK = 0 ;
X  return ;
X  } ;
X w->_begy = y ;
X w->_begx = x ;
X touchwin(w) ;
X ERR = 0 ;
X OK = 1 ;
X}
X/* #]mvwin:                 */
X/* #[touchwin: touch a window            */
Xtouchwin(w)
XWINDOW *w ;
X{
X WORD i,j ;
X w->_firstch = w->_y[0] ;
X w->_lastch = &(w->_y[w->_maxy][w->_maxx]) ;
X for ( i = 0 ; i <= w->_maxy ; i++ )
X  for ( j = 0 ; j <= w->_maxx ; j++ )
X   w->_y[i][j] = w->_y[i][j] | TOUCHED ;
X ERR = 0 ;
X OK = 1 ;
X}
X/* #]touchwin:                */
X/* #[subwin: create a sub-window           */
XWINDOW *subwin(w,l,c,by,bx)
XWINDOW *w ;
Xint l,c,by,bx ;
X{
X WINDOW *tmp ;
X WORD   i, nl, nc ;
X char *malloc() ;
X 
X/* cannot take subwindows of curscr           */
X if ( w == curscr )
X  {
X  ERR = 1 ;
X  OK = 0 ;
X  return(NULL) ;
X  } ;
X tmp = ( WINDOW * ) malloc(sizeof(WINDOW)) ;
X if ( tmp == NULL )
X  {
X  ERR = 1 ;
X  OK = 0 ;
X  return(NULL) ;
X  } ;
X tmp->_curx = 0 ;
X tmp->_cury = 0 ;
X tmp->_clear = 0 ;
X tmp->_leave = 0 ;
X tmp->_scroll = 0 ;
X if ( l == 0 )
X  nl = LINES - by ;
X else
X  nl = l ;
X if ( c == 0 )
X  nc = COLS - bx ;
X else
X  nc = c ;
X if ( l < 1 || l > (w->_maxy+1) || c < 1 || c > (w->_maxx+1) )
X  {
X  free(tmp) ;
X  ERR = 1 ;
X  OK = 0 ;
X  return(NULL) ;
X  } ;
X tmp->_maxy = nl - 1 ;
X tmp->_maxx = nc - 1 ;
X if ( nl == LINES && nc == COLS )
X  tmp->_flags = _FULLWIN | _SUBWIN ;
X else
X  tmp->_flags = _SUBWIN ;
X if ( by < w->_begy || by >= (w->_maxy+w->_begy) ||
X   bx < w->_begx || bx >= (w->_maxx+w->_begx) )
X  {
X  free(tmp) ;
X  ERR = 1 ;
X  OK = 0 ;
X  return(NULL) ;
X  } ;
X tmp->_begy = by ;
X tmp->_begx = bx ;
X tmp->_y = ( WORD ** ) malloc(sizeof(WORD *)*(tmp->_maxy+1)) ;
X if ( tmp->_y == NULL )
X  {
X  free(tmp) ;
X  ERR = 1 ;
X  OK = 0 ;
X  return(NULL) ;
X  } ;
X tmp->_y[0]=w->_y[0]+(tmp->_begy-w->_begy) * (w->_maxx+2)+(tmp->_maxx-w->_maxx);
X /* I hate these busy lines.Three operands per statement is better.CJPurcell*/
X for ( i = 1 ; i <= tmp->_maxy ; i++ )
X  tmp->_y[i] = tmp->_y[0] + i * ( w->_maxx + 2 ) ;
X/* make everything changed on first update of tmp       */
X touchwin(tmp) ;
X ERR = 0 ;
X OK = 1 ;
X return(tmp) ;
X}
X/* #]subwin:                */
X/* #[leaveok: tell curses where to leave the cursor after updating   */
Xleaveok(w,f)
XWINDOW *w ;
Xbool f ;
X{
X w->_leave = f ;
X ERR = 0 ;
X OK = 1 ;
X}
X/* #]leaveok:                */
X/* #[scrollok: tell curses it is ok to scroll the window     */
Xscrollok(w,f)
XWINDOW *w ;
Xbool f ;
X{
X w->_scroll = f ;
X ERR = 0 ;
X OK = 1 ;
X}
X/* #]scrollok:                */
X/* #[nl: tell curses to map CR to CR,LF          */
Xnl()
X{
X _nlmap = 1 ;
X ERR = 0 ;
X OK = 1 ;
X}
X/* #]nl:                                               */
X/* #[nonl: tell curses not to map CR to CR,LF          */
Xnonl()
X{
X _nlmap = 0 ;
X ERR = 0 ;
X OK = 1 ;
X}
X/* #]nonl:                                              */
X/* #[longname: return the full name of the terminal     */
X/* always returns the contents of ttytype in name       */
Xlongname(termbuf,name)
Xchar *termbuf, *name ;
X{
X int i ;
X 
X for ( i = 0 ; ttytype[i] != '\0' ; i++ )
X  name[i] = ttytype[i] ;
X name[i] = '\0' ;
X}
X/* #]longname:                */
X/* #]miscel:                */
X/* #[output: output functions            */
X/* #[waddch: add a character to a window         */
Xwaddch(w,c)
XWINDOW *w ;
Xchar   c ;
X{
X WORD i, tpos ;
X
X ERR = 0 ;
X OK = 1 ;
X if ( c >= 0x20 )
X  {
X  if ( w == curscr )
X   {
X   if ( ( w->_flags & _STANDOUT ))
X    {
X    w->_y[w->_cury][w->_curx] = c | STANDOUT | TOUCHED ;
X    Bconout(2,'\033') ;
X    Bconout(2,'p') ;
X    Bconout(5,c) ;
X    Bconout(2,'\033') ;
X    Bconout(2,'q') ;
X    }
X   else
X    {
X    w->_y[w->_cury][w->_curx] = c | TOUCHED ;
X    Bconout(5,c) ;
X    } ;
X   _csrx++ ;
X   }
X  else
X   {
X   if ( (w->_flags & _STANDOUT ))
X    w->_y[w->_cury][w->_curx] = c | STANDOUT | TOUCHED ;
X   else
X    w->_y[w->_cury][w->_curx] = c | TOUCHED ;
X   if ( w->_firstch == 0 )
X    {
X    w->_firstch = &(w->_y[w->_cury][w->_curx]) ;
X    w->_lastch = w->_firstch ;
X    }
X   else
X    {
X    if ( w->_firstch > &(w->_y[w->_cury][w->_curx]) )
X     w->_firstch = &(w->_y[w->_cury][w->_curx]) ;
X    else
X     {
X     if ( w->_lastch < &(w->_y[w->_cury][w->_curx]) )
X      w->_lastch = &(w->_y[w->_cury][w->_curx]) ;
X     } ;
X    } ;
X   } ;
X  wmove(w,w->_cury,w->_curx+1) ;
X  }
X else if ( c == '\n' )
X  {
X  wclrtoeol(w) ;
X  if ( _nlmap )
X   wmove(w,w->_cury+1,0) ;
X  else
X   wmove(w,w->_cury+1,w->_curx) ;
X  }
X else if ( c == '\r' )
X  {
X  wmove(w,w->_cury,0) ;
X  }
X else if ( c == '\t' )
X  {
X  tpos = ( w->_curx + w->_begx ) % 8 ;
X  tpos = ( tpos == 0 ) ? 8 : tpos ;
X  for ( i = 0 ; i < tpos ; i++ )
X   waddch(w,' ') ;
X  }
X else
X  {
X  if ( w == curscr )
X   {
X   if ( ( w->_flags & _STANDOUT ))
X    {
X    w->_y[w->_cury][w->_curx] = c | STANDOUT | TOUCHED ;
X    Bconout(2,'\033') ;
X    Bconout(2,'p') ;
X    Bconout(5,c) ;
X    Bconout(2,'\033') ;
X    Bconout(2,'q') ;
X    }
X   else
X    {
X    w->_y[w->_cury][w->_curx] = c | TOUCHED ;
X    Bconout(5,c) ;
X    } ;
X   _csrx++ ;
X   }
X  else
X   {
X   if ( (w->_flags & _STANDOUT ))
X    w->_y[w->_cury][w->_curx] = c | STANDOUT | TOUCHED ;
X   else
X    w->_y[w->_cury][w->_curx] = c | TOUCHED ;
X   if ( w->_firstch == 0 )
X    {
X    w->_firstch = &(w->_y[w->_cury][w->_curx]) ;
X    w->_lastch = w->_firstch ;
X    }
X   else
X    {
X    if ( w->_firstch > &(w->_y[w->_cury][w->_curx]) )
X     w->_firstch = &(w->_y[w->_cury][w->_curx]) ;
X    else
X     {
X     if ( w->_lastch < &(w->_y[w->_cury][w->_curx]) )
X      w->_lastch = &(w->_y[w->_cury][w->_curx]) ;
X     } ;
X    } ;
X   } ;
X  wmove(w,w->_cury,w->_curx+1) ;
X  } ;
X}
X/* #]waddch:                */
X/* #[waddstr: add a string of characters to a window      */
Xwaddstr(w,s)
XWINDOW *w ;
Xchar   *s ;
X{
X WORD  i ;
X 
X ERR = 0 ;
X OK = 1 ;
X for ( i = 0 ; s[i] != '\0' ; i++ )
X  waddch(w,s[i]) ;
X}
X/* #]waddstr:                */
X/* #[box: draw a box around a window          */
Xbox(w,v,h)
XWINDOW *w ;
Xchar v,h ;
X{
X WORD i ;
X 
X ERR = 0 ;
X OK = 1 ;
X for ( i = 0 ; i <= w->_maxy ; i++ )
X  {
X  mvwaddch(w,i,0,v) ;
X  mvwaddch(w,i,w->_maxx,v) ;
X  } ;
X for ( i = 1 ; i < w->_maxx ; i++ )
X  {
X  mvwaddch(w,0,i,h) ;
X  mvwaddch(w,w->_maxy,i,h) ;
X  } ;
X}
X/* #]box:                 */
X/* #[wclear: clear a window             */
Xwclear(w)
XWINDOW *w ;
X{
X ERR = 0 ;
X OK = 1 ;
X werase(w) ;
X clearok(w,TRUE) ;
X w->_curx = 0 ;
X w->_cury = 0 ;
X}
X/* #]wclear:                */
X/* #[wclrtobo: clear a window to the bottom         */
Xwclrtobot(w)
XWINDOW *w ;
X{
X WORD i,j ;
X
X ERR = 0 ;
X OK = 1 ;
X for ( i = w->_curx ; i <= w->_maxx ; i++ )
X  w->_y[w->_cury][i] = ' ' | TOUCHED ;
X for ( i = w->_cury + 1 ; i <= w->_maxy ; i++ )
X  {
X  for ( j = 0 ; j <= w->_maxx ; j++ )
X   w->_y[i][j] = ' ' | TOUCHED ;
X  } ;
X if ( w == curscr )
X  {
X  Bconout(2,'\033') ;
X  Bconout(2,'J') ;
X  }
X else
X  {
X  if ( w->_firstch == 0 )
X   {
X   w->_firstch = &(w->_y[w->_cury][w->_curx]) ;
X   w->_lastch = &(w->_y[w->_maxy][w->_maxx]) ;
X   }
X  else
X   {
X   if ( w->_firstch > &(w->_y[w->_cury][w->_curx]) )
X    w->_firstch = &(w->_y[w->_cury][w->_curx]) ;
X   w->_lastch = &(w->_y[w->_maxy][w->_maxx]) ;
X   } ;
X  } ;
X}
X/* #]wclrtobo:                */
X/* #[wclrtoeo: clear a window to the end of the line      */
Xwclrtoeol(w)
XWINDOW *w ;
X{
X WORD i ;
X
X ERR = 0 ;
X OK = 1 ;
X for ( i = w->_curx ; i <= w->_maxx ; i++ )
X  w->_y[w->_cury][i] = ' ' | TOUCHED ;
X if ( w == curscr )
X  {
X  Bconout(2,'\033') ;
X  Bconout(2,'K') ;
X  }
X else
X  {
X  if ( w->_firstch == 0 )
X   {
X   w->_firstch = &(w->_y[w->_cury][w->_curx]) ;
X   w->_lastch = &(w->_y[w->_cury][w->_maxx]) ;
X   }
X  else
X   {
X   if ( w->_firstch > &(w->_y[w->_cury][w->_curx]) )
X    w->_firstch = &(w->_y[w->_cury][w->_curx]) ;
X   if ( w->_lastch < &(w->_y[w->_cury][w->_maxx]) )
X    w->_lastch = &(w->_y[w->_cury][w->_maxx]) ;
X   } ;
X  } ;
X}
X/* #]wclrtoeo:                */
X/* #[wdelch: delete a character on a window         */
Xwdelch(w)
XWINDOW *w ;
X{
X WORD ox, oy, i ;
X 
X ERR = 0 ;
X OK = 1 ;
X ox = w->_curx ;
X oy = w->_cury ;
X for ( i = ox + 1 ; i <= w->_maxx ; i++ )
X  {
X  w->_y[oy][i-1] = w->_y[oy][i] | TOUCHED ;
X  } ;
X w->_y[oy][w->_maxx] = ' ' | TOUCHED ;
X w->_curx = ox ;
X w->_cury = oy ;
X if ( w == curscr )
X  {
X  Bconout(2,'\033') ;
X  Bconout(2,'K') ;
X  for ( i = w->_curx ; i <= w->_maxx ; i++ )
X   {
X   Bconout(5,(w->_y[w->_cury][i] & 0xff )) ;
X   _csrx++ ;
X   } ;
X  _movcur(w->_cury,w->_curx) ;
X  }
X else
X  {
X  if ( w->_firstch == 0 )
X   {
X   w->_firstch = &(w->_y[w->_cury][w->_curx]) ;
X   w->_lastch = &(w->_y[w->_cury][w->_maxx]) ;
X   }
X  else
X   {
X   if ( w->_firstch > &(w->_y[w->_cury][w->_curx]) )
X    w->_firstch = w->_y[w->_cury] ;
X   if ( w->_lastch < &(w->_y[w->_cury][w->_maxx]) )
X    w->_lastch = &(w->_y[w->_cury][w->_maxx]) ;
X   } ;
X  } ;
X}
X/* #]wdelch:                */
X/* #[wdeletel: delete a line from a window         */
Xwdeleteln(w)
XWINDOW *w ;
X{
X WORD i,j ;
X 
X ERR = 0 ;
X OK = 1 ;
X for ( i = w->_cury + 1 ; i <= w->_maxy ; i++ )
X  {
X  for ( j = 0 ; j <= w->_maxx ; j++ )
X   w->_y[i-1][j] = w->_y[i][j] | TOUCHED ;
X  } ;
X for ( j = 0 ; j <= w->_maxx ; j++ )
X  w->_y[w->_maxy][j] = ' ' | TOUCHED ;
X if ( w == curscr )
X  {
X  Bconout(2,'\033') ;
X  Bconout(2,'M') ;
X  _csrx = 0 ;
X  _movcur(w->_cury,w->_curx) ;
X  }
X else
X  {
X  if ( w->_firstch == 0 )
X   {
X   w->_firstch = w->_y[w->_cury] ;
X   w->_lastch = &(w->_y[w->_maxy][w->_maxx]) ;
X   }
X  else
X   {
X   if ( w->_firstch > w->_y[w->_cury] )
X    w->_firstch = w->_y[w->_cury] ;
X   w->_lastch = &(w->_y[w->_maxy][w->_maxx]) ;
X   } ;
X  } ;
X}
X/* #]wdeletel:                 */
X/* #[werase: erase a window             */
Xwerase(w)
XWINDOW *w ;
X{
X WORD i,j ;
X 
X ERR = 0 ;
X OK = 1 ;
X for ( i = 0 ; i <= w->_maxy ; i++ )
X  {
X  for ( j = 0 ; j <= w->_maxx ; j++ )
X   w->_y[i][j] = ' ' | TOUCHED ;
X  } ;
X if ( w == curscr )
X  {
X  Bconout(2,'\033') ;
X  Bconout(2,'E') ;
X  _csry = 0 ;
X  _csrx = 0 ;
X  _movcur(curscr._cury,curscr._curx) ;
X  }
X else
X  {
X  w->_firstch = w->_y[0] ;
X  w->_lastch = &(w->_y[w->_maxy][w->_maxx]) ;
X  } ;
X}
X/* #]werase:                */
X/* #[winsch: insert a character            */
Xwinsch(w,c)
XWINDOW *w ;
Xchar c ;
X{
X WORD ox,oy,i ;
X BYTE tstr[2] ;
X 
X ERR = 0 ;
X OK = 1 ;
X ox = w->_curx ;
X oy = w->_cury ;
X for ( i = w->_maxx - 1 ; i >= ox ; --i )
X  {
X  w->_y[oy][i+1] = w->_y[oy][i] | TOUCHED ;
X  } ;
X if ( w == curscr )
X  {
X  Bconout(2,'\033') ;
X  Bconout(2,'K') ;
X  for ( i = w->_curx ; i <= w->_maxx ; i++ )
X   {
X   Bconout(5,(w->_y[w->_cury][i] & 0xff )) ;
X   _csrx++ ;
X   } ;
X  _movcur(w->_cury,w->_curx) ;
X  }  
X else
X  {
X  if ( w->_firstch == 0 )
X   {
X   w->_firstch = &(w->_y[w->_cury][w->_curx]) ;
X   w->_lastch = &(w->_y[w->_cury][w->_maxx]) ;
X   }
X  else
X   {
X   if ( w->_firstch > &(w->_y[w->_cury][w->_curx]) )
X    w->_firstch = &(w->_y[w->_cury][w->_curx]) ;
X   if ( w->_lastch < &(w->_y[w->_cury][w->_maxx]) )
X    w->_lastch = &(w->_y[w->_cury][w->_maxx]) ;
X   } ;
X  } ;
X mvwaddch(w,oy,ox,c) ;
X}
X/* #]winsch:                */
X/* #[winsertl: insert a line in a window         */
Xwinsertln(w)
XWINDOW *w ;
X{
X WORD ox,oy,i,j ;
X 
X ERR = 0 ;
X OK = 1 ;
X for ( i = w->_maxy - 1 ; i >= w->_cury ; --i )
X  {
X  for ( j = 0 ; j <= w->_maxx ; j++ )
X   w->_y[i+1][j] = w->_y[i][j] | TOUCHED ;
X  } ;
X for ( j = 0 ; j <= w->_maxx ; j++ )
X  w->_y[w->_cury][j] = ' ' | TOUCHED ;
X if ( w == curscr )
X  {
X  Bconout(2,'\033') ;
X  Bconout(2,'L') ;
X  _csrx = 0 ;
X  _movcur(w->_cury,w->_curx) ;
X  }
X else
X  {
X  if ( w->_firstch == 0 )
X   w->_firstch = w->_y[w->_cury] ;
X  else
X   {
X   if ( w->_firstch > w->_y[w->_cury] )
X    w->_firstch = w->_y[w->_cury] ;
X   } ;
X  w->_lastch = &(w->_y[w->_maxy][w->_maxx]) ;
X  } ;
X}
X/* #]winsertl:                */
X/* #[wmove: move the cursor of the window to a location      */
Xwmove(w,y,x)
XWINDOW *w ;
Xint y,x ;
X{
X WORD i ;
X
X ERR = 0 ;
X OK = 1 ;
X if ( x < 0 )
X  {
X  w->_curx = 0 ;
X  ERR = 1 ;
X  OK = 0 ;
X  }
X else
X  {
X  if ( x > w->_maxx )
X   {
X   w->_curx = w->_maxx ;
X   ERR = 1 ;
X   OK = 0 ;
X   }
X  else
X   w->_curx = x ;
X  } ;
X if ( y < 0 )
X  {
X  w->_cury = 0 ;
X  ERR = 1 ;
X  OK = 0 ;
X  }
X else
X  {
X  if ( y > w->_maxy )
X   {
X   if ( w->_scroll )
X    {
X    for ( i = w->_maxy ; i < y ; i++ )
X     scroll(w) ;
X    } ;
X   w->_cury = w->_maxy ;
X   ERR = 1 ;
X   OK = 0 ;
X   }
X  else
X   w->_cury = y ;
X  } ;
X if ( w == curscr )
X  {
X  _movcur(curscr->_cury,curscr->_curx) ;
X  } ;
X}
X/* #]wmove:                 */ 
X/* #[overlay: overlay two windows.           */
Xoverlay(v,w)
XWINDOW *v, *w ;
X{
X WORD i, j ;
X 
X for ( i = 0 ; i <= w->_maxy && i <= v->_maxy ; i++ )
X  {
X  for ( j = 0 ; j <= w->_maxx && j <= v->_maxx ; j++ )
X   {
X   if ( ( v->_y[i][j] & 0xff ) == 0x20 )
X    w->_y[i][j] = v->_y[i][j] | TOUCHED ;
X   } ;
X  } ;
X if ( w == curscr )
X  wrefresh(curscr) ;
X else
X  {
X  w->_firstch = w->_y[0] ;
X  w->_lastch = &(w->_y[w->_maxy][w->_maxx]) ;
X  } ;
X}
X/* #]overlay:                */
X/* #[overwrit: overwrite two windows.          */
Xoverwrite(v,w)
XWINDOW *v, *w ;
X{
X WORD i, j ;
X 
X for ( i = 0 ; i <= w->_maxy && i <= v->_maxy ; i++ )
X  {
X  for ( j = 0 ; j <= w->_maxx && j <= v->_maxx ; j++ )
X   {
X   w->_y[i][j] = v->_y[i][j] | TOUCHED ;
X   } ;
X  } ;
X if ( w == curscr )
X  wrefresh(curscr) ;
X else
X  {
X  w->_firstch = w->_y[0] ;
X  w->_lastch = &(w->_y[w->_maxy][w->_maxx]) ;
X  } ;
X}
X/* #]overwrit:                */
X/* #[wstandou: set the standout flag for a window       */
Xwstandout(w)
XWINDOW *w ;
X{
X w->_flags = w->_flags | _STANDOUT ;
X ERR = 0 ;
X OK = 1 ;
X}
X/* #]wstandou:                */
X/* #[wstanden: end standout mode           */
Xwstandend(w)
XWINDOW *w ;
X{
X w->_flags = w->_flags & ( ~_STANDOUT) ;
X ERR = 0 ;
X OK = 1 ;
X}
X/* #]wstanden:                */
X/* #]output:                */
X/* #[input: input functions             */
X/* #[raw: set terminal in raw mode           */
Xraw()
X{
X/*
X * raw mode means : 
X * when getting a character from the keyboard, return everything
X * including keyboard shift state.
X */
X  int __sshft() ;
X  
X  if ( _modinp == RAW )
X   return ;
X  Supexec(__sshft) ;
X  _modinp = RAW ;
X}
X/* #]raw:                 */
X/* #[noraw: reset terminal from raw mode into cooked mode     */
Xnoraw()
X{
X int __ushft() ;
X if ( _modinp != RAW )
X  return ;
X Supexec(__ushft) ;
X _modinp = COOKED ;
X}
X/* #]noraw:                 */
X/* #[__sshft: set terminal to return keyboard shift state     */
X/* execute in supervisor mode only           */
X__sshft()
X{
X int ov, nv ;
X 
X ov = CONTERM ;
X nv = ov | 0x08 ;
X CONTERM = nv ;
X}
X/* #]__sshft:                */
X/* #[__ushft: set terminal to not return keyboard shift state    */
X/* execute in supervisor mode only           */
X__ushft()
X{
X int ov, nv ;
X 
X ov = CONTERM ;
X nv = ov & ~0x08 ;
X CONTERM = nv ;
X}
X/* #]__ushft:                */
X/* #[crmode: set terminal in cbreak mode         */
X/*
X * cbreak mode means for the atari ;
X * return both keyboard scan code as well as the character value.
X * kill the process with a process terminate -1 as soons as a control C is met
X * control D is also recognized to be the EOF.
X */
Xcrmode()
X{
X if ( _modinp == CBREAK )
X  return ;
X if ( _modinp == RAW )
X  noraw() ;
X _modinp = CBREAK ;
X}
X/* #]crmode:                */
X/* #[nocrmode: reset terminal from cbreak into cooked mode     */  
Xnocrmode()
X{
X if ( _modinp != CBREAK )
X  return ;
X _modinp = COOKED ;
X}
X/* #]nocrmode:                */
X/* #[echo: set curses to echo characters on input       */
Xecho()
X{
X _doecho = TRUE ;
X ERR = 0 ;
X OK = 1 ;
X}
X/* #]echo:                 */
X/* #[noecho: set curses not to echo characters on input      */
Xnoecho()
X{
X _doecho = FALSE ;
X ERR = 0 ;
X OK = 1 ;
X}
X/* #]noecho:                */
X/* #[wgetch: get a character from the terminal        */
X/* WARNING : wgetch returns a 32-bit value, not a char although only  */
X/* the lowest 8 bits may actually be transmitted.       */
Xlong wgetch(w) WINDOW *w ;
X{
X bool reset ;
X LONG retval ;
X
X reset = FALSE ;
X if ( _modinp == COOKED && _doecho == TRUE )
X  {
X  reset = TRUE ;
X  crmode() ;
X  } ;
X Bconout(2,'\033') ;
X Bconout(2,'e') ;
X switch ( _modinp )
X  {
X  case COOKED:
X   while ( !Cconis() ) ;
X   retval = Cnecin() ;
X   retval = retval & 0x00ff ;
X/* kill process on control C            */
X   if ( retval == 0x03 )
X    Pterm(-1L) ;
X   break ;
X  case CBREAK:
X   while ( !Cconis() ) ;
X   retval = Cnecin() ;
X/* kill process on control C            */
X   if ( ( retval & 0x00ff ) == 0x03 )
X    Pterm(-1L) ;
X   break ;
X  case RAW:
X   while ( !Cconis() ) ;
X   retval = Crawcin() ;
X   break ;
X  } ;
X Bconout(2,'\033') ;
X Bconout(2,'f') ;
X if ( _doecho )
X  waddch(w,(char ) ( 0x00ff & retval )) ;
X if ( reset )
X  nocrmode() ;
X return(retval) ;
X}
X/* #]wgetch:                */
X/* #[wgetstr: get a string from the terminal        */
Xwgetstr(w,s)
XWINDOW *w ;
Xchar *s ;
X{
X WORD ox, oy ;
X bool reset, end ;
X char c ;
X int i ;
X long wgetch() ;
X 
X reset = FALSE ;
X getyx(w,oy,ox) ;
X if ( _modinp == COOKED && _doecho == TRUE )
X  {
X  reset = TRUE ;
X  _doecho = FALSE ;
X  } ;
X i = 0 ;
X for ( end = FALSE ; !end ; i++ )
X  { 
X  switch ( _modinp )
X   {
X   case COOKED:
X    c = ( char ) wgetch(w) ;
X    if ( c != 0x0d && c != 0x0a && c != 0x04 && c != 0 )
X     {
X     s[i] = '\0' ;
X     end = TRUE ;
X     break ;
X     } ;
X/* receive a backspace */
X    if ( c == 0x08 )
X     {
X     if ( i != 0 )
X      {
X      --i ;
X      s[i] = 0 ;
X      if ( reset )
X       mvwaddstr(w,oy,ox,s) ;
X      } ; 
X     break ;
X     } ;
X/* receive control U or line kill            */
X    if ( c == 0x13 )
X     {
X     i = 0 ;
X     if ( reset )
X      wmove(w,oy,ox) ;
X     break ;
X     } ;
X    s[i] = c ;
X    if (reset)
X     waddch(w,c) ;
X    break ;
X   case CBREAK:
X    c = ( char ) wgetch(w) ;
X    if ( c != 0x0d && c != 0x0a && c != 0x04 && c != 0 )
X     {
X     s[i] = '\0' ;
X     end = TRUE ;
X     break ;
X     } ;
X    s[i] = c ;
X    break ;
X   case RAW:
X    c = ( char ) wgetch(w) ;
X    if ( c != 0x0d && c != 0x0a && c != 0x04 && c != 0 )
X     {
X     s[i] = '\0' ;
X     end = TRUE ;
X     break ;
X     } ;
X    s[i] = c ;
X    break ;
X   } ;
X  } ;
X if ( reset )
X  _doecho = TRUE ;
X}
X/* #]wgetstr:                */
X/* #]input:                 */
X/* #[wrefresh: refresh a window on the screen        */
Xwrefresh(w)
XWINDOW *w ;
X{
X WORD i,j,k,l ;
X WORD c, *ptr ;
X 
X ERR = 0 ;
X OK = 1 ;
X if ( w != curscr && curscr->_clear )
X  {
X  Bconout(2,'\033') ;
X  Bconout(2,'E') ;
X  _csry = 0 ;
X  _csrx = 0 ;
X  for ( i = 0 ; i < LINES ; i++ )
X   {
X   for ( j = 0 ; j < COLS ; j++ )
X    curscr->_y[i][j] = ' ' ;
X   } ;
X  curscr->_clear = 0 ;
X  } ;
X if ( w->_clear )
X  {
X  if ( ( w->_flags & _FULLWIN ) )
X   {
X   Bconout(2,'\033') ;
X   Bconout(2,'E') ;
X   _csry = 0 ;
X   _csrx = 0 ;
X   for ( i = 0 ; i < LINES ; i++ )
X    {
X    for ( j = 0 ; j < COLS ; j++ )
X     curscr->_y[i][j] = ' ' ;
X    } ;
X   } ;
X  w->_firstch = w->_y[0] ;
X  w->_lastch = &(w->_y[w->_maxy][w->_maxx]) ;
X  w->_clear = 0 ;
X  } ;
X if ( w != curscr )
X  {
X  if ( w->_firstch != 0 )
X   {
X   if ( w->_flags & _SUBWIN )
X    {
X    for ( i = 0 ; i <= w->_maxy ; i++ )
X     {
X     ptr = w->_y[i] ;
X     if ( ptr >= w->_firstch && ptr <= w->_lastch )
X      {
X      for ( j = 0 ; j <= w->_maxx ; j++ )
X       {
X       c = ptr[j] ;
X       k = i + w->_begy ;
X       l = j + w->_begx ;
X       if ( ( c & TOUCHED ) && ( k >= 0 && k < LINES && l >= 0 && l < COLS ) )
X        {
X        ptr[j] = c & ~TOUCHED ;
X        if ( ( curscr->_y[k][l] & 0x01ff ) != ( c & 0x01ff ) )
X         {
X         curscr->_y[k][l] = c ;
X         _movcur(k,l) ;
X         if ( ( c & STANDOUT ) )
X          {
X          Bconout(2,'\033') ;
X          Bconout(2,'p') ;
X          Bconout(5,(c & 0xff)) ;
X          Bconout(2,'\033') ;
X          Bconout(2,'q') ;
X          }
X         else
X          {
X          Bconout(5,( c & 0xff )) ;
X          } ;
X         _csry = k ;
X         _csrx = l + 1 ;
X         } ;
X        } ;
X       } ;
X      } ;
X     } ;
X    }
X   else
X    {
X    for ( ptr = w->_firstch ; ptr <= w->_lastch ; ptr++ )
X     {
X     c = *ptr ;
X     if ( c & TOUCHED )
X      {
X      k = ( WORD ) ( ptr - w->_y[0] ) ;
X      k = k / (  w->_maxx + 1 ) ;
X      l = ( WORD ) ( ptr - w->_y[k] ) + w->_begx ;
X      k = k + w->_begy ;
X      if ( k >= 0 && k < LINES && l >= 0 && l < COLS ) 
X       {
X       *ptr = c & ~TOUCHED ;
X       if ( ( curscr->_y[k][l] & 0x01ff ) != ( c & 0x01ff ) )
X        {
X        curscr->_y[k][l] = c ;
X        _movcur(k,l) ;
X        if ( ( c & STANDOUT ) )
X         {
X         Bconout(2,'\033') ;
X         Bconout(2,'p') ;
X         Bconout(5,(c & 0xff)) ;
X         Bconout(2,'\033') ;
X         Bconout(2,'q') ;
X         }
X        else
X         {
X         Bconout(5,( c & 0xff )) ;
X         } ;
X        _csry = k ;
X        _csrx = l + 1 ;
X        } ;
X       } ;
X      } ;
X     } ;
X    } ;
X   w->_firstch = 0 ;
X   w->_lastch = 0 ;
X   if ( w->_leave )
X    {
X    w->_curx = _csrx - w->_begx ;
X    w->_cury = _csry - w->_begy ;
X    curscr->_cury = _csry ;
X    curscr->_curx = _csrx ;
X    }
X   else
X    {
X    curscr->_cury = w->_cury + w->_begy ;
X    curscr->_curx = w->_curx + w->_begx ;
X    _movcur(curscr->_cury, curscr->_curx) ;
X    } ;
X   }
X  else
X   {
X   curscr->_cury = w->_cury + w->_begy ;
X   curscr->_curx = w->_curx + w->_begx ;
X   _movcur(curscr->_cury, curscr->_curx) ;
X   } ;
X  }
X else
X  {
X  Bconout(2,'\033') ;
X  Bconout(2,'H') ;
X  _csry = 0 ;
X  _csrx = 0 ;
X  for ( i = 0 ; i < LINES ; i++ )
X   {
X   for ( j = 0 ; j < COLS ; j++ )
X    {
X    c = w->_y[i][j] ;
X    if ( ( c & STANDOUT ) )
X     {
X     Bconout(2,'\033') ;
X     Bconout(2,'p') ;
X     Bconout(5,(c & 0xff)) ;
X     Bconout(2,'\033') ;
X     Bconout(2,'q') ;
X     }
X    else
X     {
X     Bconout(5,(c & 0xff)) ;
X     } ;
X    _csrx++ ;
X    } ;
X   _movcur(i+1,0) ;
X   } ;
X  _movcur( curscr->_cury, curscr->_curx) ; 
X  } ;
X}
X/* #]wrefresh:                */
X/* #[detail: detail functions of curses          */
X/* #[mvcur: move cursor in standard curses manner       */
Xmvcur(ly,lx,ny,nx)
Xint ly,lx,ny,nx ;
X{
X _movcur((WORD) ny,( WORD) nx) ;
X}
X/* #]mvcur:                 */
X/* #[_movcur: move cursor             */
X_movcur(y,x)
XWORD y,x ;
X{
X if ( _csry == y && _csrx == x )
X  return ;
X Bconout(2,'\033') ;
X Bconout(2,'Y') ;
X Bconout(2,y+' ') ;
X Bconout(2,x+' ') ;
X _csry = y ;
X _csrx = x ;
X}
X/* #]_movcur:                */
X/* #[scroll: scroll a window upward one line        */
Xscroll(w)
XWINDOW *w ;
X{
X WORD i,j ;
X 
X ERR = 0 ;
X OK = 1 ;
X for ( i = 0 ; i < w->_maxy ; i++ )
X  for ( j = 0 ; j <= w->_maxx ; j++ )
X   w->_y[i][j] = w->_y[i+1][j] ;
X for ( i = 0 ; i <= w->_maxx ; i++ )
X  w->_y[w->_maxy][i] = ' ' ;
X if ( w == curscr )
X  wrefresh(curscr) ;
X else
X  {
X  w->_firstch = w->_y[0] ;
X  w->_lastch = &(w->_y[w->_maxy][w->_maxx]) ;
X  } ;
X}
X/* #]scroll:                */
X/* #]detail:                */
X/* #]curses:                */
________This_Is_The_END________
if test `wc -l < curses.c` -ne 1384; then
	echo 'shar: curses.c was damaged during transit (should have been 1384 lines)'
fi
fi		; : end of overwriting check
echo 'x - curses.h'
if test -f curses.h; then echo 'shar: not overwriting curses.h'; else
sed 's/^X//' << '________This_Is_The_END________' > curses.h
X/* ************************************************************************ */
X/*                                                                          */
X/*   CURSES.H                      include file for programs using CURSES   */
X/*                                                                          */
X/* ************************************************************************ */
X/*                    */
X/* This source and resulting object may be modified, used or distributed by */
X/* anyone who so desires under the following conditions :                   */
X/*                   */
X/*  1) This notice and the copyright notice shall not be removed or     */
X/*     changed.               */
X/*  2) No credit shall be taken for this source and resulting objects   */
X/*  3) This source or resulting objects is not to be traded, sold or    */
X/*     used for personal gain or profit.        */
X/*  4) Inclusion of this source or resulting objects in commercially    */
X/*     available packages is forbidden without written consent of the   */
X/*     author of this source.           */
X/*                                                                          */
X/* ************************************************************************ */
X
X#include "portab.h"
X#include "stdio.h"
X
X#define reg   register
X#define bool  BYTE
X/* #define TRUE  1
X#define FALSE        0 */
X
X#define _SUBWIN  01
X#define _ENDLINE 02
X#define _FULLWIN 04
X#define _SCROLLWIN 010
X#define _STANDOUT 0200
X#define WINDOW  struct _win_st
X
X#define TOUCHED  0x0200
X#define STANDOUT 0x0100
X
X#define addch(c)   waddch(stdscr, c)
X#define mvaddch(y,x,c)  { wmove(stdscr,y,x) ; waddch(stdscr,c) ; }
X#define mvwaddch(w,y,x,c) { wmove(w,y,x) ; waddch(w,c) ; }
X#define addstr(s)   waddstr(stdscr,s)
X#define mvaddstr(y,x,s)  { wmove(stdscr,y,x) ; waddstr(stdscr,s) ; }
X#define mvwaddstr(w,y,x,s) { wmove(w,y,x) ; waddstr(w,s) ; }
X#define clear()    wclear(stdscr)
X#define clearok(w,f)  { w->_clear = (w->_flags & _FULLWIN) ? f : w->_clear ; }
X#define clrtobot()   wclrtobot(stdscr)
X#define clrtoeol()   wclrtoeol(stdscr)
X#define delch()    wdelch(stdscr)
X#define mvdelch(y,x)  { wmove(stdscr,y,x) ; wdelch(stdscr) ; }
X#define mvwdelch(w,y,x)  { wmove(w,y,x) ; wdelch(w) ; }
X#define deleteln()   wdeleteln(stdscr)
X#define mvdeleteln(y,x)  { wmove(stdscr,y,x) ; wdeleteln(stdscr) ; }
X#define mvwdeleteln(w,y,x) { wmove(w,y,x) ; wdeleteln(w) ; }
X#define erase()    werase(stdscr)
X#define insch(c)   winsch(stdscr,c)
X#define mvinsch(y,x,c)  { wmove(stdscr,y,x) ; winsch(stdscr,c) ; }
X#define mvwinsch(w,y,x,c) { wmove(w,y,x) ; winsch(w,c) ; }
X#define insertln()   winsertln(stdscr)
X#define mvinsertln(y,x)  { wmove(stdscr,y,x) ; winsertln(stdscr) ; }
X#define mvwinsertln(w,y,x) { wmove(w,y,x) ; winsertln(w) ; }
X#define move(y,x)   wmove(stdscr,y,x)
X#define refresh()   wrefresh(stdscr)
X#define standout()   wstandout(stdscr)
X#define standend()   wstandend(stdscr)
X#define getch()    wgetch(stdscr)
X#define mvgetch(y,x)  ( wmove(stdscr,y,x) , wgetch(stdscr) )
X#define mvwgetch(w,y,x)  ( wmove(w,y,x) , wgetch(w) )
X#define getstr(s)   wgetstr(stdscr,s)
X#define mvgetstr(y,x,s)  { wmove(stdscr,y,x) ; wgetstr(stdscr,s) ; }
X#define mvwgetstr(w,y,x,s) { wmove(w,y,x) ; wgetstr(w,s) ; }
X#define getyx(w,y,x)  { y = w->_cury ; x = w->_curx ; }
X#define inch()    (stdscr->_y[stdscr->_cury][stdscr->_curx])
X#define mvinch(y,x)   ( wmove(stdscr,y,x) , stdscr->_y[stdscr->_cury][stdscr->_curx])
X#define mvwinch(w,y,x)  ( wmove(w,y,x) , w4->_y[w->_cury][w->_curx])
X#define winch(w)   (w->_y[w->_cury][w->_curx])
X
Xstruct _win_st {
X WORD _cury, _curx ;
X WORD _maxy, _maxx ;
X WORD _begy, _begx ;
X WORD _flags ;
X BYTE _clear ;
X BYTE _leave ;
X BYTE _scroll ;
X WORD **_y ;
X WORD *_firstch ;
X WORD *_lastch ;
X} ;
X
Xextern WINDOW *curscr ;
Xextern WINDOW *stdscr ;
Xextern char *Def_term ;
Xextern bool My_term ;
Xextern char *ttytype ;
Xextern int LINES ;
Xextern int COLS ;
Xextern int ERR ;
Xextern int OK ;
X****************END OF SOURCE CURSES.H************************************
________This_Is_The_END________
if test `wc -l < curses.h` -ne 100; then
	echo 'shar: curses.h was damaged during transit (should have been 100 lines)'
fi
fi		; : end of overwriting check
echo 'x - curses.man'
if test -f curses.man; then echo 'shar: not overwriting curses.man'; else
sed 's/^X//' << '________This_Is_The_END________' > curses.man
X
XCURSES(3X)                                                        CURSES(3X)
X
X
XNAME
X
X    curses - screen functions with "optimal" cursor motion
X
X
XDESCRIPTION
X
X   The functions in the curses-package give you an implementation of the
XUN*X-curses package for the Atari ST series computer. It allows you to do
Xterminal-oriented graphics of a crude nature. An image is kept of what the
Xcurrent screen looks like, while the user creates a new image. Refresh()
Xmust be called to make the current screen look like the one the user has
Xprepared. Initscr() must be called to initialize the package and endwin()
Xto clean up before exiting.
X
XSEE ALSO
X
X   Screen Updating and Cursor Movement Optimization : A Library Package,
X       Ken Arnold.
X   The CURSES screen updating and cursor movement package : A collection
X       of C-functions for the Atari ST-series computers, R. van 't Veen.
X
XAUTHORS
X
X   UN*X-curses  : Ken Arnold.
X   Atari-curses : Rene van 't Veen.
X
XFUNCTIONS
X
X   addch(c)                                  add a character to stdscr
X   addstr(s)                                 add a string to stdscr
X   box(win,v,h)                              draw a box around a window
X   crmode()                                  set cbreak mode
X   clear()                                   clear stdscr
X   clearok(scr,f)                            set clear flag for scr
X   cltobot()                                 clear to bottom on stdscr
X   clrtoeol()                                clear to end of line on stdscr
X   delch()                                   delete a character
X   deleteln()                                delete a line
X   delwin(w)                                 delete window w
X   echo()                                    set echo mode
X   endwin()                                  end window mode
X   erase()                                   erase stdscr
X   getch()                                   get a char through stdscr
X   getstr()                                  get a string through stdscr
X   getyx(w,y,x)                              get current coordinates
X   inch()                                    get char at current coordinates
X   initscr()                                 initialize curses
X   insch()                                   insert a character
X   insertln()                                insert a line
X   leaveok(w,f)                              set leave flag for window w
X   longname(termbuf, name)                   get a long terminal name
X   move(y,x)                                 move to (y,x) on stdscr
X   mvcur(ly,lx,ny,nx)                        actually move the cursor
X   newwin(lines,cols,begin_y,begin_x)        create a window
X   nl()                                      set newline mapping on
X   nocrmode()                                unset cbreak mode
X   noecho()                                  unset echo mode
X   nonl()                                    set newline mapping off
X   noraw()                                   unset raw mode
X   overlay(win1,win2)                        overlay win1 on win2
X   overwrite(win1,win2)                      overwrite win1 on win2
X   raw()                                     set raw mode
X   refresh()                                 make terminal look like stdscr
X   scroll(win)                               scroll win one line up
X   scrollok(w,f)                             set scroll flag for window win
X   standend()                                leave standout mode
X   standout()                                enter standout mode
X   subwin(win,lines,cols,begin_y,begin_x)    create a sub window
X   touchwin(win)                             change everything on win
X   waddch(win,c)                             add char to win
X   waddstr(win,s)                            add string to win
X   wclear(w)                                 clear w
X   wclrtobot(w)                              clear w to bottom of w
X   wclrtoeol(w)                              clear w to end of line
X   wdelch(w)                                 delete character from w
X   wdeleteln(w)                              delete line from w
X   werase(w)                                 erase w
X   wgetch(w)                                 get a character through w
X   wgetstr(w,s)                              get a string through w
X   winch(w)                                  get char at current (y,x) of w
X   winsch(w,c)                               insert a char on w
X   winsertln(w)                              insert a line on w
X   wmove(w,y,x)                              set current coordinates of w
X   wrefresh(w)                               make terminal look like w
X   wstandend(w)                              leave standout mode for w
X   wstandout(w)                              enter standout mode for w
X
XBUGS
X
X   Hopefully none, but you never know ...
X   If you find any, please let me know, 
X   I ( Rene ) am at ..!mcvax!nikhefh!u13 .
________This_Is_The_END________
if test `wc -l < curses.man` -ne 97; then
	echo 'shar: curses.man was damaged during transit (should have been 97 lines)'
fi
fi		; : end of overwriting check
echo 'x - twinkle.c'
if test -f twinkle.c; then echo 'shar: not overwriting twinkle.c'; else
sed 's/^X//' << '________This_Is_The_END________' > twinkle.c
X/* sample application using curses calls, this takes about 25 seconds on the */
X/* Atari and over 6 minutes on a mainframe, using a vt100 on a 4800 baud     */
X/* line. Even on the mainframe it uses 24 seconds of computation time.       */
X/* see copyright notice in curses.c                                          */
X/* #include "portab.h" forbidden in MW C                                     */
X
X#include "curses.h"
X
X#define NCOLS 80
X#define NLINES 24
X#define MAXPATT 4
X
Xstruct locs {
X char y,x ;
X } ;
X
Xtypedef struct locs LOCS ;
X
XLOCS Layout[NCOLS*NLINES] ;;
X
Xint pat ;
Xint nstar ;
X
Xmain()
X{
X int i ;
X
X initscr() ;
X leaveok(stdscr,1) ;
X for ( i = 0 ; i < 10 ; i++ )
X  {
X  makeboard() ;
X  puton('*') ;
X  puton(' ') ;
X  } ;
X endwin() ;
X}
X
Xmakeboard()
X{
X int y,x ;
X LOCS *lp ;
X 
X pat = rand() % MAXPATT ;
X lp = Layout ;
X for ( y = 0 ; y < NLINES ; y++ )
X  for ( x = 0 ; x < NCOLS ; x++ )
X   if ( ison(y,x) )
X    {
X    lp->y = y ;
X    lp->x = x ;
X    lp++ ;
X    } ;
X nstar = lp - Layout ;
X}
X
Xison(y,x)
Xint y,x ;
X{
X switch ( pat )
X  {
X  case 0:
X   return(!(y & 0x01)) ;
X  case 1:
X   if ( x >= NLINES && y >= NCOLS )
X    return(0) ;
X   if ( y < 3 || y >= NLINES - 3 )
X    return(1) ;
X   return((x < 3 || x >= NCOLS - 3 )) ;
X  case 2:
X   return(((x+y) & 0x01)) ;
X  case 3:
X   return(( y>= 9 && y <= 15 )) ;
X  } ;
X}
X
Xputon(ch)
Xchar ch ;
X{
X LOCS  *lp, *end, temp ;
X int r ;
X 
X end = &(Layout[nstar]) ;
X for ( lp = Layout ; lp < end ; lp++ )
X  {
X  r = rand() % nstar ;
X  temp = *lp ;
X  *lp = Layout[r] ;
X  Layout[r] = temp ;
X  } ;
X for ( lp = Layout ; lp < end ; lp++ )
X  {
X  mvaddch(lp->y,lp->x,ch) ;
X  refresh() ;
X  } ;
X}
________This_Is_The_END________
if test `wc -l < twinkle.c` -ne 96; then
	echo 'shar: twinkle.c was damaged during transit (should have been 96 lines)'
fi
fi		; : end of overwriting check
exit 0