1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
|
/*
* prompt utils
*
* $Id: prm.c,v 1.2 2004/05/08 21:01:41 jon Exp $
*
* Copyright 1999-2004 Jon Trulson under the ARTISTIC LICENSE. (See LICENSE).
*/
#include "c_defs.h"
#include "global.h"
#include "datatypes.h"
#include "color.h"
#include "gldisplay.h"
#include "glmisc.h"
#include "prm.h"
int prmProcInput(prm_t *prm, int ch)
{
char c = (ch & 0xff); /* 8bit equiv */
int clen = strlen(prm->buf);
if (c_index ( prm->terms, ch ) != ERR)
return ch; /* you're terminated */
if ((clen >= (prm->buflen - 1)) && isprint(c))
return PRM_MAXLEN; /* buf is full */
/* check for preinit */
if (prm->preinit && ch != TERM_NORMAL && ch != TERM_EXTRA && isprint(c))
{
prm->buf[0] = c;
prm->buf[1] = 0;
prm->preinit = False;
return PRM_OK;
}
/* editing */
if ( ch == '\b' || ch == 0x7f || ch == KEY_BACKSPACE )
{
if ( clen > 0 )
{
clen--;
prm->buf[clen] = EOS;
return PRM_OK;
}
}
else if ( ch == 0x17 ) /* ^W */
{
/* Delete the last word. */
if ( clen > 0 )
{
/* Back up over blanks. */
while ( clen >= 0 )
if ( prm->buf[clen] == ' ' )
clen--;
else
break;
/* Back up over non-blanks. */
while ( clen >= 0 )
if ( prm->buf[clen] == ' ' )
break;
else
clen--;
if (clen < 0 )
{
clen = 0;
}
prm->buf[clen] = EOS;
}
}
else if ( ch == 0x15 || ch == 0x18 ) /* ^U || ^X - clear line */
{
if ( clen > 0 )
{
clen = 0;
prm->buf[clen] = EOS;
}
}
else if (!isprint(c))
mglBeep();
else
{
prm->buf[clen] = c;
prm->buf[clen + 1] = EOS;
}
return PRM_OK;
}
|