Thread: Looking for thoughts on my new alternative to printf/scanf

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    1,734

    Looking for thoughts on my new alternative to printf/scanf

    both printf and scanf have both baggage and an inflexible design, I learned that the hard way when implementing my own specifiers etc, I've now decide to start converting my existing implementations in favour of something new, this is what I've decided so far:

    Code:
    /* Originally I wanted to mimic the existing printf/scanf standards, the
     * implementing of it enlightened me to how inflexible & inefficient the design
     * was so now I declaring a new standard and ignoring printf/scanf for now
     *
     * Arguments will be read like this: %/.../`options`'scalers'type%
     *
     * %% Will as usual mean just print/parse the character %
     *
     * The options get enclosed in a string so they cannot get confused with the
     * type specifier, the same reason applies to the scalers that get enclosed in
     * a string also. The /.../ means read a string in for regular expression
     * parsing and apply the options in the /.../ to the regular expression, the
     * options will be the same as in javascript, namely:
     *
    d Generate indices for substring matches.
    g Global search.
    i Case-insensitive search.
    m Allows ^ and $ to match newline characters.
    s Allows . to match newline characters.
    u "Unicode"; treat a pattern as a sequence of Unicode code points.
    y Perform a "sticky" search that matches starting at the current position in the target string.
     *
     * NOTE: Regular expression parsing is a PLANNED fetaure for the official
     * release of paw, for now it is currently unimplemented
     *
     * The last option of a kind takes precedence over previous options, for
     * example "%`<|>`s%" would right align the output string if padding is added
     *
     * Where * is the part of the option the * can be substituted for a literal,
     * for example %`c010`s% means to read the character and pad the output/input
     * if it is not at least 8 characters wide %`c*`s% carries same meaning but
     * instead of just 1 pawd for the character being read from the va_list 2 are
     * read, the 1st for the character, the 2nd for how many characters to pad it
     * to
     *
     * For strings paw supports the following:
     *
     * s	Raw string
     * sv	Buffer string
     *
     * 'l'	pawls/pawlsv
     * 't'	pawts/pawtsv
     * 'k'	pawks/pawksv
     * '8l'	paw8ls/paw8lsv
     * '16l'paw16ls/paw16lsv
     * '32l'paw32ls/paw32lsv
     *
     * `?`	Replace unsupported characters with this pawzc character
     * `<`	Left aligns output if padding is added, default
     * `|`	Center aligns output if padding is added, padding on either side will
     * 	be equal even if it means more than the stated padding
     * `>`	Right aligns output if padding is added
     * `c*`	Read 2 values in, pad output/input with character c until it is at
     *	least * characters wide, the character is always read in as a pawd
     * `l*`	Read 2 values in, pad output/input with character c until it is at
     *	least * characters wide, the character is always read in as a pawzc
     * `^*` Repeat the output * times
     * `.*`	When printing this is the EXACT length of the string, pawlen etc are
     *	skipped in favour of this.
     *
     *	When parsing this is the max characters to fill the string with,
     *	default is 0, without defining this option your strings will always be
     *	empty unless it was into buffers that it can increase the size of
     * `#`	Prefix appropriatly, for example insert L" to the front if
     *	input/output is supposed to be pawls/pawlsv
     * '!'	Suffix appropriatly, for strings this just means append "
     *
     * For numbers the following is supported:
     *
     * b	Binary variant, default is pawu
     * d	Signed variant, default is pawd
     * u	Unsigned variant, default is pawu
     * o	Octal variant, default is pawu
     * x	Lowercase hexadecimal variant, default is pawu
     * x	Uppercase hexadecimal variant, default is pawu
     * p	Uppercase hexadecimal pointer, always void*, # is always on
     *
     * 'f'	pawfd
     * 'lf'	pawlfd
     * 'jf'	pawjfd
     * 'kf'	pawkfd
     * 'hh'	pawhhd/pawhhu
     * 'h'	pawhd/pawhu
     * 'l'	pawld/pawlu
     * 'll'	pawlld/pawllu
     * 'j'	pawjd/pawju
     * 'k'	pawkd/pawku
     * 'v'	pawvd/pawvu
     * '8'	paw8d/paw8u
     * ...	All the paw#d, paw#ld, paw#qd, paw#fd variants follow suit
     *
     * '+'	Same as standard printf definition, forces a sign for numbers
     * `?`	Replace unsupported digits with this pawzc character (L option only)
     * `<`	Left aligns output if padding is added, default
     * `|`	Center aligns output if padding is added, padding on either side will
     * 	be equal even if it means more than the stated padding
     * `>`	Right aligns output if padding is added
     * `c*`	Read 2 values in, pad output/input with character c until it is at
     *	least * characters wide, the character is always read in as a pawd
     * `l*`	Read 2 values in, pad output/input with character c until it is at
     *	least * characters wide, the character is always read in as a pawzc
     * `^*` Repeat the output * times
     * `.*`	When printing this is the EXACT length of the string, pawlen etc are
     *	skipped in favour of this.
     *
     *	When parsing this is the max characters to fill the string with,
     *	default is 0, without defining this option your strings will always be
     *	empty unless it was into buffers that it can increase the size of
     * `#`	Prefix appropriatly, for example a hexadeximal value will have 0x
     * 	prefixed, always active for pointers
     * '!'	Suffix appropriatly, for example a pawlu will have UL appended
     *
     * Planned to support on official release
     * `,`	Digits should be grouped into 1000s with locale defined separator,
     *	I don't have an implementation for this presently, so until I do there
     *	will be no beta of paw
     * `L`Use locales alternative digit representations, again I need to do some
     *	research and implement this before I declare paw in beta state
     *
     * */
    
    RAWPAW_API pawd pawio_outputv( PAWIO io, pawls args, va_list *va );
    RAWPAW_API pawd pawio_outputf( PAWIO io, pawls args, ... ) PAW_ATTR_HOT;
    
    RAWPAW_API pawd pawio_expectv( PAWIO io, pawls args, va_list *va );
    RAWPAW_API pawd pawio_expectf( PAWIO io, pawls args, ... ) PAW_ATTR_HOT;
    What other options do you think would be desired in a new alternative? I'm still gonna have built-in support for custom callback lists, just gotta decide what the option will look like from now on
    Last edited by awsdert; 02-22-2023 at 01:40 PM. Reason: Left over note needed removing

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Alternative console output functions to printf()?
    By jafadmin in forum C Programming
    Replies: 17
    Last Post: 04-15-2014, 11:46 PM
  2. What is a good alternative for scanf?
    By Karyumi in forum C Programming
    Replies: 2
    Last Post: 03-06-2012, 11:37 AM
  3. Need help. printf() and scanf().
    By HBK in forum C Programming
    Replies: 19
    Last Post: 07-17-2011, 04:04 PM
  4. scanf and printf
    By gmanUK in forum C Programming
    Replies: 5
    Last Post: 11-25-2005, 03:03 PM
  5. Alternative forms of printf.
    By OOPboredom in forum C Programming
    Replies: 5
    Last Post: 05-07-2004, 01:21 PM

Tags for this Thread