Changeset 3ac5fd8
- Timestamp:
- Aug 17, 2024, 3:15:21 PM (11 months ago)
- Branches:
- master
- Children:
- df2e00f
- Parents:
- afb15cf
- Files:
-
- 20 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/theses/jiada_liang_MMath/CFAenum.tex
rafb15cf r3ac5fd8 471 471 E e; 472 472 473 for () { 474 try { 475 @sin | e@; 476 } catch( missing_data * ) { 477 sout | "missing data"; 478 continue; // try again 473 try { 474 for () { 475 try { 476 @sin | e@; 477 } catch( missing_data * ) { 478 sout | "missing data"; 479 continue; // try again 480 } 481 sout | e | "= " | value( e ); 479 482 } 480 if ( eof( sin ) ) break; 481 sout | e | "= " | value( e ); 482 } 483 } catch( end_of_file ) {} 483 484 } 484 485 \end{cfa} -
doc/user/user.tex
rafb15cf r3ac5fd8 11 11 %% Created On : Wed Apr 6 14:53:29 2016 12 12 %% Last Modified By : Peter A. Buhr 13 %% Last Modified On : Fri Jul 26 06:56:11202414 %% Update Count : 695 513 %% Last Modified On : Thu Aug 15 22:23:30 2024 14 %% Update Count : 6957 15 15 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 16 16 … … 4656 4656 \VRef[Figure]{f:CFACommand-LineProcessing} demonstrates the file operations by showing the idiomatic \CFA command-line processing and copying an input file to an output file. 4657 4657 Note, a stream variable may be copied because it is a reference to an underlying stream data-structures. 4658 \Textbf{All I/O errors are handled as exceptions}, but end-of-file is not an exception as C programmers are use to explicitly checking for it.4658 \Textbf{All unusual I/O cases are handled as exceptions, including end-of-file.} 4659 4659 4660 4660 \begin{figure} … … 4686 4686 in | nlOn; §\C{// turn on reading newline}§ 4687 4687 char ch; 4688 for () { §\C{// read/write characters}§ 4689 in | ch; 4690 if ( eof( in ) ) break; §\C{// eof ?}§ 4691 out | ch; 4692 } // for 4688 try { 4689 for () { §\C{// read/write characters}§ 4690 in | ch; 4691 out | ch; 4692 } // for 4693 } catch( end_of_file * ) { §\C{// end-of-file raised}§ 4694 } // try 4693 4695 } // main 4694 4696 \end{cfa} -
libcfa/src/collections/string_res.cfa
rafb15cf r3ac5fd8 10 10 // Created On : Fri Sep 03 11:00:00 2021 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Apr 15 21:56:27202413 // Update Count : 8 512 // Last Modified On : Sat Aug 17 14:08:01 2024 13 // Update Count : 86 14 14 // 15 15 … … 251 251 252 252 ifstream & ?|?( ifstream & is, _Istream_Rquoted f ) with( f.rstr ) { 253 if ( eof( is ) ) throwResume ExceptionInst( missing_data);253 if ( eof( is ) ) throwResume ExceptionInst( end_of_file ); 254 254 int args; 255 255 fini: { -
libcfa/src/enum.cfa
rafb15cf r3ac5fd8 40 40 istype & ?|?( istype & is, E & e ) { 41 41 // fprintf( stderr, "here0\n" ); 42 if ( eof( is ) ) throwResume ExceptionInst( missing_data);42 if ( eof( is ) ) throwResume ExceptionInst( end_of_file ); 43 43 44 44 // Match longest input enumerator string to enumerator labels, where enumerator names are unique. … … 59 59 60 60 fmt( is, " " ); // skip optional whitespace 61 if ( eof( is ) ) throwResume ExceptionInst( end_of_file ); 62 61 63 for ( c; max ) { // scan columns of the label matix (some columns missing) 62 64 int args = fmt( is, "%c", &ch ); // read character -
libcfa/src/iostream.cfa
rafb15cf r3ac5fd8 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Aug 2 07:38:44202413 // Update Count : 20 2112 // Last Modified On : Sat Aug 17 12:31:47 2024 13 // Update Count : 2038 14 14 // 15 15 … … 777 777 forall( istype & | basic_istream( istype ) ) { 778 778 istype & ?|?( istype & is, bool & b ) { 779 if ( eof( is ) ) throwResume ExceptionInst( missing_data);779 if ( eof( is ) ) throwResume ExceptionInst( end_of_file ); 780 780 int len = -1; // len not set if no match 781 // Optional leading whitespace at start of strings.781 // remove optional leading whitespace at start of strings. 782 782 fmt( is, " " FALSE "%n", &len ); // try false 783 783 if ( len != sizeof( FALSE ) - 1 ) { // -1 removes null terminate … … 792 792 793 793 istype & ?|?( istype & is, char & c ) { 794 if ( eof( is ) ) throwResume ExceptionInst( missing_data);794 if ( eof( is ) ) throwResume ExceptionInst( end_of_file ); 795 795 char temp; 796 796 for () { 797 797 int args = fmt( is, "%c", &temp ); 798 if ( ! eof( is ) && args != 1 ) throwResume ExceptionInst( missing_data ); 798 if ( eof( is ) ) throwResume ExceptionInst( end_of_file ); 799 assert( args == 1 ); // if not EOF => a single character must be read 799 800 // do not overwrite parameter with newline unless appropriate 800 801 if ( temp != '\n' || getANL$( is ) ) { c = temp; break; } 801 if ( eof( is ) ) break;802 802 } // for 803 803 return is; … … 805 805 806 806 istype & ?|?( istype & is, signed char & sc ) { 807 if ( eof( is ) ) throwResume ExceptionInst( missing_data);808 int args = fmt( is, "%hhi", &sc ); 809 if ( args != 1 ) throwResume ExceptionInst( missing_data );807 if ( eof( is ) ) throwResume ExceptionInst( end_of_file ); 808 int args = fmt( is, "%hhi", &sc ); // can be multiple characters (100) 809 if ( ! eof( is ) && args != 1 ) throwResume ExceptionInst( missing_data ); 810 810 return is; 811 811 } // ?|? 812 812 813 813 istype & ?|?( istype & is, unsigned char & usc ) { 814 if ( eof( is ) ) throwResume ExceptionInst( missing_data);815 int args = fmt( is, "%hhi", &usc ); 814 if ( eof( is ) ) throwResume ExceptionInst( end_of_file ); 815 int args = fmt( is, "%hhi", &usc ); // can be multiple characters (-100) 816 816 if ( ! eof( is ) && args != 1 ) throwResume ExceptionInst( missing_data ); 817 817 return is; … … 819 819 820 820 istype & ?|?( istype & is, short int & si ) { 821 if ( eof( is ) ) throwResume ExceptionInst( missing_data);821 if ( eof( is ) ) throwResume ExceptionInst( end_of_file ); 822 822 int args = fmt( is, "%hi", &si ); 823 823 if ( ! eof( is ) && args != 1 ) throwResume ExceptionInst( missing_data ); … … 826 826 827 827 istype & ?|?( istype & is, unsigned short int & usi ) { 828 if ( eof( is ) ) throwResume ExceptionInst( missing_data);828 if ( eof( is ) ) throwResume ExceptionInst( end_of_file ); 829 829 int args = fmt( is, "%hi", &usi ); 830 830 if ( ! eof( is ) && args != 1 ) throwResume ExceptionInst( missing_data ); … … 833 833 834 834 istype & ?|?( istype & is, int & i ) { 835 if ( eof( is ) ) throwResume ExceptionInst( missing_data);835 if ( eof( is ) ) throwResume ExceptionInst( end_of_file ); 836 836 int args = fmt( is, "%i", &i ); 837 837 if ( ! eof( is ) && args != 1 ) throwResume ExceptionInst( missing_data ); … … 840 840 841 841 istype & ?|?( istype & is, unsigned int & ui ) { 842 if ( eof( is ) ) throwResume ExceptionInst( missing_data);842 if ( eof( is ) ) throwResume ExceptionInst( end_of_file ); 843 843 int args = fmt( is, "%i", &ui ); 844 844 if ( ! eof( is ) && args != 1 ) throwResume ExceptionInst( missing_data ); … … 847 847 848 848 istype & ?|?( istype & is, long int & li ) { 849 if ( eof( is ) ) throwResume ExceptionInst( missing_data);849 if ( eof( is ) ) throwResume ExceptionInst( end_of_file ); 850 850 int args = fmt( is, "%li", &li ); 851 851 if ( ! eof( is ) && args != 1 ) throwResume ExceptionInst( missing_data ); … … 854 854 855 855 istype & ?|?( istype & is, unsigned long int & ulli ) { 856 if ( eof( is ) ) throwResume ExceptionInst( missing_data);856 if ( eof( is ) ) throwResume ExceptionInst( end_of_file ); 857 857 int args = fmt( is, "%li", &ulli ); 858 858 if ( ! eof( is ) && args != 1 ) throwResume ExceptionInst( missing_data ); … … 861 861 862 862 istype & ?|?( istype & is, long long int & lli ) { 863 if ( eof( is ) ) throwResume ExceptionInst( missing_data);863 if ( eof( is ) ) throwResume ExceptionInst( end_of_file ); 864 864 int args = fmt( is, "%lli", &lli ); 865 865 if ( ! eof( is ) && args != 1 ) throwResume ExceptionInst( missing_data ); … … 868 868 869 869 istype & ?|?( istype & is, unsigned long long int & ulli ) { 870 if ( eof( is ) ) throwResume ExceptionInst( missing_data);870 if ( eof( is ) ) throwResume ExceptionInst( end_of_file ); 871 871 int args = fmt( is, "%lli", &ulli ); 872 872 if ( ! eof( is ) && args != 1 ) throwResume ExceptionInst( missing_data ); … … 891 891 } // for 892 892 if ( sign ) ullli = -ullli; 893 } else if ( sign ) ungetc( '-', is ); // return minus when no digits893 } // if 894 894 return is; 895 895 } // ?|? … … 897 897 898 898 istype & ?|?( istype & is, float & f ) { 899 if ( eof( is ) ) throwResume ExceptionInst( missing_data);899 if ( eof( is ) ) throwResume ExceptionInst( end_of_file ); 900 900 int args = fmt( is, "%f", &f ); 901 901 if ( ! eof( is ) && args != 1 ) throwResume ExceptionInst( missing_data ); … … 904 904 905 905 istype & ?|?( istype & is, double & d ) { 906 if ( eof( is ) ) throwResume ExceptionInst( missing_data);906 if ( eof( is ) ) throwResume ExceptionInst( end_of_file ); 907 907 int args = fmt( is, "%lf", &d ); 908 908 if ( ! eof( is ) && args != 1 ) throwResume ExceptionInst( missing_data ); … … 911 911 912 912 istype & ?|?( istype & is, long double & ld ) { 913 if ( eof( is ) ) throwResume ExceptionInst( missing_data);913 if ( eof( is ) ) throwResume ExceptionInst( end_of_file ); 914 914 int args = fmt( is, "%Lf", &ld ); 915 915 if ( ! eof( is ) && args != 1 ) throwResume ExceptionInst( missing_data ); … … 918 918 919 919 istype & ?|?( istype & is, float _Complex & fc ) { 920 if ( eof( is ) ) throwResume ExceptionInst( missing_data);920 if ( eof( is ) ) throwResume ExceptionInst( end_of_file ); 921 921 float re, im; 922 922 int args = fmt( is, "%f%fi", &re, &im ); … … 927 927 928 928 istype & ?|?( istype & is, double _Complex & dc ) { 929 if ( eof( is ) ) throwResume ExceptionInst( missing_data);929 if ( eof( is ) ) throwResume ExceptionInst( end_of_file ); 930 930 double re, im; 931 931 int args = fmt( is, "%lf%lfi", &re, &im ); … … 936 936 937 937 istype & ?|?( istype & is, long double _Complex & ldc ) { 938 if ( eof( is ) ) throwResume ExceptionInst( missing_data);938 if ( eof( is ) ) throwResume ExceptionInst( end_of_file ); 939 939 long double re, im; 940 940 int args = fmt( is, "%Lf%Lfi", &re, &im ); … … 945 945 946 946 istype & ?|?( istype & is, const char fmt[] ) { // match text 947 if ( eof( is ) ) throwResume ExceptionInst( missing_data);947 if ( eof( is ) ) throwResume ExceptionInst( end_of_file ); 948 948 size_t len = strlen( fmt ); 949 949 char fmtstr[len + 16]; … … 953 953 // scanf cursor does not move if no match 954 954 fmt( is, fmtstr, &len ); 955 if ( ! eof( is ) &&len == -1 ) throwResume ExceptionInst( missing_data );955 if ( len == -1 ) throwResume ExceptionInst( missing_data ); 956 956 return is; 957 957 } // ?|? … … 987 987 forall( istype & | basic_istream( istype ) ) { 988 988 istype & ?|?( istype & is, _Istream_Cskip f ) { 989 if ( eof( is ) ) throwResume ExceptionInst( missing_data);989 if ( eof( is ) ) throwResume ExceptionInst( end_of_file ); 990 990 if ( f.scanset ) { 991 991 int nscanset = strlen(f.scanset); … … 1000 1000 for ( f.wd ) { // skip N characters 1001 1001 int args = fmt( is, "%c", &ch ); 1002 if ( args != 1 ) throwResume ExceptionInst( missing_data );1002 if ( ! eof( is ) && args != 1 ) throwResume ExceptionInst( missing_data ); 1003 1003 } // for 1004 1004 } // if … … 1007 1007 1008 1008 istype & ?|?( istype & is, _Istream_Cquoted f ) with( f.cstr ) { 1009 if ( eof( is ) ) throwResume ExceptionInst( missing_data);1009 if ( eof( is ) ) throwResume ExceptionInst( end_of_file ); 1010 1010 int args; 1011 1011 fini: { … … 1032 1032 1033 1033 istype & ?|?( istype & is, _Istream_Cstr f ) with( f.cstr ) { 1034 if ( eof( is ) ) throwResume ExceptionInst( missing_data);1034 if ( eof( is ) ) throwResume ExceptionInst( end_of_file ); 1035 1035 const char * scanset; 1036 1036 size_t nscanset = 0; -
libcfa/src/iostream.hfa
rafb15cf r3ac5fd8 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Aug 2 07:37:57202413 // Update Count : 76 012 // Last Modified On : Thu Aug 15 18:21:22 2024 13 // Update Count : 761 14 14 // 15 15 … … 374 374 // *********************************** exceptions *********************************** 375 375 376 ExceptionDecl( end_of_file ); // read encounters end of file 376 377 ExceptionDecl( missing_data ); // read finds no appropriate data 377 378 ExceptionDecl( cstring_length ); // character string size exceeded -
libcfa/src/parseconfig.cfa
rafb15cf r3ac5fd8 105 105 106 106 static [ bool ] comments( & ifstream in, size_t size, [] char name ) { 107 while () { 108 in | wdi( size, name ); 109 if ( eof( in ) ) return true; 110 if ( name[0] != '#' ) return false; 111 in | nl; // ignore remainder of line 112 } // while 107 bool comment = false; 108 try { 109 while () { 110 in | wdi( size, name ); 111 if ( name[0] != '#' ) break; 112 in | nl; // ignore remainder of line 113 } // while 114 } catch( end_of_file * ) { 115 comment = true; 116 } // try 117 return comment; 113 118 } // comments 114 119 … … 125 130 [256] char value; 126 131 127 while () { // parameter names can appear in any order 128 // NOTE: Must add check to see if already read in value for this key, 129 // once we switch to using hash table as intermediate storage 130 if ( comments( in, 64, key ) ) break; // eof ? 131 in | wdi( 256, value ); 132 133 add_kv_pair( *kv_pairs, key, value ); 134 135 if ( eof( in ) ) break; 136 in | nl; // ignore remainder of line 137 } // for 132 try { 133 while () { // parameter names can appear in any order 134 // NOTE: Must add check to see if already read in value for this key, 135 // once we switch to using hash table as intermediate storage 136 if ( comments( in, 64, key ) ) break; // eof ? 137 in | wdi( 256, value ); 138 139 add_kv_pair( *kv_pairs, key, value ); 140 141 in | nl; // ignore remainder of line 142 } // while 143 } catch( end_of_file * ) { 144 } // try 138 145 } catch( open_failure * ex; ex->istream == &in ) { 139 146 delete( kv_pairs ); -
tests/.expect/copyfile.txt
rafb15cf r3ac5fd8 10 10 // Created On : Fri Jun 19 13:44:05 2020 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Jun 5 21:20:07 202313 // Update Count : 512 // Last Modified On : Sat Aug 17 14:18:47 2024 13 // Update Count : 11 14 14 // 15 15 … … 22 22 23 23 try { 24 choose ( argc ) { 25 case 2, 3:24 choose ( argc ) { // terminate if command-line errors 25 case 3, 2: 26 26 open( in, argv[1] ); // open input file first as output creates file 27 27 if ( argc == 3 ) open( out, argv[2] ); // do not create output unless input opens 28 28 case 1: ; // use default files 29 default: 29 default: // wrong number of options 30 30 exit | "Usage" | argv[0] | "[ input-file (default stdin) [ output-file (default stdout) ] ]"; 31 31 } // choose … … 41 41 42 42 char ch; 43 for () { // read all characters 44 in | ch; 45 if ( eof( in ) ) break; // eof ? 46 out | ch; 47 } //for 43 try { 44 for () { // read all characters 45 in | ch; 46 out | ch; 47 } // for 48 } catch( end_of_file * ) { 49 } // try 48 50 } // main 49 50 // Local Variables: //51 // tab-width: 4 //52 // compile-command: "cfa copyfile.cfa" //53 // End: // -
tests/.in/copyfile.txt
rafb15cf r3ac5fd8 10 10 // Created On : Fri Jun 19 13:44:05 2020 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Jun 5 21:20:07 202313 // Update Count : 512 // Last Modified On : Sat Aug 17 14:18:47 2024 13 // Update Count : 11 14 14 // 15 15 … … 22 22 23 23 try { 24 choose ( argc ) { 25 case 2, 3:24 choose ( argc ) { // terminate if command-line errors 25 case 3, 2: 26 26 open( in, argv[1] ); // open input file first as output creates file 27 27 if ( argc == 3 ) open( out, argv[2] ); // do not create output unless input opens 28 28 case 1: ; // use default files 29 default: 29 default: // wrong number of options 30 30 exit | "Usage" | argv[0] | "[ input-file (default stdin) [ output-file (default stdout) ] ]"; 31 31 } // choose … … 41 41 42 42 char ch; 43 for () { // read all characters 44 in | ch; 45 if ( eof( in ) ) break; // eof ? 46 out | ch; 47 } //for 43 try { 44 for () { // read all characters 45 in | ch; 46 out | ch; 47 } // for 48 } catch( end_of_file * ) { 49 } // try 48 50 } // main 49 50 // Local Variables: //51 // tab-width: 4 //52 // compile-command: "cfa copyfile.cfa" //53 // End: // -
tests/concurrency/examples/quickSort.cfa
rafb15cf r3ac5fd8 11 11 // Created On : Wed Dec 6 12:15:52 2017 12 12 // Last Modified By : Peter A. Buhr 13 // Last Modified On : Mon Jan 1 12:07:59202414 // Update Count : 1 8813 // Last Modified On : Sat Aug 17 13:59:15 2024 14 // Update Count : 199 15 15 // 16 16 … … 145 145 146 146 if ( size == -1 ) { // generate output ? 147 for () { 148 unsortedfile | size; // read number of elements in the list 149 if ( eof( unsortedfile ) ) break; 150 151 int * values = aalloc( size ); // values to be sorted, too large to put on stack 152 for ( counter; size ) { // read unsorted numbers 153 unsortedfile | values[counter]; 154 if ( counter != 0 && counter % ValuesPerLine == 0 ) sortedfile | nl | " "; 155 sortedfile | values[counter]; 156 if ( counter < size - 1 && (counter + 1) % ValuesPerLine != 0 ) sortedfile | ' '; 147 int * values = 0p; 148 try { 149 for () { 150 unsortedfile | size; // read number of elements in the list 151 values = aalloc( size ); // values to be sorted, too large to put on stack 152 for ( counter; size ) { // read unsorted numbers 153 unsortedfile | values[counter]; 154 if ( counter != 0 && counter % ValuesPerLine == 0 ) sortedfile | nl | " "; 155 sortedfile | values[counter]; 156 if ( counter < size - 1 && (counter + 1) % ValuesPerLine != 0 ) sortedfile | ' '; 157 } // for 158 sortedfile | nl; 159 160 if ( size > 0 ) { // values to sort ? 161 Quicksort QS = { values, size - 1, 0 }; // sort values 162 } // wait until sort tasks terminate 163 for ( counter; size ) { // print sorted list 164 if ( counter != 0 && counter % ValuesPerLine == 0 ) sortedfile | nl | " "; 165 sortedfile | values[counter]; 166 if ( counter < size - 1 && (counter + 1) % ValuesPerLine != 0 ) sortedfile | ' '; 167 } // for 168 sortedfile | nl | nl; 169 170 delete( values ); 171 values = 0p; 157 172 } // for 158 sortedfile | nl; 159 160 if ( size > 0 ) { // values to sort ? 161 Quicksort QS = { values, size - 1, 0 }; // sort values 162 } // wait until sort tasks terminate 163 for ( counter; size ) { // print sorted list 164 if ( counter != 0 && counter % ValuesPerLine == 0 ) sortedfile | nl | " "; 165 sortedfile | values[counter]; 166 if ( counter < size - 1 && (counter + 1) % ValuesPerLine != 0 ) sortedfile | ' '; 167 } // for 168 sortedfile | nl | nl; 169 173 } catch( end_of_file * ) { 170 174 delete( values ); 171 } // for175 } // try 172 176 } else { // timing 173 177 PRNG prng; -
tests/copyfile.cfa
rafb15cf r3ac5fd8 10 10 // Created On : Fri Jun 19 13:44:05 2020 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Jun 5 21:20:19 202313 // Update Count : 712 // Last Modified On : Sat Aug 17 14:18:47 2024 13 // Update Count : 11 14 14 // 15 15 … … 23 23 try { 24 24 choose ( argc ) { // terminate if command-line errors 25 case 2, 3:25 case 3, 2: 26 26 open( in, argv[1] ); // open input file first as output creates file 27 27 if ( argc == 3 ) open( out, argv[2] ); // do not create output unless input opens … … 41 41 42 42 char ch; 43 for () { // read all characters 44 in | ch; 45 if ( eof( in ) ) break; // eof ? 46 out | ch; 47 } // for 43 try { 44 for () { // read all characters 45 in | ch; 46 out | ch; 47 } // for 48 } catch( end_of_file * ) { 49 } // try 48 50 } // main 49 50 // Local Variables: //51 // tab-width: 4 //52 // compile-command: "cfa copyfile.cfa" //53 // End: // -
tests/coroutine/.expect/fmtLines.txt
rafb15cf r3ac5fd8 9 9 E" d istr ibut ed w ith 10 10 Cfor all. //// fmt Line 11 s.cc --/ /// Auth or 12 : P eter A. 13 Buhr // C reat ed O n 14 : Su n Se p 17 21: 15 56:1 5 20 17// Las t Mo 16 difi ed B y : Pete r A. 17 Buh r// Last Mod ifie 18 d On : F ri M ar 2 2 13 19 :41: 03 2 019/ / Up date 20 Cou nt : 33/ /#in 21 clud e <f stre am.h fa># 22 incl ude <cor outi ne.h 23 fa>c orou tine For mat 24 { ch ar c h; 25 // used for com muni 26 cati on i nt g , b; 27 / / gl obal bec 28 ause use d in des truc 29 tor} ;voi d ?{ }( F orma 30 t & fmt ) { r esum 31 e( f mt ) ; / 32 / st art coro utin e}vo 33 id ^ ?{}( For mat & fm 34 t ) { if ( fm t.g 35 != 0 || fmt. b != 0 ) 36 sou t | nl;} void mai 37 n( F orma t & fmt ) { 38 for ( ;; ) { 39 // for as many cha 40 ract ers for ( f mt.g 41 = 0 ; fm t.g < 5; fmt 42 .g + = 1 ) { // grou 11 s.cc -- form at c hara 12 cter s in to b lock s of 13 4 a nd g roup s of 5 b 14 lock s pe r li ne// // A 15 utho r : Pe 16 ter A. B uhr/ / Cr eate 17 d On : Sun Sep 18 17 21:5 6:15 201 7// 19 Last Mod ifie d By : P 20 eter A. Buhr // L ast 21 Modi fied On : Sa t Au 22 g 17 14: 26:0 3 20 24// 23 Upd ate Coun t : 24 60// #inc lude <fs trea 25 m.hf a>#i nclu de < coro 26 utin e.hf a>co rout ine 27 Form at { cha r ch ; 28 // u sed for 29 comm unic atio n in t g, 30 b; // glo 31 bal beca use used in 32 dest ruct or}; void mai 33 n( F orma t & fmt ) wi 34 th( fmt ) { for () { 35 / / fo r as 36 man y ch arac ters fo 37 r ( g = 0; g < 5 ; g 38 += 1 ) { // grou 43 39 ps o f 5 bloc ks for 44 ( f mt.b = 0 ; fm t.b 45 < 4; fmt .b + = 1 ) { 46 // b lock s of 4 c hara 47 cter s for ( ; ; ) 48 { // f or n ewli 49 ne c hara cter s su 50 spen d; i f ( fmt. 51 ch ! = '\ n' ) bre ak; 52 // igno re n ewli ne 53 } // f or so ut | 54 fmt .ch; / / pr 55 int char acte r } // 56 for s out | " "; 57 / / pr int bloc 58 k se para tor } / / fo 59 r s out | nl ; 60 // pri nt g roup sep 61 arat or } // for} // 62 main void prt ( Fo rmat 63 & f mt, char ch ) { 64 f mt.c h = ch; r 65 esum e( f mt ) ;} / / pr 66 tint mai n() { Fo rmat 67 fmt ; ch ar c h; f or ( 68 ;; ) { sin | c h; 69 // r ead one 70 char acte r if ( eof 71 ( si n ) ) br eak; 72 / / eo f ? prt ( fm 73 t, c h ); } / / fo r} / 74 / ma in// Loc al V aria 75 bles : // // t ab-w idth 76 : 4 //// com pile -com 77 mand : "c fa f mtLi nes. 78 cfa" /// / En d: / / 40 ( b = 0 ; b < 4; b + 41 = 1 ) { / / bl ocks 42 of 4 ch arac ters 43 for () { // f 44 or n ewli ne c hara cter 45 s su spen d; 46 if ( ch != ' \n' ) br 47 eak; // i gnor e ne 48 wlin e } / / fo r 49 sou t | ch; / 50 / pr int char acte r 51 } // for s out | " 52 "; / / pr int 53 bloc k se para tor } / 54 / fo r s out | nl ; 55 / / pr int grou 56 p se para tor } // for 57 } // mai nvoi d ?{ }( F 58 orma t & fmt ) { resu 59 me( fmt ); 60 // p rime (st art) cor 61 outi ne}v oid ^?{} ( Fo 62 rmat & f mt ) wit h( f 63 mt ) { i f ( g != 0 | 64 | b != 0 ) s out | nl 65 ;}vo id f orma t( F orma 66 t & fmt ) { resu me( 67 fmt );} // f orma tint 68 mai n() { Fo rmat fmt 69 ; so ut | nlO ff; 70 // turn off aut 71 o ne wlin e tr y { for 72 () { / / re 73 ad u ntil end of file 74 s in | fmt .ch; 75 // r ead one char 76 acte r form at( fmt 77 ); // pus h ch 78 arac ter for form atti 79 ng } // for } c atch 80 ( en d_of _fil e * ) { 81 } // try } // mai n -
tests/coroutine/.in/fmtLines.txt
rafb15cf r3ac5fd8 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // fmtLines.cc -- 7 // fmtLines.cc -- format characters into blocks of 4 and groups of 5 blocks per line 8 8 // 9 9 // Author : Peter A. Buhr 10 10 // Created On : Sun Sep 17 21:56:15 2017 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Mar 22 13:41:03 201913 // Update Count : 3312 // Last Modified On : Sat Aug 17 14:26:03 2024 13 // Update Count : 60 14 14 // 15 15 … … 22 22 }; 23 23 24 void ?{}( Format & fmt ) { 25 resume( fmt ); // start coroutine 26 } 27 28 void ^?{}( Format & fmt ) { 29 if ( fmt.g != 0 || fmt.b != 0 ) sout | nl; 30 } 31 32 void main( Format & fmt ) { 33 for ( ;; ) { // for as many characters 34 for ( fmt.g = 0; fmt.g < 5; fmt.g += 1 ) { // groups of 5 blocks 35 for ( fmt.b = 0; fmt.b < 4; fmt.b += 1 ) { // blocks of 4 characters 36 for ( ;; ) { // for newline characters 24 void main( Format & fmt ) with( fmt ) { 25 for () { // for as many characters 26 for ( g = 0; g < 5; g += 1 ) { // groups of 5 blocks 27 for ( b = 0; b < 4; b += 1 ) { // blocks of 4 characters 28 for () { // for newline characters 37 29 suspend; 38 if ( fmt.ch != '\n' ) break;// ignore newline30 if ( ch != '\n' ) break; // ignore newline 39 31 } // for 40 sout | fmt.ch;// print character32 sout | ch; // print character 41 33 } // for 42 34 sout | " "; // print block separator 43 35 } // for 44 sout | nl; // print group separator36 sout | nl; // print group separator 45 37 } // for 46 38 } // main 47 39 48 void prt( Format & fmt, char ch ) { 49 fmt.ch = ch; 50 resume( fmt ); 51 } // prt 40 void ?{}( Format & fmt ) { 41 resume( fmt ); // prime (start) coroutine 42 } 43 44 void ^?{}( Format & fmt ) with( fmt ) { 45 if ( g != 0 || b != 0 ) sout | nl; 46 } 47 48 void format( Format & fmt ) { 49 resume( fmt ); 50 } // format 52 51 53 52 int main() { 54 53 Format fmt; 55 char ch;54 sout | nlOff; // turn off auto newline 56 55 57 for ( ;; ) { 58 sin | ch; // read one character 59 if ( eof( sin ) ) break; // eof ? 60 prt( fmt, ch ); 61 } // for 56 try { 57 for () { // read until end of file 58 sin | fmt.ch; // read one character 59 format( fmt ); // push character for formatting 60 } // for 61 } catch( end_of_file * ) { 62 } // try 62 63 } // main 63 64 // Local Variables: //65 // tab-width: 4 //66 // compile-command: "cfa fmtLines.cfa" //67 // End: // -
tests/coroutine/cntparens.cfa
rafb15cf r3ac5fd8 10 10 // Created On : Sat Apr 20 11:04:45 2019 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sat Apr 20 11:06:21 201913 // Update Count : 112 // Last Modified On : Thu Aug 15 20:39:34 2024 13 // Update Count : 2 14 14 // 15 15 … … 46 46 char ch; 47 47 48 for () { // read until end of file 49 sin | ch; // read one character 50 if ( eof( sin ) ) { sout | "Error"; break; } // eof ? 51 Status ret = next( cpns, ch ); // push character for formatting 52 if ( ret == Match ) { sout | "Match"; break; } 53 if ( ret == Error ) { sout | "Error"; break; } 54 } // for 48 try { 49 for () { // read until end of file 50 sin | ch; // read one character 51 Status ret = next( cpns, ch ); // push character for formatting 52 if ( ret == Match ) { sout | "Match"; break; } 53 if ( ret == Error ) { sout | "Error"; break; } 54 } // for 55 } catch( end_of_file * ) { 56 sout | "Error"; 57 } // try 55 58 } // main 56 59 -
tests/coroutine/devicedriver.cfa
rafb15cf r3ac5fd8 10 10 // Created On : Sat Mar 16 15:30:34 2019 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sat Jun 17 09:11:56 202313 // Update Count : 9 412 // Last Modified On : Thu Aug 15 18:45:45 2024 13 // Update Count : 96 14 14 // 15 15 … … 71 71 72 72 sin | nlOn; // read newline (all) characters 73 eof: for () { // read until end of file 74 sin | byte; // read one character 75 if ( eof( sin ) ) break eof; // eof ? 76 choose( next( driver, byte ) ) { // analyse character 77 case CONT: ; 78 case MSG: sout | "msg:" | msg; 79 case ESTX: sout | "STX in message"; 80 case ELNTH: sout | "message too long"; 81 case ECRC: sout | "CRC failure"; 82 } // choose 83 } // for 73 try { 74 for () { // read until end of file 75 sin | byte; // read one character 76 choose( next( driver, byte ) ) { // analyse character 77 case CONT: ; 78 case MSG: sout | "msg:" | msg; 79 case ESTX: sout | "STX in message"; 80 case ELNTH: sout | "message too long"; 81 case ECRC: sout | "CRC failure"; 82 } // choose 83 } // for 84 } catch( end_of_file * ) { 85 } // try 84 86 } // main 85 87 -
tests/coroutine/fmtLines.cfa
rafb15cf r3ac5fd8 10 10 // Created On : Sun Sep 17 21:56:15 2017 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Mar 22 13:41:16 201913 // Update Count : 5812 // Last Modified On : Sat Aug 17 14:26:03 2024 13 // Update Count : 60 14 14 // 15 15 … … 54 54 sout | nlOff; // turn off auto newline 55 55 56 eof: for () { // read until end of file 57 sin | fmt.ch; // read one character 58 if ( eof( sin ) ) break eof; // eof ? 59 format( fmt ); // push character for formatting 60 } // for 56 try { 57 for () { // read until end of file 58 sin | fmt.ch; // read one character 59 format( fmt ); // push character for formatting 60 } // for 61 } catch( end_of_file * ) { 62 } // try 61 63 } // main 62 63 // Local Variables: //64 // tab-width: 4 //65 // compile-command: "cfa fmtLines.cfa" //66 // End: // -
tests/enum_tests/input.cfa
rafb15cf r3ac5fd8 6 6 E e; 7 7 8 for () { 9 try { 10 sin | e; 11 } catch( missing_data * ) { 12 sout | "missing data"; 13 continue; // try again 14 } // try 15 if ( eof( sin ) ) break; 16 sout | e | "= " | value( e ); 17 } // for 18 } 8 try { 9 for () { 10 try { 11 sin | e; 12 } catch( missing_data * ) { 13 sout | "missing data"; 14 continue; // try again 15 } // try 16 sout | e | "= " | value( e ); 17 } // for 18 } catch( end_of_file * ) { 19 } // try 20 } // main -
tests/generator/.expect/fmtLines.txt
rafb15cf r3ac5fd8 9 9 E" d istr ibut ed w ith 10 10 Cfor all. //// fmt Line 11 s.cc --/ /// Auth or 12 : P eter A. 13 Buhr // C reat ed O n 14 : Su n Se p 17 21: 15 56:1 5 20 17// Las t Mo 16 difi ed B y : Pete r A. 17 Buh r// Last Mod ifie 18 d On : F ri M ar 2 2 13 19 :41: 03 2 019/ / Up date 20 Cou nt : 33/ /#in 21 clud e <f stre am.h fa># 22 incl ude <cor outi ne.h 23 fa>c orou tine For mat 24 { ch ar c h; 25 // used for com muni 26 cati on i nt g , b; 27 / / gl obal bec 28 ause use d in des truc 29 tor} ;voi d ?{ }( F orma 30 t & fmt ) { r esum 31 e( f mt ) ; / 32 / st art coro utin e}vo 33 id ^ ?{}( For mat & fm 34 t ) { if ( fm t.g 35 != 0 || fmt. b != 0 ) 36 sou t | nl;} void mai 37 n( F orma t & fmt ) { 38 for ( ;; ) { 39 // for as many cha 40 ract ers for ( f mt.g 41 = 0 ; fm t.g < 5; fmt 42 .g + = 1 ) { // grou 43 ps o f 5 bloc ks for 44 ( f mt.b = 0 ; fm t.b 45 < 4; fmt .b + = 1 ) { 46 // b lock s of 4 c hara 47 cter s for ( ; ; ) 48 { // f or n ewli 49 ne c hara cter s su 50 spen d; i f ( fmt. 51 ch ! = '\ n' ) bre ak; 52 // igno re n ewli ne 53 } // f or so ut | 54 fmt .ch; / / pr 55 int char acte r } // 56 for s out | " "; 57 / / pr int bloc 58 k se para tor } / / fo 59 r s out | nl ; 60 // pri nt g roup sep 61 arat or } // for} // 62 main void prt ( Fo rmat 63 & f mt, char ch ) { 64 f mt.c h = ch; r 65 esum e( f mt ) ;} / / pr 66 tint mai n() { Fo rmat 67 fmt ; ch ar c h; f or ( 68 ;; ) { sin | c h; 69 // r ead one 70 char acte r if ( eof 71 ( si n ) ) br eak; 72 / / eo f ? prt ( fm 73 t, c h ); } / / fo r} / 74 / ma in// Loc al V aria 75 bles : // // t ab-w idth 76 : 4 //// com pile -com 77 mand : "c fa f mtLi nes. 78 cfa" /// / En d: / / 11 s.cf a -- for mat char 12 acte rs i nto bloc ks o 13 f 4 and grou ps o f 5 14 bloc ks p er l ine/ /// 15 Auth or : T 16 hier ry D elis le// Cre 17 ated On : Thu 18 Mar 5 1 6:09 :08 2020 19 // L ast Modi fied By 20 : Pe ter A. B uhr/ / La 21 st M odif ied On : Sat 22 Aug 17 14:2 1:28 202 23 4// Upda te C ount 24 : 5 //#i nclu de < fstr 25 eam. hfa> gene rato r Fo 26 rmat { c har ch; 27 // use d fo r co 28 mmun icat ion int g, b 29 ; // g loba 30 l be caus e us ed i n de 31 stru ctor };vo id m ain( 32 For mat & fm t ) with 33 ( fm t ) { fo r () { 34 // for as m 35 any char acte rs for 36 ( g = 0; g < 5; g += 37 1 ) { / / gr oups 38 of 5 bl ocks f or ( 39 b = 0; b < 4; b += 40 1 ) { // bloc ks o 41 f 4 char acte rs fo 42 r () { // for 43 new line cha ract ers 44 susp end; if 45 ( c h != '\n ' ) brea 46 k; // ign ore newl 47 ine } // for s 48 out | ch ; // 49 prin t ch arac ter } 50 // f or sou t | " " 51 ; // prin t bl 52 ock sepa rato r } // 53 for sou t | nl; 54 // prin t gr oup 55 sepa rato r } // f or} 56 // m ainv oid ?{}( For 57 mat & fm t ) { re sume 58 ( fm t ); // 59 pri me ( star t) c orou 60 tine }voi d ^? {}( Form 61 at & fmt ) w ith( fmt 62 ) { if ( g != 0 || 63 b != 0 ) sou t | nl;} 64 void for mat( For mat 65 & fm t ) { re sume ( fm 66 t ); } // for mati nt m 67 ain( ) { Form at f mt; 68 sout | n lOff ; 69 / / tu rn o ff a uto 70 newl ine try { f or ( 71 ) { // read 72 unt il e nd o f fi le 73 sin | f mt.c h; 74 // rea d on e ch arac 75 ter fo rmat ( fm t ); 76 // p ush char 77 acte r fo r fo rmat ting 78 } // f or } cat ch( 79 end_ of_f ile * ) { } 80 // t ry} // m ain -
tests/generator/.in/fmtLines.txt
rafb15cf r3ac5fd8 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // fmtLines.c c --7 // fmtLines.cfa -- format characters into blocks of 4 and groups of 5 blocks per line 8 8 // 9 // Author : Peter A. Buhr10 // Created On : Sun Sep 17 21:56:15 20179 // Author : Thierry Delisle 10 // Created On : Thu Mar 5 16:09:08 2020 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Mar 22 13:41:03 201913 // Update Count : 3312 // Last Modified On : Sat Aug 17 14:21:28 2024 13 // Update Count : 5 14 14 // 15 15 16 16 #include <fstream.hfa> 17 #include <coroutine.hfa>18 17 19 coroutineFormat {18 generator Format { 20 19 char ch; // used for communication 21 20 int g, b; // global because used in destructor 22 21 }; 23 22 24 void ?{}( Format & fmt ) { 25 resume( fmt ); // start coroutine 26 } 27 28 void ^?{}( Format & fmt ) { 29 if ( fmt.g != 0 || fmt.b != 0 ) sout | nl; 30 } 31 32 void main( Format & fmt ) { 33 for ( ;; ) { // for as many characters 34 for ( fmt.g = 0; fmt.g < 5; fmt.g += 1 ) { // groups of 5 blocks 35 for ( fmt.b = 0; fmt.b < 4; fmt.b += 1 ) { // blocks of 4 characters 36 for ( ;; ) { // for newline characters 23 void main( Format & fmt ) with( fmt ) { 24 for () { // for as many characters 25 for ( g = 0; g < 5; g += 1 ) { // groups of 5 blocks 26 for ( b = 0; b < 4; b += 1 ) { // blocks of 4 characters 27 for () { // for newline characters 37 28 suspend; 38 if ( fmt.ch != '\n' ) break;// ignore newline29 if ( ch != '\n' ) break; // ignore newline 39 30 } // for 40 sout | fmt.ch;// print character31 sout | ch; // print character 41 32 } // for 42 33 sout | " "; // print block separator 43 34 } // for 44 sout | nl; // print group separator35 sout | nl; // print group separator 45 36 } // for 46 37 } // main 47 38 48 void prt( Format & fmt, char ch ) { 49 fmt.ch = ch; 50 resume( fmt ); 51 } // prt 39 void ?{}( Format & fmt ) { 40 resume( fmt ); // prime (start) coroutine 41 } 42 43 void ^?{}( Format & fmt ) with( fmt ) { 44 if ( g != 0 || b != 0 ) sout | nl; 45 } 46 47 void format( Format & fmt ) { 48 resume( fmt ); 49 } // format 52 50 53 51 int main() { 54 52 Format fmt; 55 char ch;53 sout | nlOff; // turn off auto newline 56 54 57 for ( ;; ) { 58 sin | ch; // read one character 59 if ( eof( sin ) ) break; // eof ? 60 prt( fmt, ch ); 61 } // for 55 try { 56 for () { // read until end of file 57 sin | fmt.ch; // read one character 58 format( fmt ); // push character for formatting 59 } // for 60 } catch( end_of_file * ) { 61 } // try 62 62 } // main 63 64 // Local Variables: //65 // tab-width: 4 //66 // compile-command: "cfa fmtLines.cfa" //67 // End: // -
tests/generator/fmtLines.cfa
rafb15cf r3ac5fd8 10 10 // Created On : Thu Mar 5 16:09:08 2020 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Jun 10 21:56:22 202113 // Update Count : 212 // Last Modified On : Sat Aug 17 14:21:28 2024 13 // Update Count : 5 14 14 // 15 15 … … 53 53 sout | nlOff; // turn off auto newline 54 54 55 eof: for () { // read until end of file 56 sin | fmt.ch; // read one character 57 if ( eof( sin ) ) break eof; // eof ? 58 format( fmt ); // push character for formatting 59 } // for 55 try { 56 for () { // read until end of file 57 sin | fmt.ch; // read one character 58 format( fmt ); // push character for formatting 59 } // for 60 } catch( end_of_file * ) { 61 } // try 60 62 } // main 61 62 // Local Variables: //63 // tab-width: 4 //64 // compile-command: "cfa fmtLines.cfa" //65 // End: //
Note: See TracChangeset
for help on using the changeset viewer.