1*80cd5ab5SBaptiste Daroussin<!--
2*80cd5ab5SBaptiste Daroussin  $Id: hackguide.html,v 1.36 2022/11/26 19:31:56 tom Exp $
3*80cd5ab5SBaptiste Daroussin  ****************************************************************************
4*80cd5ab5SBaptiste Daroussin  * Copyright 2019-2020,2022 Thomas E. Dickey                                *
5*80cd5ab5SBaptiste Daroussin  * Copyright 2000-2013,2017 Free Software Foundation, Inc.                  *
6*80cd5ab5SBaptiste Daroussin  *                                                                          *
7*80cd5ab5SBaptiste Daroussin  * Permission is hereby granted, free of charge, to any person obtaining a  *
8*80cd5ab5SBaptiste Daroussin  * copy of this software and associated documentation files (the            *
9*80cd5ab5SBaptiste Daroussin  * "Software"), to deal in the Software without restriction, including      *
10*80cd5ab5SBaptiste Daroussin  * without limitation the rights to use, copy, modify, merge, publish,      *
11*80cd5ab5SBaptiste Daroussin  * distribute, distribute with modifications, sublicense, and/or sell       *
12*80cd5ab5SBaptiste Daroussin  * copies of the Software, and to permit persons to whom the Software is    *
13*80cd5ab5SBaptiste Daroussin  * furnished to do so, subject to the following conditions:                 *
14*80cd5ab5SBaptiste Daroussin  *                                                                          *
15*80cd5ab5SBaptiste Daroussin  * The above copyright notice and this permission notice shall be included  *
16*80cd5ab5SBaptiste Daroussin  * in all copies or substantial portions of the Software.                   *
17*80cd5ab5SBaptiste Daroussin  *                                                                          *
18*80cd5ab5SBaptiste Daroussin  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
19*80cd5ab5SBaptiste Daroussin  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
20*80cd5ab5SBaptiste Daroussin  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
21*80cd5ab5SBaptiste Daroussin  * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
22*80cd5ab5SBaptiste Daroussin  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
23*80cd5ab5SBaptiste Daroussin  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
24*80cd5ab5SBaptiste Daroussin  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
25*80cd5ab5SBaptiste Daroussin  *                                                                          *
26*80cd5ab5SBaptiste Daroussin  * Except as contained in this notice, the name(s) of the above copyright   *
27*80cd5ab5SBaptiste Daroussin  * holders shall not be used in advertising or otherwise to promote the     *
28*80cd5ab5SBaptiste Daroussin  * sale, use or other dealings in this Software without prior written       *
29*80cd5ab5SBaptiste Daroussin  * authorization.                                                           *
30*80cd5ab5SBaptiste Daroussin  ****************************************************************************
31*80cd5ab5SBaptiste Daroussin-->
32*80cd5ab5SBaptiste Daroussin<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
33*80cd5ab5SBaptiste Daroussin<html>
34*80cd5ab5SBaptiste Daroussin<head>
35*80cd5ab5SBaptiste Daroussin  <meta name="generator" content=
36*80cd5ab5SBaptiste Daroussin  "HTML Tidy for HTML5 for Linux version 5.6.0">
37*80cd5ab5SBaptiste Daroussin  <title>A Hacker's Guide to Ncurses Internals</title>
38*80cd5ab5SBaptiste Daroussin  <link rel="author" href="mailto:[email protected]">
39*80cd5ab5SBaptiste Daroussin  <meta http-equiv="Content-Type" content=
40*80cd5ab5SBaptiste Daroussin  "text/html; charset=us-ascii"><!--
41*80cd5ab5SBaptiste DaroussinThis document is self-contained, *except* that there is one relative link to
42*80cd5ab5SBaptiste Daroussinthe ncurses-intro.html document, expected to be in the same directory with
43*80cd5ab5SBaptiste Daroussinthis one.
44*80cd5ab5SBaptiste Daroussin-->
45*80cd5ab5SBaptiste Daroussin</head>
46*80cd5ab5SBaptiste Daroussin<body>
47*80cd5ab5SBaptiste Daroussin  <h1 class="no-header">A Hacker's Guide to NCURSES</h1>
48*80cd5ab5SBaptiste Daroussin
49*80cd5ab5SBaptiste Daroussin  <h2>A Hacker's Guide to NCURSES</h2>
50*80cd5ab5SBaptiste Daroussin
51*80cd5ab5SBaptiste Daroussin  <div class="nav">
52*80cd5ab5SBaptiste Daroussin    <h2>Contents</h2>
53*80cd5ab5SBaptiste Daroussin
54*80cd5ab5SBaptiste Daroussin    <ul>
55*80cd5ab5SBaptiste Daroussin      <li><a href="#abstract">Abstract</a></li>
56*80cd5ab5SBaptiste Daroussin
57*80cd5ab5SBaptiste Daroussin      <li>
58*80cd5ab5SBaptiste Daroussin        <a href="#objective">Objective of the Package</a>
59*80cd5ab5SBaptiste Daroussin        <ul>
60*80cd5ab5SBaptiste Daroussin          <li><a href="#whysvr4">Why System V Curses?</a></li>
61*80cd5ab5SBaptiste Daroussin
62*80cd5ab5SBaptiste Daroussin          <li><a href="#extensions">How to Design Extensions</a></li>
63*80cd5ab5SBaptiste Daroussin        </ul>
64*80cd5ab5SBaptiste Daroussin      </li>
65*80cd5ab5SBaptiste Daroussin
66*80cd5ab5SBaptiste Daroussin      <li><a href="#portability">Portability and Configuration</a></li>
67*80cd5ab5SBaptiste Daroussin
68*80cd5ab5SBaptiste Daroussin      <li><a href="#documentation">Documentation Conventions</a></li>
69*80cd5ab5SBaptiste Daroussin
70*80cd5ab5SBaptiste Daroussin      <li><a href="#bugtrack">How to Report Bugs</a></li>
71*80cd5ab5SBaptiste Daroussin
72*80cd5ab5SBaptiste Daroussin      <li>
73*80cd5ab5SBaptiste Daroussin        <a href="#ncurslib">A Tour of the Ncurses Library</a>
74*80cd5ab5SBaptiste Daroussin        <ul>
75*80cd5ab5SBaptiste Daroussin          <li><a href="#loverview">Library Overview</a></li>
76*80cd5ab5SBaptiste Daroussin
77*80cd5ab5SBaptiste Daroussin          <li><a href="#engine">The Engine Room</a></li>
78*80cd5ab5SBaptiste Daroussin
79*80cd5ab5SBaptiste Daroussin          <li><a href="#input">Keyboard Input</a></li>
80*80cd5ab5SBaptiste Daroussin
81*80cd5ab5SBaptiste Daroussin          <li><a href="#mouse">Mouse Events</a></li>
82*80cd5ab5SBaptiste Daroussin
83*80cd5ab5SBaptiste Daroussin          <li><a href="#output">Output and Screen Updating</a></li>
84*80cd5ab5SBaptiste Daroussin        </ul>
85*80cd5ab5SBaptiste Daroussin      </li>
86*80cd5ab5SBaptiste Daroussin
87*80cd5ab5SBaptiste Daroussin      <li><a href="#fmnote">The Forms and Menu Libraries</a></li>
88*80cd5ab5SBaptiste Daroussin
89*80cd5ab5SBaptiste Daroussin      <li>
90*80cd5ab5SBaptiste Daroussin        <a href="#tic">A Tour of the Terminfo Compiler</a>
91*80cd5ab5SBaptiste Daroussin        <ul>
92*80cd5ab5SBaptiste Daroussin          <li><a href="#nonuse">Translation of
93*80cd5ab5SBaptiste Daroussin          Non-<strong>use</strong> Capabilities</a></li>
94*80cd5ab5SBaptiste Daroussin
95*80cd5ab5SBaptiste Daroussin          <li><a href="#uses">Use Capability Resolution</a></li>
96*80cd5ab5SBaptiste Daroussin
97*80cd5ab5SBaptiste Daroussin          <li><a href="#translation">Source-Form Translation</a></li>
98*80cd5ab5SBaptiste Daroussin        </ul>
99*80cd5ab5SBaptiste Daroussin      </li>
100*80cd5ab5SBaptiste Daroussin
101*80cd5ab5SBaptiste Daroussin      <li><a href="#utils">Other Utilities</a></li>
102*80cd5ab5SBaptiste Daroussin
103*80cd5ab5SBaptiste Daroussin      <li><a href="#style">Style Tips for Developers</a></li>
104*80cd5ab5SBaptiste Daroussin
105*80cd5ab5SBaptiste Daroussin      <li><a href="#port">Porting Hints</a></li>
106*80cd5ab5SBaptiste Daroussin    </ul>
107*80cd5ab5SBaptiste Daroussin  </div>
108*80cd5ab5SBaptiste Daroussin
109*80cd5ab5SBaptiste Daroussin  <h2><a name="abstract" id="abstract">Abstract</a></h2>
110*80cd5ab5SBaptiste Daroussin
111*80cd5ab5SBaptiste Daroussin  <p>This document is a hacker's tour of the
112*80cd5ab5SBaptiste Daroussin  <strong>ncurses</strong> library and utilities. It discusses
113*80cd5ab5SBaptiste Daroussin  design philosophy, implementation methods, and the conventions
114*80cd5ab5SBaptiste Daroussin  used for coding and documentation. It is recommended reading for
115*80cd5ab5SBaptiste Daroussin  anyone who is interested in porting, extending or improving the
116*80cd5ab5SBaptiste Daroussin  package.</p>
117*80cd5ab5SBaptiste Daroussin
118*80cd5ab5SBaptiste Daroussin  <h2><a name="objective" id="objective">Objective of the
119*80cd5ab5SBaptiste Daroussin  Package</a></h2>
120*80cd5ab5SBaptiste Daroussin
121*80cd5ab5SBaptiste Daroussin  <p>The objective of the <strong>ncurses</strong> package is to
122*80cd5ab5SBaptiste Daroussin  provide a free software API for character-cell terminals and
123*80cd5ab5SBaptiste Daroussin  terminal emulators with the following characteristics:</p>
124*80cd5ab5SBaptiste Daroussin
125*80cd5ab5SBaptiste Daroussin  <ul>
126*80cd5ab5SBaptiste Daroussin    <li>Source-compatible with historical curses implementations
127*80cd5ab5SBaptiste Daroussin    (including the original BSD curses and System V curses.</li>
128*80cd5ab5SBaptiste Daroussin
129*80cd5ab5SBaptiste Daroussin    <li>Conformant with the XSI Curses standard issued as part of
130*80cd5ab5SBaptiste Daroussin    XPG4 by X/Open.</li>
131*80cd5ab5SBaptiste Daroussin
132*80cd5ab5SBaptiste Daroussin    <li>High-quality &mdash; stable and reliable code, wide
133*80cd5ab5SBaptiste Daroussin    portability, good packaging, superior documentation.</li>
134*80cd5ab5SBaptiste Daroussin
135*80cd5ab5SBaptiste Daroussin    <li>Featureful &mdash; should eliminate as much of the drudgery
136*80cd5ab5SBaptiste Daroussin    of C interface programming as possible, freeing programmers to
137*80cd5ab5SBaptiste Daroussin    think at a higher level of design.</li>
138*80cd5ab5SBaptiste Daroussin  </ul>
139*80cd5ab5SBaptiste Daroussin
140*80cd5ab5SBaptiste Daroussin  <p>These objectives are in priority order. So, for example,
141*80cd5ab5SBaptiste Daroussin  source compatibility with older version must trump featurefulness
142*80cd5ab5SBaptiste Daroussin  &mdash; we cannot add features if it means breaking the portion
143*80cd5ab5SBaptiste Daroussin  of the API corresponding to historical curses versions.</p>
144*80cd5ab5SBaptiste Daroussin
145*80cd5ab5SBaptiste Daroussin  <h3><a name="whysvr4" id="whysvr4">Why System V Curses?</a></h3>
146*80cd5ab5SBaptiste Daroussin
147*80cd5ab5SBaptiste Daroussin  <p>We used System V curses as a model, reverse-engineering their
148*80cd5ab5SBaptiste Daroussin  API, in order to fulfill the first two objectives.</p>
149*80cd5ab5SBaptiste Daroussin
150*80cd5ab5SBaptiste Daroussin  <p>System V curses implementations can support BSD curses
151*80cd5ab5SBaptiste Daroussin  programs with just a recompilation, so by capturing the System V
152*80cd5ab5SBaptiste Daroussin  API we also capture BSD's.</p>
153*80cd5ab5SBaptiste Daroussin
154*80cd5ab5SBaptiste Daroussin  <p>More importantly for the future, the XSI Curses standard
155*80cd5ab5SBaptiste Daroussin  issued by X/Open is explicitly and closely modeled on System V.
156*80cd5ab5SBaptiste Daroussin  So conformance with System V took us most of the way to
157*80cd5ab5SBaptiste Daroussin  base-level XSI conformance.</p>
158*80cd5ab5SBaptiste Daroussin
159*80cd5ab5SBaptiste Daroussin  <h3><a name="extensions" id="extensions">How to Design
160*80cd5ab5SBaptiste Daroussin  Extensions</a></h3>
161*80cd5ab5SBaptiste Daroussin
162*80cd5ab5SBaptiste Daroussin  <p>The third objective (standards conformance) requires that it
163*80cd5ab5SBaptiste Daroussin  be easy to condition source code using <strong>ncurses</strong>
164*80cd5ab5SBaptiste Daroussin  so that the absence of nonstandard extensions does not break the
165*80cd5ab5SBaptiste Daroussin  code.</p>
166*80cd5ab5SBaptiste Daroussin
167*80cd5ab5SBaptiste Daroussin  <p>Accordingly, we have a policy of associating with each
168*80cd5ab5SBaptiste Daroussin  nonstandard extension a feature macro, so that ncurses client
169*80cd5ab5SBaptiste Daroussin  code can use this macro to condition in or out the code that
170*80cd5ab5SBaptiste Daroussin  requires the <strong>ncurses</strong> extension.</p>
171*80cd5ab5SBaptiste Daroussin
172*80cd5ab5SBaptiste Daroussin  <p>For example, there is a macro
173*80cd5ab5SBaptiste Daroussin  <code>NCURSES_MOUSE_VERSION</code> which XSI Curses does not
174*80cd5ab5SBaptiste Daroussin  define, but which is defined in the <strong>ncurses</strong>
175*80cd5ab5SBaptiste Daroussin  library header. You can use this to condition the calls to the
176*80cd5ab5SBaptiste Daroussin  mouse API calls.</p>
177*80cd5ab5SBaptiste Daroussin
178*80cd5ab5SBaptiste Daroussin  <h2><a name="portability" id="portability">Portability and
179*80cd5ab5SBaptiste Daroussin  Configuration</a></h2>
180*80cd5ab5SBaptiste Daroussin
181*80cd5ab5SBaptiste Daroussin  <p>Code written for <strong>ncurses</strong> may assume an
182*80cd5ab5SBaptiste Daroussin  ANSI-standard C compiler and POSIX-compatible OS interface. It
183*80cd5ab5SBaptiste Daroussin  may also assume the presence of a System-V-compatible
184*80cd5ab5SBaptiste Daroussin  <em>select(2)</em> call.</p>
185*80cd5ab5SBaptiste Daroussin
186*80cd5ab5SBaptiste Daroussin  <p>We encourage (but do not require) developers to make the code
187*80cd5ab5SBaptiste Daroussin  friendly to less-capable UNIX environments wherever possible.</p>
188*80cd5ab5SBaptiste Daroussin
189*80cd5ab5SBaptiste Daroussin  <p>We encourage developers to support OS-specific optimizations
190*80cd5ab5SBaptiste Daroussin  and methods not available under POSIX/ANSI, provided only
191*80cd5ab5SBaptiste Daroussin  that:</p>
192*80cd5ab5SBaptiste Daroussin
193*80cd5ab5SBaptiste Daroussin  <ul>
194*80cd5ab5SBaptiste Daroussin    <li>All such code is properly conditioned so the build process
195*80cd5ab5SBaptiste Daroussin    does not attempt to compile it under a plain ANSI/POSIX
196*80cd5ab5SBaptiste Daroussin    environment.</li>
197*80cd5ab5SBaptiste Daroussin
198*80cd5ab5SBaptiste Daroussin    <li>Adding such implementation methods does not introduce
199*80cd5ab5SBaptiste Daroussin    incompatibilities in the <strong>ncurses</strong> API between
200*80cd5ab5SBaptiste Daroussin    platforms.</li>
201*80cd5ab5SBaptiste Daroussin  </ul>
202*80cd5ab5SBaptiste Daroussin
203*80cd5ab5SBaptiste Daroussin  <p>We use GNU <code>autoconf(1)</code> as a tool to deal with
204*80cd5ab5SBaptiste Daroussin  portability issues. The right way to leverage an OS-specific
205*80cd5ab5SBaptiste Daroussin  feature is to modify the autoconf specification files
206*80cd5ab5SBaptiste Daroussin  (configure.in and aclocal.m4) to set up a new feature macro,
207*80cd5ab5SBaptiste Daroussin  which you then use to condition your code.</p>
208*80cd5ab5SBaptiste Daroussin
209*80cd5ab5SBaptiste Daroussin  <h2><a name="documentation" id="documentation">Documentation
210*80cd5ab5SBaptiste Daroussin  Conventions</a></h2>
211*80cd5ab5SBaptiste Daroussin
212*80cd5ab5SBaptiste Daroussin  <p>There are three kinds of documentation associated with this
213*80cd5ab5SBaptiste Daroussin  package. Each has a different preferred format:</p>
214*80cd5ab5SBaptiste Daroussin
215*80cd5ab5SBaptiste Daroussin  <ul>
216*80cd5ab5SBaptiste Daroussin    <li>Package-internal files (README, INSTALL, TO-DO etc.)</li>
217*80cd5ab5SBaptiste Daroussin
218*80cd5ab5SBaptiste Daroussin    <li>Manual pages.</li>
219*80cd5ab5SBaptiste Daroussin
220*80cd5ab5SBaptiste Daroussin    <li>Everything else (i.e., narrative documentation).</li>
221*80cd5ab5SBaptiste Daroussin  </ul>
222*80cd5ab5SBaptiste Daroussin
223*80cd5ab5SBaptiste Daroussin  <p>Our conventions are simple:</p>
224*80cd5ab5SBaptiste Daroussin
225*80cd5ab5SBaptiste Daroussin  <ol>
226*80cd5ab5SBaptiste Daroussin    <li><strong>Maintain package-internal files in plain
227*80cd5ab5SBaptiste Daroussin    text.</strong> The expected viewer for them is <em>more(1)</em> or
228*80cd5ab5SBaptiste Daroussin    an editor window; there is no point in elaborate mark-up.</li>
229*80cd5ab5SBaptiste Daroussin
230*80cd5ab5SBaptiste Daroussin    <li><strong>Mark up manual pages in the man macros.</strong>
231*80cd5ab5SBaptiste Daroussin    These have to be viewable through traditional <em>man(1)</em>
232*80cd5ab5SBaptiste Daroussin    programs.</li>
233*80cd5ab5SBaptiste Daroussin
234*80cd5ab5SBaptiste Daroussin    <li><strong>Write everything else in HTML.</strong>
235*80cd5ab5SBaptiste Daroussin    </li>
236*80cd5ab5SBaptiste Daroussin  </ol>
237*80cd5ab5SBaptiste Daroussin
238*80cd5ab5SBaptiste Daroussin  <p>When in doubt, HTMLize a master and use <em>lynx(1)</em> to
239*80cd5ab5SBaptiste Daroussin  generate plain ASCII (as we do for the announcement
240*80cd5ab5SBaptiste Daroussin  document).</p>
241*80cd5ab5SBaptiste Daroussin
242*80cd5ab5SBaptiste Daroussin  <p>The reason for choosing HTML is that it is (a) well-adapted
243*80cd5ab5SBaptiste Daroussin  for on-line browsing through viewers that are everywhere; (b)
244*80cd5ab5SBaptiste Daroussin  more easily readable as plain text than most other mark-ups, if
245*80cd5ab5SBaptiste Daroussin  you do not have a viewer; and (c) carries enough information that
246*80cd5ab5SBaptiste Daroussin  you can generate a nice-looking printed version from it. Also, of
247*80cd5ab5SBaptiste Daroussin  course, it make exporting things like the announcement document
248*80cd5ab5SBaptiste Daroussin  to WWW pretty trivial.</p>
249*80cd5ab5SBaptiste Daroussin
250*80cd5ab5SBaptiste Daroussin  <h2><a name="bugtrack" id="bugtrack">How to Report Bugs</a></h2>
251*80cd5ab5SBaptiste Daroussin
252*80cd5ab5SBaptiste Daroussin  <p>The <a name="bugreport" id="bugreport">reporting address for
253*80cd5ab5SBaptiste Daroussin  bugs</a> is <a href=
254*80cd5ab5SBaptiste Daroussin  "mailto:[email protected]">[email protected]</a>. This is a
255*80cd5ab5SBaptiste Daroussin  majordomo list; to join, write to
256*80cd5ab5SBaptiste Daroussin  <code>[email protected]</code> with a message
257*80cd5ab5SBaptiste Daroussin  containing the line:</p>
258*80cd5ab5SBaptiste Daroussin
259*80cd5ab5SBaptiste Daroussin  <pre class="code-block">
260*80cd5ab5SBaptiste Daroussin             subscribe &lt;name&gt;@&lt;host.domain&gt;
261*80cd5ab5SBaptiste Daroussin</pre>
262*80cd5ab5SBaptiste Daroussin  <p>The <code>ncurses</code> code is maintained by a small group
263*80cd5ab5SBaptiste Daroussin  of volunteers. While we try our best to fix bugs promptly, we
264*80cd5ab5SBaptiste Daroussin  simply do not have a lot of hours to spend on elementary
265*80cd5ab5SBaptiste Daroussin  hand-holding. We rely on intelligent cooperation from our users.
266*80cd5ab5SBaptiste Daroussin  If you think you have found a bug in <code>ncurses</code>, there
267*80cd5ab5SBaptiste Daroussin  are some steps you can take before contacting us that will help
268*80cd5ab5SBaptiste Daroussin  get the bug fixed quickly.</p>
269*80cd5ab5SBaptiste Daroussin
270*80cd5ab5SBaptiste Daroussin  <p>In order to use our bug-fixing time efficiently, we put people
271*80cd5ab5SBaptiste Daroussin  who show us they have taken these steps at the head of our queue.
272*80cd5ab5SBaptiste Daroussin  This means that if you do not, you will probably end up at the
273*80cd5ab5SBaptiste Daroussin  tail end and have to wait a while.</p>
274*80cd5ab5SBaptiste Daroussin
275*80cd5ab5SBaptiste Daroussin  <ol>
276*80cd5ab5SBaptiste Daroussin    <li><p>Develop a recipe to reproduce the bug.
277*80cd5ab5SBaptiste Daroussin      <p>Bugs we can reproduce are likely to be fixed very quickly,
278*80cd5ab5SBaptiste Daroussin      often within days. The most effective single thing you can do
279*80cd5ab5SBaptiste Daroussin      to get a quick fix is develop a way we can duplicate the bad
280*80cd5ab5SBaptiste Daroussin      behavior &mdash; ideally, by giving us source for a small,
281*80cd5ab5SBaptiste Daroussin      portable test program that breaks the library. (Even better
282*80cd5ab5SBaptiste Daroussin      is a keystroke recipe using one of the test programs provided
283*80cd5ab5SBaptiste Daroussin      with the distribution.)</p>
284*80cd5ab5SBaptiste Daroussin    </li>
285*80cd5ab5SBaptiste Daroussin
286*80cd5ab5SBaptiste Daroussin    <li><p>Try to reproduce the bug on a different terminal type.
287*80cd5ab5SBaptiste Daroussin      <p>In our experience, most of the behaviors people report as
288*80cd5ab5SBaptiste Daroussin      library bugs are actually due to subtle problems in terminal
289*80cd5ab5SBaptiste Daroussin      descriptions. This is especially likely to be true if you are
290*80cd5ab5SBaptiste Daroussin      using a traditional asynchronous terminal or PC-based
291*80cd5ab5SBaptiste Daroussin      terminal emulator, rather than xterm or a UNIX console
292*80cd5ab5SBaptiste Daroussin      entry.</p>
293*80cd5ab5SBaptiste Daroussin
294*80cd5ab5SBaptiste Daroussin      <p>It is therefore extremely helpful if you can tell us
295*80cd5ab5SBaptiste Daroussin      whether or not your problem reproduces on other terminal
296*80cd5ab5SBaptiste Daroussin      types. Usually you will have both a console type and xterm
297*80cd5ab5SBaptiste Daroussin      available; please tell us whether or not your bug reproduces
298*80cd5ab5SBaptiste Daroussin      on both.</p>
299*80cd5ab5SBaptiste Daroussin
300*80cd5ab5SBaptiste Daroussin      <p>If you have xterm available, it is also good to collect
301*80cd5ab5SBaptiste Daroussin      xterm reports for different window sizes. This is especially
302*80cd5ab5SBaptiste Daroussin      true if you normally use an unusual xterm window size &mdash;
303*80cd5ab5SBaptiste Daroussin      a surprising number of the bugs we have seen are either
304*80cd5ab5SBaptiste Daroussin      triggered or masked by these.</p>
305*80cd5ab5SBaptiste Daroussin    </li>
306*80cd5ab5SBaptiste Daroussin
307*80cd5ab5SBaptiste Daroussin    <li><p>Generate and examine a trace file for the broken behavior.
308*80cd5ab5SBaptiste Daroussin      <p>Recompile your program with the debugging versions of the
309*80cd5ab5SBaptiste Daroussin      libraries. Insert a <code>trace()</code> call with the
310*80cd5ab5SBaptiste Daroussin      argument set to <code>TRACE_UPDATE</code>. (See <a href=
311*80cd5ab5SBaptiste Daroussin      "ncurses-intro.html#debugging">"Writing Programs with
312*80cd5ab5SBaptiste Daroussin      NCURSES"</a> for details on trace levels.) Reproduce your
313*80cd5ab5SBaptiste Daroussin      bug, then look at the trace file to see what the library was
314*80cd5ab5SBaptiste Daroussin      actually doing.</p>
315*80cd5ab5SBaptiste Daroussin
316*80cd5ab5SBaptiste Daroussin      <p>Another frequent cause of apparent bugs is application
317*80cd5ab5SBaptiste Daroussin      coding errors that cause the wrong things to be put on the
318*80cd5ab5SBaptiste Daroussin      virtual screen. Looking at the virtual-screen dumps in the
319*80cd5ab5SBaptiste Daroussin      trace file will tell you immediately if this is happening,
320*80cd5ab5SBaptiste Daroussin      and save you from the possible embarrassment of being told
321*80cd5ab5SBaptiste Daroussin      that the bug is in your code and is your problem rather than
322*80cd5ab5SBaptiste Daroussin      ours.</p>
323*80cd5ab5SBaptiste Daroussin
324*80cd5ab5SBaptiste Daroussin      <p>If the virtual-screen dumps look correct but the bug
325*80cd5ab5SBaptiste Daroussin      persists, it is possible to crank up the trace level to give
326*80cd5ab5SBaptiste Daroussin      more and more information about the library's update actions
327*80cd5ab5SBaptiste Daroussin      and the control sequences it issues to perform them. The test
328*80cd5ab5SBaptiste Daroussin      directory of the distribution contains a tool for digesting
329*80cd5ab5SBaptiste Daroussin      these logs to make them less tedious to wade through.</p>
330*80cd5ab5SBaptiste Daroussin
331*80cd5ab5SBaptiste Daroussin      <p>Often you will find terminfo problems at this stage by
332*80cd5ab5SBaptiste Daroussin      noticing that the escape sequences put out for various
333*80cd5ab5SBaptiste Daroussin      capabilities are wrong. If not, you are likely to learn
334*80cd5ab5SBaptiste Daroussin      enough to be able to characterize any bug in the
335*80cd5ab5SBaptiste Daroussin      screen-update logic quite exactly.</p>
336*80cd5ab5SBaptiste Daroussin    </li>
337*80cd5ab5SBaptiste Daroussin
338*80cd5ab5SBaptiste Daroussin    <li><p>Report details and symptoms, not just interpretations.
339*80cd5ab5SBaptiste Daroussin      <p>If you do the preceding two steps, it is very likely that
340*80cd5ab5SBaptiste Daroussin      you will discover the nature of the problem yourself and be
341*80cd5ab5SBaptiste Daroussin      able to send us a fix. This will create happy feelings all
342*80cd5ab5SBaptiste Daroussin      around and earn you good karma for the first time you run
343*80cd5ab5SBaptiste Daroussin      into a bug you really cannot characterize and fix
344*80cd5ab5SBaptiste Daroussin      yourself.</p>
345*80cd5ab5SBaptiste Daroussin
346*80cd5ab5SBaptiste Daroussin      <p>If you are still stuck, at least you will know what to
347*80cd5ab5SBaptiste Daroussin      tell us. Remember, we need details. If you guess about what
348*80cd5ab5SBaptiste Daroussin      is safe to leave out, you are too likely to be wrong.</p>
349*80cd5ab5SBaptiste Daroussin
350*80cd5ab5SBaptiste Daroussin      <p>If your bug produces a bad update, include a trace file.
351*80cd5ab5SBaptiste Daroussin      Try to make the trace at the <em>least</em> voluminous level
352*80cd5ab5SBaptiste Daroussin      that pins down the bug. Logs that have been through
353*80cd5ab5SBaptiste Daroussin      tracemunch are OK, it does not throw away any information
354*80cd5ab5SBaptiste Daroussin      (actually they are better than un-munched ones because they
355*80cd5ab5SBaptiste Daroussin      are easier to read).</p>
356*80cd5ab5SBaptiste Daroussin
357*80cd5ab5SBaptiste Daroussin      <p>If your bug produces a core-dump, please include a
358*80cd5ab5SBaptiste Daroussin      symbolic stack trace generated by gdb(1) or your local
359*80cd5ab5SBaptiste Daroussin      equivalent.</p>
360*80cd5ab5SBaptiste Daroussin
361*80cd5ab5SBaptiste Daroussin      <p>Tell us about every terminal on which you have reproduced
362*80cd5ab5SBaptiste Daroussin      the bug &mdash; and every terminal on which you cannot.
363*80cd5ab5SBaptiste Daroussin      Ideally, send us terminfo sources for all of these (yours
364*80cd5ab5SBaptiste Daroussin      might differ from ours).</p>
365*80cd5ab5SBaptiste Daroussin
366*80cd5ab5SBaptiste Daroussin      <p>Include your ncurses version and your OS/machine type, of
367*80cd5ab5SBaptiste Daroussin      course! You can find your ncurses version in the
368*80cd5ab5SBaptiste Daroussin      <code>curses.h</code> file.</p>
369*80cd5ab5SBaptiste Daroussin    </li>
370*80cd5ab5SBaptiste Daroussin  </ol>
371*80cd5ab5SBaptiste Daroussin
372*80cd5ab5SBaptiste Daroussin  <p>If your problem smells like a logic error or in cursor
373*80cd5ab5SBaptiste Daroussin  movement or scrolling or a bad capability, there are a couple of
374*80cd5ab5SBaptiste Daroussin  tiny test frames for the library algorithms in the progs
375*80cd5ab5SBaptiste Daroussin  directory that may help you isolate it. These are not part of the
376*80cd5ab5SBaptiste Daroussin  normal build, but do have their own make productions.</p>
377*80cd5ab5SBaptiste Daroussin
378*80cd5ab5SBaptiste Daroussin  <p>The most important of these is <code>mvcur</code>, a test
379*80cd5ab5SBaptiste Daroussin  frame for the cursor-movement optimization code. With this
380*80cd5ab5SBaptiste Daroussin  program, you can see directly what control sequences will be
381*80cd5ab5SBaptiste Daroussin  emitted for any given cursor movement or scroll/insert/delete
382*80cd5ab5SBaptiste Daroussin  operations. If you think you have got a bad capability
383*80cd5ab5SBaptiste Daroussin  identified, you can disable it and test again. The program is
384*80cd5ab5SBaptiste Daroussin  command-driven and has on-line help.</p>
385*80cd5ab5SBaptiste Daroussin
386*80cd5ab5SBaptiste Daroussin  <p>If you think the vertical-scroll optimization is broken, or
387*80cd5ab5SBaptiste Daroussin  just want to understand how it works better, build
388*80cd5ab5SBaptiste Daroussin  <code>hashmap</code> and read the header comments of
389*80cd5ab5SBaptiste Daroussin  <code>hardscroll.c</code> and <code>hashmap.c</code>; then try it
390*80cd5ab5SBaptiste Daroussin  out. You can also test the hardware-scrolling optimization
391*80cd5ab5SBaptiste Daroussin  separately with <code>hardscroll</code>.</p>
392*80cd5ab5SBaptiste Daroussin
393*80cd5ab5SBaptiste Daroussin  <h2><a name="ncurslib" id="ncurslib">A Tour of the Ncurses
394*80cd5ab5SBaptiste Daroussin  Library</a></h2>
395*80cd5ab5SBaptiste Daroussin
396*80cd5ab5SBaptiste Daroussin  <h3><a name="loverview" id="loverview">Library Overview</a></h3>
397*80cd5ab5SBaptiste Daroussin
398*80cd5ab5SBaptiste Daroussin  <p>Most of the library is superstructure &mdash; fairly trivial
399*80cd5ab5SBaptiste Daroussin  convenience interfaces to a small set of basic functions and data
400*80cd5ab5SBaptiste Daroussin  structures used to manipulate the virtual screen (in particular,
401*80cd5ab5SBaptiste Daroussin  none of this code does any I/O except through calls to more
402*80cd5ab5SBaptiste Daroussin  fundamental modules described below). The files</p>
403*80cd5ab5SBaptiste Daroussin
404*80cd5ab5SBaptiste Daroussin  <blockquote>
405*80cd5ab5SBaptiste Daroussin    <code>lib_addch.c lib_bkgd.c lib_box.c lib_chgat.c lib_clear.c
406*80cd5ab5SBaptiste Daroussin    lib_clearok.c lib_clrbot.c lib_clreol.c lib_colorset.c
407*80cd5ab5SBaptiste Daroussin    lib_data.c lib_delch.c lib_delwin.c lib_echo.c lib_erase.c
408*80cd5ab5SBaptiste Daroussin    lib_gen.c lib_getstr.c lib_hline.c lib_immedok.c lib_inchstr.c
409*80cd5ab5SBaptiste Daroussin    lib_insch.c lib_insdel.c lib_insstr.c lib_instr.c
410*80cd5ab5SBaptiste Daroussin    lib_isendwin.c lib_keyname.c lib_leaveok.c lib_move.c
411*80cd5ab5SBaptiste Daroussin    lib_mvwin.c lib_overlay.c lib_pad.c lib_printw.c lib_redrawln.c
412*80cd5ab5SBaptiste Daroussin    lib_scanw.c lib_screen.c lib_scroll.c lib_scrollok.c
413*80cd5ab5SBaptiste Daroussin    lib_scrreg.c lib_set_term.c lib_slk.c lib_slkatr_set.c
414*80cd5ab5SBaptiste Daroussin    lib_slkatrof.c lib_slkatron.c lib_slkatrset.c lib_slkattr.c
415*80cd5ab5SBaptiste Daroussin    lib_slkclear.c lib_slkcolor.c lib_slkinit.c lib_slklab.c
416*80cd5ab5SBaptiste Daroussin    lib_slkrefr.c lib_slkset.c lib_slktouch.c lib_touch.c
417*80cd5ab5SBaptiste Daroussin    lib_unctrl.c lib_vline.c lib_wattroff.c lib_wattron.c
418*80cd5ab5SBaptiste Daroussin    lib_window.c</code>
419*80cd5ab5SBaptiste Daroussin  </blockquote>
420*80cd5ab5SBaptiste Daroussin
421*80cd5ab5SBaptiste Daroussin  <p>are all in this category. They are very unlikely to need
422*80cd5ab5SBaptiste Daroussin  change, barring bugs or some fundamental reorganization in the
423*80cd5ab5SBaptiste Daroussin  underlying data structures.</p>
424*80cd5ab5SBaptiste Daroussin
425*80cd5ab5SBaptiste Daroussin  <p>These files are used only for debugging support:</p>
426*80cd5ab5SBaptiste Daroussin
427*80cd5ab5SBaptiste Daroussin  <blockquote>
428*80cd5ab5SBaptiste Daroussin    <code>lib_trace.c lib_traceatr.c lib_tracebits.c lib_tracechr.c
429*80cd5ab5SBaptiste Daroussin    lib_tracedmp.c lib_tracemse.c trace_buf.c</code>
430*80cd5ab5SBaptiste Daroussin  </blockquote>
431*80cd5ab5SBaptiste Daroussin
432*80cd5ab5SBaptiste Daroussin  <p>It is rather unlikely you will ever need to change these,
433*80cd5ab5SBaptiste Daroussin  unless you want to introduce a new debug trace level for some
434*80cd5ab5SBaptiste Daroussin  reason.</p>
435*80cd5ab5SBaptiste Daroussin
436*80cd5ab5SBaptiste Daroussin  <p>There is another group of files that do direct I/O via
437*80cd5ab5SBaptiste Daroussin  <em>tputs()</em>, computations on the terminal capabilities, or
438*80cd5ab5SBaptiste Daroussin  queries to the OS environment, but nevertheless have only fairly
439*80cd5ab5SBaptiste Daroussin  low complexity. These include:</p>
440*80cd5ab5SBaptiste Daroussin
441*80cd5ab5SBaptiste Daroussin  <blockquote>
442*80cd5ab5SBaptiste Daroussin    <code>lib_acs.c lib_beep.c lib_color.c lib_endwin.c
443*80cd5ab5SBaptiste Daroussin    lib_initscr.c lib_longname.c lib_newterm.c lib_options.c
444*80cd5ab5SBaptiste Daroussin    lib_termcap.c lib_ti.c lib_tparm.c lib_tputs.c lib_vidattr.c
445*80cd5ab5SBaptiste Daroussin    read_entry.c.</code>
446*80cd5ab5SBaptiste Daroussin  </blockquote>
447*80cd5ab5SBaptiste Daroussin
448*80cd5ab5SBaptiste Daroussin  <p>They are likely to need revision only if ncurses is being
449*80cd5ab5SBaptiste Daroussin  ported to an environment without an underlying terminfo
450*80cd5ab5SBaptiste Daroussin  capability representation.</p>
451*80cd5ab5SBaptiste Daroussin
452*80cd5ab5SBaptiste Daroussin  <p>These files have serious hooks into the tty driver and signal
453*80cd5ab5SBaptiste Daroussin  facilities:</p>
454*80cd5ab5SBaptiste Daroussin
455*80cd5ab5SBaptiste Daroussin  <blockquote>
456*80cd5ab5SBaptiste Daroussin    <code>lib_kernel.c lib_baudrate.c lib_raw.c lib_tstp.c
457*80cd5ab5SBaptiste Daroussin    lib_twait.c</code>
458*80cd5ab5SBaptiste Daroussin  </blockquote>
459*80cd5ab5SBaptiste Daroussin
460*80cd5ab5SBaptiste Daroussin  <p>If you run into porting snafus moving the package to another
461*80cd5ab5SBaptiste Daroussin  UNIX, the problem is likely to be in one of these files. The file
462*80cd5ab5SBaptiste Daroussin  <code>lib_print.c</code> uses sleep(2) and also falls in this
463*80cd5ab5SBaptiste Daroussin  category.</p>
464*80cd5ab5SBaptiste Daroussin
465*80cd5ab5SBaptiste Daroussin  <p>Almost all of the real work is done in the files</p>
466*80cd5ab5SBaptiste Daroussin
467*80cd5ab5SBaptiste Daroussin  <blockquote>
468*80cd5ab5SBaptiste Daroussin    <code>hardscroll.c hashmap.c lib_addch.c lib_doupdate.c
469*80cd5ab5SBaptiste Daroussin    lib_getch.c lib_mouse.c lib_mvcur.c lib_refresh.c lib_setup.c
470*80cd5ab5SBaptiste Daroussin    lib_vidattr.c</code>
471*80cd5ab5SBaptiste Daroussin  </blockquote>
472*80cd5ab5SBaptiste Daroussin
473*80cd5ab5SBaptiste Daroussin  <p>Most of the algorithmic complexity in the library lives in
474*80cd5ab5SBaptiste Daroussin  these files. If there is a real bug in <strong>ncurses</strong>
475*80cd5ab5SBaptiste Daroussin  itself, it is probably here. We will tour some of these files in
476*80cd5ab5SBaptiste Daroussin  detail below (see <a href="#engine">The Engine Room</a>).</p>
477*80cd5ab5SBaptiste Daroussin
478*80cd5ab5SBaptiste Daroussin  <p>Finally, there is a group of files that is actually most of
479*80cd5ab5SBaptiste Daroussin  the terminfo compiler. The reason this code lives in the
480*80cd5ab5SBaptiste Daroussin  <strong>ncurses</strong> library is to support fallback to
481*80cd5ab5SBaptiste Daroussin  /etc/termcap. These files include</p>
482*80cd5ab5SBaptiste Daroussin
483*80cd5ab5SBaptiste Daroussin  <blockquote>
484*80cd5ab5SBaptiste Daroussin    <code>alloc_entry.c captoinfo.c comp_captab.c comp_error.c
485*80cd5ab5SBaptiste Daroussin    comp_hash.c comp_parse.c comp_scan.c parse_entry.c
486*80cd5ab5SBaptiste Daroussin    read_termcap.c write_entry.c</code>
487*80cd5ab5SBaptiste Daroussin  </blockquote>
488*80cd5ab5SBaptiste Daroussin
489*80cd5ab5SBaptiste Daroussin  <p>We will discuss these in the compiler tour.</p>
490*80cd5ab5SBaptiste Daroussin
491*80cd5ab5SBaptiste Daroussin  <h3><a name="engine" id="engine">The Engine Room</a></h3>
492*80cd5ab5SBaptiste Daroussin
493*80cd5ab5SBaptiste Daroussin  <h4><a name="input" id="input">Keyboard Input</a></h4>
494*80cd5ab5SBaptiste Daroussin
495*80cd5ab5SBaptiste Daroussin  <p>All <code>ncurses</code> input funnels through the function
496*80cd5ab5SBaptiste Daroussin  <code>wgetch()</code>, defined in <code>lib_getch.c</code>. This
497*80cd5ab5SBaptiste Daroussin  function is tricky; it has to poll for keyboard and mouse events
498*80cd5ab5SBaptiste Daroussin  and do a running match of incoming input against the set of
499*80cd5ab5SBaptiste Daroussin  defined special keys.</p>
500*80cd5ab5SBaptiste Daroussin
501*80cd5ab5SBaptiste Daroussin  <p>The central data structure in this module is a FIFO queue,
502*80cd5ab5SBaptiste Daroussin  used to match multiple-character input sequences against
503*80cd5ab5SBaptiste Daroussin  special-key capabilities; also to implement pushback via
504*80cd5ab5SBaptiste Daroussin  <code>ungetch()</code>.</p>
505*80cd5ab5SBaptiste Daroussin
506*80cd5ab5SBaptiste Daroussin  <p>The <code>wgetch()</code> code distinguishes between function
507*80cd5ab5SBaptiste Daroussin  key sequences and the same sequences typed manually by doing a
508*80cd5ab5SBaptiste Daroussin  timed wait after each input character that could lead a function
509*80cd5ab5SBaptiste Daroussin  key sequence. If the entire sequence takes less than 1 second, it
510*80cd5ab5SBaptiste Daroussin  is assumed to have been generated by a function key press.</p>
511*80cd5ab5SBaptiste Daroussin
512*80cd5ab5SBaptiste Daroussin  <p>Hackers bruised by previous encounters with variant
513*80cd5ab5SBaptiste Daroussin  <code>select(2)</code> calls may find the code in
514*80cd5ab5SBaptiste Daroussin  <code>lib_twait.c</code> interesting. It deals with the problem
515*80cd5ab5SBaptiste Daroussin  that some BSD selects do not return a reliable time-left value.
516*80cd5ab5SBaptiste Daroussin  The function <code>timed_wait()</code> effectively simulates a
517*80cd5ab5SBaptiste Daroussin  System V select.</p>
518*80cd5ab5SBaptiste Daroussin
519*80cd5ab5SBaptiste Daroussin  <h4><a name="mouse" id="mouse">Mouse Events</a></h4>
520*80cd5ab5SBaptiste Daroussin
521*80cd5ab5SBaptiste Daroussin  <p>If the mouse interface is active, <code>wgetch()</code> polls
522*80cd5ab5SBaptiste Daroussin  for mouse events each call, before it goes to the keyboard for
523*80cd5ab5SBaptiste Daroussin  input. It is up to <code>lib_mouse.c</code> how the polling is
524*80cd5ab5SBaptiste Daroussin  accomplished; it may vary for different devices.</p>
525*80cd5ab5SBaptiste Daroussin
526*80cd5ab5SBaptiste Daroussin  <p>Under xterm, however, mouse event notifications come in via
527*80cd5ab5SBaptiste Daroussin  the keyboard input stream. They are recognized by having the
528*80cd5ab5SBaptiste Daroussin  <strong>kmous</strong> capability as a prefix. This is kind of
529*80cd5ab5SBaptiste Daroussin  klugey, but trying to wire in recognition of a mouse key prefix
530*80cd5ab5SBaptiste Daroussin  without going through the function-key machinery would be just
531*80cd5ab5SBaptiste Daroussin  too painful, and this turns out to imply having the prefix
532*80cd5ab5SBaptiste Daroussin  somewhere in the function-key capabilities at terminal-type
533*80cd5ab5SBaptiste Daroussin  initialization.</p>
534*80cd5ab5SBaptiste Daroussin
535*80cd5ab5SBaptiste Daroussin  <p>This kluge only works because <strong>kmous</strong> is not
536*80cd5ab5SBaptiste Daroussin  actually used by any historic terminal type or curses
537*80cd5ab5SBaptiste Daroussin  implementation we know of. Best guess is it is a relic of some
538*80cd5ab5SBaptiste Daroussin  forgotten experiment in-house at Bell Labs that did not leave any
539*80cd5ab5SBaptiste Daroussin  traces in the publicly-distributed System V terminfo files. If
540*80cd5ab5SBaptiste Daroussin  System V or XPG4 ever gets serious about using it again, this
541*80cd5ab5SBaptiste Daroussin  kluge may have to change.</p>
542*80cd5ab5SBaptiste Daroussin
543*80cd5ab5SBaptiste Daroussin  <p>Here are some more details about mouse event handling:</p>
544*80cd5ab5SBaptiste Daroussin
545*80cd5ab5SBaptiste Daroussin  <p>The <code>lib_mouse()</code> code is logically split into a
546*80cd5ab5SBaptiste Daroussin  lower level that accepts event reports in a device-dependent
547*80cd5ab5SBaptiste Daroussin  format and an upper level that parses mouse gestures and filters
548*80cd5ab5SBaptiste Daroussin  events. The mediating data structure is a circular queue of event
549*80cd5ab5SBaptiste Daroussin  structures.</p>
550*80cd5ab5SBaptiste Daroussin
551*80cd5ab5SBaptiste Daroussin  <p>Functionally, the lower level's job is to pick up primitive
552*80cd5ab5SBaptiste Daroussin  events and put them on the circular queue. This can happen in one
553*80cd5ab5SBaptiste Daroussin  of two ways: either (a) <code>_nc_mouse_event()</code> detects a
554*80cd5ab5SBaptiste Daroussin  series of incoming mouse reports and queues them, or (b) code in
555*80cd5ab5SBaptiste Daroussin  <code>lib_getch.c</code> detects the <strong>kmous</strong>
556*80cd5ab5SBaptiste Daroussin  prefix in the keyboard input stream and calls _nc_mouse_inline to
557*80cd5ab5SBaptiste Daroussin  queue up a series of adjacent mouse reports.</p>
558*80cd5ab5SBaptiste Daroussin
559*80cd5ab5SBaptiste Daroussin  <p>In either case, <code>_nc_mouse_parse()</code> should be
560*80cd5ab5SBaptiste Daroussin  called after the series is accepted to parse the digested mouse
561*80cd5ab5SBaptiste Daroussin  reports (low-level events) into a gesture (a high-level or
562*80cd5ab5SBaptiste Daroussin  composite event).</p>
563*80cd5ab5SBaptiste Daroussin
564*80cd5ab5SBaptiste Daroussin  <h4><a name="output" id="output">Output and Screen Updating</a></h4>
565*80cd5ab5SBaptiste Daroussin
566*80cd5ab5SBaptiste Daroussin  <p>With the single exception of character echoes during a
567*80cd5ab5SBaptiste Daroussin  <code>wgetnstr()</code> call (which simulates cooked-mode line
568*80cd5ab5SBaptiste Daroussin  editing in an ncurses window), the library normally does all its
569*80cd5ab5SBaptiste Daroussin  output at refresh time.</p>
570*80cd5ab5SBaptiste Daroussin
571*80cd5ab5SBaptiste Daroussin  <p>The main job is to go from the current state of the screen (as
572*80cd5ab5SBaptiste Daroussin  represented in the <code>curscr</code> window structure) to the
573*80cd5ab5SBaptiste Daroussin  desired new state (as represented in the <code>newscr</code>
574*80cd5ab5SBaptiste Daroussin  window structure), while doing as little I/O as possible.</p>
575*80cd5ab5SBaptiste Daroussin
576*80cd5ab5SBaptiste Daroussin  <p>The brains of this operation are the modules
577*80cd5ab5SBaptiste Daroussin  <code>hashmap.c</code>, <code>hardscroll.c</code> and
578*80cd5ab5SBaptiste Daroussin  <code>lib_doupdate.c</code>; the latter two use
579*80cd5ab5SBaptiste Daroussin  <code>lib_mvcur.c</code>. Essentially, what happens looks like
580*80cd5ab5SBaptiste Daroussin  this:</p>
581*80cd5ab5SBaptiste Daroussin
582*80cd5ab5SBaptiste Daroussin  <ul>
583*80cd5ab5SBaptiste Daroussin    <li>
584*80cd5ab5SBaptiste Daroussin      <p>The <code>hashmap.c</code> module tries to detect vertical
585*80cd5ab5SBaptiste Daroussin      motion changes between the real and virtual screens. This
586*80cd5ab5SBaptiste Daroussin      information is represented by the oldindex members in the
587*80cd5ab5SBaptiste Daroussin      newscr structure. These are modified by vertical-motion and
588*80cd5ab5SBaptiste Daroussin      clear operations, and both are re-initialized after each
589*80cd5ab5SBaptiste Daroussin      update. To this change-journalling information, the hashmap
590*80cd5ab5SBaptiste Daroussin      code adds deductions made using a modified Heckel algorithm
591*80cd5ab5SBaptiste Daroussin      on hash values generated from the line contents.</p>
592*80cd5ab5SBaptiste Daroussin    </li>
593*80cd5ab5SBaptiste Daroussin
594*80cd5ab5SBaptiste Daroussin    <li>
595*80cd5ab5SBaptiste Daroussin      <p>The <code>hardscroll.c</code> module computes an optimum
596*80cd5ab5SBaptiste Daroussin      set of scroll, insertion, and deletion operations to make the
597*80cd5ab5SBaptiste Daroussin      indices match. It calls <code>_nc_mvcur_scrolln()</code> in
598*80cd5ab5SBaptiste Daroussin      <code>lib_mvcur.c</code> to do those motions.</p>
599*80cd5ab5SBaptiste Daroussin    </li>
600*80cd5ab5SBaptiste Daroussin
601*80cd5ab5SBaptiste Daroussin    <li>
602*80cd5ab5SBaptiste Daroussin      <p>Then <code>lib_doupdate.c</code> goes to work. Its job is
603*80cd5ab5SBaptiste Daroussin      to do line-by-line transformations of <code>curscr</code>
604*80cd5ab5SBaptiste Daroussin      lines to <code>newscr</code> lines. Its main tool is the
605*80cd5ab5SBaptiste Daroussin      routine <code>mvcur()</code> in <code>lib_mvcur.c</code>.
606*80cd5ab5SBaptiste Daroussin      This routine does cursor-movement optimization, attempting to
607*80cd5ab5SBaptiste Daroussin      get from given screen location A to given location B in the
608*80cd5ab5SBaptiste Daroussin      fewest output characters possible.</p>
609*80cd5ab5SBaptiste Daroussin    </li>
610*80cd5ab5SBaptiste Daroussin  </ul>
611*80cd5ab5SBaptiste Daroussin
612*80cd5ab5SBaptiste Daroussin  <p>If you want to work on screen optimizations, you should use
613*80cd5ab5SBaptiste Daroussin  the fact that (in the trace-enabled version of the library)
614*80cd5ab5SBaptiste Daroussin  enabling the <code>TRACE_TIMES</code> trace level causes a report
615*80cd5ab5SBaptiste Daroussin  to be emitted after each screen update giving the elapsed time
616*80cd5ab5SBaptiste Daroussin  and a count of characters emitted during the update. You can use
617*80cd5ab5SBaptiste Daroussin  this to tell when an update optimization improves efficiency.</p>
618*80cd5ab5SBaptiste Daroussin
619*80cd5ab5SBaptiste Daroussin  <p>In the trace-enabled version of the library, it is also
620*80cd5ab5SBaptiste Daroussin  possible to disable and re-enable various optimizations at
621*80cd5ab5SBaptiste Daroussin  runtime by tweaking the variable
622*80cd5ab5SBaptiste Daroussin  <code>_nc_optimize_enable</code>. See the file
623*80cd5ab5SBaptiste Daroussin  <code>include/curses.h.in</code> for mask values, near the
624*80cd5ab5SBaptiste Daroussin  end.</p>
625*80cd5ab5SBaptiste Daroussin
626*80cd5ab5SBaptiste Daroussin  <h2><a name="fmnote" id="fmnote">The Forms and Menu Libraries</a></h2>
627*80cd5ab5SBaptiste Daroussin
628*80cd5ab5SBaptiste Daroussin  <p>The forms and menu libraries should work reliably in any
629*80cd5ab5SBaptiste Daroussin  environment you can port ncurses to. The only portability issue
630*80cd5ab5SBaptiste Daroussin  anywhere in them is what flavor of regular expressions the
631*80cd5ab5SBaptiste Daroussin  built-in form field type TYPE_REGEXP will recognize.</p>
632*80cd5ab5SBaptiste Daroussin
633*80cd5ab5SBaptiste Daroussin  <p>The configuration code prefers the POSIX regex facility,
634*80cd5ab5SBaptiste Daroussin  modeled on System V's, but will settle for BSD regexps if the
635*80cd5ab5SBaptiste Daroussin  former is not available.</p>
636*80cd5ab5SBaptiste Daroussin
637*80cd5ab5SBaptiste Daroussin  <p>Historical note: the panels code was written primarily to
638*80cd5ab5SBaptiste Daroussin  assist in porting u386mon 2.0 (comp.sources.misc v14i001-4) to
639*80cd5ab5SBaptiste Daroussin  systems lacking panels support; u386mon 2.10 and beyond use it.
640*80cd5ab5SBaptiste Daroussin  This version has been slightly cleaned up for
641*80cd5ab5SBaptiste Daroussin  <code>ncurses</code>.</p>
642*80cd5ab5SBaptiste Daroussin
643*80cd5ab5SBaptiste Daroussin  <h2><a name="tic" id="tic">A Tour of the Terminfo Compiler</a></h2>
644*80cd5ab5SBaptiste Daroussin
645*80cd5ab5SBaptiste Daroussin  <p>The <strong>ncurses</strong> implementation of
646*80cd5ab5SBaptiste Daroussin  <strong>tic</strong> is rather complex internally; it has to do a
647*80cd5ab5SBaptiste Daroussin  trying combination of missions. This starts with the fact that,
648*80cd5ab5SBaptiste Daroussin  in addition to its normal duty of compiling terminfo sources into
649*80cd5ab5SBaptiste Daroussin  loadable terminfo binaries, it has to be able to handle termcap
650*80cd5ab5SBaptiste Daroussin  syntax and compile that too into terminfo entries.</p>
651*80cd5ab5SBaptiste Daroussin
652*80cd5ab5SBaptiste Daroussin  <p>The implementation therefore starts with a table-driven,
653*80cd5ab5SBaptiste Daroussin  dual-mode lexical analyzer (in <code>comp_scan.c</code>). The
654*80cd5ab5SBaptiste Daroussin  lexer chooses its mode (termcap or terminfo) based on the first
655*80cd5ab5SBaptiste Daroussin  &ldquo;,&rdquo; or &ldquo;:&rdquo; it finds in each entry. The
656*80cd5ab5SBaptiste Daroussin  lexer does all the work of recognizing capability names and
657*80cd5ab5SBaptiste Daroussin  values; the grammar above it is trivial, just "parse entries till
658*80cd5ab5SBaptiste Daroussin  you run out of file".</p>
659*80cd5ab5SBaptiste Daroussin
660*80cd5ab5SBaptiste Daroussin  <h3><a name="nonuse" id="nonuse">Translation of
661*80cd5ab5SBaptiste Daroussin  Non-<strong>use</strong> Capabilities</a></h3>
662*80cd5ab5SBaptiste Daroussin
663*80cd5ab5SBaptiste Daroussin  <p>Translation of most things besides <strong>use</strong>
664*80cd5ab5SBaptiste Daroussin  capabilities is pretty straightforward. The lexical analyzer's
665*80cd5ab5SBaptiste Daroussin  tokenizer hands each capability name to a hash function, which
666*80cd5ab5SBaptiste Daroussin  drives a table lookup. The table entry yields an index which is
667*80cd5ab5SBaptiste Daroussin  used to look up the token type in another table, and controls
668*80cd5ab5SBaptiste Daroussin  interpretation of the value.</p>
669*80cd5ab5SBaptiste Daroussin
670*80cd5ab5SBaptiste Daroussin  <p>One possibly interesting aspect of the implementation is the
671*80cd5ab5SBaptiste Daroussin  way the compiler tables are initialized. All the tables are
672*80cd5ab5SBaptiste Daroussin  generated by various awk/sed/sh scripts from a master table
673*80cd5ab5SBaptiste Daroussin  <code>include/Caps</code>; these scripts actually write C
674*80cd5ab5SBaptiste Daroussin  initializers which are linked to the compiler. Furthermore, the
675*80cd5ab5SBaptiste Daroussin  hash table is generated in the same way, so it doesn't have to be
676*80cd5ab5SBaptiste Daroussin  generated at compiler startup time (another benefit of this
677*80cd5ab5SBaptiste Daroussin  organization is that the hash table can be in shareable text
678*80cd5ab5SBaptiste Daroussin  space).</p>
679*80cd5ab5SBaptiste Daroussin
680*80cd5ab5SBaptiste Daroussin  <p>Thus, adding a new capability is usually pretty trivial, just
681*80cd5ab5SBaptiste Daroussin  a matter of adding one line to the <code>include/Caps</code>
682*80cd5ab5SBaptiste Daroussin  file. We will have more to say about this in the section on
683*80cd5ab5SBaptiste Daroussin  <a href="#translation">Source-Form Translation</a>.</p>
684*80cd5ab5SBaptiste Daroussin
685*80cd5ab5SBaptiste Daroussin  <h3><a name="uses" id="uses">Use Capability Resolution</a></h3>
686*80cd5ab5SBaptiste Daroussin
687*80cd5ab5SBaptiste Daroussin  <p>The background problem that makes <strong>tic</strong> tricky
688*80cd5ab5SBaptiste Daroussin  is not the capability translation itself, it is the resolution of
689*80cd5ab5SBaptiste Daroussin  <strong>use</strong> capabilities. Older versions would not
690*80cd5ab5SBaptiste Daroussin  handle forward <strong>use</strong> references for this reason
691*80cd5ab5SBaptiste Daroussin  (that is, a using terminal always had to follow its use target in
692*80cd5ab5SBaptiste Daroussin  the source file). By doing this, they got away with a simple
693*80cd5ab5SBaptiste Daroussin  implementation tactic; compile everything as it blows by, then
694*80cd5ab5SBaptiste Daroussin  resolve uses from compiled entries.</p>
695*80cd5ab5SBaptiste Daroussin
696*80cd5ab5SBaptiste Daroussin  <p>This will not do for <strong>ncurses</strong>. The problem is
697*80cd5ab5SBaptiste Daroussin  that that the whole compilation process has to be embeddable in
698*80cd5ab5SBaptiste Daroussin  the <strong>ncurses</strong> library so that it can be called by
699*80cd5ab5SBaptiste Daroussin  the startup code to translate termcap entries on the fly. The
700*80cd5ab5SBaptiste Daroussin  embedded version cannot go promiscuously writing everything it
701*80cd5ab5SBaptiste Daroussin  translates out to disk &mdash; for one thing, it will typically
702*80cd5ab5SBaptiste Daroussin  be running with non-root permissions.</p>
703*80cd5ab5SBaptiste Daroussin
704*80cd5ab5SBaptiste Daroussin  <p>So our <strong>tic</strong> is designed to parse an entire
705*80cd5ab5SBaptiste Daroussin  terminfo file into a doubly-linked circular list of entry
706*80cd5ab5SBaptiste Daroussin  structures in-core, and then do <strong>use</strong> resolution
707*80cd5ab5SBaptiste Daroussin  in-memory before writing everything out. This design has other
708*80cd5ab5SBaptiste Daroussin  advantages: it makes forward and back use-references equally easy
709*80cd5ab5SBaptiste Daroussin  (so we get the latter for free), and it makes checking for name
710*80cd5ab5SBaptiste Daroussin  collisions before they are written out easy to do.</p>
711*80cd5ab5SBaptiste Daroussin
712*80cd5ab5SBaptiste Daroussin  <p>And this is exactly how the embedded version works. But the
713*80cd5ab5SBaptiste Daroussin  stand-alone user-accessible version of <strong>tic</strong>
714*80cd5ab5SBaptiste Daroussin  partly reverts to the historical strategy; it writes to disk (not
715*80cd5ab5SBaptiste Daroussin  keeping in core) any entry with no <strong>use</strong>
716*80cd5ab5SBaptiste Daroussin  references.</p>
717*80cd5ab5SBaptiste Daroussin
718*80cd5ab5SBaptiste Daroussin  <p>This is strictly a core-economy kluge, implemented because the
719*80cd5ab5SBaptiste Daroussin  terminfo master file is large enough that some core-poor systems
720*80cd5ab5SBaptiste Daroussin  swap like crazy when you compile it all in memory...there have
721*80cd5ab5SBaptiste Daroussin  been reports of this process taking <strong>three hours</strong>,
722*80cd5ab5SBaptiste Daroussin  rather than the twenty seconds or less typical on the author's
723*80cd5ab5SBaptiste Daroussin  development box.</p>
724*80cd5ab5SBaptiste Daroussin
725*80cd5ab5SBaptiste Daroussin  <p>So. The executable <strong>tic</strong> passes the
726*80cd5ab5SBaptiste Daroussin  entry-parser a hook that <em>immediately</em> writes out the
727*80cd5ab5SBaptiste Daroussin  referenced entry if it has no use capabilities. The compiler main
728*80cd5ab5SBaptiste Daroussin  loop refrains from adding the entry to the in-core list when this
729*80cd5ab5SBaptiste Daroussin  hook fires. If some other entry later needs to reference an entry
730*80cd5ab5SBaptiste Daroussin  that got written immediately, that is OK; the resolution code
731*80cd5ab5SBaptiste Daroussin  will fetch it off disk when it cannot find it in core.</p>
732*80cd5ab5SBaptiste Daroussin
733*80cd5ab5SBaptiste Daroussin  <p>Name collisions will still be detected, just not as cleanly.
734*80cd5ab5SBaptiste Daroussin  The <code>write_entry()</code> code complains before overwriting
735*80cd5ab5SBaptiste Daroussin  an entry that postdates the time of <strong>tic</strong>'s first
736*80cd5ab5SBaptiste Daroussin  call to <code>write_entry()</code>, Thus it will complain about
737*80cd5ab5SBaptiste Daroussin  overwriting entries newly made during the <strong>tic</strong>
738*80cd5ab5SBaptiste Daroussin  run, but not about overwriting ones that predate it.</p>
739*80cd5ab5SBaptiste Daroussin
740*80cd5ab5SBaptiste Daroussin  <h3><a name="translation" id="translation">Source-Form
741*80cd5ab5SBaptiste Daroussin  Translation</a></h3>
742*80cd5ab5SBaptiste Daroussin
743*80cd5ab5SBaptiste Daroussin  <p>Another use of <strong>tic</strong> is to do source
744*80cd5ab5SBaptiste Daroussin  translation between various termcap and terminfo formats. There
745*80cd5ab5SBaptiste Daroussin  are more variants out there than you might think; the ones we
746*80cd5ab5SBaptiste Daroussin  know about are described in the <strong>captoinfo(1)</strong>
747*80cd5ab5SBaptiste Daroussin  manual page.</p>
748*80cd5ab5SBaptiste Daroussin
749*80cd5ab5SBaptiste Daroussin  <p>The translation output code (<code>dump_entry()</code> in
750*80cd5ab5SBaptiste Daroussin  <code>ncurses/dump_entry.c</code>) is shared with the
751*80cd5ab5SBaptiste Daroussin  <strong>infocmp(1)</strong> utility. It takes the same internal
752*80cd5ab5SBaptiste Daroussin  representation used to generate the binary form and dumps it to
753*80cd5ab5SBaptiste Daroussin  standard output in a specified format.</p>
754*80cd5ab5SBaptiste Daroussin
755*80cd5ab5SBaptiste Daroussin  <p>The <code>include/Caps</code> file has a header comment
756*80cd5ab5SBaptiste Daroussin  describing ways you can specify source translations for
757*80cd5ab5SBaptiste Daroussin  nonstandard capabilities just by altering the master table. It is
758*80cd5ab5SBaptiste Daroussin  possible to set up capability aliasing or tell the compiler to
759*80cd5ab5SBaptiste Daroussin  plain ignore a given capability without writing any C code at
760*80cd5ab5SBaptiste Daroussin  all.</p>
761*80cd5ab5SBaptiste Daroussin
762*80cd5ab5SBaptiste Daroussin  <p>For circumstances where you need to do algorithmic
763*80cd5ab5SBaptiste Daroussin  translation, there are functions in <code>parse_entry.c</code>
764*80cd5ab5SBaptiste Daroussin  called after the parse of each entry that are specifically
765*80cd5ab5SBaptiste Daroussin  intended to encapsulate such translations. This, for example, is
766*80cd5ab5SBaptiste Daroussin  where the AIX <strong>box1</strong> capability get translated to
767*80cd5ab5SBaptiste Daroussin  an <strong>acsc</strong> string.</p>
768*80cd5ab5SBaptiste Daroussin
769*80cd5ab5SBaptiste Daroussin  <h2><a name="utils" id="utils">Other Utilities</a></h2>
770*80cd5ab5SBaptiste Daroussin
771*80cd5ab5SBaptiste Daroussin  <p>The <strong>infocmp</strong> utility is just a wrapper around
772*80cd5ab5SBaptiste Daroussin  the same entry-dumping code used by <strong>tic</strong> for
773*80cd5ab5SBaptiste Daroussin  source translation. Perhaps the one interesting aspect of the
774*80cd5ab5SBaptiste Daroussin  code is the use of a predicate function passed in to
775*80cd5ab5SBaptiste Daroussin  <code>dump_entry()</code> to control which capabilities are
776*80cd5ab5SBaptiste Daroussin  dumped. This is necessary in order to handle both the ordinary
777*80cd5ab5SBaptiste Daroussin  De-compilation case and entry difference reporting.</p>
778*80cd5ab5SBaptiste Daroussin
779*80cd5ab5SBaptiste Daroussin  <p>The <strong>tput</strong> and <strong>clear</strong> utilities
780*80cd5ab5SBaptiste Daroussin  just do an entry load followed by a <code>tputs()</code> of a
781*80cd5ab5SBaptiste Daroussin  selected capability.</p>
782*80cd5ab5SBaptiste Daroussin
783*80cd5ab5SBaptiste Daroussin  <h2><a name="style" id="style">Style Tips for Developers</a></h2>
784*80cd5ab5SBaptiste Daroussin
785*80cd5ab5SBaptiste Daroussin  <p>See the TO-DO file in the top-level directory of the source
786*80cd5ab5SBaptiste Daroussin  distribution for additions that would be particularly useful.</p>
787*80cd5ab5SBaptiste Daroussin
788*80cd5ab5SBaptiste Daroussin  <p>The prefix <code>_nc_</code> should be used on library public
789*80cd5ab5SBaptiste Daroussin  functions that are not part of the curses API in order to prevent
790*80cd5ab5SBaptiste Daroussin  pollution of the application namespace. If you have to add to or
791*80cd5ab5SBaptiste Daroussin  modify the function prototypes in curses.h.in, read
792*80cd5ab5SBaptiste Daroussin  ncurses/MKlib_gen.sh first so you can avoid breaking XSI
793*80cd5ab5SBaptiste Daroussin  conformance. Please join the ncurses mailing list. See the
794*80cd5ab5SBaptiste Daroussin  INSTALL file in the top level of the distribution for details on
795*80cd5ab5SBaptiste Daroussin  the list.</p>
796*80cd5ab5SBaptiste Daroussin
797*80cd5ab5SBaptiste Daroussin  <p>Look for the string <code>FIXME</code> in source files to tag
798*80cd5ab5SBaptiste Daroussin  minor bugs and potential problems that could use fixing.</p>
799*80cd5ab5SBaptiste Daroussin
800*80cd5ab5SBaptiste Daroussin  <p>Do not try to auto-detect OS features in the main body of the
801*80cd5ab5SBaptiste Daroussin  C code. That is the job of the configuration system.</p>
802*80cd5ab5SBaptiste Daroussin
803*80cd5ab5SBaptiste Daroussin  <p>To hold down complexity, do make your code data-driven.
804*80cd5ab5SBaptiste Daroussin  Especially, if you can drive logic from a table filtered out of
805*80cd5ab5SBaptiste Daroussin  <code>include/Caps</code>, do it. If you find you need to augment
806*80cd5ab5SBaptiste Daroussin  the data in that file in order to generate the proper table, that
807*80cd5ab5SBaptiste Daroussin  is still preferable to ad-hoc code &mdash; that is why the fifth
808*80cd5ab5SBaptiste Daroussin  field (flags) is there.</p>
809*80cd5ab5SBaptiste Daroussin
810*80cd5ab5SBaptiste Daroussin  <p>Have fun!</p>
811*80cd5ab5SBaptiste Daroussin
812*80cd5ab5SBaptiste Daroussin  <h2><a name="port" id="port">Porting Hints</a></h2>
813*80cd5ab5SBaptiste Daroussin
814*80cd5ab5SBaptiste Daroussin  <p>The following notes are intended to be a first step towards
815*80cd5ab5SBaptiste Daroussin  DOS and Macintosh ports of the ncurses libraries.</p>
816*80cd5ab5SBaptiste Daroussin
817*80cd5ab5SBaptiste Daroussin  <p>The following library modules are &ldquo;pure curses&rdquo;;
818*80cd5ab5SBaptiste Daroussin  they operate only on the curses internal structures, do all
819*80cd5ab5SBaptiste Daroussin  output through other curses calls (not including
820*80cd5ab5SBaptiste Daroussin  <code>tputs()</code> and <code>putp()</code>) and do not call any
821*80cd5ab5SBaptiste Daroussin  other UNIX routines such as signal(2) or the stdio library. Thus,
822*80cd5ab5SBaptiste Daroussin  they should not need to be modified for single-terminal
823*80cd5ab5SBaptiste Daroussin  ports.</p>
824*80cd5ab5SBaptiste Daroussin
825*80cd5ab5SBaptiste Daroussin  <blockquote>
826*80cd5ab5SBaptiste Daroussin    <code>lib_addch.c lib_addstr.c lib_bkgd.c lib_box.c lib_clear.c
827*80cd5ab5SBaptiste Daroussin    lib_clrbot.c lib_clreol.c lib_delch.c lib_delwin.c lib_erase.c
828*80cd5ab5SBaptiste Daroussin    lib_inchstr.c lib_insch.c lib_insdel.c lib_insstr.c
829*80cd5ab5SBaptiste Daroussin    lib_keyname.c lib_move.c lib_mvwin.c lib_newwin.c lib_overlay.c
830*80cd5ab5SBaptiste Daroussin    lib_pad.c lib_printw.c lib_refresh.c lib_scanw.c lib_scroll.c
831*80cd5ab5SBaptiste Daroussin    lib_scrreg.c lib_set_term.c lib_touch.c lib_tparm.c lib_tputs.c
832*80cd5ab5SBaptiste Daroussin    lib_unctrl.c lib_window.c panel.c</code>
833*80cd5ab5SBaptiste Daroussin  </blockquote>
834*80cd5ab5SBaptiste Daroussin
835*80cd5ab5SBaptiste Daroussin  <p>This module is pure curses, but calls outstr():</p>
836*80cd5ab5SBaptiste Daroussin
837*80cd5ab5SBaptiste Daroussin  <blockquote>
838*80cd5ab5SBaptiste Daroussin    <code>lib_getstr.c</code>
839*80cd5ab5SBaptiste Daroussin  </blockquote>
840*80cd5ab5SBaptiste Daroussin
841*80cd5ab5SBaptiste Daroussin  <p>These modules are pure curses, except that they use
842*80cd5ab5SBaptiste Daroussin  <code>tputs()</code> and <code>putp()</code>:</p>
843*80cd5ab5SBaptiste Daroussin
844*80cd5ab5SBaptiste Daroussin  <blockquote>
845*80cd5ab5SBaptiste Daroussin    <code>lib_beep.c lib_color.c lib_endwin.c lib_options.c
846*80cd5ab5SBaptiste Daroussin    lib_slk.c lib_vidattr.c</code>
847*80cd5ab5SBaptiste Daroussin  </blockquote>
848*80cd5ab5SBaptiste Daroussin
849*80cd5ab5SBaptiste Daroussin  <p>This modules assist in POSIX emulation on non-POSIX
850*80cd5ab5SBaptiste Daroussin  systems:</p>
851*80cd5ab5SBaptiste Daroussin
852*80cd5ab5SBaptiste Daroussin  <dl>
853*80cd5ab5SBaptiste Daroussin    <dt>sigaction.c</dt>
854*80cd5ab5SBaptiste Daroussin
855*80cd5ab5SBaptiste Daroussin    <dd>signal calls</dd>
856*80cd5ab5SBaptiste Daroussin  </dl>
857*80cd5ab5SBaptiste Daroussin
858*80cd5ab5SBaptiste Daroussin  <p>The following source files will not be needed for a
859*80cd5ab5SBaptiste Daroussin  single-terminal-type port.</p>
860*80cd5ab5SBaptiste Daroussin
861*80cd5ab5SBaptiste Daroussin  <blockquote>
862*80cd5ab5SBaptiste Daroussin    <code>alloc_entry.c captoinfo.c clear.c comp_captab.c
863*80cd5ab5SBaptiste Daroussin    comp_error.c comp_hash.c comp_main.c comp_parse.c comp_scan.c
864*80cd5ab5SBaptiste Daroussin    dump_entry.c infocmp.c parse_entry.c read_entry.c tput.c
865*80cd5ab5SBaptiste Daroussin    write_entry.c</code>
866*80cd5ab5SBaptiste Daroussin  </blockquote>
867*80cd5ab5SBaptiste Daroussin
868*80cd5ab5SBaptiste Daroussin  <p>The following modules will use
869*80cd5ab5SBaptiste Daroussin  open()/read()/write()/close()/lseek() on files, but no other OS
870*80cd5ab5SBaptiste Daroussin  calls.</p>
871*80cd5ab5SBaptiste Daroussin
872*80cd5ab5SBaptiste Daroussin  <dl>
873*80cd5ab5SBaptiste Daroussin    <dt>lib_screen.c</dt>
874*80cd5ab5SBaptiste Daroussin
875*80cd5ab5SBaptiste Daroussin    <dd>used to read/write screen dumps</dd>
876*80cd5ab5SBaptiste Daroussin
877*80cd5ab5SBaptiste Daroussin    <dt>lib_trace.c</dt>
878*80cd5ab5SBaptiste Daroussin
879*80cd5ab5SBaptiste Daroussin    <dd>used to write trace data to the logfile</dd>
880*80cd5ab5SBaptiste Daroussin  </dl>
881*80cd5ab5SBaptiste Daroussin
882*80cd5ab5SBaptiste Daroussin  <p>Modules that would have to be modified for a port start
883*80cd5ab5SBaptiste Daroussin  here:</p>
884*80cd5ab5SBaptiste Daroussin
885*80cd5ab5SBaptiste Daroussin  <p>The following modules are &ldquo;pure curses&rdquo; but
886*80cd5ab5SBaptiste Daroussin  contain assumptions inappropriate for a memory-mapped port.</p>
887*80cd5ab5SBaptiste Daroussin
888*80cd5ab5SBaptiste Daroussin  <dl>
889*80cd5ab5SBaptiste Daroussin    <dt>lib_longname.c</dt>
890*80cd5ab5SBaptiste Daroussin
891*80cd5ab5SBaptiste Daroussin    <dd>assumes there may be multiple terminals</dd>
892*80cd5ab5SBaptiste Daroussin
893*80cd5ab5SBaptiste Daroussin    <dt>lib_acs.c</dt>
894*80cd5ab5SBaptiste Daroussin
895*80cd5ab5SBaptiste Daroussin    <dd>assumes acs_map as a double indirection</dd>
896*80cd5ab5SBaptiste Daroussin
897*80cd5ab5SBaptiste Daroussin    <dt>lib_mvcur.c</dt>
898*80cd5ab5SBaptiste Daroussin
899*80cd5ab5SBaptiste Daroussin    <dd>assumes cursor moves have variable cost</dd>
900*80cd5ab5SBaptiste Daroussin
901*80cd5ab5SBaptiste Daroussin    <dt>lib_termcap.c</dt>
902*80cd5ab5SBaptiste Daroussin
903*80cd5ab5SBaptiste Daroussin    <dd>assumes there may be multiple terminals</dd>
904*80cd5ab5SBaptiste Daroussin
905*80cd5ab5SBaptiste Daroussin    <dt>lib_ti.c</dt>
906*80cd5ab5SBaptiste Daroussin
907*80cd5ab5SBaptiste Daroussin    <dd>assumes there may be multiple terminals</dd>
908*80cd5ab5SBaptiste Daroussin  </dl>
909*80cd5ab5SBaptiste Daroussin
910*80cd5ab5SBaptiste Daroussin  <p>The following modules use UNIX-specific calls:</p>
911*80cd5ab5SBaptiste Daroussin
912*80cd5ab5SBaptiste Daroussin  <dl>
913*80cd5ab5SBaptiste Daroussin    <dt>lib_doupdate.c</dt>
914*80cd5ab5SBaptiste Daroussin
915*80cd5ab5SBaptiste Daroussin    <dd>input checking</dd>
916*80cd5ab5SBaptiste Daroussin
917*80cd5ab5SBaptiste Daroussin    <dt>lib_getch.c</dt>
918*80cd5ab5SBaptiste Daroussin
919*80cd5ab5SBaptiste Daroussin    <dd>read()</dd>
920*80cd5ab5SBaptiste Daroussin
921*80cd5ab5SBaptiste Daroussin    <dt>lib_initscr.c</dt>
922*80cd5ab5SBaptiste Daroussin
923*80cd5ab5SBaptiste Daroussin    <dd>getenv()</dd>
924*80cd5ab5SBaptiste Daroussin
925*80cd5ab5SBaptiste Daroussin    <dt>lib_newterm.c</dt>
926*80cd5ab5SBaptiste Daroussin
927*80cd5ab5SBaptiste Daroussin    <dt>lib_baudrate.c</dt>
928*80cd5ab5SBaptiste Daroussin
929*80cd5ab5SBaptiste Daroussin    <dt>lib_kernel.c</dt>
930*80cd5ab5SBaptiste Daroussin
931*80cd5ab5SBaptiste Daroussin    <dd>various tty-manipulation and system calls</dd>
932*80cd5ab5SBaptiste Daroussin
933*80cd5ab5SBaptiste Daroussin    <dt>lib_raw.c</dt>
934*80cd5ab5SBaptiste Daroussin
935*80cd5ab5SBaptiste Daroussin    <dd>various tty-manipulation calls</dd>
936*80cd5ab5SBaptiste Daroussin
937*80cd5ab5SBaptiste Daroussin    <dt>lib_setup.c</dt>
938*80cd5ab5SBaptiste Daroussin
939*80cd5ab5SBaptiste Daroussin    <dd>various tty-manipulation calls</dd>
940*80cd5ab5SBaptiste Daroussin
941*80cd5ab5SBaptiste Daroussin    <dt>lib_restart.c</dt>
942*80cd5ab5SBaptiste Daroussin
943*80cd5ab5SBaptiste Daroussin    <dd>various tty-manipulation calls</dd>
944*80cd5ab5SBaptiste Daroussin
945*80cd5ab5SBaptiste Daroussin    <dt>lib_tstp.c</dt>
946*80cd5ab5SBaptiste Daroussin
947*80cd5ab5SBaptiste Daroussin    <dd>signal-manipulation calls</dd>
948*80cd5ab5SBaptiste Daroussin
949*80cd5ab5SBaptiste Daroussin    <dt>lib_twait.c</dt>
950*80cd5ab5SBaptiste Daroussin
951*80cd5ab5SBaptiste Daroussin    <dd>gettimeofday(), select().</dd>
952*80cd5ab5SBaptiste Daroussin  </dl>
953*80cd5ab5SBaptiste Daroussin
954*80cd5ab5SBaptiste Daroussin  <hr>
955*80cd5ab5SBaptiste Daroussin
956*80cd5ab5SBaptiste Daroussin  <address>
957*80cd5ab5SBaptiste Daroussin    Eric S. Raymond &lt;[email protected]&gt;
958*80cd5ab5SBaptiste Daroussin  </address>
959*80cd5ab5SBaptiste Daroussin  (Note: This is <em>not</em> the <a href="#bugtrack">bug
960*80cd5ab5SBaptiste Daroussin  address</a>!)
961*80cd5ab5SBaptiste Daroussin</body>
962*80cd5ab5SBaptiste Daroussin</html>
963