xref: /minix3/lib/libcurses/PSD.doc/appen.C (revision 51ffecc181005cb45a40108612ee28d1daaeeb86)
1*51ffecc1SBen Gras .\"	$NetBSD: appen.C,v 1.7 2003/08/07 16:44:26 agc Exp $
2*51ffecc1SBen Gras .\"
3*51ffecc1SBen Gras .\" Copyright (c) 1980, 1993
4*51ffecc1SBen Gras .\"	The Regents of the University of California.  All rights reserved.
5*51ffecc1SBen Gras .\"
6*51ffecc1SBen Gras .\" Redistribution and use in source and binary forms, with or without
7*51ffecc1SBen Gras .\" modification, are permitted provided that the following conditions
8*51ffecc1SBen Gras .\" are met:
9*51ffecc1SBen Gras .\" 1. Redistributions of source code must retain the above copyright
10*51ffecc1SBen Gras .\"    notice, this list of conditions and the following disclaimer.
11*51ffecc1SBen Gras .\" 2. Redistributions in binary form must reproduce the above copyright
12*51ffecc1SBen Gras .\"    notice, this list of conditions and the following disclaimer in the
13*51ffecc1SBen Gras .\"    documentation and/or other materials provided with the distribution.
14*51ffecc1SBen Gras .\" 3. Neither the name of the University nor the names of its contributors
15*51ffecc1SBen Gras .\"    may be used to endorse or promote products derived from this software
16*51ffecc1SBen Gras .\"    without specific prior written permission.
17*51ffecc1SBen Gras .\"
18*51ffecc1SBen Gras .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19*51ffecc1SBen Gras .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20*51ffecc1SBen Gras .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21*51ffecc1SBen Gras .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22*51ffecc1SBen Gras .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23*51ffecc1SBen Gras .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24*51ffecc1SBen Gras .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25*51ffecc1SBen Gras .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26*51ffecc1SBen Gras .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27*51ffecc1SBen Gras .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28*51ffecc1SBen Gras .\" SUCH DAMAGE.
29*51ffecc1SBen Gras .\"
30*51ffecc1SBen Gras .\"	@(#)appen.C	8.1 (Berkeley) 6/8/93
31*51ffecc1SBen Gras .\"
32*51ffecc1SBen Gras .ie t .oh '\*(Ln Appendix A''PS1:19-%'
33*51ffecc1SBen Gras .eh 'PS1:19-%''\*(Ln Appendix A'
34*51ffecc1SBen Gras .el .he ''\fIAppendix A\fR''
35*51ffecc1SBen Gras .bp
36*51ffecc1SBen Gras .(x
37*51ffecc1SBen Gras .ti 0
38*51ffecc1SBen Gras .b "Appendix A"
39*51ffecc1SBen Gras .)x
40*51ffecc1SBen Gras .sh 1 "Examples" 1
41*51ffecc1SBen Gras .pp
42*51ffecc1SBen Gras Here we present a few examples
43*51ffecc1SBen Gras of how to use the package.
44*51ffecc1SBen Gras They attempt to be representative,
45*51ffecc1SBen Gras though not comprehensive.
46*51ffecc1SBen Gras Further examples can be found in the games section
47*51ffecc1SBen Gras of the source tree and in various utilities that use the screen such as
48*51ffecc1SBen Gras .i systat(1) .
49*51ffecc1SBen Gras .sh 2 "Screen Updating"
50*51ffecc1SBen Gras .pp
51*51ffecc1SBen Gras The following examples are intended to demonstrate
52*51ffecc1SBen Gras the basic structure of a program
53*51ffecc1SBen Gras using the screen updating sections of the package.
54*51ffecc1SBen Gras Several of the programs require calculational sections
55*51ffecc1SBen Gras which are irrelevant of to the example,
56*51ffecc1SBen Gras and are therefore usually not included.
57*51ffecc1SBen Gras It is hoped that the data structure definitions
58*51ffecc1SBen Gras give enough of an idea to allow understanding
59*51ffecc1SBen Gras of what the relevant portions do.
60*51ffecc1SBen Gras .sh 3 "Simple Character Output"
61*51ffecc1SBen Gras .pp
62*51ffecc1SBen Gras This program demonstrates how to set up a window and output characters to it.
63*51ffecc1SBen Gras Also, it demonstrates how one might control the output to the window.
64*51ffecc1SBen Gras If you run this program, you will get a demonstration of the character output
65*51ffecc1SBen Gras chracteristics discussed in the above Character Output section.
66*51ffecc1SBen Gras .(l I
67*51ffecc1SBen Gras .so t2.gr
68*51ffecc1SBen Gras .)l
69*51ffecc1SBen Gras .sh 3 "A Small Screen Manipulator"
70*51ffecc1SBen Gras .pp
71*51ffecc1SBen Gras The next example follows the lines of the previous one but extends then to
72*51ffecc1SBen Gras demonstrate the various othe uses of the package.
73*51ffecc1SBen Gras Make sure you understand how this program works as it encompasses most of
74*51ffecc1SBen Gras anything you will need to do with the package.
75*51ffecc1SBen Gras .(l I
76*51ffecc1SBen Gras .so t3.gr
77*51ffecc1SBen Gras .)l
78*51ffecc1SBen Gras .sh 3 "Twinkle"
79*51ffecc1SBen Gras .pp
80*51ffecc1SBen Gras This is a moderately simple program which prints
81*51ffecc1SBen Gras patterns on the screen.
82*51ffecc1SBen Gras It switches between patterns of asterisks,
83*51ffecc1SBen Gras putting them on one by one in random order,
84*51ffecc1SBen Gras and then taking them off in the same fashion.
85*51ffecc1SBen Gras It is more efficient to write this
86*51ffecc1SBen Gras using only the motion optimization,
87*51ffecc1SBen Gras as is demonstrated below.
88*51ffecc1SBen Gras .(l I
89*51ffecc1SBen Gras .so twinkle1.gr
90*51ffecc1SBen Gras .)l
91*51ffecc1SBen Gras .sh 3 "Life"
92*51ffecc1SBen Gras .pp
93*51ffecc1SBen Gras This program fragment models the famous computer pattern game of life
94*51ffecc1SBen Gras (Scientific American, May, 1974).
95*51ffecc1SBen Gras The calculational routines create a linked list of structures
96*51ffecc1SBen Gras defining where each piece is.
97*51ffecc1SBen Gras Nothing here claims to be optimal,
98*51ffecc1SBen Gras merely demonstrative.
99*51ffecc1SBen Gras This code, however,
100*51ffecc1SBen Gras is a very good place to use the screen updating routines,
101*51ffecc1SBen Gras as it allows them to worry about what the last position looked like,
102*51ffecc1SBen Gras so you don't have to.
103*51ffecc1SBen Gras It also demonstrates some of the input routines.
104*51ffecc1SBen Gras .(l I
105*51ffecc1SBen Gras .so life.gr
106*51ffecc1SBen Gras .)l
107*51ffecc1SBen Gras .sh 2 "Motion optimization"
108*51ffecc1SBen Gras .pp
109*51ffecc1SBen Gras The following example shows how motion optimization
110*51ffecc1SBen Gras is written on its own.
111*51ffecc1SBen Gras Programs which flit from one place to another without
112*51ffecc1SBen Gras regard for what is already there
113*51ffecc1SBen Gras usually do not need the overhead of both space and time
114*51ffecc1SBen Gras associated with screen updating.
115*51ffecc1SBen Gras They should instead use motion optimization.
116*51ffecc1SBen Gras .sh 3 "Twinkle"
117*51ffecc1SBen Gras .pp
118*51ffecc1SBen Gras The
119*51ffecc1SBen Gras .b twinkle
120*51ffecc1SBen Gras program
121*51ffecc1SBen Gras is a good candidate for simple motion optimization.
122*51ffecc1SBen Gras Here is how it could be written
123*51ffecc1SBen Gras (only the routines that have been changed are shown):
124*51ffecc1SBen Gras .(l
125*51ffecc1SBen Gras .so twinkle2.gr
126*51ffecc1SBen Gras .)l
127