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

📄 ufile.c

📁 举世闻名的joe记事本源程序
💻 C
📖 第 1 页 / 共 2 页
字号:
		}		/* Restore cursor line */		pline(bw->cursor, get_file_pos(bw->b->name));		omid = mid;		mid = 1;		dofollows();		mid = omid;				return ret;	} else if (c == NO_CODE || yncheck(no_key, c)) {		/* Edit already loaded buffer */		if (notify) {			*notify = 1;		}		b = bfind(s);		er = berror;		if (bw->b->count == 1 && (bw->b->changed || bw->b->name)) {			if (orphan) {				orphit(bw);			} else {				if (uduptw(bw)) {					brm(b);					return -1;				}				bw = (BW *) maint->curwin->object;			}		}		if (er) {			msgnwt(bw->parent, joe_gettext(msgs[-er]));			if (er != -1) {				ret = -1;			}		}		object = bw->object;		w = bw->parent;		bwrm(bw);		w->object = (void *) (bw = bwmk(w, b, 0));		wredraw(bw->parent);		bw->object = object;		vsrm(s);		if (er == -1 && bw->o.mnew) {			exmacro(bw->o.mnew,1);		}		if (er == 0 && bw->o.mold) {			exmacro(bw->o.mold,1);		}		/* Restore cursor line */		pline(bw->cursor, get_file_pos(bw->b->name));		omid = mid;		mid = 1;		dofollows();		mid = omid;		return ret;	} else {		/* FIXME: need abort handler to prevent leak */		if (mkqw(bw->parent, sz(joe_gettext(_("Load original file from disk (y,n,^C)? "))), doedit1, NULL, s, notify))			return 0;		else {			vsrm(s);			return -1;		}	}}int doedit(BW *bw, unsigned char *s, void *obj, int *notify){	B *b;	b = bcheck_loaded(s);	if (b) {		if (b->changed && !b->scratch)			/* Modified buffer exists, so ask */			return doedit1(bw, 0, s, notify);		else			/* Buffer not modified- just use it as is */			return doedit1(bw, NO_CODE, s, notify);	} else		/* File not in buffer: don't ask */		return doedit1(bw, YES_CODE, s, notify);}int okrepl(BW *bw){	if (bw->b->count == 1 && bw->b->changed) {		msgnw(bw->parent, joe_gettext(_("Can't replace modified file")));		return -1;	} else {		return 0;	}}int uedit(BW *bw){	if (wmkpw(bw->parent, joe_gettext(_("Name of file to edit (^C to abort): ")), &filehist, doedit, USTR "Names", NULL, cmplt, NULL, NULL, locale_map,7)) {		return 0;	} else {		return -1;	}}int doswitch(BW *bw, unsigned char *s, void *obj, int *notify){	/* Try buffer, then file */	return doedit1(bw, NO_CODE, s, notify);}int uswitch(BW *bw){	if (wmkpw(bw->parent, joe_gettext(_("Name of buffer to edit (^C to abort): ")), &filehist, doswitch, USTR "Names", NULL, cmplt, NULL, NULL, locale_map,1)) {		return 0;	} else {		return -1;	}}int doscratch(BW *bw, unsigned char *s, void *obj, int *notify){	int ret = 0;	int er;	void *object;	W *w;	B *b;	if (notify) {		*notify = 1;	}	b = bfind_scratch(s);	er = berror;	if (bw->b->count == 1 && (bw->b->changed || bw->b->name)) {		if (orphan) {			orphit(bw);		} else {			if (uduptw(bw)) {				brm(b);				return -1;			}			bw = (BW *) maint->curwin->object;		}	}	if (er) {		msgnwt(bw->parent, joe_gettext(msgs[-er]));		if (er != -1) {			ret = -1;		}	}	object = bw->object;	w = bw->parent;	bwrm(bw);	w->object = (void *) (bw = bwmk(w, b, 0));	wredraw(bw->parent);	bw->object = object;	vsrm(s);	if (er == -1 && bw->o.mnew) {		exmacro(bw->o.mnew,1);	}	if (er == 0 && bw->o.mold) {		exmacro(bw->o.mold,1);	}	return ret;}int uscratch(BW *bw){	if (wmkpw(bw->parent, joe_gettext(_("Name of scratch buffer to edit (^C to abort): ")), &filehist, doscratch, USTR "Names", NULL, cmplt, NULL, NULL, locale_map, 1)) {		return 0;	} else {		return -1;	}}/* Load file into buffer: can result in an orphaned buffer */static int dorepl(BW *bw, unsigned char *s, void *obj, int *notify){	void *object = bw->object;	int omid;	int ret = 0;	int er;	W *w = bw->parent;	B *b;	if (notify) {		*notify = 1;	}	b = bfind(s);	er = berror;	if (berror) {		msgnwt(bw->parent, joe_gettext(msgs[-berror]));		if (berror != -1) {			ret = -1;		}	}	if (bw->b->count == 1 && (bw->b->changed || bw->b->name)) {		orphit(bw);	}	bwrm(bw);	w->object = (void *) (bw = bwmk(w, b, 0));	wredraw(bw->parent);	bw->object = object;	vsrm(s);	if (er == -1 && bw->o.mnew) {		exmacro(bw->o.mnew,1);	}	if (er == 0 && bw->o.mold) {		exmacro(bw->o.mold,1);	}	/* Restore cursor line */	pline(bw->cursor, get_file_pos(bw->b->name));	omid = mid;	mid = 1;	dofollows();	mid = omid;	return ret;}/* Switch to a particular buffer */int get_buffer_in_window(BW *bw, B *b){	void *object = bw->object;	W *w = bw->parent;	if (b == bw->b) {		return 0;		/* return -1; this helps with querysave (no error when only one buffer) */	}	if (!b->orphan) {		++b->count;	} else {		b->orphan = 0;	}	if (bw->b->count == 1) {		orphit(bw);	}	bwrm(bw);	w->object = (void *) (bw = bwmk(w, b, 0));	wredraw(bw->parent);	bw->object = object;	return 0;}/* Switch to next buffer in window */int unbuf(BW *bw){	B *b;	b = bnext();	if (b == bw->b) {		b = bnext();	}	return get_buffer_in_window(bw,b);}int upbuf(BW *bw){	B *b;	b = bprev();	if (b == bw->b) {		b = bprev();	}	return get_buffer_in_window(bw, b);}int uinsf(BW *bw){	if (wmkpw(bw->parent, joe_gettext(_("Name of file to insert (^C to abort): ")), &filehist, doinsf, USTR "Names", NULL, cmplt, NULL, NULL, locale_map, 3)) {		return 0;	} else {		return -1;	}}/* Save and exit */static int exdone(BW *bw, struct savereq *req,int flg,int *notify){	if (notify)		*notify = 1;	rmsavereq(req);	if (flg) {		return -1;	} else {		bw_unlock(bw);		bw->b->changed = 0;		saverr(bw->b->name);		return uabort1(bw, -1);	}}int uexsve(BW *bw){	if (!bw->b->changed || bw->b->scratch) {		/* It didn't change or it's just a scratch buffer: don't save */		uabort(bw, -1);		return 0;	} else if (bw->b->name && !exask) {		/* It changed, it's not a scratch buffer and it's named */		return dosave1(bw, vsncpy(NULL, 0, sz(bw->b->name)), mksavereq(exdone,NULL,NULL,0,0), NULL);	} else {		BW *pbw = wmkpw(bw->parent, joe_gettext(_("Name of file to save (^C to abort): ")), &filehist,		                dosave1, USTR "Names", NULL, cmplt,		                mksavereq(exdone,NULL,NULL,1,0), NULL, locale_map, 1);		if (pbw && bw->b->name) {			binss(pbw->cursor, bw->b->name);			pset(pbw->cursor, pbw->b->eof);			pbw->cursor->xcol = piscol(pbw->cursor);		}		if (pbw) {			return 0;		} else {			return -1;		}	}}/* If buffer is modified, prompt for saving: if user types 'n', uabort(), otherwise just return. *//* If buffer is not modified, just return. */static int nask(BW *bw, int c, void *object, int *notify){	if (c == YES_CODE || yncheck(yes_key, c)) {		/* uexsve macro should be here... */		if(notify)			*notify = 1;		return 0;	} else if (c == NO_CODE || yncheck(no_key, c)) {		if(notify)			*notify = -1;		genexmsg(bw, 0, NULL);		abortit(bw);		return -1;	} else if (bw->b->count == 1 && bw->b->changed && !bw->b->scratch) {		if (mkqw(bw->parent, sz(joe_gettext(_("Save changes to this file (y,n,^C)? "))), nask, NULL, object, notify)) {			return 0;		} else {			return -1;		}	} else {		if (notify) {			*notify = 1;		}		return 0;	}}int uask(BW *bw){	return nask(bw, 0, NULL, NULL);}/* Kill a buffer: any windows which have it get their buffer replaced with a * a scratch buffer */static int dolose(BW *bw, int c, void *object, int *notify){	W *w;	B *b, *new_b;	int cnt;	if (notify) {		*notify = 1;	}	if (c != YES_CODE && !yncheck(yes_key, c)) {		return -1;	}	b=bw->b;	cnt = b->count;	b->count = 1;	genexmsg(bw, 0, NULL);	b->count = cnt;	if ((w = maint->topwin) != NULL) {		do {			if ((w->watom->what&TYPETW) && ((BW *)w->object)->b==b) {				if ((new_b = borphan()) != NULL) {					BW *bw = (BW *)w->object;					void *object = bw->object;					/* FIXME: Shouldn't we wabort() and wcreate here to kill					   any prompt windows? */					bwrm(bw);					w->object = (void *) (bw = bwmk(w, new_b, 0));					wredraw(w);					bw->object = object;				} else {					BW *bw = (BW *)w->object;					object = bw->object;					bwrm(bw);					w->object = (void *) (bw = bwmk(w, bfind(USTR ""), 0));					wredraw(w);					bw->object = object;					if (bw->o.mnew)						exmacro(bw->o.mnew,1);				}			}		w = w->link.next;		} while (w != maint->topwin);	}	return 0;}int ulose(BW *bw){	msgnw(bw->parent, NULL);	if (bw->b->count==1 && bw->b->pid) {		return ukillpid(bw);	}	if (bw->b->changed && !bw->b->scratch) {		if (mkqw(bw->parent, sz(joe_gettext(_("Lose changes to this file (y,n,^C)? "))), dolose, NULL, NULL, NULL)) {			return 0;		} else {			return -1;		}	} else {		return dolose(bw, YES_CODE, NULL, NULL);	}}/* Buffer list */#ifdef junkstatic int dobuf(MENU *m, int x, unsigned char **s){	unsigned char *name;	BW *bw = m->parent->win->object;	int *notify = m->parent->notify;	m->parent->notify = 0;	name = vsdup(s[x]);	wabort(m->parent);	return dorepl(bw, name, NULL, notify);}static int abrtb(MENU *m, int x, unsigned char **s){	varm(s);	return -1;}int ubufed(BW *bw){	unsigned char **s = getbufs();	vasort(av(s));	if (mkmenu(bw->parent, bw->parent, s, dobuf, abrtb, NULL, 0, s, NULL))		return 0;	else {		varm(s);		return -1;	}}#endifunsigned char **sbufs = NULL;	/* Array of command names */static int bufedcmplt(BW *bw){	if (sbufs) {		varm(sbufs);		sbufs = 0;	}	if (!sbufs)		sbufs = getbufs();	return simple_cmplt(bw,sbufs);}static int dobufed(BW *bw, unsigned char *s, void *object, int *notify){/* not understanding this...	int *notify = bw->parent->notify;	bw->parent->notify = 0;	wabort(bw->parent);*/	return dorepl(bw, s, NULL, notify);}B *bufhist = NULL;int ubufed(BW *bw){	if (wmkpw(bw->parent, joe_gettext(_("Name of buffer to edit (^C to abort): ")), &bufhist, dobufed, USTR "bufed", NULL, bufedcmplt, NULL, NULL, locale_map, 0)) {		return 0;	} else {		return -1;	}}/* Query save loop */static int doquerysave(BW *bw,int c,struct savereq *req,int *notify){	W *w = bw->parent;	if (c == YES_CODE || yncheck(yes_key, c)) {		if (bw->b->name && bw->b->name[0])			return dosave1(bw, vsncpy(NULL,0,sz(bw->b->name)), req, notify);		else {			BW *pbw;			pbw = wmkpw(bw->parent, joe_gettext(_("Name of file to save (^C to abort): ")), &filehist, dosave1, USTR "Names", NULL, cmplt, req, notify, locale_map, 7);			if (pbw) {				return 0;			} else {				joe_free(req);				return -1;			}		}	} else if (c == NO_CODE || yncheck(no_key, c)) {		/* Find next buffer to save */		if (bw->b->changed)			req->not_saved = 1;		next:		if (unbuf(bw)) {			if (notify)				*notify = 1;			rmsavereq(req);			return -1;		}		bw = w->object;		if (bw->b==req->first) {			if (notify)				*notify = 1;			rmsavereq(req);			genexmsgmulti(bw,1,req->not_saved);			return 0;		}		if (!bw->b->changed || bw->b->scratch)			goto next;		return doquerysave(bw,0,req,notify);	} else {		unsigned char buf[1024];		joe_snprintf_1(buf,1024,joe_gettext(_("File %s has been modified.  Save it (y,n,^C)? ")),bw->b->name ? bw->b->name : USTR "(Unnamed)" );		if (mkqw(bw->parent, sz(buf), doquerysave, NULL, req, notify)) {			return 0;			} else {			/* Should be in abort function */			rmsavereq(req);			return -1;		}	}}static int query_next(BW *bw, struct savereq *req,int flg,int *notify){	if (flg) {		if (notify)			*notify = 1;		rmsavereq(req);		return -1;	} else		return doquerysave(bw,NO_CODE,req,notify);}int uquerysave(BW *bw){	W *w = bw->parent;	B *first;	/* Get synchronized with buffer ring */	unbuf(bw);	bw = w->object;	first = bw->b;	/* Find a modified buffer */	do {		if (bw->b->changed && !bw->b->scratch)			return doquerysave(bw,0,mksavereq(query_next,NULL,first,0,0),NULL);		else if (unbuf(bw))			return -1;		bw = w->object;	} while(bw->b!=first);	genexmsgmulti(bw,0,0);	return 0;}int ukilljoe(BW *bw){	/* Save file positions */	set_file_pos_all(bw->parent->t);	/* FIXME: emacs checks for unsaved modified buffers at this point */	leave = 1;	return 0;}

⌨️ 快捷键说明

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