home *** CD-ROM | disk | FTP | other *** search
/ Jason Aller Floppy Collection / 125.img / PRO-C4.ZIP / BENCH1.ZIP / GENSUP / GOPTION.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-05-28  |  4.8 KB  |  218 lines

  1. /* ==( bench/goption.c )== */
  2. /* ----------------------------------------------- */
  3. /* Pro-C  Copyright (C) 1988 - 1990 Vestronix Inc. */
  4. /* Modification to this source is not supported    */
  5. /* by Vestronix Inc.                               */
  6. /*            All Rights Reserved                  */
  7. /* ----------------------------------------------- */
  8. /* Written   Nig   1-Jan-87                        */
  9. /* Modified  Bob  30-Jan-90  see comments below    */
  10. /* ----------------------------------------------- */
  11. /* %W%  (%H% %T%) */
  12.  
  13. /*
  14.  * Modifications
  15.  *
  16.  * 11-Dec-89 Geo - V2 version
  17.  * 25-Oct-89 Geo - 1.32 Merge
  18.  * 23-Jan-90 Bob - general direction routine
  19.  * 30-Jan-90 Bob - var-args (special verion of do_option for gensup)
  20. */
  21.  
  22. # include <stdio.h>
  23. # include <ctype.h>
  24. # include <bench.h>
  25.  
  26. # ifdef ANSI
  27. int keytrig(char *, int *);
  28. int get_direction(struct optab *, int, int);
  29. # else
  30. int keytrig();
  31. int get_direction();
  32. # endif
  33.  
  34. extern int trigger_attr;
  35. extern int selattr;
  36.  
  37. /*
  38.  * Menu structure for selecting options
  39.  * A simple list of row, col, and string
  40.  * - the proceedure inits itself when the address
  41.  *   of the option table changes so it can be called
  42.  *   with different option lists
  43.  * - the choice variable will be modified if it exceeds
  44.  *   the range of items available (cf. code)
  45.  * - the list will terminate with a NULL, the row coord
  46.  *   is used as the normal attribute, the col coord is used
  47.  *   as the hi-light attribute
  48. */
  49.  
  50.  
  51. # ifdef UNIX
  52. int do_goptions(options, curfunc, helpnum, va_alist)
  53. struct optab options[];
  54. int curfunc, helpnum;
  55. va_dcl
  56. # else
  57. int do_goptions(struct optab options[], int curfunc, int helpnum, int va_alist, ...)
  58. # endif
  59. {
  60.     va_list ap;
  61.     int cc, iopt, oldfunc;
  62.     int dummy; /* Used to keep dummy happy */
  63.     int key;
  64.     int save = curfunc;
  65.  
  66. # ifdef MOUSE
  67.     int r, c, w, h, optctr;
  68. # endif
  69.  
  70.     ichar = 0; /* clear ichar */
  71.     dsp_opt(options, &curfunc);
  72.  
  73.     do
  74.     {
  75.         cc = inchar();
  76.         if (cc <= 'z') /* Only do this if it is near [a-z] */
  77.             if (islower(cc)) /* this should trap >8bit values ! */
  78.                 cc = toupper(cc);
  79.  
  80.         /*
  81.         * get absolute window coordinates
  82.         */
  83. # ifdef MOUSE
  84.         abs_w(&r, &c, &w, &h);
  85. # endif
  86.  
  87.         for (iopt = 0; options[iopt].text != NULL; iopt++)
  88.         {
  89. # ifdef MOUSE
  90.         int key;
  91.  
  92.             key = (int)keytrig(options[iopt].text, &dummy);
  93.  
  94.             mouse_add_object(
  95.                 (unsigned char)r + options[iopt].row, 
  96.                 (unsigned char)c + options[iopt].col, 
  97.                 (unsigned char)r + options[iopt].row, 
  98.                 (unsigned char)c + options[iopt].col +
  99.                 strlen(options[iopt].text + ((*options[iopt].text == '~') ? 1 : 0)) - 1, key, iopt, NULL);
  100. # endif
  101.  
  102.             if (keytrig(options[iopt].text, &dummy) == cc)
  103.             {
  104.                 /* Reset the display and set this alight */
  105.                 selattr = TRUE;
  106.                 dsp_opt(options, &iopt);
  107.                 selattr = FALSE; /* Does nothing when UNIX is active */
  108. # ifdef MOUSE
  109.                 for (optctr = 0; options[optctr].text != NULL; optctr++)
  110.                 {
  111.                     int key;
  112.  
  113.                     key = (int)keytrig(options[optctr].text, &dummy);
  114.  
  115.                     mouse_delete_object(key, optctr, NULL);
  116.                 }
  117. # endif
  118.                 return(iopt);
  119.             }
  120.         }
  121.  
  122.         oldfunc = curfunc;
  123.  
  124.         switch (cc)
  125.         {
  126. # ifdef MOUSE
  127.         case M_PRESS :
  128.         case M_RELEASE :
  129.             if (mouse_row == w_nrows)
  130.                 mouse_click(&optctr, cc);
  131.             else if (mouse_click(&curfunc, cc))
  132.                 dsp_opt(options, &curfunc);
  133.             break;
  134. # endif
  135.         case '?' :
  136.         case K_HELP :
  137.             help_msg(helpnum);
  138.             break;
  139.         case K_TAB :
  140.         case K_ESC :
  141.             ichar = cc; /* set ichar in case anyone's interested */
  142.             return(-1);
  143.  
  144.         default :
  145. # ifdef UNIX
  146.             va_start(ap);
  147.             key = va_arg(ap, int);
  148. # else
  149.             va_start(ap, va_alist);
  150.             key = va_alist;
  151. # endif
  152.             while (key != 0)
  153.             {
  154.                 if (cc == key)
  155.                 {
  156.                     ichar = cc;
  157.                     /*
  158.                     selattr = TRUE;
  159.                     dsp_opt(options, &curfunc);
  160.                     selattr = FALSE; 
  161.                     */
  162. # ifdef MOUSE
  163.                     for (optctr = 0; options[optctr].text != NULL; optctr++)
  164.                     {
  165.                         int key;
  166.                 
  167.                         key = (int)keytrig(options[optctr].text, &dummy);
  168.                 
  169.                         mouse_delete_object(key, optctr, NULL);
  170.                     }
  171. # endif
  172.                     return(-1);
  173.                 }
  174.                 key = va_arg(ap, int);
  175.             }
  176.             va_end(ap);
  177.  
  178.             switch(cc)
  179.             {
  180.             case ' ':
  181.                 cc = K_RIGHT;
  182.             case K_DOWN :
  183.             case K_UP :
  184.             case K_RIGHT :
  185.             case K_LEFT :
  186.                 /*
  187.                 * find the next element base on the key pressed 
  188.                 */
  189.                 curfunc = get_direction(options, curfunc, cc);
  190.                 dsp_opt(options, &curfunc);
  191.                 break;
  192.             }
  193.             break;
  194.         }
  195.     }
  196.     while (cc != K_CR && cc != K_ESC && cc != K_TAB);
  197.  
  198.     ichar = cc;
  199.  
  200.     /* Reset the display and set this alight */
  201.     selattr = TRUE;
  202.     dsp_opt(options, &curfunc);
  203.     selattr = FALSE; 
  204.     
  205. # ifdef MOUSE
  206.     for (optctr = 0; options[optctr].text != NULL; optctr++)
  207.     {
  208.         int key;
  209.  
  210.         key = (int)keytrig(options[optctr].text, &dummy);
  211.  
  212.         mouse_delete_object(key, optctr, NULL);
  213.     }
  214. # endif
  215.     return(curfunc);
  216. }
  217.  
  218.