Changes in src/libcfa/fstream.c [6152c81:0583064b]
- File:
-
- 1 edited
-
src/libcfa/fstream.c (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/libcfa/fstream.c
r6152c81 r0583064b 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : T ue Mar 7 14:48:09201713 // Update Count : 19212 // Last Modified On : Thu Mar 23 08:20:41 2017 13 // Update Count : 226 14 14 // 15 15 … … 25 25 #include <complex.h> // creal, cimag 26 26 } 27 #include "assert" 27 28 28 29 #define IO_MSG "I/O error: " 30 31 void ?{}( ofstream * this, void * file, _Bool sepDefault, _Bool sepOnOff, const char * separator, const char * tupleSeparator ) { 32 this->file = file; 33 this->sepDefault = sepDefault; 34 this->sepOnOff = sepOnOff; 35 sepSet( this, separator ); 36 sepSetCur( this, sepGet( this ) ); 37 sepSetTuple( this, tupleSeparator ); 38 } 29 39 30 40 _Bool sepPrt( ofstream * os ) { return os->sepOnOff; } … … 33 43 void sepReset( ofstream * os ) { os->sepOnOff = os->sepDefault; } 34 44 void sepReset( ofstream * os, _Bool reset ) { os->sepDefault = reset; os->sepOnOff = os->sepDefault; } 35 const char * sepGet( ofstream * os ) { return &(os->separator[0]); } 45 46 const char * sepGetCur( ofstream * os ) { return os->sepCur; } 47 void sepSetCur( ofstream * os, const char * sepCur ) { os->sepCur = sepCur; } 48 49 const char * sepGet( ofstream * os ) { return os->separator; } 36 50 37 51 void sepSet( ofstream * os, const char * s ) { 38 strncpy( &(os->separator[0]), s, separateSize - 1 ); 52 assert( s ); 53 strncpy( os->separator, s, separateSize - 1 ); 39 54 os->separator[separateSize - 1] = '\0'; 55 } // sepSet 56 57 const char * sepGetTuple( ofstream * os ) { return os->tupleSeparator; } 58 59 void sepSetTuple( ofstream * os, const char * s ) { 60 assert( s ); 61 strncpy( os->tupleSeparator, s, separateSize - 1 ); 62 os->tupleSeparator[separateSize - 1] = '\0'; 40 63 } // sepSet 41 64 … … 69 92 exit( EXIT_FAILURE ); 70 93 } // if 71 os->file = file; 72 sepOff( os ); 73 sepSet( os, " " ); 94 ?{}( os, file, 1, 0, " ", ", " ); 74 95 } // open 75 96 … … 95 116 } // write 96 117 97 int prtfmt( ofstream * os, const char fmt[], ... ) {118 int fmt( ofstream * os, const char format[], ... ) { 98 119 va_list args; 99 va_start( args, f mt );100 int len = vfprintf( (FILE *)(os->file), f mt, args );120 va_start( args, format ); 121 int len = vfprintf( (FILE *)(os->file), format, args ); 101 122 if ( len == EOF ) { 102 123 if ( ferror( (FILE *)(os->file) ) ) { … … 109 130 sepReset( os ); // reset separator 110 131 return len; 111 } // prtfmt 112 113 114 static ofstream soutFile = { (FILE *)(&_IO_2_1_stdout_), 1, 0, { ' ', '\0' } }; 132 } // fmt 133 134 static ofstream soutFile = { (FILE *)(&_IO_2_1_stdout_), 1, 0, " ", ", " }; 115 135 ofstream *sout = &soutFile; 116 static ofstream serrFile = { (FILE *)(&_IO_2_1_stderr_), 1, 0, { ' ', '\0' }};136 static ofstream serrFile = { (FILE *)(&_IO_2_1_stderr_), 1, 0, " ", ", " }; 117 137 ofstream *serr = &serrFile; 118 138 … … 173 193 } // ungetc 174 194 175 int scanfmt( ifstream * is, const char fmt[], ... ) {195 int fmt( ifstream * is, const char format[], ... ) { 176 196 va_list args; 177 197 178 va_start( args, f mt );179 int len = vfscanf( (FILE *)(is->file), f mt, args );198 va_start( args, format ); 199 int len = vfscanf( (FILE *)(is->file), format, args ); 180 200 if ( len == EOF ) { 181 201 if ( ferror( (FILE *)(is->file) ) ) { … … 186 206 va_end( args ); 187 207 return len; 188 } // prtfmt208 } // fmt 189 209 190 210
Note:
See TracChangeset
for help on using the changeset viewer.