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

📄 b.c

📁 举世闻名的joe记事本源程序
💻 C
📖 第 1 页 / 共 4 页
字号:
					n -= GSIZE(p->hdr);					p->line += p->hdr->nlines;				}				if (!pnext(p))					return NULL;			} while (n > GSIZE(p->hdr));		if (GCHAR(p) == '\n')			++p->line;		++p->byte;		++p->ofst;	} while (--n);	if (p->ofst == GSIZE(p->hdr))		pnext(p);	return p;}/* move p to the previous byte: does not take into account -crlf mode */static int prgetb1(P *p){	unsigned char c;	if (!p->ofst)		if (!pprev(p))			return NO_MORE_DATA;	--p->ofst;	c = GCHAR(p);	--p->byte;	p->valcol = 0;	if (c == '\n')		--p->line;	return c;}/* move p to the previous byte */int prgetb(P *p){	int c = prgetb1(p);	if (p->b->o.crlf && c == '\n') {		c = prgetb1(p);		if (c == '\r')			return '\n';		if (c != NO_MORE_DATA)			pgetb(p);		c = '\n';	}	return c;}/* move p to the previous character (try to keep col updated) */int prgetc(P *p){	if (p->b->o.charmap->type) {		if (pisbol(p))			return prgetb(p);		else {			P *q = pdup(p, USTR "prgetc");			P *r;			p_goto_bol(q);			r = pdup(q, USTR "prgetc");			while (q->byte<p->byte) {				pset(r, q);				pgetc(q);			}			pset(p,r);			prm(r);			prm(q);			return brch(p);		}#if 0		int d = 0;		int c;		int n = 0;		int val = p->valcol;		for(;;) {			c = prgetb(p);			if (c == NO_MORE_DATA)				return NO_MORE_DATA;			else if ((c&0xC0)==0x80) {				d |= ((c&0x3F)<<n);				n += 6;			} else if ((c&0x80)==0x00) { /* One char */				d = c;				break;			} else if ((c&0xE0)==0xC0) { /* Two chars */				d |= ((c&0x1F)<<n);				break;			} else if ((c&0xF0)==0xE0) { /* Three chars */				d |= ((c&0x0F)<<n);				break;			} else if ((c&0xF8)==0xF0) { /* Four chars */				d |= ((c&0x07)<<n);				break;			} else if ((c&0xFC)==0xF8) { /* Five chars */				d |= ((c&0x03)<<n);				break;			} else if ((c&0xFE)==0xFC) { /* Six chars */				d |= ((c&0x01)<<n);				break;			} else { /* FIXME: Invalid (0xFE or 0xFF found) */				break;			}		}		if (val && c!='\t' && c!='\n') {			p->valcol = 1;			p->col -= joe_wcwidth(1,d);		}				return d;#endif	}	else {		return prgetb(p);	}}/* move p n characters backwards */P *pbkwd(P *p, long n){	if (!n)		return p;	p->valcol = 0;	do {		if (!p->ofst)			do {				if (p->ofst) {					p->byte -= p->ofst;					n -= p->ofst;					p->line -= p->hdr->nlines;				}				if (!pprev(p))					return NULL;			} while (n > GSIZE(p->hdr));		--p->ofst;		--p->byte;		if (GCHAR(p) == '\n')			--p->line;	} while (--n);	return p;}/* move p n characters forwards/backwards according to loc */P *pgoto(P *p, long loc){	if (loc > p->byte)		pfwrd(p, loc - p->byte);	else if (loc < p->byte)		pbkwd(p, p->byte - loc);	return p;}/* make p->col valid */P *pfcol(P *p){	long pos = p->byte;	p_goto_bol(p);	while (p->byte < pos)		pgetc(p);	return p;}/* move p to the beginning of line */P *p_goto_bol(P *p){	if (pprevl(p))		pgetb(p);	p->col = 0;	p->valcol = 1;	return p;}/* move p to the indentation point */P *p_goto_indent(P *p, int c){	int d;	p_goto_bol(p);	while ((d=brc(p)), d==c || ((c==' ' || c=='\t') && (d==' ' || d=='\t')))		pgetc(p);	return p;}/* move p to the end of line */P *p_goto_eol(P *p){	if (p->b->o.crlf || p->b->o.charmap->type)		while (!piseol(p))			pgetc(p);	else		while (p->ofst != GSIZE(p->hdr)) {			unsigned char c;			c = GCHAR(p);			if (c == '\n')				break;			else {				++p->byte;				++p->ofst;				if (c == '\t')					p->col += p->b->o.tab - p->col % p->b->o.tab;				else					++p->col;				if (p->ofst == GSIZE(p->hdr))					pnext(p);			}		}	return p;}/* move p to the beginning of next line */P *pnextl(P *p){	int c;	do {		if (p->ofst == GSIZE(p->hdr))			do {				p->byte += GSIZE(p->hdr) - p->ofst;				if (!pnext(p))					return NULL;			} while (!p->hdr->nlines);		c = GCHAR(p);		++p->byte;		++p->ofst;	} while (c != '\n');	++p->line;	p->col = 0;	p->valcol = 1;	if (p->ofst == GSIZE(p->hdr))		pnext(p);	return p;}/* move p to the end of previous line */P *pprevl(P *p){	int c;	p->valcol = 0;	do {		if (!p->ofst)			do {				p->byte -= p->ofst;				if (!pprev(p))					return NULL;			} while (!p->hdr->nlines);		--p->ofst;		--p->byte;		c = GCHAR(p);	} while (c != '\n');	--p->line;	if (p->b->o.crlf && c == '\n') {		int k = prgetb1(p);		if (k != '\r' && k != NO_MORE_DATA)			pgetb(p);	}	return p;}/* move p to the given 'line' line */P *pline(P *p, long line){	if (line > p->b->eof->line) {		pset(p, p->b->eof);		return p;	}	if (line < labs(p->line - line)) {		pset(p, p->b->bof);	}	if (labs(p->b->eof->line - line) < labs(p->line - line)) {		pset(p, p->b->eof);	}	if (p->line == line) {		p_goto_bol(p);		return p;	}	while (line > p->line)		pnextl(p);	if (line < p->line) {		while (line < p->line)			pprevl(p);		p_goto_bol(p);	}	return p;}/* move p to the given 'goalcol' column *//* lands at exact column or on character which would cause us to go past goalcol */P *pcol(P *p, long goalcol){	p_goto_bol(p);	if(p->b->o.charmap->type) {		do {			int c;			int wid;			c = brch(p);			if (c == NO_MORE_DATA)				break;			if (c == '\n')				break;			if (p->b->o.crlf && c == '\r' && piseol(p))				break;			if (c == '\t')				wid = p->b->o.tab - p->col % p->b->o.tab;			else				wid = joe_wcwidth(1,c);			if (p->col + wid > goalcol)				break;			pgetc(p);		} while (p->col != goalcol);	} else {		do {			unsigned char c;			int wid;			if (p->ofst == GSIZE(p->hdr))				break;			c = GCHAR(p);			if (c == '\n')				break;			if (p->b->o.crlf && c == '\r' && piseol(p))				break;			if (c == '\t')				wid = p->b->o.tab - p->col % p->b->o.tab;			else				wid = 1;			if (p->col + wid > goalcol)				break;			if (++p->ofst == GSIZE(p->hdr))				pnext(p);			++p->byte;			p->col += wid;		} while (p->col != goalcol);	}	return p;}/* Move to goal column, then skip backwards to just after first non-whitespace character */P *pcolwse(P *p, long goalcol){	int c;	pcol(p, goalcol);	do {		c = prgetc(p);	} while (c == ' ' || c == '\t');	if (c != NO_MORE_DATA)		pgetc(p);	return p;}/* Move p to goalcol: stops after first character which equals or exceeds goal col (unlike   pcol() which will stops before character which would exceed goal col) */P *pcoli(P *p, long goalcol){	p_goto_bol(p);	if (p->b->o.charmap->type) {		while (p->col < goalcol) {			int c;			c = brc(p);			if (c == NO_MORE_DATA)				break;			if (c == '\n')				break;			if (p->b->o.crlf && c=='\r' && piseol(p))				break;			pgetc(p);		}	} else {		while (p->col < goalcol) {			unsigned char c;			if (p->ofst == GSIZE(p->hdr))				break;			c = GCHAR(p);			if (c == '\n')				break;			if (p->b->o.crlf && c == '\r' && piseol(p))				break;			if (c == '\t')				p->col += p->b->o.tab - p->col % p->b->o.tab;			else				++p->col;			if (++p->ofst == GSIZE(p->hdr))				pnext(p);			++p->byte;		}	}	return p;}/* fill space between curent column and 'to' column with tabs/spaces */void pfill(P *p, long to, int usetabs){	if (usetabs=='\t')		while (piscol(p) < to)			if (p->col + p->b->o.tab - p->col % p->b->o.tab <= to) {				binsc(p, '\t');				pgetc(p);			} else {				binsc(p, ' ');				pgetc(p);			}	else		while (piscol(p) < to) {			binsc(p, usetabs);			pgetc(p);		}}/* delete sequence of whitespaces - backwards */void pbackws(P *p){	int c;	P *q = pdup(p, USTR "pbackws");	do {		c = prgetc(q);	} while (c == ' ' || c == '\t');	if (c != NO_MORE_DATA)		pgetc(q);	bdel(q, p);	prm(q);}static int frgetc(P *p){	if (!p->ofst)		pprev(p);	--p->ofst;	return GCHAR(p);}static void ffwrd(P *p, int n){	while (n > GSIZE(p->hdr) - p->ofst) {		n -= GSIZE(p->hdr) - p->ofst;		if (!pnext(p))			return;	}	if ((p->ofst += n) == GSIZE(p->hdr))		pnext(p);}/* forward find pattern 's' in text pointed by 'p' (Boyer-Moore algorithm) */static P *ffind(P *p, unsigned char *s, int len){	long amnt = p->b->eof->byte - p->byte;	int x;	unsigned char table[256], c;	if (len > amnt)		return NULL;	if (!len)		return p;	p->valcol = 0;	mset(table, 255, 256);	for (x = 0; x != len - 1; ++x)		table[s[x]] = x;	ffwrd(p, len);	amnt -= len;	x = len;	do {		if ((c = frgetc(p)) != s[--x]) {			if (table[c] == 255) {				ffwrd(p, len + 1);				amnt -= x + 1;			} else if (x <= table[c]) {				ffwrd(p, len - x + 1);				--amnt;			} else {				ffwrd(p, len - table[c]);				amnt -= x - table[c];			}			if (amnt < 0)				return NULL;			else				x = len;		}	} while (x);	return p;}/* forward find (case insensitive) pattern 's' in text pointed by 'p' (Boyer-Moore algorithm) */static P *fifind(P *p, unsigned char *s, int len){	long amnt = p->b->eof->byte - p->byte;	int x;	struct charmap *map = p->b->o.charmap;	unsigned char table[256], c;	if (len > amnt)		return NULL;	if (!len)		return p;	p->valcol = 0;	mset(table, 255, 256);	for (x = 0; x != len - 1; ++x)		table[s[x]] = x;	ffwrd(p, len);	amnt -= len;	x = len;	do {		if ((c = joe_tolower(map,frgetc(p))) != s[--x]) {			if (table[c] == 255) {				ffwrd(p, len + 1);				amnt -= x + 1;			} else if (x <= table[c]) {				ffwrd(p, len - x + 1);				--amnt;			} else {				ffwrd(p, len - table[c]);				amnt -= x - table[c];			}			if (amnt < 0)				return NULL;			else				x = len;		}	} while (x);	return p;}/* move cursor p to q's position and set p's col, line, ofst, byte etc. accordingly *//* same as rgetto() but p is before q */static P *getto(P *p, P *q){	while (p->hdr != q->hdr || p->ofst != q->ofst) {		if (GCHAR(p) == '\n')			++p->line;		++p->byte;		++p->ofst;		if (p->ofst == GSIZE(p->hdr))			pnext(p);		while (!p->ofst && p->hdr != q->hdr) {			p->byte += GSIZE(p->hdr);			p->line += p->hdr->nlines;			pnext(p);		}	}	return p;}/* find forward substring s in text pointed by p and set p after found substring */P *pfind(P *p, unsigned char *s, int len){	P *q = pdup(p, USTR "pfind");	if (ffind(q, s, len)) {		getto(p, q);		prm(q);		return p;	} else {		prm(q);		return NULL;	}}/* same as pfind() but case insensitive */P *pifind(P *p, unsigned char *s, int len){	P *q = pdup(p, USTR "pifind");	if (fifind(q, s, len)) {		getto(p, q);		prm(q);		return p;	} else {		prm(q);		return NULL;	}}static void fbkwd(P *p, int n){	while (n > p->ofst) {		n -= p->ofst;		if (!pprev(p))			return;	}	if (p->ofst >= n)		p->ofst -= n;	else		p->ofst = 0;}static int fpgetc(P *p){	int c;	if (p->ofst == GSIZE(p->hdr))		return NO_MORE_DATA;	c = GCHAR(p);	if (++p->ofst == GSIZE(p->hdr))		pnext(p);	return c;}/* backward find pattern 's' in text pointed by 'p' (Boyer-Moore algorithm) */static P *frfind(P *p, unsigned char *s, int len){	long amnt = p->byte;	int x;	unsigned char table[256], c;	if (len > p->b->eof->byte - p->byte) {		x = len - (p->b->eof->byte - p->byte);		if (amnt < x)			return NULL;		amnt -= x;		fbkwd(p, x);	}	if (!len)		return p;	p->valcol = 0;	mset(table, 255, 256);	for (x = len; --x; table[s[x]] = len - x - 1) ;	x = 0;	do {		if ((c = fpgetc(p)) != s[x++]) {			if (table[c] == 255) {				fbkwd(p, len + 1);				amnt -= len - x + 1;			} else if (len - table[c] <= x) {				fbkwd(p, x + 1);				--amnt;			} else {				fbkwd(p, len - table[c]);				amnt -= len - table[c] - x;			}			if (amnt < 0)				return NULL;			else				x = 0;		}	} while (x != len);	fbkwd(p, len);	return p;}/* backward find (case insensitive) pattern 's' in text pointed by 'p' (Boyer-Moore algorithm) */static P *frifind(P *p, unsigned char *s, int len){	long amnt = p->byte;	int x;	unsigned char table[256], c;	struct charmap *map = p->b->o.charmap;	if (len > p->b->eof->byte - p->byte) {		x = len - (p->b->eof->byte - p->byte);		if (amnt < x)			return NULL;		amnt -= x;		fbkwd(p, x);	}	if (!len)		return p;	p->valcol = 0;	mset(table, 255, 256);	for (x = len; --x; table[s[x]] = len - x - 1) ;	x = 0;	do {		if ((c = joe_tolower(map,fpgetc(p))) != s[x++]) {			if (table[c] == 255) {				fbkwd(p, len + 1);				amnt -= len - x + 1;			} else if (len - table[c] <= x) {				fbkwd(p, x + 1);				--amnt;			} else {				fbkwd(p, len - table[c]);				amnt -= len - table[c] - x;			}			if (amnt < 0)				return NULL;			else				x = 0;		}	} while (x != len);	fbkwd(p, len);	return p;}/* move cursor p to q's position and set p's col, line, ofst, byte etc. accordingly *//* same as getto() but q is before p */static P *rgetto(P *p, P *q){	while (p->hdr != q->hdr || p->ofst != q->ofst) {		if (!p->ofst)			do {				if (p->ofst) {					p->byte -= p->ofst;					p->line -= p->hdr->nlines;

⌨️ 快捷键说明

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