예제 #1
0
/*
 * set a string option
 */
int
get_str(void *vopt, WINDOW *win)
{
    char *opt = (char *) vopt;
    char *sp;
    int c, oy, ox;
    char buf[80];

    PC_GFX_SET_CURSOR(1);
    draw(win);
    getyx(win, oy, ox);
    /*
     * loop reading in the string, and put it in a temporary buffer
     */
    for (sp = buf;
	(c = readchar(win)) != '\n' && c != '\r' && c != '\033' && c != '\007';
	wclrtoeol(win), draw(win))
    {
	if (c == -1)
	    continue;
	else if (c == md_erasechar())	/* process erase character */
	{
	    if (sp > buf)
	    {
		int i;
		int myx, myy;

		sp--;

		for (i = (int) strlen(unctrl(*sp)); i; i--)
		{
		    getyx(win,myy,myx);
		    if ((myx == 0)&& (myy > 0))
		    {
			wmove(win,myy-1,getmaxx(win)-1);
			waddch(win,' ');
			wmove(win,myy-1,getmaxx(win)-1);
		    }
		    else
			waddch(win, '\b');
		}
	    }
	    continue;
	}
	else if (c == md_killchar())	/* process kill character */
	{
	    sp = buf;
	    wmove(win, oy, ox);
	    continue;
	}
	else if (sp == buf)
	    if (c == '-')
		break;
	    else if (c == '~')
	    {
		strcpy(buf, home);
		waddstr(win, home);
		sp += strlen(home);
		continue;
	    }

	if ((sp - buf) < 78) /* Avoid overflow */
	{
	    *sp++ = c;
	    waddstr(win, unctrl(c));
	}
    }
    *sp = '\0';
    if (sp > buf)	/* only change option if something has been typed */
	strucpy(opt, buf, strlen(buf));
    wmove(win, oy, ox);
    waddstr(win, opt);
    waddch(win, '\n');
    draw(win);
    if (win == cw)
	mpos += (int)(sp - buf);
    PC_GFX_SET_CURSOR(0);
    if (c == '-')
	return MINUS;
    else if (c == '\033' || c == '\007')
	return QUIT;
    else
	return NORM;
}
 /*
  * set a string option
  */
 int
 get_str(void *vp, WINDOW *win)
 {
     char *opt = (char *) vp;
     register char *sp;
     register int c, oy, ox;
     char buf[LINELEN];
     
	 *opt = 0;
     
	 draw(win);
     getyx(win, oy, ox);
     /*
      * loop reading in the string, and put it in a temporary buffer
      */
     for (sp = buf;
 	(c = readchar(win)) != '\n'	&& 
 	c != '\r'			&& 
 	c != '\033'			&& 
 	c != '\007'			&&
 	sp < &buf[LINELEN-1];
 	wclrtoeol(win), draw(win))
     {
 	if (c == -1)
 	    continue;
 	else if (c == md_erasechar()) /* process erase character */
 	{
 	    if (sp > buf)
 	    {
 		register size_t i;
 
 		sp--;
 		for (i = strlen(unctrl(*sp)); i; i--)
 		    waddch(win, '\b');
 	    }
 	    continue;
 	}
 	else if (c == md_killchar())  /* process kill character */
 	{
 	    sp = buf;
 	    wmove(win, oy, ox);
 	    continue;
 	}
 	else if (sp == buf)
	{
 	    if (c == '-' && win == hw)	/* To move back a line in hw */
 		break;
 	    else if (c == '~')
 	    {
 		strcpy(buf, home);
 		waddstr(win, home);
 		sp += strlen(home);
 		continue;
 	    }
 	}
	*sp++ = (char) c;
 	waddstr(win, unctrl(c));
     }
     *sp = '\0';
     if (sp > buf)	/* only change option if something has been typed */
 	strucpy(opt, buf, strlen(buf));
     wmove(win, oy, ox);
     waddstr(win, opt);
     waddch(win, '\n');
     draw(win);
     if (win == cw)
 	mpos += (int)(sp - buf);
     if (c == '-')
 	return MINUS;
     else if (c == '\033' || c == '\007')
 	return QUIT;
     else
 	return NORM;
 }