Changeset 04396aa


Ignore:
Timestamp:
Jun 12, 2019, 3:40:40 PM (5 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
6625727
Parents:
8548c35
Message:

formatting, add const char * and char * sin operators, add skip( n ) manipulator

Files:
3 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/iostream.cfa

    r8548c35 r04396aa  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Jun 10 18:06:16 2019
    13 // Update Count     : 809
     12// Last Modified On : Wed Jun 12 15:00:31 2019
     13// Update Count     : 819
    1414//
    1515
     
    740740        } // ?|?
    741741
     742        istype & ?|?( istype & is, const char * fmt ) {
     743                fmt( is, fmt, "" );
     744                return is;
     745        } // ?|?
     746
     747        istype & ?|?( istype & is, char * s ) {
     748                fmt( is, "%s", s );
     749                return is;
     750        } // ?|?
     751
    742752        // manipulators
    743753        istype & ?|?( istype & is, istype & (* manip)( istype & ) ) {
     
    767777        // skip xxx
    768778        if ( ! f.s ) {
    769                 // printf( "skip %s\n", f.scanset );
    770                 fmt( is, f.scanset, "" );                                               // no input arguments
     779                //printf( "skip %s %d\n", f.scanset, f.wd );
     780                if ( f.wd != -1 ) for ( f.wd ) fmt( is, "%*c" ); // no input arguments
     781                else fmt( is, f.scanset, "" );
    771782                return is;
    772783        } // if
  • libcfa/src/iostream.hfa

    r8548c35 r04396aa  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Jun 10 18:05:13 2019
    13 // Update Count     : 320
     12// Last Modified On : Wed Jun 12 13:35:42 2019
     13// Update Count     : 331
    1414//
    1515
     
    190190        _Ostream_Manip(T) sign( T val ) { return (_Ostream_Manip(T))@{ val, 1, 0, CODE, { .flags.sign : true } }; } \
    191191        _Ostream_Manip(T) & sign( _Ostream_Manip(T) & fmt ) { fmt.flags.sign = true; return fmt; } \
    192 } \
     192} /* distribution */ \
    193193forall( dtype ostype | ostream( ostype ) ) { \
    194194        ostype & ?|?( ostype & os, _Ostream_Manip(T) f ); \
     
    227227        _Ostream_Manip(T) nodp( T val ) { return (_Ostream_Manip(T))@{ val, 1, 0, 'g', { .flags.nobsdp : true } }; } \
    228228        _Ostream_Manip(T) & nodp( _Ostream_Manip(T) & fmt ) { fmt.flags.nobsdp = true; return fmt; } \
    229 } \
     229} /* distribution */ \
    230230forall( dtype ostype | ostream( ostype ) ) { \
    231231        ostype & ?|?( ostype & os, _Ostream_Manip(T) f ); \
     
    239239
    240240static inline {
    241         _Ostream_Manip(char) bin( char val ) { return (_Ostream_Manip(char))@{ val, 1, 0, 'b', { .all : 0 } }; }
    242         _Ostream_Manip(char) oct( char val ) { return (_Ostream_Manip(char))@{ val, 1, 0, 'o', { .all : 0 } }; }
    243         _Ostream_Manip(char) hex( char val ) { return (_Ostream_Manip(char))@{ val, 1, 0, 'x', { .all : 0 } }; }
    244         _Ostream_Manip(char) wd( unsigned int w, char val ) { return (_Ostream_Manip(char))@{ val, w, 0, 'c', { .all : 0 } }; }
     241        _Ostream_Manip(char) bin( char c ) { return (_Ostream_Manip(char))@{ c, 1, 0, 'b', { .all : 0 } }; }
     242        _Ostream_Manip(char) oct( char c ) { return (_Ostream_Manip(char))@{ c, 1, 0, 'o', { .all : 0 } }; }
     243        _Ostream_Manip(char) hex( char c ) { return (_Ostream_Manip(char))@{ c, 1, 0, 'x', { .all : 0 } }; }
     244        _Ostream_Manip(char) wd( unsigned int w, char c ) { return (_Ostream_Manip(char))@{ c, w, 0, 'c', { .all : 0 } }; }
    245245        _Ostream_Manip(char) & wd( unsigned int w, _Ostream_Manip(char) & fmt ) { fmt.wd = w; return fmt; }
    246246        _Ostream_Manip(char) & left( _Ostream_Manip(char) & fmt ) { fmt.flags.left = true; return fmt; }
     
    256256
    257257static inline {
    258         _Ostream_Manip(const char *) bin( const char * val ) { return (_Ostream_Manip(const char *))@{ val, 1, 0, 'b', { .all : 0 } }; }
    259         _Ostream_Manip(const char *) oct( const char * val ) { return (_Ostream_Manip(const char *))@{ val, 1, 0, 'o', { .all : 0 } }; }
    260         _Ostream_Manip(const char *) hex( const char * val ) { return (_Ostream_Manip(const char *))@{ val, 1, 0, 'x', { .all : 0 } }; }
    261         _Ostream_Manip(const char *) wd( unsigned int w, const char * val ) { return (_Ostream_Manip(const char *))@{ val, w, 0, 's', { .all : 0 } }; }
    262         _Ostream_Manip(const char *) wd( unsigned int w, unsigned char pc, const char * val ) { return (_Ostream_Manip(const char *))@{ val, w, pc, 's', { .flags.pc : true } }; }
     258        _Ostream_Manip(const char *) bin( const char * s ) { return (_Ostream_Manip(const char *))@{ s, 1, 0, 'b', { .all : 0 } }; }
     259        _Ostream_Manip(const char *) oct( const char * s ) { return (_Ostream_Manip(const char *))@{ s, 1, 0, 'o', { .all : 0 } }; }
     260        _Ostream_Manip(const char *) hex( const char * s ) { return (_Ostream_Manip(const char *))@{ s, 1, 0, 'x', { .all : 0 } }; }
     261        _Ostream_Manip(const char *) wd( unsigned int w, const char * s ) { return (_Ostream_Manip(const char *))@{ s, w, 0, 's', { .all : 0 } }; }
     262        _Ostream_Manip(const char *) wd( unsigned int w, unsigned char pc, const char * s ) { return (_Ostream_Manip(const char *))@{ s, w, pc, 's', { .flags.pc : true } }; }
    263263        _Ostream_Manip(const char *) & wd( unsigned int w, _Ostream_Manip(const char *) & fmt ) { fmt.wd = w; return fmt; }
    264264        _Ostream_Manip(const char *) & wd( unsigned int w, unsigned char pc, _Ostream_Manip(const char *) & fmt ) { fmt.wd = w; fmt.pc = pc; fmt.flags.pc = true; return fmt; }
     
    316316        istype & ?|?( istype &, long double _Complex & );
    317317
    318         // Cannot have char & and char * => cstr manipulator
    319         // istype & ?|?( istype &, char * );
     318        istype & ?|?( istype &, const char * );
     319        istype & ?|?( istype &, char * );
    320320
    321321        // manipulators
     
    341341}; // _Istream_Cstr
    342342
    343 static inline _Istream_Cstr skip( const char * scanset ) { return (_Istream_Cstr){ 0p, scanset, -1, { .all : 0 } }; }
    344 static inline _Istream_Cstr incl( const char * scanset, char * s ) { return (_Istream_Cstr){ s, scanset, -1, { .flags.inex : false } }; }
    345 static inline _Istream_Cstr incl( const char * scanset, _Istream_Cstr & fmt ) { fmt.scanset = scanset; fmt.flags.inex = false; return fmt; }
    346 static inline _Istream_Cstr excl( const char * scanset, char * s ) { return (_Istream_Cstr){ s, scanset, -1, { .flags.inex : true } }; }
    347 static inline _Istream_Cstr excl( const char * scanset, _Istream_Cstr & fmt ) { fmt.scanset = scanset; fmt.flags.inex = true; return fmt; }
    348 static inline _Istream_Cstr cstr( char * s ) { return (_Istream_Cstr){ s, 0p, -1, { .all : 0 } }; }
    349 static inline _Istream_Cstr ignore( const char * s ) { return (_Istream_Cstr)@{ 0p, 0p, -1, { .flags.ignore : true } }; }
    350 static inline _Istream_Cstr ignore( _Istream_Cstr & fmt ) { fmt.flags.ignore = true; return fmt; }
    351 static inline _Istream_Cstr wd( unsigned int w, char * s ) { return (_Istream_Cstr)@{ s, 0p, w, { .all : 0 } }; }
    352 static inline _Istream_Cstr wd( unsigned int w, _Istream_Cstr & fmt ) { fmt.wd = w; return fmt; }
     343static inline {
     344        _Istream_Cstr skip( unsigned int n ) { return (_Istream_Cstr){ 0p, 0p, n, { .all : 0 } }; }
     345        _Istream_Cstr skip( const char * scanset ) { return (_Istream_Cstr){ 0p, scanset, -1, { .all : 0 } }; }
     346        _Istream_Cstr incl( const char * scanset, char * s ) { return (_Istream_Cstr){ s, scanset, -1, { .flags.inex : false } }; }
     347        _Istream_Cstr & incl( const char * scanset, _Istream_Cstr & fmt ) { fmt.scanset = scanset; fmt.flags.inex = false; return fmt; }
     348        _Istream_Cstr excl( const char * scanset, char * s ) { return (_Istream_Cstr){ s, scanset, -1, { .flags.inex : true } }; }
     349        _Istream_Cstr & excl( const char * scanset, _Istream_Cstr & fmt ) { fmt.scanset = scanset; fmt.flags.inex = true; return fmt; }
     350        _Istream_Cstr ignore( const char * s ) { return (_Istream_Cstr)@{ s, 0p, -1, { .flags.ignore : true } }; }
     351        _Istream_Cstr & ignore( _Istream_Cstr & fmt ) { fmt.flags.ignore = true; return fmt; }
     352        _Istream_Cstr wd( unsigned int w, char * s ) { return (_Istream_Cstr)@{ s, 0p, w, { .all : 0 } }; }
     353        _Istream_Cstr & wd( unsigned int w, _Istream_Cstr & fmt ) { fmt.wd = w; return fmt; }
     354} // distribution
    353355forall( dtype istype | istream( istype ) ) istype & ?|?( istype & is, _Istream_Cstr f );
    354356
     
    357359}; // _Istream_Char
    358360
    359 static inline _Istream_Char ignore( const char c ) { return (_Istream_Char)@{ true }; }
    360 static inline _Istream_Char ignore( _Istream_Char & fmt ) { fmt.ignore = true; return fmt; }
     361static inline {
     362        _Istream_Char ignore( const char c ) { return (_Istream_Char)@{ true }; }
     363        _Istream_Char & ignore( _Istream_Char & fmt ) { fmt.ignore = true; return fmt; }
     364} // distribution
    361365forall( dtype istype | istream( istype ) ) istype & ?|?( istype & is, _Istream_Char f );
    362366
     
    369373
    370374#define InputFMTDecl( T ) \
    371 static inline _Istream_Manip(T) ignore( const T & val ) { return (_Istream_Manip(T))@{ (T &)val, -1, true }; } \
    372 static inline _Istream_Manip(T) ignore( _Istream_Manip(T) & fmt ) { fmt.ignore = true; return fmt; } \
    373 static inline _Istream_Manip(T) wdi( unsigned int w, T & val ) { return (_Istream_Manip(T))@{ val, w, false }; } \
     375static inline { \
     376        _Istream_Manip(T) ignore( const T & val ) { return (_Istream_Manip(T))@{ (T &)val, -1, true }; } \
     377        _Istream_Manip(T) & ignore( _Istream_Manip(T) & fmt ) { fmt.ignore = true; return fmt; } \
     378        _Istream_Manip(T) wdi( unsigned int w, T & val ) { return (_Istream_Manip(T))@{ val, w, false }; } \
     379        _Istream_Manip(T) & wd( unsigned int w, _Istream_Manip(T) & fmt ) { fmt.wd = w; return fmt; } \
     380} /* distribution */ \
    374381forall( dtype istype | istream( istype ) ) { \
    375382        istype & ?|?( istype & is, _Istream_Manip(T) f ); \
  • tests/.in/manipulatorsInput.txt

    r8548c35 r04396aa  
    1 abc
     1abc
     2abc
     3xx
    24abcxxx
    35abcyyy
    46aaaaaaaaxxxxxxxxaabbccbbdddwwwbbbbbbbbwwwwwwwwaaaaaaaawwwwwwww
    5 abc
     7abc
     8abc
     9xx
    610abcxxx
    711abcyyy
Note: See TracChangeset for help on using the changeset viewer.