# 2.11BSD#431 - /usr/src/ucb/ex/ex_tagio.c

##### Functions

    tclose            X
    tgets             X
    topen             X
    tseek             X

       1: /* Copyright (c) 1985 Regents of the University of California */
       2:
       3: /*
       4:  * These routines are for faster tag lookup.  They support the binary
       5:  * search used in tagfind() instead of the linear search.  The speedup
       6:  * is quite noticable looking for a tag at the end of a long tags
       7:  * file.  Define FASTTAG in the Makefile to use these routines.
       8:  */
       9:
      10: #ifdef FASTTAG
      11: #if !defined(lint) && defined(DOSCCS)
      12: static char *sccsid = "@(#)ex_tagio.c	7.3 (Berkeley) 1/31/86";
      13: #endif
      14:
      15: #include <sys/file.h>
      16: #include "ex.h"
      17:
      18: static long offset = -1;
      19: static long block = -1;
      20: static int bcnt = 0;
      21: static int b_size = MAXBSIZE;
      22: static char *ibuf;
      23:
      24: topen(file, buf)
      25: char *file, *buf;
      26: {
      27:     int fd;
      28:     struct stat statb;
      29:
      30:     offset = -1;
      31:     block = -1;
      32:     if ((fd = open(file, O_RDONLY, 0)) < 0)
      33:         return(-1);
      34:     if (fstat(fd, &statb) < 0) {
      35:         (void)close(fd);
      36:         return(-1);
      37:     }
      38:     ibuf = buf;
      39:     b_size = statb.st_blksize;
      40:     return(fd);
      41: }
      42:
      43: tseek(fd, off)
      44: int fd;
      45: long off;
      46: {
      47:     long nblock;
      48:
      49:     nblock = off / b_size * b_size;
      50:     offset = off % b_size;
      51:     if (nblock == block)
      52:         return(0);
      53:     block = nblock;
      54:     if (lseek(fd, nblock, L_SET) < 0)
      55:         return(-1);
      56:     if ((bcnt = read(fd, ibuf, b_size)) < 0)
      57:         return(-1);
      58:     return(0);
      59: }
      60:
      61: tgets(buf, cnt, fd)
      62: register char *buf;
      63: int cnt;
      64: int fd;
      65: {
      66:     register char *cp;
      67:     register cc;
      68:
      69:     cc = offset;
      70:     if (cc == -1) {
      71:         if ((bcnt = read(fd, ibuf, b_size)) <= 0)
      72:             return (NULL);
      73:         cc = 0;
      74:         block = 0;
      75:     }
      76:     if (bcnt == 0)      /* EOF */
      77:         return(NULL);
      78:     cp = ibuf + cc;
      79:     while (--cnt > 0) {
      80:         if (++cc > bcnt) {
      81:             block += b_size;
      82:             if ((bcnt = read(fd, ibuf, b_size)) <= 0) {
      83:                 offset = cc;
      84:                 return (NULL);
      85:             }
      86:             cp = ibuf;
      87:             cc = 1;
      88:         }
      89:         if ((*buf++ = *cp++) == '\n')
      90:             break;
      91:     }
      92:     *--buf = NULL;
      93:     offset = cc;
      94:     return(1);
      95: }
      96:
      97: tclose(fd)
      98: int fd;
      99: {
     100:     (void)close(fd);
     101:     offset = -1;
     102:     block = -1;
     103:     bcnt = 0;
     104: }
     105: #endif

#### Defined functions

tclose defined in line 97; used 2 times

- in /usr/src/ucb/ex/ex_cmdsub.c line 589, 671

tgets defined in line 61; used 2 times

- in /usr/src/ucb/ex/ex_cmdsub.c line 561-564(2)

topen defined in line 24; used 1 times

- in /usr/src/ucb/ex/ex_cmdsub.c line 524

tseek defined in line 43; used 1 times

- in /usr/src/ucb/ex/ex_cmdsub.c line 558

#### Defined variables

b_size defined in line 21; used 8 times

- in line 39, 49-50(3), 56, 71, 81-82(2)

bcnt defined in line 20; used 6 times

- in line 56, 71-82(4), 103

block defined in line 19; used 6 times

- in line 31, 51-53(2), 74, 81, 102

ibuf defined in line 22; used 6 times

- in line 38, 56, 71, 78-86(3)

offset defined in line 18; used 6 times

- in line 30, 50, 69, 83, 93, 101

sccsid defined in line 12; never used

Last modified: 1991-09-08 Generated: 2016-12-26 | Generated by src2html V0.67 page hit count: 1372 |