2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
24 //%% (c) Copyright 1993, 1994 Hewlett-Packard Company
25 //%% (c) Copyright 1993, 1994 International Business Machines Corp.
26 //%% (c) Copyright 1993, 1994 Sun Microsystems, Inc.
27 //%% (c) Copyright 1993, 1994 Novell, Inc.
28 //%% $TOG: tt_iostream.C /main/5 1998/04/03 17:10:03 mgreess $
30 * @(#)tt_iostream.cc 1.4 93/08/15
32 * Copyright 1993 Sun Microsystems, Inc. All rights reserved.
37 #include "util/tt_iostream.h"
38 #include "util/tt_enumname.h"
39 #include "mp/mp_message.h"
40 #include "mp/mp_pattern.h"
42 _Tt_ostream::_Tt_ostream()
46 _was_newline = 1; // so we indent the first line
49 _Tt_ostream::_Tt_ostream(
59 _Tt_ostream::_Tt_ostream(
69 _Tt_ostream::~_Tt_ostream()
74 _Tt_ostream::operator =(
84 _Tt_ostream::operator =(
94 _Tt_ostream::operator <<(
103 _Tt_ostream::operator <<(
112 _Tt_ostream::operator <<(
121 _Tt_ostream::operator <<(
125 *this << _tt_enumname( status );
130 _Tt_ostream::operator <<(
131 Tt_callback_action val
134 *this << _tt_enumname( val );
139 _Tt_ostream::operator <<(
144 ::sprintf( buf, "0x%p", p );
150 _Tt_ostream::operator <<(
159 // If no indenting and no newlines...
161 if ((_indent.len() <= 0) && (strchr( s, '\n' ) == 0)) {
163 // ... just blast the whole string
169 *_s = (*_s).cat( s );
175 // XXX - Inefficient.
176 // The string either has a newline in it, or indents is > 0,
177 // so deal with it on a per-character basis.
179 while (*pc != '\0') {
187 _Tt_ostream::operator <<(
192 if (_indent.len() > 0) {
193 if (_was_newline == 1) {
200 if (_indent.len() > 0) {
201 if (_was_newline == 1) {
202 *_s = (*_s).cat( _indent );
205 *_s = (*_s).cat( c );
209 ((_Tt_ostream *) this)->_was_newline = 1;
211 ((_Tt_ostream *) this)->_was_newline = 0;
218 _Tt_ostream::operator <<(
223 ::sprintf( buf, "%d", n );
228 #if defined(__osf__) || defined(linux) || defined(CSRG_BASED)
229 /* This operator is being added to take care of uid_t and gid_t
232 _Tt_ostream::operator <<(
237 ::sprintf( buf, "%u", n );
244 _Tt_ostream::operator <<(
249 ::sprintf( buf, "%ld", n );
255 _Tt_ostream::operator <<(
260 ::sprintf( buf, "%lu", n );
267 _Tt_object_printfn print_it,
268 const _Tt_object *obj
271 (*print_it)( *this, obj );
276 _Tt_ostream::sprintf(
283 char *buf = (char *)malloc( maxlen + 1 );
287 va_start( args, format );
288 int val = vsprintf( buf, format, args );
298 _Tt_ostream::set_indent(
299 const _Tt_string &new_indent
302 _Tt_ostream *nonconst_this = (_Tt_ostream *)this;
303 nonconst_this->_indent = new_indent;