Changeset aa25216 for libcfa/src/iostream.cfa
- Timestamp:
- Aug 25, 2023, 12:53:55 PM (13 months ago)
- Branches:
- master
- Children:
- 8f2aa3c
- Parents:
- 88001dd
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/iostream.cfa
r88001dd raa25216 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Aug 24 10:25:20202313 // Update Count : 15 1612 // Last Modified On : Fri Aug 25 12:04:27 2023 13 // Update Count : 1526 14 14 // 15 15 … … 21 21 #include <float.h> // DBL_DIG, LDBL_DIG 22 22 #include <complex.h> // creal, cimag 23 //#include <string.h> // strlen, strcmp, memcpy 23 //#include <stdio.h> 24 24 25 extern "C" { 25 26 extern size_t strlen (const char *__s) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1))); … … 971 972 972 973 int check = f.wd - 1; 974 const char * scanset = f.scanset;; 975 if ( f.flags.delimit ) scanset = f.delimit; // getline ? 973 976 974 977 // getline 975 if ( f.flags.delimit ) {976 enum { size = 32 };977 char fmtstr[size];978 snprintf( fmtstr, size, "%%%d[^%c]s", f.wd, f.delimit );979 if ( ! f.flags.rwd ) f.s[check] = '\0'; // insert sentinel980 int len = fmt( is, fmtstr, f.s ); // read upto delimiter981 if ( ! f.flags.rwd && f.s[check] != '\0' ) // sentinel overwritten ?982 throw (cstring_length){ &cstring_length_vt };983 if ( len == 0 ) f.s[0] = '\0'; // empty read => argument unchanged => set empty984 //fprintf( stderr, "getline %s %s %d %d %d '%c'\n", fmtstr, f.s, len, f.wd, check, f.s[check] );985 if ( ! eof( is ) ) fmt( is, "%*c" ); // ignore delimiter986 return is;987 } // if978 // if ( f.flags.delimit ) { 979 // enum { size = 32 }; 980 // char fmtstr[size]; 981 // snprintf( fmtstr, size, "%%%d[^%c]s", f.wd, f.delimit ); 982 // if ( ! f.flags.rwd ) f.s[check] = '\0'; // insert sentinel 983 // int len = fmt( is, fmtstr, f.s ); // read upto delimiter 984 // if ( ! f.flags.rwd && f.s[check] != '\0' ) // sentinel overwritten ? 985 // throw (cstring_length){ &cstring_length_vt }; 986 // if ( len == 0 ) f.s[0] = '\0'; // empty read => argument unchanged => set empty 987 // // fprintf( stderr, "getline %s %s %d %d %d '%c'\n", fmtstr, f.s, len, f.wd, check, f.s[check] ); 988 // if ( ! eof( is ) ) fmt( is, "%*c" ); // ignore delimiter 989 // return is; 990 // } // if 988 991 989 992 size_t len = 0; 990 if ( f.scanset ) len = strlen( f.scanset );993 if ( scanset ) len = strlen( scanset ); 991 994 char fmtstr[len + 16]; 992 995 int start = 1; … … 995 998 if ( f.wd != -1 ) { start += sprintf( &fmtstr[start], "%d", f.wd ); } 996 999 997 if ( ! f.scanset ) {1000 if ( ! scanset ) { 998 1001 // %s, %*s, %ws, %*ws 999 1002 fmtstr[start] = 's'; fmtstr[start + 1] = '\0'; … … 1004 1007 fmtstr[start] = '['; start += 1; 1005 1008 if ( f.flags.inex ) { fmtstr[start] = '^'; start += 1; } 1006 strcpy( &fmtstr[start], f.scanset );// copy includes '\0'1009 strcpy( &fmtstr[start], scanset ); // copy includes '\0' 1007 1010 len += start; 1008 1011 fmtstr[len] = ']'; fmtstr[len + 1] = '\0'; … … 1011 1014 1012 1015 if ( ! f.flags.rwd ) f.s[check] = '\0'; // insert sentinel 1013 fmt( is, fmtstr, f.s );1014 // fprintf( stderr, "KK %s %d %c\n", fmtstr, check, f.s[check] );1016 len = fmt( is, fmtstr, f.s ); 1017 //fprintf( stderr, "KK %s %zd %d %c\n", fmtstr, len, check, f.s[check] ); 1015 1018 if ( ! f.flags.rwd && f.s[check] != '\0' ) // sentinel overwritten ? 1016 1019 throw (cstring_length){ &cstring_length_vt }; 1020 1021 if ( f.flags.delimit ) { // getline ? 1022 if ( len == 0 ) f.s[0] = '\0'; // empty read => argument unchanged => set empty 1023 if ( ! eof( is ) ) fmt( is, "%*c" ); // ignore delimiter 1024 } //if 1017 1025 return is; 1018 1026 } // ?|?
Note: See TracChangeset
for help on using the changeset viewer.