Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/libcfa/fstream.c

    r6152c81 r0583064b  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Mar  7 14:48:09 2017
    13 // Update Count     : 192
     12// Last Modified On : Thu Mar 23 08:20:41 2017
     13// Update Count     : 226
    1414//
    1515
     
    2525#include <complex.h>                                                                    // creal, cimag
    2626}
     27#include "assert"
    2728
    2829#define IO_MSG "I/O error: "
     30
     31void ?{}( 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}
    2939
    3040_Bool sepPrt( ofstream * os ) { return os->sepOnOff; }
     
    3343void sepReset( ofstream * os ) { os->sepOnOff = os->sepDefault; }
    3444void sepReset( ofstream * os, _Bool reset ) { os->sepDefault = reset; os->sepOnOff = os->sepDefault; }
    35 const char * sepGet( ofstream * os ) { return &(os->separator[0]); }
     45
     46const char * sepGetCur( ofstream * os ) { return os->sepCur; }
     47void sepSetCur( ofstream * os, const char * sepCur ) { os->sepCur = sepCur; }
     48
     49const char * sepGet( ofstream * os ) { return os->separator; }
    3650
    3751void sepSet( ofstream * os, const char * s ) {
    38         strncpy( &(os->separator[0]), s, separateSize - 1 );
     52        assert( s );
     53        strncpy( os->separator, s, separateSize - 1 );
    3954        os->separator[separateSize - 1] = '\0';
     55} // sepSet
     56
     57const char * sepGetTuple( ofstream * os ) { return os->tupleSeparator; }
     58
     59void sepSetTuple( ofstream * os, const char * s ) {
     60        assert( s );
     61        strncpy( os->tupleSeparator, s, separateSize - 1 );
     62        os->tupleSeparator[separateSize - 1] = '\0';
    4063} // sepSet
    4164
     
    6992                exit( EXIT_FAILURE );
    7093        } // if
    71         os->file = file;
    72         sepOff( os );
    73         sepSet( os, " " );
     94        ?{}( os, file, 1, 0, " ", ", " );
    7495} // open
    7596
     
    95116} // write
    96117
    97 int prtfmt( ofstream * os, const char fmt[], ... ) {
     118int fmt( ofstream * os, const char format[], ... ) {
    98119        va_list args;
    99         va_start( args, fmt );
    100         int len = vfprintf( (FILE *)(os->file), fmt, args );
     120        va_start( args, format );
     121        int len = vfprintf( (FILE *)(os->file), format, args );
    101122        if ( len == EOF ) {
    102123                if ( ferror( (FILE *)(os->file) ) ) {
     
    109130        sepReset( os );                                                                         // reset separator
    110131        return len;
    111 } // prtfmt
    112 
    113 
    114 static ofstream soutFile = { (FILE *)(&_IO_2_1_stdout_), 1, 0, { ' ', '\0' } };
     132} // fmt
     133
     134static ofstream soutFile = { (FILE *)(&_IO_2_1_stdout_), 1, 0, " ", ", " };
    115135ofstream *sout = &soutFile;
    116 static ofstream serrFile = { (FILE *)(&_IO_2_1_stderr_), 1, 0, { ' ', '\0' } };
     136static ofstream serrFile = { (FILE *)(&_IO_2_1_stderr_), 1, 0, " ", ", " };
    117137ofstream *serr = &serrFile;
    118138
     
    173193} // ungetc
    174194
    175 int scanfmt( ifstream * is, const char fmt[], ... ) {
     195int fmt( ifstream * is, const char format[], ... ) {
    176196        va_list args;
    177197
    178         va_start( args, fmt );
    179         int len = vfscanf( (FILE *)(is->file), fmt, args );
     198        va_start( args, format );
     199        int len = vfscanf( (FILE *)(is->file), format, args );
    180200        if ( len == EOF ) {
    181201                if ( ferror( (FILE *)(is->file) ) ) {
     
    186206        va_end( args );
    187207        return len;
    188 } // prtfmt
     208} // fmt
    189209
    190210
Note: See TracChangeset for help on using the changeset viewer.