Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/iostream.cfa

    r714e206 r211def2  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Feb 10 09:28:32 2024
    13 // Update Count     : 1946
     12// Last Modified On : Wed Feb  7 22:19:59 2024
     13// Update Count     : 1918
    1414//
    1515
     
    774774forall( istype & | basic_istream( istype ) ) {
    775775        istype & ?|?( istype & is, bool & b ) {
    776                 if ( eof( is ) ) throwResume ExceptionInst( missing_data );
    777776                char val[6];
    778777                int args = fmt( is, "%5s", val );
    779                 if ( ! eof( is ) && args != 1 ) throwResume ExceptionInst( missing_data );
     778                if ( args != -1 && args != 1 ) throwResume ExceptionInst( missing_data );
    780779                if ( strcmp( val, "true" ) == 0 ) b = true;
    781780                else if ( strcmp( val, "false" ) == 0 ) b = false;
     
    788787
    789788        istype & ?|?( istype & is, char & c ) {
    790                 if ( eof( is ) ) throwResume ExceptionInst( missing_data );
    791789                char temp;
    792790                for () {
    793791                        int args = fmt( is, "%c", &temp );
    794                         if ( ! eof( is ) && args != 1 ) throwResume ExceptionInst( missing_data );
     792                        if ( args != -1 && args != 1 ) throwResume ExceptionInst( missing_data );
    795793                        // do not overwrite parameter with newline unless appropriate
    796794                        if ( temp != '\n' || getANL$( is ) ) { c = temp; break; }
     
    801799
    802800        istype & ?|?( istype & is, signed char & sc ) {
    803                 if ( eof( is ) ) throwResume ExceptionInst( missing_data );
    804801                int args = fmt( is, "%hhi", &sc );
    805                 if ( args != 1 ) throwResume ExceptionInst( missing_data );
     802                if ( args != -1 && args != 1 ) throwResume ExceptionInst( missing_data );
    806803                return is;
    807804        } // ?|?
    808805
    809806        istype & ?|?( istype & is, unsigned char & usc ) {
    810                 if ( eof( is ) ) throwResume ExceptionInst( missing_data );
    811807                int args = fmt( is, "%hhi", &usc );
    812                 if ( ! eof( is ) && args != 1 ) throwResume ExceptionInst( missing_data );
     808                if ( args != -1 && args != 1 ) throwResume ExceptionInst( missing_data );
    813809                return is;
    814810        } // ?|?
    815811
    816812        istype & ?|?( istype & is, short int & si ) {
    817                 if ( eof( is ) ) throwResume ExceptionInst( missing_data );
    818813                int args = fmt( is, "%hi", &si );
    819                 if ( ! eof( is ) && args != 1 ) throwResume ExceptionInst( missing_data );
     814                if ( args != -1 && args != 1 ) throwResume ExceptionInst( missing_data );
    820815                return is;
    821816        } // ?|?
    822817
    823818        istype & ?|?( istype & is, unsigned short int & usi ) {
    824                 if ( eof( is ) ) throwResume ExceptionInst( missing_data );
    825819                int args = fmt( is, "%hi", &usi );
    826                 if ( ! eof( is ) && args != 1 ) throwResume ExceptionInst( missing_data );
     820                if ( args != -1 && args != 1 ) throwResume ExceptionInst( missing_data );
    827821                return is;
    828822        } // ?|?
    829823
    830824        istype & ?|?( istype & is, int & i ) {
    831                 if ( eof( is ) ) throwResume ExceptionInst( missing_data );
    832825                int args = fmt( is, "%i", &i );
    833                 if ( ! eof( is ) && args != 1 ) throwResume ExceptionInst( missing_data );
     826                if ( args != -1 && args != 1 ) throwResume ExceptionInst( missing_data );
    834827                return is;
    835828        } // ?|?
    836829
    837830        istype & ?|?( istype & is, unsigned int & ui ) {
    838                 if ( eof( is ) ) throwResume ExceptionInst( missing_data );
    839831                int args = fmt( is, "%i", &ui );
    840                 if ( ! eof( is ) && args != 1 ) throwResume ExceptionInst( missing_data );
     832                if ( args != -1 && args != 1 ) throwResume ExceptionInst( missing_data );
    841833                return is;
    842834        } // ?|?
    843835
    844836        istype & ?|?( istype & is, long int & li ) {
    845                 if ( eof( is ) ) throwResume ExceptionInst( missing_data );
    846837                int args = fmt( is, "%li", &li );
    847                 if ( ! eof( is ) && args != 1 ) throwResume ExceptionInst( missing_data );
     838                if ( args != -1 && args != 1 ) throwResume ExceptionInst( missing_data );
    848839                return is;
    849840        } // ?|?
    850841
    851842        istype & ?|?( istype & is, unsigned long int & ulli ) {
    852                 if ( eof( is ) ) throwResume ExceptionInst( missing_data );
    853843                int args = fmt( is, "%li", &ulli );
    854                 if ( ! eof( is ) && args != 1 ) throwResume ExceptionInst( missing_data );
     844                if ( args != -1 && args != 1 ) throwResume ExceptionInst( missing_data );
    855845                return is;
    856846        } // ?|?
    857847
    858848        istype & ?|?( istype & is, long long int & lli ) {
    859                 if ( eof( is ) ) throwResume ExceptionInst( missing_data );
    860849                int args = fmt( is, "%lli", &lli );
    861                 if ( ! eof( is ) && args != 1 ) throwResume ExceptionInst( missing_data );
     850                if ( args != -1 && args != 1 ) throwResume ExceptionInst( missing_data );
    862851                return is;
    863852        } // ?|?
    864853
    865854        istype & ?|?( istype & is, unsigned long long int & ulli ) {
    866                 if ( eof( is ) ) throwResume ExceptionInst( missing_data );
    867855                int args = fmt( is, "%lli", &ulli );
    868                 if ( ! eof( is ) && args != 1 ) throwResume ExceptionInst( missing_data );
     856                if ( args != -1 && args != 1 ) throwResume ExceptionInst( missing_data );
    869857                return is;
    870858        } // ?|?
     
    893881
    894882        istype & ?|?( istype & is, float & f ) {
    895                 if ( eof( is ) ) throwResume ExceptionInst( missing_data );
    896883                int args = fmt( is, "%f", &f );
    897                 if ( ! eof( is ) && args != 1 ) throwResume ExceptionInst( missing_data );
     884                if ( args != -1 && args != 1 ) throwResume ExceptionInst( missing_data );
    898885                return is;
    899886        } // ?|?
    900887
    901888        istype & ?|?( istype & is, double & d ) {
    902                 if ( eof( is ) ) throwResume ExceptionInst( missing_data );
    903889                int args = fmt( is, "%lf", &d );
    904                 if ( ! eof( is ) && args != 1 ) throwResume ExceptionInst( missing_data );
     890                if ( args != -1 && args != 1 ) throwResume ExceptionInst( missing_data );
    905891                return is;
    906892        } // ?|?
    907893
    908894        istype & ?|?( istype & is, long double & ld ) {
    909                 if ( eof( is ) ) throwResume ExceptionInst( missing_data );
    910895                int args = fmt( is, "%Lf", &ld );
    911                 if ( ! eof( is ) && args != 1 ) throwResume ExceptionInst( missing_data );
     896                if ( args != -1 && args != 1 ) throwResume ExceptionInst( missing_data );
    912897                return is;
    913898        } // ?|?
    914899
    915900        istype & ?|?( istype & is, float _Complex & fc ) {
    916                 if ( eof( is ) ) throwResume ExceptionInst( missing_data );
    917901                float re, im;
    918902                int args = fmt( is, "%f%fi", &re, &im );
    919                 if ( ! eof( is ) && args != 2 ) throwResume ExceptionInst( missing_data );
     903                if ( args != -1 && args != 2 ) throwResume ExceptionInst( missing_data );
    920904                fc = re + im * _Complex_I;
    921905                return is;
     
    923907
    924908        istype & ?|?( istype & is, double _Complex & dc ) {
    925                 if ( eof( is ) ) throwResume ExceptionInst( missing_data );
    926909                double re, im;
    927910                int args = fmt( is, "%lf%lfi", &re, &im );
    928                 if ( ! eof( is ) && args != 2 ) throwResume ExceptionInst( missing_data );
     911                if ( args != -1 && args != 2 ) throwResume ExceptionInst( missing_data );
    929912                dc = re + im * _Complex_I;
    930913                return is;
     
    932915
    933916        istype & ?|?( istype & is, long double _Complex & ldc ) {
    934                 if ( eof( is ) ) throwResume ExceptionInst( missing_data );
    935917                long double re, im;
    936918                int args = fmt( is, "%Lf%Lfi", &re, &im );
    937                 if ( ! eof( is ) && args != 2 ) throwResume ExceptionInst( missing_data );
     919                if ( args != -1 && args != 2 ) throwResume ExceptionInst( missing_data );
    938920                ldc = re + im * _Complex_I;
    939921                return is;
     
    941923
    942924        istype & ?|?( istype & is, const char fmt[] ) {
    943                 if ( eof( is ) ) throwResume ExceptionInst( missing_data );
    944925                size_t len = strlen( fmt );
    945                 char fmtstr[len + 16];
    946                 strcpy( fmtstr, fmt );                                                  // copy format and add %n
    947                 strcpy( &fmtstr[len], "%n" );
     926                char fmt2[len + 16];
     927                strcpy( fmt2, fmt );                                                    // copy format and add %n
     928                strcpy( &fmt2[len], "%n" );
    948929                int len2 = -1;
    949                 fmt( is, fmtstr, &len2 );
    950                 if ( ! eof( is ) && len2 == -1 ) throwResume ExceptionInst( missing_data );
     930                int args = fmt( is, fmt2, &len2 );
     931                if ( args != -1 && len2 == -1 ) throwResume ExceptionInst( missing_data );
    951932                return is;
    952933        } // ?|?
     
    982963forall( istype & | basic_istream( istype ) ) {
    983964        istype & ?|?( istype & is, _Istream_Cskip f ) {
    984                 if ( eof( is ) ) throwResume ExceptionInst( missing_data );
     965                // printf( "skip %s %d\n", f.scanset, f.wd );
    985966                if ( f.scanset ) {
    986967                        int nscanset = strlen(f.scanset);
     
    990971                        strcpy( &fmtstr[pos], f.scanset );  pos += nscanset;
    991972                        strcpy( &fmtstr[pos], "]" );
    992                         fmt( is, fmtstr, "" );                                          // skip scanset, zero or more
     973                        fmt( is, fmtstr, "" );                                          // skip scanset
    993974                } else {
    994975                        char ch;
     976                        // fprintf( stderr, "skip " );
    995977                        for ( f.wd ) {                                                          // skip N characters
    996                                 int args = fmt( is, "%c", &ch );
    997                                 if ( ! eof( is ) && args != 1 ) throwResume ExceptionInst( missing_data );
     978                          if ( eof( is ) ) break;
     979                                fmt( is, "%c", &ch );
     980                                // fprintf( stderr, "`%c' ", ch );
    998981                        } // for
    999982                } // if
     
    1002985
    1003986        istype & ?|?( istype & is, _Istream_Cquoted f ) with( f.cstr ) {
    1004                 if ( eof( is ) ) throwResume ExceptionInst( missing_data );
    1005987                int args;
    1006988          fini: {
    1007                         char rfmt[5] = { ' ', delimiters[0], '%', 'n', '\0' };
    1008                         int len = -1;                                                           // may not be set in fmt
    1009                         args = fmt( is, rfmt, &len );                           // remove leading whitespace and quote
    1010                         if ( eof( is ) || len == -1 ) break fini;
     989                        args = fmt( is, "%*[ \f\n\r\t\v]" );            // remove leading whitespace
     990                  if ( eof( is ) ) break fini;
     991                        char rfmt[4] = { delimiters[0], '%', 'n', '\0' };
     992                        int len = 0;                                                            // may not be set in fmt
     993                        args = fmt( is, rfmt, &len );                           // remove leading quote
     994                  if ( len == 0 || eof( is ) ) break fini;
    1011995
    1012996                        // Change the remainder of the read into a getline by reseting the closing delimiter.
     
    10271011
    10281012        istype & ?|?( istype & is, _Istream_Cstr f ) with( f.cstr ) {
    1029                 if ( eof( is ) ) throwResume ExceptionInst( missing_data );
    10301013                const char * scanset;
    10311014                size_t nscanset = 0;
     
    10631046                                fmt( is, "%c", &peek );                                 // check for whitespace terminator
    10641047                                // fprintf( stderr, "peek %d '%c'\n", args, peek );
    1065                                 if ( ! eof( is ) ) {                                    // can only fail at eof
     1048                                if ( ! eof( is ) ) {
    10661049                                        ungetc( is, peek );
    10671050                                        if ( ! isspace( peek ) ) throwResume ExceptionInst( cstring_length );
     
    10731056                        if ( flags.delimiter ) {                                        // getline
    10741057                                int len = 0;                                                    // may not be set in fmt
    1075                                 if ( delimiters[2] != '\0' ) {                  // (quoted) read single character ?
     1058                                if ( delimiters[2] != '\0' ) {                  // read single character ?
    10761059                                        sprintf( &fmtstr[pos], "c%%n" );
    10771060                                } else {
     
    10801063                                if ( flags.ignore ) args = fmt( is, fmtstr, &len ); // no string argument for '*'
    10811064                                else args = fmt( is, fmtstr, s, &len );
    1082 
    1083                                 // cannot have empty character constant ''
    1084                                 if ( delimiters[2] != '\0' && len != 1 ) throwResume ExceptionInst( missing_data );
    1085 
    10861065                                if ( check && len == rwd && ! eof( is ) ) {     // might not fit
    10871066                                        char peek;
     
    11171096                } // if
    11181097                if ( args == 1 && eof( is ) ) {                                 // data but scan ended at EOF
     1098                        // fprintf( stderr, "clear\n" );
    11191099                        clear( is );                                                            // => reset EOF => detect again on next read
    11201100                } // if
Note: See TracChangeset for help on using the changeset viewer.