2005-09-20 21:26:39 +08:00
|
|
|
/** \file wutil.h
|
|
|
|
|
|
|
|
Prototypes for wide character equivalents of various standard unix
|
2006-01-20 22:27:21 +08:00
|
|
|
functions. Also contains fallback implementations of a large number
|
|
|
|
of wide character unix functions.
|
2005-09-20 21:26:39 +08:00
|
|
|
*/
|
2005-10-04 23:11:39 +08:00
|
|
|
#ifndef FISH_WUTIL_H
|
|
|
|
#define FISH_WUTIL_H
|
2005-09-20 21:26:39 +08:00
|
|
|
|
2005-10-04 23:11:39 +08:00
|
|
|
#include <wchar.h>
|
2005-09-20 21:26:39 +08:00
|
|
|
#include <dirent.h>
|
|
|
|
#include <unistd.h>
|
2005-10-04 23:11:39 +08:00
|
|
|
#include <sys/stat.h>
|
2005-10-06 06:37:08 +08:00
|
|
|
#include <sys/types.h>
|
2006-01-26 17:57:06 +08:00
|
|
|
#include <stdarg.h>
|
2005-09-20 21:26:39 +08:00
|
|
|
|
2005-11-02 23:41:59 +08:00
|
|
|
/**
|
|
|
|
Call this function on startup to create internal wutil
|
|
|
|
resources. This function doesn't do anything.
|
|
|
|
*/
|
|
|
|
void wutil_init();
|
|
|
|
|
2005-09-20 21:26:39 +08:00
|
|
|
/**
|
|
|
|
Call this function on exit to free internal wutil resources
|
|
|
|
*/
|
|
|
|
void wutil_destroy();
|
|
|
|
|
|
|
|
/**
|
|
|
|
Wide character version of fopen().
|
|
|
|
*/
|
|
|
|
FILE *wfopen(const wchar_t *path, const char *mode);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Wide character version of freopen().
|
|
|
|
*/
|
|
|
|
FILE *wfreopen(const wchar_t *path, const char *mode, FILE *stream);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Wide character version of open().
|
|
|
|
*/
|
|
|
|
int wopen(const wchar_t *pathname, int flags, ...);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Wide character version of creat().
|
|
|
|
*/
|
|
|
|
int wcreat(const wchar_t *pathname, mode_t mode);
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
Wide character version of opendir().
|
|
|
|
*/
|
|
|
|
DIR *wopendir(const wchar_t *name);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Wide character version of stat().
|
|
|
|
*/
|
|
|
|
int wstat(const wchar_t *file_name, struct stat *buf);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Wide character version of lstat().
|
|
|
|
*/
|
|
|
|
int lwstat(const wchar_t *file_name, struct stat *buf);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Wide character version of access().
|
|
|
|
*/
|
|
|
|
int waccess(const wchar_t *pathname, int mode);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Wide character version of perror().
|
|
|
|
*/
|
|
|
|
void wperror(const wchar_t *s);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Wide character version of getcwd().
|
|
|
|
*/
|
|
|
|
wchar_t *wgetcwd( wchar_t *buff, size_t sz );
|
|
|
|
|
|
|
|
/**
|
|
|
|
Wide character version of chdir()
|
|
|
|
*/
|
|
|
|
int wchdir( const wchar_t * dir );
|
|
|
|
|
2006-01-21 00:34:04 +08:00
|
|
|
/*
|
|
|
|
Here follows the prototypes for fallback implementations of various
|
|
|
|
standarcs libc functions relating to wide character support. Some of
|
|
|
|
these prototypes are always defined, since some libc versions
|
|
|
|
include the code, but you have to use special magical #defines for
|
|
|
|
the prototype to appear.
|
|
|
|
*/
|
2005-09-20 21:26:39 +08:00
|
|
|
|
2006-01-20 22:27:21 +08:00
|
|
|
#if !HAVE_FWPRINTF
|
2005-09-20 21:26:39 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
Print formated string. Some operating systems (Like NetBSD) do not
|
|
|
|
have wide string formating functions. Therefore we implement our
|
|
|
|
own. Not at all complete. Supports wide and narrow characters,
|
|
|
|
strings and decimal numbers, position (%n), field width and
|
|
|
|
precision.
|
|
|
|
*/
|
|
|
|
int fwprintf( FILE *f, const wchar_t *format, ... );
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
Print formated string. Some operating systems (Like NetBSD) do not
|
|
|
|
have wide string formating functions. Therefore we define our
|
|
|
|
own. Not at all complete. Supports wide and narrow characters,
|
|
|
|
strings and decimal numbers, position (%n), field width and
|
|
|
|
precision.
|
|
|
|
*/
|
|
|
|
int swprintf( wchar_t *str, size_t l, const wchar_t *format, ... );
|
|
|
|
|
|
|
|
/**
|
|
|
|
Print formated string. Some operating systems (Like NetBSD) do not
|
|
|
|
have wide string formating functions. Therefore we define our
|
|
|
|
own. Not at all complete. Supports wide and narrow characters,
|
|
|
|
strings and decimal numbers, position (%n), field width and
|
|
|
|
precision.
|
|
|
|
*/
|
|
|
|
int wprintf( const wchar_t *format, ... );
|
|
|
|
|
2006-01-21 00:34:04 +08:00
|
|
|
/**
|
|
|
|
Print formated string. Some operating systems (Like NetBSD) do not
|
|
|
|
have wide string formating functions. Therefore we define our
|
|
|
|
own. Not at all complete. Supports wide and narrow characters,
|
|
|
|
strings and decimal numbers, position (%n), field width and
|
|
|
|
precision.
|
|
|
|
*/
|
2006-01-20 22:27:21 +08:00
|
|
|
int vwprintf( const wchar_t *filter, va_list va );
|
2006-01-21 00:34:04 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
Print formated string. Some operating systems (Like NetBSD) do not
|
|
|
|
have wide string formating functions. Therefore we define our
|
|
|
|
own. Not at all complete. Supports wide and narrow characters,
|
|
|
|
strings and decimal numbers, position (%n), field width and
|
|
|
|
precision.
|
|
|
|
*/
|
2006-01-20 22:27:21 +08:00
|
|
|
int vfwprintf( FILE *f, const wchar_t *filter, va_list va );
|
2006-01-21 00:34:04 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
Print formated string. Some operating systems (Like NetBSD) do not
|
|
|
|
have wide string formating functions. Therefore we define our
|
|
|
|
own. Not at all complete. Supports wide and narrow characters,
|
|
|
|
strings and decimal numbers, position (%n), field width and
|
|
|
|
precision.
|
|
|
|
*/
|
2006-01-20 22:27:21 +08:00
|
|
|
int vswprintf( wchar_t *out, size_t n, const wchar_t *filter, va_list va );
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef HAVE_FGETWC
|
|
|
|
|
2006-01-21 00:34:04 +08:00
|
|
|
/**
|
|
|
|
Fallback implementation of fgetwc
|
|
|
|
*/
|
2006-01-20 22:27:21 +08:00
|
|
|
wint_t fgetwc(FILE *stream);
|
2006-01-21 00:34:04 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
Fallback implementation of getwc
|
|
|
|
*/
|
2006-01-20 22:27:21 +08:00
|
|
|
wint_t getwc(FILE *stream);
|
2005-09-20 21:26:39 +08:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2006-01-20 22:27:21 +08:00
|
|
|
#ifndef HAVE_FPUTWC
|
|
|
|
|
2006-01-21 00:34:04 +08:00
|
|
|
/**
|
|
|
|
Fallback implementation of fputwc
|
|
|
|
*/
|
2006-01-20 22:27:21 +08:00
|
|
|
wint_t fputwc(wchar_t wc, FILE *stream);
|
2006-01-21 00:34:04 +08:00
|
|
|
/**
|
|
|
|
Fallback implementation of putwc
|
|
|
|
*/
|
2006-01-20 22:27:21 +08:00
|
|
|
wint_t putwc(wchar_t wc, FILE *stream);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef HAVE_WCSTOK
|
2006-01-21 00:34:04 +08:00
|
|
|
/**
|
|
|
|
Fallback implementation of wcstok. Uses code borrowed from glibc.
|
|
|
|
*/
|
2006-01-20 22:27:21 +08:00
|
|
|
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);
|
|
|
|
|
2005-09-20 21:26:39 +08:00
|
|
|
#endif
|