[comp.sources.amiga] v91i033: Curses 1.22 - terminal screen handling and optimization package, Part01/08

amiga-request@ab20.larc.nasa.gov (Amiga Sources/Binaries Moderator) (03/04/91)

Submitted-by: sie@fulcrum.bt.co.uk (Simon Raybould)
Posting-number: Volume 91, Issue 033
Archive-name: libraries/curses-1.22/part01

[ includes uuencoded libraries and sample programs  ...tad ]

This is V1.22 of my amiga curses package.

    This package is mainly aimed at people who wish to port screen based UN*X
applications to the Amiga. I have written a brief documentation file but I
assume that such people have access to full curses documentation. I have no
intention of re-writing the Curses documentation as this would be of little
or no use to people because documentation is generally available at book
stores.

    I hope this is the package people have been waiting for on the Amiga
and would like to make this the best PD curses package available. So please
report bugs to me.

#!/bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of archive 1 (of 8)."
# Contents:  History ReadMe curses.doc curses.h examples
#   examples/battle examples/battle/Makefile examples/hanoi
#   examples/hanoi/Makefile examples/hanoi/hanoi.c examples/odds
#   examples/odds/knight.c examples/odds/rain.c examples/odds/worms.c
#   src src/Makefile.lattice src/Read_Me src/acurses.h
# Wrapped by tadguy@ab20 on Sun Mar  3 18:04:24 1991
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'History' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'History'\"
else
echo shar: Extracting \"'History'\" \(3001 characters\)
sed "s/^X//" >'History' <<'END_OF_FILE'
X                     AMIGA CURSES PACKAGE
X                     ====================
X
X
XAuthor: Simon J Raybould.    sie@fulcrum.bt.co.uk
X
X
XUpdates from V1.00 to V1.10
X===========================
X
XBugs Fixed
X----------
X
X    1. calling wrefresh() and other such functions with an uninitialised
X       pointer caused the machine to hang up.
X    
X    2. Fixed bugs in box() routine, including cursor position after
X       drawing a box.
X
X    3. Fixed all of the mvwxxxx() routines such as mvwaddch(), mvwaddstr, 
X       e.t.c. These were previously doing the move part of the instruction 
X       in stdscr instead of the specified window.
X
X
XChanges Made
X------------
X
X    1. Now distributed with two libraries, one with full 32 bit addressing
X       for large programs, and one without for smaller code.
X
X    2. Changed the advised line to blink in the examples. Now includes
X       curses.lib before the other libraries.
X
X    3. Added more examples.
X
X    4. Corrected newwin/subwin control/refreshing to be more like UNIX.
X
X    5. Added nocrmode().
X
X    6. Altered the header file to fix the mvwxxxx() bugs mentioned above.
X
X    7. Added mvwin().
X
X    8. Added full keyboard support including Function keys and Cursor keys.
X
X    9. Made keypad() switch the ANSI mapping off when set to TRUE.
X
X
XUpdates from V1.10 to V1.20
X===========================
X
XBugs Fixed
X----------
X
X    1. Reference from address 0 in endwin() removed.
X
X    2. Fixed curscr to make it a copy of the physical screen.
X       So wrefresh(curscr) will tidy up the screen to what it was last time
X       a refresh was done.
X
XChanges Made
X------------
X
X    1. Changed data structure for line storage to reduce the overhead in
X       finding a particular line.
X
X    2. Many speed improvements.
X
X    3. Added doupdate() & wnoutrefresh().
X
X    4. Made LINES & COLS extern ints and made them initialise to the size
X       of the active screen when curses is invoked. This is unless the
X       environment variables LINES and COLS exist, in which case, they will
X       be used.
X
X    5. Changed the format of the libraries in an attempt to make them
X       compatible with more linkers by making them standard amiga format.
X    
X    6. Added many more functions, including flushinp(), resetterm() e.t.c.
X
X
XUpdates from V1.20 to V1.21
X===========================
X
XBugs Fixed
X----------
X
X    1. Fixed the range on box() to allow SPACE as a character.
X       This allows you to draw a box of inverse spaces.
X
XChanges Made
X------------
X
X    1. Added mvcur() to allow the cursor to be moved straight away
X       without calling refresh().
X
X
XUpdates from V1.21 to V1.22
X===========================
X
XBugs Fixed
X----------
X
X    1. If active screen is interlaced then the curses screen is also interlaced
X       to allow 64 lines on a PAL system.
X
X    2. When there was a '\n' in a print that had inverse video set, a line of
X       inverse spaces was added up to the end of line. This was incompatible
X       with UNIX curses and has now been fixed.
END_OF_FILE
if test 3001 -ne `wc -c <'History'`; then
    echo shar: \"'History'\" unpacked with wrong size!
fi
# end of 'History'
fi
if test -f 'ReadMe' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'ReadMe'\"
else
echo shar: Extracting \"'ReadMe'\" \(2898 characters\)
sed "s/^X//" >'ReadMe' <<'END_OF_FILE'
X            AMIGA CURSES PACKAGE V1.20
X            ==========================
X
XAuthor : Simon John Raybould    (sie@fulcrum.bt.co.uk)
XDate   : 2nd December 1990
X
X
X
X    This code is freely distributable as long as all of the files supplied
Xare included in the distribution.
X
X    I am including the source so that users other than Lattice may benifit
Xfrom this package. Please DO NOT CHANGE THE SOURCE inform me of any bugs you
Xwant fixing and it shall be done - FAST.
X
X    DO NOT DISRTRIBUTE AN ALTERED COPY OF THIS CODE TELL ME IF YOU WANT
X    SOMETHING FIXING OR CHANGING IN THE SOURCE AND I WILL DO IT AND
X    INCLUDE IT IN FUTURE RELEASES, YOU'LL EVEN GET A MENTION IN THE
X    HISTORY FILE AS BEING INVOLVED IN ITS HISTORY!
X
X    I ASK FOR NO MONEY THIS STUFF IS TOTALLY FREE GRATIS FOR NOTHING GIVE
X    IT TO WHOEVER WANTS IT BUT DONT CHARGE THEM FOR THE SOFTWARE, YOU MAY
X    CHARGE FOR YOUR TIME AND EFFORT IN COPYING, YOU MAY ALSO CHARGE FOR
X    ANY MEDIA USED.
X
X    This package is mainly aimed at people who wish to port screen based UN*X
Xapplications to the Amiga. I have written a brief documentation file but I
Xassume that such people have access to full curses documentation. I have no
Xintention of re-writing the Curses documentation as this would be of little
Xor no use to people because documentation is generally available at book
Xstores.
X
X    I hope this is the package people have been waiting for on the Amiga
Xand would like to make this the best PD curses package available. So please
Xreport bugs to me.
X
X    To use this, include curses.h at the top of your code instead of stdio.h
X(curses.h will include stdio.h). Compile as normal and when linking, link in
Xthe library 'curses.lib'. 'curses.h' should be installed in the same
Xdirectory as 'stdio.h' (INCLUDE:) with lattice V5. 'curses.lib' should be
Xin the same directory as 'lc.lib' or 'c.lib' (LIB:) with lattice V5.
X
X    This code was compiled under Lattice C V5.05. It should work O.K. with
Xall Lattice setups and I hope with Aztec too.
X
X    I have not tested with Aztec as I don't have a copy.
X
X
XNOTE
X====
X
X    The curses library should be linked in before all other libraries on
X    the link line.
X
X
XEXAMPLE
X=======
X
X    blink lib:c.o foo.o TO foo LIB lib:curses.lib+lib:lc.lib+lib:amiga.lib
X
X
XThanks
X======
X
X    I feel I must thank certain people for their help in the improvement of
Xthis package from which we all stand to gain. Without their suggestions, the
Xdevelopment of this package would have been significantly slower, Thanks.
X
X    Michael Fischer - For finding many bugs in the first alpha of curses and
X                      continued bug finding and suggestions. Thanks Mike!
X    Phil Kernick    - For his excellent suggestions for improvements.
X    Kai Vorma       - For suggestions, bug reports e.t.c.
X
X    Any bugs, suggestions,  e.t.c. email to 'sie@fulcrum.bt.co.uk'
X
X
X
XCheers,
X
X       Simon J Raybould
END_OF_FILE
if test 2898 -ne `wc -c <'ReadMe'`; then
    echo shar: \"'ReadMe'\" unpacked with wrong size!
