home *** CD-ROM | disk | FTP | other *** search
/ ftp.wwiv.com / ftp.wwiv.com.zip / ftp.wwiv.com / pub / OFFLINE / UQWK18.ZIP / UQWK18.TAR / close.c next >
C/C++ Source or Header  |  1994-02-10  |  4KB  |  231 lines

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <sys/types.h>
  4. #include <time.h>
  5. #include "uqwk.h"
  6.  
  7. #ifdef SERVER
  8. #include "nntp.h"
  9. extern void close_server();
  10. #endif
  11.  
  12. /*
  13.  *  Wrap things up
  14.  */
  15.  
  16. CloseStuff()
  17. {
  18.     if (msg_fd != NULL) fclose (msg_fd);
  19.  
  20.     /* Write QWK CONTROL.DAT file (or SLNP AREAS file) */
  21.     if (!zip_mode && !sum_mode && (do_mail || do_news)) WriteControl();
  22.  
  23.     /* Close summary file */
  24.     if (sum_mode) fclose (sum_fd);
  25.  
  26.     /* Update .newsrc */
  27.     if (do_news && (!read_only) ) WriteNewsrc();
  28.  
  29.     if ( (blk_cnt >= max_blks) && (max_blks > 0) )
  30.     {
  31.         fprintf (stderr,
  32.             "%s: block count exceeded; some articles not packed\n",
  33.             progname);
  34.     }
  35.  
  36.     /* Remove reply packet */
  37.     if ( (!read_only) && (strcmp (rep_file, DEF_REP_FILE)))
  38.     {
  39.         unlink (rep_file);
  40.     }
  41.  
  42. #ifdef SERVER
  43.     if (strcmp (rep_file, DEF_REP_FILE) || do_news) close_server();
  44. #endif
  45. }
  46.  
  47. WriteControl()
  48. /*
  49.  *  Create the CONTROL.DAT file (or AREAS if SLNP)
  50.  */
  51. {
  52.     struct conf_ent *cp;
  53.     struct tm *t;
  54.     char ctl_fname[PATH_LEN];
  55.     time_t clock;
  56.     int n;
  57.  
  58.     strcpy (ctl_fname, home_dir);
  59.     strcat (ctl_fname, "/");
  60.  
  61.     if (slnp_mode)
  62.     {
  63.         strcat (ctl_fname, "AREAS");
  64.     }
  65.     else
  66.     {
  67.         strcat (ctl_fname, "control.dat");
  68.     }
  69.  
  70.     if (NULL == (ctl_fd = fopen (ctl_fname, "w")))
  71.     {
  72.         fprintf (stderr, "%s: can't open %s\n", progname, ctl_fname);
  73.         exit (0);
  74.     }
  75.  
  76.     /* SLNP AREAS file is different */
  77.     if (slnp_mode)
  78.     {
  79.         WriteAreas();
  80.         return (0);
  81.     }
  82.  
  83.     fprintf (ctl_fd, "%s\r\n%s\r\n%s\r\n%s\r\n%s\r\n",
  84.         bbs_name, bbs_city, bbs_phone, bbs_sysop, bbs_id);
  85.  
  86.     /* Date */
  87.     clock = time (NULL);
  88.     t = gmtime (&clock);
  89.     fprintf (ctl_fd, "%02d-%02d-%04d,%02d:%02d:%02d\r\n",
  90.         t->tm_mon+1, t->tm_mday, t->tm_year+1900,
  91.         t->tm_hour, t->tm_min, t->tm_sec);
  92.  
  93.     fprintf (ctl_fd, "%s\r\n \r\n0\r\n", user_name);
  94.  
  95.     /* Count conferences with articles */
  96.     n = 0;
  97.     cp = conf_list;
  98.     while (cp != NULL)
  99.     {
  100.         if (every_mode || (cp->count > 0)) n++;
  101.         cp = cp->next;
  102.     }
  103.     fprintf (ctl_fd, "%d\r\n%d\r\n", msg_cnt, n-1);
  104.  
  105.     /* List of conferences */
  106.     cp = conf_list;
  107.     while (cp != NULL)
  108.     {
  109.         if (every_mode || (cp->count > 0))
  110.         {
  111.             strcpy (buf, cp->name);
  112.  
  113.             /* Translate the name if desired */
  114.             if (trn_list != NULL) TransName (buf);
  115.  
  116.             /* Truncate the group name if desired */
  117.             if ( (grp_len > 0) && (grp_len < BUF_LEN) )
  118.             {
  119.                 buf[grp_len] = 0;
  120.             }
  121.  
  122.             fprintf (ctl_fd, "%d\r\n%s\r\n", cp->number, buf);
  123.         }
  124.         cp = cp->next;
  125.     }
  126.  
  127.     fprintf (ctl_fd, "WELCOME.DAT\r\nNEWS.DAT\r\nLOGOFF.DAT\r\n");
  128.     fprintf (ctl_fd, "\032");
  129.     fclose (ctl_fd);
  130.     return (0);
  131. }
  132.  
  133. WriteAreas()
  134. /*
  135.  *  Write the SLNP AREAS file
  136.  */
  137. {
  138.     struct conf_ent *cp;
  139.  
  140.     /* Loop through conference list */
  141.     cp = conf_list;
  142.     while (cp != NULL)
  143.     {
  144.         if (strcmp (cp->name, MAIL_CONF_NAME))
  145.         {
  146.             if (cp->count > 0)
  147.             {
  148.                 fprintf (ctl_fd, "%07d\011%s\011un\n",
  149.                     cp->number, cp->name);
  150.             }
  151.         }
  152.         else
  153.         {
  154.             fprintf (ctl_fd, "%07d\011%s\011bn\n",
  155.                 cp->number, cp->name);
  156.         }
  157.  
  158.         cp = cp->next;
  159.     }
  160.     fclose (ctl_fd);
  161.     return (0);
  162. }
  163.  
  164. WriteNewsrc()
  165. /*
  166.  *  Rewrite the updated .newsrc file
  167.  */
  168. {
  169.     struct nrc_ent *np;
  170.  
  171.     if (read_only) return (0);
  172.  
  173.     if (NULL == (nrc_fd = fopen (nrc_file, "w")))
  174.     {
  175.         fprintf (stderr, "%s: can't write %s\n",
  176.             progname, nrc_file);
  177.         return (0);
  178.     }
  179.  
  180.     for (np=nrc_list; np!=NULL; np=np->next)
  181.     {
  182.         /* Write this one */
  183.         if (waf_mode)
  184.         {
  185.             if (np->subscribed)
  186.             {
  187.                 fprintf (nrc_fd, "%s %d\r\n",
  188.                     np->name, np->sub->hi);
  189.             }
  190.         }
  191.         else  /* Not waffle mode */
  192.         {
  193.             if (np->subscribed)
  194.             {
  195.                 fprintf (nrc_fd, "%s: ", np->name);
  196.             }
  197.             else
  198.             {
  199.                 fprintf (nrc_fd, "%s! ", np->name);
  200.             }
  201.             WriteSub (nrc_fd, np->sub);
  202.         }
  203.     }
  204.     fclose (nrc_fd);
  205.     return (1);
  206. }
  207.  
  208. TransName (n)
  209. char *n;
  210. /*
  211.  *  Translate newsgroup name
  212.  */
  213. {
  214.     struct trn_ent *tp;
  215.  
  216.     tp = trn_list;
  217.  
  218.     while (tp != NULL)
  219.     {
  220.         if (!strcmp (n, tp->old))
  221.         {
  222.             /* Found a match */
  223.             strcpy (n, tp->new);
  224.             return (0);
  225.         }
  226.         tp = tp->next;
  227.     }
  228.     return (0);
  229. }
  230.  
  231.