home *** CD-ROM | disk | FTP | other *** search
- /* ==( bench/goption.c )== */
- /* ----------------------------------------------- */
- /* Pro-C Copyright (C) 1988 - 1990 Vestronix Inc. */
- /* Modification to this source is not supported */
- /* by Vestronix Inc. */
- /* All Rights Reserved */
- /* ----------------------------------------------- */
- /* Written Nig 1-Jan-87 */
- /* Modified Bob 30-Jan-90 see comments below */
- /* ----------------------------------------------- */
- /* %W% (%H% %T%) */
-
- /*
- * Modifications
- *
- * 11-Dec-89 Geo - V2 version
- * 25-Oct-89 Geo - 1.32 Merge
- * 23-Jan-90 Bob - general direction routine
- * 30-Jan-90 Bob - var-args (special verion of do_option for gensup)
- */
-
- # include <stdio.h>
- # include <ctype.h>
- # include <bench.h>
-
- # ifdef ANSI
- int keytrig(char *, int *);
- int get_direction(struct optab *, int, int);
- # else
- int keytrig();
- int get_direction();
- # endif
-
- extern int trigger_attr;
- extern int selattr;
-
- /*
- * Menu structure for selecting options
- * A simple list of row, col, and string
- * - the proceedure inits itself when the address
- * of the option table changes so it can be called
- * with different option lists
- * - the choice variable will be modified if it exceeds
- * the range of items available (cf. code)
- * - the list will terminate with a NULL, the row coord
- * is used as the normal attribute, the col coord is used
- * as the hi-light attribute
- */
-
-
- # ifdef UNIX
- int do_goptions(options, curfunc, helpnum, va_alist)
- struct optab options[];
- int curfunc, helpnum;
- va_dcl
- # else
- int do_goptions(struct optab options[], int curfunc, int helpnum, int va_alist, ...)
- # endif
- {
- va_list ap;
- int cc, iopt, oldfunc;
- int dummy; /* Used to keep dummy happy */
- int key;
- int save = curfunc;
-
- # ifdef MOUSE
- int r, c, w, h, optctr;
- # endif
-
- ichar = 0; /* clear ichar */
- dsp_opt(options, &curfunc);
-
- do
- {
- cc = inchar();
- if (cc <= 'z') /* Only do this if it is near [a-z] */
- if (islower(cc)) /* this should trap >8bit values ! */
- cc = toupper(cc);
-
- /*
- * get absolute window coordinates
- */
- # ifdef MOUSE
- abs_w(&r, &c, &w, &h);
- # endif
-
- for (iopt = 0; options[iopt].text != NULL; iopt++)
- {
- # ifdef MOUSE
- int key;
-
- key = (int)keytrig(options[iopt].text, &dummy);
-
- mouse_add_object(
- (unsigned char)r + options[iopt].row,
- (unsigned char)c + options[iopt].col,
- (unsigned char)r + options[iopt].row,
- (unsigned char)c + options[iopt].col +
- strlen(options[iopt].text + ((*options[iopt].text == '~') ? 1 : 0)) - 1, key, iopt, NULL);
- # endif
-
- if (keytrig(options[iopt].text, &dummy) == cc)
- {
- /* Reset the display and set this alight */
- selattr = TRUE;
- dsp_opt(options, &iopt);
- selattr = FALSE; /* Does nothing when UNIX is active */
- # ifdef MOUSE
- for (optctr = 0; options[optctr].text != NULL; optctr++)
- {
- int key;
-
- key = (int)keytrig(options[optctr].text, &dummy);
-
- mouse_delete_object(key, optctr, NULL);
- }
- # endif
- return(iopt);
- }
- }
-
- oldfunc = curfunc;
-
- switch (cc)
- {
- # ifdef MOUSE
- case M_PRESS :
- case M_RELEASE :
- if (mouse_row == w_nrows)
- mouse_click(&optctr, cc);
- else if (mouse_click(&curfunc, cc))
- dsp_opt(options, &curfunc);
- break;
- # endif
- case '?' :
- case K_HELP :
- help_msg(helpnum);
- break;
- case K_TAB :
- case K_ESC :
- ichar = cc; /* set ichar in case anyone's interested */
- return(-1);
-
- default :
- # ifdef UNIX
- va_start(ap);
- key = va_arg(ap, int);
- # else
- va_start(ap, va_alist);
- key = va_alist;
- # endif
- while (key != 0)
- {
- if (cc == key)
- {
- ichar = cc;
- /*
- selattr = TRUE;
- dsp_opt(options, &curfunc);
- selattr = FALSE;
- */
- # ifdef MOUSE
- for (optctr = 0; options[optctr].text != NULL; optctr++)
- {
- int key;
-
- key = (int)keytrig(options[optctr].text, &dummy);
-
- mouse_delete_object(key, optctr, NULL);
- }
- # endif
- return(-1);
- }
- key = va_arg(ap, int);
- }
- va_end(ap);
-
- switch(cc)
- {
- case ' ':
- cc = K_RIGHT;
- case K_DOWN :
- case K_UP :
- case K_RIGHT :
- case K_LEFT :
- /*
- * find the next element base on the key pressed
- */
- curfunc = get_direction(options, curfunc, cc);
- dsp_opt(options, &curfunc);
- break;
- }
- break;
- }
- }
- while (cc != K_CR && cc != K_ESC && cc != K_TAB);
-
- ichar = cc;
-
- /* Reset the display and set this alight */
- selattr = TRUE;
- dsp_opt(options, &curfunc);
- selattr = FALSE;
-
- # ifdef MOUSE
- for (optctr = 0; options[optctr].text != NULL; optctr++)
- {
- int key;
-
- key = (int)keytrig(options[optctr].text, &dummy);
-
- mouse_delete_object(key, optctr, NULL);
- }
- # endif
- return(curfunc);
- }
-
-