HP C
Run-Time Library Reference Manual for OpenVMS Systems


Previous Contents Index

6.5 Predefined Variables and Constants

The <curses.h> header file defines variables and constants useful for implementing Curses (see Table 6-2).

Table 6-2 Curses Predefined Variables and#define Constants
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:

  1. The clear macro erases stdscr and positions the cursor at coordinates (0,0).
  2. The first occurrence of move moves the cursor to coordinates (10,10).
  3. The second occurrence of move uses the predefined variables LINES and COLS to calculate the center of the screen (by calculating the value of half the number of LINES and COLS on the screen).
  4. The mvcur function forces absolute addressing. This function can address the lower left corner of the screen by claiming that the cursor is presently in the upper right corner. You can use this method if you are unsure of the current position of the cursor, but move works just as well.

6.7 Program Example

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:

  1. The program waits for input. The echo was disabled using the noecho macro, so the words that you type do not appear on stdscr . However, the macro stores the words in the variable str for use elsewhere in the program.
  2. The getch macro causes the program to pause. When you are finished viewing the screen, press Return so the program can resume. The getch macro refreshes stdscr on the terminal screen without calling refresh . The screen appears like Figure 6-4.

Figure 6-4 An Example of the getch Macro


  1. The touchwin function refreshes the screen so that all of stdscr is visible and the deleted occluding window no longer appears on the screen.


Chapter 7
Math Functions

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.

Table 7-1 Math Functions
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 (INTEGRITY SERVERS, ALPHA) Returns the arc cosine of its radian argument, in the range [0,180] degrees.
acosh (INTEGRITY SERVERS, ALPHA) 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 (INTEGRITY SERVERS, ALPHA) Returns the arc sine of its radian argument, in the range [ -90,90 ] degrees.
asinh (INTEGRITY SERVERS, ALPHA) 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 (INTEGRITY SERVERS, ALPHA) 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 (INTEGRITY SERVERS, ALPHA) Returns the arc tangent of y/ x (its two radian arguments), in the range [ -180,180 ] degrees.
atanh (INTEGRITY SERVERS, ALPHA) 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 (INTEGRITY SERVERS, ALPHA) Returns the rounded cube root of its argument.
ceil Returns the smallest integer greater than or equal to its argument.
copysign (INTEGRITY SERVERS, ALPHA) Returns its first argument with the same sign as its second.
cos Returns the cosine of its radian argument in radians.
cosd (INTEGRITY SERVERS, ALPHA) 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 (INTEGRITY SERVERS, ALPHA) 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 (INTEGRITY SERVERS, ALPHA) Returns the error function of its argument.
erfc (INTEGRITY SERVERS, ALPHA) Returns (1.0 - erf (x )).
exp Returns the base e raised to the power of the argument.
expm1 (INTEGRITY SERVERS, ALPHA) Returns exp (x ) - 1.
fabs Returns the absolute value of a floating-point value.
finite (INTEGRITY SERVERS, ALPHA) 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 (INTEGRITY SERVERS, ALPHA) Determines the class of IEEE floating-point values, returning a constant from the <fp_class.h> header file.
isnan (INTEGRITY SERVERS, ALPHA) Test for NaN. Returns 1 if its argument is a NaN; 0 if not.
j0, j1, jn (INTEGRITY SERVERS, ALPHA) 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 (INTEGRITY SERVERS, ALPHA) Computes the logarithm of the gamma function.
llabs, qabs (INTEGRITY SERVERS, ALPHA) 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 (INTEGRITY SERVERS, ALPHA) Returns the quotient and remainder after the division of their arguments.
log2 (INTEGRITY SERVERS, ALPHA) , log, log10 Returns the logarithm of their arguments.
log1p (INTEGRITY SERVERS, ALPHA) Computes ln(1+ x) accurately.
logb (INTEGRITY SERVERS, ALPHA) Returns the radix-independent exponent of its argument.
nextafter (INTEGRITY SERVERS, ALPHA) Returns the next machine-representable number following x in the direction of y.
nint (INTEGRITY SERVERS, ALPHA) 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 (INTEGRITY SERVERS, ALPHA) Rounds its argument to an integral value according to the current IEEE rounding direction specified by the user.
scalb (INTEGRITY SERVERS, ALPHA) 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 (INTEGRITY SERVERS, ALPHA) 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 (INTEGRITY SERVERS, ALPHA) Returns the tangent of its radian argument in degrees.
tanh Returns the hyperbolic tangent of its argument.
trunc (INTEGRITY SERVERS, ALPHA) Truncates its argument to an integral value.
unordered (INTEGRITY SERVERS, ALPHA) Returns 1 if either or both of its arguments is a NaN; 0, if not.
y0, y1, yn (INTEGRITY SERVERS, ALPHA) Computes Bessel functions of the second kind.

7.1 Math Function Variants---float, long double (INTEGRITY SERVERS, ALPHA)

Additional math routine variants are supported for HP C on OpenVMS Alpha and Integrity server 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