Changes in libcfa/src/iostream.cfa [4aae2bd:8c13ca8]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/iostream.cfa
r4aae2bd r8c13ca8 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 3 10:53:13 202413 // Update Count : 18 9812 // Last Modified On : Fri Nov 17 13:33:12 2023 13 // Update Count : 1853 14 14 // 15 15 … … 984 984 } 985 985 986 istype & ?|?( istype & is, _Istream_Cquoted f ) with( f ){986 istype & ?|?( istype & is, _Istream_Cquoted f ) { 987 987 char fmtstr[32]; // storage scanset and format codes 988 988 fmtstr[0] = '%'; … … 992 992 bool check = true; 993 993 994 if ( cstr.flags.ignore ) { check = false; fmtstr[1] = '*'; pos += 1; }995 int rwd = cstr.wd;996 if ( cstr.wd != -1 ) {// => just ignore versus ignore with width994 if ( f.flags.ignore ) { check = false; fmtstr[1] = '*'; pos += 1; } 995 int rwd = f.wd; 996 if ( f.wd != -1 ) { // => just ignore versus ignore with width 997 997 // wd is buffer bytes available (for input chars + null terminator) 998 998 // rwd is count of input chars 999 999 // no maximum width necessary because text ignored => width is read width 1000 if ( cstr.flags.rwd ) check = false;1001 else rwd = cstr.wd - 1;1000 if ( f.flags.rwd ) check = false; 1001 else rwd = f.wd - 1; 1002 1002 pos += sprintf( &fmtstr[pos], "%d", rwd ); 1003 1003 } // if 1004 1004 1005 1005 int len = 0; // may not be set in fmt 1006 char enddelim;1007 if ( ! cstr.flags.inex ) { // => quoted getline1006 if ( ! f.flags.inex ) { // => quoted getline 1007 // fprintf( stderr, "quoted\n" ); 1008 1008 args = fmt( is, "%*[ \f\n\r\t\v]" ); // remove leading whitespace 1009 1009 if ( eof( is ) ) goto Eof; 1010 char rfmt[4] = { cstr.delimiters[0], '%', 'n', '\0' }; 1011 args = fmt( is, rfmt, &len ); // remove leading quote 1010 // args = fmt( is, (const char *)f.delimiter ); // remove leading quote 1011 args = fmt( is, "'%n", &len ); // remove leading quote 1012 fprintf( stderr, "quoted %d %d\n", args, len ); 1012 1013 if ( len == 0 || eof( is ) ) goto Eof; 1013 1014 } // if 1014 enddelim = cstr.delimiters[1] == '\0' ? cstr.delimiters[0] : cstr.delimiters[1]; 1015 sprintf( &fmtstr[pos], "[^%c]%%n", enddelim ); 1016 if ( cstr.flags.ignore ) args = fmt( is, fmtstr, &len ); // no string argument for '*' 1017 else args = fmt( is, fmtstr, cstr.s, &len ); 1015 sprintf( &fmtstr[pos], "[^%c]%%n", f.delimiter[0] ); 1016 // fprintf( stderr, "getline %s %d\n", fmtstr, f.wd ); 1017 if ( f.flags.ignore ) args = fmt( is, fmtstr, &len ); // no string argument for '*' 1018 else args = fmt( is, fmtstr, f.s, &len ); 1019 // fprintf( stderr, "getline %s %d %d %d\n", fmtstr, args, f.wd, eof( is ) ); 1018 1020 if ( check && len == rwd && ! eof( is ) ) { // might not fit 1019 1021 char peek; 1020 1022 fmt( is, "%c", &peek ); // check for delimiter 1023 // fprintf( stderr, "peek %d '%c'\n", args, peek ); 1021 1024 if ( ! eof( is ) ) { 1022 if ( peek != enddelim) {1025 if ( peek != f.delimiter[0] ) { 1023 1026 ungetc( is, peek ); 1024 1027 throwResume ExceptionInst( cstring_length ); … … 1027 1030 } else fmt( is, "%*c" ); // remove delimiter 1028 1031 Eof: ; 1029 if ( rwd > 0 && args == 0 ) cstr.s[0] = '\0';// read failed => no pattern match => set string to null1032 if ( rwd > 0 && args == 0 ) f.s[0] = '\0'; // read failed => no pattern match => set string to null 1030 1033 if ( args == 1 && eof( is ) ) { // data but scan ended at EOF 1034 // fprintf( stderr, "clear\n" ); 1031 1035 clear( is ); // => reset EOF => detect again on next read 1032 1036 } // if … … 1034 1038 } 1035 1039 1036 istype & ?|?( istype & is, _Istream_Cstr f ) with( f ){1040 istype & ?|?( istype & is, _Istream_Cstr f ) { 1037 1041 const char * scanset; 1038 1042 size_t nscanset = 0; 1039 if ( f lags.delimiter ) scanset = delimiters; // getline ?1043 if ( f.flags.delimiter ) scanset = f.delimiter; // getline ? 1040 1044 else scanset = f.scanset; 1041 1045 if ( scanset ) nscanset = strlen( scanset ); … … 1080 1084 if ( f.flags.delimiter ) { // getline 1081 1085 int len = 0; // may not be set in fmt 1082 sprintf( &fmtstr[pos], "[^%c]%%n", f.delimiters[0] ); 1086 if ( ! f.flags.inex ) { // => quoted getline 1087 // fprintf( stderr, "quoted\n" ); 1088 args = fmt( is, "%*[ \f\n\r\t\v]" ); // remove leading whitespace 1089 if ( eof( is ) ) goto X; 1090 args = fmt( is, "\"" ); // remove leading quote 1091 if ( eof( is ) ) goto X; 1092 } // if 1093 // fprintf( stderr, "getline\n" ); 1094 // sprintf( &fmtstr[pos], "[%s%s]%%n", f.flags.inex ? "^" : "", scanset ); 1095 sprintf( &fmtstr[pos], "[^%s]%%n", scanset ); 1096 // fprintf( stderr, "getline %s %d\n", fmtstr, f.wd ); 1083 1097 if ( f.flags.ignore ) args = fmt( is, fmtstr, &len ); // no string argument for '*' 1084 1098 else args = fmt( is, fmtstr, f.s, &len ); 1099 // fprintf( stderr, "getline %s %d %d %d\n", fmtstr, args, f.wd, eof( is ) ); 1085 1100 if ( check && len == rwd && ! eof( is ) ) { // might not fit 1086 fmtstr[0] = f.delimiters[0]; fmtstr[1] = '%'; fmtstr[2] = 'n'; fmtstr[3] = '\0'; 1087 fmt( is, fmtstr, &len ); // remove delimiter 1101 char peek; 1102 fmt( is, "%c", &peek ); // check for delimiter 1103 // fprintf( stderr, "peek %d '%c'\n", args, peek ); 1088 1104 if ( ! eof( is ) ) { 1089 // if ( peek != f.delimiter[0] ) { 1090 if ( len != 1 ) { 1091 // ungetc( is, peek ); 1105 if ( peek != f.delimiter[0] ) { 1106 ungetc( is, peek ); 1092 1107 throwResume ExceptionInst( cstring_length ); 1093 1108 } // if 1094 1109 } // if 1095 } else fmt( is, "%*c" ); // remove delimiter 1110 } else fmt( is, "%*c" ); // remove delimiter 1111 X: ; 1096 1112 } else { 1097 1113 // incl %[xxx], %*[xxx], %w[xxx], %*w[xxx]
Note:
See TracChangeset
for help on using the changeset viewer.