1: /*************************************************************************
   2:  * This program is copyright (C) 1985, 1986 by Jonathan Payne.  It is    *
   3:  * provided to you without charge for use only on a licensed Unix        *
   4:  * system.  You may copy JOVE provided that this notice is included with *
   5:  * the copy.  You may not sell copies of this program or versions        *
   6:  * modified for use on microcomputer systems, unless the copies are      *
   7:  * included with a Unix system distribution and the source is provided.  *
   8:  *************************************************************************/
   9: 
  10: #include "jove.h"
  11: #include "io.h"
  12: #include "temp.h"
  13: #include "rec.h"
  14: #include <sys/file.h>
  15: 
  16: static int  rec_fd = 0; /* File descriptor of recover file. */
  17: static char *recfname;
  18: static File *rec_out;
  19: 
  20: #ifndef L_SET
  21: #	define L_SET 0
  22: #endif
  23: 
  24: struct rec_head Header;
  25: 
  26: recinit()
  27: {
  28:     recfname = mktemp(RECFILE);
  29:     rec_fd = creat(recfname, 0644);
  30:     if (rec_fd == -1) {
  31:         f_mess("Cannot open \"%s\"; recovery disabled.", recfname);
  32:         (void) SitFor(7);
  33:         return;
  34:     }
  35:     /* Initialize the record IO. */
  36:     rec_out = fd_open(recfname, F_WRITE|F_LOCK, rec_fd, iobuff, LBSIZE);
  37: 
  38:     /* Initialize the record header. */
  39:     Header.Uid = getuid();
  40:     Header.Pid = getpid();
  41:     Header.UpdTime = 0L;
  42:     Header.Nbuffers = 0;
  43:     (void) write(rec_fd, (char *) &Header, sizeof Header);
  44: }
  45: 
  46: recclose()
  47: {
  48:     if (rec_fd == -1)
  49:         return;
  50:     (void) close(rec_fd);
  51:     (void) unlink(recfname);
  52: }
  53: 
  54: static
  55: putaddr(addr, p)
  56: disk_line   addr;
  57: register File   *p;
  58: {
  59:     register char   *cp = (char *) &addr;
  60:     register int    nchars = sizeof (disk_line);
  61: 
  62:     while (--nchars >= 0)
  63:         putc(*cp++ & 0377, p);
  64: }
  65: 
  66: static
  67: putn(cp, nbytes)
  68: register char   *cp;
  69: register int    nbytes;
  70: {
  71:     while (--nbytes >= 0)
  72:         putc(*cp++ & 0377, rec_out);
  73: }
  74: 
  75: /* Write out the line pointers for buffer B. */
  76: 
  77: static
  78: dmppntrs(b)
  79: register Buffer *b;
  80: {
  81:     register Line   *lp;
  82: 
  83:     for (lp = b->b_first; lp != 0; lp = lp->l_next)
  84:         putaddr(lp->l_dline, rec_out);
  85: }
  86: 
  87: /* dump the buffer info and then the actual line pointers. */
  88: 
  89: static
  90: dmp_buf(b)
  91: register Buffer *b;
  92: {
  93:     static struct rec_entry record;
  94:     register Line   *lp;
  95:     register int    nlines = 0;
  96: 
  97:     for (lp = b->b_first; lp != 0; lp = lp->l_next, nlines++)
  98:         ;
  99:     strcpy(record.r_fname, b->b_fname ? b->b_fname : NullStr);
 100:     strcpy(record.r_bname, b->b_name);
 101:     record.r_nlines = nlines;
 102:     putn((char *) &record, sizeof record);
 103:     dmppntrs(b);
 104: }
 105: 
 106: /* Goes through all the buffers and syncs them to the disk. */
 107: 
 108: int SyncFreq = 50;
 109: 
 110: SyncRec()
 111: {
 112:     register Buffer *b;
 113: 
 114:     if (rec_fd == 0)
 115:         recinit();  /* Init recover file. */
 116:     if (rec_fd == -1)
 117:         return;
 118:     lseek(rec_fd, 0L, L_SET);
 119:     (void) time(&Header.UpdTime);
 120:     Header.Nbuffers = 0;
 121:     for (b = world; b != 0; b = b->b_next)
 122:         if (b->b_type == B_SCRATCH || !IsModified(b))
 123:             continue;
 124:         else
 125:             Header.Nbuffers++;
 126:     putn((char *) &Header, sizeof Header);
 127:     if (Header.Nbuffers != 0) {
 128:         SyncTmp();
 129:         for (b = world; b != 0; b = b->b_next)
 130:             if (b->b_type == B_SCRATCH || !IsModified(b))
 131:                 continue;
 132:             else
 133:                 dmp_buf(b);
 134:     }
 135:     flush(rec_out);
 136: }

Defined functions

SyncRec defined in line 110; used 2 times
dmp_buf defined in line 89; used 1 times
dmppntrs defined in line 77; used 1 times
putaddr defined in line 54; used 1 times
  • in line 84
putn defined in line 66; used 2 times
recclose defined in line 46; used 1 times
recinit defined in line 26; used 1 times

Defined variables

Header defined in line 24; used 12 times
SyncFreq defined in line 108; used 1 times
rec_fd defined in line 16; used 9 times
recfname defined in line 17; used 5 times

Defined macros

L_SET defined in line 21; used 2 times
Last modified: 1986-03-28
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1248
Valid CSS Valid XHTML 1.0 Strict