home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_100 / 157_01 / qed10 < prev    next >
Text File  |  1987-10-12  |  2KB  |  107 lines

  1. /*  VERSION 0005  (DATE: 28/04/87)  (TIME: 22:38)  */
  2. /*
  3.     e (qed) screen editor
  4.  
  5.     (C) G. Nigel Gilbert, MICROLOGY, 1981
  6.  
  7.     August-December 1981
  8.  
  9.     Modified: Aug-Dec    1984:    BDS-C 'e'(vers 4.6a) to 'qe' (J.W. Haefner)
  10.               March        1985:    BDS-C 'qe' to DeSmet-C 'qed' (J.W. Haefner)
  11.  
  12.     FILE: qed10
  13.  
  14.     FUNCTIONS: fopen,fcreat,fflush,fclose,putc,getc,funlink,
  15.             frename,dskcheck,err1,err2,err3,err4
  16.  
  17.     PURPOSE: file buffer operations extracted and stripped from stdlib1,
  18.         with protection from bdos error crashes added
  19.  
  20. */
  21.  
  22. #include "qed.h"
  23.  
  24. int fopen(filename,iobuf)
  25. struct iobuffer *iobuf;
  26. char *filename;
  27. {
  28.     if ((iobuf -> _fd = open(filename,0))<0)
  29.          return FAIL;
  30.     iobuf -> _nleft = 0;
  31.     return iobuf -> _fd;
  32. }
  33.  
  34. int fcreat(name,iobuf)
  35. char *name;
  36. struct iobuffer *iobuf;
  37. {
  38.     if ((iobuf -> _fd = creat(name)) < 0 )
  39.         return FAIL;
  40.     iobuf -> _nextp = iobuf -> _buff;
  41.     iobuf -> _nleft = (NSECTS * SECSIZ);
  42.     return iobuf -> _fd;
  43. }
  44.  
  45. int fflush(iobuf)    /*does NOT allow more writing*/
  46. struct iobuffer *iobuf;
  47. {
  48.     int i;
  49.  
  50.     if (iobuf -> _nleft == (NSECTS * SECSIZ)) return YES;
  51.     i = NSECTS*SECSIZ - iobuf->_nleft;
  52.     if (write(iobuf -> _fd, iobuf -> _buff, i) != i) return FAIL;
  53.     return YES;
  54. }
  55.  
  56. int fclose(iobuf)
  57. struct iobuffer *iobuf;
  58. {
  59.     return close(iobuf -> _fd);
  60. }
  61.  
  62. eputc(c,iobuf)    /*stripped down version of standard putc*/
  63. char c;
  64. struct iobuffer *iobuf;
  65. {
  66.     if (iobuf -> _nleft--) return *iobuf -> _nextp++ = c;
  67.     if ((write(iobuf -> _fd, iobuf -> _buff, NSECTS*SECSIZ)) != NSECTS*SECSIZ)
  68.         /*return DFAIL;*/
  69.         return FAIL;
  70.     iobuf -> _nleft = (NSECTS * SECSIZ -1);
  71.     iobuf -> _nextp = iobuf -> _buff;
  72.     return *iobuf -> _nextp++ = c;
  73. }
  74.  
  75. int egetc(iobuf)    /*the standard getc, trimmed for speed*/
  76. struct iobuffer  *iobuf;
  77. {
  78.     int nbytes;
  79.  
  80.     if (iobuf -> _nleft--) return *iobuf -> _nextp++;
  81.     if ((nbytes = read(iobuf -> _fd, iobuf -> _buff, NSECTS*SECSIZ))==FAIL) {
  82.         iobuf -> _nleft++;
  83.         return DFAIL;
  84.         }
  85.     iobuf -> _nleft = nbytes - 1;
  86.     iobuf -> _nextp = iobuf -> _buff;
  87.     if (nbytes<(NSECTS*SECSIZ)) {
  88.       (iobuf->_buff)[nbytes]=ENDFILE;
  89.       (iobuf -> _nleft)++;
  90.     }
  91.     return *iobuf->_nextp++;
  92. }
  93.  
  94. funlink(name)
  95. char *name;
  96. {
  97. /*    if (dskcheck(setjmp(dskerr))) return FAIL;*/
  98.     return unlink(name);
  99. }
  100.  
  101. frename(oldname,newname)
  102. char *oldname,*newname;
  103. {
  104. /*    if (dskcheck(setjmp(dskerr))) return FAIL;*/
  105.     return rename(oldname,newname);
  106. }
  107.