home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume36 / uqwk / part01 / close.c next >
Encoding:
C/C++ Source or Header  |  1993-03-11  |  2.0 KB  |  116 lines

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <time.h>
  4. #include "uqwk.h"
  5.  
  6. /*
  7.  *  Wrap things up
  8.  */
  9.  
  10. CloseStuff()
  11. {
  12.     fclose (msg_fd);
  13.  
  14.     WriteControl();
  15.     if (do_news && (!read_only) ) WriteNewsrc();
  16.  
  17.     if (blk_cnt >= max_blks)
  18.     {
  19.         fprintf (stderr,
  20.             "%s: block count exceeded; some articles not packed\n",
  21.             progname);
  22.     }
  23.  
  24.     /* Remove reply packet */
  25.     if ( (!read_only) && (strcmp (rep_file, DEF_REP_FILE)))
  26.     {
  27.         unlink (rep_file);
  28.     }
  29. }
  30.  
  31. WriteControl()
  32. /*
  33.  *  Create the CONTROL.DAT file
  34.  */
  35. {
  36.     struct conf_ent *cp;
  37.     struct tm *t;
  38.     char ctl_fname[PATH_LEN];
  39.     int clock;
  40.  
  41.     strcpy (ctl_fname, home_dir);
  42.     strcpy (ctl_fname, "/");
  43.     strcpy (ctl_fname, "control.dat");
  44.  
  45.     if (NULL == (ctl_fd = fopen (ctl_fname, "w")))
  46.     {
  47.         fprintf (stderr, "%s: can't open %s\n", progname, ctl_fname);
  48.         exit (0);
  49.     }
  50.  
  51.     fprintf (ctl_fd, "%s\r\n%s\r\n%s\r\n%s\r\n%s\r\n",
  52.         bbs_name, bbs_city, bbs_phone, bbs_sysop, bbs_id);
  53.  
  54.     /* Date */
  55.     clock = time (NULL);
  56.     t = gmtime (&clock);
  57.     fprintf (ctl_fd, "%02d\-%02d\-%04d,%02d\:%02d\:%02d\r\n",
  58.         t->tm_mon+1, t->tm_mday, t->tm_year+1900,
  59.         t->tm_hour, t->tm_min, t->tm_sec);
  60.  
  61.     fprintf (ctl_fd, "%s\r\n \r\n0\r\n", user_name);
  62.     fprintf (ctl_fd, "%d\r\n%d\r\n", msg_cnt, conf_cnt-1);
  63.  
  64.     /* List of conferences */
  65.     cp = conf_list;
  66.     while (cp != NULL)
  67.     {
  68.         fprintf (ctl_fd, "%d\r\n%s\r\n", cp->number, cp->name);
  69.         cp = cp->next;
  70.     }
  71.  
  72.     fprintf (ctl_fd, "WELCOME.DAT\r\nNEWS.DAT\r\nLOGOFF.DAT\r\n");
  73.     fprintf (ctl_fd, "\032");
  74.     fclose (ctl_fd);
  75. }
  76.  
  77. WriteNewsrc()
  78. /*
  79.  *  Rewrite the updated .newsrc file
  80.  */
  81. {
  82.     if (read_only) return (0);
  83.  
  84.     if (NULL == (nrc_fd = fopen (nrc_file, "w")))
  85.     {
  86.         fprintf (stderr, "%s: can't write %s\n",
  87.             progname, nrc_file);
  88.         return (0);
  89.     }
  90.  
  91.     /* We do this recursively to preserve the order of the .newsrc */
  92.     wn (nrc_list);
  93.  
  94.     fclose (nrc_fd);
  95. }
  96.  
  97. wn (np)
  98. struct nrc_ent *np;
  99. {
  100.     if (np == NULL) return (0);
  101.  
  102.     /* Write the rest of them */
  103.     wn (np->next);
  104.  
  105.     /* Write this one */
  106.     if (np->subscribed)
  107.     {
  108.         fprintf (nrc_fd, "%s: 1-%d\n", np->name, np->hi);
  109.     }
  110.     else
  111.     {
  112.         fprintf (nrc_fd, "%s! 1-%d\n", np->name, np->hi);
  113.     }
  114. }
  115.  
  116.