home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume4 / rolodex / part3 / toolsdir / menu.h < prev    next >
Encoding:
C/C++ Source or Header  |  1986-11-30  |  4.3 KB  |  140 lines

  1. /* You must include "<ctools.h>" before including this file. */
  2.  
  3. #define MENU_EOF -1
  4. #define MENU_MATCH 0
  5. #define MENU_AMBIGUOUS 1
  6. #define MENU_NO_MATCH 2        
  7. #define MENU_ERROR 3
  8. #define MENU_RETURN 4
  9.  
  10. #define MAX_MENU_OPTIONS 20
  11. #define MAX_MENU_RESPONSE_LENGTH 255
  12.  
  13.  
  14. extern int menu_match();
  15.  
  16. /* menu_match (
  17.  
  18.         int *ptr_rval,
  19.         char **ptr_user_response,
  20.         char *prompt,
  21.         int case_significant,
  22.         int initial_substring_sufficient,
  23.         int repeat_if_no_match,
  24.         int repeat_if_ambiguous,
  25.         int n_options,
  26.         char *option1, int rval1,
  27.         char *option2, int rval2,
  28.         .
  29.         .
  30.         .
  31.  
  32.     );
  33.  
  34.     Returns one of MENU_MATCH, MENU_AMBIGUOUS, MENU_NO_MATCH, and MENU_ERROR.
  35.     If MENU_MATCH is returned, *ptr_rval contains the value that the caller
  36.     asked to be returned.  *ptr_user_response is what exactly what the user
  37.     typed in, minus the linefeed at the end.
  38.     
  39.     prompt is a character string that is printed out.  A line of input is
  40.     then read from the terminal, stripped of excess blanks, and compared
  41.     with the menu items.  Up to MAX_MENU_OPTIONS can be specified.  Each
  42.     option is a character string and has an associated integer return value.
  43.     
  44.     If case_significant is not zero, the user's response will be checked
  45.     against the options with upper/lower case distinction. 
  46.     If initial_substring_sufficient is not zero, then a match will occur
  47.     if the user's response is the same as an initial substring of an option,
  48.     otherwise the response must match the option exactly.
  49.     
  50.     If more than one menu option matches the response, MENU_AMBIGUOUS is
  51.     returned.  If n_options exceeds MAX_MENU_OPTIONS or the read fails
  52.     MENU_ERROR is returned.  If no option matches the response, MENU_NO_MATCH
  53.     is returned.  However, if repeat_if_no_match and/or repeat_if_ambiguous
  54.     are non_zero, the user is prompted again until he answers correctly if
  55.     he answers wrongly/ambiguously, respectively.
  56.     
  57.     If "" is not specified as an option, and the user enters a blank line,
  58.     the routine simply prompts the user again.  It is impossible to match
  59.     on a string of blanks (e.g., "  "), because any blank line the user
  60.     types is considered to be "".
  61.     
  62.     If the response the user types is too long, an error message is printed
  63.     out and the user is asked to try again.
  64.     
  65. */
  66.  
  67.  
  68. #define MENU_NO 0
  69. #define MENU_YES 1
  70. #define MENU_HELP 2
  71. #define MENU_ABORT 3
  72. #define MENU_DATA 4
  73.  
  74. extern int menu_yes_no();
  75.  
  76. /* menu_yes_no (prompt,allow_help) char *prompt; int allow_help;
  77.  
  78.         returns one of MENU_NO, MENU_YES or, if help is allowed,
  79.         MENU_HELP.  Help can be obtained via "?" or any initial
  80.         substring of "Help", case independently.  Returns MENU_EOF
  81.         if end of file encountered when reading. 
  82.  
  83.         Yes or no can be obtained via any case independent initial
  84.         substring of "Yes" or "No" respectively.
  85.  
  86. */
  87.  
  88.  
  89. #define DEFAULT_YES 0
  90. #define DEFAULT_NO 1
  91. #define NO_DEFAULT 2
  92.  
  93. extern int menu_yes_no_abort_or_help ();
  94.  
  95. /*  menu_yes_no_abort_or_help (prompt,abortstring,helpallowed,return_for_yes)
  96.  
  97.     char *prompt, *abortstring;
  98.     int helpallowed; 
  99.     int return_for_yes;
  100.  
  101.     Returns one of MENU_YES, MENU_NO, MENU_ABORT, MENU_HELP or MENU_EOF.
  102.     If !helpallowed, MENU_HELP will not be returned.  
  103.     If return_for_yes is DEFAULT_NO, hitting return will re-prompt.
  104.     If it is DEFAULT_YES, hitting return is like typing yes.
  105.     If it is any other value, hitting return is like typing no.
  106.  
  107. */    
  108.  
  109. extern int menu_data_help_or_abort ();
  110.  
  111. /*
  112.  
  113. extern int menu_data_help_or_abort (prompt,abortstring,ptr_response)
  114.  
  115.   char *prompt, *abortstring, **ptr_response;
  116.  
  117.   Returns either MENU_ABORT, MENU_HELP or MENU_DATA.  If MENU_DATA is
  118.   returned, *response contains the user's response.  MENU_HELP is
  119.   returned in the user types in "?" or any initial substring of "Help"
  120.   (case independently).
  121.   
  122. */  
  123.   
  124.  
  125. extern int menu_number_help_or_abort ();
  126.  
  127. /*
  128. menu_number_help_or_abort (prompt,abortstring,low,high,ptr_ival)
  129.  
  130.   char *prompt; *abortstring;
  131.   int low,high,*ptr_ival;
  132.  
  133.   Returns either MENU_DATA, MENU_ABORT, MENU_HELP or MENU_EOF.
  134.   If low > high any number will be considered valid, otherwise the
  135.   range is checked, inclusivewise.  If MENU_DATA is returned, *ptr_ival
  136.   contains the number entered.
  137.  
  138.   At the moment number can only be non-negative.
  139. */
  140.