home *** CD-ROM | disk | FTP | other *** search
/ Jason Aller Floppy Collection / 125.img / PRO-C4.ZIP / BENCH1.ZIP / BENCH / SELKEY.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-06-05  |  3.5 KB  |  170 lines

  1. /* ==( bench/selkey.c )== */
  2.  
  3. /* ----------------------------------------------- */
  4. /* Pro-C  Copyright (C) 1988 - 1990 Vestronix Inc. */
  5. /* Modification to this source is not supported    */
  6. /* by Vestronix Inc.                               */
  7. /*            All Rights Reserved                  */
  8. /* ----------------------------------------------- */
  9. /* Written   Nig   1-Jan-87                        */
  10. /* Modified  Geo  11-Dec-89  See comments below    */
  11. /* ----------------------------------------------- */
  12. /* %W%  (%H% %T%) */
  13.  
  14. /*
  15.  *  Modifications
  16.  *
  17.  *  11-Dec-89  Geo - V2 version
  18.  *  25-Oct-89  Geo - 1.32 Merge
  19. */
  20.  
  21. /*
  22.  *     This routine is responsible for determining which key field will
  23.  * be used to access a data file
  24. */
  25. # include <stdio.h>
  26. # include <bench.h>
  27.  
  28. # define MAXKEYS 64
  29. # define MAXDEP  10
  30.  
  31. int selectkey(keys, numkeys, title, curfunc, match)
  32. char    *keys[];
  33. int    numkeys, curfunc;
  34. char *title;
  35. int  *match;
  36. {
  37.    int i, j, k;
  38.    int smax, tlen;
  39.    int slen;
  40.     int again, wid;
  41.     int cfunc;
  42.  
  43.     static struct optab options[MAXKEYS + 1];
  44.     static int handle = 0;
  45.  
  46.     if( numkeys == 1 )
  47.     {
  48.         if( *match >= 0 )
  49.             match_type(10, 30, match);
  50.         return(curfunc + 1);
  51.     }
  52.  
  53.    for (i = 0, smax = 0; i < numkeys; i++)
  54.    {
  55.       if ((slen = strlen(keys[i])) > smax)
  56.          smax = slen;
  57.    }
  58.  
  59.    /*
  60.     * No big deal. We know there is more than 1 key to display.
  61.     * So create the key display window and let them select it.
  62.    */
  63.     do
  64.     {
  65.         again = FALSE;
  66.  
  67.        for (i = 0, j = 0, k = 0; i < numkeys; k++, i++)
  68.        {
  69.             if (k == MAXDEP)  /* Max number of keys in one column */
  70.             {
  71.                 k = 0;
  72.                 j++;
  73.             }
  74.  
  75.             options[i].row = 2 + k;
  76.            options[i].col = 2 + (j * (smax + 1));
  77.           options[i].text = keys[i];
  78.        }
  79.         options[i].row = NORMAL;
  80.         options[i].col = REVVID;
  81.        options[i].text = NULL;
  82.  
  83.         /*
  84.         * If there are too many keys for the screen, then truncate
  85.         * the really long ones to ten characters.
  86.         */
  87.         if (numkeys > 20)
  88.         {
  89.             for (i = 0; i < numkeys; i++)
  90.             {
  91.                 if (strlen(options[i].text) > 10)
  92.                 {
  93.                     again = TRUE;
  94.                     options[i].text[10] = '\0';
  95.                 }
  96.             }
  97.             smax = 10;
  98.         }
  99.     }
  100.     while(again);
  101.  
  102.     wid = 2 + j + ((j + 1) * smax);
  103.  
  104.     wid = ((tlen = strlen(title) + 2) > wid) ? tlen : wid;
  105.  
  106.     /*
  107.     * Box the key choices
  108.     */
  109.    ncreate_w(8, 40-wid/2, (numkeys > MAXDEP) ? MAXDEP + 2 : numkeys + 2, wid, &handle);
  110.    border_w(boxset, BOLD);
  111.  
  112.     center_w(1, 1, BOLD, wid, title);
  113.  
  114.     cfunc = curfunc;
  115.  
  116.     curfunc = do_options(options, cfunc, 2);
  117.    delete_w();
  118.  
  119.     if(curfunc != -1)
  120.         if( *match >= 0 )
  121.             match_type(10, 30, match);
  122.  
  123.     if(curfunc == -1)
  124.         curfunc = cfunc;
  125.  
  126.     return (curfunc + 1);
  127. }
  128.  
  129.  
  130. /*
  131.  * This routine permits the user to select the type of key matching
  132.  * they would like to have.
  133. */
  134. static int match_type(row, col, keymatch)
  135. int row, col;
  136. int *keymatch;
  137. {
  138. char *title = " Type of Key Match ";
  139. static struct optab options[] =
  140. {
  141.    {2, 2, "Partial Key Match"},
  142.    {3, 2, "Exact Key Match"},
  143.    {NORMAL, REVVID, NULL}
  144. };
  145. static int curfunc = 0;
  146. static int handle = 0;
  147.  
  148.    ncreate_w(row, col, 4, 21, &handle);
  149.    border_w(boxset, BOLD);
  150.  
  151.    center_w(1, 1, BOLD, 21, title);
  152.  
  153.     curfunc = do_options(options, curfunc, 3);
  154.    delete_w();
  155.  
  156.    if (curfunc != -1)
  157.    {
  158.       /* User made a selection */
  159.         *keymatch = curfunc;
  160.       return(TRUE);
  161.    }
  162.    else
  163.    {
  164.       /* Escape pressed */
  165.       curfunc = 0;
  166.       return(FALSE);
  167.    }
  168. }
  169.  
  170.