Changeset f45772e for libcfa/src/iostream.cfa
- Timestamp:
- Oct 8, 2023, 9:14:31 AM (15 months ago)
- Branches:
- master
- Children:
- 92211d9
- Parents:
- 2261bcc (diff), 9689e54 (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
r2261bcc rf45772e 22 22 #include <float.h> // DBL_DIG, LDBL_DIG 23 23 #include <complex.h> // creal, cimag 24 #include <ctype.h> // isspace 24 25 //#include <stdio.h> 25 26 … … 29 30 extern char *strcpy (char *__restrict __dest, const char *__restrict __src) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1, 2))); 30 31 extern void *memcpy (void *__restrict __dest, const void *__restrict __src, size_t __n) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1, 2))); 32 extern char *strchr(const char *str, int ch); 31 33 } // extern "C" 32 34 … … 960 962 istype & ?|?( istype & is, _Istream_Cskip f ) { 961 963 // printf( "skip %s %d\n", f.scanset, f.wd ); 962 if ( f.scanset ) fmt( is, f.scanset, "" ); // no input arguments 964 if ( f.scanset ) { 965 int nscanset = strlen(f.scanset); 966 char fmtstr[ sizeof("%*[]") + nscanset ]; 967 int pos = 0; 968 fmtstr[pos] = '%'; pos += 1; 969 fmtstr[pos] = '*'; pos += 1; 970 fmtstr[pos] = '['; pos += 1; 971 strcpy( &fmtstr[pos], f.scanset ); pos += nscanset; 972 fmtstr[pos] = ']'; pos += 1; 973 fmtstr[pos] = '\0'; 974 fmt( is, fmtstr, (void*)0 ); // last arg is dummy: suppress gcc warning 975 } 963 976 else for ( f.wd ) fmt( is, "%*c" ); 964 977 return is; … … 980 993 // wd is buffer bytes available (for input chars + null terminator) 981 994 // rwd is count of input chars 982 int rwd = f.flags.rwd ? f.wd : (f.wd - 1); 995 int rwd; 996 if (f.flags.rwd) { 997 verify (f.wd >= 0); 998 rwd = f.wd; 999 } else { 1000 verify (f.wd >= 1); 1001 rwd = f.wd - 1; 1002 } // if 983 1003 start += sprintf( &fmtstr[start], "%d", rwd ); 984 1004 } … … 1000 1020 1001 1021 int check = f.wd - 2; 1002 if ( ! f.flags.rwd ) f.s[check] = '\0'; // insert sentinel 1022 if (! f.flags.ignore ) { 1023 f.s[0] = '\0'; 1024 if ( ! f.flags.rwd ) f.s[check] = '\0'; // insert sentinel 1025 } 1003 1026 len = fmt( is, fmtstr, f.s ); 1004 1027 //fprintf( stderr, "KK %s %zd %d %c %s\n", fmtstr, len, check, f.s[check], f.s ); 1005 1028 1006 if ( ! f.flags.rwd && f.s[check] != '\0' ) // sentinel overwritten ? 1007 throw (cstring_length){ &cstring_length_vt }; 1029 if ( ! f.flags.ignore && ! f.flags.rwd && f.s[check] != '\0' ) { // sentinel overwritten ? 1030 // buffer filled, but would we have kept going? 1031 if ( ! eof( is ) ) { 1032 char peek; 1033 fmt( is, "%c", &peek ); 1034 ungetc( is, peek ); 1035 bool hasMore; 1036 if (f.flags.delimiter) { // getline 1037 hasMore = (peek != f.delimiter[0]); 1038 } else if (f.scanset) { // incl/excl 1039 bool peekMatch = strchr(f.scanset, peek) != 0p; 1040 hasMore = f.flags.inex ? (!peekMatch) : (peekMatch); 1041 } else { // %s 1042 hasMore = !isspace(peek); 1043 } 1044 if (hasMore) throw (cstring_length){ &cstring_length_vt }; 1045 } // if 1046 } // if 1008 1047 1009 1048 if ( f.flags.delimiter ) { // getline ?
Note: See TracChangeset
for help on using the changeset viewer.