home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / com / bbs / squish / typedefs.h < prev   
Encoding:
C/C++ Source or Header  |  1992-02-28  |  4.8 KB  |  295 lines

  1. #ifndef __TYPEDEFS_H_DEFINED
  2. #define __TYPEDEFS_H_DEFINED
  3.  
  4. #define _fast
  5.  
  6. #if defined(__386__) || defined(__FLAT__)
  7.   typedef unsigned      bit;
  8.  
  9.   typedef unsigned char byte;
  10.   typedef signed char   sbyte;
  11.  
  12.   typedef unsigned short word;
  13.   typedef signed short   sword;
  14.  
  15.   typedef unsigned int  dword;
  16.   typedef signed int    sdword;
  17.  
  18.   typedef unsigned short ushort;
  19.   typedef   signed short sshort;
  20.  
  21.   typedef unsigned long  ulong;
  22.   typedef   signed long  slong;
  23. #else
  24.   typedef unsigned      bit;
  25.  
  26.   typedef unsigned char byte;
  27.   typedef signed char   sbyte;
  28.  
  29.   typedef unsigned int  word;
  30.   typedef signed int    sword;
  31.  
  32.   typedef unsigned long dword;
  33.   typedef signed long   sdword;
  34.  
  35.   typedef unsigned short ushort;
  36.   typedef   signed short sshort;
  37.  
  38.   typedef unsigned long  ulong;
  39.   typedef   signed long  slong;
  40. #endif
  41.  
  42. #endif
  43.  
  44. struct _netaddr;
  45. typedef struct _netaddr NETADDR;
  46.  
  47. struct _netaddr
  48. {
  49.   word zone;
  50.   word net;
  51.   word node;
  52.   word point;
  53. };
  54.  
  55.  
  56. #define PATHLEN   120
  57. #define TRUE      1
  58. #define FALSE     0
  59.  
  60. extern void _fast NoMem(void);
  61.  
  62. void * smalloc(unsigned size)
  63. {
  64.   void *mem;
  65.   
  66.   if ((mem=(void *)malloc(size))==NULL)
  67.     NoMem();
  68.  
  69.   memset(mem, '\0', size);
  70.   return mem;
  71. }
  72.  
  73. byte * Address(NETADDR *a)
  74. {
  75.   static char temp[30];
  76.   char point[10];
  77.  
  78.   sprintf(point,".%u",a->point);
  79.   sprintf(temp,"%u:%u/%u%s",a->zone,a->net,a->node,a->point ? point : "");
  80.  
  81.   return temp;
  82. }
  83.  
  84. char * sstrdup(char *s)
  85. {
  86.   char *p;
  87.   
  88.   if ((p=strdup(s))==NULL)
  89.     NoMem();
  90.   
  91.   return p;
  92. }
  93.  
  94. #define eqstri(a, b) (stricmp(a,b)==0)
  95.  
  96. char * firstchar(char *strng,char *delim,int findword)
  97. {
  98.   int x,
  99.       isw,
  100.       sl_d,
  101.       sl_s,
  102.       wordno=0;
  103.  
  104.   char *string,
  105.        *oldstring;
  106.  
  107.   /* We can't do *anything* if the string is blank... */
  108.  
  109.   if (! *strng)
  110.     return NULL;
  111.  
  112.   string=oldstring=strng;
  113.  
  114.   sl_d=strlen(delim);
  115.  
  116.   for (string=strng;*string;string++)
  117.   {
  118.     for (x=0,isw=0;x <= sl_d;x++)
  119.       if (*string==delim[x])
  120.         isw=1;
  121.  
  122.     if (isw==0)
  123.     {
  124.       oldstring=string;
  125.       break;
  126.     }
  127.   }
  128.  
  129.   sl_s=strlen(string);
  130.  
  131.   for (wordno=0;(string-oldstring) < sl_s;string++)
  132.   {
  133.     for (x=0,isw=0;x <= sl_d;x++)
  134.       if (*string==delim[x])
  135.       {
  136.         isw=1;
  137.         break;
  138.       }
  139.  
  140.     if (!isw && string==oldstring)
  141.       wordno++;
  142.  
  143.     if (isw && (string != oldstring))
  144.     {
  145.       for (x=0,isw=0;x <= sl_d;x++) if (*(string+1)==delim[x])
  146.       {
  147.         isw=1;
  148.         break;
  149.       }
  150.  
  151.       if (isw==0)
  152.         wordno++;
  153.     }
  154.  
  155.     if (wordno==findword)
  156.       return((string==oldstring || string==oldstring+sl_s) ? string : string+1);
  157.   }
  158.  
  159.   return NULL;
  160. }
  161.  
  162.  
  163.  
  164.  
  165.  
  166. static char *colon=":";
  167. static char *slash="/";
  168.  
  169. #include <string.h>
  170. #include <ctype.h>
  171. #include <stdlib.h>
  172.  
  173. #define ZONE_ALL  56685u
  174. #define NET_ALL   56685u
  175. #define NODE_ALL  56685u
  176. #define POINT_ALL 56685u
  177.  
  178.  
  179. void ParseNN(char *netnode,word *zone,word *net,word *node,word *point,word all)
  180. {
  181.   char *p;
  182.  
  183.   p=netnode;
  184.   
  185.   if (all && point)
  186.     *point=POINT_ALL;
  187.  
  188.   if (all && toupper(*netnode)=='W')  /* World */
  189.   {
  190.     if (zone)
  191.       *zone=ZONE_ALL;
  192.  
  193.     if (net)
  194.       *net=NET_ALL;
  195.  
  196.     if (node)
  197.       *node=NODE_ALL;
  198.  
  199.     return;
  200.   }
  201.  
  202.   /* If we have a zone (and the caller wants the zone to be passed back).. */
  203.  
  204.   if (strchr(netnode,':'))
  205.   {
  206.     if (zone)
  207.     {
  208.       if (all && toupper(*p)=='A')  /* All */
  209.         *zone=ZONE_ALL;
  210.       else *zone=atoi(p);
  211.     }
  212.  
  213.     p=firstchar(p,colon,2);
  214.   }
  215.  
  216.   /* If we have a net number... */
  217.  
  218.   if (p && *p)
  219.   {
  220.     if (strchr(netnode,'/'))
  221.     {
  222.       if (net)
  223.       {
  224.         if (all && toupper(*p)=='A')  /* All */
  225.           *net=NET_ALL;
  226.         else *net=atoi(p);
  227.       }
  228.  
  229.       p=firstchar(p,slash,2);
  230.     }
  231.     else if (all && toupper(*p)=='A')
  232.     {
  233.       /* If it's in the form "1:All" or "All" */
  234.  
  235.       if (strchr(netnode,':')==NULL && zone)
  236.         *zone=ZONE_ALL;
  237.  
  238.       *net=NET_ALL;
  239.       *node=NODE_ALL;
  240.       p += 3;
  241.     }
  242.   }
  243.  
  244.   /* If we got a node number... */
  245.  
  246.   if (p && *p && node && *netnode != '.')
  247.   {
  248.     if (all && toupper(*p)=='A')  /* All */
  249.     {
  250.       *node=NODE_ALL;
  251.  
  252.       /* 1:249/All implies 1:249/All.All too... */
  253.  
  254.       if (point && all)
  255.         *point=POINT_ALL;
  256.     }
  257.     else *node=atoi(p);
  258.   }
  259.  
  260.   if (p)
  261.     while (*p && isdigit(*p))
  262.       p++;
  263.  
  264.   /* And finally check for a point number... */
  265.  
  266.   if (p && *p=='.')
  267.   {
  268.     p++;
  269.  
  270.     if (point)
  271.     {
  272.       if (!p && *netnode=='.')
  273.         p=netnode+1;
  274.  
  275.       if (p && *p)
  276.       {
  277.         *point=atoi(p);
  278.  
  279.         if (all && toupper(*p)=='A')  /* All */
  280.           *point=POINT_ALL;
  281.       }
  282.       else *point=0;
  283.     }
  284.   }
  285. }
  286.  
  287. #ifdef __WATCOMC__
  288. #define _stdc
  289. #else
  290. #define _stdc cdecl
  291. #endif
  292.  
  293. #define NW(x) (void)x
  294.  
  295.