public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "a.w. kinnunen" <a.w.kinnunen@gmail.com>
To: glibc-bugs@sourceware.org
Subject: overriding defaults with register_printf_function
Date: Wed, 18 Apr 2007 15:42:00 -0000	[thread overview]
Message-ID: <17d645d50704180842g36e54029ie4996dbdc1e67f61@mail.gmail.com> (raw)

Hi!

Here's a bug I suppose. libc manual says in

12.13.1 Registering New Conversions :
...You can redefine the built-in conversions like `%s',...

but it doesn't seems to work. I'm porting an application to linux, and
I need to maintain non-unicode+windows support. This happens with
glibc-2.3.5-0ubuntu1

Here's the code, it won't compile for as it is but you'll get the point:

#ifdef _UNICODE
/*
    these can be used to redefine %s and %S to work
    in windows style,

    they need to be registered using register_printfs;
*/
int print_char_callback( FILE *stream,
                        const struct printf_info *info_box, const void
*const *args){

    const char *chr;
    chr = *((const char **) (args[0]));
    return fprintf( stream, "%ls", char_to_TCHAR(chr));
}
int print_wchar_callback( FILE *stream,
                        const struct printf_info *info_box, const void
*const *args){
    const TCHAR *chr;
    chr = *((const TCHAR **) (args[0]));
    return fprintf( stream, "%ls", chr);
}
int printf_wchars_arginfo( const struct printf_info *info, size_t n,
int *argtypes ){
    if (n > 0)
        argtypes[0] =  PA_WSTRING;
    return 1;
}

void register_printfs(){
// these work if I printf with %y
//    register_printf_function('Y', print_char_callback, printf_wchars_arginfo);
//    register_printf_function('y', print_wchar_callback,
printf_wchars_arginfo);

// and these below won't just work
    register_printf_function('S', print_char_callback, printf_wchars_arginfo);
    register_printf_function('s', print_wchar_callback, printf_wchars_arginfo);
}
#endif


                 reply	other threads:[~2007-04-18 15:42 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=17d645d50704180842g36e54029ie4996dbdc1e67f61@mail.gmail.com \
    --to=a.w.kinnunen@gmail.com \
    --cc=glibc-bugs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).