fi
# end of 'ReadMe'
fi
if test -f 'curses.doc' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'curses.doc'\"
else
echo shar: Extracting \"'curses.doc'\" \(12989 characters\)
sed "s/^X//" >'curses.doc' <<'END_OF_FILE'
X            AMIGA CURSES PACKAGE V1.20
X            ==========================
X
XAuthor : Simon John Raybould    (sie@fulcrum.bt.co.uk)
XDate   : 07th November 1990
X
X
X    This is a brief description of the curses functions provided by this
Xpackage. I have not gone into great detail as I assume the users of this to
Xalready have a knowledge of UN*X curses, more than likely porting UN*X screen
Xbased applications to the Amiga. There is plenty of curses documentation
Xabout so I will only outline each of the functions provided.
X
X    Cheers
X
X        Sie
X
X
X
X
XBelow is a list of the supported functions and there operation.
X===============================================================
X
X
Xinitscr()
X
X    This is usually the first function called by a program. It creates
X    stdscr and must be called before any of the other functions will work.
X
X
Xendwin()
X
X    This should be called before exiting a curses program.
X    It frees all memory used and dismantles all structures.
X    It closes the custom screen and window used.
X
X
Xbeep()
X
X    Produces an audible beep from the speaker. This beep is similar in pitch
X    and duration to the beep from a terminal when a BEL (^G) character is
X    recieved.
X
X
Xflash()
X
X    Flashes the display by complementing the background colour. With the
X    default black background, this will flash the screen yellow.
X
X
Xbox(window, vertical, horizontal)
X
X    Draws a box around the edge of the window.
X    window     - pointer returned from newwin or subwin, or stdscr even.
X    vertical   - character to use for the verticals.
X    horizontal - character to use for the horizontals.
X
X    Either of the characters may be zero. In this case, the defaults of
X    '|' and '-' will be used for vertical and horizontal respectivly.
X
X    NOTE
X    ----
X    The box drawn is INSIDE the window. Therefore any of the clear routines
X    will effect the box if carried out on its window.
X
X
Xcbreak()
Xnocbreak()
X
X    cbreak() puts the terminal into CBREAK mode, making characters typed
X    available immediately.
X
X    nocbreak() sets NOCBREAK mode and characters are not available until
X    a newline is typed.
X
X    The default is NOCBREAK mode, so most programs call cbreak() before
X    doing any reads on the keyboard.
X
X
Xcrmode()
Xnocrmode()
X
X    As cbreak() and nocbreak() as shown above.
X
X
Xclearok(WinPtr, flag)
X
X    If flag is TRUE then this function will make every refresh clear the
X    display before updating it. If the flag is FALSE then the screen will
X    not be cleared on each refresh. The DEFAULT is FALSE.
X
X
Xleavok(window, flag)
X
X    If flag is TRUE then the cursor will not be displayed.
X    The default is FALSE and the cursor is displayed.
X
X
Xsubwin(orig, lines, cols, beg_line, beg_col)
X
X    Creates a new window within another window. The original window has
X    its pointer passed as 'orig'.
X    The new window will be at line 'beg_line' and column 'beg_col' of the
X    window pointed to by 'orig'. It will be of size 'lines' lines of 'cols'
X    columns.
X
X    A sub-window is part of its surrounding window. When the surrounding
X    window is refreshed, the sub-window is refreshed as well.
X
X
Xnewwin(lines, cols, beg_line, beg_col)
X
X    Creates a new window at line 'beg_line' and column 'beg_col'.
X    The size of this window is 'lines' lines of 'cols' columns.
X
X    The new window has its own data structures and does not affect any
X    data in other windows.
X
X
Xdelwin(window)
X
X    Deletes a window and frees the associated memory. This should be done if
X    the window is no longer used.
X
X    It is not necessary to free all windows, endwin() will free all windows
X    still allocated before returning.
X
X
Xmvwin(window, new_line, new_col)
X
X    Moves a window to a new position on the screen. This position is relative
X    to the top left of the screen and NOT to the start of any surrounding
X    window in the case of sub-windows.
X
X
Xnl()
Xnonl()
X
X    nl() - Causes newline to newline/carriage return mapping on output and
X    return to newline mapping on input.
X
X    nonl() - disables this.
X    The DEFAULT is that mapping is done.
X
X
Xecho()
Xnoecho()
X
X    echo() causes every character read to be echoed back to the display.
X    noecho() prevents the echo, this is useful when reading movement keys,
X    you don't want them echoed to the screen.
X    The DEFAULT is that echoing is performed.
X
X
Xnodelay(window, flag)
X
X    nodelay is enabled by a call : nodelay(stdscr, TRUE);
X    When in nodelay mode, getch will return -1 if there is no input pending.
X    The DEFAULT is nodelay FALSE and getch will wait for at least one char
X    in CBREAK mode or a newline otherwise.
X
X
Xhas_colors()
Xstart_color()
Xinit_color(n, r, g, b) 
X
X    has_colors() is to check if colours are available on this terminal.
X    On the Amiga, it will simply return TRUE.
X
X    start_colour() is to tell the terminal that you wish to use colour.
X
X    init_color() will alter the Red, Green and Blue content of colour n.
X    r, g and b are in the range 1 to 1000. The colour number 'n' is in the
X    range 0 to 15 and it should be noted that colour 0 is the background
X    colour. Initially the foreground is set to colour 1 but can be changed
X    with the attron() or attrset() function to any of the colours 1 to 15,
X    0 is not allowed as this is the background. If 0 is selected, the
X    foreground colour will be set to 1.
X
X
Xkeypad(window, flag)
X
X    If flag is TRUE then the ANSI sequences for the function keys and the
X    cursor keys will be converted to the tokens KEY_UP, KEY_HELP, e.t.c.
X    The DEFAULT is that the ANSI sequences will returned.
X    So to cause special keys to be returned as tokens in the standard screen,
X    add the following line:
X
X        keypad(stdscr, TRUE);
X
X
Xprintw(fmt, args)
Xwprintw(window, fmt, args)
Xmvprintw(line, col, fmt, args)
Xmvwprintw(window, line, col, fmt, args)
X
X    Offer formatted output similar to printf(3).
X    printw() - prints at the current position in stdscr.
X    wprintw() - prints at the current position in window.
X    mvprintw() - prints at line 'line' column 'col' in stdscr.
X    mvwprintw() - prints at line 'line' column 'col' in 'window'.
X
X
Xscanw(fmt, args)
Xwscanw(window, fmt, args)
Xmvscanw(line, col, fmt, args)
Xmvwscanw(window, line, col, fmt, args)
X
X    Offer formatted input similar to scanf(3).
X    scanw() - scans at the current position in stdscr.
X    wscanw() - scans at the current position in window.
X    mvscanw() - scans at line 'line' column 'col' in stdscr.
X    mvwscanw() - scans at line 'line' column 'col' in 'window'.
X
X
Xscrollok(window, flag)
X
X    When flag is true, curses will automatically scroll the window up one
X    line when output goes off the bottom.
X    E.g.
X            scrollok(stdscr, TRUE);
X    
X    stdscr will then be automatically scrolled up one line when output goes
X    off bottom of stdscr.
X    The DEFAULT is that the window will NOT be scrolled, the bottom line
X    will be used over and over again without scrolling.
X
X
Xscroll(window)
X
X    The window is scrolled up one line.
X
X
Xsetscrreg(top, bottom)
Xwsetscrreg(window, top, bottom)
X
X    Sets the region from line 'top' to line 'bottom' inclusive.
X    When output moves below line 'bottom', the region is scrolled up one line
X    ( if scrollok() has been called ).
X
X
Xtouchwin(window)
X
X    Will force the window to be completely refreshed on the next call to
X    refresh by dumping all optimisation information. This can be useful if
X    the state of the screen is unknown or if a window was obscured by
X    another window which was not a subwindow of the one it covered. Then
X    you may need to touchwin() the window that was covered and refresh it.
X    
X
Xaddch(c)
Xwaddch(window, c)
Xmvaddch(line, col, c)
Xmvwaddch(window, line, col, c)
X
X    addch(c) - Prints character c at current screen position in stdscr.
X    addch(window, c) - Prints character c at current screen position in
X            window.
X    mvaddch(line, col, c) - Prints character c at line 'line' column 'col' in
X            stdscr.
X    mvwaddch(window, line, col, c) - Prints character c at line 'line' column
X            'col' in window.
X
X
Xaddstr(str)
Xwaddstr(window, str)
Xmvaddstr(line, col, str)
Xmvwaddstr(window, line, col, str)
X
X    addstr(str) - Prints string str at current screen position in stdscr.
X    waddstr(window, str) - Prints string str at current screen position in
X            window.
X    mvaddstr(line, col, str) - Prints string str at line 'line' column 'col'
X            in stdscr.
X    mvwaddstr(window, line, col, str) - Prints string str at line 'line'
X            column 'col' in window.
X    
X
Xattrset(attrs)
Xwattrset(window, attrs)
X
X    These routines set the attributes for stdscr or the specified window in
X    the case of wattset() to the value passed in attrs. This is usually used
X    to get the attributes to a known state before using attron() and
X    attroff() to add and remove extra attributes respectively.
X
X
Xattron(attrs)
Xwattron(window, attrs)
X
X    These routines add the attributes specified in attrs to those already set
X    for stdscr or the window specified in the case of wattron(). Any previous
X    attributes that are not directly affected by the changes will be left as
X    they were.
X
X
Xattroff(attrs)
Xwattroff(window, attrs)
X
X    These routines remove the attributes specified in attrs from those set
X    for stdscr or the window specified in the case of wattroff().
X    Any previous attributes that are not directly affected by the changes
X    will be left as they were.
X
X        e.g.
X                attron(A_REVERSE)
X                addstr("This is in inverse");
X                attroff(A_REVERSE);
X                refresh();
X
X
Xstandout()
Xwstandout(window)
X
X    These routines make the following text appear in inverse video.
X
X
Xstandend()
Xwstandend(window)
X
X    These routines will return the text type to normal video.
X
X
Xclear()
Xwclear(window)
X
X    These routines will empty the screen buffer and will cause the screen
X    to be cleared on the next call to refresh().
X
X
Xerase()
Xwerase(window)
X
X    These routines will empty the screen buffer and will cause the screen
X    to be cleared on the next call to refresh(). Similar to erase() except
X    that these will call clearok() as well.
X
X
Xclrtobot()
Xwclrtobot(window)
X
X    On the next refresh(), the window will be blanked from the current
X    position to bottom righthand corner.
X
X
Xclrtoeol()
Xwclrtoeol(window)
X
X    On the next refresh(), the window will be blanked from the current
X    position to the end of the line.
X
X
Xdelch()
Xwdelch(window)
Xmvdelch(line, col)
Xmvwdelch(window, line, col)
X
X    These routines delete the character at the current position, the rest of
X    the line to the right of this character is slid along to the left to
X    fill the gap. This can be very useful in editors and the like.
X
X
Xgetch()
Xwgetch(window)
Xmvgetch(line, col)
Xmvwgetch(window, line, col)
X
X    These routines return the next character from the keyboard. If cbreak()
X    has been called then they return as soon as there is a character to read
X    else they wait for a <CR> before returning. If nodelay() has been called
X    then they will return a character if there is one or -1 if not.
X
X
Xgetstr()
Xwgetstr(window)
Xmvgetstr(line, col)
Xmvwgetstr(window, line, col)
X
X    These routines should be used to read a string in from the keyboard.
X    Delete is processed for you.
X
X
Xinch()
Xwinch(window)
Xmvinch(line, col)
Xmvwinch(window, line, col)
X
X    These routines return the character at the current position in the
X    window or at the specified position in the 'mv' cases.
X
X
Xinsch()
Xwinsch(window)
Xmvinsch(line, col)
Xmvwinsch(window, line, col)
X
X    These routines insert a character at the current window position, or at
X    the specified position in the 'mv' cases. The remainder of the line is
X    shifted along to the right to make room. The character at the far right
X    is lost.
X
X
Xinsertln()
Xwinsterln(window)
X
X    These routines insert a line at the current window position.
X    All of the lines below are shifted down and the bottom line is lost.
X
X
Xdeleteln()
Xwdeleteln(window)
X
X    These routines delete a line at the current window position.
X    All of the lines below are shifted up into the space and the bottom line
X    is left blank.
X
X
Xmove(line, col)
Xwmove(window, line, col)
X
X    These routines set the current position to line 'line' and column 'col'.
X
Xrefresh()
Xwrefresh(window)
X
X    These routines cause all outstanding changes to 'stdscr' or the specified
X    window 'wrefresh' to be sent to the screen.
X
Xwnoutrefresh(window)
Xdoupdate()
X
X    Will cause "window" to be refreshed when doupdate() is next called.
X    You can then wnoutrefresh() several windows and make one call to
X    doupdate() to do all the updates at once.
X
Xmvcur(CurrentLine, CurrentCol, NewLine, NewCol)
X
X    This will move the cursor to the position specified by 'NewLine' and
X    'NewCol'. The move is immediate and so refresh() does not need to be
X    called, in fact a call to refresh() will cause the cursor to be moved
X    after the last char printed during that refresh.
END_OF_FILE
if test 12989 -ne `wc -c <'curses.doc'`; then
    echo shar: \"'curses.doc'\" unpacked with wrong size!
