/********************************************************
* File: node2dpat.c
* Created at Sun Jan 28 22:10:31 MSK 2001 by raorn // raorn@binec.ru
* 2D address handling
* $Id: node2dpat.c,v 1.2 2001/02/18 15:26:23 raorn Exp $
*******************************************************/
#include "crashecho.h"
int NodeCompare(uchar * pat, ushort num)
{
uchar buf[10], c;
snprintf(buf, 10, "%u", num);
if (pat[0] == 0)
return (0);
for (c = 0; c < strlen(pat); c++)
{
if (pat[c] == '*')
return (0);
if (pat[c] != buf[c] && pat[c] != '?')
return (1);
if (buf[c] == 0)
return (1);
}
if (buf[c] != 0)
return (1);
return (0);
}
bool Parse2DPat(uchar * buf, struct Node2DPat * node)
{
ulong c = 0, tempc = 0;
uchar temp[10];
bool GotNet = FALSE;
strcpy(node->Net, "*");
strcpy(node->Node, "*");
if (strcmp(buf, "*") == 0)
return (TRUE);
for (c = 0; c < strlen(buf); c++)
{
if (buf[c] == '/')
{
if (GotNet)
return (FALSE);
strcpy(node->Net, temp);
GotNet = TRUE;
tempc = 0;
} else if ((buf[c] >= '0' && buf[c] <= '9') || buf[c] == '*' ||
buf[c] == '?')
{
if (tempc < 9)
{
temp[tempc++] = buf[c];
temp[tempc] = 0;
}
} else
return (FALSE);
}
strcpy(node->Node, temp);
return (TRUE);
}
int Compare2DPat(struct Node2DPat *nodepat, ushort net, ushort node)
{
if (NodeCompare(nodepat->Net, net) != 0)
return (1);
if (NodeCompare(nodepat->Node, node) != 0)
return (1);
return (0);
}
syntax highlighted by Code2HTML, v. 0.9.1