Changeset 04138cc
- Timestamp:
- Jan 22, 2025, 8:24:44 AM (14 hours ago)
- Branches:
- master
- Children:
- 373f098
- Parents:
- 5db17077
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/iostream.cfa
r5db17077 r04138cc 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Jan 20 18:45:43202513 // Update Count : 20 6312 // 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 () { … … 950 950 strcpy( &fmtstr[len], "%n" ); 951 951 len = -1; 952 // scanf cursor does not move if no match 952 // scanf cursor does not move if no match, so eof cannot be detected. 953 953 fmt( is, fmtstr, &len ); // can be called with EOF on 954 954 if ( ! eof( is ) && len == -1 ) throwResume ExceptionInst( missing_data ); … … 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.