00001 /* Copyright 1994, 1995 LongView Technologies L.L.C. $Revision: 1.11 $ */ 00002 /* Copyright (c) 2006, Sun Microsystems, Inc. 00003 All rights reserved. 00004 00005 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the 00006 following conditions are met: 00007 00008 * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 00009 * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following 00010 disclaimer in the documentation and/or other materials provided with the distribution. 00011 * Neither the name of Sun Microsystems nor the names of its contributors may be used to endorse or promote products derived 00012 from this software without specific prior written permission. 00013 00014 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT 00015 NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 00016 THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00017 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00018 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 00019 OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE 00020 00021 00022 */ 00023 00024 // Output streams for printing 00025 00026 class outputStream : public ResourceObj { 00027 protected: 00028 int _indentation; // current indentation 00029 int _width; // width of the page 00030 int _position; // position on the current line 00031 00032 void basic_print(char* str); 00033 00034 public: 00035 // creation 00036 outputStream(int width = 80); 00037 00038 // indentation 00039 void indent(); 00040 void inc() { _indentation++; }; 00041 void dec() { _indentation--; }; 00042 int indentation() const { return _indentation; } 00043 void set_indentation(int i) { _indentation = i; } 00044 void fill_to(int col); 00045 00046 // sizing 00047 int width() const { return _width; } 00048 int position() const { return _position; } 00049 00050 // printing 00051 void print(char* format, ...); 00052 void print_cr(char* format, ...); 00053 00054 void vprint(const char *format, va_list argptr); 00055 void vprint_cr(const char* format, va_list argptr); 00056 00057 void print_raw(char* str) { basic_print(str); } 00058 void out_hex(int addr); 00059 00060 virtual void put(char c); 00061 virtual void sp(); 00062 virtual void cr(); 00063 00064 void dec_cr() { dec(); cr(); } 00065 void inc_cr() { inc(); cr(); } 00066 }; 00067 00068 // Standard output 00069 extern outputStream* std; 00070 00071 // Standard error 00072 extern outputStream* err; 00073 00074 class stringStream : public outputStream { 00075 protected: 00076 char* buffer; 00077 int buffer_pos; 00078 int buffer_length; 00079 public: 00080 stringStream(int initial_size = 1 * K); 00081 void put(char c); 00082 char* as_string(); 00083 00084 // Conversion into Delta object 00085 byteArrayOop as_byteArray(); 00086 }; 00087 00088 class fileStream : public outputStream { 00089 protected: 00090 FILE* _file; 00091 public: 00092 fileStream(char* file_name); 00093 ~fileStream(); 00094 int is_open() const { return _file != NULL; } 00095 void put(char c); 00096 }; 00097 00098 00099 00100