home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / OS2PLST.SRC / PARSECFG.C < prev    next >
Text File  |  1989-07-16  |  15KB  |  738 lines

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