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

📄 bw.c

📁 举世闻名的joe记事本源程序
💻 C
📖 第 1 页 / 共 3 页
字号:
			from = long_min(w->cursor->xcol, markb->xcol);			to = long_max(w->cursor->xcol, markb->xcol);			dosquare = 1;		} else {			from = long_min(w->cursor->byte, markb->byte);			to = long_max(w->cursor->byte, markb->byte);		}	}	if (marking && w == (BW *)maint->curwin->object)		msetI(t->updtab + w->y, 1, w->h);	if (dosquare) {		from = 0;		to = 0;	}	y=w->y;	attr = t->attr + y*w->t->w;	for (screen = t->scrn + y * w->t->w; y != bot; ++y, (screen += w->t->w), (attr += w->t->w)) {		unsigned char txt[80];		int fmt[80];		unsigned char bf[16];		int x;		memset(txt,' ',76);		msetI(fmt,BG_COLOR(bg_text),76);		txt[76]=0;		if (!flg) {#if SIZEOF_LONG_LONG && SIZEOF_LONG_LONG == SIZEOF_OFF_T			sprintf((char *)bf,"%8llx ",q->byte);#else			sprintf((char *)bf,"%8lx ",q->byte);#endif			memcpy(txt,bf,9);			for (x=0; x!=8; ++x) {				int c;				if (q->byte==w->cursor->byte && !flg) {					fmt[10+x*3] |= INVERSE;					fmt[10+x*3+1] |= INVERSE;				}				if (q->byte>=from && q->byte<to && !flg) {					fmt[10+x*3] |= UNDERLINE;					fmt[10+x*3+1] |= UNDERLINE;					fmt[60+x] |= INVERSE;				}				c = pgetb(q);				if (c >= 0) {					sprintf((char *)bf,"%2.2x",c);					txt[10+x*3] = bf[0];					txt[10+x*3+1] = bf[1];					if (c >= 0x20 && c <= 0x7E)						txt[60+x] = c;					else						txt[60+x] = '.';				} else					flg = 1;			}			for (x=8; x!=16; ++x) {				int c;				if (q->byte==w->cursor->byte && !flg) {					fmt[11+x*3] |= INVERSE;					fmt[11+x*3+1] |= INVERSE;				}				if (q->byte>=from && q->byte<to && !flg) {					fmt[11+x*3] |= UNDERLINE;					fmt[11+x*3+1] |= UNDERLINE;					fmt[60+x] |= INVERSE;				}				c = pgetb(q);				if (c >= 0) {					sprintf((char *)bf,"%2.2x",c);					txt[11+x*3] = bf[0];					txt[11+x*3+1] = bf[1];					if (c >= 0x20 && c <= 0x7E)						txt[60+x] = c;					else						txt[60+x] = '.';				} else					flg = 1;			}		}		genfield(t, screen, attr, 0, y, w->offset, txt, 76, 0, w->w, 1, fmt);	}	prm(q);}void bwgen(BW *w, int linums){	int *screen;	int *attr;	P *p = NULL;	P *q;	int bot = w->h + w->y;	int y;	int dosquare = 0;	long from, to;	long fromline, toline;	SCRN *t = w->t->t;	/* Set w.db to correct value */	if (w->o.highlight && w->o.syntax && (!w->db || w->db->syn != w->o.syntax))		w->db = find_lattr_db(w->b, w->o.syntax);	fromline = toline = from = to = 0;	if (w->b == errbuf) {		P *tmp = pdup(w->cursor, USTR "bwgen");		p_goto_bol(tmp);		from = tmp->byte;		pnextl(tmp);		to = tmp->byte;		prm(tmp);	} else if (markv(0) && markk->b == w->b)		if (square) {			from = markb->xcol;			to = markk->xcol;			dosquare = 1;			fromline = markb->line;			toline = markk->line;		} else {			from = markb->byte;			to = markk->byte;		}	else if (marking && w == (BW *)maint->curwin->object && markb && markb->b == w->b && w->cursor->byte != markb->byte && !from) {		if (square) {			from = long_min(w->cursor->xcol, markb->xcol);			to = long_max(w->cursor->xcol, markb->xcol);			fromline = long_min(w->cursor->line, markb->line);			toline = long_max(w->cursor->line, markb->line);			dosquare = 1;		} else {			from = long_min(w->cursor->byte, markb->byte);			to = long_max(w->cursor->byte, markb->byte);		}	}	if (marking && w == (BW *)maint->curwin->object)		msetI(t->updtab + w->y, 1, w->h);	q = pdup(w->cursor, USTR "bwgen");	y = w->cursor->line - w->top->line + w->y;	attr = t->attr + y*w->t->w;	for (screen = t->scrn + y * w->t->w; y != bot; ++y, (screen += w->t->w), (attr += w->t->w)) {		if (ifhave && !linums)			break;		if (linums)			gennum(w, screen, attr, t, y, t->compose);		if (t->updtab[y]) {			p = getto(p, w->cursor, w->top, w->top->line + y - w->y);/*			if (t->insdel && !w->x) {				pset(q, p);				if (dosquare)					if (w->top->line + y - w->y >= fromline && w->top->line + y - w->y <= toline)						lgena(t, y, t->compose, w->x, w->x + w->w, q, w->offset, from, to);					else						lgena(t, y, t->compose, w->x, w->x + w->w, q, w->offset, 0L, 0L);				else					lgena(t, y, t->compose, w->x, w->x + w->w, q, w->offset, from, to);				magic(t, y, screen, attr, t->compose, (int) (w->cursor->xcol - w->offset + w->x));			} */			if (dosquare)				if (w->top->line + y - w->y >= fromline && w->top->line + y - w->y <= toline)					t->updtab[y] = lgen(t, y, screen, attr, w->x, w->x + w->w, p, w->offset, from, to, get_highlight_state(w,p,w->top->line+y-w->y),w);				else					t->updtab[y] = lgen(t, y, screen, attr, w->x, w->x + w->w, p, w->offset, 0L, 0L, get_highlight_state(w,p,w->top->line+y-w->y),w);			else				t->updtab[y] = lgen(t, y, screen, attr, w->x, w->x + w->w, p, w->offset, from, to, get_highlight_state(w,p,w->top->line+y-w->y),w);		}	}	y = w->y;	attr = t->attr + w->y * w->t->w;	for (screen = t->scrn + w->y * w->t->w; y != w->y + w->cursor->line - w->top->line; ++y, (screen += w->t->w), (attr += w->t->w)) {		if (ifhave && !linums)			break;		if (linums)			gennum(w, screen, attr, t, y, t->compose);		if (t->updtab[y]) {			p = getto(p, w->cursor, w->top, w->top->line + y - w->y);/*			if (t->insdel && !w->x) {				pset(q, p);				if (dosquare)					if (w->top->line + y - w->y >= fromline && w->top->line + y - w->y <= toline)						lgena(t, y, t->compose, w->x, w->x + w->w, q, w->offset, from, to);					else						lgena(t, y, t->compose, w->x, w->x + w->w, q, w->offset, 0L, 0L);				else					lgena(t, y, t->compose, w->x, w->x + w->w, q, w->offset, from, to);				magic(t, y, screen, attr, t->compose, (int) (w->cursor->xcol - w->offset + w->x));			} */			if (dosquare)				if (w->top->line + y - w->y >= fromline && w->top->line + y - w->y <= toline)					t->updtab[y] = lgen(t, y, screen, attr, w->x, w->x + w->w, p, w->offset, from, to, get_highlight_state(w,p,w->top->line+y-w->y),w);				else					t->updtab[y] = lgen(t, y, screen, attr, w->x, w->x + w->w, p, w->offset, 0L, 0L, get_highlight_state(w,p,w->top->line+y-w->y),w);			else				t->updtab[y] = lgen(t, y, screen, attr, w->x, w->x + w->w, p, w->offset, from, to, get_highlight_state(w,p,w->top->line+y-w->y),w);		}	}	prm(q);	if (p)		prm(p);}void bwmove(BW *w, int x, int y){	w->x = x;	w->y = y;}void bwresz(BW *w, int wi, int he){	if (he > w->h && w->y != -1) {		msetI(w->t->t->updtab + w->y + w->h, 1, he - w->h);	}	w->w = wi;	w->h = he;}BW *bwmk(W *window, B *b, int prompt){	BW *w = (BW *) joe_malloc(sizeof(BW));	w->parent = window;	w->b = b;	if (prompt || (!window->y && staen)) {		w->y = window->y;		w->h = window->h;	} else {		w->y = window->y + 1;		w->h = window->h - 1;	}	if (b->oldcur) {		w->top = b->oldtop;		b->oldtop = NULL;		w->top->owner = NULL;		w->cursor = b->oldcur;		b->oldcur = NULL;		w->cursor->owner = NULL;	} else {		w->top = pdup(b->bof, USTR "bwmk");		w->cursor = pdup(b->bof, USTR "bwmk");	}	w->t = window->t;	w->object = NULL;	w->offset = 0;	w->o = w->b->o;	if (w->o.linums) {		w->x = window->x + LINCOLS;		w->w = window->w - LINCOLS;	} else {		w->x = window->x;		w->w = window->w;	}	if (window == window->main) {		rmkbd(window->kbd);		window->kbd = mkkbd(kmap_getcontext(w->o.context));	}	w->top->xcol = 0;	w->cursor->xcol = 0;	w->linums = 0;	w->top_changed = 1;	w->linums = 0;	w->db = 0;	return w;}/* Database of last file positions */#define MAX_FILE_POS 20 /* Maximum number of file positions we track */static struct file_pos {	LINK(struct file_pos) link;	unsigned char *name;	long line;} file_pos = { { &file_pos, &file_pos } };static int file_pos_count;struct file_pos *find_file_pos(unsigned char *name){	struct file_pos *p;	for (p = file_pos.link.next; p != &file_pos; p = p->link.next)		if (!zcmp(p->name, name)) {			promote(struct file_pos,link,&file_pos,p);			return p;		}	p = (struct file_pos *)malloc(sizeof(struct file_pos));	p->name = zdup(name);	p->line = 0;	enquef(struct file_pos,link,&file_pos,p);	if (++file_pos_count == MAX_FILE_POS) {		free(deque_f(struct file_pos,link,file_pos.link.prev));		--file_pos_count;	}	return p;}int restore_file_pos;long get_file_pos(unsigned char *name){	if (name && restore_file_pos) {		struct file_pos *p = find_file_pos(name);		return p->line;	} else {		return 0;	}}void set_file_pos(unsigned char *name, long pos){	if (name) {		struct file_pos *p = find_file_pos(name);		p->line = pos;	}}void save_file_pos(FILE *f){	struct file_pos *p;	for (p = file_pos.link.prev; p != &file_pos; p = p->link.prev) {		fprintf(f,"	%ld ",p->line);		emit_string(f,p->name,zlen(p->name));		fprintf(f,"\n");	}	fprintf(f,"done\n");}void load_file_pos(FILE *f){	unsigned char buf[1024];	while (fgets((char *)buf,sizeof(buf)-1,f) && zcmp(buf,USTR "done\n")) {		unsigned char *p = buf;		long pos;		unsigned char name[1024];		parse_ws(&p,'#');		if (!parse_long(&p, &pos)) {			parse_ws(&p, '#');			if (parse_string(&p, name, sizeof(name)) > 0) {				set_file_pos(name, pos);			}		}	}}/* Save file position for all windows */void set_file_pos_all(Screen *t){	/* Step through all windows */	W *w = t->topwin;	do {		if (w->watom == &watomtw) {			BW *bw = w->object;			set_file_pos(bw->b->name, bw->cursor->line);		}		w = w->link.next;	} while(w != t->topwin);	/* Set through orphaned buffers */	set_file_pos_orphaned();}void bwrm(BW *w){	if (w->b == errbuf && w->b->count == 1) {		/* Do not lose message buffer */		orphit(w);	}	set_file_pos(w->b->name,w->cursor->line);	prm(w->top);	prm(w->cursor);	brm(w->b);	joe_free(w);}int ustat(BW *bw){	static unsigned char buf[160];	unsigned char bf1[100];	unsigned char bf2[100];	int c = brch(bw->cursor);#if SIZEOF_LONG_LONG && SIZEOF_LONG_LONG == SIZEOF_OFF_T		joe_snprintf_1(bf1, sizeof(bf1), "%lld", bw->cursor->byte);		joe_snprintf_1(bf2, sizeof(bf2), "%llx", bw->cursor->byte);#else		joe_snprintf_1(bf1, sizeof(bf1), "%ld", bw->cursor->byte);		joe_snprintf_1(bf2, sizeof(bf2), "%lx", bw->cursor->byte);#endif	if (c == NO_MORE_DATA)		joe_snprintf_4(buf, sizeof(buf), joe_gettext(_("** Line %ld  Col %ld  Offset %s(0x%s) **")), bw->cursor->line + 1, piscol(bw->cursor) + 1, bf1, bf2);	else		joe_snprintf_9(buf, sizeof(buf), joe_gettext(_("** Line %ld  Col %ld  Offset %s(0x%s)  %s %d(0%o/0x%X) Width %d **")), bw->cursor->line + 1, piscol(bw->cursor) + 1, bf1, bf2, bw->b->o.charmap->name, c, c, c, joe_wcwidth(bw->o.charmap->type,c));	msgnw(bw->parent, buf);	return 0;}int ucrawlr(BW *bw){	int amnt = bw->w / 2;	pcol(bw->cursor, bw->cursor->xcol + amnt);	bw->cursor->xcol += amnt;	bw->offset += amnt;	updall();	return 0;}int ucrawll(BW *bw){	int amnt = bw->w / 2;	int curamnt = bw->w / 2;	if (amnt > bw->offset) {		amnt = bw->offset;		curamnt = bw->offset;	}	if (!bw->offset)		curamnt = bw->cursor->xcol;	if (!curamnt)		return -1;	pcol(bw->cursor, bw->cursor->xcol - curamnt);	bw->cursor->xcol -= curamnt;	bw->offset -= amnt;	updall();	return 0;}/* If we are about to call bwrm, and b->count is 1, and orphan mode * is set, call this. */void orphit(BW *bw){	++bw->b->count; /* Assumes bwrm() is abour to be called */	bw->b->orphan = 1;	pdupown(bw->cursor, &bw->b->oldcur, USTR "orphit");	pdupown(bw->top, &bw->b->oldtop, USTR "orphit");}

⌨️ 快捷键说明

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