]> ncurses.scripts.mit.edu Git - ncurses.git/blob - misc/hackguide.doc
ncurses 4.2
[ncurses.git] / misc / hackguide.doc
1
2                           A Hacker's Guide to NCURSES
3                                        
4                                    Contents
5                                        
6      * Abstract
7      * Objective of the Package
8           + Why System V Curses?
9           + How to Design Extensions
10      * Portability and Configuration
11           + If autoconf Fails
12      * Documentation Conventions
13      * How to Report Bugs
14      * A Tour of the Ncurses Library
15           + Library Overview
16           + The Engine Room
17           + Keyboard Input
18           + Mouse Events
19           + Output and Screen Updating
20      * The Forms and Menu Libraries
21      * A Tour of the Terminfo Compiler
22           + Translation of Non-use Capabilities
23           + Use Capability Resolution
24           + Source-Form Translation
25      * Other Utilities
26      * Style Tips for Developers
27      * Porting Hints
28        
29                                    Abstract
30                                        
31    This document is a hacker's tour of the ncurses library and utilities.
32    It discusses design philosophy, implementation methods, and the
33    conventions used for coding and documentation. It is recommended
34    reading for anyone who is interested in porting, extending or
35    improving the package.
36    
37                            Objective of the Package
38                                        
39    The objective of the ncurses package is to provide a freeware API for
40    character-cell terminals and terminal emulators with the following
41    characteristics:
42    
43      * Source-compatible with historical curses implementations
44        (including the original BSD curses and System V curses.
45      * Conformant with the XSI Curses standard issued as part of XPG4 by
46        X/Open.
47      * High-quality -- stable and reliable code, wide portability, good
48        packaging, superior documentation.
49      * Featureful -- should eliminate as much of the drudgery of C
50        interface programming as possible, freeing programmers to think at
51        a higher level of design.
52        
53    These objectives are in priority order. So, for example, source
54    compatibility with older version must trump featurefulness -- we
55    cannot add features if it means breaking the portion of the API
56    corresponding to historical curses versions.
57    
58 Why System V Curses?
59
60    We used System V curses as a model, reverse-engineering their API, in
61    order to fulfill the first two objectives.
62    
63    System V curses implementations can support BSD curses programs with
64    just a recompilation, so by capturing the System V API we also capture
65    BSD's.
66    
67    More importantly for the future, the XSI Curses standard issued by
68    X/Open is explicitly and closely modeled on System V. So conformance
69    with System V took us most of the way to base-level XSI conformance.
70    
71 How to Design Extensions
72
73    The third objective (standards conformance) requires that it be easy
74    to condition source code using ncurses so that the absence of
75    nonstandard extensions does not break the code.
76    
77    Accordingly, we have a policy of associating with each nonstandard
78    extension a feature macro, so that ncurses client code can use this
79    macro to condition in or out the code that requires the ncurses
80    extension.
81    
82    For example, there is a macro NCURSES_MOUSE_VERSION which XSI Curses
83    does not define, but which is defined in the ncurses library header.
84    You can use this to condition the calls to the mouse API calls.
85    
86                          Portability and Configuration
87                                        
88    Code written for ncurses may assume an ANSI-standard C compiler and
89    POSIX-compatible OS interface. It may also assume the presence of a
90    System-V-compatible select(2) call.
91    
92    We encourage (but do not require) developers to make the code friendly
93    to less-capable UNIX environments wherever possible.
94    
95    We encourage developers to support OS-specific optimizations and
96    methods not available under POSIX/ANSI, provided only that:
97    
98      * All such code is properly conditioned so the build process does
99        not attempt to compile it under a plain ANSI/POSIX environment.
100      * Adding such implementation methods does not introduce
101        incompatibilities in the ncurses API between platforms.
102        
103    We use GNU autoconf(1) as a tool to deal with portability issues. The
104    right way to leverage an OS-specific feature is to modify the autoconf
105    specification files (configure.in and aclocal.m4) to set up a new
106    feature macro, which you then use to condition your code.
107    
108 If autoconf Fails
109
110    The 'configure' script usually gets your system environment right
111    automatically. Here are some -D options you might need to compile with
112    if it fails:
113    
114    -DHAVE_UNISTD_H
115           if <unistd.h> is present
116           
117    -DHAVE_SIGACTION
118           if the sigaction function is present
119           
120    -DHAVE_USLEEP
121           if the usleep function is present
122           
123    -DSVR4_ACTION
124           if (e.g., svr4) you need _POSIX_SOURCE to have sigaction
125           
126    -DHAVE_TERMIOS_H
127           if you have <termios.h>
128           
129    -DHAVE_TERMIO_H
130           if you have <termio.h>; otherwise it uses <sgtty.h>
131           
132    -DBROKEN_TIOCGETWINSZ
133           on SVR4 and HPUX, the get window size ioctl is broken.
134           
135                            Documentation Conventions
136                                        
137    There are three kinds of documentation associated with this package.
138    Each has a different preferred format:
139    
140      * Package-internal files (README, INSTALL, TO-DO etc.)
141      * Manual pages.
142      * Everything else (i.e., narrative documentation).
143        
144    Our conventions are simple:
145    
146     1. Maintain package-internal files in plain text. The expected viewer
147        for them more(1) or an editor window; there's no point in
148        elaborate mark-up.
149     2. Mark up manual pages in the man macros. These have to be viewable
150        through traditional man(1) programs.
151     3. Write everything else in HTML.
152        
153    When in doubt, HTMLize a master and use lynx(1) to generate plain
154    ASCII (as we do for the announcement document).
155    
156    The reason for choosing HTML is that it's (a) well-adapted for on-line
157    browsing through viewers that are everywhere; (b) more easily readable
158    as plain text than most other mark-ups, if you don't have a viewer;
159    and (c) carries enough information that you can generate a
160    nice-looking printed version from it. Also, of course, it make
161    exporting things like the announcement document to WWW pretty trivial.
162    
163                               How to Report Bugs
164                                        
165    The reporting address for bugs is bug-ncurses@gnu.org. This is a
166    majordomo list; to join, write to ncurses-request@gnu.org with a
167    message containing the line:
168              subscribe <name>@<host.domain>
169
170    The ncurses code is maintained by a small group of volunteers. While
171    we try our best to fix bugs promptly, we simply don't have a lot of
172    hours to spend on elementary hand-holding. We rely on intelligent
173    cooperation from our users. If you think you have found a bug in
174    ncurses, there are some steps you can take before contacting us that
175    will help get the bug fixed quickly.
176    
177    In order to use our bug-fixing time efficiently, we put people who
178    show us they've taken these steps at the head of our queue. This means
179    that if you don't, you'll probably end up at the tail end and have to
180    wait a while.
181    
182     1. Develop a recipe to reproduce the bug.
183        Bugs we can reproduce are likely to be fixed very quickly, often
184        within days. The most effective single thing you can do to get a
185        quick fix is develop a way we can duplicate the bad behavior --
186        ideally, by giving us source for a small, portable test program
187        that breaks the library. (Even better is a keystroke recipe using
188        one of the test programs provided with the distribution.)
189     2. Try to reproduce the bug on a different terminal type.
190        In our experience, most of the behaviors people report as library
191        bugs are actually due to subtle problems in terminal descriptions.
192        This is especially likely to be true if you're using a traditional
193        asynchronous terminal or PC-based terminal emulator, rather than
194        xterm or a UNIX console entry.
195        It's therefore extremely helpful if you can tell us whether or not
196        your problem reproduces on other terminal types. Usually you'll
197        have both a console type and xterm available; please tell us
198        whether or not your bug reproduces on both.
199        If you have xterm available, it is also good to collect xterm
200        reports for different window sizes. This is especially true if you
201        normally use an unusual xterm window size -- a surprising number
202        of the bugs we've seen are either triggered or masked by these.
203     3. Generate and examine a trace file for the broken behavior.
204        Recompile your program with the debugging versions of the
205        libraries. Insert a trace() call with the argument set to
206        TRACE_UPDATE. (See "Writing Programs with NCURSES" for details on
207        trace levels.) Reproduce your bug, then look at the trace file to
208        see what the library was actually doing.
209        Another frequent cause of apparent bugs is application coding
210        errors that cause the wrong things to be put on the virtual
211        screen. Looking at the virtual-screen dumps in the trace file will
212        tell you immediately if this is happening, and save you from the
213        possible embarrassment of being told that the bug is in your code
214        and is your problem rather than ours.
215        If the virtual-screen dumps look correct but the bug persists,
216        it's possible to crank up the trace level to give more and more
217        information about the library's update actions and the control
218        sequences it issues to perform them. The test directory of the
219        distribution contains a tool for digesting these logs to make them
220        less tedious to wade through.
221        Often you'll find terminfo problems at this stage by noticing that
222        the escape sequences put out for various capabilities are wrong.
223        If not, you're likely to learn enough to be able to characterize
224        any bug in the screen-update logic quite exactly.
225     4. Report details and symptoms, not just interpretations.
226        If you do the preceding two steps, it is very likely that you'll
227        discover the nature of the problem yourself and be able to send us
228        a fix. This will create happy feelings all around and earn you
229        good karma for the first time you run into a bug you really can't
230        characterize and fix yourself.
231        If you're still stuck, at least you'll know what to tell us.
232        Remember, we need details. If you guess about what is safe to
233        leave out, you are too likely to be wrong.
234        If your bug produces a bad update, include a trace file. Try to
235        make the trace at the least voluminous level that pins down the
236        bug. Logs that have been through tracemunch are OK, it doesn't
237        throw away any information (actually they're better than
238        un-munched ones because they're easier to read).
239        If your bug produces a core-dump, please include a symbolic stack
240        trace generated by gdb(1) or your local equivalent.
241        Tell us about every terminal on which you've reproduced the bug --
242        and every terminal on which you can't. Ideally, sent us terminfo
243        sources for all of these (yours might differ from ours).
244        Include your ncurses version and your OS/machine type, of course!
245        You can find your ncurses version in the curses.h file.
246        
247    If your problem smells like a logic error or in cursor movement or
248    scrolling or a bad capability, there are a couple of tiny test frames
249    for the library algorithms in the progs directory that may help you
250    isolate it. These are not part of the normal build, but do have their
251    own make productions.
252    
253    The most important of these is mvcur, a test frame for the
254    cursor-movement optimization code. With this program, you can see
255    directly what control sequences will be emitted for any given cursor
256    movement or scroll/insert/delete operations. If you think you've got a
257    bad capability identified, you can disable it and test again. The
258    program is command-driven and has on-line help.
259    
260    If you think the vertical-scroll optimization is broken, or just want
261    to understand how it works better, build hashmap and read the header
262    comments of hardscroll.c and hashmap.c; then try it out. You can also
263    test the hardware-scrolling optimization separately with hardscroll.
264    
265    There's one other interactive tester, tctest, that exercises
266    translation between termcap and terminfo formats. If you have a
267    serious need to run this, you probably belong on our development team!
268    
269                          A Tour of the Ncurses Library
270                                        
271 Library Overview
272
273    Most of the library is superstructure -- fairly trivial convenience
274    interfaces to a small set of basic functions and data structures used
275    to manipulate the virtual screen (in particular, none of this code
276    does any I/O except through calls to more fundamental modules
277    described below). The files lib_addch.c, lib_bkgnd.c, lib_box.c,
278    lib_clear.c, lib_clrbot.c, lib_clreol.c, lib_data.c, lib_delch.c,
279    lib_delwin.c, lib_erase.c, lib_getstr.c, lib_inchstr.c, lib_insch.c,
280    lib_insdel.c, lib_insstr.c, lib_instr.c, lib_isendwin.c,
281    lib_keyname.c, lib_move.c, lib_mvwin.c, lib_overlay.c, lib_pad.c,
282    lib_printw.c, lib_scanw.c, lib_screen.c, lib_scroll.c, lib_scrreg.c,
283    lib_set_term.c, lib_slk.c, lib_touch.c, lib_unctrl.c, and lib_window.c
284    are all in this category. They are very unlikely to need change,
285    barring bugs or some fundamental reorganization in the underlying data
286    structures.
287    
288    The lib_trace.c, lib_traceatr.c, and lib_tracechr.c file are used only
289    for debugging support. It is rather unlikely you will ever need to
290    change these, unless you want to introduce a new debug trace level for
291    some reasoon.
292    
293    There is another group of files that do direct I/O via tputs(),
294    computations on the terminal capabilities, or queries to the OS
295    environment, but nevertheless have only fairly low complexity. These
296    include: lib_acs.c, lib_beep.c, lib_color.c, lib_endwin.c,
297    lib_initscr.c, lib_longname.c, lib_newterm.c, lib_options.c,
298    lib_termcap.c, lib_ti.c, lib_tparm.c, lib_tputs.c, lib_vidattr.c, and
299    read_entry.c. These are likely to need revision only if ncurses is
300    being ported to an environment without an underlying terminfo
301    capability representation.
302    
303    The files lib_kernel.c, lib_baudrate.c, lib_raw.c, lib_tstp.c, and
304    lib_twait.c have serious hooks into the tty driver and signal
305    facilities. If you run into porting snafus moving the package to
306    another UNIX, the problem is likely to be in one of these files. The
307    file lib_print.c uses sleep(2) and also falls in this category.
308    
309    Almost all of the real work is done in the files hashmap.c,
310    hardscroll.c, lib_addch.c, lib_doupdate.c, lib_mvcur.c, lib_getch.c,
311    lib_mouse.c, lib_refresh.c, and lib_setup.c. Most of the algorithmic
312    complexity in the library lives in these files. If there is a real bug
313    in ncurses itself, it's probably here. We'll tour some of these files
314    in detail below (see The Engine Room).
315    
316    Finally, there is a group of files that is actually most of the
317    terminfo compiler. The reason this code lives in the ncurses library
318    is to support fallback to /etc/termcap. These files include
319    alloc_entry.c, captoinfo.c, comp_captab.c, comp_error.c, comp_hash.c,
320    comp_parse.c, comp_scan.c, and parse_entry.c, read_termcap.c, and
321    write_entry.c. We'll discuss these in the compiler tour.
322    
323 The Engine Room
324
325   Keyboard Input
326   
327    All ncurses input funnels through the function wgetch(), defined in
328    lib_getch.c. This function is tricky; it has to poll for keyboard and
329    mouse events and do a running match of incoming input against the set
330    of defined special keys.
331    
332    The central data structure in this module is a FIFO queue, used to
333    match multiple-character input sequences against special-key
334    capabilities; also to implement pushback via ungetch().
335    
336    The wgetch() code distinguishes between function key sequences and the
337    same sequences typed manually by doing a timed wait after each input
338    character that could lead a function key sequence. If the entire
339    sequence takes less than 1 second, it is assumed to have been
340    generated by a function key press.
341    
342    Hackers bruised by previous encounters with variant select(2) calls
343    may find the code in lib_twait.c interesting. It deals with the
344    problem that some BSD selects don't return a reliable time-left value.
345    The function timed_wait() effectively simulates a System V select.
346    
347   Mouse Events
348   
349    If the mouse interface is active, wgetch() polls for mouse events each
350    call, before it goes to the keyboard for input. It is up to
351    lib_mouse.c how the polling is accomplished; it may vary for different
352    devices.
353    
354    Under xterm, however, mouse event notifications come in via the
355    keyboard input stream. They are recognized by having the kmous
356    capability as a prefix. This is kind of klugey, but trying to wire in
357    recognition of a mouse key prefix without going through the
358    function-key machinery would be just too painful, and this turns out
359    to imply having the prefix somewhere in the function-key capabilities
360    at terminal-type initialization.
361    
362    This kluge only works because kmous isn't actually used by any
363    historic terminal type or curses implementation we know of. Best guess
364    is it's a relic of some forgotten experiment in-house at Bell Labs
365    that didn't leave any traces in the publicly-distributed System V
366    terminfo files. If System V or XPG4 ever gets serious about using it
367    again, this kluge may have to change.
368    
369    Here are some more details about mouse event handling:
370    
371    The lib_mouse()code is logically split into a lower level that accepts
372    event reports in a device-dependent format and an upper level that
373    parses mouse gestures and filters events. The mediating data structure
374    is a circular queue of event structures.
375    
376    Functionally, the lower level's job is to pick up primitive events and
377    put them on the circular queue. This can happen in one of two ways:
378    either (a) _nc_mouse_event() detects a series of incoming mouse
379    reports and queues them, or (b) code in lib_getch.c detects the kmous
380    prefix in the keyboard input stream and calls _nc_mouse_inline to
381    queue up a series of adjacent mouse reports.
382    
383    In either case, _nc_mouse_parse() should be called after the series is
384    accepted to parse the digested mouse reports (low-level events) into a
385    gesture (a high-level or composite event).
386    
387   Output and Screen Updating
388   
389    With the single exception of character echoes during a wgetnstr() call
390    (which simulates cooked-mode line editing in an ncurses window), the
391    library normally does all its output at refresh time.
392    
393    The main job is to go from the current state of the screen (as
394    represented in the curscr window structure) to the desired new state
395    (as represented in the newscr window structure), while doing as little
396    I/O as possible.
397    
398    The brains of this operation are the modules hashmap.c, hardscroll.c
399    and lib_doupdate.c; the latter two use lib_mvcur.c. Essentially, what
400    happens looks like this:
401    
402    The hashmap.c module tries to detect vertical motion changes between
403    the real and virtual screens. This information is represented by the
404    oldindex members in the newscr structure. These are modified by
405    vertical-motion and clear operations, and both are re-initialized
406    after each update. To this change-journalling information, the hashmap
407    code adds deductions made using a modified Heckel algorithm on hash
408    values generated from the line contents.
409    
410    The hardscroll.c module computes an optimum set of scroll, insertion,
411    and deletion operations to make the indices match. It calls
412    _nc_mvcur_scrolln() in lib_mvcur.c to do those motions.
413    
414    Then lib_doupdate.c goes to work. Its job is to do line-by-line
415    transformations of curscr lines to newscr lines. Its main tool is the
416    routine mvcur() in lib_mvcur.c. This routine does cursor-movement
417    optimization, attempting to get from given screen location A to given
418    location B in the fewest output characters posible.
419    
420    If you want to work on screen optimizations, you should use the fact
421    that (in the trace-enabled version of the library) enabling the
422    TRACE_TIMES trace level causes a report to be emitted after each
423    screen update giving the elapsed time and a count of characters
424    emitted during the update. You can use this to tell when an update
425    optimization improves efficiency.
426    
427    In the trace-enabled version of the library, it is also possible to
428    disable and re-enable various optimizations at runtime by tweaking the
429    variable _nc_optimize_enable. See the file include/curses.h.in for
430    mask values, near the end.
431    
432                          The Forms and Menu Libraries
433                                        
434    The forms and menu libraries should work reliably in any environment
435    you can port ncurses to. The only portability issue anywhere in them
436    is what flavor of regular expressions the built-in form field type
437    TYPE_REGEXP will recognize.
438    
439    The configuration code prefers the POSIX regex facility, modeled on
440    System V's, but will settle for BSD regexps if the former isn't
441    available.
442    
443    Historical note: the panels code was written primarily to assist in
444    porting u386mon 2.0 (comp.sources.misc v14i001-4) to systems lacking
445    panels support; u386mon 2.10 and beyond use it. This version has been
446    slightly cleaned up for ncurses.
447    
448                         A Tour of the Terminfo Compiler
449                                        
450    The ncurses implementation of tic is rather complex internally; it has
451    to do a trying combination of missions. This starts with the fact
452    that, in addition to its normal duty of compiling terminfo sources
453    into loadable terminfo binaries, it has to be able to handle termcap
454    syntax and compile that too into terminfo entries.
455    
456    The implementation therefore starts with a table-driven, dual-mode
457    lexical analyzer (in comp_scan.c). The lexer chooses its mode (termcap
458    or terminfo) based on the first `,' or `:' it finds in each entry. The
459    lexer does all the work of recognizing capability names and values;
460    the grammar above it is trivial, just "parse entries till you run out
461    of file".
462    
463 Translation of Non-use Capabilities
464
465    Translation of most things besides use capabilities is pretty
466    straightforward. The lexical analyzer's tokenizer hands each
467    capability name to a hash function, which drives a table lookup. The
468    table entry yields an index which is used to look up the token type in
469    another table, and controls interpretation of the value.
470    
471    One possibly interesting aspect of the implementation is the way the
472    compiler tables are initialized. All the tables are generated by
473    various awk/sed/sh scripts from a master table include/Caps; these
474    scripts actually write C initializers which are linked to the
475    compiler. Furthermore, the hash table is generated in the same way, so
476    it doesn't have to be generated at compiler startup time (another
477    benefit of this organization is that the hash table can be in
478    shareable text space).
479    
480    Thus, adding a new capability is usually pretty trivial, just a matter
481    of adding one line to the include/Caps file. We'll have more to say
482    about this in the section on Source-Form Translation.
483    
484 Use Capability Resolution
485
486    The background problem that makes tic tricky isn't the capability
487    translation itself, it's the resolution of use capabilities. Older
488    versions would not handle forward use references for this reason (that
489    is, a using terminal always had to follow its use target in the source
490    file). By doing this, they got away with a simple implementation
491    tactic; compile everything as it blows by, then resolve uses from
492    compiled entries.
493    
494    This won't do for ncurses. The problem is that that the whole
495    compilation process has to be embeddable in the ncurses library so
496    that it can be called by the startup code to translate termcap entries
497    on the fly. The embedded version can't go promiscuously writing
498    everything it translates out to disk -- for one thing, it will
499    typically be running with non-root permissions.
500    
501    So our tic is designed to parse an entire terminfo file into a
502    doubly-linked circular list of entry structures in-core, and then do
503    use resolution in-memory before writing everything out. This design
504    has other advantages: it makes forward and back use-references equally
505    easy (so we get the latter for free), and it makes checking for name
506    collisions before they're written out easy to do.
507    
508    And this is exactly how the embedded version works. But the
509    stand-alone user-accessible version of tic partly reverts to the
510    historical strategy; it writes to disk (not keeping in core) any entry
511    with no use references.
512    
513    This is strictly a core-economy kluge, implemented because the
514    terminfo master file is large enough that some core-poor systems swap
515    like crazy when you compile it all in memory...there have been reports
516    of this process taking three hours, rather than the twenty seconds or
517    less typical on the author's development box.
518    
519    So. The executable tic passes the entry-parser a hook that immediately
520    writes out the referenced entry if it has no use capabilities. The
521    compiler main loop refrains from adding the entry to the in-core list
522    when this hook fires. If some other entry later needs to reference an
523    entry that got written immediately, that's OK; the resolution code
524    will fetch it off disk when it can't find it in core.
525    
526    Name collisions will still be detected, just not as cleanly. The
527    write_entry() code complains before overwriting an entry that
528    postdates the time of tic's first call to write_entry(), Thus it will
529    complain about overwriting entries newly made during the tic run, but
530    not about overwriting ones that predate it.
531    
532 Source-Form Translation
533
534    Another use of tic is to do source translation between various termcap
535    and terminfo formats. There are more variants out there than you might
536    think; the ones we know about are described in the captoinfo(1) manual
537    page.
538    
539    The translation output code (dump_entry() in ncurses/dump_entry.c) is
540    shared with the infocmp(1) utility. It takes the same internal
541    representation used to generate the binary form and dumps it to
542    standard output in a specified format.
543    
544    The include/Caps file has a header comment describing ways you can
545    specify source translations for nonstandard capabilities just by
546    altering the master table. It's possible to set up capability aliasing
547    or tell the compiler to plain ignore a given capability without
548    writing any C code at all.
549    
550    For circumstances where you need to do algorithmic translation, there
551    are functions in parse_entry.c called after the parse of each entry
552    that are specifically intended to encapsulate such translations. This,
553    for example, is where the AIX box1 capability get translated to an
554    acsc string.
555    
556                                 Other Utilities
557                                        
558    The infocmp utility is just a wrapper around the same entry-dumping
559    code used by tic for source translation. Perhaps the one interesting
560    aspect of the code is the use of a predicate function passed in to
561    dump_entry() to control which capabilities are dumped. This is
562    necessary in order to handle both the ordinary De-compilation case and
563    entry difference reporting.
564    
565    The tput and clear utilities just do an entry load followed by a
566    tputs() of a selected capability.
567    
568                            Style Tips for Developers
569                                        
570    See the TO-DO file in the top-level directory of the source
571    distribution for additions that would be particularly useful.
572    
573    The prefix _nc_ should be used on library public functions that are
574    not part of the curses API in order to prevent pollution of the
575    application namespace. If you have to add to or modify the function
576    prototypes in curses.h.in, read ncurses/MKlib_gen.sh first so you can
577    avoid breaking XSI conformance. Please join the ncurses mailing list.
578    See the INSTALL file in the top level of the distribution for details
579    on the list.
580    
581    Look for the string FIXME in source files to tag minor bugs and
582    potential problems that could use fixing.
583    
584    Don't try to auto-detect OS features in the main body of the C code.
585    That's the job of the configuration system.
586    
587    To hold down complexity, do make your code data-driven. Especially, if
588    you can drive logic from a table filtered out of include/Caps, do it.
589    If you find you need to augment the data in that file in order to
590    generate the proper table, that's still preferable to ad-hoc code --
591    that's why the fifth field (flags) is there.
592    
593    Have fun!
594    
595                                  Porting Hints
596                                        
597    The following notes are intended to be a first step towards DOS and
598    Macintosh ports of the ncurses libraries.
599    
600    The following library modules are `pure curses'; they operate only on
601    the curses internal structures, do all output through other curses
602    calls (not including tputs() and putp()) and do not call any other
603    UNIX routines such as signal(2) or the stdio library. Thus, they
604    should not need to be modified for single-terminal ports.
605    
606    lib_addch.c lib_addstr.c lib_bkgd.c lib_box.c lib_clear.c lib_clrbot.c
607    lib_clreol.c lib_delch.c lib_delwin.c lib_erase.c lib_inchstr.c
608    lib_insch.c lib_insdel.c lib_insstr.c lib_keyname.c lib_move.c
609    lib_mvwin.c lib_newwin.c lib_overlay.c lib_pad.c lib_printw.c
610    lib_refresh.c lib_scanw.c lib_scroll.c lib_scrreg.c lib_set_term.c
611    lib_touch.c lib_tparm.c lib_tputs.c lib_unctrl.c lib_window.c panel.c
612    
613    This module is pure curses, but calls outstr():
614    
615    lib_getstr.c
616    
617    These modules are pure curses, except that they use tputs() and
618    putp():
619    
620    lib_beep.c lib_endwin.c lib_color.c lib_options.c lib_slk.c
621    lib_vidattr.c
622    
623    This modules assist in POSIX emulation on non-POSIX systems:
624    
625    sigaction.c
626           signal calls
627           
628    The following source files will not be needed for a
629    single-terminal-type port.
630    
631    captoinfo.c clear.c comp_captab.c comp_error.c comp_hash.c comp_main.c
632    comp_parse.c comp_scan.c alloc_entry.c dump_entry.c parse_entry.c
633    read_entry.c write_entry.c infocmp.c tput.c
634    
635    The following modules will use open()/read()/write()/close()/lseek()
636    on files, but no other OS calls.
637    
638    lib_screen.c
639           used to read/write screen dumps
640           
641    lib_trace.c
642           used to write trace data to the logfile
643           
644    Modules that would have to be modified for a port start here:
645    
646    The following modules are `pure curses' but contain assumptions
647    inappropriate for a memory-mapped port.
648    
649 lib_longname.c  -- assumes there may be multiple terminals
650         longname()              -- return long name of terminal
651 lib_acs.c       -- assumes acs_map as a double indirection
652         init_acs()              -- initialize acs map
653 lib_mvcur.c     -- assumes cursor moves have variable cost
654         mvcur_init()            -- initialize
655         mvcur()                 -- do physical cursor move
656         mvcur_wrap()            -- wrap
657         scrolln()               -- do physical scrolling
658 lib_termcap.c   -- assumes there may be multiple terminals
659         tgetent()               -- load entry
660         tgetflag()              -- get boolean capability
661         tgetnum()               -- get numeric capability
662         tgetstr()               -- get string capability
663 lib_ti.c        -- assumes there may be multiple terminals
664         tigetent()              -- load entry
665         tigetflag()             -- get boolean capability
666         tigetnum()              -- get numeric capability
667         tigetstr()              -- get string capability
668
669 The following modules use UNIX-specific calls:
670
671 lib_doupdate.c  -- input checking
672         doupdate()              -- repaint real screen to match virtual
673         _nc_outch()             -- put out a single character
674 lib_getch.c     -- read()
675         wgetch()                -- get single character
676         wungetch()              -- push back single character
677 lib_initscr.c   -- getenv()
678         initscr()               -- initialize curses functions
679 lib_newterm.c
680         newterm()               -- set up new terminal screen
681 lib_baudrate.c
682         baudrate()              -- return the baudrate
683 lib_kernel.c    -- various tty-manipulation and system calls
684         reset_prog_mode()       -- reset ccurses-raw mode
685         reset_shell_mode()      -- reset cooked mode
686         erasechar()             -- return the erase char
687         killchar()              -- return the kill character
688         flushinp()              -- flush pending input
689         savetty()               -- save tty state
690         resetty()               -- reset tty to state at last savetty()
691 lib_raw.c       -- various tty-manipulation calls
692         raw()
693         echo()
694         nl()
695         qiflush()
696         cbreak()
697         noraw()
698         noecho()
699         nonl()
700         noqiflush()
701         nocbreak()
702 lib_setup.c     -- various tty-manipulation calls
703         use_env()
704         setupterm()
705 lib_restart.c   -- various tty-manipulation calls
706         def_shell_mode()
707         def_prog_mode()
708         set_curterm()
709         del_curterm()
710 lib_tstp.c      -- signal-manipulation calls
711         _nc_signal_handler()    -- enable/disable window-mode signal catching
712 lib_twait.c     -- gettimeofday(), select().
713         usleep()                -- microsecond sleep
714         _nc_timed_wait()        -- timed wait for input
715
716    The package kernel could be made smaller.
717      _________________________________________________________________
718    
719    
720     Eric S. Raymond <esr@snark.thyrsus.com>
721     
722    (Note: This is not the bug address!)