Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/iostream.cfa

    r0860d9c r2fa0237  
    2222#include <float.h>                                                                              // DBL_DIG, LDBL_DIG
    2323#include <complex.h>                                                                    // creal, cimag
    24 #include <ctype.h>                                                                              // isspace
    2524//#include <stdio.h>
    2625
     
    3029extern char *strcpy (char *__restrict __dest, const char *__restrict __src) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1, 2)));
    3130extern 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);
    3331} // extern "C"
    3432
     
    962960        istype & ?|?( istype & is, _Istream_Cskip f ) {
    963961                // printf( "skip %s %d\n", f.scanset, f.wd );
    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                 }
     962                if ( f.scanset ) fmt( is, f.scanset, "" );              // no input arguments
    976963                else for ( f.wd ) fmt( is, "%*c" );
    977964                return is;
     
    993980                        // wd is buffer bytes available (for input chars + null terminator)
    994981                        // rwd is count of input chars
    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
     982                        int rwd = f.flags.rwd ? f.wd : (f.wd - 1);
    1003983                        start += sprintf( &fmtstr[start], "%d", rwd );
    1004984                }
     
    10201000
    10211001                int check = f.wd - 2;
    1022                 if (! f.flags.ignore ) {
    1023                         f.s[0] = '\0';
    1024                         if ( ! f.flags.rwd ) f.s[check] = '\0';         // insert sentinel
    1025                 }
     1002                if ( ! f.flags.rwd ) f.s[check] = '\0';                 // insert sentinel
    10261003                len = fmt( is, fmtstr, f.s );
    10271004                //fprintf( stderr, "KK %s %zd %d %c %s\n", fmtstr, len, check, f.s[check], f.s );
    10281005
    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
     1006                if ( ! f.flags.rwd && f.s[check] != '\0' )              // sentinel overwritten ?
     1007                        throw (cstring_length){ &cstring_length_vt };
    10471008
    10481009                if ( f.flags.delimiter ) {                                              // getline ?
Note: See TracChangeset for help on using the changeset viewer.