Changes in libcfa/src/iostream.cfa [04138cc:fd5d251]
- File:
-
- 1 edited
-
libcfa/src/iostream.cfa (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/iostream.cfa
r04138cc rfd5d251 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Jan 22 07:31:19202513 // Update Count : 20 7912 // Last Modified On : Mon Jan 20 18:45:43 2025 13 // Update Count : 2063 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 ); 779 780 int len = -1; // len not set if no match 780 fmt( is, " " ); // remove leading whitespace781 fmt( is, FALSE "%n", &len ); // try false, returns 0781 // remove optional leading whitespace at start of strings. 782 fmt( is, " " FALSE "%n", &len ); // try false 782 783 if ( len != sizeof( FALSE ) - 1 ) { // -1 removes null terminate 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 784 fmt( is, " " TRUE "%n", &len ); // try true 786 785 if ( len != sizeof( TRUE ) - 1 ) throwResume ExceptionInst( missing_data ); 787 786 b = true; … … 793 792 794 793 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 , so eof cannot be detected.952 // scanf cursor does not move if no match 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 // if ( eof( is ) ) throwResume ExceptionInst( end_of_file ); 1206 // fprintf( stderr, "here0\n" ); 1207 if ( eof( is ) ) throwResume ExceptionInst( end_of_file ); 1207 1208 1208 1209 // Match longest input enumerator string to enumerator labels, where enumerator names are unique. 1209 1210 1210 1211 int N = countof( E ), lnths[N], fred = 0; 1212 // printf( "N %d\n", N ); 1211 1213 int r = 0; 1214 // for ( s; E : r; 0~@ ) { 1212 1215 for ( s; E ) { // scan string rows gathering lengths 1213 1216 lnths[r] = strlen( label( s ) ); 1214 1217 if ( lnths[r] > fred ) fred = lnths[r]; 1218 // fprintf( stderr, "%s %d %d\n", label( s ), lnths[r], fred ); 1215 1219 r += 1; 1216 1220 } // for … … 1219 1223 char ch, curr = '\0', prev = '\0'; 1220 1224 1221 fmt( is, " " ); // remove leadingwhitespace1225 fmt( is, " " ); // skip optional whitespace 1222 1226 if ( eof( is ) ) throwResume ExceptionInst( end_of_file ); 1223 1227 1224 1228 for ( c; fred ) { // scan columns of the label matix (some columns missing) 1225 1229 int args = fmt( is, "%c", &ch ); // read character 1230 // fprintf( stderr, "fmt args: %d eof: %d\n", args, eof(is) ); 1226 1231 if ( eof( is ) ) { 1232 // fprintf( stderr, "Eof1\n" ); 1227 1233 if ( c == 0 ) return is; // no characters read ? 1228 1234 clear( is ); // => read something => reset EOF => detect again on next read 1235 // fprintf( stderr, "Eof2\n" ); 1229 1236 break; 1230 1237 } // if 1231 1238 if ( args != 1 ) throwResume ExceptionInst( missing_data ); // may be unnecessary since reading single character 1232 1239 1240 // printf( "read '%c'\n", ch ); 1233 1241 for ( r; N ) { // scan enumeration strings for matching character in current column 1242 // printf( "%d %d %d\n", c, r, lnths[r] ); 1234 1243 if ( c < lnths[r] ) { // string long enough for this column check ? 1235 1244 char match = label( fromInt( r ) )[c]; // optimization 1245 // printf( "%c '%c'\n", match, ch ); 1236 1246 // Stop on first match, could be other matches. 1237 1247 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] ); 1238 1249 mcol = c; // matching column 1239 1250 prev = curr; // last matching character … … 1243 1254 } // if 1244 1255 } else { 1256 // fprintf( stderr, "finished mcol: %d ch: '%c' curr: '%c' prev: '%c'\n", mcol, ch, curr, prev ); 1245 1257 ungetc( ch, is ); // push back last unmatching character 1246 1258 if ( mcol == -1 ) throwResume ExceptionInst( missing_data ); // no matching character in first column 1247 1259 break; 1248 1260 } // for 1261 // printf( "\n" ); 1262 // } else { 1263 // fprintf( stderr, "finished2 %d\n", mcol ); 1249 1264 } // for 1250 1265 … … 1252 1267 if ( mcol == lnths[c] - 1 ) { 1253 1268 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 ); 1254 1270 if ( (match == curr) && (mcol == 0 || prev == label( fromInt( c ) )[mcol - 1]) ) { 1255 1271 e = fromInt( c ); … … 1258 1274 } // if 1259 1275 } else { 1276 // fprintf( stderr, "finished3 %d\n", mcol ); 1260 1277 throwResume ExceptionInst( missing_data ); // no match in this column 1261 1278 } // for
Note:
See TracChangeset
for help on using the changeset viewer.