home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / trn_12.zip / src / getactive.c < prev    next >
C/C++ Source or Header  |  1993-11-08  |  3KB  |  117 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,
  48.              "Usage: getactive [active|distributions|newsgroups] filename\n");
  49.         exit(1);
  50.     }
  51.     if (argc == 2) action = "ACTIVE";
  52.     else{
  53.          action = argv[1];
  54.          argc--;
  55.          argv++;
  56.     }
  57.     if ((server = get_server_name(1)) == NULL)
  58.         exit(1);
  59.     response = server_init(server);
  60.     if (response < 0) {
  61.         fprintf(stderr,
  62.             "getactive: Can't get %s file from server %s.\n",
  63.                 action, server);
  64.         exit(1);
  65.     }
  66.  
  67.     if (handle_server_response(response, server) < 0)
  68.         exit(1);
  69.  
  70.     sprintf(command,"LIST %s",action);
  71.     put_server(command); 
  72. #ifdef HAVESIGHOLD
  73.      sighold(SIGINT);
  74. #endif
  75.     (void) get_server(ser_line, sizeof(ser_line));
  76.     if (*ser_line != CHAR_OK) {        /* and then see if that's ok */
  77.         fprintf(stderr,
  78.             "getactive: Can't get %s file from server.\n",action);
  79.         fprintf(stderr, "Server said: %s\n", ser_line);
  80.         exit(1);
  81.     }
  82.  
  83.     actfp = fos2open(argv[1], "w");        /* and get ready */
  84.     if (actfp == NULL) {
  85.         close_server();
  86.         perror(argv[1]);
  87.         exit(1);
  88.     }
  89.  
  90.     while (get_server(ser_line, sizeof(ser_line)) >= 0) {  /* while */
  91.         if (ser_line[0] == '.')        /* there's another line */
  92.             break;            /* get it and write it to */
  93.         if (actfp != NULL) {        /* the temporary active file */
  94.             fputs(ser_line, actfp);
  95.             putc('\n', actfp);
  96.         }
  97.     }
  98.  
  99.     if (ferror(actfp)) {
  100.          perror(argv[1]);
  101.          exit(1);
  102.     }
  103.  
  104.     if (fclose(actfp) == EOF) {
  105.          perror(argv[1]);
  106.          exit(1);
  107.     }
  108.  
  109. #ifdef HAVESIGHOLD
  110.  
  111.     exit(0);
  112.     sigrelse(SIGINT);
  113. #endif
  114.     close_server();
  115.     exit(0);
  116. }
  117.