Ignore:
Timestamp:
Sep 24, 2021, 6:13:46 PM (4 years ago)
Author:
caparsons <caparson@…>
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.
Message:

fixed merge

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/fstream.cfa

    r7e7a076 rf93c50a  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Jul 29 22:34:10 2021
    13 // Update Count     : 454
     12// Last Modified On : Tue Sep 21 21:51:38 2021
     13// Update Count     : 460
    1414//
    1515
     
    2828#define IO_MSG "I/O error: "
    2929
    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;
     30void ?{}( 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;
    3838        sepSetCur$( os, sepGet( os ) );
    3939        sepSet( os, " " );
     
    124124void open( ofstream & os, const char name[], const char mode[] ) {
    125125        FILE * file = fopen( name, mode );
    126         // #ifdef __CFA_DEBUG__
    127126        if ( file == 0p ) {
    128127                throw (Open_Failure){ os };
    129128                // abort | IO_MSG "open output file \"" | name | "\"" | nl | strerror( errno );
    130129        } // if
    131         // #endif // __CFA_DEBUG__
    132         (os){ file };
     130        (os){ file };                                                                           // initialize
    133131} // open
    134132
     
    137135} // open
    138136
    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 ) {
     137void 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 ) {
    144142                throw (Close_Failure){ os };
    145143                // abort | IO_MSG "close output" | nl | strerror( errno );
    146144        } // if
    147         os.file$ = 0p;
     145        file$ = 0p;
    148146} // close
    149147
     
    177175} // fmt
    178176
    179 inline void acquire( ofstream & os ) {
    180         lock( os.lock$ );
    181         if ( ! os.acquired$ ) os.acquired$ = true;
    182         else unlock( os.lock$ );
     177inline 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
    183181} // acquire
    184182
     
    187185} // release
    188186
    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$ ); }
     187void ?{}( osacquire & acq, ofstream & os ) { lock( os.lock$ ); &acq.os = &os; }
    193188void ^?{}( osacquire & acq ) { release( acq.os ); }
    194189
     
    222217
    223218// private
    224 void ?{}( ifstream & is, void * file ) {
    225         is.file$ = file;
    226         is.nlOnOff$ = false;
    227         is.acquired$ = false;
     219void ?{}( ifstream & is, void * file ) with(is) {
     220        file$ = file;
     221        nlOnOff$ = false;
     222        acquired$ = false;
    228223} // ?{}
    229224
     
    265260void open( ifstream & is, const char name[], const char mode[] ) {
    266261        FILE * file = fopen( name, mode );
    267         // #ifdef __CFA_DEBUG__
    268262        if ( file == 0p ) {
    269263                throw (Open_Failure){ is };
    270264                // abort | IO_MSG "open input file \"" | name | "\"" | nl | strerror( errno );
    271265        } // if
    272         // #endif // __CFA_DEBUG__
    273         is.file$ = file;
     266        (is){ file };                                                                           // initialize
    274267} // open
    275268
     
    278271} // open
    279272
    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 ) {
     273void 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 ) {
    285278                throw (Close_Failure){ is };
    286279                // abort | IO_MSG "close input" | nl | strerror( errno );
    287280        } // if
    288         is.file$ = 0p;
     281        file$ = 0p;
    289282} // close
    290283
     
    327320} // fmt
    328321
    329 inline void acquire( ifstream & is ) {
    330         lock( is.lock$ );
    331         if ( ! is.acquired$ ) is.acquired$ = true;
    332         else unlock( is.lock$ );
     322inline 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
    333326} // acquire
    334327
     
    337330} // release
    338331
    339 void ?{}( isacquire & acq, ifstream & is ) { &acq.is = &is; lock( is.lock$ ); }
     332void ?{}( isacquire & acq, ifstream & is ) { lock( is.lock$ ); &acq.is = &is; }
    340333void ^?{}( isacquire & acq ) { release( acq.is ); }
    341334
     
    350343
    351344// exception I/O constructors
    352 void ?{}( Open_Failure & this, ofstream & ostream ) {
    353         this.virtual_table = &Open_Failure_vt;
    354         this.ostream = &ostream;
    355         this.tag = 1;
    356 } // ?{}
    357 
    358 void ?{}( Open_Failure & this, ifstream & istream ) {
    359         this.virtual_table = &Open_Failure_vt;
    360         this.istream = &istream;
    361         this.tag = 0;
     345void ?{}( Open_Failure & ex, ofstream & ostream ) with(ex) {
     346        virtual_table = &Open_Failure_vt;
     347        ostream = &ostream;
     348        tag = 1;
     349} // ?{}
     350
     351void ?{}( Open_Failure & ex, ifstream & istream ) with(ex) {
     352        virtual_table = &Open_Failure_vt;
     353        istream = &istream;
     354        tag = 0;
    362355} // ?{}
    363356
     
    366359
    367360// exception I/O constructors
    368 void ?{}( Close_Failure & this, ofstream & ostream ) {
    369         this.virtual_table = &Close_Failure_vt;
    370         this.ostream = &ostream;
    371         this.tag = 1;
    372 } // ?{}
    373 
    374 void ?{}( Close_Failure & this, ifstream & istream ) {
    375         this.virtual_table = &Close_Failure_vt;
    376         this.istream = &istream;
    377         this.tag = 0;
     361void ?{}( Close_Failure & ex, ofstream & ostream ) with(ex) {
     362        virtual_table = &Close_Failure_vt;
     363        ostream = &ostream;
     364        tag = 1;
     365} // ?{}
     366
     367void ?{}( Close_Failure & ex, ifstream & istream ) with(ex) {
     368        virtual_table = &Close_Failure_vt;
     369        istream = &istream;
     370        tag = 0;
    378371} // ?{}
    379372
     
    382375
    383376// exception I/O constructors
    384 void ?{}( Write_Failure & this, ofstream & ostream ) {
    385         this.virtual_table = &Write_Failure_vt;
    386         this.ostream = &ostream;
    387         this.tag = 1;
    388 } // ?{}
    389 
    390 void ?{}( Write_Failure & this, ifstream & istream ) {
    391         this.virtual_table = &Write_Failure_vt;
    392         this.istream = &istream;
    393         this.tag = 0;
     377void ?{}( Write_Failure & ex, ofstream & ostream ) with(ex) {
     378        virtual_table = &Write_Failure_vt;
     379        ostream = &ostream;
     380        tag = 1;
     381} // ?{}
     382
     383void ?{}( Write_Failure & ex, ifstream & istream ) with(ex) {
     384        virtual_table = &Write_Failure_vt;
     385        istream = &istream;
     386        tag = 0;
    394387} // ?{}
    395388
     
    398391
    399392// exception I/O constructors
    400 void ?{}( Read_Failure & this, ofstream & ostream ) {
    401         this.virtual_table = &Read_Failure_vt;
    402         this.ostream = &ostream;
    403         this.tag = 1;
    404 } // ?{}
    405 
    406 void ?{}( Read_Failure & this, ifstream & istream ) {
    407         this.virtual_table = &Read_Failure_vt;
    408         this.istream = &istream;
    409         this.tag = 0;
     393void ?{}( Read_Failure & ex, ofstream & ostream ) with(ex) {
     394        virtual_table = &Read_Failure_vt;
     395        ostream = &ostream;
     396        tag = 1;
     397} // ?{}
     398
     399void ?{}( Read_Failure & ex, ifstream & istream ) with(ex) {
     400        virtual_table = &Read_Failure_vt;
     401        istream = &istream;
     402        tag = 0;
    410403} // ?{}
    411404
Note: See TracChangeset for help on using the changeset viewer.