home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / TELECOM / rn_4_3_blars.lzh / backpage.c < prev    next >
Text File  |  1990-08-25  |  2KB  |  115 lines

  1. /* $Header: backpage.c,v 4.3 85/05/01 11:36:03 lwall Exp $
  2.  *
  3.  * $Log:    backpage.c,v $
  4.  * Revision 4.3  85/05/01  11:36:03  lwall
  5.  * Baseline for release with 4.3bsd.
  6.  * 
  7.  */
  8.  
  9. #include "EXTERN.h"
  10. #include "common.h"
  11. #include "intrp.h"
  12. #include "final.h"
  13. #include "INTERN.h"
  14. #include "backpage.h"
  15.  
  16. ART_LINE maxindx = -1;
  17. long lseek();
  18.  
  19. void
  20. backpage_init()
  21. {
  22.     char *varyname;
  23.     
  24.     varyname = filexp(VARYNAME);
  25. #ifndef OSK
  26.     close(creat(varyname,0600));
  27.     varyfd = open(varyname,2);
  28.     UNLINK(varyname);
  29. #else
  30.     varyfd = create(varyname, S_IREAD | S_IWRITE, S_IREAD | S_IWRITE);
  31.     if (varyfd < 0 && errno == E_CEF)
  32.         varyfd = open(varyname, S_IREAD | S_IWRITE);
  33. #endif
  34.     if (varyfd < 0) {
  35.     printf(cantopen,varyname) FLUSH;
  36.     sig_catcher(0);
  37.     }
  38.     
  39. }
  40.  
  41. /* virtual array read */
  42.  
  43. ART_POS
  44. vrdary(indx)
  45. ART_LINE indx;
  46. {
  47.     int subindx;
  48.     long offset;
  49.  
  50. #ifdef DEBUGGING
  51.     if (indx > maxindx) {
  52.     printf("vrdary(%ld) > %ld\n",(long)indx, (long)maxindx) FLUSH;
  53.     return 0;
  54.     }
  55. #endif
  56.     if (indx < 0)
  57.     return 0;
  58.     subindx = indx % VARYSIZE;
  59.     offset = (indx - subindx) * sizeof(varybuf[0]);
  60.     if (offset != oldoffset) {
  61.     if (oldoffset >= 0) {
  62. #ifndef lint
  63.         (void)lseek(varyfd,oldoffset,0);
  64.         write(varyfd, (char *)varybuf,sizeof(varybuf));
  65. #endif lint
  66.     }
  67. #ifndef lint
  68.     (void)lseek(varyfd,offset,0);
  69.     read(varyfd,(char *)varybuf,sizeof(varybuf));
  70. #endif lint
  71.     oldoffset = offset;
  72.     }
  73.     return varybuf[subindx];
  74. }
  75.  
  76. /* write to virtual array */
  77.  
  78. void
  79. vwtary(indx,newvalue)
  80. ART_LINE indx;
  81. ART_POS newvalue;
  82. {
  83.     int subindx;
  84.     long offset;
  85.  
  86. #ifdef DEBUGGING
  87.     if (indx < 0)
  88.     printf("vwtary(%ld)\n",(long)indx) FLUSH;
  89.     if (!indx)
  90.     maxindx = 0;
  91.     if (indx > maxindx) {
  92.     if (indx != maxindx + 1)
  93.         printf("indx skipped %d-%d\n",maxindx+1,indx-1) FLUSH;
  94.     maxindx = indx;
  95.     }
  96. #endif
  97.     subindx = indx % VARYSIZE;
  98.     offset = (indx - subindx) * sizeof(varybuf[0]);
  99.     if (offset != oldoffset) {
  100.     if (oldoffset >= 0) {
  101. #ifndef lint
  102.         (void)lseek(varyfd,oldoffset,0);
  103.         write(varyfd,(char *)varybuf,sizeof(varybuf));
  104. #endif lint
  105.     }
  106. #ifndef lint
  107.     (void)lseek(varyfd,offset,0);
  108.     read(varyfd,(char *)varybuf,sizeof(varybuf));
  109. #endif lint
  110.     oldoffset = offset;
  111.     }
  112.     varybuf[subindx] = newvalue;
  113. }
  114.  
  115.