Changeset 3bf3b6b for libcfa/src/fstream.cfa
- Timestamp:
- Sep 21, 2021, 9:59:03 PM (18 months ago)
- Branches:
- enum, forall-pointer-decay, master, pthread-emulation, qualifiedEnum
- Children:
- cf78319
- Parents:
- 6cc87c0
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/fstream.cfa
r6cc87c0 r3bf3b6b 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 void ?{}( osacquire & acq, ofstream & os ) { &acq.os = &os; lock( os.lock$ ); }187 void ?{}( osacquire & acq, ofstream & os ) { lock( os.lock$ ); &acq.os = &os; } 190 188 void ^?{}( osacquire & acq ) { release( acq.os ); } 191 189 … … 219 217 220 218 // private 221 void ?{}( ifstream & is, void * file ) {222 is.file$ = file;223 is.nlOnOff$ = false;224 is.acquired$ = false;219 void ?{}( ifstream & is, void * file ) with(is) { 220 file$ = file; 221 nlOnOff$ = false; 222 acquired$ = false; 225 223 } // ?{} 226 224 … … 262 260 void open( ifstream & is, const char name[], const char mode[] ) { 263 261 FILE * file = fopen( name, mode ); 264 // #ifdef __CFA_DEBUG__265 262 if ( file == 0p ) { 266 263 throw (Open_Failure){ is }; 267 264 // abort | IO_MSG "open input file \"" | name | "\"" | nl | strerror( errno ); 268 265 } // if 269 // #endif // __CFA_DEBUG__ 270 is.file$ = file; 266 (is){ file }; // initialize 271 267 } // open 272 268 … … 275 271 } // open 276 272 277 void close( ifstream & is ) {278 if ( (FILE *)( is.file$) == 0p ) return;279 if ( (FILE *)( is.file$) == (FILE *)stdin ) return;280 281 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 ) { 282 278 throw (Close_Failure){ is }; 283 279 // abort | IO_MSG "close input" | nl | strerror( errno ); 284 280 } // if 285 is.file$ = 0p;281 file$ = 0p; 286 282 } // close 287 283 … … 324 320 } // fmt 325 321 326 inline void acquire( ifstream & is ) {327 lock( is.lock$ );328 if ( ! is.acquired$ ) is.acquired$ = true;329 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 330 326 } // acquire 331 327 … … 334 330 } // release 335 331 336 void ?{}( isacquire & acq, ifstream & is ) { &acq.is = &is; lock( is.lock$ ); }332 void ?{}( isacquire & acq, ifstream & is ) { lock( is.lock$ ); &acq.is = &is; } 337 333 void ^?{}( isacquire & acq ) { release( acq.is ); } 338 334 … … 347 343 348 344 // exception I/O constructors 349 void ?{}( Open_Failure & this, ofstream & ostream) {350 this.virtual_table = &Open_Failure_vt;351 this.ostream = &ostream;352 t his.tag = 1;353 } // ?{} 354 355 void ?{}( Open_Failure & this, ifstream & istream) {356 this.virtual_table = &Open_Failure_vt;357 this.istream = &istream;358 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; 359 355 } // ?{} 360 356 … … 363 359 364 360 // exception I/O constructors 365 void ?{}( Close_Failure & this, ofstream & ostream) {366 this.virtual_table = &Close_Failure_vt;367 this.ostream = &ostream;368 t his.tag = 1;369 } // ?{} 370 371 void ?{}( Close_Failure & this, ifstream & istream) {372 this.virtual_table = &Close_Failure_vt;373 this.istream = &istream;374 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; 375 371 } // ?{} 376 372 … … 379 375 380 376 // exception I/O constructors 381 void ?{}( Write_Failure & this, ofstream & ostream) {382 this.virtual_table = &Write_Failure_vt;383 this.ostream = &ostream;384 t his.tag = 1;385 } // ?{} 386 387 void ?{}( Write_Failure & this, ifstream & istream) {388 this.virtual_table = &Write_Failure_vt;389 this.istream = &istream;390 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; 391 387 } // ?{} 392 388 … … 395 391 396 392 // exception I/O constructors 397 void ?{}( Read_Failure & this, ofstream & ostream) {398 this.virtual_table = &Read_Failure_vt;399 this.ostream = &ostream;400 t his.tag = 1;401 } // ?{} 402 403 void ?{}( Read_Failure & this, ifstream & istream) {404 this.virtual_table = &Read_Failure_vt;405 this.istream = &istream;406 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; 407 403 } // ?{} 408 404
Note: See TracChangeset
for help on using the changeset viewer.