00001 /* 00002 00003 Copyright (C) 2000, 2001 Silicon Graphics, Inc. All Rights Reserved. 00004 00005 This program is free software; you can redistribute it and/or modify it 00006 under the terms of version 2 of the GNU General Public License as 00007 published by the Free Software Foundation. 00008 00009 This program is distributed in the hope that it would be useful, but 00010 WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00012 00013 Further, this software is distributed without any warranty that it is 00014 free of the rightful claim of any third person regarding infringement 00015 or the like. Any license provided herein, whether implied or 00016 otherwise, applies only to this software file. Patent licenses, if 00017 any, provided herein do not apply to combinations of this program with 00018 other software, or any other product whatsoever. 00019 00020 You should have received a copy of the GNU General Public License along 00021 with this program; if not, write the Free Software Foundation, Inc., 59 00022 Temple Place - Suite 330, Boston MA 02111-1307, USA. 00023 00024 Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pky, 00025 Mountain View, CA 94043, or: 00026 00027 http://www.sgi.com 00028 00029 For further information regarding this notice, see: 00030 00031 http://oss.sgi.com/projects/GenInfo/NoticeExplan 00032 00033 */ 00034 00035 00036 /* -*-Mode: c++;-*- (Tell emacs to use c++ mode) */ 00037 #ifndef anl_file_mngr_INCLUDED 00038 #define anl_file_mngr_INCLUDED 00039 00040 // ============================================================== 00041 // ============================================================== 00042 // 00043 // Module: anl_file_mngr.h 00044 // $Revision: 1.1 $ 00045 // $Date: 2005/07/27 02:13:44 $ 00046 // $Author: kevinlo $ 00047 // $Source: /depot/CVSROOT/javi/src/sw/cmplr/be/prompf_anl/anl_file_mngr.h,v $ 00048 // 00049 // Description: 00050 // 00051 // A file handler, which reports error messages using an abstraction 00052 // named DIAGNOSTICS. The interface of DIAGNOSTICS is expected to 00053 // include the following: 00054 // 00055 // Warning: (char *) -> void 00056 // Error: (char *) -> void 00057 // Fatal: (char *) -> void 00058 // 00059 // where a Fatal call is not expected to return, but is expected to 00060 // terminate execution. An Error or a Warning will return. The state 00061 // after an error may not be as expected. 00062 // 00063 // This implementation is based on the <stdio.h> facilities and 00064 // exports only what we currently need. The interface can be 00065 // extended and generalized to fit any future needs. Intended 00066 // use for reading from a file (similar for writing to a file): 00067 // 00068 // ANL_FILE_MNGR file_mngr(diag); 00069 // file_mngr.Open_Read(filename); 00070 // while (!file_mngr.Error_Status() && !file_mngr.End_Of_File()) 00071 // { 00072 // char c = file_mngr.Read_Char(); 00073 // .... c ... 00074 // } 00075 // file_mngr.Close_File(); 00076 // 00077 // This abstraction does not buffer output beyond what is provided 00078 // by default through the <stdio.h> utilities, so any such buffering 00079 // must occur outside of this abstraction. Such buffering may be 00080 // desirable, since this abstraction will perform fairly extensive 00081 // tests on all IO operations. 00082 // 00083 // ============================================================== 00084 // ============================================================== 00085 00086 00087 class ANL_DIAGNOSTICS; 00088 00089 class ANL_FILE_MNGR 00090 { 00091 private: 00092 00093 ANL_DIAGNOSTICS *_diag; 00094 const char *_name; 00095 FILE *_file; 00096 INT32 _next_ch; 00097 00098 static const INT _obuf_size = 513; // Size of output buffer 00099 INT _next_obuf; // Next available char in _obuf 00100 char _obuf[_obuf_size+1]; // Output buffer 00101 00102 static void _Concat(char *buf, 00103 INT max_chars, 00104 const char *string[], 00105 INT num_strings); 00106 00107 static UINT64 _Get_Decimal_Number(INT ch); 00108 static UINT64 _Get_Hex_Number(INT ch); 00109 static BOOL _Exists(const char *name); 00110 00111 void _General_Check(BOOL c, const char *proc_name, const char *msg); 00112 void _Not_Open_Check(const char *proc_name, const char *to_be_opened); 00113 void _Is_Open_Check(const char *proc_name); 00114 void _Overwrite_Warning(const char *proc_name, const char *filename); 00115 void _Write_Obuf(); 00116 00117 public: 00118 00119 ANL_FILE_MNGR(ANL_DIAGNOSTICS *diag): 00120 _diag(diag), 00121 _name(NULL), 00122 _file(NULL), 00123 _next_ch(EOF), 00124 _next_obuf(0) 00125 {} 00126 00127 ~ANL_FILE_MNGR() { if (_file != NULL) Close_File(); } 00128 00129 void Open_Read(const char *name); 00130 void Open_Create(const char *name); 00131 void Open_Append(const char *name); 00132 void Close_File(); 00133 void Close_And_Remove_File(); 00134 00135 BOOL File_Is_Open() {return (_file != NULL);} 00136 BOOL End_Of_File() {return (_next_ch == EOF);} 00137 char Peek_Char() {return _next_ch;} // Does not alter stream ptr 00138 char Read_Char(); // Returns current char and advances stream ptr 00139 UINT64 Read_Uint64(BOOL as_hex = FALSE); 00140 UINT64 Read_Ptr() {return Read_Uint64(TRUE);} 00141 void Write_Char(char c); 00142 void Write_String(const char *s); 00143 void Flush_Write_Buffer() {if (_next_obuf > 0) _Write_Obuf();} 00144 00145 const char *Name() const {return _name;} 00146 FILE *File() {return _file;} 00147 00148 }; // ANL_FILE_MNGR 00149 00150 00151 #endif /* anl_file_mngr_INCLUDED */
1.5.6