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