fi
# end of 'curses.doc'
fi
if test -f 'curses.h' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'curses.h'\"
else
echo shar: Extracting \"'curses.h'\" \(8421 characters\)
sed "s/^X//" >'curses.h' <<'END_OF_FILE'
X/*
X *
X *    Author    : Simon J Raybould.    (sie@fulcrum.bt.co.uk).
X *
X *    Date      : v1.00a    16th Feb 1990
X *                v1.10     30th Sep 1990
X *                v1.20a     4th Oct 1990 (very limited distribution)
X *                v1.20      7th Nov 1990
X *                v1.21      2nd Dec 1990
X *
X *    Desc    : Header file for my AMIGA CURSES package.
X *              This should be included instead of stdio.h, this will
X *              include stdio.h for you.
X *              This file is Public Domain but please leave the name
X *              of the author intact.
X *
X */
X
X#ifndef CURSES_H
X#define CURSES_H
X
X#ifndef stdin    /* May be a better way to do this !! */
X#include <stdio.h>
X#endif /* stdin */
X
X#ifndef TRUE
X#define TRUE      1 
X#define FALSE     0 
X#endif /* TRUE */
X
X#define ERR      -1
X#define OK        0
X
Xextern int LINES, COLS;
X
X
X/*
X *    Macros
X */
X
X#define addch(c)                   waddch(stdscr, (c))
X#define addstr(str)                waddstr(stdscr, (str))
X#define attrset(attr)              wattrset(stdscr, (attr))
X#define attron(attr)               wattron(stdscr, (attr))
X#define attroff(attr)              wattroff(stdscr, (attr))
X#define clear()                    wclear(stdscr)
X#define clrtoeol()                 wclrtoeol(stdscr)
X#define clrtobot()                 wclrtobot(stdscr)
X#define delch()                    wdelch(stdscr)
X#define deleteln()                 wdeleteln(stdscr)
X#define erase()                    werase(stdscr)
X#define inch()                     winch(stdscr)
X#define insch(c)                   winsch(stdscr, (c))
X#define insertln()                 winsertln(stdscr)
X#define getch()                    wgetch(stdscr)
X#define getstr(ptr)                wgetstr(stdscr, (ptr))
X#define getyx(win,y,x)             ((y) = getcury(win), (x) = getcurx(win))
X#define getbegyx(win,y,x)          ((y) = getbegy(win), (x) = getbegx(win))
X#define getmaxyx(win,y,x)          ((y) = getmaxy(win), (x) = getmaxx(win))
X#define getparyx(win,y,x)          ((y) = getpary(win), (x) = getparx(win))
X#define getcury(win)               ((win)->_cury)
X#define getcurx(win)               ((win)->_curx)
X#define getbegy(win)               ((win)->_begy)
X#define getbegx(win)               ((win)->_begx)
X#define getmaxy(win)               ((win)->_maxy)
X#define getmaxx(win)               ((win)->_maxx)
X#define getpary(win)               ((win)->_pary)
X#define getparx(win)               ((win)->_parx)
X#define getbkgd(win)               ((win)->_bkgd)
X#define getattrs(win)              ((win)->_attrs)
X#define move(line, col)            wmove(stdscr, (line), (col))
X#define mvdelch(y, x)              (move((y), (x)), delch())
X#define mvwdelch(win, y, x)        (wmove((win),(y),(x)),wdelch((win)))
X#define mvgetch(y, x)              (move((y), (x)), getch())
X#define mvwgetch(win, y, x)        (wmove((win),(y),(x)),wgetch((win)))
X#define mvgetstr(y, x, ptr)        (move((y), (x)), getstr((ptr)))
X#define mvwgetstr(win, y, x, ptr)  (wmove((win), (y), (x)), \
X				   wgetstr((win), (ptr)))
X#define mvinsch(y, x, c)           (move((y), (x)), insch((c)))
X#define mvwinsch(win, y, x, c)     (wmove((win), (y), (x)), \
X				   winsch((win), (c)))
X#define mvinch(y, x)               (move((y), (x)), inch())
X#define mvwinch(win, y, x)         (wmove((win), (y), (x)),winch((win)))
X#define mvaddch(y, x, c)           (move((y), (x)), addch((c)))
X#define mvwaddch(win, y, x, c)     (wmove((win), (y), (x)), \
X				   waddch((win), (c)))
X#define mvaddstr(y, x, str)        (move((y), (x)), addstr((str)))
X#define mvwaddstr(win, y, x, str)  (wmove((win), (y), (x)), \
X				   waddstr((win), (str)))
X#define refresh()                  wrefresh(stdscr)
X#define noutrefresh()              wnoutrefresh(stdscr)
X#define setscrreg(top, bottom)     wsetscrreg(stdscr, (top), (bottom))
X#define standend()                 wstandend(stdscr)
X#define standout()                 wstandout(stdscr)
X
X/*
X *    NON STANDARD MACROS
X */
X
X#define pencolour(n)    wpencolour(stdscr, (n))
X
X/*
X *    Colours
X */
X
X#define COLOR_BLACK     0     /* Black */
X#define COLOR_WHITE     1     /* White */
X#define COLOR_YELLOW    2     /* Yellow */
X#define COLOR_ORANGE    3     /* Orange */
X#define COLOR_BLUE      4     /* Blue */
X#define COLOR_MAGENTA   5     /* Magenta */
X#define COLOR_CYAN      6     /* Cyan */
X#define COLOR_PWHITE    7     /* Paper White */
X#define COLOR_BROWN     8     /* Brown */
X#define COLOR_RED       9     /* Red */
X#define COLOR_LGREEN    10    /* Light Green */
X#define COLOR_TAN       11    /* Well err Tan really */
X#define COLOR_BBLUE     12    /* Different to BLUE */
X#define COLOR_PURPLE    13    /* Pomegranate colour */
X#define COLOR_GREEN     14    /* The Bla Bla Grass of home and all that */
X#define COLOR_GREY      15    /* Dead giveaway that one */
X
X
X/*
X *    Video Attributes.
X */
X
X#define A_NORMAL      0000000
X#define A_STANDOUT    0000200
X#define _STANDOUT     A_STANDOUT    /* for compatibility with old curses */
X#define A_UNDERLINE   0000400
X#define A_REVERSE     0001000
X#define A_BLINK       0002000
X#define A_DIM         0004000
X#define A_BOLD        0010000
X
X#define A_ATTRIBUTES  0377600
X#define A_CHARTEXT    0000177
X
X
X
X#define bool    char
X#define reg     register
X
Xstruct _win_st {
X  short   _cury, _curx;
X  short   _maxy, _maxx;
X  short   _begy, _begx;
X  short   _flags;
X  short   _attrs;
X  bool    _clear;    /* T=clear on every refresh set by clearok() */
X  bool    _cls;    /* T=clear on next refresh set by clear() */
X  bool    _leave;
X  bool    _scroll;
X  bool    _use_idl;
X  bool    _use_keypad;    /* 0=no, 1=yes, 2=yes/timeout */
X  bool    _use_meta;      /* T=use the meta key */
X  bool    _nodelay;       /* T=don't wait for tty input */
X  char    **_y;
X  short   *_firstch;
X  short   *_lastch;
X  short   _tmarg,_bmarg;
X  char    *_WinStat;        /* Window state SJR */
X};
X
Xtypedef struct _win_st  WINDOW;
Xextern WINDOW *stdscr, *curscr;
X
X/* Funny "characters" enabled for various special function keys for input */
X#define KEY_BREAK       0401            /* break key (unreliable) */
X#define KEY_DOWN        0402            /* The four arrow keys ... */
X#define KEY_UP          0403
X#define KEY_LEFT        0404
X#define KEY_RIGHT       0405            /* ... */
X#define KEY_HOME        0406            /* Home key (upward+left arrow) */
X#define KEY_BACKSPACE   0407            /* backspace (unreliable) */
X#define KEY_F0          0410            /* Function keys.  Space for 64 */
X#define KEY_F(n)        (KEY_F0+(n))    /* keys is reserved. */
X#define KEY_DL          0510            /* Delete line */
X#define KEY_IL          0511            /* Insert line */
X#define KEY_DC          0512            /* Delete character */
X#define KEY_IC          0513            /* Insert char or enter insert mode */
X#define KEY_EIC         0514            /* Exit insert char mode */
X#define KEY_CLEAR       0515            /* Clear screen */
X#define KEY_EOS         0516            /* Clear to end of screen */
X#define KEY_EOL         0517            /* Clear to end of line */
X#define KEY_SF          0520            /* Scroll 1 line forward */
X#define KEY_SR          0521            /* Scroll 1 line backwards (reverse) */
X#define KEY_NPAGE       0522            /* Next page */
X#define KEY_PPAGE       0523            /* Previous page */
X#define KEY_STAB        0524            /* Set tab */
X#define KEY_CTAB        0525            /* Clear tab */
X#define KEY_CATAB       0526            /* Clear all tabs */
X#define KEY_ENTER       0527            /* Enter or send (unreliable) */
X#define KEY_SRESET      0530            /* soft (partial) reset (unreliable) */
X#define KEY_RESET       0531            /* reset or hard reset (unreliable) */
X#define KEY_PRINT       0532            /* print or copy */
X#define KEY_LL          0533            /* home down or bottom (lower left) */
X/* The keypad is arranged like this: */
X/*    a1    up    a3   */
X/*   left   b2  right  */
X/*    c1   down   c3   */
X#define KEY_A1          0534            /* upper left of keypad */
X#define KEY_A3          0535            /* upper right of keypad */
X#define KEY_B2          0536            /* center of keypad */
X#define KEY_C1          0537            /* lower left of keypad */
X#define KEY_C3          0540            /* lower right of keypad */
X#define KEY_HELP        0553            /* Help Key */
X
XWINDOW *newwin(), *subwin();
X
X#endif /* CURSES_H */
END_OF_FILE
if test 8421 -ne `wc -c <'curses.h'`; then
    echo shar: \"'curses.h'\" unpacked with wrong size!
