Beispiel #1
0
CARD
getcard()
{
	int	c, c1;

	for (;;) {
		while ((c = readch()) == '\n' || c == '\r' || c == ' ')
			continue;
		if (islower(c))
			c = toupper(c);
		if (c == killchar() || c == erasechar())
			return -1;
		addstr(unctrl(c));
		clrtoeol();
		switch (c) {
		  case '1':	case '2':	case '3':
		  case '4':	case '5':	case '6':
			c -= '0';
			break;
		  case '0':	case 'P':	case 'p':
			c = 0;
			break;
		  default:
			beep();
			addch('\b');
			if (!isprint(c))
				addch('\b');
			c = -1;
			break;
		}
		refresh();
		if (c >= 0) {
			while ((c1 = readch()) != '\r' && c1 != '\n' && c1 != ' ')
				if (c1 == killchar())
					return -1;
				else if (c1 == erasechar()) {
					addch('\b');
					clrtoeol();
					refresh();
					goto cont;
				}
				else
					beep();
			return c;
		}
cont:		;
	}
}
Beispiel #2
0
int
getline(char s[], size_t size, int firstchar, BOOL iscaseless)
{
	int	c, i = 0;
	int	j;

	/* if a character already has been typed */
	if (firstchar != '\0') {
		if (iscaseless == YES) {
			firstchar = tolower(firstchar);
		}
		(void) addch((unsigned)firstchar);	/* display it */
		s[i++] = firstchar;	/* save it */
	}
	/* until the end of the line is reached */
	while ((c = mygetch()) != '\r' && c != '\n' && c != KEY_ENTER &&
	    c != '\003' && c != KEY_BREAK) {
		if (c == erasechar() || c == '\b' ||		/* erase */
		    c == KEY_BACKSPACE) {
			if (i > 0) {
				(void) addstr("\b \b");
				--i;
			}
		} else if (c == killchar()) {			/* kill */
			for (j = 0; j < i; ++j) {
				(void) addch('\b');
			}
			for (j = 0; j < i; ++j) {
				(void) addch(' ');
			}
			for (j = 0; j < i; ++j) {
				(void) addch('\b');
			}
			i = 0;
		} else if (isprint(c) || c == '\t') {		/* printable */
			if (iscaseless == YES) {
				c = tolower(c);
			}
			/* if it will fit on the line */
			if (i < size) {
				(void) addch((unsigned)c);	/* display it */
				s[i++] = c;		/* save it */
			}
		} else if (c == ctrl('X')) {
			/* mouse */
			(void) getmouseevent(); 	/* ignore it */
		} else if (c == EOF) {			/* end-of-file */
			break;
		}
		/* return on an empty line to allow a command to be entered */
		if (firstchar != '\0' && i == 0) {
			break;
		}
	}
	s[i] = '\0';
	return (i);
}
erasewchar(wchar_t * wch)
{
    int value;
    int result = ERR;

    T((T_CALLED("erasewchar()")));
    if ((value = erasechar()) != ERR) {
	*wch = value;
	result = OK;
    }
    returnCode(result);
}
Beispiel #4
0
int main(void)
{
	char ch;

	initscr();

	ch = erasechar();
	printw("The Erasechar is 0x%02x or %s\n",ch,unctrl(ch));
	refresh();
	getch();

	endwin();
	return 0;
}
Beispiel #5
0
/*
 * get_line:
 *      Reads the next line up to '\n' or EOF.  Multiple spaces are
 *	compressed to one space; a space is inserted before a ','
 */
char *
get_line(void)
{
	size_t pos;
	int c, oy, ox;
	WINDOW *oscr;

	oscr = stdscr;
	stdscr = Msgwin;
	getyx(stdscr, oy, ox);
	refresh();
	/* loop reading in the string, and put it in a temporary buffer */
	for (pos = 0; (c = readchar()) != '\n'; clrtoeol(), refresh()) {
		if (c == -1)
			continue;
		if (c == ' ' && (pos == 0 || linebuf[pos - 1] == ' '))
			continue;
		if (c == erasechar()) {
			if (pos > 0) {
				int i;
				pos--;
				for (i = strlen(unctrl(linebuf[pos])); i; i--)
					addch('\b');
			}
			continue;
		}
		if (c == killchar()) {
			pos = 0;
			move(oy, ox);
			continue;
		}
		if (pos >= LINESIZE - 1 || !(isalnum(c) || c == ' ')) {
			beep();
			continue;
		}
		if (islower(c))
			c = toupper(c);
		linebuf[pos++] = c;
		addstr(unctrl(c));
		Mpos++;
	}
	while (pos < sizeof(linebuf))
		linebuf[pos++] = '\0';
	stdscr = oscr;
	return (linebuf);
}
Beispiel #6
0
/*
 * get_line:
 *      Reads the next line up to '\n' or EOF.  Multiple spaces are
 *	compressed to one space; a space is inserted before a ','
 */
