Changes in / [96f01d7f:172a88d]


Ignore:
Location:
libcfa/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/fstream.cfa

    r96f01d7f r172a88d  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Oct  1 08:10:21 2021
    13 // Update Count     : 473
     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 // private
    31 void ?{}( ofstream & os, void * file ) with( os ) {
     30void ?{}( ofstream & os, void * file ) with(os) {
    3231        file$ = file;
    3332        sepDefault$ = true;
     
    4241} // ?{}
    4342
    44 inline bool sepPrt$( ofstream & os ) { setNL$( os, false ); return os.sepOnOff$; }
    45 inline void sepReset$( ofstream & os ) { os.sepOnOff$ = os.sepDefault$; }
    46 inline void sepReset$( ofstream & os, bool reset ) { os.sepDefault$ = reset; os.sepOnOff$ = os.sepDefault$; }
    47 inline const char * sepGetCur$( ofstream & os ) { return os.sepCur$; }
    48 inline void sepSetCur$( ofstream & os, const char sepCur[] ) { os.sepCur$ = sepCur; }
    49 inline bool getNL$( ofstream & os ) { return os.sawNL$; }
    50 inline void setNL$( ofstream & os, bool state ) { os.sawNL$ = state; }
    51 inline bool getANL$( ofstream & os ) { return os.nlOnOff$; }
    52 inline bool getPrt$( ofstream & os ) { return os.prt$; }
    53 inline void setPrt$( ofstream & os, bool state ) { os.prt$ = state; }
    54 
    55 inline void lock( ofstream & os ) with( os ) {  lock( os.lock$ ); }
    56 inline void unlock( ofstream & os ) { unlock( os.lock$ ); }
     43// private
     44bool sepPrt$( ofstream & os ) { setNL$( os, false ); return os.sepOnOff$; }
     45void sepReset$( ofstream & os ) { os.sepOnOff$ = os.sepDefault$; }
     46void sepReset$( ofstream & os, bool reset ) { os.sepDefault$ = reset; os.sepOnOff$ = os.sepDefault$; }
     47const char * sepGetCur$( ofstream & os ) { return os.sepCur$; }
     48void sepSetCur$( ofstream & os, const char sepCur[] ) { os.sepCur$ = sepCur; }
     49bool getNL$( ofstream & os ) { return os.sawNL$; }
     50void setNL$( ofstream & os, bool state ) { os.sawNL$ = state; }
     51bool getANL$( ofstream & os ) { return os.nlOnOff$; }
     52bool getPrt$( ofstream & os ) { return os.prt$; }
     53void setPrt$( ofstream & os, bool state ) { os.prt$ = state; }
    5754
    5855// public
    5956void ?{}( ofstream & os ) { os.file$ = 0p; }
    60 void ?{}( ofstream & os, const char name[], const char mode[] ) { open( os, name, mode ); }
    61 void ?{}( ofstream & os, const char name[] ) { open( os, name, "w" ); }
    62 void ^?{}( ofstream & os ) { close( os ); }
     57
     58void ?{}( ofstream & os, const char name[], const char mode[] ) {
     59        open( os, name, mode );
     60} // ?{}
     61
     62void ?{}( ofstream & os, const char name[] ) {
     63        open( os, name, "w" );
     64} // ?{}
     65
     66void ^?{}( ofstream & os ) {
     67        close( os );
     68} // ^?{}
    6369
    6470void sepOn( ofstream & os ) { os.sepOnOff$ = ! getNL$( os ); }
     
    101107        if ( &os == &exit ) exit( EXIT_FAILURE );
    102108        if ( &os == &abort ) abort();
    103         if ( os.acquired$ ) { os.acquired$ = false; unlock( os ); }
     109        if ( os.acquired$ ) { os.acquired$ = false; release( os ); }
    104110} // ends
    105111
    106 bool fail( ofstream & os ) { return os.file$ == 0 || ferror( (FILE *)(os.file$) ); }
    107 void clear( ofstream & os ) { clearerr( (FILE *)(os.file$) ); }
    108 int flush( ofstream & os ) { return fflush( (FILE *)(os.file$) ); }
     112bool fail( ofstream & os ) {
     113        return os.file$ == 0 || ferror( (FILE *)(os.file$) );
     114} // fail
     115
     116void clear( ofstream & os ) {
     117        clearerr( (FILE *)(os.file$) );
     118} // clear
     119
     120int flush( ofstream & os ) {
     121        return fflush( (FILE *)(os.file$) );
     122} // flush
    109123
    110124void open( ofstream & os, const char name[], const char mode[] ) {
     
    117131} // open
    118132
    119 void open( ofstream & os, const char name[] ) { open( os, name, "w" ); }
    120 
    121 void close( ofstream & os ) with( os ) {
     133void open( ofstream & os, const char name[] ) {
     134        open( os, name, "w" );
     135} // open
     136
     137void close( ofstream & os ) with(os) {
    122138  if ( (FILE *)(file$) == 0p ) return;
    123139  if ( (FILE *)(file$) == (FILE *)stdout || (FILE *)(file$) == (FILE *)stderr ) return;
     
    127143                // abort | IO_MSG "close output" | nl | strerror( errno );
    128144        } // if
    129         file$ = 0p;                                                                                     // safety after close
     145        file$ = 0p;
    130146} // close
    131147
     
    159175} // fmt
    160176
    161 void acquire( ofstream & os ) with( os ) {
    162         lock( os );                                                                                     // may increase recursive lock
     177inline void acquire( ofstream & os ) with(os) {
     178        lock( lock$ );                                                                          // may increase recursive lock
    163179        if ( ! acquired$ ) acquired$ = true;                            // not locked ?
    164         else unlock( os );                                                                      // unwind recursive lock at start
     180        else unlock( lock$ );                                                           // unwind recursive lock at start
    165181} // acquire
    166182
    167 void ?{}( osacquire & acq, ofstream & os ) { &acq.os = &os; lock( os ); }
    168 void ^?{}( osacquire & acq ) { unlock( acq.os ); }
     183inline void release( ofstream & os ) {
     184        unlock( os.lock$ );
     185} // release
     186
     187void ?{}( osacquire & acq, ofstream & os ) { lock( os.lock$ ); &acq.os = &os; }
     188void ^?{}( osacquire & acq ) { release( acq.os ); }
    169189
    170190static ofstream soutFile = { (FILE *)stdout };
     
    185205        flush( os );
    186206        return os;
     207        // (ofstream &)(os | '\n');
     208        // setPrt$( os, false );                                                        // turn off
     209        // setNL$( os, true );
     210        // flush( os );
     211        // return sepOff( os );                                                 // prepare for next line
    187212} // nl
    188213
     
    192217
    193218// private
    194 void ?{}( ifstream & is, void * file ) with( is ) {
     219void ?{}( ifstream & is, void * file ) with(is) {
    195220        file$ = file;
    196221        nlOnOff$ = false;
     
    198223} // ?{}
    199224
    200 inline void lock( ifstream & os ) with( os ) { lock( os.lock$ ); }
    201 inline void unlock( ifstream & os ) { unlock( os.lock$ ); }
    202 
    203225// public
    204226void ?{}( ifstream & is ) { is.file$ = 0p; }
    205 void ?{}( ifstream & is, const char name[], const char mode[] ) { open( is, name, mode ); }
    206 void ?{}( ifstream & is, const char name[] ) { open( is, name, "r" ); }
    207 void ^?{}( ifstream & is ) { close( is ); }
     227
     228void ?{}( ifstream & is, const char name[], const char mode[] ) {
     229        open( is, name, mode );
     230} // ?{}
     231
     232void ?{}( ifstream & is, const char name[] ) {
     233        open( is, name, "r" );
     234} // ?{}
     235
     236void ^?{}( ifstream & is ) {
     237        close( is );
     238} // ^?{}
    208239
    209240void nlOn( ifstream & os ) { os.nlOnOff$ = true; }
     
    211242bool getANL( ifstream & os ) { return os.nlOnOff$; }
    212243
    213 bool fail( ifstream & is ) { return is.file$ == 0p || ferror( (FILE *)(is.file$) ); }
    214 void clear( ifstream & is ) { clearerr( (FILE *)(is.file$) ); }
     244bool fail( ifstream & is ) {
     245        return is.file$ == 0p || ferror( (FILE *)(is.file$) );
     246} // fail
     247
     248void clear( ifstream & is ) {
     249        clearerr( (FILE *)(is.file$) );
     250} // clear
    215251
    216252void ends( ifstream & is ) {
    217         if ( is.acquired$ ) { is.acquired$ = false; unlock( is ); }
     253        if ( is.acquired$ ) { is.acquired$ = false; release( is ); }
    218254} // ends
    219255
    220 bool eof( ifstream & is ) { return feof( (FILE *)(is.file$) ); }
     256bool eof( ifstream & is ) {
     257        return feof( (FILE *)(is.file$) );
     258} // eof
    221259
    222260void open( ifstream & is, const char name[], const char mode[] ) {
     
    229267} // open
    230268
    231 void open( ifstream & is, const char name[] ) { open( is, name, "r" ); }
    232 
    233 void close( ifstream & is ) with( is ) {
     269void open( ifstream & is, const char name[] ) {
     270        open( is, name, "r" );
     271} // open
     272
     273void close( ifstream & is ) with(is) {
    234274  if ( (FILE *)(file$) == 0p ) return;
    235275  if ( (FILE *)(file$) == (FILE *)stdin ) return;
     
    280320} // fmt
    281321
    282 void acquire( ifstream & is ) with( is ) {
    283         lock( is );                                                                                     // may increase recursive lock
     322inline void acquire( ifstream & is ) with(is) {
     323        lock( lock$ );                                                                          // may increase recursive lock
    284324        if ( ! acquired$ ) acquired$ = true;                            // not locked ?
    285         else unlock( is );                                                                      // unwind recursive lock at start
     325        else unlock( lock$ );                                                           // unwind recursive lock at start
    286326} // acquire
    287327
    288 void ?{}( isacquire & acq, ifstream & is ) { &acq.is = &is; lock( is ); }
    289 void ^?{}( isacquire & acq ) { unlock( acq.is ); }
     328inline void release( ifstream & is ) {
     329        unlock( is.lock$ );
     330} // release
     331
     332void ?{}( isacquire & acq, ifstream & is ) { lock( is.lock$ ); &acq.is = &is; }
     333void ^?{}( isacquire & acq ) { release( acq.is ); }
    290334
    291335static ifstream sinFile = { (FILE *)stdin };
  • libcfa/src/fstream.hfa

    r96f01d7f r172a88d  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Oct  1 07:40:37 2021
    13 // Update Count     : 238
     12// Last Modified On : Wed Jul 28 07:35:50 2021
     13// Update Count     : 234
    1414//
    1515
     
    5353void setPrt$( ofstream &, bool );
    5454
    55 void lock( ofstream & );
    56 void unlock( ofstream & );
    57 
    5855// public
    5956void sepOn( ofstream & );
     
    8178
    8279void acquire( ofstream & );
     80void release( ofstream & );
     81
     82void lock( ofstream & );
     83void unlock( ofstream & );
    8384
    8485struct osacquire {
     
    113114
    114115// Satisfies istream
    115 
    116 // private
    117 void lock( ifstream & );
    118 void unlock( ifstream & );
    119116
    120117// public
     
    135132
    136133void acquire( ifstream & is );
     134void release( ifstream & is );
    137135
    138136struct isacquire {
Note: See TracChangeset for help on using the changeset viewer.