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

📄 uedit.c

📁 举世闻名的joe记事本源程序
💻 C
📖 第 1 页 / 共 4 页
字号:
		for (x = 0; x != scrollamnt; ++x)			pprevl(bw->top);		p_goto_bol(bw->top);		/* Move cursor */		for (x = 0; x != cursoramnt; ++x)			pprevl(bw->cursor);		p_goto_bol(bw->cursor);		pcol(bw->cursor, bw->cursor->xcol);		/* If window is on the screen, give (buffered) scrolling command */		if (bw->parent->y != -1)			nscrldn(bw->parent->t->t, bw->y, bw->y + bw->h, scrollamnt);	}}/* Scroll buffer window down n lines * If end of file is close, scrolls as much as possible * If end of file is on-screen, cursor jumps to end of file * * If flg is set: cursor stays fixed relative to screen edge * If flg is clr: cursor stays fixed on the buffer line */void scrdn(BW *bw, int n, int flg){	int scrollamnt = 0;	int cursoramnt = 0;	int x;	/* How much we're really going to scroll... */	if (bw->o.hex) {		if (bw->top->b->eof->byte/16 < bw->top->byte/16 + bw->h) {			cursoramnt = bw->top->b->eof->byte/16 - bw->cursor->byte/16;			if (!flg && cursoramnt > n)				cursoramnt = n;		} else if (bw->top->b->eof->byte/16 - (bw->top->byte/16 + bw->h) >= n)			cursoramnt = scrollamnt = n;		else			cursoramnt = scrollamnt = bw->top->b->eof->byte/16 - (bw->top->byte/16 + bw->h) + 1;	} else {		if (bw->top->b->eof->line < bw->top->line + bw->h) {			cursoramnt = bw->top->b->eof->line - bw->cursor->line;			if (!flg && cursoramnt > n)				cursoramnt = n;		} else if (bw->top->b->eof->line - (bw->top->line + bw->h) >= n)			cursoramnt = scrollamnt = n;		else			cursoramnt = scrollamnt = bw->top->b->eof->line - (bw->top->line + bw->h) + 1;	}	if (bw->o.hex) {		/* Move top-of-window pointer */		pfwrd(bw->top,16*scrollamnt);		/* Move cursor */		pfwrd(bw->cursor,16*cursoramnt);		/* If window is on screen, give (buffered) scrolling command to terminal */		if (bw->parent->y != -1)			nscrlup(bw->parent->t->t, bw->y, bw->y + bw->h, scrollamnt);	} else {		/* Move top-of-window pointer */		for (x = 0; x != scrollamnt; ++x)			pnextl(bw->top);		/* Move cursor */		for (x = 0; x != cursoramnt; ++x)			pnextl(bw->cursor);		pcol(bw->cursor, bw->cursor->xcol);		/* If window is on screen, give (buffered) scrolling command to terminal */		if (bw->parent->y != -1)			nscrlup(bw->parent->t->t, bw->y, bw->y + bw->h, scrollamnt);	}}/* Page up */int upgup(BW *bw){	if (menu_above) {		if (bw->parent->link.prev->watom==&watommenu) {			return umpgup(bw->parent->link.prev->object);		}	} else {		if (bw->parent->link.next->watom==&watommenu) {			return umpgup(bw->parent->link.next->object);		}	}	bw = (BW *) bw->parent->main->object;	if (bw->o.hex ? bw->cursor->byte < 16 : !bw->cursor->line)		return -1;	if (pgamnt < 0)		scrup(bw, bw->h / 2 + bw->h % 2, 1);	else if (pgamnt < bw->h)		scrup(bw, bw->h - pgamnt, 1);	else		scrup(bw, 1, 1);	return 0;}/* Page down */int upgdn(BW *bw){	if (menu_above) {		if (bw->parent->link.prev->watom==&watommenu) {			return umpgdn(bw->parent->link.prev->object);		}	} else {		if (bw->parent->link.next->watom==&watommenu) {			return umpgdn(bw->parent->link.next->object);		}	}	bw = (BW *) bw->parent->main->object;	if (bw->o.hex ? bw->cursor->byte/16 == bw->b->eof->byte/16 : bw->cursor->line == bw->b->eof->line)		return -1;	if (pgamnt < 0)		scrdn(bw, bw->h / 2 + bw->h % 2, 1);	else if (pgamnt < bw->h)		scrdn(bw, bw->h - pgamnt, 1);	else		scrdn(bw, 1, 1);	return 0;}/* Scroll by a single line.  The cursor moves with the scroll */int uupslide(BW *bw){	bw = (BW *) bw->parent->main->object;	if (bw->o.hex ? bw->top->byte/16 : bw->top->line) {		if (bw->o.hex ? bw->top->byte/16 + bw->h -1 != bw->cursor->byte/16 : bw->top->line + bw->h - 1 != bw->cursor->line)			udnarw(bw);		scrup(bw, 1, 0);		return 0;	} else		/* was return -1; */		return uuparw(bw);}int udnslide(BW *bw){	bw = (BW *) bw->parent->main->object;	if (bw->o.hex ? bw->top->line/16 + bw->h <= bw->top->b->eof->byte/16 : bw->top->line + bw->h <= bw->top->b->eof->line) {		if (bw->o.hex ? bw->top->byte/16 != bw->cursor->byte/16 : bw->top->line != bw->cursor->line)			uuparw(bw);		scrdn(bw, 1, 0);		return 0;	} else		/* was return -1; */		return udnarw(bw);}/* Move cursor to specified line number */static B *linehist = NULL;	/* History of previously entered line numbers */static int doline(BW *bw, unsigned char *s, void *object, int *notify){	long num = calc(bw, s);	if (notify)		*notify = 1;	vsrm(s);	if (num >= 1 && !merr) {		int tmp = mid;		if (num > bw->b->eof->line)			num = bw->b->eof->line + 1;		pline(bw->cursor, num - 1), bw->cursor->xcol = piscol(bw->cursor);		mid = 1;		dofollows();		mid = tmp;		return 0;	} else {		if (merr)			msgnw(bw->parent, merr);		else			msgnw(bw->parent, joe_gettext(_("Invalid line number")));		return -1;	}}int uline(BW *bw){	if (wmkpw(bw->parent, joe_gettext(_("Go to line (^C to abort): ")), &linehist, doline, NULL, NULL, NULL, NULL, NULL, locale_map, 0))		return 0;	else		return -1;}/* Move cursor to specified column number */static B *colhist = NULL;	/* History of previously entered column numbers */static int docol(BW *bw, unsigned char *s, void *object, int *notify){	long num = calc(bw, s);	if (notify)		*notify = 1;	vsrm(s);	if (num >= 1 && !merr) {		int tmp = mid;		pcol(bw->cursor, num - 1), bw->cursor->xcol = piscol(bw->cursor);		mid = 1;		dofollows();		mid = tmp;		return 0;	} else {		if (merr)			msgnw(bw->parent, merr);		else			msgnw(bw->parent, joe_gettext(_("Invalid column number")));		return -1;	}}int ucol(BW *bw){	if (wmkpw(bw->parent, joe_gettext(_("Go to column (^C to abort): ")), &colhist, docol, NULL, NULL, NULL, NULL, NULL, locale_map, 0))		return 0;	else		return -1;}/* Move cursor to specified byte number */static B *bytehist = NULL;	/* History of previously entered byte numbers */static int dobyte(BW *bw, unsigned char *s, void *object, int *notify){	long num = calc(bw, s);	if (notify)		*notify = 1;	vsrm(s);	if (num >= 0 && !merr) {		int tmp = mid;		pgoto(bw->cursor, num), bw->cursor->xcol = piscol(bw->cursor);		mid = 1;		dofollows();		mid = tmp;		return 0;	} else {		if (merr)			msgnw(bw->parent, merr);		else			msgnw(bw->parent, joe_gettext(_("Invalid byte number")));		return -1;	}}int ubyte(BW *bw){	if (wmkpw(bw->parent, joe_gettext(_("Go to byte (^C to abort): ")), &bytehist, dobyte, NULL, NULL, NULL, NULL, NULL, locale_map, 0))		return 0;	else		return -1;}/* Delete character under cursor * or write ^D to process if we're at end of file in a shell window */int udelch(BW *bw){	P *p;	if (piseof(bw->cursor))		return -1;	pgetc(p = pdup(bw->cursor, USTR "udelch"));	bdel(bw->cursor, p);	prm(p);	return 0;}/* Backspace */int ubacks(BW *bw, int k){	/* Don't backspace when at beginning of line in prompt windows */	if (bw->parent->watom->what == TYPETW || !pisbol(bw->cursor)) {		int c;		int indent;		int col;		int indwid;		int wid;		/* Degenerate into ltarw for overtype mode */		if (bw->o.overtype) {			return u_goto_left(bw);		}		if (pisbof(bw->cursor))			return -1;		/* Indentation point of this line */		indent = pisindent(bw->cursor);		/* Column position of cursor */		col = piscol(bw->cursor);		/* Indentation step in columns */		if (bw->o.indentc=='\t')			wid = bw->o.tab;		else			wid = 1;		indwid = (bw->o.istep*wid);		/* Smart backspace when: cursor is at indentation point, indentation point		   is a multiple of indentation width, we're not at beginning of line,		   'smarthome' option is enabled, and indentation is purely made out of		   indent characters (or purify indents is enabled). */				/* Ignore purify for backspace */		if (col == indent && (col%indwid)==0 && col!=0 && bw->o.smartbacks && bw->o.autoindent) {			P *p;			/* Delete all indentation */			p = pdup(bw->cursor, USTR "ubacks");			p_goto_bol(p);			bdel(p,bw->cursor);			prm(p);			/* Indent to new position */			pfill(bw->cursor,col-indwid,bw->o.indentc);		} else if (col<indent && !pisbol(bw->cursor)) {			/* We're before indent point: delete indwid worth of space but do not			   cross line boundary.  We could probably replace the above with this. */			int cw=0;			P *p = pdup(bw->cursor, USTR "ubacks");			do {				c = prgetc(bw->cursor);				if(c=='\t') cw += bw->o.tab;				else cw += 1;				bdel(bw->cursor, p);			} while(!pisbol(bw->cursor) && cw<indwid);			prm(p);		} else {			/* Regular backspace */			P *p = pdup(bw->cursor, USTR "ubacks");			if ((c = prgetc(bw->cursor)) != NO_MORE_DATA)				if (!bw->o.overtype || c == '\t' || pisbol(p) || piseol(p))					bdel(bw->cursor, p);			prm(p);		}		return 0;	} else		return -1;}/*  * Delete sequence of characters (alphabetic, numeric) or (white-space) *	if cursor is on the white-space it will delete all white-spaces *		until alphanumeric character *      if cursor is on the alphanumeric it will delete all alphanumeric *		characters until character that is not alphanumeric */int u_word_delete(BW *bw){	P *p = pdup(bw->cursor, USTR "u_word_delete");	struct charmap *map=bw->b->o.charmap;	int c = brch(p);	if (joe_isalnum_(map,c))		while (joe_isalnum_(map,(c = brch(p))))			pgetc(p);	else if (joe_isspace(map,c))		while (joe_isspace(map,(c = brch(p))))			pgetc(p);	else		pgetc(p);	if (p->byte == bw->cursor->byte) {		prm(p);		return -1;	}	bdel(bw->cursor, p);	prm(p);	return 0;}/* Delete from cursor to beginning of word it's in or immediately after, * to start of whitespace, or a single character */int ubackw(BW *bw){	P *p = pdup(bw->cursor, USTR "ubackw");	int c = prgetc(bw->cursor);	struct charmap *map=bw->b->o.charmap;	if (joe_isalnum_(map,c)) {		while (joe_isalnum_(map,(c = prgetc(bw->cursor))))			/* do nothing */;		if (c != NO_MORE_DATA)			pgetc(bw->cursor);	} else if (joe_isspace(map,c)) {		while (joe_isspace(map,(c = prgetc(bw->cursor))))			/* do nothing */;		if (c != NO_MORE_DATA)			pgetc(bw->cursor);	}	if (bw->cursor->byte == p->byte) {		prm(p);		return -1;	}	bdel(bw->cursor, p);	prm(p);	return 0;}/* Delete from cursor to end of line, or if there's nothing to delete, * delete the line-break */int udelel(BW *bw){	P *p = p_goto_eol(pdup(bw->cursor, USTR "udelel"));	if (bw->cursor->byte == p->byte) {		prm(p);		return udelch(bw);	} else		bdel(bw->cursor, p);	prm(p);	return 0;}/* Delete to beginning of line, or if there's nothing to delete, * delete the line-break */int udelbl(BW *bw){	P *p = p_goto_bol(pdup(bw->cursor, USTR "udelbl"));	if (p->byte == bw->cursor->byte) {		prm(p);		return ubacks(bw, 8);	/* The 8 goes to the process if we're at EOF of shell window */	} else		bdel(p, bw->cursor);	prm(p);	return 0;}/* Delete entire line */int udelln(BW *bw){	P *p = pdup(bw->cursor, USTR "udelln");	p_goto_bol(bw->cursor);	pnextl(p);	if (bw->cursor->byte == p->byte) {		prm(p);		return -1;	}	bdel(bw->cursor, p);	prm(p);	return 0;}/* Insert a space */int uinsc(BW *bw){	binsc(bw->cursor, ' ');	return 0;}/* Move p backwards to first non-blank line and return its indentation */int find_indent(P *p){	int x;	for (x=0; x != 10; ++x) {		if (!pprevl(p)) return -1;		p_goto_bol(p);		if (!pisblank(p)) break;	}	if (x==10)		return -1;	else		return pisindent(p);}/* Type a character into the buffer (deal with left margin, overtype mode and * word-wrap), if cursor is at end of shell window buffer, just send character * to process. */struct utf8_sm utype_utf8_sm;int utypebw_raw(BW *bw, int k, int no_decode){	struct charmap *map=bw->b->o.charmap;	/* Send data to shell window */	if (bw->b->pid && piseof(bw->cursor)) {		unsigned char c = k;		joe_write(bw->b->out, &c, 1);		return 0;	}	/* Hex mode overtype is real simple */	if (bw->o.hex && bw->o.overtype) {		P *p;		unsigned char c = k;		binsm(bw->cursor, &c, 1);		pgetb(bw->cursor);		if (piseof(bw->cursor))			return 0;		pgetb(p = pdup(bw->cursor, USTR "utypebw_raw"));		bdel(bw->cursor, p);		prm(p);		return 0;	}	if (k == '\t' && bw->o.overtype && !piseol(bw->cursor)) { /* TAB in overtype mode is supposed to be just cursor motion */		int col = bw->cursor->xcol;		/* Current cursor column */		col = col + bw->o.tab - (col%bw->o.tab);/* Move to next tab stop */		pcol(bw->cursor,col);			/* Try to position cursor there */		if (!bw->o.picture && piseol(bw->cursor) && piscol(bw->cursor)<col) {	/* We moved past end of line, insert a tab (unless in picture mode) */			if (bw->o.spaces)				pfill(bw->cursor,col,' ');			else				pfill(bw->cursor,col,'\t');		}		bw->cursor->xcol = col;			/* Put cursor there even if we can't really go there */	} else if (k == '\t' && bw->o.smartbacks && bw->o.autoindent && pisindent(bw->cursor)>=piscol(bw->cursor)) {		P *p = pdup(bw->cursor, USTR "utypebw_raw");		int n = find_indent(p);		if (n != -1 && pisindent(bw->cursor)==piscol(bw->cursor) && n > pisindent(bw->cursor)) {			if (!pisbol(bw->cursor))				udelbl(bw);			while (joe_isspace(map,(k = pgetc(p))) && k != '\n') {				binsc(bw->cursor, k);				pgetc(bw->cursor);			}		} else {			int x;			for (x=0;x<bw->o.istep;++x) {				binsc(bw->cursor,bw->o.indentc);				pgetc(bw->cursor);			}		}		bw->cursor->xcol = piscol(bw->cursor);		prm (p);	} else if (k == '\t' && bw->o.spaces) {		long n;		if (bw->o.picture)			n = bw->cursor->xcol;		else			n = piscol(bw->cursor);		utype_utf8_sm.state = 0;		utype_utf8_sm.ptr = 0;		n = bw->o.tab - n % bw->o.tab;		while (n--)			utypebw(bw, ' ');	} else {		int upd;		int simple;		int x;		/* Picture mode */		if (bw->o.picture && bw->cursor->xcol!=piscol(bw->cursor))			pfill(bw->cursor,bw->cursor->xcol,' '); /* Why no tabs? */		/* UTF8 decoder */		if(locale_map->type && !no_decode) {			int utf8_char = utf8_decode(&utype_utf8_sm,k);			if(utf8_char >= 0)				k = utf8_char;			else				return 0;		}		upd = bw->parent->t->t->updtab[bw->y + bw->cursor->line - bw->top->line];		simple = 1;		if (pisblank(bw->cursor))			while (piscol(bw->cursor) < bw->o.lmargin) {				binsc(bw->cursor, ' ');				pgetc(bw->cursor);			}		if (!no_decode) {			if(locale_map->type && !bw->b->o.charmap->type) {				unsigned char buf[10];				utf8_encode(buf,k);				k = from_utf8(bw->b->o.charmap,buf);			} else if(!locale_map->type && bw->b->o.charmap->type) {				unsigned char buf[10];				to_utf8(locale_map,buf,k);

⌨️ 快捷键说明

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