#include "metasets.h" #define MAP_EMPTY -2 /* map entry not set */ /* t_keymap(key) / tennis library (T. Garrard 1/92) * * The key is a 16-bit integer, which contains a 2-character * string representing a particular set. Keymap() maps the * key according to two cases: * * 1) Keys that are all alpha characters are mapped into an * index (nset) into the setdscr structure array, which * holds the set's defining parameters. * 2) Keys made up of special characters (see csqueeze * below) are mapped into the set length (setlen). * * The map values are stored in one of 2 arrays: in user_map, * as 8-bits, for case 1, and in reserve_map, as 16-bits, for * case 2. All map values are returned to the calling routines * as 32-bit integers. */ char user_map[52][52]; short reserve_map[22][22]; int t_keymap(key) short key;{ char *p; int i,j,n; p= (char*)&key; i= t_csqueeze(*p++); /* 1st char (particular) */ j= t_csqueeze(*p); /* 2nd char (project) */ if(i<0 || j<0) n= T_ERR; else if(i<=51 && j<=51) n= (int)user_map[i][j]; else if(i>=52 && j>=52) n= (int)reserve_map[i-52][j-52]; else n= T_ERR; return(n); } /* --------------------------------------------------------------------- */ /* t_setkeymap / tennis library * * Setkeymap() allows for the dynamic initialization * of user_map and reserve_map. Key specifies which * map element, and nval is the map value, either a * setdscr index or a set length as described above * for keymap(). * Again, user_map corresponds to keys that are all * alpha, and reserve_map, to those that have special * characters. * * Setkeymap is normally called, by getset(), after * reading in new set descriptors (set 0!) or, by * putset(), before writing out new sets. */ int t_setkeymap(key,nval) short key; int nval;{ char *p; int i,j,n; p= (char*)&key; i= t_csqueeze(*p++); /* 1st char (particular) */ j= t_csqueeze(*p); /* 2nd char (project) */ n= 0; if(i<0 || j<0) n= T_ERR; else if(i<=51 && j<=51) user_map[i][j]= (char)nval; else if(i>=52 && j>=52) reserve_map[i-52][j-52]= (short)nval; else n= T_ERR; return(n); } /* --------------------------------------------------------------------- */ /* t_csqueeze / tennis library: * Maps c -> code, as specified by the following * table; chars not in the table return -1(error). * * c ascii code c ascii code * - ----- ---- - ----- ---- * a 0141 0 : 0072 62 * b 0142 1 [ 0133 63 * ... ... ... ] 0135 64 * z 0172 25 ? 0077 65 * A 0101 26 @ 0100 66 * B 0102 27 ! 0041 67 * ... ... ... $ 0044 68 * Z 0132 51 % 0045 69 * 0 0060 52 & 0046 70 * 1 0061 53 * 0052 71 * ... ... ... + 0053 72 * 9 0071 61 / 0057 73 */ int t_csqueeze(c) char c;{ int code; if((c >= 'a')&&(c <= 'z')) code= c-'a'; else if((c >= 'A')&&(c <= 'Z')) code= c-'A'+26; else if((c >= '0')&&(c <= ':')) code= c-'0'+52; else switch(c){ case '[': code= 63; break; case ']': code= 64; break; case '?': code= 65; break; case '@': code= 66; break; case '!': code= 67; break; case '$': code= 68; break; case '%': code= 69; break; case '&': code= 70; break; case '*': code= 71; break; case '+': code= 72; break; case '/': code= 73; break; default : code= -1; break; } return(code); } /* --------------------------------------------------------------------- */ /* t_initkeymap() * Initialize map elements to MAP_EMPTY, indicating no entries for * setdscr[], or no lengths specified for meta sets. * As a special case, the reserve_map is presently used only for end of * tourney sets 'n]'. These are also initialized below. * * This is called at beginning of both get_set() and put_set(), before * the occurance of any other calls to setkeymap(). Note that only the 1st * call here is effective. */ t_initkeymap(){ static int kclear= 111; char *p; short skey; int i,j,n; if(kclear==111){ kclear= 0; for(i=0;i<52;i++){ /* clear maps */ for(j=0;j<52;j++) user_map[i][j]= MAP_EMPTY; /* -> map entry not set */ } for(i=0;i<22;i++){ for(j=0;j<22;j++) reserve_map[i][j]= MAP_EMPTY; } /* *** for(n=0;n<10;n++){ * set reserve_map * p= (char*)&skey; NOT NOW.... p[0]= '0'+n; p[1]= ']'; t_setkeymap(skey,EOTLEN); * key 0]-9] setlen * } *** */ } } /* --------------------------------------------------------------------- */