diff options
author | axel <axel@liljencrantz.se> | 2006-01-21 00:27:21 +1000 |
---|---|---|
committer | axel <axel@liljencrantz.se> | 2006-01-21 00:27:21 +1000 |
commit | a47065f6481a412c2a69ab248b21d6f739361438 (patch) | |
tree | e108c09e0ba6f76916d70469dcb417d4063332c7 /wutil.h | |
parent | 70351b0e4fbff2c5f2e58fd5eb8553f973714ee7 (diff) |
Add fallback implementations of wcstok, putwc and getwc. Move all fallbacks from common.c to wutil.c.
darcs-hash:20060120142721-ac50b-4b9850d889e2210e1d545339e29dcc038a3f2b04.gz
Diffstat (limited to 'wutil.h')
-rw-r--r-- | wutil.h | 102 |
1 files changed, 99 insertions, 3 deletions
@@ -1,8 +1,8 @@ /** \file wutil.h Prototypes for wide character equivalents of various standard unix - functions. - + functions. Also contains fallback implementations of a large number + of wide character unix functions. */ #ifndef FISH_WUTIL_H #define FISH_WUTIL_H @@ -82,7 +82,7 @@ wchar_t *wgetcwd( wchar_t *buff, size_t sz ); int wchdir( const wchar_t * dir ); -#if !HAVE_WPRINTF +#if !HAVE_FWPRINTF /** Print formated string. Some operating systems (Like NetBSD) do not @@ -112,7 +112,103 @@ int swprintf( wchar_t *str, size_t l, const wchar_t *format, ... ); */ int wprintf( const wchar_t *format, ... ); +int vwprintf( const wchar_t *filter, va_list va ); +int vfwprintf( FILE *f, const wchar_t *filter, va_list va ); +int vswprintf( wchar_t *out, size_t n, const wchar_t *filter, va_list va ); + +#endif + +#ifndef HAVE_FGETWC + +wint_t fgetwc(FILE *stream); +wint_t getwc(FILE *stream); #endif +#ifndef HAVE_FPUTWC + +wint_t fputwc(wchar_t wc, FILE *stream); +wint_t putwc(wchar_t wc, FILE *stream); + +#endif + +#ifndef HAVE_WCSTOK + +wchar_t *wcstok(wchar_t *wcs, const wchar_t *delim, wchar_t **ptr); + +#endif + +/** + Return the number of columns used by a character. This is a libc + function, but the prototype for this function is missing in some libc + implementations. + + Fish has a fallback implementation in case the implementation is + missing altogether. In locales without a native wcwidth, Unicode + is probably so broken that it isn't worth trying to implement a + real wcwidth. Therefore, the fallback wcwidth assumes any printing + character takes up one column and anything else uses 0 columns. +*/ +int wcwidth( wchar_t c ); + +/** + Create a duplicate string. Wide string version of strdup. Will + automatically exit if out of memory. +*/ +wchar_t *wcsdup(const wchar_t *in); + +size_t wcslen(const wchar_t *in); + +/** + Case insensitive string compare function. Wide string version of + strcasecmp. + + This implementation of wcscasecmp does not take into account + esoteric locales where uppercase and lowercase do not cleanly + transform between each other. Hopefully this should be fine since + fish only uses this function with one of the strings supplied by + fish and guaranteed to be a sane, english word. Using wcscasecmp on + a user-supplied string should be considered a bug. +*/ +int wcscasecmp( const wchar_t *a, const wchar_t *b ); + +/** + Case insensitive string compare function. Wide string version of + strncasecmp. + + This implementation of wcsncasecmp does not take into account + esoteric locales where uppercase and lowercase do not cleanly + transform between each other. Hopefully this should be fine since + fish only uses this function with one of the strings supplied by + fish and guaranteed to be a sane, english word. Using wcsncasecmp on + a user-supplied string should be considered a bug. +*/ +int wcsncasecmp( const wchar_t *a, const wchar_t *b, int count ); + +/** + Returns a newly allocated wide character string wich is a copy of + the string in, but of length c or shorter. The returned string is + always null terminated, and the null is not included in the string + length. +*/ +wchar_t *wcsndup( const wchar_t *in, int c ); + +/** + Converts from wide char to digit in the specified base. If d is not + a valid digit in the specified base, return -1. +*/ +long convert_digit( wchar_t d, int base ); + +/** + Fallback implementation. Convert a wide character string to a + number in the specified base. This functions is the wide character + string equivalent of strtol. For bases of 10 or lower, 0..9 are + used to represent numbers. For bases below 36, a-z and A-Z are used + to represent numbers higher than 9. Higher bases than 36 are not + supported. +*/ +long wcstol(const wchar_t *nptr, + wchar_t **endptr, + int base); + #endif |