fi
# end of 'curses.h'
fi
if test ! -d 'examples' ; then
    echo shar: Creating directory \"'examples'\"
    mkdir 'examples'
fi
if test ! -d 'examples/battle' ; then
    echo shar: Creating directory \"'examples/battle'\"
    mkdir 'examples/battle'
fi
if test -f 'examples/battle/Makefile' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'examples/battle/Makefile'\"
else
echo shar: Extracting \"'examples/battle/Makefile'\" \(159 characters\)
sed "s/^X//" >'examples/battle/Makefile' <<'END_OF_FILE'
XCC= lc
XCFLAGS= -cw
X
X
Xbattle: battle.o
X	blink LIB:c.o,battle.o TO battle LIB LIB:curses.lib,LIB:lc.lib,LIB:amiga.lib
X
Xbattle.o:	battle.c
X
Xclean:
X	-delete \#?.o
END_OF_FILE
if test 159 -ne `wc -c <'examples/battle/Makefile'`; then
    echo shar: \"'examples/battle/Makefile'\" unpacked with wrong size!
fi
# end of 'examples/battle/Makefile'
fi
if test ! -d 'examples/hanoi' ; then
    echo shar: Creating directory \"'examples/hanoi'\"
    mkdir 'examples/hanoi'
fi
if test -f 'examples/hanoi/Makefile' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'examples/hanoi/Makefile'\"
else
echo shar: Extracting \"'examples/hanoi/Makefile'\" \(40 characters\)
sed "s/^X//" >'examples/hanoi/Makefile' <<'END_OF_FILE'
Xhanoi: hanoi.c
X	lc -L+lib:curses.lib $@
END_OF_FILE
if test 40 -ne `wc -c <'examples/hanoi/Makefile'`; then
    echo shar: \"'examples/hanoi/Makefile'\" unpacked with wrong size!