char *
get_line(void)
{
	size_t pos;
	int c, oy, ox;
	WINDOW *oscr;

	oscr = stdscr;
	stdscr = Msgwin;
	getyx(stdscr, oy, ox);
	refresh();
	/* loop reading in the string, and put it in a temporary buffer */
	for (pos = 0; (c = readchar()) != '\n'; clrtoeol(), refresh()) {
			if (c == erasechar()) {	/* process erase character */
				if (pos > 0) {
					int i;

					pos--;
					for (i = strlen(unctrl(linebuf[pos])); i; i--)
						addch('\b');
				}
				continue;
			} else
				if (c == killchar()) {	/* process kill
							 * character */
					pos = 0;
					move(oy, ox);
					continue;
				} else
					if (pos == 0 && c == ' ')
						continue;
		if (pos >= LINESIZE - 1 || !(isprint(c) || c == ' '))
			putchar(CTRL('G'));
		else {
			if (islower(c))
				c = toupper(c);
			linebuf[pos++] = c;
			addstr(unctrl(c));
			Mpos++;
		}
	}
	linebuf[pos] = '\0';
	stdscr = oscr;
	return (linebuf);
}
Beispiel #7
0
int weditstr(WINDOW *win, char *buf, int field)
{
    char org[MAXSTRLEN], *tp, *bp = buf;
    bool defdisp = TRUE, stop = FALSE, insert = FALSE;
    int cury, curx, begy, begx;
    chtype oldattr;
    WINDOW *wedit;
    int c = 0;

    if ((field >= MAXSTRLEN) || (buf == NULL) ||
        ((int)strlen(buf) > field - 1))
        return ERR;

    strcpy(org, buf);   /* save original */

    wrefresh(win);
    getyx(win, cury, curx);
    getbegyx(win, begy, begx);

    wedit = subwin(win, 1, field, begy + cury, begx + curx);
    oldattr = wedit->_attrs;
    colorbox(wedit, EDITBOXCOLOR, 0);

    keypad(wedit, TRUE);
    curs_set(1);

    while (!stop)
    {
        idle();
        repainteditbox(wedit, bp - buf, buf);

        switch (c = wgetch(wedit))
        {
        case ERR:
            break;

        case KEY_ESC:
            strcpy(buf, org);   /* restore original */
            stop = TRUE;
            break;

        case '\n':
        case KEY_UP:
        case KEY_DOWN:
            stop = TRUE;
            break;

        case KEY_LEFT:
            if (bp > buf)
                bp--;
            break;

        case KEY_RIGHT:
            defdisp = FALSE;
            if (bp - buf < (int)strlen(buf))
                bp++;
            break;

        case '\t':            /* TAB -- because insert
                                  is broken on HPUX */
        case KEY_IC:          /* enter insert mode */
        case KEY_EIC:         /* exit insert mode */
            defdisp = FALSE;
            insert = !insert;

            curs_set(insert ? 2 : 1);
            break;

        default:
            if (c == erasechar())       /* backspace, ^H */
            {
                if (bp > buf)
                {
                    memmove((void *)(bp - 1), (const void *)bp, strlen(bp) + 1);
                    bp--;
                }
            }
            else if (c == killchar())   /* ^U */
            {
                bp = buf;
                *bp = '\0';
            }
            else if (c == wordchar())   /* ^W */
            {
                tp = bp;

                while ((bp > buf) && (*(bp - 1) == ' '))
                    bp--;
                while ((bp > buf) && (*(bp - 1) != ' '))
                    bp--;

                memmove((void *)bp, (const void *)tp, strlen(tp) + 1);
            }
            else if (isprint(c))
            {
                if (defdisp)
                {
                    bp = buf;
                    *bp = '\0';
                    defdisp = FALSE;
                }

                if (insert)
                {
                    if ((int)strlen(buf) < field - 1)
                    {
                        memmove((void *)(bp + 1), (const void *)bp,
                                strlen(bp) + 1);

                        *bp++ = c;
                    }
                }
                else if (bp - buf < field - 1)
                {
                    /* append new string terminator */

                    if (!*bp)
                        bp[1] = '\0';

                    *bp++ = c;
                }
            }
        }
    }

    curs_set(0);

    wattrset(wedit, oldattr);
    repainteditbox(wedit, bp - buf, buf);
    delwin(wedit);

    return c;
}
Beispiel #8
0
static void
gnt_entry_class_init(GntEntryClass *klass)
{
	GntBindableClass *bindable = GNT_BINDABLE_CLASS(klass);
	char s[3] = {'\033', erasechar(), 0};

	parent_class = GNT_WIDGET_CLASS(klass);
	parent_class->clicked = gnt_entry_clicked;
	parent_class->destroy = gnt_entry_destroy;
	parent_class->draw = gnt_entry_draw;
	parent_class->map = gnt_entry_map;
	parent_class->size_request = gnt_entry_size_request;
	parent_class->key_pressed = gnt_entry_key_pressed;
	parent_class->lost_focus = gnt_entry_lost_focus;

	signals[SIG_TEXT_CHANGED] =
		g_signal_new("text_changed",
					 G_TYPE_FROM_CLASS(klass),
					 G_SIGNAL_RUN_LAST,
					 G_STRUCT_OFFSET(GntEntryClass, text_changed),
					 NULL, NULL,
					 g_cclosure_marshal_VOID__VOID,
					 G_TYPE_NONE, 0);

	signals[SIG_COMPLETION] =
		g_signal_new("completion",
					 G_TYPE_FROM_CLASS(klass),
					 G_SIGNAL_RUN_LAST,
					 0, NULL, NULL,
					 gnt_closure_marshal_VOID__POINTER_POINTER,
					 G_TYPE_NONE, 2, G_TYPE_POINTER, G_TYPE_POINTER);

	gnt_bindable_class_register_action(bindable, "cursor-home", move_start,
				GNT_KEY_CTRL_A, NULL);
	gnt_bindable_register_binding(bindable, "cursor-home", GNT_KEY_HOME, NULL);
	gnt_bindable_class_register_action(bindable, "cursor-end", move_end,
				GNT_KEY_CTRL_E, NULL);
	gnt_bindable_register_binding(bindable, "cursor-end", GNT_KEY_END, NULL);
	gnt_bindable_class_register_action(bindable, "delete-prev", backspace,
				GNT_KEY_BACKSPACE, NULL);
	gnt_bindable_register_binding(bindable, "delete-prev", s + 1, NULL);
	gnt_bindable_register_binding(bindable, "delete-prev", GNT_KEY_CTRL_H, NULL);
	gnt_bindable_class_register_action(bindable, "delete-next", delkey,
				GNT_KEY_DEL, NULL);
	gnt_bindable_register_binding(bindable, "delete-next", GNT_KEY_CTRL_D, NULL);
	gnt_bindable_class_register_action(bindable, "delete-start", del_to_home,
				GNT_KEY_CTRL_U, NULL);
	gnt_bindable_class_register_action(bindable, "delete-end", del_to_end,
				GNT_KEY_CTRL_K, NULL);
	gnt_bindable_class_register_action(bindable, "delete-prev-word", del_prev_word,
				GNT_KEY_CTRL_W, NULL);
	gnt_bindable_register_binding(bindable, "delete-prev-word", s, NULL);
	gnt_bindable_class_register_action(bindable, "cursor-prev-word", move_back_word,
				"\033" "b", NULL);
	gnt_bindable_class_register_action(bindable, "cursor-prev", move_back,
				GNT_KEY_LEFT, NULL);
	gnt_bindable_register_binding(bindable, "cursor-prev", GNT_KEY_CTRL_B, NULL);
	gnt_bindable_class_register_action(bindable, "cursor-next", move_forward,
				GNT_KEY_RIGHT, NULL);
	gnt_bindable_register_binding(bindable, "cursor-next", GNT_KEY_CTRL_F, NULL);
	gnt_bindable_class_register_action(bindable, "cursor-next-word", move_forward_word,
				"\033" "f", NULL);
	gnt_bindable_class_register_action(bindable, "delete-next-word", delete_forward_word,
				"\033" "d", NULL);
	gnt_bindable_class_register_action(bindable, "transpose-chars", transpose_chars,
				GNT_KEY_CTRL_T, NULL);
	gnt_bindable_class_register_action(bindable, "yank", entry_yank,
				GNT_KEY_CTRL_Y, NULL);
	gnt_bindable_class_register_action(bindable, "suggest-show", suggest_show,
				"\t", NULL);
	gnt_bindable_class_register_action(bindable, "suggest-next", suggest_next,
				GNT_KEY_DOWN, NULL);
	gnt_bindable_class_register_action(bindable, "suggest-prev", suggest_prev,
				GNT_KEY_UP, NULL);
	gnt_bindable_class_register_action(bindable, "suggest-next-page", suggest_next_page,
				GNT_KEY_PGDOWN, NULL);
	gnt_bindable_class_register_action(bindable, "suggest-prev-page", suggest_prev_page,
				GNT_KEY_PGUP, NULL);
	gnt_bindable_class_register_action(bindable, "history-next", history_next,
				GNT_KEY_CTRL_DOWN, NULL);
	gnt_bindable_class_register_action(bindable, "history-prev", history_prev,
				GNT_KEY_CTRL_UP, NULL);
	gnt_bindable_register_binding(bindable, "history-prev", GNT_KEY_CTRL_P, NULL);
	gnt_bindable_register_binding(bindable, "history-next", GNT_KEY_CTRL_N, NULL);
	gnt_bindable_class_register_action(bindable, "history-search", history_search,
				GNT_KEY_CTRL_R, NULL);
	gnt_bindable_class_register_action(bindable, "clipboard-paste", clipboard_paste,
				GNT_KEY_CTRL_V, NULL);

	gnt_style_read_actions(G_OBJECT_CLASS_TYPE(klass), GNT_BINDABLE_CLASS(klass));
	GNTDEBUG;
}
Beispiel #9
0
static int
keyboard_dispatch(int ch)
{

	if (ch == ERR) {
		if (errno == EINTR)
			return 0;
		exit(1);
	}
	if (ch >= 'A' && ch <= 'Z')
		ch += 'a' - 'A';
	if (col == 0) {
		if (ch == CTRL('l')) {
			wrefresh(curscr);
			return 0;
		}
		if (ch == CTRL('g')) {
			status();
			return 0;
		}
		if (ch != ':')
			return 0;
		move(CMDLINE, 0);
		clrtoeol();
	}
	if (ch == erasechar() && col > 0) {
		if (col == 1 && line[0] == ':')
			return 0;
		col--;
		goto doerase;
	}
	if (ch == CTRL('w') && col > 0) {
		while (--col >= 0 && isspace(line[col]))
			;
		col++;
		while (--col >= 0 && !isspace(line[col]))
			if (col == 0 && line[0] == ':')
				return 1;
		col++;
		goto doerase;
	}
	if (ch == killchar() && col > 0) {
		col = 0;
		if (line[0] == ':')
			col++;
doerase:
		move(CMDLINE, col);
		clrtoeol();
		return 0;
	}
	if (isprint(ch) || ch == ' ') {
		line[col] = ch;
		mvaddch(CMDLINE, col, ch);
		col++;
	}

	if (col == 0 || (ch != '\r' && ch != '\n'))
		return 0;

	return 1;
}
EIF_CHARACTER c_ecurses_erasechar ()
{
    return erasechar ();
};
Beispiel #11
0
/* get a line from the terminal in non-canonical mode */
int
mygetline(char p[], char s[], unsigned size, int firstchar, BOOL iscaseless)
{
    int	c;
    unsigned int i = 0, j;
    char *sright;	/* substring to the right of the cursor */
    unsigned int ri = 0;		/* position in right-string */

    /* Inserts and deletes are always performed on the left-string,
     * but we'll also have a right-string 'sright' to hold characters
     * which are on the right of the cursor [insertion point].
     *
     * Think of 'sright' as a stack -- we push chars into it when the cursor
     * moves left, and we pop chars off it when the cursor moves right again.
     * At the end of the function, we'll pop off any remaining characters
     * onto the end of 's'
     */
    sright = calloc(sizeof(char), size );

    strcpy ( s, p);
    i += strlen(p);
    /* if a character already has been typed */
    if (firstchar != '\0') {
	if(iscaseless == YES) {
	    firstchar = tolower(firstchar);
	}
	addch(firstchar);	/* display it */
	s[i++] = firstchar;	/* save it */
    }
    /* until the end of the line is reached */
    while ((c = mygetch()) != '\r' && c != '\n' && c != KEY_ENTER) {
	if (c == KEY_LEFT || c == ctrl('B')) {	/* left */
	    if (i > 0) {
		addch('\b');
		/* move this char into the second (rhs) string */
		sright[ri++] = s[--i];
	    }
	} else if (c == KEY_RIGHT || c == ctrl('F')) {	/* right */
	    if (i < size && ri > 0) {
		/* move this char to the left of the cursor */
		s[i++] = sright[--ri];
		addch(s[i-1]);
	    }
	} else if (
#ifdef KEY_HOME
		   c == KEY_HOME ||
#endif
		   c == ctrl('A') ) {
	    while (i > 0) {
		sright[ri++] = s[--i];
		addch('\b');
		addch(s[i]);
		addch('\b');
	    }
	} else if (
#ifdef KEY_END
		   c == KEY_END ||
#endif
		   c == ctrl('E') ) {
	    while (ri > 0) {
		s[i++] = sright[--ri];
		addch(s[i-1]);
	    }
	} else if (c == erasechar() || c == KEY_BACKSPACE
		   || c == DEL || c == ctrl('H') ) {
	    /* erase */
	    if (i > 0) {
		if (ri == 0)  {
		    addstr("\b \b");
		} else {
		    addch('\b');
		    delch();
		}
		s[i] = '\0';
		--i;
	    }
	} else if (c == killchar() || c == KEY_BREAK) {
	    /* kill */
	    for (j = 0; j < i; ++j) {
		addch('\b');
	    }
	    for (j = 0; j < i; ++j) {
		addch(' ');
	    }
	    for (j = 0; j < i; ++j) {
		addch('\b');
	    }
	    i = 0;
	} else if (isprint(c) || c == '\t') {
	    /* printable */
	    if(iscaseless == YES) {
		c = tolower(c);
	    }
	    /* if it will fit on the line */
	    if (i < size) {
		s[i++] = c;	/* save it */
		if (ri == 0) {
		    addch(c);	/* display it */
		} else {
		    insch(c);	/* display it */
		    addch(c);	/* advance cursor */
		}
	    }
#if UNIXPC
	} else if (unixpcmouse == YES && c == ESC) {	/* mouse */
	    getmouseaction(ESC);	/* ignore it */
#endif
	} else if (mouse == YES && c == ctrl('X')) {
	    getmouseaction(ctrl('X'));	/* ignore it */
	} else if (c == EOF) {				/* end-of-file */
	    break;
	}

	/* return on an empty line to allow a command to be entered */
	if (firstchar != '\0' && (i+ri) == 0) {
	    break;
	}
    }

    /* move any remaining chars on the rhs of the cursor
     * onto the end of our string
     */
    while (ri > 0) {
	s[i++] = sright[--ri];
    }
    free(sright);

    s[i] = '\0';
    return(i);
}
Beispiel #12
0
int
get_str(void *vopt, WINDOW *win)
{
    char *opt = (char *) vopt;
    char *sp;
    int oy, ox;
    int i;
    signed char c;
    static char buf[MAXSTR];

    getyx(win, oy, ox);
    wrefresh(win);
    /*
     * loop reading in the string, and put it in a temporary buffer
     */
    for (sp = buf; (c = readchar()) != '\n' && c != '\r' && c != ESCAPE;
	wclrtoeol(win), wrefresh(win))
    {
	if (c == -1)
	    continue;
	else if (c == erasechar() || c == 8 || c == 127)	/* process erase character */
	{
	    if (sp > buf)
	    {
		sp--;
		for (i = (int) strlen(unctrl(*sp)); i; i--)
		    waddch(win, '\b');
	    }
	    continue;
	}
	else if (c == killchar())	/* process kill character */
	{
	    sp = buf;
	    wmove(win, oy, ox);
	    continue;
	}
	else if (sp == buf)
	{
	    if (c == '-' && win != stdscr)
		break;
	    else if (c == '~')
	    {
		strcpy(buf, home);
		waddstr(win, home);
		sp += strlen(home);
		continue;
	    }
	}
	if (sp >= &buf[MAXINP] || !(isprint(c) || c == ' '))
	    putchar(CTRL('G'));
	else
	{
	    *sp++ = c;
	    waddstr(win, unctrl(c));
	}
    }
    *sp = '\0';
    if (sp > buf)	/* only change option if something has been typed */
	strucpy(opt, buf, (int) strlen(buf));
    mvwprintw(win, oy, ox, "%s\n", opt);
    wrefresh(win);
    if (win == stdscr)
	mpos += (int)(sp - buf);
    if (c == '-')
	return MINUS;
    else if (c == ESCAPE)
	return QUIT;
    else
	return NORM;
}
Beispiel #13
0
/***
Fetch the terminal's current erase character.
@function erasechar
@treturn int current erase character
@see erasechar(3x)
*/
static int
Perasechar(lua_State *L)
{
	return pushintresult(erasechar());
}
Beispiel #14
0
int
get_input(int prompt_position)
{
	struct view *view;
	int i, key, cursor_y, cursor_x;

	if (prompt_position)
		input_mode = TRUE;

	while (TRUE) {
		bool loading = FALSE;

		foreach_view (view, i) {
			update_view(view);
			if (view_is_displayed(view) && view->has_scrolled &&
			    use_scroll_redrawwin)
				redrawwin(view->win);
			view->has_scrolled = FALSE;
			if (view->pipe)
				loading = TRUE;
		}

		/* Update the cursor position. */
		if (prompt_position) {
			getbegyx(status_win, cursor_y, cursor_x);
			cursor_x = prompt_position;
		} else {
			view = display[current_view];
			getbegyx(view->win, cursor_y, cursor_x);
			cursor_x = view->width - 1;
			cursor_y += view->pos.lineno - view->pos.offset;
		}
		setsyx(cursor_y, cursor_x);

		/* Refresh, accept single keystroke of input */
		doupdate();
		nodelay(status_win, loading);
		key = wgetch(status_win);

		/* wgetch() with nodelay() enabled returns ERR when
		 * there's no input. */
		if (key == ERR) {

		} else if (key == KEY_RESIZE) {
			int height, width;

			getmaxyx(stdscr, height, width);

			wresize(status_win, 1, width);
			mvwin(status_win, height - 1, 0);
			wnoutrefresh(status_win);
			resize_display();
			redraw_display(TRUE);

		} else {
			input_mode = FALSE;
			if (key == erasechar())
				key = KEY_BACKSPACE;
			return key;
		}
	}
Beispiel #15
0
save() {

	reg char	*sp;
	reg int		outf;
	reg time_t	*tp;
	char		buf[80];
	time_t		tme;
	STAT		junk;

	tp = &tme;
	if (Fromfile && getyn(SAMEFILEPROMPT))
		strcpy(buf, Fromfile);
	else {
over:
		prompt(FILEPROMPT);
		leaveok(Board, FALSE);
		refresh();
		sp = buf;
		while ((*sp = readch()) != '\n') {
			if (*sp == killchar())
				goto over;
			else if (*sp == erasechar()) {
				if (--sp < buf)
					sp = buf;
				else {
					addch('\b');
					/*
					 * if the previous char was a control
					 * char, cover up two characters.
					 */
					if (*sp < ' ')
						addch('\b');
					clrtoeol();
				}
			}
			else
				addstr(unctrl(*sp++));
			refresh();
		}
		*sp = '\0';
		leaveok(Board, TRUE);
	}

	/*
	 * check for existing files, and confirm overwrite if needed
	 */

	if (sp == buf || (!Fromfile && stat(buf, &junk) > -1
	    && getyn(OVERWRITEFILEPROMPT) == FALSE))
		return FALSE;

	if ((outf = creat(buf, 0644)) < 0) {
		error(strerror(errno));
		return FALSE;
	}
	mvwaddstr(Score, ERR_Y, ERR_X, buf);
	wrefresh(Score);
	time(tp);			/* get current time		*/
	strcpy(buf, ctime(tp));
	for (sp = buf; *sp != '\n'; sp++)
		continue;
	*sp = '\0';
	varpush(outf, write);
	close(outf);
	wprintw(Score, " [%s]", buf);
	wclrtoeol(Score);
	wrefresh(Score);
	return TRUE;
}
Beispiel #16
0
/*
 * __wgetnstr --
 *	The actual implementation.
 *	Note that we include a trailing '\0' for safety, so str will contain
 *	at most n - 1 other characters.
 *	XXX: character deletion from screen is based on how the characters
 *	are displayed by wgetch().
 */
int
__wgetnstr(WINDOW *win, char *str, int n)
{
	char *ostr, ec, kc;
	int c, xpos, oldx, remain;

	ostr = str;
	ec = erasechar();
	kc = killchar();
	xpos = oldx = win->curx;
	_DIAGASSERT(n == -1 || n > 1);
	remain = n - 1;

	while ((c = wgetch(win)) != ERR && c != '\n' && c != '\r') {
#ifdef DEBUG
		__CTRACE(__CTRACE_INPUT,
		    "__wgetnstr: win %p, char 0x%x, remain %d\n",
		    win, c, remain);
#endif
		*str = c;
		touchline(win, win->cury, 1);
		if (c == ec || c == KEY_BACKSPACE || c == KEY_LEFT) {
			*str = '\0';
			if (str != ostr) {
				if ((char) c == ec) {
					mvwaddch(win, win->cury, xpos, ' ');
					if (xpos > oldx)
						mvwaddch(win, win->cury,
						    xpos - 1, ' ');
					if (win->curx > xpos - 1)
						wmove(win, win->cury, xpos - 1);
					xpos--;
				}
				if (c == KEY_BACKSPACE || c == KEY_LEFT) {
					/* getch() displays the key sequence */
					mvwaddch(win, win->cury, win->curx,
					    ' ');
					mvwaddch(win, win->cury, win->curx - 1,
					    ' ');
					if (win->curx > xpos)
						wmove(win, win->cury, xpos - 1);
					xpos--;
				}
				str--;
				if (n != -1) {
					/* We're counting chars */
					remain++;
				}
			} else {        /* str == ostr */
				/* getch() displays the other keys */
				if (win->curx > oldx)
					mvwaddch(win, win->cury, win->curx - 1,
					    ' ');
				wmove(win, win->cury, oldx);
				xpos = oldx;
			}
		} else if (c == kc) {
			*str = '\0';
			if (str != ostr) {
				/* getch() displays the kill character */
				mvwaddch(win, win->cury, win->curx - 1, ' ');
				/* Clear the characters from screen and str */
				while (str != ostr) {
					mvwaddch(win, win->cury, win->curx - 1,
					    ' ');
					wmove(win, win->cury, win->curx - 1);
					str--;
					if (n != -1)
						/* We're counting chars */
						remain++;
				}
				mvwaddch(win, win->cury, win->curx - 1, ' ');
				wmove(win, win->cury, win->curx - 1);
			} else
				/* getch() displays the kill character */
				mvwaddch(win, win->cury, oldx, ' ');
			wmove(win, win->cury, oldx);
		} else if (c >= KEY_MIN && c <= KEY_MAX) {
			/* getch() displays these characters */
			mvwaddch(win, win->cury, xpos, ' ');
			wmove(win, win->cury, xpos);
		} else {
			if (remain) {
				if (iscntrl((unsigned char)c))
					mvwaddch(win, win->cury, xpos, ' ');
				str++;
				xpos++;
				remain--;
			} else
				mvwaddch(win, win->cury, xpos, ' ');
			wmove(win, win->cury, xpos);
		}
	}

	if (c == ERR) {
		*str = '\0';
		return (ERR);
	}
	*str = '\0';
	return (OK);
}
Beispiel #17
0
int
display_iserasechar(char ch)
{
	return ch == erasechar();
}
Beispiel #18
0
wgetn_wstr(WINDOW *win, wint_t *str, int maxlen)
{
    SCREEN *sp = _nc_screen_of(win);
    TTY buf;
    bool oldnl, oldecho, oldraw, oldcbreak;
    wint_t erasec;
    wint_t killc;
    wint_t *oldstr = str;
    wint_t *tmpstr = str;
    wint_t ch;
    int y, x, code;

    T((T_CALLED("wgetn_wstr(%p,%p, %d)"), win, str, maxlen));

    if (!win)
	returnCode(ERR);

    _nc_get_tty_mode(&buf);

    oldnl = sp->_nl;
    oldecho = sp->_echo;
    oldraw = sp->_raw;
    oldcbreak = sp->_cbreak;
    nl();
    noecho();
    noraw();
    cbreak();

    erasec = (wint_t) erasechar();
    killc = (wint_t) killchar();

    getyx(win, y, x);

    if (is_wintouched(win) || (win->_flags & _HASMOVED))
	wrefresh(win);

    while ((code = wget_wch(win, &ch)) != ERR) {
	/*
	 * Map special characters into key-codes.
	 */
	if (ch == '\r')
	    ch = '\n';
	if (ch == '\n') {
	    code = KEY_CODE_YES;
	    ch = KEY_ENTER;
	}
	if (ch < KEY_MIN) {
	    if (ch == erasec) {
		ch = KEY_BACKSPACE;
		code = KEY_CODE_YES;
	    }
	    if (ch == killc) {
		ch = KEY_EOL;
		code = KEY_CODE_YES;
	    }
	}
	if (code == KEY_CODE_YES) {
	    /*
	     * Some terminals (the Wyse-50 is the most common) generate a \n
	     * from the down-arrow key.  With this logic, it's the user's
	     * choice whether to set kcud=\n for wget_wch(); terminating
	     * *getn_wstr() with \n should work either way.
	     */
	    if (ch == KEY_DOWN || ch == KEY_ENTER) {
		if (oldecho == TRUE
		    && win->_cury == win->_maxy
		    && win->_scroll)
		    wechochar(win, (chtype) '\n');
		break;
	    }
	    if (ch == KEY_LEFT || ch == KEY_BACKSPACE) {
		if (tmpstr > oldstr) {
		    tmpstr = WipeOut(win, y, x, oldstr, tmpstr, oldecho);
		}
	    } else if (ch == KEY_EOL) {
		while (tmpstr > oldstr) {
		    tmpstr = WipeOut(win, y, x, oldstr, tmpstr, oldecho);
		}
	    } else {
		beep();
	    }
	} else if (maxlen >= 0 && tmpstr - oldstr >= maxlen) {
	    beep();
	} else {
	    *tmpstr++ = ch;
	    *tmpstr = 0;
	    if (oldecho == TRUE) {
		int oldy = win->_cury;

		if (wadd_wint(win, tmpstr - 1) == ERR) {
		    /*
		     * We can't really use the lower-right corner for input,
		     * since it'll mess up bookkeeping for erases.
		     */
		    win->_flags &= ~_WRAPPED;
		    waddch(win, (chtype) ' ');
		    tmpstr = WipeOut(win, y, x, oldstr, tmpstr, oldecho);
		    continue;
		} else if (win->_flags & _WRAPPED) {
		    /*
		     * If the last waddch forced a wrap & scroll, adjust our
		     * reference point for erasures.
		     */
		    if (win->_scroll
			&& oldy == win->_maxy
			&& win->_cury == win->_maxy) {
			if (--y <= 0) {
			    y = 0;
			}
		    }
		    win->_flags &= ~_WRAPPED;
		}
		wrefresh(win);
	    }
	}
    }

    win->_curx = 0;
    win->_flags &= ~_WRAPPED;
    if (win->_cury < win->_maxy)
	win->_cury++;
    wrefresh(win);

    /* Restore with a single I/O call, to fix minor asymmetry between
     * raw/noraw, etc.
     */
    sp->_nl = oldnl;
    sp->_echo = oldecho;
    sp->_raw = oldraw;
    sp->_cbreak = oldcbreak;

    (void) _nc_set_tty_mode(&buf);

    *tmpstr = 0;
    if (code == ERR) {
	if (tmpstr == oldstr) {
	    *tmpstr++ = WEOF;
	    *tmpstr = 0;
	}
	returnCode(ERR);
    }

    T(("wgetn_wstr returns %s", _nc_viswibuf(oldstr)));

    returnCode(OK);
}
Beispiel #19
0
/*
 * quit:
 *	Handle the end of the game when the player dies
 */
int
quit(int old_status)
{
	bool explain;
	int ch;

	if (Last_player)
		return Q_QUIT;
#ifdef OTTO
	if (Otto_mode)
		return Q_CLOAK;
#endif
	move(HEIGHT, 0);
	addstr("Re-enter game [ynwo]? ");
	clrtoeol();
	explain = false;
	for (;;) {
		refresh();
		if (isupper(ch = getchar()))
			ch = tolower(ch);
		if (ch == 'y')
			return old_status;
		else if (ch == 'o')
			break;
		else if (ch == 'n') {
#ifndef INTERNET
			return Q_QUIT;
#else
			move(HEIGHT, 0);
			addstr("Write a parting message [yn]? ");
			clrtoeol();
			refresh();
			for (;;) {
				if (isupper(ch = getchar()))
					ch = tolower(ch);
				if (ch == 'y')
					goto get_message;
				if (ch == 'n')
					return Q_QUIT;
			}
#endif
		}
#ifdef INTERNET
		else if (ch == 'w') {
			static char buf[WIDTH + WIDTH % 2];
			char *cp, c;

get_message:
			c = ch;		/* save how we got here */
			move(HEIGHT, 0);
			addstr("Message: ");
			clrtoeol();
			refresh();
			cp = buf;
			for (;;) {
				refresh();
				if ((ch = getchar()) == '\n' || ch == '\r')
					break;
				if (ch == erasechar()) {
					if (cp > buf) {
						int y, x;
						getyx(stdscr, y, x);
						move(y, x - 1);
						cp -= 1;
						clrtoeol();
					}
					continue;
				}
				else if (ch == killchar()) {
					int y, x;
					getyx(stdscr, y, x);
					move(y, x - (cp - buf));
					cp = buf;
					clrtoeol();
					continue;
				} else if (!isprint(ch)) {
					beep();
					continue;
				}
				addch(ch);
				*cp++ = ch;
				if (cp + 1 >= buf + sizeof buf)
					break;
			}
			*cp = '\0';
			Send_message = buf;
			return (c == 'w') ? old_status : Q_MESSAGE;
		}
#endif
		beep();
		if (!explain) {
			addstr("(Yes, No, Write message, or Options) ");
			explain = true;
		}
	}

	move(HEIGHT, 0);
#ifdef FLY
	addstr("Scan, Cloak, Flying, or Quit? ");
#else
	addstr("Scan, Cloak, or Quit? ");
#endif
	clrtoeol();
	refresh();
	explain = false;
	for (;;) {
		if (isupper(ch = getchar()))
			ch = tolower(ch);
		if (ch == 's')
			return Q_SCAN;
		else if (ch == 'c')
			return Q_CLOAK;
#ifdef FLY
		else if (ch == 'f')
			return Q_FLY;
#endif
		else if (ch == 'q')
			return Q_QUIT;
		beep();
		if (!explain) {
#ifdef FLY
			addstr("[SCFQ] ");
#else
			addstr("[SCQ] ");
#endif
			explain = true;
		}
		refresh();
	}
}
Beispiel #20
0
int
get_input(int prompt_position, struct key_input *input, bool modifiers)
{
	struct view *view;
	int i, key, cursor_y, cursor_x;

	if (prompt_position)
		input_mode = TRUE;

	memset(input, 0, sizeof(*input));

	while (TRUE) {
		bool loading = FALSE;

		foreach_view (view, i) {
			update_view(view);
			if (view_is_displayed(view) && view->has_scrolled &&
			    use_scroll_redrawwin)
				redrawwin(view->win);
			view->has_scrolled = FALSE;
			if (view->pipe)
				loading = TRUE;
		}

		/* Update the cursor position. */
		if (prompt_position) {
			getbegyx(status_win, cursor_y, cursor_x);
			cursor_x = prompt_position;
		} else {
			view = display[current_view];
			getbegyx(view->win, cursor_y, cursor_x);
			cursor_x = view->width - 1;
			cursor_y += view->pos.lineno - view->pos.offset;
		}
		setsyx(cursor_y, cursor_x);

		/* Refresh, accept single keystroke of input */
		doupdate();
		nodelay(status_win, loading);
		key = wgetch(status_win);

		/* wgetch() with nodelay() enabled returns ERR when
		 * there's no input. */
		if (key == ERR) {

		} else if (key == KEY_ESC && modifiers) {
			input->modifiers.escape = 1;

		} else if (key == KEY_RESIZE) {
			int height, width;

			getmaxyx(stdscr, height, width);

			wresize(status_win, 1, width);
			mvwin(status_win, height - 1, 0);
			wnoutrefresh(status_win);
			resize_display();
			redraw_display(TRUE);

		} else {
			int pos, key_length;

			input_mode = FALSE;
			if (key == erasechar())
				key = KEY_BACKSPACE;

			/*
			 * Ctrl-<key> values are represented using a 0x1F
			 * bitmask on the key value. To 'unmap' we assume that:
			 *
			 * - Ctrl-Z is handled by Ncurses.
			 * - Ctrl-m is the same as Return/Enter.
			 * - Ctrl-i is the same as Tab.
			 *
			 * For all other key values in the range the Ctrl flag
			 * is set and the key value is updated to the proper
			 * ASCII value.
			 */
			if (KEY_CTL('a') <= key && key <= KEY_CTL('x') && key != KEY_RETURN && key != KEY_TAB) {
				input->modifiers.control = 1;
				key = key | 0x40;
			}

			if ((key >= KEY_MIN && key < KEY_MAX) || key < 0x1F) { // || key == ' ') {
				input->data.key = key;
				return input->data.key;
			}

			input->modifiers.multibytes = 1;
			input->data.bytes[0] = key;

			key_length = utf8_char_length(input->data.bytes);
			for (pos = 1; pos < key_length && pos < sizeof(input->data.bytes) - 1; pos++) {
				input->data.bytes[pos] = wgetch(status_win);
			}

			return OK;
		}
	}
Beispiel #21
0
wgetnstr_events(WINDOW *win,
		char *str,
		int maxlen,
		EVENTLIST_1st(_nc_eventlist * evl))
{
    SCREEN *sp = _nc_screen_of(win);
    TTY buf;
    bool oldnl, oldecho, oldraw, oldcbreak;
    char erasec;
    char killc;
    char *oldstr;
    int ch;
    int y, x;

    T((T_CALLED("wgetnstr(%p,%p, %d)"), win, str, maxlen));

    if (!win)
	returnCode(ERR);

    _nc_get_tty_mode(&buf);

    oldnl = sp->_nl;
    oldecho = sp->_echo;
    oldraw = sp->_raw;
    oldcbreak = sp->_cbreak;
    nl();
    noecho();
    noraw();
    cbreak();

    erasec = erasechar();
    killc = killchar();

    oldstr = str;
    getyx(win, y, x);

    if (is_wintouched(win) || (win->_flags & _HASMOVED))
	wrefresh(win);

    while ((ch = wgetch_events(win, evl)) != ERR) {
	/*
	 * Some terminals (the Wyse-50 is the most common) generate
	 * a \n from the down-arrow key.  With this logic, it's the
	 * user's choice whether to set kcud=\n for wgetch();
	 * terminating *getstr() with \n should work either way.
	 */
	if (ch == '\n'
	    || ch == '\r'
	    || ch == KEY_DOWN
	    || ch == KEY_ENTER) {
	    if (oldecho == TRUE
		&& win->_cury == win->_maxy
		&& win->_scroll)
		wechochar(win, (chtype) '\n');
	    break;
	}
#ifdef KEY_EVENT
	if (ch == KEY_EVENT)
	    break;
#endif
#ifdef KEY_RESIZE
	if (ch == KEY_RESIZE)
	    break;
#endif
	if (ch == erasec || ch == KEY_LEFT || ch == KEY_BACKSPACE) {
	    if (str > oldstr) {
		str = WipeOut(win, y, x, oldstr, str, oldecho);
	    }
	} else if (ch == killc) {
	    while (str > oldstr) {
		str = WipeOut(win, y, x, oldstr, str, oldecho);
	    }
	} else if (ch >= KEY_MIN
		   || (maxlen >= 0 && str - oldstr >= maxlen)) {
	    beep();
	} else {
	    *str++ = (char) ch;
	    if (oldecho == TRUE) {
		int oldy = win->_cury;
		if (waddch(win, (chtype) ch) == ERR) {
		    /*
		     * We can't really use the lower-right
		     * corner for input, since it'll mess
		     * up bookkeeping for erases.
		     */
		    win->_flags &= ~_WRAPPED;
		    waddch(win, (chtype) ' ');
		    str = WipeOut(win, y, x, oldstr, str, oldecho);
		    continue;
		} else if (win->_flags & _WRAPPED) {
		    /*
		     * If the last waddch forced a wrap &
		     * scroll, adjust our reference point
		     * for erasures.
		     */
		    if (win->_scroll
			&& oldy == win->_maxy
			&& win->_cury == win->_maxy) {
			if (--y <= 0) {
			    y = 0;
			}
		    }
		    win->_flags &= ~_WRAPPED;
		}
		wrefresh(win);
	    }
	}
    }

    win->_curx = 0;
    win->_flags &= ~_WRAPPED;
    if (win->_cury < win->_maxy)
	win->_cury++;
    wrefresh(win);

    /* Restore with a single I/O call, to fix minor asymmetry between
     * raw/noraw, etc.
     */
    sp->_nl = oldnl;
    sp->_echo = oldecho;
    sp->_raw = oldraw;
    sp->_cbreak = oldcbreak;

    _nc_set_tty_mode(&buf);

    *str = '\0';
    if (ch == ERR)
	returnCode(ch);

    T(("wgetnstr returns %s", _nc_visbuf(oldstr)));

#ifdef KEY_EVENT
    if (ch == KEY_EVENT)
	returnCode(ch);
#endif
#ifdef KEY_RESIZE
    if (ch == KEY_RESIZE)
	returnCode(ch);
#endif

    returnCode(OK);
}
Beispiel #22
0
void menu_nym(char *nnym)
{
  char nym[maxnym][LINELEN];
  char pending[maxnym][LINELEN];
  int c, i, num = 0, numpending = 0, select = -1;
  int edit = 0;
  BUFFER *nymlist;
  int s;
  int pass = 0;
  char reliability[9]; /* When printing information about a chain,
			  this variable stores the reliability. */

  nymlist = buf_new();

  strcpy(nym[0], NONANON);
  strcatn(nym[0], " (", sizeof(nym[0]));
  strcatn(nym[0], NAME, sizeof(nym[0]));
  strcatn(nym[0], ")", sizeof(nym[0]));

  strcpy(nym[1], ANON);
  num = 2;
  if (nymlist_read(nymlist) == -1) {
    user_delpass();
    mix_status("");
  } else
    pass = 1;
  while (nymlist_get(nymlist, nym[num], NULL, NULL, NULL, NULL, NULL, &s) >= 0) {
    if (s == NYM_OK) {
      if (num < maxnym)
	num++;
    } else if (s == NYM_WAITING) {
      if (numpending < maxnym)
	strncpy(pending[numpending++], nym[num], LINELEN);
    }
  }
  buf_free(nymlist);

nymselect:
  clear();
  standout();
  printw("Select nym:\n\n");
  standend();
#ifdef USE_PGP
  if (pass)
    printw("c)reate new nym\ne)dit nym\nd)elete nym\n\n");
  else
    printw("[nym passphrase is invalid]\n\n");
#endif /* USE_PGP */
  for (i = 0; i < num; i++)
    printw("%d) %s\n", i, nym[i]);
  if (numpending > 0) {
    printw("\n\nWaiting for confirmation: ");
    for (i = 0; i < numpending; i++)
      printw("%s ", pending[i]);
    printw("\n");
  }
select:
  if (select != -1)
    printw("\r%d", select);
  else
    printw("\r          \r");
  refresh();
  c = getch();
  if (c == erasechar())
    c = KEY_BACKSPACE;
  if (c >= '0' && c <= '9') {
    if (select == -1)
      select = c - '0';
    else
      select = 10 * select + c - '0';
    if (edit ? select == 0 || select >= num + numpending - 1 : select >= num) {
      beep();
      select = -1;
    }
    refresh();
    goto select;
  } else
    switch (c) {
    case KEY_BACKSPACE:
      select /= 10;
      if (select < 1)
	select = -1;
      goto select;
    case 'q':
      if (edit) {
	edit = 0;
	select = -1;
	goto nymselect;
      }
      break;
#ifdef USE_PGP
    case 'e':
      if (pass) {
	if (edit || num + numpending < 3) {
	  edit = 0;
	  select = -1;
	  goto nymselect;
	} else {
	  clear();
	  standout();
	  printw("Edit nym:\n\n");
	  standend();
	  for (i = 2; i < num + numpending; i++)
	    printw("%d) %s\n", i - 1, i < num ? nym[i] : pending[i - num]);
	  printw("\n");
	  select = -1;
	  edit = NYM_MODIFY;
	  goto select;
	}
      }
      break;
    case 'd':
      if (pass) {
	if (edit || num + numpending < 3) {
	  edit = 0;
	  select = -1;
	  goto nymselect;
	} else {
	  clear();
	  standout();
	  printw("Delete nym:\n\n");
	  standend();
	  for (i = 2; i < num + numpending; i++)
	    printw("%d) %s\n", i - 1, i < num ? nym[i] : pending[i - num]);
	  printw("\n");
	  select = -1;
	  edit = NYM_DELETE;
	  goto select;
	}
      }
      break;
    case '\r':
    case '\n':
      if (select == -1 || (edit && select == 0)) {
	beep();
	edit = 0;
	select = -1;
	goto nymselect;
      }
      if (!edit) {
	strncpy(nnym, nym[select], LINELEN);
	return;
      }
      /* fallthru */
    case 'c':
      if (pass) {
	char nymserv[LINELEN] = "*";
	char replyblock[5][CHAINMAX], dest[10][LINELEN];
	int latent[5], desttype[5];
	char mdest[LINELEN], pdest[LINELEN] = "alt.anonymous.messages",
	psub[LINELEN] = "";
	int deflatent = 0, defdesttype = MSG_MAIL;
	char alias[LINELEN] = "";
	BUFFER *name, *opt;
	char sendchain[CHAINMAX];
	int sendnumcopies = 1, rnum = 1;
	int i;
	char line[LINELEN];
	int acksend = 0, signsend = 0, fixedsize = 0, disable = 0,
	    fingerkey = 1;

	name = buf_new();
	opt = buf_new();
	strncpy(sendchain, CHAIN, CHAINMAX);
	strncpy(mdest, ADDRESS, LINELEN);
	if (edit)
	  strncpy(alias, select + 1 < num ? nym[select + 1] :
		  pending[select + 1 - num], LINELEN);
	if (edit == NYM_MODIFY) {
	  nymlist_getnym(alias, NULL, NULL, opt, name, NULL);
	  acksend = bufifind(opt, "+acksend");
	  signsend = bufifind(opt, "+signsend");
	  fixedsize = bufifind(opt, "+fixedsize");
	  disable = bufifind(opt, "+disable");
	  fingerkey = bufifind(opt, "+fingerkey");
	  rnum = -1;
	}
      newnym:
	if (!edit) {
	  clear();
	  standout();
	  printw("Create a nym:");
	  standend();

	  mvprintw(3, 0, "Alias address: ");
	  echo();
	  wgetnstr(stdscr, alias, LINELEN);
	  noecho();
	  if (alias[0] == '\0')
	    goto end;
	  for (i = 0; alias[i] > ' ' && alias[i] != '@'; i++) ;
	  alias[i] = '\0';
	  if (i == 0)
	    goto newnym;
	  mvprintw(4, 0, "Pseudonym: ");
	  echo();
	  wgetnstr(stdscr, line, LINELEN);
	  noecho();
	  buf_sets(name, line);
	  menu_chain(nymserv, 2, 0);
	}
	if (edit != NYM_DELETE) {
	  for (i = 0; i < 5; i++) {
	    desttype[i] = defdesttype;
	    latent[i] = deflatent;
	    dest[i][0] = '\0';
	    strcpy(replyblock[i], "*,*,*,*");
	  }
	  if (rnum != -1) {
	    menu_replychain(&defdesttype, &deflatent, mdest, pdest, psub,
			    replyblock[0]);
	    desttype[0] = defdesttype;
	    latent[0] = deflatent;
	    strncpy(dest[0], desttype[0] == MSG_POST ? pdest : mdest,
		    LINELEN);
	  }
	}
      redraw:
	clear();
	standout();
	switch (edit) {
	case NYM_DELETE:
	  printw("Delete nym:");
	  break;
	case NYM_MODIFY:
	  printw("Edit nym:");
	  break;
	default:
	  printw("Create a nym:");
	  break;
	}
	standend();
      loop:
	{
	  if (!edit) {
	    cl(2, 0);
	    printw("Nym: a)lias address: %s", alias);
	    cl(3, 0);
	    printw("     nym s)erver: %s", nymserv);
	  }
	  if (edit != NYM_DELETE) {
	    cl(4, 0);
	    printw("     p)seudonym: %s", name->data);
	    if (edit)
	      mvprintw(6, 0, "Nym modification:");
	    else
	      mvprintw(6, 0, "Nym creation:");
	  }
	  cl(7, 0);
	  chain_reliability(sendchain, 0, reliability); /* chaintype 0=mix */
	  printw("     c)hain to nym server: %-30s (reliability: %s)", sendchain, reliability);
	  cl(8, 0);
	  printw("     n)umber of redundant copies: %d", sendnumcopies);
	  if (edit != NYM_DELETE) {
	    mvprintw(10, 0, "Configuration:\n");
	    printw("     A)cknowledge sending: %s\n", acksend ? "yes" : "no");
	    printw("     S)erver signatures: %s\n", signsend ? "yes" : "no");
	    printw("     F)ixed size replies: %s\n", fixedsize ? "yes" :
		   "no");
	    printw("     D)isable: %s\n", disable ? "yes" : "no");
	    printw("     Finger K)ey: %s\n", fingerkey ? "yes" : "no");
	    mvprintw(17, 0, "Reply chains:");
	    cl(18, 0);
	    if (rnum == -1)
	      printw("     create new r)eply block");
	    else {
 	      printw("     number of r)eply chains: %2d                                     reliability", rnum);
	      for (i = 0; i < rnum; i++) {
		cl(i + 19, 0);
 		chain_reliability(replyblock[i], 1, reliability); /* 1=ek */
 		printw("     %d) %30s %-31s [%s]", i + 1,
  		       desttype[i] == MSG_NULL ?
 		       "(cover traffic)" : dest[i], replyblock[i],
 		       reliability);
	      }
	    }
	  }
	  move(LINES - 1, COLS - 1);
	  refresh();
	  c = getch();
	  if (edit != NYM_DELETE && c >= '1' && c <= '9' && c - '1' < rnum) {
	    menu_replychain(&defdesttype, &deflatent, mdest, pdest, psub,
			    replyblock[c - '1']);
	    desttype[c - '1'] = defdesttype;
	    latent[c - '1'] = deflatent;
	    strncpy(dest[c - '1'],
		    desttype[c - '1'] == MSG_POST ? pdest : mdest, LINELEN);
	    goto redraw;
	  }
	  switch (c) {
	  case 'A':
	    acksend = !acksend;
	    goto redraw;
	  case 'S':
	    signsend = !signsend;
	    goto redraw;
	  case 'F':
	    fixedsize = !fixedsize;
	    goto redraw;
	  case 'D':
	    disable = !disable;
	    goto redraw;
	  case 'K':
	    fingerkey = !fingerkey;
	    goto redraw;
	  case 'q':
	    edit = 0;
	    select = -1;
	    goto nymselect;
	  case '\014':
	    goto redraw;
	  case 'a':
	    cl(2, 0);
	    printw("Nym: a)lias address: ");
	    echo();
	    wgetnstr(stdscr, alias, LINELEN);
	    noecho();
	    for (i = 0; alias[i] > ' ' && alias[i] != '@'; i++) ;
	    alias[i] = '\0';
	    if (i == 0)
	      goto nymselect;
	    goto redraw;
	  case 'p':
	    cl(4, 0);
	    printw("     p)seudonym: ");
	    echo();
	    wgetnstr(stdscr, line, LINELEN);
	    noecho();
	    if (line[0] != '\0')
	      buf_sets(name, line);
	    goto redraw;
	  case 'c':
	    menu_chain(sendchain, 0, 0);
	    goto redraw;
	  case 'n':
	    cl(8, 0);
	    printw("     n)umber of redundant copies: ");
	    echo();
	    wgetnstr(stdscr, line, LINELEN);
	    noecho();
	    sendnumcopies = strtol(line, NULL, 10);
	    if (sendnumcopies < 1 || sendnumcopies > 10)
	      sendnumcopies = 1;
	    goto redraw;
	  case 'r':
	    cl(18, 0);
	    printw("     number of r)eply chains: ");
	    echo();
	    wgetnstr(stdscr, line, LINELEN);
	    noecho();
	    i = rnum;
	    rnum = strtol(line, NULL, 10);
	    if (rnum < 1)
	      rnum = 1;
	    if (rnum > 5)
	      rnum = 5;
	    for (; i < rnum; i++)
	      if (dest[i][0] == '\0') {
		desttype[i] = defdesttype;
		latent[i] = deflatent;
		strncpy(dest[i], defdesttype == MSG_POST ? pdest :
			mdest, LINELEN);
	      }
	    goto redraw;
	  case 's':
	    menu_chain(nymserv, 2, 0);
	    goto redraw;
	  case '\n':
	  case '\r':
	    {
	      BUFFER *chains;
	      int err;

	      if (rnum == -1)
		chains = NULL;
	      else {
		chains = buf_new();
		for (i = 0; i < rnum; i++)
		  if (replyblock[i][0] != '\0') {
		    if (desttype[i] == MSG_POST)
		      buf_appendf(chains, "Subject: %s\n", psub);
		    if (desttype[i] == MSG_MAIL)
		      buf_appends(chains, "To: ");
		    else if (desttype[i] == MSG_POST)
		      buf_appends(chains, "Newsgroups: ");
		    else
		      buf_appends(chains, "Null:");
		    buf_appendf(chains, "%s\n", dest[i]);
		    buf_appendf(chains, "Chain: %s\n", replyblock[i]);
		    buf_appendf(chains, "Latency: %d\n\n", latent[i]);
		  }
	      }
	    create:
	      clear();
	      buf_setf(opt,
		       " %cacksend %csignsend +cryptrecv %cfixedsize %cdisable %cfingerkey",
		       acksend ? '+' : '-',
		       signsend ? '+' : '-',
		       fixedsize ? '+' : '-',
		       disable ? '+' : '-',
		       fingerkey ? '+' : '-');
	      if (edit) {
		mix_status("Preparing nymserver configuration message...");
		err = nym_config(edit, alias, NULL,
				 name, sendchain, sendnumcopies,
				 chains, opt);
	      } else {
		mix_status("Preparing nym creation request...");
		err = nym_config(edit, alias, nymserv, name,
				 sendchain, sendnumcopies, chains,
				 opt);
	      }
	      if (err == -3) {
		beep();
		mix_status("Bad passphrase!");
		getch();
		goto create;
	      }
	      if (err != 0) {
		mix_genericerror();
		beep();
		refresh();
	      } else {
		if (edit)
		  mix_status("Nymserver configuration message completed.");
		else
		  mix_status("Nym creation request completed.");
	      }
	      if (chains)
		buf_free(chains);
	      goto end;
	    }
	  default:
	    beep();
	    goto loop;
	  }
	}
      end:
	buf_free(name);
	buf_free(opt);
	return;
      }
#endif /* USE_PGP */
    default:
      beep();
      goto select;
    }
}