Ignore:
Timestamp:
Aug 25, 2023, 12:53:55 PM (13 months ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
master
Children:
8f2aa3c
Parents:
88001dd
Message:

remove special case for getline in C-string input

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/iostream.cfa

    r88001dd raa25216  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Aug 24 10:25:20 2023
    13 // Update Count     : 1516
     12// Last Modified On : Fri Aug 25 12:04:27 2023
     13// Update Count     : 1526
    1414//
    1515
     
    2121#include <float.h>                                                                              // DBL_DIG, LDBL_DIG
    2222#include <complex.h>                                                                    // creal, cimag
    23 //#include <string.h>                                                                   // strlen, strcmp, memcpy
     23//#include <stdio.h>
     24
    2425extern "C" {
    2526extern size_t strlen (const char *__s) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1)));
     
    971972
    972973                int check = f.wd - 1;
     974                const char * scanset = f.scanset;;
     975                if ( f.flags.delimit ) scanset = f.delimit;             // getline ?
    973976
    974977                // 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 sentinel
    980                         int len = fmt( is, fmtstr, f.s );                       // read upto delimiter
    981                         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 empty
    984 //                      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 delimiter
    986                         return is;
    987                 } // if
     978                // 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
    988991
    989992                size_t len = 0;
    990                 if ( f.scanset ) len = strlen( f.scanset );
     993                if ( scanset ) len = strlen( scanset );
    991994                char fmtstr[len + 16];
    992995                int start = 1;
     
    995998                if ( f.wd != -1 ) { start += sprintf( &fmtstr[start], "%d", f.wd ); }
    996999
    997                 if ( ! f.scanset ) {
     1000                if ( ! scanset ) {
    9981001                        // %s, %*s, %ws, %*ws
    9991002                        fmtstr[start] = 's'; fmtstr[start + 1] = '\0';
     
    10041007                        fmtstr[start] = '['; start += 1;
    10051008                        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'
    10071010                        len += start;
    10081011                        fmtstr[len] = ']'; fmtstr[len + 1] = '\0';
     
    10111014
    10121015                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] );
    10151018                if ( ! f.flags.rwd && f.s[check] != '\0' )              // sentinel overwritten ?
    10161019                        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
    10171025                return is;
    10181026        } // ?|?
Note: See TracChangeset for help on using the changeset viewer.