Changes in libcfa/src/fstream.cfa [5cb2b8c:a87d40b]
- File:
-
- 1 edited
-
libcfa/src/fstream.cfa (modified) (18 diffs)
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/fstream.cfa
r5cb2b8c ra87d40b 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu May 16 08:33:28201913 // Update Count : 3 2812 // Last Modified On : Mon Jul 15 18:11:26 2019 13 // Update Count : 349 14 14 // 15 15 … … 24 24 #include <assert.h> 25 25 #include <errno.h> // errno 26 27 28 //*********************************** ofstream *********************************** 29 26 30 27 31 #define IO_MSG "I/O error: " … … 37 41 sepSetCur( os, sepGet( os ) ); 38 42 sepSetTuple( os, ", " ); 39 } 43 } // ?{} 40 44 41 45 // private … … 56 60 void ?{}( ofstream & os, const char * name, const char * mode ) { 57 61 open( os, name, mode ); 58 } 62 } // ?{} 63 59 64 void ?{}( ofstream & os, const char * name ) { 60 65 open( os, name, "w" ); 61 } 66 } // ?{} 62 67 63 68 void sepOn( ofstream & os ) { os.sepOnOff = ! getNL( os ); } … … 95 100 } // sepSet 96 101 102 void ends( ofstream & os ) { 103 if ( getANL( os ) ) nl( os ); 104 else setPrt( os, false ); // turn off 105 if ( &os == &exit ) exit( EXIT_FAILURE ); 106 if ( &os == &abort ) abort(); 107 } // ends 108 97 109 int fail( ofstream & os ) { 98 110 return os.file == 0 || ferror( (FILE *)(os.file) ); … … 107 119 #ifdef __CFA_DEBUG__ 108 120 if ( file == 0 ) { 109 abort ( IO_MSG "open output file \"%s\", %s", name, strerror( errno ));121 abort | IO_MSG "open output file \"" | name | "\"" | nl | strerror( errno ); 110 122 } // if 111 123 #endif // __CFA_DEBUG__ … … 121 133 122 134 if ( fclose( (FILE *)(os.file) ) == EOF ) { 123 abort ( IO_MSG "close output %s", strerror( errno ));135 abort | IO_MSG "close output" | nl | strerror( errno ); 124 136 } // if 125 137 } // close … … 127 139 ofstream & write( ofstream & os, const char * data, size_t size ) { 128 140 if ( fail( os ) ) { 129 abort ( "attempt write I/O on failed stream\n" );141 abort | IO_MSG "attempt write I/O on failed stream"; 130 142 } // if 131 143 132 144 if ( fwrite( data, 1, size, (FILE *)(os.file) ) != size ) { 133 abort ( IO_MSG "write %s", strerror( errno ));145 abort | IO_MSG "write" | nl | strerror( errno ); 134 146 } // if 135 147 return os; … … 142 154 if ( len == EOF ) { 143 155 if ( ferror( (FILE *)(os.file) ) ) { 144 abort ( "invalid write\n" );156 abort | IO_MSG "invalid write"; 145 157 } // if 146 158 } // if … … 153 165 154 166 static ofstream soutFile = { (FILE *)(&_IO_2_1_stdout_) }; 155 ofstream & sout = soutFile ;167 ofstream & sout = soutFile, & stdout = soutFile; 156 168 static ofstream serrFile = { (FILE *)(&_IO_2_1_stderr_) }; 157 ofstream & serr = serrFile; 158 159 // static ofstream sexitFile = { (FILE *)(&_IO_2_1_stdout_) }; 160 // ofstream & sexit = sexitFile; 161 // static ofstream sabortFile = { (FILE *)(&_IO_2_1_stderr_) }; 162 // ofstream & sabort = sabortFile; 163 164 void nl( ofstream & os ) { 165 if ( getANL( os ) ) (ofstream &)(nl( os )); // implementation only 166 else setPrt( os, false ); // turn off 167 } 168 169 //--------------------------------------- 169 ofstream & serr = serrFile, & stderr = serrFile; 170 171 static ofstream exitFile = { (FILE *)(&_IO_2_1_stdout_) }; 172 ofstream & exit = exitFile; 173 static ofstream abortFile = { (FILE *)(&_IO_2_1_stderr_) }; 174 ofstream & abort = abortFile; 175 176 177 //*********************************** ifstream *********************************** 178 170 179 171 180 // private … … 173 182 is.file = file; 174 183 is.nlOnOff = false; 175 } 184 } // ?{} 176 185 177 186 // public … … 180 189 void ?{}( ifstream & is, const char * name, const char * mode ) { 181 190 open( is, name, mode ); 182 } 191 } // ?{} 192 183 193 void ?{}( ifstream & is, const char * name ) { 184 194 open( is, name, "r" ); 185 } 195 } // ?{} 186 196 187 197 void nlOn( ifstream & os ) { os.nlOnOff = true; } … … 201 211 #ifdef __CFA_DEBUG__ 202 212 if ( file == 0 ) { 203 abort ( IO_MSG "open input file \"%s\", %s\n", name, strerror( errno ));213 abort | IO_MSG "open input file \"" | name | "\"" | nl | strerror( errno ); 204 214 } // if 205 215 #endif // __CFA_DEBUG__ … … 215 225 216 226 if ( fclose( (FILE *)(is.file) ) == EOF ) { 217 abort ( IO_MSG "close input %s", strerror( errno ));227 abort | IO_MSG "close input" | nl | strerror( errno ); 218 228 } // if 219 229 } // close … … 221 231 ifstream & read( ifstream & is, char * data, size_t size ) { 222 232 if ( fail( is ) ) { 223 abort ( "attempt read I/O on failed stream\n" );233 abort | IO_MSG "attempt read I/O on failed stream"; 224 234 } // if 225 235 226 236 if ( fread( data, size, 1, (FILE *)(is.file) ) == 0 ) { 227 abort ( IO_MSG "read %s", strerror( errno ));237 abort | IO_MSG "read" | nl | strerror( errno ); 228 238 } // if 229 239 return is; … … 232 242 ifstream &ungetc( ifstream & is, char c ) { 233 243 if ( fail( is ) ) { 234 abort ( "attempt ungetc I/O on failed stream\n" );244 abort | IO_MSG "attempt ungetc I/O on failed stream"; 235 245 } // if 236 246 237 247 if ( ungetc( c, (FILE *)(is.file) ) == EOF ) { 238 abort ( IO_MSG "ungetc %s", strerror( errno ));248 abort | IO_MSG "ungetc" | nl | strerror( errno ); 239 249 } // if 240 250 return is; … … 248 258 if ( len == EOF ) { 249 259 if ( ferror( (FILE *)(is.file) ) ) { 250 abort ( "invalid read\n" );260 abort | IO_MSG "invalid read"; 251 261 } // if 252 262 } // if … … 257 267 258 268 static ifstream sinFile = { (FILE *)(&_IO_2_1_stdin_) }; 259 ifstream & sin = sinFile ;269 ifstream & sin = sinFile, & stdin = sinFile; 260 270 261 271 // Local Variables: //
Note:
See TracChangeset
for help on using the changeset viewer.