[an error occurred while processing this directive]
HP OpenVMS SystemsC Programming Language |
Compaq C
|
Previous | Contents | Index |
The <curses.h> header file defines variables and constants useful for implementing Curses (see Table 6-2).
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.
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 Compaq 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 Compaq C Run-Time Library (RTL). For more detailed information on each function, see the Reference Section.
Additional math routine variants are supported for Compaq C on OpenVMS Alpha systems only. They are defined in <math.h> and are float and long double variants of the routines listed in the preceding table.
Float variants take float arguments and return float values. Their names are suffixed with an f . For example:
float cosf (float x); float tandf (float x); |
Long double variants take long double arguments and return long double values. Their names are suffixed with an l . 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 Compaq C RTL math routines map to the X_FLOAT entry points documented in the Compaq Portable Mathematics Library (CPML) manual.
Previous | Next | Contents | Index |