|
|
1.1 root 1: 0707070044042147441006440042240042240000020065000443212436100000700000026560README
2: 5/9/89: Have filebuf::sync() reset last_seek. This will have the
3: effect that if somebody else moves the file pointer
4: after a sync() but before a seek(), the filebuf will behave
5: sensibly.
6:
7: 5/9/89: Fix define of "hardfail".
8:
9: 5/5/89: Lots of stuff to improve buffering. New function
10:
11: ostream::osfx()
12: Perform "suffix" actions before returning from
13: inserters. This is called by all predefined
14: inserters. It isn't called by the binary output functions.
15: And should be called by user inserters
16: after any direct manipulation of the streambuf.
17:
18: There are two new format flags:
19:
20: unitbuf: when set a flush is performed by osfx() ;
21: stdio: when set stdout and stderr are flushed by osfx() ;
22:
23: cerr is now unitbuf'ed rather than unbuffered.
24:
25: sync_with_stdio makes cout, cerr unit buffered rather than
26: unbuffered.
27:
28: cin and cout now get the arrays they use dynamically. (Previously
29: they were statically allocated.) This change is prompted
30: by people who complained about wasting 2K when they didn't
31: use cin or cout.
32:
33: 5/5/89: Add check in streambuf* insertor so that it sets failbit when
34: given the null pointer. (Right now it just core dumps).
35:
36: 5/5/89: Change ios::clear to have an int argument
37:
38: cycle 16
39:
40: 5/4/89: Change all open_mode arguments to ints.
41:
42: 5/3/89: Fix ws manipulator so that it will flushed tied ostream
43: when required.
44:
45: 5/2/89: More cleanup of open_mode arguments. Add defaults for
46: ifstream::open and ofstream::open. Change all
47: defaults to filebuf::openprot
48:
49: cycle 15
50:
51: 4/28/89. Add default open_mode arguments to ifstream and ofstream
52: constructors.
53:
54: cycle 14?
55:
56: 4/18/89. Fix bug is filebuf::seekoff that also caused problems
57: for tellg and tellp.
58:
59: 4/13/89. Change cstreams.c so it doesn't refer to skip (which is
60: a stream compatibility function.
61:
62: ------------------------------------------------
63: Cycle 13
64:
65: Change typedef in strstream.c to avoid use of size_t. (This is
66: because of header file compatibility problems.)
67:
68: Change exit(10) to abort() in oldformat.c.
69:
70: Cycle 12
71:
72: Put in include of <iostream.h> in strstream.h
73:
74: Change istream::get() so that it really gets expanded inline.
75: Previous definition was being outlined.
76:
77: Reorder declarations so that ipfx comes before any operator>>. Not
78: just before the ones that have inline code refering to it. The old
79: ordering was resulting in a failure to expand ipfx where it should
80: have been.
81:
82: Move declaration of ios_user_union higher in stream.c in order to
83: eliminate a new warning message.
84:
85: Change values of O_CREAT O_TRUNC O_EXCL in cases where headers don't
86: define them (the only known such system is V9)
87:
88: Fix ostream::out_waiting. It was just returning non-zero when there was stuff
89: accumulated but not consumed. It was supposed to return the number
90: (at least according to the man page.)
91:
92: -----------------------------------------------------
93: Cycle 11
94:
95: Change cstreams.c for change to way explicit placement works.
96:
97: Implement bidirectional strstream.
98:
99: ----------------------------------------------------
100: Cycle 9
101:
102: Fix bug in void* inserter. (Showbase should have been set
103: but wasn't)
104:
105:
106: --------------------------------------------------
107: Cycle 8
108:
109: streambuf::snextc was not incrementing the get pointer before
110: it called underflow. This had no effect because the streambuf
111: classes assume that when underflow is called there
112: was nothing in the buffer. The man page said that although this
113: was "normally the case" but doesn't guarantee it. I wrote a new
114: streambuf class that checked for the condition and it failed.
115: I've fixed snextc.
116:
117: ---------------------------------------------------
118: Cycle 7
119:
120: Fix bug in setstate.
121:
122: Change return type of filebuf::close to filebuf*
123:
124: Add noreplace to open_mode
125:
126: Fixed bug in adjustment of floating fields
127:
128: -----------------------------------------------------
129:
130: Cycle 6.1
131:
132: Interpretation of justification fields was screwed up.
133:
134: Fix for whitespace eating of character extractor of cycle 6 was
135: incomplete. (It might read characters when the stream was
136: in error status).
137:
138: -----------------------------------------------------
139: Cycle 6
140:
141: Make streambuf::xsgetn and streambuf::xsputn virtuals
142:
143: ios::operator int changed to ios::operator void* in order to allow
144: detection of "cin << 5" without requiring any extractor or inserter
145: to be declared in class iostream.
146:
147: sync is moved from ios to istream, the corresponding action on
148: ostreams is flushing.
149:
150: Reorder declarations in iostream.h to avoid forward enum tag
151: declarations.
152:
153: Fixes to single character extractors to make sure they skip
154: whitespace when required.
155:
156: Massive simplification of format control stuff
157:
158: struct fmtinfo goes away as do pushing and popping of it.
159:
160: several format state variables are consolodated into
161: a single flag field and new flags are added to control
162: more stuff. Remaining state variables are fill, precision and
163: width. New statevariable "flags".
164:
165: Flags declared in an enum within ios:
166:
167: enum { skipws=01,
168: /* skip whitespace on input */
169: left=02, right=04, internal=010,
170: /* padding location */
171: dec=020, oct=040, hex=0100,
172: /* conversion base */
173: showbase=0200, showpoint=0400, uppercase=01000,
174: showpos=02000,
175: /* modifiers */
176: scientific=04000, fixed=010000
177: /* floating point notation */ } ;
178:
179: Functions to manipulate the flag field
180: s.flags() return current flag
181: s.flags(b) sets flags to b
182: s.setf(b) turns on bits marked in f in flags
183: s.setf(b,f) assigns b to "field" specified by f
184: (i.e. bits that are on in f)
185:
186: static ios int members for convienent reference to fields
187: ios::basefield = hex|dec|oct ;
188: ios::adjustfield = left|right|internal ;
189: ios::floatfield = scientific|fixed ;
190:
191: New manipulators
192:
193: s << setfill(f) sets fill state variable
194: s << setprecision(p) sets precision state variable
195: s << setiosflags(b) does s.setf(b)
196: s << resetiosflags(b) does s.setf(0,b)
197:
198: New user setable state variables
199:
200: flags are a long user code may use unassigned bits
201: s.iword(x) returns a long&
202: s.pword(s) returns a void*& (sharing space with s.iword(x)
203:
204:
205: ios::bitalloc() returns a previously unallocated bit
206: ios::xalloc() returns a previously unused index
207:
208: ---------------------------------------------
209: Cycle 5
210:
211: Eliminated a lot of warnings about assigning longs to ints and
212: the like.
213:
214: Put in some overflow detection on integer input (it is still very
215: incomplete).
216:
217: Change sync_with_stdio into a static member function
218:
219: Add enum_mode, nocreate. Causes failure of an open if file does not
220: previously exist.
221:
222: Changed popfmt to reset width to 0. This is more consistent with the
223: normal use.
224:
225: Fixed some bugs in interaction of EOF eating whitespace and "ignore"
226:
227: ------------------------------------------
228:
229: Multiple Inheritance Version.
230:
231: Changes from previous version:
232:
233: MI structure in classes. Mainly this is a lot of trivial changes.
234: But one substantive change arises. Because ios is now inherited
235: as a virtual base class, a constructor with no arguments must
236: be used. Therefore ios::init(streambuf*) is declared protected and
237: must be used to initialize in derived classes.
238:
239: -------------------------------------------
240:
241: The latest version of the iostream package incorporates a large
242: number of changes and bug fixes. They are listed here in my
243: estimation of their importance.
244:
245: In principle, istream, ostream, and iostream are now distinct
246: classes. istream only contains input operations and ostream only
247: contains output operations. iostream is the "join" of the two. There
248: is a new class ios containing the common state information from which
249: all these are derived.
250:
251: This means, for example, that cin should't be passed to a function
252: expecting an iostream.
253:
254: In practice to do this would have required a good implementation of
255: multiple inheritance with virtual base classes. To avoid relying on
256: this feature of C++ all the stream classes are typedefed to ios.
257:
258: As a consequence of this change several classes derived from
259: "istream" and "ostream" have been added. Namely ifstream, ofstream,
260: istrstream and ostrstream. These (rather than the bidrectional
261: fstream and strstream) should be used when a stream for only input or
262: only output is desired.
263:
264: The kludge that used #defines and pointer variables to implement cin,
265: cour, cerr and cdebug has been eliminated. The standard streams are
266: now declared as extern variables in iostream.h. Their types are
267: classes derived from iostream with an assignment operator. So that it
268: is now permitted to assign streams to them.
269:
270: Because cfront now distinguishes int from char in overload resolution
271: cout << 'a' now outputs the character 'a' rather than the decimal
272: value. This is an incompatibility with the old stream package, but
273: is such a large improvement that I thought it was worth any
274: conversion problems it might cause. This made the manipulator
275: "onec" redundant and it has been removed.
276:
277: The name space has been cleaned up. A lot of identifiers that were
278: previously part of the global name space have been made local to a
279: class. A table of the old and new names follows. Probably the most
280: important is the renaming of open_modes.
281:
282: old name new name
283: -------- --------
284:
285: iocdebug // eliminated
286: iocerr // eliminated
287: iocin // eliminated
288: iocout // eliminated
289:
290: cdebug clog // Renamed because of
291: // complaints about old name
292:
293: state_value io_state
294: // Renamed because state_value
295: // was too unspecific
296:
297: _bad ios::badbit
298: _eof ios::eofbit
299: _fail ios::failbit
300: _good ios::goodbit
301:
302: append ios::app
303: atend ios::ate
304: input ios::in
305: output ios::out
306:
307: seek_beg ios::beg
308: seek_cur ios::cur
309: seek_end ios::end
310:
311: stream.h contains declarations of the names required for backward
312: compatibility with the stream package.
313:
314: The macros for declaring manipulator classes (IOMANIP and IOMANIP2)
315: have been replaced by a collection of macros that are more
316: "template-like". Two argument manipulators are not implemented.
317: (Users may follow the pattern in iomanip.h to implement them
318: themselves.)
319:
320: filebuf and fstream operations no longer clear errno.
321:
322: The virtual declaration of streambuf::setbuf now only has two
323: arguments. The three argument form exists in streambuf for
324: compatibility with the stream package, but the "official"
325: definition has only two arguments. Similarly the documented
326: constructor is now streambuf(char*,int).
327:
328: The members of fstream (ifstream and ofstream) that used to return an
329: int as an error indication (namely open, attach, close) now return
330: void. Errors are indicated by setting failbit in the error state.
331: There was some confusion here about whether an error was indicated by
332: returning 0 or EOF. Declaraing these functions to return void
333: eliminates the possibility of confusion.
334:
335: strstreambuf now allows setbuf in order to control sizes of
336: allocation in dynamic mode. (When character strings are being
337: automatically extended.)
338:
339: More careful checks for whether flushes are required on streams that
340: are tied to other streams. (E.g. flushes on cout when characters are
341: extracted from cin.)
342:
343: Tieing now works for insertion. E.g. cerr is tied to cout, so
344: insertion into cerr causes cout to be flushed.
345:
346: Redundant calls to allocate have been removed from streambuf::xsgetn
347: and streambuf::xsputn. (This means that the only calls to
348: streambuf::allocate from streambuf member functions are from the
349: virtuals that may be overriden in derived classes.)
350:
351: open with ios::ate (the old atend) no longer implies ios::out (the
352: old output). ios::app does. (ate is a perfectly sensible mode
353: for input.)
354:
355: eatwhite is defined for compatibility with stream package.
356: 0707070044044145711004440042240042240000011611140443034215700001300000003313cstreams.c /*ident "@(#)ctrans:lib/stream/cstreams.c 1.1.4.1" */
357: /**************************************************************************
358: Copyright (c) 1984 AT&T
359: All Rights Reserved
360:
361: THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T
362:
363: The copyright notice above does not evidence any
364: actual or intended publication of such source code.
365:
366: cstreams.c:
367:
368: *****************************************************************************/
369:
370: #include <iostream.h>
371: #include <fstream.h>
372: #include <new.h>
373: #include "streamdefs.h"
374:
375: int Iostream_init::stdstatus = 0 ;
376: int Iostream_init::initcount = 0 ;
377:
378: istream_withassign cin ;
379: ostream_withassign cout ;
380: ostream_withassign cerr ;
381: ostream_withassign clog ;
382:
383: // The value of Iostream_init::stdstatus describes the
384: // The std stream variables
385:
386: // 0 means istream::stdin, ostream::stdout, ostream::stderr, and
387: // ostream::stdlog are unitialized
388: // 1 means they are initialized to filebufs
389: // 2 means they are initialized to stdiobufs
390:
391: Iostream_init::Iostream_init()
392: {
393: ++initcount ;
394: if ( initcount > 1 ) return ;
395:
396: // Be careful. Initialization occurs before constructors
397: // of the standard streams are called.
398: new (&cin) istream_withassign ;
399: new (&cout) ostream_withassign ;
400: new (&cerr) ostream_withassign ;
401: new (&clog) ostream_withassign ;
402: cin = new filebuf(0) ;
403: cout = new filebuf(1) ;
404: cerr = new filebuf(2) ;
405: clog = new filebuf(2) ;
406:
407: cin.setf(~0L,ios::skipws) ;
408: cerr.setf(~0L,ios::unitbuf) ;
409: cin.tie(&cout) ;
410: cerr.tie(&cout) ;
411: clog.tie(&cout) ;
412: stdstatus = 1 ;
413: }
414:
415: Iostream_init::~Iostream_init()
416: {
417: --initcount ;
418: if ( initcount > 0 ) return ;
419: cout.flush() ;
420: cerr.flush() ;
421: clog.flush() ;
422: }
423: 0707070044044142401004440042240042240000011563100443207260400001200000021543filebuf.c /*ident "@(#)ctrans:lib/stream/filebuf.c 1.1.2.2" */
424: /**************************************************************************
425: Copyright (c) 1984 AT&T
426: All Rights Reserved
427:
428: THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T
429:
430: The copyright notice above does not evidence any
431: actual or intended publication of such source code.
432:
433: filebuf.c:
434:
435: *****************************************************************************/
436:
437: #include <iostream.h>
438: #include <fstream.h>
439: #include <osfcn.h>
440: #include "streamdefs.h"
441:
442: #ifndef O_RDONLY
443: # include <fcntl.h>
444: #endif
445:
446: #ifndef O_CREAT
447: # define O_CREAT 00400
448: #endif
449:
450: #ifndef O_TRUNC
451: # define O_TRUNC 01000
452: #endif
453:
454: #ifndef O_EXCL
455: # define O_EXCL 02000
456: #endif
457:
458:
459: #ifndef O_APPEND
460: # define O_APPEND 0
461: #endif
462:
463: #include <errno.h>
464: extern int errno ;
465:
466: const int filebuf::openprot = 0644 ;
467:
468: static const int input=ios::in ;
469: static const int output=ios::out ;
470: static const int append=ios::app ;
471: static const int atend=ios::ate ;
472: static const int tcate=ios::trunc ;
473: static const int nocr=ios::nocreate ;
474: static const int norep=ios::noreplace ;
475:
476: static const int seek_beg=ios::beg ;
477: static const int seek_end=ios::end ;
478: static const int seek_cur=ios::cur ;
479:
480: int filebuf::last_op()
481: {
482: return (pptr()?output:(gptr()?input:0)) ;
483: }
484:
485: inline void save_errno(int& orig)
486: {
487: orig = ::errno ;
488: ::errno = 0 ;
489: }
490:
491: inline int restore_errno(int& orig)
492: {
493: if ( ::errno == 0 ) ::errno = orig ;
494: return EOF ;
495: }
496:
497: /*
498: * Open a file with the given mode.
499: * Return: NULL if failure
500: * this if success
501: */
502: filebuf* filebuf::open (const char *name, int om, int prot)
503: {
504: int errno_orig ;
505: save_errno(errno_orig) ;
506: if ( om&append ) om |= output ;
507:
508: if ( opened ) {
509: restore_errno(errno_orig) ;
510: return 0 ;
511: }
512:
513: int flags = 0 ;
514: if ( om&append ) flags |= O_APPEND ;
515:
516: switch (om&(input|output)) {
517: case input :
518: flags |= O_RDONLY ;
519: xfd = ::open(name,flags) ;
520: break ;
521:
522: case output :
523: flags |= O_WRONLY|O_CREAT|O_TRUNC ;
524: if ( om&nocr ) flags &= ~O_CREAT ;
525: if ( om&norep ) flags |= O_CREAT|O_EXCL ;
526: if ( om&append ) flags |= O_APPEND ;
527: if ( flags == (O_WRONLY|O_CREAT|O_TRUNC) ) {
528: xfd = ::creat(name,prot) ;
529: }
530: else {
531: xfd = ::open(name,flags,prot) ;
532: }
533:
534: if ( xfd >= 0 && (om&(atend|append))) lseek(xfd,0,2) ;
535: break ;
536:
537: case input|output:
538: flags |= O_RDWR|O_CREAT ;
539: if ( om&tcate ) flags |= O_TRUNC ;
540: if ( om&append ) flags |= O_APPEND ;
541: if ( om&nocr ) flags &= ~O_CREAT ;
542: xfd = ::open(name,flags,prot) ;
543: if ( xfd >= 0 && (om&(atend|append))) lseek(xfd,0,2) ;
544: break;
545: }
546:
547: if (xfd < 0) return 0;
548:
549: opened = 1;
550: setp(0,0) ;
551: setg(0,0,0) ;
552: mode = om ;
553: last_seek = EOF ;
554: restore_errno(errno_orig) ;
555: return this;
556: }
557:
558: filebuf* filebuf::attach (int f)
559: {
560: if ( opened ) return 0 ;
561: xfd = f;
562: opened = 1;
563: setp(0,0) ;
564: setg(0,0,0) ;
565: mode=0 ;
566: last_seek= EOF;
567: return this;
568: }
569:
570: /*
571: * Empty an output buffer.
572: * Returns: EOF on error
573: * 0 on success
574: */
575: int filebuf::overflow(int c)
576: {
577: int errno_orig ;
578: save_errno(errno_orig) ;
579: if ( !opened ) return restore_errno(errno_orig) ;
580: if ( allocate() == EOF ) return restore_errno(errno_orig) ;
581: if ( last_op() == input ) {
582: if ( sync()==EOF ) return restore_errno(errno_orig) ;
583: }
584:
585: register char* p = base() ;
586: // pptr()==NULL does not imply p < pptr(), so we need separate
587: // test.
588: while ( pptr() && p < pptr() ) {
589: if ( O_APPEND==0 && (mode&append) ) {
590: // System doesn't have an append mode, so approximate
591: // as best we can.
592: lseek(xfd,0,2) ;
593: }
594: /* Partial writes are sometimes possible in peculiar
595: * circumstances */
596: register int count = write(xfd,p,pptr()-p) ;
597: if ( count < 0 ) {
598: last_seek = EOF ;
599: return restore_errno(errno_orig) ;
600: }
601: p += count ;
602:
603: if ( SEEK_ARITH_OK
604: && last_seek != EOF
605: && mode && !(mode&append)
606: && count >= 0 ) {
607: last_seek += count ;
608: } else {
609: last_seek = EOF ;
610: }
611:
612: if ( count < 0 ) return restore_errno(errno_orig) ;
613: }
614:
615: setp(base(),ebuf()) ;
616: setg(0,0,0);
617:
618: if ( c == EOF ) /* don't do anything */ ;
619: else if ( unbuffered() ) {
620: char ch = c;
621: last_seek = EOF ;
622: while ( write(xfd,&ch,1)!=1 && ::errno==0 ) ;
623: if ( ::errno != 0 ) return restore_errno(errno_orig) ;
624: }
625: else {
626: sputc(c) ;
627: }
628:
629: restore_errno(errno_orig) ;
630: return zapeof(c) ;
631: }
632:
633:
634: /*
635: * Fill an input buffer.
636: * Returns: EOF on error or end of input
637: * next character on success
638: */
639: int filebuf::underflow()
640: {
641: int count;
642:
643: if ( !opened ) return EOF ;
644: if ( allocate() == EOF ) return EOF ;
645: if ( last_op() == output ) {
646: if ( sync()==EOF ) return EOF ;
647: }
648: int orig_errno ;
649: save_errno(orig_errno) ;
650: setp(0,0) ;
651: if ( unbuffered() ) {
652: last_seek=EOF ;
653: count = read(xfd,&lahead[0],1) ;
654: setg(&lahead[0],&lahead[0],&lahead[count]) ;
655: if ( count <= 0 ) return EOF ;
656: }
657: else {
658: register int rdsize ;
659: if ( blen() > 2*sizeof(long) ) {
660: /* gptr must be set greater than base to
661: * guarantee at least 1 char of pushback.
662: * putting it farther will tend in many common
663: * cases to keep things aligned.
664: */
665: in_start = base()+sizeof(long) ;
666: rdsize = blen()-sizeof(long) ;
667: } else {
668: in_start = base()+1 ;
669: rdsize = blen()-1 ;
670: }
671: count = read(xfd,in_start,rdsize) ;
672: while ( count<=0 && ::errno==EINTR ) {
673: /*
674: * Signal caught and returned before any data
675: * transfered.
676: */
677: ::errno = 0 ;
678: count = read(xfd,in_start,rdsize) ;
679: }
680:
681: if ( SEEK_ARITH_OK
682: && last_seek != EOF
683: && mode && !(mode&append)
684: && count >= 0 ) {
685: last_seek += count ;
686: } else {
687: last_seek = EOF ;
688: }
689:
690: if ( count <= 0 ) {
691: setg(0,0,0) ;
692: return restore_errno(orig_errno) ;
693: }
694: setg(base(),in_start,in_start+count) ;
695: }
696:
697: restore_errno(orig_errno) ;
698: return zapeof(*gptr());
699: }
700:
701: filebuf* filebuf::close()
702: {
703: int f = xfd ;
704: if ( !opened ) {
705: return 0 ;
706: }
707: if (last_op()==output) overflow();
708: setg(0,0,0) ;
709: setp(0,0) ;
710: opened = 0 ;
711: xfd = -1 ;
712: last_seek = EOF ;
713: if ( mode != 0 ) {
714: mode = 0 ;
715: int orig_errno ;
716: save_errno(orig_errno) ;
717: int ok = ::close(f);
718: restore_errno(orig_errno) ;
719: return ( ok==EOF ? 0 : this ) ;
720: } else {
721: return this ;
722: }
723: }
724:
725: int filebuf::sync()
726: {
727: int ok = 0 ;
728: int orig_errno ;
729: save_errno(orig_errno) ;
730: switch(last_op()) {
731: case input:
732: last_seek = lseek(xfd,gptr()-egptr(),seek_cur) ;
733: if ( last_seek < 0 ) {
734: ok = EOF ;
735: last_seek = EOF ;
736: }
737: break ;
738: case output:
739: ok = overflow() ;
740: /* This does not result in infinite recursion even though
741: * under some circumstances overflow might call sync.
742: * it explicitly does not when last_op==output
743: */
744: break;
745: }
746: setp(0,0) ;
747: setg(0,0,0) ;
748: last_seek = EOF ;
749: restore_errno(orig_errno) ;
750: return (ok==EOF ? EOF : 0 ) ;
751: }
752:
753: streampos filebuf::seekoff(streamoff p, seek_dir d, int m)
754: {
755: int orig_errno ;
756: save_errno(orig_errno) ;
757:
758: if ( last_seek == EOF ) {
759: last_seek = lseek(xfd,0,seek_cur) ;
760: }
761: if ( last_seek == EOF ) return EOF ;
762: if( SEEK_ARITH_OK && !unbuffered() ) {
763: char* refptr = 0 ;
764: streampos sneed ;
765: streampos sref, minavail, maxavail ;
766:
767: switch ( last_op() ) {
768: case input : {
769: refptr = gptr() ;
770: sref = last_seek-(egptr()-gptr()) ;
771: minavail = last_seek-(egptr()-in_start) ;
772: maxavail = last_seek-1 ;
773: } break ;
774: case output : {
775: // only allowable seek during output is
776: // to present position.
777: refptr = pptr() ;
778: sref = last_seek+pptr()-pbase() ;
779: minavail = maxavail = sref ;
780: } break ;
781: }
782: switch( d ) {
783: case seek_beg : sneed = p ; break ;
784: case seek_cur : sneed = sref+p ;break ;
785: case seek_end : refptr = 0 ; break ;
786: /* Can't do seek_end */
787: }
788: if ( refptr && sneed >= minavail && sneed <= maxavail ) {
789: switch( last_op() ) {
790: case input : {
791: setg(eback(),refptr+(sneed-sref),egptr());
792: } break ;
793: case output : {
794: // Seeking to current position. Nothing to
795: // do.
796: } break ;
797: default : {
798: // shouldn't get here. Try to recover somehow
799: sync() ;
800: seekoff(p,d,m);
801: } break ;
802: }
803: return sneed ;
804: }
805: if ( refptr && sneed < sref && sneed+blen()/2 > sref
806: && last_op() == input ) {
807: // looks like we are stepping backward through
808: // a file. Performance may be improved by
809: // backing up a little extra.
810:
811: streampos toofar = sneed-blen()/2 ;
812: if ( toofar < 0 ) toofar = 0 ;
813: sync() ;
814: last_seek=lseek(xfd,toofar,seek_beg) ;
815: overflow();
816: seekoff(p,d,m);
817: }
818: }
819:
820: restore_errno(orig_errno) ;
821: if ( sync()==EOF ) return EOF ;
822: else {
823: last_seek=lseek(xfd,p,d) ;
824: return last_seek ;
825: }
826: }
827:
828: filebuf::filebuf()
829: : xfd(-1), opened(0), mode(0), last_seek(EOF)
830: {
831:
832: }
833:
834: filebuf::filebuf(int f)
835: : xfd(f), opened(1), mode(0), last_seek(EOF)
836: {
837:
838: }
839:
840: filebuf::filebuf(int f, char* p, int l)
841: : streambuf(p,l), xfd(f), opened(1), mode(0), last_seek(EOF)
842: {
843:
844: }
845:
846: filebuf::~filebuf() {
847: close() ;
848: }
849:
850: streambuf* filebuf::setbuf(char* p , int len)
851: {
852: if ( is_open() && base() ) return 0 ;
853: // Note the special case of allowing buffering to be turned
854: // on even for an already opened filebuf.
855: setb(0,0) ;
856: return streambuf::setbuf(p,len) ;
857: }
858: 0707070044044145301004440042240042240000011662000443034061200000600000006470flt.c /*ident "@(#)ctrans:lib/stream/flt.c 1.1.4.1" */
859: /**************************************************************************
860: Copyright (c) 1984 AT&T
861: All Rights Reserved
862:
863: THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T
864:
865: The copyright notice above does not evidence any
866: actual or intended publication of such source code.
867:
868: flt.c:
869:
870: *****************************************************************************/
871:
872: #include <iostream.h>
873: #include <ctype.h>
874: #include <stdio.h>
875: #include <libc.h>
876: #include <string.h>
877:
878: #define OSTREAM ostream
879: #define ISTREAM istream
880:
881: // This file contains all the functions having to do with i/o of
882: // floats and doubles. It drags in lots of stuff from stdio, which
883: // is why I made it separate.
884:
885: istream& ISTREAM::operator>>(double& d)
886: /*
887: {+|-} d* {.} d* { e|E {+|-} d+ }
888: except that
889: - a dot must be pre- or succeeded by at least one digit
890: - an exponent must be preceded by at least one digit
891: */
892: {
893: register c = 0;
894: register anydigits = 0 ;
895: char buf[256];
896: register char* p = buf;
897: register streambuf* nbp = bp;
898:
899: if (!ipfx() ) return *this ;
900:
901: /* get the sign */
902: switch (c = nbp->sgetc()) {
903: case EOF:
904: setstate(eofbit|failbit) ;
905: return *this;
906: case '-':
907: case '+':
908: *p++ = c;
909: c = bp->snextc();
910: }
911:
912: /* get integral part */
913: while (isdigit(c)) {
914: *p++ = c;
915: c = bp->snextc();
916: anydigits = 1 ;
917: }
918:
919: /* get fraction */
920: if (c == '.') {
921: do {
922: *p++ = c;
923: c = bp->snextc();
924: anydigits = 1 ;
925: } while (isdigit(c));
926: }
927:
928: /* get exponent */
929: if ( anydigits && (c == 'e' || c == 'E')) {
930: *p++ = c;
931: switch (c = nbp->snextc()) {
932: case EOF:
933: setstate(eofbit|failbit) ;
934: return *this;
935: case '-':
936: case '+':
937: *p++ = c;
938: c = bp->snextc();
939: }
940: while (isdigit(c)) {
941: *p++ = c;
942: c = bp->snextc();
943: }
944: }
945:
946: *p = 0;
947: d = atof(buf);
948:
949: if (c == EOF) setstate(eofbit) ;
950: if (!anydigits) setstate(badbit) ;
951: return *this;
952: }
953:
954:
955: istream& ISTREAM::operator>>(float& f)
956: {
957: double d;
958:
959:
960: if (!ipfx() ) return *this ;
961:
962: *this >> d ;
963: if ( good() ) f = d;
964:
965: return *this;
966: }
967:
968: ostream& OSTREAM::operator<<(float f) { return *this << (double)f ; }
969:
970: static const int fltbits =
971: ios::scientific|ios::fixed|ios::uppercase ;
972:
973: ostream& OSTREAM::operator<<(double d)
974: {
975: char buf[32];
976: int w = width(0) ;
977: int p = precision() ;
978: int explicitp = ( p > 0 ) || (flags()&ios::fixed) ;
979: if (!opfx()) return *this;
980: long bits = flags() & fltbits ;
981: char fmt[20] ;
982: strcpy(fmt,"%") ;
983: if ( flags() & ios::showpoint ) {
984: strcat(fmt,"#") ;
985: }
986: if ( flags() & ios::showpos ) {
987: strcat(fmt,"+") ;
988: }
989: if ( explicitp ) {
990: strcat(fmt,".*") ;
991: }
992:
993: long mode = flags()
994: & (ios::scientific|ios::fixed|ios::uppercase);
995:
996: switch(mode) {
997: case ios::scientific : strcat(fmt,"e") ; break ;
998: case ios::scientific|ios::uppercase :
999: strcat(fmt,"E") ; break;
1000: case ios::fixed : strcat(fmt,"f") ; break ;
1001: case ios::fixed|ios::uppercase: strcat(fmt,"F") ; break ;
1002: case ios::uppercase : strcat(fmt,"G") ; break ;
1003: default : strcat(fmt,"g") ; break ;
1004: }
1005:
1006: if ( explicitp ) {
1007: sprintf(buf,fmt,p,d) ;
1008: }
1009: else {
1010: sprintf(buf,fmt,d) ;
1011: }
1012:
1013: int padf = w-strlen(buf) ;
1014: if ( padf < 0 ) padf = 0 ;
1015: if ( padf && !(flags()&ios::left) ) {
1016: while ( padf-- > 0 ) put(fill()) ;
1017: }
1018: *this << buf ;
1019: while ( padf-- > 0 ) put(fill()) ;
1020: osfx() ;
1021: return *this ;
1022: }
1023: 0707070044044146061004440042240042240000011611500443013563700001200000005353fstream.c /*ident "@(#)ctrans:lib/stream/fstream.c 1.1.2.2" */
1024: /**************************************************************************
1025: Copyright (c) 1984 AT&T
1026: All Rights Reserved
1027:
1028: THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T
1029:
1030: The copyright notice above does not evidence any
1031: actual or intended publication of such source code.
1032:
1033: fstream.c:
1034:
1035: *****************************************************************************/
1036:
1037: #include <iostream.h>
1038: #include <fstream.h>
1039:
1040: static const int ios_atend = ios::ate ;
1041: static const int ios_input = ios::in ;
1042: static const int ios_output = ios::out ;
1043: static const int ios_append = ios::app ;
1044: static const int seek_cur = ios::cur ;
1045: static const int seek_end = ios::end ;
1046: static const int seek_beg = ios::beg ;
1047:
1048: fstreambase::fstreambase() { init(&buf) ; }
1049:
1050: fstreambase::fstreambase(const char* name, int mode, int prot)
1051: {
1052: init(&buf) ;
1053: open(name,mode,prot) ;
1054: }
1055:
1056: fstreambase::fstreambase(int fd)
1057: : buf(fd)
1058: {
1059: init(&buf) ;
1060: }
1061:
1062: fstreambase::fstreambase(int fd, char* p, int l)
1063: : buf(fd,p,l)
1064: {
1065: init(&buf) ;
1066: }
1067:
1068: static inline void fstreambase::verify(int ok)
1069: {
1070: if ( ok ) clear(0) ;
1071: else setstate(ios::failbit) ;
1072: }
1073:
1074: void fstreambase::setbuf(char* p, int len)
1075: {
1076: verify(buf.setbuf(p,len) != 0 ) ;
1077: }
1078:
1079: void fstreambase::open(const char* name, int mode, int prot)
1080: {
1081: verify(buf.open(name,mode,prot) != 0 ) ;
1082: }
1083:
1084: void fstreambase::attach(int fd )
1085: {
1086: verify(buf.attach(fd) != 0 ) ;
1087: }
1088:
1089: void fstreambase::close()
1090: {
1091: verify(buf.close() != (filebuf*)0 ) ;
1092: }
1093:
1094: fstreambase::~fstreambase() { }
1095:
1096: ifstream::ifstream() { }
1097: ifstream::ifstream(const char* name, int mode, int prot)
1098: : fstreambase(name,mode|ios_input,prot) { }
1099: ifstream::ifstream(int fd) : fstreambase(fd) { }
1100: ifstream::ifstream(int fd, char* p, int l) : fstreambase(fd,p,l) { }
1101: ifstream::~ifstream() { }
1102:
1103: void ifstream::open(const char* name, int mode, int prot)
1104: {
1105: verify(rdbuf()->open(name,mode|ios_input,prot) != (filebuf*)0 ) ;
1106: }
1107:
1108: ofstream::ofstream() { }
1109: ofstream::ofstream(const char* name, int mode, int prot)
1110: : fstreambase(name,mode|ios_output,prot) { }
1111: ofstream::ofstream(int fd) : fstreambase(fd) { }
1112: ofstream::ofstream(int fd, char* p, int l) : fstreambase(fd,p,l) { }
1113: ofstream::~ofstream() { }
1114: void ofstream::open(const char* name, int mode, int prot)
1115: {
1116: verify(rdbuf()->open(name,mode|ios_output,prot) != (filebuf*)0 ) ;
1117: }
1118:
1119: fstream::fstream() { }
1120: fstream::fstream(const char* name, int mode, int prot)
1121: : fstreambase(name,mode,prot) { }
1122: fstream::fstream(int fd) : fstreambase(fd) { }
1123: fstream::fstream(int fd, char* p, int l) : fstreambase(fd,p,l) { }
1124: fstream::~fstream() { }void fstream::open(const char* name, int mode, int prot)
1125: {
1126: verify(rdbuf()->open(name,mode,prot) != (filebuf*)0 ) ;
1127: }
1128: 0707070044044146021004440042240042240000011560430443013461300001200000005573fstream.h /*ident "@(#)ctrans:incl/fstream.h 1.1.1.2" */
1129: /**************************************************************************
1130: Copyright (c) 1984 AT&T
1131: All Rights Reserved
1132:
1133: THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T
1134:
1135: The copyright notice above does not evidence any
1136: actual or intended publication of such source code.
1137:
1138: *****************************************************************************/
1139: #ifndef FSTREAMH
1140: #define FSTREAMH
1141:
1142: #include <iostream.h>
1143:
1144: class filebuf : public streambuf { /* a stream buffer for files */
1145: public:
1146: static const int openprot ; /* default protection for open */
1147: public:
1148: filebuf() ;
1149: filebuf(int fd);
1150: filebuf(int fd, char* p, int l) ;
1151:
1152: int is_open() { return opened ; }
1153: int fd() { return xfd ; }
1154: filebuf* open(const char *name, int om, int prot=openprot);
1155: filebuf* attach(int fd) ;
1156: filebuf* close() ;
1157: ~filebuf() ;
1158: public: /* virtuals */
1159: virtual int overflow(int=EOF);
1160: virtual int underflow();
1161: virtual int sync() ;
1162: virtual streampos
1163: seekoff(streamoff,seek_dir,int) ;
1164: virtual streambuf*
1165: setbuf(char* p, int len) ;
1166: protected:
1167: int xfd;
1168: int mode ;
1169: char opened;
1170: streampos last_seek ;
1171: char* in_start;
1172: int last_op();
1173: char lahead[2] ;
1174: };
1175:
1176: class fstreambase : virtual public ios {
1177: public:
1178: fstreambase() ;
1179:
1180: fstreambase(const char* name,
1181: int mode,
1182: int prot=filebuf::openprot) ;
1183: fstreambase(int fd) ;
1184: fstreambase(int fd, char* p, int l) ;
1185: ~fstreambase() ;
1186: void open(const char* name, int mode,
1187: int prot=filebuf::openprot) ;
1188: void attach(int fd);
1189: void close() ;
1190: void setbuf(char* p, int l) ;
1191: filebuf* rdbuf() { return &buf ; }
1192: private:
1193: filebuf buf ;
1194: protected:
1195: void verify(int) ;
1196: } ;
1197:
1198: class ifstream : public fstreambase, public istream {
1199: public:
1200: ifstream() ;
1201: ifstream(const char* name,
1202: int mode=ios::in,
1203: int prot=filebuf::openprot) ;
1204: ifstream(int fd) ;
1205: ifstream(int fd, char* p, int l) ;
1206: ~ifstream() ;
1207:
1208: filebuf* rdbuf() { return fstreambase::rdbuf(); }
1209: void open(const char* name, int mode=ios::in,
1210: int prot=filebuf::openprot) ;
1211: } ;
1212:
1213: class ofstream : public fstreambase, public ostream {
1214: public:
1215: ofstream() ;
1216: ofstream(const char* name,
1217: int mode=ios::out,
1218: int prot=filebuf::openprot) ;
1219: ofstream(int fd) ;
1220: ofstream(int fd, char* p, int l) ;
1221: ~ofstream() ;
1222:
1223: filebuf* rdbuf() { return fstreambase::rdbuf(); }
1224: void open(const char* name, int mode=ios::out,
1225: int prot=filebuf::openprot) ;
1226: } ;
1227:
1228: class fstream : public fstreambase, public iostream {
1229: public:
1230: fstream() ;
1231:
1232: fstream(const char* name,
1233: int mode,
1234: int prot=filebuf::openprot) ;
1235: fstream(int fd) ;
1236: fstream(int fd, char* p, int l) ;
1237: ~fstream() ;
1238: filebuf* rdbuf() { return fstreambase::rdbuf(); }
1239: void open(const char* name, int mode,
1240: int prot=filebuf::openprot) ;
1241: } ;
1242:
1243: #endif
1244: 0707070044044142541004440042240042240000011572060437432273600000500000003350in.c /*ident "@(#)ctrans:lib/stream/in.c 1.1.1.1" */
1245: /**************************************************************************
1246: Copyright (c) 1984 AT&T
1247: All Rights Reserved
1248:
1249: THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T
1250:
1251: The copyright notice above does not evidence any
1252: actual or intended publication of such source code.
1253:
1254: in.c:
1255:
1256: *****************************************************************************/
1257:
1258: #include <ctype.h>
1259: #include <iostream.h>
1260:
1261: #define ISTREAM istream
1262:
1263: void ISTREAM::eatwhite ()
1264: {
1265: register streambuf *nbp = bp;
1266: register int c = nbp->sgetc();
1267: while (isspace(c)) c = nbp->snextc();
1268: if (c == EOF) setstate(eofbit);
1269: }
1270:
1271: void ISTREAM::xget(char* c)
1272: {
1273: register streambuf* sbp = bp ;
1274: if ( !ipfx(1) ) return ;
1275: x_gcount = 0 ;
1276: register int newc = sbp->sbumpc() ;
1277: if ( newc == EOF ) {
1278: setstate(failbit|eofbit) ;
1279: return ;
1280: }
1281: x_gcount = 1 ;
1282: *c = newc ;
1283: }
1284:
1285: istream& ISTREAM::operator>>(register char* s)
1286: {
1287: /* get string */
1288:
1289: register int w = width(0) ;
1290: if ( flags()&skipws ) {
1291: // We don't know a maximum number of required
1292: // characters
1293: if ( !ipfx(0) ) return *this ;
1294: }
1295: else if ( !ipfx(w) ) {
1296: return *this ;
1297: }
1298:
1299: register streambuf *nbp = bp;
1300: register int c = nbp->sgetc();
1301:
1302: if (c == EOF) setstate(failbit|eofbit) ;
1303:
1304: if ( w > 0 ) {
1305: while (!isspace(c) && c != EOF && --w > 0 ) {
1306: *s++ = c;
1307: c = nbp->snextc();
1308: }
1309: } else {
1310: while (!isspace(c) && c != EOF ) {
1311: *s++ = c;
1312: c = nbp->snextc();
1313: }
1314: }
1315:
1316: *s = '\0';
1317:
1318: if (c == EOF) setstate(eofbit) ;
1319:
1320: return *this;
1321: }
1322:
1323: istream& ISTREAM::operator>>(unsigned char* s)
1324: {
1325: return *this >> (char*)s ;
1326: }
1327:
1328: istream& ISTREAM::putback(register char c)
1329: {
1330: if ( !good() ) return *this ;
1331: if ( bp->sputbackc(c) == EOF ) setstate(badbit) ;
1332: return *this;
1333: }
1334: 0707070044044142711004440042240042240000011574300437215614100001000000010725intin.c /*ident "@(#)ctrans:lib/stream/intin.c 1.1.1.1" */
1335: /**************************************************************************
1336: Copyright (c) 1984 AT&T
1337: All Rights Reserved
1338:
1339: THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T
1340:
1341: The copyright notice above does not evidence any
1342: actual or intended publication of such source code.
1343:
1344: intin.c: Input conversions of numbers
1345:
1346: *****************************************************************************/
1347:
1348:
1349: #include <ctype.h>
1350: #include <iostream.h>
1351:
1352: /****************
1353: *
1354: * This file contains the extraction operations for integer input.
1355: * It suffers from several flaws that ought to be fixed.
1356: *
1357: * All other versions depend on the extractor for longs to
1358: * do the real work. This is OK when int==long but on a machine
1359: * where int!=long there will be a large performance penalty.
1360: *
1361: * Overflow detection is limited to cases where the long is
1362: * shortened and changes its value. This misses a lot of cases.
1363: *
1364: ***************/
1365:
1366:
1367: #define ISTREAM istream
1368:
1369: static const int a10 = 'a'-10;
1370: static const int A10 = 'A'-10;
1371:
1372: istream& ISTREAM::operator>>(long& i)
1373: {
1374: // This code ignores overflows. This ought to be fixed
1375: // in some future version.
1376:
1377: if ( !ipfx() ) return *this ;
1378:
1379: register int c;
1380: register int base ;
1381:
1382: switch ( flags()&(ios::dec|ios::hex|ios::oct) ) {
1383: case ios::hex : base = 16 ; break ;
1384: case ios::oct : base = 8 ; break ;
1385: case ios::dec : base = 10 ; break ;
1386: default : base = 0 ; break ;
1387: }
1388:
1389: register streambuf *nbp = bp; // put bp in a reg for efficiency
1390: register int x = 0 ; // how many chars are processed
1391: register int neg = 0; // set to '-' for negative number
1392:
1393: switch (c = nbp->sgetc()) {
1394: case '-':
1395: neg = 1 ;
1396: c = nbp->snextc(); ++x ;
1397: break;
1398: case '+':
1399: c = nbp->snextc(); ++x ;
1400: break;
1401: case EOF:
1402: setstate(failbit|eofbit) ;
1403: break ;
1404: }
1405:
1406: if ( base==0 && c=='0' ) {
1407: c = nbp->snextc() ; ++x ;
1408:
1409: if ( c=='x' || c=='X' ) {
1410: base = 16 ;
1411: c = nbp->snextc() ; ++x ;
1412: }
1413: else {
1414: base = 8 ;
1415: }
1416: } else if ( base==0 ) base = 10 ;
1417:
1418: // for efficiency we have similar loops
1419: // Note that when we reach this point c has already been set to
1420: // the first char of the string to be converted.
1421:
1422: if ( base==10 ) {
1423: register long ii = 0;
1424: for( ; isdigit(c) ; c=nbp->snextc(),++x ) {
1425:
1426: /* accumulate as negative to avoid problems
1427: * with biggest negative integer on
1428: * 2's complement machines
1429: */
1430: ii = ii*10-(c-'0');
1431: }
1432: i = neg ? ii : -ii;
1433: } else if ( base < 10 ) {
1434: register unsigned long ii = 0;
1435: for( ; isdigit(c) ; c=nbp->snextc(),++x ) {
1436: /* accumulate as unsigned */
1437: register int diff = c-'0' ;
1438: if ( diff >= base ) break ;
1439: ii = ii*base+diff ;
1440: }
1441: i = neg ? -(long)ii : (long)ii;
1442: } else if ( base>10 ) { /* hex like base */
1443: register unsigned long ii = 0;
1444: /* accumulate as unsigned */
1445: for( ; isxdigit(c) ; c=nbp->snextc(),++x ) {
1446: register int diff ;
1447: if ( isdigit(c) ) diff = (c-'0');
1448: else if ( isupper(c) ) diff = (c-A10);
1449: else diff = (c-a10);
1450: if ( diff >= base ) break ;
1451: ii = ii*base+diff ;
1452: }
1453: i = neg ? -(long)ii : (long)ii;
1454: }
1455:
1456:
1457: if (x == 0 ) setstate(failbit) ;
1458: // Correct treatment of this case
1459: // (i.e. no correct digits)
1460: // is unclear. Making it an error
1461: // avoids certain infinite loops.
1462:
1463: return *this;
1464: }
1465:
1466: istream& ISTREAM::operator>>(int& i)
1467: {
1468: long l;
1469:
1470: if ( !ipfx() ) return *this ;
1471:
1472: *this>>l ;
1473: if ( good() ) {
1474: i = (int)l ;
1475: if ( i != l ) {
1476: // overflow
1477: setstate(failbit) ;
1478: }
1479: }
1480: return *this;
1481: }
1482:
1483: istream& ISTREAM::operator>>(short& i)
1484: {
1485: long l;
1486:
1487: if (!ipfx() ) return *this ;
1488:
1489: *this>>l ;
1490: if ( good() ) {
1491: i = (short)l ;
1492: if ( i != l ) {
1493: // overflow
1494: setstate(failbit) ;
1495: }
1496: }
1497:
1498: return *this;
1499: }
1500:
1501:
1502: // The following routines deal with unsigned by reading a long and
1503: // copying. This is certainly safe for "shorts", but is
1504: // slightly problematic for ints and longs. It works on "common"
1505: // machines.
1506:
1507:
1508: istream& ISTREAM::operator>>(unsigned short& u)
1509: {
1510: long l ;
1511: *this >> l ;
1512: if ( good() ) {
1513: u = (unsigned short)l ;
1514: if ( u != l ) {
1515: // overflow
1516: setstate(failbit) ;
1517: }
1518: }
1519: return *this ;
1520: }
1521:
1522: istream& ISTREAM::operator>>(unsigned int& u)
1523: {
1524: long l ;
1525: *this >> l ;
1526: if ( good() ) {
1527: u = (unsigned int)l ;
1528: if ( u != l ) {
1529: // overflow
1530: setstate(failbit) ;
1531: }
1532: }
1533: return *this ;
1534: }
1535:
1536: istream& ISTREAM::operator>>(unsigned long& u)
1537: {
1538: long l ;
1539: *this >> l ;
1540: if ( good() ) {
1541: u = (unsigned long)l ;
1542: if ( u != l ) {
1543: // overflow
1544: setstate(failbit) ;
1545: }
1546: }
1547: return *this ;
1548: }
1549:
1550: 0707070044044142501004440042240042240000011613440437222454700001200000006507iomanip.h /*ident "@(#)ctrans:incl/iomanip.h 1.1.1.2" */
1551: /**************************************************************************
1552: Copyright (c) 1984 AT&T
1553: All Rights Reserved
1554:
1555: THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T
1556:
1557: The copyright notice above does not evidence any
1558: actual or intended publication of such source code.
1559:
1560: *****************************************************************************/
1561:
1562: #ifndef IOMANIPH
1563: #define IOMANIPH
1564:
1565: #include <generic.h>
1566:
1567: #define SMANIP(T)name2(smanip_,T)
1568: #define SAPP(T)name2(sapply_,T)
1569: #define IMANIP(T)name2(imanip_,T)
1570: #define OMANIP(T)name2(omanip_,T)
1571: #define IOMANIP(T)name2(iomanip_,T)
1572: #define IAPP(T)name2(iapply_,T)
1573: #define OAPP(T)name2(oapply_,T)
1574: #define IOAPP(T)name2(ioapply_,T)
1575:
1576: #define IOMANIPdeclare(T) \
1577: class SMANIP(T) { \
1578: ios& (*fct)(ios&,T) ; \
1579: T arg ; \
1580: public: \
1581: SMANIP(T)(ios& (*f)(ios&, T), T a) : \
1582: fct(f), arg(a) { } \
1583: friend istream& operator>>(istream& i, SMANIP(T)& m) { \
1584: ios* s = &i ; \
1585: (*m.fct)(*s,m.arg) ; return i ; } \
1586: friend ostream& operator<<(ostream& o, SMANIP(T)& m) { \
1587: ios* s = &o ; \
1588: (*m.fct)(*s,m.arg) ; return o ; } \
1589: } ; \
1590: class SAPP(T) { \
1591: ios& (*fct)(ios&, T) ; \
1592: public: \
1593: SAPP(T)(ios& (*f)(ios&,T)) : fct(f) { } \
1594: SMANIP(T) operator()(T a) { \
1595: return SMANIP(T)(fct,a) ; } \
1596: } ; \
1597: class IMANIP(T) { \
1598: istream& (*fct)(istream&,T) ; \
1599: T arg ; \
1600: public: \
1601: IMANIP(T)(istream& (*f)(istream&, T), T a ) : \
1602: fct(f), arg(a) { } \
1603: friend istream& operator>>(istream& s, IMANIP(T)& m) { \
1604: return(*m.fct)(s,m.arg) ; \
1605: } \
1606: } ; \
1607: class IAPP(T) { \
1608: istream& (*fct)(istream&, T) ; \
1609: public: \
1610: IAPP(T)(istream& (*f)(istream&,T)) : fct(f) { } \
1611: IMANIP(T) operator()(T a) { \
1612: return IMANIP(T)(fct,a) ; } \
1613: } ; \
1614: class OMANIP(T) { \
1615: ostream& (*fct)(ostream&,T) ; \
1616: T arg ; \
1617: public: \
1618: OMANIP(T)(ostream& (*f)(ostream&, T), T a ) : \
1619: fct(f), arg(a) { } \
1620: friend ostream& operator<<(ostream& s, OMANIP(T)& m) { \
1621: return(*m.fct)(s,m.arg) ; \
1622: } \
1623: } ; \
1624: class OAPP(T) { \
1625: ostream& (*fct)(ostream&, T) ; \
1626: public: \
1627: OAPP(T)(ostream& (*f)(ostream&,T)) : fct(f) { } \
1628: OMANIP(T) operator()(T a) { \
1629: return OMANIP(T)(fct,a) ; } \
1630: } ; \
1631: class IOMANIP(T) { \
1632: iostream& (*fct)(iostream&,T) ; \
1633: T arg ; \
1634: public: \
1635: IOMANIP(T)(iostream& (*f)(iostream&, T), T a ) : \
1636: fct(f), arg(a) { } \
1637: friend istream& operator>>(iostream& s, IOMANIP(T)& m) { \
1638: return(*m.fct)(s,m.arg) ; \
1639: } \
1640: friend ostream& operator<<(iostream& s, IOMANIP(T)& m) { \
1641: return(*m.fct)(s,m.arg) ; \
1642: } \
1643: } ; \
1644: class IOAPP(T) { \
1645: iostream& (*fct)(iostream&, T) ; \
1646: public: \
1647: IOAPP(T)(iostream& (*f)(iostream&,T)) : fct(f) { } \
1648: IOMANIP(T) operator()(T a) { \
1649: return IOMANIP(T)(fct,a) ; } \
1650: } ; \
1651:
1652:
1653:
1654: IOMANIPdeclare(int) ;
1655: IOMANIPdeclare(long) ;
1656:
1657: SMANIP(int) setbase(int b) ; /* 10, 8, 16 or 0 */
1658: SMANIP(long) resetiosflags(long b) ;
1659: SMANIP(long) setiosflags(long b) ;
1660: SMANIP(int) setfill(int f);
1661: SMANIP(int) setprecision(int p);
1662: SMANIP(int) setw(int w) ;
1663:
1664: #endif
1665: 0707070044044142431004440042240042240000011577100443212410100001300000032472iostream.h /*ident "@(#)ctrans:incl/iostream.h 1.1.5.2" */
1666: /**************************************************************************
1667: Copyright (c) 1984 AT&T
1668: All Rights Reserved
1669:
1670: THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T
1671:
1672: The copyright notice above does not evidence any
1673: actual or intended publication of such source code.
1674:
1675: *****************************************************************************/
1676: #ifndef IOSTREAMH
1677: #define IOSTREAMH
1678:
1679: #include <memory.h>
1680: /* Some inlines use memcpy */
1681:
1682: /* If EOF is defined already verify that it is -1. Otherwise
1683: * define it.
1684: */
1685:
1686: #ifdef EOF
1687: # if EOF!=-1
1688: # define EOF (-1)
1689: # endif
1690: #else
1691: # define EOF (-1)
1692: #endif
1693:
1694: /* Don't worry about NULL not being 0 */
1695: #ifndef NULL
1696: # define NULL 0
1697: #endif
1698:
1699: #define zapeof(c) ((c)&0377)
1700: /* extracts char from c. The critical requirement is
1701: * zapeof(EOF)!=EOF
1702: * ((c)&0377) and ((unsigned char)(c)) are alternative definitions
1703: * whose efficiency depends on compiler environment.
1704: */
1705:
1706: typedef long streampos ;
1707: typedef long streamoff ;
1708:
1709: class streambuf ;
1710: class ostream ;
1711:
1712:
1713: class ios {
1714: public: /* Some enums are declared in ios to avoid pollution of
1715: * global namespace
1716: */
1717: enum io_state { goodbit=0, eofbit=1, failbit=2, badbit=4,
1718: hardfail=0200};
1719: /* hard fail can be set and reset internally,
1720: * but not via public function */
1721: enum open_mode { in=1, out=2, ate=4, app=010, trunc=020,
1722: nocreate=040, noreplace=0100} ;
1723: enum seek_dir { beg=0, cur=1, end=2 } ;
1724:
1725: /* flags for controlling format */
1726: enum { skipws=01,
1727: /* skip whitespace on input */
1728: left=02, right=04, internal=010,
1729: /* padding location */
1730: dec=020, oct=040, hex=0100,
1731: /* conversion base */
1732: showbase=0200, showpoint=0400, uppercase=01000,
1733: showpos=02000,
1734: /* modifiers */
1735: scientific=04000, fixed=010000,
1736: /* floating point notation */
1737: unitbuf=020000, stdio=040000
1738: /* stuff to control flushing */
1739: } ;
1740: static const long
1741: basefield ; /* dec|oct|hex */
1742: static const long
1743: adjustfield ; /* left|right|internal */
1744: static const long
1745: floatfield ; /* scientific|fixed */
1746: public:
1747: ios(streambuf*) ;
1748: virtual ~ios() ;
1749:
1750: long flags() { return x_flags ; }
1751: long flags(long f);
1752:
1753: long setf(long setbits, long field);
1754: long setf(long) ;
1755: long unsetf(long) ;
1756:
1757: int width() { return x_width ; }
1758: int width(int w)
1759: {
1760: int i = x_width ; x_width = w ; return i ;
1761: }
1762:
1763: ostream* tie(ostream* s);
1764: ostream* tie() { return x_tie ; }
1765: char fill(char) ;
1766: char fill() { return x_fill ; }
1767: int precision(int) ;
1768: int precision() { return x_precision ; }
1769:
1770: int rdstate() { return state ; }
1771: operator void*()
1772: {
1773: if (state&(failbit|badbit|hardfail)) return 0 ;
1774: else return this ;
1775: }
1776:
1777: int operator!()
1778: { return state&(failbit|badbit|hardfail); }
1779: int eof() { return state&eofbit; }
1780: int fail() { return state&(failbit|badbit|hardfail); }
1781: int bad() { return state&badbit ; }
1782: int good() { return state==0 ; }
1783: void clear(int i =0)
1784: {
1785: state = (i&0377) | (state&hardfail) ;
1786: ispecial = (ispecial&~0377) | state ;
1787: ospecial = (ospecial&~0377) | state ;
1788: }
1789: streambuf* rdbuf() { return bp ;}
1790:
1791: public: /* Members related to user allocated bits and words */
1792: long & iword(int) ;
1793: void* & pword(int) ;
1794: static long bitalloc() ;
1795: static long xalloc() ;
1796:
1797: private: /*** privates for implemting allocated bits and words */
1798: static long nextbit ;
1799: static long nextword ;
1800:
1801: int nuser ;
1802: union ios_user_union*
1803: x_user ;
1804: void uresize(int) ;
1805: public: /* static member functions */
1806: static void sync_with_stdio() ;
1807: protected:
1808: enum { skipping=01000, tied=02000 } ;
1809: /*** bits 0377 are reserved for userbits ***/
1810: streambuf* bp;
1811: void setstate(int b)
1812: { state |= (b&0377) ;
1813: ispecial |= b&~skipping ;
1814: ispecial |= b ;
1815: }
1816: int state;
1817: int ispecial;
1818: int ospecial;
1819: int isfx_special;
1820: int osfx_special;
1821: int delbuf;
1822: ostream* x_tie;
1823: long x_flags;
1824: short x_precision;
1825: char x_fill;
1826: short x_width;
1827:
1828: static void (*stdioflush)() ;
1829:
1830: void init(streambuf*) ;
1831: /* Does the real work of a constructor */
1832: ios() ; /* No initialization at all. Needed by
1833: * multiple inheritance versions */
1834: int assign_private ;
1835: /* needed by with_assgn classes */
1836: private:
1837: ios(ios&) ; /* Declared but not defined */
1838: void operator=(ios&) ; /* Declared but not defined */
1839: public: /* old stream package compatibility */
1840: int skip(int i) ;
1841: };
1842:
1843: class streambuf {
1844: short alloc;
1845: short x_unbuf;
1846: char* x_base;
1847: char* x_pbase;
1848: char* x_pptr;
1849: char* x_epptr;
1850: char* x_gptr;
1851: char* x_egptr;
1852: char* x_eback;
1853: int x_blen;
1854: private:
1855: streambuf(streambuf&); /* Declared but not defined */
1856: void operator=(streambuf&); /* Declared but not defined */
1857: public:
1858: void dbp();
1859: protected:
1860: char* base() { return x_base ; }
1861: char* pbase() { return x_pbase ; }
1862: char* pptr() { return x_pptr ; }
1863: char* epptr() { return x_epptr ; }
1864: char* gptr() { return x_gptr ; }
1865: char* egptr() { return x_egptr ; }
1866: char* eback() { return x_eback ; }
1867: char* ebuf() { return x_base+x_blen ; }
1868: int blen() { return x_blen; }
1869: void setp(char* p, char* ep)
1870: {
1871: x_pbase=x_pptr=p ; x_epptr=ep ;
1872: }
1873: void setg(char* eb,char* g, char* eg)
1874: {
1875: x_eback=eb; x_gptr=g ; x_egptr=eg ;
1876: }
1877: void pbump(int n)
1878: {
1879: x_pptr+=n ;
1880: }
1881:
1882: void gbump(int n)
1883: {
1884: x_gptr+=n ;
1885: }
1886:
1887: void setb(char* b, char* eb, int a = 0 )
1888: {
1889: if ( alloc && x_base ) delete x_base ;
1890: x_base = b ;
1891: x_blen= (eb>b) ? (eb-b) : 0 ;
1892: alloc = a ;
1893: }
1894: int unbuffered() { return x_unbuf; }
1895: void unbuffered(int unb) { x_unbuf = (unb!=0) ; }
1896: int allocate()
1897: {
1898: if ( x_base== 0 && !unbuffered() ) return doallocate() ;
1899: else return 0 ;
1900: }
1901: virtual int doallocate();
1902: public :
1903: virtual int overflow(int c=EOF);
1904: virtual int underflow();
1905: virtual int pbackfail(int c);
1906: virtual int sync();
1907: virtual streampos
1908: seekoff(streamoff,seek_dir,int =ios::in|ios::out);
1909: virtual streampos
1910: seekpos(streampos, int =ios::in|ios::out) ;
1911: virtual int xsputn(const char* s,int n);
1912: virtual int xsgetn(char* s,int n);
1913:
1914: int in_avail()
1915: {
1916: return x_gptr<x_egptr ? x_egptr-x_gptr : 0 ;
1917: }
1918:
1919: int out_waiting()
1920: {
1921: if ( x_pptr ) return x_pptr-x_pbase ;
1922: else return 0 ;
1923: }
1924:
1925: int sgetc()
1926: {
1927: /***WARNING: sgetc does not bump the pointer ***/
1928: return (x_gptr>=x_egptr) ? underflow() : zapeof(*x_gptr);
1929: }
1930: int snextc()
1931: {
1932: return (++x_gptr>=x_egptr)
1933: ? x_snextc()
1934: : zapeof(*x_gptr);
1935: }
1936: int sbumpc()
1937: {
1938: return ( x_gptr>=x_egptr && underflow()==EOF )
1939: ? EOF
1940: : zapeof(*x_gptr++) ;
1941: }
1942: void stossc()
1943: {
1944: if ( x_gptr++ > x_egptr ) underflow() ;
1945: }
1946:
1947: int sputbackc(char c)
1948: {
1949: if (x_gptr > x_eback ) {
1950: if ( *--x_gptr == c ) return zapeof(c) ;
1951: else return zapeof(*x_gptr=c) ;
1952: } else {
1953: return pbackfail(c) ;
1954: }
1955: }
1956:
1957: int sputc(int c)
1958: {
1959: return (x_pptr>=x_epptr) ? overflow(zapeof(c))
1960: : zapeof(*x_pptr++=c);
1961: }
1962: int sputn(const char* s,int n)
1963: {
1964: if ( n <= (x_epptr-x_pptr) ) {
1965: memcpy(x_pptr,s,n) ;
1966: pbump(n);
1967: return n ;
1968: } else {
1969: return xsputn(s,n) ;
1970: }
1971: }
1972: int sgetn(char* s,int n)
1973: {
1974: if ( n <= (x_egptr-x_gptr) ) {
1975: memcpy(s,x_gptr,n) ;
1976: gbump(n);
1977: return n ;
1978: } else {
1979: return xsgetn(s,n) ;
1980: }
1981: }
1982: virtual streambuf*
1983: setbuf(char* p, int len) ;
1984: streambuf* setbuf(unsigned char* p, int len) ;
1985:
1986: streambuf* setbuf(char* p, int len, int count) ;
1987: /* obsolete third argument */
1988: /*** Constructors -- should be protected ***/
1989: streambuf() ;
1990: streambuf(char* p, int l) ;
1991:
1992: streambuf(char* p, int l,int c) ;
1993: /* 3 argument form is obsolete.
1994: * Use strstreambuf.
1995: */
1996: virtual ~streambuf() ;
1997: private:
1998: int x_snextc() ;
1999: };
2000:
2001: class istream : virtual public ios {
2002: public: /* Constructor */
2003: istream(streambuf*) ;
2004: virtual ~istream() ;
2005: public:
2006: int ipfx(int noskipws=0)
2007: { if ( noskipws?(ispecial&~skipping):ispecial) {
2008: return do_ipfx(noskipws) ;
2009: } else return 1 ;
2010: }
2011: void isfx() { }
2012: istream& seekg(streampos p) ;
2013: istream& seekg(streamoff o, seek_dir d) ;
2014: streampos tellg() ;
2015: istream& operator>> (istream& (*f)(istream&))
2016: { return (*f)(*this) ; }
2017: istream& operator>> (ios& (*f)(ios&) ) ;
2018: istream& operator>>(char*);
2019: istream& operator>>(unsigned char*);
2020: istream& operator>>(unsigned char& c)
2021: { if ( ipfx(0) ) {
2022: if ( bp->in_avail() ) {
2023: c = bp->sbumpc() ;
2024: } else xget((char*)&c) ;
2025: }
2026: return *this ;
2027: }
2028: istream& operator>>(char& c)
2029: { if ( ipfx(0) ) {
2030: if ( bp->in_avail() ) {
2031: c = bp->sbumpc() ;
2032: } else xget((char*)&c) ;
2033: }
2034: return *this ;
2035: }
2036: istream& operator>>(short&);
2037: istream& operator>>(int&);
2038: istream& operator>>(long&);
2039: istream& operator>>(unsigned short&);
2040: istream& operator>>(unsigned int&);
2041: istream& operator>>(unsigned long&);
2042: istream& operator>>(float&);
2043: istream& operator>>(double&);
2044: istream& operator>>(streambuf*);
2045: istream& get(char* , int lim, char delim='\n');
2046: istream& get(unsigned char* b,int lim, char delim='\n');
2047: istream& getline(char* b, int lim, char delim='\n');
2048: istream& getline(unsigned char* b, int lim, char delim='\n');
2049: istream& get(streambuf& sb, char delim ='\n');
2050: istream& get(unsigned char& c)
2051: {
2052: if ( ipfx(1) && bp->in_avail()) {
2053: x_gcount = 1 ;
2054: c = bp->sbumpc() ;
2055: } else {
2056: xget((char*)&c) ;
2057: }
2058: return *this ;
2059: }
2060: istream& get(char& c)
2061: {
2062: if ( ipfx(1) && bp->in_avail()) {
2063: x_gcount = 1 ;
2064: c = bp->sbumpc() ;
2065: } else {
2066: xget(&c) ;
2067: }
2068: return *this ;
2069: }
2070: int get()
2071: {
2072: int c ;
2073: if ( !ipfx(1) ) return EOF ;
2074: else {
2075: c = bp->sbumpc() ;
2076: if ( c == EOF ) setstate(eofbit) ;
2077: return c ;
2078: }
2079: }
2080: int peek()
2081: {
2082: if ( ipfx(-1) ) return bp->sgetc() ;
2083: else return EOF ;
2084:
2085: }
2086: istream& ignore(int n=1,int delim=EOF) ;
2087: istream& read(char* s,int n);
2088: istream& read(unsigned char* s,int n)
2089: {
2090: return read((char*)s,n) ;
2091: }
2092: int gcount() ;
2093: istream& putback(char c);
2094: int sync() { return bp->sync() ; }
2095: protected:
2096: int do_ipfx(int noskipws) ;
2097: void eatwhite() ;
2098: istream() ;
2099: private:
2100: int x_gcount ;
2101: void xget(char* c) ;
2102: public: /*** Obsolete constructors, carried over from stream package ***/
2103: istream(streambuf*, int sk, ostream* t=0) ;
2104: /* obsolete, set sk and tie
2105: * via format state variables */
2106: istream(int size ,char*,int sk=1) ;
2107: /* obsolete, use strstream */
2108: istream(int fd,int sk=1, ostream* t=0) ;
2109: /* obsolete use fstream */
2110: };
2111:
2112: class ostream : virtual public ios {
2113: public: /* Constructor */
2114: ostream(streambuf*) ;
2115: virtual ~ostream();
2116: public:
2117: int opfx() /* Output prefix */
2118: { if ( ospecial ) return do_opfx() ;
2119: else return 1 ;
2120: }
2121: void osfx()
2122: { if ( osfx_special ) do_osfx() ; }
2123:
2124: ostream& flush() ;
2125: ostream& seekp(streampos p) ;
2126: ostream& seekp(streamoff o, seek_dir d) ;
2127: streampos tellp() ;
2128: ostream& put(char c)
2129: {
2130: if ( opfx() ) {
2131: if ( bp->sputc(c) == EOF ) {
2132: setstate(eofbit|failbit) ;
2133: }
2134: osfx() ;
2135: }
2136: return *this ;
2137: }
2138: ostream& operator<<(char c) { put(c) ; osfx() ; return *this ; }
2139:
2140: ostream& operator<<(unsigned char c)
2141: { put(c) ; osfx() ; return *this ; }
2142:
2143: ostream& operator<<(const char*);
2144: ostream& operator<<(int a);
2145: ostream& operator<<(long);
2146: ostream& operator<<(double);
2147: ostream& operator<<(float);
2148: ostream& operator<<(unsigned int a);
2149: ostream& operator<<(unsigned long);
2150: ostream& operator<<(void*);
2151: ostream& operator<<(streambuf*);
2152: ostream& operator<<(short i) { return *this << (int)i ; }
2153: ostream& operator<<(unsigned short i)
2154: { return *this << (int)i ; }
2155:
2156: ostream& operator<< (ostream& (*f)(ostream&))
2157: { return (*f)(*this) ; }
2158: ostream& operator<< (ios& (*f)(ios&) ) ;
2159:
2160: ostream& write(const char* s,int n)
2161: {
2162: if ( !state ) {
2163: if ( bp->sputn(s,n) != n ) setstate(eofbit|failbit);
2164: }
2165: return *this ;
2166: }
2167: ostream& write(const unsigned char* s, int n)
2168: {
2169: return write((const char*)s,n);
2170: }
2171: protected: /* More ostream members */
2172: int do_opfx() ;
2173: void do_osfx() ;
2174: ostream() ;
2175:
2176: public: /*** Obsolete constructors, carried over from stream package ***/
2177: ostream(int fd) ;
2178: /* obsolete use fstream */
2179: ostream(int size ,char*) ;
2180: /* obsolete, use strstream */
2181: } ;
2182:
2183: class iostream : public istream, public ostream {
2184: public:
2185: iostream(streambuf*) ;
2186: virtual ~iostream() ;
2187: protected:
2188: iostream() ;
2189: } ;
2190:
2191: class istream_withassign : public istream {
2192: public:
2193: istream_withassign() ;
2194: virtual ~istream_withassign() ;
2195: istream_withassign& operator=(istream&) ;
2196: istream_withassign& operator=(streambuf*) ;
2197: } ;
2198:
2199: class ostream_withassign : public ostream {
2200: public:
2201: ostream_withassign() ;
2202: virtual ~ostream_withassign() ;
2203: ostream_withassign& operator=(ostream&) ;
2204: ostream_withassign& operator=(streambuf*) ;
2205: } ;
2206:
2207: class iostream_withassign : public iostream {
2208: public:
2209: iostream_withassign() ;
2210: virtual ~iostream_withassign() ;
2211: iostream_withassign& operator=(ios&) ;
2212: iostream_withassign& operator=(streambuf*) ;
2213: } ;
2214:
2215: extern istream_withassign cin ;
2216: extern ostream_withassign cout ;
2217: extern ostream_withassign cerr ;
2218: extern ostream_withassign clog ;
2219:
2220: ios& dec(ios&) ;
2221: ostream& endl(ostream& i) ;
2222: ostream& ends(ostream& i) ;
2223: ostream& flush(ostream&) ;
2224: ios& hex(ios&) ;
2225: ios& oct(ios&) ;
2226: istream& ws(istream&) ;
2227:
2228: static class Iostream_init {
2229: static int stdstatus ; /* see cstreams.c */
2230: static int initcount ;
2231: friend ios ;
2232: public:
2233: Iostream_init() ;
2234: ~Iostream_init() ;
2235: } iostream_init ;
2236:
2237: #endif
2238: 0707070044044142561004440042240042240000011571420442762431100001000000004471manip.c /*ident "@(#)ctrans:lib/stream/manip.c 1.1.3.1" */
2239: /**************************************************************************
2240: Copyright (c) 1984 AT&T
2241: All Rights Reserved
2242:
2243: THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T
2244:
2245: The copyright notice above does not evidence any
2246: actual or intended publication of such source code.
2247:
2248: manip.c:
2249:
2250: *****************************************************************************/
2251:
2252: #include <iostream.h>
2253: #include <iomanip.h>
2254: #include <ctype.h>
2255:
2256: istream& ws(istream& i)
2257: {
2258: if ( !i.ipfx(1) ) return i ;
2259: register streambuf *nbp = i.rdbuf();
2260: register int c = nbp->sgetc();
2261: while (isspace(c)) c = nbp->snextc();
2262: if (c == EOF) i.clear(ios::eofbit) ;
2263: return i ;
2264: }
2265:
2266: ostream& ends(ostream& i)
2267: {
2268: return i.put(0) ;
2269: }
2270:
2271: ostream& endl(ostream& i)
2272: {
2273: i.put('\n') ;
2274: i.flush() ;
2275: return i ;
2276: }
2277:
2278: static const int basebits = ios::dec|ios::oct|ios::hex ;
2279:
2280: static ios& setb(ios& i, int b)
2281: {
2282: switch(b) {
2283: case 10 : i.setf(ios::dec,basebits) ; break ;
2284: case 8 : i.setf(ios::oct,basebits) ; break ;
2285: case 16 : i.setf(ios::hex,basebits) ; break ;
2286: default : i.setf(0,basebits) ; break ;
2287: }
2288: return i ;
2289: }
2290:
2291: SMANIP(int) setbase(int b) { return SMANIP(int)(setb,b) ; }
2292:
2293: static ios& resetiosflags(ios& i,long b) { i.setf(0,b) ; return i ; }
2294: SMANIP(long) resetiosflags(long b) { return SMANIP(long)(resetiosflags,b) ; }
2295:
2296: static ios& setiosflags(ios& i,long b) { i.setf(b) ; return i ; }
2297: SMANIP(long) setiosflags(long b) { return SMANIP(long)(setiosflags,b) ; }
2298:
2299: static ios& setfill(ios& i,int f) { i.fill(f) ; return i ; }
2300: SMANIP(int) setfill(int f) { return SMANIP(int)(setfill,f) ; }
2301:
2302: static ios& setprecision(ios& i,int p) { i.precision(p) ; return i ; }
2303: SMANIP(int) setprecision(int p) { return SMANIP(int)(setprecision,p) ; }
2304:
2305: static ios& setw(ios& i,int w) { i.width(w) ; return i ; }
2306: SMANIP(int) setw(int w) { return SMANIP(int)(setw,w) ; }
2307:
2308: ios& hex(ios& s) { s.setf(ios::hex,basebits ) ; return s ; }
2309: ios& dec(ios& s) { s.setf(ios::dec,basebits ) ; return s ; }
2310: ios& oct(ios& s) { s.setf(ios::oct,basebits ) ; return s ; }
2311:
2312: ostream& flush(ostream& s) { s.flush() ; return s ; }
2313:
2314: ostream& ostream::operator<<( ios& (*f)(ios&) )
2315: {
2316: f(*this) ;
2317: return *this ;
2318: }
2319:
2320: istream& istream::operator>>( ios& (*f)(ios&) )
2321: {
2322: f(*this) ;
2323: return *this ;
2324: }
2325: 0707070044044141271004440042240042240000011557620441667020000001400000013350oldformat.c /*ident "@(#)ctrans:lib/stream/oldformat.c 1.1.4.1" */
2326: /**************************************************************************
2327: Copyright (c) 1984 AT&T
2328: All Rights Reserved
2329:
2330: THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T
2331:
2332: The copyright notice above does not evidence any
2333: actual or intended publication of such source code.
2334:
2335: oldformat.c:
2336: file for obsolete stream stuff that isn't part of the
2337: official iostream package.
2338: *****************************************************************************/
2339:
2340: #include <stream.h>
2341: #include "streamdefs.h"
2342: #include <string.h>
2343: #include <strstream.h>
2344: #include <fstream.h>
2345: #include <libc.h>
2346:
2347: #ifdef VSPRINTF
2348: # include <stdarg.h>
2349: #endif
2350:
2351: static const int cb_size = 1024 ;
2352: static const int fld_size = 256 ;
2353:
2354: /* a circular formating buffer */
2355: static char formbuf[cb_size]; // some slob for form overflow
2356: static char* bfree=formbuf;
2357: static char* max = &formbuf[cb_size-1];
2358:
2359: char* chr(register i, register int w) /* note: chr(0) is "" */
2360: {
2361: register char* buf = bfree;
2362:
2363: if (w<=0 || fld_size<w) w = 1;
2364: w++; /* space for trailing 0 */
2365: if (max < buf+w) buf = formbuf;
2366: bfree = buf+w;
2367: char * res = buf;
2368:
2369: w -= 2; /* pad */
2370: while (w--) *buf++ = ' ';
2371: if (i<0 || 127<i) i = ' ';
2372: *buf++ = i;
2373: *buf = 0;
2374: return res;
2375: }
2376:
2377: char* str(const char* s, register int w)
2378: {
2379: register char* buf = bfree;
2380: int ll = strlen(s);
2381: if (w<=0 || fld_size<w) w = ll;
2382: if (w < ll) ll = w;
2383: w++; /* space for traling 0 */
2384: if (max < buf+w) buf = formbuf;
2385: bfree = buf+w;
2386: char* res = buf;
2387:
2388: w -= (ll+1); /* pad */
2389: while (w--) *buf++ = ' ';
2390: while (*s) *buf++ = *s++;
2391: *buf = 0;
2392: return res;
2393: }
2394:
2395: char* form(const char* format ...)
2396: {
2397: register char* buf = bfree;
2398: if (max < buf+fld_size) buf = formbuf;
2399:
2400: # ifdef VSPRINTF
2401: va_list args ;
2402: va_start(args,format) ;
2403: VSPRINTF(buf,format,args) ;
2404: va_end(args) ;
2405: # else
2406: // not very portable
2407: register* ap = (int*)((char*)&format+sizeof(char*));
2408: sprintf(buf,format,ap[0],ap[1],ap[2],ap[3],ap[4],ap[5],ap[6],ap[7],ap[8],ap[9]);
2409: # endif
2410:
2411: register ll = strlen(buf); // not all sprintf's return length
2412: if (0<ll && ll<cb_size) // length
2413: ;
2414: else if (buf<(char*)ll && (char*)ll<buf+cb_size)// pointer to trailing 0
2415: ll = (char*)ll - buf;
2416: else
2417: ll = strlen(buf);
2418:
2419: // If we have scribbled beyond the end of the buffer then
2420: // who knows what data we've destroyed. Better to abort here
2421: // here there is some chance that somebody can associate
2422: // the location with the error than to continue and die
2423: // a mysterious death later.
2424: if (fld_size < ll) abort();
2425:
2426: bfree = buf+ll+1;
2427: return buf;
2428: }
2429:
2430: const char a10 = 'a'-10;
2431:
2432: char* hex(long ii, register w)
2433: {
2434: int m = sizeof(long)*2; // maximum hex digits for a long
2435: if (w<0 || fld_size<w) w = 0;
2436: int sz = (w?w:m)+1;
2437: register char* buf = bfree;
2438: if (max < buf+sz) buf = formbuf;
2439: register char* p = buf+sz;
2440: bfree = p+1;
2441: *p-- = 0; // trailing 0
2442: register unsigned long i = ii;
2443:
2444: if (w) {
2445: do {
2446: register h = (int)(i&0xf);
2447: *p-- = (h < 10) ? h+'0' : h+a10;
2448: } while (--w && (i>>=4));
2449: while (0<w--) *p-- = ' ';
2450: }
2451: else {
2452: do {
2453: register h = (int)(i&0xf);
2454: *p-- = (h < 10) ? h+'0' : h+a10;
2455: } while (i>>=4);
2456: }
2457: return p+1;
2458: }
2459:
2460: char* oct(long ii, int w)
2461: {
2462: int m = sizeof(long)*3; // maximum oct digits for a long
2463: if (w<0 || fld_size<w) w = 0;
2464: int sz = (w?w:m)+1;
2465: register char* buf = bfree;
2466: if (max < buf+sz) buf = formbuf;
2467: register char* p = buf+sz;
2468: bfree = p+1;
2469: *p-- = 0; // trailing 0
2470: register unsigned long i = ii;
2471:
2472: if (w) {
2473: do {
2474: register h = (int)(i&07);
2475: *p-- = h + '0';
2476: } while (--w && (i>>=3));
2477: while (0<w--) *p-- = ' ';
2478: }
2479: else {
2480: do {
2481: register h = (int)(i&07);
2482: *p-- = h+'0';
2483: } while (i>>=3);
2484: }
2485:
2486: return p+1;
2487: }
2488:
2489: char* dec(long i, int w)
2490: {
2491: int sign = 0;
2492: if (i < 0) {
2493: sign = 1;
2494: i = -i;
2495: }
2496: int m = sizeof(long)*3; /* maximum dec digits for a long */
2497: if (w<0 || fld_size<w) w = 0;
2498: int sz = (w?w:m)+1;
2499: register char* buf = bfree;
2500: if (max < buf+sz) buf = formbuf;
2501: register char* p = buf+sz;
2502: bfree = p+1;
2503: *p-- = 0; /* trailing 0 */
2504:
2505: if (w) {
2506: do {
2507: register h = (int)(i%10);
2508: *p-- = h + '0';
2509: } while (--w && (i/=10));
2510: if (sign && 0<w) {
2511: w--;
2512: *p-- = '-';
2513: }
2514: while (0<w--) *p-- = ' ';
2515: }
2516: else {
2517: do {
2518: register h = (int)(i%10);
2519: *p-- = h + '0';
2520: } while (i/=10);
2521: if (sign) *p-- = '-';
2522: }
2523:
2524: return p+1;
2525: }
2526:
2527: istream& WS(istream& i) { return i >> ws ; }
2528:
2529: void eatwhite(istream& i) { i >> ws ; }
2530:
2531: istream::istream(streambuf* b, int sk, ostream* t)
2532: {
2533: init(b) ;
2534: skip(sk) ;
2535: tie(t) ;
2536: }
2537:
2538: istream::istream(int len, char* b, int sk)
2539: {
2540: init( new streambuf(b,len,-len) ) ;
2541: delbuf = 1 ;
2542: skip(sk) ;
2543: }
2544:
2545: istream::istream(int fd, int sk, ostream* t)
2546: {
2547: init( new filebuf(fd) ) ;
2548: delbuf = 1 ;
2549: skip(sk) ;
2550: tie(t) ;
2551: }
2552:
2553: ostream::ostream(int fd)
2554: {
2555: init( new filebuf(fd) ) ;
2556: delbuf = 1 ;
2557: }
2558:
2559: ostream::ostream(int len, char* b)
2560: {
2561: init( new streambuf(b,len,0) ) ;
2562: delbuf = 1 ;
2563: }
2564:
2565: streambuf::streambuf(char* p, int l, int c ) :
2566: x_unbuf(0), alloc(0)
2567: {
2568: setb(0,0,0);
2569: setbuf(p,l,c) ;
2570: }
2571:
2572: streambuf* streambuf::setbuf(char* p, int len, int count)
2573: {
2574: // Three argument setbuf for compatibility with old
2575: // stream package.
2576: if ( x_base ) return 0 ;
2577: if ( len <= 0 || p == 0 ) {
2578: // make it unbuffered
2579: setb(0,0,0) ;
2580: setg(0,0,0) ;
2581: setp(0,0);
2582: unbuffered(1) ;
2583: } else if ( count >= 0 ) {
2584: setb(p,p+len,0) ;
2585: setg(p,p,p+count) ;
2586: setp(p+count,p+len) ;
2587: unbuffered(0) ;
2588: } else { // count < 0
2589: // Special case,
2590: // Used by iostream::iostream(char*,int)
2591: // For backwards compatibility with old streams
2592: setb(p,p+len,0) ;
2593: setg(p,p,p-count) ;
2594: setp(p,p+len) ;
2595: unbuffered(0) ;
2596: }
2597: return this;
2598: }
2599:
2600: int ios::skip(int sk)
2601: {
2602: long f ;
2603: if ( sk ) f = setf(skipws,skipws) ;
2604: else f = setf(0,skipws) ;
2605:
2606: return (f&skipws) != 0 ;
2607: }
2608: 0707070044044142441006440042240042240000011611200443034047300000600000020040out.c /*ident "@(#)ctrans:lib/stream/out.c 1.1.2.1" */
2609: /**************************************************************************
2610: Copyright (c) 1984 AT&T
2611: All Rights Reserved
2612:
2613: THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T
2614:
2615: The copyright notice above does not evidence any
2616: actual or intended publication of such source code.
2617:
2618: out.c:
2619:
2620: *****************************************************************************/
2621:
2622: #include <iostream.h>
2623: #include "streamdefs.h"
2624: #include <string.h>
2625:
2626: #define OSTREAM ostream
2627:
2628: const int basebits = ios::dec|ios::oct|ios::hex ;
2629:
2630: // At the cost of 100 bytes of table we can measurably speed
2631: // up conversion (at least on a VAX)
2632:
2633: static char digit1[] = {
2634: '0','1','2','3','4','5','6','7','8','9',
2635: '0','1','2','3','4','5','6','7','8','9',
2636: '0','1','2','3','4','5','6','7','8','9',
2637: '0','1','2','3','4','5','6','7','8','9',
2638: '0','1','2','3','4','5','6','7','8','9',
2639: '0','1','2','3','4','5','6','7','8','9',
2640: '0','1','2','3','4','5','6','7','8','9',
2641: '0','1','2','3','4','5','6','7','8','9',
2642: '0','1','2','3','4','5','6','7','8','9',
2643: '0','1','2','3','4','5','6','7','8','9',
2644: } ;
2645:
2646: static char digit2[] = {
2647: '0','0','0','0','0','0','0','0','0','0',
2648: '1','1','1','1','1','1','1','1','1','1',
2649: '2','2','2','2','2','2','2','2','2','2',
2650: '3','3','3','3','3','3','3','3','3','3',
2651: '4','4','4','4','4','4','4','4','4','4',
2652: '5','5','5','5','5','5','5','5','5','5',
2653: '6','6','6','6','6','6','6','6','6','6',
2654: '7','7','7','7','7','7','7','7','7','7',
2655: '8','8','8','8','8','8','8','8','8','8',
2656: '9','9','9','9','9','9','9','9','9','9',
2657: } ;
2658:
2659: static char* conv10(long i, char* bufend)
2660: /* p points to right end of a buffer. Function function returns
2661: * pointer to left end of converted number. Number is not 0 terminated.
2662: *
2663: * Special care with negatives to avoid problems with
2664: * biggest negative number on 2's complement machines
2665: */
2666: {
2667: register long j = i ;
2668: register char* p = bufend ;
2669:
2670: /* Above entered low order digit or 0 if i is zero */
2671:
2672: if ( j >= 0 ) {
2673: register int diff ;
2674: do {
2675: long register by100 = j/100 ;
2676: diff = (int)(j-100*by100) ;
2677: *p-- = digit1[diff] ;
2678: *p-- = digit2[diff] ;
2679: j = by100;
2680: } while ( j > 0 ) ;
2681: if ( diff<10 ) ++p ; //compensate for extra 0
2682: } else { // j < 0
2683: register int diff ;
2684: do {
2685: long register by100 = j/100 ;
2686: diff = (int)(100*by100-j) ;
2687: *p-- = digit1[diff] ;
2688: *p-- = digit2[diff] ;
2689: j = by100;
2690: } while ( j < 0 ) ;
2691: if ( diff<10 ) ++p ; //compensate for extra 0
2692: }
2693: return p+1 ;
2694:
2695: }
2696:
2697: static char* uconv10(unsigned long i, char* bufend)
2698: /* Same interface as conv10 except unsigned so we don't have
2699: * to worry about negatives */
2700: {
2701: register unsigned long j = i ;
2702: register char* p = bufend ;
2703: register int diff ;
2704:
2705: do {
2706: long register by100 = j/100 ;
2707: diff = (int)(j-100*by100) ;
2708: *p-- = digit1[diff] ;
2709: *p-- = digit2[diff] ;
2710: j = by100;
2711: } while ( j > 0 ) ;
2712: if ( diff<10 ) ++p ; //compensate for extra 0
2713:
2714: return p+1 ;
2715:
2716: }
2717:
2718:
2719: static char* conv8(register unsigned long i, register char* p)
2720: {
2721: do {
2722: *p-- = (char)('0' + i%8) ;
2723: } while ( (i >>= 3) > 0 ) ;
2724: return p+1 ;
2725: }
2726:
2727: static char* conv16(register unsigned long i, register char* p)
2728: {
2729: do {
2730: register dig = (int)(i%16) ;
2731: if ( dig < 10 ) *p-- = (char)('0' + i%16) ;
2732: else *p-- = (char)('a'-10 + dig) ;
2733:
2734: } while ( (i >>= 4) > 0 ) ;
2735: return p+1 ;
2736: }
2737:
2738:
2739: static char* conv16u(register unsigned long i, register char* p)
2740: {
2741: do {
2742: register dig = (int)(i%16) ;
2743: if ( dig < 10 ) *p-- = (char)('0' + i%16) ;
2744: else *p-- = (char)('A'-10 + dig) ;
2745:
2746: } while ( (i >>= 4) > 0 ) ;
2747: return p+1 ;
2748: }
2749: ostream& OSTREAM::operator<<(const char* s)
2750: {
2751: // I play some games so that if BREAKEVEN is <= 0 all
2752: // tests get set the right way at compile time
2753:
2754: # if BREAKEVEN > 0
2755: static int avglen = BREAKEVEN ;
2756: // running average of the lengths
2757: // of strings ;
2758: # else
2759: static const int avglen = BREAKEVEN ;
2760: // fixed constant so all tests
2761: // are fixed at compile time
2762: # endif
2763:
2764: register int fwidth = width(0) ;
2765:
2766: if (!opfx() ) return *this ;
2767: if ( s==0 ) return *this;
2768: register streambuf* nbp = bp ;
2769: register const char* p ;
2770: register int len ;
2771: register int pad ;
2772:
2773: register int leftjust = ( (flags()&left) != 0 ) ;
2774: if ( BREAKEVEN<0
2775: || BREAKEVEN>0 && avglen<=BREAKEVEN &&
2776: (fwidth==0 || leftjust)){
2777: p = s ;
2778: while ( *p ) {
2779: if ( nbp->sputc(*p++) == EOF ) {
2780: setstate(badbit) ;
2781: break ;
2782: }
2783: }
2784: len = p-s ;
2785: pad = fwidth-len ;
2786: } else {
2787: len = strlen(s) ;
2788: pad = fwidth-len ;
2789: if ( pad>0 && !leftjust ) {
2790: while ( pad-- > 0 ) {
2791: if ( nbp->sputc(fill()) == EOF ) {
2792: setstate(badbit) ;
2793: }
2794: }
2795: }
2796: write(s,len) ;
2797: }
2798:
2799: if ( pad > 0 ) {
2800: while ( pad-- > 0 ) {
2801: if ( nbp->sputc(fill()) == EOF ) setstate(badbit) ;
2802: }
2803: }
2804:
2805: if ( BREAKEVEN > 0 ) { // will be eliminated at compile time
2806: avglen = (3*avglen + len) >> 2;
2807: }
2808: osfx() ;
2809: return *this;
2810: }
2811:
2812: static int dofield(
2813: ostream* ios,
2814: register char* pfx,
2815: int pwidth,
2816: register char* sfx,
2817: int swidth)
2818: {
2819: register streambuf* b = ios->rdbuf() ;
2820: register int w = ios->width(0)-(pwidth+swidth) ;
2821: register int f = (int)ios->flags() ;
2822: register int fchar = ios->fill() ;
2823:
2824: if ( (f&ios::right) || !(f&(ios::left|ios::internal)) ) {
2825: while ( w-- > 0 ) {
2826: if ( b->sputc(fchar) == EOF ) return ios::badbit ;
2827: }
2828: }
2829:
2830: while ( *pfx ) {
2831: if ( b->sputc(*pfx++) == EOF ) return ios::badbit ;
2832: }
2833:
2834: if ( f&ios::internal ) {
2835: while ( w-- > 0 ) {
2836: if ( b->sputc(fchar) == EOF ) return ios::badbit ;
2837: }
2838: }
2839: while ( *sfx ) {
2840: if ( b->sputc(*sfx++) == EOF ) return ios::badbit ;
2841: }
2842:
2843: while ( w-- > 0 ) {
2844: if ( b->sputc(fchar) == EOF ) return ios::badbit ;
2845: }
2846:
2847: return 0 ;
2848: }
2849:
2850: static const int dbufsize = 32 ;
2851:
2852: ostream& OSTREAM::operator<<(long i)
2853: {
2854: if (!opfx()) {
2855: width(0) ;
2856: return *this;
2857: }
2858: char buf[dbufsize];
2859:
2860: register char *p ;
2861: register char* pfx = "" ;
2862: register int pfxsize = 0 ;
2863:
2864: buf[dbufsize-1] = 0 ;
2865: switch( flags()&basebits ) {
2866: case ios::oct :
2867: p = conv8(i,&buf[dbufsize-2]) ;
2868: if ( (flags()&showbase) && i ) {
2869: pfx = "0" ; pfxsize = 1 ;
2870: }
2871: break ;
2872: case ios::hex :
2873: if ( flags()&uppercase ) {
2874: p=conv16u(i,&buf[dbufsize-2]);
2875: if ( flags()&showbase ) {
2876: pfx = "0X" ; pfxsize = 2 ;
2877: }
2878: }
2879: else {
2880: p=conv16(i,&buf[dbufsize-2]);
2881: if ( flags()&showbase ) {
2882: pfx = "0x" ; pfxsize = 2 ;
2883: }
2884: }
2885: break ;
2886: default:
2887: p = conv10(i,&buf[dbufsize-2]) ;
2888: if ( i < 0 ) {
2889: pfx = "-" ; pfxsize = 1 ;
2890: }
2891: else if ( flags()&showpos ) {
2892: pfx = "+" ; pfxsize = 1 ;
2893: }
2894: break ;
2895: }
2896: register int err ;
2897: if ( err = dofield(this,pfx,pfxsize,p,&buf[dbufsize-1]-p) ) {
2898: setstate(err) ;
2899: }
2900: osfx() ;
2901: return *this ;
2902: }
2903:
2904: ostream& OSTREAM::operator<<(unsigned long i)
2905: {
2906: if (!opfx()) {
2907: width(0) ;
2908: return *this;
2909: }
2910: char buf[dbufsize];
2911: register char *p ;
2912: register char* pfx = "" ;
2913: register int pfxsize = 0 ;
2914:
2915:
2916: buf[dbufsize-1] = 0 ;
2917: switch( flags()&basebits ) {
2918: case ios::oct :
2919: p = conv8(i,&buf[dbufsize-2]) ;
2920: if ( (flags()&showbase) && i ) {
2921: pfx = "0" ; pfxsize = 1 ;
2922: }
2923: break ;
2924: case ios::hex :
2925: if ( flags()&uppercase ) {
2926: p=conv16u(i,&buf[dbufsize-2]);
2927: if ( flags()&showbase ) {
2928: pfx = "0X" ; pfxsize = 2 ;
2929: }
2930: }
2931: else {
2932: p=conv16(i,&buf[dbufsize-2]);
2933: if ( flags()&showbase ) {
2934: pfx = "0x" ; pfxsize = 2 ;
2935: }
2936: }
2937: break ;
2938: default:
2939: p = uconv10(i,&buf[dbufsize-2]) ;
2940: break ;
2941: }
2942: register int err ;
2943: if ( err = dofield(this,pfx,pfxsize,p,&buf[dbufsize-1]-p) ) {
2944: setstate(err) ;
2945: }
2946: osfx() ;
2947: return *this ;
2948: }
2949:
2950: ostream& OSTREAM::operator<<(register streambuf* b)
2951: {
2952: register streambuf* nbp = bp;
2953: register int c;
2954:
2955: if (!opfx()) return *this;
2956: if ( !b ) {
2957: setstate(failbit) ;
2958: return *this ;
2959: }
2960: c = b->sgetc();
2961: while (c != EOF) {
2962: if (nbp->sputc(c) == EOF) {
2963: setstate(badbit) ;
2964: break;
2965: }
2966: c = b->snextc();
2967: }
2968:
2969: osfx() ;
2970: return *this;
2971: }
2972:
2973: ostream& OSTREAM::operator<<( void* p)
2974: {
2975: long f = setf(ios::showbase|PTRBASE, basebits|ios::showbase) ;
2976: *this << (long)p ;
2977: setf(f,~0) ;
2978: return *this ;
2979: }
2980:
2981: ostream& OSTREAM::operator<<(int x)
2982: {
2983: *this << (long)x ;
2984: return *this ;
2985: }
2986:
2987: ostream& OSTREAM::operator<<(unsigned int x)
2988: {
2989: *this << (unsigned long)x ;
2990: return *this ;
2991: }
2992: 0707070044044142671004440042240042240000011604650437162573100001000000005714rawin.c /*ident "@(#)ctrans:lib/stream/rawin.c 1.1.1.1" */
2993: /**************************************************************************
2994: Copyright (c) 1984 AT&T
2995: All Rights Reserved
2996:
2997: THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T
2998:
2999: The copyright notice above does not evidence any
3000: actual or intended publication of such source code.
3001:
3002: rawin.c:
3003: raw input functions. (I.e. those that don't "eatwhite".)
3004:
3005: *****************************************************************************/
3006:
3007: #include <iostream.h>
3008:
3009: #define ISTREAM istream
3010:
3011: istream& ISTREAM::read(char* s, int n)
3012: {
3013: if ( !ipfx(n) ) {
3014: if ( n > 0 ) setstate(eofbit|failbit) ;
3015: return *this ;
3016: }
3017: x_gcount = bp->sgetn(s,n) ; ;
3018: if ( x_gcount < n ) setstate(eofbit|failbit) ;
3019: return *this ;
3020: }
3021:
3022: istream& ISTREAM::ignore(register int n, register int delim)
3023: {
3024: x_gcount = 0 ;
3025: if ( !ipfx(1) ) return *this ;
3026: if ( n == 0 ) return *this ;
3027: register streambuf* nbp = bp ;
3028: register int count = 0 ;
3029:
3030: while ( 1 ) {
3031: register int c = nbp->sbumpc() ;
3032: if ( c == EOF ) {
3033: setstate(eofbit|failbit) ;
3034: break ;
3035: }
3036: ++count ;
3037: if ( c == delim ) break ;
3038: if ( count == n ) break ;
3039: }
3040: x_gcount = count ;
3041: return *this ;
3042: }
3043:
3044: istream& ISTREAM::get(
3045: register char* s, /* character array to read into */
3046: register int len, /* size of character array */
3047: register char term /* character that terminates input */
3048: ) {
3049: register c;
3050: register streambuf *nbp = bp;
3051:
3052:
3053: x_gcount = 0 ;
3054: if ( len == 0 ) return *this ;
3055:
3056: if ( !ipfx(len) ) {
3057: *s = 0 ;
3058: return *this ;
3059: }
3060:
3061: if ( len<=0 ) return *this ;
3062:
3063: if ((c = bp->sgetc()) == EOF) {
3064: setstate(failbit | eofbit) ;
3065: return *this;
3066: }
3067:
3068: while (c != term && c != EOF && len > 1) {
3069: *s++ = c;
3070: c = nbp->snextc();
3071: len--;
3072: ++x_gcount ;
3073: }
3074: *s = '\0';
3075: if (c == EOF) setstate(eofbit) ;
3076: return *this;
3077: }
3078:
3079:
3080: istream& ISTREAM::get(
3081: register streambuf &s, /* streambuf to input to */
3082: register char term /* termination character */
3083: ){
3084: register c;
3085:
3086: int oldskip = skip(0) ;
3087: if ( !ipfx() ) {
3088: skip(oldskip) ;
3089: return *this ;
3090: }
3091: skip(oldskip) ;
3092: register streambuf *nbp = bp;
3093:
3094: x_gcount = 0 ;
3095: if ((c = bp->sgetc()) == EOF) {
3096: setstate(failbit | eofbit) ;
3097: return *this;
3098: }
3099:
3100: while (c != term && c != EOF) {
3101: if (s.sputc(c) == EOF) break;
3102: c = nbp->snextc();
3103: ++x_gcount ;
3104: }
3105: if (c == EOF) setstate(eofbit) ;
3106: return *this;
3107: }
3108:
3109: istream& ISTREAM::getline(char* b, int len, char d )
3110: {
3111: get(b,len,d) ;
3112: if ( x_gcount != len-1 && d!=EOF && bp->sgetc()==d) {
3113: ++x_gcount ;
3114: bp->sbumpc() ;
3115: }
3116: return *this ;
3117: }
3118:
3119: istream& ISTREAM::getline(unsigned char* b, int len, char d )
3120: {
3121: return getline((char*)b,len,d) ;
3122: }
3123:
3124: int ISTREAM::gcount()
3125: {
3126: return x_gcount ;
3127: }
3128:
3129: istream& ISTREAM::operator>>(register streambuf* s) {
3130: register c;
3131: if ( !ipfx() ) return *this ;
3132:
3133: register streambuf *nbp = bp;
3134:
3135: if ((c = bp->sgetc()) == EOF) {
3136: setstate(failbit | eofbit) ;
3137: return *this;
3138: }
3139:
3140: while (c != EOF) {
3141: if (s->sputc(c) == EOF) break;
3142: c = nbp->snextc();
3143: }
3144: if (c == EOF) setstate(eofbit) ;
3145: return *this;
3146: }
3147:
3148: 0707070044043602501004440042240042240000010416170437115412200001300000001542sbuf.dbp.c /*ident "@(#)ctrans:lib/stream/sbuf.dbp.c 1.1.2.1" */
3149: /**************************************************************************
3150: Copyright (c) 1984 AT&T
3151: All Rights Reserved
3152:
3153: THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T
3154:
3155: The copyright notice above does not evidence any
3156: actual or intended publication of such source code.
3157:
3158: sbuf.dbp.c
3159:
3160: *****************************************************************************/
3161:
3162:
3163: #include <iostream.h>
3164: #include <stdio.h>
3165: #include <string.h>
3166: #include <osfcn.h>
3167:
3168: void streambuf::dbp()
3169: {
3170: char msg[256] ;
3171: sprintf(msg,"buf at %#x, base=%#x, ebuf=%#x, ",
3172: this, base(), ebuf());
3173: write(1,msg,strlen(msg)) ;
3174: sprintf(msg,"pptr=%#x, epptr=%#x, ", pptr(),epptr() );
3175: write(1,msg,strlen(msg)) ;
3176: sprintf(msg,"eback=%#x, gptr=%#x, egptr=%#x\n",
3177: eback(), gptr(), egptr() ) ;
3178: write(1,msg,strlen(msg)) ;
3179:
3180: }
3181: 0707070044044146101004440042240042240000011575740443013564500001300000003220stdiobuf.c /*ident "@(#)ctrans:lib/stream/stdiobuf.c 1.1.2.2" */
3182: /**************************************************************************
3183: Copyright (c) 1984 AT&T
3184: All Rights Reserved
3185:
3186: THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T
3187:
3188: The copyright notice above does not evidence any
3189: actual or intended publication of such source code.
3190:
3191: stdiobuf.c:
3192:
3193: *****************************************************************************/
3194:
3195:
3196: #include <iostream.h>
3197: #include <stdiostream.h>
3198:
3199: int stdiobuf::overflow(int c)
3200: {
3201: if ( fp == 0 || c==EOF) return EOF ;
3202: if ( last_op == ios::in ) {
3203: if ( egptr()!=gptr() ) ungetc(*gptr(),fp) ;
3204: // stdio requires seeks between reads and writes
3205: fseek(fp,0,ios::cur) ;
3206: setg(0,0,0) ;
3207: }
3208: last_op = ios::out ;
3209:
3210: return putc(c,fp) ;
3211: }
3212:
3213: int stdiobuf::underflow() {
3214: if ( fp == 0 ) return EOF ;
3215: if ( last_op == ios::out ) {
3216: fseek(fp,0,0) ;
3217: }
3218: if ( feof(fp) ) return EOF ;
3219: int c = getc(fp) ;
3220: if ( c == EOF ) return EOF ;
3221: setg(buf,buf,buf+1) ;
3222: buf[0] = c ;
3223: return c ;
3224: }
3225:
3226: int stdiobuf::pbackfail(int c)
3227: {
3228: return ungetc(c,fp) ;
3229: }
3230:
3231: int stdiobuf::sync()
3232: {
3233: if ( last_op==ios::out ) fflush(fp) ;
3234: else if ( last_op==ios::in && gptr()!=egptr() ) {
3235: ungetc(*gptr(),fp) ;
3236: setg(0,0,0) ;
3237: }
3238: return fseek(fp,0,ios::cur) ;
3239: }
3240:
3241: streampos stdiobuf::seekoff(streamoff p,seek_dir d,int)
3242: {
3243:
3244: if ( gptr()!=egptr() ) ungetc(*gptr(),fp) ;
3245: setg(0,0,0) ;
3246: return fseek(fp,p,d) ;
3247: }
3248:
3249: stdiobuf::stdiobuf(FILE* f) :
3250: fp(f)
3251: {
3252: setbuf((char*)0,0) ;
3253: }
3254:
3255: stdiobuf::~stdiobuf()
3256: {
3257: if (fp) fflush(fp) ;
3258: }
3259:
3260: stdiostream::stdiostream(FILE* f) : buf(f)
3261: {
3262: init(&buf) ;
3263: }
3264:
3265: stdiostream::~stdiostream() { }
3266:
3267: stdiobuf* stdiostream::rdbuf() { return &buf ; }
3268: 0707070044044146041004440042240042240000011615120443013464300001600000002172stdiostream.h /*ident "@(#)ctrans:incl/stdiostream.h 1.1.1.2" */
3269: /**************************************************************************
3270: Copyright (c) 1984 AT&T
3271: All Rights Reserved
3272:
3273: THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T
3274:
3275: The copyright notice above does not evidence any
3276: actual or intended publication of such source code.
3277:
3278: *****************************************************************************/
3279: #ifndef STDSTREAMH
3280: #define STDSTREAMH
3281:
3282: #include <iostream.h>
3283: #include <stdio.h>
3284:
3285: class stdiobuf : public streambuf {
3286: /*** stdiobuf is obsolete, should be avoided ***/
3287: public: // Virtuals
3288: virtual int overflow(int=EOF);
3289: virtual int underflow();
3290: virtual int sync() ;
3291: virtual streampos
3292: seekoff(streamoff,seek_dir,int) ;
3293: virtual int pbackfail(int c);
3294: public:
3295: stdiobuf(FILE* f) ;
3296: FILE* stdiofile() { return fp ; }
3297: virtual ~stdiobuf() ;
3298: private:
3299: FILE* fp ;
3300: int last_op ;
3301: char buf[2];
3302: };
3303:
3304: class stdiostream : public ios {
3305: public:
3306: stdiostream(FILE*) ;
3307: ~stdiostream() ;
3308: stdiobuf* rdbuf() ;
3309: private:
3310: stdiobuf buf ;
3311: };
3312:
3313: #endif
3314:
3315: 0707070044044146241004440042240042240000011614100443034011500001100000015362stream.c /*ident "@(#)ctrans:lib/stream/stream.c 1.1.3.2" */
3316: /**************************************************************************
3317: Copyright (c) 1984 AT&T
3318: All Rights Reserved
3319:
3320: THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T
3321:
3322: The copyright notice above does not evidence any
3323: actual or intended publication of such source code.
3324:
3325: stream.c:
3326:
3327: *****************************************************************************/
3328:
3329: #include <iostream.h>
3330:
3331: void (*ios::stdioflush)() = 0 ;
3332:
3333: long ios::nextbit = 1L<<16 ;
3334: long ios::nextword = 0 ;
3335:
3336: const long ios::adjustfield = ios::left|ios::right|ios::internal ;
3337: const long ios::floatfield = ios::fixed|ios::scientific ;
3338: const long ios::basefield = ios::dec|ios::hex|ios::oct ;
3339:
3340: #define ISTREAM istream
3341: #define OSTREAM ostream
3342: #define IOSTREAM iostream
3343:
3344: union ios_user_union { long i ; void* p ; } ;
3345:
3346: void ios::init(streambuf* b)
3347: {
3348: // Must be called by other constructors. */
3349: bp=b ;
3350: state = 0 ;
3351: ispecial = 0 ;
3352: ospecial = 0 ;
3353: osfx_special = 0 ;
3354: isfx_special = 0 ;
3355: delbuf = 0 ;
3356: if (!bp ) setstate(hardfail|failbit) ;
3357: flags(skipws|dec) ;
3358: width(0);
3359: precision(6);
3360: fill(' ');
3361: tie(0);
3362:
3363: x_user = 0 ;
3364: nuser = 0 ;
3365: }
3366:
3367: ios::ios(streambuf* b) { init(b) ; }
3368:
3369: ios::~ios()
3370: {
3371: if (bp) bp->sync() ;
3372: if (delbuf) {
3373: delete bp ;
3374: bp = 0 ;
3375: }
3376: if (x_user) {
3377: delete x_user ;
3378: x_user = 0 ;
3379: }
3380: }
3381:
3382: iostream::iostream(streambuf* b) { init(b) ; }
3383: iostream::~iostream() { }
3384: istream::istream(streambuf* b) { init(b) ; }
3385: istream::~istream() { }
3386: ostream::ostream(streambuf* b) { init(b) ; }
3387: ostream::~ostream() { }
3388:
3389: IOSTREAM::IOSTREAM() { }
3390: ISTREAM::ISTREAM() { }
3391: OSTREAM::OSTREAM() { }
3392:
3393: ostream& OSTREAM::flush()
3394: {
3395: if ( bp->out_waiting() ) bp->overflow() ;
3396: else if ( bp->in_avail() ) bp->sync() ;
3397:
3398: return *this ;
3399: }
3400:
3401: streampos OSTREAM::tellp()
3402: {
3403: return bp->seekoff(0,cur,out) ;
3404: }
3405:
3406: streampos ISTREAM::tellg()
3407: {
3408: return bp->seekoff(0,cur,in) ;
3409: }
3410:
3411: ostream& OSTREAM::seekp(streampos p)
3412: {
3413: if ( bp->seekpos(p,out) == EOF ) setstate(badbit) ;
3414: return *this ;
3415: }
3416:
3417: typedef seek_dir Sdir ; /** Gets around a bug in release 2.0 beta 5 **/
3418:
3419: ostream& OSTREAM::seekp(streamoff o, Sdir d)
3420: {
3421: if ( bp->seekoff(o,d,out) == EOF ) setstate(badbit) ;
3422: return *this ;
3423: }
3424:
3425: istream& ISTREAM::seekg(streampos p)
3426: {
3427: if ( bp->seekpos(p,in) == EOF ) setstate(badbit) ;
3428: return *this ;
3429: }
3430:
3431: istream& ISTREAM::seekg(streamoff o, Sdir d)
3432: {
3433: if ( bp->seekoff(o,d,in) == EOF ) setstate(badbit) ;
3434: return *this ;
3435: }
3436:
3437: ostream* ios::tie(ostream* s)
3438: {
3439: ostream* t = x_tie ;
3440: x_tie = s ;
3441:
3442: if ( s ) {
3443: ispecial |= tied ;
3444: ospecial |= tied ;
3445: }
3446: else {
3447: ispecial &= ~tied ;
3448: ospecial &= ~tied ;
3449: }
3450: return t ;
3451: }
3452:
3453: char ios::fill(char c)
3454: {
3455: char oldf = x_fill ;
3456: x_fill = c ;
3457: return oldf ;
3458: }
3459:
3460: int ios::precision(int p)
3461: {
3462: register int oldp = x_precision ;
3463: x_precision = p;
3464: return oldp ;
3465: }
3466:
3467: long ios::setf(long b, long f)
3468: {
3469: long oldf = x_flags ;
3470: x_flags = (b&f) | (x_flags&~f) ;
3471:
3472: if (x_flags&skipws ) ispecial |= skipping ;
3473: else ispecial &= ~skipping ;
3474:
3475: osfx_special = (x_flags&(unitbuf|stdio)) != 0 ;
3476:
3477: return oldf ;
3478: }
3479:
3480: long ios::setf(long b)
3481: {
3482: long oldf = x_flags ;
3483: x_flags |= b ;
3484:
3485: if (x_flags&skipws ) ispecial |= skipping ;
3486: else ispecial &= ~skipping ;
3487:
3488: osfx_special = (x_flags&(unitbuf|stdio)) != 0 ;
3489: return oldf ;
3490: }
3491:
3492: long ios::unsetf(long b)
3493: {
3494: long oldf = x_flags ;
3495: x_flags &= ~b ;
3496:
3497: if (x_flags&skipws ) ispecial |= skipping ;
3498: else ispecial &= ~skipping ;
3499:
3500: osfx_special = (x_flags&(unitbuf|stdio)) != 0 ;
3501: return oldf ;
3502: }
3503:
3504: long ios::flags(long f)
3505: {
3506: long oldf = x_flags ;
3507: x_flags = f ;
3508:
3509: if (x_flags&skipws ) ispecial |= skipping ;
3510: else ispecial &= ~skipping ;
3511:
3512: osfx_special = (x_flags&(unitbuf|stdio)) != 0 ;
3513: return oldf ;
3514: }
3515:
3516: int ISTREAM::do_ipfx(int noskipws)
3517: {
3518: if ( state&hardfail) return 0 ;
3519: // note that we flush tied stream even when !this->good().
3520: if ( x_tie && x_tie->rdbuf()->out_waiting()
3521: && (noskipws==0 || rdbuf()->in_avail()<noskipws) ){
3522: x_tie->flush() ;
3523: }
3524: if ( good() && !noskipws && (ispecial&skipping) ) eatwhite() ;
3525: if ( eof() ) {
3526: // if we were only skipping this wouldn't be a failure.
3527: // but the presumption is that this is a prefix operation
3528: // prior to inputting something else.
3529: setstate(ios::failbit) ;
3530: return 0 ;
3531: }
3532: return good() ;
3533: }
3534:
3535: int OSTREAM::do_opfx()
3536: {
3537: if ( state&hardfail) return 0 ;
3538: if ( x_tie && x_tie->rdbuf()->out_waiting()) {
3539: x_tie->flush() ;
3540: }
3541: return good() ;
3542: }
3543:
3544: void OSTREAM::do_osfx()
3545: {
3546: if ( (x_flags & stdio) && stdioflush ) { (*stdioflush)() ; }
3547: if ( x_flags & unitbuf ) flush() ;
3548: }
3549:
3550: void ios::operator=(ios& rhs) { bp = rhs.bp ; }
3551:
3552: ios::ios() { assign_private = state ; state = hardfail ; }
3553:
3554: istream_withassign::istream_withassign()
3555: {
3556: // In order for the standard streams to be properly initialized
3557: // it is essential that nothing is done by the combination
3558: // of this constructor and ios::ios(). So we undo the effect of
3559: // ios::ios()
3560: state = assign_private ;
3561: }
3562:
3563: istream_withassign::~istream_withassign() { }
3564:
3565: istream_withassign& istream_withassign::operator=(istream& s)
3566: {
3567: init(s.rdbuf()) ;
3568: return *this ;
3569: }
3570:
3571: ostream_withassign::~ostream_withassign() { }
3572:
3573: istream_withassign& istream_withassign::operator=(streambuf* sb)
3574: {
3575: init(sb) ;
3576: return *this ;
3577: }
3578:
3579: ostream_withassign::ostream_withassign()
3580: {
3581: // In order for the standard streams to be properly initialized
3582: // it is essential that nothing is done by the combination
3583: // of this constructor and ios::ios(). So we undo the effect of
3584: // ios::ios()
3585: state = assign_private ;
3586: }
3587:
3588: ostream_withassign& ostream_withassign::operator=(ostream& s)
3589: {
3590: init(s.rdbuf()) ;
3591: return *this ;
3592: }
3593:
3594: ostream_withassign& ostream_withassign::operator=(streambuf* sb)
3595: {
3596: init(sb) ;
3597: return *this ;
3598: }
3599:
3600: iostream_withassign::iostream_withassign()
3601: {
3602: // In order for the standard streams to be properly initialized
3603: // it is essential that nothing is done by the combination
3604: // of this constructor and ios::ios(). So we undo the effect of
3605: // ios::ios()
3606: state = assign_private ;
3607: }
3608:
3609: iostream_withassign::~iostream_withassign() { }
3610:
3611:
3612: iostream_withassign& iostream_withassign::operator=(ios& s)
3613: {
3614: init(s.rdbuf()) ;
3615: return *this ;
3616: }
3617:
3618: iostream_withassign& iostream_withassign::operator=(streambuf* sb)
3619: {
3620: init(sb) ;
3621: return *this ;
3622: }
3623:
3624: void ios::uresize(int n)
3625: {
3626: if ( n < nuser ) return ;
3627: ios_user_union* newu = new ios_user_union[n+1] ;
3628: for ( int x = 0 ; x < nuser ; ++x ) {
3629: newu[x] = x_user[x] ;
3630: } ;
3631: delete [nuser] x_user ;
3632: nuser = n+1 ;
3633: x_user = newu ;
3634: }
3635:
3636: long & ios::iword(int x)
3637: {
3638: if ( x < 0 ) x = 0 ;
3639: if ( x >= nuser ) uresize(x) ;
3640: return x_user[x].i ;
3641: }
3642:
3643: void* & ios::pword(int x)
3644: {
3645: if ( x < 0 ) x = 0 ;
3646: if ( x >= nuser ) uresize(x) ;
3647: return x_user[x].p ;
3648: }
3649:
3650:
3651: long ios::bitalloc()
3652: {
3653: long w = nextbit ;
3654: nextbit = nextbit << 1 ;
3655: return w ;
3656: }
3657:
3658: long ios::xalloc()
3659: {
3660: return nextword++ ;
3661: }
3662: 0707070044043602551004440042240042240000010450100437115412200001100000003251stream.h /*ident "@(#)ctrans:incl/stream.h 1.1.5.1" */
3663: /**************************************************************************
3664: Copyright (c) 1984 AT&T
3665: All Rights Reserved
3666:
3667: THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T
3668:
3669: The copyright notice above does not evidence any
3670: actual or intended publication of such source code.
3671:
3672: *****************************************************************************/
3673:
3674: #ifndef STREAMH
3675: #define STREAMH
3676:
3677: #include <iostream.h>
3678: #include <iomanip.h>
3679: #include <stdiostream.h>
3680:
3681: #ifndef NULL
3682: #define NULL 0
3683: #endif
3684:
3685: extern char* oct(long, int =0);
3686: extern char* dec(long, int =0);
3687: extern char* hex(long, int =0);
3688:
3689: extern char* chr(int, int =0); /* chr(0) is the empty string "" */
3690: extern char* str(const char*, int =0);
3691: extern char* form(const char* ...);
3692: /* printf format
3693: * Things may go terribly wrong (maybe even core
3694: * dumps, if form tries to create a string with
3695: * more than "max_field_width" characters. */
3696:
3697: /* WS used to be a special in streams. The WS manipulator
3698: * is implemented differently but may be extracted from an istream
3699: * with the same effect as the old form.
3700: */
3701:
3702: extern istream& WS(istream&) ;
3703: extern void eatwhite(istream&) ;
3704:
3705: static const int input = (ios::in) ;
3706: static const int output = (ios::out) ;
3707: static const int append = (ios::app) ;
3708: static const int atend = (ios::ate) ;
3709: static const int _good = (ios::goodbit) ;
3710: static const int _bad = (ios::badbit) ;
3711: static const int _fail = (ios::failbit) ;
3712: static const int _eof = (ios::eofbit) ;
3713:
3714: typedef io_state state_value ;
3715:
3716: #endif
3717: 0707070044044146111004440042240042240000011627220443013566500001400000007423streambuf.c /*ident "@(#)ctrans:lib/stream/streambuf.c 1.1.6.2" */
3718: /**************************************************************************
3719: Copyright (c) 1984 AT&T
3720: All Rights Reserved
3721:
3722: THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T
3723:
3724: The copyright notice above does not evidence any
3725: actual or intended publication of such source code.
3726:
3727: streambuf.c:
3728:
3729: *****************************************************************************/
3730:
3731: #include <iostream.h>
3732: #include "streamdefs.h"
3733: #include <string.h>
3734: #include <memory.h>
3735:
3736: /*
3737: Allocate some space for the buffer.
3738: Returns: EOF on error
3739: 0 on success
3740: */
3741: int streambuf::doallocate()
3742: {
3743: char *buf = new char[STREAMBUFSIZE] ;
3744: if ( !buf ) return EOF ;
3745: setb(buf,buf+STREAMBUFSIZE,1) ;
3746: return 0;
3747: }
3748:
3749: /*
3750: Come here on a put to a full buffer. Allocate the buffer if
3751: it is uninitialized.
3752: Returns: EOF on error
3753: the argument on success
3754: */
3755: int streambuf::overflow(int c)
3756: {
3757: if ( c==EOF ) return zapeof(c) ;
3758: if ( allocate() == EOF) return EOF;
3759:
3760: if ( x_pptr <= x_epptr ) return sputc(c) ;
3761: else return EOF ;
3762: }
3763:
3764: /*
3765: Fill a buffer.
3766: Returns: EOF on error or end of input
3767: next character on success
3768: */
3769: int streambuf::underflow()
3770: {
3771: if ( x_pptr > x_egptr ) setg(x_eback,x_gptr,x_pptr) ;
3772:
3773: if ( x_egptr > x_gptr ) return 0 ;
3774: else return EOF ;
3775: }
3776:
3777: int streambuf::pbackfail(int)
3778: {
3779: return EOF;
3780: }
3781:
3782: int streambuf::sync()
3783: {
3784: // It's unclear exactly what this should do. Should it reset
3785: // the buffer or what. One theory (that used to be in the code.
3786: // was that it should insert a 0. Which seems to be the
3787: // right thing for "strings".
3788: if ( x_pptr && x_epptr > x_pptr ) sputc(0) ;
3789: return EOF ;
3790: }
3791:
3792:
3793: streampos streambuf::seekpos(streampos p, int m)
3794: {
3795: return seekoff(p, ios::beg, m) ;
3796: }
3797:
3798: streampos streambuf::seekoff(streampos,seek_dir,int)
3799: {
3800: return EOF ;
3801: }
3802:
3803: int streambuf::xsputn(register const char* s, int n)
3804: {
3805: register int req = n ;
3806: if ( unbuffered() ) {
3807: while( req-- > 0 ) {
3808: if ( sputc(*s++) == EOF ) return n-req-1 ;
3809: }
3810: return n ;
3811: }
3812: register int avail = x_epptr-x_pptr ;
3813: while ( avail < req ) {
3814: memcpy(x_pptr,s,avail) ;
3815: s += avail ;
3816: pbump(avail) ;
3817: req -= avail ;
3818: if ( overflow(zapeof(*s++)) == EOF ) return n-req ;
3819: --req ;
3820: avail = x_epptr-x_pptr ;
3821: }
3822: memcpy(x_pptr,s,req ) ;
3823: pbump(req) ;
3824: return n ;
3825: }
3826:
3827: int streambuf::xsgetn(register char* s, int n)
3828: {
3829: register char* p = s ;
3830: register int req = n ;
3831: if ( unbuffered() ) {
3832: while (req-- > 0 ) {
3833: register int c ;
3834: if ( (c=sbumpc() ) != EOF ) *p++ = c ;
3835: else return p-s ;
3836: }
3837: }
3838:
3839: if ( req <= 0 ) return 0 ;
3840:
3841: register int avail = x_egptr-x_gptr ;
3842: while ( avail < req ) {
3843: memcpy(p,x_gptr,avail) ;
3844: p += avail ;
3845: req -= avail ;
3846: gbump(avail) ;
3847: if ( underflow()==EOF ) return p-s ;
3848: avail = x_egptr-x_gptr ;
3849: }
3850:
3851: memcpy(p,x_gptr,req) ;
3852: gbump(req) ;
3853: return n ;
3854: }
3855:
3856:
3857: streambuf* streambuf::setbuf(char* p , int len)
3858: {
3859:
3860: if ( x_base ) return 0 ;
3861: if ( len <= 0 || p == 0 ) {
3862: // make it unbuffered
3863: setb(0,0,0) ;
3864: setg(0,0,0) ;
3865: setp(0,0);
3866: unbuffered(1) ;
3867: }
3868: else {
3869: setb(p,p+len,0) ;
3870: setg(p,p,p) ;
3871: setp(p,p+len) ;
3872: unbuffered(0) ;
3873: }
3874: return this;
3875: }
3876:
3877: streambuf* streambuf::setbuf(unsigned char* p, int len)
3878: {
3879: return setbuf((char*)p,len) ;
3880: }
3881:
3882: streambuf::streambuf() :
3883: x_unbuf(0), alloc(0)
3884: {
3885: setb(0,0,0);
3886: setg(0,0,0);
3887: setp(0,0);
3888: }
3889:
3890: streambuf::streambuf(char* p, int l) :
3891: x_unbuf(0), alloc(0)
3892: {
3893: setb(0,0,0);
3894: setbuf(p,l) ;
3895: }
3896:
3897: streambuf::~streambuf()
3898: {
3899: sync() ;
3900: if (x_base && alloc) delete x_base;
3901: }
3902:
3903: int streambuf::x_snextc()
3904: {
3905: // called by snextc to handle overflow
3906: if ( x_egptr==0 || x_gptr != x_egptr ) {
3907: // we stepped beyond x_gptr meaning snextc was called when
3908: // x_gtr == x_egptr rather than when x_gptr+1=x_egptr.
3909: underflow() ;
3910: pbump(1) ;
3911: }
3912: return sgetc() ;
3913: }
3914: 0707070044044142641004440042240042240000011622740437760332500001500000004211streamdefs.h /*ident "@(#)ctrans:lib/stream/streamdefs.h 1.1.2.1" */
3915: /**************************************************************************
3916: Copyright (c) 1984 AT&T
3917: All Rights Reserved
3918:
3919: THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T
3920:
3921: The copyright notice above does not evidence any
3922: actual or intended publication of such source code.
3923:
3924: streamdefs.h:
3925:
3926: *****************************************************************************/
3927:
3928:
3929: // This file contains #defines for controlling conditional compilation
3930: // of the stream library
3931:
3932:
3933: // The follwing functions adjust for machine dependencies
3934:
3935: #define BREAKEVEN 10
3936: /* The approximate length of a string
3937: * for which it is faster to do a strncpy
3938: * than a char by char loop. If BREAKEVEN is 0
3939: * then strncpy is always better. If it is <0 then
3940: * loop is always better, (e.g. if strncopy does
3941: * a char by char copy anyway.)
3942: */
3943:
3944: #define SEEK_ARITH_OK 1
3945: /* System supports arithmetic on stream positions.
3946: * I.e. if file is at a position and we read or
3947: * write n bytes we can find the new position
3948: * by adding n to old position. (Providing
3949: * O_APPEND isn't set in on open.)
3950: */
3951:
3952: static const int PTRBASE = ios::hex ;
3953: /* base for output of pointers (void*) */
3954:
3955: // There is one important machine dependent feature of this implementation
3956: // It assumes that it can always create a pointer to the byte after
3957: // a char array used as a buffer, and that pointer will be greater than
3958: // any pointer into the array.
3959: // My reading of the ANSI standard is that this assumption is permissible,
3960: // but I can imagine segmented architectures where it fails.
3961:
3962: /* #define VSPRINTF vsprintf */
3963:
3964: /* If defined, the name of a "vsprintf" function.
3965: * If not defined,
3966: * various non-portable kludges are used in
3967: * oldformat.c
3968: */
3969:
3970: static const int STREAMBUFSIZE = 1024 ;
3971: // The default buffer size.
3972:
3973: /*******
3974: #define O_CREAT 01000
3975: #define O_TRUNC 02000
3976: #define O_EXCL 04000
3977: *******/
3978: /* Used in filebuf.c. Define if your system
3979: * needs it to have a value different from
3980: * that indicated here, but doesn't
3981: * define it in standard system headers
3982: */
3983: 0707070044044146121004440042240042240000011606300443013570600001400000014566strstream.c /*ident "@(#)ctrans:lib/stream/strstream.c 1.1.4.2" */
3984: /**************************************************************************
3985: Copyright (c) 1984 AT&T
3986: All Rights Reserved
3987:
3988: THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T
3989:
3990: The copyright notice above does not evidence any
3991: actual or intended publication of such source code.
3992:
3993: strstream.c:
3994:
3995: *****************************************************************************/
3996:
3997: #include <iostream.h>
3998: #include <string.h>
3999: #include <strstream.h>
4000: #include <memory.h>
4001:
4002: typedef unsigned int Size_t ;
4003: // Some day <memory.h> will be ANSIfied and
4004: // this will be declared there.
4005: // Until then make it compatible with declaration
4006: // of third argument of memcpy.
4007:
4008: static const int initsize = 16*sizeof(int) ;
4009: static const int increment = 2 ;
4010:
4011: static const int arbitrary = 1024 ; // used by ignore_oflow.
4012:
4013: static const int ios_atend = ios::ate ;
4014: static const int ios_input = ios::in ;
4015: static const int ios_output = ios::out ;
4016: static const int ios_append = ios::app ;
4017: static const int seek_cur = ios::cur ;
4018: static const int seek_end = ios::end ;
4019: static const int seek_beg = ios::beg ;
4020:
4021: strstreambuf::strstreambuf(void* (*a)(long), void (*f)(void*)) :
4022: afct(a),
4023: ffct(f),
4024: froozen(1),
4025: auto_extend(initsize),
4026: ignore_oflow(0)
4027: {
4028: }
4029:
4030: void strstreambuf::init(char* b, int size, char* pstart)
4031: {
4032: if ( b && size > 0 ) {
4033: setb(b,b+size) ;
4034: }
4035: else if ( b && size == 0 ) {
4036: setb(b,b+strlen(b) ) ;
4037: }
4038: else if ( b && size < 0 ) {
4039: ignore_oflow = 1 ;
4040: setb(b,b+arbitrary) ;
4041: }
4042: else if ( !b && size > initsize ) {
4043: auto_extend = size ;
4044: setb(0,0) ;
4045: }
4046: else {
4047: setb(0,0) ;
4048: }
4049:
4050: if ( pstart && base() && base() <= pstart && pstart <= ebuf() ) {
4051: setp(pstart,ebuf()) ;
4052: }
4053: else {
4054: setp(0,0) ;
4055: }
4056:
4057: if ( base() ) {
4058: setg(base(),base(),ebuf()) ;
4059: auto_extend = 0 ;
4060: froozen = 1 ;
4061: }
4062: else {
4063: setg(0,0,0) ;
4064: }
4065: }
4066:
4067: strstreambuf::strstreambuf(char* b, int size, char* pstart) :
4068: afct(0),
4069: ffct(0),
4070: froozen(0),
4071: auto_extend(0),
4072: ignore_oflow(0)
4073: {
4074: init(b,size,pstart) ;
4075: }
4076:
4077: strstreambuf::strstreambuf(unsigned char* b, int size, unsigned char* pstart) :
4078: afct(0),
4079: ffct(0),
4080: froozen(0),
4081: auto_extend(0),
4082: ignore_oflow(0)
4083: {
4084: init((char*)b,size,(char*)pstart) ;
4085: }
4086:
4087:
4088: strstreambuf::strstreambuf(int ae) :
4089: afct(0),
4090: ffct(0),
4091: froozen(1),
4092: auto_extend(ae>0?ae:initsize),
4093: ignore_oflow(0)
4094: {
4095: }
4096:
4097: strstreambuf::strstreambuf() :
4098: afct(0),
4099: ffct(0),
4100: froozen(1),
4101: auto_extend(initsize),
4102: ignore_oflow(0)
4103: {
4104: }
4105:
4106:
4107: int strstreambuf::doallocate()
4108: {
4109: if ( auto_extend < initsize ) auto_extend = initsize ;
4110: char* newspace = afct ? (char*)(*afct)(auto_extend)
4111: : new char[auto_extend] ;
4112:
4113: if ( !newspace ) return EOF ;
4114:
4115: froozen = 0 ;
4116: setb(newspace,newspace+auto_extend,0) ;
4117: // Will free this space ourselves if neccessary
4118:
4119: setp(newspace,newspace+auto_extend) ;
4120: setg(newspace,newspace,newspace) ;
4121:
4122: return 0 ;
4123: }
4124:
4125: int strstreambuf::overflow(int c)
4126: {
4127: if ( !base() ) {
4128: allocate() ;
4129: if ( !base() ) return EOF ;
4130: }
4131: else if ( auto_extend && !froozen ) {
4132: Size_t inserted=pptr()-base() ; // number of chars previously
4133: // inserted into buffer
4134:
4135: Size_t extracted=gptr()-base() ;
4136: // number of chars previously
4137: // extracted from buffer
4138:
4139: // after we copy chars from current space to a new
4140: // (larger) area we have to adjust pointers to take into
4141: // acount previous activities.
4142:
4143: Size_t newsize = (Size_t)increment*blen() + 4 ;
4144: if ( newsize < auto_extend ) newsize = auto_extend ;
4145: char* newspace = afct ? (char*)(*afct)(newsize)
4146: : new char[newsize] ;
4147:
4148: if ( !newspace ) return EOF ;
4149:
4150: memcpy(newspace,base(),inserted) ;
4151:
4152: if ( ffct ) (*ffct)(base()) ;
4153: else delete base() ;
4154:
4155: setb(newspace,newspace+newsize,0) ;
4156: setp(base()+inserted,ebuf()) ;
4157: setg(base(),base()+extracted,pptr()) ;
4158: }
4159: else if ( ignore_oflow ) {
4160: setp(pptr(),pptr()+arbitrary) ;
4161: }
4162: else {
4163: return EOF ;
4164: }
4165: if ( c!=EOF ) return sputc(c) ;
4166: }
4167:
4168: int strstreambuf::underflow()
4169: {
4170: if ( !pptr() ) return EOF ;
4171: if ( !egptr() ) return EOF ;
4172:
4173: setg(base(),egptr(),pptr()) ;
4174:
4175: if ( egptr() <= gptr() ) return EOF ;
4176: else return *gptr() ;
4177: }
4178:
4179: void strstreambuf::freeze(int n)
4180: {
4181: froozen = n ;
4182: }
4183:
4184:
4185: char* strstreambuf::str()
4186: {
4187: freeze() ;
4188: return base() ;
4189: }
4190:
4191: strstreambuf::~strstreambuf()
4192: {
4193: if ( !froozen && base() ) {
4194: if ( ffct ) ffct(base()) ;
4195: else delete base() ;
4196: }
4197: }
4198:
4199: streambuf* strstreambuf::setbuf(char* p, int size)
4200: {
4201: if ( p == 0 && ( base()==0 || auto_extend ) ) {
4202: auto_extend = size ;
4203: return this ;
4204: }
4205: else {
4206: return 0 ;
4207: }
4208: }
4209:
4210: streampos strstreambuf::seekoff(streamoff o, seek_dir d, int m)
4211: {
4212: switch (d) {
4213: case seek_beg : break ;
4214: case seek_cur : {
4215: if ( (m&ios_input) ) {
4216: o += gptr()-base() ;
4217: }
4218: else {
4219: o += pptr()-base() ;
4220: }
4221: } break ;
4222: case seek_end : {
4223: if ( gptr()<egptr() && egptr()>pptr() ) {
4224: o += egptr()-base() ;
4225: }
4226: else if ( pptr()<epptr() ) {
4227: o += pptr()-base();
4228: }
4229: } break ;
4230: } // end switch
4231: if ( o < 0 ) return streampos(EOF) ;
4232: if ( o >= blen() && !ignore_oflow ) return streampos(EOF) ;
4233: if ( m&ios_input ) setg(base(), base()+o, egptr() ) ;
4234: if ( m&ios_output) setp(base()+o, epptr() ) ;
4235: return o ;
4236: }
4237:
4238: strstreambase::strstreambase(char* str, int size, char* pstart)
4239: : buf(str,size,pstart) { init(&buf) ; }
4240:
4241: strstreambase::strstreambase() : buf() { init(&buf) ; }
4242:
4243: strstreambase::~strstreambase() { }
4244:
4245: strstreambuf* strstreambase::rdbuf() { return &buf ; }
4246:
4247: istrstream::istrstream(char* str)
4248: : strstreambase(str,strlen(str),0) { }
4249:
4250: istrstream::istrstream(char* str, int size)
4251: : strstreambase(str, size , 0) { }
4252:
4253: istrstream::~istrstream() { }
4254:
4255:
4256: static char* pstart(char* str, int size, int m)
4257: {
4258: if ( (m&(ios_append|ios_output)) == 0 ) return str+size ;
4259: else if ( (m&(ios_append|ios_atend)) ) return str+strlen(str) ;
4260: else return str ;
4261: }
4262:
4263: ostrstream::ostrstream(char* str, int size, int m)
4264: : strstreambase(str, size, pstart(str,size, (m|ios_output)) )
4265: { }
4266:
4267: ostrstream::ostrstream() : strstreambase() { }
4268:
4269:
4270: ostrstream::~ostrstream()
4271: {
4272: ios::rdbuf()->sputc(0) ;
4273: }
4274:
4275: char* ostrstream::str()
4276: {
4277: return strstreambase::rdbuf()->str() ;
4278: }
4279:
4280: int ostrstream::pcount() {
4281: return ios::rdbuf()->out_waiting() ;
4282: }
4283:
4284: strstream::strstream() : strstreambase() { }
4285:
4286: strstream::strstream(char* str, int size, int m)
4287: : strstreambase(str,size,pstart(str,size,m))
4288: { }
4289:
4290: char* strstream::str()
4291: {
4292: return strstreambase::rdbuf()->str() ;
4293: }
4294:
4295:
4296: strstream::~strstream() { }
4297: 0707070044044146051004440042240042240000011620550443013473100001400000003720strstream.h /*ident "@(#)ctrans:incl/strstream.h 1.1.1.1" */
4298: /**************************************************************************
4299: Copyright (c) 1984 AT&T
4300: All Rights Reserved
4301:
4302: THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T
4303:
4304: The copyright notice above does not evidence any
4305: actual or intended publication of such source code.
4306:
4307: *****************************************************************************/
4308: #ifndef STRSTREAMH
4309: #define STRSTREAMH
4310:
4311: #include <iostream.h>
4312: class strstreambuf : public streambuf
4313: {
4314: public:
4315: strstreambuf() ;
4316: strstreambuf(int) ;
4317: strstreambuf(void* (*a)(long), void (*f)(void*)) ;
4318: strstreambuf(char* b, int size, char* pstart = 0 ) ;
4319: strstreambuf(unsigned char* b, int size, unsigned char* pstart = 0 ) ;
4320: void freeze(int n=1) ;
4321: char* str() ;
4322: ~strstreambuf() ;
4323:
4324: public: /* virtuals */
4325: virtual int doallocate() ;
4326: virtual int overflow(int) ;
4327: virtual int underflow() ;
4328: virtual streambuf*
4329: setbuf(char* p, int l) ;
4330: virtual streampos
4331: seekoff(streamoff,seek_dir,int) ;
4332:
4333: private:
4334: void init(char*,int,char*) ;
4335:
4336: void* (*afct)(long) ;
4337: void (*ffct)(void*) ;
4338: int ignore_oflow ;
4339: int froozen ;
4340: int auto_extend ;
4341:
4342: public:
4343: } ;
4344:
4345: class strstreambase : public virtual ios {
4346: public:
4347: strstreambuf* rdbuf() ;
4348: protected:
4349: strstreambase(char*, int, char*) ;
4350: strstreambase() ;
4351: ~strstreambase() ;
4352: private:
4353: strstreambuf buf ;
4354: } ;
4355:
4356: class istrstream : public strstreambase, public istream {
4357: public:
4358: istrstream(char* str);
4359: istrstream(char* str, int size ) ;
4360: ~istrstream() ;
4361: } ;
4362:
4363: class ostrstream : public strstreambase, public ostream {
4364: public:
4365: ostrstream(char* str, int size, int=ios::out) ;
4366: ostrstream() ;
4367: ~ostrstream() ;
4368: char* str() ;
4369: int pcount() ;
4370: } ;
4371:
4372:
4373: class strstream : public strstreambase, public iostream {
4374: public:
4375: strstream() ;
4376: strstream(char* str, int size, int mode) ;
4377: ~strstream() ;
4378: char* str() ;
4379: } ;
4380:
4381: #endif
4382: 0707070044044142521004440042240042240000011613160443033725500001200000002075swstdio.c /*ident "@(#)ctrans:lib/stream/swstdio.c 1.1.1.1" */
4383: /**************************************************************************
4384: Copyright (c) 1984 AT&T
4385: All Rights Reserved
4386:
4387: THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T
4388:
4389: The copyright notice above does not evidence any
4390: actual or intended publication of such source code.
4391:
4392: swstdio.c:
4393:
4394: *****************************************************************************/
4395:
4396:
4397: #include <iostream.h>
4398: #include <stdiostream.h>
4399:
4400: static void stdioflush()
4401: {
4402: fflush(stdout) ;
4403: fflush(stderr) ;
4404: }
4405:
4406: void ios::sync_with_stdio()
4407: {
4408: switch ( Iostream_init::stdstatus )
4409: {
4410: case 1 : cout.flush() ; cerr.flush() ; clog.flush() ; break ;
4411: case 2 : break ;
4412: default : return ; }
4413:
4414: cin = new stdiobuf(stdin) ;
4415: cout = new stdiobuf(stdout) ;
4416: cerr = new stdiobuf(stderr) ;
4417: clog = cerr ;
4418: cin.setf(~0L,skipws) ;
4419: cout.setf(~0L,unitbuf|stdio) ;
4420: cerr.setf(~0L,unitbuf|stdio) ;
4421: clog.setf(~0L,unitbuf|stdio) ;
4422: cin.tie(&cout) ;
4423: cerr.tie(&cout) ;
4424: clog.tie(&cout) ;
4425: Iostream_init::stdstatus = 2 ;
4426: ios::stdioflush = ::stdioflush ;
4427: }
4428: 0707070044043601661006440042240042240000010432300443212600200001000000000134version Iostream with multiple inheritance
4429: hector!/home/jss/work/iosrc
4430: Wed May 10 17:39:14 EDT 1989
4431: 0707070044043601661006440042240042240000010432300443212600200001300000000000TRAILER!!! 0134version Iostream with multiple inheritance
4432: hector!/home/jss/work/iosrc
4433: Wed May 10 17:39:14 EDT 1989
4434: 0707070044043601661006440042240042240000010432300443212600200001300000000000TRAILER!!! 0134version Iostream with multiple inheritance
4435: hector!/home/jss/work/iosrc
4436: Wed May 10 17:39:14 EDT 1989
4437: 07070700440436016610064400
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.