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