/*
* BLsetText sets everything up for storing text, if the optional parameter
* sta is set, it copies it in.
*/
void
BLsetText(bl, sta)
Blockobj *bl;
StrArray *sta;
{
/** Reset data field and put in new values **/
if (BLgetDatatype(bl) != BDATA_TEXT) {
BLdatadestroy(bl);
/*
* BLfromNet() assumes that the initial '+' in the data stream has been read,
* along with the blockname, up to the ':', but not anything after..
*
* It then executes most of the state diagram, it returns when it has
* encountered EOF, or encounters the next '+', or '.'
*
* Returns the following:
* 0 for EOF encountered, block retrieved successfully
* 1 for successful retrieve, and another block coming
* neg value for error conditions from read routines and botched block vals
*/
int
BLfromNet(bl, fd, blockname)
Blockobj *bl;
int fd;
char *blockname;
{
char inputline[512];
int err;
/*** State: _GotBlockName_ ***/
BLsetName(bl, blockname);
/** Find out if there's a gopher reference **/
err = readrecvbuf(fd, inputline, 1);
gs = GSnew();
GSfromNet(gs, fd);
BLsetGref(bl, gs);
/** read up to the next \r\n+ **/
while (1) {
if ((err= readrecvbuf(fd, inputline, 1)) <= 0)
return(err);
if (*inputline == '+')
return(1);
else {
err = readline(fd, inputline, sizeof(inputline));
if (err <= 0)
return(err); /*** Error ***/
}
}
}
/** Okay, let's just stick the text in verbatim **/
/** get rid of remaining newline **/
readline(fd, inputline, sizeof(inputline));
/** State: _FirstChar_ **/
while (1) {
/** Check for plus **/
if ((err= readrecvbuf(fd, inputline, 1)) <=0)
return(err);
if (*inputline == '+')
return(1);
/*** Return to state _NewBlock_ ***/
if (*inputline == '.') {
readline(fd, inputline, sizeof(inputline));
return(0);
}
if (*inputline == ' ') {
/** add a line otherwise State: _Addline_ **/
readline(fd, inputline, sizeof(inputline));
ZapCRLF(inputline);
BLaddText(bl, inputline);
} else {
/** malformed block line received
proceed as if it was OK, but don't add the line **/
readline(fd, inputline, sizeof(inputline));
}
}
}
int
BLAsearch(bla, bname)
BlockArray *bla;
char *bname;
{
int i;
if (bla == NULL)
return(-1);
for (i=0; i<BLAgetTop(bla); i++) {
if (strcmp(BLgetName(BLAgetEntry(bla,i)), bname)==0)
return(i);
}