hackguide.doc 32 KB

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