Changeset d395012 for src


Ignore:
Timestamp:
Jul 1, 2017, 5:24:03 PM (7 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
86f384b
Parents:
b0f7a43
Message:

support separator at end of line

Location:
src
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • src/libcfa/fstream

    rb0f7a43 rd395012  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon May 15 18:11:09 2017
    13 // Update Count     : 104
     12// Last Modified On : Sat Jul  1 16:37:53 2017
     13// Update Count     : 112
    1414//
    1515
     
    2424        _Bool sepDefault;
    2525        _Bool sepOnOff;
     26        _Bool lastSepOn;
    2627        const char * sepCur;
    2728        char separator[separateSize];
     
    3536const char * sepGetCur( ofstream * );
    3637void sepSetCur( ofstream *, const char * );
     38_Bool lastSepOn( ofstream * );
    3739
    3840// public
  • src/libcfa/fstream.c

    rb0f7a43 rd395012  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon May 15 18:11:11 2017
    13 // Update Count     : 234
     12// Last Modified On : Sat Jul  1 16:37:54 2017
     13// Update Count     : 242
    1414//
    1515
     
    3333        this->sepDefault = sepDefault;
    3434        this->sepOnOff = sepOnOff;
     35        this->lastSepOn = false;
    3536        sepSet( this, separator );
    3637        sepSetCur( this, sepGet( this ) );
     
    3940
    4041// private
    41 _Bool sepPrt( ofstream * os ) { return os->sepOnOff; }
     42_Bool lastSepOn( ofstream * os ) { return os->lastSepOn; }
     43_Bool sepPrt( ofstream * os ) { os->lastSepOn = false; return os->sepOnOff; }
    4244void sepReset( ofstream * os ) { os->sepOnOff = os->sepDefault; }
    4345void sepReset( ofstream * os, _Bool reset ) { os->sepDefault = reset; os->sepOnOff = os->sepDefault; }
     
    4648
    4749// public
    48 void sepOn( ofstream * os ) { os->sepOnOff = 1; }
    49 void sepOff( ofstream * os ) { os->sepOnOff = 0; }
     50void sepOn( ofstream * os ) { os->lastSepOn = true; os->sepOnOff = true; }
     51void sepOff( ofstream * os ) { os->lastSepOn = false; os->sepOnOff = 0; }
    5052
    5153_Bool sepDisable( ofstream *os ) {
    5254        _Bool temp = os->sepDefault;
    5355        os->sepDefault = false;
     56        os->lastSepOn = false;
    5457        sepReset( os );
    5558        return temp;
     
    9295                exit( EXIT_FAILURE );
    9396        } // if
    94         ?{}( os, file, 1, 0, " ", ", " );
     97        ?{}( os, file, true, false, " ", ", " );
    9598} // open
    9699
     
    132135} // fmt
    133136
    134 static ofstream soutFile = { (FILE *)(&_IO_2_1_stdout_), 1, 0, " ", ", " };
     137static ofstream soutFile = { (FILE *)(&_IO_2_1_stdout_), true, false, " ", ", " };
    135138ofstream *sout = &soutFile;
    136 static ofstream serrFile = { (FILE *)(&_IO_2_1_stderr_), 1, 0, " ", ", " };
     139static ofstream serrFile = { (FILE *)(&_IO_2_1_stderr_), true, false, " ", ", " };
    137140ofstream *serr = &serrFile;
    138141
  • src/libcfa/iostream

    rb0f7a43 rd395012  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon May 15 18:08:44 2017
    13 // Update Count     : 105
     12// Last Modified On : Sat Jul  1 16:37:52 2017
     13// Update Count     : 108
    1414//
    1515
     
    3131        _Bool sepDisable( ostype * );                                           // set default state to off, and return previous state
    3232        _Bool sepEnable( ostype * );                                            // set default state to on, and return previous state
     33        _Bool lastSepOn( ostype * );                                            // last manipulator is setOn (context sensitive)
    3334
    3435        const char * sepGet( ostype * );                                        // get separator string
  • src/libcfa/iostream.c

    rb0f7a43 rd395012  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon May  8 18:24:23 2017
    13 // Update Count     : 369
     12// Last Modified On : Sat Jul  1 16:37:51 2017
     13// Update Count     : 374
    1414//
    1515
     
    217217forall( dtype ostype | ostream( ostype ) )
    218218ostype * endl( ostype * os ) {
     219        if ( lastSepOn( os ) ) fmt( os, "%s", sepGetCur( os ) );
    219220        os | '\n';
    220221        flush( os );
  • src/tests/.expect/io.txt

    rb0f7a43 rd395012  
    55
    66x (1 x [2 x {3 x =4 x $5 x £6 x ¥7 x ¡8 x ¿9 x «10
    7 1, x 2. x 3; x 4! x 5? x 6% x 7¢ x 8» x 9) x 10] x 11} x
     71, x 2. x 3; x 4! x 5? x 6% x 7¢ x 8» x 9) x 10] x 11} x 
    88x`1`x'2'x"3"x:4:x 5 x   6       x
    997
     
    1414x
    151510
    16 x
     16x 
    1717x ( 1 ) x 2 , x 3 :x: 4
    1818A
     
    23231.11.21.3
    24241.1+2.3i1.1-2.3i1.1-2.3i
    25  abcxyz
    26 abcxyz
     25 abcxyz 
     26abcxyz 
    2727
    28281.1, $1.2, $1.3
    29291.1+2.3i, $1.1-2.3i, $1.1-2.3i
    30 abc, $xyz
     30abc, $xyz, $
    3131
    32321, 2, 3, 4
     33
    33341, $2, $3 ", $"
    34351 2 3 " "
     36
     37 1 2 3
     3812 3
    3539 1 2 3
    36 12 3
     401 2 3
     41 1 2 3
     42
    3743123
    38441 23
    39451 2 3
     46123
     471 2 3
     48123
     491 2 3
     50
    40511 2 3 4 " "
    41521, 2, 3, 4 ", "
    42531, 2, 3, 4
     54
    43553, 4, a, 7.2
    44563, 4, a, 7.2
  • src/tests/io.c

    rb0f7a43 rd395012  
    1010// Created On       : Wed Mar  2 16:56:02 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Jun  8 09:52:10 2017
    13 // Update Count     : 51
     12// Last Modified On : Sat Jul  1 16:21:07 2017
     13// Update Count     : 58
    1414//
    1515
     
    108108        [int, int] t1 = [1, 2], t2 = [3, 4];
    109109        sout | t1 | t2 | endl;                                                          // print tuple
     110        sout | endl;
    110111
    111112        sepSet( sout, " " );
     
    114115        sepSet( sout, " " );                                                            // reset separator to " "
    115116        sout | 1 | 2 | 3 | " \"" | sepGet( sout ) | "\"" | endl;
     117        sout | endl;
    116118
    117         sout | sepOn | 1 | 2 | 3 | sepOn | endl;                        // separator at start of line
     119        sout | sepOn | 1 | 2 | 3 | sepOn | endl;                        // separator at start/end of line
    118120        sout | 1 | sepOff | 2 | 3 | endl;                                       // locally turn off implicit separator
     121        sout | sepOn | 1 | 2 | 3 | sepOn | sepOff | endl;       // separator at start of line
     122        sout | 1 | 2 | 3 | endl | sepOn;                                        // separator at start of next line
     123        sout | 1 | 2 | 3 | endl;
     124        sout | endl;
    119125
    120126        sout | sepDisable | 1 | 2 | 3 | endl;                           // globally turn off implicit separation
    121127        sout | 1 | sepOn | 2 | 3 | endl;                                        // locally turn on implicit separator
    122         sout | sepEnable | 1 | 2 | 3 | endl;                            // globally turn on implicit separation
     128        sout | sepEnable | 1 | 2 | 3 | endl | sepDisable;       // globally turn on/off implicit separation
     129        sout | 1 | 2 | 3 | endl | sepEnable;                            // globally turn on implicit separation
     130        sout | 1 | 2 | 3 | sepOn | sepDisable | endl;           // ignore seperate at end of line
     131        sout | 1 | 2 | 3 | sepOn | sepEnable | endl;            // separator at end of line
     132        sout | 1 | 2 | 3 | endl;
     133        sout | endl;
    123134
    124135        sepSetTuple( sout, " " );                                                       // set tuple separator from ", " to " "
     
    126137        sepSetTuple( sout, ", " );                                                      // reset tuple separator to ", "
    127138        sout | t1 | t2 | " \"" | sepGetTuple( sout ) | "\"" | endl;
    128 
    129139        sout | t1 | t2 | endl;                                                          // print tuple
     140        sout | endl;
    130141
    131142        [int, int, const char *, double] t3 = { 3, 4, "a", 7.2 };
Note: See TracChangeset for help on using the changeset viewer.