File:  [Research Unix] / researchv10no / cmd / cfront / libC / iostream.cpio
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Tue Apr 24 17:21:35 2018 UTC (8 years, 1 month ago) by root
Branches: belllabs, MAIN
CVS tags: researchv10, HEAD
researchv10 Norman

0707070044042147441006440042240042240000020065000443212436100000700000026560README
5/9/89: Have filebuf::sync() reset last_seek.  This will have the
        effect that if somebody else moves the file pointer
        after a sync() but before a seek(), the filebuf will behave
	sensibly.

5/9/89: Fix define of "hardfail".

5/5/89: Lots of stuff to improve buffering. New function 
	
	ostream::osfx()
		Perform "suffix" actions before returning from
		inserters.  This is called by all predefined
		inserters.  It isn't called by the binary output functions.
		And should be called by user inserters
		after any direct manipulation of the streambuf.

	There are two new format flags:

		unitbuf: when set a flush is performed by osfx() ;
		stdio: when set stdout and stderr are flushed by osfx() ;

	cerr is now unitbuf'ed rather than unbuffered.

	sync_with_stdio makes cout, cerr unit buffered rather than
	unbuffered.

	cin and cout now get the arrays they use dynamically. (Previously
	they were statically allocated.)  This change is prompted
	by people who complained about wasting 2K when they didn't
	use cin or cout.

5/5/89: Add check in streambuf* insertor so that it sets failbit when
	given the null pointer.  (Right now it just core dumps).

5/5/89: Change ios::clear to have an int argument

cycle 16

5/4/89: Change all open_mode arguments to ints.

5/3/89: Fix ws manipulator so that it will flushed tied ostream
	when required.

5/2/89: More cleanup of open_mode arguments.  Add defaults for
	ifstream::open and ofstream::open.  Change all
	defaults to filebuf::openprot

cycle 15

4/28/89. Add default open_mode arguments to ifstream and ofstream
	 constructors.

cycle 14?

4/18/89.  Fix bug is filebuf::seekoff that also caused problems
	  for tellg and tellp.  

4/13/89.  Change cstreams.c so it doesn't refer to skip (which is
	a stream compatibility function.

------------------------------------------------
Cycle 13

Change typedef in strstream.c to avoid use of size_t.  (This is
because of header file compatibility problems.)

Change exit(10) to abort() in oldformat.c.

Cycle 12

Put in include of <iostream.h> in strstream.h

Change istream::get() so that it really gets expanded inline.
Previous definition was being outlined.

Reorder declarations so that ipfx comes before any operator>>. Not
just before the ones that have inline code refering to it. The old
ordering was resulting in a failure to expand ipfx where it should
have been.

Move declaration of ios_user_union higher in stream.c in order to
eliminate a new warning message.

Change values of O_CREAT O_TRUNC O_EXCL in cases where headers don't
define them (the only known such system is V9)

Fix ostream::out_waiting.  It was just returning non-zero when there was stuff
accumulated but not consumed.  It was supposed to return the number
(at least according to the man page.)

-----------------------------------------------------
Cycle 11

Change cstreams.c for change to way explicit placement works.

Implement bidirectional strstream. 

----------------------------------------------------
Cycle 9 

