1 /* Copyright 1994, 1995 LongView Technologies L.L.C. $Revision: 1.16 $ */
2 /* Copyright (c) 2006, Sun Microsystems, Inc.
5 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
6 following conditions are met:
8 * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
9 * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
10 disclaimer in the documentation and/or other materials provided with the distribution.
11 * Neither the name of Sun Microsystems nor the names of its contributors may be used to endorse or promote products derived
12 from this software without specific prior written permission.
14 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
15 NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
16 THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
17 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
18 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
19 OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
24 # include "incls/_precompiled.incl"
25 # include "incls/_ostream.cpp.incl"
27 outputStream::outputStream(int width
) {
33 void outputStream::basic_print(char* str
) {
34 int len
= strlen(str
);
35 for (int i
= 0; i
< len
; i
++) put(str
[i
]);
38 #define BUFLEN 2000 /* max size of output of individual print() methods */
40 void outputStream::print(char* format
, ...) {
44 if (_vsnprintf(buffer
, BUFLEN
, format
, ap
) < 0) {
45 warning("increase BUFLEN in ostream.cpp -- output truncated");
52 void outputStream::print_cr(char* format
, ...) {
56 if (_vsnprintf(buffer
, BUFLEN
, format
, ap
) < 0) {
57 warning("increase BUFLEN in ostream.cpp -- output truncated");
65 void outputStream::vprint(const char *format
, va_list argptr
) {
67 if (_vsnprintf(buffer
, BUFLEN
, format
, argptr
) < 0) {
68 warning("increase BUFLEN in ostream.cpp -- output truncated");
74 void outputStream::vprint_cr(const char* format
, va_list argptr
) {
75 vprint(format
, argptr
);
79 void outputStream::fill_to(int col
) {
80 while (position() < col
) sp();
83 void outputStream::put(char c
) {
88 void outputStream::out_hex(int addr
) {
92 void outputStream::sp() {
96 void outputStream::cr() {
101 void outputStream::indent() {
102 while (_position
< _indentation
) sp();
105 stringStream::stringStream(int initial_size
) : outputStream() {
106 buffer_length
= initial_size
;
107 buffer
= NEW_RESOURCE_ARRAY(char, buffer_length
);
111 void stringStream::put(char c
) {
112 if (buffer_pos
>= buffer_length
) {
113 // grow string buffer
114 char* oldbuf
= buffer
;
115 buffer
= NEW_RESOURCE_ARRAY(char, buffer_length
* 2);
116 strncpy(buffer
, oldbuf
, buffer_length
);
119 buffer
[buffer_pos
++] = c
;
123 char* stringStream::as_string() {
124 buffer
[buffer_pos
] = '\0';
125 char* copy
= NEW_RESOURCE_ARRAY(char, buffer_pos
+ 1);
126 strcpy(copy
, buffer
);
130 byteArrayOop
stringStream::as_byteArray() {
131 byteArrayOop a
= oopFactory::new_byteArray(buffer_pos
);
132 for (int i
= 0; i
< buffer_pos
; i
++) {
133 a
->byte_at_put(i
+1, buffer
[i
]);
138 fileStream::fileStream(char* file_name
) {
139 _file
= fopen(file_name
, "w");
142 void fileStream::put(char c
) {
147 fileStream::~fileStream() {
155 void ostream_init() {
156 std
= new(true) outputStream(); // NB: this stream is allocated on the C heap