Changeset f93c50a for libcfa/src/fstream.cfa
- Timestamp:
- Sep 24, 2021, 6:13:46 PM (4 years ago)
- Branches:
- ADT, ast-experimental, enum, forall-pointer-decay, master, pthread-emulation, qualifiedEnum
- Children:
- 166b384
- Parents:
- 7e7a076 (diff), 9411cf0 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)links above to see all the changes relative to each parent. - File:
-
- 1 edited
-
libcfa/src/fstream.cfa (modified) (15 diffs)
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/fstream.cfa
r7e7a076 rf93c50a 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : T hu Jul 29 22:34:10202113 // Update Count : 4 5412 // Last Modified On : Tue Sep 21 21:51:38 2021 13 // Update Count : 460 14 14 // 15 15 … … 28 28 #define IO_MSG "I/O error: " 29 29 30 void ?{}( ofstream & os, void * file ) {31 os.file$ = file;32 os.sepDefault$ = true;33 os.sepOnOff$ = false;34 os.nlOnOff$ = true;35 os.prt$ = false;36 os.sawNL$ = false;37 os.acquired$ = false;30 void ?{}( ofstream & os, void * file ) with(os) { 31 file$ = file; 32 sepDefault$ = true; 33 sepOnOff$ = false; 34 nlOnOff$ = true; 35 prt$ = false; 36 sawNL$ = false; 37 acquired$ = false; 38 38 sepSetCur$( os, sepGet( os ) ); 39 39 sepSet( os, " " ); … … 124 124 void open( ofstream & os, const char name[], const char mode[] ) { 125 125 FILE * file = fopen( name, mode ); 126 // #ifdef __CFA_DEBUG__127 126 if ( file == 0p ) { 128 127 throw (Open_Failure){ os }; 129 128 // abort | IO_MSG "open output file \"" | name | "\"" | nl | strerror( errno ); 130 129 } // if 131 // #endif // __CFA_DEBUG__ 132 (os){ file }; 130 (os){ file }; // initialize 133 131 } // open 134 132 … … 137 135 } // open 138 136 139 void close( ofstream & os ) {140 if ( (FILE *)( os.file$) == 0p ) return;141 if ( (FILE *)( os.file$) == (FILE *)stdout || (FILE *)(os.file$) == (FILE *)stderr ) return;142 143 if ( fclose( (FILE *)( os.file$) ) == EOF ) {137 void close( ofstream & os ) with(os) { 138 if ( (FILE *)(file$) == 0p ) return; 139 if ( (FILE *)(file$) == (FILE *)stdout || (FILE *)(file$) == (FILE *)stderr ) return; 140 141 if ( fclose( (FILE *)(file$) ) == EOF ) { 144 142 throw (Close_Failure){ os }; 145 143 // abort | IO_MSG "close output" | nl | strerror( errno ); 146 144 } // if 147 os.file$ = 0p;145 file$ = 0p; 148 146 } // close 149 147 … … 177 175 } // fmt 178 176 179 inline void acquire( ofstream & os ) {180 lock( os.lock$ );181 if ( ! os.acquired$ ) os.acquired$ = true;182 else unlock( os.lock$ );177 inline void acquire( ofstream & os ) with(os) { 178 lock( lock$ ); // may increase recursive lock 179 if ( ! acquired$ ) acquired$ = true; // not locked ? 180 else unlock( lock$ ); // unwind recursive lock at start 183 181 } // acquire 184 182 … … 187 185 } // release 188 186 189 inline void lock( ofstream & os ) { acquire( os ); } 190 inline void unlock( ofstream & os ) { release( os ); } 191 192 void ?{}( osacquire & acq, ofstream & os ) { &acq.os = &os; lock( os.lock$ ); } 187 void ?{}( osacquire & acq, ofstream & os ) { lock( os.lock$ ); &acq.os = &os; } 193 188 void ^?{}( osacquire & acq ) { release( acq.os ); } 194 189 … … 222 217 223 218 // private 224 void ?{}( ifstream & is, void * file ) {225 is.file$ = file;226 is.nlOnOff$ = false;227 is.acquired$ = false;219 void ?{}( ifstream & is, void * file ) with(is) { 220 file$ = file; 221 nlOnOff$ = false; 222 acquired$ = false; 228 223 } // ?{} 229 224 … … 265 260 void open( ifstream & is, const char name[], const char mode[] ) { 266 261 FILE * file = fopen( name, mode ); 267 // #ifdef __CFA_DEBUG__268 262 if ( file == 0p ) { 269 263 throw (Open_Failure){ is }; 270 264 // abort | IO_MSG "open input file \"" | name | "\"" | nl | strerror( errno ); 271 265 } // if 272 // #endif // __CFA_DEBUG__ 273 is.file$ = file; 266 (is){ file }; // initialize 274 267 } // open 275 268 … … 278 271 } // open 279 272 280 void close( ifstream & is ) {281 if ( (FILE *)( is.file$) == 0p ) return;282 if ( (FILE *)( is.file$) == (FILE *)stdin ) return;283 284 if ( fclose( (FILE *)( is.file$) ) == EOF ) {273 void close( ifstream & is ) with(is) { 274 if ( (FILE *)(file$) == 0p ) return; 275 if ( (FILE *)(file$) == (FILE *)stdin ) return; 276 277 if ( fclose( (FILE *)(file$) ) == EOF ) { 285 278 throw (Close_Failure){ is }; 286 279 // abort | IO_MSG "close input" | nl | strerror( errno ); 287 280 } // if 288 is.file$ = 0p;281 file$ = 0p; 289 282 } // close 290 283 … … 327 320 } // fmt 328 321 329 inline void acquire( ifstream & is ) {330 lock( is.lock$ );331 if ( ! is.acquired$ ) is.acquired$ = true;332 else unlock( is.lock$ );322 inline void acquire( ifstream & is ) with(is) { 323 lock( lock$ ); // may increase recursive lock 324 if ( ! acquired$ ) acquired$ = true; // not locked ? 325 else unlock( lock$ ); // unwind recursive lock at start 333 326 } // acquire 334 327 … … 337 330 } // release 338 331 339 void ?{}( isacquire & acq, ifstream & is ) { &acq.is = &is; lock( is.lock$ ); }332 void ?{}( isacquire & acq, ifstream & is ) { lock( is.lock$ ); &acq.is = &is; } 340 333 void ^?{}( isacquire & acq ) { release( acq.is ); } 341 334 … … 350 343 351 344 // exception I/O constructors 352 void ?{}( Open_Failure & this, ofstream & ostream) {353 this.virtual_table = &Open_Failure_vt;354 this.ostream = &ostream;355 t his.tag = 1;356 } // ?{} 357 358 void ?{}( Open_Failure & this, ifstream & istream) {359 this.virtual_table = &Open_Failure_vt;360 this.istream = &istream;361 t his.tag = 0;345 void ?{}( Open_Failure & ex, ofstream & ostream ) with(ex) { 346 virtual_table = &Open_Failure_vt; 347 ostream = &ostream; 348 tag = 1; 349 } // ?{} 350 351 void ?{}( Open_Failure & ex, ifstream & istream ) with(ex) { 352 virtual_table = &Open_Failure_vt; 353 istream = &istream; 354 tag = 0; 362 355 } // ?{} 363 356 … … 366 359 367 360 // exception I/O constructors 368 void ?{}( Close_Failure & this, ofstream & ostream) {369 this.virtual_table = &Close_Failure_vt;370 this.ostream = &ostream;371 t his.tag = 1;372 } // ?{} 373 374 void ?{}( Close_Failure & this, ifstream & istream) {375 this.virtual_table = &Close_Failure_vt;376 this.istream = &istream;377 t his.tag = 0;361 void ?{}( Close_Failure & ex, ofstream & ostream ) with(ex) { 362 virtual_table = &Close_Failure_vt; 363 ostream = &ostream; 364 tag = 1; 365 } // ?{} 366 367 void ?{}( Close_Failure & ex, ifstream & istream ) with(ex) { 368 virtual_table = &Close_Failure_vt; 369 istream = &istream; 370 tag = 0; 378 371 } // ?{} 379 372 … … 382 375 383 376 // exception I/O constructors 384 void ?{}( Write_Failure & this, ofstream & ostream) {385 this.virtual_table = &Write_Failure_vt;386 this.ostream = &ostream;387 t his.tag = 1;388 } // ?{} 389 390 void ?{}( Write_Failure & this, ifstream & istream) {391 this.virtual_table = &Write_Failure_vt;392 this.istream = &istream;393 t his.tag = 0;377 void ?{}( Write_Failure & ex, ofstream & ostream ) with(ex) { 378 virtual_table = &Write_Failure_vt; 379 ostream = &ostream; 380 tag = 1; 381 } // ?{} 382 383 void ?{}( Write_Failure & ex, ifstream & istream ) with(ex) { 384 virtual_table = &Write_Failure_vt; 385 istream = &istream; 386 tag = 0; 394 387 } // ?{} 395 388 … … 398 391 399 392 // exception I/O constructors 400 void ?{}( Read_Failure & this, ofstream & ostream) {401 this.virtual_table = &Read_Failure_vt;402 this.ostream = &ostream;403 t his.tag = 1;404 } // ?{} 405 406 void ?{}( Read_Failure & this, ifstream & istream) {407 this.virtual_table = &Read_Failure_vt;408 this.istream = &istream;409 t his.tag = 0;393 void ?{}( Read_Failure & ex, ofstream & ostream ) with(ex) { 394 virtual_table = &Read_Failure_vt; 395 ostream = &ostream; 396 tag = 1; 397 } // ?{} 398 399 void ?{}( Read_Failure & ex, ifstream & istream ) with(ex) { 400 virtual_table = &Read_Failure_vt; 401 istream = &istream; 402 tag = 0; 410 403 } // ?{} 411 404
Note:
See TracChangeset
for help on using the changeset viewer.