home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume25 / trn / part02 / getactive.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-12-02  |  2.6 KB  |  116 lines

  1. /* $Id: getactive.c,v 4.4 1991/09/09 20:18:23 sob Exp sob $
  2.  *
  3.  * $Log: getactive.c,v $
  4.  * Revision 4.4  1991/09/09  20:18:23  sob
  5.  * release 4.4
  6.  *
  7.  *
  8.  * 
  9.  *
  10.  */
  11. /* This software is Copyright 1991 by Stan Barber. 
  12.  *
  13.  * Permission is hereby granted to copy, reproduce, redistribute or otherwise
  14.  * use this software as long as: there is no monetary profit gained
  15.  * specifically from the use or reproduction of this software, it is not
  16.  * sold, rented, traded or otherwise marketed, and this copyright notice is
  17.  * included prominently in any copy made. 
  18.  *
  19.  * The author make no claims as to the fitness or correctness of this software
  20.  * for any use whatsoever, and it is provided as is. Any use of this software
  21.  * is at the user's own risk. 
  22.  */
  23. #include <stdio.h>
  24. #include "config.h"
  25. #include <signal.h>
  26. /* what to do with ansi prototypes -- '()' == ignore, 'x' == use */
  27. #ifndef ANSI
  28. #   define ANSI(x) ()
  29. #endif
  30. #include "INTERN.h"
  31. #ifdef SERVER
  32. #include "server.h"
  33. #endif
  34.  
  35. main(argc, argv)
  36.     int        argc;
  37.     char         *argv[];
  38. {
  39.     char        ser_line[NNTP_STRLEN];
  40.     char        command[32];
  41.     int        response;
  42.     char         *action;
  43.     register char    *server;
  44.     register FILE    *actfp;
  45.  
  46.     if (argc < 2 || argc > 3) {
  47.         fprintf(stderr, "Usage: getactive [active|distributions|newsgroups] filename\n");
  48.         exit(1);
  49.     }
  50.     if (argc == 2) action = "ACTIVE";
  51.     else{
  52.          action = argv[1];
  53.          argc--;
  54.          argv++;
  55.     }
  56.     if ((server = get_server_name(1)) == NULL)
  57.         exit(1);
  58.     response = server_init(server);
  59.     if (response < 0) {
  60.         fprintf(stderr,
  61.             "getactive: Can't get %s file from server %s.\n",
  62.                 action, server);
  63.         exit(1);
  64.     }
  65.  
  66.     if (handle_server_response(response, server) < 0)
  67.         exit(1);
  68.  
  69.     sprintf(command,"LIST %s",action);
  70.     put_server(command); 
  71. #ifdef HAVESIGHOLD
  72.      sighold(SIGINT);
  73. #endif
  74.     (void) get_server(ser_line, sizeof(ser_line));
  75.     if (*ser_line != CHAR_OK) {        /* and then see if that's ok */
  76.         fprintf(stderr,
  77.             "getactive: Can't get %s file from server.\n",action);
  78.         fprintf(stderr, "Server said: %s\n", ser_line);
  79.         exit(1);
  80.     }
  81.  
  82.     actfp = fopen(argv[1], "w");        /* and get ready */
  83.     if (actfp == NULL) {
  84.         close_server();
  85.         perror(argv[1]);
  86.         exit(1);
  87.     }
  88.  
  89.     while (get_server(ser_line, sizeof(ser_line)) >= 0) {  /* while */
  90.         if (ser_line[0] == '.')        /* there's another line */
  91.             break;            /* get it and write it to */
  92.         if (actfp != NULL) {        /* the temporary active file */
  93.             fputs(ser_line, actfp);
  94.             putc('\n', actfp);
  95.         }
  96.     }
  97.  
  98.     if (ferror(actfp)) {
  99.          perror(argv[1]);
  100.          exit(1);
  101.     }
  102.  
  103.     if (fclose(actfp) == EOF) {
  104.          perror(argv[1]);
  105.          exit(1);
  106.     }
  107.  
  108. #ifdef HAVESIGHOLD
  109.  
  110.     exit(0);
  111.     sigrelse(SIGINT);
  112. #endif
  113.     close_server();
  114.     exit(0);
  115. }
  116.