fi
# end of 'examples/hanoi/Makefile'
fi
if test -f 'examples/hanoi/hanoi.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'examples/hanoi/hanoi.c'\"
else
echo shar: Extracting \"'examples/hanoi/hanoi.c'\" \(5132 characters\)
sed "s/^X//" >'examples/hanoi/hanoi.c' <<'END_OF_FILE'
X/*
X *	Name: Towers of Hanoi.
X *
X *	Desc:
X *		This is a playable copy of towers of hanoi.
X *		Its sole purpose is to demonstrate my Amiga Curses package.
X *		This program should compile on any system that has Curses.
X *		'hanoi'		will give a manual game with 7 playing pieces.
X *		'hanoi n'	will give a manual game with n playing pieces.
X *		'hanoi n a' will give an auto solved game with n playing pieces.
X *
X *	Author: Simon J Raybould	(sie@fulcrum.bt.co.uk).
X *
X *	Date: 05.Nov.90
X *
X */
X
X#include <curses.h>
X
X#define NPEGS			3	/* This is not configurable !! */
X#define MINTILES		3
X#define MAXTILES		9
X#define DEFAULTTILES	7
X#define TOPLINE			6
X#define BASELINE		16
X#define STATUSLINE		(LINES-3)
X#define LEFTPEG			19
X#define MIDPEG			39
X#define RIGHTPEG		59
X
X#define LENTOIND(x)		(((x)-1)/2-1)
X#define OTHER(a,b)		(3-((a)+(b)))
X
Xstruct Peg {
X	int Length[MAXTILES];
X	int Count;
X};
X
Xstruct Peg Pegs[NPEGS];
Xint PegPos[] = { LEFTPEG, MIDPEG, RIGHTPEG };
Xint TileColour[] = {
X	COLOR_ORANGE,	/* Length 3 */
X	COLOR_MAGENTA,	/* Length 5 */
X	COLOR_RED,		/* Length 7 */
X	COLOR_BLUE,		/* Length 9 */
X	COLOR_GREEN,	/* Length 11 */
X	COLOR_GREY,		/* Length 13 */
X	COLOR_YELLOW,	/* Length 15 */
X	COLOR_CYAN,		/* Length 17 */
X	COLOR_WHITE,	/* Length 19 */
X};
Xint NMoves = 0;
X
Xmain(int argc, char **argv)
X{
X	int NTiles, FromCol, ToCol, catch();
X	unsigned char AutoFlag = 0;
X	void InitTiles(), DisplayTiles(), MakeMove(), AutoMove(), Usage();
X
X	switch(argc) {
X	case 1:
X		NTiles = DEFAULTTILES;
X		break;
X	case 2:
X		NTiles = atoi(argv[1]);
X		if(NTiles>MAXTILES || NTiles<MINTILES) {
X			fprintf(stderr, "Range %d to %d\n", MINTILES, MAXTILES);
X			exit(1);
X		}
X		break;
X	case 3:
X		if(strcmp(argv[2], "a")) {
X			Usage();
X			exit(1);
X		}
X		NTiles = atoi(argv[1]);
X		if(NTiles>MAXTILES || NTiles<MINTILES) {
X			fprintf(stderr, "Range %d to %d\n", MINTILES, MAXTILES);
X			exit(1);
X		}
X		AutoFlag = TRUE;
X		break;
X	default:
X		Usage();
X		exit(1);
X	}
X	initscr();
X	cbreak();
X	if(LINES<24) {
X		fprintf(stderr, "Min screen length 24 lines\n");
X		endwin();
X		exit(1);
X	}
X	if(AutoFlag)
X		leaveok(stdscr, TRUE);	/* Attempt to remove cursor */
X	InitTiles(NTiles);
X	DisplayTiles();
X	if(AutoFlag) {
X		do {
X			AutoMove(0, 2, NTiles);
X		} while(!Solved(NTiles));
X		sleep(5);
X	} else {
X		for(;;) {
X			if(GetMove(&FromCol, &ToCol))
X				break;
X			if(InvalidMove(FromCol, ToCol)) {
X				mvaddstr(STATUSLINE, 0, "Invalid Move !!");
X				refresh();
X				beep();
X				continue;
X			}
X			MakeMove(FromCol, ToCol);
X			if(Solved(NTiles)) {
X				mvprintw(STATUSLINE, 0, "Well Done !! You did it in %d moves", NMoves);
X				refresh();
X				sleep(5);
X				break;
X			}
X		}
X	}
X	endwin();
X}
X
XInvalidMove(int From, int To)
X{
X	if(From == To)
X		return TRUE;
X	if(!Pegs[From].Count)
X		return TRUE;
X	if(Pegs[To].Count &&
X			Pegs[From].Length[Pegs[From].Count-1] >
X			Pegs[To].Length[Pegs[To].Count-1])
X		return TRUE;
X	return FALSE;
X}
X
Xvoid
XInitTiles(int NTiles)
X{
X	int Size, SlotNo;
X	
X	for(Size=NTiles*2+1, SlotNo=0; Size>=3; Size-=2)
X		Pegs[0].Length[SlotNo++] = Size;
X	
X	Pegs[0].Count = NTiles;
X	Pegs[1].Count = 0;
X	Pegs[2].Count = 0;
X}
X
Xvoid
XDisplayTiles()
X{
X	int Line, Peg, SlotNo;
X	char TileBuf[BUFSIZ];
X
X	erase();
X	mvaddstr(1, 24, "T O W E R S   O F   H A N O I");
X	mvaddstr(3, 34, "SJR 1990");
X	mvprintw(19, 5, "Moves : %d", NMoves);
X	attron(COLOR_TAN);
X	standout();
X	mvaddstr(BASELINE, 8, "                                                               ");
X
X	for(Line=TOPLINE; Line<BASELINE; Line++) {
X		mvaddch(Line, LEFTPEG, ' ');
X		mvaddch(Line, MIDPEG, ' ');
X		mvaddch(Line, RIGHTPEG, ' ');
X	}
X	mvaddch(BASELINE, LEFTPEG, '1');
X	mvaddch(BASELINE, MIDPEG, '2');
X	mvaddch(BASELINE, RIGHTPEG, '3');
X
X	/* Draw tiles */
X	for(Peg=0; Peg<NPEGS; Peg++) {
X		for(SlotNo=0; SlotNo<Pegs[Peg].Count; SlotNo++) {
X			memset(TileBuf, ' ', Pegs[Peg].Length[SlotNo]);
X			TileBuf[Pegs[Peg].Length[SlotNo]] = '\0';
X			attron(TileColour[LENTOIND(Pegs[Peg].Length[SlotNo])]);
X			mvaddstr(BASELINE-(SlotNo+1),
X					PegPos[Peg]-Pegs[Peg].Length[SlotNo]/2, TileBuf);
X		}
X	}
X	attrset(0);
X	refresh();
X}
X
XGetMove(int *From, int *To)
X{
X	mvaddstr(STATUSLINE, 0, "Next move ('q' to quit) from ");
X	clrtoeol();
X	refresh();
X	if((*From = getch()) == 'q')
X		return TRUE;
X	*From -= ('0'+1);
X	addstr(" to ");
X	clrtoeol();
X	refresh();
X	if((*To = getch()) == 'q')
X		return TRUE;
X	*To -= ('0'+1);
X	move(STATUSLINE, 0);
X	clrtoeol();
X	refresh();
X	return FALSE;
X}
X
Xvoid
XMakeMove(int From, int To)
X{
X	void DisplayTiles();
X
X	Pegs[From].Count--;
X	Pegs[To].Length[Pegs[To].Count] = Pegs[From].Length[Pegs[From].Count];
X	Pegs[To].Count++;
X	NMoves++;
X	DisplayTiles();
X}
X
Xvoid
XAutoMove(int From, int To, int Num)
X{
X	void MakeMove();
X
X	if(Num == 1) {
X		MakeMove(From, To);
X		return;
X	}
X	AutoMove(From, OTHER(From, To), Num-1);
X	MakeMove(From, To);
X	AutoMove(OTHER(From, To), To, Num-1);
X}
X
XSolved(int NumTiles)
X{
X	int i;
X
X	for(i=1; i<NPEGS; i++)
X		if(Pegs[i].Count == NumTiles)
X			return TRUE;
X	return FALSE;
X}
X
Xvoid
XUsage()
X{
X	fprintf(stderr, "Usage: %s [<No Of Tiles>] [a]\n");
X	fprintf(stderr, "The 'a' option causes the tower to be solved automatically\n");
X}
X
X#ifdef AMIGA
Xsleep(int n)
X{
X	Delay(50*n);
X	return 0;
X}
X#endif /* AMIGA */
END_OF_FILE
if test 5132 -ne `wc -c <'examples/hanoi/hanoi.c'`; then
    echo shar: \"'examples/hanoi/hanoi.c'\" unpacked with wrong size!
fi
# end of 'examples/hanoi/hanoi.c'
fi
if test ! -d 'examples/odds' ; then
    echo shar: Creating directory \"'examples/odds'\"
    mkdir 'examples/odds'
