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 / norm.saver.c < prev    next >
C/C++ Source or Header  |  1990-08-26  |  1KB  |  60 lines

  1. /* norm.saver.c created from norm.saver.SH by blarson@usc.edu */
  2. /* 
  3. /*    Arguments:
  4. /*    1 Full name of article (%A)
  5. /*    2 Public news spool directory (%P)
  6. /*    3 Directory of current newsgroup (%c)
  7. /*    4 Article number (%a)
  8. /*    5 Where in article to start (%B)
  9. /*    6 Newsgroup name (%C)
  10. /*    7 Save destination (%b)
  11. /*
  12.  */
  13.  
  14. #include <stdio.h>
  15. #include "fileinfo.h"
  16.  
  17. main(argc, argv)
  18. int argc;
  19. char **argv;
  20. {
  21.     register int outfile, infile, count;
  22.     char buffer[8192];
  23.  
  24.     if(argc < 8) {
  25.         fprintf(stderr, "norm.saver: less than 7 arguments\n");
  26.     exit(1);
  27.     }
  28.     if((infile = open(argv[1], OPEN_READ)) < 0) {
  29.         fprintf(stderr, "Can't open %s for reading\n", argv[1]);
  30.     exit(1);
  31.     }
  32.     count = atoi(argv[5]);
  33.     if(count > 0) {
  34.         if(lseek(infile, count, 0) < 0) {
  35.         fprintf(stderr, "Can't position in %s\n", argv[1]);
  36.         exit(1);
  37.     }
  38.     }
  39.     if((outfile = open(argv[7], OPEN_READWRITE)) < 0) {
  40.         if((outfile = creat(argv[7], CREAT_READWRITE)) < 0) {
  41.             fprintf(stderr, "Can't open %s for writing\n", argv[7]);
  42.         exit(1);
  43.     }
  44.     } else {
  45.     if(lseek(outfile, 0, 2) < 0) {
  46.             fprintf(stderr, "Can't position to end of %s\n", argv[7]);
  47.         exit(1);
  48.     }
  49.     }
  50.     if(count==0) {
  51.         sprintf(buffer, "Article %s of %s:\n", argv[4], argv[6]);
  52.     write(outfile, buffer, strlen(buffer));
  53.     }
  54.     while((count = read(infile, buffer, sizeof buffer)) > 0) {
  55.         write(outfile, buffer, count);
  56.     }
  57.     write(outfile, "\n\n", 2);
  58.     exit(0);
  59. }
  60.