Fix bug in void* inserter.  (Showbase should have been set
but wasn't)


--------------------------------------------------
Cycle 8

streambuf::snextc was not incrementing the get pointer before
it called underflow.  This had no effect because the streambuf
classes assume that when underflow is called there
was nothing in the buffer.  The man page said that although this
was "normally the case" but doesn't guarantee it.  I wrote a new
streambuf class that checked for the condition and it failed.
I've fixed snextc.  

---------------------------------------------------
Cycle 7  

Fix bug in setstate.  

Change return type of filebuf::close to filebuf*

Add noreplace to open_mode 

Fixed bug in adjustment of floating fields

-----------------------------------------------------

Cycle 6.1 

Interpretation of justification fields was screwed up.

Fix for whitespace eating of character extractor of cycle 6  was
incomplete. (It might read characters when the stream was
in error status).

-----------------------------------------------------
Cycle 6

Make streambuf::xsgetn and streambuf::xsputn virtuals

ios::operator int changed to ios::operator void* in order to allow
detection of "cin << 5" without requiring any extractor or inserter
to be declared in class iostream.

sync is moved from ios to istream,  the corresponding action on
ostreams is flushing.

Reorder declarations in iostream.h to avoid forward enum tag
declarations.

Fixes to single character extractors to make sure they skip
whitespace when required.

Massive simplification of format control stuff

	struct fmtinfo goes away as do pushing and popping of it.

	several format state variables are consolodated into
	a single flag field and new flags are added to control
	more stuff.  Remaining state variables are fill, precision and
	width.  New statevariable "flags".

	Flags declared in an enum within ios:

	enum		{ skipws=01,	
					/* skip whitespace on input */
			  left=02,  right=04, internal=010,
					/* padding location */
			  dec=020, oct=040, hex=0100, 
					/* conversion base */
			  showbase=0200, showpoint=0400, uppercase=01000,
			  showpos=02000, 
					/* modifiers */
			  scientific=04000, fixed=010000
					/* floating point notation */ 					  	  } ;
	
	Functions to manipulate the flag field
		s.flags() 	return current flag
		s.flags(b)	sets flags to b 
		s.setf(b)	turns on bits marked in f in flags
		s.setf(b,f)	assigns b to "field" specified by f
				(i.e. bits that are on in f)

        static ios int members for convienent reference to fields
                ios::basefield = hex|dec|oct ;
                ios::adjustfield = left|right|internal ;
                ios::floatfield = scientific|fixed ;

New manipulators

	s << setfill(f) 	sets fill state variable
	s << setprecision(p)	sets precision state variable
	s << setiosflags(b)	does s.setf(b)
	s << resetiosflags(b)	does s.setf(0,b)

New user setable state variables

	flags are a long user code may use unassigned bits
	s.iword(x) 		returns a long& 
	s.pword(s)		returns a void*& (sharing space with s.iword(x)
	

	ios::bitalloc()		returns a previously unallocated bit
	ios::xalloc()		returns a previously unused index
	
---------------------------------------------
Cycle 5

Eliminated a lot of warnings about assigning longs to ints and
the like.

Put in some overflow detection on integer input (it is still very
incomplete). 

Change sync_with_stdio into a static member function

Add enum_mode, nocreate.  Causes failure of an open if file does not
previously exist. 

Changed popfmt to reset width to 0.  This is more consistent with the
normal use.

Fixed some bugs in interaction of EOF eating whitespace and "ignore"

------------------------------------------

Multiple Inheritance Version.  

Changes from previous version:

MI structure in classes.  Mainly this is a lot of trivial changes.
But one substantive change arises.  Because ios is now inherited
as a virtual base class, a constructor with no arguments must
be used.  Therefore ios::init(streambuf*) is declared protected and
must be used to initialize in derived classes.

-------------------------------------------

The latest version of the iostream package incorporates a large
number of changes and bug fixes.  They are listed here in my
estimation of their importance.

In principle, istream, ostream, and iostream are now distinct
classes. istream only contains input operations and ostream only
contains output operations.  iostream is the "join" of the two. There
is a new class ios containing the common state information from which
all these are derived.

This means, for example, that cin should't be passed to a function
expecting an iostream.

In practice to do this would have required a good implementation of
multiple inheritance with virtual base classes. To avoid relying on
this feature of C++ all the stream classes are typedefed to ios.

As a consequence of this change several classes derived from
"istream" and "ostream" have been added.  Namely ifstream, ofstream,
istrstream and ostrstream.  These (rather than the bidrectional
fstream and strstream) should be used when a stream for only input or
only output is desired.

The kludge that used #defines and pointer variables to implement cin,
cour, cerr and cdebug has been eliminated. The standard streams are
now declared as extern variables in iostream.h. Their types are
classes derived from iostream with an assignment operator. So that it
is now permitted to assign streams to them.

Because cfront now distinguishes int from char in overload resolution
cout << 'a' now outputs the character 'a' rather than the decimal
value.  This is an incompatibility with the old stream package, but
is such a large improvement that I thought it was worth any
conversion problems it might cause.   This made the manipulator
"onec" redundant and it has been removed.

The name space has been cleaned up.  A lot of identifiers that were
previously part of the global name space have been made local to a
class. A table of the old and new names follows.  Probably the most
important is the renaming of open_modes.

	old name		new name
	--------		--------

	iocdebug			// eliminated
	iocerr				// eliminated
	iocin				// eliminated
	iocout				// eliminated
	
	cdebug			clog	// Renamed because of
					// complaints about old name

	state_value		io_state
					// Renamed because state_value
					// was too unspecific

	_bad			ios::badbit
	_eof			ios::eofbit
	_fail			ios::failbit
	_good			ios::goodbit

	append			ios::app
	atend			ios::ate
	input			ios::in
	output			ios::out

	seek_beg		ios::beg
	seek_cur		ios::cur
	seek_end		ios::end

stream.h contains declarations of the names required for backward
compatibility with the stream package.

The macros for declaring manipulator classes (IOMANIP and  IOMANIP2)
have been replaced by a collection of macros that are more
"template-like". Two argument manipulators are not implemented.
(Users may follow the pattern in iomanip.h to implement them
themselves.)

filebuf and fstream operations no longer clear errno.

The virtual declaration of streambuf::setbuf now only has two
arguments. The three argument form exists in streambuf for
compatibility with the stream package, but the "official"
definition has only two arguments. Similarly the documented
constructor is now streambuf(char*,int).

The members of fstream (ifstream and ofstream) that used to return an
int as an error indication (namely open, attach, close) now return
void.  Errors are indicated by setting failbit in the error state.
There was some confusion here about whether an error was indicated by
returning 0 or EOF.  Declaraing these functions to return void
eliminates the possibility of confusion.

strstreambuf now allows setbuf in order to control sizes of
allocation in dynamic mode. (When character strings are being
automatically extended.)

More careful checks for whether flushes are required on streams that
are tied to other streams. (E.g. flushes on cout when characters are
extracted from cin.)

Tieing now works for insertion. E.g. cerr is tied to cout, so
insertion into cerr causes cout to be flushed.

Redundant calls to allocate have been removed from streambuf::xsgetn
and streambuf::xsputn.  (This means that the only calls to
streambuf::allocate from streambuf member functions are from the
virtuals that may be overriden in derived classes.)

open with ios::ate (the old atend) no longer implies ios::out (the
old output).  ios::app does.  (ate is a perfectly sensible mode
for input.)

eatwhite is defined for compatibility with stream package.
0707070044044145711004440042240042240000011611140443034215700001300000003313cstreams.c/*ident	"@(#)ctrans:lib/stream/cstreams.c	1.1.4.1" */
/**************************************************************************
                        Copyright (c) 1984 AT&T
                          All Rights Reserved   

        THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T
        
        The copyright notice above does not evidence any        
        actual or intended publication of such source code.

cstreams.c:

*****************************************************************************/

#include <iostream.h>
#include <fstream.h>
#include <new.h>
#include "streamdefs.h"

int Iostream_init::stdstatus = 0 ;
int Iostream_init::initcount = 0 ;

istream_withassign cin ;
ostream_withassign cout ;
ostream_withassign cerr ;
ostream_withassign clog ;

	// The value of Iostream_init::stdstatus describes the
	// The std stream variables

	// 0 means istream::stdin, ostream::stdout, ostream::stderr, and
	//	ostream::stdlog are unitialized
	// 1 means they are initialized to filebufs
	// 2 means they are initialized to stdiobufs

Iostream_init::Iostream_init() 
{
	++initcount ;
	if ( initcount > 1 ) return ;

	// Be careful.  Initialization occurs before constructors
	// of the standard streams are called.
	new (&cin) istream_withassign ;
	new (&cout) ostream_withassign ;
	new (&cerr) ostream_withassign ;
	new (&clog) ostream_withassign ;
	cin = new filebuf(0) ;
	cout = new filebuf(1) ;
	cerr = new filebuf(2) ;
	clog = new filebuf(2) ;

	cin.setf(~0L,ios::skipws) ;
	cerr.setf(~0L,ios::unitbuf) ;
	cin.tie(&cout) ;
	cerr.tie(&cout) ;
	clog.tie(&cout) ;
	stdstatus = 1 ;
	}

Iostream_init::~Iostream_init()
{
	--initcount ;
	if ( initcount > 0 ) return ;
	cout.flush() ;
	cerr.flush() ;
	clog.flush() ;
	}
0707070044044142401004440042240042240000011563100443207260400001200000021543filebuf.c/*ident	"@(#)ctrans:lib/stream/filebuf.c	1.1.2.2" */
/**************************************************************************
                        Copyright (c) 1984 AT&T
                          All Rights Reserved   

        THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T
      
        The copyright notice above does not evidence any        
        actual or intended publication of such source code.

filebuf.c:

*****************************************************************************/

#include <iostream.h>
#include <fstream.h>
#include <osfcn.h>
#include "streamdefs.h"

#ifndef O_RDONLY
#	include <fcntl.h>
#endif

#ifndef O_CREAT
#	define O_CREAT 00400
#endif

#ifndef O_TRUNC
#	define O_TRUNC 01000
#endif

#ifndef O_EXCL
#	define O_EXCL 02000
#endif


#ifndef O_APPEND
#	define O_APPEND 0
#endif

#include <errno.h>
extern int errno ;

const int filebuf::openprot = 0644 ;

static const int input=ios::in ;
static const int output=ios::out ;
static const int append=ios::app ;
static const int atend=ios::ate ;
static const int tcate=ios::trunc ;
static const int nocr=ios::nocreate ;
static const int norep=ios::noreplace ;

static const int seek_beg=ios::beg ;
static const int seek_end=ios::end ;
static const int seek_cur=ios::cur ;

int filebuf::last_op() 
{
	return (pptr()?output:(gptr()?input:0)) ;
}

inline void save_errno(int& orig)
{
	orig = ::errno ;
	::errno = 0 ;
}

inline int restore_errno(int& orig)
{
	if ( ::errno == 0 ) ::errno = orig ;
	return EOF ;
}
	
/*
 *	Open a file with the given mode.
 *	Return:		NULL if failure
 *			this if success
 */
filebuf* filebuf::open (const char *name, int om, int prot)
{
	int errno_orig ;
	save_errno(errno_orig) ;
	if ( om&append ) om |= output ;

	if ( opened ) {
		restore_errno(errno_orig) ;
		return 0 ;
		}

        int flags = 0 ;
	if ( om&append ) flags |= O_APPEND ;

	switch (om&(input|output)) {
	case input : 
		flags |=  O_RDONLY ;
		xfd = ::open(name,flags) ;
		break ;

	case output :
		flags |= O_WRONLY|O_CREAT|O_TRUNC ;
		if ( om&nocr ) flags &= ~O_CREAT ;
		if ( om&norep ) flags |= O_CREAT|O_EXCL ;
		if ( om&append ) flags |= O_APPEND ;
		if ( flags == (O_WRONLY|O_CREAT|O_TRUNC) ) {
			xfd = ::creat(name,prot) ;
			}
		else {
			xfd = ::open(name,flags,prot) ;
			}

		if ( xfd >= 0 && (om&(atend|append))) lseek(xfd,0,2) ;
		break ;

	case input|output:
		flags |= O_RDWR|O_CREAT ;
		if ( om&tcate ) flags |= O_TRUNC ;
		if ( om&append ) flags |= O_APPEND ;
		if ( om&nocr ) flags &= ~O_CREAT ;
		xfd = ::open(name,flags,prot) ;
		if ( xfd >= 0 && (om&(atend|append))) lseek(xfd,0,2) ;
		break;
	}

	if (xfd < 0) return 0;

	opened = 1;
	setp(0,0) ;
	setg(0,0,0) ;
	mode = om ;
	last_seek = EOF ;
	restore_errno(errno_orig) ;
	return this;
}

filebuf* filebuf::attach (int f)
{
	if ( opened ) return 0 ;
	xfd = f;
	opened = 1;
	setp(0,0) ;
	setg(0,0,0) ;
	mode=0 ;
	last_seek= EOF;
	return this;
}

/*
 *	Empty an output buffer.
 *	Returns:	EOF on error
 *			0 on success
 */
int filebuf::overflow(int c)
{
	int errno_orig ;
	save_errno(errno_orig) ;
	if ( !opened ) return restore_errno(errno_orig) ;
	if ( allocate() == EOF ) return restore_errno(errno_orig) ;
	if ( last_op() == input ) {
		if ( sync()==EOF ) return restore_errno(errno_orig) ;
	}

	register char* p = base() ;
	// pptr()==NULL does not imply p < pptr(),  so we need separate
	// test.
	while ( pptr() && p < pptr() )  {
		if ( O_APPEND==0 && (mode&append) ) {
			// System doesn't have an append mode, so approximate
			// as best we can.
			lseek(xfd,0,2) ;
			}
		/* Partial writes are sometimes possible in peculiar
		 * circumstances */
		register int count = write(xfd,p,pptr()-p) ;
		if ( count < 0 ) {
			last_seek = EOF ;
			return restore_errno(errno_orig) ;
		}
		p += count ;

		if ( SEEK_ARITH_OK	
				&& last_seek != EOF
				&& mode && !(mode&append)
				&& count >= 0 ) {
			last_seek += count ;
		} else {
			last_seek = EOF ;
		}

		if ( count < 0  ) return restore_errno(errno_orig) ;
	}

	setp(base(),ebuf()) ;
	setg(0,0,0);

	if ( c == EOF ) /* don't do anything */ ;
	else if ( unbuffered() ) {
		char ch = c;
		last_seek = EOF ;
		while ( write(xfd,&ch,1)!=1 && ::errno==0 ) ;
		if ( ::errno != 0 ) return restore_errno(errno_orig) ;
		}
	else {
		sputc(c) ;
		}

	restore_errno(errno_orig) ;
	return zapeof(c) ;
}


/*
 *	Fill an input buffer.
 *	Returns:	EOF on error or end of input
 *			next character on success
 */
int filebuf::underflow()
{
	int count;

	if ( !opened ) return EOF ;
	if ( allocate() == EOF ) return EOF ;
	if ( last_op() == output ) {
		if ( sync()==EOF ) return EOF ;
	}
	int orig_errno ;
	save_errno(orig_errno) ;
	setp(0,0) ;
	if ( unbuffered() ) {
		last_seek=EOF ;
		count = read(xfd,&lahead[0],1) ;
		setg(&lahead[0],&lahead[0],&lahead[count]) ;
		if ( count <= 0 ) return EOF ;
		} 
	else {
		register int	rdsize ;
		if ( blen() > 2*sizeof(long) ) {
			/* gptr must be set greater than base to
			 * guarantee at least 1 char of pushback.
			 * putting it farther will tend in many common
			 * cases to keep things aligned. 
			 */
			in_start = base()+sizeof(long) ;
			rdsize = blen()-sizeof(long) ;
		} else {
			in_start = base()+1 ;
			rdsize = blen()-1 ;
		}
		count = read(xfd,in_start,rdsize) ;
		while ( count<=0 && ::errno==EINTR ) {
			/*
			 * Signal caught and returned before any data
			 * transfered. 	
			 */
			::errno = 0 ;
			count = read(xfd,in_start,rdsize) ;
		}

		if ( SEEK_ARITH_OK	
				&& last_seek != EOF
				&& mode && !(mode&append) 
				&& count >= 0 ) {
			last_seek += count ;
		} else {
			last_seek = EOF ;
		}

		if ( count <= 0 ) {
			setg(0,0,0) ;
			return restore_errno(orig_errno) ;
			}
		setg(base(),in_start,in_start+count) ;
	}
	
	restore_errno(orig_errno) ;	
	return zapeof(*gptr());
}

filebuf* filebuf::close()
{
	int f = xfd ;
	if ( !opened ) {
		return 0 ;
	}
	if (last_op()==output) overflow();
	setg(0,0,0) ;
	setp(0,0) ;
	opened = 0 ;
	xfd = -1 ;
	last_seek = EOF ;
	if ( mode != 0 ) {
		mode = 0 ;
		int orig_errno ;
		save_errno(orig_errno) ;
		int ok = ::close(f);
		restore_errno(orig_errno) ;
		return ( ok==EOF ? 0 : this ) ;
	} else {
		return this ; 
	}
}

int filebuf::sync() 
{
	int ok = 0 ;
	int orig_errno ;
	save_errno(orig_errno) ;
	switch(last_op()) {
	case input: 
		last_seek = lseek(xfd,gptr()-egptr(),seek_cur) ;
		if ( last_seek < 0 ) {
			ok = EOF ;
			last_seek = EOF ;
			}
		break ;
	case output:
		ok = overflow() ;
		/* This does not result in infinite recursion even though
		 * under some circumstances overflow might call sync.
		 * it explicitly does not when last_op==output
		 */
		break;
	}
	setp(0,0) ;
	setg(0,0,0) ;
	last_seek = EOF ;
	restore_errno(orig_errno) ;
	return (ok==EOF ? EOF : 0 ) ;
}

streampos filebuf::seekoff(streamoff p, seek_dir d, int m)
{
	int orig_errno ;
	save_errno(orig_errno) ;

	if ( last_seek == EOF ) {
		last_seek = lseek(xfd,0,seek_cur) ;
		}
	if ( last_seek == EOF ) return EOF ;
	if( SEEK_ARITH_OK  && !unbuffered() ) {
		char* refptr = 0 ;
		streampos sneed ;
		streampos sref, minavail, maxavail ;

		switch ( last_op() ) {
		case input : {
			refptr = gptr() ;
			sref = last_seek-(egptr()-gptr()) ;
			minavail = last_seek-(egptr()-in_start) ; 
			maxavail = last_seek-1 ;
			} break ;
		case output : {
			// only allowable seek during output is
			// to present position. 
			refptr = pptr() ;
			sref = last_seek+pptr()-pbase() ;
			minavail = maxavail = sref ;
			} break  ;
		}
		switch( d ) {
		case seek_beg : sneed = p ; break ;
		case seek_cur : sneed = sref+p ;break ;
		case seek_end : refptr = 0 ; break ;
				/* Can't do seek_end */
		}
		if ( refptr && sneed >= minavail && sneed <= maxavail ) {
			switch( last_op() ) {
			case input : {
				setg(eback(),refptr+(sneed-sref),egptr());
				} break ;
			case output : {
				// Seeking to current position.  Nothing to
				// do.
				} break ;
			default : { 
				// shouldn't get here.  Try to recover somehow
				sync() ;
				seekoff(p,d,m);
				} break ;
			}
			return sneed ;
		}
		if ( refptr && sneed < sref && sneed+blen()/2 > sref 
			&& last_op() == input ) {
			// looks like we are stepping backward through
			// a file.  Performance may be improved by
			// backing up a little extra. 

			streampos toofar = sneed-blen()/2 ;
			if ( toofar < 0 ) toofar = 0 ;
			sync() ;
			last_seek=lseek(xfd,toofar,seek_beg) ;
			overflow();
			seekoff(p,d,m);
		}
	}

	restore_errno(orig_errno) ;
	if ( sync()==EOF )	return EOF ;
	else	{
		last_seek=lseek(xfd,p,d) ;
		return last_seek ;
		}
}

filebuf::filebuf()
	: xfd(-1), opened(0), mode(0), last_seek(EOF)
{

}

filebuf::filebuf(int f)
	: xfd(f), opened(1), mode(0), last_seek(EOF)
{

}

filebuf::filebuf(int f, char* p, int l) 
	: streambuf(p,l), xfd(f), opened(1), mode(0), last_seek(EOF)
{

}
	
filebuf::~filebuf() {
	close() ;
	}

streambuf* filebuf::setbuf(char* p , int len)
{
	if ( is_open() && base() ) return 0 ;
	// Note the special case of allowing buffering to be turned
	// on even for an already opened filebuf.
	setb(0,0) ;
	return streambuf::setbuf(p,len) ;
}
0707070044044145301004440042240042240000011662000443034061200000600000006470flt.c/*ident	"@(#)ctrans:lib/stream/flt.c	1.1.4.1" */
/**************************************************************************
                        Copyright (c) 1984 AT&T
                          All Rights Reserved   

        THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T
        
        The copyright notice above does not evidence any        
        actual or intended publication of such source code.

flt.c:

*****************************************************************************/

#include <iostream.h>
#include <ctype.h>
#include <stdio.h>
#include <libc.h>
#include <string.h>

#define OSTREAM ostream
#define ISTREAM istream

// This file contains all the functions having to do with i/o of
// floats and doubles.  It drags in lots of stuff from stdio, which
// is why I made it separate.

istream& ISTREAM::operator>>(double& d)
/*
	{+|-} d* {.} d* { e|E {+|-} d+ } 
	except that
		- a dot must be pre- or succeeded by at least one digit
		- an exponent must be preceded by at least one digit
*/
{
	register c = 0;
	register anydigits = 0 ;
	char buf[256];
	register char* p = buf;
	register streambuf* nbp = bp;
	
	if (!ipfx() ) return *this ;

	/* get the sign */
	switch (c = nbp->sgetc()) {
	case EOF:
		setstate(eofbit|failbit) ;
		return *this;
	case '-':
	case '+':
		*p++ = c;
		c = bp->snextc();
	}

	/* get integral part */
	while (isdigit(c)) {
		*p++ = c;
		c = bp->snextc();
		anydigits = 1 ;
	}

	/* get fraction */
	if (c == '.') {
		do {
			*p++ = c;
			c = bp->snextc();
			anydigits = 1 ;
		} while (isdigit(c));
	}

	/* get exponent */
	if ( anydigits && (c == 'e' || c == 'E')) {
		*p++ = c;
		switch (c = nbp->snextc()) {
		case EOF:
			setstate(eofbit|failbit) ;
			return *this;
		case '-':
		case '+':
			*p++ = c;
			c = bp->snextc();
		}
		while (isdigit(c)) {
			*p++ = c;
			c = bp->snextc();
		}
	}

	*p = 0;
	d = atof(buf);

	if (c == EOF) setstate(eofbit) ;
	if (!anydigits) setstate(badbit) ;
	return *this;
}


istream& ISTREAM::operator>>(float& f)
{
	double d;


	if (!ipfx() ) return *this ;

	*this >> d ;
	if ( good() ) f = d;

	return *this;
}

ostream& OSTREAM::operator<<(float f)  { return *this << (double)f ; }

static const int fltbits =
		ios::scientific|ios::fixed|ios::uppercase ;

ostream& OSTREAM::operator<<(double d)
{
	char buf[32];
	int w = width(0) ;
	int p = precision() ;
	int explicitp = ( p > 0 ) || (flags()&ios::fixed) ;
	if (!opfx()) return *this;
	long bits = flags() & fltbits ;
	char fmt[20] ;
	strcpy(fmt,"%") ;
	if ( flags() & ios::showpoint ) {
		strcat(fmt,"#") ;
		}
	if ( flags() & ios::showpos ) {
		strcat(fmt,"+") ;
		}
	if ( explicitp ) {
		strcat(fmt,".*") ;
		}

	long mode = flags()
		    & (ios::scientific|ios::fixed|ios::uppercase);
	
	switch(mode) {
	case ios::scientific :		strcat(fmt,"e") ; break ;
	case ios::scientific|ios::uppercase :
						strcat(fmt,"E") ; break;
	case ios::fixed :			strcat(fmt,"f") ; break ;
	case ios::fixed|ios::uppercase:	strcat(fmt,"F") ; break ;
	case ios::uppercase :		strcat(fmt,"G") ; break ;
	default :				strcat(fmt,"g") ; break ;
	}

	if ( explicitp ) {
		sprintf(buf,fmt,p,d) ;
		}
	else {
		sprintf(buf,fmt,d) ;
		}

	int padf = w-strlen(buf) ;
	if ( padf < 0 ) padf = 0 ;
	if ( padf && !(flags()&ios::left) ) {
		while ( padf-- > 0 ) put(fill()) ;
		}
	*this << buf ;
	while ( padf-- > 0 ) put(fill()) ;
	osfx() ;
	return *this ;
	}
0707070044044146061004440042240042240000011611500443013563700001200000005353fstream.c/*ident	"@(#)ctrans:lib/stream/fstream.c	1.1.2.2" */
/**************************************************************************
                        Copyright (c) 1984 AT&T
                          All Rights Reserved   

        THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T
      
        The copyright notice above does not evidence any        
        actual or intended publication of such source code.

fstream.c:

*****************************************************************************/

#include <iostream.h>
#include <fstream.h>

static const int ios_atend = ios::ate ;
static const int ios_input = ios::in ;
static const int ios_output = ios::out ;
static const int ios_append = ios::app ;
static const int seek_cur = ios::cur ;
static const int seek_end = ios::end ;
static const int seek_beg = ios::beg ;

fstreambase::fstreambase() { init(&buf) ; }

fstreambase::fstreambase(const char* name, int mode, int prot)
{
	init(&buf) ;
	open(name,mode,prot) ;
	}

fstreambase::fstreambase(int fd) 
	: buf(fd) 
{
	init(&buf) ;
	}

fstreambase::fstreambase(int fd, char* p, int l)
	: buf(fd,p,l) 
{
	init(&buf) ;
	}

static inline void fstreambase::verify(int ok)
{
	if ( ok ) clear(0) ;
	else 	  setstate(ios::failbit) ;
	}

void fstreambase::setbuf(char* p, int len) 
{
	verify(buf.setbuf(p,len) != 0 ) ;
	}

void fstreambase::open(const char* name, int mode, int prot)
{
	verify(buf.open(name,mode,prot) != 0 ) ;
	}

void fstreambase::attach(int fd ) 
{
	verify(buf.attach(fd) != 0 ) ;
	}

void fstreambase::close() 
{
	verify(buf.close() != (filebuf*)0 ) ;
	}

fstreambase::~fstreambase() { }

ifstream::ifstream() { }
ifstream::ifstream(const char* name, int mode, int prot)
	: fstreambase(name,mode|ios_input,prot) { }
ifstream::ifstream(int fd) : fstreambase(fd) { }
ifstream::ifstream(int fd, char* p, int l) : fstreambase(fd,p,l) { }
ifstream::~ifstream() { }

void ifstream::open(const char* name, int mode, int prot)
{
	verify(rdbuf()->open(name,mode|ios_input,prot) != (filebuf*)0 ) ;
	}

ofstream::ofstream() { }
ofstream::ofstream(const char* name, int mode, int prot)
	: fstreambase(name,mode|ios_output,prot) { }
ofstream::ofstream(int fd) : fstreambase(fd) { }
ofstream::ofstream(int fd, char* p, int l) : fstreambase(fd,p,l) { }
ofstream::~ofstream() { }
void ofstream::open(const char* name, int mode, int prot)
{
	verify(rdbuf()->open(name,mode|ios_output,prot) != (filebuf*)0 ) ;
	}

fstream::fstream() { }
fstream::fstream(const char* name, int mode, int prot)
	: fstreambase(name,mode,prot) { }
fstream::fstream(int fd) : fstreambase(fd) { }
fstream::fstream(int fd, char* p, int l) : fstreambase(fd,p,l) { }
fstream::~fstream() { }void fstream::open(const char* name, int mode, int prot)
{
	verify(rdbuf()->open(name,mode,prot) != (filebuf*)0 ) ;
	}
0707070044044146021004440042240042240000011560430443013461300001200000005573fstream.h/*ident	"@(#)ctrans:incl/fstream.h	1.1.1.2" */
/**************************************************************************
                        Copyright (c) 1984 AT&T
                          All Rights Reserved   

        THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T
      
        The copyright notice above does not evidence any        
        actual or intended publication of such source code.

*****************************************************************************/
#ifndef FSTREAMH
#define FSTREAMH

#include <iostream.h>

class  filebuf : public streambuf {	/* a stream buffer for files */
public:
	static const int openprot ; /* default protection for open */
public:
			filebuf() ;
			filebuf(int fd);
			filebuf(int fd, char*  p, int l) ;

	int		is_open() { return opened ; }
	int		fd() { return xfd ; }
	filebuf*	open(const char *name, int om, int prot=openprot);
	filebuf*	attach(int fd) ;
	filebuf* 	close() ;
			~filebuf() ;
public: /* virtuals */
	virtual int	overflow(int=EOF);
	virtual int	underflow();
	virtual int	sync() ;
	virtual streampos
			seekoff(streamoff,seek_dir,int) ;
	virtual streambuf*
			setbuf(char*  p, int len) ;
protected:
	int		xfd;	
	int		mode ;
	char		opened;
	streampos	last_seek ;
	char* 		in_start;
	int		last_op();
	char		lahead[2] ;
};

class fstreambase : virtual public ios { 
public:
			fstreambase() ;
	
			fstreambase(const char* name, 
					int mode,
					int prot=filebuf::openprot) ;
			fstreambase(int fd) ;
			fstreambase(int fd, char*  p, int l) ;
			~fstreambase() ;
	void		open(const char* name, int mode, 
					int prot=filebuf::openprot) ;
	void		attach(int fd);
	void		close() ;
	void		setbuf(char*  p, int l) ;
	filebuf*	rdbuf() { return &buf ; }
private:
	filebuf		buf ;
protected:
	void		verify(int) ;
} ;

class ifstream : public fstreambase, public istream {
public:
			ifstream() ;
			ifstream(const char* name, 
					int mode=ios::in,
					int prot=filebuf::openprot) ;
			ifstream(int fd) ;
			ifstream(int fd, char*  p, int l) ;
			~ifstream() ;

	filebuf*	rdbuf() { return fstreambase::rdbuf(); }
	void		open(const char* name, int mode=ios::in, 
					int prot=filebuf::openprot) ;
} ;

class ofstream : public fstreambase, public ostream {
public:
			ofstream() ;
			ofstream(const char* name, 
					int mode=ios::out,
					int prot=filebuf::openprot) ;
			ofstream(int fd) ;
			ofstream(int fd, char*  p, int l) ;
			~ofstream() ;

	filebuf*	rdbuf() { return fstreambase::rdbuf(); }
	void		open(const char* name, int mode=ios::out, 
					int prot=filebuf::openprot) ;
} ;

class fstream : public fstreambase, public iostream {
public:
			fstream() ;
	
			fstream(const char* name, 
					int mode,
					int prot=filebuf::openprot) ;
			fstream(int fd) ;
			fstream(int fd, char*  p, int l) ;
			~fstream() ;
	filebuf*	rdbuf() { return fstreambase::rdbuf(); }
	void		open(const char* name, int mode, 
				int prot=filebuf::openprot) ;
} ;

#endif
0707070044044142541004440042240042240000011572060437432273600000500000003350in.c/*ident	"@(#)ctrans:lib/stream/in.c	1.1.1.1" */
/**************************************************************************
			Copyright (c) 1984 AT&T
	  		  All Rights Reserved  	

	THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T
	
	The copyright notice above does not evidence any   	
	actual or intended publication of such source code.

in.c:

*****************************************************************************/

#include <ctype.h>
#include <iostream.h>

#define ISTREAM istream

void ISTREAM::eatwhite ()
{
	register streambuf *nbp = bp;
	register int c = nbp->sgetc();
	while (isspace(c)) c = nbp->snextc();
	if (c == EOF) setstate(eofbit);
}

void ISTREAM::xget(char* c) 
{
	register streambuf* sbp = bp ;
	if ( !ipfx(1) ) return ;
	x_gcount = 0 ; 
	register int newc = sbp->sbumpc() ;
	if ( newc == EOF ) {
		setstate(failbit|eofbit) ;
		return ;
		}
	x_gcount = 1 ;
	*c = newc ;
	}

istream& ISTREAM::operator>>(register char* s)
{
	/* get string */

	register int w = width(0) ;
	if ( flags()&skipws ) {
		// We don't know a maximum number of required
		// characters 
		if ( !ipfx(0) ) return *this ;
		}
	else if ( !ipfx(w) ) {
		return *this ;
		}

	register streambuf *nbp = bp;
	register int c = nbp->sgetc();

	if (c == EOF) setstate(failbit|eofbit) ;

	if ( w > 0 ) {
		while (!isspace(c) && c != EOF && --w > 0 ) {
			*s++ = c;
			c = nbp->snextc();
		}
	} else {
		while (!isspace(c) && c != EOF ) {
			*s++ = c;
			c = nbp->snextc();
		}
	}
	
	*s = '\0';

	if (c == EOF) setstate(eofbit) ;

	return *this;
}

istream& ISTREAM::operator>>(unsigned char* s)
{
	return *this >> (char*)s ;
}

istream& ISTREAM::putback(register char c)
{
	if ( !good() ) return *this ;
	if ( bp->sputbackc(c) == EOF ) setstate(badbit) ;
	return *this;
}
0707070044044142711004440042240042240000011574300437215614100001000000010725intin.c/*ident	"@(#)ctrans:lib/stream/intin.c	1.1.1.1" */
/**************************************************************************
			Copyright (c) 1984 AT&T
	  		  All Rights Reserved  	

	THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T
	
	The copyright notice above does not evidence any   	
	actual or intended publication of such source code.

intin.c: Input conversions of numbers

*****************************************************************************/


#include <ctype.h>
#include <iostream.h>

/****************
 * 
 *	This file contains the extraction operations for integer input. 
 *	It suffers from several flaws that ought to be fixed. 
 *
 * 	All other versions depend on the extractor for longs to
 *	do the real work.  This is OK when int==long but on a machine
 * 	where int!=long there will be a large performance penalty.
 *
 *  	Overflow detection is limited to cases where the long is
 *	shortened and changes its value.  This misses a lot of cases.
 *
 ***************/


#define ISTREAM istream

static const int a10 = 'a'-10;
static const int A10 = 'A'-10;

istream& ISTREAM::operator>>(long& i)
{
	// This code ignores overflows.  This ought to be fixed
	// in some future version.

	if ( !ipfx() ) return *this ;

	register int	c;
	register int	base	;

	switch ( flags()&(ios::dec|ios::hex|ios::oct) ) {
		case ios::hex :	base = 16 ; break ;
	  	case ios::oct :	base = 8 ; break ;
		case ios::dec :	base = 10 ; break ;
		default :		base = 0 ; break ;
		}

	register streambuf *nbp	= bp;	// put bp in a reg for efficiency
	register int	x	= 0 ;	// how many chars are processed 
	register int	neg	= 0;	// set to '-' for negative number

	switch (c = nbp->sgetc()) {
	case '-':
		neg = 1 ;
		c = nbp->snextc(); ++x ;
		break;
	case '+':
		c = nbp->snextc(); ++x ;
		break;
	case EOF:
		setstate(failbit|eofbit) ;
		break ;
	}

	if ( base==0 && c=='0' ) {
		c = nbp->snextc() ; ++x ;

		if ( c=='x' || c=='X' ) {
			base = 16 ;
			c = nbp->snextc() ; ++x ;
			}
		else {
			base = 8 ;
		}
	} else if ( base==0 ) base = 10 ;

	// for efficiency we have similar loops
	// Note that when we reach this point c has already been set to
	// the first char of the string to be converted. 

	if ( base==10 ) {
		register long ii = 0;
		for( ; isdigit(c) ; c=nbp->snextc(),++x ) {
			
			/* accumulate as negative to avoid problems
			 * with biggest negative integer on
		 	 * 2's complement machines
			 */
			ii = ii*10-(c-'0');
		}
		i = neg ? ii : -ii;
	} else if ( base < 10 ) {
		register unsigned long ii = 0;
		for( ; isdigit(c)  ; c=nbp->snextc(),++x ) {
			/* accumulate as unsigned */
			register int diff = c-'0' ;
			if ( diff >= base ) break ;
			ii = ii*base+diff ;
		}
		i = neg ? -(long)ii : (long)ii;
	} else if ( base>10 ) { /* hex like base */
		register unsigned long ii = 0;
		/* accumulate as unsigned */
		for( ; isxdigit(c) ; c=nbp->snextc(),++x ) {
			register int diff ;
			if ( isdigit(c) )	diff = (c-'0');
			else if ( isupper(c) )	diff = (c-A10);
			else			diff = (c-a10);
			if ( diff >= base ) break ;
			ii = ii*base+diff ;
		}
		i = neg ? -(long)ii : (long)ii;
	}
	

	if (x == 0 ) setstate(failbit) ;
				// Correct treatment of this case
				// (i.e. no correct digits) 
				// is unclear. Making it an error
				// avoids certain infinite loops.
			
	return *this;
}

istream& ISTREAM::operator>>(int& i)
{
	long l;
	
	if ( !ipfx() ) return *this ;

	*this>>l ;
	if ( good() ) {
		i = (int)l ;
		if  ( i != l ) {
			// overflow
			setstate(failbit) ;
			}
		} 
	return *this;
}

istream& ISTREAM::operator>>(short& i)
{
	long l;

	if (!ipfx() ) return *this ;

	*this>>l ;
	if ( good() ) {
		i = (short)l ;
		if  ( i != l ) {
			// overflow
			setstate(failbit) ;
			}
		} 

	return *this;
}


// The following routines deal with unsigned by reading a long and
// copying.  This is certainly safe for "shorts", but is
// slightly problematic for ints and longs.  It works on "common"
// machines.


istream& ISTREAM::operator>>(unsigned short& u)
{
	long l ;
	*this >> l ;
	if ( good() ) {
		u = (unsigned short)l ;
		if  ( u != l ) {
			// overflow
			setstate(failbit) ;
			}
		} 
	return *this ;
	} 

istream& ISTREAM::operator>>(unsigned int& u)
{
	long l ;
	*this >> l ;
	if ( good() ) {
		u = (unsigned int)l ;
		if  ( u != l ) {
			// overflow
			setstate(failbit) ;
			}
		} 
	return *this ;
	} 

istream& ISTREAM::operator>>(unsigned long& u)
{
	long l ;
	*this >> l ;
	if ( good() ) {
		u = (unsigned long)l ;
		if  ( u != l ) {
			// overflow
			setstate(failbit) ;
			}
		} 
	return *this ;
	} 

0707070044044142501004440042240042240000011613440437222454700001200000006507iomanip.h/*ident	"@(#)ctrans:incl/iomanip.h	1.1.1.2" */
/**************************************************************************
                        Copyright (c) 1984 AT&T
                          All Rights Reserved   

        THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T
      
        The copyright notice above does not evidence any        
        actual or intended publication of such source code.

*****************************************************************************/

#ifndef IOMANIPH
#define IOMANIPH

#include <generic.h>

#define SMANIP(T)name2(smanip_,T)
#define SAPP(T)name2(sapply_,T)
#define IMANIP(T)name2(imanip_,T)
#define OMANIP(T)name2(omanip_,T)
#define IOMANIP(T)name2(iomanip_,T)
#define IAPP(T)name2(iapply_,T)
#define OAPP(T)name2(oapply_,T)
#define IOAPP(T)name2(ioapply_,T)

#define IOMANIPdeclare(T)						\
class SMANIP(T) {							\
	ios& (*fct)(ios&,T) ;						\
	T arg ;								\
public:									\
	SMANIP(T)(ios& (*f)(ios&, T), T a) :				\
			fct(f), arg(a) { }				\
	friend istream& operator>>(istream& i, SMANIP(T)& m) {		\
			ios* s = &i ;					\
			(*m.fct)(*s,m.arg) ; return i ; }		\
	friend ostream& operator<<(ostream& o, SMANIP(T)& m) {		\
			ios* s = &o ;					\
			(*m.fct)(*s,m.arg) ; return o ; }		\
	} ;								\
class SAPP(T) {								\
	ios& (*fct)(ios&, T) ;						\
public:									\
	SAPP(T)(ios& (*f)(ios&,T)) : fct(f) { }				\
	SMANIP(T) operator()(T a) {					\
			return SMANIP(T)(fct,a) ; }			\
	} ;								\
class IMANIP(T) {							\
	istream& (*fct)(istream&,T) ;					\
	T arg ;								\
public:									\
	IMANIP(T)(istream& (*f)(istream&, T), T a ) :			\
		fct(f), arg(a) { }					\
	friend istream& operator>>(istream& s, IMANIP(T)& m) {		\
		return(*m.fct)(s,m.arg) ;				\
		}							\
	} ;								\
class IAPP(T) {								\
	istream& (*fct)(istream&, T) ;					\
public:									\
	IAPP(T)(istream& (*f)(istream&,T)) : fct(f) { }			\
	IMANIP(T) operator()(T a) {					\
			return IMANIP(T)(fct,a) ; }			\
	} ;								\
class OMANIP(T) {							\
	ostream& (*fct)(ostream&,T) ;					\
	T arg ;								\
public:									\
	OMANIP(T)(ostream& (*f)(ostream&, T), T a ) :			\
		fct(f), arg(a) { }					\
	friend ostream& operator<<(ostream& s, OMANIP(T)& m) {		\
		return(*m.fct)(s,m.arg) ;				\
		}							\
	} ;								\
class OAPP(T) {								\
	ostream& (*fct)(ostream&, T) ;					\
public:									\
	OAPP(T)(ostream& (*f)(ostream&,T)) : fct(f) { }			\
	OMANIP(T) operator()(T a) {					\
			return OMANIP(T)(fct,a) ; }			\
	} ;								\
class IOMANIP(T) {							\
	iostream& (*fct)(iostream&,T) ;					\
	T arg ;								\
public:									\
	IOMANIP(T)(iostream& (*f)(iostream&, T), T a ) :		\
		fct(f), arg(a) { }					\
	friend istream& operator>>(iostream& s, IOMANIP(T)& m) {	\
		return(*m.fct)(s,m.arg) ;				\
		}							\
	friend ostream& operator<<(iostream& s, IOMANIP(T)& m) {	\
		return(*m.fct)(s,m.arg) ;				\
		}							\
	} ;								\
class IOAPP(T) {							\
	iostream& (*fct)(iostream&, T) ;				\
public:									\
	IOAPP(T)(iostream& (*f)(iostream&,T)) : fct(f) { }		\
	IOMANIP(T) operator()(T a) {					\
			return IOMANIP(T)(fct,a) ; }			\
	} ;								\



IOMANIPdeclare(int) ;
IOMANIPdeclare(long) ;

SMANIP(int) 	setbase(int b) ;	/* 10, 8, 16 or 0 */
SMANIP(long)	resetiosflags(long b) ;
SMANIP(long)	setiosflags(long b) ;
SMANIP(int)	setfill(int f);
SMANIP(int)	setprecision(int p);
SMANIP(int)	setw(int w) ;

#endif
0707070044044142431004440042240042240000011577100443212410100001300000032472iostream.h/*ident	"@(#)ctrans:incl/iostream.h	1.1.5.2" */
/**************************************************************************
                        Copyright (c) 1984 AT&T
                          All Rights Reserved   

        THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T
      
        The copyright notice above does not evidence any        
        actual or intended publication of such source code.

*****************************************************************************/
#ifndef IOSTREAMH
#define IOSTREAMH

#include <memory.h>
		/* Some inlines use memcpy */

/* If EOF is defined already verify that it is -1.  Otherwise
 * define it.
 */

#ifdef EOF
#	if EOF!=-1
#		define EOF (-1) 
#	endif
#else
#	define EOF (-1)
#endif

/* Don't worry about NULL not being 0 */
#ifndef NULL
#	define NULL 0
#endif

#define	zapeof(c) ((c)&0377)
	    /* extracts char from c. The critical requirement is
	     *      zapeof(EOF)!=EOF
	     * ((c)&0377) and ((unsigned char)(c)) are alternative definitions
	     * whose efficiency depends on compiler environment.
	     */

typedef long streampos ;
typedef long streamoff ;

class streambuf ;
class ostream ;


class ios {
public: /* Some enums are declared in ios to avoid pollution of
	 * global namespace
	 */
	enum io_state	{ goodbit=0, eofbit=1, failbit=2, badbit=4, 
				hardfail=0200};
				/* hard fail can be set and reset internally,
				 * but not via public function */
	enum open_mode	{ in=1, out=2, ate=4, app=010, trunc=020,
				nocreate=040, noreplace=0100} ;
	enum seek_dir	{ beg=0, cur=1, end=2 } ;

	/* flags for controlling format */
	enum		{ skipws=01,	
					/* skip whitespace on input */
			  left=02,  right=04, internal=010,
					/* padding location */
			  dec=020, oct=040, hex=0100, 
					/* conversion base */
			  showbase=0200, showpoint=0400, uppercase=01000,
			  showpos=02000, 
					/* modifiers */
			  scientific=04000, fixed=010000,
					/* floating point notation */
			  unitbuf=020000, stdio=040000
					/* stuff to control flushing */
			  } ;
	static const long 
			basefield ; /* dec|oct|hex */
	static const long
			adjustfield ; /* left|right|internal */
	static const long
			floatfield ; /* scientific|fixed */
public:
			ios(streambuf*) ;
	virtual		~ios() ;

	long		flags() 	{ return x_flags ; }
	long		flags(long f);

	long		setf(long setbits, long field);
	long		setf(long) ;
	long		unsetf(long) ;

	int		width()		{ return x_width ; }
	int		width(int w)
	{
			int i = x_width ; x_width = w ; return i ;
	}
		
	ostream*	tie(ostream* s); 
	ostream*	tie()		{ return x_tie ; }
	char		fill(char) ;
	char		fill() 		{ return x_fill ; }
	int		precision(int) ;
	int		precision()	{ return x_precision ; }

	int		rdstate()	{ return state ; }
			operator void*()
				{
				if (state&(failbit|badbit|hardfail)) return 0 ;
				else return this ;
				}

	int		operator!()
				{ return state&(failbit|badbit|hardfail); } 
	int		eof()	{ return state&eofbit; }
	int		fail()	{ return state&(failbit|badbit|hardfail); }
	int		bad()	{ return state&badbit ; }
	int		good()	{ return state==0 ; }
	void		clear(int i =0) 
				{	
				state =  (i&0377) | (state&hardfail) ;
				ispecial = (ispecial&~0377) | state ; 
				ospecial = (ospecial&~0377) | state ; 
				}
	streambuf*	rdbuf() { return bp ;} 

public: /* Members related to user allocated bits and words */
	long &		iword(int) ;
	void* &		pword(int) ;
	static long	bitalloc() ;
	static long	xalloc() ;

private: /*** privates for implemting allocated bits and words */ 
	static long	nextbit ;
	static long	nextword ;
	
	int		nuser ;
	union ios_user_union*
			x_user ;
	void	uresize(int) ;
public: /* static member functions */
	static void	sync_with_stdio() ;
protected:
	enum 		{ skipping=01000, tied=02000 } ;
			/*** bits 0377 are reserved for userbits ***/
	streambuf*	bp;
	void		setstate(int b)
			{	state |= (b&0377) ;
				ispecial |= b&~skipping ;
				ispecial |= b ;
			}
	int		state;	
	int		ispecial;		
	int		ospecial;
	int		isfx_special;
	int		osfx_special;		
	int		delbuf;
	ostream*	x_tie;
	long 		x_flags;
	short		x_precision;
	char		x_fill;
	short 		x_width;

	static void	(*stdioflush)() ;

	void		init(streambuf*) ;
				/* Does the real work of a constructor */
			ios() ; /* No initialization at all. Needed by
				 * multiple inheritance versions */
	int		assign_private ;
				/* needed by with_assgn classes */
private:		
			ios(ios&) ; /* Declared but not defined */
	void		operator=(ios&) ; /* Declared but not defined */
public:   /* old stream package compatibility */
	int		skip(int i) ; 
};

class streambuf {
	short		alloc;	
	short		x_unbuf;
	char* 		x_base;	
	char*		x_pbase;
	char*		x_pptr;	
	char* 		x_epptr;
	char* 		x_gptr;
	char*		x_egptr;
	char*		x_eback;
	int		x_blen;	
    private:
			streambuf(streambuf&); /* Declared but not defined */
	void		operator=(streambuf&); /* Declared but not defined */
    public:
	void		dbp();
    protected:
	char*		base() 		{ return x_base ; }
	char*		pbase()		{ return x_pbase ; }
	char*		pptr() 		{ return x_pptr ; }
	char*		epptr() 	{ return x_epptr ; }
	char*		gptr() 		{ return x_gptr ; }
	char*		egptr() 	{ return x_egptr ; }
	char*		eback() 	{ return x_eback ; }
	char* 		ebuf()		{ return x_base+x_blen ; }
	int		blen()		{ return x_blen; }
	void		setp(char*  p, char*  ep)
	{
		x_pbase=x_pptr=p ; x_epptr=ep ;
	}
	void		setg(char*  eb,char*  g, char*  eg)
	{
		x_eback=eb; x_gptr=g ; x_egptr=eg ;
	}
	void		pbump(int n) 
	{ 
		x_pptr+=n ;
	}

	void		gbump(int n) 
	{ 
		x_gptr+=n ;
		}

	void		setb(char* b, char* eb, int a = 0 )
	{
		if ( alloc && x_base ) delete x_base ;
		x_base = b ;
		x_blen= (eb>b) ? (eb-b) : 0 ;
		alloc = a ;
		}
	int		unbuffered() { return x_unbuf; }
	void		unbuffered(int unb) { x_unbuf = (unb!=0)  ; }
	int		allocate()
	{
		if ( x_base== 0 && !unbuffered() ) return doallocate() ;
		else			  	 return 0 ;
	}
	virtual int 	doallocate();
    public : 
	virtual int	overflow(int c=EOF);
	virtual int	underflow();
	virtual int	pbackfail(int c);
	virtual int	sync();
	virtual streampos
			seekoff(streamoff,seek_dir,int =ios::in|ios::out);
	virtual streampos
			seekpos(streampos, int =ios::in|ios::out) ;
	virtual int	xsputn(const char*  s,int n);
	virtual int	xsgetn(char*  s,int n);

	int		in_avail()
	{
		return x_gptr<x_egptr ? x_egptr-x_gptr : 0 ;
	}

	int		out_waiting() 
	{	
		if ( x_pptr ) return x_pptr-x_pbase ;
		else	      return 0 ; 
	}

	int		sgetc()
	{
		/***WARNING: sgetc does not bump the pointer ***/
		return (x_gptr>=x_egptr) ? underflow() : zapeof(*x_gptr);
	}
	int		snextc()
	{
		return (++x_gptr>=x_egptr)
				? x_snextc()
				: zapeof(*x_gptr);
	}
	int		sbumpc()
	{
		return  ( x_gptr>=x_egptr && underflow()==EOF ) 
				? EOF 
				: zapeof(*x_gptr++) ;
	}
	void		stossc()
	{
		if ( x_gptr++ > x_egptr ) underflow() ;
	}

	int		sputbackc(char c)
	{
		if (x_gptr > x_eback ) {
			if ( *--x_gptr == c ) return zapeof(c) ;
			else 		      return zapeof(*x_gptr=c) ;
		} else {
			return pbackfail(c) ;
		}
	}

	int		sputc(int c)
	{
		return (x_pptr>=x_epptr) ? overflow(zapeof(c))
				      : zapeof(*x_pptr++=c);
	}
	int		sputn(const char*  s,int n)
	 {
		if ( n <= (x_epptr-x_pptr) ) {
			memcpy(x_pptr,s,n) ;
			pbump(n);
			return n ;
		} else {
			return xsputn(s,n) ;
		}
	}
	int		sgetn(char*  s,int n)
	{
		if ( n <= (x_egptr-x_gptr) ) {
			memcpy(s,x_gptr,n) ;
			gbump(n);
			return n ;
		} else {
			return xsgetn(s,n) ;
		}
	}
	virtual streambuf*
			setbuf(char*  p, int len) ;
   	streambuf*	setbuf(unsigned char*  p, int len) ;

	streambuf*	setbuf(char*  p, int len, int count) ;
				/* obsolete third argument */
  			/*** Constructors -- should be protected ***/
			streambuf() ;
			streambuf(char*  p, int l) ;

			streambuf(char*  p, int l,int c) ;
			/* 3 argument form is obsolete.
			 * Use strstreambuf.
			 */
	virtual		~streambuf() ;
private:
	int		x_snextc() ;
};

class istream : virtual public ios {
public: /* Constructor */
			istream(streambuf*) ;
	virtual		~istream() ;
public:	
	int		ipfx(int noskipws=0)
			{	if ( noskipws?(ispecial&~skipping):ispecial) {
					return do_ipfx(noskipws) ;
				} else return 1 ;
			}
	void		isfx() { }  
	istream&	seekg(streampos p) ;
	istream&	seekg(streamoff o, seek_dir d) ;
   	streampos	tellg() ; 
	istream&	operator>> (istream& (*f)(istream&))
			{	return (*f)(*this) ; }
	istream&	operator>> (ios& (*f)(ios&) ) ;
	istream&	operator>>(char*);
	istream&	operator>>(unsigned char*);
	istream&	operator>>(unsigned char& c)
			{	if ( ipfx(0) ) {
					if (  bp->in_avail() ) {
						c = bp->sbumpc() ;
					} else  xget((char*)&c) ;
				}
				return *this ;
			}
	istream&	operator>>(char& c)
			{	if ( ipfx(0) ) {
					if (  bp->in_avail() ) {
						c = bp->sbumpc() ;
					} else  xget((char*)&c) ;
				}
				return *this ;
			}
	istream&	operator>>(short&);
	istream&	operator>>(int&);
	istream&	operator>>(long&);
	istream&	operator>>(unsigned short&);
	istream&	operator>>(unsigned int&);
	istream&	operator>>(unsigned long&);
	istream&	operator>>(float&);
	istream&	operator>>(double&);
	istream&	operator>>(streambuf*);
	istream&	get(char* , int lim, char delim='\n');
	istream&	get(unsigned char* b,int lim, char delim='\n');
	istream&	getline(char* b, int lim, char delim='\n');
	istream&	getline(unsigned char* b, int lim, char delim='\n');
	istream&	get(streambuf& sb, char delim ='\n');
	istream&	get(unsigned char& c)
			{
				if ( ipfx(1) && bp->in_avail()) {
					x_gcount = 1 ;
					c = bp->sbumpc() ;
				} else {
					xget((char*)&c) ;
				}
				return *this ;
			}
	istream&	get(char& c)
			{
				if ( ipfx(1) && bp->in_avail()) {
					x_gcount = 1 ;
					c = bp->sbumpc() ;
				} else {
					xget(&c) ;
				}
				return *this ;
			}
	int 		get()
			{
				int c ;
				if ( !ipfx(1) ) return EOF ;
				else {
					c = bp->sbumpc() ;
					if ( c == EOF ) setstate(eofbit) ;
					return c ;
					}
			}
	int		peek() 
			{
				if ( ipfx(-1) ) return bp->sgetc() ;
				else		return EOF ;

			}
	istream&	ignore(int n=1,int delim=EOF) ;
	istream&	read(char*  s,int n);
	istream&	read(unsigned char* s,int n) 
			{
				return read((char*)s,n) ;
			}
	int		gcount() ;
	istream&	putback(char c);
	int		sync()	{ return bp->sync() ; }
protected:  
	int		do_ipfx(int noskipws) ;
	void		eatwhite() ;
			istream() ;
private: 
	int		x_gcount ;
	void 		xget(char*  c) ;
public: /*** Obsolete constructors, carried over from stream package ***/
			istream(streambuf*, int sk, ostream* t=0) ;
				/* obsolete, set sk and tie
				 * via format state variables */
			istream(int size ,char*,int sk=1) ;
				/* obsolete, use strstream */
			istream(int fd,int sk=1, ostream* t=0) ;
				/* obsolete use fstream */
};

class ostream : virtual public ios {
public: /* Constructor */
			ostream(streambuf*) ;
	virtual		~ostream();
public:	
	int		opfx()	/* Output prefix */
			{	if ( ospecial )	return do_opfx() ;
				else		return 1 ;
			}
	void		osfx() 
			{	if ( osfx_special ) do_osfx() ; }

	ostream&	flush() ;
	ostream&	seekp(streampos p) ;
	ostream&	seekp(streamoff o, seek_dir d) ;
 	streampos	tellp() ; 
	ostream&	put(char c)
	{
		if ( opfx() ) {
			if (  bp->sputc(c) == EOF )  {
				setstate(eofbit|failbit) ;
			}
			osfx() ;
		}
		return *this ;
	}
	ostream&	operator<<(char c) { put(c) ; osfx() ; return *this ; }

	ostream&	operator<<(unsigned char c) 
	{	put(c) ; osfx() ; return *this ; }

	ostream&	operator<<(const char*);
	ostream&	operator<<(int a); 
	ostream&	operator<<(long);	
	ostream&	operator<<(double);
	ostream&	operator<<(float);
	ostream&	operator<<(unsigned int a);
	ostream&	operator<<(unsigned long);
	ostream&	operator<<(void*);
	ostream&	operator<<(streambuf*);
	ostream&	operator<<(short i) { return *this << (int)i ; }
	ostream&	operator<<(unsigned short i) 
			{ return *this << (int)i  ; }

	ostream&	operator<< (ostream& (*f)(ostream&))
			{ return (*f)(*this) ; }
	ostream&	operator<< (ios& (*f)(ios&) ) ;

	ostream&	write(const char*  s,int n)	
	{
		if ( !state ) {
			if ( bp->sputn(s,n) != n ) setstate(eofbit|failbit);
			}
		return *this ;
	}
	ostream&	write(const unsigned char* s, int n)
	{
		return write((const char*)s,n);
	}
protected: /* More ostream members */
	int		do_opfx() ;
	void		do_osfx() ;
			ostream() ;

public: /*** Obsolete constructors, carried over from stream package ***/
			ostream(int fd) ;
				/* obsolete use fstream */
			ostream(int size ,char*) ;
				/* obsolete, use strstream */
} ;

class iostream : public istream, public ostream {
public:
			iostream(streambuf*) ;
	virtual		~iostream() ;
protected:
			iostream() ;
	} ;

class istream_withassign : public istream {
public:
			istream_withassign() ;
	virtual		~istream_withassign() ;
	istream_withassign&	operator=(istream&) ;
	istream_withassign&	operator=(streambuf*) ;
} ;

class ostream_withassign : public ostream {
public:
			ostream_withassign() ;
	virtual		~ostream_withassign() ;
	ostream_withassign&	operator=(ostream&) ;
	ostream_withassign&	operator=(streambuf*) ;
} ;

class iostream_withassign : public iostream {
public:
			iostream_withassign() ;
	virtual		~iostream_withassign() ;
	iostream_withassign&	operator=(ios&) ;
	iostream_withassign&	operator=(streambuf*) ;
} ;

extern istream_withassign cin ;
extern ostream_withassign cout ;
extern ostream_withassign cerr ;
extern ostream_withassign clog ;

ios&		dec(ios&) ; 
ostream&	endl(ostream& i) ;
ostream&	ends(ostream& i) ;
ostream&	flush(ostream&) ;
ios&		hex(ios&) ;
ios&		oct(ios&) ; 
istream&	ws(istream&) ;

static class Iostream_init {
	static int	stdstatus ; /* see cstreams.c */
	static int	initcount ;
	friend		ios ;
public:
	Iostream_init() ; 
	~Iostream_init() ; 
} iostream_init ;	

#endif
0707070044044142561004440042240042240000011571420442762431100001000000004471manip.c/*ident	"@(#)ctrans:lib/stream/manip.c	1.1.3.1" */
/**************************************************************************
                        Copyright (c) 1984 AT&T
                          All Rights Reserved   

        THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T
      
        The copyright notice above does not evidence any        
        actual or intended publication of such source code.

manip.c:

*****************************************************************************/

#include <iostream.h>
#include <iomanip.h>
#include <ctype.h>

istream& ws(istream& i)
{
	if ( !i.ipfx(1) ) return i ;
	register streambuf *nbp = i.rdbuf();
	register int c = nbp->sgetc();
	while (isspace(c)) c = nbp->snextc();
	if (c == EOF) i.clear(ios::eofbit) ;
	return i ;
}

ostream& ends(ostream& i) 
{
	return i.put(0) ;
}

ostream& endl(ostream& i) 
{
	i.put('\n') ;
	i.flush() ;
	return i ;
}

static const int basebits = ios::dec|ios::oct|ios::hex ;

static ios& setb(ios& i, int b)
{
	switch(b) {
		case 10 : i.setf(ios::dec,basebits) ; break ;
		case 8 : i.setf(ios::oct,basebits) ; break ;
		case 16 : i.setf(ios::hex,basebits) ; break ;
		default : i.setf(0,basebits) ; break ;
		}
	return i ;
	}

SMANIP(int) setbase(int b) { return SMANIP(int)(setb,b) ; }

static ios& resetiosflags(ios& i,long b) { i.setf(0,b) ; return i ; }
SMANIP(long) resetiosflags(long b) { return SMANIP(long)(resetiosflags,b) ; }

static ios& setiosflags(ios& i,long b) { i.setf(b) ; return i ; }
SMANIP(long) setiosflags(long b) { return SMANIP(long)(setiosflags,b) ; }

static ios& setfill(ios& i,int f) { i.fill(f) ; return i ; }
SMANIP(int) setfill(int f) { return SMANIP(int)(setfill,f) ; }

static ios& setprecision(ios& i,int p) { i.precision(p) ; return i ; }
SMANIP(int) setprecision(int p) { return SMANIP(int)(setprecision,p) ; }

static ios& setw(ios& i,int w) { i.width(w) ; return i ; }
SMANIP(int) setw(int w) { return SMANIP(int)(setw,w) ; }

ios& hex(ios& s) { s.setf(ios::hex,basebits ) ; return s ; }
ios& dec(ios& s) { s.setf(ios::dec,basebits ) ; return s ; }
ios& oct(ios& s) { s.setf(ios::oct,basebits ) ; return s ; }

ostream& flush(ostream& s) { s.flush() ; return s ; }

ostream& ostream::operator<<( ios& (*f)(ios&) )
{
	f(*this) ;
	return *this ;
	}

istream& istream::operator>>( ios& (*f)(ios&) )
{
	f(*this) ;
	return *this ;
	}
0707070044044141271004440042240042240000011557620441667020000001400000013350oldformat.c/*ident	"@(#)ctrans:lib/stream/oldformat.c	1.1.4.1" */
/**************************************************************************
                        Copyright (c) 1984 AT&T
                          All Rights Reserved   

        THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T
      
        The copyright notice above does not evidence any        
        actual or intended publication of such source code.

oldformat.c:
           file for obsolete stream stuff that isn't part of the
           official iostream package.
*****************************************************************************/

#include <stream.h>
#include "streamdefs.h"
#include <string.h>
#include <strstream.h>
#include <fstream.h>
#include <libc.h>

#ifdef VSPRINTF
#	include <stdarg.h>
#endif

static const int cb_size = 1024 ;
static const int fld_size = 256 ;

/* a circular formating buffer */
static char	formbuf[cb_size];	// some slob for form overflow
static char*	bfree=formbuf;
static char*	max = &formbuf[cb_size-1];

char* chr(register i, register int w)	/* note: chr(0) is "" */
{
	register char* buf = bfree;

	if (w<=0 || fld_size<w) w = 1;
	w++;				/* space for trailing 0 */
	if (max < buf+w) buf = formbuf;
	bfree = buf+w;
	char * res = buf;

	w -= 2;				/* pad */
	while (w--) *buf++ = ' ';
	if (i<0 || 127<i) i = ' ';
	*buf++ = i;
	*buf = 0;
	return res;
}

char* str(const char* s, register int w)
{
	register char* buf = bfree;
	int ll = strlen(s);
	if (w<=0 || fld_size<w) w = ll;
	if (w < ll) ll = w;
	w++;				/* space for traling 0 */
	if (max < buf+w) buf = formbuf;
	bfree = buf+w;
	char* res = buf;

	w -= (ll+1);			/* pad */
	while (w--) *buf++ = ' ';
	while (*s) *buf++ = *s++;
	*buf = 0;
	return res;
}

char* form(const char* format ...)
{
	register char* buf = bfree;
	if (max < buf+fld_size) buf = formbuf;

#	ifdef VSPRINTF
		va_list args ;
		va_start(args,format) ;
		VSPRINTF(buf,format,args) ;
		va_end(args) ;
#	else
		// not very portable
		register* ap = (int*)((char*)&format+sizeof(char*));
		sprintf(buf,format,ap[0],ap[1],ap[2],ap[3],ap[4],ap[5],ap[6],ap[7],ap[8],ap[9]);	
#	endif

	register ll = strlen(buf);			// not all sprintf's return length
	if (0<ll && ll<cb_size)				// length
		;
	else if (buf<(char*)ll && (char*)ll<buf+cb_size)// pointer to trailing 0
		ll = (char*)ll - buf;
	else
		ll = strlen(buf);

	// If we have scribbled beyond the end of the buffer then
	// who knows what data we've destroyed.  Better to abort here
	// here there is some chance that somebody can associate
	// the location with the error than to continue and die
	// a mysterious death later.
	if (fld_size < ll) abort();

	bfree = buf+ll+1;
	return buf;
}

const char a10 = 'a'-10;

char* hex(long ii, register w)
{
	int m = sizeof(long)*2;		// maximum hex digits for a long
	if (w<0 || fld_size<w) w = 0;
	int sz = (w?w:m)+1;
	register char* buf = bfree;
	if (max < buf+sz) buf = formbuf;
	register char* p = buf+sz;
	bfree = p+1;
	*p-- = 0;			// trailing 0
	register unsigned long i = ii;

	if (w) {
		do {
			register h = (int)(i&0xf);
			*p-- = (h < 10) ? h+'0' : h+a10;
		} while (--w && (i>>=4));
		while (0<w--) *p-- = ' ';
	}
	else {
		do {
			register h = (int)(i&0xf);
			*p-- = (h < 10) ? h+'0' : h+a10;
		} while (i>>=4);
	}
	return p+1;
}

char* oct(long ii, int w)
{
	int m = sizeof(long)*3;		// maximum oct digits for a long
	if (w<0 || fld_size<w) w = 0;
	int sz = (w?w:m)+1;
	register char* buf = bfree;
	if (max < buf+sz) buf = formbuf;
	register char* p = buf+sz;
	bfree = p+1;
	*p-- = 0;			// trailing 0
	register unsigned long i = ii;

	if (w) {
		do {
			register h = (int)(i&07);
			*p-- = h + '0';
		} while (--w && (i>>=3));
		while (0<w--) *p-- = ' ';
	}
	else {
		do {
			register h = (int)(i&07);
			*p-- = h+'0';
		} while (i>>=3);
	}

	return p+1;
}

char* dec(long i, int w)
{
	int sign = 0;
	if (i < 0) {
		sign = 1;
		i = -i;
	}	
	int m = sizeof(long)*3;		/* maximum dec digits for a long */
	if (w<0 || fld_size<w) w = 0;
	int sz = (w?w:m)+1;
	register char* buf = bfree;
	if (max < buf+sz) buf = formbuf;
	register char* p = buf+sz;
	bfree = p+1;
	*p-- = 0;			/* trailing 0 */

	if (w) {
		do {
			register h = (int)(i%10);
			*p-- = h + '0';
		} while (--w && (i/=10));
		if (sign && 0<w) {
			w--;
			*p-- = '-';
		}
		while (0<w--) *p-- = ' ';
	}
	else {
		do {
			register h = (int)(i%10);
			*p-- = h + '0';
		} while (i/=10);
		if (sign) *p-- = '-';
	}

	return p+1;
}

istream& WS(istream& i) { return i >> ws ; }

void eatwhite(istream& i) { i >> ws ; }

istream::istream(streambuf* b, int sk, ostream* t) 
{
	init(b) ;
	skip(sk) ;
	tie(t) ;
	}

istream::istream(int len, char* b, int sk) 
{
	init( new streambuf(b,len,-len) ) ;
	delbuf = 1 ;
	skip(sk) ;
}

istream::istream(int fd, int sk, ostream* t) 
{
	init( new filebuf(fd) ) ;
	delbuf = 1 ;
	skip(sk) ;
	tie(t) ;
}

ostream::ostream(int fd) 
{
	init( new filebuf(fd) ) ;
	delbuf = 1 ;
}

ostream::ostream(int len, char* b) 
{
	init( new streambuf(b,len,0) ) ;
	delbuf = 1 ;
}

streambuf::streambuf(char* p, int l, int c ) :
	x_unbuf(0), alloc(0)
{
	setb(0,0,0);
	setbuf(p,l,c) ;
}

streambuf* streambuf::setbuf(char* p, int len, int count)
{
	// Three argument setbuf for compatibility with old
	// stream package.
	if ( x_base ) return 0 ;
	if ( len <= 0 || p == 0 ) {
		// make it unbuffered
		setb(0,0,0) ;
		setg(0,0,0) ;
		setp(0,0);
		unbuffered(1) ;
	} else if ( count >= 0 ) {
		setb(p,p+len,0) ;
		setg(p,p,p+count) ;
		setp(p+count,p+len) ;
		unbuffered(0) ;
	} else  { // count < 0 
		// Special case,
		// Used by iostream::iostream(char*,int) 
		// For backwards compatibility with old streams
		setb(p,p+len,0) ;
		setg(p,p,p-count) ;
		setp(p,p+len) ;
		unbuffered(0) ;
		}
	return this;
	}

int ios::skip(int sk)
{
	long f ;
	if ( sk ) f = setf(skipws,skipws) ;
	else	  f = setf(0,skipws) ;
	
	return (f&skipws) != 0 ;
}
0707070044044142441006440042240042240000011611200443034047300000600000020040out.c/*ident	"@(#)ctrans:lib/stream/out.c	1.1.2.1" */
/**************************************************************************
			Copyright (c) 1984 AT&T
	  		  All Rights Reserved  	

	THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T
	
	The copyright notice above does not evidence any   	
	actual or intended publication of such source code.

out.c: 

*****************************************************************************/

#include <iostream.h>
#include "streamdefs.h"
#include <string.h>

#define OSTREAM ostream

const int basebits = ios::dec|ios::oct|ios::hex ;

// At the cost of 100 bytes of table we can measurably speed
// up conversion (at least on a VAX)

static char digit1[] = {
	'0','1','2','3','4','5','6','7','8','9',
	'0','1','2','3','4','5','6','7','8','9',
	'0','1','2','3','4','5','6','7','8','9',
	'0','1','2','3','4','5','6','7','8','9',
	'0','1','2','3','4','5','6','7','8','9',
	'0','1','2','3','4','5','6','7','8','9',
	'0','1','2','3','4','5','6','7','8','9',
	'0','1','2','3','4','5','6','7','8','9',
	'0','1','2','3','4','5','6','7','8','9',
	'0','1','2','3','4','5','6','7','8','9',
	} ;

static char digit2[] = {
	'0','0','0','0','0','0','0','0','0','0',
	'1','1','1','1','1','1','1','1','1','1',
	'2','2','2','2','2','2','2','2','2','2',
	'3','3','3','3','3','3','3','3','3','3',
	'4','4','4','4','4','4','4','4','4','4',
	'5','5','5','5','5','5','5','5','5','5',
	'6','6','6','6','6','6','6','6','6','6',
	'7','7','7','7','7','7','7','7','7','7',
	'8','8','8','8','8','8','8','8','8','8',
	'9','9','9','9','9','9','9','9','9','9',
	} ;

static char* conv10(long i, char* bufend) 
/* p points to right end of a buffer. Function function returns
 * pointer to left end of converted number.  Number is not 0 terminated.
 *
 * Special care with negatives to avoid problems with
 * biggest negative number on 2's complement machines
 */
{
	register long j = i ;
	register char* p = bufend ;

	/* Above entered low order digit or 0 if i is zero */

	if ( j >= 0 ) {
		register int diff ;
		do {
			long register by100 = j/100 ;
			diff = (int)(j-100*by100) ;
			*p-- = digit1[diff] ;
			*p-- = digit2[diff] ;
			j = by100;
		} while ( j > 0 ) ;
		if ( diff<10 ) ++p ; //compensate for extra 0
	} else { // j < 0
		register int diff ;
		do {
			long register by100 = j/100 ;
			diff = (int)(100*by100-j) ;
			*p-- = digit1[diff] ;
			*p-- = digit2[diff] ;
			j = by100;
		} while ( j < 0 ) ;
		if ( diff<10 ) ++p ; //compensate for extra 0
	}
	return p+1 ;

}

static char* uconv10(unsigned long i, char* bufend) 
/* Same interface as conv10 except unsigned so we don't have
 * to worry about negatives */
{
	register unsigned long j = i ;
	register char* p = bufend ;
	register int diff ;

	do {
		long register by100 = j/100 ;
		diff = (int)(j-100*by100) ;
		*p-- = digit1[diff] ;
		*p-- = digit2[diff] ;
		j = by100;
	} while ( j > 0 ) ;
	if ( diff<10 ) ++p ; //compensate for extra 0
	
	return p+1 ;

}


static char* conv8(register unsigned long i, register char* p) 
{
	do {
		*p-- = (char)('0' + i%8) ;
		} while ( (i >>= 3) > 0 ) ;
	return p+1 ;
}

static char* conv16(register unsigned long i, register char* p) 
{
	do {
		register dig = (int)(i%16) ;
		if ( dig < 10 )	*p-- = (char)('0' + i%16) ;
		else		*p-- = (char)('a'-10 + dig) ;

		} while ( (i >>= 4) > 0 ) ;
	return p+1 ;
}


static char* conv16u(register unsigned long i, register char* p) 
{
	do {
		register dig = (int)(i%16) ;
		if ( dig < 10 )	*p-- = (char)('0' + i%16) ;
		else		*p-- = (char)('A'-10 + dig) ;

		} while ( (i >>= 4) > 0 ) ;
	return p+1 ;
}
ostream& OSTREAM::operator<<(const char* s)
{
	// I play some games so that if BREAKEVEN is <= 0 all
	// tests get set the right way at compile time 

#       if BREAKEVEN > 0
		static int	avglen = BREAKEVEN ;
					// running average of the lengths
					// of strings ;
#	else
		static const int avglen = BREAKEVEN ;
					// fixed constant so all tests
					// are fixed at compile time
#	endif

	register int fwidth = width(0) ;

	if (!opfx() ) return *this ;
	if ( s==0 ) return *this;
	register streambuf* nbp = bp ;
	register const char* p ;
	register int len ;
	register int pad ;

	register int leftjust = ( (flags()&left) != 0 ) ;
	if ( BREAKEVEN<0 
			|| BREAKEVEN>0 && avglen<=BREAKEVEN &&
			   (fwidth==0 || leftjust)){
		p = s ;
		while ( *p ) {
			if ( nbp->sputc(*p++) == EOF ) {
				setstate(badbit) ;
				break ;
			}
		}
		len = p-s ;
		pad = fwidth-len ;
	} else {
		len = strlen(s) ;
		pad = fwidth-len ;
		if ( pad>0 && !leftjust ) {
			while ( pad-- > 0 ) {
				if ( nbp->sputc(fill()) == EOF ) {
					setstate(badbit) ;
				}
			}
		}
		write(s,len) ;
	}

	if ( pad > 0  ) {
		while ( pad-- > 0 ) {
			if ( nbp->sputc(fill()) == EOF ) setstate(badbit) ;
		}
	}

 	if ( BREAKEVEN > 0 ) { // will be eliminated at compile time 
		avglen = (3*avglen + len) >> 2;
	}
	osfx() ;
	return *this;
}

static int dofield(
	ostream* ios,
	register char* pfx,
	int pwidth,
	register char* sfx,
	int swidth) 
{
	register streambuf* b = ios->rdbuf() ;
	register int w = ios->width(0)-(pwidth+swidth) ;
	register int f = (int)ios->flags() ;
	register int fchar = ios->fill() ; 

	if ( (f&ios::right) || !(f&(ios::left|ios::internal)) ) {
		while ( w-- > 0 ) {
			if ( b->sputc(fchar) == EOF ) return ios::badbit ;
			}
		}

	while ( *pfx ) {
		if ( b->sputc(*pfx++) == EOF ) return ios::badbit ;
		}

	if ( f&ios::internal ) {
		while ( w-- > 0 ) {
			if ( b->sputc(fchar) == EOF ) return ios::badbit ;
			}
		}
	while ( *sfx ) {
		if ( b->sputc(*sfx++) == EOF ) return ios::badbit ;
		}

	while ( w-- > 0 ) {
		if ( b->sputc(fchar) == EOF ) return ios::badbit ;
		}

	return 0 ;
	}

static const int dbufsize = 32 ;

ostream& OSTREAM::operator<<(long i)
{
	if (!opfx()) {
		width(0) ;
		return *this;
		}
	char buf[dbufsize];

	register char *p ;
	register char* pfx = "" ;
	register int pfxsize = 0 ;

	buf[dbufsize-1] = 0 ;
	switch( flags()&basebits ) {
		case ios::oct :
			p = conv8(i,&buf[dbufsize-2]) ;
			if ( (flags()&showbase) && i ) {
				pfx = "0" ; pfxsize = 1 ;
				}
			break ;
		case ios::hex :
			if ( flags()&uppercase ) {
				p=conv16u(i,&buf[dbufsize-2]);
				if ( flags()&showbase ) {
					pfx = "0X" ; pfxsize = 2 ;
					}
				}
			else {
				p=conv16(i,&buf[dbufsize-2]); 
				if ( flags()&showbase ) {
					pfx = "0x" ; pfxsize = 2 ;
					}
				}
			break ;
		default:
			p = conv10(i,&buf[dbufsize-2]) ;
			if ( i < 0 ) {
				pfx = "-" ; pfxsize = 1 ;
				}
			else if ( flags()&showpos ) {
				pfx = "+" ; pfxsize = 1 ;
				}
			break ;
		}
	register int err ;
	if ( err = dofield(this,pfx,pfxsize,p,&buf[dbufsize-1]-p) ) {
		setstate(err) ;
		}
	osfx() ;
	return *this ;
	}

ostream& OSTREAM::operator<<(unsigned long i)
{
	if (!opfx()) {
		width(0) ;
		return *this;
		}
	char buf[dbufsize];
	register char *p ;
	register char* pfx = "" ;
	register int pfxsize = 0 ;


	buf[dbufsize-1] = 0 ;
	switch( flags()&basebits ) {
		case ios::oct :
			p = conv8(i,&buf[dbufsize-2]) ;
			if ( (flags()&showbase) && i ) {
				pfx = "0" ; pfxsize = 1 ;
				}
			break ;
		case ios::hex :
			if ( flags()&uppercase ) {
				p=conv16u(i,&buf[dbufsize-2]);
				if ( flags()&showbase ) {
					pfx = "0X" ; pfxsize = 2 ;
					}
				}
			else {
				p=conv16(i,&buf[dbufsize-2]); 
				if ( flags()&showbase ) {
					pfx = "0x" ; pfxsize = 2 ;
					}
				}
			break ;
		default:
			p = uconv10(i,&buf[dbufsize-2]) ;
			break ;
		}
	register int err ;
	if ( err = dofield(this,pfx,pfxsize,p,&buf[dbufsize-1]-p) ) {
		setstate(err) ;
		}
	osfx() ;
	return *this ;
	}
	
ostream& OSTREAM::operator<<(register streambuf* b)
{
	register streambuf* nbp = bp;
	register int c;

	if (!opfx()) return *this;
	if ( !b ) {
		setstate(failbit) ;
		return *this ;
		}
	c = b->sgetc();
	while (c != EOF) {
		if (nbp->sputc(c) == EOF) {
			setstate(badbit) ;
			break;
			}
		c = b->snextc();
		}

	osfx() ;		
	return *this;
	}

ostream& OSTREAM::operator<<( void* p)
{
	long f = setf(ios::showbase|PTRBASE,  basebits|ios::showbase) ;
	*this << (long)p ;
	setf(f,~0) ;
	return *this ;
	}

ostream& OSTREAM::operator<<(int x)
{
	*this << (long)x ;
	return *this ;
	}

ostream& OSTREAM::operator<<(unsigned int x)
{
	*this << (unsigned long)x ;
	return *this ;
	}
0707070044044142671004440042240042240000011604650437162573100001000000005714rawin.c/*ident	"@(#)ctrans:lib/stream/rawin.c	1.1.1.1" */
/**************************************************************************
			Copyright (c) 1984 AT&T
	  		  All Rights Reserved  	

	THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T
	
	The copyright notice above does not evidence any   	
	actual or intended publication of such source code.

rawin.c:
       raw input functions. (I.e. those that don't "eatwhite".)

*****************************************************************************/

#include <iostream.h>

#define ISTREAM istream

istream& ISTREAM::read(char* s, int n)
{
	if ( !ipfx(n) ) {
		if ( n > 0 ) setstate(eofbit|failbit) ;
		return *this ;
		}
	x_gcount = bp->sgetn(s,n) ; ;
	if ( x_gcount < n ) setstate(eofbit|failbit) ;
	return *this ;
}

istream& ISTREAM::ignore(register int n, register int delim)
{
	x_gcount = 0 ;
	if ( !ipfx(1) ) return *this ;
	if ( n == 0 ) return *this ;
	register streambuf* nbp = bp ;
	register int count = 0 ;

	while ( 1 ) {
		register int c = nbp->sbumpc() ;
		if (  c == EOF ) {
			setstate(eofbit|failbit) ;
			break ;
			}
		++count ;
		if ( c == delim ) break ;
		if ( count == n ) break ;
		}
	x_gcount = count ;
	return *this ;
	}

istream& ISTREAM::get(
	register char* s, 	/* character array to read into */
	register int len,	/* size of character array */
	register char term	/* character that terminates input */
) {
	register c;
	register streambuf *nbp = bp;


	x_gcount = 0 ;
	if ( len == 0 ) return *this ;

	if ( !ipfx(len) ) {
		*s = 0 ;
		return *this ;
	}

	if ( len<=0 ) return *this ;

	if ((c = bp->sgetc()) == EOF) {
		setstate(failbit | eofbit) ;
		return *this;
	}

	while (c != term && c != EOF && len > 1) {
		*s++ = c;
		c = nbp->snextc();
		len--;
		++x_gcount ;
	}
	*s = '\0';
	if (c == EOF) setstate(eofbit) ;
	return *this;
}


istream& ISTREAM::get(
	register streambuf &s,	/* streambuf to input to */
	register char term	/* termination character */
){
	register c;

	int oldskip = skip(0) ;
	if ( !ipfx() ) {
		skip(oldskip) ;
		return *this ;
	}
	skip(oldskip) ;
	register streambuf *nbp = bp;

	x_gcount = 0 ;
	if ((c = bp->sgetc()) == EOF) {
		setstate(failbit | eofbit) ;
		return *this;
	}

	while (c != term && c != EOF) {
		if (s.sputc(c) == EOF) break;
		c = nbp->snextc();
		++x_gcount ;
	}
	if (c == EOF) setstate(eofbit) ;
	return *this;
}

istream& ISTREAM::getline(char* b, int len, char d ) 
{
	get(b,len,d) ;
	if ( x_gcount != len-1 && d!=EOF && bp->sgetc()==d) {
		++x_gcount ;
		bp->sbumpc() ;
	}
	return *this ;
}

istream& ISTREAM::getline(unsigned char* b, int len, char d ) 
{
	return getline((char*)b,len,d) ;
}

int ISTREAM::gcount()
{
	return x_gcount ;
}

istream& ISTREAM::operator>>(register streambuf* s) {
	register c;
	if ( !ipfx() ) return *this ;

	register streambuf *nbp = bp;

	if ((c = bp->sgetc()) == EOF) {
		setstate(failbit | eofbit) ;
		return *this;
	}

	while (c != EOF) {
		if (s->sputc(c) == EOF) break;
		c = nbp->snextc();
	}
	if (c == EOF) setstate(eofbit) ;
	return *this;
}

0707070044043602501004440042240042240000010416170437115412200001300000001542sbuf.dbp.c/*ident	"@(#)ctrans:lib/stream/sbuf.dbp.c	1.1.2.1" */
/**************************************************************************
			Copyright (c) 1984 AT&T
	  		  All Rights Reserved  	

	THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T
	
	The copyright notice above does not evidence any   	
	actual or intended publication of such source code.

sbuf.dbp.c

*****************************************************************************/


#include <iostream.h>
#include <stdio.h>
#include <string.h>
#include <osfcn.h>

void streambuf::dbp()
{
	char msg[256] ;
	sprintf(msg,"buf at %#x, base=%#x, ebuf=%#x, ",
				this, base(), ebuf());
	write(1,msg,strlen(msg)) ;
	sprintf(msg,"pptr=%#x, epptr=%#x, ", pptr(),epptr() );
	write(1,msg,strlen(msg)) ;
	sprintf(msg,"eback=%#x, gptr=%#x, egptr=%#x\n",
			eback(), gptr(), egptr() ) ;
	write(1,msg,strlen(msg)) ;

}
0707070044044146101004440042240042240000011575740443013564500001300000003220stdiobuf.c/*ident	"@(#)ctrans:lib/stream/stdiobuf.c	1.1.2.2" */
/**************************************************************************
			Copyright (c) 1984 AT&T
	  		  All Rights Reserved  	

	THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T
	
	The copyright notice above does not evidence any   	
	actual or intended publication of such source code.

stdiobuf.c:

*****************************************************************************/


#include <iostream.h>
#include <stdiostream.h>

int stdiobuf::overflow(int c) 
{
	if ( fp == 0 || c==EOF) return EOF ;
	if ( last_op == ios::in ) {
		if ( egptr()!=gptr() ) ungetc(*gptr(),fp) ;
		// stdio requires seeks between reads and writes
		fseek(fp,0,ios::cur) ;
		setg(0,0,0) ;
		}
	last_op = ios::out ;
	
	return putc(c,fp) ;
}

int stdiobuf::underflow() {
	if ( fp == 0 ) return EOF ;
	if ( last_op == ios::out ) {
		fseek(fp,0,0) ;
		}
	if ( feof(fp) ) return EOF ;
	int c = getc(fp) ;
	if ( c == EOF ) return EOF ;
	setg(buf,buf,buf+1) ;
	buf[0] = c ;
	return c ;
}

int stdiobuf::pbackfail(int c) 
{
	return ungetc(c,fp) ;
}

int stdiobuf::sync()
{
	if ( last_op==ios::out ) fflush(fp) ;
	else if ( last_op==ios::in && gptr()!=egptr() ) {
		ungetc(*gptr(),fp) ;
		setg(0,0,0) ;
	}
	return fseek(fp,0,ios::cur) ;
}
	
streampos stdiobuf::seekoff(streamoff p,seek_dir d,int) 
{

	if ( gptr()!=egptr() ) ungetc(*gptr(),fp) ;
	setg(0,0,0) ;
	return fseek(fp,p,d) ;
}

stdiobuf::stdiobuf(FILE* f) :
	fp(f)
{
	setbuf((char*)0,0) ;
}

stdiobuf::~stdiobuf() 
{
	if (fp) fflush(fp) ;
}

stdiostream::stdiostream(FILE* f) :  buf(f)
{
	init(&buf) ;
}

stdiostream::~stdiostream() { }

stdiobuf* stdiostream::rdbuf() { return &buf ; }
0707070044044146041004440042240042240000011615120443013464300001600000002172stdiostream.h/*ident	"@(#)ctrans:incl/stdiostream.h	1.1.1.2" */
/**************************************************************************
                        Copyright (c) 1984 AT&T
                          All Rights Reserved   

        THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T
      
        The copyright notice above does not evidence any        
        actual or intended publication of such source code.

*****************************************************************************/
#ifndef STDSTREAMH
#define STDSTREAMH

#include <iostream.h>
#include <stdio.h>

class stdiobuf : public streambuf {
	/*** stdiobuf is obsolete, should be avoided ***/
public: // Virtuals
	virtual int	overflow(int=EOF);
	virtual int	underflow();
	virtual int	sync() ;
	virtual streampos
			seekoff(streamoff,seek_dir,int) ;
	virtual int	pbackfail(int c);
public:
			stdiobuf(FILE* f) ;
	FILE*		stdiofile() { return fp ; }
	virtual		~stdiobuf() ;
private:
	FILE*		fp ;			
	int		last_op ;
	char		buf[2];
};

class stdiostream : public ios {
public:
			stdiostream(FILE*) ;
			~stdiostream() ;
	stdiobuf*	rdbuf() ;
private:
	stdiobuf	buf ;
};

#endif

0707070044044146241004440042240042240000011614100443034011500001100000015362stream.c/*ident	"@(#)ctrans:lib/stream/stream.c	1.1.3.2" */
/**************************************************************************
                        Copyright (c) 1984 AT&T
                          All Rights Reserved   

        THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T
      
        The copyright notice above does not evidence any        
        actual or intended publication of such source code.

stream.c:

*****************************************************************************/

#include <iostream.h>

void (*ios::stdioflush)() = 0 ;

long ios::nextbit = 1L<<16 ;
long ios::nextword = 0 ;

const long ios::adjustfield = ios::left|ios::right|ios::internal ;
const long ios::floatfield = ios::fixed|ios::scientific ;
const long ios::basefield = ios::dec|ios::hex|ios::oct ;

#define ISTREAM istream
#define OSTREAM ostream
#define IOSTREAM iostream

union ios_user_union { long i ; void* p ; } ;

void ios::init(streambuf* b)
{
	// Must be called by other constructors. */
	bp=b ;
	state = 0 ;
	ispecial = 0 ;
	ospecial = 0 ;
	osfx_special = 0 ;
	isfx_special = 0 ;
	delbuf = 0 ;
	if (!bp ) setstate(hardfail|failbit) ;
	flags(skipws|dec) ;
	width(0);
	precision(6);
	fill(' ');
	tie(0);
	
	x_user = 0 ;
	nuser = 0 ;
	}

ios::ios(streambuf* b) { init(b) ; }

ios::~ios()
{
	if (bp) bp->sync() ;
	if (delbuf) {
		delete bp ;
		bp = 0 ;
		}
	if (x_user) {
		delete x_user ; 
		x_user = 0 ;
		}
	}

iostream::iostream(streambuf* b) { init(b) ; }
iostream::~iostream() { }
istream::istream(streambuf* b) { init(b) ; }
istream::~istream() { }
ostream::ostream(streambuf* b) { init(b) ; }
ostream::~ostream() { }

IOSTREAM::IOSTREAM() { } 
ISTREAM::ISTREAM() { } 
OSTREAM::OSTREAM() { }

ostream& OSTREAM::flush()
{
	if ( bp->out_waiting() )	bp->overflow() ;
	else if ( bp->in_avail() ) 	bp->sync() ; 

	return *this ;
}

streampos OSTREAM::tellp()
{
	return bp->seekoff(0,cur,out) ;
}

streampos ISTREAM::tellg()
{
	return bp->seekoff(0,cur,in) ;
}
	
ostream& OSTREAM::seekp(streampos p)
{
	if ( bp->seekpos(p,out) == EOF ) setstate(badbit) ;
	return *this ;
}

typedef seek_dir Sdir ; /** Gets around a bug in release 2.0 beta 5 **/

ostream& OSTREAM::seekp(streamoff o, Sdir d)
{
	if ( bp->seekoff(o,d,out) == EOF ) setstate(badbit) ;
	return *this ;
}
	
istream& ISTREAM::seekg(streampos p)
{
	if ( bp->seekpos(p,in) == EOF ) setstate(badbit) ;
	return *this ;
}

istream& ISTREAM::seekg(streamoff o, Sdir d)
{
	if ( bp->seekoff(o,d,in) == EOF ) setstate(badbit) ;
	return *this ;
}

ostream* ios::tie(ostream* s) 
{
	ostream* t = x_tie ;
	x_tie = s ;

	if ( s ) {
		ispecial |= tied ;
		ospecial |= tied ;
		}
	else {
		ispecial &= ~tied ;
		ospecial &= ~tied ;
		}
	return t ;
}

char ios::fill(char c)
{
	char oldf = x_fill ;
	x_fill = c ;
	return oldf ;
	}

int ios::precision(int p)
{
	register int oldp = x_precision ;
	x_precision = p;
	return oldp ;
	}

long ios::setf(long b, long f)
{
	long oldf = x_flags ;
	x_flags = (b&f) | (x_flags&~f) ;

	if (x_flags&skipws ) 	ispecial |= skipping ;
	else			ispecial &= ~skipping ;

	osfx_special = (x_flags&(unitbuf|stdio)) != 0 ;
			
	return oldf ;
	}

long ios::setf(long b)
{
	long oldf = x_flags ;
	x_flags |= b ;

	if (x_flags&skipws ) 	ispecial |= skipping ;
	else			ispecial &= ~skipping ;

	osfx_special = (x_flags&(unitbuf|stdio)) != 0 ;
	return oldf ;
	}

long ios::unsetf(long b)
{
	long oldf = x_flags ;
	x_flags &= ~b ;

	if (x_flags&skipws ) 	ispecial |= skipping ;
	else			ispecial &= ~skipping ;

	osfx_special = (x_flags&(unitbuf|stdio)) != 0 ;
	return oldf ;
	}

long ios::flags(long f) 
{
	long oldf = x_flags ;
	x_flags = f ;

	if (x_flags&skipws ) 	ispecial |= skipping ;
	else			ispecial &= ~skipping ;

	osfx_special = (x_flags&(unitbuf|stdio)) != 0 ;
	return oldf ;
	}
	
int ISTREAM::do_ipfx(int noskipws)
{
	if ( state&hardfail) return 0 ;
	// note that we flush tied stream even when !this->good().
	if ( x_tie && x_tie->rdbuf()->out_waiting()
			&& (noskipws==0 || rdbuf()->in_avail()<noskipws) ){
		x_tie->flush() ;
		}
	if ( good() && !noskipws && (ispecial&skipping) ) eatwhite() ;
	if ( eof() ) {
		// if we were only skipping this wouldn't be a failure.
		// but the presumption is that this is a prefix operation
		// prior to inputting something else.
		setstate(ios::failbit) ;
	 	return 0 ;
		}
	return good() ;
	}

int OSTREAM::do_opfx()
{
	if ( state&hardfail) return 0 ;
	if ( x_tie && x_tie->rdbuf()->out_waiting()) {
		x_tie->flush() ;
		}
	return good() ;
	}

void OSTREAM::do_osfx()
{
	if ( (x_flags & stdio) && stdioflush ) { (*stdioflush)() ; }
	if ( x_flags & unitbuf ) flush() ;
	}

void ios::operator=(ios& rhs) { bp = rhs.bp ; }

ios::ios() { assign_private = state ; state = hardfail ; } 

istream_withassign::istream_withassign() 
{
	// In order for the standard streams to be properly initialized
	// it is essential that nothing is done by the combination
	// of this constructor and ios::ios().  So we undo the effect of
	// ios::ios() 
	state = assign_private ;
	}

istream_withassign::~istream_withassign()  { } 

istream_withassign& istream_withassign::operator=(istream& s)
{
	init(s.rdbuf()) ;
	return *this ;
	}

ostream_withassign::~ostream_withassign()  { } 

istream_withassign& istream_withassign::operator=(streambuf* sb)
{
	init(sb) ;
	return *this ;
	}

ostream_withassign::ostream_withassign() 
{
	// In order for the standard streams to be properly initialized
	// it is essential that nothing is done by the combination
	// of this constructor and ios::ios().  So we undo the effect of
	// ios::ios() 
	state = assign_private ;
	}

ostream_withassign& ostream_withassign::operator=(ostream& s)
{
	init(s.rdbuf()) ;
	return *this ;
	}

ostream_withassign& ostream_withassign::operator=(streambuf* sb)
{
	init(sb) ;
	return *this ;
	}

iostream_withassign::iostream_withassign() 
{
	// In order for the standard streams to be properly initialized
	// it is essential that nothing is done by the combination
	// of this constructor and ios::ios().  So we undo the effect of
	// ios::ios() 
	state = assign_private ;
	}

iostream_withassign::~iostream_withassign()  { } 


iostream_withassign& iostream_withassign::operator=(ios& s)
{
	init(s.rdbuf()) ;
	return *this ;
	}

iostream_withassign& iostream_withassign::operator=(streambuf* sb)
{
	init(sb) ;
	return *this ;
	}

void ios::uresize(int n)
{
	if ( n < nuser ) return ;
	ios_user_union* newu = new ios_user_union[n+1] ;
	for ( int x = 0 ; x < nuser ; ++x ) {
		newu[x] = x_user[x] ;
		} ;
	delete [nuser] x_user ;
	nuser = n+1 ;
	x_user = newu ;
	}

long & ios::iword(int x)
{
	if ( x < 0 ) x = 0 ;
	if ( x >= nuser ) uresize(x) ;
	return x_user[x].i ;
	}

void* & ios::pword(int x)
{
	if ( x < 0 ) x = 0 ;
	if ( x >= nuser ) uresize(x) ;
	return x_user[x].p ;
	}


long ios::bitalloc()
{
	long w = nextbit ;
	nextbit = nextbit << 1 ;
	return w ;
	}

long ios::xalloc()
{
	return nextword++ ;
	}
0707070044043602551004440042240042240000010450100437115412200001100000003251stream.h/*ident	"@(#)ctrans:incl/stream.h	1.1.5.1" */
/**************************************************************************
                        Copyright (c) 1984 AT&T
                          All Rights Reserved   

        THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T
      
        The copyright notice above does not evidence any        
        actual or intended publication of such source code.

*****************************************************************************/

#ifndef STREAMH
#define STREAMH

#include <iostream.h>
#include <iomanip.h>
#include <stdiostream.h>

#ifndef NULL
#define NULL	0
#endif

extern char*  oct(long, int =0);
extern char*  dec(long, int =0);
extern char*  hex(long, int =0);

extern char*  chr(int, int =0);	/* chr(0) is the empty string "" */
extern char*  str(const char*, int =0);
extern char*  form(const char* ...);
			/* printf format
                         * Things may go terribly wrong (maybe even core
                         * dumps, if form tries to create a string with
                         * more than "max_field_width" characters. */

/* WS used to be a special in streams. The WS manipulator
 * is implemented differently but may be extracted from an istream
 * with the same effect as the old form.
 */

extern istream& WS(istream&) ;
extern void eatwhite(istream&) ;

static const int input = (ios::in) ;
static const int output = (ios::out) ;
static const int append = (ios::app) ;
static const int atend = (ios::ate) ;
static const int _good = (ios::goodbit) ;
static const int _bad = (ios::badbit) ;
static const int _fail = (ios::failbit) ;
static const int _eof = (ios::eofbit) ;

typedef io_state state_value ;

#endif
0707070044044146111004440042240042240000011627220443013566500001400000007423streambuf.c/*ident	"@(#)ctrans:lib/stream/streambuf.c	1.1.6.2" */
/**************************************************************************
                        Copyright (c) 1984 AT&T
                          All Rights Reserved   

        THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T
      
        The copyright notice above does not evidence any        
        actual or intended publication of such source code.

streambuf.c:

*****************************************************************************/

#include <iostream.h>
#include "streamdefs.h"
#include <string.h>
#include <memory.h>

/*
	Allocate some space for the buffer.
	Returns:	EOF on error
			0 on success
*/
int streambuf::doallocate()
{
	char *buf = new char[STREAMBUFSIZE] ;
	if ( !buf ) return EOF ;
	setb(buf,buf+STREAMBUFSIZE,1) ;
	return 0;
}

/*
	Come here on a put to a full buffer.  Allocate the buffer if 
	it is uninitialized.
	Returns:	EOF on error
			the argument on success
*/
int streambuf::overflow(int c)
{
	if ( c==EOF ) 			return zapeof(c) ;
	if ( allocate() == EOF)		return EOF;

	if ( x_pptr <= x_epptr )  	return sputc(c) ;
	else				return EOF ;
}

/*
	Fill a buffer.
	Returns:	EOF on error or end of input
			next character on success
*/
int streambuf::underflow()
{
	if ( x_pptr > x_egptr ) setg(x_eback,x_gptr,x_pptr) ;

	if ( x_egptr > x_gptr )	return 0 ;
	else 		    	return EOF ;
}

int streambuf::pbackfail(int)
{
	return EOF;
}

int streambuf::sync()
{
	// It's unclear exactly what this should do.  Should it reset
	// the buffer or what.  One theory (that used to be in the code.
	// was that it should insert a 0.  Which seems to be the
	// right thing for "strings".
	if ( x_pptr && x_epptr > x_pptr )  sputc(0) ;
	return EOF ;
}


streampos streambuf::seekpos(streampos p, int m)
{
	return seekoff(p, ios::beg, m) ;
	}

streampos streambuf::seekoff(streampos,seek_dir,int) 
{
	return EOF ;
}

int streambuf::xsputn(register const char* s, int n)
{
	register int req = n ;
	if ( unbuffered() ) {
		while( req-- > 0 ) {
			if ( sputc(*s++) == EOF ) return n-req-1 ;
		}
		return n ;
	}
	register int avail = x_epptr-x_pptr ;
	while ( avail < req ) {
		memcpy(x_pptr,s,avail) ;
		s += avail ;
		pbump(avail) ;
		req -= avail ;
		if ( overflow(zapeof(*s++)) == EOF ) return n-req ;
		--req ;
		avail = x_epptr-x_pptr ;
	}
	memcpy(x_pptr,s,req ) ;
	pbump(req) ;
	return n ;
}

int streambuf::xsgetn(register char* s, int n)
{
	register char* p = s ;
	register int req = n ;
	if (  unbuffered()  ) {
		while (req-- > 0 ) {
			register int c ;
			if ( (c=sbumpc() ) != EOF )  *p++ = c ;
			else 			return p-s ;
		}
	}

	if ( req <= 0 ) return 0 ;

	register int avail = x_egptr-x_gptr ;
	while (  avail < req ) {
		memcpy(p,x_gptr,avail) ;
		p += avail ; 
		req -= avail ;
		gbump(avail) ;
		if ( underflow()==EOF ) return p-s ;
		avail = x_egptr-x_gptr ;
		}

	memcpy(p,x_gptr,req) ;
	gbump(req) ;
	return n ;
}


streambuf* streambuf::setbuf(char* p , int len)
{

	if ( x_base ) return 0 ;
	if ( len <= 0 || p == 0 ) {
		// make it unbuffered
		setb(0,0,0) ;
		setg(0,0,0) ;
		setp(0,0);
		unbuffered(1) ; 
		}
	else {
		setb(p,p+len,0) ;
		setg(p,p,p) ;
		setp(p,p+len) ;
		unbuffered(0) ;
		} 
	return this;
}

streambuf* streambuf::setbuf(unsigned char* p, int len)
{
	return setbuf((char*)p,len) ;
}

streambuf::streambuf() :
	x_unbuf(0), alloc(0)
{
	setb(0,0,0);
	setg(0,0,0);
	setp(0,0);
}

streambuf::streambuf(char* p, int l) :
	x_unbuf(0), alloc(0)
{
	setb(0,0,0);
	setbuf(p,l) ;
}

streambuf::~streambuf() 
{
	sync() ;
	if (x_base && alloc) delete x_base;
	}

int streambuf::x_snextc()
{
	// called by snextc to handle overflow
	if ( x_egptr==0 || x_gptr != x_egptr ) {
		// we stepped beyond x_gptr meaning snextc was called when
		// x_gtr == x_egptr rather than when x_gptr+1=x_egptr.
		underflow() ;
		pbump(1) ;
		}
	return sgetc() ;
	}
0707070044044142641004440042240042240000011622740437760332500001500000004211streamdefs.h/*ident	"@(#)ctrans:lib/stream/streamdefs.h	1.1.2.1" */
/**************************************************************************
			Copyright (c) 1984 AT&T
	  		  All Rights Reserved  	

	THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T
	
	The copyright notice above does not evidence any   	
	actual or intended publication of such source code.

streamdefs.h:

*****************************************************************************/


// This file contains #defines for controlling conditional compilation 
// of the stream library


// The follwing functions adjust for machine dependencies

#define BREAKEVEN	10    
			/* The approximate length of a string
			 * for which it is faster to do a strncpy
			 * than a char by char loop. If BREAKEVEN is 0 
			 * then strncpy is always better.  If it is <0 then 
			 * loop is always better, (e.g. if strncopy does
			 * a char by char copy anyway.)
			 */

#define SEEK_ARITH_OK	1
			/* System supports arithmetic on stream positions.
			 * I.e. if file is at a position and we read or
			 * write n bytes we can find the new position
			 * by adding n to old position. (Providing
			 * O_APPEND isn't set in on open.)
			 */

static const int PTRBASE = ios::hex ;
			/* base for output of pointers (void*) */

// There is one important machine dependent feature of this implementation
// It assumes that it can always create a pointer to the byte after
// a char array used as a buffer, and that pointer will be greater than
// any pointer into the array. 
// My reading of the ANSI standard is that this assumption is permissible,
// but I can imagine segmented architectures where it fails.

/* #define VSPRINTF vsprintf */

			/* If defined, the name of a "vsprintf" function.
			 * If not defined, 
			 * various non-portable kludges are used in
			 * oldformat.c
			 */

static const int STREAMBUFSIZE = 1024 ;
			// The default buffer size.

/*******
	#define O_CREAT 01000 
	#define O_TRUNC 02000 
	#define O_EXCL  04000
 *******/
			/* Used in filebuf.c.  Define if your system
			 * needs it to have a value different from
			 * that indicated here, but doesn't
			 * define it in standard system headers
			 */
0707070044044146121004440042240042240000011606300443013570600001400000014566strstream.c/*ident	"@(#)ctrans:lib/stream/strstream.c	1.1.4.2" */
/**************************************************************************
                        Copyright (c) 1984 AT&T
                          All Rights Reserved   

        THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T
      
        The copyright notice above does not evidence any        
        actual or intended publication of such source code.

strstream.c:

*****************************************************************************/

#include <iostream.h>
#include <string.h>
#include <strstream.h>
#include <memory.h>

typedef unsigned int Size_t ;	
			// Some day <memory.h> will be ANSIfied and
			// this will be declared there.
			// Until then make it compatible with declaration
			// of third argument of memcpy.

static const int initsize = 16*sizeof(int) ;
static const int increment = 2 ; 	

static const int arbitrary = 1024 ;	// used by ignore_oflow.

static const int ios_atend = ios::ate ;
static const int ios_input = ios::in ;
static const int ios_output = ios::out ;
static const int ios_append = ios::app ;
static const int seek_cur = ios::cur ;
static const int seek_end = ios::end ;
static const int seek_beg = ios::beg ;

strstreambuf::strstreambuf(void* (*a)(long), void (*f)(void*)) :
	afct(a),
	ffct(f),
	froozen(1),
	auto_extend(initsize),
	ignore_oflow(0)
{
	}

void strstreambuf::init(char* b, int size, char* pstart)
{
	if ( b && size > 0 ) {
		setb(b,b+size) ;
		}
	else if ( b && size == 0 ) {
		setb(b,b+strlen(b) ) ;
		}
	else if ( b && size < 0 ) {
		ignore_oflow = 1 ;
		setb(b,b+arbitrary) ;
		}
	else if ( !b && size > initsize ) {
		auto_extend = size ;
		setb(0,0) ;
		}
	else {
		setb(0,0) ;
		}

	if ( pstart && base() && base() <= pstart && pstart <= ebuf() ) {
		setp(pstart,ebuf()) ;
		}
	else {
		setp(0,0) ;
		}
	
	if ( base() ) {
		setg(base(),base(),ebuf()) ;
		auto_extend = 0 ;
		froozen = 1 ;
		}
	else {
		setg(0,0,0) ;
		}
	}

strstreambuf::strstreambuf(char* b, int size, char* pstart) :
	afct(0),
	ffct(0),
	froozen(0),
	auto_extend(0),
	ignore_oflow(0)
{
	init(b,size,pstart) ; 
	}

strstreambuf::strstreambuf(unsigned char* b, int size, unsigned char* pstart) :
	afct(0),
	ffct(0),
	froozen(0),
	auto_extend(0),
	ignore_oflow(0)
{
	init((char*)b,size,(char*)pstart) ; 
	}


strstreambuf::strstreambuf(int ae) :
	afct(0),
	ffct(0),
	froozen(1),
	auto_extend(ae>0?ae:initsize),
	ignore_oflow(0)
{
	}

strstreambuf::strstreambuf() :
	afct(0),
	ffct(0),
	froozen(1),
	auto_extend(initsize),
	ignore_oflow(0)
{
	}


int strstreambuf::doallocate()
{
	if ( auto_extend < initsize ) auto_extend = initsize ;
	char* newspace  = afct ? (char*)(*afct)(auto_extend) 
			       : new char[auto_extend] ;

	if ( !newspace ) return EOF ;

	froozen = 0 ;
	setb(newspace,newspace+auto_extend,0) ;
			// Will free this space ourselves if neccessary

	setp(newspace,newspace+auto_extend) ;
	setg(newspace,newspace,newspace) ;

	return 0 ;
	}

int strstreambuf::overflow(int c)
{
	if ( !base() ) {
		allocate() ;
		if ( !base() ) return EOF ;
		}
	else if ( auto_extend && !froozen ) {
		Size_t inserted=pptr()-base() ; // number of chars previously
						// inserted into buffer

		Size_t extracted=gptr()-base() ;
						// number of chars previously
						// extracted from buffer

		// after we copy chars from current space to a new
		// (larger) area we have to adjust pointers to take into
		// acount previous activities.

		Size_t newsize = (Size_t)increment*blen() + 4 ;
		if ( newsize < auto_extend ) newsize = auto_extend ;
		char* newspace = afct ? (char*)(*afct)(newsize) 
			     	      : new char[newsize] ;

		if ( !newspace ) return EOF ;

		memcpy(newspace,base(),inserted) ;

		if ( ffct )	(*ffct)(base()) ;
		else		delete base() ;

		setb(newspace,newspace+newsize,0) ;
		setp(base()+inserted,ebuf()) ;
		setg(base(),base()+extracted,pptr()) ;
		}
	else if ( ignore_oflow ) {
		setp(pptr(),pptr()+arbitrary) ; 
		}
	else {
		return EOF ;
		}
	if ( c!=EOF ) return sputc(c) ;
	}

int strstreambuf::underflow()
{
	if ( !pptr() ) return EOF ;
	if ( !egptr() ) return EOF ;

	setg(base(),egptr(),pptr()) ;
	
	if ( egptr() <= gptr() )	return EOF ;
	else				return *gptr() ;
	}

void strstreambuf::freeze(int n) 
{
	froozen = n ;
	}


char* strstreambuf::str() 
{
	freeze() ;
	return base() ;
	}

strstreambuf::~strstreambuf()
{
	if ( !froozen && base() ) {
		if ( ffct ) 	ffct(base()) ;
		else		delete base() ;
		}
	}

streambuf* strstreambuf::setbuf(char* p, int size) 
{
	if ( p == 0 && ( base()==0 || auto_extend ) ) {
		auto_extend = size ;
		return this ;
		}
	else {
		return 0 ;
		}
	}

streampos strstreambuf::seekoff(streamoff o, seek_dir d, int m)
{
	switch (d) {
	case seek_beg : break ;
	case seek_cur : {
		if ( (m&ios_input) ) {
			o += gptr()-base() ;
			}
		else  {
			o += pptr()-base() ;
			}
		} break ;
	case seek_end : {
		if ( gptr()<egptr() && egptr()>pptr() ) {
			o += egptr()-base() ;
			}
		else if ( pptr()<epptr() ) {
			o += pptr()-base();
			}
		} break ;
	    } // end switch
	if ( o < 0 ) return streampos(EOF) ;
	if ( o >= blen() && !ignore_oflow ) return streampos(EOF) ;
	if ( m&ios_input ) setg(base(), base()+o, egptr() ) ;
	if ( m&ios_output) setp(base()+o, epptr() ) ;
	return o ;
	}

strstreambase::strstreambase(char* str, int size, char* pstart)
	:  buf(str,size,pstart) { init(&buf) ; }

strstreambase::strstreambase() : buf() { init(&buf) ; }

strstreambase::~strstreambase() { }

strstreambuf* strstreambase::rdbuf() { return &buf ; }

istrstream::istrstream(char* str)
	: strstreambase(str,strlen(str),0) { }

istrstream::istrstream(char* str, int size)
	: strstreambase(str, size , 0) { }

istrstream::~istrstream() { }


static char* pstart(char* str, int size, int m)
{
	if ( (m&(ios_append|ios_output)) == 0 )	return str+size ;
	else if ( (m&(ios_append|ios_atend)) )	return str+strlen(str) ;
	else					return str ;
	}

ostrstream::ostrstream(char* str, int size, int m)
	: strstreambase(str, size, pstart(str,size, (m|ios_output)) )
{ }

ostrstream::ostrstream() : strstreambase() { }


ostrstream::~ostrstream()
{
	ios::rdbuf()->sputc(0) ;
	}

char* ostrstream::str() 
{
	return strstreambase::rdbuf()->str() ;
	}

int ostrstream::pcount() {
	return ios::rdbuf()->out_waiting() ;
	}

strstream::strstream() : strstreambase() { }

strstream::strstream(char* str, int size, int m) 
	: strstreambase(str,size,pstart(str,size,m)) 
{ }

char* strstream::str() 
{
	return strstreambase::rdbuf()->str() ;
	}


strstream::~strstream() { }
0707070044044146051004440042240042240000011620550443013473100001400000003720strstream.h/*ident	"@(#)ctrans:incl/strstream.h	1.1.1.1" */
/**************************************************************************
                        Copyright (c) 1984 AT&T
                          All Rights Reserved   

        THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T
      
        The copyright notice above does not evidence any        
        actual or intended publication of such source code.

*****************************************************************************/
#ifndef STRSTREAMH
#define STRSTREAMH

#include <iostream.h>
class strstreambuf : public streambuf
{
public: 
			strstreambuf() ;
			strstreambuf(int) ;
			strstreambuf(void* (*a)(long), void (*f)(void*)) ;
			strstreambuf(char* b, int size, char* pstart = 0 ) ;
			strstreambuf(unsigned char* b, int size, unsigned char* pstart = 0 ) ;
	void		freeze(int n=1) ;
	char*		str() ;
			~strstreambuf() ;

public: /* virtuals  */
	virtual int	doallocate() ;
	virtual int	overflow(int) ;
	virtual int	underflow() ;
	virtual streambuf*
			setbuf(char*  p, int l) ;
	virtual streampos
			seekoff(streamoff,seek_dir,int) ;

private:
	void		init(char*,int,char*) ;

	void*		(*afct)(long) ;
	void		(*ffct)(void*) ;
	int		ignore_oflow ;
	int		froozen ;
	int		auto_extend ;

public:
	} ;

class strstreambase : public virtual ios {
public:
	strstreambuf*	rdbuf() ;
protected:	
			strstreambase(char*, int, char*) ;
			strstreambase() ;
			~strstreambase() ;
private:
	strstreambuf	buf ; 
	} ;

class istrstream : public strstreambase, public istream {
public:
			istrstream(char* str);
			istrstream(char* str, int size ) ;
			~istrstream() ;
	} ;

class ostrstream : public strstreambase, public ostream {
public:
			ostrstream(char* str, int size, int=ios::out) ;
			ostrstream() ;
			~ostrstream() ;
	char*		str() ;
	int		pcount() ;
	} ;


class strstream : public strstreambase, public iostream {
public:
			strstream() ;
			strstream(char* str, int size, int mode) ;
			~strstream() ;
	char*		str() ;
	} ;

#endif
0707070044044142521004440042240042240000011613160443033725500001200000002075swstdio.c/*ident	"@(#)ctrans:lib/stream/swstdio.c	1.1.1.1" */
/**************************************************************************
			Copyright (c) 1984 AT&T
	  		  All Rights Reserved  	

	THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T
	
	The copyright notice above does not evidence any   	
	actual or intended publication of such source code.

swstdio.c:

*****************************************************************************/


#include <iostream.h>
#include <stdiostream.h>

static void stdioflush()
{
	fflush(stdout) ;
	fflush(stderr) ;
	}

void ios::sync_with_stdio() 
{
	switch ( Iostream_init::stdstatus )
	{
	case 1 : cout.flush() ; cerr.flush() ; clog.flush() ; break ;
	case 2 : break ;
	default : return ; }
 
	cin = new stdiobuf(stdin) ;
	cout = new stdiobuf(stdout) ;
	cerr = new stdiobuf(stderr) ;
	clog = cerr ;
	cin.setf(~0L,skipws) ;
	cout.setf(~0L,unitbuf|stdio) ;
	cerr.setf(~0L,unitbuf|stdio) ;
	clog.setf(~0L,unitbuf|stdio) ;
	cin.tie(&cout) ;
	cerr.tie(&cout) ;
	clog.tie(&cout) ;
	Iostream_init::stdstatus = 2 ;
	ios::stdioflush = ::stdioflush ;
	}
0707070044043601661006440042240042240000010432300443212600200001000000000134versionIostream with multiple inheritance
hector!/home/jss/work/iosrc
Wed May 10 17:39:14 EDT 1989
0707070044043601661006440042240042240000010432300443212600200001300000000000TRAILER!!!0134versionIostream with multiple inheritance
hector!/home/jss/work/iosrc
Wed May 10 17:39:14 EDT 1989
0707070044043601661006440042240042240000010432300443212600200001300000000000TRAILER!!!0134versionIostream with multiple inheritance
hector!/home/jss/work/iosrc
Wed May 10 17:39:14 EDT 1989
07070700440436016610064400

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.