xref: /netbsd/lib/libcurses/PSD.doc/appen.C (revision c4a72b64)
1 .\"	$NetBSD: appen.C,v 1.6 2002/10/01 19:06:39 wiz 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.
50 Further examples can be found in the games section
51 of the source tree and in various utilities that use the screen such as
52 .i systat(1) .
53 .sh 2 "Screen Updating"
54 .pp
55 The following examples are intended to demonstrate
56 the basic structure of a program
57 using the screen updating sections of the package.
58 Several of the programs require calculational sections
59 which are irrelevant of to the example,
60 and are therefore usually not included.
61 It is hoped that the data structure definitions
62 give enough of an idea to allow understanding
63 of what the relevant portions do.
64 .sh 3 "Simple Character Output"
65 .pp
66 This program demonstrates how to set up a window and output characters to it.
67 Also, it demonstrates how one might control the output to the window.
68 If you run this program, you will get a demonstration of the character output
69 chracteristics discussed in the above Character Output section.
70 .(l I
71 .so t2.gr
72 .)l
73 .sh 3 "A Small Screen Manipulator"
74 .pp
75 The next example follows the lines of the previous one but extends then to
76 demonstrate the various othe uses of the package.
77 Make sure you understand how this program works as it encompasses most of
78 anything you will need to do with the package.
79 .(l I
80 .so t3.gr
81 .)l
82 .sh 3 "Twinkle"
83 .pp
84 This is a moderately simple program which prints
85 patterns on the screen.
86 It switches between patterns of asterisks,
87 putting them on one by one in random order,
88 and then taking them off in the same fashion.
89 It is more efficient to write this
90 using only the motion optimization,
91 as is demonstrated below.
92 .(l I
93 .so twinkle1.gr
94 .)l
95 .sh 3 "Life"
96 .pp
97 This program fragment models the famous computer pattern game of life
98 (Scientific American, May, 1974).
99 The calculational routines create a linked list of structures
100 defining where each piece is.
101 Nothing here claims to be optimal,
102 merely demonstrative.
103 This code, however,
104 is a very good place to use the screen updating routines,
105 as it allows them to worry about what the last position looked like,
106 so you don't have to.
107 It also demonstrates some of the input routines.
108 .(l I
109 .so life.gr
110 .)l
111 .sh 2 "Motion optimization"
112 .pp
113 The following example shows how motion optimization
114 is written on its own.
115 Programs which flit from one place to another without
116 regard for what is already there
117 usually do not need the overhead of both space and time
118 associated with screen updating.
119 They should instead use motion optimization.
120 .sh 3 "Twinkle"
121 .pp
122 The
123 .b twinkle
124 program
125 is a good candidate for simple motion optimization.
126 Here is how it could be written
127 (only the routines that have been changed are shown):
128 .(l
129 .so twinkle2.gr
130 .)l
131