fi
if test -f 'examples/odds/knight.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'examples/odds/knight.c'\"
else
echo shar: Extracting \"'examples/odds/knight.c'\" \(7237 characters\)
sed "s/^X//" >'examples/odds/knight.c' <<'END_OF_FILE'
X/* Knights Tour - a brain game */
X
X#include <stdio.h>
X#ifdef BSD
X#include <ctype.h>
X#endif
X#include <curses.h>
X#include <signal.h>
X
Xshort   board [64];     /* the squares */
Xchar    row, column;    /* input characters */
Xint     rw,col;         /* numeric equivalent of row and column */
Xint     curow,curcol;   /* current row and column integers */
Xint     rdif, cdif;     /* difference between input and current */
Xint     j;              /* index into board */
X
Xchar	script[]={"'_)//,/(-)/__/__(_<_(__),|/|/_///_/_<//_/_)__o__o'______///_(--_(_)___,(_/,_/__(_\0"};
X
Xint	ypos[] ={1,0,1,2,3,0,1,2,2,3,3,2,2,3,2,2,3,3,3,3,3,2,3,3,2,4,5,5,
X	4,3,3,2,1,2,3,3,3,2,1,3,3,2,3,3,3,2,1,1,0,1,4,4,4,4,4,4,5,6,7,7,
X	7,6,6,6,7,7,7,6,6,6,6,7,7,7,6,7,7,6,6,7,7};
X
Xint	xpos[]={0,1,2,1,0,5,4,3,2,4,6,7,8,8,9,10,10,11,12,13,14,15,15,16,
X	16,16,15,14,15,17,18,19,20,20,20,21,22,23,24,23,25,26,27,26,28,
X	13,23,25,27,27,2,3,4,5,6,7,4,3,2,1,0,1,2,5,4,5,6,6,7,8,9,8,9,10,
X	11,11,12,13,14,14,15};
X
Xstatic char *instructions[] = 
X{
X"     Knight's Tour is a board game for one player.   It is played on",
X"an eight by eight board and is based on the allowable moves that a knight",
X"can make in the game of chess.  For those who are unfamiliar with the",
X"game, a knight may move either on a row or a column but not diagonally.",
X"He may move one square in any direction and two squares in a perpendicular",
X"direction >or< two squares in any direction and one square in a",
X"perpendicular direction.  He may not, of course, move off the board.",
X"",
X"     At the beginning of a game you will be asked to either choose a",
X"starting square or allow the computer to select a random location.",
X"Squares are designated by a letter-number combination where the row is",
X"specified by a letter A-H and the numbers 1-8 define a column.  Invalid",
X"entries are ignored and illegal moves produce a beep at the terminal.",
X"",
X"     The objective is to visit every square on the board.  When you claim",
X"a square a marker is placed on it to show where you've been.  You may",
X"not revisit a square that you've landed on before.",
X"",
X"     After each move the program checks to see if you have any legal",
X"moves left.  If not, the game ends and your squares are counted.  If",
X"you've made all the squares you win the game.  Otherwise, you are told",
X"the number of squares you did make.",
X"END"
X};
X
X
Xmain ()
X{
X	init ();
X	for (;;)  if (!play ()) {
X			endwin ();
X			exit (0);
X	}
X}
X
Xinit ()
X{
X	char c;
X
X	srand48 (getpid());
X	initscr ();
X	signal (SIGINT,SIG_IGN); 
X	cbreak ();              /* immediate char return */
X	noecho ();              /* no immediate echo */
X	title (1,23);
X	mvaddstr (23, 25, "Would you like instructions? ");
X	refresh();
X	if ((c=toupper (getch())) == 'Y') instruct();
X	clear ();
X}
X
Xplay ()
X{
X	drawboard ();           /* clear screen and drawboard */
X	for (j = 0; j < 64; j++) board[j]=0;
X	getfirst ();            /* get the starting square */
X	for (;;) {
X		getrc();
X		if (evalmove()) {
X			putstars ();
X			if (!chkmoves()) return (endgame ());
X		}
X#ifdef BSD
X		else putchar('\007');
X#else
X		else beep();
X#endif
X	}
X}
X
Xdrawboard ()
X{
X	erase ();
X	dosquares ();
X	refresh ();
X	mvaddstr (0, 7, "1   2   3   4   5   6   7   8");
X	for (j = 0; j < 8; j++) mvaddch (2*j+2, 3, j + 'A');
X	refresh ();
X	mvaddstr (20,  5, "ROW:");
X	mvaddstr (20, 27, "COLUMN:");
X	mvaddstr (14, 49, "CURRENT ROW");
X	mvaddstr (16, 49, "CURRENT COL");
X	mvaddstr (22,  5, "A - H or Q to quit");
X	mvaddstr (22, 27, "1 - 8 or ESC to cancel row");
X	refresh ();
X	title (1,40);
X}
X
Xdosquares ()
X{
X	mvaddstr (1, 6, "-------------------------------");
X	for (j = 1; j < 9; j++){
X		mvaddstr (2*j, 5,  "|   |   |   |   |   |   |   |   |");
X		mvaddstr (2*j+1, 6, "-------------------------------");
X	}
X}
X
Xgetfirst ()                             /* get first square */
X{
X	mvaddstr (23, 25, "(S)elect or (R)andom "); refresh ();
X	do {
X		row = toupper(getch());
X	} while ((row != 'S') && (row != 'R'));
X	if (row == 'R') {
X		rw = lrand48() % 8;
X		col = lrand48() % 8;
X		j = 8* rw + col;
X		row = rw + 'A';
X		column = col + '1';
X	}
X	else {
X		mvaddstr (23, 25, "Enter starting row and column");
X		refresh ();
X		getrc();                        /* get row and column */
X	}
X	putstars ();
X	move (23, 0);
X	clrtobot();
X}       
X
Xgetrc ()                                /* get row and column */
X{
X	noecho ();
X	do {
X		mvaddstr (20, 35, "  ");
X		refresh ();
X		do {
X			mvaddch (20, 11, ' ');
X			move (20, 11);
X			refresh ();
X			row=toupper(getch());
X			if (row == 'Q') {
X				endwin ();
X				exit (1);
X			}
X		} while ((row < 'A') || (row > 'H'));
X		addch (row);
X		move (20, 35);
X		refresh ();
X		do {
X			column=getch();
X			if (column == '\033') break;
X		} while ((column < '1') || (column > '8'));
X		if (column != '\033') addch (column);
X	} while (column == '\033');
X	refresh();
X	rw = row - 'A';
X	col= column - '1';
X	j = 8 * rw + col;
X}
X
Xputstars ()                     /* place the stars, update board & currents */
X{
X	mvaddch (2*curow+2, 38, ' ');
X	mvaddch (2*rw+2, 38, '<');
X	mvaddch (18, curcol*4+7, ' ');
X	mvaddch (18, col*4+7, '^');
X	curow = rw;
X	curcol= col;
X	mvaddstr (2 * rw + 2, 4*col+6, "***");
X	mvaddch (14, 61, row);
X	mvaddch (16, 61, column);
X	refresh ();
X	board[j] = 1;
X}
X
Xevalmove()                      /* convert row and column to integers */
X		                /* and evaluate move */
X{
X	rdif = rw - curow;
X	cdif = col - curcol;
X	rdif = abs(rw  - curow);
X	cdif = abs(col - curcol);
X	refresh ();
X	if ((rdif == 1) && (cdif == 2)) if (board [j] == 0) return (1);
X	if ((rdif == 2) && (cdif == 1)) if (board [j] == 0) return (1);
X	return (0);
X}
X
Xchkmoves ()                     /* check to see if valid moves are available */
X{
X	if (chksqr(2,1))   return (1);
X	if (chksqr(2,-1))  return (1);
X	if (chksqr(-2,1))  return (1);
X	if (chksqr(-2,-1)) return (1);
X	if (chksqr(1,2))   return (1);
X	if (chksqr(1,-2))  return (1);
X	if (chksqr(-1,2))  return (1);
X	if (chksqr(-1,-2)) return (1);
X	return (0);
X}
X
Xendgame ()                      /* check for filled board or not */
X{
X	rw = 0;
X	for (j = 0; j < 64; j++) if (board[j] != 0) rw+=1;
X	if (rw == 64) mvaddstr (20, 20, "Congratulations !! You got 'em all");
X		else mvprintw (20, 20, "You have ended up with %2d squares",rw);
X	mvaddstr (21, 25, "Play again ? (y/n) ");
X	refresh ();
X	if ((row=tolower(getch())) == 'y') return (1);
X		else return (0);
X}
X
X#ifndef abs
Xabs(num)
Xint	num;
X{
X	if (num < 0) return (-num);
X		else return (num);
X}
X#endif
X
Xchksqr (n1, n2)
Xint	n1,n2;
X
X{
X	int	r1, c1;
X
X	r1 = rw + n1;
X	c1 = col + n2;
X	if ((r1<0) || (r1>7)) return (0);
X	if ((c1<0) || (c1>7)) return (0);
X	if (board[r1*8+c1] == 0) return (1);
X		else return (0);
X}
X
Xinstruct()
X{
X	int i;
X	char	c;
X
X	clear ();
X	for (i=0;;i++) {
X		if ((strcmp(instructions[i],"END"))) mvaddstr (i, 0, instructions[i]);
X			else {
X				mvaddstr (23, 25, "Ready to play ? (y/n) ");
X				refresh();
X				if ((c=toupper(getch())) == 'Y') {
X					clear ();
X					return (1);
X				}
X					else {
X						clear ();
X						refresh ();
X						endwin ();
X						exit ();
X					}
X			}
X	}
X}
X
Xtitle (y,x)
Xint	y,x;
X{
X	char c;
X	j = 0;
X	do {
X		c = script[j];
X		if (c == 0) break ;
X		mvaddch (ypos[j]+y, xpos[j]+x, c);
X		refresh ();
X		j++;
X	} while (c != 0);
X}
X
X#ifdef AMIGA
Xgetpid()
X{
X  return 221;
X}
X#endif /* AMIGA */
X
END_OF_FILE
if test 7237 -ne `wc -c <'examples/odds/knight.c'`; then
    echo shar: \"'examples/odds/knight.c'\" unpacked with wrong size!
fi
# end of 'examples/odds/knight.c'
fi
if test -f 'examples/odds/rain.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'examples/odds/rain.c'\"
else
echo shar: Extracting \"'examples/odds/rain.c'\" \(1713 characters\)
sed "s/^X//" >'examples/odds/rain.c' <<'END_OF_FILE'
X#define MINICURSES
X#include <curses.h>
X#include <signal.h>
X/* rain 11/3/1980 EPS/CITHEP */
X
X#define cursor(col,row) move(row,col)
Xmain(argc,argv)
Xint argc;
Xchar *argv[];
X{
X    char *malloc();
X    float ranf();
X    int onsig();
X    register int x, y, j;
X    static int xpos[5], ypos[5];
X    setbuf(stdout,malloc(BUFSIZ));
X
X#ifdef AMIGA
X    signal(SIGINT, SIG_IGN);
X#else
X    for (j=SIGHUP;j<=SIGTERM;j++)
X	if (signal(j,SIG_IGN)!=SIG_IGN) signal(j,onsig);
X#endif /* AMIGA */
X
X    initscr();
X    nl();
X    noecho();
X    for (j=5;--j>=0;) {
X	xpos[j]=(int)(76.*ranf())+2;
X	ypos[j]=(int)(20.*ranf())+2;
X    }
X    for (j=0;;) {
X	x=(int)(76.*ranf())+2;
X	y=(int)(20.*ranf())+2;
X
X	cursor(x,y); addch('.');
X
X	cursor(xpos[j],ypos[j]); addch('o');
X
X	if (j==0) j=4; else --j;
X	cursor(xpos[j],ypos[j]); addch('O');
X
X	if (j==0) j=4; else --j;
X	cursor(xpos[j],ypos[j]-1);
X	addch('-');
X	cursor(xpos[j]-1,ypos[j]);
X	addstr("|.|");
X	cursor(xpos[j],ypos[j]+1);
X	addch('-');
X
X	if (j==0) j=4; else --j;
X	cursor(xpos[j],ypos[j]-2);
X	addch('-');
X	cursor(xpos[j]-1,ypos[j]-1);
X	addstr("/ \\");
X	cursor(xpos[j]-2,ypos[j]);
X	addstr("| O |");
X	cursor(xpos[j]-1,ypos[j]+1);
X	addstr("\\ /");
X	cursor(xpos[j],ypos[j]+2);
X	addch('-');
X
X	if (j==0) j=4; else --j;
X	cursor(xpos[j],ypos[j]-2);
X	addch(' ');
X	cursor(xpos[j]-1,ypos[j]-1);
X	addstr("   ");
X	cursor(xpos[j]-2,ypos[j]);
X	addstr("     ");
X	cursor(xpos[j]-1,ypos[j]+1);
X	addstr("   ");
X	cursor(xpos[j],ypos[j]+2);
X	addch(' ');
X	xpos[j]=x; ypos[j]=y;
X	refresh();
X    }
X}
X
Xonsig(n)
Xint n;
X{
X    endwin();
X    exit(0);
X}
X
Xfloat
Xranf()
X{
X    float rv;
X    long r = rand();
X
X    r &= 077777;
X    rv =((float)r/32767.);
X    return rv;
X}
X
X#ifdef AMIGA
Xgetpid()
X{
X  return 221;
X}
X#endif /* AMIGA */
END_OF_FILE
if test 1713 -ne `wc -c <'examples/odds/rain.c'`; then
    echo shar: \"'examples/odds/rain.c'\" unpacked with wrong size!
