[tyndur-devel] [PATCH] libc: wctype_t, iswctype, btowc
Kevin Wolf ·
On Mon, Aug 17, 2009 at 02:50:03AM +0200, hartmut at tyndur.org wrote: > From: Alexander Hartmut Kluth <hartmut at tyndur.org> > > wctype_t und Konsorten implementiert > > + Typ wctype_t hinzugefuegt > + Funktion iswctype hinzugefuegt > + Funktion btowc als Stub hinzugefuegt > > Signed-off-by: Alexander Hartmut Kluth <hartmut at tyndur.org> > --- > src/include/wctype.h | 7 +++ > src/modules/include/wchar.h | 7 +++ > src/modules/lib/stdlibc/wctype.c | 77 ++++++++++++++++++++++++++++++++++++++ > 3 files changed, 91 insertions(+), 0 deletions(-) > > diff --git a/src/include/wctype.h b/src/include/wctype.h > index f273a71..30e47c6 100644 > --- a/src/include/wctype.h > +++ b/src/include/wctype.h > @@ -120,6 +120,12 @@ int iswprint(wint_t wc); > int iswcntrl(wint_t wc); > > > +int iswgraph(wint_t c); > + > + > +int iswxdigit(wint_t c); Ich habe den Eindruck, da fehlen Kommentare. > + > + > /** > * Breites Zeichen in einen Grossbuchstaben umwandeln, falls es sich um einen > * Kleinbuchstaben handelt. Sonst wird das Zeichen unveraendert zurueckgegeben. > @@ -139,5 +145,6 @@ wint_t towupper(wint_t wc); > */ > wint_t towlower(wint_t wc); > > + > #endif /* ndef WCTYPE_H */ > Eine zusätzliche Leerzeile ist besonders nützlich ;-) > diff --git a/src/modules/include/wchar.h b/src/modules/include/wchar.h > index 3870f9d..d39c632 100644 > --- a/src/modules/include/wchar.h > +++ b/src/modules/include/wchar.h > @@ -40,6 +40,13 @@ > */ > typedef wchar_t wint_t; > > + > +/** > + * wctype_t ist ein Funktionspointer Das sehe ich. Aber wofür benutzt man diesen Typ? > + */ > +typedef int (*wctype_t)(wint_t); > + > + > /** > * Repraesentiert den internen Shift-Status einer Funktion, brauchen wir mit > * UTF-8 nicht. > diff --git a/src/modules/lib/stdlibc/wctype.c b/src/modules/lib/stdlibc/wctype.c > index b3c174c..b3c689c 100644 > --- a/src/modules/lib/stdlibc/wctype.c > +++ b/src/modules/lib/stdlibc/wctype.c > @@ -27,6 +27,81 @@ > */ > > #include <wctype.h> > +#include <string.h> > + > + > +struct { const char* name; wctype_t func; } types[] = { > + { "alnum", iswalnum }, > + { "alpha", iswalpha }, > + { "blank", iswblank }, > + { "cntrl", iswcntrl }, > + { "digit", iswdigit }, > + { "graph", iswgraph }, > + { "lower", iswlower }, > + { "print", iswprint }, > + { "punct", iswpunct }, > + { "space", iswspace }, > + { "upper", iswupper }, > + { "xdigit", iswxdigit }, > +}; Sollte static sein. > + > + > +/** > + * Erstellt ein wctype-Objekt > + * > + * @param type Typ des zu erstellenden Objekts > + * > + * @return Das Objekt, ansonsten (wctype_t)0 > + */ > +wctype_t wctype(const char* name) > +{ > + int i; > + > + for (i = 0; i < sizeof(types) / sizeof(types[0]); ++i) > + { > + if (!strcmp(name,types[i].name)) { > + return types[i].func; > + } > + } > + > + return (wctype_t)0; > +} > + > + > +/** > + * Pr??ft, ob der als Parameter ??bergebene Typ auch vom Typ Irgendwas macht regelmäßig deine Umlaute kaputt. > + * wctype_t ist > + * > + * @param wc ??bergebener Typ > + * @param type Typklasse > + * > + * @return 0, wenn die Klasse nicht vorhanden ist, ansonsten den > + * Funktionspointer > + */ > +int iswctype(wint_t wc, wctype_t type) > +{ > + return type(wc); > +} > + > + > +/// TODO > +wint_t btowc(wint_t c) > +{ > + return 0; > +} Hm, wofür ist die Funktion gut? Sie ist hier als Stub vorhanden, kommt aber nichtmal in der Headerdatei vor. > + > + > +int iswgraph(wint_t c) > +{ > + return 0; > +} > + > + > +int iswxdigit(wint_t c) > +{ > + return 0; > +} > + Ich glaube ja ehrlichgesagt nicht, dass die Funktionen so schwer zu implementieren sind, dass man sie als Stubs lassen muss. Aber wenn sie schon Stubs bleiben, sollten sie in ein #ifndef CONFIG_LIBC_NO_STUBS