DataMuseum.dk

Presents historical artifacts from the history of:

Rational R1000/400 Tapes

This is an automatic "excavation" of a thematic subset of
artifacts from Datamuseum.dk's BitArchive.

See our Wiki for more about Rational R1000/400 Tapes

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - download
Index: ┃ T b

⟦b0d443267⟧ TextFile

    Length: 3279 (0xccf)
    Types: TextFile
    Names: »buffering.c«

Derivation

└─⟦8ee07855d⟧ Bits:30000545 8mm tape, Rational 1000, DTIA 2_1_6
    └─ ⟦0c25cb74a⟧ »DATA« 
        └─⟦038380b96⟧ 
└─⟦d0624311f⟧ Bits:30000529 8mm tape, Rational 1000, DTIA 2_1_7
    └─ ⟦f494b5154⟧ »DATA« 
        └─⟦038380b96⟧ 
            └─ ⟦this⟧ »buffering.c« 
└─⟦8ee07855d⟧ Bits:30000545 8mm tape, Rational 1000, DTIA 2_1_6
    └─ ⟦0c25cb74a⟧ »DATA« 
        └─⟦0732ea0cf⟧ 
└─⟦d0624311f⟧ Bits:30000529 8mm tape, Rational 1000, DTIA 2_1_7
    └─ ⟦f494b5154⟧ »DATA« 
        └─⟦0732ea0cf⟧ 
            └─ ⟦this⟧ »../../dtia/release_apollo_2.1/buffering.c« 
└─⟦8ee07855d⟧ Bits:30000545 8mm tape, Rational 1000, DTIA 2_1_6
    └─ ⟦0c25cb74a⟧ »DATA« 
        └─⟦25fab149a⟧ 
└─⟦d0624311f⟧ Bits:30000529 8mm tape, Rational 1000, DTIA 2_1_7
    └─ ⟦f494b5154⟧ »DATA« 
        └─⟦25fab149a⟧ 
            └─ ⟦this⟧ »../../dtia/release_sun_2.1/buffering.c« 
└─⟦8ee07855d⟧ Bits:30000545 8mm tape, Rational 1000, DTIA 2_1_6
    └─ ⟦0c25cb74a⟧ »DATA« 
        └─⟦be254d495⟧ 
└─⟦d0624311f⟧ Bits:30000529 8mm tape, Rational 1000, DTIA 2_1_7
    └─ ⟦f494b5154⟧ »DATA« 
        └─⟦be254d495⟧ 
            └─ ⟦this⟧ »../../dtia/release_aix_2.1/buffering.c« 
└─⟦8ee07855d⟧ Bits:30000545 8mm tape, Rational 1000, DTIA 2_1_6
    └─ ⟦0c25cb74a⟧ »DATA« 
        └─⟦c67979795⟧ 
└─⟦d0624311f⟧ Bits:30000529 8mm tape, Rational 1000, DTIA 2_1_7
    └─ ⟦f494b5154⟧ »DATA« 
        └─⟦c67979795⟧ 
            └─ ⟦this⟧ »../../dtia/release_hp_2.1/buffering.c« 

TextFile

#ifndef	lint
#ifndef	DEBUG
static char SCCS_id[] = "@(#)buffering.c 2.1 90/08/02 19:04:06  Copyright(c) 1990 by Rational.";
#else
static char SCCS_id[] = "@(#)buffering.c DEBUG 2.1 90/08/02 19:04:06  Copyright(c) 1990 by Rational.";
#endif
#endif

#define	BUFFERING
#include	"talk.h"
#undef	BUFFERING

#define	MAXSIZEBUFFER	2*MAX_SIZE_ITEM

static	char	big_buffer[MAXSIZEBUFFER];
static	int	begin_big_buffer=0;
static	int	end_big_buffer= -1;

int	buff_debug() {
	printf("Buffer: debut%d fin%d MAX%d\n",
	    begin_big_buffer,end_big_buffer,MAXSIZEBUFFER);
}

/* empty buffer when begin==end+1	*/
/* nb elements is end-begin+1		*/
/* Good index is in 0..MAXSIZEBUFFER-1	*/

