⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 window.c

📁 使用BorlandC++4.5编译的一个MUD客户端程序
💻 C
📖 第 1 页 / 共 3 页
字号:
}

/* input_fdel - delete character under cursor
 *
 * This also updates text to the end of the line.
 *
 * Parameters:
 *   num - number of chars to delete.  must be >= 0, < kpos
 */
void input_fdel(num)
	int num;
{
	int n;
        assert(num >= 0 /* count may not be negative */);
        assert(num <= (Klen - kpos) /* Delete past end of string */);

	if (!echo_mode)
		return;
	n = min(Klen - kpos - num, Margin - icol);
	IBwriteal(&Kptr[kpos + num], n);
	Iclear_end;
	Imove_left(n, icol);
	IBflush;
}

/* input_clear - clears the input edit line */
void input_clear()
{
	if (!echo_mode)
		return;
	if (kpos <= Isize * Margin) /* fills entire window? */
        {
		input_cmove(0);
		IBwritea(s_clreol);
                icol = Oplen % Margin;
	}
        else
        {
		Iclear_space(Itop, 1);
		draw_prompt();      /* sets icol */
	}
	IBflush;
}

/* input_draw - draws the input edit line (no prompt)
 *
 * Sets icol.
 *
 * Note:
 *  This is not easy to get right, so be careful
 *  to step through every inch of code after modification.
 */
void input_draw()
{
    int pos = 0;                /* offset in kbuf */
    int n, col;

    if (!echo_mode)
        return;
    
    col = Oplen % Margin;       /* initial location */
    if (Klen > 0)
    {
        while (1)                   /* Loop to write input line */
        {
            n = min(Klen - pos, Margin - col);
            assert(n >= 0);         /* Logic error */
            IBwriteal(&Kptr[pos], n);
            pos += n;               /* printed n chars */
            assert(pos <= Klen);    /* off end of array? */
            
            if (pos > kpos || pos >= Klen)         /* Cursor on line? */
                break;
            else                    /* not done, scroll forward */
                Iscr_fwd;
            
            col = 0;                /* beginning of row now */
        };
        if (n == (Margin - col)) /* write ended at last line on screen? */
            Iscr_fwd;
    };
    icol = (Oplen + kpos) % Margin;
    assert(icol >= 0 && icol < cols); /* off screen? */
        
    Iclear_end;
    Icmove(icol, 1);
    IBflush;
}

void input_newline()
{
	input_cmove(Klen);
	Iscr_fwd;
	icol = 0;
	if (plen && !vtc_mode) {
		Discardstring(prompt);
		prompt = vtstrdup("");
		plen = 0;
	}
	IBflush;
}

/* change_prompt - set a new prompt with length l
 *
 * Nonprintable characters are ignored.
 */
void change_prompt(new, l)
	char *new;
	int l;
{
	char *p, *q;
	Discardstring(prompt);
	for (p = new; *p; p++) {       /* Get new prompt length */
		if (!isprint(*p))
			l--;
	}
	q = prompt = Newarray(char, l + 1); /* copy prompt string */
	for (p = new; *p; p++) {
		if (isprint(*p))
			*q++ = *p;
	}
	*q = 0;

        /* clear and redraw input window */
        
	if (!vtc_mode) {                
		curs_input();
		clear_input_window();
	}
	plen = l;                       
	if (!vtc_mode) {                 
		draw_prompt();
		input_draw();
	}
}

void update_echo_mode()
{
	int new_mode;
	
	if(0 != ign_echo_mode)
		return;

	new_mode = (active_win->Wrmt) ? active_win->Wrmt->Recho : 1;

	if (echo_mode != new_mode) {
		echo_mode = 1;
		curs_input();
		if (new_mode)
			input_draw();
		else
			input_clear();
		echo_mode = new_mode;
	}
}

/* Output routines */

void output(win, text)
	Unode *win;
	char *text;
{
	int norm, n;

	if (!win) {
		win = active_win;
		if (win->Wnl)
			output(win, "[background] ");
	}
	curs_window(win);
	if (win->Wnl) {
		BputEOLN();
		win->Wnl = 0;
	}
	while (1) {
		norm = strcspn(text, "\n\b\f\v\t\r");
		n = cols - win->Wcol;
		for (; norm >= n; text += n, norm -= n, n = cols) {
			BputEOLN();
			cmove(win->Wcol, win->Wbot - 1);
			Bwriteal(text, n);
			cmove(0, win->Wbot);
			win->Wcol = 0;
		}
		Bwriteal(text, norm);
		win->Wcol = (win->Wcol + norm) % cols;
		text += norm;
		switch(*text++) {
		    case '\0':
			Bflush;
			return;
		    case '\n':
		    case '\v':
			if (*text)
				BputEOLN();
			else
				win->Wnl = 1;
			win->Wcol = 0;
		    Case '\b':
			if (win->Wcol) {
				Bputch('\b');
				win->Wcol--;
			}
		    Case '\f':
			clear_space(win->Wtop, win->Wbot);
			win->Wcol = 0;
			curs_window(win);
		    Case '\t':
			if (win->Wcol == cols - 1) {
				BputEOLN();
				win->Wcol = 0;
			} else {
				do {
					Bputch(' ');
					win->Wcol++;
				} while (win->Wcol % 8 && 
					 win->Wcol < cols - 1);
			}
		    Case '\r':
			Bputch('\r');
			win->Wcol = 0;
		}
	}
}

#ifdef USE_STDARG
void outputf(char *fmt, ...)
#else
void outputf(va_alist)
	va_dcl
