home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / sqdev200.zip / samples / parsenn.c < prev    next >
C/C++ Source or Header  |  1994-05-23  |  2KB  |  132 lines

  1. #define NOVARS
  2. #define NOVER
  3. #define MAX_NOPROTO
  4.  
  5. #include <string.h>
  6. #include <stdlib.h>
  7. #include <ctype.h>
  8. #include "prog.h"
  9. #include "max.h"
  10.  
  11. static char *colon=":";
  12. static char *slash="/";
  13.  
  14. void _fast ParseNNN(char *netnode, NETADDR *pn, word all)
  15. {
  16.   ParseNN(netnode, &pn->zone, &pn->net, &pn->node, &pn->point, all);
  17. }
  18.  
  19. void _fast Parse_NetNode(char *netnode,word *zone,word *net,word *node,word *point)
  20. {
  21.   ParseNN(netnode,zone,net,node,point,FALSE);
  22. }
  23.  
  24. void _fast ParseNN(char *netnode,word *zone,word *net,word *node,word *point,word all)
  25. {
  26.   char *p;
  27.  
  28.   p=netnode;
  29.   
  30.   if (all && point)
  31.     *point=POINT_ALL;
  32.  
  33.   if (all && toupper(*netnode)=='W')  /* World */
  34.   {
  35.     if (zone)
  36.       *zone=ZONE_ALL;
  37.  
  38.     if (net)
  39.       *net=NET_ALL;
  40.  
  41.     if (node)
  42.       *node=NODE_ALL;
  43.  
  44.     return;
  45.   }
  46.  
  47.   /* If we have a zone (and the caller wants the zone to be passed back).. */
  48.  
  49.   if (strchr(netnode,':'))
  50.   {
  51.     if (zone)
  52.     {
  53.       if (all && toupper(*p)=='A')  /* All */
  54.         *zone=ZONE_ALL;
  55.       else *zone=atoi(p);
  56.     }
  57.  
  58.     p=firstchar(p,colon,2);
  59.   }
  60.  
  61.   /* If we have a net number... */
  62.  
  63.   if (p && *p)
  64.   {
  65.     if (strchr(netnode,'/'))
  66.     {
  67.       if (net)
  68.       {
  69.         if (all && toupper(*p)=='A')  /* All */
  70.           *net=NET_ALL;
  71.         else *net=atoi(p);
  72.       }
  73.  
  74.       p=firstchar(p,slash,2);
  75.     }
  76.     else if (all && toupper(*p)=='A')
  77.     {
  78.       /* If it's in the form "1:All" or "All" */
  79.  
  80.       if (strchr(netnode,':')==NULL && zone)
  81.         *zone=ZONE_ALL;
  82.  
  83.       *net=NET_ALL;
  84.       *node=NODE_ALL;
  85.       p += 3;
  86.     }
  87.   }
  88.  
  89.   /* If we got a node number... */
  90.  
  91.   if (p && *p && node && *netnode != '.')
  92.   {
  93.     if (all && toupper(*p)=='A')  /* All */
  94.     {
  95.       *node=NODE_ALL;
  96.  
  97.       /* 1:249/All implies 1:249/All.All too... */
  98.  
  99.       if (point && all)
  100.         *point=POINT_ALL;
  101.     }
  102.     else *node=atoi(p);
  103.   }
  104.  
  105.   if (p)
  106.     while (*p && isdigit(*p))
  107.       p++;
  108.  
  109.   /* And finally check for a point number... */
  110.  
  111.   if (p && *p=='.')
  112.   {
  113.     p++;
  114.  
  115.     if (point)
  116.     {
  117.       if (!p && *netnode=='.')
  118.         p=netnode+1;
  119.  
  120.       if (p && *p)
  121.       {
  122.         *point=atoi(p);
  123.  
  124.         if (all && toupper(*p)=='A')  /* All */
  125.           *point=POINT_ALL;
  126.       }
  127.       else *point=0;
  128.     }
  129.   }
  130. }
  131.  
  132.