Ignore:
Timestamp:
May 2, 2016, 3:28:16 PM (9 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
1b7ea43
Parents:
1f6e009 (diff), e945826 (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:

Merge branch 'master' into global-init

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/libcfa/fstream.c

    r1f6e009 r1048b31  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Feb 29 18:41:10 2016
    13 // Update Count     : 162
     12// Last Modified On : Wed Apr 27 18:20:30 2016
     13// Update Count     : 187
    1414//
    1515
     
    2525}
    2626
    27 #define IO_MSG "I/O error "
     27#define IO_MSG "I/O error: "
    2828
    29 _Bool sepPrt( ofstream * os ) { return os->separate == 1; }
    30 void sepOn( ofstream * os ) { if ( os->separate != 2 ) os->separate = 1; }
    31 void sepOff( ofstream * os ) { if ( os->separate != 2 ) os->separate = 0; }
     29_Bool sepPrt( ofstream * os ) { return os->sepOnOff; }
     30void sepOn( ofstream * os ) { os->sepOnOff = 1; }
     31void sepOff( ofstream * os ) { os->sepOnOff = 0; }
     32void sepReset( ofstream * os ) { os->sepOnOff = os->sepDefault; }
     33void sepReset( ofstream * os, _Bool reset ) { os->sepDefault = reset; os->sepOnOff = os->sepDefault; }
    3234void sepSet( ofstream * os, const char * s ) {
    3335        strncpy( &(os->separator[0]), s, separateSize - 1 );
     
    3537} // sepSet
    3638const char * sepGet( ofstream * os ) { return &(os->separator[0]); }
    37 void sepDisable( ofstream *os ) { os->separate = 2; }
    38 void sepEnable( ofstream *os ) { os->separate = 0; }
     39_Bool sepDisable( ofstream *os ) {
     40        _Bool temp = os->sepDefault;
     41        os->sepDefault = 0;
     42        sepReset( os );
     43        return temp;
     44} // sepDisable
     45_Bool sepEnable( ofstream *os ) {
     46        _Bool temp = os->sepDefault;
     47        os->sepDefault = 1;
     48        sepReset( os );
     49        return temp;
     50} // sepEnable
    3951
    4052int fail( ofstream * os ) {
     
    4961        FILE *file = fopen( name, mode );
    5062        if ( file == 0 ) {                                                                      // do not change unless successful
    51                 perror( IO_MSG "open output" );
     63                fprintf( stderr, IO_MSG "open output file \"%s\", ", name );
     64                perror( 0 );
    5265                exit( EXIT_FAILURE );
    5366        } // if
     
    8093int prtfmt( ofstream * os, const char fmt[], ... ) {
    8194    va_list args;
    82 
    8395    va_start( args, fmt );
    8496    int len = vfprintf( (FILE *)(os->file), fmt, args );
     
    90102        } // if
    91103    va_end( args );
     104
     105        sepReset( os );                                                                         // reset separator
    92106        return len;
    93107} // prtfmt
    94108
    95109
    96 static ofstream soutFile = { (FILE *)(&_IO_2_1_stdout_), 0, { ' ', '\0' } };
     110static ofstream soutFile = { (FILE *)(&_IO_2_1_stdout_), 1, 0, { ' ', '\0' } };
    97111ofstream *sout = &soutFile;
    98 static ofstream serrFile = { (FILE *)(&_IO_2_1_stderr_), 0, { ' ', '\0' } };
     112static ofstream serrFile = { (FILE *)(&_IO_2_1_stderr_), 1, 0, { ' ', '\0' } };
    99113ofstream *serr = &serrFile;
    100114
     
    114128        FILE *t = fopen( name, mode );
    115129        if ( t == 0 ) {                                                                         // do not change unless successful
    116                 perror( IO_MSG "open input" );
     130                fprintf( stderr, IO_MSG "open input file \"%s\", ", name );
     131                perror( 0 );
    117132                exit( EXIT_FAILURE );
    118133        } // if
     
    175190// Local Variables: //
    176191// tab-width: 4 //
    177 // compile-command: "cfa fstream.c" //
    178192// End: //
Note: See TracChangeset for help on using the changeset viewer.