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

📄 rec.c

📁 早期freebsd实现
💻 C
字号:
/*************************************************************************** * This program is Copyright (C) 1986, 1987, 1988 by Jonathan Payne.  JOVE * * is provided to you without charge, and with no warranty.  You may give  * * away copies of JOVE, including sources, provided that this notice is    * * included in all the files.                                              * ***************************************************************************/#include "jove.h"#include "fp.h"#include "rec.h"#ifndef	MAC#	include <sys/file.h>#endifprivate int	rec_fd = -1;private char	*recfname;private File	*rec_out;#ifndef	L_SET#	define L_SET 0#endifprivate struct rec_head	Header;private voidrecinit(){	char	buf[128];#ifdef	MAC	swritef(buf, sizeof(buf), "%s/%s", HomeDir, p_tempfile);#else	swritef(buf, sizeof(buf), "%s/%s", TmpFilePath, p_tempfile);#endif	recfname = copystr(buf);	recfname = mktemp(recfname);	rec_fd = creat(recfname, 0644);	if (rec_fd == -1) {		complain("Cannot create \"%s\"; recovery disabled.", recfname);		return;	}	/* initialize the record IO */	rec_out = fd_open(recfname, F_WRITE|F_LOCKED, rec_fd, iobuff, LBSIZE);	/* Initialize the record header. */	Header.Uid = getuid();	Header.Pid = getpid();	Header.UpdTime = 0L;	Header.Nbuffers = 0;	(void) write(rec_fd, (UnivPtr) &Header, sizeof Header);}/* Close recfile before execing a child process. * Since we might be vforking, we must not change any variables * (in particular rec_fd). */voidrecclose(){	if (rec_fd == -1)		return;	(void) close(rec_fd);}/* Close and remove recfile before exiting. */voidrecremove(){	if (rec_fd == -1)		return;	recclose();	(void) unlink(recfname);}private voidputaddr(addr, p)daddr	addr;register File	*p;{	register char	*cp = (char *) &addr;	register int	nchars = sizeof (daddr);	while (--nchars >= 0)		jputc(*cp++ & 0377, p);}private voidputn(cp, nbytes)register char	*cp;register size_t	nbytes;{	while (nbytes-- > 0)		jputc(*cp++ & 0377, rec_out);}/* Write out the line pointers for buffer B. */private voiddmppntrs(b)register Buffer	*b;{	register Line	*lp;	for (lp = b->b_first; lp != NULL; lp = lp->l_next)		putaddr(lp->l_dline, rec_out);}/* dump the buffer info and then the actual line pointers. */private voiddmp_buf_header(b)register Buffer	*b;{	struct rec_entry	record;	register Line	*lp;	register int	nlines = 0;	for (lp = b->b_first; lp != NULL; lp = lp->l_next, nlines++)		if (lp == b->b_dot)			record.r_dotline = nlines;	strcpy(record.r_fname, b->b_fname ? b->b_fname : NullStr);	strcpy(record.r_bname, b->b_name);	record.r_nlines = nlines;	record.r_dotchar = b->b_char;	putn((char *) &record, sizeof record);}/* Goes through all the buffers and syncs them to the disk. */int	SyncFreq = 50;voidSyncRec(){	register Buffer	*b;	static bool	beenhere = NO;	if (!beenhere) {		beenhere = YES;		recinit();	/* Init recover file. */	}	if (rec_fd == -1)		return;	lseek(rec_fd, 0L, L_SET);	(void) time(&Header.UpdTime);	Header.Nbuffers = 0;	for (b = world; b != NULL; b = b->b_next)		if (b->b_type == B_SCRATCH || !IsModified(b))			continue;		else			Header.Nbuffers += 1;	Header.FreePtr = DFree;	putn((char *) &Header, sizeof Header);	if (Header.Nbuffers != 0) {		lsave();	/* this makes things really right */		SyncTmp();		for (b = world; b != NULL; b = b->b_next)			if (b->b_type == B_SCRATCH || !IsModified(b))				continue;			else				dmp_buf_header(b);		for (b = world; b != NULL; b = b->b_next)			if (b->b_type == B_SCRATCH || !IsModified(b))				continue;			else				dmppntrs(b);	}	flushout(rec_out);}/* Full Recover.  What we have to do is go find the name of the tmp   file data/rec pair and use those instead of the ones we would have   created eventually.  The rec file has a list of buffers, and then   the actual pointers.  Stored for each buffer is the buffer name,   the file name, the number of lines, the current line, the current   character.  The current modes do not need saving as they will be   saved when the file name is set.  If a process was running in a   buffer, it will be lost. */voidFullRecover(){}

⌨️ 快捷键说明

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