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

📄 uedit.c

📁 举世闻名的joe记事本源程序
💻 C
📖 第 1 页 / 共 4 页
字号:
/* *	Basic user edit functions *	Copyright * 		(C) 1992 Joseph H. Allen * *	This file is part of JOE (Joe's Own Editor) */#include "types.h"/***************//* Global options */int pgamnt = -1;		/* No. of PgUp/PgDn lines to keep *//*  * Move cursor to beginning of line */int u_goto_bol(BW *bw){	if (bw->o.hex) {		pbkwd(bw->cursor,bw->cursor->byte%16);	} else {		p_goto_bol(bw->cursor);	}	return 0;}/* * Move cursor to first non-whitespace character, unless it is * already there, in which case move it to beginning of line */int uhome(BW *bw){	P *p;	if (bw->o.hex) {		return u_goto_bol(bw);	}	p = pdup(bw->cursor, USTR "uhome");	if (bw->o.indentfirst) {		if ((bw->o.smarthome) && (piscol(p) > pisindent(p))) { 			p_goto_bol(p);			while (joe_isblank(p->b->o.charmap,brc(p)))				pgetc(p);		} else			p_goto_bol(p);	} else {		if (bw->o.smarthome && piscol(p)==0 && pisindent(p)) {			while (joe_isblank(p->b->o.charmap,brc(p)))				pgetc(p);		} else			p_goto_bol(p);	}	pset(bw->cursor, p);	prm(p);	return 0;}/* * Move cursor to end of line */int u_goto_eol(BW *bw){	if (bw->o.hex) {		if (bw->cursor->byte + 15 - bw->cursor->byte%16 > bw->b->eof->byte)			pset(bw->cursor,bw->b->eof);		else			pfwrd(bw->cursor, 15 - bw->cursor->byte%16);	} else		p_goto_eol(bw->cursor);	return 0;}/* * Move cursor to beginning of file */int u_goto_bof(BW *bw){	p_goto_bof(bw->cursor);	return 0;}/* * Move cursor to end of file */int u_goto_eof(BW *bw){	p_goto_eof(bw->cursor);	return 0;}/* * Move cursor left */int u_goto_left(BW *bw){	if (bw->o.hex) {		if (prgetb(bw->cursor) != NO_MORE_DATA) {			return 0;		} else {			return -1;		}	}	if (bw->o.picture) {		if (bw->cursor->xcol) {			--bw->cursor->xcol;			pcol(bw->cursor,bw->cursor->xcol);			return 0;		} else			return -1;	} else {		/* Have to do ECHKXCOL here because of picture mode */		if (bw->cursor->xcol != piscol(bw->cursor)) {			bw->cursor->xcol = piscol(bw->cursor);			return 0;		} else if (prgetc(bw->cursor) != NO_MORE_DATA) {			bw->cursor->xcol = piscol(bw->cursor);			return 0;		} else {			return -1;		}	}}/* * Move cursor right */int u_goto_right(BW *bw){	if (bw->o.hex) {		if (pgetb(bw->cursor) != NO_MORE_DATA) {			return 0;		} else {			return -1;		}	}	if (bw->o.picture) {		++bw->cursor->xcol;		pcol(bw->cursor,bw->cursor->xcol);		return 0;	} else {		int rtn;		if (pgetc(bw->cursor) != NO_MORE_DATA) {			bw->cursor->xcol = piscol(bw->cursor);			rtn = 0;		} else {			rtn = -1;		}		/* Have to do EFIXXCOL here because of picture mode */		if (bw->cursor->xcol != piscol(bw->cursor))			bw->cursor->xcol = piscol(bw->cursor);		return rtn;	}}/* * Move cursor to beginning of previous word or if there isn't  * previous word then go to beginning of the file * * WORD is a sequence non-white-space characters */int p_goto_prev(P *ptr){	P *p = pdup(ptr, USTR "p_goto_prev");	struct charmap *map=ptr->b->o.charmap;	int c = prgetc(p);	if (joe_isalnum_(map,c)) {		while (joe_isalnum_(map,(c=prgetc(p))))			/* Do nothing */;		if (c != NO_MORE_DATA)			pgetc(p);	} else if (joe_isspace(map,c) || joe_ispunct(map,c)) {		while ((c=prgetc(p)), (joe_isspace(map,c) || joe_ispunct(map,c)))			/* Do nothing */;		while(joe_isalnum_(map,(c=prgetc(p))))			/* Do nothing */;		if (c != NO_MORE_DATA)			pgetc(p);	}	pset(ptr, p);	prm(p);	return 0;}int u_goto_prev(BW *bw){	return p_goto_prev(bw->cursor);}/* * Move cursor to end of next word or if there isn't  * next word then go to end of the file * * WORD is a sequence non-white-space characters */int p_goto_next(P *ptr){	P *p = pdup(ptr, USTR "p_goto_next");	struct charmap *map=ptr->b->o.charmap;	int c = brch(p);	int rtn = -1;	if (joe_isalnum_(map,c)) {		rtn = 0;		while (joe_isalnum_(map,(c = brch(p))))			pgetc(p);	} else if (joe_isspace(map,c) || joe_ispunct(map,c)) {		while (joe_isspace(map, (c = brch(p))) || joe_ispunct(map,c))			pgetc(p);		while (joe_isalnum_(map,(c = brch(p)))) {			rtn = 0;			pgetc(p);		}	} else		pgetc(p);	pset(ptr, p);	prm(p);	return rtn;}int u_goto_next(BW *bw){	return p_goto_next(bw->cursor);}static P *pboi(P *p){	p_goto_bol(p);	while (joe_isblank(p->b->o.charmap,brch(p)))		pgetc(p);	return p;}static int pisedge(P *p){	P *q;	int c;	if (pisbol(p))		return -1;	if (piseol(p))		return 1;	q = pdup(p, USTR "pisedge");	pboi(q);	if (q->byte == p->byte)		goto left;	if (joe_isblank(p->b->o.charmap,(c = brch(p)))) {		pset(q, p);		if (joe_isblank(p->b->o.charmap,prgetc(q)))			goto no;		if (c == '\t')			goto right;		pset(q, p);		pgetc(q);		if (pgetc(q) == ' ')			goto right;		goto no;	} else {		pset(q, p);		c = prgetc(q);		if (c == '\t')			goto left;		if (c != ' ')			goto no;		if (prgetc(q) == ' ')			goto left;		goto no;	}      right:prm(q);	return 1;      left:prm(q);	return -1;      no:prm(q);	return 0;}int upedge(BW *bw){	if (prgetc(bw->cursor) == NO_MORE_DATA)		return -1;	while (pisedge(bw->cursor) != -1)		prgetc(bw->cursor);	return 0;}int unedge(BW *bw){	if (pgetc(bw->cursor) == NO_MORE_DATA)		return -1;	while (pisedge(bw->cursor) != 1)		pgetc(bw->cursor);	return 0;}/* Move cursor to matching delimiter *//* * begin end * * module endmodule * * function endfunction *  * <word </word * * if elif else fi * * do done * * case esac, endcase * * #if #ifdef #ifndef #elseif #else #endif * * `ifdef  `ifndef  `else `endif * *//* A delimiter set list is a : separated list of delimiter sets.   A delimiter set is two or more groups of matching delimiters.   A group is a list of equivalent delimiters separated with |.   For example, here is a delimiter set list, with three sets:   	"case|casex|casez=endcase:begin=end:if=elif=else=fi:   In the first delimiter set: "case," "casex" and "casez" all match with   "endcase." In the third set: "if" matches with "elif," which matches with   "else," which finally matches with "fi".   The search goes forward if the delimiter matches any words of any group   but the last of the set.  If the delimiter matches a word in the last   group, the search goes backward to the first delimiter.*//* Return pointer to first matching set in delimiter set list.  Returns NULL   if no matches were found. */unsigned char *next_set(unsigned char *set){	while (*set && *set!=':')		++set;	if (*set==':')		++set;	return set;}unsigned char *next_group(unsigned char *group){	while (*group && *group!='=' && *group!=':')		++group;	if (*group=='=')		++group;	return group;}unsigned char *next_word(unsigned char *word){	while (*word && *word!='|' && *word!='=' && *word!=':')		++word;	if (*word=='|')		++word;	return word;}int match_word(unsigned char *word,unsigned char *s){	while (*word==*s && *s && *word) {		++word;		++s;	}	if (!*s && (!*word || *word=='|' || *word=='=' || *word==':'))		return 1;	else		return 0;}int is_in_group(unsigned char *group,unsigned char *s){	while (*group && *group!='=' && *group!=':') {		if (match_word(group, s))			return 1;		else			group = next_word(group);	}	return 0;}int is_in_any_group(unsigned char *group,unsigned char *s){	while (*group && *group!=':') {		if (match_word(group, s))			return 1;		else {			group = next_word(group);			if (*group == '=')				++group;		}	}	return 0;}unsigned char *find_last_group(unsigned char *group){	unsigned char *s;	for (s = group; *s && *s!=':'; s=next_group(s))		group = s;	return group;}#define MAX_WORD_SIZE 255int tomatch_word(BW *bw,unsigned char *set,unsigned char *group){	if (!*group || *group==':') {		/* Backward search */		unsigned char *last_of_set = find_last_group(set);		P *p=pdup(bw->cursor, USTR "tomatch_word");		int c;		unsigned char buf[MAX_WORD_SIZE+1];		int len;		int cnt = 1;		p_goto_next(p);		p_goto_prev(p);		while ((c=prgetc(p)) != NO_MORE_DATA) {			int peek = prgetc(p);			if(peek!=NO_MORE_DATA)				pgetc(p);			if (peek=='\\') {			} else if (c == '"') {				while((c = prgetc(p)) != NO_MORE_DATA) {					if (c == '"') {						c = prgetc(p);						if (c != '\\') {							if (c != NO_MORE_DATA)								pgetc(p);							break;						}					}				}			} else if (bw->o.single_quoted && c == '\'') {				while((c = prgetc(p)) != NO_MORE_DATA)					if (c == '\'') {						c = prgetc(p);						if (c != '\\') {							if (c != NO_MORE_DATA)								pgetc(p);							break;						}					}			} else if (bw->o.c_comment && c == '/') {				c = prgetc(p);				if (c == '*') {					c = prgetc(p);					do {						do {							if (c == '*') break;						} while ((c = prgetc(p)) != NO_MORE_DATA);						c = prgetc(p);					} while (c != NO_MORE_DATA && c != '/');				} else if (c != NO_MORE_DATA)					pgetc(p);			} else if ((bw->o.cpp_comment || bw->o.pound_comment ||			            bw->o.semi_comment || bw->o.vhdl_comment) && c == '\n') {				P *q = pdup(p, USTR "tomatch_word");				int cc;				p_goto_bol(q);				while((cc = pgetc(q)) != '\n') {					if (bw->o.pound_comment && cc == '$' && brch(q)=='#') {						pgetc(q);					} else if(cc=='"') {						while ((cc = pgetc(q)) != '\n')							if (cc == '"') break;							else if (cc == '\\') pgetc(q);					} else if (bw->o.cpp_comment && cc == '/') {						if (brch(q)=='/') {							prgetc(q);							pset(p,q);							break;						}					} else if (bw->o.single_quoted && cc == '\'') {						while((cc = pgetc(q)) != '\n')							if (cc == '\'') break;							else if (cc == '\\') pgetc(q);					} else if (bw->o.vhdl_comment && cc == '-') {						if (brch(q)=='-') {							prgetc(q);							pset(p,q);							break;						}					} else if (bw->o.pound_comment && cc == '#') {						pset(p,q);						break;					} else if (bw->o.semi_comment && cc == ';') {						pset(p,q);						break;					}				}				prm(q);			} else if ((c >= 'a' && c <= 'z') || (c>='A' && c<='Z') || (c>='0' && c<='9') || c=='_') {				int x;				int flg=0;				P *q;				len=0;				while ((c >= 'a' && c <= 'z') || (c>='A' && c<='Z') || c=='_' || (c>='0' && c<='9')) {					if(len!=MAX_WORD_SIZE)						buf[len++]=c;					c=prgetc(p);				}				/* ifdef hack */				q=pdup(p, USTR "tomatch_word");				while (c ==' ' || c=='\t')					c=prgetc(q);				prm(q);				/* VHDL hack */				if ((c=='d' || c=='D') && bw->o.vhdl_comment) {					c=prgetc(q);					if(c=='n' || c=='N') {						c=prgetc(q);						if(c=='e' || c=='E') {							c=prgetc(q);							if(c==' ' || c=='\t' || c=='\n' || c==NO_MORE_DATA)								flg=1;						}					}				}				prm(q);				if (c == set[0])					buf[len++] = c;				if(c!=NO_MORE_DATA)					pgetc(p);				buf[len]=0;				for(x=0;x!=len/2;++x) {					int d = buf[x];					buf[x] = buf[len-x-1];					buf[len-x-1] = d;				}				if (is_in_group(last_of_set,buf)) {					++cnt;				} else if(is_in_group(set,buf) && !flg && !--cnt) {					pset(bw->cursor,p);					prm(p);					return 0;				}			}		}		prm(p);		return -1;	} else {		/* Forward search */		unsigned char *last_of_set = find_last_group(group);		P *p=pdup(bw->cursor, USTR "tomatch_word");		int c;		unsigned char buf[MAX_WORD_SIZE+1];		int len;		int cnt = 1;		p_goto_next(p);		while ((c=pgetc(p)) != NO_MORE_DATA) {			if (c == '\\') {				pgetc(p);			} else if (c == '"') {				while ((c = pgetc(p)) != NO_MORE_DATA)					if (c == '"') break;					else if (c == '\\') pgetc(p);			} else if (c == '$' && brch(p)=='#' && bw->o.pound_comment) {				pgetc(p);			} else if ((bw->o.pound_comment && c == '#') ||				   (bw->o.semi_comment && c == ';') ||				   (bw->o.vhdl_comment && c == '-' && brch(p) == '-')) {				while ((c = pgetc(p)) != NO_MORE_DATA)					if (c == '\n')						break;			} else if (bw->o.single_quoted && c == '\'') {				while((c = pgetc(p)) != NO_MORE_DATA)					if (c == '\'') break;					else if (c == '\\') pgetc(p);			} else if ((bw->o.c_comment || bw->o.cpp_comment) && c == '/') {				c = pgetc(p);				if (c == '*') {					c = pgetc(p);					do {						do {							if (c == '*') break;						} while ((c = pgetc(p)) != NO_MORE_DATA);						c = pgetc(p);					} while (c != NO_MORE_DATA && c != '/');				} else if (c == '/') {					while ((c = pgetc(p)) != NO_MORE_DATA)						if (c == '\n')							break;				} else if (c != NO_MORE_DATA)					prgetc(p);			} else if (c == set[0]) {				/* ifdef hack */				while ((c = pgetc(p))!=NO_MORE_DATA) {					if (c!=' ' && c!='\t')						break;				}				buf[0]=set[0];				len=1;				if (c >= 'a' && c <= 'z')					goto doit;			} else if ((c >= 'a' && c <= 'z') || (c>='A' && c<='Z') || c=='_') {

⌨️ 快捷键说明

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