fi
# end of 'examples/odds/rain.c'
fi
if test -f 'examples/odds/worms.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'examples/odds/worms.c'\"
else
echo shar: Extracting \"'examples/odds/worms.c'\" \(6021 characters\)
sed "s/^X//" >'examples/odds/worms.c' <<'END_OF_FILE'
X/*
X
X	 @@@        @@@    @@@@@@@@@@     @@@@@@@@@@@    @@@@@@@@@@@@
X	 @@@        @@@   @@@@@@@@@@@@    @@@@@@@@@@@@   @@@@@@@@@@@@@
X	 @@@        @@@  @@@@      @@@@   @@@@           @@@@ @@@  @@@@
X	 @@@   @@   @@@  @@@        @@@   @@@            @@@  @@@   @@@
X	 @@@  @@@@  @@@  @@@        @@@   @@@            @@@  @@@   @@@
X	 @@@@ @@@@ @@@@  @@@        @@@   @@@            @@@  @@@   @@@
X	  @@@@@@@@@@@@   @@@@      @@@@   @@@            @@@  @@@   @@@
X	   @@@@  @@@@     @@@@@@@@@@@@    @@@            @@@  @@@   @@@
X	    @@    @@       @@@@@@@@@@     @@@            @@@  @@@   @@@
X
X				 Eric P. Scott
X			  Caltech High Energy Physics
X				 October, 1980
X
X*/
X#define MINICURSES
X#include <curses.h>
X#include <signal.h>
X#define cursor(col,row) move(row,col)
Xint Wrap;
Xshort *ref[128];
Xstatic char flavor[]={
X    'O', '*', '#', '$', '%', '0'
X};
Xstatic short xinc[]={
X     1,  1,  1,  0, -1, -1, -1,  0
X}, yinc[]={
X    -1,  0,  1,  1,  1,  0, -1, -1
X};
Xstatic struct worm {
X    int orientation, head;
X    short *xpos, *ypos;
X} worm[40];
Xstatic char *field;
Xstatic int length=16, number=3, trail=' ';
Xstatic struct options {
X    int nopts;
X    int opts[3];
X} normal[8]={
X    { 3, { 7, 0, 1 } },
X    { 3, { 0, 1, 2 } },
X    { 3, { 1, 2, 3 } },
X    { 3, { 2, 3, 4 } },
X    { 3, { 3, 4, 5 } },
X    { 3, { 4, 5, 6 } },
X    { 3, { 5, 6, 7 } },
X    { 3, { 6, 7, 0 } }
X}, upper[8]={
X    { 1, { 1, 0, 0 } },
X    { 2, { 1, 2, 0 } },
X    { 0, { 0, 0, 0 } },
X    { 0, { 0, 0, 0 } },
X    { 0, { 0, 0, 0 } },
X    { 2, { 4, 5, 0 } },
X    { 1, { 5, 0, 0 } },
X    { 2, { 1, 5, 0 } }
X}, left[8]={
X    { 0, { 0, 0, 0 } },
X    { 0, { 0, 0, 0 } },
X    { 0, { 0, 0, 0 } },
X    { 2, { 2, 3, 0 } },
X    { 1, { 3, 0, 0 } },
X    { 2, { 3, 7, 0 } },
X    { 1, { 7, 0, 0 } },
X    { 2, { 7, 0, 0 } }
X}, right[8]={
X    { 1, { 7, 0, 0 } },
X    { 2, { 3, 7, 0 } },
X    { 1, { 3, 0, 0 } },
X    { 2, { 3, 4, 0 } },
X    { 0, { 0, 0, 0 } },
X    { 0, { 0, 0, 0 } },
X    { 0, { 0, 0, 0 } },
X    { 2, { 6, 7, 0 } }
X}, lower[8]={
X    { 0, { 0, 0, 0 } },
X    { 2, { 0, 1, 0 } },
X    { 1, { 1, 0, 0 } },
X    { 2, { 1, 5, 0 } },
X    { 1, { 5, 0, 0 } },
X    { 2, { 5, 6, 0 } },
X    { 0, { 0, 0, 0 } },
X    { 0, { 0, 0, 0 } }
X}, upleft[8]={
X    { 0, { 0, 0, 0 } },
X    { 0, { 0, 0, 0 } },
X    { 0, { 0, 0, 0 } },
X    { 0, { 0, 0, 0 } },
X    { 0, { 0, 0, 0 } },
X    { 1, { 3, 0, 0 } },
X    { 2, { 1, 3, 0 } },
X    { 1, { 1, 0, 0 } }
X}, upright[8]={
X    { 2, { 3, 5, 0 } },
X    { 1, { 3, 0, 0 } },
X    { 0, { 0, 0, 0 } },
X    { 0, { 0, 0, 0 } },
X    { 0, { 0, 0, 0 } },
X    { 0, { 0, 0, 0 } },
X    { 0, { 0, 0, 0 } },
X    { 1, { 5, 0, 0 } }
X}, lowleft[8]={
X    { 3, { 7, 0, 1 } },
X    { 0, { 0, 0, 0 } },
X    { 0, { 0, 0, 0 } },
X    { 1, { 1, 0, 0 } },
X    { 2, { 1, 7, 0 } },
X    { 1, { 7, 0, 0 } },
X    { 0, { 0, 0, 0 } },
X    { 0, { 0, 0, 0 } }
X}, lowright[8]={
X    { 0, { 0, 0, 0 } },
X    { 1, { 7, 0, 0 } },
X    { 2, { 5, 7, 0 } },
X    { 1, { 5, 0, 0 } },
X    { 0, { 0, 0, 0 } },
X    { 0, { 0, 0, 0 } },
X    { 0, { 0, 0, 0 } },
X    { 0, { 0, 0, 0 } }
X};
Xmain(argc,argv)
Xint argc;
Xchar *argv[];
X{
X    char *malloc();
X    int onsig();
X    float ranf();
X    register int x, y;
X    register int n;
X    register struct worm *w;
X    register struct options *op;
X    register int h;
X    register short *ip;
X    int last, bottom;
X
X    setbuf(stdout,malloc(BUFSIZ));
X
X    for (x=1;x<argc;x++) {
X	register char *p;
X	p=argv[x];
X	if (*p=='-') p++;
X	switch (*p) {
X	case 'f':
X	    field="WORM";
X	    break;
X	case 'l':
X	    if (++x==argc) goto usage;
X	    if ((length=atoi(argv[x]))<2||length>1024) {
X		fprintf(stderr,"%s: Invalid length\n",*argv);
X		exit(1);
X	    }
X	    break;
X	case 'n':
X	    if (++x==argc) goto usage;
X	    if ((number=atoi(argv[x]))<1||number>40) {
X		fprintf(stderr,"%s: Invalid number of worms\n",*argv);
X		exit(1);
X	    }
X	    break;
X	case 't':
X	    trail='.';
X	    break;
X	default:
X	usage:
X	    fprintf(stderr,
X		"usage: %s [-field] [-length #] [-number #] [-trail]\n",*argv);
X	    exit(1);
X	    break;
X	}
X    }
X
X    signal(SIGINT, onsig);
X    initscr();
X    bottom = LINES-1;
X    last = COLS-1;
X
X    ip=(short *)malloc(LINES*COLS*sizeof (short));
X
X    for (n=0;n<LINES;) {
X	ref[n++]=ip; ip+=COLS;
X    }
X    for (ip=ref[0],n=LINES*COLS;--n>=0;) *ip++=0;
X    ref[bottom][last]=1;
X    for (n=number, w= &worm[0];--n>=0;w++) {
X	w->orientation=w->head=0;
X	if (!(ip=(short *)malloc(length*sizeof (short)))) {
X	    fprintf(stderr,"%s: out of memory\n",*argv);
X	    exit(1);
X	}
X	w->xpos=ip;
X	for (x=length;--x>=0;) *ip++ = -1;
X	if (!(ip=(short *)malloc(length*sizeof (short)))) {
X	    fprintf(stderr,"%s: out of memory\n",*argv);
X	    exit(1);
X	}
X	w->ypos=ip;
X	for (y=length;--y>=0;) *ip++ = -1;
X    }
X    if (field) {
X	register char *p;
X	p=field;
X	for (y=bottom;--y>=0;) {
X	    for (x=COLS;--x>=0;) {
X		addch(*p++);
X		if (!*p) p=field;
X	    }
X            addch('\n');
X        }
X    }
X    refresh();
X
X    for (;;) {
X	for (n=0,w= &worm[0];n<number;n++,w++) {
X	    if ((x=w->xpos[h=w->head])<0) {
X		cursor(x=w->xpos[h]=0,y=w->ypos[h]=bottom);
X		addch(flavor[n%6]);
X		ref[y][x]++;
X	    }
X	    else y=w->ypos[h];
X	    if (++h==length) h=0;
X	    if (w->xpos[w->head=h]>=0) {
X		register int x1, y1;
X		x1=w->xpos[h]; y1=w->ypos[h];
X		if (--ref[y1][x1]==0) {
X		    cursor(x1,y1); addch(trail);
X		}
X	    }
X            op= &(x==0 ? (y==0 ? upleft : (y==bottom ? lowleft : left)) :
X                (x==last ? (y==0 ? upright : (y==bottom ? lowright : right)) :
X		(y==0 ? upper : (y==bottom ? lower : normal))))[w->orientation];
X	    switch (op->nopts) {
X	    case 0:
X		refresh();
X		endwin();
X		abort();
X		return;
X	    case 1:
X		w->orientation=op->opts[0];
X		break;
X	    default:
X		w->orientation=op->opts[(int)(ranf()*(float)op->nopts)];
X	    }
X	    cursor(x+=xinc[w->orientation], y+=yinc[w->orientation]);
X	    if (!Wrap||x!=last||y!=bottom) addch(flavor[n%6]);
X	    ref[w->ypos[h]=y][w->xpos[h]=x]++;
X	}
X	refresh();
X    }
X}
X
Xonsig()
X{
X	endwin();
X	exit(0);
X}
X
Xfloat
Xranf()
X{
X    float rv;
X    long r = rand();
X
X    r &= 077777;
X    rv =((float)r/32767.);
X    return rv;
X}
END_OF_FILE
if test 6021 -ne `wc -c <'examples/odds/worms.c'`; then
    echo shar: \"'examples/odds/worms.c'\" unpacked with wrong size!
