Annotation of researchv10no/cmd/cfront/libC/oiostream/stream.c, revision 1.1

1.1     ! root        1: /*ident        "@(#)ctrans:lib/stream/stream.c 1.1.3.2" */
        !             2: /**************************************************************************
        !             3:                         Copyright (c) 1984 AT&T
        !             4:                           All Rights Reserved   
        !             5: 
        !             6:         THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T
        !             7:       
        !             8:         The copyright notice above does not evidence any        
        !             9:         actual or intended publication of such source code.
        !            10: 
        !            11: stream.c:
        !            12: 
        !            13: *****************************************************************************/
        !            14: 
        !            15: #include <iostream.h>
        !            16: 
        !            17: long ios::nextbit = 1L<<16 ;
        !            18: long ios::nextword = 0 ;
        !            19: 
        !            20: const long ios::adjustfield = ios::left|ios::right|ios::internal ;
        !            21: const long ios::floatfield = ios::fixed|ios::scientific ;
        !            22: const long ios::basefield = ios::dec|ios::hex|ios::oct ;
        !            23: 
        !            24: #define ISTREAM istream
        !            25: #define OSTREAM ostream
        !            26: #define IOSTREAM iostream
        !            27: 
        !            28: union ios_user_union { long i ; void* p ; } ;
        !            29: 
        !            30: void ios::init(streambuf* b)
        !            31: {
        !            32:        // Must be called by other constructors. */
        !            33:        bp=b ;
        !            34:        state = 0 ;
        !            35:        ispecial = 0 ;
        !            36:        ospecial = 0 ;
        !            37:        delbuf = 0 ;
        !            38:        if (!bp ) setstate(hardfail|failbit) ;
        !            39:        flags(skipws|dec) ;
        !            40:        width(0);
        !            41:        precision(6);
        !            42:        fill(' ');
        !            43:        tie(0);
        !            44:        
        !            45:        x_user = 0 ;
        !            46:        nuser = 0 ;
        !            47:        }
        !            48: 
        !            49: ios::ios(streambuf* b) { init(b) ; }
        !            50: 
        !            51: ios::~ios()
        !            52: {
        !            53:        if (bp) bp->sync() ;
        !            54:        if (delbuf) {
        !            55:                delete bp ;
        !            56:                bp = 0 ;
        !            57:                }
        !            58:        if (x_user) {
        !            59:                delete x_user ; 
        !            60:                x_user = 0 ;
        !            61:                }
        !            62:        }
        !            63: 
        !            64: iostream::iostream(streambuf* b) { init(b) ; }
        !            65: iostream::~iostream() { }
        !            66: istream::istream(streambuf* b) { init(b) ; }
        !            67: istream::~istream() { }
        !            68: ostream::ostream(streambuf* b) { init(b) ; }
        !            69: ostream::~ostream() { }
        !            70: 
        !            71: IOSTREAM::IOSTREAM() { } 
        !            72: ISTREAM::ISTREAM() { } 
        !            73: OSTREAM::OSTREAM() { }
        !            74: 
        !            75: ostream& OSTREAM::flush()
        !            76: {
        !            77:        if ( bp->out_waiting() )        bp->overflow() ;
        !            78:        else if ( bp->in_avail() )      bp->sync() ; 
        !            79: 
        !            80:        return *this ;
        !            81: }
        !            82: 
        !            83: streampos OSTREAM::tellp()
        !            84: {
        !            85:        return bp->seekoff(0,cur,out) ;
        !            86: }
        !            87: 
        !            88: streampos ISTREAM::tellg()
        !            89: {
        !            90:        return bp->seekoff(0,cur,in) ;
        !            91: }
        !            92:        
        !            93: ostream& OSTREAM::seekp(streampos p)
        !            94: {
        !            95:        if ( bp->seekpos(p,out) == EOF ) setstate(badbit) ;
        !            96:        return *this ;
        !            97: }
        !            98: 
        !            99: typedef seek_dir Sdir ; /** Gets around a bug in release 2.0 beta 5 **/
        !           100: 
        !           101: ostream& OSTREAM::seekp(streamoff o, Sdir d)
        !           102: {
        !           103:        if ( bp->seekoff(o,d,out) == EOF ) setstate(badbit) ;
        !           104:        return *this ;
        !           105: }
        !           106:        
        !           107: istream& ISTREAM::seekg(streampos p)
        !           108: {
        !           109:        if ( bp->seekpos(p,in) == EOF ) setstate(badbit) ;
        !           110:        return *this ;
        !           111: }
        !           112: 
        !           113: istream& ISTREAM::seekg(streamoff o, Sdir d)
        !           114: {
        !           115:        if ( bp->seekoff(o,d,in) == EOF ) setstate(badbit) ;
        !           116:        return *this ;
        !           117: }
        !           118: 
        !           119: ostream* ios::tie(ostream* s) 
        !           120: {
        !           121:        ostream* t = x_tie ;
        !           122:        x_tie = s ;
        !           123: 
        !           124:        if ( s ) {
        !           125:                ispecial |= tied ;
        !           126:                ospecial |= tied ;
        !           127:                }
        !           128:        else {
        !           129:                ispecial &= ~tied ;
        !           130:                ospecial &= ~tied ;
        !           131:                }
        !           132:        return t ;
        !           133: }
        !           134: 
        !           135: char ios::fill(char c)
        !           136: {
        !           137:        char oldf = x_fill ;
        !           138:        x_fill = c ;
        !           139:        return oldf ;
        !           140:        }
        !           141: 
        !           142: int ios::precision(int p)
        !           143: {
        !           144:        register int oldp = x_precision ;
        !           145:        x_precision = p;
        !           146:        return oldp ;
        !           147:        }
        !           148: 
        !           149: long ios::setf(long b, long f)
        !           150: {
        !           151:        long oldf = x_flags ;
        !           152:        x_flags = (b&f) | (x_flags&~f) ;
        !           153: 
        !           154:        if (x_flags&skipws )    ispecial |= skipping ;
        !           155:        else                    ispecial &= ~skipping ;
        !           156: 
        !           157:        return oldf ;
        !           158:        }
        !           159: 
        !           160: long ios::setf(long b)
        !           161: {
        !           162:        long oldf = x_flags ;
        !           163:        x_flags |= b ;
        !           164:        if ( b & skipws ) ispecial |= skipping ;
        !           165:        return oldf ;
        !           166:        }
        !           167: 
        !           168: long ios::unsetf(long b)
        !           169: {
        !           170:        long oldf = x_flags ;
        !           171:        x_flags &= ~b ;
        !           172:        if ( b & skipws ) ispecial &= ~skipping ;
        !           173:        return oldf ;
        !           174:        }
        !           175: 
        !           176: long ios::flags(long f) 
        !           177: {
        !           178:        long oldf = x_flags ;
        !           179:        x_flags = f ;
        !           180: 
        !           181:        if (x_flags&skipws )    ispecial |= skipping ;
        !           182:        else                    ispecial &= ~skipping ;
        !           183: 
        !           184:        return oldf ;
        !           185:        }
        !           186:        
        !           187: int ISTREAM::do_ipfx(int noskipws)
        !           188: {
        !           189:        if ( state&hardfail) return 0 ;
        !           190:        // note that we flush tied stream even when !this->good().
        !           191:        if ( x_tie && x_tie->rdbuf()->out_waiting()
        !           192:                        && (noskipws==0 || rdbuf()->in_avail()<noskipws) ){
        !           193:                x_tie->flush() ;
        !           194:                }
        !           195:        if ( good() && !noskipws && (ispecial&skipping) ) eatwhite() ;
        !           196:        if ( eof() ) {
        !           197:                // if we were only skipping this wouldn't be a failure.
        !           198:                // but the presumption is that this is a prefix operation
        !           199:                // prior to inputting something else.
        !           200:                setstate(ios::failbit) ;
        !           201:                return 0 ;
        !           202:                }
        !           203:        return good() ;
        !           204:        }
        !           205: 
        !           206: int OSTREAM::do_opfx()
        !           207: {
        !           208:        if ( state&hardfail) return 0 ;
        !           209:        if ( x_tie && x_tie->rdbuf()->out_waiting()) {
        !           210:                x_tie->flush() ;
        !           211:                }
        !           212:        return good() ;
        !           213:        }
        !           214: 
        !           215: void ios::operator=(ios& rhs) { bp = rhs.bp ; }
        !           216: 
        !           217: ios::ios() { assign_private = state ; state = hardfail ; } 
        !           218: 
        !           219: istream_withassign::istream_withassign() 
        !           220: {
        !           221:        // In order for the standard streams to be properly initialized
        !           222:        // it is essential that nothing is done by the combination
        !           223:        // of this constructor and ios::ios().  So we undo the effect of
        !           224:        // ios::ios() 
        !           225:        state = assign_private ;
        !           226:        }
        !           227: 
        !           228: istream_withassign::~istream_withassign()  { } 
        !           229: 
        !           230: istream_withassign& istream_withassign::operator=(istream& s)
        !           231: {
        !           232:        init(s.rdbuf()) ;
        !           233:        return *this ;
        !           234:        }
        !           235: 
        !           236: ostream_withassign::~ostream_withassign()  { } 
        !           237: 
        !           238: istream_withassign& istream_withassign::operator=(streambuf* sb)
        !           239: {
        !           240:        init(sb) ;
        !           241:        return *this ;
        !           242:        }
        !           243: 
        !           244: ostream_withassign::ostream_withassign() 
        !           245: {
        !           246:        // In order for the standard streams to be properly initialized
        !           247:        // it is essential that nothing is done by the combination
        !           248:        // of this constructor and ios::ios().  So we undo the effect of
        !           249:        // ios::ios() 
        !           250:        state = assign_private ;
        !           251:        }
        !           252: 
        !           253: ostream_withassign& ostream_withassign::operator=(ostream& s)
        !           254: {
        !           255:        init(s.rdbuf()) ;
        !           256:        return *this ;
        !           257:        }
        !           258: 
        !           259: ostream_withassign& ostream_withassign::operator=(streambuf* sb)
        !           260: {
        !           261:        init(sb) ;
        !           262:        return *this ;
        !           263:        }
        !           264: 
        !           265: iostream_withassign::iostream_withassign() 
        !           266: {
        !           267:        // In order for the standard streams to be properly initialized
        !           268:        // it is essential that nothing is done by the combination
        !           269:        // of this constructor and ios::ios().  So we undo the effect of
        !           270:        // ios::ios() 
        !           271:        state = assign_private ;
        !           272:        }
        !           273: 
        !           274: iostream_withassign::~iostream_withassign()  { } 
        !           275: 
        !           276: 
        !           277: iostream_withassign& iostream_withassign::operator=(ios& s)
        !           278: {
        !           279:        init(s.rdbuf()) ;
        !           280:        return *this ;
        !           281:        }
        !           282: 
        !           283: iostream_withassign& iostream_withassign::operator=(streambuf* sb)
        !           284: {
        !           285:        init(sb) ;
        !           286:        return *this ;
        !           287:        }
        !           288: 
        !           289: void ios::uresize(int n)
        !           290: {
        !           291:        if ( n < nuser ) return ;
        !           292:        ios_user_union* newu = new ios_user_union[n+1] ;
        !           293:        for ( int x = 0 ; x < nuser ; ++x ) {
        !           294:                newu[x] = x_user[x] ;
        !           295:                } ;
        !           296:        delete [nuser] x_user ;
        !           297:        nuser = n+1 ;
        !           298:        x_user = newu ;
        !           299:        }
        !           300: 
        !           301: long & ios::iword(int x)
        !           302: {
        !           303:        if ( x < 0 ) x = 0 ;
        !           304:        if ( x >= nuser ) uresize(x) ;
        !           305:        return x_user[x].i ;
        !           306:        }
        !           307: 
        !           308: void* & ios::pword(int x)
        !           309: {
        !           310:        if ( x < 0 ) x = 0 ;
        !           311:        if ( x >= nuser ) uresize(x) ;
        !           312:        return x_user[x].p ;
        !           313:        }
        !           314: 
        !           315: 
        !           316: long ios::bitalloc()
        !           317: {
        !           318:        long w = nextbit ;
        !           319:        nextbit = nextbit << 1 ;
        !           320:        return w ;
        !           321:        }
        !           322: 
        !           323: long ios::xalloc()
        !           324: {
        !           325:        return nextword++ ;
        !           326:        }

unix.superglobalmegacorp.com

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