#define	ZONE		(big_buffer+begin_big_buffer)
#define	SIZEZONE	(end_big_buffer-begin_big_buffer+1)

#define	ISEMPTY		(SIZEZONE==0)
#define	EMPTY		{begin_big_buffer=0;end_big_buffer= -1;}

#define	FREEZONE	(big_buffer+end_big_buffer+1)
#define	SIZEFREEZONE	(MAXSIZEBUFFER-end_big_buffer-1)

#define	TRANSLATE	{int	lg=SIZEZONE;			\
			 if (lg == 0) EMPTY else		\
			 { bcopy(ZONE,big_buffer,lg);		\
			 begin_big_buffer=0;			\
			 end_big_buffer=lg-1;} }

#define	CONCAT(ss,ll)	{bcopy(ss,FREEZONE,ll);end_big_buffer+=ll;}
#define	EXTRACT(ss,ll)	{bcopy(ZONE,ss,ll);begin_big_buffer+=ll;\
			 if ISEMPTY EMPTY;}

#define	READ(fd,nb)	{nb=my_read(fd,FREEZONE,SIZEFREEZONE);	\
			 if(nb>0)end_big_buffer+=nb;}

static	int	my_write(fd,s,l)
int	fd;
char	*s;
int	l; 
{
	int	lg_wrote,lg;
	lg_wrote=0;
	while (lg_wrote<l) {
		lg=write(fd,s,l);
		if (lg==-1) {
			return	-1;
		} else {
			lg_wrote+=lg;
			s+=lg;
		}
	}
	return	lg_wrote;
}
static	int	my_read(fd,s,l)
int	fd;
char	*s;
int	l; 
{
	int	lg_read;
	while ((lg_read=read(fd,s,l))==-1) {
		if (errno==EINTR)	continue;
	}
	return	lg_read;
}


static	int	ok_write(content,size)
char	*content;
int	size; 
{
	if 	(size<=SIZEFREEZONE) {
		CONCAT(content,size);
		return	(TRUE);
	} else {
		return	(FALSE);
	}
}

static	int	ok_read(content,size)
char	*content;
int	size; 
{
	if	(size>SIZEZONE) {
		return	(FALSE);
	} else {
		EXTRACT(content,size);
		return	(TRUE);
	}
}

static	int	to_be_flushed=1;
void	b_flush(f)	int f ; 
{
	to_be_flushed=f;
}

int	b_is_empty() {
	return	ISEMPTY;
}

int	buff_write(fd,content,size)
int	fd;
char	*content;
int	size; 
{
	int	lg1,lg2;
	lg1=lg2=0;
	if 	(!ok_write(content,size)) {
		lg1=my_write(fd,ZONE,SIZEZONE);
		EMPTY;
		if	(!ok_write(content,size)) {
			lg2=my_write(fd,content,size);
		} else {
			if	(to_be_flushed) {
				lg2=my_write(fd,ZONE,SIZEZONE);
				EMPTY;
			}
		}
	} else {
		if	(to_be_flushed) {
			lg1=my_write(fd,ZONE,SIZEZONE);
			EMPTY;
		}
	}
	return 	(((lg1== -1)||(lg2== -1))?-1:size);
}

int	buff_read(fd,content,size)
int	fd;
char	*content;
int	size; 
{
	int	lg,lg_read;
	if	(!ok_read(content,size)) {
		TRANSLATE
		    READ(fd,lg);
		if	(lg<=0)	return (-1);
		if (!ok_read(content,size)) {
			bcopy(ZONE,content,SIZEZONE);
			lg_read=SIZEZONE;
			EMPTY;
			while (lg_read<size) {
				/* here already read lg_read (not enough) */
				/* and big_buffer is empty		  */
				READ(fd,lg);
				if	(lg== -1)		return	-1;
				if (!ok_read(content+lg_read,size-lg_read)) {
					bcopy(ZONE,content+lg_read,SIZEZONE);
					lg_read+=SIZEZONE;
					EMPTY;
				} else {
					lg_read=size;
				}
			}
		}
	}
	return	size;
}