home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / PLST_133.SZH / PARSECFG.C < prev    next >
Text File  |  1991-09-20  |  21KB  |  734 lines

  1. /*
  2.                               Nodelist Parser
  3.  
  4.               This module was originally written by Bob Hartman
  5.                        Sysop of FidoNet node 1:104/501
  6.  
  7.  This program source code is being released with the following provisions:
  8.  
  9.  1.  You are  free to make  changes to this source  code for use on your own
  10.  machine,  however,  altered source files may not be distributed without the
  11.  consent of Spark Software.
  12.  
  13.  2.  You may distribute "patches"  or  "diff" files for any changes that you
  14.  have made, provided that the "patch" or "diff" files are also sent to Spark
  15.  Software for inclusion in future releases of the entire package.   A "diff"
  16.  file for the source archives may also contain a compiled version,  provided
  17.  it is  clearly marked as not  being created  from the original source code.
  18.  No other  executable  versions may be  distributed without  the  consent of
  19.  Spark Software.
  20.  
  21.  3.  You are free to include portions of this source code in any program you
  22.  develop, providing:  a) Credit is given to Spark Software for any code that
  23.  may is used, and  b) The resulting program is free to anyone wanting to use
  24.  it, including commercial and government users.
  25.  
  26.  4.  There is  NO  technical support  available for dealing with this source
  27.  code, or the accompanying executable files.  This source  code  is provided
  28.  as is, with no warranty expressed or implied (I hate legalease).   In other
  29.  words, if you don't know what to do with it,  don't use it,  and if you are
  30.  brave enough to use it, you're on your own.
  31.  
  32. */
  33.  
  34. #include <stdio.h>
  35. #include <ctype.h>
  36. #include <sys/types.h>
  37. #include <sys/stat.h>
  38. #include <time.h>
  39. #include <stdlib.h>
  40. #include <math.h>
  41. #include <string.h>
  42.  
  43. #include "types.h"
  44. #include "externs.h"
  45.  
  46. static char t_buff[128];
  47.  
  48. void parse_config (char *filename,char *mylist,char *pvtlist)
  49. {
  50.    FILE *f1;
  51.    PWTRP tpw;
  52.    PHTRP tph;
  53.    BDTRP tbd;
  54.    DLTRP tdl;
  55.    COTRP tco;
  56.    ETTRP tet;
  57.    CMTRP tcm;
  58.    FNLSTP tfn;
  59.    int foo1;
  60.    char *p, *p1, *p2, *p3;
  61. /* extern char *strchr(); */
  62.  
  63.    /* Need to read in the configuration options from control file */
  64.    if ((f1 = fopen (filename, "r")) != NULL)
  65.       {
  66.       strupr (filename);
  67.       printf ("Processing Configuration File '%s'\n", filename);
  68.  
  69.       if(mylist)
  70.          {
  71.          tfn = (FNLSTP) mymalloc (sizeof (FNLST));
  72.          tfn->fname = mymalloc (64);
  73.          tfn->fname=mylist;
  74.          mylist=NULL;
  75.          strupr (tfn->fname);
  76.          tfn->next = NULL;
  77.          tfn->private = 1;
  78.          fn->next = tfn;
  79.          fn = tfn;
  80.          }
  81.  
  82.       if(pvtlist)
  83.          {
  84.          tfn = (FNLSTP) mymalloc (sizeof (FNLST));
  85.          tfn->fname = mymalloc (64);
  86.          tfn->fname=pvtlist;
  87.          strupr (tfn->fname);
  88.          pvtlist=NULL;
  89.          tfn->next = NULL;
  90.          tfn->private = 1;
  91.          fn->next = tfn;
  92.          fn = tfn;
  93.          }
  94.  
  95.       while (fgets (t_buff, 127, f1) != NULL)
  96.          {
  97.          if ((p3 = strchr (t_buff, ';')) != NULL)
  98.             *p3 = '\0';
  99.  
  100.          p2 = t_buff;
  101.          while ((*p2) && (isspace (*p2)))
  102.             {
  103.             ++p2;
  104.             }
  105.  
  106.          if ((*p2 == ';') || isspace (*p2) || (*p2 == '\0'))
  107.             continue;
  108.  
  109.          if (strnicmp (p2, "publist", 7) == 0)
  110.             {
  111.             printf ("PUBLIST statement not supported\n");
  112.             continue;
  113.             }
  114.          if (strnicmp (p2, "cleanup", 7) == 0)
  115.             {
  116.             printf ("CLEANUP statement not supported\n");
  117.             continue;
  118.             }
  119.          if (strnicmp (p2, "ozone", 5) == 0)
  120.             {
  121.             printf ("OZONE statement not supported\n");
  122.             continue;
  123.             }
  124.          if (strnicmp (p2, "addr", 4) == 0)
  125.             {
  126.             printf ("ADDR statement not supported\n");
  127.             continue;
  128.             }
  129.          if (strnicmp (p2, "points", 6) == 0)
  130.             {
  131.             printf ("POINTS statement not supported\n");
  132.             continue;
  133.             }
  134.          if (strnicmp (p2, "index", 5) == 0)
  135.             {
  136.             printf ("INDEX statement not supported\n");
  137.             continue;
  138.             }
  139.          if (strnicmp (p2, "sindex", 6) == 0)
  140.             {
  141.             printf ("SINDEX statement not supported\n");
  142.             continue;
  143.             }
  144.  
  145.          if (strnicmp (p2, "fidoprn", 7) == 0)
  146.             {
  147.             fidoprn = 1;
  148.             continue;
  149.             }
  150.          if (strnicmp (p2, "fidotxt", 7) == 0)
  151.             {
  152.             fidotxt = 1;
  153.             continue;
  154.             }
  155.          if (strnicmp (p2, "nofidolist", 10) == 0)
  156.             {
  157.             fidoprn = 0;
  158.             fidotxt = 0;
  159.             continue;
  160.             }
  161.          if (strnicmp (p2, "noindex", 7) == 0)
  162.             {
  163.             do_index = 0;
  164.             continue;
  165.             }
  166.          if (strnicmp (p2, "nopoints", 8) == 0)
  167.             {
  168.             do_points = 0;
  169.             continue;
  170.             }
  171.          if ((strnicmp (p2, "seadog", 6) == 0) ||
  172.              (strnicmp (p2, "gated", 5) == 0))
  173.             {
  174.             out_type = 1;
  175.             continue;
  176.             }
  177.          if ((strnicmp (p2, "fido", 4) == 0) ||
  178.              (strnicmp (p2, "opus", 4) == 0) ||
  179.              (strnicmp (p2, "binkley", 7) == 0) ||
  180.              (strnicmp (p2, "complete", 8) == 0))
  181.             {
  182.             out_type = 0;
  183.             continue;
  184.             }
  185.          if (strnicmp (p2, "version7", 8) == 0)
  186.             {
  187.             version7 = 1;
  188.             continue;
  189.             }
  190.          if ((strnicmp (p2, "newopus", 7) == 0) || (strnicmp (p2, "version6", 8) == 0))
  191.             {
  192.             version6 = 1;
  193.             continue;
  194.             }
  195.          if ((strnicmp (p2, "oldopus", 7) == 0) || (strnicmp (p2, "version5", 8) == 0))
  196.             {
  197.             version5 = 1;
  198.             continue;
  199.             }
  200.          if (strnicmp (p2, "tbbslist", 8) == 0)
  201.             {
  202.             sealist = 1;
  203.             continue;
  204.             }
  205.          if (strnicmp (p2, "binklist", 8) == 0)
  206.             {
  207.             binkley = 1;
  208.             continue;
  209.             }
  210.          if (strnicmp (p2, "quickbbslist", 12) == 0)
  211.             {
  212.             quickbbs = 1;
  213.             continue;
  214.             }
  215.          if (strnicmp (p2, "igate", 5) == 0)
  216.             {
  217.             tet = (ETTRP) mymalloc (sizeof (ETTR));
  218.             get_addr (&p2[5], &(tet->zone), &(tet->net), &(tet->node));
  219.             tet->etype = 'I';
  220.             tet->next = NULL;
  221.             if (et_head == NULL)
  222.                {
  223.                et_head = tet;
  224.                }
  225.             else
  226.                {
  227.                et->next = tet;
  228.                }
  229.             et = tet;
  230.             continue;
  231.             }
  232.          if (strnicmp (p2, "ogate", 5) == 0)
  233.             {
  234.             tet = (ETTRP) mymalloc (sizeof (ETTR));
  235.             get_addr (&p2[5], &(tet->zone), &(tet->net), &(tet->node));
  236.             tet->etype = 'O';
  237.             tet->next = NULL;
  238.             if (et_head == NULL)
  239.                {
  240.                et_head = tet;
  241.                }
  242.             else
  243.                {
  244.                et->next = tet;
  245.                }
  246.             et = tet;
  247.             continue;
  248.             }
  249.          if (strnicmp (p2, "gate", 4) == 0)
  250.             {
  251.             tet = (ETTRP) mymalloc (sizeof (ETTR));
  252.             get_addr (&p2[4], &(tet->zone), &(tet->net), &(tet->node));
  253.             tet->etype = 'G';
  254.             tet->next = NULL;
  255.             if (et_head == NULL)
  256.                {
  257.                et_head = tet;
  258.                }
  259.             else
  260.                {
  261.                et->next = tet;
  262.                }
  263.             et = tet;
  264.             continue;
  265.             }
  266.          if (strnicmp (p2, "hub", 3) == 0)
  267.             {
  268.             tet = (ETTRP) mymalloc (sizeof (ETTR));
  269.             get_addr (&p2[3], &(tet->zone), &(tet->net), &(tet->node));
  270.             tet->etype = 'H';
  271.             tet->next = NULL;
  272.             if (et_head == NULL)
  273.                {
  274.                et_head = tet;
  275.                }
  276.             else
  277.                {
  278.                et->next = tet;
  279.                }
  280.             et = tet;
  281.             continue;
  282.             }
  283.          if (strnicmp (p2, "include", 7) == 0)
  284.             {
  285.             p = &p2[7];
  286.             while ((*p) && isspace (*p))
  287.                {
  288.                ++p;
  289.                }
  290.  
  291.             p1 = p;
  292.             while ((*p) && (!isspace (*p)))
  293.                {
  294.                ++p;
  295.                }
  296.             *p = '\0';
  297.  
  298.             parse_config (p1, mylist, pvtlist);
  299.             printf ("Continuing Processing on File '%s'\n", filename);
  300.             continue;
  301.             }
  302.          if (strnicmp (p2, "comments", 8) == 0)
  303.             {
  304.             comments = 1;
  305.             continue;
  306.             }
  307.          if (strnicmp (p2, "nocomments", 10) == 0)
  308.             {
  309.             comments = 0;
  310.             continue;
  311.             }
  312.          if (strnicmp (p2, "usezone", 7) == 0)
  313.             {
  314.             usezone = 1;
  315.             continue;
  316.             }
  317.          if (strnicmp (p2, "report", 6) == 0)
  318.             {
  319.             doreport = 1;
  320.             continue;
  321.             }
  322.          if (strnicmp (p2, "noreport", 8) == 0)
  323.             {
  324.             doreport = 0;
  325.             continue;
  326.             }
  327.          if (strnicmp (p2, "dash", 4) == 0)
  328.             {
  329.             nodash = 0;
  330.             continue;
  331.             }
  332.          if (strnicmp (p2, "nodash", 6) == 0)
  333.             {
  334.             nodash = 1;
  335.             continue;
  336.             }
  337.          if (strnicmp (p2, "nonodelist", 10) == 0)
  338.             {
  339.             nlist = 0;
  340.             continue;
  341.             }
  342.          if (strnicmp (p2, "nodelist", 8) == 0)
  343.             {
  344.             nlist = 1;
  345.             continue;
  346.             }
  347.          if (strnicmp (p2, "nouserlist", 10) == 0)
  348.             {
  349.             udata = 0;
  350.             continue;
  351.             }
  352.          if (strnicmp (p2, "userlist", 8) == 0)
  353.             {
  354.             udata = 2;
  355.             continue;
  356.             }
  357.          if (strnicmp (p2, "interlist", 9) == 0)
  358.             {
  359.             udata = 1;
  360.             continue;
  361.             }
  362.          if (strnicmp (p2, "node", 4) == 0)
  363.             {
  364.             if (sscanf (&p2[4], "%d:%d/%d", &myzone, &mynet, &mynode) != 3)
  365.                {
  366.                myzone = -1;
  367.                if (sscanf (&p2[4], "%d/%d", &mynet, &mynode) != 2)
  368.                   {
  369.                   continue;
  370.                   }
  371.                }
  372.             continue;
  373.             }
  374.          if (strnicmp (p2, "route", 5) == 0)
  375.             {
  376.             rdata = 1;
  377.             continue;
  378.             }
  379.          if (strnicmp (p2, "noroute", 7) == 0)
  380.             {
  381.             rdata = 0;
  382.             continue;
  383.             }
  384.          if (strnicmp (p2, "country", 7) == 0)
  385.             {
  386.             sscanf (&p2[7], "%s", country);
  387.             continue;
  388.             }
  389.          if (strnicmp (p2, "mylist", 6) == 0)
  390.             {
  391.             tfn = (FNLSTP) mymalloc (sizeof (FNLST));
  392.             tfn->fname = mymalloc (64);
  393.             sscanf (&p2[7], "%s", tfn->fname);
  394.             strupr (tfn->fname);
  395.             tfn->next = NULL;
  396.             tfn->private = 0;
  397.             fn->next = tfn;
  398.             fn = tfn;
  399.             continue;
  400.             }
  401.          if (strnicmp (p2, "pvtlist", 7) == 0)
  402.             {
  403.             tfn = (FNLSTP) mymalloc (sizeof (FNLST));
  404.             tfn->fname = mymalloc (64);
  405.             sscanf (&p2[7], "%s", tfn->fname);
  406.             strupr (tfn->fname);
  407.             tfn->next = NULL;
  408.             tfn->private = 1;
  409.             fn->next = tfn;
  410.             fn = tfn;
  411.             continue;
  412.             }
  413.          if (strnicmp (p2, "maxbaud", 7) == 0)
  414.             {
  415.             maxbaud = atoi (&p2[7]);
  416.             continue;
  417.             }
  418.          if (strnicmp (p2, "phone", 5) == 0)
  419.             {
  420.             tph = (PHTRP) mymalloc (sizeof (PHTR));
  421.             tph->num = mymalloc (30);
  422.             if (sscanf (&p2[5], "%d:%d/%d %s", &(tph->zone), &(tph->net), &(tph->node), tph->num) != 4)
  423.                {
  424.                tph->zone = myzone;
  425.                sscanf (&p2[5], "%d/%d %s", &(tph->net), &(tph->node), tph->num);
  426.                }
  427.             tph->next = NULL;
  428.             if (ph_head == NULL)
  429.                {
  430.                ph_head = tph;
  431.                }
  432.             else
  433.                {
  434.                ph->next = tph;
  435.                }
  436.             ph = tph;
  437.             continue;
  438.             }
  439.          if (strnicmp (p2, "password", 8) == 0)
  440.             {
  441.             tpw = (PWTRP) mymalloc (sizeof (PWTR));
  442.             tpw->pw = mymalloc (30);
  443.             if (sscanf (&p2[8], "%d:%d/%d %s", &(tpw->zone), &(tpw->net), &(tpw->node), &(tpw->pw[1])) != 4)
  444.                {
  445.                sscanf (&p2[8], "%d/%d %s", &(tpw->net), &(tpw->node), &(tpw->pw[1]));
  446.                tpw->zone = myzone;
  447.                }
  448.             tpw->pw[0] = '!';
  449.             strlwr (tpw->pw);
  450.             tpw->next = NULL;
  451.             if (pw_head == NULL)
  452.                {
  453.                pw_head = tpw;
  454.                }
  455.             else
  456.                {
  457.                pw->next = tpw;
  458.                }
  459.             pw = tpw;
  460.             continue;
  461.             }
  462.          if (strnicmp (p2, "cm", 2) == 0)
  463.             {
  464.             tcm = (CMTRP) mymalloc (sizeof (CMTR));
  465.             get_addr (&p2[2], &(tcm->zone), &(tcm->net), &(tcm->node));
  466.             tcm->next = NULL;
  467.             if (cm_head == NULL)
  468.                {
  469.                cm_head = tcm;
  470.                }
  471.             else
  472.                {
  473.                cm->next = tcm;
  474.                }
  475.             cm = tcm;
  476.             continue;
  477.             }
  478.          if (strnicmp (p2, "baud", 4) == 0)
  479.             {
  480.             tbd = (BDTRP) mymalloc (sizeof (BDTR));
  481.             if (sscanf (&p2[4], "%d:%d/%d %d", &(tbd->zone), &(tbd->net), &(tbd->node), &(tbd->baud)) != 4)
  482.                {
  483.                sscanf (&p2[4], "%d/%d %d", &(tbd->net), &(tbd->node), &(tbd->baud));
  484.                tbd->zone = myzone;
  485.                }
  486.             tbd->next = NULL;
  487.             if (bd_head == NULL)
  488.                {
  489.                bd_head = tbd;
  490.                }
  491.             else
  492.                {
  493.                bd->next = tbd;
  494.                }
  495.             bd = tbd;
  496.             continue;
  497.             }
  498.          if (strnicmp (p2, "dial", 4) == 0)
  499.             {
  500.             /* Save the defaults */
  501.             strcpy (t_str, &p2[4]);
  502.  
  503.             while (fgets (t_buff, 127, f1) != NULL)
  504.                {
  505.                p2 = t_buff;
  506.                if ((p3 = strchr (p2, ';')) != NULL)
  507.                   *p3 = '\0';
  508.  
  509.                while (isspace (*p2) && *p2)
  510.                   ++p2;
  511.  
  512.                if (strnicmp (p2, "end", 3) == 0)
  513.                   {
  514.                   break;
  515.                   }
  516.  
  517.                /* Process each line of dial */
  518.                p = p2;
  519.                while ((*p) && (isspace (*p)))
  520.                   {
  521.                   ++p;
  522.                   }
  523.  
  524.                if ((*p == ';') || (*p == '\0'))
  525.                   {
  526.                   continue;
  527.                   }
  528.  
  529.                tdl = (DLTRP) mymalloc (sizeof (DLTR));
  530.                tdl->mstr = mymalloc (30);
  531.                tdl->pre  = mymalloc (30);
  532.                tdl->post = mymalloc (30);
  533.  
  534.                p1 = tdl->mstr;
  535.                while ((*p) && (!isspace (*p)))
  536.                   {
  537.                   *p1++ = *p++;
  538.                   }
  539.                *p1 = '\0';
  540.  
  541.                while ((*p) && (isspace (*p)))
  542.                   {
  543.                   ++p;
  544.                   }
  545.  
  546.                p1 = tdl->pre;
  547.                while ((*p) && (*p != '/') && (!isspace(*p)))
  548.                   {
  549.                   *p1++ = *p++;
  550.                   }
  551.                *p1 = '\0';
  552.  
  553.                p1 = tdl->post;
  554.                if ((*p == '\0') || (isspace (*p)))
  555.                   {
  556.                   *p1 = '\0';
  557.                   }
  558.                else
  559.                   {
  560.                   ++p;
  561.  
  562.                   while ((*p) && (!isspace (*p)))
  563.                      {
  564.                      *p1++ = *p++;
  565.                      }
  566.                   *p1 = '\0';
  567.                   }
  568.  
  569.                tdl->mlen = strlen (tdl->mstr);
  570.                tdl->next = NULL;
  571.                if (dl_head == NULL)
  572.                   {
  573.                   dl_head = tdl;
  574.                   }
  575.                else
  576.                   {
  577.                   dl->next = tdl;
  578.                   }
  579.                dl = tdl;
  580.                }
  581.  
  582.             tdl = (DLTRP) mymalloc (sizeof (DLTR));
  583.             tdl->mstr = country;
  584.             tdl->mlen = strlen (country);
  585.             tdl->next = NULL;
  586.             tdl->pre  = mymalloc (30);
  587.             tdl->post = mymalloc (30);
  588.  
  589.             p = t_str;
  590.             while ((*p) && (isspace (*p)))
  591.                {
  592.                ++p;
  593.                }
  594.  
  595.             p1 = tdl->pre;
  596.             while ((*p) && (*p != '/') && (!isspace(*p)))
  597.                {
  598.                *p1++ = *p++;
  599.                }
  600.             *p1 = '\0';
  601.             strcat (tdl->pre, country);
  602.  
  603.             p1 = tdl->post;
  604.             if ((*p == '\0') || (isspace (*p)))
  605.                {
  606.                *p1 = '\0';
  607.                }
  608.             else
  609.                {
  610.                ++p;
  611.  
  612.                while ((*p) && (!isspace (*p)))
  613.                   {
  614.                   *p1++ = *p++;
  615.                   }
  616.                *p1 = '\0';
  617.                }
  618.  
  619.             while ((*p) && (isspace (*p)))
  620.                {
  621.                ++p;
  622.                }
  623.  
  624.             p1 = intl_pre_dl;
  625.             while ((*p) && (*p != '/') && (!isspace(*p)))
  626.                {
  627.                *p1++ = *p++;
  628.                }
  629.             *p1 = '\0';
  630.  
  631.             p1 = intl_post_dl;
  632.             if ((*p == '\0') || (isspace (*p)))
  633.                {
  634.                *p1 = '\0';
  635.                }
  636.             else
  637.                {
  638.                ++p;
  639.  
  640.                while ((*p) && (!isspace (*p)))
  641.                   {
  642.                   *p1++ = *p++;
  643.                   }
  644.                *p1 = '\0';
  645.                }
  646.  
  647.             if (dl_head == NULL)
  648.                {
  649.                dl_head = tdl;
  650.                }
  651.             else
  652.                {
  653.                dl->next = tdl;
  654.                }
  655.             dl = tdl;
  656.  
  657.             continue;
  658.             }
  659.          if (strnicmp (p2, "cost", 4) == 0)
  660.             {
  661.             /* Save the defaults */
  662.             strcpy (t_str, p2);
  663.             sscanf (&t_str[4], "%d %d", &foo1, &intl_cost);
  664.  
  665.             while (fgets (p2, 127, f1) != NULL)
  666.                {
  667.                if ((p3 = strchr (p2, ';')) != NULL)
  668.                   *p3 = '\0';
  669.  
  670.                if (strnicmp (p2, "end", 3) == 0)
  671.                   {
  672.                   break;
  673.                   }
  674.  
  675.                p = p2;
  676.                while ((*p) && (isspace (*p)))
  677.                   {
  678.                   ++p;
  679.                   }
  680.  
  681.                /* Process each line of cost */
  682.                if ((*p == ';') || (*p == '\0'))
  683.                   {
  684.                   continue;
  685.                   }
  686.  
  687.                tco = (COTRP) mymalloc (sizeof (COTR));
  688.                tco->mstr = mymalloc (30);
  689.                tco->cost = foo1;
  690.                tco->baud = 0;
  691.  
  692.                if (sscanf (p, "%s %d %d\n", tco->mstr, &(tco->cost), &(tco->baud)) == 1)
  693.                   {
  694.                   tco->cost = foo1;
  695.                   tco->baud = 0;
  696.                   }
  697.  
  698.                tco->mlen = strlen (tco->mstr);
  699.                tco->next = NULL;
  700.                if (co_head == NULL)
  701.                   {
  702.                   co_head = tco;
  703.                   }
  704.                else
  705.                   {
  706.                   co->next = tco;
  707.                   }
  708.                co = tco;
  709.                }
  710.  
  711.             tco = (COTRP) mymalloc (sizeof (COTR));
  712.             tco->mstr = country;
  713.             tco->mlen = strlen (country);
  714.             sscanf (&t_str[4], "%d %d", &(tco->cost), &intl_cost);
  715.             tco->baud = 0;
  716.             tco->next = NULL;
  717.             if (co_head == NULL)
  718.                {
  719.                co_head = tco;
  720.                }
  721.             else
  722.                {
  723.                co->next = tco;
  724.                }
  725.             co = tco;
  726.  
  727.             continue;
  728.             }
  729.          printf ("Cannot decipher line:\n%s", p2);
  730.          }
  731.       fclose (f1);
  732.       }
  733. }
  734.