[comp.sources.atari.st] v02i091: curses -- Screen updating package part02/02

koreth@panarthea.ebay.sun.com (Steven Grimm) (10/13/89)

Submitted-by: gray@hplb.hpl.hp.com (Graham Higgins)
Posting-number: Volume 2, Issue 91
Archive-name: curses/part02

#!/bin/sh
# this is part 2 of a multipart archive
# do not concatenate these parts, unpack them in order with /bin/sh
# file curses.doc continued
#
CurArch=2
if test ! -r s2_seq_.tmp
then echo "Please unpack part 1 first!"
     exit 1; fi
( read Scheck
  if test "$Scheck" != $CurArch
  then echo "Please unpack part $Scheck next!"
       exit 1;
  else exit 0; fi
) < s2_seq_.tmp || exit 1
sed 's/^X//' << 'SHAR_EOF' >> curses.doc
Xkeyboard and echoes it through addch() if echo is set. When using curses
Xyou may notice that, while performing output and other functions, the cursor
Xis switched off, when curses waits for input however the cursor is switched
Xon. Input can be done in either one of three modes : cooked, cbreak and raw.
XThese input modes are primarily introduced to maintain UN*X-compatability, but
Xthey do not work the same, so when porting UN*X-programs special care should
Xbe taken with any input routines. Moreover, you should not perform any input
Xthrough the stdio library, as they will surely echo something on the screen.
XUN*X-curses can handle this because it explicitly sets the echo of the terminal
Xoff, whereas Atari-curses only simulates this behaviour. So : any input only
Xthrough curses.
X   Cooked mode is supposed to be a line-oriented input interface. Using UN*X
Xand curses, cooked input can only be performed, when echo is not set, if it
Xis set cooked mode input turns to cbreak mode for the duration of the
Xinput call. Using Atari and curses, the same restrictions apply, with the
Xexception that the following characters have special meanings :
X
X+---------------+-------+------------------------------------------+
X| character     | ASCII | action                                   |
X+===============+=======+==========================================+
X| control-C     |   $03 | do a Pterm(-1), i.e. exit immediately    |
X| control-H/BS  |   $08 | do a backspace, not beyond the beginning |
X|               |       | of the input-field.                      |
X| control-U     |   $13 | kill the entire input field              |
X+---------------+-------+------------------------------------------+
X
X   Cbreak mode is supposed to be a single character oriented interface, with
Xwhich one can receive any character and have no special meaning attached to it.
XThe only exceptions are job-control characters like control-C ( interrupt ),
Xdelete ( kill the process ), control-Z ( suspend the process ) etc. On Atari
Xthis is translated in the following : all characters are received and only
Xcontrol-C has special meaning, which is : terminate the process.
X   Raw mode is also a single character interface and has no special processing
Xwhatsoever. The same holds for Atari.
X   Apart from the above-mentioned functions one should also note that
Xgetch() does not return a character, but a 32-bit value. For UN*X getch()
Xreturns an int, with ( apart from errors ) only the lower 7 or 8 bits set.
XOn Atari the same holds true for cooked mode, in cbreak mode the ASCII value
Xis returned in bits 0 to 7 and the scancode of the key in bits 16 to 23, raw
Xmode adds the keyboard shift state in bits 24 to 30. When entering a string
Xthrough getstr() or wgetstr() only the character portion of the long values
Xare retained.
X   Cleaning up is performed by the endwin() function. It releases the storage
Xacquired for curscr and stdscr, switches the terminal to its normal state
Xand puts the cursor in a reasonably comfortable place, i.e. at the bottom
Xof the screen. Note that any windows acquired through newwin() and subwin()
Xstill exist. They should be released from storage prior to calling endwin().  
X
X
X   Constants, types and variables defined by curses.h.
X   
X   The include file curses.h makes several constants, types and variables
Xavailable to the programmer. In this section something will be told about
Xtheir function and use.
X   The most important thing defined in curses.h is the data type WINDOW. This
Xdatatype is used by curses to maintain data for all windows. It has the
Xfollowing definition :
X
X#define      WINDOW         struct _win_st
X
Xstruct _win_st {
X    WORD   _cury, _curx ;
X    WORD   _maxy, _maxx ;
X    WORD   _begy, _begx ;
X    WORD   _flags ;
X    bool   _clear ;
X    bool   _leave ;
X    bool   _scroll ;
X    WORD   **_y ;
X    WORD   *_firstch ;
X    WORD   *_lastch ;
X    } ;
X
XThe internals of this structure are not normally to be accessed by the user.
XThis structure differs in three aspects from the UN*X-curses WINDOW structure.
XFirst of all the _y field is char in UN*X-curses, WORD in Atari-curses. This
Xhad been done to ensure that all characters in the Atari character set, 
Xincluding all diacritical marks, can be displayed, whereas UN*X-curses will
Xonly display characters $20-$7f, or standard ASCII characters. As a matter
Xof act the Atari will display codes $00-$ff, with the exception of tabs,
Xlinefeeds and carriage returns. These have a special meaning.
X Each character can be in standout mode, if so desired. The other changes are
Xin the _firstch, _lastch fields. This reflects the updating algorithms used.
X   The fields have the following meaning : _cury and _curx are the current
Xcoordinates of the window, relative to the window's home, _begy and _begx. This
Xbeginning is relative to the terminals home position (0,0). _maxy and _maxx are
Xthe maximum values allowed for _cury and _curx. _flags is a bit-pattern
Xof several flags describing the structure of the window. _flags can have 
Xseveral values OR'ed into it. _SUBWIN means that the window is a subwindow,
Xwhich indicates to delwin() that the character space cannot be freed. The 
X_FULLWIN flag indicates that the window is a screen. _STANDOUT means that any
Xadded character is in standout-mode. UN*X-curses also defines the _ENDLINE
Xand _SCROLLWIN flags, they are defined in curses.h for compatability purposes,
Xbut Atari-curses does nothing with these values. The _clear field in the
XWINDOW structure is set when the next refresh on the window should generate
Xa clear screen sequence. Setting the clear flag for curscr will always
Xgenerate a clear screen sequence on any refresh. The _leave field is TRUE
Xif the windows current coordinates are to be set after the last character
Xchanged on the terminal after a refresh. The _scroll field is TRUE, if
Xscrolling is allowed. The _y field is a pointer to an array of pointers to
Xarrays of character values. These values are the actual contents of a window.
XThe lower 8 bits of a character value contain the real character value, the
Xupper 8 bits are used by curses internally. The _firstch and _lastch fields
Xare used by the updating algorithms of curses. Unless you know what you are
Xdoing you are not supposed to tamper with any of these values, curses supplies
Xa full set of functions to set any values which you want to be set.
X   After initializing curses you can be sure the following variables have been
Xset and initialized to their proper values. Some variables may even be set
Xprior to initializing curses. This is marked by a & in the table.
X
X+----------------+------------+-----------------------------------------------+
X| variable name  | type       | description                                   |
X+================+============+===============================================+
X| curscr         | WINDOW *   | curses idea of what the terminal screen looks |
X|                |            | like.                                         |
X| stdscr         | WINDOW *   | Default screen for updates.                   |
X| Def_term       | char *     | Default terminal type. UN*X-compatability.    |
X| My_term      & | bool       | UN*X-compatability, does nothing.             |
X| ttytype        | char *     | Full name of the terminal                     |
X| LINES        & | int        | Number of ines curses thinks the terminal has |
X|                |            | normally 25, but may be changed, see text     |
X| COLS         & | int        | Number of columns curses thinks the terminal  |
X|                |            | has, may be changed, see text.                |
X| ERR            | int        | If this is set, curses had an internal error  |
X| OK             | int        | If this is set, everything is gone right      |
X+----------------+------------+-----------------------------------------------+
X
X   Also the following constants and macros are defined in curses.h :
X
X+----------------+------------------------------------------------------------+
X| name           | description                                                |
X+================+============================================================+
X| reg            | storage class register, i.e. register int i => reg int i   |
X| bool           | boolean type, values can be TRUE or FALSE                  |
X| TRUE           | boolean 'true' flag.                                       |
X| FALSE          | boolean 'false' flag.                                      |
X+----------------+------------------------------------------------------------+
X
X   Another difference between Atari-curses and UN*X-curses is that UN*X-curses
Xreads in a lot of variables described in /etc/termcap, no such thing exists
Xfor Atari, and is not needed anyway. However these variables are available
Xto the programmer in UN*X-curses, but not in Atari-curses. These include
Xthings like strings, which when output to the terminal cause some action to be
Xtaken, like the string VB, for a visible bell, or DM, enter delete mode. Care
Xshould be taken with UN*X-programs that perform such actions.
X
X
X   Description of individual functions.
X   
X   The following is a description of all the individual routines, a lot of them
Xare defined as macros, notably those that take stdscr as the window and
Xfunctions that can be preceded by "mv". If such is the case, it is stated by
Xa '!' a little further on the line.
X
X   Output functions.
X   
X
Xaddch(c)                  !
Xchar c ;
X
Xmvaddch(y,x,c)            !
Xint y,x ;
Xchar c ;
X
Xmvwaddch(win,y,x,c)       !
XWINDOW *win ;
Xint y,x ;
Xchar c ;
X
Xwaddch(win,c)
XWINDOW *win ;
Xchar c ;
X
X   Add the character c at the current coordinates of the window w. The
Xfollowing characters cause special processing : a newline ('\n') causes
Xthe line to be cleared to the end, and the current coordinates to be changed to
Xthe beginning of the next line if newline mapping is on, or to the next line
Xat the same column if newline mapping isn't on. A return ('\r') will move the
Xcursor to the beginning of the line on the window. Tabs ('\t') will be
Xexpanded into spaces into the normal tabstop positions of every eight
Xcharacters.
X   
Xaddstr(s)                 !
Xchar *s ;
X
Xmvaddstr(y,x,s)           !
Xint y,x ;
Xchar *s ;
X
Xmvwaddstr(win,y,x,s)      !
XWINDOW *win ;
Xint y,x ;
Xchar *s ;
X
Xwaddstr(win,s)
XWINDOW *win ;
Xchar *s ;
X
X   Add the string s to the window at the current coordinates. Addstr() calls
Xaddch repeatedly to add the characters.
X
Xbox(win,vert,hor)
XWINDOW *win ;
Xchar vert, hor ;
X
Xmvbox(win,y,x,vert,hor)   !
XWINDOW *win ;
Xint y, x ;
Xchar vert, hor ;
X
X   Draws a box around the window using vert as the vertical drawing character
Xand hort as the horizontal drawing character.
X
Xclear()                   !
X
Xwclear(win)               
XWINDOW *win ;
X
X   Reset the window to blanks. If win is a screen this will cause a clear
Xscreen sequence to be sent on the next refresh. The current coordinates
Xare also moved to the home-position (0, 0).
X
Xclearok(scr, boolf)       !
XWINDOW *scr ;
Xbool boolf
X
X   Sets the clear-flag for the screen scr to boolf. If boolf is TRUE this
Xwill generate a clear screen sequence on the next refresh. If it is FALSE
Xrefresh may be stopped from generating a clear screen sequence.
X
Xclrtobot()                !
X
Xwclrtobot(win)
XWINDOW *win ;
X
X   Clear the window from the current coordinates to the bottom. The current
Xcoordinates aren't changed.
X
Xclrtoeol()                !
X
Xwclrtoeol(win)
XWINDOW *win ;
X
X   Clear the window from the current coordinates to the end of the line. This
Xdoesn't change the current coordinates.
X
Xdelch()                   !
X
Xmvdelch(y,x)              !
Xint y, x ;
X
Xmvwdelch(win,y,x)         !
XWINDOW *win ;
Xint y, x ;
X
Xwdelch(win)
XWINDOW *win ;
X
X   Delete the character at the current coordinates. Characters on the same
Xline after the deleted character shift to the left and the last character
Xbecomes blank.
X
Xdeleteln()                !
X
Xmvdeleteln(y,x)           !
Xint y, x ;
X
Xmvwdeleteln(win,y,x)      !
XWINDOW *win ;
Xint y,x ;
X
Xwdeleteln(win)
XWINDOW *win ;
X
X   Delete the current line, move every line under it one line up and make the
Xbottom line blank. This doesn't change the current coordinates.
X
Xerase()                   !
X
Xwerase(win)
XWINDOW *win ;
X
X   Sets the entire window to blanks without setting the clear flag. See
Xclear(). The difference is that erase doesn't cause a clear screen sequence
Xto be generated.
X
Xinsch(c)                  !
Xchar c ;
X
Xmvinsch(y,x,c)            !
Xint y, x ;
Xchar c ;
X
Xmvwinsch(win,y,x,c)       !
XWINDOW *win ;
Xint y, x ;
Xchar c ;
X
X   Insert the character c at the current coordinates. each character after
Xthe current character shifts one place to the right and the rightmost character
Xfalls off.
X
Xinsertln()                !
X
Xmvinsertln(y,x)           !
Xint y, x ;
X
Xmvwinsertln(win,y,x)      !
XWINDOW *win ;
Xint y, x ;
X
X   Insert a line above the current line. Every line below will scroll down, and
Xthe bottom line will disappear. The inserted line will be blank. The current
Xcoordinates aren't chnaged by this function.
X
Xmove(y,x)                 !
Xint y, x ;
X
Xwmove(win,y,x)
XWINDOW *win ;
Xint y, x ;
X
X   Change the current coordinates of window win to (y, x). Whenever one of the
Xother output or input functions are preceded by "mv", this function is
Xexecuted first.
X
Xoverlay(win1,win2)
XWINDOW *win1, *win2 ;
X
X   The contents of win1 are placed on win2 at their respective starting
Xcoordinates. Those contents of win1, which would not fit in win2, are
Xdiscarded. Blanks on win1 leave the contents of win2 untouched.
X
Xoverwrite(win1, win2)
XWINDOW *win1, *win2 ;
X
X   The contents of win1 are placed on win2 at their respective starting
Xcoordinates. Those contents of win1, which would not fit in win2, are
Xdiscarded.
X
Xrefresh()                 !
X
Xwrefresh(win)
XWINDOW *win ;
X
X   Update the terminal screen with the contents of the window. Only those parts
Xcovered by the window will be updated. If the window is a screen and its
Xclear flag has been set, then a clear screen sequence will be generated.
X
Xmvstandend(y,x)           !
Xint y, x ;
X
Xmvwstandend(win,y,x)      !
XWINDOW *win ;
Xint y, x ;
X
Xstandend()                !
X
Xwstandend(win)
XWINDOW *win ;
X
X   Stop putting characters onto win in standout mode.
X
Xmvstandout(y,x)           !
Xint y, x ;
X
Xmvwstandout(win,y,x)      !
XWINDOW *win ;
Xint y, x ;
X
Xstandout()                !
X
Xwstandout(win)
XWINDOW *win ;
X
X   Start putting characters onto win in standout mode, i.e. display inverted
Xcharacters.
X
X
X   Input functions.
X   
X
Xcrmode()
X
X   Set the terminal in cbreak mode.
X
Xnocrmode()
X 
X   Reset the terminal from cbreak mode into cooked mode.
X
Xecho()
X
X   Let the terminal echo characters on input.
X
Xnoecho()
X
X   Do not allow the terminal to echo characters on input.
X
Xgetch()                   !
X
Xmvgetch(y,x)              !
Xint y,x ;
X
Xmvwgetch(win,y,x)         !
XWINDOW *win ;
Xint y, x ;
X
Xwgetch(win)
XWINDOW *win ;
X
X   Get a character from the terminal and echo it on the window if echo is set.
XSee the section on programming with curses for more details about input modes.
XRemember getch() returns a 32-bit value, and not a char.
X
Xgetstr(s)                 !
Xchar *s ;
X
Xmvgetstr(y,x,s)           !
Xint y,x ;
Xchar *s ;
X
Xmvwgetstr(win,y,x,s)      !
XWINDOW *win ;
Xint y, x ;
Xchar *s ;
X
Xwgetstr(win,s)
XWINDOW *win ;
Xchar *s ;
X
X   Get a string through the window win and put it in the string s, which is
Xassumed to be large enough to hold the data. To get the input it calls 
Xgetch() repeatedly. The end of the input is designated by any of the
Xfollowing characters, a carriage return, a linefeed, a EOF or control-D, and
Xany character, which results in a '\0'. This character is stripped of the
Xstring and replaced by a null character to indicate the end of the string.
X
Xraw()
X
X   Set the terminal in raw input mode.
X
Xnoraw()
X
X   Set the terminal from raw into cooked input mode.
X
X
X   Miscellaneous functions.
X   
X
Xdelwin(win)
XWINDOW *win ;
X
X   Deletes the window. All resources ( i.e. storage ) held by the window is
Xfreed for future use. As subwindows share their character space with another
Xwindow their character space is not freed. To delete a window with
Xsubwindows, you should first delete the subwindows and then the root window,
Xas any access to a subwindow after deletion of its parent window is a sure
Xroute to disaster.
X
Xendwin()
X
X   Clean up after curses. You should call this prior to termination of
Xyour program.
X
Xgetyx(win,y,x)            !
XWINDOW *win ;
Xint y,x ;
X
X   This macro puts the window current coordinates into the variables y and x.
XNote that you do not supply the address of the variables, as it is a macro.
X
Xinch()                    !
X
Xmvinch(y,x)               !
Xint y,x ;
X
Xmvwinch(w,y,x)            !
XWINDOW *w ;
Xint y, x ;
X
Xwinch(win)                !
XWINDOW *win ;
X
X   This macro returns the value of the character at the current coordinates
Xof the window. This does not change the contents of the window. The functions
Xmvinch() and mvwinch() are not supported by standard UN*X-curses, although
Xthey probably are by most UN*X-implementations.
X
Xinitscr()
X
X   Initialize curses. You should call this before any of the other calls.
X
Xleaveok(win,flag)
XWINDOW *win ;
Xbool   flag ;
X
X   Sets the _leave field of the window win to the value flag. If flag is
XTRUE then after an update on the terminal, the window's current
Xcoordinates will be set to the coordinates immediately after the last updated
Xcharacter. If flag is FALSE, then the cursor will be moved to the windows
Xcurrent coordinates. This flag is FALSE by default.
X
Xlongname(termbuf,name)
Xchar *termbuf, *name ;
X
X   Introduced for UN*X-compatability, it returns the contents of ttytype
Xin name, regardless of the contents of termbuf. This is not really consistent
Xwith UN*X-curses.
X
Xmvwin(win,y,x)
XWINDOW *win ;
Xint y, x ;
X
X   Move the home position of the window win, from its current coordinates to
Xthe coordinates specified in y and x. You cannot move a window off the
Xterminal screen, not even by a character.
X
XWINDOW *newwin(l,c,by,bx)
Xint l, c, by, bx ;
X
X   Create a new window with l lines and c columns starting at position (by,bx).
XIf either l or c is zero, then the dimension will be set to ( LINES - by ),
X( LINES - bx ). To get a screen, one would say newwin(0,0,0,0).
X
Xnl()
X
X   Set curses to newline mapping. This has consequences for adding the
Xcharacter '\n'. See addch() for these consequences.
X
Xnonl()
X
X   Set curses to do no newline mapping. This is the default. In UN*X-curses
Xyou get the fastest updates when you have no newline mapping, Atari-curses
Xdoesn't care about it.
X
Xscrollok(win,flag)
X
X   Set the _scroll field of the window win to flag. If flag is FALSE, the
Xterminal is not allowed to scroll, which is also the default.
X
Xtouchwin(win)
XWINDOW *win ;
X
X   Force curses to believe that the entire window has changed on the next
Xrefresh. This is useful for overlapping windows.
X
XWINDOW *subwin(win,l,c,by,bx)
X
X   Create a new window with a shared character space,as opposed to newwin(),
Xwhich allocates a new character space. See newwin() for more details about
Xthe l, c, by and bx parameters. The new window will share the character space
Xwith the window win. The subwindow must be smaller or the same size as
Xthe parent window. Changes on either window are reflected on the other window.
XMoving subwindows with mvwin() will create some pretty weird results, because
Xthe mapping of the subwindow to the parent window will tend to get displaced.
XFor instance, if I have a one character subwindow of a screen at coordinates
X(2,3) and if I move the subwindow to say (4,5), then if I change the character
Xon the subwindow at (4,5), the parent window will have changed at (2,3).
XI don't know whether this is UN*X-compatible, so take care here.
X
X
X   Detail functions.
X   
X
X   These routines are at the core of UN*X-curses, and can be used on a
Xstandalone basis. Atari-curses has a very limited implemntation of this, so
Xif a program uses these, you'd better rewrite the whole thing. Most likely,
Xthe results of using these won't be the same on either of the two 
Ximplementations.
X
Xmvcur(lasty,lastx,newy,newx)
Xint lasty, lastx, newy, newx ;
X
X   Move the terminals cursor from (lasty,lastx) to (newy,newx). Don't use it
Xwhen you use any of the screen routines.
X
Xscroll(win)
XWINDOW *win ;
X
X   Scroll the window upward one line. You don't normally want to do this.
X
X
X   Functions not supported by Atari-curses.
X   
X
X   Several functions are not supported by Atari-curses, but are by UN*X-curses.
XThe names of these functions are given, as well as a reason for not
Ximplementing them.
X
Xmvprintw(), mvwprintw(), printw() and wprintw()
X
X   Performs a printf() on a window. I didn't want to implement this for two
Xreasons :
X1. This introduces compiler dependant code.
X2. A large overhead in coding is required. ( I'm very lazy. )
XThis omission can easily be gotten around with by inline replacement with :
X                 sprintf(a_string, format, ... ) ;
X                 addstr(a_string) ;
X
Xmvscanw(), mvwscanw(), scanw() and wscanw()
X
X  Performs a scanf() on a window. The same reasons apply here as the reasons
Xfor printw(). Replace it inline with :
X                 getstr(a_string) ;
X                 sscanf(a_string, format, ... ) ;
X
Xuncntrl()
X
X  Returns a string which is a representation of a character, nice debugging
Xfeature for UN*X-curses, but pretty meaningless for Atari-curses as
XAtari-curses can show any character.
X
Xgettmode()
X
X   A function called by UN*X-initscr(), it gets tty stats, which is
XUN*X-dependant anyway.
X
Xsavetty() and resetty()
X
X   Save and reset tty characteristics, used by UN*X-curses to initialize and
Xclean up respectively. Not necessary on Atari.
X
Xsetterm(name)
X
X   Set terminal characteristics to those of the terminal with name name.
XPretty useless on Atari.
X
Xtstp()
X
X   Function which is used in UN*X-curses to save the current state when a 
Xprocess is put to sleep and to restore it when it is restarted. This is the 
Xnormal catch for the signal SIGTSTP, which Atari users won't be able to receive
Xanyway.
X
X
X   Caveats and bugs.
X   
X
X   There are differences between Atari-curses and UN*X-curses, especially in
Xthe area of input and the more detailed workings of curses. I will
Xprobably not change the workings of any input routines, because if I did
Xapplication programs wouldn't have any control over say function keys, cursor
Xkeys, etc. Such keys really make a difference in user friendly programs, so
XI'd better let a programmer have access to them. The more detailed workings
Xof curses are best left out too, as they concern themselves with multiple types
Xof terminals, where the Atari-curses is only fitted to a single 
Xterminaltype, i.e. the Atari's VT52 emulation mode. Another problem
Xis possibly the low-resolution mode of the Atari, I don't have access to
Xa color monitor, so I wasn't able to test it in either medium or low-res.
XMedium probably works fine, but low-res ?. So, if you don't do anything too
Xfancy, you should be allright. One more thing : when you write portable
Xprograms, keep in mind that the Atari-curses is a lot faster than any
Ximplementation, which sends data over a terminal line. Comparing speeds
Xwill put any program on the Atari seemingly on a 50+ kilobaud line.
XAlso beware of funny characters, i.e. portable programs require character
Xranges between $20 and $7F, Atari-curses can and will handle a lot more. This
Xwarning should especially be heeded by say Germans and French, diacritical
Xmarks may screw things up real bad.
SHAR_EOF
chmod 0640 curses.doc || echo "restore of curses.doc fails"
sed 's/^X//' << 'SHAR_EOF' > 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 ;
SHAR_EOF
chmod 0640 curses.h || echo "restore of curses.h fails"
sed 's/^X//' << 'SHAR_EOF' > curses.man &&
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 .
SHAR_EOF
chmod 0640 curses.man || echo "restore of curses.man fails"
sed 's/^X//' << 'SHAR_EOF' > portab.h &&
X/*
X * This file re-implements portions of the Alcyon portab.h needed
X * by curses. If you have a more complete portab.h that contains
X * the following definitions, use it.
X */
X
X#define	BYTE	char
X#define	WORD	int
X#define	LONG	long
SHAR_EOF
chmod 0640 portab.h || echo "restore of portab.h fails"
sed 's/^X//' << 'SHAR_EOF' > readme.too &&
X		Notes for the Megamax Version of Curses
X
XThis version of curses compiles with the Megamax C compiler. A couple
Xof bug fixes were needed and the wgetstr routine was hacked quite a bit.
X
X
XNotes:
X
X1. The overlay() routine was renamed woverlay() to avoid a conflict with
X   the Megamax reserved word.
X
X2. The entire file was placed in an overlay because I needed the space.
X   You may want to get rid of the overlay line in curses.c depending on
X   what you're linking curses with.
X
X3. The routines printw() and scanw() are implemented in the usual brute-
X   force way since Megamax doesn't have varargs. These are at the end
X   of curses.c.
X
X4. Remember to change your init.c to get extra stack space.
X
X5. The file portab.h contains the definitions needed from the Alcyon
X   file of the same name. If you have a more complete version, use it.
X
X6. twinkle.tos isn't in this distribution because I wanted to post this
X   stuff as clear text.
X
X
XTony Andrews
Xihnp4!onecom!wldrdg!tony
XWildridge Consulting, Inc.
XBoulder, CO
SHAR_EOF
chmod 0640 readme.too || echo "restore of readme.too fails"
sed 's/^X//' << 'SHAR_EOF' > readme.txt &&
XThis 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
SHAR_EOF
chmod 0640 readme.txt || echo "restore of readme.txt fails"
sed 's/^X//' << 'SHAR_EOF' > 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
X#include "portab.h"
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 = ((unsigned int) 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}
SHAR_EOF
chmod 0640 twinkle.c || echo "restore of twinkle.c fails"
rm -f s2_seq_.tmp
echo "You have unpacked the last part"
exit 0