home *** CD-ROM | disk | FTP | other *** search
- /* ==( bench/selkey.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 Geo 11-Dec-89 See comments below */
- /* ----------------------------------------------- */
- /* %W% (%H% %T%) */
-
- /*
- * Modifications
- *
- * 11-Dec-89 Geo - V2 version
- * 25-Oct-89 Geo - 1.32 Merge
- */
-
- /*
- * This routine is responsible for determining which key field will
- * be used to access a data file
- */
- # include <stdio.h>
- # include <bench.h>
-
- # define MAXKEYS 64
- # define MAXDEP 10
-
- int selectkey(keys, numkeys, title, curfunc, match)
- char *keys[];
- int numkeys, curfunc;
- char *title;
- int *match;
- {
- int i, j, k;
- int smax, tlen;
- int slen;
- int again, wid;
- int cfunc;
-
- static struct optab options[MAXKEYS + 1];
- static int handle = 0;
-
- if( numkeys == 1 )
- {
- if( *match >= 0 )
- match_type(10, 30, match);
- return(curfunc + 1);
- }
-
- for (i = 0, smax = 0; i < numkeys; i++)
- {
- if ((slen = strlen(keys[i])) > smax)
- smax = slen;
- }
-
- /*
- * No big deal. We know there is more than 1 key to display.
- * So create the key display window and let them select it.
- */
- do
- {
- again = FALSE;
-
- for (i = 0, j = 0, k = 0; i < numkeys; k++, i++)
- {
- if (k == MAXDEP) /* Max number of keys in one column */
- {
- k = 0;
- j++;
- }
-
- options[i].row = 2 + k;
- options[i].col = 2 + (j * (smax + 1));
- options[i].text = keys[i];
- }
- options[i].row = NORMAL;
- options[i].col = REVVID;
- options[i].text = NULL;
-
- /*
- * If there are too many keys for the screen, then truncate
- * the really long ones to ten characters.
- */
- if (numkeys > 20)
- {
- for (i = 0; i < numkeys; i++)
- {
- if (strlen(options[i].text) > 10)
- {
- again = TRUE;
- options[i].text[10] = '\0';
- }
- }
- smax = 10;
- }
- }
- while(again);
-
- wid = 2 + j + ((j + 1) * smax);
-
- wid = ((tlen = strlen(title) + 2) > wid) ? tlen : wid;
-
- /*
- * Box the key choices
- */
- ncreate_w(8, 40-wid/2, (numkeys > MAXDEP) ? MAXDEP + 2 : numkeys + 2, wid, &handle);
- border_w(boxset, BOLD);
-
- center_w(1, 1, BOLD, wid, title);
-
- cfunc = curfunc;
-
- curfunc = do_options(options, cfunc, 2);
- delete_w();
-
- if(curfunc != -1)
- if( *match >= 0 )
- match_type(10, 30, match);
-
- if(curfunc == -1)
- curfunc = cfunc;
-
- return (curfunc + 1);
- }
-
-
- /*
- * This routine permits the user to select the type of key matching
- * they would like to have.
- */
- static int match_type(row, col, keymatch)
- int row, col;
- int *keymatch;
- {
- char *title = " Type of Key Match ";
- static struct optab options[] =
- {
- {2, 2, "Partial Key Match"},
- {3, 2, "Exact Key Match"},
- {NORMAL, REVVID, NULL}
- };
- static int curfunc = 0;
- static int handle = 0;
-
- ncreate_w(row, col, 4, 21, &handle);
- border_w(boxset, BOLD);
-
- center_w(1, 1, BOLD, 21, title);
-
- curfunc = do_options(options, curfunc, 3);
- delete_w();
-
- if (curfunc != -1)
- {
- /* User made a selection */
- *keymatch = curfunc;
- return(TRUE);
- }
- else
- {
- /* Escape pressed */
- curfunc = 0;
- return(FALSE);
- }
- }
-
-