cc [ flags ] files -lterm -ltermcap [ libraries ]
Exceptions to the above are GetBool for which valid inputs are n, N, y, Y, SPACE, and RETURN, for no, yes, toggle, and accept respectively, PickOne which understands ^ for previous value, SPACE for next value, and RETURN for accept, and MenuPick which understands ^ for previous value, SPACE for next value, > for next page, and RETURN for accept.
Magic cookies are dealt with properly but with the result that the field on the screen is wider than the requested datum field during entry. The requested field size is used when the field is rewritten in normal mode after acceptance of a datum value. This is a feature of term and a bug in the terminals with magic cookies. Curses(3x) deals with this problem by just not allowing standout mode. Which would you rather buy?
George W. Sherouse Radiation Oncology North Carolina Memorial Hospital University of North Carolina, Chapel Hill
Get a floating point number. Imagine %(field_width).(places)f
in a printf.
float GetFloat(default, field_width, places);
float default;
int field_width;
int places;
Get an integer.
int GetInt(default, field_width);
int default;
int field_width;
Get a boolean.
int GetBool(default);
int default;
Get a string. String should be at least field_size + 1 long
to accomodate the appended null. Null_ok is a boolean which
declares whether or not a string of length zero is acceptable.
void GetString(string, field_size, null_ok);
char *string;
int field_size;
int null_ok;
Get a hospital number in the format 00-00-00.
void GetHospNum(hosp_num);
char *hosp_num
Pick one string from a list of strings by displaying one choice at a time in
the field.
int PickOne(list, choice_count);
char **list;
int choice_count;
A full-screen version of PickOne. The page is cleared, the prompt is displayed
at the top of the page and the first <some number> choices are displayed.
The user may step through the choices with ^ and SPACE.
If there are more than <some number> choices, the user may also change pages
with >.
RETURN accepts currently highlighted value.
int MenuPick(prompt, list, choice_count);
char *prompt;
char **list;
int choice_count;
Clear the screen.
void page();
Move cursor. Coordinates are 1-indexed from upper left.
void gotoxy(col, line);
int col;
int line;
Clear to end of line.
void ClearEOL();
Print string centered on line. Mode == 0 requests normal print, == 1 requests
underline, and == 2 requests standout.
void center(line, string, mode);
int line;
char *string;
int mode;
Set or clear standout mode. Not very useful at the applications level.
void StandOut(on_or_off);
int on_or_off;
Set or clear underline mode. Not very useful at the applications level.
void underline(on_or_off);
int on_or_off;
Issue some backspaces. Not very interesting at the applications level.
void TermRewind(count);
int count;
Place stdin into raw mode with no echo on odd calls and restore original modes
on even calls.
Return the terminal's erase character.
Not intended for use at the applications level.
char TermSetUp();
Some unreasonable assumptions are made regarding sanity in the termcap. You will know what they are if you violate them. I apologize in advance.
GetFloat does not support scientific notation. It also does not let you back up over the decimal point once it has placed it. This is no great hardship since you can always ^X to restart.
Some of the code is a little ugly, having been hacked unmercifully through many revisions. It does seem to work, though.