コード例 #1
0
ファイル: screen.c プロジェクト: erichuang1994/fbbs
/**
 * Output a character.
 * @param c The character.
 * @return 1, 0 on ansi control codes.
 * @deprecated
 */
int outc(int c)
{
	if (!screen.buf) {
		if (!isprint2(c)) {
			if (c == '\n') {
				terminal_putchar('\r');
			} else {
				if (c != KEY_ESC || !showansi)
					c = '*';
			}
		}
		terminal_putchar(c);
		return 1;
	}

	screen_line_t *slp = get_screen_line(screen.cur_ln);

	if (!isprint2(c)) {
		if (c == '\n' || c == '\r') {
			if (screen.cur_col> slp->len) {
				memset(slp->data + slp->len, ' ',
						screen.cur_col - slp->len + 1);
			}
			slp->len = screen.cur_col;
			screen.cur_col = 0;
			if (screen.cur_ln < screen.lines)
				screen.cur_ln++;
			return 1;
		} else {
			if (c != KEY_ESC || !showansi)
				c = '*';
		}
	}

	screen_put_gbk(c);

	if (screen.cur_col >= screen.columns) {
		screen.cur_col = 0;
		if (screen.cur_ln < screen.lines)
			screen.cur_ln++;
	}
	return 1;
}
コード例 #2
0
ファイル: more.c プロジェクト: yrchen/Athena
static int
readln(FILE * fp, char *buf)
{
  register int ch, i, len, bytes, in_ansi;

  len = bytes = in_ansi = i = 0;
  while (len < t_columns && i < ANSILINELEN && (ch = getc(fp)) != EOF)
  {
    bytes++;
    if (ch == '\n')
      break;
    else if (ch == '\t')
    {
      do
      {
	buf[i++] = ' ';
      } while ((++len & 7) && len < t_columns);
    }
    else if (ch == '\a')
      beep = 1;
    else if (ch == '\033')
    {
      if (showansi)
	buf[i++] = ch;
      in_ansi = 1;
    }
    else if (in_ansi)
    {
      if (showansi)
	buf[i++] = ch;
      if (!strchr("[0123456789;,", ch))
	in_ansi = 0;
    }
    else if (isprint2(ch))
    {
      len++;
      buf[i++] = ch;
    }
  }
  buf[i] = '\0';
  return bytes;
}
コード例 #3
0
ファイル: tui.c プロジェクト: fbbs/fbbs
int multi_getdata(int line, int col, int maxcol, const char *prompt,
		char *buf, int len, int maxline, int clearlabel, int textmode)
{
	extern int RMSG;
	extern int msg_num;
	int ch, x, y, startx, starty, curr, i, k, chk, cursorx, cursory, size;
	bool init = true;
	char tmp[MAX_MSG_SIZE+1];

	if (clearlabel == YEA)
		memset(buf, 0, len);
	screen_move(line, col);
	if (prompt)
		prints("%s", prompt);
	screen_coordinates(&starty, &startx);
	curr = strlen(buf);
	strncpy(tmp, buf, MAX_MSG_SIZE);
	tmp[MAX_MSG_SIZE] = 0;
	cursory = starty;
	cursorx = startx;
	while (true) {
		y = starty;
		x = startx;
		screen_move(y, x);
		chk = 0;
		if (curr == 0) {
			cursory = y;
			cursorx = x;
		}
		//以下遍历buf的功能是显示出每次terminal_getchar的动作。
		size = strlen(buf);
		for (i = 0; i < size; i++) {
			if (chk) {
				chk = 0;
			} else {
				if (buf[i] < 0)
					chk=1;
			}
			if (chk && x >= maxcol)
				x++;
			if (buf[i] != '\r' && buf[i] != '\n') {
				if (x > maxcol) {
					clrtoeol();
					x = 0;
					y++;
					screen_move(y, x);
				}
				//Ctrl('H')中退行bug
				if (x == maxcol && y - starty + 1 < MAX_MSG_LINE) {
					screen_move(y + 1, 0);
					clrtoeol();
					screen_move(y, x);
				}
				if (init)
					prints("\033[4m");
				prints("%c", buf[i]);
				x++;
			}
			else {
				clrtoeol();
				x = 0;
				y++;
				screen_move(y, x);
			}
			if(i == curr - 1) { //打印到buf最后一个字符时的x和y是下一步初始xy
				cursory = y;
				cursorx = x;
			}
		}
		clrtoeol();
		screen_move(cursory, cursorx);
		ch = terminal_getchar();

		if ((RMSG == YEA) && msg_num == 0) 
		{
			if (ch == Ctrl('Z') ) 
			{
				buf[0] = Ctrl('Z');
				x = 1;
				break; //可以改成return 某个行试试
			}
			if (ch == Ctrl('A') ) 
			{
				buf[0] = Ctrl('A');
				x = 1;
				break;
			}
		}

		if(ch == Ctrl('Q'))
		{
			init = true;
			buf[0]=0; curr=0;
			for(k=0; k < MAX_MSG_LINE;k++)
			{
				screen_move(starty+k,0);
				clrtoeol();
			}
			continue;
		}


		if(textmode == 0){
			if ((ch == '\n' || ch == '\r'))
				break;
		}
		else{
			if (ch == Ctrl('W'))
				break;
		}

		switch(ch) {
			case KEY_UP:
				init = false;
				if (cursory > starty) {
					y = starty; x = startx;
					chk = 0;
					if(y == cursory - 1 && x <= cursorx)
						curr = 0;
					size = strlen(buf);
					for (i = 0; i < size; i++) {
						if (chk) {
							chk = 0;
						} else {
							if (buf[i] < 0)
								chk = 1;
						}
						if (chk && x >= maxcol)
							x++;
						if (buf[i] != '\r' && buf[i] != '\n') {
							if(x > maxcol) {
								x = col;
								y++;
							}
							x++;
						}
						else {
							x = col;
							y++;
						}
						if (y == cursory - 1 && x <= cursorx)
							curr = i + 1;
					}
				}
				break;
			case KEY_DOWN:
				init=false;
				if(cursory<y) {
					y = starty; x = startx;
					chk = 0;
					if(y==cursory+1&&x<=cursorx)
						curr=0;
					size = strlen(buf);
					for(i=0; i<size; i++) {
						if(chk) chk=0;
						else if(buf[i]<0) chk=1;
						if(chk&&x>=maxcol) x++;
						if(buf[i]!=13&&buf[i]!=10) {
							if(x>maxcol) {
								x = col;
								y++;
							}
							x++;
						}
						else {
							x = col;
							y++;
						}
						if(y==cursory+1&&x<=cursorx)
							curr=i+1;
					}
				}
				break;
			case '\177':
			case Ctrl('H'):
				if(init) {
					init=false;
					buf[0]=0;
					curr=0;
				}
				if(curr>0) {
					int currDec = 0, patch = 0;
					if(buf[curr-1] < 0){
						for(i = curr - 2; i >=0 && buf[i]<0; i--)
							patch++;
						if(patch%2 == 0 && buf[curr] < 0)
							patch = 1;
						else if(patch%2)
							patch = currDec = 1;
						else
							patch = 0;
					}
					if(currDec) curr--;
					strcpy(tmp, &buf[curr+patch]);
					buf[--curr] = 0;
					strcat(buf, tmp);
				}
				break;
			case KEY_DEL:
				if (init) {
					init = false;
					buf[0] = '\0';
					curr = 0;
				}
				size = strlen(buf);
				if (curr < size)
					memmove(buf + curr, buf + curr + 1, size - curr);
				break;
			case KEY_LEFT:
				init=false;
				if(curr>0) {
					curr--;
				}
				break;
			case KEY_RIGHT:
				init=false;
				if(curr<strlen(buf)) {
					curr++;
				}
				break;
			case KEY_HOME:
			case Ctrl('A'):
				init=false;
				curr--;
				while (curr >= 0 && buf[curr] != '\n' && buf[curr] != '\r')
					curr--;
				curr++;
				break;
			case KEY_END:
			case Ctrl('E'):
				init = false;
				size = strlen(buf);
				while (curr < size && buf[curr] != '\n' && buf[curr] != '\r')
					curr++;
				break;
			case KEY_PGUP:
				init=false;
				curr=0;
				break;
			case KEY_PGDN:
				init=false;
				curr = strlen(buf);
				break;
			default:
				if(isprint2(ch)&&strlen(buf)<len-1) {
					if(init) {
						init=false;
						buf[0]=0;
						curr=0;
					}
					size = strlen(buf);
					memmove(buf + curr + 1, buf + curr, size - curr + 1);
					size++;
					buf[curr++]=ch;
					y = starty; x = startx;
					chk = 0;
					for(i = 0; i < size; i++) {
						if(chk) chk=0;
						else if(buf[i]<0) chk=1;
						if(chk&&x>=maxcol) x++;
						if(buf[i]!=13&&buf[i]!=10) {
							if(x>maxcol) {
								x = col;
								y++;
							}
							x++;
						}
						else {
							x = col;
							y++;
						}
					}
					//采用先插入后检查是否超过maxline,如果超过,那么删去这个字符调整
					if (y - starty + 1 > maxline) {
						memmove(buf + curr -1, buf + curr, size - curr + 1);
						curr--;
					}
				}
				init=false;
				break;
		}
	}

	return y-starty+1;
}
コード例 #4
0
ファイル: tui.c プロジェクト: fbbs/fbbs
static int _tui_input(int line, int col, const char *prompt, char *buf,
		int len, int echo, int clear, bool utf8)
{
	extern int RMSG;
	extern int msg_num;

	if (clear)
		buf[0] = '\0';
	buf[len - 1] = '\0';

	int real_x = prompt ? screen_display_width(prompt, utf8) : 0;

	int cur, clen;
	cur = clen = strlen(buf);

	bool inited = screen_inited(), prompted = false;
	while (1) {
		if (inited || !prompted) {
			screen_move(line, col);
			clrtoeol();
			if (prompt) {
				if (utf8)
					screen_printf("%s", prompt);
				else
					prints("%s", prompt);
			}
			prompted = true;
		}
		if (inited) {
			if (echo)
				prints("%s", buf);
			else
				tui_repeat_char('*', clen);
			screen_move(line, real_x + cur);
		}

		if (RMSG)
			screen_flush();

		int ch = terminal_getchar();

		if (RMSG && msg_num == 0) {
			if (ch == Ctrl('Z') || ch == KEY_UP) {
				buf[0] = Ctrl('Z');
				clen = 1;
				break;
			}
			if (ch == Ctrl('A') || ch == KEY_DOWN) {
				buf[0] = Ctrl('A');
				clen = 1;
				break;
			}
		}

		if (ch == '\n' || ch == '\r')
			break;

		if (!inited) {
			if (ch == '\x7f' || ch == Ctrl('H')) {
				int dec = remove_character(buf, &cur, clen, true);
				if (dec) {
					clen -= dec;
					screen_puts("\x8 \x8", 3);
				}
			} else if (isprint2(ch) && clen < len - 1) {
				buf[cur] = ch;
				buf[++cur] = '\0';
				++clen;
				screen_putc(echo ? ch : '*');
			}
			continue;
		}

		if (ch == '\x7f' || ch == Ctrl('H')) {
			clen -= remove_character(buf, &cur, clen, true);
		} else if (ch == KEY_DEL) {
			clen -= remove_character(buf, &cur, clen, false);
		} else if (ch == KEY_LEFT) {
			if (cur > 0)
				--cur;
		} else if (ch == KEY_RIGHT) {
			if (cur < clen)
				++cur;
		} else if (ch == Ctrl('E') || ch == KEY_END) {
			cur = clen;
		} else if (ch == Ctrl('A') || ch == KEY_HOME) {
			cur = 0;
		} else if (isprint2(ch) && clen < len - 1) {
			if (buf[cur] != '\0')
				memmove(buf + cur + 1, buf + cur, clen - cur);
			buf[cur++] = ch;
			buf[++clen] = '\0';
		}
	}

	screen_putc('\n');
	screen_flush();
	return clen;
}
コード例 #5
0
ファイル: chat.c プロジェクト: wyat/kbs
static int ent_chat(int chatnum)
{                               /* 进入聊天室 */
    chatcontext *pthis;
    char inbuf[128];
    int ch, cmdpos;
    int currchar;
    int modified;               /* the line is modified? -- wwj */
    int newmail;
    int page_pending = false;
    int chatting = true;
#ifdef NEW_HELP
    int oldhelpmode=helpmode;
#endif

    if (!strcmp(getCurrentUser()->userid, "guest"))
        return -1;
    pthis = (chatcontext *) malloc(sizeof(chatcontext));
    bzero(pthis, sizeof(chatcontext));
    if (!pthis)
        return -1;
    modify_user_mode(CHAT1);
    ch = ent_chat_conn(pthis, chatnum);
    if (ch != 1) {
        free(pthis);
        return ch;
    }
#ifdef NEW_HELP
    helpmode=HELP_CHAT;
#endif
    add_io(pthis->cfd, 0);
    modified = newmail = cmdpos = currchar = 0;
    /* update uinfo */
    uinfo.in_chat = true;
    strcpy(uinfo.chatid, pthis->chatid);
    UPDATE_UTMP(in_chat, uinfo);
    UPDATE_UTMP_STR(chatid, uinfo);
    /* initiate screen */
    clear();
    pthis->chatline = 2;
    move(s_lines, 0);
    outs(msg_seperator);
    move(1, 0);
    outs(msg_seperator);
    print_chatid(pthis);
    memset(inbuf, 0, 80);
    /* chat begin */
    while (chatting) {
        if (chat_checkparse(pthis) == 0)
            break;
        move(b_lines, currchar + 10);
        pthis->outputcount = 0;
        ch = igetkey();
        if (ch==KEY_TALK) {
            int talkpage = servicepage(0, pthis->buf);

            if (talkpage != page_pending) {
                bell();
                oflush();
                printchatline(pthis, pthis->buf);
                page_pending = talkpage;
            }
        }
        if (chat_checkparse(pthis) == 0)
            break;
        if (ch == I_OTHERDATA)
            continue;
        switch (ch) {
            case KEY_UP:
            case KEY_DOWN:
                if (cmdpos == pthis->cmdpos) {
                    strcpy(pthis->lastcmd[cmdpos], inbuf);
                    modified = 0;
                }
                if (ch == KEY_UP) {
                    if (cmdpos != (pthis->cmdpos + 1) % MAXLASTCMD) {
                        int i = (cmdpos + MAXLASTCMD - 1) % MAXLASTCMD;

                        if (pthis->lastcmd[i][0])
                            cmdpos = i;
                    }
                }
                if (ch == KEY_DOWN) {
                    if (cmdpos != pthis->cmdpos)
                        cmdpos = (cmdpos + 1) % MAXLASTCMD;
                }
                strcpy(inbuf, pthis->lastcmd[cmdpos]);
                if (cmdpos == pthis->cmdpos) {
                    modified = 1;
                }
                move(b_lines, 10);
                clrtoeol();
                ch = inbuf[69];
                inbuf[69] = 0;
                outs(inbuf);
                inbuf[69] = ch;
                currchar = strlen(inbuf);
                continue;
#ifdef CHINESE_CHARACTER
            case Ctrl('R'):
                SET_CHANGEDEFINE(getCurrentUser(), DEF_CHCHAR);
                continue;
#endif
            case KEY_LEFT:
                if (currchar)
                    --currchar;
#ifdef CHINESE_CHARACTER
                if (DEFINE(getCurrentUser(), DEF_CHCHAR)) {
                    int i,j=0;
                    for (i=0;i<currchar;i++)
                        if (j) j=0;
                        else if (inbuf[i]<0) j=1;
                    if (j) {
                        currchar--;
                    }
                }
#endif
                continue;
            case KEY_RIGHT:
                if (inbuf[currchar])
                    ++currchar;
#ifdef CHINESE_CHARACTER
                if (DEFINE(getCurrentUser(), DEF_CHCHAR)) {
                    int i,j=0;
                    for (i=0;i<currchar;i++)
                        if (j) j=0;
                        else if (inbuf[i]<0) j=1;
                    if (j) {
                        if (inbuf[currchar])
                            ++currchar;
                    }
                }
#endif
                continue;
            case KEY_ESC:
            case Ctrl('X'):
                inbuf[0] = 0;
                currchar = 0;
                move(b_lines, currchar + 10);
                clrtoeol();
                modified = 1;
                continue;
            case Ctrl('A'):
                currchar = 0;
                continue;
            case Ctrl('E'):
                currchar = strlen(inbuf);
                continue;
        }
        if (!newmail && chkmail(0)) {   /* check mail */
            newmail = 1;
            printchatline(pthis, "\033[32m*** \033[31m当!你有新信来啦...\033[m");
        }
        if (isprint2(ch)) {
            if (currchar < 126) {       /* 未满一行,print it */
                modified = 1;
                if (inbuf[currchar]) {  /* insert */
                    int i;

                    for (i = currchar; inbuf[i] && i < 127; i++);
                    inbuf[i + 1] = '\0';
                    for (; i > currchar; i--)
                        inbuf[i] = inbuf[i - 1];
                } else {        /* append */
                    inbuf[currchar + 1] = '\0';
                }
                inbuf[currchar] = ch;
                ch = inbuf[69]; /* save the end of line */
                inbuf[69] = 0;
                move(b_lines, currchar + 10);
                outs(&inbuf[currchar++]);
                inbuf[69] = ch;
            }
            continue;
        }
        if (ch == '\n' || ch == '\r') {
            if (currchar) {
                if (modified) {
                    /* add to command history */
                    ch = sizeof(pthis->lastcmd[pthis->cmdpos]) - 1;
                    strncpy(pthis->lastcmd[pthis->cmdpos], inbuf, ch);
                    pthis->lastcmd[pthis->cmdpos][ch] = 0;
                    pthis->cmdpos = (pthis->cmdpos + 1) % MAXLASTCMD;
                    cmdpos = pthis->cmdpos;
                } else {        /* use history, so can +1 */
                    cmdpos = (cmdpos + 1) % MAXLASTCMD;
                }
                if (inbuf[0] == '/' && Isspace(inbuf[1])) {     /* discard / b */
                    printchatline(pthis,
                                  "\x1b[37m*** \x1b[32m请输入正确的指令,使用/h寻求帮助\x1b[37m ***\x1b[m");
                } else {
                    chatting = chat_cmd(pthis, inbuf);  /*local命令处理 */
                    if (chatting == 0)
                        chatting = chat_send(pthis, inbuf);
                    if (inbuf[0] == '/') {
                        ch = 1;
                        while (inbuf[ch] != '\0' && inbuf[ch] != ' ')
                            ch++;
                        if (ch > 1) {
                            if (!strncasecmp(inbuf, "/bye", ch))
                                break;
                            if (!strncasecmp(inbuf, "/exit", ch))
                                break;  /*added by alex, 96.9.5 */
                        }
                    }
                }
                modified = 0;
                inbuf[0] = '\0';
                currchar = 0;
                move(b_lines, 10);
                clrtoeol();
            }
            continue;
        }
        if (ch == Ctrl('H') || ch == '\177') {  /*Backspace */
            if (currchar) {
                currchar--;
                inbuf[127] = '\0';
                memcpy(&inbuf[currchar], &inbuf[currchar + 1],
                       127 - currchar);
                move(b_lines, currchar + 10);
                clrtoeol();
                ch = inbuf[69]; /* save the end of line */
                inbuf[69] = 0;
                outs(&inbuf[currchar]);
                inbuf[69] = ch;
            }
#ifdef CHINESE_CHARACTER
            if (DEFINE(getCurrentUser(), DEF_CHCHAR)) {
                int i,j=0;
                for (i=0;i<currchar;i++)
                    if (j) j=0;
                    else if (inbuf[i]<0) j=1;
                if (j) {
                    currchar--;
                    inbuf[127] = '\0';
                    memcpy(&inbuf[currchar], &inbuf[currchar + 1],
                           127 - currchar);
                    move(b_lines, currchar + 10);
                    clrtoeol();
                    ch = inbuf[69]; /* save the end of line */
                    inbuf[69] = 0;
                    outs(&inbuf[currchar]);
                    inbuf[69] = ch;
                }
            }
#endif
            continue;
        }
        if (ch == Ctrl('Z')) {
            r_lastmsg();        /* Leeward 98.07.30 support msgX */
            inbuf[0] = '\0';
            currchar = 0;
            move(b_lines, 10);
            clrtoeol();
            continue;
        }
        if (ch == Ctrl('C') /*|| ch == Ctrl('D') */) {  /* ^C 退出 */
            chat_send(pthis, "/b");
            if (pthis->rec)
                set_rec(pthis,NULL);
            break;
        }
    }
    /* chat end */
    if (pthis->rec)set_rec(pthis,NULL);
    close(pthis->cfd);
    add_io(0, 0);
    uinfo.in_chat = false;
    uinfo.chatid[0] = '\0';
    UPDATE_UTMP(in_chat, uinfo);
    UPDATE_UTMP(chatid[0], uinfo);
    clear();
    free(pthis);
#ifdef NEW_HELP
    helpmode=oldhelpmode;
#endif
    return 0;
}
コード例 #6
0
ファイル: chat2.c プロジェクト: PichuChen/formosa
int t_chat2()
{
	int currchar;
	char inbuf[120];
	BOOL page_pending = FALSE;
	int ch;
	char seedstr[STRLEN];
	long seed;
	char rcvbuf[512];
	int chatport;
	char *mycrypt();


	if (check_page_perm() < 0)
		return C_FOOT;

	chatport = CHATPORT;
#if 1
	if (chatport == 0)
		chatport = 6177;
#endif

#if 0
#if	defined(NSYSUBBS1)
	getdata(1, 0, _msg_chat_1, genbuf, 2, ECHONOSP);
	if (genbuf[0] == '2')
		chatport = CHATPORT + 1;
#endif
#endif

	/* initialize */
	inbuf[0] = '\0';
	currchar = 0;
	chat_line = 0;

	if (!getdata(1, 0, "Enter Chat id: ", mychatid, CHATIDLEN, ECHONOSP))
		xstrncpy(mychatid, curuser.userid, CHATIDLEN);

	fixchatid(mychatid);

	if ((ac = ConnectServer(CHAT_SERVER, chatport)) < 0)
	{
		move(2, 0);
		outs(_msg_chat_3);
		refresh();
		sprintf(genbuf, "bbschatd %d", chatport);
		outdoor(genbuf);
		sleep(2);
		if ((ac = ConnectServer(CHAT_SERVER, chatport)) < 0)
		{
			perror("connect failed");
			pressreturn();
			return C_FULL;
		}
	}

	/* receive ChatServer Hello Welcome VersionInfo */
	net_gets(ac, genbuf, sizeof(genbuf));
	/* receive Random Number for Checksum */
	net_gets(ac, seedstr, sizeof(seedstr));
	seed = atol(mycrypt(seedstr));
	net_printf(ac, "USRID\t%s\t%ld\r\n", curuser.userid, seed);
	net_gets(ac, genbuf, sizeof(genbuf));
	if (strncmp(genbuf, "+OK", 3))	/* lthuang */
	{
		outs(_msg_chat_4);
		pressreturn();
		return C_FULL;
	}

	uinfo.mode = CHATROOM;
	xstrncpy(uinfo.chatid, mychatid, sizeof(uinfo.chatid));
	update_ulist(cutmp, &uinfo);

	/* set prompt */
	strcpy(prompt, mychatid);
	strcat(prompt, ":           ");
	prompt[SAYWORD_POINT] = '\0';

	draw_chat_screen();

	add_io(ac, 0);

	net_gets(ac, genbuf, sizeof(genbuf));	/* welcome !! */
	genbuf[strlen(genbuf) - 1] = '\0';
	printchatline(genbuf);
#if 0
	net_printf(ac, "JOIN\t%s\t%s\r\n", DEFAULT_CHANNAME, NOPASSWORD);
	net_gets(ac, genbuf, sizeof(genbuf));
#endif
	if (strcmp(mychatid, curuser.userid))
	{
		net_printf(ac, "NICKNAME\t%s\r\n", mychatid);
		net_gets(ac, genbuf, sizeof(genbuf));
	}

	/* Chat Main */
	while (1)
	{
		ch = getkey();
		if (PLINE != CUR_PLINE) {
			draw_chat_screen();
			continue;
		}
		if (talkrequest)
			page_pending = TRUE;
		if (page_pending)
			page_pending = servicepage(0);
		if (msqrequest)
		{
			add_io(0, 0);
			msqrequest = FALSE;
			msq_reply();
			add_io(ac, 0);
			continue;
		}

		if (ch == I_OTHERDATA)
		{
			if (!net_gets(ac, rcvbuf, sizeof(rcvbuf)))
				break;
			rcvbuf[strlen(rcvbuf) - 1] = '\0';	/* lthuang */
			if (rcvbuf[0] == '/')
			{
				char *p, *nick;

				if ((p = strchr(rcvbuf, '\t')) != NULL)
				{
					*p = '\0';
					if (cmp_wlist(iglist, rcvbuf + 1, strcmp))
						continue;

					nick = p + 1;
					if ((p = strchr(nick, '\t')) != NULL)
					{
						*p = '\0';

						if (cmp_wlist(iglist, nick, strcmp))
							continue;

						strcpy(genbuf, nick);
						strcat(genbuf, ":           ");
						genbuf[SAYWORD_POINT] = '\0';
						strcat(genbuf, ++p);
						printchatline(genbuf);
					}
				}
			}
#if 0
			else if (rcvbuf[0] == '*')
			{
				sprintf(genbuf, "%s", rcvbuf);
				printchatline(genbuf);
			}
#endif
			else
				printchatline(rcvbuf);
		}
		else if (isprint2(ch))
		{
			if (SAYWORD_POINT + currchar - 1 >= t_columns - 3)
			{
				bell();
				continue;
			}
			inbuf[currchar++] = ch;
			inbuf[currchar] = '\0';
			move(PLINE, SAYWORD_POINT + currchar - 1);
			outc(ch);
		}
		else if (ch == '\n' || ch == '\r')
		{
			char *p = inbuf;

			currchar = 0;

			while (*p != '\0' && isspace((int)(*p)))
				p++;
			if (*p == '\0')
				continue;
			if (inbuf[0] == '/')
				dochatcommand(inbuf + 1);
			else
			{
				net_printf(ac, "SPEAK\t%s\r\n", inbuf);
				sprintf(genbuf, "%s%s", prompt, inbuf);
				printchatline(genbuf);
			}

			inbuf[0] = '\0';

			/* show prompt */
			move(PLINE, 0);
			clrtoeol();
			outs(prompt);
		}
		else if (ch == CTRL('H') || ch == '\177')
		{
			if (currchar == 0)
			{
				bell();
				continue;
			}
			move(PLINE, SAYWORD_POINT + --currchar);
			outs(" ");
			inbuf[currchar] = '\0';
		}
		else if (ch == CTRL('C') || ch == CTRL('D'))
		{
			net_printf(ac, "QUIT\r\n");	/* lthuang */
			break;
		}
		else if (ch == CTRL('R'))
		{
			msq_reply();
			continue;
		}
		else if (ch == CTRL('Q'))
		{
			add_io(0, 0);
			t_query();
			add_io(ac, 0);
			continue;
		}
		move(PLINE, currchar + SAYWORD_POINT);
	}
	add_io(0, 0);
	close(ac);
	uinfo.chatid[0] = '\0';
	update_ulist(cutmp, &uinfo);
	free_wlist(&iglist, free);

	return C_FULL;
}
コード例 #7
0
ファイル: five.c プロジェクト: madoldman/inankai_bbs
int five_pk(int fd,int first)
{
    int cx, ch, cy,datac,fdone,x /* ,y */;
    char genbuf[100],data[90],xy_po[5],genbuf1[20] /* ,x1[1],y1[1],done[1] */;
    /*    struct user_info *opponent; */
    /*     char fname[50]; */
    int i,j /* ,k */,fway,banf,idone;


    /*
     *      Ôö¼ÓÁÄÌ칦ÄÜ. Added by satan. 99.04.02
     */

#define START    17
#define END      21
#define PROMPT   23
#undef MAX
#define MAX      (END - START)
#define BSIZE    60


    char chatbuf[80], *cbuf;
    int ptr = 0, chating = 0 /*, over = 0 */;

    setutmpmode(FIVE);       /*Óû§×´Ì¬ÉèÖÃ*/
    clear ();
    InitScreen();
    five_chat (NULL, 1);

    cbuf = chatbuf + 19;
    chatbuf[0] = '\0';
    chatbuf[79] = '\0';
    cbuf[0] = '\0';
    sprintf (chatbuf + 1, "%-16s: ", cuser.username);

    add_io(fd, 0);

begin:
    for(i=0; i<=14; i++)
        for(j=0; j<=14; j++)
            playboard[i][j]=0;


    hand=1;
    winner=0;
    quitf=0;
    px=14;
    py=7;
    fway = 1;
    banf = 1;
    idone = 0;


    sprintf(genbuf, "%s (%s)", cuser.userid, cuser.username);

    if(first)
    {
        move(1,33);
        prints("ºÚ¡ñÏÈÊÖ %s  ",genbuf);
        move(2,33);
        prints("°×¡ðºóÊÖ %s  ",save_page_requestor);
    }
    else
    {
        move(1,33);
        prints("°×¡ðºóÊÖ %s  ",genbuf);
        move(2,33);
        prints("ºÚ¡ñÏÈÊÖ %s  ",save_page_requestor);
    }


    move(15,35);
    if(first)
        outs("¡ïµÈ´ý¶Ô·½ÏÂ×Ó¡ï");
    else
        outs("¡ôÏÖÔÚ¸Ã×Ô¼ºÏ¡ô");
    move(7,14);
    outs("¡ñ");
    player=white;
    playboard[7][7]=black;
    chess[1][0]=14; /*¼Í¼ËùÏÂλַ*/
    chess[1][1]=7;
    move(4,35);
    outs("µÚ 1ÊÖ ¡ñH 8");

    if(!first)
    {   /*³¬¹Ö!*/
        move (7, 14);
        fdone=1;
    }
    else
        fdone=0;    /*¶ÔÊÖÍê³É*/

    while (1)
    {
        ch=igetkey();

        if (ch == I_OTHERDATA)
        {
            datac = recv(fd, data, sizeof(data), 0);
            if (datac <= 0)
            {
                move(17,30);
                outs(" ¶Ô·½Í¶½µÁË...@_@ ");
                break;
            }
            if (data[0] == '\0')
            {
                five_chat (data + 1, 0);
                if (chating)
                    move (PROMPT, ptr + 6);
                else
                    move (py, px);
                continue;
            }
            else if (data[0] == '\1')
            {
                bell ();
                RMSG = YEA;
                saveline (PROMPT, 0);
                sprintf (genbuf, "%s ˵: ÖØÀ´Ò»Å̺ÃÂð? (Y/N)[Y]:", save_page_requestor);
                getdata (PROMPT, 0, genbuf, genbuf1, 2, LCECHO, YEA);
                RMSG = NA;
                if (genbuf1[0] == 'n' || genbuf1[0] == 'N')
                {
                    saveline (PROMPT, 1);
                    send (fd, "\3", 1, 0);
                    continue;
                }
                else
                {
                    saveline (PROMPT, 1);
                    InitScreen ();
                    first = 0;
                    send (fd, "\2", 1, 0);
                    goto begin;
                }
            }
            else if (data[0] == '\2')
            {
                bell ();
                saveline (PROMPT, 0);
                move (PROMPT, 0);
                clrtoeol ();
                prints ("%s ½ÓÊÜÁËÄãµÄÇëÇó :-)", save_page_requestor);
                refresh ();
                sleep (1);
                saveline (PROMPT, 1);
                InitScreen ();
                first = 1;
                goto begin;
            }
            else if (data[0] == '\3')
            {
                bell ();
                saveline (PROMPT, 0);
                move (PROMPT, 0);
                clrtoeol ();
                prints ("%s ¾Ü¾øÁËÄãµÄÇëÇó :-(", save_page_requestor);
                refresh ();
                sleep (1);
                saveline (PROMPT, 1);
                if (chating)
                    move (PROMPT, ptr + 6);
                else
                    move (py, px);
                continue;
            }
            else if (data[0] == '\xff')
            {
                move (PROMPT, 0);
                quit ();
                break;
            }
            i=atoi(data);
            cx=i/1000;   /*½âÒëdata³ÉÆåÅÌ×ÊÁÏ*/
            cy=(i%1000)/10;
            fdone=i%10;
            hand+=1;

            if(hand%2==0)
                move(((hand-1)%20)/2+4,48);
            else
                move(((hand-1)%19)/2+4,35);

            prints("µÚ%2dÊÖ %s%c%2d",hand,
                   (player==black)?"¡ñ":"¡ð",abcd[cx/2],15-cy);


            move(cy,cx);
            x=cx/2;
            playboard[x][cy]=player;
            if(player==black)
            {
                outs("¡ñ");
                player=white;
            }
            else
            {
                outs("¡ð");
                player=black;
            }
            move (cy, cx);
            refresh ();
            bell ();
            move(15,35);
            outs("¡ôÏÖÔÚ¸Ã×Ô¼ºÏ¡ô");
            haha (5);

            tdeadf=tlivef=livethree=threefour=0;
            for(j=0; j<=10; j++)
                calvalue(cx/2,j,cx/2,j+1,cx/2,j+2,cx/2,j+3,cx/2,j+4);
            for(i=0; i<=10; i++) /*ºáÏò*/
                calvalue(i,cy,i+1,cy,i+2,cy,i+3,cy,i+4,cy);
            for(i=-4; i<=0; i++) /*бÓÒÏÂ*/
                calvalue(cx/2+i,cy+i,cx/2+i+1,cy+i+1,cx/2+i+2,cy+i+2,
                         cx/2+i+3,cy+i+3,cx/2+i+4,cy+i+4);
            for(i=-4; i<=0; i++) /*б×óÏÂ*/
                calvalue(cx/2-i,cy+i,cx/2-i-1,cy+i+1,cx/2-i-2,cy+i+2,cx/2-i-3,
                         cy+i+3,cx/2-i-4,cy+i+4);

            for(j=0; j<=9; j++)
                callfour(cx/2,j,cx/2,j+1,cx/2,j+2,cx/2,j+3,cx/2,j+4,cx/2,j+5);
            for(i=0; i<=9; i++) /*ËĺáÏò*/
                callfour(i,cy,i+1,cy,i+2,cy,i+3,cy,i+4,cy,i+5,cy);
            for(i=-5; i<=0; i++)
            {   /*ËÄбÓÒÏÂ*/
                callfour(cx/2+i,cy+i,cx/2+i+1,cy+i+1,cx/2+i+2,cy+i+2,
                         cx/2+i+3,cy+i+3,cx/2+i+4,cy+i+4,cx/2+i+5,cy+i+5);
                /*ËÄб×óÏÂ*/
                callfour(cx/2-i,cy+i,cx/2-i-1,cy+i+1,cx/2-i-2,cy+i+2,cx/2-i-3,
                         cy+i+3,cx/2-i-4,cy+i+4,cx/2-i-5,cy+i+5);
            }

            py = cy;
            px = cx;
            if(tlivef>=2 && winner==0)
                bandhand(4);
            if(livethree>=2 && tlivef ==0)
                bandhand(3);
            if(threefour==black)
                haha(1);
            else if(threefour==white)
                haha(1);
            if (chating)
            {
                sleep (1);
                move (PROMPT, ptr + 6);
            }
            else
                move (py, px);
            if (winner)
            {
                InitScreen ();
                goto begin;
            }
        }
        else
        {
            if (ch == Ctrl('X'))
            {
                quitf = 1;
            }
            else if (ch==Ctrl('C') || ((ch=='Q' || ch=='q') && !chating))
            {
                RMSG = YEA;
                saveline (PROMPT, 0);
                getdata(PROMPT, 0, "ÄúÈ·¶¨ÒªÀ뿪Âð? (Y/N)?[N] ", genbuf1, 2, LCECHO, YEA);
                if (genbuf1[0] == 'Y' || genbuf1[0] == 'y')
                    quitf = 1;
                else
                    quitf = 0;
                saveline (PROMPT, 1);
                RMSG = NA;
            }
            else if (ch==Ctrl('N') || ((ch=='N' || ch=='n') && !chating))
            {
                saveline (PROMPT, 0);
                RMSG = YEA;
                getdata(PROMPT,0,"ÄúÈ·¶¨ÒªÖØпªÊ¼Âð? (Y/N)?[N] ",genbuf1,2,LCECHO, YEA);
                if (genbuf1[0] == 'Y' || genbuf1[0] == 'y')
                {
                    send (fd, "\1", 1, 0);
                    move (PROMPT, 0);
                    bell ();
                    clrtoeol ();
                    move (PROMPT, 0);
                    outs ("ÒѾ­ÒѾ­ÌæÄú·¢³öÇëÇóÁË");
                    refresh ();
                    sleep (1);
                }
                RMSG = NA;
                saveline (PROMPT, 1);
                if (chating)
                    move (PROMPT, ptr + 6);
                else
                    move (py, px);
                continue;
            }
            else if (ch == '\t')
            {
                if (chating)
                {
                    chating = 0;
                    move (py, px);
                }
                else
                {
                    chating = 1;
                    move (PROMPT, 6 + ptr);
                }
                continue;
            }
            else if (ch == '\0')
                continue;
            else if (chating)
            {
                if (ch == '\n' || ch == '\r')
                {
                    if (!cbuf[0])
                        continue;
                    ptr = 0;
                    five_chat (chatbuf + 1, 0);
                    send (fd, chatbuf, strlen (chatbuf + 1) + 2, 0);
                    cbuf[0] = '\0';
                    move (PROMPT, 6);
                    clrtoeol ();
                }
                else if (ch == KEY_LEFT)
                {
                    if (ptr)
                        ptr --;
                }
                else if (ch == KEY_RIGHT)
                {
                    if (cbuf[ptr])
                        ptr ++;
                }
                else if (ch == Ctrl ('H') || ch == '\177')
                {
                    if (ptr)
                    {
                        ptr --;
                        memcpy (&cbuf[ptr], &cbuf[ptr+1], BSIZE-ptr);
                        move (PROMPT, ptr+6);
                        clrtoeol ();
                        prints ("%s",&cbuf[ptr]);
                    }
                }
                else if (ch == KEY_DEL)
                {
                    if (cbuf[ptr])
                    {
                        memcpy (&cbuf[ptr], &cbuf[ptr+1], BSIZE-ptr);
                        clrtoeol ();
                        prints ("%s",&cbuf[ptr]);
                    }
                }
                else if (ch == Ctrl ('A'))
                {
                    ptr = 0;
                }
                else if (ch == Ctrl ('E'))
                {
                    while (cbuf[++ptr])
                        ;
                }
                else if (ch == Ctrl ('K'))
                {
                    ptr = 0;
                    cbuf[ptr] = '\0';
                    move (PROMPT, ptr+6);
                    clrtoeol ();
                }
                else if (ch == Ctrl ('U'))
                {
                    memmove (cbuf, &cbuf[ptr], BSIZE - ptr + 1);
                    ptr = 0;
                    move (PROMPT, ptr+6);
                    clrtoeol ();
                    prints ("%s",cbuf);
                }
                else if (ch == Ctrl ('W'))
                {
                    if (ptr)
                    {
                        int optr;

                        optr = ptr;
                        ptr --;
                        do
                        {
                            if (cbuf[ptr] != ' ')
                                break;
                        }
                        while (-- ptr);
                        do
                        {
                            if (cbuf[ptr] == ' ')
                            {
                                if (cbuf[ptr+1] != ' ')
                                    ptr ++;
                                break;
                            }
                        }
                        while (-- ptr);
                        memcpy (&cbuf[ptr], &cbuf[optr], BSIZE-optr+1);
                        move (PROMPT, ptr+6);
                        clrtoeol ();
                        prints ("%s",&cbuf[ptr]);
                    }
                }
                else if (isprint2 (ch))
                {
                    if (ptr == BSIZE)
                        continue;
                    if (!cbuf[ptr])
                    {
                        cbuf[ptr] = ch;
                        move (PROMPT, 6 + ptr);
                        outc (ch);
                        cbuf[++ptr] = 0;
                    }
                    else
                    {
                        memmove (&cbuf[ptr+1], &cbuf[ptr], BSIZE-ptr+1);
                        cbuf[ptr] = ch;
                        move (PROMPT, 6 + ptr);
                        prints ("%s",&cbuf[ptr]);
                        ptr ++;
                    }
                }
                move (PROMPT, 6 + ptr);
                continue;
            }
        }

        if(fdone==1 && !chating && ch != I_OTHERDATA)/*»»ÎÒ*/
        {

            move(py,px);
            switch (ch)
            {

            case KEY_DOWN:
            case 'j':
            case 'J':
                py=py+1;
                if(py>14)
                    py=0;
                break;

            case KEY_UP:
            case 'k':
            case 'K':
                py=py-1;
                if(py<0)
                    py=14;
                break;

            case KEY_LEFT:
            case 'h':
            case 'H':
                px=px-1;
                if(px<0)
                    px=28;
                break;

            case KEY_RIGHT:
            case 'l':
            case 'L':
                px=px+1;
                if(px>28)
                {
                    px=0;
                    px=px-1;
                }                      /*»áÌø¸ñßÖ*/
                break;
            case ' ':
                if(banf==1)
                    break;

                if((px%2)==1)
                    px=px-1; /*½â¾önetterm²»ºÏÎÊÌâ*/
                move(py,px);
                hand+=1;
                playboard[x][py]=player;
                if(player==black)
                {
                    outs("¡ñ");
                    player=white;
                }
                else
                {
                    outs("¡ð");
                    player=black;
                }
                chess[hand][0]=px;
                chess[hand][1]=py;
                if(hand%2==0)
                    move(((hand-1)%20)/2+4,48);
                else
                    move(((hand-1)%19)/2+4,35);

                prints("µÚ%2dÊÖ %s%c%2d",hand,
                       (hand%2==1)?"¡ñ":"¡ð",abcd[px/2],15-py);
                idone=1;
                move (py, px);
                refresh ();
                break;
            default:
                break;
            }
            move(py,px);
            x=px/2;
            if(playboard[x][py]!=0)
                banf=1;
            else
                banf=0;

            if(idone==1)
            {
                xy_po[0] = px/10 + '0';
                xy_po[1] = px%10 + '0';
                xy_po[2] = py/10 + '0';
                xy_po[3] = py%10 + '0';
                fdone=0;
                xy_po[4]='1';
                if(send(fd,xy_po,sizeof(xy_po),0)==-1)
                    break;

                move(15,35);
                outs("¡ïµÈ´ý¶Ô·½ÏÂ×Ó¡ï");
                haha (5);

                tdeadf=tlivef=livethree=threefour=0;
                for(j=0; j<=10; j++)
                    calvalue(px/2,j,px/2,j+1,px/2,j+2,px/2,j+3,px/2,j+4);
                for(i=0; i<=10; i++) /*ºáÏò*/
                    calvalue(i,py,i+1,py,i+2,py,i+3,py,i+4,py);
                for(i=-4; i<=0; i++) /*бÓÒÏÂ*/
                    calvalue(px/2+i,py+i,px/2+i+1,py+i+1,px/2+i+2,py+i+2,
                             px/2+i+3,py+i+3,px/2+i+4,py+i+4);
                for(i=-4; i<=0; i++) /*б×óÏÂ*/
                    calvalue(px/2-i,py+i,px/2-i-1,py+i+1,px/2-i-2,py+i+2,px/2-i-3,
                             py+i+3,px/2-i-4,py+i+4);

                for(j=0; j<=9; j++)
                    callfour(px/2,j,px/2,j+1,px/2,j+2,px/2,j+3,px/2,j+4,px/2,j+5);
                for(i=0; i<=9; i++) /*ËĺáÏò*/
                    callfour(i,py,i+1,py,i+2,py,i+3,py,i+4,py,i+5,py);
                for(i=-5; i<=0; i++)
                {   /*ËÄбÓÒÏÂ*/
                    callfour(px/2+i,py+i,px/2+i+1,py+i+1,px/2+i+2,py+i+2,
                             px/2+i+3,py+i+3,px/2+i+4,py+i+4,px/2+i+5,py+i+5);
                    /*ËÄб×óÏÂ*/
                    callfour(px/2-i,py+i,px/2-i-1,py+i+1,px/2-i-2,py+i+2,px/2-i-3,
                             py+i+3,px/2-i-4,py+i+4,px/2-i-5,py+i+5);
                }

                if(tlivef>=2 && winner==0)
                    bandhand(4);
                if(livethree>=2 && tlivef ==0)
                    bandhand(3);
                if(threefour==black)
                    haha(1);
                else if(threefour==white)
                    haha(1);

            }
            idone=0;
        }
        if (quitf)
        {
            genbuf1[0] = '\xff';
            send (fd, genbuf1, 1, 0);
            press ();
            break;
        }
        if (winner)
        {
            InitScreen ();
            goto begin;
        }
    }

    add_io(0, 0);
    close(fd);
    return;
}
コード例 #8
0
ファイル: addr_manage.c プロジェクト: marvelliu/lilacsrc
int add_addresslist( struct addresslist * oldal ){

	struct addresslist al;
	char ans[110];
	char anss[4];

	bzero(&al,sizeof(al));
	if( oldal ){
		memcpy(&al, oldal, sizeof(al));
	}
	clear();
	move(0,0);
	ans[0]=0;
	prints("                                 增加通讯录条目\n");
	prints("\033[1;31m------------------------------------------------------------------------\033[m\n");

	if(oldal)
		strcpy(ans, oldal->name);
	else
		ans[0]=0;
	getdata(2, 0, "请输入姓名(不可空):", ans, 16, DOECHO, NULL, false);
	if( ans[0] == '\n' || ( ans[0] == 0 && oldal == NULL ) || ans[0]=='\r' || !isprint2(ans[0])){
		prints("\n取消...");
		pressanykey();
		return 0;
	}
	if( ans[0] == 0 )
		strcpy(al.name, oldal->name);
	else
		strncpy(al.name, ans, 15);
	al.name[14]=0;

	if(oldal)
		strcpy(ans, oldal->bbsid);
	else
		ans[0]=0;
	getdata(3, 0, "请输入bbsid:", ans, 15, DOECHO, NULL, false);
	strncpy(al.bbsid, ans, 15);
	al.bbsid[14]=0;

	if(oldal)
		strcpy(ans, oldal->mobile);
	else
		ans[0]=0;
	getdata(4, 0, "请输入移动电话:", ans, 15, DOECHO, NULL, false);
	strncpy(al.mobile, ans, 15);
	al.mobile[14]=0;

	if(oldal)
		strcpy(ans, oldal->group);
	else
		ans[0]=0;
	getdata(5, 0, "请输入分组名称:", ans, 10, DOECHO, NULL, false);
	strncpy(al.group, ans, 10);
	al.group[9]=0;

	if(oldal)
		strcpy(ans, oldal->school);
	else
		ans[0]=0;
	getdata(6, 0, "请输入学校:", ans, 100, DOECHO, NULL, false);
	strncpy(al.school, ans, 100);
	al.school[99]=0;

	if(oldal)
		strcpy(ans, oldal->zipcode);
	else
		ans[0]=0;
	getdata(7, 0, "请输入邮政编码:", ans, 7, DOECHO, NULL, false);
	strncpy(al.zipcode, ans, 7);
	al.zipcode[6]=0;

	if(oldal)
		strcpy(ans, oldal->homeaddr);
	else
		ans[0]=0;
	getdata(8, 0, "请输入家庭地址:", ans, 100, DOECHO, NULL, false);
	strncpy(al.homeaddr, ans, 100);
	al.homeaddr[99]=0;

	if(oldal)
		strcpy(ans, oldal->companyaddr);
	else
		ans[0]=0;
	getdata(9, 0, "请输入工作地址:", ans, 100, DOECHO, NULL, false);
	strncpy(al.companyaddr, ans, 100);
	al.companyaddr[99]=0;

	if(oldal)
		strcpy(ans, oldal->tel_h);
	else
		ans[0]=0;
	getdata(10, 0, "请输入家庭电话:", ans, 20, DOECHO, NULL, false);
	strncpy(al.tel_h, ans, 20);
	al.tel_h[19]=0;

	if(oldal)
		strcpy(ans, oldal->tel_o);
	else
		ans[0]=0;
	getdata(11, 0, "请输入工作电话:", ans, 20, DOECHO, NULL, false);
	strncpy(al.tel_o, ans, 20);
	al.tel_o[19]=0;

	if(oldal)
		strcpy(ans, oldal->email);
	else
		ans[0]=0;
	getdata(12, 0, "请输入电子邮箱:", ans, 30, DOECHO, NULL, false);
	strncpy(al.email, ans, 30);
	al.email[29]=0;

	if(oldal)
		strcpy(ans, oldal->qq);
	else
		ans[0]=0;
	getdata(13, 0, "请输入qq:", ans, 10, DOECHO, NULL, false);
	strncpy(al.qq, ans, 10);
	al.qq[9]=0;

	if(oldal)
		sprintf(ans,"%d", oldal->birth_year);
	else
		ans[0]=0;
	getdata(14, 0, "请输入生日年份:", ans, 5, DOECHO, NULL, false);
	al.birth_year = atoi(ans);
	if(al.birth_year <= 0)
		al.birth_year = 1;
	if(al.birth_year < 1000)
		al.birth_year += 1000;
	if(al.birth_year > 9000)
		al.birth_year = 9000;

	if(oldal)
		sprintf(ans,"%d", oldal->birth_month);
	else
		ans[0]=0;
	getdata(15, 0, "请输入生日月份:", ans, 3, DOECHO, NULL, false);
	al.birth_month = atoi(ans);
	if(al.birth_month <= 0)
		al.birth_month = 1;
	if(al.birth_month >12)
		al.birth_month = 12;

	if(oldal)
		sprintf(ans,"%d", oldal->birth_day);
	else
		ans[0]=0;
	getdata(16, 0, "请输入生日日期:", ans, 3, DOECHO, NULL, false);
	al.birth_day = atoi(ans);
	if(al.birth_day <= 0)
		al.birth_day = 1;
	if(al.birth_day >31)
		al.birth_day = 31;

	if(oldal)
		strcpy(ans, oldal->memo);
	else
		ans[0]=0;
	move(17,0);
	prints("请输入备注:\n");
	multi_getdata(18, 0, 79, NULL, ans, 100, 4, false, 0);
	ans[99]=0;

	if( oldal )
		getdata(t_lines-1, 0, "确定修改? (Y/N) [Y]:", anss, 3, DOECHO, NULL, true);
	else
		getdata(t_lines-1, 0, "确定增加? (Y/N) [Y]:", anss, 3, DOECHO, NULL, true);

	if( anss[0] != 'N' && anss[0] != 'n' )
		return add_sql_al( getCurrentUser()->userid, &al, ans );

	return 0;
}
コード例 #9
0
ファイル: newio.c プロジェクト: zhouqt/kbs
int multi_getdata(int line, int col, int maxcol, char *prompt, char *buf, int len, int maxline, int clearlabel, int textmode)
{
    int ch, x, y, startx, starty, now, i, j, k, i0, chk, cursorx, cursory;
    char savebuffer[25][LINELEN*3];
    bool init=true;
    char tmp[1024];
    extern int RMSG;

    /*************stiger************
     * textmode 0 :  ctrl+q换行,enter发表
     * textmode 1 :  enter换行,ctrl+w发送
     *********************************/

    if (uinfo.mode!=MSGING && uinfo.mode != POSTTMPL)
        ingetdata = true;
    if (clearlabel == true) {
        buf[0] = 0;
    }
    move(line, col);
    if (prompt)
        prints("%s", prompt);
    getyx(&starty, &startx);
    now = strlen(buf);
    for (i=0; i<=24; i++)
        saveline(i, 0, savebuffer[i]);
    strncpy(tmp, buf, 1024);
    tmp[1023]=0;
    cursory = starty;
    cursorx = startx;

    while (1) {
        y = starty; x = startx;
        move(y, x);
        chk = 0;
        if (now==0) {
            cursory = y;
            cursorx = x;
        }
        for (i=0; i<strlen(buf); i++) {
            if (chk) chk=0;
            else if (buf[i]<0) chk=1;
            if (chk&&x>=maxcol) x++;
            if (buf[i]!=13&&buf[i]!=10) {
                if (x>maxcol) {
                    clrtoeol();
                    x = 0;
                    y++;
                    if (y>=scr_lns) {
                        scroll();
                        starty--;
                        cursory--;
                        y--;
                    }
                    move(y, x);
                }
                if (init) prints("\x1b[4m");
                prints("%c", buf[i]);
                resetcolor();
                x++;
            } else {
                clrtoeol();
                x = 0;
                y++;
                if (y>=scr_lns) {
                    scroll();
                    starty--;
                    cursory--;
                    y--;
                }
                move(y, x);
            }
            if (i==now-1) {
                cursory = y;
                cursorx = x;
            }
        }
        clrtoeol();
        move(cursory, cursorx);
        ch = igetkey();
        if (textmode == 0) {
            if ((ch == '\n' || ch == '\r'))
                break;
        } else {
            if (ch == Ctrl('W'))
                break;
        }
        for (i=starty; i<=y; i++)
            saveline(i, 1, savebuffer[i]);
        if (true == RMSG && (KEY_UP == ch || KEY_DOWN == ch) && (!buf[0])) {
            ingetdata = false;
            return -ch;
        }
        if (true == UPDOWN && (KEY_UP == ch || KEY_DOWN == ch)) {
            ingetdata = false;
            return -ch;
        }
#if 0 //#ifdef NINE_BUILD
        if (RMSG && (ch == Ctrl('Z')) && (!buf[0])) {
            ingetdata = false;
            return -ch;
        }
#endif
#ifdef CHINESE_CHARACTER
        if (ch == Ctrl('R')) {
            init=false;
            SET_CHANGEDEFINE(getCurrentUser(), DEF_CHCHAR);
            continue;
        }
#endif
        switch (ch) {
            case KEY_ESC:
                init=true;
                strncpy(buf, tmp, Min(len,STRLEN));
                buf[Min(len,1024-1)]=0;
                now=strlen(buf);
                break;
            case Ctrl('W'):
            case Ctrl('Q'):
            case '\n':
            case '\r':
                if (init) {
                    init=false;
                    buf[0]=0;
                    now=0;
                }
                if (UPDOWN) break;
                if (y-starty+1<maxline) {
                    for (i=strlen(buf)+1; i>now; i--)
                        buf[i]=buf[i-1];
                    buf[now++]='\n';
                }
                break;
            case KEY_UP:
                init=false;
                if (cursory>starty) {
                    y = starty; x = startx;
                    chk = 0;
                    if (y==cursory-1&&x<=cursorx)
                        now=0;
                    for (i=0; i<strlen(buf); i++) {
                        if (chk) chk=0;
                        else if (buf[i]<0) chk=1;
                        if (chk&&x>=maxcol) x++;
                        if (buf[i]!=13&&buf[i]!=10) {
                            if (x>maxcol) {
                                x = col;
                                y++;
                            }
                            x++;
                        } else {
                            x = col;
                            y++;
                        }
#ifdef CHINESE_CHARACTER
                        if (!DEFINE(getCurrentUser(), DEF_CHCHAR)||!chk)
#endif
                            if (y==cursory-1&&x<=cursorx)
                                now=i+1;
                    }
                }
                break;
            case KEY_DOWN:
                init=false;
                if (cursory<y) {
                    y = starty; x = startx;
                    chk = 0;
                    if (y==cursory+1&&x<=cursorx)
                        now=0;
                    for (i=0; i<strlen(buf); i++) {
                        if (chk) chk=0;
                        else if (buf[i]<0) chk=1;
                        if (chk&&x>=maxcol) x++;
                        if (buf[i]!=13&&buf[i]!=10) {
                            if (x>maxcol) {
                                x = col;
                                y++;
                            }
                            x++;
                        } else {
                            x = col;
                            y++;
                        }
#ifdef CHINESE_CHARACTER
                        if (!DEFINE(getCurrentUser(), DEF_CHCHAR)||!chk)
#endif
                            if (y==cursory+1&&x<=cursorx)
                                now=i+1;
                    }
                }
                break;
            case '\177':
            case Ctrl('H'):
                if (init) {
                    init=false;
                    buf[0]=0;
                    now=0;
                }
                if (now>0) {
                    for (i=now-1; i<strlen(buf); i++)
                        buf[i]=buf[i+1];
                    now--;
#ifdef CHINESE_CHARACTER
                    if (DEFINE(getCurrentUser(), DEF_CHCHAR)) {
                        chk = 0;
                        for (i=0; i<now; i++) {
                            if (chk) chk=0;
                            else if (buf[i]<0) chk=1;
                        }
                        if (chk) {
                            for (i=now-1; i<strlen(buf); i++)
                                buf[i]=buf[i+1];
                            now--;
                        }
                    }
#endif
                }
                break;
            case KEY_DEL:
                if (init) {
                    init=false;
                    buf[0]=0;
                    now=0;
                }
                if (now<strlen(buf)) {
#ifdef CHINESE_CHARACTER
                    if (DEFINE(getCurrentUser(), DEF_CHCHAR)) {
                        chk = 0;
                        for (i=0; i<now+1; i++) {
                            if (chk) chk=0;
                            else if (buf[i]<0) chk=1;
                        }
                        if (chk)
                            for (i=now; i<strlen(buf); i++)
                                buf[i]=buf[i+1];
                    }
#endif
                    for (i=now; i<strlen(buf); i++)
                        buf[i]=buf[i+1];
                }
                break;
            case KEY_LEFT:
                init=false;
                if (now>0) {
                    now--;
#ifdef CHINESE_CHARACTER
                    if (DEFINE(getCurrentUser(), DEF_CHCHAR)) {
                        chk = 0;
                        for (i=0; i<now; i++) {
                            if (chk) chk=0;
                            else if (buf[i]<0) chk=1;
                        }
                        if (chk) now--;
                    }
#endif
                }
                break;
            case KEY_RIGHT:
                init=false;
                if (now<strlen(buf)) {
                    now++;
#ifdef CHINESE_CHARACTER
                    if (DEFINE(getCurrentUser(), DEF_CHCHAR)) {
                        chk = 0;
                        for (i=0; i<now; i++) {
                            if (chk) chk=0;
                            else if (buf[i]<0) chk=1;
                        }
                        if (chk) now++;
                    }
#endif
                }
                break;
            case KEY_HOME:
            case Ctrl('A'):
                init=false;
                now--;
                while (now>=0&&buf[now]!='\n'&&buf[now]!='\r') now--;
                now++;
                break;
            case KEY_END:
            case Ctrl('E'):
                init=false;
                while (now<strlen(buf)&&buf[now]!='\n'&&buf[now]!='\r') now++;
                break;
            case KEY_PGUP:
                init=false;
                now=0;
                break;
            case KEY_PGDN:
                init=false;
                now = strlen(buf);
                break;
            case Ctrl('Y'):
                if (init) {
                    init=false;
                    buf[0]=0;
                    now=0;
                }
                i0 = strlen(buf);
                i=now-1;
                while (i>=0&&buf[i]!='\n'&&buf[i]!='\r') i--;
                i++;
                if (!buf[i]) break;
                j=now;
                while (j<i0-1&&buf[j]!='\n'&&buf[j]!='\r') j++;
                if (j>=i0-1) j=i0-1;
                j=j-i+1;
                if (j<0) j=0;
                for (k=0; k<i0-i-j+1; k++)
                    buf[i+k]=buf[i+j+k];

                y = starty; x = startx;
                chk = 0;
                if (y==cursory&&x<=cursorx)
                    now=0;
                for (i=0; i<strlen(buf); i++) {
                    if (chk) chk=0;
                    else if (buf[i]<0) chk=1;
                    if (chk&&x>=maxcol) x++;
                    if (buf[i]!=13&&buf[i]!=10) {
                        if (x>maxcol) {
                            x = col;
                            y++;
                        }
                        x++;
                    } else {
                        x = col;
                        y++;
                    }
#ifdef CHINESE_CHARACTER
                    if (!DEFINE(getCurrentUser(), DEF_CHCHAR)||!chk)
#endif
                        if (y==cursory&&x<=cursorx)
                            now=i+1;
                }

                if (now>strlen(buf)) now=strlen(buf);
                break;
            default:
                if (isprint2(ch)&&strlen(buf)<len-1) {
                    if (init) {
                        init=false;
                        buf[0]=0;
                        now=0;
                    }
                    for (i=strlen(buf)+1; i>now; i--)
                        buf[i]=buf[i-1];
                    buf[now++]=ch;
                    y = starty; x = startx;
                    chk = 0;
                    for (i=0; i<strlen(buf); i++) {
                        if (chk) chk=0;
                        else if (buf[i]<0) chk=1;
                        if (chk&&x>=maxcol) x++;
                        if (buf[i]!=13&&buf[i]!=10) {
                            if (x>maxcol) {
                                x = col;
                                y++;
                            }
                            x++;
                        } else {
                            x = col;
                            y++;
                        }
                    }
                    if (y-starty+1>maxline) {
                        for (i=now-1; i<strlen(buf); i++)
                            buf[i]=buf[i+1];
                        now--;
                    }
                }
                init=false;
                break;
        }
    }

    ingetdata = false;
    return y-starty+1;
}
コード例 #10
0
ファイル: newio.c プロジェクト: zhouqt/kbs
/*
 * ret:  -1: user cancel input
 */
