|
|
1.1 ! root 1: /*ident "@(#)ctrans:lib/stream/rawin.c 1.1.1.1" */ ! 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: rawin.c: ! 12: raw input functions. (I.e. those that don't "eatwhite".) ! 13: ! 14: *****************************************************************************/ ! 15: ! 16: #include <iostream.h> ! 17: ! 18: #define ISTREAM istream ! 19: ! 20: istream& ISTREAM::read(char* s, int n) ! 21: { ! 22: if ( !ipfx(n) ) { ! 23: if ( n > 0 ) setstate(eofbit|failbit) ; ! 24: return *this ; ! 25: } ! 26: x_gcount = bp->sgetn(s,n) ; ; ! 27: if ( x_gcount < n ) setstate(eofbit|failbit) ; ! 28: return *this ; ! 29: } ! 30: ! 31: istream& ISTREAM::ignore(register int n, register int delim) ! 32: { ! 33: x_gcount = 0 ; ! 34: if ( !ipfx(1) ) return *this ; ! 35: if ( n == 0 ) return *this ; ! 36: register streambuf* nbp = bp ; ! 37: register int count = 0 ; ! 38: ! 39: while ( 1 ) { ! 40: register int c = nbp->sbumpc() ; ! 41: if ( c == EOF ) { ! 42: setstate(eofbit|failbit) ; ! 43: break ; ! 44: } ! 45: ++count ; ! 46: if ( c == delim ) break ; ! 47: if ( count == n ) break ; ! 48: } ! 49: x_gcount = count ; ! 50: return *this ; ! 51: } ! 52: ! 53: istream& ISTREAM::get( ! 54: register char* s, /* character array to read into */ ! 55: register int len, /* size of character array */ ! 56: register char term /* character that terminates input */ ! 57: ) { ! 58: register c; ! 59: register streambuf *nbp = bp; ! 60: ! 61: ! 62: x_gcount = 0 ; ! 63: if ( len == 0 ) return *this ; ! 64: ! 65: if ( !ipfx(len) ) { ! 66: *s = 0 ; ! 67: return *this ; ! 68: } ! 69: ! 70: if ( len<=0 ) return *this ; ! 71: ! 72: if ((c = bp->sgetc()) == EOF) { ! 73: setstate(failbit | eofbit) ; ! 74: return *this; ! 75: } ! 76: ! 77: while (c != term && c != EOF && len > 1) { ! 78: *s++ = c; ! 79: c = nbp->snextc(); ! 80: len--; ! 81: ++x_gcount ; ! 82: } ! 83: *s = '\0'; ! 84: if (c == EOF) setstate(eofbit) ; ! 85: return *this; ! 86: } ! 87: ! 88: ! 89: istream& ISTREAM::get( ! 90: register streambuf &s, /* streambuf to input to */ ! 91: register char term /* termination character */ ! 92: ){ ! 93: register c; ! 94: ! 95: int oldskip = skip(0) ; ! 96: if ( !ipfx() ) { ! 97: skip(oldskip) ; ! 98: return *this ; ! 99: } ! 100: skip(oldskip) ; ! 101: register streambuf *nbp = bp; ! 102: ! 103: x_gcount = 0 ; ! 104: if ((c = bp->sgetc()) == EOF) { ! 105: setstate(failbit | eofbit) ; ! 106: return *this; ! 107: } ! 108: ! 109: while (c != term && c != EOF) { ! 110: if (s.sputc(c) == EOF) break; ! 111: c = nbp->snextc(); ! 112: ++x_gcount ; ! 113: } ! 114: if (c == EOF) setstate(eofbit) ; ! 115: return *this; ! 116: } ! 117: ! 118: istream& ISTREAM::getline(char* b, int len, char d ) ! 119: { ! 120: get(b,len,d) ; ! 121: if ( x_gcount != len-1 && d!=EOF && bp->sgetc()==d) { ! 122: ++x_gcount ; ! 123: bp->sbumpc() ; ! 124: } ! 125: return *this ; ! 126: } ! 127: ! 128: istream& ISTREAM::getline(unsigned char* b, int len, char d ) ! 129: { ! 130: return getline((char*)b,len,d) ; ! 131: } ! 132: ! 133: int ISTREAM::gcount() ! 134: { ! 135: return x_gcount ; ! 136: } ! 137: ! 138: istream& ISTREAM::operator>>(register streambuf* s) { ! 139: register c; ! 140: if ( !ipfx() ) return *this ; ! 141: ! 142: register streambuf *nbp = bp; ! 143: ! 144: if ((c = bp->sgetc()) == EOF) { ! 145: setstate(failbit | eofbit) ; ! 146: return *this; ! 147: } ! 148: ! 149: while (c != EOF) { ! 150: if (s->sputc(c) == EOF) break; ! 151: c = nbp->snextc(); ! 152: } ! 153: if (c == EOF) setstate(eofbit) ; ! 154: return *this; ! 155: } ! 156:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.