home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume25 / trn / part02 / backpage.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-12-02  |  2.6 KB  |  123 lines

  1. /* $Id: backpage.c,v 4.4 1991/09/09 20:18:23 sob Exp sob $
  2.  *
  3.  * $Log: backpage.c,v $
  4.  * Revision 4.4  1991/09/09  20:18:23  sob
  5.  * release 4.4
  6.  *
  7.  *
  8.  * 
  9.  */
  10. /* This software is Copyright 1991 by Stan Barber. 
  11.  *
  12.  * Permission is hereby granted to copy, reproduce, redistribute or otherwise
  13.  * use this software as long as: there is no monetary profit gained
  14.  * specifically from the use or reproduction of this software, it is not
  15.  * sold, rented, traded or otherwise marketed, and this copyright notice is
  16.  * included prominently in any copy made. 
  17.  *
  18.  * The author make no claims as to the fitness or correctness of this software
  19.  * for any use whatsoever, and it is provided as is. Any use of this software
  20.  * is at the user's own risk. 
  21.  */
  22.  
  23. #include "EXTERN.h"
  24. #include "common.h"
  25. #include "intrp.h"
  26. #include "final.h"
  27. #include "INTERN.h"
  28. #include "backpage.h"
  29.  
  30. ART_LINE maxindx = -1;
  31. long lseek();
  32.  
  33. void
  34. backpage_init()
  35. {
  36.     char *varyname;
  37.     
  38.     varyname = filexp(VARYNAME);
  39.     close(creat(varyname,0600));
  40.     varyfd = open(varyname,2);
  41.     UNLINK(varyname);
  42.     if (varyfd < 0) {
  43.     printf(cantopen,varyname) FLUSH;
  44.     sig_catcher(0);
  45.     }
  46.     
  47. }
  48.  
  49. /* virtual array read */
  50.  
  51. ART_POS
  52. vrdary(indx)
  53. ART_LINE indx;
  54. {
  55.     int subindx;
  56.     long offset;
  57.  
  58. #ifdef DEBUGGING
  59.     if (indx > maxindx) {
  60.     printf("vrdary(%ld) > %ld\n",(long)indx, (long)maxindx) FLUSH;
  61.     return 0;
  62.     }
  63. #endif
  64.     if (indx < 0)
  65.     return 0;
  66.     subindx = indx % VARYSIZE;
  67.     offset = (indx - subindx) * sizeof(varybuf[0]);
  68.     if (offset != oldoffset) {
  69.     if (oldoffset >= 0) {
  70. #ifndef lint
  71.         (void)lseek(varyfd,oldoffset,0);
  72.         write(varyfd, (char *)varybuf,sizeof(varybuf));
  73. #endif /* lint */
  74.     }
  75. #ifndef lint
  76.     (void)lseek(varyfd,offset,0);
  77.     read(varyfd,(char *)varybuf,sizeof(varybuf));
  78. #endif /* lint */
  79.     oldoffset = offset;
  80.     }
  81.     return varybuf[subindx];
  82. }
  83.  
  84. /* write to virtual array */
  85.  
  86. void
  87. vwtary(indx,newvalue)
  88. ART_LINE indx;
  89. ART_POS newvalue;
  90. {
  91.     int subindx;
  92.     long offset;
  93.  
  94. #ifdef DEBUGGING
  95.     if (indx < 0)
  96.     printf("vwtary(%ld)\n",(long)indx) FLUSH;
  97.     if (!indx)
  98.     maxindx = 0;
  99.     if (indx > maxindx) {
  100.     if (indx != maxindx + 1)
  101.         printf("indx skipped %d-%d\n",maxindx+1,indx-1) FLUSH;
  102.     maxindx = indx;
  103.     }
  104. #endif
  105.     subindx = indx % VARYSIZE;
  106.     offset = (indx - subindx) * sizeof(varybuf[0]);
  107.     if (offset != oldoffset) {
  108.     if (oldoffset >= 0) {
  109. #ifndef lint
  110.         (void)lseek(varyfd,oldoffset,0);
  111.         write(varyfd,(char *)varybuf,sizeof(varybuf));
  112. #endif /* lint */
  113.     }
  114. #ifndef lint
  115.     (void)lseek(varyfd,offset,0);
  116.     read(varyfd,(char *)varybuf,sizeof(varybuf));
  117. #endif /* lint */
  118.     oldoffset = offset;
  119.     }
  120.     varybuf[subindx] = newvalue;
  121. }
  122.  
  123.