Example #1
0
int getcommand(char *msgstr, char *comstr)
/* Reads in a command and acts on it */
{
 int ch, counter, len = strlen(msgstr);

 scroll(UP, 0, 1, 24, 80, 24, WHITE);
 for (counter = 0; counter < len; counter++)
 {
  if (isupper(msgstr[counter]))
   writef(counter + 1, 24, COMMANDCOLOR, 1, "%c", msgstr[counter]);
  else
   writef(counter + 1, 24, LOWCOMMANDCOLOR, 1, "%c", msgstr[counter]);
 }
 do
  ch = toupper(getkey());
 while ((strchr(comstr, ch) == NULL) && (ch != ESC));
 clearinput();
 return((ch == ESC) ? -1 : strlen(comstr) - strlen(strchr(comstr, ch)));
} /* getcommand */
Example #2
0
/* Allows the user to edit a string with only certain characters allowed -
    Returns TRUE if ESC was not pressed, FALSE is ESC was pressed. */
int editstring(char *s, char *legal, int maxlength)
{
    int c, len = strlen(s), pos = len, insert = TRUE;

    changecursor(insert);
    do {
        writef(1, 25, WHITE, 79, "%s", s);
        gotoxy(pos + 1, 25);
        switch(c = getkey()) {
        case HOMEKEY :
            pos = 0;
            break;
        case ENDKEY :
            pos = len;
            break;
        case INSKEY :
            insert = !insert;
            changecursor(insert);
            break;
        case LEFTKEY :
            if (pos > 0)
                pos--;
            break;
        case RIGHTKEY :
            if (pos < len)
                pos++;
            break;
        case BS :
            if (pos > 0) {
                movmem(&s[pos], &s[pos - 1], len - pos + 1);
                pos--;
                len--;
            }
            break;
        case DELKEY :
            if (pos < len) {
                movmem(&s[pos + 1], &s[pos], len - pos);
                len--;
            }
            break;
        case CR :
            break;
        case UPKEY :
            break;
        case DOWNKEY :
            break;
        case ESC :
            break;
        default :
            if (((legal[0] == 0) || (strchr(legal, c) != NULL)) &&
                    ((c >= ' ') && (c <= '~')) &&
                    (len < maxlength)) {
                if (insert) {
                    memmove(&s[pos + 1], &s[pos], len - pos + 1);
                    len++;
                }
                else if (pos >= len)
                    len++;
                s[pos++] = c;
            }
            break;
        } /* switch */
        s[len] = 0;
    }
    while ((c!=UPKEY)&&(c!=DOWNKEY)&&(c!=CR)&&(c!=ESC));
    clearinput();
    changecursor(FALSE);
    setcursor(nocursor);
    return(c != ESC);
} /* editstring */