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

📄 disp.c

📁 早期freebsd实现
💻 C
📖 第 1 页 / 共 2 页
字号:
	register int	i;	int	num = 0,		nonspace = 0;	char	c;	for (i = 0; i < len; i++) {		if ((c = *s++) != *t++)			break;		if (c != ' ')			nonspace++;		if (nonspace)			num += 1;	}	return num;}private boolOkayDelete(Saved, num, samelength)int	Saved,	num,	samelength;{	/* If the old and the new are the same length, then we don't	 * have to clear to end of line.  We take that into consideration.	 */	return ((Saved + (!samelength ? CElen : 0))		> min(MDClen, DClen * num));}private boolOkayInsert(Saved, num)int	Saved,	num;{	register int	n = 0;	if (IC)		/* Per character prefixes */		n = min(num * IClen, MIClen);	if (IM && !IN_INSmode) {		/* Good terminal.  Fewer characters in this case */		n += IMlen;	}	n += num;	/* The characters themselves */	return Saved > n;}private voidDelChar(lineno, col, num)int	lineno,	col,	num;{	register char	*from,			*to;	register int	i;	struct screenline *sp = (&Screen[lineno]);	Placur(lineno, col);	if (M_DC && num > 1) {		putargpad(M_DC, num, num);	} else {		for (i = num; --i >= 0; )			putpad(DC, 1);	}	to = sp->s_line + col;	from = to + num;	byte_copy(from, to, (size_t) (sp->s_length - from + 1));	clrline(sp->s_length - num, sp->s_length);	sp->s_length -= num;}private voidInsChar(lineno, col, num, new)int	lineno,	col,	num;char	*new;{	register char	*sp1,			*sp2,	/* To push over the array. */			*sp3;	/* Last character to push over. */	int	i;	i_set(lineno, 0);	sp2 = Curline->s_length + num;	if (sp2 >= cursend) {		i_set(lineno, CO - num - 1);		cl_eol();		sp2 = cursend - 1;	}	Curline->s_length = sp2;	sp1 = sp2 - num;	sp3 = Curline->s_line + col;	while (sp1 >= sp3)		*sp2-- = *sp1--;	new += col;	byte_copy(new, sp3, (size_t) num);	/* The internal screen is correct, and now we have to do	   the physical stuff. */	Placur(lineno, col);	if (IM) {		if (!IN_INSmode)			INSmode(ON);	} else if (M_IC && num > 1) {		putargpad(M_IC, num, num);	} else if (IC) {		for (i = 0; i < num; i++)			putpad(IC, 1);	}	for (i = 0; i < num; i++) {		jputchar(new[i]);		if (IN_INSmode)			putpad(IP, 1);	}	CapCol += num;}#endif	/* ID_CHAR */#ifdef	UNIX		/* obviously ... no mail today if not Unix*//* chkmail() returns nonzero if there is new mail since the   last time we checked. */char	Mailbox[FILESIZE];	/* initialized in main */int	MailInt = 60;		/* check no more often than 60 seconds */#ifdef	BIFFbool	BiffChk = NO;		/* whether to turn off biff while in JOVE */#endifintchkmail(force)int	force;{	time_t	now;	static int	state = NO;	/* assume unknown */	static time_t	last_chk = 0,			mbox_time = 0;	struct stat	stbuf;	if (MailInt == 0)		return NO;	time(&now);	if ((force == NO) && (now < last_chk + MailInt))		return state;	last_chk = now;	if (stat(Mailbox, &stbuf) < 0) {		state = NO;		/* no mail */		return NO;	}	if (((stbuf.st_atime > stbuf.st_mtime) &&	     (stbuf.st_atime > mbox_time)) ||	    (stbuf.st_size == 0)) {		mbox_time = stbuf.st_atime;		state = NO;	} else if (stbuf.st_mtime > mbox_time) {		if (mbox_time > 0)			dobell(2);		/* announce the change */		mbox_time = stbuf.st_mtime;		state = YES;	}	return state;}#endif	/* UNIX *//* Print the mode line. */private char	*mode_p,		*mend_p;bool	BriteMode = ON;		/* modeline should standout */private voidmode_app(str)register const char	*str;{	do ; while ((mode_p < mend_p) && (*mode_p++ = *str++)!='\0');	mode_p -= 1;	/* back over the null */}char	ModeFmt[120] = "%3c %w %[%sJOVE (%M)   Buffer: %b  \"%f\" %]%s%m*- %((%t)%s%)%e";private voidModeLine(w)register Window	*w;{	int	n,		glue = 0;	bool	ign_some = NO;	char	line[MAXCOLS],		*fmt = ModeFmt,		fillc,		c;	register Buffer	*thisbuf = w->w_bufp;	register Buffer *bp;	mode_p = line;	mend_p = &line[(sizeof line) - 1];#ifdef	IBMPC	/* very subtle - don't mess up attributes too much */	fillc = '-';#else	/* !IBMPC */#  ifdef	MAC	fillc = '_';	/* looks better on a Mac */#  else	/* !MAC */	if (SO == NULL)		BriteMode = OFF;	fillc = BriteMode ? ' ' : '-';#  endif	/* !MAC */#endif	/* !IBMPC */	while ((c = *fmt++)!='\0' && mode_p<mend_p) {		if (c != '%') {			if (c == '\\')				if ((c = *fmt++) == '\0')					break;			if (!ign_some)				*mode_p++ = c;			continue;		}		if ((c = *fmt++) == '\0')	/* char after the '%' */			break;		if (ign_some && c != ')')			continue;		n = 1;		if (c >= '0' && c <= '9') {			n = 0;			while (c >= '0' && c <= '9') {				n = n * 10 + (c - '0');				c = *fmt++;			}			if (c == '\0')				break;		}		switch (c) {		case '(':			if (w->w_next != fwind)	/* Not bottom window. */				ign_some = YES;			break;		case ')':			ign_some = NO;			break;		case '[':		case ']':			for (n=RecDepth; n>0 && mode_p<mend_p; n--)				*mode_p++ = c;			break;#ifdef	UNIX		case 'C':	/* check mail here */			if (chkmail(NO) == YES)				mode_app("[New mail]");			break;#endif	/* UNIX */		case 'M':		    {			static const char	*const mmodes[] = {				"Fundamental ",				"Text ",				"C ",#ifdef	LISP				"Lisp ",#endif				NULL			};			mode_app(mmodes[thisbuf->b_major]);			if (BufMinorMode(thisbuf, Fill))				mode_app("Fill ");			if (BufMinorMode(thisbuf, Abbrev))				mode_app("Abbrev ");			if (BufMinorMode(thisbuf, OverWrite))				mode_app("OvrWt ");			if (BufMinorMode(thisbuf, Indent))				mode_app("Indent ");			if (BufMinorMode(thisbuf, ReadOnly))				mode_app("RO ");			if (InMacDefine)				mode_app("Def ");			mode_p -= 1;	/* Back over the extra space. */			break;		    }		case 'c':			while (--n>=0 && mode_p<mend_p)				*mode_p++ = fillc;			break;		case 'd':	/* print working directory */			mode_app(pr_name(pwd(), YES));			break;		case 'e':	/* stretchable glue */			*mode_p++ = '\0';	/* glue marker */			glue++;			break;		case 'b':			mode_app(thisbuf->b_name);			break;		case 'f':		case 'F':			if (thisbuf->b_fname == NULL)				mode_app("[No file]");			else {				if (c == 'f')					mode_app(pr_name(thisbuf->b_fname, YES));				else					mode_app(basename(thisbuf->b_fname));			}			break;#ifdef	LOAD_AV		case 'l':		    {			int	la = get_la();			char	minibuf[10];			swritef(minibuf, sizeof(minibuf), "%d.%02d",			       la/100, la%100);			mode_app(minibuf);			break;		    }#endif		case 'm':		    {			char	yea = (*fmt == '\0') ? '*' : *fmt++;			char	nay = (*fmt == '\0') ? ' ' : *fmt++;			*mode_p++ = IsModified(w->w_bufp) ? yea : nay;			break;		    }		case 'n':		    {			char	tmp[16];			for (bp = world, n = 1; bp != NULL; bp = bp->b_next, n++)				if (bp == thisbuf)					break;			swritef(tmp, sizeof(tmp), "%d", n);			mode_app(tmp);			break;		    }#ifdef	IPROCS		case 'p':			if (thisbuf->b_type == B_PROCESS) {				char	tmp[40];				Process	*p = thisbuf->b_process;				swritef(tmp, sizeof(tmp), "(%s%s)",					((p == NULL || p->p_dbx_mode == NO)					 ? "" : "DBX "),					((p == NULL) ? "No process" :					 pstate(p)));				mode_app(tmp);			}			break;#endif		case 's':			if (mode_p[-1] != ' ')				*mode_p++ = ' ';			break;		case 't':		    {			char	timestr[12];			mode_app(get_time((time_t *)NULL, timestr, 11, 16));			break;		    }		case 'w':			if (w->w_LRscroll > 0)				mode_app(">");			break;		default:			mode_app("?");			break;		}	}	/* Glue (Knuth's term) is a field that expands to fill	 * any leftover space.  Multiple glue fields compete	 * on an equal basis.  This is a generalization of a	 * mechanism to allow centring and right-justification.	 * The original meaning of %e (fill the rest of the	 * line) has also been generalized.  %e can now	 * meaningfully be used 0 or more times.	 */	if  (glue) {		/* 2 space pad plus padding for magic cookies */		register char	*to = &line[CO - 2 - (2 * SG)],				*from = mode_p;		if (to < from)			to = from;		mode_p = to;		while (from != line) {			if ((*--to = *--from) == '\0') {				register int	portion = (to-from) / glue;				glue--;				*to = fillc;				while (--portion >= 0)					*--to = fillc;			}		}	}	*mode_p = '\0';	/* Highlight mode line. */	if (BriteMode) {#ifdef	ID_CHAR		if (IN_INSmode)			INSmode(OFF);#endif		SO_on();	}	if (swrite(line, BriteMode, YES))		do_cl_eol(i_line);	else		UpdModLine = YES;	if (BriteMode)		SO_off();}private voidv_clear(line1, line2)register int	line1;int	line2;{	register struct scrimage	*phys_p, *des_p;	phys_p = &PhysScreen[line1];	des_p = &DesiredScreen[line1];	while (line1 <= line2) {		i_set(line1, 0);		cl_eol();		phys_p->s_id = des_p->s_id = 0;		phys_p += 1;		des_p += 1;		line1 += 1;	}}/* This tries to place the current line of the current window in the   center of the window, OR to place it at the arg'th line of the window.   This also causes the horizontal position of the line to be centered,   if the line needs scrolling, or moved all the way back to the left,   if that's possible. */voidRedrawDisplay(){	int	line;	Line	*newtop = prev_line((curwind->w_line = curline), is_an_arg() ?				arg_value() : HALF(curwind));	if ((line = in_window(curwind, curwind->w_line)) != -1)		PhysScreen[line].s_offset = -1;	if (newtop == curwind->w_top)		v_clear(FLine(curwind), FLine(curwind) + SIZE(curwind));	else		SetTop(curwind, newtop);}voidClAndRedraw(){	cl_scr(YES);}voidNextPage(){	Line	*newline;	if (Asking)		return;	if (arg_value() < 0) {		negate_arg_value();		PrevPage();		return;	}	if (arg_type() == YES)		UpScroll();	else {		if (in_window(curwind, curwind->w_bufp->b_last) != -1) {			rbell();			return;		}		newline = next_line(curwind->w_top, max(1, SIZE(curwind) - 1));		SetTop(curwind, curwind->w_line = newline);		if (curwind->w_bufp == curbuf)			SetLine(newline);	}}#ifdef	MSDOSvoidPageScrollUp(){	int i, n;    n = max(1, SIZE(curwind) - 1);	for (i=0; i<n; i++) {	    UpScroll();	    redisplay();	}}voidPageScrollDown(){	int i, n;	n = max(1, SIZE(curwind) - 1);	for (i=0; i<n; i++) {	    DownScroll();	    redisplay();	}}#endif	/* MSDOS */voidPrevPage(){	Line	*newline;	if (Asking)		return;	if (arg_value() < 0) {		negate_arg_value();		NextPage();		return;	}	if (arg_type() == YES)		DownScroll();	else {		newline = prev_line(curwind->w_top, max(1, SIZE(curwind) - 1));		SetTop(curwind, curwind->w_line = newline);		if (curwind->w_bufp == curbuf)			SetLine(newline);	}}voidUpScroll(){	SetTop(curwind, next_line(curwind->w_top, arg_value()));	if ((curwind->w_bufp == curbuf) &&	    (in_window(curwind, curline) == -1))		SetLine(curwind->w_top);}voidDownScroll(){	SetTop(curwind, prev_line(curwind->w_top, arg_value()));	if ((curwind->w_bufp == curbuf) &&	    (in_window(curwind, curline) == -1))		SetLine(curwind->w_top);}bool	VisBell = NO;voidrbell(){	RingBell = YES;}/* Message prints the null terminated string onto the bottom line of the   terminal. */voidmessage(str)char	*str;{	if (InJoverc)		return;	UpdMesg = YES;	errormsg = NO;	if (str != mesgbuf)		null_ncpy(mesgbuf, str, (sizeof mesgbuf) - 1);}/* End of Window */voidEow(){	if (Asking)		return;	SetLine(next_line(curwind->w_top, SIZE(curwind) - 1 -			min(SIZE(curwind) - 1, arg_value() - 1)));	if (!is_an_arg())		Eol();}/* Beginning of Window */voidBow(){	if (Asking)		return;	SetLine(next_line(curwind->w_top, min(SIZE(curwind) - 1, arg_value() - 1)));}private int	LineNo,		last_col;private bool		DoAutoNL;private Window	*old_wind;	/* save the window we were in BEFORE				   before we were called, if UseBuffers				   is nonzero */bool	UseBuffers = FALSE,	TOabort = FALSE;/* This initializes the typeout.  If send-typeout-to-buffers is set   the buffer NAME is created (emptied if it already exists) and output   goes to the buffer.  Otherwise output is drawn on the screen and   erased by TOstop() */voidTOstart(name, auto_newline)char	*name;bool	auto_newline;{	if (UseBuffers) {		old_wind = curwind;		pop_wind(name, YES, B_SCRATCH);	} else		DisabledRedisplay = YES;	TOabort = FALSE;	LineNo = last_col = 0;	DoAutoNL = auto_newline;}#ifdef	STDARGS	voidTypeout(char *fmt, ...)#else	/*VARARGS1*/ voidTypeout(fmt, va_alist)	char	*fmt;	va_dcl#endif{	if (TOabort)		return;	if (!UseBuffers && (LineNo == ILI - 1)) {		register int	c;		LineNo = 0;		last_col = 0;		f_mess("--more--");		if ((c = jgetchar()) != ' ') {			TOabort = TRUE;			if (c != AbortChar && c != RUBOUT)				Ungetc(c);			f_mess(NullStr);			return;		}		f_mess(NullStr);	}	if (fmt) {		char	string[132];		va_list	ap;		va_init(ap, fmt);		format(string, sizeof string, fmt, ap);		va_end(ap);		if (UseBuffers) {			ins_str(string, NO);		} else {			i_set(LineNo, last_col);			(void) swrite(string, NO, YES);			last_col = i_col;		}	}	if (!UseBuffers) {		PhysScreen[LineNo].s_id = -1;		if (fmt == NULL || DoAutoNL) {			cl_eol();			flushscreen();			LineNo += 1;			last_col = 0;		}	} else if (fmt == NULL || DoAutoNL)		ins_str("\n", NO);}voidTOstop(){	int	c;	if (UseBuffers) {		ToFirst();		SetWind(old_wind);	} else {		if (TOabort) {			DisabledRedisplay = NO;		} else {			if (last_col != 0)				Typeout((char *)NULL);			Typeout("----------");			cl_eol();			flushscreen();			c = jgetchar();			if (c != ' ')				Ungetc(c);			DisabledRedisplay = NO;		}	}}

⌨️ 快捷键说明

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