home *** CD-ROM | disk | FTP | other *** search
/ ftp.wwiv.com / ftp.wwiv.com.zip / ftp.wwiv.com / pub / OFFLINE / UQWK18.ZIP / UQWK18.TAR / init.c < prev    next >
C/C++ Source or Header  |  1994-01-21  |  3KB  |  181 lines

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include "uqwk.h"
  4.  
  5. #define QWK_MAGIC "Produced by Qmail...Copyright (c) 1987 by Sparkware.  All rights Reserved"
  6.  
  7. #ifdef SERVER
  8. #include "nntp.h"
  9. extern void connect_nntp();
  10. #endif
  11.  
  12. InitStuff()
  13. /*
  14.  *  Initialize stuff
  15.  */
  16. {
  17.     char msg_fname[PATH_LEN];
  18.     int n;
  19.  
  20.     /* Mail, conference, etc. lists */
  21.     mail_list = NULL;
  22.     conf_list = NULL;
  23.     last_conf = NULL;
  24.     act_list = NULL;
  25.     nrc_list = NULL;
  26.     trn_list = NULL;
  27.     ng_list = NULL;
  28.  
  29.     /* Message and conference counts */
  30.     msg_cnt = 0;
  31.     conf_cnt = 0;
  32.  
  33.     /* Kludge around fclose() bug in close.c */
  34.     msg_fd = NULL;
  35.  
  36.     /* Open MESSAGES.DAT */
  37.     if (!slnp_mode && !zip_mode && !sum_mode)
  38.     {
  39.         strcpy (msg_fname, home_dir);
  40.         strcat (msg_fname, "/");
  41.         strcat (msg_fname, "messages.dat");
  42.  
  43.         if (NULL == (msg_fd = fopen (msg_fname, "w")))
  44.         {
  45.             fprintf (stderr, "%s: can't open %s\n",
  46.                 progname, msg_fname);
  47.             exit (0);
  48.         }
  49.  
  50.         /* Write magic string to MESSAGES.DAT */
  51.         fprintf (msg_fd, QWK_MAGIC);
  52.         n = 128 - strlen (QWK_MAGIC);
  53.         while (n--) fputc (' ', msg_fd);
  54.         blk_cnt = 2;
  55.     }
  56.  
  57.     /* Open summary file */
  58.     if (sum_mode)
  59.     {
  60.         if (NULL == (sum_fd = fopen (sum_file, "w")))
  61.         {
  62.             fprintf (stderr, "%s: can't open %s\n",
  63.                     progname, sum_file);
  64.             exit (0);
  65.         }
  66.     }
  67.  
  68.     /* Read the ng trans table if specified */
  69.     if (strcmp (trn_file, DEF_TRN_FILE)) ReadTrans();
  70.  
  71.     /* Read the desired newsgroups file if specified */
  72.     if (strcmp (ng_file, DEF_NG_FILE)) ReadNG();
  73.  
  74. #ifdef SERVER
  75.     if (strcmp (rep_file, DEF_REP_FILE) || do_news) connect_nntp();
  76. #endif
  77. }
  78.  
  79. ReadTrans()
  80. /*
  81.  *  Read the newsgroup name translation table
  82.  */
  83. {
  84.     FILE *trn_fd;
  85.     struct trn_ent *tp;
  86.     char n1[PATH_LEN], n2[PATH_LEN];
  87.  
  88.     /* Open the file */
  89.     if (NULL == (trn_fd = fopen (trn_file, "r")))
  90.     {
  91.         fprintf (stderr, "%s: can't open %s, tran table not used\n",
  92.             progname, trn_file);
  93.         return (0);
  94.     }
  95.  
  96.     /* Read through the file */
  97.     while (2 == fscanf (trn_fd, "%s %s", n1, n2))
  98.     {
  99.         /* Get space for new list entry */
  100.  
  101.         if (NULL == (tp = (struct trn_ent *)
  102.                 malloc (sizeof (struct trn_ent))))    
  103.         {
  104.             OutOfMemory();
  105.         }
  106.         if (NULL == (tp->old = (char *) malloc (strlen(n1)+1)))
  107.         {
  108.             OutOfMemory();
  109.         }
  110.         if (NULL == (tp->new = (char *) malloc (strlen(n2)+1)))
  111.         {
  112.             OutOfMemory();
  113.         }
  114.  
  115.         /* Fill in new entry */
  116.         strcpy (tp->old, n1);
  117.         strcpy (tp->new, n2);
  118.  
  119.         /* Add to list */
  120.         tp->next = trn_list;
  121.         trn_list = tp;
  122.     }
  123.  
  124.     fclose (trn_fd);
  125.     return (0);
  126. }
  127.  
  128. ReadNG()
  129. /*
  130.  *  Read the desired newsgroups file
  131.  */
  132. {
  133.     FILE *ng_fd;
  134.     struct ng_ent *np, *last_np;
  135.     char n[PATH_LEN];
  136.  
  137.     /* Open the file */
  138.     if (NULL == (ng_fd = fopen (ng_file, "r")))
  139.     {
  140.         fprintf (stderr, "%s: can't open %s, ng file not used\n",
  141.             progname, ng_file);
  142.         return (0);
  143.     }
  144.  
  145.     /* Read through the file */
  146.     while (1 == fscanf (ng_fd, "%s", n))
  147.     {
  148.         /* Get space for new list entry */
  149.  
  150.         if (NULL == (np = (struct ng_ent *)
  151.                 malloc (sizeof (struct ng_ent))))    
  152.         {
  153.             OutOfMemory();
  154.         }
  155.         if (NULL == (np->name = (char *) malloc (strlen(n)+1)))
  156.         {
  157.             OutOfMemory();
  158.         }
  159.  
  160.         /* Fill in new entry */
  161.         strcpy (np->name, n);
  162.  
  163.         /* Add to list */
  164.         if (ng_list == NULL)
  165.         {
  166.             /* First one */
  167.             ng_list = np;
  168.         }
  169.         else
  170.         {
  171.             /* Add to end */
  172.             last_np->next = np;
  173.         }
  174.         np->next = NULL;
  175.         last_np = np;
  176.     }
  177.  
  178.     fclose (ng_fd);
  179.     return (0);
  180. }
  181.