/*********************************************************************/
/* */
/* This Program Written by Paul Edwards, 3:711/934{at}fidonet. */
/* Released to the Public Domain */
/* */
/*********************************************************************/
/*********************************************************************/
/* */
/* pkt - read Fidonet packets */
/* */
/*********************************************************************/
#include
#include
#include "pkt.h"
#include "slidwin.h"
#include "repofile.h"
#include "estdlib.h"
#include "error.h"
static void pktExtractMsg(PKT *pkt);
void pktDefaults(PKT *pkt)
{
pkt->szbuf = 60000U;
repofileDefaults(&pkt->repofile);
slidwinDefaults(&pkt->slidwin);
return;
}
void pktInit(PKT *pkt)
{
pkt->buf = emalloc(pkt->szbuf);
if (ALLOK)
{
repofileInit(&pkt->repofile);
if (ALLOK)
{
slidwinInit(&pkt->slidwin);
slidwinSetBuf(&pkt->slidwin, pkt->buf, pkt->szbuf);
}
if (!ALLOK)
{
repofileTerm(&pkt->repofile);
}
}
if (!ALLOK)
{
efree(&pkt->buf);
}
return;
}
void pktTerm(PKT *pkt)
{
slidwinTerm(&pkt->slidwin);
repofileTerm(&pkt->repofile);
efree(pkt->buf);
return;
}
void pktSetFile(PKT *pkt, char *filename)
{
repofileSetFile(&pkt->repofile, filename);
slidwinSetRepo(&pkt->slidwin, repofileGetRepo(&pkt->repofile));
return;
}
void pktFinFile(PKT *pkt)
{
slidwinFinRepo(&pkt->slidwin);
return;
}
PMSG *pktFirstMsg(PKT *pkt)
{
pkt->nextLoc = 58;
if (slidwinLoc(&pkt->slidwin) != pkt->nextLoc)
{
slidwinSeek(&pkt->slidwin, pkt->nextLoc);
}
if (slidwinVal(&pkt->slidwin) <= 2)
{
pkt->rmsg = NULL;
}
else
{
pktExtractMsg(pkt);
pkt->rmsg = &pkt->pmsg;
}
return (pkt->rmsg);
}
PMSG *pktNextMsg(PKT *pkt)
{
if (slidwinLoc(&pkt->slidwin) != pkt->nextLoc)
{
slidwinSeek(&pkt->slidwin, pkt->nextLoc);
}
if (slidwinVal(&pkt->slidwin) <= 2)
{
pkt->rmsg = NULL;
}
else
{
pktExtractMsg(pkt);
pkt->rmsg = &pkt->pmsg;
}
return (pkt->rmsg);
}
static void pktExtractMsg(PKT *pkt)
{
pkt->pmsg.date = pkt->buf + 14;
pkt->pmsg.to = pkt->pmsg.date + strlen(pkt->pmsg.date) + 1;
pkt->pmsg.from = pkt->pmsg.to + strlen(pkt->pmsg.to) + 1;
pkt->pmsg.subject = pkt->pmsg.from + strlen(pkt->pmsg.from) + 1;
pkt->pmsg.text = pkt->pmsg.subject + strlen(pkt->pmsg.subject) + 1;
if (strncmp(pkt->pmsg.text, "AREA:", 5) == 0)
{
strncpy(pkt->pmsg.area, pkt->pmsg.text + 5, 80);
pkt->pmsg.area[79] = '\0';
pkt->p = strchr(pkt->pmsg.area, '\r');
if (pkt->p != NULL)
{
*pkt->p = '\0';
}
}
pkt->pmsg.endt = pkt->pmsg.text + strlen(pkt->pmsg.text) + 1;
pkt->nextLoc += (pkt->pmsg.endt - pkt->buf);
return;
}
@EOT:
---
* Origin: X (3:711/934.9)
|