home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 2 BBS
/
02-BBS.zip
/
XGRP_000.SZH
/
PATH.C
< prev
next >
Wrap
C/C++ Source or Header
|
1991-08-23
|
16KB
|
546 lines
#include "xgroup.h"
/* external var references */
extern GROUP *group;
extern CONTROLS control;
extern ADDR *myaddr;
extern ECHOREC *echos;
extern char *groupin;
extern char *groupout;
extern char *grouphold;
extern char *msgdir;
extern char *outbound;
extern char *inbound;
extern char *archive;
extern char *unarchive;
extern word packsize;
extern word netarea;
extern char buffer[1024];
#define MAXPATH 12480
SB * _fastcall parse_oldpath (char *sbs) {
/* returns an array of net/node pairs (ending in 0/0) */
SB *s;
char *p,endofline;
word lastnet = 0;
int x = 0;
s = (SB *)calloc(MAXPATH + 1,sizeof(SB));
if(!s) return NULL;
do {
while(*sbs == '\r') {
sbs++;
}
if(!strncmp(sbs,"\01PATH",5)) {
sbs += 5;
if(*sbs == ':') sbs++;
sbs = skip_white(sbs);
endofline = 0;
while(*sbs && *sbs != '\r' && !endofline) {
while(*sbs && *sbs == ' ' || *sbs == '\t') sbs++;
p = sbs;
while(*p && *p != ' ' && *p != '\t' && *p != '\r') p++;
if(*p == '\r') {
endofline = 1;
}
if(*p) {
*p = 0;
p++;
}
if(lastnet == 0) lastnet = atoi(sbs);
if(!strstr(sbs,"/")) s[x].net = lastnet;
else {
s[x].net = atoi(sbs);
lastnet = s[x].net;
while(*sbs != '/' && *sbs) sbs++;
if(*sbs == '/') sbs++;
}
s[x++].node = atoi(sbs);
if(x > MAXPATH) { /* this has GOT to be a grunged msg */
my_free(s);
return NULL;
}
sbs = p;
}
}
else break;
} while(*sbs && lastnet != 0);
return s;
}
long _fastcall spit_oldpath (SB *s,int handle) {
/* puke path array out to file, formatted as old path */
int len = 0,x = 0;
word lastnet = 0;
char temp[32];
long totallen = 0L;
while(s[x].net != 0) {
if(len > 67) {
totallen += (long)ffprintf(handle,"%s\r",buffer);
len = 0;
}
if(!len) {
len += sprintf(buffer,"\01PATH: ");
strcat(buffer,ltoa((long)s[x].net,temp,10));
len += strlen(temp);
strcat(buffer,"/");
len++;
strcat(buffer,ltoa((long)s[x].node,temp,10));
len += strlen(temp);
lastnet = s[x++].net;
}
else {
if(lastnet != s[x].net) {
strcat(buffer," ");
len++;
strcat(buffer,ltoa((long)s[x].net,temp,10));
lastnet = s[x].net;
len += strlen(temp);
strcat(buffer,"/");
len++;
strcat(buffer,ltoa((long)s[x].node,temp,10));
len += strlen(temp);
}
else {
strcat(buffer," ");
len++;
strcat(buffer,ltoa((long)s[x].node,temp,10));
len += strlen(temp);
}
x++;
}
}
if(len) {
totallen += (long)ffprintf(handle,"%s\r",buffer);
}
return totallen;
}
ADDR * _fastcall parse_newpath (char *sbs) {
ADDR *top = NULL,*info,*last;
char *domain,*zone,*net,*node,*point,*temp;
char *lastdomain,*lastzone,*lastnet,*lastnode,*lastpoint;
char lastdelim = 0,endofline;
char *p,*pp;
if(!sbs || !*sbs) return NULL;
lastdomain = lastzone = lastnet = lastnode = lastpoint =
domain = zone = net = node = point = temp = NULL;
do {
while(*sbs == '\r') {
sbs++;
}
if(!strncmp(sbs,"\01NPTH",5)) {
sbs += 5;
if(*sbs == ':') sbs++;
sbs = skip_white(sbs);
endofline = 0;
while(*sbs && *sbs != '\r' && !endofline) {
while(*sbs && *sbs == ' ' || *sbs == '\t') sbs++;
pp = sbs;
while(*pp && *pp != ' ' && *pp != '\t' && *pp != '\r') pp++;
if(*pp == '\r') {
endofline = 1;
}
if(*pp) {
*pp = 0;
pp++;
}
p = sbs;
do {
temp = p;
p = to_delim(p,"#:/.\t ");
switch((int) *p) {
case '\0':
case '\r':
case ' ':
case 't': if(lastdelim == '.') point = temp;
else if(lastdelim=='@') domain = temp;
else node = temp;
goto BreakOut;
case '#': domain = temp;
break;
case ':': zone = temp;
break;
case '/': net = temp;
break;
case '.': node = temp;
break;
}
lastdelim = *p;
p++; /* Skip delimiter */
} while(p && *p);
BreakOut:
sbs = pp;
if(domain) lastdomain = domain;
if(zone) lastzone = zone;
if(net) lastnet = net;
if(node) lastnode = node;
if(point) lastpoint = point;
if(!domain) domain = lastdomain;
if(!zone) zone = lastzone;
if(!net) net = lastnet;
if(!node) node = lastnode;
if(!point) point = lastpoint;
info = (ADDR *)malloc(sizeof(ADDR));
if(!info) {
printf("\nOut of memory\n");
free_addresses(top);
return NULL;
}
if(zone) info->zone = atoi(zone);
else info->zone = 0;
if(net) info->net = atoi(net);
else info->net = 0;
if(node) info->node = atoi(node);
else info->node = 0;
if(point) info->point = atoi(point);
else info->point = 0;
info->domain = strdup(domain);
if(!info->domain) {
printf("\nOut of memory\n");
my_free(info);
free_addresses(top);
return NULL;
}
if(!top) {
top = info;
}
else {
last->next = info;
}
info->next = NULL;
last = info;
}
}
else break;
} while(*sbs && *lastdomain);
return top;
}
long _fastcall spit_newpath (SB *s,ADDR *addr,ADDR *maddr,int handle) {
/* puke path arrays out to file, formatted as new path */
int len = 0,x = 0;
word lastnet = 0,lastzone = 0,lastpoint = 0,lastnode = 65535U;
char temp[32],*lastdomain = NULL;
long totallen = 0L;
ADDR *info;
info = addr;
while(info) {
if(len > 67) {
totallen += (long)ffprintf(handle,"%s\r",buffer);
len = 0;
*buffer = 0;
}
if(!len) {
len += sprintf(buffer,"\01NPTH:");
}
if(!lastdomain || stricmp(lastdomain,info->domain)) {
strcat(buffer," ");
len++;
strcat(buffer,info->domain);
len += strlen(info->domain);
strcat(buffer,"#");
strcat(buffer,ltoa((long)info->zone,temp,10));
len += strlen(temp);
strcat(buffer,":");
len++;
strcat(buffer,ltoa((long)info->net,temp,10));
len += strlen(temp);
strcat(buffer,"/");
len++;
strcat(buffer,ltoa((long)info->node,temp,10));
len += strlen(temp);
if(info->point) {
strcat(buffer,".");
len++;
strcat(buffer,ltoa((long)info->point,temp,10));
len += strlen(temp);
}
lastdomain = info->domain;
lastzone = info->zone;
lastnet = info->net;
lastnode = info->node;
lastpoint = info->point;
}
else if(lastzone != info->zone) {
strcat(buffer," ");
len++;
strcat(buffer,ltoa((long)info->zone,temp,10));
len += strlen(temp);
strcat(buffer,":");
len++;
strcat(buffer,ltoa((long)info->net,temp,10));
len += strlen(temp);
strcat(buffer,"/");
len++;
strcat(buffer,ltoa((long)info->node,temp,10));
len += strlen(temp);
if(info->point) {
strcat(buffer,".");
len++;
strcat(buffer,ltoa((long)info->point,temp,10));
len += strlen(temp);
}
lastzone = info->zone;
lastnet = info->net;
lastnode = info->node;
lastpoint = info->point;
}
else if(lastnet != info->net) {
strcat(buffer," ");
len++;
strcat(buffer,ltoa((long)info->net,temp,10));
len += strlen(temp);
strcat(buffer,"/");
len++;
strcat(buffer,ltoa((long)info->node,temp,10));
len += strlen(temp);
if(info->point) {
strcat(buffer,".");
len++;
strcat(buffer,ltoa((long)info->point,temp,10));
len += strlen(temp);
}
lastnet = info->net;
lastnode = info->node;
lastpoint = info->point;
}
else if(lastnode != info->node) {
strcat(buffer," ");
len++;
strcat(buffer,ltoa((long)info->node,temp,10));
len += strlen(temp);
if(info->point) {
strcat(buffer,".");
len++;
strcat(buffer,ltoa((long)info->point,temp,10));
len += strlen(temp);
}
lastnode = info->node;
lastpoint = info->point;
}
else if(lastpoint != info->point) {
if(info->point) {
strcat(buffer," ");
len++;
strcat(buffer,".");
len++;
strcat(buffer,ltoa((long)info->point,temp,10));
len += strlen(temp);
}
lastpoint = info->point;
}
info = info->next;
}
if(!s) goto SkipOld;
lastpoint = 0;
while(s[x].net != 0) { /* add old stuff */
if(len > 67) {
totallen += (long)ffprintf(handle,"%s\r",buffer);
len = 0;
*buffer = 0;
}
if(!len) {
len += sprintf(buffer,"\01NPTH:");
if(!addr) {
strcat(buffer," ");
len++;
strcat(buffer,maddr->domain);
len += strlen(maddr->domain);
lastdomain = maddr->domain;
strcat(buffer,"#");
len++;
strcat(buffer,ltoa((long)maddr->zone,temp,10));
len += strlen(temp);
lastzone = maddr->zone;
strcat(buffer,":");
len++;
strcat(buffer,ltoa((long)s[x].net,temp,10));
len += strlen(temp);
lastnet = s[x].net;
strcat(buffer,"/");
len++;
strcat(buffer,ltoa((long)s[x].node,temp,10));
len += strlen(temp);
lastnode = s[x++].node;
}
}
else {
if(lastnet != s[x].net) {
strcat(buffer," ");
len++;
strcat(buffer,ltoa((long)s[x].net,temp,10));
lastnet = s[x].net;
len += strlen(temp);
strcat(buffer,"/");
len++;
strcat(buffer,ltoa((long)s[x].node,temp,10));
len += strlen(temp);
}
else {
strcat(buffer," ");
len++;
strcat(buffer,ltoa((long)s[x].node,temp,10));
len += strlen(temp);
}
x++;
}
}
SkipOld:
if(len > 67) {
totallen += (long)ffprintf(handle,"%s\r",buffer);
len = 0;
*buffer = 0;
}
if(!len) {
len += sprintf(buffer,"\01NPTH:");
}
if(!lastdomain || stricmp(lastdomain,maddr->domain)) {
strcat(buffer," ");
len++;
strcat(buffer,maddr->domain);
len += strlen(maddr->domain);
strcat(buffer,"#");
strcat(buffer,ltoa((long)maddr->zone,temp,10));
len += strlen(temp);
strcat(buffer,":");
len++;
strcat(buffer,ltoa((long)maddr->net,temp,10));
len += strlen(temp);
strcat(buffer,"/");
len++;
strcat(buffer,ltoa((long)maddr->node,temp,10));
len += strlen(temp);
if(maddr->point) {
strcat(buffer,".");
len++;
strcat(buffer,ltoa((long)maddr->point,temp,10));
len += strlen(temp);
}
}
else if(lastzone != maddr->zone) {
strcat(buffer," ");
len++;
strcat(buffer,ltoa((long)maddr->zone,temp,10));
len += strlen(temp);
strcat(buffer,":");
len++;
strcat(buffer,ltoa((long)maddr->net,temp,10));
len += strlen(temp);
strcat(buffer,"/");
len++;
strcat(buffer,ltoa((long)maddr->node,temp,10));
len += strlen(temp);
if(maddr->point) {
strcat(buffer,".");
len++;
strcat(buffer,ltoa((long)maddr->point,temp,10));
len += strlen(temp);
}
}
else if(lastnet != maddr->net) {
strcat(buffer," ");
len++;
strcat(buffer,ltoa((long)maddr->net,temp,10));
len += strlen(temp);
strcat(buffer,"/");
len++;
strcat(buffer,ltoa((long)maddr->node,temp,10));
len += strlen(temp);
if(maddr->point) {
strcat(buffer,".");
len++;
strcat(buffer,ltoa((long)maddr->point,temp,10));
len += strlen(temp);
}
}
else if(lastnode != maddr->node) {
strcat(buffer," ");
len++;
strcat(buffer,ltoa((long)maddr->node,temp,10));
len += strlen(temp);
if(maddr->point) {
strcat(buffer,".");
len++;
strcat(buffer,ltoa((long)maddr->point,temp,10));
len += strlen(temp);
}
}
else if(lastpoint != maddr->point) {
if(maddr->point) {
strcat(buffer," ");
len++;
strcat(buffer,".");
len++;
strcat(buffer,ltoa((long)maddr->point,temp,10));
len += strlen(temp);
}
lastpoint = maddr->point;
}
if(len) {
totallen += (long)ffprintf(handle,"%s\r",buffer);
}
return totallen;
}
void _fastcall free_addresses (ADDR *top) { /* free list of addresses */
ADDR *next;
while(top) {
next = top->next;
if(top->domain) my_free(top->domain);
my_free(top);
top = next;
}
}