home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_100 / 199_01 / ged10.c < prev    next >
Text File  |  1987-12-17  |  3KB  |  163 lines

  1. /*
  2. Header:          CUG199;
  3. Title:           Module 10 of ged editor;
  4. Last Updated:    12/01/87;
  5.  
  6. Description:    "PURPOSE: file buffer operations extracted and stripped
  7.                  from stdlib1, with protection from bdos error crashes
  8.                  removed for MSDOS";
  9.  
  10. Keywords:        e, editor, qed, ged, DeSmet, MSDOS;
  11. Filename:        ged10.c;
  12. Warnings:       "O file must be present during link for ged";
  13.  
  14. Authors:         G. Nigel Gilbert, James W. Haefner, and Mel Tearle;
  15. Compilers:       DeSmet 2.51;
  16.  
  17. References:
  18. Endref;
  19. */
  20.  
  21. /*
  22. e/qed/ged  screen editor
  23.  
  24. (C) G. Nigel Gilbert, MICROLOGY, 1981 - August-December 1981
  25.  
  26. Modified:  Aug-Dec   1984:  BDS-C 'e'(vers 4.6a) to 'qe' (J.W. Haefner)
  27.            March     1985:  BDS-C 'qe' to DeSmet-C 'qed' (J.W. Haefner)
  28.  
  29.            May       1986:  qed converted to ged         (Mel Tearle)
  30.            August    1987:  ged converted to MSC 4.0     (Mel Tearle)
  31.  
  32. File:      ged10.c
  33.  
  34. Functions: ffopen, fcreat, dflush, ffclose, eputc, egetc, funlink,
  35.            frename
  36. */
  37.  
  38.  
  39. #ifndef  TC
  40. #include "ged.h"
  41. #else
  42. #include "ged.t"
  43. #endif
  44.  
  45.  
  46. int ffopen(filename,iobuf)
  47. struct iobuffer *iobuf;
  48. char   *filename;
  49. {
  50. #ifndef DS
  51.   if ( ( iobuf -> _fd = open( filename, O_RDWR | O_TEXT ) ) < 0 )
  52.          return  FAIL;
  53. #else
  54.   if ( ( iobuf -> _fd = open( filename, 0 ) ) < 0 )
  55.          return  FAIL;
  56. #endif
  57.  
  58. iobuf -> _nleft = 0;
  59. return  iobuf -> _fd;
  60. }
  61.  
  62.  
  63. int fcreat(name,iobuf)
  64. char   *name;
  65. struct iobuffer *iobuf;
  66. {
  67.  
  68. if ( ( iobuf -> _fd = creat( name ) ) < 0 )
  69.        return  FAIL;
  70.  
  71. iobuf -> _nextp = iobuf -> _buff;
  72. iobuf -> _nleft = ( NSECTS * SECSIZ );
  73.  
  74. return  iobuf -> _fd;
  75. }
  76.  
  77.  
  78. /* does NOT allow more writing
  79.  */
  80. int dflush(iobuf)
  81. struct  iobuffer *iobuf;
  82. {
  83. unsigned int i;
  84.  
  85. if ( iobuf -> _nleft == ( NSECTS * SECSIZ ) )
  86.      return  YES;
  87.  
  88. i = NSECTS*SECSIZ - iobuf->_nleft;
  89.  
  90. if ( write( iobuf -> _fd, iobuf -> _buff, i ) != i )
  91.      return  FAIL;
  92.  
  93. return YES;
  94. }
  95.  
  96.  
  97. int ffclose(iobuf)
  98. struct  iobuffer *iobuf;
  99. {
  100. return  close( iobuf -> _fd );
  101. }
  102.  
  103.  
  104. /* stripped down version of standard putc
  105.  */
  106. int eputc(c,iobuf)
  107. char    c;
  108. struct  iobuffer *iobuf;
  109. {
  110. if ( iobuf -> _nleft-- )  return  *iobuf -> _nextp++ = c;
  111.  
  112. if ( ( write(iobuf -> _fd, iobuf -> _buff, NSECTS*SECSIZ ) )
  113.        != NSECTS*SECSIZ )
  114.        return  FAIL;
  115.  
  116. iobuf -> _nleft = ( NSECTS * SECSIZ -1 );
  117. iobuf -> _nextp = iobuf -> _buff;
  118.  
  119. return  *iobuf -> _nextp++ = c;
  120. }
  121.  
  122.  
  123. /* the standard getc, trimmed for speed
  124.  */
  125. int egetc(iobuf)
  126. struct  iobuffer  *iobuf;
  127. {
  128. unsigned int nbytes;
  129.  
  130. if ( iobuf -> _nleft-- )  return  *iobuf -> _nextp++;
  131.    if ( ( nbytes = read( iobuf -> _fd,
  132.                    iobuf -> _buff,
  133.                    NSECTS*SECSIZ ) ) < 0 )  {
  134.             iobuf -> _nleft++;
  135.             return  DFAIL;
  136.    }
  137.    if ( nbytes == 0 ) {
  138.         iobuf -> _nleft++;
  139.         return  ENDFILE;
  140.    }
  141. iobuf -> _nleft = nbytes - 1;
  142. iobuf -> _nextp = iobuf -> _buff;
  143.  
  144. return  *iobuf->_nextp++;
  145. }
  146.  
  147.  
  148. int funlink(name)
  149. char *name;
  150. {
  151. return  unlink( name );
  152. }
  153.  
  154.  
  155. int frename(oldname,newname)
  156. char *oldname,*newname;
  157. {
  158. return  rename( oldname, newname );
  159. }
  160.  
  161.  
  162. /* that's all */
  163.