HP OpenVMS Systems Documentation |
HP C
|
Previous | Contents | Index |
The <curses.h> header file defines variables and constants useful for implementing Curses (see Table 6-2).
Name | Type | Description |
---|---|---|
curscr | WINDOW * | Window of current screen |
stdscr | WINDOW * | Default window |
LINES | int | Number of lines on the terminal screen |
COLS | int | Number of columns on the terminal screen |
ERR | --- | Flag (0) for failed routines |
OK | --- | Flag (1) for successful routines |
TRUE | --- | Boolean true flag (1) |
FALSE | --- | Boolean false flag (0) |
_BLINK | --- | Parameter for setattr and clrattr |
_BOLD | --- | Parameter for setattr and clrattr |
_REVERSE | --- | Parameter for setattr and clrattr |
_UNDERLINE | --- | Parameter for setattr and clrattr |
For example, you can use the predefined macro ERR to test the success or failure of a Curses function. Example 6-4 shows how to perform such a test.
Example 6-4 Curses Predefined Variables |
---|
#include <curses.h> WINDOW *win1, *win2, *win3; main() { initscr(); win1 = newwin(10, 10, 1, 5); . . . if (mvwin(win1, 1, 10) == ERR) addstr("The MVWIN function failed."); . . . endwin(); } |
In Example 6-4, if the
mvwin
function fails, the program adds a string to
stdscr
that explains the outcome. The Curses
mvwin
function moves the starting position of a window.
6.6 Cursor Movement
In the UNIX system environment, you can use Curses functions to move the cursor across the terminal screen. With other implementations, you can either allow Curses to move the cursor using the move function, or you can specify the origin and the destination of the cursor to the mvcur function, which moves the cursor in a more efficient manner.
In HP C for OpenVMS Systems, the two functions are functionally equivalent and move the cursor with the same efficiency.
Example 6-5 shows how to use the move and mvcur functions.
Example 6-5 The Cursor Movement Functions |
---|
#include <curses.h> main() { initscr(); . . . (1) clear(); (2) move(10, 10); (3) move(LINES/2, COLS/2); (4) mvcur(0, COLS-1, LINES-1, 0); . . . endwin(); } |
Key to Example 6-5:
The following program example shows the effects of many of the Curses macros and functions. You can find explanations of the individual lines of code, if not self-explanatory, in the comments to the right of the particular line. Detailed discussions of the functions follow the source code listing.
Example 6-6 shows the definition and manipulation of one user-defined window and stdscr .
Example 6-6 stdscr and Occluding Windows |
---|
/* CHAP_6_STDSCR_OCCLUDE.C */ /* This program defines one window: win1. win1 is */ /* located towards the center of the default window */ /* stdscr. When writing to an occluding window (win1) */ /* that is later erased, the writing is erased as well. */ #include <curses.h> /* Include header file. */ WINDOW *win1; /* Define windows. */ main() { char str[80]; /* Variable declaration.*/ initscr(); /* Set up Curses. */ noecho(); /* Turn off echo. */ /* Create window. */ win1 = newwin(10, 20, 10, 10); box(stdscr, '|', '-'); /* Draw a box around stdscr. */ box(win1, '|', '-'); /* Draw a box around win1. */ refresh(); /* Display stdscr on screen. */ wrefresh(win1); /* Display win1 on screen. */ (1) getstr(str); /* Pause. Type a few words! */ mvaddstr(22, 1, str); (2) getch(); /* Add string to win1. */ mvwaddstr(win1, 5, 5, "Hello"); wrefresh(win1); /* Add win1 to terminal scr. */ getch(); /* Pause. Press Return. */ delwin(win1); /* Delete win1. */ (3) touchwin(stdscr); /* Refresh all of stdscr. */ getch(); /* Pause. Press Return. */ endwin(); /* Ends session. */ } |
Key to Example 6-6:
Figure 6-4 An Example of the getch Macro
Table 7-1 lists and describes the math functions in the HP C Run-Time Library (RTL). For more detailed information on each function, see the Reference Section.
Function | Description |
---|---|
abs | Returns the absolute value of an integer. |
acos | Returns the arc cosine of its radian argument, in the range [0,pi] radians. |
acosd (ALPHA ONLY) | Returns the arc cosine of its radian argument, in the range [0,180] degrees. |
acosh (ALPHA ONLY) | Returns the hyperbolic arc cosine of its argument. |
asin | Returns the arc sine of its radian argument in the range [ - pi/2,pi/2] radians. |
asind (ALPHA ONLY) | Returns the arc sine of its radian argument, in the range [ -90,90 ] degrees. |
asinh (ALPHA ONLY) | Returns the hyperbolic arc sine of its argument. |
atan | Returns the arc tangent of its radian argument, in the range [ - pi/2,pi/2] radians. |
atand (ALPHA ONLY) | Returns the arc tangent of its radian argument, in the range [ -90,90 ] degrees. |
atan2 | Returns the arc tangent of y/ x (its two radian arguments), in the range [ - pi,pi] radians. |
atand2 (ALPHA ONLY) | Returns the arc tangent of y/ x (its two radian arguments), in the range [ -180,180 ] degrees. |
atanh (ALPHA ONLY) | Returns the hyperbolic arc tangent of its radian argument. |
cabs | Returns the absolute value of a complex number as: sqrt ( x 2 + y 2) . |
cbrt (ALPHA ONLY) | Returns the rounded cube root of its argument. |
ceil | Returns the smallest integer greater than or equal to its argument. |
copysign (ALPHA ONLY) | Returns its first argument with the same sign as its second. |
cos | Returns the cosine of its radian argument in radians. |
cosd (ALPHA ONLY) | Returns the cosine of its radian argument in degrees. |
cosh | Returns the hyperbolic cosine of its argument. |
cot | Returns the cotangent of its radian argument in radians. |
cotd (ALPHA ONLY) | Returns the cotangent of its radian argument in degrees. |
drand48 , erand48 , jrand48 , lrand48 , mrand48 , nrand48 | Generates uniformly distributed pseudorandom number sequences. Returns 48-bit, nonnegative, double-precision floating-point values. |
erf (ALPHA ONLY) | Returns the error function of its argument. |
erfc (ALPHA ONLY) | Returns (1.0 - erf (x )). |
exp | Returns the base e raised to the power of the argument. |
expm1 (ALPHA ONLY) | Returns exp (x ) - 1. |
fabs | Returns the absolute value of a floating-point value. |
finite (ALPHA ONLY) | Returns 1 if its argument is a finite number; 0 if not. |
floor | Returns the largest integer less than or equal to its argument. |
fmod | Computes the floating-point remainder of its first argument divided by its second. |
fp_class (ALPHA ONLY) | Determines the class of IEEE floating-point values, returning a constant from the <fp_class.h> header file. |
isnan (ALPHA ONLY) | Test for NaN. Returns 1 if its argument is a NaN; 0 if not. |
j0, j1, jn (ALPHA ONLY) | Computes Bessel functions of the first kind. |
frexp | Calculates the fractional and exponent parts of a floating-point value. |
hypot | Returns the square root of the sum of the squares of two arguments. |
initstate | Initializes random number generators. |
labs | Returns the absolute value of an integer as a long int . |
lcong48 | Initializes a 48-bit uniformly distributed pseudorandom number sequence. |
lgamma (ALPHA ONLY) | Computes the logarithm of the gamma function. |
llabs, qabs (ALPHA ONLY) | Returns the absolute value of an __int64 integer. |
ldexp | Returns its first argument multiplied by 2 raised to the power of its second argument. |
ldiv, div | Returns the quotient and remainder after the division of their arguments. |
lldiv, qdiv (ALPHA ONLY) | Returns the quotient and remainder after the division of their arguments. |
log2 (ALPHA ONLY), log, log10 | Returns the logarithm of their arguments. |
log1p (ALPHA ONLY) | Computes ln(1+ x) accurately. |
logb (ALPHA ONLY) | Returns the radix-independent exponent of its argument. |
nextafter (ALPHA ONLY) | Returns the next machine-representable number following x in the direction of y. |
nint (ALPHA ONLY) | Returns the nearest integral value to the argument. |
modf | Returns the positive fractional part of its first argument and assigns the integral part to the object whose address is specified by the second argument. |
pow | Returns the first argument raised to the power of the second. |
rand, srand | Returns pseudorandom numbers in the range 0 to 2 31-1 . |
random , srandom | Generates pseudorandom numbers in a more random sequence. |
rint (ALPHA ONLY) | Rounds its argument to an integral value according to the current IEEE rounding direction specified by the user. |
scalb (ALPHA ONLY) | Returns the exponent of a floating-point number. |
seed48 , srand48 | Initializes a 48-bit random number generator. |
setstate | Restarts, and changes random number generators. |
sin | Returns the sine of its radian argument in radians. |
sind (ALPHA ONLY) | Returns the sine of its radian argument in degrees. |
sinh | Returns the hyperbolic sine of its argument. |
sqrt | Returns the square root of its argument. |
tan | Returns the tangent of its radian argument in radians. |
tand (ALPHA ONLY) | Returns the tangent of its radian argument in degrees. |
tanh | Returns the hyperbolic tangent of its argument. |
trunc (ALPHA ONLY) | Truncates its argument to an integral value. |
unordered (ALPHA ONLY) | Returns 1 if either or both of its arguments is a NaN; 0, if not. |
y0, y1, yn (ALPHA ONLY) | Computes Bessel functions of the second kind. |
Additional math routine variants are supported for HP C on OpenVMS Alpha systems only. They are defined in <math.h> and are float and long double variants of the routines listed in Table 7-1.
Float variants take float arguments and return float values. Their names have an f suffix. For example:
float cosf (float x); float tandf (float x); |
Long double variants take long double arguments and return long double values. Their names have an l suffix. For example:
long double cosl (long double x); long double tandl (long double x); |
All math routine variants are included in the Reference Section of this manual.
Note that for programs compiled without /L_DOUBLE=64 (that is, compiled with the default /L_DOUBLE=128), the long double variants of these HP C RTL math routines map to the X_FLOAT entry points documented in the HP Portable Mathematics Library (HPML) manual.
Previous | Next | Contents | Index |