Changeset de8a0a4 for libcfa/src
- Timestamp:
- Jan 26, 2025, 6:37:05 PM (8 months ago)
- Branches:
- master
- Children:
- a950021
- Parents:
- 0f070a4 (diff), 11f92fac (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/iostream.cfa
r0f070a4 rde8a0a4 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun Oct 13 10:53:09 202413 // Update Count : 20 4112 // Last Modified On : Wed Jan 22 07:31:19 2025 13 // Update Count : 2079 14 14 // 15 15 … … 777 777 forall( istype & | basic_istream( istype ) ) { 778 778 istype & ?|?( istype & is, bool & b ) { 779 if ( eof( is ) ) throwResume ExceptionInst( end_of_file );780 779 int len = -1; // len not set if no match 781 // remove optional leading whitespace at start of strings.782 fmt( is, " " FALSE "%n", &len ); // try false780 fmt( is, " " ); // remove leading whitespace 781 fmt( is, FALSE "%n", &len ); // try false, returns 0 783 782 if ( len != sizeof( FALSE ) - 1 ) { // -1 removes null terminate 784 fmt( is, " " TRUE "%n", &len ); // try true 783 if ( eof( is ) ) throwResume ExceptionInst( end_of_file ); 784 fmt( is, " " ); // remove leading whitespace 785 fmt( is, TRUE "%n", &len ); // try true, returns 0 785 786 if ( len != sizeof( TRUE ) - 1 ) throwResume ExceptionInst( missing_data ); 786 787 b = true; … … 792 793 793 794 istype & ?|?( istype & is, char & c ) { 794 if ( eof( is ) ) throwResume ExceptionInst( end_of_file );795 795 char temp; 796 796 for () { 797 int args = fmt( is, "%c", &temp ); 797 int args = fmt( is, "%c", &temp ); // can be called with EOF on 798 798 if ( eof( is ) ) throwResume ExceptionInst( end_of_file ); 799 799 assert( args == 1 ); // if not EOF => a single character must be read … … 805 805 806 806 istype & ?|?( istype & is, signed char & sc ) { 807 if ( eof( is ) ) throwResume ExceptionInst( end_of_file );808 807 int args = fmt( is, "%hhi", &sc ); // can be multiple characters (100) 809 808 if ( ! eof( is ) && args != 1 ) throwResume ExceptionInst( missing_data ); 809 if ( eof( is ) && args != 1 ) throwResume ExceptionInst( end_of_file ); 810 810 return is; 811 811 } // ?|? 812 812 813 813 istype & ?|?( istype & is, unsigned char & usc ) { 814 if ( eof( is ) ) throwResume ExceptionInst( end_of_file );815 814 int args = fmt( is, "%hhi", &usc ); // can be multiple characters (-100) 816 815 if ( ! eof( is ) && args != 1 ) throwResume ExceptionInst( missing_data ); 816 if ( eof( is ) && args != 1 ) throwResume ExceptionInst( end_of_file ); 817 817 return is; 818 818 } // ?|? 819 819 820 820 istype & ?|?( istype & is, short int & si ) { 821 if ( eof( is ) ) throwResume ExceptionInst( end_of_file ); 822 int args = fmt( is, "%hi", &si ); 821 int args = fmt( is, "%hi", &si ); // can be called with EOF on 823 822 if ( ! eof( is ) && args != 1 ) throwResume ExceptionInst( missing_data ); 823 if ( eof( is ) && args != 1 ) throwResume ExceptionInst( end_of_file ); 824 824 return is; 825 825 } // ?|? 826 826 827 827 istype & ?|?( istype & is, unsigned short int & usi ) { 828 if ( eof( is ) ) throwResume ExceptionInst( end_of_file ); 829 int args = fmt( is, "%hi", &usi ); 828 int args = fmt( is, "%hi", &usi ); // can be called with EOF on 830 829 if ( ! eof( is ) && args != 1 ) throwResume ExceptionInst( missing_data ); 830 if ( eof( is ) && args != 1 ) throwResume ExceptionInst( end_of_file ); 831 831 return is; 832 832 } // ?|? 833 833 834 834 istype & ?|?( istype & is, int & i ) { 835 if ( eof( is ) ) throwResume ExceptionInst( end_of_file ); 836 int args = fmt( is, "%i", &i ); 835 int args = fmt( is, "%i", &i ); // can be called with EOF on 837 836 if ( ! eof( is ) && args != 1 ) throwResume ExceptionInst( missing_data ); 837 if ( eof( is ) && args != 1 ) throwResume ExceptionInst( end_of_file ); 838 838 return is; 839 839 } // ?|? 840 840 841 841 istype & ?|?( istype & is, unsigned int & ui ) { 842 if ( eof( is ) ) throwResume ExceptionInst( end_of_file ); 843 int args = fmt( is, "%i", &ui ); 842 int args = fmt( is, "%i", &ui ); // can be called with EOF on 844 843 if ( ! eof( is ) && args != 1 ) throwResume ExceptionInst( missing_data ); 844 if ( eof( is ) && args != 1 ) throwResume ExceptionInst( end_of_file ); 845 845 return is; 846 846 } // ?|? 847 847 848 848 istype & ?|?( istype & is, long int & li ) { 849 if ( eof( is ) ) throwResume ExceptionInst( end_of_file ); 850 int args = fmt( is, "%li", &li ); 849 int args = fmt( is, "%li", &li ); // can be called with EOF on 851 850 if ( ! eof( is ) && args != 1 ) throwResume ExceptionInst( missing_data ); 851 if ( eof( is ) && args != 1 ) throwResume ExceptionInst( end_of_file ); 852 852 return is; 853 853 } // ?|? 854 854 855 855 istype & ?|?( istype & is, unsigned long int & ulli ) { 856 if ( eof( is ) ) throwResume ExceptionInst( end_of_file ); 857 int args = fmt( is, "%li", &ulli ); 856 int args = fmt( is, "%li", &ulli ); // can be called with EOF on 858 857 if ( ! eof( is ) && args != 1 ) throwResume ExceptionInst( missing_data ); 858 if ( eof( is ) && args != 1 ) throwResume ExceptionInst( end_of_file ); 859 859 return is; 860 860 } // ?|? 861 861 862 862 istype & ?|?( istype & is, long long int & lli ) { 863 if ( eof( is ) ) throwResume ExceptionInst( end_of_file ); 864 int args = fmt( is, "%lli", &lli ); 863 int args = fmt( is, "%lli", &lli ); // can be called with EOF on 865 864 if ( ! eof( is ) && args != 1 ) throwResume ExceptionInst( missing_data ); 865 if ( eof( is ) && args != 1 ) throwResume ExceptionInst( end_of_file ); 866 866 return is; 867 867 } // ?|? 868 868 869 869 istype & ?|?( istype & is, unsigned long long int & ulli ) { 870 if ( eof( is ) ) throwResume ExceptionInst( end_of_file ); 871 int args = fmt( is, "%lli", &ulli ); 870 int args = fmt( is, "%lli", &ulli ); // can be called with EOF on 872 871 if ( ! eof( is ) && args != 1 ) throwResume ExceptionInst( missing_data ); 872 if ( eof( is ) && args != 1 ) throwResume ExceptionInst( end_of_file ); 873 873 return is; 874 874 } // ?|? … … 897 897 898 898 istype & ?|?( istype & is, float & f ) { 899 if ( eof( is ) ) throwResume ExceptionInst( end_of_file ); 900 int args = fmt( is, "%f", &f ); 899 int args = fmt( is, "%f", &f ); // can be called with EOF on 901 900 if ( ! eof( is ) && args != 1 ) throwResume ExceptionInst( missing_data ); 901 if ( eof( is ) && args != 1 ) throwResume ExceptionInst( end_of_file ); 902 902 return is; 903 903 } // ?|? 904 904 905 905 istype & ?|?( istype & is, double & d ) { 906 if ( eof( is ) ) throwResume ExceptionInst( end_of_file ); 907 int args = fmt( is, "%lf", &d ); 906 int args = fmt( is, "%lf", &d ); // can be called with EOF on 908 907 if ( ! eof( is ) && args != 1 ) throwResume ExceptionInst( missing_data ); 908 if ( eof( is ) && args != 1 ) throwResume ExceptionInst( end_of_file ); 909 909 return is; 910 910 } // ?|? 911 911 912 912 istype & ?|?( istype & is, long double & ld ) { 913 if ( eof( is ) ) throwResume ExceptionInst( end_of_file ); 914 int args = fmt( is, "%Lf", &ld ); 913 int args = fmt( is, "%Lf", &ld ); // can be called with EOF on 915 914 if ( ! eof( is ) && args != 1 ) throwResume ExceptionInst( missing_data ); 915 if ( eof( is ) && args != 1 ) throwResume ExceptionInst( end_of_file ); 916 916 return is; 917 917 } // ?|? 918 918 919 919 istype & ?|?( istype & is, float _Complex & fc ) { 920 if ( eof( is ) ) throwResume ExceptionInst( end_of_file );921 920 float re, im; 922 int args = fmt( is, "%f%fi", &re, &im ); 921 int args = fmt( is, "%f%fi", &re, &im ); // can be called with EOF on 923 922 if ( ! eof( is ) && args != 2 ) throwResume ExceptionInst( missing_data ); 923 if ( eof( is ) && args != 2 ) throwResume ExceptionInst( end_of_file ); 924 924 fc = re + im * _Complex_I; 925 925 return is; … … 927 927 928 928 istype & ?|?( istype & is, double _Complex & dc ) { 929 if ( eof( is ) ) throwResume ExceptionInst( end_of_file );930 929 double re, im; 931 int args = fmt( is, "%lf%lfi", &re, &im ); 930 int args = fmt( is, "%lf%lfi", &re, &im ); // can be called with EOF on 932 931 if ( ! eof( is ) && args != 2 ) throwResume ExceptionInst( missing_data ); 932 if ( eof( is ) && args != 2 ) throwResume ExceptionInst( end_of_file ); 933 933 dc = re + im * _Complex_I; 934 934 return is; … … 936 936 937 937 istype & ?|?( istype & is, long double _Complex & ldc ) { 938 if ( eof( is ) ) throwResume ExceptionInst( end_of_file );939 938 long double re, im; 940 int args = fmt( is, "%Lf%Lfi", &re, &im ); 939 int args = fmt( is, "%Lf%Lfi", &re, &im ); // can be called with EOF on 941 940 if ( ! eof( is ) && args != 2 ) throwResume ExceptionInst( missing_data ); 941 if ( eof( is ) && args != 2 ) throwResume ExceptionInst( end_of_file ); 942 942 ldc = re + im * _Complex_I; 943 943 return is; … … 945 945 946 946 istype & ?|?( istype & is, const char fmt[] ) { // match text 947 if ( eof( is ) ) throwResume ExceptionInst( end_of_file );948 947 size_t len = strlen( fmt ); 949 948 char fmtstr[len + 16]; … … 951 950 strcpy( &fmtstr[len], "%n" ); 952 951 len = -1; 953 // scanf cursor does not move if no match 954 fmt( is, fmtstr, &len ); 955 if ( len == -1 ) throwResume ExceptionInst( missing_data ); 952 // scanf cursor does not move if no match, so eof cannot be detected. 953 fmt( is, fmtstr, &len ); // can be called with EOF on 954 if ( ! eof( is ) && len == -1 ) throwResume ExceptionInst( missing_data ); 955 if ( eof( is ) && len == -1 ) throwResume ExceptionInst( end_of_file ); 956 956 return is; 957 957 } // ?|? … … 999 999 char ch; 1000 1000 for ( f.wd ) { // skip N characters 1001 int args = fmt( is, "%c", &ch ); 1001 int args = fmt( is, "%c", &ch ); // can be called with EOF on 1002 1002 if ( ! eof( is ) && args != 1 ) throwResume ExceptionInst( missing_data ); 1003 1003 } // for … … 1204 1204 forall( istype & | istream( istype ), E | CfaEnum( E ) | Serial( E ) ) 1205 1205 istype & ?|?( istype & is, E & e ) { 1206 // fprintf( stderr, "here0\n" ); 1207 if ( eof( is ) ) throwResume ExceptionInst( end_of_file ); 1206 // if ( eof( is ) ) throwResume ExceptionInst( end_of_file ); 1208 1207 1209 1208 // Match longest input enumerator string to enumerator labels, where enumerator names are unique. 1210 1209 1211 1210 int N = countof( E ), lnths[N], fred = 0; 1212 // printf( "N %d\n", N );1213 1211 int r = 0; 1214 // for ( s; E : r; 0~@ ) {1215 1212 for ( s; E ) { // scan string rows gathering lengths 1216 1213 lnths[r] = strlen( label( s ) ); 1217 1214 if ( lnths[r] > fred ) fred = lnths[r]; 1218 // fprintf( stderr, "%s %d %d\n", label( s ), lnths[r], fred );1219 1215 r += 1; 1220 1216 } // for … … 1223 1219 char ch, curr = '\0', prev = '\0'; 1224 1220 1225 fmt( is, " " ); // skip optionalwhitespace1221 fmt( is, " " ); // remove leading whitespace 1226 1222 if ( eof( is ) ) throwResume ExceptionInst( end_of_file ); 1227 1223 1228 1224 for ( c; fred ) { // scan columns of the label matix (some columns missing) 1229 1225 int args = fmt( is, "%c", &ch ); // read character 1230 // fprintf( stderr, "fmt args: %d eof: %d\n", args, eof(is) );1231 1226 if ( eof( is ) ) { 1232 // fprintf( stderr, "Eof1\n" );1233 1227 if ( c == 0 ) return is; // no characters read ? 1234 1228 clear( is ); // => read something => reset EOF => detect again on next read 1235 // fprintf( stderr, "Eof2\n" );1236 1229 break; 1237 1230 } // if 1238 1231 if ( args != 1 ) throwResume ExceptionInst( missing_data ); // may be unnecessary since reading single character 1239 1232 1240 // printf( "read '%c'\n", ch );1241 1233 for ( r; N ) { // scan enumeration strings for matching character in current column 1242 // printf( "%d %d %d\n", c, r, lnths[r] );1243 1234 if ( c < lnths[r] ) { // string long enough for this column check ? 1244 1235 char match = label( fromInt( r ) )[c]; // optimization 1245 // printf( "%c '%c'\n", match, ch );1246 1236 // Stop on first match, could be other matches. 1247 1237 if ( (match == ch) && (c == 0 || curr == label( fromInt( r ) )[c - 1]) ) { 1248 // printf( "match %d %d %d '%c' '%c' '%c' '%c' 'c'\n", c, r, lnths[r], match, ch, prev, label( fromInt( r ) )[c - 1] );1249 1238 mcol = c; // matching column 1250 1239 prev = curr; // last matching character … … 1254 1243 } // if 1255 1244 } else { 1256 // fprintf( stderr, "finished mcol: %d ch: '%c' curr: '%c' prev: '%c'\n", mcol, ch, curr, prev );1257 1245 ungetc( ch, is ); // push back last unmatching character 1258 1246 if ( mcol == -1 ) throwResume ExceptionInst( missing_data ); // no matching character in first column 1259 1247 break; 1260 1248 } // for 1261 // printf( "\n" );1262 // } else {1263 // fprintf( stderr, "finished2 %d\n", mcol );1264 1249 } // for 1265 1250 … … 1267 1252 if ( mcol == lnths[c] - 1 ) { 1268 1253 char match = label( fromInt( c ) )[mcol]; // optimization 1269 // printf( "finished1 mcol: %d c: %d lnth: %d match: '%c' curr: '%c' prev: '%c'\n", mcol, c, lnths[c], match, curr, prev );1270 1254 if ( (match == curr) && (mcol == 0 || prev == label( fromInt( c ) )[mcol - 1]) ) { 1271 1255 e = fromInt( c ); … … 1274 1258 } // if 1275 1259 } else { 1276 // fprintf( stderr, "finished3 %d\n", mcol );1277 1260 throwResume ExceptionInst( missing_data ); // no match in this column 1278 1261 } // for
Note:
See TracChangeset
for help on using the changeset viewer.