Changeset aa25216
- Timestamp:
- Aug 25, 2023, 12:53:55 PM (15 months ago)
- Branches:
- master
- Children:
- 8f2aa3c
- Parents:
- 88001dd
- Location:
- libcfa/src
- Files:
-
- 2 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 } // ?|? -
libcfa/src/iostream.hfa
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 11:35:02202313 // Update Count : 53 012 // Last Modified On : Fri Aug 25 11:55:46 2023 13 // Update Count : 533 14 14 // 15 15 … … 20 20 21 21 // *********************************** ostream *********************************** 22 23 22 24 23 forall( ostype & ) … … 305 304 } // ?|? 306 305 307 308 306 // *********************************** istream *********************************** 309 310 307 311 308 #define ISTYPE_VOID( T ) void ?|?( istype &, T ) … … 403 400 } // distribution 404 401 405 406 402 // *********************************** exceptions *********************************** 407 403 408 409 404 ExceptionDecl( cstring_length ); 410 411 405 412 406 // *********************************** manipulators *********************************** … … 416 410 union { 417 411 const char * scanset; 418 char delimit ;412 char delimit[2]; 419 413 }; 420 414 int wd; // width … … 440 434 _Istream_Cstr skip( const char scanset[] ) { return (_Istream_Cstr){ 0p, {scanset}, -1, {.all : 0} }; } 441 435 _Istream_Cstr skip( unsigned int wd ) { return (_Istream_Cstr){ 0p, {0p}, wd, {.all : 0} }; } 442 _Istream_Cstr & getline( _Istream_Cstr & fmt, const char delimit = '\n' ) { fmt.delimit = delimit; fmt.flags.delimit = true; return fmt; } 436 _Istream_Cstr & getline( _Istream_Cstr & fmt, const char delimit = '\n' ) { 437 fmt.delimit[0] = delimit; fmt.delimit[1] = '\0'; fmt.flags.delimit = true; fmt.flags.inex = true; return fmt; } 443 438 _Istream_Cstr & incl( const char scanset[], _Istream_Cstr & fmt ) { fmt.scanset = scanset; fmt.flags.inex = false; return fmt; } 444 439 _Istream_Cstr & excl( const char scanset[], _Istream_Cstr & fmt ) { fmt.scanset = scanset; fmt.flags.inex = true; return fmt; } … … 502 497 INPUT_FMT_DECL( long double _Complex ) 503 498 504 505 499 // *********************************** time *********************************** 506 507 500 508 501 #include <time_t.hfa> // Duration (constructors) / Time (constructors)
Note: See TracChangeset
for help on using the changeset viewer.