home *** CD-ROM | disk | FTP | other *** search
/ ftp.wwiv.com / ftp.wwiv.com.zip / ftp.wwiv.com / pub / MISC / SQDEV200.ZIP / SRC / PARSENN.C < prev    next >
C/C++ Source or Header  |  1994-05-23  |  4KB  |  155 lines

  1. /***************************************************************************
  2.  *                                                                         *
  3.  *  Squish Developers Kit Source, Version 2.00                             *
  4.  *  Copyright 1989-1994 by SCI Communications.  All rights reserved.       *
  5.  *                                                                         *
  6.  *  USE OF THIS FILE IS SUBJECT TO THE RESTRICTIONS CONTAINED IN THE       *
  7.  *  SQUISH DEVELOPERS KIT LICENSING AGREEMENT IN SQDEV.PRN.  IF YOU DO NOT *
  8.  *  FIND THE TEXT OF THIS AGREEMENT IN THE AFOREMENTIONED FILE, OR IF YOU  *
  9.  *  DO NOT HAVE THIS FILE, YOU SHOULD IMMEDIATELY CONTACT THE AUTHOR AT    *
  10.  *  ONE OF THE ADDRESSES LISTED BELOW.  IN NO EVENT SHOULD YOU PROCEED TO  *
  11.  *  USE THIS FILE WITHOUT HAVING ACCEPTED THE TERMS OF THE SQUISH          *
  12.  *  DEVELOPERS KIT LICENSING AGREEMENT, OR SUCH OTHER AGREEMENT AS YOU ARE *
  13.  *  ABLE TO REACH WITH THE AUTHOR.                                         *
  14.  *                                                                         *
  15.  *  You can contact the author at one of the address listed below:         *
  16.  *                                                                         *
  17.  *  Scott Dudley       FidoNet     1:249/106                               *
  18.  *  777 Downing St.    Internet    sjd@f106.n249.z1.fidonet.org            *
  19.  *  Kingston, Ont.     CompuServe  >INTERNET:sjd@f106.n249.z1.fidonet.org  *
  20.  *  Canada  K7M 5N3    BBS         1-613-634-3058, V.32bis                 *
  21.  *                                                                         *
  22.  ***************************************************************************/
  23.  
  24. #define NOVARS
  25. #define NOVER
  26. #define MAX_NOPROTO
  27.  
  28. #include <string.h>
  29. #include <stdlib.h>
  30. #include <ctype.h>
  31. #include "prog.h"
  32. #include "max.h"
  33.  
  34. static char *colon=":";
  35. static char *slash="/";
  36.  
  37. void _fast ParseNNN(char *netnode, NETADDR *pn, word all)
  38. {
  39.   ParseNN(netnode, &pn->zone, &pn->net, &pn->node, &pn->point, all);
  40. }
  41.  
  42. void _fast Parse_NetNode(char *netnode,word *zone,word *net,word *node,word *point)
  43. {
  44.   ParseNN(netnode,zone,net,node,point,FALSE);
  45. }
  46.  
  47. void _fast ParseNN(char *netnode,word *zone,word *net,word *node,word *point,word all)
  48. {
  49.   char *p;
  50.  
  51.   p=netnode;
  52.   
  53.   if (all && point)
  54.     *point=POINT_ALL;
  55.  
  56.   if (all && toupper(*netnode)=='W')  /* World */
  57.   {
  58.     if (zone)
  59.       *zone=ZONE_ALL;
  60.  
  61.     if (net)
  62.       *net=NET_ALL;
  63.  
  64.     if (node)
  65.       *node=NODE_ALL;
  66.  
  67.     return;
  68.   }
  69.  
  70.   /* If we have a zone (and the caller wants the zone to be passed back).. */
  71.  
  72.   if (strchr(netnode,':'))
  73.   {
  74.     if (zone)
  75.     {
  76.       if (all && toupper(*p)=='A')  /* All */
  77.         *zone=ZONE_ALL;
  78.       else *zone=atoi(p);
  79.     }
  80.  
  81.     p=firstchar(p,colon,2);
  82.   }
  83.  
  84.   /* If we have a net number... */
  85.  
  86.   if (p && *p)
  87.   {
  88.     if (strchr(netnode,'/'))
  89.     {
  90.       if (net)
  91.       {
  92.         if (all && toupper(*p)=='A')  /* All */
  93.           *net=NET_ALL;
  94.         else *net=atoi(p);
  95.       }
  96.  
  97.       p=firstchar(p,slash,2);
  98.     }
  99.     else if (all && toupper(*p)=='A')
  100.     {
  101.       /* If it's in the form "1:All" or "All" */
  102.  
  103.       if (strchr(netnode,':')==NULL && zone)
  104.         *zone=ZONE_ALL;
  105.  
  106.       *net=NET_ALL;
  107.       *node=NODE_ALL;
  108.       p += 3;
  109.     }
  110.   }
  111.  
  112.   /* If we got a node number... */
  113.  
  114.   if (p && *p && node && *netnode != '.')
  115.   {
  116.     if (all && toupper(*p)=='A')  /* All */
  117.     {
  118.       *node=NODE_ALL;
  119.  
  120.       /* 1:249/All implies 1:249/All.All too... */
  121.  
  122.       if (point && all)
  123.         *point=POINT_ALL;
  124.     }
  125.     else *node=atoi(p);
  126.   }
  127.  
  128.   if (p)
  129.     while (*p && isdigit(*p))
  130.       p++;
  131.  
  132.   /* And finally check for a point number... */
  133.  
  134.   if (p && *p=='.')
  135.   {
  136.     p++;
  137.  
  138.     if (point)
  139.     {
  140.       if (!p && *netnode=='.')
  141.         p=netnode+1;
  142.  
  143.       if (p && *p)
  144.       {
  145.         *point=atoi(p);
  146.  
  147.         if (all && toupper(*p)=='A')  /* All */
  148.           *point=POINT_ALL;
  149.       }
  150.       else *point=0;
  151.     }
  152.   }
  153. }
  154.  
  155.