ncurses, which stands for “new curses,” is a freely redistributable clone of the curses libraries distributed with the System V Release 4.0 (SVR4) UNIX distributed by Bell Labs. The term “curses” derives from the phrase “cursor optimization,” succinctly describing how curses behaves. The SVR4 curses package, in turn, was a continued evolution of the curses available with System II UNIX, which itself was based on the original curses implementation shipped with early Berkeley Software Distribution (BSD) UNIX releases.

Compiling with ncurses

To compile a program with ncurses, you need its function and variable definitions, soinclude <curses.h> in your source code:

#include <curses.h>

Many Linux systems make /usr/include/curses.h a symbolic link to the /usr/include/ncurses.h, so you could conceivably include <ncurses.h>. However, for maximum portability, use <curses.h> because, believe it or not, ncurses is not  available on all UNIX and UNIX-like platforms. You will also need to link against the ncurses libraries, so use the -lcurses option when linking, or add -lcurses to the LDFLAGS make variable or the $LDFLAGS environment variable:

$ gcc curses_prog.c -o curses_prog –lcurses

Debugging ncurses Programs

By default, debug tracing is disabled in ncurses programs. To enable debugging, link against ncurses’ debug library, ncurses_g, and either call trace(N) in your code or set the environment variable $NCURSES_TRACE to N, where N is a positive, non-zero integer. Doing so forces debugging output to a file named, appropriately, trace, in the current directry. The larger N’s value, the more finely grained and voluminous the debugging output. Useful values for N are documented in <ncurses.h>. For example, the standard trace level, TRACE_ORDINARY, is 31.

Posted on: 18/12/2009

If you want to leave a comment please Login or Register