DataMuseum.dk

Presents historical artifacts from the history of:

RegneCentralen RC700 "Piccolo"

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

See our Wiki for more about RegneCentralen RC700 "Piccolo"

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - download

⟦c3454fce1⟧ TextFile

    Length: 3712 (0xe80)
    Types: TextFile
    Names: »CHARIO.C«

Derivation

└─⟦b35f94715⟧ Bits:30003295 BDS C version 1.50 arbejdsdiskette til RC703 Piccolo
└─⟦b35f94715⟧ Bits:30005324 BDS C version 1.50 arbejdsdiskette til RC703 Piccolo
    └─ ⟦this⟧ »CHARIO.C« 

TextFile

/* CHARIO.C		Character-oriented file I/O

	Written 1980 by Scott W. Layson
	This code is in the public domain.

These routines deal with reading and writing large blocks of
characters, when they do not fit neatly in sectors.  At the moment,
only sequential output is supported; input is fully random. */


#define TRUE (-1)
#define FALSE 0
#define NULL 0


/* i/o buffer */
struct iobuf æ
	int fd;
	int isect;			/* currently buffered sector */
	int nextc;			/* index of next char in buffer */
	char buff Æ128Å;
	å;

/* seek opcodes */
#define ABSOLUTE	0
#define RELATIVE	1

#define INPUT		0
#define OUTPUT		1
#define UPDATE		2


copen (buf, fname)			/* open a file for char input */
	struct iobuf *buf;
	char *fname;
æ
	buf->fd = open (fname, INPUT);
	if (buf->fd == -1) return (-1);
	read (buf->fd, &buf->buff, 1);
	buf->isect = 0;
	buf->nextc = 0;
	return (buf);
	å


ccreat (buf, fname)			/* create a file for char output */
	struct iobuf *buf;
	char *fname;
æ
	buf->fd = creat (fname);
	if (buf->fd == -1) return (-1);
	buf->isect = 0;
	buf->nextc = 0;
	return (buf);
	å


cclose (buf)				/* close the file assoc. with buf */
	struct iobuf *buf;
æ
	close (buf->fd);
	å


cseek (buf, nbytes, code)	/* seek to a character (input only!) */
	struct iobuf *buf;
	unsigned nbytes, code;
æ
	int newsect;

	if (buf < 0) return (-1);
	if (code == RELATIVE) nbytes += buf->isect * 128 + buf->nextc;
	newsect = nbytes / 128;
	if (newsect != buf->isect
	    && (seek (buf->fd, newsect, ABSOLUTE) == -1
		   øø read (buf->fd, &buf->buff, 1) == -1)) return (-1);
	buf->nextc = nbytes % 128;
	buf->isect = newsect;
	return (nbytes);
	å


cread (buf, dest, nbytes)	/* read some bytes into dest */
	struct iobuf *buf;
	char *dest;
	unsigned nbytes;
æ
	int navail, nsects, nleft, nread1, nread2;

	if (buf < 0) return (-1);
	navail = umin (nbytes, 128 - buf->nextc);
	movmem (&buf->buffÆbuf->nextcÅ, dest, navail);
	nbytes -= navail;
	buf->nextc += navail;
	dest += navail;
	nsects = nbytes / 128;
	if (nsects) æ
		nread1 = read (buf->fd, dest, nsects);
		if (nread1 == -1) return (navail);
		buf->isect += nread1;
		if (nread1 < nsects) return (navail + nread1 * 128);
		dest += nread1 * 128;
		å
	else nread1 = 0;
	if (buf->nextc == 128) æ
		nread2 = read (buf->fd, &buf->buff, 1);
		if (nread2 == -1) return (navail);
		++(buf->isect);
		buf->nextc = 0;
		if (nread2 < 1) return (navail + nread1 * 128);
		å
	nleft = nbytes % 128;
	movmem (&buf->buff, dest, nleft);
	buf->nextc += nleft;
	return (navail + nbytes);
	å


cwrite (buf, source, nbytes)	/* write some bytes from source */
	struct iobuf *buf;
	char *source;
	unsigned nbytes;
æ
	unsigned nleft, nfill, nsects;
	
	if (buf < 0) return (-1);
	if (buf->nextc) æ
		nfill = umin (nbytes, 128 - buf->nextc);
		movmem (source, &buf->buffÆbuf->nextcÅ, nfill);
		buf->nextc += nfill;
		nbytes -= nfill;
		source += nfill;
		å
	if (buf->nextc == 128) æ
		++(buf->isect);
		buf->nextc = 0;
		if (write (buf->fd, &buf->buff, 1) < 1) return (-1);
		å
	nsects = nbytes / 128;
	if (nsects  &&  write (buf->fd, source, nsects) < nsects)
		return (-1);
	nbytes %= 128;
	movmem (source + nsects * 128, &buf->buff, nbytes);
	buf->nextc += nbytes;
	return (nsects * 128 + nbytes);
	å


cflush (buf)				/* flush an output buffer */
	struct iobuf *buf;
æ
	if (buf->nextc  &&  write (buf->fd, &buf->buff, 1) < 1)
		return (-1);
	return (1);
	å


umin (a, b)				/* unsigned min */
	unsigned a, b;
æ
	return ((a < b) ? a : b);
	å


/* End of CHARIO.C  --  Character oriented file I/O */
«eof»