#endif
{
	va_list ap;
	char *ptr, *sval, *intstr;
	String *buf = &wbufs[1];
	int width = 0;
#ifdef USE_STDARG
	va_start(ap, fmt);
#else
	char *fmt;
	va_start(ap);
	fmt = va_arg(ap, char *);
#endif

	s_term(buf, 0);
	ptr = strchr(fmt, '%');
	while (ptr) {
		s_cat(buf, cstr_sl(fmt, ptr - fmt));
		if (isdigit(*++ptr)) {
			width = atoi(ptr);
			while (isdigit(*++ptr));
		}
		if (*ptr == 'd') {
			intstr = ITOA(va_arg(ap, int));
			for (width -= strlen(intstr); width > 0; width--)
				s_fadd(buf, ' ');
			s_acat(buf, intstr);
		} else if (*ptr == 's') {
			sval = va_arg(ap, char *);
			for (width -= strlen(sval); width > 0; width--)
				s_fadd(buf, ' ');
			s_acat(buf, sval);
		} else
			s_fadd(buf, *ptr);
		fmt = ptr + 1;
		ptr = strchr(fmt, '%');
	}
	s_acat(buf, fmt);
	output(Cur_win, buf->c.s);
	va_end(ap);
}

void operror(s, rmt)
	char *s;
	Unode *rmt;
{
	char errbuf[128];
	Unode *win = rmt ? rmt->Rwin : Cur_win;

	strcpy(errbuf, s);
	strcat(errbuf, ": ");
	strcat(errbuf, sys_errlist[errno]);
	strcat(errbuf, "\n");
	output(win, errbuf);
}

@2.2log@Changed comments around #ifdef.@text@d2 1a2 1/* $Id: window.c 2.1 1995/10/24 15:46:14 tsurace Exp tsurace $ */d5 1d44 1a44 1static void clear_end(int);d144 1a144 1# define Iclear_end(n)  clear_end(n)d420 6a425 1	cap_formatted(s_cmove, col, row);d459 6a464 2static void clear_end(len)	int len;d466 1a466 4	if (len > 1)		Bwritea(s_clreol);	else if (len == 1)		Bwritea(" \010");d752 1d755 16a770 9	int pos = 0;	while (pos < Oplen) {		IBwritem(&prompt[pos], plen - pos, Margin);		if ((pos += Margin) <= plen)			Iscr_fwd;	}	icol = Oplen % Margin;	IBflush;d773 1d776 22a797 13	if (kpos + Oplen <= Isize * Margin) {		input_cmove(0);		while (plen > Margin) {			Iscr_rev;			plen -= Margin;		}                Icmove(0, 1);		IBwritea(s_clreol);		IBflush;	} else		Iclear_space(Itop, 1);}d806 2a807 1	while (cstr.l) {d810 2a811 1		if (!(icol = (icol + n) % Margin))d815 1d822 4a825 1/* Move to the new column, updating the screen wrap if necessary */d829 82a910 38	int offset = new - kpos, pos, n;	if (new == kpos || !echo_mode)		return;	if (new == kpos - 1 && icol) {                Imove_left(1, new);		icol--;	} else if (new == kpos + 1 && icol < Margin - 1) {		IBputch(Kptr[kpos]);		icol++;	} else if (new > kpos) {		pos = Round(kpos + Oplen, Margin) + Margin - Oplen;		while (icol + offset >= Margin) {			Iscr_fwd;			IBwritem(&Kptr[pos], Klen - pos, Margin);			pos += Margin;			offset -= Margin;		}		Icmove(icol += offset, 1);	} else {		pos = Round(kpos + Oplen, Margin) - Oplen - Isize * Margin;		while (icol + offset < 0) {			Iscr_rev;			if (pos >= 0)				IBwritem(&Kptr[pos], Klen - pos, Margin);			else if (pos + Oplen >= 0) {				n = min(-pos, Margin);				IBwriteal(&prompt[plen + pos], n);				IBwritem(Kptr, Klen, Margin - n);			}			pos -= Margin;			offset += Margin;		}		Icmove(icol += offset, 1);	}	IBflush;}d915 2a916 1d922 1a922 1	Iclear_end(min(num, Margin - icol - n));d927 7d938 2d945 1a945 1	Iclear_end(min(num, Margin - icol - n));d950 1d955 2a956 1	if (kpos <= Isize * Margin) {d959 4a962 1	} else {d964 1a964 1		draw_prompt();a965 1	icol = Oplen % Margin;d969 8d979 2a980 1	int pos = 0, n = 0, col;d982 30a1011 13	if (!echo_mode)		return;	col = Oplen % Margin;	while (pos <= kpos) {		n = min(Klen - pos, Margin - col);		IBwriteal(&Kptr[pos], n);		if ((pos += Margin) <= kpos)			Iscr_fwd;		col = 0;	}	icol = Oplen + kpos % Margin;	Imove_left(n - icol, icol);	IBflush;d1027 4a1035 5	if (!vtc_mode) {		curs_input();		clear_input_window();	}d1037 1a1037 1	for (p = new; *p; p++) {d1041 1a1041 1	q = prompt = Newarray(char, l + 1);d1047 9a1055 2	plen = l;	if (!vtc_mode) {@2.1log@Roll.@text@d2 1a2 1/* $Id: window.c 1.1 1995/10/12 21:37:13 tsurace Beta tsurace $ */d200 3a202 1#ifndef __WIN32__ /* won't work */@1.1log@Initial revision@text@d2 1a2 1/* $Id$ */@

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -