1: #include "parms.h"
   2: #include "structs.h"
   3: 
   4: #ifdef  RCSIDENT
   5: static char rcsid[] = "$Header: pagein.c,v 1.7 85/01/18 15:33:36 notes Rel $";
   6: #endif	RCSIDENT
   7: 
   8: /*
   9:  *	pagein(zfile, where)
  10:  *	FILE *zfile; struct daddr_f *where;
  11:  *
  12:  *	reads in a single 'page' as defined by the notesfile system and
  13:  *	returns the count of characters moved.
  14:  *
  15:  *	Original Coding:	Ray Essick	Long agao
  16:  *		moved out of gtext.c and mult.c and others   4/5/82
  17:  *	Converted for infinite size notes	RBE 5/8/82
  18:  *
  19:  */
  20: 
  21: long    pagein (io, zfile, where)
  22: struct io_f *io;
  23: FILE * zfile;
  24: struct daddr_f *where;
  25: {
  26: 
  27:     register int    c;
  28:     register int    i;
  29:     register long   nchars;
  30:     register long   ignored;                /* number ignored */
  31:     register int    ignoring;               /* whether ignoring */
  32:     struct daddr_f  nwhere;
  33:     struct txtbuf_f buf;                /* hold text */
  34: 
  35:     locknf (io, TXTLOCK);               /* CRITICAL */
  36:     x (lseek (io -> fidtxt, 0L, 0) < 0, "pagein: bad seek 0");
  37:     x (read (io -> fidtxt, where, sizeof *where) < 0, "pagein: read 0");
  38:     x (lseek (io -> fidtxt, where -> addr, 0) < 0,
  39:         "pagein: bad seek 1");
  40: 
  41:     where -> textlen = 0;               /* no text yet */
  42:     nchars = 0;
  43:     i = 0;
  44:     ignoring = 0;                   /* save em for now */
  45:     ignored = 0;
  46:     while ((c = getc (zfile)) != EOF)           /* grab input */
  47:     {
  48:     if (!ignoring)
  49:     {
  50:         if (i == BUFSIZE)               /* flush full buffer */
  51:         {
  52:         x (write (io -> fidtxt, buf.txtbuf, BUFSIZE) != BUFSIZE, "pagein: bad text");
  53:         i = 0;                  /* reset buffer */
  54:         }
  55:         buf.txtbuf[i++] = c;
  56:         if (++nchars >= io -> descr.d_longnote) /* count characters */
  57:         {
  58:         ignoring++;             /* don't add any more */
  59:         }
  60:     }
  61:     else                        /* ignoring */
  62:     {
  63:         ignored++;
  64:     }
  65:     }
  66:     if (i != 0)                     /* if we've got some */
  67:     x (write (io -> fidtxt, buf.txtbuf, i) != i, "pagein: bad text");
  68:     if (ignored)                    /* write warning */
  69:     {
  70:     sprintf (buf.txtbuf, "\n\n%s ignored %ld excess bytes\n",
  71:         System, ignored);
  72:     i = strlen (buf.txtbuf);            /* get length */
  73:     x (write (io -> fidtxt, buf.txtbuf, i) != i, "pagein: bad text");
  74:     nchars += i;                    /* count extras */
  75:     }
  76: /*
  77:  *	fix count in the header
  78:  */
  79:     where -> textlen = nchars;              /* fill header */
  80: /*
  81:  *	fix free pointer
  82:  */
  83:     x (lseek (io -> fidtxt, 0l, 0) < 0, "pagein:bad reseek");
  84:     nwhere.addr = where -> addr + nchars;
  85:     if (nwhere.addr & 1)                /* odd?? */
  86:     nwhere.addr++;                  /* round to word boundary */
  87:     x (write (io -> fidtxt, &nwhere, sizeof nwhere) != sizeof nwhere, "pagein: badupdate");
  88: 
  89:     unlocknf (io, TXTLOCK);
  90:     return ((long) nchars);
  91: }
Last modified: 1985-01-19
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 2381
Valid CSS Valid XHTML 1.0 Strict