Changeset 0860d9c for libcfa/src
- Timestamp:
- Oct 5, 2023, 4:17:14 PM (10 months ago)
- Branches:
- master
- Children:
- 4d860ea3
- Parents:
- b67b632
- Location:
- libcfa/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/collections/string_res.cfa
rb67b632 r0860d9c 218 218 // Read in chunks. Often, one chunk is enough. Keep the string that accumulates chunks last in the heap, 219 219 // so available room is rest of heap. When a chunk fills the heap, force growth then take the next chunk. 220 for (;;) { 220 for (bool cont = true; cont; ) { 221 cont = false; 222 221 223 // Append dummy content to temp, forcing expansion when applicable (occurs always on subsequent loops) 222 224 // length 2 ensures room for at least one real char, plus scanf/pipe-cstr's null terminator … … 228 230 temp.Handle.ulink->EndVbyte -= 2; 229 231 230 // rest of heap , less 1 byte for null terminator,is available to read into231 int lenReadable = (char*)temp.Handle.ulink->ExtVbyte - temp.Handle.ulink->EndVbyte - 1;232 assert (lenReadable >= 1);232 // rest of heap is available to read into 233 int lenReadable = (char*)temp.Handle.ulink->ExtVbyte - temp.Handle.ulink->EndVbyte; 234 assert (lenReadable >= 2); 233 235 234 236 // get bytes 235 in | wdi( lenReadable + 1, lenReadable, temp.Handle.ulink->EndVbyte ); 237 try { 238 in | wdi( lenReadable, temp.Handle.ulink->EndVbyte ); 239 } catch (cstring_length*) { 240 cont = true; 241 } 236 242 int lenWasRead = strlen(temp.Handle.ulink->EndVbyte); 237 243 … … 239 245 temp.Handle.lnth += lenWasRead; 240 246 temp.Handle.ulink->EndVbyte += lenWasRead; 241 242 if (lenWasRead < lenReadable) break;243 247 } 244 248 -
libcfa/src/iostream.cfa
rb67b632 r0860d9c 22 22 #include <float.h> // DBL_DIG, LDBL_DIG 23 23 #include <complex.h> // creal, cimag 24 #include <ctype.h> // isspace 24 25 //#include <stdio.h> 25 26 … … 29 30 extern char *strcpy (char *__restrict __dest, const char *__restrict __src) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1, 2))); 30 31 extern 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); 31 33 } // extern "C" 32 34 … … 991 993 // wd is buffer bytes available (for input chars + null terminator) 992 994 // rwd is count of input chars 993 int rwd = f.flags.rwd ? f.wd : (f.wd - 1); 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 994 1003 start += sprintf( &fmtstr[start], "%d", rwd ); 995 1004 } … … 1018 1027 //fprintf( stderr, "KK %s %zd %d %c %s\n", fmtstr, len, check, f.s[check], f.s ); 1019 1028 1020 if (! f.flags.ignore && ! f.flags.rwd && f.s[check] != '\0' ) // sentinel overwritten ? 1021 throw (cstring_length){ &cstring_length_vt }; 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 1022 1047 1023 1048 if ( f.flags.delimiter ) { // getline ?
Note: See TracChangeset
for help on using the changeset viewer.