<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 3.0//EN">
<!--
- $Id: hackguide.html,v 1.23 1999/01/17 00:15:48 tom Exp $
+ $Id: hackguide.html,v 1.25 2000/03/25 18:45:21 tom Exp $
-->
<HTML>
<HEAD>
<H1>Contents</H1>
<UL>
<LI><A HREF="#abstract">Abstract</A>
-<P>
<LI><A HREF="#objective">Objective of the Package</A>
<UL>
<LI><A HREF="#whysvr4">Why System V Curses?</A>
<LI><A HREF="#extensions">How to Design Extensions</A>
</UL>
-<LI><A HREF="#portability">Portability and Configuration</A><UL>
-</UL>
+<LI><A HREF="#portability">Portability and Configuration</A>
<LI><A HREF="#documentation">Documentation Conventions</A>
-<P>
<LI><A HREF="#bugtrack">How to Report Bugs</A>
-<P>
<LI><A HREF="#ncurslib">A Tour of the Ncurses Library</A>
<UL>
<LI><A HREF="#loverview">Library Overview</A>
<LI><A HREF="#output">Output and Screen Updating</A>
</UL>
<LI><A HREF="#fmnote">The Forms and Menu Libraries</A>
-<P>
<LI><A HREF="#tic">A Tour of the Terminfo Compiler</A>
<UL>
<LI><A HREF="#nonuse">Translation of Non-<STRONG>use</STRONG> Capabilities</A>
<LI><A HREF="#translation">Source-Form Translation</A>
</UL>
<LI><A HREF="#utils">Other Utilities</A>
-<P>
<LI><A HREF="#style">Style Tips for Developers</A>
-<P>
<LI><A HREF="#port">Porting Hints</A>
</UL>
It discusses design philosophy, implementation methods, and the
conventions used for coding and documentation. It is recommended
reading for anyone who is interested in porting, extending or improving the
-package. <P>
+package.
<H1><A NAME="objective">Objective of the Package</A></H1>
The objective of the <STRONG>ncurses</STRONG> package is to provide a free software API for
character-cell terminals and terminal emulators with the following
-characteristics: <P>
+characteristics:
<UL>
<LI>Source-compatible with historical curses implementations (including
the original BSD curses and System V curses.
-<P>
<LI>Conformant with the XSI Curses standard issued as part of XPG4 by
X/Open.
-<P>
<LI>High-quality -- stable and reliable code, wide portability, good
packaging, superior documentation.
-<P>
<LI>Featureful -- should eliminate as much of the drudgery of C interface
programming as possible, freeing programmers to think at a higher
level of design.
These objectives are in priority order. So, for example, source
compatibility with older version must trump featurefulness -- we cannot
add features if it means breaking the portion of the API corresponding
-to historical curses versions. <P>
+to historical curses versions.
<H2><A NAME="whysvr4">Why System V Curses?</A></H2>
More importantly for the future, the XSI Curses standard issued by X/Open
is explicitly and closely modeled on System V. So conformance with
-System V took us most of the way to base-level XSI conformance. <P>
+System V took us most of the way to base-level XSI conformance.
<H2><A NAME="extensions">How to Design Extensions</A></H2>
For example, there is a macro <CODE>NCURSES_MOUSE_VERSION</CODE> which XSI Curses
does not define, but which is defined in the <STRONG>ncurses</STRONG> library header.
-You can use this to condition the calls to the mouse API calls. <P>
+You can use this to condition the calls to the mouse API calls.
<H1><A NAME="portability">Portability and Configuration</A></H1>
to less-capable UNIX environments wherever possible. <P>
We encourage developers to support OS-specific optimizations and methods
-not available under POSIX/ANSI, provided only that: <P>
+not available under POSIX/ANSI, provided only that:
<UL>
<LI>All such code is properly conditioned so the build process does not
attempt to compile it under a plain ANSI/POSIX environment.
-<P>
<LI>Adding such implementation methods does not introduce incompatibilities
in the <STRONG>ncurses</STRONG> API between platforms.
</UL>
We use GNU <CODE>autoconf(1)</CODE> as a tool to deal with portability issues.
The right way to leverage an OS-specific feature is to modify the autoconf
specification files (configure.in and aclocal.m4) to set up a new feature
-macro, which you then use to condition your code. <P>
+macro, which you then use to condition your code.
<H1><A NAME="documentation">Documentation Conventions</A></H1>
There are three kinds of documentation associated with this package. Each
-has a different preferred format: <P>
+has a different preferred format:
<UL>
<LI>Package-internal files (README, INSTALL, TO-DO etc.)
<LI>Everything else (i.e., narrative documentation).
</UL>
-Our conventions are simple: <P>
+Our conventions are simple:
<OL>
<LI><STRONG>Maintain package-internal files in plain text.</STRONG>
The expected viewer for them <EM>more(1)</EM> or an editor window; there's
- no point in elaborate mark-up. <P>
+ no point in elaborate mark-up.
<LI><STRONG>Mark up manual pages in the man macros.</STRONG> These have to be viewable
- through traditional <EM>man(1)</EM> programs. <P>
+ through traditional <EM>man(1)</EM> programs.
<LI><STRONG>Write everything else in HTML.</STRONG>
</OL>
as plain text than most other mark-ups, if you don't have a viewer; and (c)
carries enough information that you can generate a nice-looking printed
version from it. Also, of course, it make exporting things like the
-announcement document to WWW pretty trivial.<P>
+announcement document to WWW pretty trivial.
<H1><A NAME="bugtrack">How to Report Bugs</A></H1>
In order to use our bug-fixing time efficiently, we put people who
show us they've taken these steps at the head of our queue. This
means that if you don't, you'll probably end up at the tail end and
-have to wait a while. <P>
+have to wait a while.
<OL>
-<LI>Develop a recipe to reproduce the bug. <P>
-
+<LI>Develop a recipe to reproduce the bug.
+<p>
Bugs we can reproduce are likely to be fixed very quickly, often
within days. The most effective single thing you can do to get a
quick fix is develop a way we can duplicate the bad behavior --
ideally, by giving us source for a small, portable test program that
breaks the library. (Even better is a keystroke recipe using one of
-the test programs provided with the distribution.) <P>
+the test programs provided with the distribution.)
<LI>Try to reproduce the bug on a different terminal type. <P>
If you have xterm available, it is also good to collect xterm reports for
different window sizes. This is especially true if you normally use an
unusual xterm window size -- a surprising number of the bugs we've seen
-are either triggered or masked by these. <P>
+are either triggered or masked by these.
<LI>Generate and examine a trace file for the broken behavior. <P>
Often you'll find terminfo problems at this stage by noticing that the
escape sequences put out for various capabilities are wrong. If not,
you're likely to learn enough to be able to characterize any bug in
-the screen-update logic quite exactly. <P>
+the screen-update logic quite exactly.
<LI>Report details and symptoms, not just interpretations. <P>
There's one other interactive tester, <CODE>tctest</CODE>, that exercises
translation between termcap and terminfo formats. If you have a serious
-need to run this, you probably belong on our development team! <P>
+need to run this, you probably belong on our development team!
<H1><A NAME="ncurslib">A Tour of the Ncurses Library</A></H1>
reorganization in the underlying data structures. <P>
These files are used only for debugging support:
-<blockquote><code>
+<blockquote>
+<code>
lib_trace.c
lib_traceatr.c
lib_tracebits.c
lib_tracedmp.c
lib_tracemse.c
trace_buf.c
-</blockquote></code>
+</code>
+</blockquote>
It is rather unlikely you will ever need to change these, unless
you want to introduce a new debug trace level for some reasoon.<P>
computations on the terminal capabilities, or queries to the OS
environment, but nevertheless have only fairly low complexity. These
include:
-<blockquote><code>
+<blockquote>
+<code>
lib_acs.c
lib_beep.c
lib_color.c
lib_tputs.c
lib_vidattr.c
read_entry.c.
-</blockquote></code>
+</code>
+</blockquote>
They are likely to need revision only if
ncurses is being ported to an environment without an underlying
terminfo capability representation. <P>
These files
have serious hooks into
the tty driver and signal facilities:
-<blockquote><code>
+<blockquote>
+<code>
lib_kernel.c
lib_baudrate.c
lib_raw.c
lib_tstp.c
lib_twait.c
-</blockquote></code>
+</code>
+</blockquote>
If you run into porting snafus
moving the package to another UNIX, the problem is likely to be in one
of these files.
falls in this category.<P>
Almost all of the real work is done in the files
-<blockquote><code>
+<blockquote>
+<code>
hardscroll.c
hashmap.c
lib_addch.c
lib_refresh.c
lib_setup.c
lib_vidattr.c
-</blockquote></code>
+</code>
+</blockquote>
Most of the algorithmic complexity in the
library lives in these files.
If there is a real bug in <STRONG>ncurses</STRONG> itself, it's probably here.
Finally, there is a group of files that is actually most of the
terminfo compiler. The reason this code lives in the <STRONG>ncurses</STRONG>
library is to support fallback to /etc/termcap. These files include
-<blockquote><code>
+<blockquote>
+<code>
alloc_entry.c
captoinfo.c
comp_captab.c
parse_entry.c
read_termcap.c
write_entry.c
-</blockquote></code>
-We'll discuss these in the compiler tour. <P>
+</code>
+</blockquote>
+We'll discuss these in the compiler tour.
<H2><A NAME="engine">The Engine Room</A></H2>
calls may find the code in <CODE>lib_twait.c</CODE> interesting. It deals
with the problem that some BSD selects don't return a reliable
time-left value. The function <CODE>timed_wait()</CODE> effectively
-simulates a System V select. <P>
+simulates a System V select.
<H3><A NAME="mouse">Mouse Events</A></H3>
In either case, <CODE>_nc_mouse_parse()</CODE> should be called after the
series is accepted to parse the digested mouse reports (low-level
-events) into a gesture (a high-level or composite event). <P>
+events) into a gesture (a high-level or composite event).
<H3><A NAME="output">Output and Screen Updating</A></H3>
In the trace-enabled version of the library, it is also possible to disable
and re-enable various optimizations at runtime by tweaking the variable
<CODE>_nc_optimize_enable</CODE>. See the file <CODE>include/curses.h.in</CODE>
-for mask values, near the end. <P>
+for mask values, near the end.
<H1><A NAME="fmnote">The Forms and Menu Libraries</A></H1>
Historical note: the panels code was written primarily to assist in
porting u386mon 2.0 (comp.sources.misc v14i001-4) to systems lacking
panels support; u386mon 2.10 and beyond use it. This version has been
-slightly cleaned up for <CODE>ncurses</CODE>. <P>
+slightly cleaned up for <CODE>ncurses</CODE>.
<H1><A NAME="tic">A Tour of the Terminfo Compiler</A></H1>
mode (termcap or terminfo) based on the first `,' or `:' it finds in
each entry. The lexer does all the work of recognizing capability
names and values; the grammar above it is trivial, just "parse entries
-till you run out of file". <P>
+till you run out of file".
<H2><A NAME="nonuse">Translation of Non-<STRONG>use</STRONG> Capabilities</A></H2>
Thus, adding a new capability is usually pretty trivial, just a matter
of adding one line to the <CODE>include/Caps</CODE> file. We'll have more
to say about this in the section on <A HREF="#translation">Source-Form
-Translation</A>. <P>
+Translation</A>.
<H2><A NAME="uses">Use Capability Resolution</A></H2>
postdates the time of <STRONG>tic</STRONG>'s first call to
<CODE>write_entry()</CODE>, Thus it will complain about overwriting
entries newly made during the <STRONG>tic</STRONG> run, but not about
-overwriting ones that predate it. <P>
+overwriting ones that predate it.
<H2><A NAME="translation">Source-Form Translation</A></H2>
are functions in <CODE>parse_entry.c</CODE> called after the parse of each
entry that are specifically intended to encapsulate such
translations. This, for example, is where the AIX <STRONG>box1</STRONG> capability
-get translated to an <STRONG>acsc</STRONG> string.<P>
+get translated to an <STRONG>acsc</STRONG> string.
<H1><A NAME="utils">Other Utilities</A></H1>
the ordinary De-compilation case and entry difference reporting. <P>
The <STRONG>tput</STRONG> and <STRONG>clear</STRONG> utilities just do an entry load
-followed by a <CODE>tputs()</CODE> of a selected capability. <P>
+followed by a <CODE>tputs()</CODE> of a selected capability.
<H1><A NAME="style">Style Tips for Developers</A></H1>
preferable to ad-hoc code -- that's why the fifth field (flags) is
there. <P>
-Have fun! <P>
+Have fun!
<H1><A NAME="port">Porting Hints</A></H1>
calls (not including <CODE>tputs()</CODE> and <CODE>putp()</CODE>) and do not
call any other UNIX routines such as signal(2) or the stdio library.
Thus, they should not need to be modified for single-terminal
-ports. <P>
+ports.
-<blockquote><code>
+<blockquote>
+<code>
lib_addch.c
lib_addstr.c
lib_bkgd.c
lib_unctrl.c
lib_window.c
panel.c
-</blockquote></code>
+</code>
+</blockquote>
<P>
-This module is pure curses, but calls outstr(): <P>
+This module is pure curses, but calls outstr():
-<blockquote><code>
+<blockquote>
+<code>
lib_getstr.c
-</blockquote></code>
+</code>
+</blockquote>
<P>
These modules are pure curses, except that they use <CODE>tputs()</CODE>
-and <CODE>putp()</CODE>: <P>
+and <CODE>putp()</CODE>:
-<blockquote><code>
+<blockquote>
+<code>
lib_beep.c
lib_color.c
lib_endwin.c
lib_options.c
lib_slk.c
lib_vidattr.c
-</blockquote></code>
+</code>
+</blockquote>
<P>
-This modules assist in POSIX emulation on non-POSIX systems: <P>
+This modules assist in POSIX emulation on non-POSIX systems:
<DL>
<DT> sigaction.c
<DD> signal calls
</DL>
The following source files will not be needed for a
-single-terminal-type port. <P>
+single-terminal-type port.
-<blockquote><code>
+<blockquote>
+<code>
alloc_entry.c
captoinfo.c
clear.c
read_entry.c
tput.c
write_entry.c
-</blockquote></code>
+</code>
+</blockquote>
<P>
The following modules will use open()/read()/write()/close()/lseek() on files,
-but no other OS calls. <P>
+but no other OS calls.
<DL>
<DT>lib_screen.c
Modules that would have to be modified for a port start here: <P>
The following modules are `pure curses' but contain assumptions inappropriate
-for a memory-mapped port. <P>
+for a memory-mapped port.
<dl>
<dt>lib_longname.c<dd>assumes there may be multiple terminals