コード例 #1
0
ファイル: namecomplete.c プロジェクト: erichuang1994/fbbs
int usercomplete(char *prompt, char *data) {
	char *cwbuf, *cwlist, *temp;
	int cwnum, x, y, origx, origy;
	int clearbot = NA, count = 0, morenum = 0;
	char ch;

	cwbuf = malloc(MAXUSERS * (IDLEN + 1));
	if (prompt != NULL) {
		prints("%s", prompt);
		clrtoeol();
	}
	temp = data;
	cwlist = u_namearray((void *)cwbuf, &cwnum, "");
	screen_coordinates(&y, &x);
	screen_coordinates(&origy, &origx);
	while ((ch = terminal_getchar()) != EOF) {
		if (ch == '\n' || ch == '\r') {
			int i;
			char *ptr;

			*temp = '\0';
			prints("\n");
			ptr = cwlist;
			for (i = 0; i < cwnum; i++) {
				if (strncasecmp(data, ptr, IDLEN + 1) == 0)
					strcpy(data, ptr);
				ptr += IDLEN + 1;
			}
			/* if( cwnum == 1 ) strcpy( data, cwlist ); */
			break;
		} // if
		if (ch == ' ' || ch == KEY_TAB) {
			int col, len, i, j;
			int n;

			if (cwnum == 1) {
				strcpy(data, cwlist);
				screen_move(y, x);
				prints("%s", data + count);
				count = strlen(data);
				temp = data + count;
				screen_coordinates(&y, &x);
				continue;
			}
			for (i = strlen(data); i && i < IDLEN; i++) {
				ch = cwlist[i];
				if (ch == '\0')
					break;
				for (j = 0; j < cwnum; j++) {
					if (toupper((cwlist + (IDLEN + 1) * j)[i]) != toupper(ch))
						break;
				}
				if (j != cwnum)
					break;
				*temp++ = ch;
				*temp = '\0';
				n = UserSubArray((void *)cwbuf, (void *)cwlist, cwnum, ch,
						count);
				if (n == 0) {
					temp--;
					*temp = '\0';
					break;
				}
				cwlist = cwbuf;
				count++;
				cwnum = n;
				morenum = 0;
				screen_move(y, x);
				outc(ch);
				x++;
			}
			clearbot = YEA;
			col = 0;
			len = UserMaxLen((void *)cwlist, cwnum, morenum, NUMLINES);
			screen_move(origy + 1, 0);
			screen_clrtobot();
			//% printdash(" 所有使用者列表 ");
			printdash(" \xcb\xf9\xd3\xd0\xca\xb9\xd3\xc3\xd5\xdf\xc1\xd0\xb1\xed ");
			while (len + col < 79) {
				int i;
				for (i = 0; morenum < cwnum && i < NUMLINES - origy + 1; i++) {
					char *tmpptr = cwlist + (IDLEN + 1) * morenum++;
					if (*tmpptr != '\0') { //by Eric
						screen_move(origy + 2 + i, col);
						prints("%s ", tmpptr);
					} else
						i--;
				}
				col += len + 2;
				if (morenum >= cwnum)
					break;
				len = UserMaxLen((void *)cwlist, cwnum, morenum, NUMLINES);
			}
			if (morenum < cwnum) {
				screen_move(-1, 0);
				//% prints("-- 还有使用者 --                                                               ");
				prints("-- \xbb\xb9\xd3\xd0\xca\xb9\xd3\xc3\xd5\xdf --                                                               ");
			} else {
				morenum = 0;
			}
			screen_move(y, x);
			continue;
		}
		if (ch == '\177' || ch == '\010') {
			if (temp == data)
				continue;
			temp--;
			count--;
			*temp = '\0';
			cwlist = u_namearray((void *)cwbuf, &cwnum, data);
			morenum = 0;
			x--;
			screen_move(y, x);
			outc(' ');
			screen_move(y, x);
			continue;
		}
		if (count < STRLEN) {
			int n;
			*temp++ = ch;
			*temp = '\0';
			n = UserSubArray((void *)cwbuf, (void *)cwlist, cwnum, ch,
					count);
			if (n == 0) {
				temp--;
				*temp = '\0';
				continue;
			}
			cwlist = cwbuf;
			count++;
			cwnum = n;
			morenum = 0;
			screen_move(y, x);
			outc(ch);
			x++;
		}
	}
	free(cwbuf);
	if (ch == EOF)
		longjmp(byebye, -1);
	prints("\n");
	screen_flush();
	if (clearbot) {
		screen_move(origy, 0);
		screen_clrtobot();
	}
	if (*data) {
		screen_move(origy, origx);
		prints("%s\n", data);
	}
	return 0;
}
コード例 #2
0
ファイル: name.c プロジェクト: YanlongLai/Program
void usercomplete(char *prompt, char *data) {
    char *temp;
    char *cwbuf, *cwlist;
    int cwnum, x, y, origx, origy;
    int clearbot = NA, count = 0, morenum = 0;
    char ch;

    cwbuf = malloc(MAX_USERS * (IDLEN + 1));
    cwlist = u_namearray((arrptr)cwbuf, &cwnum, "");
    temp = data;
    
    outs(prompt);
    clrtoeol();
    getyx(&y, &x);
    getyx(&origy, &origx);
    standout();
    prints("%*s", IDLEN + 1, "");
    standend();
    move(y, x);
    while((ch = igetch()) != EOF) {
	if(ch == '\n' || ch == '\r') {
	    int i;
	    char *ptr;
	    
	    *temp = '\0';
	    outc('\n');
	    ptr = (char *)cwlist;
	    for(i = 0; i < cwnum; i++) {
		if(strncasecmp(data, ptr, IDLEN + 1) == 0)
		    strcpy(data, ptr);
		ptr += IDLEN + 1;
	    }
	    break;
	} else if(ch == ' ') {
	    int col, len;
	    
	    if(cwnum == 1) {
		strcpy(data, (char *)cwlist);
		move(y, x);
		outs(data + count);
		count = strlen(data);
		temp = data + count;
		getyx(&y, &x);
		continue;
	    }
	    clearbot = YEA;
	    col = 0;
	    len = UserMaxLen((arrptr)cwlist, cwnum, morenum, p_lines);
	    move(2, 0);
	    clrtobot();
	    printdash("使用者代號一覽表");
	    while(len + col < 79) {
		int i;
		
		for(i = 0; morenum < cwnum && i < p_lines; i++)	{
		    move(3 + i, col);
		    prints("%s ", cwlist + (IDLEN + 1) * morenum++);
		}
		col += len + 2;
		if(morenum >= cwnum)
		    break;
		len = UserMaxLen((arrptr)cwlist, cwnum, morenum, p_lines);
	    }
	    if(morenum < cwnum) {
		move(b_lines, 0);
		outs(msg_more);
	    } else
		morenum = 0;
	    move(y, x);
	    continue;
	} else if(ch == '\177' || ch == '\010') {
	    if(temp == data)
		continue;
	    temp--;
	    count--;
	    *temp = '\0';
	    cwlist = u_namearray((arrptr)cwbuf, &cwnum, data);
	    morenum = 0;
	    x--;
	    move(y, x);
	    outc(' ');
	    move(y, x);
	    continue;
	} else if(count < STRLEN && isprint(ch)) {
	    int n;
	    
	    *temp++ = ch;
	    *temp = '\0';
	    n = UserSubArray((arrptr)cwbuf, (arrptr)cwlist, cwnum, ch, count);
	    if(n == 0) {
		temp--;
		*temp = '\0';
		continue;
	    }
	    cwlist = cwbuf;
	    count++;
	    cwnum = n;
	    morenum = 0;
	    move(y, x);
	    outc(ch);
	    x++;
	}
    }
    free(cwbuf);
    if(ch == EOF)
	/* longjmp(byebye, -1); */
	raise(SIGHUP);	/* jochang: don't know if this is necessary */
    outc('\n');
    refresh();
    if(clearbot) {
	move(2, 0);
	clrtobot();
    }
    if(*data) {
	move(origy, origx);
	outs(data);
	outc('\n');
    }
}