static char rcsid[] = "$Id: xpandkey.c,v 1.2 1992/12/28 00:53:30 mike Exp $";

/* $Log: xpandkey.c,v $
 * Revision 1.2  1992/12/28  00:53:30  mike
 * - `ktoa' recognizes the `A-' prefix now.
 *
 * Revision 1.1  1992/09/14  13:02:14  mike
 * Initial revision
 *
 */

/* xpandkey.c : 
 * C Durland
 */

/* Copyright 1990, 1991 Craig Durland
 *   Distributed under the terms of the GNU General Public License.
 *   Distributed "as is", without warranties of any kind, but comments,
 *     suggestions and bug reports are welcome.
 */

#include "ed.h"

extern KeyCode Eprefixes[];
static void ktoa();

   /* Convert a KeyCode to a something that is printable.
    * Example output:  a, A, C-A, M-A, S-F-A, C-XC-C, etc.
    * Warning:  Make sure buf is NULL terminated BEFORE you call this!
    *   (because strcat() is used).
    */
void Expand_key(pkeys,keycode,buf) PKey *pkeys; KeyCode keycode; char *buf;
{
  register int j;

	/* check for PFIX1, 2 or 3.  META handled automatically. */
  for (j = 1; j<PKEYS; j++) if (Eprefixes[j] & keycode) ktoa(buf,pkeys[j]);
  ktoa(buf,keycode);
}

static void ktoa(buf,keycode) char *buf; KeyCode keycode;
{
  char foo[2];

  foo[1] = '\0';
  if (keycode & META)   strcat(buf,"M-");
#ifdef atarist
  if (keycode & PFIX2)  strcat(buf,"A-");
#endif
  if (keycode & SHIFT)  strcat(buf,"S-");
  if (keycode & CTRL)   strcat(buf,"C-");
  if (keycode & SOFKEY) strcat(buf,"F-");
  
  *foo = keycode & 0xFF;	/* get rid of modifier bits */
  strcat(buf,foo);
}  
