Changes in libcfa/src/iostream.cfa [714e206:211def2]
- File:
-
- 1 edited
-
libcfa/src/iostream.cfa (modified) (16 diffs)
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/iostream.cfa
r714e206 r211def2 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sat Feb 10 09:28:32202413 // Update Count : 19 4612 // Last Modified On : Wed Feb 7 22:19:59 2024 13 // Update Count : 1918 14 14 // 15 15 … … 774 774 forall( istype & | basic_istream( istype ) ) { 775 775 istype & ?|?( istype & is, bool & b ) { 776 if ( eof( is ) ) throwResume ExceptionInst( missing_data );777 776 char val[6]; 778 777 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 ); 780 779 if ( strcmp( val, "true" ) == 0 ) b = true; 781 780 else if ( strcmp( val, "false" ) == 0 ) b = false; … … 788 787 789 788 istype & ?|?( istype & is, char & c ) { 790 if ( eof( is ) ) throwResume ExceptionInst( missing_data );791 789 char temp; 792 790 for () { 793 791 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 ); 795 793 // do not overwrite parameter with newline unless appropriate 796 794 if ( temp != '\n' || getANL$( is ) ) { c = temp; break; } … … 801 799 802 800 istype & ?|?( istype & is, signed char & sc ) { 803 if ( eof( is ) ) throwResume ExceptionInst( missing_data );804 801 int args = fmt( is, "%hhi", &sc ); 805 if ( args != 1 ) throwResume ExceptionInst( missing_data );802 if ( args != -1 && args != 1 ) throwResume ExceptionInst( missing_data ); 806 803 return is; 807 804 } // ?|? 808 805 809 806 istype & ?|?( istype & is, unsigned char & usc ) { 810 if ( eof( is ) ) throwResume ExceptionInst( missing_data );811 807 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 ); 813 809 return is; 814 810 } // ?|? 815 811 816 812 istype & ?|?( istype & is, short int & si ) { 817 if ( eof( is ) ) throwResume ExceptionInst( missing_data );818 813 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 ); 820 815 return is; 821 816 } // ?|? 822 817 823 818 istype & ?|?( istype & is, unsigned short int & usi ) { 824 if ( eof( is ) ) throwResume ExceptionInst( missing_data );825 819 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 ); 827 821 return is; 828 822 } // ?|? 829 823 830 824 istype & ?|?( istype & is, int & i ) { 831 if ( eof( is ) ) throwResume ExceptionInst( missing_data );832 825 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 ); 834 827 return is; 835 828 } // ?|? 836 829 837 830 istype & ?|?( istype & is, unsigned int & ui ) { 838 if ( eof( is ) ) throwResume ExceptionInst( missing_data );839 831 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 ); 841 833 return is; 842 834 } // ?|? 843 835 844 836 istype & ?|?( istype & is, long int & li ) { 845 if ( eof( is ) ) throwResume ExceptionInst( missing_data );846 837 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 ); 848 839 return is; 849 840 } // ?|? 850 841 851 842 istype & ?|?( istype & is, unsigned long int & ulli ) { 852 if ( eof( is ) ) throwResume ExceptionInst( missing_data );853 843 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 ); 855 845 return is; 856 846 } // ?|? 857 847 858 848 istype & ?|?( istype & is, long long int & lli ) { 859 if ( eof( is ) ) throwResume ExceptionInst( missing_data );860 849 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 ); 862 851 return is; 863 852 } // ?|? 864 853 865 854 istype & ?|?( istype & is, unsigned long long int & ulli ) { 866 if ( eof( is ) ) throwResume ExceptionInst( missing_data );867 855 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 ); 869 857 return is; 870 858 } // ?|? … … 893 881 894 882 istype & ?|?( istype & is, float & f ) { 895 if ( eof( is ) ) throwResume ExceptionInst( missing_data );896 883 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 ); 898 885 return is; 899 886 } // ?|? 900 887 901 888 istype & ?|?( istype & is, double & d ) { 902 if ( eof( is ) ) throwResume ExceptionInst( missing_data );903 889 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 ); 905 891 return is; 906 892 } // ?|? 907 893 908 894 istype & ?|?( istype & is, long double & ld ) { 909 if ( eof( is ) ) throwResume ExceptionInst( missing_data );910 895 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 ); 912 897 return is; 913 898 } // ?|? 914 899 915 900 istype & ?|?( istype & is, float _Complex & fc ) { 916 if ( eof( is ) ) throwResume ExceptionInst( missing_data );917 901 float re, im; 918 902 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 ); 920 904 fc = re + im * _Complex_I; 921 905 return is; … … 923 907 924 908 istype & ?|?( istype & is, double _Complex & dc ) { 925 if ( eof( is ) ) throwResume ExceptionInst( missing_data );926 909 double re, im; 927 910 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 ); 929 912 dc = re + im * _Complex_I; 930 913 return is; … … 932 915 933 916 istype & ?|?( istype & is, long double _Complex & ldc ) { 934 if ( eof( is ) ) throwResume ExceptionInst( missing_data );935 917 long double re, im; 936 918 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 ); 938 920 ldc = re + im * _Complex_I; 939 921 return is; … … 941 923 942 924 istype & ?|?( istype & is, const char fmt[] ) { 943 if ( eof( is ) ) throwResume ExceptionInst( missing_data );944 925 size_t len = strlen( fmt ); 945 char fmt str[len + 16];946 strcpy( fmt str, fmt ); // copy format and add %n947 strcpy( &fmt str[len], "%n" );926 char fmt2[len + 16]; 927 strcpy( fmt2, fmt ); // copy format and add %n 928 strcpy( &fmt2[len], "%n" ); 948 929 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 ); 951 932 return is; 952 933 } // ?|? … … 982 963 forall( istype & | basic_istream( istype ) ) { 983 964 istype & ?|?( istype & is, _Istream_Cskip f ) { 984 if ( eof( is ) ) throwResume ExceptionInst( missing_data);965 // printf( "skip %s %d\n", f.scanset, f.wd ); 985 966 if ( f.scanset ) { 986 967 int nscanset = strlen(f.scanset); … … 990 971 strcpy( &fmtstr[pos], f.scanset ); pos += nscanset; 991 972 strcpy( &fmtstr[pos], "]" ); 992 fmt( is, fmtstr, "" ); // skip scanset , zero or more973 fmt( is, fmtstr, "" ); // skip scanset 993 974 } else { 994 975 char ch; 976 // fprintf( stderr, "skip " ); 995 977 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 ); 998 981 } // for 999 982 } // if … … 1002 985 1003 986 istype & ?|?( istype & is, _Istream_Cquoted f ) with( f.cstr ) { 1004 if ( eof( is ) ) throwResume ExceptionInst( missing_data );1005 987 int args; 1006 988 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; 1011 995 1012 996 // Change the remainder of the read into a getline by reseting the closing delimiter. … … 1027 1011 1028 1012 istype & ?|?( istype & is, _Istream_Cstr f ) with( f.cstr ) { 1029 if ( eof( is ) ) throwResume ExceptionInst( missing_data );1030 1013 const char * scanset; 1031 1014 size_t nscanset = 0; … … 1063 1046 fmt( is, "%c", &peek ); // check for whitespace terminator 1064 1047 // fprintf( stderr, "peek %d '%c'\n", args, peek ); 1065 if ( ! eof( is ) ) { // can only fail at eof1048 if ( ! eof( is ) ) { 1066 1049 ungetc( is, peek ); 1067 1050 if ( ! isspace( peek ) ) throwResume ExceptionInst( cstring_length ); … … 1073 1056 if ( flags.delimiter ) { // getline 1074 1057 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 ? 1076 1059 sprintf( &fmtstr[pos], "c%%n" ); 1077 1060 } else { … … 1080 1063 if ( flags.ignore ) args = fmt( is, fmtstr, &len ); // no string argument for '*' 1081 1064 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 1086 1065 if ( check && len == rwd && ! eof( is ) ) { // might not fit 1087 1066 char peek; … … 1117 1096 } // if 1118 1097 if ( args == 1 && eof( is ) ) { // data but scan ended at EOF 1098 // fprintf( stderr, "clear\n" ); 1119 1099 clear( is ); // => reset EOF => detect again on next read 1120 1100 } // if
Note:
See TracChangeset
for help on using the changeset viewer.