示例#1
0
文件: buffer.c 项目: WizardGed/mg
/*
 * Ensures a buffer has not been modified elsewhere; e.g. on disk.
 * Prompt the user if it has.
 * Returns TRUE if it has NOT (i.e. buffer is ok to edit).
 * FALSE or ABORT otherwise
 */
int
checkdirty(struct buffer *bp)
{
	int s;

	if ((bp->b_flag & (BFCHG | BFDIRTY)) == 0)
		if (fchecktime(bp) != TRUE)
			bp->b_flag |= BFDIRTY;

	if ((bp->b_flag & (BFDIRTY | BFIGNDIRTY)) == BFDIRTY) {
		s = eynorr("File changed on disk; really edit the buffer");
		switch (s) {
		case TRUE:
			bp->b_flag &= ~BFDIRTY;
			bp->b_flag |= BFIGNDIRTY;
			return (TRUE);
		case REVERT:
			dorevert();
			return (FALSE);
		default:
			return (s);
		}
	}

	return (TRUE);
}
示例#2
0
文件: buffer.c 项目: WizardGed/mg
/*
 * Display the given buffer in the given window. Flags indicated
 * action on redisplay. Update modified flag so insert loop can check it.
 */
int
showbuffer(struct buffer *bp, struct mgwin *wp, int flags)
{
	struct buffer	*obp;
	struct mgwin	*owp;

	/* Ensure file has not been modified elsewhere */
	if (fchecktime(bp) != TRUE)
		bp->b_flag |= BFDIRTY;

	if (wp->w_bufp == bp) {	/* Easy case! */
		wp->w_rflag |= flags;
		return (TRUE);
	}
	/* First, detach the old buffer from the window */
	if ((bp->b_altb = obp = wp->w_bufp) != NULL) {
		if (--obp->b_nwnd == 0) {
			obp->b_dotp = wp->w_dotp;
			obp->b_doto = wp->w_doto;
			obp->b_markp = wp->w_markp;
			obp->b_marko = wp->w_marko;
			obp->b_dotline = wp->w_dotline;
			obp->b_markline = wp->w_markline;
		}
	}
	/* Now, attach the new buffer to the window */
	wp->w_bufp = bp;

	if (bp->b_nwnd++ == 0) {	/* First use.		 */
		wp->w_dotp = bp->b_dotp;
		wp->w_doto = bp->b_doto;
		wp->w_markp = bp->b_markp;
		wp->w_marko = bp->b_marko;
		wp->w_dotline = bp->b_dotline;
		wp->w_markline = bp->b_markline;
	} else
		/* already on screen, steal values from other window */
		for (owp = wheadp; owp != NULL; owp = wp->w_wndp)
			if (wp->w_bufp == bp && owp != wp) {
				wp->w_dotp = owp->w_dotp;
				wp->w_doto = owp->w_doto;
				wp->w_markp = owp->w_markp;
				wp->w_marko = owp->w_marko;
				wp->w_dotline = owp->w_dotline;
				wp->w_markline = owp->w_markline;
				break;
			}
	wp->w_rflag |= WFMODE | flags;
	return (TRUE);
}
示例#3
0
文件: file.c 项目: Scarletts/LiteBSD
/*
 * Save the contents of the buffer argument into its associated file.  Do
 * nothing if there have been no changes (is this a bug, or a feature?).
 * Error if there is no remembered file name. If this is the first write
 * since the read or visit, then a backup copy of the file is made.
 * Allow user to select whether or not to make backup files by looking at
 * the value of makebackup.
 */
int
buffsave(struct buffer *bp)
{
	int	 s;
        FILE    *ffp;

	/* return, no changes */
	if ((bp->b_flag & BFCHG) == 0) {
		ewprintf("(No changes need to be saved)");
		return (TRUE);
	}

	/* must have a name */
	if (bp->b_fname[0] == '\0') {
		dobeep();
		ewprintf("No file name");
		return (FALSE);
	}

	/* Ensure file has not been modified elsewhere */
	/* We don't use the ignore flag here */
	if (fchecktime(bp) != TRUE) {
		if ((s = eyesno("File has changed on disk since last save. "
		    "Save anyway")) != TRUE)
			return (s);
	}
	if (makebackup && (bp->b_flag & BFBAK)) {
		s = fbackupfile(bp->b_fname);
		/* hard error */
		if (s == ABORT)
			return (FALSE);
		/* softer error */
		if (s == FALSE &&
		    (s = eyesno("Backup error, save anyway")) != TRUE)
			return (s);
	}
	if ((s = writeout(&ffp, bp, bp->b_fname)) == TRUE) {
		(void)fupdstat(bp);
		bp->b_flag &= ~(BFCHG | BFBAK);
		upmodes(bp);
		undo_add_boundary(FFRAND, 1);
		undo_add_modified();
	}
	return (s);
}
示例#4
0
/*
 * Re-initialize the terminal when the editor is resumed.
 * The keypad_xmit doesn't really belong here but...
 */
void
ttreinit(void)
{
	/* check if file was modified while we were gone */
	if (fchecktime(curbp) != TRUE) {
		curbp->b_flag |= BFDIRTY;
	}

	if (enter_ca_mode)
		/* enter application mode */
		putpad(enter_ca_mode, 1);

	if (keypad_xmit)
		/* turn on keypad */
		putpad(keypad_xmit, 1);

	ttresize();
}