home *** CD-ROM | disk | FTP | other *** search
/ RISC DISC 2 / RISC_DISC_2.iso / pd_share / utilities / cli / nspark / store_c < prev    next >
Encoding:
Text File  |  1994-12-12  |  1.2 KB  |  62 lines

  1. /*
  2.  * store/unstore archive file
  3.  *
  4.  * $Header: store.c 1.4 93/08/20 $
  5.  * $Log:    store.c,v $
  6.  * Revision 1.4  93/08/20  11:50:20  arb
  7.  * Do not print "unstored" if in quiet mode
  8.  *
  9.  * Revision 1.3  92/12/07  17:19:39  duplain
  10.  * reformatted source.
  11.  * 
  12.  * Revision 1.2  92/10/01  11:22:46  duplain
  13.  * Added check for EOF.
  14.  * 
  15.  * Revision 1.1  92/09/29  18:02:26  duplain
  16.  * Initial revision
  17.  * 
  18.  */
  19.  
  20. #include <stdio.h>
  21. #include "spark.h"
  22. #include "main.h"
  23. #include "crc.h"
  24. #include "io.h"
  25.  
  26. #ifdef UNIX
  27. static char rcsid[] = "$Header: store.c 1.4 93/08/20 $";
  28. #endif /* UNIX */
  29.  
  30. Status
  31. unstore(header, ifp, ofp)
  32.     Header *header;
  33.     FILE *ifp, *ofp;
  34. {
  35.     register len = header->complen;
  36.     register Byte byte;
  37.  
  38.     crc = 0;
  39.     while (len--) {
  40.     if (check_stream(ifp) != FNOERR)
  41.         break;
  42.     byte = read_byte(ifp);
  43.     calccrc(byte);
  44.     if (!testing)
  45.         write_byte(ofp, byte);
  46.     }
  47.  
  48.     if (check_stream(ifp) == FRWERR)
  49.     return (RERR);
  50.     if (!testing && check_stream(ofp) == FRWERR)
  51.     return (WERR);
  52.     if ((Halfword)crc != header->crc)
  53.     return (CRCERR);
  54.     if (testing)
  55.     {
  56.     if (!quiet) printf("OK (stored)");
  57.     }
  58.     else
  59.     if (!quiet) printf("unstored");
  60.     return (NOERR);
  61. }
  62.