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 / getactive.c < prev    next >
C/C++ Source or Header  |  1990-08-22  |  2KB  |  81 lines

  1. /* $Header: getactive.c,v 1.2 89/11/28 01:50:22 sob Locked $
  2.  *
  3.  * $Log:    getactive.c,v $
  4.  * Revision 1.2  89/11/28  01:50:22  sob
  5.  * Changed so that it won't give makedepend problems with SERVER is not defined.
  6.  * 
  7.  * Revision 1.1  89/11/06  00:50:14  sob
  8.  * Initial revision
  9.  * 
  10.  *
  11.  */
  12. #include <stdio.h>
  13. #include "config.h"
  14. #include "EXTERN.h"
  15. #ifdef SERVER
  16. #include "server.h"
  17. #endif
  18.  
  19. main(argc, argv)
  20.     int        argc;
  21.     char         *argv[];
  22. {
  23.     char        ser_line[256];
  24.     int        response;
  25.     register char    *server;
  26.     register FILE    *actfp;
  27.  
  28.     if (argc != 2) {
  29.         fprintf(stderr, "Usage: getactive filename\n");
  30.         exit(1);
  31.     }
  32.  
  33.     server = getserverbyfile(SERVER_FILE);
  34.     if (server == NULL) {
  35.         fprintf(stderr, "Couldn't get name of news server from %s\n",
  36.             SERVER_FILE);
  37.         fprintf(stderr,
  38.       "Either fix this file, or put NNTPSERVER in your environment.\n");
  39.         exit(1);
  40.     }
  41.  
  42.     response = server_init(server);
  43.     if (response < 0) {
  44.         fprintf(stderr,
  45.             "getactive: Can't get active file from server %s.\n",
  46.                 server);
  47.         exit(1);
  48.     }
  49.  
  50.     if (handle_server_response(response, server) < 0)
  51.         exit(1);
  52.  
  53.     put_server("LIST");    /* tell server we want the active file */
  54.     (void) get_server(ser_line, sizeof(ser_line));
  55.     if (*ser_line != CHAR_OK) {        /* and then see if that's ok */
  56.         fprintf(stderr,
  57.             "getactive: Can't get active file from server.\n");
  58.         fprintf(stderr, "Server said: %s\n", ser_line);
  59.         exit(1);
  60.     }
  61.  
  62.     actfp = fopen(argv[1], "w");        /* and get ready */
  63.     if (actfp == NULL) {
  64.         close_server();
  65.         perror(argv[1]);
  66.         exit(1);
  67.     }
  68.  
  69.     while (get_server(ser_line, sizeof(ser_line)) >= 0) {  /* while */
  70.         if (ser_line[0] == '.')        /* there's another line */
  71.             break;            /* get it and write it to */
  72.         if (actfp != NULL) {        /* the temporary active file */
  73.             fputs(ser_line, actfp);
  74.             putc('\n', actfp);
  75.         }
  76.     }
  77.  
  78.     (void) fclose(actfp);
  79.     close_server();
  80. }
  81.