Changeset 53a6c2a


Ignore:
Timestamp:
Jul 7, 2017, 10:39:08 AM (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:
29038ef
Parents:
52a9004
Message:

change meaning of sepOn, and replace #if with #pragma once in include files

Files:
15 edited

Legend:

Unmodified
Added
Removed
  • doc/user/user.tex

    r52a9004 r53a6c2a  
    1111%% Created On       : Wed Apr  6 14:53:29 2016
    1212%% Last Modified By : Peter A. Buhr
    13 %% Last Modified On : Sun Jul  2 09:49:56 2017
    14 %% Update Count     : 2503
     13%% Last Modified On : Fri Jul  7 10:36:39 2017
     14%% Update Count     : 2547
    1515%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    1616
     
    24502450\end{cfa}
    24512451\\
    2452 \begin{cfa}[mathescape=off,showspaces=true,aboveskip=0pt,belowskip=0pt]
     2452\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
    245324531® ®2® ®3
    24542454\end{cfa}
    24552455&
    2456 \begin{cfa}[mathescape=off,showspaces=true,aboveskip=0pt,belowskip=0pt]
     2456\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
    245724571 2 3
    24582458\end{cfa}
     
    24612461The \CFA form has half the characters of the \CC form, and is similar to \Index*{Python} I/O with respect to implicit separators.
    24622462Similar simplification occurs for \Index{tuple} I/O, which prints all tuple values separated by ``\lstinline[showspaces=true]@, @''.
    2463 \begin{cfa}[mathescape=off,aboveskip=0pt,belowskip=0pt]
    2464 [int, [ int, int ] ] t1 = [ 1, [ 2, 3 ] ], t2 = [ 3, [ 4, 5 ] ];
     2463\begin{cfa}
     2464[int, [ int, int ] ] t1 = [ 1, [ 2, 3 ] ], t2 = [ 4, [ 5, 6 ] ];
    24652465sout | t1 | t2 | endl;                                  §\C{// print tuples}§
    24662466\end{cfa}
    2467 \begin{cfa}[mathescape=off,showspaces=true,belowskip=0pt]
    2468 1®, ®2®, ®3 3®, ®4®, ®5
     2467\begin{cfa}[showspaces=true,aboveskip=0pt]
     24681®, ®2®, ®3 4®, ®5®, ®6
    24692469\end{cfa}
    24702470Finally, \CFA uses the logical-or operator for I/O as it is the lowest-priority overloadable operator, other than assignment.
     
    24852485\\
    24862486&
    2487 \begin{cfa}[mathescape=off,showspaces=true,aboveskip=0pt,belowskip=0pt]
     2487\begin{cfa}[showspaces=true,aboveskip=0pt]
    248824883 3 12 0 3 1 2
    24892489\end{cfa}
     
    25032503sout | 1 | 2 | 3 | endl;
    25042504\end{cfa}
    2505 \begin{cfa}[mathescape=off,showspaces=true,aboveskip=0pt,belowskip=0pt]
     2505\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
    250625061 2 3
    25072507\end{cfa}
     
    25702570\subsection{Manipulator}
    25712571
    2572 The following routines and \CC-style \Index{manipulator}s control implicit seperation.
     2572The following \CC-style \Index{manipulator}s and routines control implicit seperation.
    25732573\begin{enumerate}
    25742574\item
    2575 Routines \Indexc{sepSet}\index{manipulator!sepSet@©sepSet©} and \Indexc{sepGet}\index{manipulator!sepGet@©sepGet©} set and get the separator string.
     2575Routines \Indexc{sepSet}\index{manipulator!sepSet@©sepSet©} and \Indexc{sep}\index{manipulator!sep@©sep©}/\Indexc{sepGet}\index{manipulator!sepGet@©sepGet©} set and get the separator string.
    25762576The separator string can be at most 16 characters including the ©'\0'© string terminator (15 printable characters).
    2577 \begin{cfa}[mathescape=off,aboveskip=0pt,belowskip=0pt]
     2577\begin{cfa}[mathescape=off,belowskip=0pt]
    25782578sepSet( sout, ", $" );                                          §\C{// set separator from " " to ", \$"}§
    2579 sout | 1 | 2 | 3 | " \"" | ®sepGet( sout )® | "\"" | endl;
     2579sout | 1 | 2 | 3 | " \"" | ®sep® | "\"" | endl;
    25802580\end{cfa}
    25812581%$
     
    25842584\end{cfa}
    25852585%$
    2586 \begin{cfa}[mathescape=off,aboveskip=0pt,belowskip=0pt]
     2586\begin{cfa}[belowskip=0pt]
    25872587sepSet( sout, " " );                                            §\C{// reset separator to " "}§
    25882588sout | 1 | 2 | 3 | " \"" | ®sepGet( sout )® | "\"" | endl;
    25892589\end{cfa}
    2590 \begin{cfa}[mathescape=off,showspaces=true,aboveskip=0pt]
     2590\begin{cfa}[showspaces=true,aboveskip=0pt]
    259125911® ®2® ®3 ®" "®
    25922592\end{cfa}
    2593 
    2594 \item
    2595 Routine \Indexc{sepSetTuple}\index{manipulator!sepSetTuple@©sepSetTuple©} and \Indexc{sepGetTuple}\index{manipulator!sepGetTuple@©sepGetTuple©} get and set the tuple separator-string.
     2593©sepGet© can be used to store a separator and then restore it:
     2594\begin{cfa}[belowskip=0pt]
     2595char store[®sepSize®];                                          §\C{// sepSize is the maximum separator size}§
     2596strcpy( store, sepGet( sout ) );
     2597sepSet( sout, "_" );
     2598sout | 1 | 2 | 3 | endl;
     2599\end{cfa}
     2600\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
     26011®_®2®_®3
     2602\end{cfa}
     2603\begin{cfa}[belowskip=0pt]
     2604sepSet( sout, store );
     2605sout | 1 | 2 | 3 | endl;
     2606\end{cfa}
     2607\begin{cfa}[showspaces=true,aboveskip=0pt]
     26081® ®2® ®3
     2609\end{cfa}
     2610
     2611\item
     2612Routine \Indexc{sepSetTuple}\index{manipulator!sepSetTuple@©sepSetTuple©} and \Indexc{sepTuple}\index{manipulator!sepTuple@©sepTuple©}/\Indexc{sepGetTuple}\index{manipulator!sepGetTuple@©sepGetTuple©} get and set the tuple separator-string.
    25962613The tuple separator-string can be at most 16 characters including the ©'\0'© string terminator (15 printable characters).
    2597 \begin{cfa}[mathescape=off,aboveskip=0pt,belowskip=0pt]
     2614\begin{cfa}[belowskip=0pt]
    25982615sepSetTuple( sout, " " );                                       §\C{// set tuple separator from ", " to " "}§
    2599 sout | t1 | t2 | " \"" | ®sepGetTuple( sout )® | "\"" | endl;
    2600 \end{cfa}
    2601 \begin{cfa}[mathescape=off,showspaces=true,aboveskip=0pt]
    2602 1 2 3 4 ®" "®
    2603 \end{cfa}
    2604 \begin{cfa}[mathescape=off,aboveskip=0pt,belowskip=0pt]
     2616sout | t1 | t2 | " \"" | ®sepTuple® | "\"" | endl;
     2617\end{cfa}
     2618\begin{cfa}[showspaces=true,aboveskip=0pt]
     26191 2 3 4 5 6 ®" "®
     2620\end{cfa}
     2621\begin{cfa}[belowskip=0pt]
    26052622sepSetTuple( sout, ", " );                                      §\C{// reset tuple separator to ", "}§
    26062623sout | t1 | t2 | " \"" | ®sepGetTuple( sout )® | "\"" | endl;
    26072624\end{cfa}
    2608 \begin{cfa}[mathescape=off,showspaces=true,aboveskip=0pt]
    2609 1, 2, 3, 4 ®", "®
    2610 \end{cfa}
    2611 
    2612 \item
    2613 Manipulators \Indexc{sepOn}\index{manipulator!sepOn@©sepOn©} and \Indexc{sepOff}\index{manipulator!sepOff@©sepOff©} \emph{locally} toggle printing the separator, \ie the seperator is adjusted only with respect to the next printed item.
    2614 \begin{cfa}[mathescape=off,belowskip=0pt]
    2615 sout | sepOn | 1 | 2 | 3 | sepOn | endl;        §\C{// separator at start/end of line}§
    2616 \end{cfa}
    2617 \begin{cfa}[mathescape=off,showspaces=true,aboveskip=0pt,belowskip=0pt]
    2618 ® ®1 2 3® ®
    2619 \end{cfa}
    2620 \begin{cfa}[mathescape=off,aboveskip=0pt,belowskip=0pt]
    2621 sout | 1 | sepOff | 2 | 3 | endl;                       §\C{// locally turn off implicit separator}§
    2622 \end{cfa}
    2623 \begin{cfa}[mathescape=off,showspaces=true,aboveskip=0pt,belowskip=0pt]
    2624 12 3
    2625 \end{cfa}
    2626 The tuple separator also responses to being turned on and off.
    2627 \begin{cfa}[mathescape=off,aboveskip=0pt,belowskip=0pt]
    2628 sout | sepOn | t1 | sepOff | t2 | endl;         §\C{// locally turn on/off implicit separation}§
    2629 \end{cfa}
    2630 \begin{cfa}[mathescape=off,showspaces=true,aboveskip=0pt,belowskip=0pt]
    2631 , 1, 23, 4
    2632 \end{cfa}
    2633 Notice a tuple seperator starts the line because the next item is a tuple.
    2634 
    2635 \item
    2636 Manipulators \Indexc{sepDisable}\index{manipulator!sepDisable@©sepDisable©} and \Indexc{sepEnable}\index{manipulator!sepEnable@©sepEnable©} \emph{globally} toggle printing the separator, \ie the seperator is adjusted with respect to all subsequent printed items, unless locally adjusted.
    2637 \begin{cfa}[mathescape=off,aboveskip=0pt,belowskip=0pt]
    2638 sout | sepDisable | 1 | 2 | 3 | endl;           §\C{// globally turn off implicit separation}§
    2639 \end{cfa}
    2640 \begin{cfa}[mathescape=off,showspaces=true,aboveskip=0pt,belowskip=0pt]
     2625\begin{cfa}[showspaces=true,aboveskip=0pt]
     26261, 2, 3 4, 5, 6 ®", "®
     2627\end{cfa}
     2628As for ©sepGet©, ©sepGetTuple© can be use to store a tuple separator and then restore it.
     2629
     2630\item
     2631Manipulators \Indexc{sepDisable}\index{manipulator!sepDisable@©sepDisable©} and \Indexc{sepEnable}\index{manipulator!sepEnable@©sepEnable©} \emph{globally} toggle printing the separator, \ie the seperator is adjusted with respect to all subsequent printed items.
     2632\begin{cfa}[belowskip=0pt]
     2633sout | sepDisable | 1 | 2 | 3 | endl;           §\C{// globally turn off implicit separator}§
     2634\end{cfa}
     2635\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
    26412636123
    26422637\end{cfa}
    2643 \begin{cfa}[mathescape=off,aboveskip=0pt,belowskip=0pt]
    2644 sout | 1 | ®sepOn® | 2 | 3 | endl;                      §\C{// locally turn on implicit separator}§
    2645 \end{cfa}
    2646 \begin{cfa}[mathescape=off,showspaces=true,aboveskip=0pt,belowskip=0pt]
    2647 1® ®23
    2648 \end{cfa}
    2649 \begin{cfa}[mathescape=off,aboveskip=0pt,belowskip=0pt]
    2650 sout | sepEnable | 1 | 2 | 3 | endl;            §\C{// globally turn on implicit separation}§
     2638\begin{cfa}[belowskip=0pt]
     2639sout | sepEnable | 1 | 2 | 3 | endl;            §\C{// globally turn on implicit separator}§
    26512640\end{cfa}
    26522641\begin{cfa}[mathescape=off,showspaces=true,aboveskip=0pt,belowskip=0pt]
    265326421 2 3
    26542643\end{cfa}
     2644
     2645\item
     2646Manipulators \Indexc{sepOn}\index{manipulator!sepOn@©sepOn©} and \Indexc{sepOff}\index{manipulator!sepOff@©sepOff©} \emph{locally} toggle printing the separator, \ie the seperator is adjusted only with respect to the next printed item.
     2647\begin{cfa}[belowskip=0pt]
     2648sout | 1 | sepOff | 2 | 3 | endl;                       §\C{// locally turn off implicit separator}§
     2649\end{cfa}
     2650\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
     265112 3
     2652\end{cfa}
     2653\begin{cfa}[belowskip=0pt]
     2654sout | sepDisable | 1 | sepOn | 2 | 3 | endl; §\C{// locally turn on implicit separator}§
     2655\end{cfa}
     2656\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
     26571 23
     2658\end{cfa}
     2659The tuple separator also responses to being turned on and off.
     2660\begin{cfa}[belowskip=0pt]
     2661sout | t1 | sepOff | t2 | endl;                         §\C{// locally turn on/off implicit separator}§
     2662\end{cfa}
     2663\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
     26641, 2, 34, 5, 6
     2665\end{cfa}
     2666©sepOn© \emph{cannot} be used to start/end a line with a separator because separators do not appear at the start/end of a line;
     2667use ©sep© to accomplish this functionality.
     2668\begin{cfa}[belowskip=0pt]
     2669sout | sepOn | 1 | 2 | 3 | sepOn | endl ;       §\C{// sepOn does nothing at start/end of line}§
     2670\end{cfa}
     2671\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
     26721 2 3
     2673\end{cfa}
     2674\begin{cfa}[belowskip=0pt]
     2675sout | sep | 1 | 2 | 3 | sep | endl ;           §\C{// use sep to print separator at start/end of line}§
     2676\end{cfa}
     2677\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
     2678® ®1 2 3® ®
     2679\end{cfa}
    26552680\end{enumerate}
    26562681
    26572682\begin{comment}
    26582683#include <fstream>
     2684#include <string.h>                                                                             // strcpy
    26592685
    26602686int main( void ) {
    26612687        int x = 1, y = 2, z = 3;
    26622688        sout | x | y | z | endl;
    2663         [int, [ int, int ] ] t1 = [ 1, [ 2, 3 ] ], t2 = [ 3, [ 4, 5 ] ];
     2689        [int, [ int, int ] ] t1 = [ 1, [ 2, 3 ] ], t2 = [ 4, [ 5, 6 ] ];
    26642690        sout | t1 | t2 | endl;                                          // print tuples
    26652691        sout | x * 3 | y + 1 | z << 2 | x == y | (x | y) | (x || y) | (x > z ? 1 : 2) | endl;
     
    26752701
    26762702        sepSet( sout, ", $" );                                          // set separator from " " to ", $"
    2677         sout | 1 | 2 | 3 | " \"" | sepGet( sout ) | "\"" | endl;
     2703        sout | 1 | 2 | 3 | " \"" | sep | "\"" | endl;
    26782704        sepSet( sout, " " );                                            // reset separator to " "
    26792705        sout | 1 | 2 | 3 | " \"" | sepGet( sout ) | "\"" | endl;
    26802706
    2681         sout | sepOn | 1 | 2 | 3 | sepOn | endl;        // separator at start of line
    2682         sout | 1 | sepOff | 2 | 3 | endl;                       // locally turn off implicit separator
    2683 
    2684         sout | sepDisable | 1 | 2 | 3 | endl;           // globally turn off implicit separation
    2685         sout | 1 | sepOn | 2 | 3 | endl;                        // locally turn on implicit separator
    2686         sout | sepEnable | 1 | 2 | 3 | endl;            // globally turn on implicit separation
     2707        char store[sepSize];
     2708        strcpy( store, sepGet( sout ) );
     2709        sepSet( sout, "_" );
     2710        sout | 1 | 2 | 3 | endl;
     2711        sepSet( sout, store );
     2712        sout | 1 | 2 | 3 | endl;
    26872713
    26882714        sepSetTuple( sout, " " );                                       // set tuple separator from ", " to " "
    2689         sout | t1 | t2 | " \"" | sepGetTuple( sout ) | "\"" | endl;
     2715        sout | t1 | t2 | " \"" | sepTuple | "\"" | endl;
    26902716        sepSetTuple( sout, ", " );                                      // reset tuple separator to ", "
    26912717        sout | t1 | t2 | " \"" | sepGetTuple( sout ) | "\"" | endl;
    26922718
    2693         sout | t1 | t2 | endl;                                          // print tuple
    2694         sout | sepOn | t1 | sepOff | t2 | endl;         // locally turn on/off implicit separation
     2719        sout | sepDisable | 1 | 2 | 3 | endl;           // globally turn off implicit separator
     2720        sout | sepEnable | 1 | 2 | 3 | endl;            // globally turn on implicit separator
     2721       
     2722        sout | 1 | sepOff | 2 | 3 | endl;                       // locally turn on implicit separator
     2723        sout | sepDisable | 1 | sepOn | 2 | 3 | endl; // globally turn off implicit separator
     2724        sout | sepEnable;
     2725        sout | t1 | sepOff | t2 | endl;                         // locally turn on/off implicit separator
     2726
     2727        sout | sepOn | 1 | 2 | 3 | sepOn | endl ;       // sepOn does nothing at start/end of line
     2728        sout | sep | 1 | 2 | 3 | sep | endl ;           // use sep to print separator at start/end of line
    26952729}
    26962730
     
    55485582// C unsafe allocation
    55495583extern "C" {
    5550 void * mallac( size_t size );§\indexc{memset}§
     5584void * malloc( size_t size );§\indexc{memset}§
    55515585void * calloc( size_t dim, size_t size );§\indexc{calloc}§
    55525586void * realloc( void * ptr, size_t size );§\indexc{realloc}§
  • src/libcfa/fstream

    r52a9004 r53a6c2a  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Jul  1 16:37:53 2017
    13 // Update Count     : 112
     12// Last Modified On : Fri Jul  7 08:32:38 2017
     13// Update Count     : 117
    1414//
    1515
    16 #ifndef __FSTREAM_H__
    17 #define __FSTREAM_H__
     16#pragma once
    1817
    1918#include "iostream"
    2019
    21 enum { separateSize = 16 };
     20enum { sepSize = 16 };
    2221struct ofstream {
    2322        void * file;
    2423        _Bool sepDefault;
    2524        _Bool sepOnOff;
    26         _Bool lastSepOn;
     25        _Bool sawNL;
    2726        const char * sepCur;
    28         char separator[separateSize];
    29         char tupleSeparator[separateSize];
     27        char separator[sepSize];
     28        char tupleSeparator[sepSize];
    3029}; // ofstream
    3130
     
    3635const char * sepGetCur( ofstream * );
    3736void sepSetCur( ofstream *, const char * );
    38 _Bool lastSepOn( ofstream * );
     37_Bool getNL( ofstream * );
     38void setNL( ofstream *, _Bool );
    3939
    4040// public
     
    7575extern ifstream * sin;
    7676
    77 #endif // __FSTREAM_H__
    78 
    7977// Local Variables: //
    8078// mode: c //
  • src/libcfa/fstream.c

    r52a9004 r53a6c2a  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Jul  1 16:37:54 2017
    13 // Update Count     : 242
     12// Last Modified On : Thu Jul  6 18:38:25 2017
     13// Update Count     : 251
    1414//
    1515
     
    3333        this->sepDefault = sepDefault;
    3434        this->sepOnOff = sepOnOff;
    35         this->lastSepOn = false;
    3635        sepSet( this, separator );
    3736        sepSetCur( this, sepGet( this ) );
     
    4039
    4140// private
    42 _Bool lastSepOn( ofstream * os ) { return os->lastSepOn; }
    43 _Bool sepPrt( ofstream * os ) { os->lastSepOn = false; return os->sepOnOff; }
     41_Bool sepPrt( ofstream * os ) { setNL( os, false ); return os->sepOnOff; }
    4442void sepReset( ofstream * os ) { os->sepOnOff = os->sepDefault; }
    4543void sepReset( ofstream * os, _Bool reset ) { os->sepDefault = reset; os->sepOnOff = os->sepDefault; }
    4644const char * sepGetCur( ofstream * os ) { return os->sepCur; }
    4745void sepSetCur( ofstream * os, const char * sepCur ) { os->sepCur = sepCur; }
     46_Bool getNL( ofstream * os ) { return os->sawNL; }
     47void setNL( ofstream * os, _Bool state ) { os->sawNL = state; }
    4848
    4949// public
    50 void sepOn( ofstream * os ) { os->lastSepOn = true; os->sepOnOff = true; }
    51 void sepOff( ofstream * os ) { os->lastSepOn = false; os->sepOnOff = 0; }
     50void sepOn( ofstream * os ) { os->sepOnOff = ! getNL( os ); }
     51void sepOff( ofstream * os ) { os->sepOnOff = false; }
    5252
    5353_Bool sepDisable( ofstream *os ) {
    5454        _Bool temp = os->sepDefault;
    5555        os->sepDefault = false;
    56         os->lastSepOn = false;
    5756        sepReset( os );
    5857        return temp;
     
    6968void sepSet( ofstream * os, const char * s ) {
    7069        assert( s );
    71         strncpy( os->separator, s, separateSize - 1 );
    72         os->separator[separateSize - 1] = '\0';
     70        strncpy( os->separator, s, sepSize - 1 );
     71        os->separator[sepSize - 1] = '\0';
    7372} // sepSet
    7473
     
    7675void sepSetTuple( ofstream * os, const char * s ) {
    7776        assert( s );
    78         strncpy( os->tupleSeparator, s, separateSize - 1 );
    79         os->tupleSeparator[separateSize - 1] = '\0';
     77        strncpy( os->tupleSeparator, s, sepSize - 1 );
     78        os->tupleSeparator[sepSize - 1] = '\0';
    8079} // sepSet
    8180
     
    153152
    154153void open( ifstream * is, const char * name, const char * mode ) {
    155         FILE *t = fopen( name, mode );
    156         if ( t == 0 ) {                                                                         // do not change unless successful
     154        FILE *file = fopen( name, mode );
     155        if ( file == 0 ) {                                                                      // do not change unless successful
    157156                fprintf( stderr, IO_MSG "open input file \"%s\", ", name );
    158157                perror( 0 );
    159158                exit( EXIT_FAILURE );
    160159        } // if
    161         is->file = t;
     160        is->file = file;
    162161} // open
    163162
  • src/libcfa/gmp

    r52a9004 r53a6c2a  
    1010// Created On       : Tue Apr 19 08:43:43 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat May 27 09:55:51 2017
    13 // Update Count     : 14
     12// Last Modified On : Fri Jul  7 09:33:20 2017
     13// Update Count     : 15
    1414//
    1515
    1616// https://gmplib.org/gmp-man-6.1.1.pdf
     17
     18#pragma once
    1719
    1820#include <gmp.h>                                                                                // GNU multi-precise integers
  • src/libcfa/iostream

    r52a9004 r53a6c2a  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun Jul  2 08:42:56 2017
    13 // Update Count     : 110
     12// Last Modified On : Fri Jul  7 08:35:59 2017
     13// Update Count     : 118
    1414//
    1515
    16 #ifndef __IOSTREAM_H__
    17 #define __IOSTREAM_H__
     16#pragma once
    1817
    1918#include "iterator"
     
    2625        const char * sepGetCur( ostype * );                                     // get current separator string
    2726        void sepSetCur( ostype *, const char * );                       // set current separator string
    28         _Bool lastSepOn( ostype * );                                            // last manipulator is setOn (context sensitive)
     27        _Bool getNL( ostype * );                                                        // check newline
     28        void setNL( ostype *, _Bool );                                          // saw newline
    2929        // public
    3030        void sepOn( ostype * );                                                         // turn separator state on
     
    8282forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, ostype * (*)( ostype * ) );
    8383forall( dtype ostype | ostream( ostype ) ) ostype * endl( ostype * );
     84forall( dtype ostype | ostream( ostype ) ) ostype * sep( ostype * );
     85forall( dtype ostype | ostream( ostype ) ) ostype * sepTuple( ostype * );
    8486forall( dtype ostype | ostream( ostype ) ) ostype * sepOn( ostype * );
    8587forall( dtype ostype | ostream( ostype ) ) ostype * sepOff( ostype * );
     
    137139forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, _Istream_cstrC );
    138140
    139 #endif // __IOSTREAM_H
    140 
    141141// Local Variables: //
    142142// mode: c //
  • src/libcfa/iostream.c

    r52a9004 r53a6c2a  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun Jul  2 08:54:02 2017
    13 // Update Count     : 375
     12// Last Modified On : Thu Jul  6 18:14:17 2017
     13// Update Count     : 396
    1414//
    1515
     
    1818extern "C" {
    1919#include <stdio.h>
     20#include <stdbool.h>                                                                    // true/false
    2021#include <string.h>                                                                             // strlen
    2122#include <float.h>                                                                              // DBL_DIG, LDBL_DIG
     
    2425
    2526forall( dtype ostype | ostream( ostype ) )
    26 ostype * ?|?( ostype * os, char c ) {
    27         fmt( os, "%c", c );
     27ostype * ?|?( ostype * os, char ch ) {
     28        fmt( os, "%c", ch );
     29        if ( ch == '\n' ) setNL( os, true );
    2830        sepOff( os );
    2931        return os;
     
    180182
    181183        // last character IS spacing or opening punctuation => turn off separator for next item
    182         unsigned int len = strlen( cp ), posn = len - 1;
    183         ch = cp[posn];                                                                          // must make unsigned
     184        size_t len = strlen( cp );
     185        ch = cp[len - 1];                                                                       // must make unsigned
    184186        if ( sepPrt( os ) && mask[ ch ] != Open && mask[ ch ] != OpenClose ) {
    185187                sepOn( os );
     
    187189                sepOff( os );
    188190        } // if
     191        if ( ch == '\n' ) setNL( os, true );                            // check *AFTER* sepPrt call above as it resets NL flag
    189192        return write( os, cp, len );
    190193} // ?|?
     
    216219
    217220forall( dtype ostype | ostream( ostype ) )
     221ostype * sep( ostype * os ) {
     222        os | sepGet( os );
     223        return os;
     224} // sep
     225
     226forall( dtype ostype | ostream( ostype ) )
     227ostype * sepTuple( ostype * os ) {
     228        os | sepGetTuple( os );
     229        return os;
     230} // sepTuple
     231
     232forall( dtype ostype | ostream( ostype ) )
    218233ostype * endl( ostype * os ) {
    219         if ( lastSepOn( os ) ) fmt( os, "%s", sepGetCur( os ) );
    220234        os | '\n';
     235        setNL( os, true );
    221236        flush( os );
    222237        sepOff( os );                                                                           // prepare for next line
  • src/libcfa/iterator

    r52a9004 r53a6c2a  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Mar  2 18:06:05 2016
    13 // Update Count     : 9
     12// Last Modified On : Fri Jul  7 08:37:25 2017
     13// Update Count     : 10
    1414//
    1515
    16 #ifndef ITERATOR_H
    17 #define ITERATOR_H
     16#pragma once
    1817
    1918// An iterator can be used to traverse a data structure.
     
    3938
    4039forall( otype iterator_type, otype elt_type | iterator( iterator_type, elt_type ) )
    41 void for_each( iterator_type begin, iterator_type end, void (*func)( elt_type ) );
     40void for_each( iterator_type begin, iterator_type end, void (* func)( elt_type ) );
    4241
    4342forall( otype iterator_type, otype elt_type | iterator( iterator_type, elt_type ) )
    44 void for_each_reverse( iterator_type begin, iterator_type end, void (*func)( elt_type ) );
    45 
    46 #endif // ITERATOR_H
     43void for_each_reverse( iterator_type begin, iterator_type end, void (* func)( elt_type ) );
    4744
    4845// Local Variables: //
  • src/libcfa/iterator.c

    r52a9004 r53a6c2a  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Mar  2 18:08:11 2016
    13 // Update Count     : 27
     12// Last Modified On : Fri Jul  7 08:38:23 2017
     13// Update Count     : 28
    1414//
    1515
     
    1717
    1818forall( otype iterator_type, otype elt_type | iterator( iterator_type, elt_type ) )
    19 void for_each( iterator_type begin, iterator_type end, void (*func)( elt_type ) ) {
     19void for_each( iterator_type begin, iterator_type end, void (* func)( elt_type ) ) {
    2020        for ( iterator_type i = begin; i != end; ++i ) {
    2121                func( *i );
    22         }
    23 }
     22        } // for
     23} // for_each
    2424
    2525forall( otype iterator_type, otype elt_type | iterator( iterator_type, elt_type ) )
    26 void for_each_reverse( iterator_type begin, iterator_type end, void (*func)( elt_type ) ) {
     26void for_each_reverse( iterator_type begin, iterator_type end, void (* func)( elt_type ) ) {
    2727        for ( iterator_type i = end; i != begin; ) {
    2828                --i;
    2929                func( *i );
    30         }
    31 }
     30        } // for
     31} // for_each_reverse
    3232
    3333// Local Variables: //
  • src/libcfa/limits

    r52a9004 r53a6c2a  
    1010// Created On       : Wed Apr  6 18:06:52 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Apr  6 21:08:16 2016
    13 // Update Count     : 6
     12// Last Modified On : Fri Jul  7 09:33:57 2017
     13// Update Count     : 7
    1414//
    1515
    16 #ifndef LIMITS_H
    17 #define LIMITS_H
     16#pragma once
    1817
    1918// Integral Constants
     
    110109extern const long _Complex _1_SQRT_2;                                   // 1 / sqrt(2)
    111110
    112 #endif // LIMITS_H
    113 
    114111// Local Variables: //
    115112// mode: c //
  • src/libcfa/math

    r52a9004 r53a6c2a  
    1010// Created On       : Mon Apr 18 23:37:04 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed May 24 17:40:39 2017
    13 // Update Count     : 60
    14 //
    15 
    16 #ifndef MATH_H
    17 #define MATH_H
     12// Last Modified On : Fri Jul  7 09:34:15 2017
     13// Update Count     : 61
     14//
     15
     16#pragma once
    1817
    1918extern "C" {
     
    345344long double scalbln( long double, long int );
    346345
    347 #endif // MATH_H
    348 
    349346// Local Variables: //
    350347// mode: c //
  • src/libcfa/rational

    r52a9004 r53a6c2a  
    1212// Created On       : Wed Apr  6 17:56:25 2016
    1313// Last Modified By : Peter A. Buhr
    14 // Last Modified On : Mon May 15 21:30:12 2017
    15 // Update Count     : 90
     14// Last Modified On : Fri Jul  7 09:34:33 2017
     15// Update Count     : 93
    1616//
    1717
    18 #ifndef RATIONAL_H
    19 #define RATIONAL_H
     18#pragma once
    2019
    2120#include "iostream"
     
    4746// implementation
    4847
    49 forall ( otype RationalImpl | arithmetic( RationalImpl ) )
     48forall( otype RationalImpl | arithmetic( RationalImpl ) )
    5049struct Rational {
    5150        RationalImpl numerator, denominator;                            // invariant: denominator > 0
     
    5453// constructors
    5554
    56 forall ( otype RationalImpl | arithmetic( RationalImpl ) )
     55forall( otype RationalImpl | arithmetic( RationalImpl ) )
    5756void ?{}( Rational(RationalImpl) * r );
    5857
    59 forall ( otype RationalImpl | arithmetic( RationalImpl ) )
     58forall( otype RationalImpl | arithmetic( RationalImpl ) )
    6059void ?{}( Rational(RationalImpl) * r, RationalImpl n );
    6160
    62 forall ( otype RationalImpl | arithmetic( RationalImpl ) )
     61forall( otype RationalImpl | arithmetic( RationalImpl ) )
    6362void ?{}( Rational(RationalImpl) * r, RationalImpl n, RationalImpl d );
    6463
    65 forall ( otype RationalImpl | arithmetic( RationalImpl ) )
     64forall( otype RationalImpl | arithmetic( RationalImpl ) )
    6665void ?{}( Rational(RationalImpl) * r, zero_t );
    6766
    68 forall ( otype RationalImpl | arithmetic( RationalImpl ) )
     67forall( otype RationalImpl | arithmetic( RationalImpl ) )
    6968void ?{}( Rational(RationalImpl) * r, one_t );
    7069
    71 // getter for numerator/denominator
     70// numerator/denominator getter
    7271
    73 forall ( otype RationalImpl | arithmetic( RationalImpl ) )
     72forall( otype RationalImpl | arithmetic( RationalImpl ) )
    7473RationalImpl numerator( Rational(RationalImpl) r );
    7574
    76 forall ( otype RationalImpl | arithmetic( RationalImpl ) )
     75forall( otype RationalImpl | arithmetic( RationalImpl ) )
    7776RationalImpl denominator( Rational(RationalImpl) r );
    78 forall ( otype RationalImpl | arithmetic( RationalImpl ) )
     77
     78forall( otype RationalImpl | arithmetic( RationalImpl ) )
    7979[ RationalImpl, RationalImpl ] ?=?( * [ RationalImpl, RationalImpl ] dest, Rational(RationalImpl) src );
    8080
    81 // setter for numerator/denominator
     81// numerator/denominator setter
    8282
    83 forall ( otype RationalImpl | arithmetic( RationalImpl ) )
     83forall( otype RationalImpl | arithmetic( RationalImpl ) )
    8484RationalImpl numerator( Rational(RationalImpl) r, RationalImpl n );
    8585
    86 forall ( otype RationalImpl | arithmetic( RationalImpl ) )
     86forall( otype RationalImpl | arithmetic( RationalImpl ) )
    8787RationalImpl denominator( Rational(RationalImpl) r, RationalImpl d );
    8888
    8989// comparison
    9090
    91 forall ( otype RationalImpl | arithmetic( RationalImpl ) )
     91forall( otype RationalImpl | arithmetic( RationalImpl ) )
    9292int ?==?( Rational(RationalImpl) l, Rational(RationalImpl) r );
    9393
    94 forall ( otype RationalImpl | arithmetic( RationalImpl ) )
     94forall( otype RationalImpl | arithmetic( RationalImpl ) )
    9595int ?!=?( Rational(RationalImpl) l, Rational(RationalImpl) r );
    9696
    97 forall ( otype RationalImpl | arithmetic( RationalImpl ) )
     97forall( otype RationalImpl | arithmetic( RationalImpl ) )
    9898int ?<?( Rational(RationalImpl) l, Rational(RationalImpl) r );
    9999
    100 forall ( otype RationalImpl | arithmetic( RationalImpl ) )
     100forall( otype RationalImpl | arithmetic( RationalImpl ) )
    101101int ?<=?( Rational(RationalImpl) l, Rational(RationalImpl) r );
    102102
    103 forall ( otype RationalImpl | arithmetic( RationalImpl ) )
     103forall( otype RationalImpl | arithmetic( RationalImpl ) )
    104104int ?>?( Rational(RationalImpl) l, Rational(RationalImpl) r );
    105105
    106 forall ( otype RationalImpl | arithmetic( RationalImpl ) )
     106forall( otype RationalImpl | arithmetic( RationalImpl ) )
    107107int ?>=?( Rational(RationalImpl) l, Rational(RationalImpl) r );
    108108
    109109// arithmetic
    110110
    111 forall ( otype RationalImpl | arithmetic( RationalImpl ) )
     111forall( otype RationalImpl | arithmetic( RationalImpl ) )
    112112Rational(RationalImpl) +?( Rational(RationalImpl) r );
    113113
    114 forall ( otype RationalImpl | arithmetic( RationalImpl ) )
     114forall( otype RationalImpl | arithmetic( RationalImpl ) )
    115115Rational(RationalImpl) -?( Rational(RationalImpl) r );
    116116
    117 forall ( otype RationalImpl | arithmetic( RationalImpl ) )
     117forall( otype RationalImpl | arithmetic( RationalImpl ) )
    118118Rational(RationalImpl) ?+?( Rational(RationalImpl) l, Rational(RationalImpl) r );
    119119
    120 forall ( otype RationalImpl | arithmetic( RationalImpl ) )
     120forall( otype RationalImpl | arithmetic( RationalImpl ) )
    121121Rational(RationalImpl) ?-?( Rational(RationalImpl) l, Rational(RationalImpl) r );
    122122
    123 forall ( otype RationalImpl | arithmetic( RationalImpl ) )
     123forall( otype RationalImpl | arithmetic( RationalImpl ) )
    124124Rational(RationalImpl) ?*?( Rational(RationalImpl) l, Rational(RationalImpl) r );
    125125
    126 forall ( otype RationalImpl | arithmetic( RationalImpl ) )
     126forall( otype RationalImpl | arithmetic( RationalImpl ) )
    127127Rational(RationalImpl) ?/?( Rational(RationalImpl) l, Rational(RationalImpl) r );
    128128
    129129// conversion
    130 forall ( otype RationalImpl | arithmetic( RationalImpl ) | { double convert( RationalImpl ); } )
     130forall( otype RationalImpl | arithmetic( RationalImpl ) | { double convert( RationalImpl ); } )
    131131double widen( Rational(RationalImpl) r );
    132 forall ( otype RationalImpl | arithmetic( RationalImpl ) | { double convert( RationalImpl );  RationalImpl convert( double );} )
     132forall( otype RationalImpl | arithmetic( RationalImpl ) | { double convert( RationalImpl );  RationalImpl convert( double );} )
    133133Rational(RationalImpl) narrow( double f, RationalImpl md );
    134134
    135135// I/O
    136 forall ( otype RationalImpl | arithmetic( RationalImpl ) )
     136forall( otype RationalImpl | arithmetic( RationalImpl ) )
    137137forall( dtype istype | istream( istype ) | { istype * ?|?( istype *, RationalImpl * ); } )
    138138istype * ?|?( istype *, Rational(RationalImpl) * );
    139139
    140 forall ( otype RationalImpl | arithmetic( RationalImpl ) )
     140forall( otype RationalImpl | arithmetic( RationalImpl ) )
    141141forall( dtype ostype | ostream( ostype ) | { ostype * ?|?( ostype *, RationalImpl ); } )
    142142ostype * ?|?( ostype *, Rational(RationalImpl ) );
    143 
    144 #endif // RATIONAL_H
    145143
    146144// Local Variables: //
  • src/libcfa/rational.c

    r52a9004 r53a6c2a  
    1010// Created On       : Wed Apr  6 17:54:28 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon May 15 21:29:23 2017
    13 // Update Count     : 149
     12// Last Modified On : Tue May 16 18:35:36 2017
     13// Update Count     : 150
    1414//
    1515
     
    2222// Calculate greatest common denominator of two numbers, the first of which may be negative. Used to reduce rationals.
    2323// alternative: https://en.wikipedia.org/wiki/Binary_GCD_algorithm
    24 forall ( otype RationalImpl | arithmetic( RationalImpl ) )
     24forall( otype RationalImpl | arithmetic( RationalImpl ) )
    2525static RationalImpl gcd( RationalImpl a, RationalImpl b ) {
    2626        for ( ;; ) {                                                                            // Euclid's algorithm
     
    3333} // gcd
    3434
    35 forall ( otype RationalImpl | arithmetic( RationalImpl ) )
     35forall( otype RationalImpl | arithmetic( RationalImpl ) )
    3636static RationalImpl simplify( RationalImpl * n, RationalImpl * d ) {
    3737        if ( *d == (RationalImpl){0} ) {
     
    4646// constructors
    4747
    48 forall ( otype RationalImpl | arithmetic( RationalImpl ) )
     48forall( otype RationalImpl | arithmetic( RationalImpl ) )
    4949void ?{}( Rational(RationalImpl) * r ) {
    5050        r{ (RationalImpl){0}, (RationalImpl){1} };
    5151} // rational
    5252
    53 forall ( otype RationalImpl | arithmetic( RationalImpl ) )
     53forall( otype RationalImpl | arithmetic( RationalImpl ) )
    5454void ?{}( Rational(RationalImpl) * r, RationalImpl n ) {
    5555        r{ n, (RationalImpl){1} };
    5656} // rational
    5757
    58 forall ( otype RationalImpl | arithmetic( RationalImpl ) )
     58forall( otype RationalImpl | arithmetic( RationalImpl ) )
    5959void ?{}( Rational(RationalImpl) * r, RationalImpl n, RationalImpl d ) {
    6060        RationalImpl t = simplify( &n, &d );                            // simplify
     
    6666// getter for numerator/denominator
    6767
    68 forall ( otype RationalImpl | arithmetic( RationalImpl ) )
     68forall( otype RationalImpl | arithmetic( RationalImpl ) )
    6969RationalImpl numerator( Rational(RationalImpl) r ) {
    7070        return r.numerator;
    7171} // numerator
    7272
    73 forall ( otype RationalImpl | arithmetic( RationalImpl ) )
     73forall( otype RationalImpl | arithmetic( RationalImpl ) )
    7474RationalImpl denominator( Rational(RationalImpl) r ) {
    7575        return r.denominator;
    7676} // denominator
    7777
    78 forall ( otype RationalImpl | arithmetic( RationalImpl ) )
     78forall( otype RationalImpl | arithmetic( RationalImpl ) )
    7979[ RationalImpl, RationalImpl ] ?=?( * [ RationalImpl, RationalImpl ] dest, Rational(RationalImpl) src ) {
    8080        return *dest = src.[ numerator, denominator ];
     
    8383// setter for numerator/denominator
    8484
    85 forall ( otype RationalImpl | arithmetic( RationalImpl ) )
     85forall( otype RationalImpl | arithmetic( RationalImpl ) )
    8686RationalImpl numerator( Rational(RationalImpl) r, RationalImpl n ) {
    8787        RationalImpl prev = r.numerator;
     
    9292} // numerator
    9393
    94 forall ( otype RationalImpl | arithmetic( RationalImpl ) )
     94forall( otype RationalImpl | arithmetic( RationalImpl ) )
    9595RationalImpl denominator( Rational(RationalImpl) r, RationalImpl d ) {
    9696        RationalImpl prev = r.denominator;
     
    104104// comparison
    105105
    106 forall ( otype RationalImpl | arithmetic( RationalImpl ) )
     106forall( otype RationalImpl | arithmetic( RationalImpl ) )
    107107int ?==?( Rational(RationalImpl) l, Rational(RationalImpl) r ) {
    108108        return l.numerator * r.denominator == l.denominator * r.numerator;
    109109} // ?==?
    110110
    111 forall ( otype RationalImpl | arithmetic( RationalImpl ) )
     111forall( otype RationalImpl | arithmetic( RationalImpl ) )
    112112int ?!=?( Rational(RationalImpl) l, Rational(RationalImpl) r ) {
    113113        return ! ( l == r );
    114114} // ?!=?
    115115
    116 forall ( otype RationalImpl | arithmetic( RationalImpl ) )
     116forall( otype RationalImpl | arithmetic( RationalImpl ) )
    117117int ?<?( Rational(RationalImpl) l, Rational(RationalImpl) r ) {
    118118        return l.numerator * r.denominator < l.denominator * r.numerator;
    119119} // ?<?
    120120
    121 forall ( otype RationalImpl | arithmetic( RationalImpl ) )
     121forall( otype RationalImpl | arithmetic( RationalImpl ) )
    122122int ?<=?( Rational(RationalImpl) l, Rational(RationalImpl) r ) {
    123123        return l.numerator * r.denominator <= l.denominator * r.numerator;
    124124} // ?<=?
    125125
    126 forall ( otype RationalImpl | arithmetic( RationalImpl ) )
     126forall( otype RationalImpl | arithmetic( RationalImpl ) )
    127127int ?>?( Rational(RationalImpl) l, Rational(RationalImpl) r ) {
    128128        return ! ( l <= r );
    129129} // ?>?
    130130
    131 forall ( otype RationalImpl | arithmetic( RationalImpl ) )
     131forall( otype RationalImpl | arithmetic( RationalImpl ) )
    132132int ?>=?( Rational(RationalImpl) l, Rational(RationalImpl) r ) {
    133133        return ! ( l < r );
     
    137137// arithmetic
    138138
    139 forall ( otype RationalImpl | arithmetic( RationalImpl ) )
     139forall( otype RationalImpl | arithmetic( RationalImpl ) )
    140140Rational(RationalImpl) +?( Rational(RationalImpl) r ) {
    141141        Rational(RationalImpl) t = { r.numerator, r.denominator };
     
    143143} // +?
    144144
    145 forall ( otype RationalImpl | arithmetic( RationalImpl ) )
     145forall( otype RationalImpl | arithmetic( RationalImpl ) )
    146146Rational(RationalImpl) -?( Rational(RationalImpl) r ) {
    147147        Rational(RationalImpl) t = { -r.numerator, r.denominator };
     
    149149} // -?
    150150
    151 forall ( otype RationalImpl | arithmetic( RationalImpl ) )
     151forall( otype RationalImpl | arithmetic( RationalImpl ) )
    152152Rational(RationalImpl) ?+?( Rational(RationalImpl) l, Rational(RationalImpl) r ) {
    153153        if ( l.denominator == r.denominator ) {                         // special case
     
    160160} // ?+?
    161161
    162 forall ( otype RationalImpl | arithmetic( RationalImpl ) )
     162forall( otype RationalImpl | arithmetic( RationalImpl ) )
    163163Rational(RationalImpl) ?-?( Rational(RationalImpl) l, Rational(RationalImpl) r ) {
    164164        if ( l.denominator == r.denominator ) {                         // special case
     
    171171} // ?-?
    172172
    173 forall ( otype RationalImpl | arithmetic( RationalImpl ) )
     173forall( otype RationalImpl | arithmetic( RationalImpl ) )
    174174Rational(RationalImpl) ?*?( Rational(RationalImpl) l, Rational(RationalImpl) r ) {
    175175        Rational(RationalImpl) t = { l.numerator * r.numerator, l.denominator * r.denominator };
     
    177177} // ?*?
    178178
    179 forall ( otype RationalImpl | arithmetic( RationalImpl ) )
     179forall( otype RationalImpl | arithmetic( RationalImpl ) )
    180180Rational(RationalImpl) ?/?( Rational(RationalImpl) l, Rational(RationalImpl) r ) {
    181181        if ( r.numerator < (RationalImpl){0} ) {
     
    190190// conversion
    191191
    192 forall ( otype RationalImpl | arithmetic( RationalImpl ) | { double convert( RationalImpl ); } )
     192forall( otype RationalImpl | arithmetic( RationalImpl ) | { double convert( RationalImpl ); } )
    193193double widen( Rational(RationalImpl) r ) {
    194194        return convert( r.numerator ) / convert( r.denominator );
     
    196196
    197197// http://www.ics.uci.edu/~eppstein/numth/frap.c
    198 forall ( otype RationalImpl | arithmetic( RationalImpl ) | { double convert( RationalImpl ); RationalImpl convert( double ); } )
     198forall( otype RationalImpl | arithmetic( RationalImpl ) | { double convert( RationalImpl ); RationalImpl convert( double ); } )
    199199Rational(RationalImpl) narrow( double f, RationalImpl md ) {
    200200        if ( md <= (RationalImpl){1} ) {                                        // maximum fractional digits too small?
     
    227227// I/O
    228228
    229 forall ( otype RationalImpl | arithmetic( RationalImpl ) )
     229forall( otype RationalImpl | arithmetic( RationalImpl ) )
    230230forall( dtype istype | istream( istype ) | { istype * ?|?( istype *, RationalImpl * ); } )
    231231istype * ?|?( istype * is, Rational(RationalImpl) * r ) {
     
    238238} // ?|?
    239239
    240 forall ( otype RationalImpl | arithmetic( RationalImpl ) )
     240forall( otype RationalImpl | arithmetic( RationalImpl ) )
    241241forall( dtype ostype | ostream( ostype ) | { ostype * ?|?( ostype *, RationalImpl ); } )
    242242ostype * ?|?( ostype * os, Rational(RationalImpl ) r ) {
  • src/libcfa/stdlib

    r52a9004 r53a6c2a  
    1010// Created On       : Thu Jan 28 17:12:35 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Jun  2 15:51:03 2017
    13 // Update Count     : 218
    14 //
    15 
    16 #ifndef STDLIB_H
    17 #define STDLIB_H
     12// Last Modified On : Fri Jul  7 09:34:49 2017
     13// Update Count     : 219
     14//
     15
     16#pragma once
    1817
    1918//---------------------------------------
     
    232231void swap( T * t1, T * t2 );
    233232
    234 #endif // STDLIB_H
    235 
    236233// Local Variables: //
    237234// mode: c //
  • src/tests/.expect/io.txt

    r52a9004 r53a6c2a  
    44123
    55
    6 opening delimiters 
     6opening delimiters
    77x (1 x [2 x {3 x =4 x $5 x £6 x ¥7 x ¡8 x ¿9 x «10
    88
    9 closing delimiters 
    10 1, x 2. x 3; x 4! x 5? x 6% x 7¢ x 8» x 9) x 10] x 11} x 
     9closing delimiters
     101, x 2. x 3; x 4! x 5? x 6% x 7¢ x 8» x 9) x 10] x 11} x
    1111
    12 opening/closing delimiters 
     12opening/closing delimiters
    1313x`1`x'2'x"3"x:4:x 5 x   6       x
    14147
     
    1919x
    202010
    21 x 
     21x
    2222
    23 override opening/closing delimiters 
     23override opening/closing delimiters
    2424x ( 1 ) x 2 , x 3 :x: 4
    2525
    26 input bacis types 
     26input bacis types
    2727
    28 output basic types 
     28output basic types
    2929A
    30301 2 3 4 5 6 7 8
     
    32321.1+2.3i 1.1-2.3i 1.1-2.3i
    3333
    34 tuples 
    35 1, 2, 3 3, 4, 5
     34tuples
     351, 2, 3 4, 5, 6
    3636
    37 toggle separator 
     37toggle separator
    38381.11.21.3
    39391.1+2.3i1.1-2.3i1.1-2.3i
    40  abcxyz
    41 abcxyz
     401.1+2.3i 1.1-2.3i1.1-2.3i
     411.1+2.3i 1.1-2.3i 1.1-2.3i
     421.1+2.3i1.1-2.3i 1.1-2.3i
     43abcxyz
     44abcxyz
    4245
    43 change separator 
    44 from "  "to " , $"
     46change separator
     47from " " to ", $"
    45481.1, $1.2, $1.3
    46491.1+2.3i, $1.1-2.3i, $1.1-2.3i
    47 abc, $xyz, $
    48 1, 2, 3, $3, 4, 5
     50abc, $xyz
     511, 2, 3, $4, 5, 6
    4952
    50 from ", $"to " "
     53from ", $" to " "
    51541.1 1.2 1.3
    52551.1+2.3i 1.1-2.3i 1.1-2.3i
    53 abc xyz 
    54 1, 2, 3 3, 4, 5
     56abc xyz
     571, 2, 3 4, 5, 6
    5558
    56  1 2 3
     59check sepOn/sepOff
     601 2 3
    576112 3
    58  1 2 3
    59621 2 3
    60  1 2 3
     631 2 3
    6164
     651 2 3
     66
     67check enable/disable
    6268123
    63691 23
     
    6571123
    66721 2 3
    67 123 
     73123
    68741 2 3
    6975
    70 1 2 3 3 4 5 " "
    71 1, 2, 3 3, 4, 5 ", "
    72 1, 2, 3 3, 4, 5
     761 2 3 4 5 6 " "
     771, 2, 3 4, 5, 6 " "
     781, 2, 3 4, 5, 6
    7379
    74803, 4, a, 7.2
    75813, 4, a, 7.2
    76823 4 a 7.2
    77  3 4 a 7.234a7.23 4 a 7.2
     833 4 a 7.234a7.23 4 a 7.2
    78843-4-a-7.2^3^4^3-4-a-7.2
  • src/tests/io.c

    r52a9004 r53a6c2a  
    1010// Created On       : Wed Mar  2 16:56:02 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun Jul  2 09:40:58 2017
    13 // Update Count     : 68
     12// Last Modified On : Thu Jul  6 23:26:12 2017
     13// Update Count     : 78
    1414//
    1515
     
    104104
    105105        sout | "tuples" | endl;
    106         [int, [ int, int ] ] t1 = [ 1, [ 2, 3 ] ], t2 = [ 3, [ 4, 5 ] ];
     106        [int, [ int, int ] ] t1 = [ 1, [ 2, 3 ] ], t2 = [ 4, [ 5, 6 ] ];
    107107        sout | t1 | t2 | endl;                                                          // print tuple
    108108        sout | endl;
     
    110110        sout | "toggle separator" | endl;
    111111        sout | f | "" | d | "" | ld | endl                                      // floating point without separator
    112                 | sepDisable | fc | dc | ldc | sepEnable | endl // complex without separator
    113                 | sepOn | s1 | sepOff | s2 | endl                               // local separator removal
    114                 | s1 | "" | s2 | endl;                                                  // C string without separator
     112                | sepDisable | fc | dc | ldc | endl                             // complex without separator
     113                | fc | sepOn | dc | ldc | endl                                  // local separator add
     114                | sepEnable | fc | dc | ldc | endl                              // complex with separator
     115                | fc | sepOff | dc | ldc | endl                                 // local separator removal
     116                | s1 | sepOff | s2 | endl                                               // local separator removal
     117                | s1 | "" | s2 | endl;                                                  // local separator removal
    115118        sout | endl;
    116119
    117120        sout | "change separator" | endl;
    118         sout | "from \" " | sepGet( sout ) | "\"";
     121        sout | "from \"" | sep | "\"";
    119122        sepSet( sout, ", $" );                                                          // change separator, maximum of 15 characters
    120         sout | "to \" " | sepGet( sout ) | "\"" | endl;
     123        sout | " to \"" | sep | "\"" | endl;
    121124        sout | f | d | ld | endl
    122125                | fc | dc | ldc | endl
     
    124127                | t1 | t2 | endl;                                                               // print tuple
    125128        sout | endl;
    126         sout | "from \"" | sepGet( sout ) | "\"";
     129        sout | "from \"" | sep | "\" ";
    127130        sepSet( sout, " " );                                                            // restore separator
    128         sout | "to \"" | sepGet( sout ) | "\"" | endl;
     131        sout | "to \"" | sep | "\"" | endl;
    129132        sout | f | d | ld | endl
    130133                | fc | dc | ldc | endl
     
    133136        sout | endl;
    134137
    135         sout | sepOn | 1 | 2 | 3 | sepOn | endl;                        // separator at start/end of line
     138        sout | "check sepOn/sepOff" | endl;
     139        sout | sepOn | 1 | 2 | 3 | sepOn | endl;                        // no separator at start/end of line
    136140        sout | 1 | sepOff | 2 | 3 | endl;                                       // locally turn off implicit separator
    137         sout | sepOn | 1 | 2 | 3 | sepOn | sepOff | endl;       // separator at start of line
    138         sout | 1 | 2 | 3 | endl | sepOn;                                        // separator at start of next line
     141        sout | sepOn | sepOn | 1 | 2 | 3 | sepOn | sepOff | sepOn | '\n'; // no separator at start/end of line
     142        sout | 1 | 2 | 3 | "\n\n" | sepOn;                                      // no separator at start of next line
    139143        sout | 1 | 2 | 3 | endl;
    140144        sout | endl;
    141145
     146        sout | "check enable/disable" | endl;
    142147        sout | sepDisable | 1 | 2 | 3 | endl;                           // globally turn off implicit separation
    143148        sout | 1 | sepOn | 2 | 3 | endl;                                        // locally turn on implicit separator
     
    149154        sout | endl;
    150155
     156//      sout | fmt( d, "%8.3f" ) || endl;
     157//      sout | endl;
     158
    151159        sepSetTuple( sout, " " );                                                       // set tuple separator from ", " to " "
    152         sout | t1 | t2 | " \"" | sepGetTuple( sout ) | "\"" | endl;
     160        sout | t1 | t2 | " \"" | sep | "\"" | endl;
    153161        sepSetTuple( sout, ", " );                                                      // reset tuple separator to ", "
    154         sout | t1 | t2 | " \"" | sepGetTuple( sout ) | "\"" | endl;
     162        sout | t1 | t2 | " \"" | sep | "\"" | endl;
    155163        sout | t1 | t2 | endl;                                                          // print tuple
    156164        sout | endl;
Note: See TracChangeset for help on using the changeset viewer.