Changeset 53a6c2a
- Timestamp:
- Jul 7, 2017, 10:39:08 AM (7 years ago)
- 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
- Files:
-
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/user/user.tex
r52a9004 r53a6c2a 11 11 %% Created On : Wed Apr 6 14:53:29 2016 12 12 %% Last Modified By : Peter A. Buhr 13 %% Last Modified On : Sun Jul 2 09:49:56201714 %% Update Count : 25 0313 %% Last Modified On : Fri Jul 7 10:36:39 2017 14 %% Update Count : 2547 15 15 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 16 16 … … 2450 2450 \end{cfa} 2451 2451 \\ 2452 \begin{cfa}[ mathescape=off,showspaces=true,aboveskip=0pt,belowskip=0pt]2452 \begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt] 2453 2453 1® ®2® ®3 2454 2454 \end{cfa} 2455 2455 & 2456 \begin{cfa}[ mathescape=off,showspaces=true,aboveskip=0pt,belowskip=0pt]2456 \begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt] 2457 2457 1 2 3 2458 2458 \end{cfa} … … 2461 2461 The \CFA form has half the characters of the \CC form, and is similar to \Index*{Python} I/O with respect to implicit separators. 2462 2462 Similar 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 ] ]; 2465 2465 sout | t1 | t2 | endl; §\C{// print tuples}§ 2466 2466 \end{cfa} 2467 \begin{cfa}[ mathescape=off,showspaces=true,belowskip=0pt]2468 1®, ®2®, ®3 3®, ®4®, ®52467 \begin{cfa}[showspaces=true,aboveskip=0pt] 2468 1®, ®2®, ®3 4®, ®5®, ®6 2469 2469 \end{cfa} 2470 2470 Finally, \CFA uses the logical-or operator for I/O as it is the lowest-priority overloadable operator, other than assignment. … … 2485 2485 \\ 2486 2486 & 2487 \begin{cfa}[ mathescape=off,showspaces=true,aboveskip=0pt,belowskip=0pt]2487 \begin{cfa}[showspaces=true,aboveskip=0pt] 2488 2488 3 3 12 0 3 1 2 2489 2489 \end{cfa} … … 2503 2503 sout | 1 | 2 | 3 | endl; 2504 2504 \end{cfa} 2505 \begin{cfa}[ mathescape=off,showspaces=true,aboveskip=0pt,belowskip=0pt]2505 \begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt] 2506 2506 1 2 3 2507 2507 \end{cfa} … … 2570 2570 \subsection{Manipulator} 2571 2571 2572 The following routines and \CC-style \Index{manipulator}s control implicit seperation.2572 The following \CC-style \Index{manipulator}s and routines control implicit seperation. 2573 2573 \begin{enumerate} 2574 2574 \item 2575 Routines \Indexc{sepSet}\index{manipulator!sepSet@©sepSet©} and \Indexc{sep Get}\index{manipulator!sepGet@©sepGet©} set and get the separator string.2575 Routines \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. 2576 2576 The 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] 2578 2578 sepSet( sout, ", $" ); §\C{// set separator from " " to ", \$"}§ 2579 sout | 1 | 2 | 3 | " \"" | ®sep Get( sout )® | "\"" | endl;2579 sout | 1 | 2 | 3 | " \"" | ®sep® | "\"" | endl; 2580 2580 \end{cfa} 2581 2581 %$ … … 2584 2584 \end{cfa} 2585 2585 %$ 2586 \begin{cfa}[ mathescape=off,aboveskip=0pt,belowskip=0pt]2586 \begin{cfa}[belowskip=0pt] 2587 2587 sepSet( sout, " " ); §\C{// reset separator to " "}§ 2588 2588 sout | 1 | 2 | 3 | " \"" | ®sepGet( sout )® | "\"" | endl; 2589 2589 \end{cfa} 2590 \begin{cfa}[ mathescape=off,showspaces=true,aboveskip=0pt]2590 \begin{cfa}[showspaces=true,aboveskip=0pt] 2591 2591 1® ®2® ®3 ®" "® 2592 2592 \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] 2595 char store[®sepSize®]; §\C{// sepSize is the maximum separator size}§ 2596 strcpy( store, sepGet( sout ) ); 2597 sepSet( sout, "_" ); 2598 sout | 1 | 2 | 3 | endl; 2599 \end{cfa} 2600 \begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt] 2601 1®_®2®_®3 2602 \end{cfa} 2603 \begin{cfa}[belowskip=0pt] 2604 sepSet( sout, store ); 2605 sout | 1 | 2 | 3 | endl; 2606 \end{cfa} 2607 \begin{cfa}[showspaces=true,aboveskip=0pt] 2608 1® ®2® ®3 2609 \end{cfa} 2610 2611 \item 2612 Routine \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. 2596 2613 The 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] 2598 2615 sepSetTuple( sout, " " ); §\C{// set tuple separator from ", " to " "}§ 2599 sout | t1 | t2 | " \"" | ®sep GetTuple( 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]2616 sout | t1 | t2 | " \"" | ®sepTuple® | "\"" | endl; 2617 \end{cfa} 2618 \begin{cfa}[showspaces=true,aboveskip=0pt] 2619 1 2 3 4 5 6 ®" "® 2620 \end{cfa} 2621 \begin{cfa}[belowskip=0pt] 2605 2622 sepSetTuple( sout, ", " ); §\C{// reset tuple separator to ", "}§ 2606 2623 sout | t1 | t2 | " \"" | ®sepGetTuple( sout )® | "\"" | endl; 2607 2624 \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] 2626 1, 2, 3 4, 5, 6 ®", "® 2627 \end{cfa} 2628 As for ©sepGet©, ©sepGetTuple© can be use to store a tuple separator and then restore it. 2629 2630 \item 2631 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. 2632 \begin{cfa}[belowskip=0pt] 2633 sout | sepDisable | 1 | 2 | 3 | endl; §\C{// globally turn off implicit separator}§ 2634 \end{cfa} 2635 \begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt] 2641 2636 123 2642 2637 \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] 2639 sout | sepEnable | 1 | 2 | 3 | endl; §\C{// globally turn on implicit separator}§ 2651 2640 \end{cfa} 2652 2641 \begin{cfa}[mathescape=off,showspaces=true,aboveskip=0pt,belowskip=0pt] 2653 2642 1 2 3 2654 2643 \end{cfa} 2644 2645 \item 2646 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. 2647 \begin{cfa}[belowskip=0pt] 2648 sout | 1 | sepOff | 2 | 3 | endl; §\C{// locally turn off implicit separator}§ 2649 \end{cfa} 2650 \begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt] 2651 12 3 2652 \end{cfa} 2653 \begin{cfa}[belowskip=0pt] 2654 sout | sepDisable | 1 | sepOn | 2 | 3 | endl; §\C{// locally turn on implicit separator}§ 2655 \end{cfa} 2656 \begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt] 2657 1 23 2658 \end{cfa} 2659 The tuple separator also responses to being turned on and off. 2660 \begin{cfa}[belowskip=0pt] 2661 sout | t1 | sepOff | t2 | endl; §\C{// locally turn on/off implicit separator}§ 2662 \end{cfa} 2663 \begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt] 2664 1, 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; 2667 use ©sep© to accomplish this functionality. 2668 \begin{cfa}[belowskip=0pt] 2669 sout | 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] 2672 1 2 3 2673 \end{cfa} 2674 \begin{cfa}[belowskip=0pt] 2675 sout | 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} 2655 2680 \end{enumerate} 2656 2681 2657 2682 \begin{comment} 2658 2683 #include <fstream> 2684 #include <string.h> // strcpy 2659 2685 2660 2686 int main( void ) { 2661 2687 int x = 1, y = 2, z = 3; 2662 2688 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 ] ]; 2664 2690 sout | t1 | t2 | endl; // print tuples 2665 2691 sout | x * 3 | y + 1 | z << 2 | x == y | (x | y) | (x || y) | (x > z ? 1 : 2) | endl; … … 2675 2701 2676 2702 sepSet( sout, ", $" ); // set separator from " " to ", $" 2677 sout | 1 | 2 | 3 | " \"" | sep Get( sout )| "\"" | endl;2703 sout | 1 | 2 | 3 | " \"" | sep | "\"" | endl; 2678 2704 sepSet( sout, " " ); // reset separator to " " 2679 2705 sout | 1 | 2 | 3 | " \"" | sepGet( sout ) | "\"" | endl; 2680 2706 2681 sout | sepOn | 1 | 2 | 3 | sepOn | endl; // separator at start of line2682 s out | 1 | sepOff | 2 | 3 | endl; // locally turn off implicit separator2683 2684 sout | sepDisable | 1 | 2 | 3 | endl; // globally turn off implicit separation2685 s out | 1 | sepOn | 2 | 3 | endl; // locally turn on implicit separator2686 sout | sepEnable | 1 | 2 | 3 | endl; // globally turn on implicit separation2707 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; 2687 2713 2688 2714 sepSetTuple( sout, " " ); // set tuple separator from ", " to " " 2689 sout | t1 | t2 | " \"" | sep GetTuple( sout )| "\"" | endl;2715 sout | t1 | t2 | " \"" | sepTuple | "\"" | endl; 2690 2716 sepSetTuple( sout, ", " ); // reset tuple separator to ", " 2691 2717 sout | t1 | t2 | " \"" | sepGetTuple( sout ) | "\"" | endl; 2692 2718 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 2695 2729 } 2696 2730 … … 5548 5582 // C unsafe allocation 5549 5583 extern "C" { 5550 void * mall ac( size_t size );§\indexc{memset}§5584 void * malloc( size_t size );§\indexc{memset}§ 5551 5585 void * calloc( size_t dim, size_t size );§\indexc{calloc}§ 5552 5586 void * realloc( void * ptr, size_t size );§\indexc{realloc}§ -
src/libcfa/fstream
r52a9004 r53a6c2a 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sat Jul 1 16:37:53201713 // Update Count : 11 212 // Last Modified On : Fri Jul 7 08:32:38 2017 13 // Update Count : 117 14 14 // 15 15 16 #ifndef __FSTREAM_H__ 17 #define __FSTREAM_H__ 16 #pragma once 18 17 19 18 #include "iostream" 20 19 21 enum { sep arateSize = 16 };20 enum { sepSize = 16 }; 22 21 struct ofstream { 23 22 void * file; 24 23 _Bool sepDefault; 25 24 _Bool sepOnOff; 26 _Bool lastSepOn;25 _Bool sawNL; 27 26 const char * sepCur; 28 char separator[sep arateSize];29 char tupleSeparator[sep arateSize];27 char separator[sepSize]; 28 char tupleSeparator[sepSize]; 30 29 }; // ofstream 31 30 … … 36 35 const char * sepGetCur( ofstream * ); 37 36 void sepSetCur( ofstream *, const char * ); 38 _Bool lastSepOn( ofstream * ); 37 _Bool getNL( ofstream * ); 38 void setNL( ofstream *, _Bool ); 39 39 40 40 // public … … 75 75 extern ifstream * sin; 76 76 77 #endif // __FSTREAM_H__78 79 77 // Local Variables: // 80 78 // mode: c // -
src/libcfa/fstream.c
r52a9004 r53a6c2a 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sat Jul 1 16:37:54201713 // Update Count : 2 4212 // Last Modified On : Thu Jul 6 18:38:25 2017 13 // Update Count : 251 14 14 // 15 15 … … 33 33 this->sepDefault = sepDefault; 34 34 this->sepOnOff = sepOnOff; 35 this->lastSepOn = false;36 35 sepSet( this, separator ); 37 36 sepSetCur( this, sepGet( this ) ); … … 40 39 41 40 // 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; } 44 42 void sepReset( ofstream * os ) { os->sepOnOff = os->sepDefault; } 45 43 void sepReset( ofstream * os, _Bool reset ) { os->sepDefault = reset; os->sepOnOff = os->sepDefault; } 46 44 const char * sepGetCur( ofstream * os ) { return os->sepCur; } 47 45 void sepSetCur( ofstream * os, const char * sepCur ) { os->sepCur = sepCur; } 46 _Bool getNL( ofstream * os ) { return os->sawNL; } 47 void setNL( ofstream * os, _Bool state ) { os->sawNL = state; } 48 48 49 49 // public 50 void sepOn( ofstream * os ) { os-> lastSepOn = true; os->sepOnOff = true; }51 void sepOff( ofstream * os ) { os-> lastSepOn = false; os->sepOnOff = 0; }50 void sepOn( ofstream * os ) { os->sepOnOff = ! getNL( os ); } 51 void sepOff( ofstream * os ) { os->sepOnOff = false; } 52 52 53 53 _Bool sepDisable( ofstream *os ) { 54 54 _Bool temp = os->sepDefault; 55 55 os->sepDefault = false; 56 os->lastSepOn = false;57 56 sepReset( os ); 58 57 return temp; … … 69 68 void sepSet( ofstream * os, const char * s ) { 70 69 assert( s ); 71 strncpy( os->separator, s, sep arateSize - 1 );72 os->separator[sep arateSize - 1] = '\0';70 strncpy( os->separator, s, sepSize - 1 ); 71 os->separator[sepSize - 1] = '\0'; 73 72 } // sepSet 74 73 … … 76 75 void sepSetTuple( ofstream * os, const char * s ) { 77 76 assert( s ); 78 strncpy( os->tupleSeparator, s, sep arateSize - 1 );79 os->tupleSeparator[sep arateSize - 1] = '\0';77 strncpy( os->tupleSeparator, s, sepSize - 1 ); 78 os->tupleSeparator[sepSize - 1] = '\0'; 80 79 } // sepSet 81 80 … … 153 152 154 153 void open( ifstream * is, const char * name, const char * mode ) { 155 FILE * t= fopen( name, mode );156 if ( t == 0 ) {// do not change unless successful154 FILE *file = fopen( name, mode ); 155 if ( file == 0 ) { // do not change unless successful 157 156 fprintf( stderr, IO_MSG "open input file \"%s\", ", name ); 158 157 perror( 0 ); 159 158 exit( EXIT_FAILURE ); 160 159 } // if 161 is->file = t;160 is->file = file; 162 161 } // open 163 162 -
src/libcfa/gmp
r52a9004 r53a6c2a 10 10 // Created On : Tue Apr 19 08:43:43 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sat May 27 09:55:51201713 // Update Count : 1 412 // Last Modified On : Fri Jul 7 09:33:20 2017 13 // Update Count : 15 14 14 // 15 15 16 16 // https://gmplib.org/gmp-man-6.1.1.pdf 17 18 #pragma once 17 19 18 20 #include <gmp.h> // GNU multi-precise integers -
src/libcfa/iostream
r52a9004 r53a6c2a 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun Jul 2 08:42:56201713 // Update Count : 11 012 // Last Modified On : Fri Jul 7 08:35:59 2017 13 // Update Count : 118 14 14 // 15 15 16 #ifndef __IOSTREAM_H__ 17 #define __IOSTREAM_H__ 16 #pragma once 18 17 19 18 #include "iterator" … … 26 25 const char * sepGetCur( ostype * ); // get current separator string 27 26 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 29 29 // public 30 30 void sepOn( ostype * ); // turn separator state on … … 82 82 forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, ostype * (*)( ostype * ) ); 83 83 forall( dtype ostype | ostream( ostype ) ) ostype * endl( ostype * ); 84 forall( dtype ostype | ostream( ostype ) ) ostype * sep( ostype * ); 85 forall( dtype ostype | ostream( ostype ) ) ostype * sepTuple( ostype * ); 84 86 forall( dtype ostype | ostream( ostype ) ) ostype * sepOn( ostype * ); 85 87 forall( dtype ostype | ostream( ostype ) ) ostype * sepOff( ostype * ); … … 137 139 forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, _Istream_cstrC ); 138 140 139 #endif // __IOSTREAM_H140 141 141 // Local Variables: // 142 142 // mode: c // -
src/libcfa/iostream.c
r52a9004 r53a6c2a 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun Jul 2 08:54:02201713 // Update Count : 3 7512 // Last Modified On : Thu Jul 6 18:14:17 2017 13 // Update Count : 396 14 14 // 15 15 … … 18 18 extern "C" { 19 19 #include <stdio.h> 20 #include <stdbool.h> // true/false 20 21 #include <string.h> // strlen 21 22 #include <float.h> // DBL_DIG, LDBL_DIG … … 24 25 25 26 forall( dtype ostype | ostream( ostype ) ) 26 ostype * ?|?( ostype * os, char c ) { 27 fmt( os, "%c", c ); 27 ostype * ?|?( ostype * os, char ch ) { 28 fmt( os, "%c", ch ); 29 if ( ch == '\n' ) setNL( os, true ); 28 30 sepOff( os ); 29 31 return os; … … 180 182 181 183 // 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 unsigned184 size_t len = strlen( cp ); 185 ch = cp[len - 1]; // must make unsigned 184 186 if ( sepPrt( os ) && mask[ ch ] != Open && mask[ ch ] != OpenClose ) { 185 187 sepOn( os ); … … 187 189 sepOff( os ); 188 190 } // if 191 if ( ch == '\n' ) setNL( os, true ); // check *AFTER* sepPrt call above as it resets NL flag 189 192 return write( os, cp, len ); 190 193 } // ?|? … … 216 219 217 220 forall( dtype ostype | ostream( ostype ) ) 221 ostype * sep( ostype * os ) { 222 os | sepGet( os ); 223 return os; 224 } // sep 225 226 forall( dtype ostype | ostream( ostype ) ) 227 ostype * sepTuple( ostype * os ) { 228 os | sepGetTuple( os ); 229 return os; 230 } // sepTuple 231 232 forall( dtype ostype | ostream( ostype ) ) 218 233 ostype * endl( ostype * os ) { 219 if ( lastSepOn( os ) ) fmt( os, "%s", sepGetCur( os ) );220 234 os | '\n'; 235 setNL( os, true ); 221 236 flush( os ); 222 237 sepOff( os ); // prepare for next line -
src/libcfa/iterator
r52a9004 r53a6c2a 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Mar 2 18:06:05 201613 // Update Count : 912 // Last Modified On : Fri Jul 7 08:37:25 2017 13 // Update Count : 10 14 14 // 15 15 16 #ifndef ITERATOR_H 17 #define ITERATOR_H 16 #pragma once 18 17 19 18 // An iterator can be used to traverse a data structure. … … 39 38 40 39 forall( 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 ) );40 void for_each( iterator_type begin, iterator_type end, void (* func)( elt_type ) ); 42 41 43 42 forall( 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 43 void for_each_reverse( iterator_type begin, iterator_type end, void (* func)( elt_type ) ); 47 44 48 45 // Local Variables: // -
src/libcfa/iterator.c
r52a9004 r53a6c2a 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Mar 2 18:08:11 201613 // Update Count : 2 712 // Last Modified On : Fri Jul 7 08:38:23 2017 13 // Update Count : 28 14 14 // 15 15 … … 17 17 18 18 forall( 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 ) ) {19 void for_each( iterator_type begin, iterator_type end, void (* func)( elt_type ) ) { 20 20 for ( iterator_type i = begin; i != end; ++i ) { 21 21 func( *i ); 22 } 23 } 22 } // for 23 } // for_each 24 24 25 25 forall( 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 ) ) {26 void for_each_reverse( iterator_type begin, iterator_type end, void (* func)( elt_type ) ) { 27 27 for ( iterator_type i = end; i != begin; ) { 28 28 --i; 29 29 func( *i ); 30 } 31 } 30 } // for 31 } // for_each_reverse 32 32 33 33 // Local Variables: // -
src/libcfa/limits
r52a9004 r53a6c2a 10 10 // Created On : Wed Apr 6 18:06:52 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Apr 6 21:08:16 201613 // Update Count : 612 // Last Modified On : Fri Jul 7 09:33:57 2017 13 // Update Count : 7 14 14 // 15 15 16 #ifndef LIMITS_H 17 #define LIMITS_H 16 #pragma once 18 17 19 18 // Integral Constants … … 110 109 extern const long _Complex _1_SQRT_2; // 1 / sqrt(2) 111 110 112 #endif // LIMITS_H113 114 111 // Local Variables: // 115 112 // mode: c // -
src/libcfa/math
r52a9004 r53a6c2a 10 10 // Created On : Mon Apr 18 23:37:04 2016 11 11 // 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 18 17 19 18 extern "C" { … … 345 344 long double scalbln( long double, long int ); 346 345 347 #endif // MATH_H348 349 346 // Local Variables: // 350 347 // mode: c // -
src/libcfa/rational
r52a9004 r53a6c2a 12 12 // Created On : Wed Apr 6 17:56:25 2016 13 13 // Last Modified By : Peter A. Buhr 14 // Last Modified On : Mon May 15 21:30:12201715 // Update Count : 9 014 // Last Modified On : Fri Jul 7 09:34:33 2017 15 // Update Count : 93 16 16 // 17 17 18 #ifndef RATIONAL_H 19 #define RATIONAL_H 18 #pragma once 20 19 21 20 #include "iostream" … … 47 46 // implementation 48 47 49 forall 48 forall( otype RationalImpl | arithmetic( RationalImpl ) ) 50 49 struct Rational { 51 50 RationalImpl numerator, denominator; // invariant: denominator > 0 … … 54 53 // constructors 55 54 56 forall 55 forall( otype RationalImpl | arithmetic( RationalImpl ) ) 57 56 void ?{}( Rational(RationalImpl) * r ); 58 57 59 forall 58 forall( otype RationalImpl | arithmetic( RationalImpl ) ) 60 59 void ?{}( Rational(RationalImpl) * r, RationalImpl n ); 61 60 62 forall 61 forall( otype RationalImpl | arithmetic( RationalImpl ) ) 63 62 void ?{}( Rational(RationalImpl) * r, RationalImpl n, RationalImpl d ); 64 63 65 forall 64 forall( otype RationalImpl | arithmetic( RationalImpl ) ) 66 65 void ?{}( Rational(RationalImpl) * r, zero_t ); 67 66 68 forall 67 forall( otype RationalImpl | arithmetic( RationalImpl ) ) 69 68 void ?{}( Rational(RationalImpl) * r, one_t ); 70 69 71 // getter for numerator/denominator70 // numerator/denominator getter 72 71 73 forall 72 forall( otype RationalImpl | arithmetic( RationalImpl ) ) 74 73 RationalImpl numerator( Rational(RationalImpl) r ); 75 74 76 forall 75 forall( otype RationalImpl | arithmetic( RationalImpl ) ) 77 76 RationalImpl denominator( Rational(RationalImpl) r ); 78 forall ( otype RationalImpl | arithmetic( RationalImpl ) ) 77 78 forall( otype RationalImpl | arithmetic( RationalImpl ) ) 79 79 [ RationalImpl, RationalImpl ] ?=?( * [ RationalImpl, RationalImpl ] dest, Rational(RationalImpl) src ); 80 80 81 // setter for numerator/denominator81 // numerator/denominator setter 82 82 83 forall 83 forall( otype RationalImpl | arithmetic( RationalImpl ) ) 84 84 RationalImpl numerator( Rational(RationalImpl) r, RationalImpl n ); 85 85 86 forall 86 forall( otype RationalImpl | arithmetic( RationalImpl ) ) 87 87 RationalImpl denominator( Rational(RationalImpl) r, RationalImpl d ); 88 88 89 89 // comparison 90 90 91 forall 91 forall( otype RationalImpl | arithmetic( RationalImpl ) ) 92 92 int ?==?( Rational(RationalImpl) l, Rational(RationalImpl) r ); 93 93 94 forall 94 forall( otype RationalImpl | arithmetic( RationalImpl ) ) 95 95 int ?!=?( Rational(RationalImpl) l, Rational(RationalImpl) r ); 96 96 97 forall 97 forall( otype RationalImpl | arithmetic( RationalImpl ) ) 98 98 int ?<?( Rational(RationalImpl) l, Rational(RationalImpl) r ); 99 99 100 forall 100 forall( otype RationalImpl | arithmetic( RationalImpl ) ) 101 101 int ?<=?( Rational(RationalImpl) l, Rational(RationalImpl) r ); 102 102 103 forall 103 forall( otype RationalImpl | arithmetic( RationalImpl ) ) 104 104 int ?>?( Rational(RationalImpl) l, Rational(RationalImpl) r ); 105 105 106 forall 106 forall( otype RationalImpl | arithmetic( RationalImpl ) ) 107 107 int ?>=?( Rational(RationalImpl) l, Rational(RationalImpl) r ); 108 108 109 109 // arithmetic 110 110 111 forall 111 forall( otype RationalImpl | arithmetic( RationalImpl ) ) 112 112 Rational(RationalImpl) +?( Rational(RationalImpl) r ); 113 113 114 forall 114 forall( otype RationalImpl | arithmetic( RationalImpl ) ) 115 115 Rational(RationalImpl) -?( Rational(RationalImpl) r ); 116 116 117 forall 117 forall( otype RationalImpl | arithmetic( RationalImpl ) ) 118 118 Rational(RationalImpl) ?+?( Rational(RationalImpl) l, Rational(RationalImpl) r ); 119 119 120 forall 120 forall( otype RationalImpl | arithmetic( RationalImpl ) ) 121 121 Rational(RationalImpl) ?-?( Rational(RationalImpl) l, Rational(RationalImpl) r ); 122 122 123 forall 123 forall( otype RationalImpl | arithmetic( RationalImpl ) ) 124 124 Rational(RationalImpl) ?*?( Rational(RationalImpl) l, Rational(RationalImpl) r ); 125 125 126 forall 126 forall( otype RationalImpl | arithmetic( RationalImpl ) ) 127 127 Rational(RationalImpl) ?/?( Rational(RationalImpl) l, Rational(RationalImpl) r ); 128 128 129 129 // conversion 130 forall 130 forall( otype RationalImpl | arithmetic( RationalImpl ) | { double convert( RationalImpl ); } ) 131 131 double widen( Rational(RationalImpl) r ); 132 forall 132 forall( otype RationalImpl | arithmetic( RationalImpl ) | { double convert( RationalImpl ); RationalImpl convert( double );} ) 133 133 Rational(RationalImpl) narrow( double f, RationalImpl md ); 134 134 135 135 // I/O 136 forall 136 forall( otype RationalImpl | arithmetic( RationalImpl ) ) 137 137 forall( dtype istype | istream( istype ) | { istype * ?|?( istype *, RationalImpl * ); } ) 138 138 istype * ?|?( istype *, Rational(RationalImpl) * ); 139 139 140 forall 140 forall( otype RationalImpl | arithmetic( RationalImpl ) ) 141 141 forall( dtype ostype | ostream( ostype ) | { ostype * ?|?( ostype *, RationalImpl ); } ) 142 142 ostype * ?|?( ostype *, Rational(RationalImpl ) ); 143 144 #endif // RATIONAL_H145 143 146 144 // Local Variables: // -
src/libcfa/rational.c
r52a9004 r53a6c2a 10 10 // Created On : Wed Apr 6 17:54:28 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon May 15 21:29:23201713 // Update Count : 1 4912 // Last Modified On : Tue May 16 18:35:36 2017 13 // Update Count : 150 14 14 // 15 15 … … 22 22 // Calculate greatest common denominator of two numbers, the first of which may be negative. Used to reduce rationals. 23 23 // alternative: https://en.wikipedia.org/wiki/Binary_GCD_algorithm 24 forall 24 forall( otype RationalImpl | arithmetic( RationalImpl ) ) 25 25 static RationalImpl gcd( RationalImpl a, RationalImpl b ) { 26 26 for ( ;; ) { // Euclid's algorithm … … 33 33 } // gcd 34 34 35 forall 35 forall( otype RationalImpl | arithmetic( RationalImpl ) ) 36 36 static RationalImpl simplify( RationalImpl * n, RationalImpl * d ) { 37 37 if ( *d == (RationalImpl){0} ) { … … 46 46 // constructors 47 47 48 forall 48 forall( otype RationalImpl | arithmetic( RationalImpl ) ) 49 49 void ?{}( Rational(RationalImpl) * r ) { 50 50 r{ (RationalImpl){0}, (RationalImpl){1} }; 51 51 } // rational 52 52 53 forall 53 forall( otype RationalImpl | arithmetic( RationalImpl ) ) 54 54 void ?{}( Rational(RationalImpl) * r, RationalImpl n ) { 55 55 r{ n, (RationalImpl){1} }; 56 56 } // rational 57 57 58 forall 58 forall( otype RationalImpl | arithmetic( RationalImpl ) ) 59 59 void ?{}( Rational(RationalImpl) * r, RationalImpl n, RationalImpl d ) { 60 60 RationalImpl t = simplify( &n, &d ); // simplify … … 66 66 // getter for numerator/denominator 67 67 68 forall 68 forall( otype RationalImpl | arithmetic( RationalImpl ) ) 69 69 RationalImpl numerator( Rational(RationalImpl) r ) { 70 70 return r.numerator; 71 71 } // numerator 72 72 73 forall 73 forall( otype RationalImpl | arithmetic( RationalImpl ) ) 74 74 RationalImpl denominator( Rational(RationalImpl) r ) { 75 75 return r.denominator; 76 76 } // denominator 77 77 78 forall 78 forall( otype RationalImpl | arithmetic( RationalImpl ) ) 79 79 [ RationalImpl, RationalImpl ] ?=?( * [ RationalImpl, RationalImpl ] dest, Rational(RationalImpl) src ) { 80 80 return *dest = src.[ numerator, denominator ]; … … 83 83 // setter for numerator/denominator 84 84 85 forall 85 forall( otype RationalImpl | arithmetic( RationalImpl ) ) 86 86 RationalImpl numerator( Rational(RationalImpl) r, RationalImpl n ) { 87 87 RationalImpl prev = r.numerator; … … 92 92 } // numerator 93 93 94 forall 94 forall( otype RationalImpl | arithmetic( RationalImpl ) ) 95 95 RationalImpl denominator( Rational(RationalImpl) r, RationalImpl d ) { 96 96 RationalImpl prev = r.denominator; … … 104 104 // comparison 105 105 106 forall 106 forall( otype RationalImpl | arithmetic( RationalImpl ) ) 107 107 int ?==?( Rational(RationalImpl) l, Rational(RationalImpl) r ) { 108 108 return l.numerator * r.denominator == l.denominator * r.numerator; 109 109 } // ?==? 110 110 111 forall 111 forall( otype RationalImpl | arithmetic( RationalImpl ) ) 112 112 int ?!=?( Rational(RationalImpl) l, Rational(RationalImpl) r ) { 113 113 return ! ( l == r ); 114 114 } // ?!=? 115 115 116 forall 116 forall( otype RationalImpl | arithmetic( RationalImpl ) ) 117 117 int ?<?( Rational(RationalImpl) l, Rational(RationalImpl) r ) { 118 118 return l.numerator * r.denominator < l.denominator * r.numerator; 119 119 } // ?<? 120 120 121 forall 121 forall( otype RationalImpl | arithmetic( RationalImpl ) ) 122 122 int ?<=?( Rational(RationalImpl) l, Rational(RationalImpl) r ) { 123 123 return l.numerator * r.denominator <= l.denominator * r.numerator; 124 124 } // ?<=? 125 125 126 forall 126 forall( otype RationalImpl | arithmetic( RationalImpl ) ) 127 127 int ?>?( Rational(RationalImpl) l, Rational(RationalImpl) r ) { 128 128 return ! ( l <= r ); 129 129 } // ?>? 130 130 131 forall 131 forall( otype RationalImpl | arithmetic( RationalImpl ) ) 132 132 int ?>=?( Rational(RationalImpl) l, Rational(RationalImpl) r ) { 133 133 return ! ( l < r ); … … 137 137 // arithmetic 138 138 139 forall 139 forall( otype RationalImpl | arithmetic( RationalImpl ) ) 140 140 Rational(RationalImpl) +?( Rational(RationalImpl) r ) { 141 141 Rational(RationalImpl) t = { r.numerator, r.denominator }; … … 143 143 } // +? 144 144 145 forall 145 forall( otype RationalImpl | arithmetic( RationalImpl ) ) 146 146 Rational(RationalImpl) -?( Rational(RationalImpl) r ) { 147 147 Rational(RationalImpl) t = { -r.numerator, r.denominator }; … … 149 149 } // -? 150 150 151 forall 151 forall( otype RationalImpl | arithmetic( RationalImpl ) ) 152 152 Rational(RationalImpl) ?+?( Rational(RationalImpl) l, Rational(RationalImpl) r ) { 153 153 if ( l.denominator == r.denominator ) { // special case … … 160 160 } // ?+? 161 161 162 forall 162 forall( otype RationalImpl | arithmetic( RationalImpl ) ) 163 163 Rational(RationalImpl) ?-?( Rational(RationalImpl) l, Rational(RationalImpl) r ) { 164 164 if ( l.denominator == r.denominator ) { // special case … … 171 171 } // ?-? 172 172 173 forall 173 forall( otype RationalImpl | arithmetic( RationalImpl ) ) 174 174 Rational(RationalImpl) ?*?( Rational(RationalImpl) l, Rational(RationalImpl) r ) { 175 175 Rational(RationalImpl) t = { l.numerator * r.numerator, l.denominator * r.denominator }; … … 177 177 } // ?*? 178 178 179 forall 179 forall( otype RationalImpl | arithmetic( RationalImpl ) ) 180 180 Rational(RationalImpl) ?/?( Rational(RationalImpl) l, Rational(RationalImpl) r ) { 181 181 if ( r.numerator < (RationalImpl){0} ) { … … 190 190 // conversion 191 191 192 forall 192 forall( otype RationalImpl | arithmetic( RationalImpl ) | { double convert( RationalImpl ); } ) 193 193 double widen( Rational(RationalImpl) r ) { 194 194 return convert( r.numerator ) / convert( r.denominator ); … … 196 196 197 197 // http://www.ics.uci.edu/~eppstein/numth/frap.c 198 forall 198 forall( otype RationalImpl | arithmetic( RationalImpl ) | { double convert( RationalImpl ); RationalImpl convert( double ); } ) 199 199 Rational(RationalImpl) narrow( double f, RationalImpl md ) { 200 200 if ( md <= (RationalImpl){1} ) { // maximum fractional digits too small? … … 227 227 // I/O 228 228 229 forall 229 forall( otype RationalImpl | arithmetic( RationalImpl ) ) 230 230 forall( dtype istype | istream( istype ) | { istype * ?|?( istype *, RationalImpl * ); } ) 231 231 istype * ?|?( istype * is, Rational(RationalImpl) * r ) { … … 238 238 } // ?|? 239 239 240 forall 240 forall( otype RationalImpl | arithmetic( RationalImpl ) ) 241 241 forall( dtype ostype | ostream( ostype ) | { ostype * ?|?( ostype *, RationalImpl ); } ) 242 242 ostype * ?|?( ostype * os, Rational(RationalImpl ) r ) { -
src/libcfa/stdlib
r52a9004 r53a6c2a 10 10 // Created On : Thu Jan 28 17:12:35 2016 11 11 // 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 18 17 19 18 //--------------------------------------- … … 232 231 void swap( T * t1, T * t2 ); 233 232 234 #endif // STDLIB_H235 236 233 // Local Variables: // 237 234 // mode: c // -
src/tests/.expect/io.txt
r52a9004 r53a6c2a 4 4 123 5 5 6 opening delimiters 6 opening delimiters 7 7 x (1 x [2 x {3 x =4 x $5 x £6 x ¥7 x ¡8 x ¿9 x «10 8 8 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 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 11 11 12 opening/closing delimiters 12 opening/closing delimiters 13 13 x`1`x'2'x"3"x:4:x 5 x 6 x 14 14 7 … … 19 19 x 20 20 10 21 x 21 x 22 22 23 override opening/closing delimiters 23 override opening/closing delimiters 24 24 x ( 1 ) x 2 , x 3 :x: 4 25 25 26 input bacis types 26 input bacis types 27 27 28 output basic types 28 output basic types 29 29 A 30 30 1 2 3 4 5 6 7 8 … … 32 32 1.1+2.3i 1.1-2.3i 1.1-2.3i 33 33 34 tuples 35 1, 2, 3 3, 4, 534 tuples 35 1, 2, 3 4, 5, 6 36 36 37 toggle separator 37 toggle separator 38 38 1.11.21.3 39 39 1.1+2.3i1.1-2.3i1.1-2.3i 40 abcxyz 41 abcxyz 40 1.1+2.3i 1.1-2.3i1.1-2.3i 41 1.1+2.3i 1.1-2.3i 1.1-2.3i 42 1.1+2.3i1.1-2.3i 1.1-2.3i 43 abcxyz 44 abcxyz 42 45 43 change separator 44 from " "to ", $"46 change separator 47 from " " to ", $" 45 48 1.1, $1.2, $1.3 46 49 1.1+2.3i, $1.1-2.3i, $1.1-2.3i 47 abc, $xyz , $48 1, 2, 3, $ 3, 4, 550 abc, $xyz 51 1, 2, 3, $4, 5, 6 49 52 50 from ", $" to " "53 from ", $" to " " 51 54 1.1 1.2 1.3 52 55 1.1+2.3i 1.1-2.3i 1.1-2.3i 53 abc xyz 54 1, 2, 3 3, 4, 556 abc xyz 57 1, 2, 3 4, 5, 6 55 58 56 1 2 3 59 check sepOn/sepOff 60 1 2 3 57 61 12 3 58 1 2 359 62 1 2 3 60 63 1 2 3 61 64 65 1 2 3 66 67 check enable/disable 62 68 123 63 69 1 23 … … 65 71 123 66 72 1 2 3 67 123 73 123 68 74 1 2 3 69 75 70 1 2 3 3 4 5" "71 1, 2, 3 3, 4, 5 ","72 1, 2, 3 3, 4, 576 1 2 3 4 5 6 " " 77 1, 2, 3 4, 5, 6 " " 78 1, 2, 3 4, 5, 6 73 79 74 80 3, 4, a, 7.2 75 81 3, 4, a, 7.2 76 82 3 4 a 7.2 77 83 3 4 a 7.234a7.23 4 a 7.2 78 84 3-4-a-7.2^3^4^3-4-a-7.2 -
src/tests/io.c
r52a9004 r53a6c2a 10 10 // Created On : Wed Mar 2 16:56:02 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun Jul 2 09:40:58201713 // Update Count : 6812 // Last Modified On : Thu Jul 6 23:26:12 2017 13 // Update Count : 78 14 14 // 15 15 … … 104 104 105 105 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 ] ]; 107 107 sout | t1 | t2 | endl; // print tuple 108 108 sout | endl; … … 110 110 sout | "toggle separator" | endl; 111 111 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 115 118 sout | endl; 116 119 117 120 sout | "change separator" | endl; 118 sout | "from \" " | sepGet( sout )| "\"";121 sout | "from \"" | sep | "\""; 119 122 sepSet( sout, ", $" ); // change separator, maximum of 15 characters 120 sout | " to \" " | sepGet( sout )| "\"" | endl;123 sout | " to \"" | sep | "\"" | endl; 121 124 sout | f | d | ld | endl 122 125 | fc | dc | ldc | endl … … 124 127 | t1 | t2 | endl; // print tuple 125 128 sout | endl; 126 sout | "from \"" | sep Get( sout ) | "\"";129 sout | "from \"" | sep | "\" "; 127 130 sepSet( sout, " " ); // restore separator 128 sout | "to \"" | sep Get( sout )| "\"" | endl;131 sout | "to \"" | sep | "\"" | endl; 129 132 sout | f | d | ld | endl 130 133 | fc | dc | ldc | endl … … 133 136 sout | endl; 134 137 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 136 140 sout | 1 | sepOff | 2 | 3 | endl; // locally turn off implicit separator 137 sout | sepOn | 1 | 2 | 3 | sepOn | sepOff | endl; // separator at startof line138 sout | 1 | 2 | 3 | endl | sepOn; //separator at start of next line141 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 139 143 sout | 1 | 2 | 3 | endl; 140 144 sout | endl; 141 145 146 sout | "check enable/disable" | endl; 142 147 sout | sepDisable | 1 | 2 | 3 | endl; // globally turn off implicit separation 143 148 sout | 1 | sepOn | 2 | 3 | endl; // locally turn on implicit separator … … 149 154 sout | endl; 150 155 156 // sout | fmt( d, "%8.3f" ) || endl; 157 // sout | endl; 158 151 159 sepSetTuple( sout, " " ); // set tuple separator from ", " to " " 152 sout | t1 | t2 | " \"" | sep GetTuple( sout )| "\"" | endl;160 sout | t1 | t2 | " \"" | sep | "\"" | endl; 153 161 sepSetTuple( sout, ", " ); // reset tuple separator to ", " 154 sout | t1 | t2 | " \"" | sep GetTuple( sout )| "\"" | endl;162 sout | t1 | t2 | " \"" | sep | "\"" | endl; 155 163 sout | t1 | t2 | endl; // print tuple 156 164 sout | endl;
Note: See TracChangeset
for help on using the changeset viewer.