|
From: Howard K. <ho...@ka...> - 2002-01-14 02:51:48
|
>o How do we use ctype functions? For example, how do we use= isupper() >for the narrow character version, and iswupper() for the wide >character version? >A solution could be to define a macro per ctype function. For >example, TRIO_ISUPPER() would be a macro for isupper() for= narrow >characters and iswupper() for wide characters. That's the Microsoft TCHAR solution. Which actually works pretty well. I've started down that road actually -- looks promising. BTW, Microsoft defines _istupper() mapping to isupper/iswupper= depending on various details. Quite an extensive list actually (TCHAR.H),= though we won't need that many. I started down this path, but now that I'm getting a feel for the= code I want to go back over it from scratch and first come up with the= naming rules. We have some options, will post a note later in the week= or next weekend w/details and see what everyone thinks. >o How do we use triostr functions? As above, we use= trio_length() etc. >in a number of places. But the wide character version has a >different >name. Same issue as above. is*() functions, str/wcs*() functions,= triostr functions, etc. >o How do we specify the name of the printf functions? For= example, the >narrow version must be called fprintf() whereas the wide= character >version must be called fwprintf(). This one's actually got some leeway -- do we go for rigorous= standard compliance (and use similar rules for extensions), or do we go= for pure trio unique names and provide mapping for 'drop-in replacement'?= e.g. do we provide =09int printf(const char *,...) or =09int trio_printf(const char *,...) =09#if defined(TRIO_REPLACE_STD) =09# define printf trio_printf =09#endif I vote for the latter. If we name everything trio*() then we just have to make sure we= have a compatible replacement for everything we want to replace, e.g.= ANSI C/C++ define =09sprintf =09snprintf =09wsprintf BUT... 1) ...there's no wsnprintf() 2) ...wsprintf() is functionally equivalent to wsnprintf() Thus even though it's called wsprintf it's really a Wide-String-Nsized-PRINTF. Should trio provide all 4 functions or= just the pure 3, i.e. =09...narrow flavors... =09trio_wsnprintf() =09#define wsprintf=09=09trio_wsprintf or =09...narrow flavors... =09trio_wsprintf() =09trio_wsnprintf() =09#if defined(TRIO_REPLACE_STD) =09#define wsprintf=09=09trio_wsnprintf =09#endif I went thru this recently. This is, IMO, a huge pain converting a 'narrow' program to 'wide'= strings. Sure sprintf may potentially cause buffer overruns, but= do you know how easy it is to change =09sprintf(buffer, "fmt", vars) to =09wsprintf(buffer, ***size***, "fmt", vars) It may be the "right" thing to do, but in some code it can be= extremely time consuming and far lower on the priority list. Also can't= really fake it out via macros unless you've got varadic(?) macros, which= almost no one supports today. Fundamentally we have to answer, should trio provide= wsnprintf+wsprintf as wide equivalents to snprintf/sprintf, or should trio only= provide wsprintf as per C/C++ standards (even though, by definition, we= need to provide snprintf). Answer that, and the rest is just details. >o We need to ensure standard compliancy. This involves reading >carefully through the standards. What about "implementation dependent" behavior? Thought I recall some of the printf family varies here (return= value? of sprintf?). Been a while so maybe not, and even if so maybe C99= cleans it up. >o In the wide character version we must determine when to use= int and >when to use wint_t. This one's going to be rough, though not as bad as the standards= compliance. >o Grouping and scan ranges will probably fail (or generate huge >arrays). These needs to be looked at. Yes. I have no idea how to handle these, though to be honest I= haven't put any thought into them. I need to do some 'real' work for a few days so I'll probably= hack some more trio code next weekend. Top of the list is a single-source= triostr.c that can be compiled twice (narrow + wide), plus a list of naming= conventions we can discuss. =09- Howard -- Email: mailto:ho...@ka... WWW:= http://www.kapustein.com/howard/ -- "IT'S GOD'S RESPONSIBILITY TO FORGIVE BIN LADEN... =09=09IT'S OUR RESPONSIBILITY TO ARRANGE THE MEETING." =09=09=09=09- United States Marines |