|
|
1.1 root 1: /*ident "@(#)ctrans:lib/stream/in.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: in.c:
12:
13: *****************************************************************************/
14:
15: #include <ctype.h>
16: #include <iostream.h>
17:
18: #define ISTREAM istream
19:
20: void ISTREAM::eatwhite ()
21: {
22: register streambuf *nbp = bp;
23: register int c = nbp->sgetc();
24: while (isspace(c)) c = nbp->snextc();
25: if (c == EOF) setstate(eofbit);
26: }
27:
28: void ISTREAM::xget(char* c)
29: {
30: register streambuf* sbp = bp ;
31: if ( !ipfx(1) ) return ;
32: x_gcount = 0 ;
33: register int newc = sbp->sbumpc() ;
34: if ( newc == EOF ) {
35: setstate(failbit|eofbit) ;
36: return ;
37: }
38: x_gcount = 1 ;
39: *c = newc ;
40: }
41:
42: istream& ISTREAM::operator>>(register char* s)
43: {
44: /* get string */
45:
46: register int w = width(0) ;
47: if ( flags()&skipws ) {
48: // We don't know a maximum number of required
49: // characters
50: if ( !ipfx(0) ) return *this ;
51: }
52: else if ( !ipfx(w) ) {
53: return *this ;
54: }
55:
56: register streambuf *nbp = bp;
57: register int c = nbp->sgetc();
58:
59: if (c == EOF) setstate(failbit|eofbit) ;
60:
61: if ( w > 0 ) {
62: while (!isspace(c) && c != EOF && --w > 0 ) {
63: *s++ = c;
64: c = nbp->snextc();
65: }
66: } else {
67: while (!isspace(c) && c != EOF ) {
68: *s++ = c;
69: c = nbp->snextc();
70: }
71: }
72:
73: *s = '\0';
74:
75: if (c == EOF) setstate(eofbit) ;
76:
77: return *this;
78: }
79:
80: istream& ISTREAM::operator>>(unsigned char* s)
81: {
82: return *this >> (char*)s ;
83: }
84:
85: istream& ISTREAM::putback(register char c)
86: {
87: if ( !good() ) return *this ;
88: if ( bp->sputbackc(c) == EOF ) setstate(badbit) ;
89: return *this;
90: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.