#include "../sccshead/sfile.h"
char putl____[] "~|^`putl.c:	4.1";
/*
	Routine to create and open a file for output.
*/

crtl(buf,file,mode,fd)
struct Obufr *buf;
char file[];
int mode, fd;
{
	if(nargs() == 4) buf->Ofildes = fd;
	else buf->Ofildes = xcreat(file,mode);

	buf->Orecptr = buf->Obuff1;
	buf->Oend = buf->Orecptr + 511;
	return(0);
}


/*
	Routine to write a line to a "normal" ASCII file.  Second
	argument must point to a newline-terminated string.
*/

putl(buf,rec)
struct Obufr *buf;
char *rec;
{
	register char *p, *r, *e;

	p = buf->Orecptr;
	e = buf->Oend;
	r = rec;
	while(1) {
		while(p <= e)
			if((*p++ = *r++) == '\n') {
				buf->Orecptr = p;
				return(0);
			}

		xwrite(buf->Ofildes,p=buf->Obuff1,512);
	}
}


/*
	Routine to dump output buffer.  Must be called if putl is used.
*/

flshl(buf)
struct Obufr *buf;
{
	register int n;

	n = buf->Orecptr - buf->Obuff1;
	xwrite(buf->Ofildes,buf->Orecptr=buf->Obuff1,n);
	return(0);
}
