Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/libcfa/fstream.c

    r0583064b r6152c81  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Mar 23 08:20:41 2017
    13 // Update Count     : 226
     12// Last Modified On : Tue Mar  7 14:48:09 2017
     13// Update Count     : 192
    1414//
    1515
     
    2525#include <complex.h>                                                                    // creal, cimag
    2626}
    27 #include "assert"
    2827
    2928#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 }
    3929
    4030_Bool sepPrt( ofstream * os ) { return os->sepOnOff; }
     
    4333void sepReset( ofstream * os ) { os->sepOnOff = os->sepDefault; }
    4434void 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; }
     35const char * sepGet( ofstream * os ) { return &(os->separator[0]); }
    5036
    5137void sepSet( ofstream * os, const char * s ) {
    52         assert( s );
    53         strncpy( os->separator, s, separateSize - 1 );
     38        strncpy( &(os->separator[0]), s, separateSize - 1 );
    5439        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';
    6340} // sepSet
    6441
     
    9269                exit( EXIT_FAILURE );
    9370        } // if
    94         ?{}( os, file, 1, 0, " ", ", " );
     71        os->file = file;
     72        sepOff( os );
     73        sepSet( os, " " );
    9574} // open
    9675
     
    11695} // write
    11796
    118 int fmt( ofstream * os, const char format[], ... ) {
     97int prtfmt( ofstream * os, const char fmt[], ... ) {
    11998        va_list args;
    120         va_start( args, format );
    121         int len = vfprintf( (FILE *)(os->file), format, args );
     99        va_start( args, fmt );
     100        int len = vfprintf( (FILE *)(os->file), fmt, args );
    122101        if ( len == EOF ) {
    123102                if ( ferror( (FILE *)(os->file) ) ) {
     
    130109        sepReset( os );                                                                         // reset separator
    131110        return len;
    132 } // fmt
     111} // prtfmt
    133112
    134 static ofstream soutFile = { (FILE *)(&_IO_2_1_stdout_), 1, 0, " ", ", " };
     113
     114static ofstream soutFile = { (FILE *)(&_IO_2_1_stdout_), 1, 0, { ' ', '\0' } };
    135115ofstream *sout = &soutFile;
    136 static ofstream serrFile = { (FILE *)(&_IO_2_1_stderr_), 1, 0, " ", ", " };
     116static ofstream serrFile = { (FILE *)(&_IO_2_1_stderr_), 1, 0, { ' ', '\0' } };
    137117ofstream *serr = &serrFile;
    138118
     
    193173} // ungetc
    194174
    195 int fmt( ifstream * is, const char format[], ... ) {
     175int scanfmt( ifstream * is, const char fmt[], ... ) {
    196176        va_list args;
    197177
    198         va_start( args, format );
    199         int len = vfscanf( (FILE *)(is->file), format, args );
     178        va_start( args, fmt );
     179        int len = vfscanf( (FILE *)(is->file), fmt, args );
    200180        if ( len == EOF ) {
    201181                if ( ferror( (FILE *)(is->file) ) ) {
     
    206186        va_end( args );
    207187        return len;
    208 } // fmt
     188} // prtfmt
    209189
    210190
Note: See TracChangeset for help on using the changeset viewer.