int getdata(int line, int col, char *prompt, char *buf, int len, int echo, void *nouse, int clearlabel)
{
    int ch, clen = 0, curr = 0, x, y;
    bool init=true;
    char tmp[STRLEN],save[STRLEN];
    extern int scr_cols;
    extern int RMSG;

    if (clearlabel == true) {
        buf[0] = 0;
    }
    if (scrint) move(line, col);
    if (prompt) prints("%s", prompt);
    if (scrint) getyx(&y, &x);
    clen = strlen(buf);
    if (clen>=len) clen = len - 1;
    curr = clen;
    buf[curr] = '\0';
    strncpy(save, buf, STRLEN);
    save[STRLEN-1]=0;

    if (!scrint) {
        prints("%s", buf);
        while ((ch = igetkey()) != '\r') {
            /*
             * TODO: add KEY_REFRESH support
             */
            if (ch == '\n')
                break;
            if (ch == '\177' || ch == Ctrl('H')) {
                if (clen == 0)
                    continue;
                clen--;
                ochar(Ctrl('H'));
                ochar(' ');
                ochar(Ctrl('H'));
                oflush();
                continue;
            }
            if (!isprint2(ch))
                continue;
            if (clen >= len - 1)
                continue;
            buf[clen++] = ch;
            if (echo) ochar(ch);
            else ochar('*');
        }
        buf[clen] = '\0';
        prints("\n");
        oflush();
        return clen;
    }
    ingetdata = true;
    clrtoeol();
    while (1) {
        int i;
        move(y, x);
        if (init) prints("\x1b[4m");
        for (i=0; i<clen; i++)
            if (!echo||buf[i]==KEY_ESC||!isprint2(buf[i])) outc('*');
            else outc(buf[i]);
        resetcolor();
        clrtoeol();
        move(y, x+curr);

        ch = igetkey();

        if (kicked) {
            ingetdata = false;
            return 0;
        }
        if (true == RMSG && (KEY_UP == ch || KEY_DOWN == ch)) {
            ingetdata = false;
            return -ch;         /* Leeward 98.07.30 supporting msgX */
        }
        if ((uinfo.mode == KILLER && (!buf[0]) && (ch==KEY_UP||ch==KEY_DOWN||ch==KEY_PGUP||ch==KEY_PGDN))||(ch>=Ctrl('S')&&ch<=Ctrl('W'))) {
            ingetdata = false;
            return -ch;
        }
#if 0 //#ifdef NINE_BUILD
        if (true == RMSG && ch == Ctrl('Z') && clen == 0) break;
#endif
        if (ch == '\n' || ch == '\r')
            break;
#ifdef CHINESE_CHARACTER
        if (ch == Ctrl('R')) {
            SET_CHANGEDEFINE(getCurrentUser(), DEF_CHCHAR);
            init=false;
            continue;
        }
#endif
        if (ch == '\177' || ch == Ctrl('H')) {
            if (init) {
                init=false;
                buf[0]=0;
                curr=0;
                clen=0;
            }
            if (curr == 0) {
                continue;
            }
            strcpy(tmp, &buf[curr]);
            buf[--curr] = '\0';
#ifdef CHINESE_CHARACTER
            if (DEFINE(getCurrentUser(), DEF_CHCHAR)) {
                int i,j=0;
                for (i=0; i<curr; i++)
                    if (j) j=0;
                    else if (buf[i]<0) j=1;
                if (j) {
                    buf[--curr] = '\0';
                    clen--;
                }
            }
#endif
            (void) strcat(buf, tmp);
            clen--;
            continue;
        }

        if (ch == KEY_ESC&&!enableESC) {
            strncpy(buf, save, Min(len,STRLEN));
            buf[Min(len,STRLEN-1)]=0;
            curr = strlen(buf);
            clen = curr;
            init=true;
            continue;
        }
        if (ch == Ctrl('C')) {
            buf[0]='\0';
            outc('\n');
            ingetdata = false;
            return -1;
        }

        if (ch == KEY_DEL) {
            if (init) {
                init=false;
                buf[0]=0;
                curr=0;
                clen=0;
            }
            if (curr >= clen) {
                curr = clen;
                continue;
            }
            strcpy(tmp, &buf[curr + 1]);
#ifdef CHINESE_CHARACTER
            if (DEFINE(getCurrentUser(), DEF_CHCHAR)) {
                int i,j=0;
                for (i=0; i<curr+1; i++)
                    if (j) j=0;
                    else if (buf[i]<0) j=1;
                if (j) {
                    strcpy(tmp, &buf[curr + 2]);
                    clen--;
                }
            }
#endif
            buf[curr] = '\0';
            (void) strcat(buf, tmp);
            clen--;
            continue;
        }
        if (ch == KEY_LEFT) {
            init=false;
            if (curr == 0) {
                continue;
            }
            curr--;
#ifdef CHINESE_CHARACTER
            if (DEFINE(getCurrentUser(), DEF_CHCHAR)) {
                int i,j=0;
                for (i=0; i<curr; i++)
                    if (j) j=0;
                    else if (buf[i]<0) j=1;
                if (j) curr--;
            }
#endif
            move(y, x + curr);
            continue;
        }
        if (ch == Ctrl('E') || ch == KEY_END) {
            init=false;
            curr = clen;
            move(y, x + curr);
            continue;
        }
        if (ch == Ctrl('A') || ch == KEY_HOME) {
            init=false;
            curr = 0;
            move(y, x + curr);
            continue;
        }
        if (ch == KEY_RIGHT) {
            init=false;
            if (curr >= clen) {
                curr = clen;
                continue;
            }
            curr++;
#ifdef CHINESE_CHARACTER
            if (DEFINE(getCurrentUser(), DEF_CHCHAR)) {
                int i,j=0;
                for (i=0; i<curr; i++)
                    if (j) j=0;
                    else if (buf[i]<0) j=1;
                if (j) curr++;
            }
#endif
            move(y, x + curr);
            continue;
        }
        if (!isprint2(ch)&&(ch!=KEY_ESC||!enableESC)) {
            init=false;
            continue;
        }
        if (x + clen >= scr_cols || clen >= len - 1) {
            if (!init) continue;
        }

        if (init) {
            init=false;
            buf[0]=0;
            curr=0;
            clen=0;
        }
        if (!buf[curr]) {
            buf[curr + 1] = '\0';
            buf[curr] = ch;
        } else {
            int i;
            for (i = len - 2; i >= curr; i--)
                buf[i + 1] = buf[i];
            buf[curr] = ch;
        }
        curr++;
        clen++;
    }
    buf[clen] = '\0';
    outc('\n');
    ingetdata = false;
    return clen;
}
コード例 #11
0
ファイル: io.c プロジェクト: chage/formosa
int _getdata(int line, int col, const char *prompt, char *buf, int len, int echo, char *prefix)
{
	unsigned char ch;
	int clen = 0;
	int x, y;
	int pre_len = (prefix) ? strlen(prefix) : 0;

	if (prompt)
	{
		move(line, col);
		clrtoeol();	/* lthuang */
		outs(prompt);
	}
	if (!dumb_term)
	{
		clrtoeol();
		getyx(&y, &x);
	}

	while (1)
	{
		if (pre_len)
		{
			ch = prefix[clen];
			pre_len--;
		}
		else
			ch = igetch();
#ifndef _BBS_UTIL_
#if 1
		if (dumb_term && !init_enter)
		{
			fflush(stdout);
			if (ch == 255)
			{	/* 255 == IAC */
				while (ch == 255)
				{
					if ((ch = igetch()) == 250)
					{	/* 250 == SB */
						while ((ch = igetch()) != 240);		/* 240 == SE */
						ch = igetch();
						continue;
					}
					else if (ch == 255)	/* if really send 255
								 * char */
						break;
					igetch();	/* DO, DONT, WILL, WONT
							 * on */
					ch = igetch();
				}
			}
		}
#endif
#endif
		if (ch == '\n' || ch == '\r')
			break;
		else if (ch == ' ')
		{
			if (echo & XNOSP)
				continue;	/* chang */
		}
#if 1
		else if (ch == 0x1b)	/* 0x1b is ESC */
		{		/* chang */
			ch = igetch();
			if (ch == '1' || ch == '4')	/* lthuang */
				igetch();
			else if (ch == '[' || ch == 'O')	/* lthuang */
			{
				ch = igetch();
				if (ch >= '1' && ch <= '6')
					igetch();
			}
			continue;
		}
#endif
		else if (ch == '\177' || ch == CTRL('H'))
		{
			if (clen == 0)
			{
				bell();
				continue;
			}
			clen--;
			x--;
			if (dumb_term)
			{
				ochar(CTRL('H'));
				outc(' ');
				ochar(CTRL('H'));
			}
			else
			{
				move(y, x);
				outc(' ');
				move(y, x);
				refresh();
			}
			continue;
		}
		else if (!isprint2(ch))
		{
			bell();
			continue;
		}

		if (!dumb_term && x >= (t_columns - 1))
		{
			bell();
			continue;
		}

		if (clen >= len - 1)
		{
			bell();
			continue;
		}
		buf[clen++] = (echo & XLCASE) ? tolower(ch) : ch;
		outc((echo & XECHO) ? ch : '*');
#ifdef _BBS_UTIL_
		refresh();
#endif
		x++;
	}
	buf[clen] = '\0';
	outc('\n');
	return clen;
}
コード例 #12
0
ファイル: visio.c プロジェクト: yrchen/Athena
int 
getdata(int line, int col, char *prompt, char *buf, int len, int echo, char *ans)
{
  register int ch;
  int clen;
  int x, y;
  int off_set = 0; /*add color*/
#define MAXLASTCMD 6
  static char lastcmd[MAXLASTCMD][80];

  if (prompt)
  {
    move(line, col);
    clrtoeol();
    outs(prompt);
    off_set=offset_count(prompt); /*add color*/
  }
  else
    clrtoeol();

  if (echo == NOECHO)
  {
    len--;              /* 下面這段程式碼是沒有反白 (!echo) */
    clen = 0;
    while ((ch = igetkey()) != '\r')
    {
      if (ch == '\n')
        break;
      if (ch == KEY_BKSP || ch == Ctrl('H'))
      {
        if (!clen)
          bell();
        else
          clen--;
          
        continue;
      }

#ifdef BIT8
      if (!isprint2(ch))
#else
      if (!isprint(ch))
#endif
      {
        continue;
      }

      if (clen >= len)
        continue;

      buf[clen++] = ch;
    }
    buf[clen] = '\0';
    outc('\n');
    oflush();
  }
  else
  {
   int cmdpos = MAXLASTCMD -1;
   int currchar = 0;
   int keydown;
   int dirty, i;

    getyx(&y, &x);
    x=x-off_set;  /*add color by hialan*/
    standout();
    for (clen = len; clen; clen--)
      outc(' ');
    standend();

    if (ans != NULL) 
    {
       str_ansi(buf, ans, len);
       move(y, x);
       edit_outs(buf);
       clen = currchar = strlen(buf);
    }
    
    /* 因為 buf 有可能會和 ans 相同 , 所以先把初始字串完成後 */
    /* 再根據 clen 將字串後面清空 */
    memset(buf+clen, 0, len-clen);

    len--;
    dirty = 0;
    while (move(y, x + currchar), (ch = igetkey()) != '\r')
    {
       keydown = 0;
       switch (ch) 
       {
       case Ctrl('Y'): 
       {
          if (clen && dirty) 
          {
             for (i = MAXLASTCMD - 1; i; i--)
                strcpy(lastcmd[i], lastcmd[i - 1]);
             strlcpy(lastcmd[0], buf, sizeof(lastcmd[0]) );
          }

          move(y, x);
          for (clen = len; clen; clen--)
            outc(' ');
          memset(buf, '\0', len);
          clen = currchar = 0;
          continue;
       }

       case KEY_DOWN:
       case Ctrl('N'):
          keydown = 1;
       case Ctrl('P'):
       case KEY_UP: 
       {
          if (clen && dirty) 
          {
             for (i = MAXLASTCMD - 1; i; i--)
                strcpy(lastcmd[i], lastcmd[i - 1]);
             strlcpy(lastcmd[0], buf, sizeof(lastcmd[0]) );
          }

          i = cmdpos;
          do 
          {
             if (keydown)
                --cmdpos;
             else
                ++cmdpos;
             if (cmdpos < 0)
                cmdpos = MAXLASTCMD - 1;
             else if (cmdpos == MAXLASTCMD)
                cmdpos = 0;
          } while (cmdpos != i && (!*lastcmd[cmdpos] || !strncmp(buf, lastcmd[cmdpos], len)));
          if (cmdpos == i)
             continue;

          strncpy(buf, lastcmd[cmdpos], len);
          buf[len] = 0;

          move(y, x);                   /* clrtoeof */
          for (i = 0; i <= clen; i++)
             outc(' ');
          move(y, x);

          if (echo == PASS)
            passwd_outs(buf);
          else
            edit_outs(buf);
          clen = currchar = strlen(buf);
          dirty = 0;
          continue;
       }
       case KEY_ESC:
         if(currutmp)
         {
           if (KEY_ESC_arg == 'c')
              capture_screen();
              
           if (KEY_ESC_arg == 'n')
              edit_note();
         }
         continue;

       /* yagami.000504 : 游標可到最前或最後 */ 
       case Ctrl('A'):
       case KEY_HOME:
         currchar = 0;
         break;
       case Ctrl('E'):
       case KEY_END:
         currchar = clen;
         break;

       case KEY_LEFT:
          if (currchar)
             --currchar;
          continue;
       case KEY_RIGHT:
          if (buf[currchar])
             ++currchar;
          continue;
       case Ctrl('K'):
       {
         buf[currchar] = 0;
         move(y, x + currchar);
         for (i = currchar; i < clen; i++)
            outc(' ');
         clen = currchar;
         dirty = 1;
         continue;
       }
 
       case Ctrl('D'): 
       {
         if (buf[currchar]) 
         {
            clen--;
            for (i = currchar; i <= clen; i++)
               buf[i] = buf[i + 1];
            move(y, x + clen);
            outc(' ');
            move(y, x);
            if (echo == PASS)
              passwd_outs(buf);
            else
              edit_outs(buf);
            dirty = 1;
         }
         continue;
       }       
       
       case KEY_BKSP:
       case Ctrl('H'):
       {
         if (currchar) 
         {
            currchar--;
            clen--;
            for (i = currchar; i <= clen; i++)
               buf[i] = buf[i + 1];
            move(y, x + clen);
            outc(' ');
            move(y, x);
            if (echo == PASS)
              passwd_outs(buf);
            else
              edit_outs(buf);
            dirty = 1;
         }
         continue;
       }       
       
       case Ctrl('I'):
         if(currstat != IDLE && !(currutmp->mode == 0 &&
            (currutmp->chatid[0] == 2 || currutmp->chatid[0] == 3))) 
         {
           t_idle();
         }
         continue;

       } /* switch(ch) */

      if (ch == '\n' || ch == '\r')
         break;

      if (!(isprint2(ch)) || clen >= len || x + clen >= scr_cols)
        continue;

      if (buf[currchar]) 
      {     		                /* insert */
         for (i = currchar; buf[i] && i < len && i < 80; i++)
            ;
         buf[i + 1] = 0;
         for (; i > currchar; i--)
            buf[i] = buf[i - 1];
      }
      else                              /* append */
         buf[currchar + 1] = '\0';

      buf[currchar] = ch;
      move(y, x + currchar);
      if (echo == PASS)
        passwd_outs(buf + currchar);
      else
      /* shakalaca.990422: 原本只有下面那行, 這是為了輸入 passwd 有反白 */
        edit_outs(buf + currchar);
      currchar++;
      clen++;
      dirty = 1;
    }
    buf[clen] = '\0';

    if (clen > 1 && echo != PASS) 
    /* shaklaaca.990514: ^^^^^^^ 不讓輸入的 password 留下紀錄 */
    {
       for (cmdpos = MAXLASTCMD - 1; cmdpos; cmdpos--)
          strcpy(lastcmd[cmdpos], lastcmd[cmdpos - 1]);
       strlcpy(lastcmd[0], buf, sizeof(lastcmd[0]) );
    }

    move(y, x + clen);
    outc('\n');
    refresh();
  }

  if(echo == LCECHO)
    buf[0] = tolower(buf[0]);

  return clen;
}
コード例 #13
0
ファイル: edit.c プロジェクト: PichuChen/formosa
int vedit(const char *filename, const char *saveheader, char *bname)
{
	int ch, foo;
	int lastcharindent = -1;
	BOOL firstkey = TRUE;
	char bakfile[PATHLEN];
	int old_rows = t_lines, old_columns = t_columns;

	sethomefile(bakfile, curuser.userid, UFNAME_EDIT);

	if ((saveheader || uinfo.mode == EDITPLAN || uinfo.mode == EDITBMWEL)
	    && isfile(bakfile)	/* lthuang */
#ifdef GUEST
	 && strcmp(curuser.userid, GUEST)
#endif
	 )
	{
		clear();
		outs(_msg_edit_8);
		if (getkey() != '2')
			mycp(bakfile, filename);
	}
	if (!isfile(filename))
		unlink(bakfile);
	if (saveheader)
		do_article_sig(filename);

	read_file(filename);

	top_of_win = firstline;
	currline = firstline;
	curr_window_line = 0;
	currpnt = 0;

	ansi_mode = FALSE;

	clear();
	display_buffer();

	move(curr_window_line, currpnt);
	while ((ch = getkey()) != EOF)
	{
		if (firstkey)
		{
			firstkey = FALSE;
			show_help_msg();
		}
		if (talkrequest)	/* lthuang */
		{
			backup_file(bakfile);
			talkreply();
			pressreturn();
			ch = CTRL('G');		/* redraw screen */
		}
		else if (msqrequest)	/* lthuang */
		{
			msqrequest = FALSE;
			msq_reply();
#if 0
			ch = CTRL('G');
#endif
		}
		if (old_rows != t_lines || old_columns != t_columns)
		{
			static const char *msg_resized = "螢幕大小已改變, 按(Ctrl-G)回到頁首!";

			old_rows = t_lines;
			old_columns = t_columns;

			top_of_win = firstline;
			currline = top_of_win;
			curr_window_line = 0;
			currpnt = 0;
			shift = 0;
			redraw_everything = TRUE;
			move(t_lines / 2, (t_columns - strlen(msg_resized)) / 2);
			outs(msg_resized);
			while (getkey() != CTRL('G'));
		}
		else if (ch < 0x100 && isprint2(ch))
		{
			insert_char(ch);
			lastcharindent = -1;
		}
		else
			switch (ch)
			{
			case KEY_UP:
				if (lastcharindent == -1)
					lastcharindent = currpnt;
				if (!currline->prev)
				{
					bell();
					break;
				}
				curr_window_line--;
				currline = currline->prev;
				currpnt = (currline->len > lastcharindent) ? lastcharindent : currline->len;
				break;
			case KEY_DOWN:
				if (lastcharindent == -1)
					lastcharindent = currpnt;
				if (!currline->next)
				{
					bell();
					break;
				}
				curr_window_line++;
				currline = currline->next;
				currpnt = (currline->len > lastcharindent) ? lastcharindent : currline->len;
				break;
			default:
				lastcharindent = -1;
				switch (ch)
				{
				case CTRL('T'):
					top_of_win = back_line(lastline, b_lines - 2);
					currline = lastline;
					curr_window_line = getlineno();
					currpnt = 0;
					redraw_everything = TRUE;
					break;
				case CTRL('S'):
					top_of_win = firstline;
					currline = top_of_win;
					curr_window_line = 0;
					currpnt = 0;
					redraw_everything = TRUE;
					break;
				case '\t':
					do
					{
						insert_char(' ');
					}
					while (currpnt & 0x7);
					break;
				case CTRL('U'):
				case CTRL('V'):
					insert_char(0x1b);
					break;
				case CTRL('C'):
					insert_char(0x1b);
					insert_char('[');
					insert_char('m');
					break;
				case KEY_RIGHT:
				case CTRL('F'):
					if (currline->len == currpnt)
					{
						if (!currline->next)
							bell();
						else
						{
							currpnt = 0;
							curr_window_line++;
							currline = currline->next;
						}
					}
					else
						currpnt++;
					break;
				case KEY_LEFT:
				case CTRL('B'):
					if (currpnt == 0)
					{
						if (!currline->prev)
							bell();
						else
						{
							currline = currline->prev;
							currpnt = currline->len;
							curr_window_line--;
						}
					}
					else
						currpnt--;
					break;
				case CTRL('G'):
					clear();
					redraw_everything = TRUE;
					break;
				case CTRL('Z'):
					vedit_help();
					break;
				case KEY_PGUP:
				case CTRL('P'):
					top_of_win = back_line(top_of_win, b_lines - 2);
					currline = top_of_win;
					currpnt = 0;
					curr_window_line = 0;
					redraw_everything = TRUE;
					break;
				case KEY_PGDN:
				case CTRL('N'):
					top_of_win = forward_line(top_of_win, b_lines - 2);
					currline = top_of_win;
					currpnt = 0;
					curr_window_line = 0;
					redraw_everything = TRUE;
					break;
				case KEY_HOME:
				case CTRL('A'):
					currpnt = 0;
					break;
				case KEY_END:
				case CTRL('E'):
					currpnt = currline->len;
					break;
				case CTRL('R'):
#if 0
					backup_file(bakfile);
#endif
					msq_reply();
#if 0
					redraw_everything = TRUE;	/* lthuang */
#endif
					break;
				case CTRL('Q'):
					ansi_mode = TRUE;
					display_buffer();
					pressreturn();
					ansi_mode = FALSE;
					display_buffer();
					break;
				case CTRL('X'):
				case CTRL('W'):
					backup_file(bakfile);
					clear();
					foo = write_file(filename, saveheader, bname);
					if (foo == BACKUP_EDITING)
						return foo;
					else if (foo != KEEP_EDITING)
					{
						unlink(bakfile);
						return foo;
					}
					redraw_everything = TRUE;	/* lthuang */
					break;
				case '\r':
				case '\n':
					split(currline, currpnt);
					/* lthuang: reduce the times of backup */
					if (total_num_of_line % 7 == 0)
						backup_file(bakfile);
					break;
				case '\177':
				case CTRL('H'):
					if (currpnt == 0)
					{
						if (!currline->prev)
						{
							bell();
							break;
						}
						curr_window_line--;
						currline = currline->prev;
						currpnt = currline->len;
						if (*killsp(currline->next->data) == '\0') {
							delete_line(currline->next);
							redraw_everything = TRUE;
						} else {
							join_currline();
						}
						if (curr_window_line == -1) {
							curr_window_line = 0;
							top_of_win = currline;
							rscroll();
						}
						break;
					}
					currpnt--;
					delete_char();
					break;
				case CTRL('D'):
					if (currline->len == currpnt)
						join_currline();
					else
						delete_char();
					break;
				case CTRL('Y'):
					currpnt = 0;
					currline->len = 0;
					delete_currline();
					break;
				case CTRL('K'):
					if (currline->len == 0)
						delete_currline();
					else if (currline->len == currpnt)
						join_currline();
					else
					{
						currline->len = currpnt;
						currline->data[currpnt] = '\0';
					}
					break;
				default:
					break;
				}
				break;
			}
		if (curr_window_line == -1)
		{
			curr_window_line = 0;
			if (!top_of_win->prev)
			{
				indigestion(6);
				bell();
			}
			else
			{
				top_of_win = top_of_win->prev;
				rscroll();
			}
		}
		if (curr_window_line == t_lines - 1)
		{
			curr_window_line = t_lines - 2;
			if (!top_of_win->next)
			{
				indigestion(7);
				bell();
			}
			else
			{
				top_of_win = top_of_win->next;
				scroll();
			}
		}

		/* lthuang: 99/07 */
		if (currpnt - shift >= t_columns - 1)
		{
			shift = (currpnt / (t_columns - 1)) * (t_columns - 1) - 1;
			redraw_everything = TRUE;
		}
		else if (currpnt - shift < 0)
		{
			shift = 0;
			redraw_everything = TRUE;
		}

		if (redraw_everything)
		{
			display_buffer();
			redraw_everything = FALSE;
		}
		else
		{
			move(curr_window_line, 0);
			clrtoeol();	/* lthuang */
			vedit_outs(currline->data);
		}

		move(curr_window_line, currpnt - shift);	/* lthuang: 99/07 */
	}
	if (uinfo.mode == POSTING || uinfo.mode == SMAIL)
		unlink(filename);
	return ABORT_EDITING;
}
コード例 #14
0
ファイル: boards.c プロジェクト: phoenixgao/fdubbs
static int search_board(const choose_board_t *cbrd, int *num)
{
	static int i = 0, find = YEA;
	static char bname[STRLEN];
	int n, ch, tmpn = NA;

	if (find == YEA) {
		bzero(bname, sizeof (bname));
		find = NA;
		i = 0;
	}

	while (1) {
		move(t_lines - 1, 0);
		clrtoeol();
		prints("请输入要查找的版面名称:%s", bname);
		ch = egetch();

		if (isprint2(ch)) {
			bname[i++] = ch;
			for (n = 0; n < cbrd->num; n++) {
				if (!strncasecmp(cbrd->brds[n].name, bname, i)) {
					tmpn = YEA;
					*num = n;
					if (!strcmp(cbrd->brds[n].name, bname))
						return 1 /* 找到类似的版,画面重画
						 */;
				}
			}
			if (tmpn)
				return 1;
			if (find == NA) {
				bname[--i] = '\0';
			}
			continue;
		} else if (ch == Ctrl('H') || ch == KEY_LEFT || ch == KEY_DEL
				|| ch == '\177') {
			i--;
			if (i < 0) {
				find = YEA;
				break;
			} else {
				bname[i] = '\0';
				continue;
			}
		} else if (ch == '\t') {
			find = YEA;
			break;
		} else if (ch == '\n' || ch == '\r' || ch == KEY_RIGHT) {
			find = YEA;
			break;
		}
		bell(1);
	}
	if (find) {
		move(t_lines - 1, 0);
		clrtoeol();
		return 2 /* 结束了 */;
	}
	return 1;
}
コード例 #15
0
ファイル: do_talk.c プロジェクト: yrchen/Athena
static void do_talk_char(struct talk_win *twin, int ch)
{
  extern int dumb_term;
  extern screenline* big_picture;
  screenline* line;
  int i;
  char ch0, buf[81];

  if (isprint2(ch))
  {
    ch0 = big_picture[twin->curln].data[twin->curcol];
    if (big_picture[twin->curln].len < 79)
       move(twin->curln, twin->curcol);
    else
       do_talk_nextline(twin);
    outc(ch);
    ++(twin->curcol);
    line =  big_picture + twin->curln;
    if (twin->curcol < line->len) {      /* insert */
       ++(line->len);
       memcpy(buf, line->data + twin->curcol, 80);
       save_cursor();
       do_move(twin->curcol, twin->curln);
       ochar(line->data[twin->curcol] = ch0);
       for (i = twin->curcol + 1; i < line->len; i++)
          ochar(line->data[i] = buf[i - twin->curcol - 1]);
       restore_cursor();
    }
    line->data[line->len] = 0;
    return;
  }

  switch (ch)
  {
  case Ctrl('H'):
  case '\177':
    if (twin->curcol == 0)
    {
      return;
    }
    line =  big_picture + twin->curln;
    --(twin->curcol);
    if (twin->curcol < line->len) {
       --(line->len);
       save_cursor();
       do_move(twin->curcol, twin->curln);
       for (i = twin->curcol; i < line->len; i++)
          ochar(line->data[i] = line->data[i + 1]);
       line->data[i] = 0;
       ochar(' ');
       restore_cursor();
    }
    move(twin->curln, twin->curcol);
    return;

  case Ctrl('D'):
     line =  big_picture + twin->curln;
     if (twin->curcol < line->len) {
        --(line->len);
        save_cursor();
        do_move(twin->curcol, twin->curln);
        for (i = twin->curcol; i < line->len; i++)
           ochar(line->data[i] = line->data[i + 1]);
        line->data[i] = 0;
        ochar(' ');
        restore_cursor();
     }
     return;
  case Ctrl('G'):
    bell();
    return;
  case Ctrl('B'):
     if (twin->curcol > 0) {
        --(twin->curcol);
        move(twin->curln, twin->curcol);
     }
     return;
  case Ctrl('F'):
     if (twin->curcol < 79) {
        ++(twin->curcol);
        move(twin->curln, twin->curcol);
     }
     return;
  case Ctrl('A'):
     twin->curcol = 0;
     move(twin->curln, twin->curcol);
     return;
  case Ctrl('K'):
     clrtoeol();
     return;
  case Ctrl('Y'):
     twin->curcol = 0;
     move(twin->curln, twin->curcol);
     clrtoeol();
     return;
  case Ctrl('E'):
     twin->curcol = big_picture[twin->curln].len;
     move(twin->curln, twin->curcol);
     return;
  case Ctrl('M'):
  case Ctrl('J'):
     line =  big_picture + twin->curln;
     strncpy(buf, line->data, line->len);
     buf[line->len] = 0;
     if (dumb_term)
       outc('\n');
     do_talk_nextline(twin);
     break;
  case Ctrl('P'):
     line =  big_picture + twin->curln;
     strncpy(buf, line->data, line->len);
     buf[line->len] = 0;
     if (twin->curln > twin->sline) {
        --(twin->curln);
        move(twin->curln, twin->curcol);
     }
     break;
  case Ctrl('N'):
     line =  big_picture + twin->curln;
     strncpy(buf, line->data, line->len);
     buf[line->len] = 0;
     if (twin->curln < twin->eline) {
        ++(twin->curln);
        move(twin->curln, twin->curcol);
     }
     break;
  }
  str_trim(buf);
  if (*buf)
     fprintf(flog, "%s%s: %s%s\n",
        (twin->eline == b_lines - 1) ? "" : "",
        (twin->eline == b_lines - 1) ?
        getuserid(currutmp->destuid) : cuser.userid, buf,
        (ch == Ctrl('P')) ? "(Up)" : "");
}