fi
# end of 'examples/odds/worms.c'
fi
if test ! -d 'src' ; then
    echo shar: Creating directory \"'src'\"
    mkdir 'src'
fi
if test -f 'src/Makefile.lattice' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'src/Makefile.lattice'\"
else
echo shar: Extracting \"'src/Makefile.lattice'\" \(564 characters\)
sed "s/^X//" >'src/Makefile.lattice' <<'END_OF_FILE'
X#
X#	Description : Lattice Makefile for AMIGA CURSES library.
X#
X#	Authur	  : Simon Raybould.  (sie@fulcrum.bt.co.uk)
X#
X#	Date		: 16th February 1990
X#
X
XCC= lc
XCFLAGS= -v
X
Xall: curses.lib curses32.lib
X	 copy curses.lib LIB: CLONE
X	 copy curses32.lib LIB: CLONE
X	 copy curses.h INCLUDE: CLONE
X
Xcurses.lib: curses.c acurses.h
X	$(CC) $(CFLAGS) curses.c
X	copy curses.o $@
X	delete curses.o
X
Xcurses32.lib:	curses.c acurses.h
X	$(CC) -b0 $(CFLAGS) curses.c
X	copy curses.o $@
X	delete curses.o
X
Xclean:	
X	-delete \#?.o
X	-delete \#?.lnk
X	-delete curses.lib
X	-delete curses32.lib
END_OF_FILE
if test 564 -ne `wc -c <'src/Makefile.lattice'`; then
    echo shar: \"'src/Makefile.lattice'\" unpacked with wrong size!
fi
# end of 'src/Makefile.lattice'
fi
if test -f 'src/Read_Me' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'src/Read_Me'\"
else
echo shar: Extracting \"'src/Read_Me'\" \(739 characters\)
sed "s/^X//" >'src/Read_Me' <<'END_OF_FILE'
X		Curses for the Amiga
X
XThis is the Read_Me file provided with the source code for Amiga Curses.
XSee the documentation provided with the libraries for more information.
X
XThis source is the result of many requests mainly from Aztec users for source
Xcode to allow them to use curses. So here it is (Don't say I don't read the
Xletters). Please do NOT alter this code, report any changes you wish made
Xback to me and they will be added for future releases. Thank You!
X
XThis source is provided for people to make up working libraries under
Xvarious other compilers.
X
XThe code must NOT be altered in any way.
X
XVerbatim copies of source may be freely distributed.
X
XPlease report any bugs back to 'sie@fulcrum.bt.co.uk' so that others may
Xbenifit.
END_OF_FILE
if test 739 -ne `wc -c <'src/Read_Me'`; then
    echo shar: \"'src/Read_Me'\" unpacked with wrong size!
fi
# end of 'src/Read_Me'
fi
if test -f 'src/acurses.h' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'src/acurses.h'\"
else
echo shar: Extracting \"'src/acurses.h'\" \(2121 characters\)
sed "s/^X//" >'src/acurses.h' <<'END_OF_FILE'
X#include <intuition/intuition.h>
X#include <intuition/screens.h>
X  
X#undef TRUE
X#undef FALSE
X#include "curses.h"
X  
X/*
X *
X * Module      : acurses.h
X *
X * Description : Header file for AMIGA CURSES package.
X *
X * Author      : Simon Raybould  (sie@fulcrum.bt.co.uk)
X *
X * Date        : 16th February 1990
X *
X */
X  
X  
X#define MAXTEXTLEN    80    /* Max text to an output call */
X#define SOUNDLENGTH    2    /* Number of bytes in the sound wave */
X#define CAPSMASK    0x07    /* leftshift | rightshift | capslock */
X#define SHIFTMASK    0x03    /* leftshift | rightshift */
X  
X/*
X *    Characters
X */
X  
X#define BS            0x08    /* Backspace */
X#define CR            0x0d    /* Carriage return */
X  
X/*
X *    My Flags. These are global to all windows, not window specific.
X */
X
X#define CFLAG_CURSOR    (1<<0)    /* T=Cursor on, F=Cursor off. */
X#define CFLAG_CBREAK    (1<<1)    /* T=cbreak mode, F=nocbreak mode */
X#define CFLAG_NLCR    (1<<2)    /* T=nl to cr mapping, F=no mapping */
X#define    CFLAG_ECHO    (1<<3)    /* T=Echo enabled, F=no echo */
X#define    CFLAG_INITSCR    (1<<4)    /* T=initscr has been called */
X
X/*
X *    WINDOW flags, these are specific to each window.
X */
X
X#define CWF_MOVED    (1<<0)    /* move() has been done on this window */
X
X/*
X *    Buffer size for raw key events.
X */
X#define RAWBUFSIZ    32
X
X/*
X *    Scroll directions
X */
X#define SCROLL_UP    1
X#define SCROLL_DOWN    2
X
X/*
X *    Internal structures.
X */
X
Xstruct LineElement {
X  unsigned char Touched;    /* This line needs refreshing */
X  char *Line;    /* Actual text */
X  char *LRLine;    /* text when last refreshed */
X  short *ATTRS;    /* Attributes */
X  short *LRATTRS;    /* Attributes when last refreshed */
X  unsigned char StartCol;
X  unsigned char EndCol;
X};
X
Xstruct WindowState {
X  WINDOW *ParentWin;
X  WINDOW Window;
X  short ScrollTop;
X  short ScrollBot;
X  struct WindowState *Prev;
X  struct WindowState *Next;
X  struct LineElement *LnArry;
X  unsigned char NLines;
X};
X
X/*
X *    Simple implementation of wnoutrefresh() and doupdate()
X */
X
Xstruct RefreshElement {
X  WINDOW *WinPtr;
X  struct RefreshElement *Next;
X};
END_OF_FILE
if test 2121 -ne `wc -c <'src/acurses.h'`; then
    echo shar: \"'src/acurses.h'\" unpacked with wrong size!
fi
# end of 'src/acurses.h'
fi
echo shar: End of archive 1 \(of 8\).
cp /dev/null ark1isdone
MISSING=""
for I in 1 2 3 4 5 6 7 8 ; do
    if test ! -f ark${I}isdone ; then
	MISSING="${MISSING} ${I}"
    fi
done
if test "${MISSING}" = "" ; then
    echo You have unpacked all 8 archives.
    rm -f ark[1-9]isdone
else
    echo You still need to unpack the following archives:
    echo "        " ${MISSING}
fi
##  End of shell archive.
exit 0
-- 
Mail submissions (sources or binaries) to <amiga@uunet.uu.net>.
Mail comments to the moderator at <amiga-request@uunet.uu.net>.
Post requests for sources, and general discussion to comp.sys.amiga.misc.