Changeset 1048b31 for src/libcfa/fstream.c
- Timestamp:
- May 2, 2016, 3:28:16 PM (9 years ago)
- 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. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/libcfa/fstream.c
r1f6e009 r1048b31 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Feb 29 18:41:10 201613 // Update Count : 1 6212 // Last Modified On : Wed Apr 27 18:20:30 2016 13 // Update Count : 187 14 14 // 15 15 … … 25 25 } 26 26 27 #define IO_MSG "I/O error "27 #define IO_MSG "I/O error: " 28 28 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; } 30 void sepOn( ofstream * os ) { os->sepOnOff = 1; } 31 void sepOff( ofstream * os ) { os->sepOnOff = 0; } 32 void sepReset( ofstream * os ) { os->sepOnOff = os->sepDefault; } 33 void sepReset( ofstream * os, _Bool reset ) { os->sepDefault = reset; os->sepOnOff = os->sepDefault; } 32 34 void sepSet( ofstream * os, const char * s ) { 33 35 strncpy( &(os->separator[0]), s, separateSize - 1 ); … … 35 37 } // sepSet 36 38 const 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 39 51 40 52 int fail( ofstream * os ) { … … 49 61 FILE *file = fopen( name, mode ); 50 62 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 ); 52 65 exit( EXIT_FAILURE ); 53 66 } // if … … 80 93 int prtfmt( ofstream * os, const char fmt[], ... ) { 81 94 va_list args; 82 83 95 va_start( args, fmt ); 84 96 int len = vfprintf( (FILE *)(os->file), fmt, args ); … … 90 102 } // if 91 103 va_end( args ); 104 105 sepReset( os ); // reset separator 92 106 return len; 93 107 } // prtfmt 94 108 95 109 96 static ofstream soutFile = { (FILE *)(&_IO_2_1_stdout_), 0, { ' ', '\0' } };110 static ofstream soutFile = { (FILE *)(&_IO_2_1_stdout_), 1, 0, { ' ', '\0' } }; 97 111 ofstream *sout = &soutFile; 98 static ofstream serrFile = { (FILE *)(&_IO_2_1_stderr_), 0, { ' ', '\0' } };112 static ofstream serrFile = { (FILE *)(&_IO_2_1_stderr_), 1, 0, { ' ', '\0' } }; 99 113 ofstream *serr = &serrFile; 100 114 … … 114 128 FILE *t = fopen( name, mode ); 115 129 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 ); 117 132 exit( EXIT_FAILURE ); 118 133 } // if … … 175 190 // Local Variables: // 176 191 // tab-width: 4 // 177 // compile-command: "cfa fstream.c" //178 192 // End: //
Note:
See TracChangeset
for help on using the changeset viewer.