home *** CD-ROM | disk | FTP | other *** search
/ The Devil's Doorknob BBS Capture (1996-2003) / devilsdoorknobbbscapture1996-2003.iso / WWIV2.ZIP / SUBXTR.C < prev    next >
C/C++ Source or Header  |  1992-12-18  |  7KB  |  263 lines

  1. /*****************************************************************************
  2.  
  3.                 WWIV Version 4
  4.                     Copyright (C) 1988-1993 by Wayne Bell
  5.  
  6. Distribution of the source code for WWIV, in any form, modified or unmodified,
  7. without PRIOR, WRITTEN APPROVAL by the author, is expressly prohibited.
  8. Distribution of compiled versions of WWIV is limited to copies compiled BY
  9. THE AUTHOR.  Distribution of any copies of WWIV not compiled by the author
  10. is expressly prohibited.
  11.  
  12.  
  13. *****************************************************************************/
  14.  
  15. #pragma hdrstop
  16.  
  17. #include <stdio.h>
  18. #include <string.h>
  19. #include <alloc.h>
  20. #include <stdlib.h>
  21. #include <fcntl.h>
  22. #include <io.h>
  23.  
  24. #include "subxtr.h"
  25. #include "vardec.h"
  26. #include "net.h"
  27.  
  28.  
  29. extern configrec syscfg;
  30. extern int net_num_max;
  31. extern net_networks_rec *net_networks;
  32.  
  33. /****************************************************************************/
  34.  
  35. static char *mallocin_file(char *fn, long *len)
  36. {
  37.   char *ss;
  38.   int f;
  39.  
  40.   *len=0;
  41.   ss=NULL;
  42.  
  43.   f=open(fn, O_RDONLY|O_BINARY|O_DENYNONE);
  44.   if (f>0) {
  45.     *len=filelength(f);
  46.     ss=farmalloc(*len+20);
  47.     if (ss) {
  48.       read(f,ss,*len);
  49.       ss[*len]=0;
  50.     }
  51.     close(f);
  52.     return(ss);
  53.   }
  54.   return(ss);
  55. }
  56.  
  57. /****************************************************************************/
  58.  
  59. static char *skipspace(char *ss2)
  60. {
  61.   while ((*ss2) && ((*ss2!=' ') && (*ss2!='\t')))
  62.     ++ss2;
  63.   if (*ss2)
  64.     *ss2++=0;
  65.   while ((*ss2==' ') || (*ss2=='\t'))
  66.     ++ss2;
  67.   return(ss2);
  68. }
  69.  
  70.  
  71. /****************************************************************************/
  72.  
  73. static xtrasubsnetrec *xsubsn;
  74. static int nn;
  75.  
  76. static xtrasubsnetrec *fsub(int netnum, unsigned short type)
  77. {
  78.   int i;
  79.  
  80.   if (type) {
  81.     for (i=0; i<nn; i++) {
  82.       if ((xsubsn[i].net_num==netnum) && (xsubsn[i].type==type))
  83.         return(&(xsubsn[i]));
  84.     }
  85.   }
  86.   return(NULL);
  87. }
  88.  
  89. int read_subs_xtr(int max_subs, int num_subs, subboardrec *subboards)
  90. {
  91.   char *ss,*ss1,*ss2;
  92.   long l;
  93.   int f,n,i,i1,curn;
  94.   char s[81];
  95.   xtrasubsnetrec *xnp;
  96.  
  97.   l=((long)max_subs)*sizeof(xtrasubsrec);
  98.   xsubs=(xtrasubsrec *)farmalloc(l+1);
  99.   if (!xsubs) {
  100.     printf("Insufficient memory (%ld bytes) for SUBS.XTR\n", l);
  101.     return(1);
  102.   }
  103.   memset(xsubs, 0, l);
  104.  
  105.   sprintf(s,"%sSUBS.XTR",syscfg.datadir);
  106.   ss=mallocin_file(s,&l);
  107.   nn=0;
  108.   if (ss) {
  109.     for (ss1=strtok(ss,"\r\n"); ss1; ss1=strtok(NULL,"\r\n")) {
  110.       if (*ss1=='$')
  111.         ++nn;
  112.     }
  113.     farfree(ss);
  114.   } else {
  115.     for (i=0; i<num_subs; i++) {
  116.       if (subboards[i].type)
  117.         ++nn;
  118.     }
  119.   }
  120.   if (nn) {
  121.     l=((long)nn)*sizeof(xtrasubsnetrec);
  122.     xsubsn=(xtrasubsnetrec *)farmalloc(l);
  123.     if (!xsubsn) {
  124.       printf("Insufficient memory (%ld bytes) for net subs info\n", l);
  125.       return(1);
  126.     }
  127.     memset(xsubsn, 0, l);
  128.  
  129.     nn=0;
  130.     ss=mallocin_file(s,&l);
  131.     if (ss) {
  132.       curn=-1;
  133.       for (ss1=strtok(ss,"\r\n"); ss1; ss1=strtok(NULL,"\r\n")) {
  134.         switch(*ss1) {
  135.           case '!': /* sub idx */
  136.             curn=atoi(ss1+1);
  137.             if ((curn<0) || (curn>=num_subs))
  138.               curn=-1;
  139.             break;
  140.           case '@': /* desc */
  141.             if (curn>=0) {
  142.               strncpy(xsubs[curn].desc,ss1+1,60);
  143.             }
  144.             break;
  145.           case '#': /* flags */
  146.             if (curn>=0) {
  147.               xsubs[curn].flags=atol(ss1+1);
  148.             }
  149.             break;
  150.           case '$': /* net info */
  151.             if (curn>=0) {
  152.               if (!xsubs[curn].num_nets)
  153.                 xsubs[curn].nets=&(xsubsn[nn]);
  154.               ss2=skipspace(++ss1);
  155.               for (i=0; i<net_num_max; i++) {
  156.                 if (stricmp(net_networks[i].name, ss1)==0)
  157.                   break;
  158.               }
  159.               if ((i<net_num_max) && (*ss2)) {
  160.                 xsubsn[nn].net_num=i;
  161.                 ss1=ss2;
  162.                 ss2=skipspace(ss2);
  163.                 strncpy(xsubsn[nn].stype,ss1,7);
  164.                 xsubsn[nn].type=atoi(xsubsn[nn].stype);
  165.                 if (xsubsn[nn].type)
  166.                   sprintf(xsubsn[nn].stype,"%u",xsubsn[nn].type);
  167.                 ss1=ss2;
  168.                 ss2=skipspace(ss2);
  169.                 xsubsn[nn].flags=atol(ss1);
  170.                 ss1=ss2;
  171.                 ss2=skipspace(ss2);
  172.                 xsubsn[nn].host=atoi(ss1);
  173.                 ss1=ss2;
  174.                 ss2=skipspace(ss2);
  175.                 xsubsn[nn].category=atoi(ss1);
  176.                 nn++;
  177.                 xsubs[curn].num_nets++;
  178.                 xsubs[curn].num_nets_max++;
  179.               } else {
  180.                 printf("Unknown network '%s' in SUBS.XTR\n",ss1);
  181.               }
  182.             }
  183.             break;
  184.           case 0:
  185.             break;
  186.           default:
  187.             break;
  188.         }
  189.       }
  190.       farfree(ss);
  191.     } else {
  192.       for (curn=0; curn<num_subs; curn++) {
  193.         if (subboards[curn].type) {
  194.           if (subboards[curn].age&0x80)
  195.             xsubsn[nn].net_num=subboards[curn].name[40];
  196.           else
  197.             xsubsn[nn].net_num=0;
  198.           if ((xsubsn[nn].net_num>=0) && (xsubsn[nn].net_num<net_num_max)) {
  199.             xsubs[curn].nets=&(xsubsn[nn]);
  200.             xsubsn[nn].type=subboards[curn].type;
  201.             sprintf(xsubsn[nn].stype,"%u",xsubsn[nn].type);
  202.             nn++;
  203.             xsubs[curn].num_nets=1;
  204.             xsubs[curn].num_nets_max=1;
  205.           }
  206.         }
  207.       }
  208.       for (n=0; n<net_num_max; n++) {
  209.         sprintf(s,"%sALLOW.NET",net_networks[n].dir);
  210.         ss=mallocin_file(s,&l);
  211.         if (ss) {
  212.           for (ss1=strtok(ss," \t\r\n"); ss1; ss1=strtok(NULL," \t\r\n")) {
  213.             xnp=fsub(n, atoi(ss1));
  214.             if (xnp)
  215.               xnp->flags |= XTRA_NET_AUTO_ADDDROP;
  216.           }
  217.           farfree(ss);
  218.         }
  219.  
  220.         sprintf(s,"%sSUBS.PUB",net_networks[n].dir);
  221.         ss=mallocin_file(s,&l);
  222.         if (ss) {
  223.           for (ss1=strtok(ss," \t\r\n"); ss1; ss1=strtok(NULL," \t\r\n")) {
  224.             xnp=fsub(n, atoi(ss1));
  225.             if (xnp)
  226.               xnp->flags |= XTRA_NET_AUTO_INFO;
  227.           }
  228.           farfree(ss);
  229.         }
  230.         sprintf(s,"%sNNALL.NET",net_networks[n].dir);
  231.         ss=mallocin_file(s,&l);
  232.         if (ss) {
  233.           for (ss1=strtok(ss,"\r\n"); ss1; ss1=strtok(NULL,"\r\n")) {
  234.             while ((*ss1==' ') || (*ss1=='\t'))
  235.               ++ss1;
  236.             ss2=skipspace(ss1);
  237.             xnp=fsub(n, atoi(ss1));
  238.             if (xnp)
  239.               xnp->host=atoi(ss2);
  240.           }
  241.           farfree(ss);
  242.         }
  243.       }
  244.       for (i=0; i<nn; i++) {
  245.         if ((xsubsn[i].type) && (!xsubsn[i].host)) {
  246.           sprintf(s,"%sNN%u.NET",
  247.                   net_networks[xsubsn[i].net_num].dir,
  248.                   xsubsn[i].type);
  249.           ss=mallocin_file(s,&l);
  250.           if (ss) {
  251.             for (ss1=ss; (*ss1) && ((*ss1<'0') || (*ss1>'9')); ss1++)
  252.               ;
  253.             xsubsn[i].host=atoi(ss1);
  254.             farfree(ss);
  255.           }
  256.         }
  257.       }
  258.     }
  259.   }
  260.  
  261.   return(0);
  262. }
  263.