home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume1 / pcurses / part01 next >
Encoding:
Internet Message Format  |  1986-11-30  |  39.9 KB

  1. Subject:  Terminfo/Curses Part 1 of 11
  2.  
  3. : Run this shell script with "sh" not "csh"
  4. PATH=:/bin:/usr/bin:/usr/ucb
  5. export PATH
  6. if test ! -d =doc
  7. then
  8.     echo 'Making directory "=doc"'
  9.     mkdir =doc
  10. fi
  11. echo 'x - =doc/Installation'
  12. sed 's/^X//' <<'//go.sysin dd *' >=doc/Installation
  13. How to install Curses/Terminfo on your system (Beta-one test release)
  14. ---------------------------------------------------------------------
  15.  
  16. Assumptions: You have unpacked the tar-file into an empty directory.
  17. You found this file in a subdirectory of that one called '=doc'.
  18. There are three other subdirectories, called '=src', '=test', and '=data'.
  19.  
  20. [ Actually, if you recieved this file as part of the mod.sources
  21.   distribution, you got this distribution as eleven shar format archive
  22.   files, which (when passed through "sh" to unbundle them) create the
  23.   exact same source heirarchy              - John Nelson (mod.sources)]
  24.  
  25. If any of these assumptions is false, I make no claims for the
  26. correctness of the following instructions.
  27.  
  28. 1.  Decide where you want to put the object files and source files
  29.     of terminal descriptions.  On our system (and I recommend it for
  30.     you), the directory /etc/term is used.  If you really can't stand
  31.     the idea (remember, this is not where the C language source code
  32.     to the library will go; this is where the actual terminal
  33.     descriptions and their object files will go), you'll need to do
  34.     these steps (skip these if you're being reasonable or lazy):
  35.     a. Keep in mind that this directory should probably be
  36.        in your root filesystem so that programs which use terminfo
  37.        can be used even when the system is only up single-user.
  38.     b. Change the value of the variable SRCDIR in =src/Makefile
  39.        to the name of the directory you've chosen.
  40.     c. Change the man pages in =doc to reflect the name-change.
  41.  
  42. 2.  Copy everything in the subdirectory =data into the directory
  43.     chosen in step 1.
  44.  
  45. 3.  Change to the subdirectory =src and type 'make'.  Absolutely no
  46.     error-messages should be produced.  This should compile the library
  47.     (two versions, normal and debugging), the terminfo compiler and the
  48.     dump program. Then type 'make install' to copy the header files into
  49.     /usr/include, copy the compiler and dump programs into the directory
  50.     chosen in step 1, and copy the versions of the library into /usr/lib.
  51.     You will probably need to be super-user to do this.
  52.  
  53. 4.  Change to the directory chosen in step 1 and type 'make'.  This should
  54.     compile the database.  Again, no error-messages of any sort should be
  55.     produced.
  56.  
  57. 5.  Change to the subdirectory =test and type 'make'.  This should compile
  58.     all of the test programs in the release.  Once again, there should be
  59.     no errors.
  60.  
  61. 6.  You may want to install the test programs, make copies of the 
  62.     documentation, etc.
  63.  
  64. NOTES:
  65.     This release of terminfo/curses will not work on any PDP-11 UNIX
  66.     systems I know of because the Pre-processor to the C compiler
  67.     can't hack the number of #define's in term.h.  If you get this
  68.     up on an eleven, let me know.  Real systems hackers can probably
  69.     find a nice constant to change in their cpp code, but I hesitate
  70.     to try to tell you where to find it.
  71.  
  72.     The library is stored in /usr/lib/libncurses.a, unless you changed
  73.     the Makefile.  Note the 'n'!!  Programs wishing to use the new
  74.     package should say "-lncurses" on their 'cc' command while those
  75.     wanting the old package should still say '-lcurses'.
  76.  
  77.     Similarly, the curses header file should be included using
  78.             #include <ncurses.h>
  79.  
  80.     The header file <terminfo.h> has been included so that programs
  81.         which work only at the terminfo-level need not worry about name
  82.     conflicts with the rest of the package.  By including
  83.     <terminfo.h> instead of <ncurses.h>, they will get everything
  84.     needed for the terminfo-level routines.
  85.  
  86.     You, dear reader, are truly a guinea pig.  If there's anything
  87.     wrong with this package, these instructions, etc., you're
  88.     supposed to tell me about it.  I'm going to be very depressed if
  89.     I send this out and get no response at all.   So, save me the
  90.     agony of loneliness and write to me your impressions/complaints/
  91.     suggestions!
  92.  
  93.     [ actually, this is being posted two years after the original
  94.       distribution.  Most of the bugs should be out, but of course,
  95.       there are no guarantees        - John Nelson (mod.sources) ]
  96.  
  97.     Oh, yes.  Thank you.
  98.     
  99.             Pavel Curtis
  100.         Computer Science Dept.
  101.         405 Upson Hall
  102.         Cornell University
  103.         Ithaca, NY 14853
  104.         
  105.         Ph- (607) 256-4934
  106.         
  107.         decvax!cornell!pavel        (UUCP)
  108.         Pavel.Cornell@Udel-Relay    (ARPA)
  109. //go.sysin dd *
  110. echo 'x - =doc/changes.ms'
  111. sed 's/^X//' <<'//go.sysin dd *' >=doc/changes.ms
  112. X.po +.5i
  113. X.TL
  114. New Features in Curses and Terminfo
  115. X.AU
  116. Pavel Curtis
  117. X.NH
  118. Introduction
  119. X.PP
  120. This document describes new features that are being added to the
  121. Berkeley \fBcurses\fP subroutine package.
  122. It also describes the new \fBterminfo\fP database, which
  123. replaces the Berkeley \fBtermcap\fP database.  The emphasis is on the
  124. new features.
  125. X.NH
  126. New Features in Curses
  127. X.PP
  128. This section describes the enhancements to curses.  Briefly, the
  129. enhancements are:
  130. X.de Np
  131. X.IP \\n+(l%.
  132. X..
  133. X.nr l% 0 1
  134. X.af l% a
  135. X.Np
  136. Curses is smarter.  It can take advantage of insert/delete
  137. line/character.  (By default, it will not use insert/delete
  138. line.  See \fIidlok()\fR.)
  139. X.Np  
  140. Curses uses the new \fBterminfo\fP data base, as described in the
  141. next section.
  142. X.Np  
  143. Curses works on more terminals.
  144. X.Np  
  145. It is possible to use more than one terminal at a time.
  146. X.Np  
  147. Video attributes can be displayed in any combination.
  148. X.Np  
  149. Curses handles terminals with the ``magic cookie'' video
  150. attribute glitch.
  151. X.Np  
  152. The function and arrow keys on terminals can be input as
  153. though they were a single character.
  154. X.Np  
  155. There is a user accessible scrolling region, like the DEC
  156. VT100.
  157. X.Np  
  158. If the programmer restricts his code to a subset of the full
  159. curses, the \fBMINICURSES\fP version can be used, which is smaller
  160. and faster.
  161. X.Np  
  162. Two routines are provided for setting the tty bits to the
  163. proper state for shell escapes and control-Z suspensions.
  164. X.Np  
  165. On systems that support it (currently only 4.1BSD), if the
  166. user types something during an update, the update will stop,
  167. pending a future update.  This is useful when the user hits
  168. several keys, each of which causes a good deal of output.
  169. X.Np  
  170. The routine \fBgetstr()\fP is smarter - it handles the users erase
  171. and kill characters, and echos its input.
  172. X.Np  
  173. The function \fBlongname()\fP is now useful and actually works.
  174. X.Np  
  175. Nodelay mode allows ``real time'' programs to be written
  176. with the same interface on both systems.  Setting the flag
  177. causes \fBgetch\fP to return -1 if no input is waiting.
  178. X.Np  
  179. Several useful routines are provided to enhance portability.
  180. X.NH 2
  181. Curses is Smarter
  182. X.PP
  183. The algorithm used by curses has been replaced with an algorithm
  184. that takes into account insert and delete line and character
  185. functions, if available, in the terminal.  By default, curses
  186. will not use insert/delete line.  This was not done for
  187. performance reasons, since there is no speed penalty involved.  Rather,
  188. it was found that some programs do not need this facility, and
  189. that if curses uses insert/delete line, the result on the screen
  190. can be visually annoying.  Since most simple programs using
  191. curses do not need this, and since the old curses did not use it,
  192. the default is to avoid insert/delete line.  Call the routine
  193. X.DS
  194. \fBidlok(stdscr, TRUE);\fP
  195. X.DE
  196. to enable insert/delete line, if your application needs it.
  197. Insert/delete character is always considered.
  198. X.NH 2
  199. Additional Terminals
  200. X.PP
  201. Curses works on a larger class of terminals than the previous
  202. version.  Terminfo is able to address the cursor on more kinds of
  203. terminals.  Curses will work even if absolute cursor addressing
  204. is not possible, as long as the cursor can be moved from any
  205. location to any other location.  It considers local motions,
  206. parameterized motions, home, and carriage return.
  207. X.PP
  208. Curses is still aimed at full duplex, alphanumeric, video
  209. terminals.  No attempt is made to handle half-duplex, synchronous,
  210. hard copy, or bitmapped terminals.
  211. X.PP
  212. Curses handles terminals with the ``magic cookie glitch'' in
  213. their video attributes.\u*\d
  214. X.FS
  215. \u*\dThis feature is not supported in the current test release.  It will
  216. be implemented in the official distribution.
  217. X.FE
  218. This glitch means that a change in video
  219. attributes is implemented by storing a ``magic cookie'' in a
  220. location on the screen.  This ``cookie'' takes up a space,
  221. preventing an exact implementation of what the programmer wanted.
  222. Curses takes the extra space into account, and moves part of the
  223. line to the right, as necessary.  In some cases, this will
  224. unavoidably result in losing text from the right hand edge of the
  225. screen.  Existing spaces are taken advantage of.
  226. X.NH 2
  227. Multiple Terminals
  228. X.PP
  229. Some applications need to display text on more than one terminal,
  230. controlled by the same process.  Even if the terminals are
  231. different, the new curses can handle this.
  232. X.PP
  233. All information about the current terminal is kept in a global
  234. variable
  235. X.DS
  236. \fBstruct screen\fP *SP;
  237. X.DE
  238. Although the screen structure is hidden from the user, the C
  239. compiler will accept declarations of variables which are pointers.
  240. The user program should declare one screen pointer variable for
  241. each terminal it wishes to handle.  The routine
  242. X.DS
  243. \fBstruct screen *
  244. \fInewterm\fR(type, fd)
  245. \fBchar\fP *type;
  246. XFILE *fp;
  247. X.DE
  248. will set up a new terminal of the given terminal type which does
  249. output on file pointer fp.  A call to \fIinitscr()\fP is essentially
  250. \fInewterm\fP(\fIgetenv\fP(``TERM''), \fBstdout\fR).
  251. A program wishing to use more
  252. than one terminal should use \fInewterm()\fP for each terminal and save
  253. the value returned as a reference to that terminal.
  254. X.PP
  255. To switch to a different terminal, call
  256. X.DS
  257. \fBstruct screen\fP *
  258. \fIset_term\fP(term)
  259. \fBstruct screen\fP *term;
  260. X.DE
  261. The old value of SP will be returned.  You should not assign
  262. directly to SP because certain other global variables must also
  263. be changed.
  264. X.PP
  265. All curses routines always affect the current terminal.  To
  266. handle several terminals, switch to each one in turn with \fIset_term()\fP,
  267. and then access it.  Each terminal must be set up with \fInewterm()\fP,
  268. and closed down with \fIendwin()\fP.
  269. X.NH 2
  270. Video Attributes
  271. X.PP
  272. Video attributes can be displayed in any combination on terminals
  273. with this capability.  They are treated as an extension of the
  274. standout capability, which is still present.
  275. X.PP
  276. Each character position on the screen has 16 bits of information
  277. associated with it.  7 of these bits are the character to be
  278. displayed, leaving separate bits for 9 video attributes.  These
  279. bits are used for standout, underline, reverse video, blink, dim,
  280. bold, blank, protect, and alternate character set.  Standout is
  281. taken to be whatever highlighting works best on the terminal, and
  282. should be used by any program that does not need specific or
  283. combined attributes.  Underlining, reverse video, blink, dim, and
  284. bold are the usual video attributes.  Blank means that the
  285. character is displayed as a space, for security reasons.  Protected
  286. and alternate character set are dependent on the particular
  287. terminal.  The use of these last three bits is subject to change and
  288. not recommended.
  289. X.PP
  290. The routines to use these attributes include
  291. X.DS
  292. X.ta 2i
  293. \fIattrset\fP(attrs)    \fIwattrset\fP(attrs)
  294. \fIattron\fP(attrs)    \fIwattron\fP(attrs)
  295. \fIattroff\fP(attrs)    \fIwattroff\fP(attrs)
  296. \fIstandout\fP()    \fIwstandout\fP()
  297. \fIstandend\fP()    \fIwstandend\fP()
  298. X.DE
  299. X.PP
  300. Attributes, if given, can be any combination of A_STANDOUT,
  301. A_UNDERLINE, A_REVERSE, A_BLINK, A_DIM, A_BOLD, A_INVIS,
  302. A_PROTECT, and A_ALTCHARSET.  These constants, defined in
  303. curses.h, can be combined with the C | (or) operator to get
  304. multiple attributes.  \fIAttrset()\fP sets the current attributes to the
  305. given \fIattr\fP; \fIattron()\fP turns on the given \fIattrs\fP in addition to any
  306. attributes that are already on; \fIattroff()\fP turns off the given
  307. attributes, without affecting any others.  \fIstandout()\fP and \fIstandend()\fP
  308. are equivalent to \fIattron\fP(A_STANDOUT) and \fIattroff\fP(A_STANDOUT).
  309. X.PP
  310. Since standout is stored in the 8th bit of the text byte, it is
  311. possible to recompile curses so that only 8 bits are stored for
  312. each character, making a smaller curses, and still be able to use
  313. standout.  Also, programs that restrict themselves to the
  314. routines \fIstandout()\fP and \fIstandend()\fP will work with both
  315. the new and old curses.
  316. X.PP
  317. If the particular terminal does not have the particular attribute
  318. or combination requested, curses will attempt to use some other
  319. attribute in its place.  If the terminal has no highlighting at
  320. all, all attributes will be ignored.
  321. X.NH 2
  322. XFunction Keys
  323. X.PP
  324. Many terminals have special keys, such as arrow keys, keys to
  325. erase the screen, insert or delete text, and keys intended for
  326. user functions.  The particular sequences these terminals send
  327. differs from terminal to terminal.  Curses allows the programmer
  328. to handle these keys.
  329. X.PP
  330. A program using function keys should turn on the keypad by
  331. calling
  332. X.DS
  333. \fIkeypad\fP(\fBstdscr\fP, TRUE)
  334. X.DE
  335. at initialization.  This will cause special characters to be
  336. passed through to the program by the function \fIgetch()\fP.  These keys
  337. have constants which are defined in curses.h.  They have values
  338. starting at 0401, so they should not be stored in a \fBchar\fP
  339. variable, as significant bits will be lost.
  340. X.PP
  341. A program using function keys should avoid using the \s-2ESCAPE\s0 key,
  342. since most sequences start with escape, creating an ambiguity.
  343. Curses will set a one second alarm to deal with this ambiguity,
  344. which will cause delayed response to the escape key.  It is a
  345. good idea to avoid escape in any case, since there is eventually
  346. pressure for nearly \fIany\fP screen oriented program to accept arrow
  347. key input.
  348. X.NH 2
  349. Scrolling Region
  350. X.PP
  351. There is a user accessible scrolling region, like the DEC VT100.
  352. Normally, it is set to the entire window, but the calls
  353. X.DS
  354. \fIsetscrreg\fP(top, bot)
  355. \fIwsetscrreg\fP(win, top, bot)
  356. X.DE
  357. set the scrolling region for \fBstdscr\fP or the given window to any
  358. combination of top and bottom margins.  If scrolling has been
  359. enabled with \fIscrollok\fP, scrolling will take place only within that
  360. window.  See the \fICurses Reference Manual\fP for the detailed semantics
  361. of this construct.
  362. X.NH 2
  363. Mini-Curses\u*\d
  364. X.FS
  365. \u*\dThis feature is not supported in the current test release.  It will
  366. be implemented in the official distribution.
  367. X.FE
  368. X.PP
  369. The new curses is bigger than the old one, and has to copy from
  370. the current window to an internal screen image for every call to
  371. \fIrefresh()\fP.  If the programmer is only interested in screen output
  372. optimization, and does not want the windowing or input functions,
  373. an interface to the lower level routines is available.  This will
  374. make the program somewhat smaller and faster.  The interface is a
  375. subset of full curses, so that conversion between the levels is
  376. not necessary to switch from mini-curses to full curses.
  377. X.PP
  378. The subset mainly requires you to avoid use of more than the one
  379. window \fBstdscr\fP.  Thus, all functions beginning with ``w'' are
  380. generally undefined.  Certain high level functions that are
  381. convenient but not essential are also not available, including
  382. \fIprintw()\fP and \fIscanw()\fP  Also, the input routine \fIgetch()\fP
  383. cannot be used
  384. with mini-curses.  Features implemented at a low level, such as
  385. use of hardware insert/delete line and video attributes, are
  386. available in both versions.  Also, mode setting routines such as
  387. \fIcbreak()\fP and \fInoecho()\fP are allowed.
  388. See the manual page for the exact
  389. list of routines allowed with mini-curses.
  390. X.PP
  391. To access mini-curses, add \fB-DMINICURSES\fP to the CFLAGS in your
  392. makefile.  If you ask for routines that are not in the subset,
  393. the loader will print error messages such as
  394. X.DS
  395. Undefined:
  396. no_getch
  397. no_waddch
  398. X.DE
  399. to tell you that the routines \fIgetch()\fP and \fIwaddch()\fP were used but are
  400. not available in the subset.  Since the preprocessor is involved
  401. in the implementation of mini-curses, you must recompile the
  402. entire program if you change from one version to the other.
  403. Similarly, programs compiled with the old curses must be
  404. recompiled for the new curses.
  405. X.NH 2
  406. TTY Mode Functions
  407. X.PP
  408. In addition to the save/restore routines \fIsavetty()\fP and \fIresetty()\fP,
  409. standard routines are available for going into and out of normal
  410. tty mode.  These routines are \fIresetterm()\fP, which puts the
  411. terminal back in the mode it was in when curses was started, and \fIfixterm()\fP,
  412. which undoes the effects of \fIresetterm()\fP, that is, restores
  413. the ``current curses mode''.  \fIendwin()\fP automatically calls
  414. \fIresetterm()\fP, and the routine to handle control-Z (on 4.1BSD systems with
  415. process control) also uses \fIresetterm()\fP and \fIfixterm()\fP.  The programmer
  416. should use these routines before and after shell escapes, and
  417. also if he writes his own routine to handle control-Z.  These
  418. routines are also available at the \fIterminfo\fP level.
  419. X.NH 2
  420. Typeahead Check\u*\d
  421. X.FS
  422. \u*\dThis feature is not supported in the current test release.  It will
  423. be implemented in the official distribution.
  424. X.FE
  425. X.PP
  426. On systems that support it (current only 4.1BSD), if the user
  427. types something during an update, the update will stop, pending a
  428. future update.  This is useful when the user rapidly hits several
  429. keys, each of which causes a good deal of output.  This feature
  430. is automatic and cannot be disabled.
  431. X.NH 2
  432. Getstr()
  433. X.PP
  434. The routine \fIgetstr()\fP is smarter.  The semantics are slightly
  435. different from the old \fIgetstr()\fP, but no incompatibilities are
  436. anticipated.  No matter what the setting of \fIecho\fP is, strings typed in
  437. here are echoed at the current cursor location.  The users erase
  438. and kill characters are understood and handled.  This makes it
  439. unnecessary for an interactive program to deal with erase, kill,
  440. and echoing when the user is typing a line of text.
  441. X.NH 2
  442. Longname()
  443. X.PP
  444. The function \fIlongname()\fP is now useful and actually works.  The
  445. previous version required the programmer to call \fItgetent()\fP directly
  446. and pass the resulting string, along with a buffer, to \fIlongname()\fP.
  447. The string actually returned was the second alias for the
  448. terminal, not the long name.
  449. X.PP
  450. The new \fIlongname()\fP function does not take any arguments.  It
  451. returns a pointer to a static area containing the actual long
  452. name of the terminal.  No call to \fItgetent()\fP is needed, in fact,
  453. that routine no longer exists.
  454. X.NH 2
  455. Nodelay Mode
  456. X.PP
  457. The call
  458. X.DS
  459. \fInodelay\fP(\fBstdscr\fP, TRUE)
  460. X.DE
  461. will put the terminal in ``nodelay mode''.  While in this mode,
  462. any call to \fIgetch()\fP will return -1 if there is nothing waiting to
  463. be read immediately.  This is useful for writing programs
  464. requiring ``real time'' behavior where the user watches action on the
  465. screen and presses a key when he wants something to happen.  For
  466. example, the cursor can be moving across the screen, and the user
  467. can press an arrow key to change direction.  This mode is
  468. especially useful for games such as PacMan and Space Invaders.
  469. X.NH 2
  470. Portability
  471. X.PP
  472. Several useful routines are provided to enhance portability.
  473. While these routines do not directly relate to terminal handling,
  474. their implementation is different from system to system, and the
  475. differences can be isolated from the user program by including
  476. them in curses.
  477. X.PP
  478. XFunctions \fIerasechar()\fP and \fIkillchar()\fP return the characters which
  479. erase one character, and kill the entire input line,
  480. respectively.  The function \fIbaudrate()\fP will return the current baud
  481. rate, as an integer.  (For example, at 9600 baud, the integer
  482. 9600 will be returned, not the value B9600 from <sgtty.h>.) The
  483. routine \fIflushinp()\fP will cause all typeahead to be thrown away.
  484. X.NH 2
  485. XFeatures No Longer Supported
  486. X.PP
  487. In general, an effort has been made to support old features where
  488. possible.  However, there are some features of the old curses
  489. that cannot be supported, due to the change to terminfo, or due
  490. to other miscelaneous causes.
  491. X.PP
  492. The old curses defined a number of two letter variables, such as
  493. CM, containing termcap capabilities.  These variables are no
  494. longer accessible to the user.  In general, their semantics are
  495. different, as are their names.  A program using primarily these
  496. variables is really written at the termcap level.  Also
  497. unavailable are the related variables NONL, GT, and UPPERCASE.
  498. X.PP
  499. Such programs should be recoded to avoid these capabilities, if
  500. at all possible, instead using the higher level curses functions.
  501. If this is not possible, recode at the terminfo level.  A program
  502. making only light use can probably be easily changed to avoid
  503. these variables completely.  A program at the terminfo level that
  504. only needs motion optimization should probably still be recoded
  505. to use the high level routines, in order to work on more
  506. terminals.  If this is not possible, recode at the terminfo level,
  507. continuing to use \fImvcur()\fP, which is still supported.  It is not
  508. necessary to call \fImvcur()\fP to move to the lower left corner of the
  509. screen before calling \fIendwin()\fP.
  510. X.PP
  511. Some programs (notably rogue) use varibles in <curses.h> which
  512. begin with an underline.  Use of these variables and fields is to
  513. be avoided.  Most of the internal structures used by curses are
  514. hidden from the user.  The variables _tty and _tty_ch are no
  515. longer accessible.  (Since _tty was a version 7 dependent
  516. structure, it was not portable to use it anyway.) Useful fields, such
  517. as the erase and kill characters, and the baud rate, can be
  518. discovered using the portable functions described above.
  519. X.NH
  520. Termlib-Level Changes
  521. X.PP
  522. The termcap(3) (termlib) library has been consolidated with the
  523. curses(3) library to form a new curses(3) library.  The termlib
  524. level is very different in the new version.  The routines
  525. \fItgetent()\fP, \fItgetnum()\fP, \fItgetstr()\fP, and \fItgetflag()\fP are gone.
  526. Initialization is instead done by calling
  527. X.DS
  528. \fIsetupterm\fP(termtype, filedes, errret)
  529. \fBchar\fP *termtype;
  530. \fBint\fP filedes;
  531. \fBint\fP *errret;
  532. X.DE
  533. This routine takes care of all reading in of capabilities, and
  534. any other system dependent initialization.  The terminal type can
  535. be passed as 0, causing \fIsetupterm()\fP to use \fIgetenv\fP(``TERM'') as a
  536. default.  \fIerrret\fP is a pointer to an integer used to return a
  537. status value.  The value returned is 0 if there is no such
  538. terminal type, 1 if all went well, or -1 for some trouble.  A null
  539. pointer can be passed for this value, telling \fIsetupterm()\fP to print
  540. an error message and exit if the terminal cannot be found.
  541. X.PP
  542. When exiting, or calling a shell escape, the user program should
  543. call \fIresetterm()\fP to restore the tty modes.  After the shell
  544. escape, \fIfixterm()\fP can be called to set the tty modes back to
  545. their internal settings.  These calls are now \fBrequired\fP, since
  546. they perform system dependent processing.  They do not output the
  547. \fBenter_ca_mode\fP and \fBexit_ca_mode\fP strings (\fBti\fP and \fBte\fP
  548. in termcap) but
  549. should be called at the same times.
  550. \fISetupterm()\fP calls \fIfixterm()\fP.
  551. X.PP
  552. \fItgoto()\fP has been replaced by \fItparm()\fP, which is a more powerful
  553. parameterized string mechanism.  The \fItgoto()\fP routine is still
  554. available for compatibility.  \fItputs()\fP is unchanged.
  555. X.PP
  556. The external variables \fBUP\fP, \fBBC\fP, \fBPC\fP, and \fBospeed\fP
  557. no longer exist.
  558. The programmer need not worry about these, as their function is
  559. now handled internally.
  560. X.NH
  561. Changes from Termcap to Terminfo
  562. X.PP
  563. This section describes the extensions in terminfo that were not
  564. present in termcap, and the incompatible changes that were made.
  565. It is intended for a programmer or termcap author who is familiar
  566. with termcap and wishes to become familiar with terminfo.  The
  567. emphasis is on the database, not on the programmer interface.
  568. X.NH 2
  569. Syntax
  570. X.PP
  571. The first thing you will notice upon scanning terminfo is that it
  572. looks cosmetically different from termcap.  All the backslashes
  573. are gone from ends of lines.  Fields are separated with commas
  574. instead of colons, and white space after the commas makes them
  575. more readable.  Continuation lines are now defined as lines
  576. beginning with a blank or tab, not lines following a backslash.
  577. These changes make terminfo easier to read and to modify.
  578. X.NH 2
  579. Names
  580. X.PP
  581. The names of the capabilities are no longer limited to two
  582. letters.  There is no longer a hard limit to the names, but an
  583. informal limit of 5 characters is used.  Since the two letter
  584. limit is gone, many of the capabilities have been renamed.  They
  585. now correspond as closely as possible the the ANSI standard
  586. XX3.64.  While learning the new set of names will be tricky at
  587. first, eventually life will be simpler, since most new terminals
  588. use the ANSI abbreviations.
  589. X.NH 2
  590. Defaults
  591. X.PP
  592. A change that is perhaps not so obvious is that certain defaults
  593. are no longer implied.  In termcap, \er was assumed to be a
  594. carriage return unless \fBnc\fP was present, indicating that it did not
  595. work, or \fBcr\fP was present, indicating an alternative.  In terminfo,
  596. if \fBcr\fP is present, the string so given works, otherwise it should
  597. be assumed \fInot\fP to work.  The \fBbs\fP and \fBbc\fP capabilities are replaced
  598. by \fBcub\fP and \fBcub1\fP.  (The former takes a parameter, moving left that
  599. many spaces.  The latter is probably more common in terminals and
  600. moves left one space.)  \fBnl\fP (linefeed) has been split into two
  601. functions: \fBcud1\fP (moves the cursor down one line) and \fBind\fP (scroll
  602. forward).  \fBcud1\fP applies when the cursor is not on the bottom
  603. line, \fBind\fP applies when it is on the bottom line.  The bell
  604. capability is now explicitly given as \fBbel\fP.
  605. X.NH 2
  606. Compilation
  607. X.PP
  608. The terminfo database is compiled, unlike termcap.  This means
  609. that a terminfo source file (describing some set of terminals) is
  610. processed by the terminfo compiler, producing a binary
  611. description of the terminal in a file under /etc/term.  The setupterm
  612. routine reads in this file.
  613. X.PP
  614. The advantage to compilation is that starting up a program using
  615. terminfo is faster.  It is no longer necessary to carry around
  616. the variable TERMCAP in the environment.  It is actually faster
  617. to start up a compiled terminfo \fIwithout\fP the environment variable,
  618. than it is to start up an uncompiled termcap \fIwith\fP the environment
  619. variable.  The increase in speed comes partly from not having to
  620. skip past other terminal descriptions, and partly from the
  621. compiler having sorted the capabilities into order so that a linear
  622. scan can read them in.  (The termcap initialization algorithm is
  623. quadratic on the size of the capability.  The more capabilities
  624. you are interested in, the worse this gets.  It had gotten to the
  625. point where it took 2 CPU seconds on a VAX 11/750 to start up a
  626. process using an uncompiled terminfo!)
  627. X.PP
  628. There exists an environment variable TERMINFO which is taken by the compiler
  629. to be the destination directory of the new object files.  It is also used by
  630. \fIsetupterm()\fP to find an entry for a given terminal.  First it looks in
  631. the directory given in TERMINFO and, if not found there, checks /etc/term.
  632. \fBNote\fP, however, that, unlike the old TERMCAP variable, you may not
  633. put the source for an entry in the TERMINFO variable.  \fIAll\fP
  634. terminfo entries must be compiled.
  635. X.NH 2
  636. Parameterised Strings
  637. X.PP
  638. The old \fItgoto()\fP mechanism, which was designed for cursor addressing
  639. only, has been replaced by a more general parameter mechanism,
  640. accessed through the function \fItparm()\fP.  Since the parameters are
  641. not compatible in the terminfo database, a termcap \fBcm\fI description
  642. must be converted manually to terminfo.
  643. X.PP
  644. The new mechanism is based on a stack.  % operations are used to
  645. push parameters and constants onto the stack, do arithmetic and
  646. other operations on the top of the stack, and print out values in
  647. various formats.  This makes it possible to handle a larger class
  648. of terminals, such as the AED 512, which addresses the cursor in
  649. terms of pixels, not character positions, and the TEC scope,
  650. which numbers the rows and columns from the lower right hand
  651. corner of the screen.  Any number of parameters from 1 to 9 is
  652. possible, whereas \fItgoto()\fP allowed only two parameters. 
  653. If-then-else testing is possible, as is storage in a limited number of
  654. variables.  There is no provision for loops or printing strings
  655. in any format other than %s.  The full details are described in
  656. terminfo(5).
  657. X.PP
  658. A few brief examples are included here to show common
  659. conversions.  For more examples, compare the termcap \fBcm\fP and terminfo
  660. \fBcup\fP entries for your favorite terminal.  ``%+ '' (add space and
  661. print as a character) would be treated as ``%p1%' '%+%c'', that
  662. is, push the first parameter, push space, add the top two numbers
  663. on the stack, and output the top item on the stack using
  664. character (%c) format.  (Of course, for the second parameter, the %p1
  665. must be changed to %p2.) ``%.'' (print as a character) would be
  666. ``%p1%c''.  ``%d'' (print in decimal) would be ``%p1%d''.  As
  667. with \fItgoto()\fP, characters standing by themselves (no % sign) are
  668. output as is.
  669. X.NH 2
  670. More Capabilities
  671. X.PP
  672. There are a number of new capabilities.  The set of new
  673. capabilities may vary, depending on the version of termcap you are used
  674. to.  It is probably worthwhile to read terminfo(5) for a complete
  675. list.  This section describes capabilities new to terminfo that
  676. were never put in termcap.
  677. X.PP
  678. There are provisions for dealing with more video attributes.
  679. Termcap had strings to turn on and off standout and underline
  680. modes.  Terminfo has these and several more.  There are strings
  681. to turn on bold, inverse video, blinking, dim, protected, and
  682. blanking.  Rather than have separate string for turning off each
  683. of these, a single capability: \fBsgr0\fP, turns them all off.
  684. X.PP
  685. The effect of turning on more than one attribute at a time with
  686. the separate strings is undefined.  A parameterized string, \fBsgr\fP,
  687. can be used to turn them on in combination.
  688. X.PP
  689. More function keys are defined now.  There are provisions for f0
  690. through f10 as well as keys such as erase, insert mode, insert
  691. line, delete line, delete character, print, and so on.  All of
  692. these keys can be accessed through curses as if they were single
  693. characters.  Also, \fBvi\fP version 3.8 has default meanings for many
  694. of them.
  695. X.PP
  696. Several new uses are made of parameterized strings.  For example,
  697. capabilities exist to move the cursor to a particular column in
  698. the current row, a particular row in the current column, and to
  699. move left, right, up, or down a given number of spaces.  These
  700. capabilities make a big difference on some terminals, such as the
  701. Tektronix 4025.  Also, column addressing is useful for filters
  702. that do not know what row they are in, or as a shorter form of
  703. cursor addressing when the target is in the same row.
  704. X.PP
  705. There are now capabilities to turn on and off a local printer,
  706. and to print the current page.  Also, there are provisions for
  707. moving the cursor to and from a status line.  These capabilities
  708. can be used by a background status program, such as \fIsysline\fP, to
  709. keep status information in the status line without bothering
  710. foreground processes.  This only works on terminals with a
  711. writable status line, such as the h19 or tvi950, or on terminals
  712. where one can be simulated, such as the hp2626, vt100, or
  713. ambassador, by allocating one of the ordinary screen lines for a
  714. status line.
  715. X.NH 2
  716. How to Convert from Termcap to Terminfo
  717. X.PP
  718. This section is intended for programmers who need to convert
  719. programs that use termcap to the new terminfo database.  It
  720. describes the steps needed for the conversion.
  721. X.PP
  722. If you must make the conversion, you are strongly urged to
  723. convert to curses, rather than converting to terminfo.  The curses
  724. interface is higher level and will probably do a better job of
  725. optimizing your output.  Your program will work on a wider range
  726. of terminals if you use curses.  It will also become more
  727. portable.  The effort to convert to curses is probably about the same
  728. as to convert to terminfo.
  729. X.PP
  730. There are some programs for which curses is not a possibility.
  731. Curses takes over the CRT screen, and this implies initially
  732. clearing the screen.  For some programs, such as filters, this
  733. may not make sense.  Also, if you are writing a special purpose
  734. program which uses some terminfo capability that curses does not
  735. use, it will probably be necessary to use the terminfo level
  736. interface.
  737. X.NH 2
  738. Conversion
  739. X.PP
  740. The first step is to include the headers <curses.h> and <term.h>
  741. (in that order).  These headers will bring into existence a set
  742. of ``variables'' (actually macros) that contain values of
  743. capabilities.  For example, the macro \fBcursor_address\fP will be defined,
  744. replacing the termcap \fBcm\fP
  745. capability.  You should remove the declarations for all variables
  746. you use for capabilities returned by \fItgetflag()\fP, \fItgetnum()\fP, and
  747. \fItgetstr()\fP.
  748. X.PP
  749. The most difficult step is that all variables removed in the
  750. previous step must be renamed the standard names.  For example, if
  751. you stored \fBcm\fP in the variable CM, you would change
  752. \fItputs\fP(\fItgoto\fP(\fBCM\fP, i, j), 1, outch) to
  753. \fItputs\fP(\fItgoto\fP(\fBcursor_address\fP, i, j), 1, outch).
  754. Consult terminfo(5) for a list of standard
  755. names.  A \fBsed\fP script is often useful for this step.  Care must be
  756. taken to avoid mention of the variable as part of a longer word
  757. (a version of \fBsed\fP supporting the \fBex\fP \<word\> convention is useful
  758. here.) Also, you should proofread the results, since sometimes
  759. comments and strings get substituted that shouldn't have been.
  760. X.PP
  761. Remove all your termcap initialization code.  This code typically
  762. calls \fItgetent()\fP, \fItgetstr()\fP, \fItgetflag()\fP, and \fItgetnum()\fP.
  763. You can also
  764. remove declarations used only for this initialization, usually
  765. including buffers for the entry and string values.  Replace it
  766. with a single call to \fIsetupterm\fP(0, 1, 0).  This call will never
  767. return if something goes wrong, that is, if there is no $TERM in
  768. the environment or there is no such terminal, the routine will
  769. print an error and exit.  If you need an error indication passed
  770. back for more sophisticated error recovery, pass an integer
  771. variable in the third parameter, i.e.  setupterm(0, 1, &i).  The
  772. value returned in \fBi\fP will be the same as that previously returned
  773. by \fItgetent()\fP.  Other more sophisticated calls to \fIsetupterm()\fP are
  774. possible, see the documentation if some terminal other than $TERM or
  775. some file descriptor other than \fBstdout\fP are involved.
  776. X.PP
  777. Before the program exits, insert a call to \fIresetterm()\fP.  This
  778. will restore the tty modes to their state before setupterm was
  779. called, and do any other system dependent exit processing.  This
  780. routine can also be called before a shell escape, you should call
  781. \fIfixterm()\fP after the shell escape to restore the tty modes to
  782. those needed by terminfo.  (Currently \fIsetupterm()\fP will turn off the
  783. XXTABS bit in the tty driver, since some terminals need to send
  784. control I for escape sequences.  You should be sure to expand any
  785. tabs in your software if necessary.)
  786. X.PP
  787. XFrom the programmers viewpoint, the routine \fItputs()\fP is exactly as
  788. in termcap.  The padding syntax in the capability is different,
  789. but this only affects the capabilities in the terminfo database.
  790. No change to a program will be needed for \fItputs()\fP.
  791. X.PP
  792. The \fItgoto()\fP routine is kept around for upward compatibility, but
  793. you should probably replace calls to \fItgoto()\fP by calls to \fItparm()\fP.
  794. The call \fItgoto\fP(cap, y, x) will call \fItparm\fP(cap, x, y).  Note that
  795. the order of the last two arguments is reversed - it was
  796. backwards in \fItgoto()\fP from what it probably should have been.  In
  797. addition to the capability, \fItparm()\fP can now take up to nine parameters,
  798. or as few as one.
  799. X.PP
  800. If you use certain capabilities, there are a few convention
  801. changes you should be aware of.  These do not affect very many
  802. programs, but will require some minor recoding of a few programs.
  803. In termcap, the cursor is moved left by control-H if \fBbs\fP is
  804. present, otherwise, if \fBbc\fP is present, that character is used.  In
  805. terminfo, the cursor is moved left with \fBcub1\fP, if present, or by
  806. \fBcub\fP, if present.  If neither is there, there is no implied
  807. control-H.  Similarly, termcap assumed that control-M was carriage
  808. return unless \fBnc\fP or \fBcr\fP was specified.  In terminfo, carriage
  809. return is always the string specified by \fBcr\fP, and if not present,
  810. there is no carriage return capability.  In termcap, linefeed is
  811. assumed to both move the cursor down (if it is not on the bottom
  812. line) and to scroll one line (if it is on the bottom line),
  813. unless \fBns\fP is present.  \fBsf\fP and \fBdo\fP capabilities were present but
  814. little used, and some software assumed that \fBsf\fP worked with the
  815. cursor anywhere on the screen.  In terminfo, there is no implied
  816. linefeed - moving the cursor down is done with \fBcud1\fP or \fBcud\fP and
  817. scrolling is done with \fBind\fP.  \fBind\fP is only defined when the cursor
  818. is at the bottom of the screen.  Finally, the implied control G
  819. used to ring the bell unless \fBvb\fP was present has been replaced
  820. with an explicit \fBbel\fP.
  821. X.PP
  822. Replace references in your makefile from -ltermcap or -ltermlib
  823. with references to -lcurses.
  824. X.PP
  825. Now recompile your program.  It should run properly using
  826. terminfo.
  827. X.NH 2
  828. Space Conditions
  829. X.PP
  830. The expansion of a macro name into a structure reference 
  831. will probably make your program a bit bigger.  If space is a
  832. problem, one thing you can do is add \fB-DSINGLE\fP to the CFLAGS in
  833. your makefile.  This causes the macros to expand to a static
  834. reference instead of a dynamic reference, resulting in smaller
  835. code.  It cannot be used if you intend to involve more than one
  836. terminal from a single process.  Since very few programs talk to
  837. two terminals at once, it is almost always safe to define SINGLE.
  838. X.PP
  839. If your program was pushing the limit on a small machine, it may
  840. not fit with terminfo unless you trim it down some.  While the
  841. startup routines are faster, they tend to generate larger code
  842. than those of termcap.  Also, \fItputs()\fP and \fItparm()\fP are more
  843. sophisticated and larger.
  844. //go.sysin dd *
  845. echo 'x - =doc/compile.1'
  846. sed 's/^X//' <<'//go.sysin dd *' >=doc/compile.1
  847. X.TH COMPILE 1 Terminfo/Curses
  848. X.SH NAME
  849. compile \- Compile the terminfo database
  850. X.SH SYNOPSIS
  851. X.B /etc/term/compile
  852. [\fB-v\fR[\fIn\fR]] source-file
  853. X.SH DESCRIPTION
  854. X.I Compile
  855. is the program which translates the source files in the terminfo
  856. terminal capability database into their object format.  The given
  857. X.I file
  858. is expected to contain one or more terminfo entries, as described in
  859. X.IR terminfo (5).
  860. This file is expected to be self-contained, i.e., it may not
  861. contain ``\fBuse\fP'' entries which refer to terminals not described fully
  862. in the same file.
  863. X.PP
  864. The object files are normally placed in subdirectories of the directory
  865. X/etc/term (see
  866. X.IR term (5)),
  867. but if the environment variable TERMINFO is defined, it is taken to be the
  868. name of an alternate directory to use.
  869. X.PP
  870. Debugging and tracing information may be obtained by use of the
  871. X.B -v
  872. flag.
  873. The number after the flag controls the amount of debugging information
  874. given, according to the following table:
  875. X.IP 1
  876. Names of files created and linked
  877. X.IP 2
  878. Information related to the ``\fBuse\fR'' facility
  879. X.IP 3
  880. Statistics from the hashing algorithm
  881. X.IP 5
  882. String-table memory allocations
  883. X.IP 7
  884. Entries into the string-table
  885. X.IP 8
  886. List of tokens encountered by scanner
  887. X.IP 9
  888. All values computed in construction of the hash table
  889. X.in -0.5i
  890. X.sp
  891. If \fIn\fP is not given, it is taken to be one.
  892. X.SH FILES
  893. X/etc/term/*    Default location of object files
  894. X.SH SEE ALSO
  895. terminfo(5), term(5), dump(1).
  896. X.SH AUTHOR
  897. Pavel Curtis, Cornell University
  898. X.br
  899. (decvax!cornell!pavel  or  Pavel.Cornell@Udel-Relay)
  900. X.SH BUGS
  901. You tell me.
  902. //go.sysin dd *
  903. echo 'x - =doc/dump.1'
  904. sed 's/^X//' <<'//go.sysin dd *' >=doc/dump.1
  905. X.TH DUMP 1 Terminfo/Curses
  906. X.SH NAME
  907. dump \- Print the contents of a compiled terminfo file in human-readable form
  908. X.SH SYNOPSIS
  909. X.B /etc/term/dump 
  910. file ...
  911. X.SH DESCRIPTION
  912. X.I Dump 
  913. reads the given files and decodes their contents to derive a reasonable
  914. representation of the terminfo entry which produced the file originally.
  915. It should be noted, in case of emergency, that the output of
  916. X.I dump
  917. is perfectly usable as the input to
  918. X.IR compile (1).
  919. X.SH SEE ALSO
  920. compile(1), term(5), terminfo(5)
  921. X.SH AUTHOR
  922. Pavel Curtis, Cornell University
  923. X.br
  924. (decvax!cornell!pavel or Pavel.Cornell@Udel-Relay)
  925. //go.sysin dd *
  926. exit
  927.