home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / trn_12.zip / src / backpage.c < prev    next >
C/C++ Source or Header  |  1992-09-22  |  3KB  |  134 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.     char *tmpname;
  38.     
  39. /***OS2: VARYNAME is #defined in common.h as a name
  40.           which is located in /tmp. Now we use the temp-name
  41.           which is defined in UUPCSYSRC. ***/
  42. /*    varyname = filexp(VARYNAME);   */
  43.  
  44.     tmpname = (char *)malloc(strlen(uupc_rc_settings.temp_name) + 20);
  45.     sprintf(tmpname,"%s/rnvary.%$",uupc_rc_settings.temp_name);
  46.     varyname = filexp(tmpname);
  47.     free(tmpname);
  48. /*** OS2: end of patch ***/
  49.  
  50.     close(creat(varyname,0600));
  51.     varyfd = open(varyname,2);
  52.     UNLINK(varyname);
  53.     if (varyfd < 0) {
  54.     printf(cantopen,varyname) ; FLUSH;
  55.     sig_catcher(0);
  56.     }
  57.     
  58. }
  59.  
  60. /* virtual array read */
  61.  
  62. ART_POS
  63. vrdary(indx)
  64. ART_LINE indx;
  65. {
  66.     int subindx;
  67.     long offset;
  68.  
  69. #ifdef DEBUGGING
  70.     if (indx > maxindx) {
  71.     printf("vrdary(%ld) > %ld\n",(long)indx, (long)maxindx) ; FLUSH;
  72.     return 0;
  73.     }
  74. #endif
  75.     if (indx < 0)
  76.     return 0;
  77.     subindx = indx % VARYSIZE;
  78.     offset = (indx - subindx) * sizeof(varybuf[0]);
  79.     if (offset != oldoffset) {
  80.     if (oldoffset >= 0) {
  81. #ifndef lint
  82.         (void)lseek(varyfd,oldoffset,0);
  83.         write(varyfd, (char *)varybuf,sizeof(varybuf));
  84. #endif /* lint */
  85.     }
  86. #ifndef lint
  87.     (void)lseek(varyfd,offset,0);
  88.     read(varyfd,(char *)varybuf,sizeof(varybuf));
  89. #endif /* lint */
  90.     oldoffset = offset;
  91.     }
  92.     return varybuf[subindx];
  93. }
  94.  
  95. /* write to virtual array */
  96.  
  97. void
  98. vwtary(indx,newvalue)
  99. ART_LINE indx;
  100. ART_POS newvalue;
  101. {
  102.     int subindx;
  103.     long offset;
  104.  
  105. #ifdef DEBUGGING
  106.     if (indx < 0)
  107.     printf("vwtary(%ld)\n",(long)indx) ; FLUSH;
  108.     if (!indx)
  109.     maxindx = 0;
  110.     if (indx > maxindx) {
  111.     if (indx != maxindx + 1)
  112.         printf("indx skipped %d-%d\n",maxindx+1,indx-1) ; FLUSH;
  113.     maxindx = indx;
  114.     }
  115. #endif
  116.     subindx = indx % VARYSIZE;
  117.     offset = (indx - subindx) * sizeof(varybuf[0]);
  118.     if (offset != oldoffset) {
  119.     if (oldoffset >= 0) {
  120. #ifndef lint
  121.         (void)lseek(varyfd,oldoffset,0);
  122.         write(varyfd,(char *)varybuf,sizeof(varybuf));
  123. #endif /* lint */
  124.     }
  125. #ifndef lint
  126.     (void)lseek(varyfd,offset,0);
  127.     read(varyfd,(char *)varybuf,sizeof(varybuf));
  128. #endif /* lint */
  129.     oldoffset = offset;
  130.     }
  131.     varybuf[subindx] = newvalue;
  132. }
  133.  
  134.