2006-02-28 21:17:16 +08:00
# ifndef FISH_FALLBACK_H
# define FISH_FALLBACK_H
2006-03-06 05:24:11 +08:00
# include <stdio.h>
2006-05-10 21:27:04 +08:00
# include <stdint.h>
2006-03-06 05:24:11 +08:00
# include <stdarg.h>
2006-03-13 09:43:33 +08:00
# include <wctype.h>
# include <wchar.h>
2006-05-19 17:59:48 +08:00
# include <limits.h>
2006-06-21 22:15:44 +08:00
# include <sys/time.h>
2006-08-28 20:25:15 +08:00
# include <sys/types.h>
# include <signal.h>
2006-03-06 05:24:11 +08:00
2012-07-16 01:45:18 +08:00
/** fish's internal versions of wcwidth and wcswidth, which can use an internal implementation if the system one is busted. */
int fish_wcwidth ( wchar_t wc ) ;
int fish_wcswidth ( const wchar_t * str , size_t n ) ;
2006-05-10 00:42:22 +08:00
# ifndef WCHAR_MAX
/**
This _should_ be defined by wchar . h , but e . g . OpenBSD doesn ' t .
*/
2006-05-19 17:59:48 +08:00
# define WCHAR_MAX INT_MAX
2006-05-10 00:42:22 +08:00
# endif
2006-06-08 08:01:45 +08:00
/**
2006-06-09 07:52:12 +08:00
Make sure __func__ is defined to some string . In C99 , this should
be the currently compiled function . If we aren ' t using C99 or
later , older versions of GCC had __FUNCTION__ .
2006-06-08 08:01:45 +08:00
*/
# if __STDC_VERSION__ < 199901L
# if __GNUC__ >= 2
# define __func__ __FUNCTION__
# else
# define __func__ "<unknown>"
# endif
# endif
2006-03-14 08:08:01 +08:00
/**
Under curses , tputs expects an int ( * func ) ( char ) as its last
parameter , but in ncurses , tputs expects a int ( * func ) ( int ) as its
last parameter . tputs_arg_t is defined to always be what tputs
expects . Hopefully .
*/
2006-02-28 21:17:16 +08:00
2006-03-14 08:08:01 +08:00
# ifdef NCURSES_VERSION
typedef int tputs_arg_t ;
# else
typedef char tputs_arg_t ;
# endif
2006-08-10 06:26:56 +08:00
# ifndef SIGIO
# define SIGIO SIGUSR1
# endif
2006-08-28 20:25:15 +08:00
# ifndef SIGWINCH
2006-10-19 23:39:50 +08:00
# define SIGWINCH SIGUSR2
2006-08-28 20:25:15 +08:00
# endif
2006-07-31 04:55:44 +08:00
# ifndef HAVE_WINSIZE
2008-01-14 00:47:47 +08:00
/**
Structure used to get the size of a terminal window
*/
2012-11-18 18:23:22 +08:00
struct winsize
2006-07-31 04:55:44 +08:00
{
2012-11-19 08:30:30 +08:00
/**
Number of rows
*/
unsigned short ws_row ;
/**
Number of columns
*/
unsigned short ws_col ;
2006-07-31 04:55:44 +08:00
}
2007-10-15 21:21:25 +08:00
;
2006-07-31 04:55:44 +08:00
# endif
2006-03-14 08:08:01 +08:00
# ifdef TPUTS_KLUDGE
2006-03-06 05:24:11 +08:00
2006-02-28 21:17:16 +08:00
/**
Linux on PPC seems to have a tputs implementation that sometimes
behaves strangely . This fallback seems to fix things .
*/
2006-04-03 23:04:22 +08:00
int tputs ( const char * str , int affcnt , int ( * fish_putc ) ( tputs_arg_t ) ) ;
2006-02-28 21:17:16 +08:00
# endif
2007-08-22 15:57:41 +08:00
# ifdef TPARM_SOLARIS_KLUDGE
/**
Solaris tparm has a set fixed of paramters in it ' s curses implementation ,
work around this here .
*/
# define tparm tparm_solaris_kludge
2012-11-19 08:30:30 +08:00
char * tparm_solaris_kludge ( char * str , . . . ) ;
2007-08-22 15:57:41 +08:00
# endif
2006-03-26 00:21:03 +08:00
# ifndef HAVE_FWPRINTF
2006-02-28 21:17:16 +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 .
*/
2012-11-19 08:30:30 +08:00
int fwprintf ( FILE * f , const wchar_t * format , . . . ) ;
2006-02-28 21:17:16 +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 .
*/
2012-11-19 08:30:30 +08:00
int swprintf ( wchar_t * str , size_t l , const wchar_t * format , . . . ) ;
2006-02-28 21:17:16 +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 .
*/
2012-11-19 08:30:30 +08:00
int wprintf ( const wchar_t * format , . . . ) ;
2006-02-28 21:17:16 +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 .
*/
2012-11-19 08:30:30 +08:00
int vwprintf ( const wchar_t * filter , va_list va ) ;
2006-02-28 21:17:16 +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 .
*/
2012-11-19 08:30:30 +08:00
int vfwprintf ( FILE * f , const wchar_t * filter , va_list va ) ;
2006-02-28 21:17:16 +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 .
*/
2012-11-19 08:30:30 +08:00
int vswprintf ( wchar_t * out , size_t n , const wchar_t * filter , va_list va ) ;
2006-02-28 21:17:16 +08:00
2006-03-26 00:21:03 +08:00
# endif
# ifndef HAVE_FGETWC
2006-02-28 21:17:16 +08:00
/**
Fallback implementation of fgetwc
*/
wint_t fgetwc ( FILE * stream ) ;
/**
Fallback implementation of getwc
*/
wint_t getwc ( FILE * stream ) ;
2006-03-26 00:21:03 +08:00
# endif
# ifndef HAVE_FPUTWC
2006-02-28 21:17:16 +08:00
/**
Fallback implementation of fputwc
*/
wint_t fputwc ( wchar_t wc , FILE * stream ) ;
/**
Fallback implementation of putwc
*/
wint_t putwc ( wchar_t wc , FILE * stream ) ;
2006-03-26 00:21:03 +08:00
# endif
# ifndef HAVE_WCSTOK
2006-02-28 21:17:16 +08:00
/**
Fallback implementation of wcstok . Uses code borrowed from glibc .
*/
wchar_t * wcstok ( wchar_t * wcs , const wchar_t * delim , wchar_t * * ptr ) ;
2006-03-26 00:21:03 +08:00
# endif
# ifndef HAVE_WCWIDTH
2006-02-28 21:17:16 +08:00
/**
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
2012-11-18 18:23:22 +08:00
implementations .
2006-02-28 21:17:16 +08:00
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 .
*/
2012-11-19 08:30:30 +08:00
int wcwidth ( wchar_t c ) ;
2006-02-28 21:17:16 +08:00
2006-03-26 00:21:03 +08:00
# endif
2012-07-21 05:33:08 +08:00
/** On OS X, use weak linking for wcsdup and wcscasecmp. Weak linking allows you to call the function only if it exists at runtime. You can detect it by testing the function pointer against NULL. To avoid making the callers do that, redefine wcsdup to wcsdup_use_weak, and likewise with wcscasecmp. This lets us use the same binary on SnowLeopard (10.6) and Lion+ (10.7), even though these functions only exist on 10.7+.
2006-02-28 21:17:16 +08:00
2012-07-21 05:33:08 +08:00
On other platforms , use what ' s detected at build time .
*/
# if __APPLE__ && __DARWIN_C_LEVEL >= 200809L
2012-11-19 08:30:30 +08:00
wchar_t * wcsdup_use_weak ( const wchar_t * ) ;
int wcscasecmp_use_weak ( const wchar_t * , const wchar_t * ) ;
2013-05-17 10:44:21 +08:00
int wcsncasecmp_use_weak ( const wchar_t * s1 , const wchar_t * s2 , size_t n ) ;
2012-11-19 08:30:30 +08:00
# define wcsdup(a) wcsdup_use_weak((a))
# define wcscasecmp(a, b) wcscasecmp_use_weak((a), (b))
2013-05-17 10:44:21 +08:00
# define wcsncasecmp(a, b, c) wcsncasecmp_use_weak((a), (b), (c))
2012-11-18 18:23:22 +08:00
2012-07-21 05:33:08 +08:00
# else
2006-03-26 00:21:03 +08:00
2012-11-19 08:30:30 +08:00
# ifndef HAVE_WCSDUP
2006-03-26 00:21:03 +08:00
/**
2012-07-21 05:33:08 +08:00
Create a duplicate string . Wide string version of strdup . Will
automatically exit if out of memory .
2006-03-26 00:21:03 +08:00
*/
2012-07-21 05:33:08 +08:00
wchar_t * wcsdup ( const wchar_t * in ) ;
2006-02-28 21:17:16 +08:00
2012-11-19 08:30:30 +08:00
# endif
2006-03-26 00:21:03 +08:00
2012-11-19 08:30:30 +08:00
# ifndef HAVE_WCSCASECMP
2006-02-28 21:17:16 +08:00
/**
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 .
*/
2012-11-19 08:30:30 +08:00
int wcscasecmp ( const wchar_t * a , const wchar_t * b ) ;
2006-02-28 21:17:16 +08:00
2012-11-19 08:30:30 +08:00
# endif
2012-07-21 05:33:08 +08:00
# endif //__APPLE__
# ifndef HAVE_WCSLEN
/**
Fallback for wclsen . Returns the length of the specified string .
*/
size_t wcslen ( const wchar_t * in ) ;
2006-03-26 00:21:03 +08:00
# endif
2012-07-21 05:33:08 +08:00
2006-03-26 00:21:03 +08:00
# ifndef HAVE_WCSNCASECMP
2006-02-28 21:17:16 +08:00
/**
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 .
*/
2013-05-17 10:44:21 +08:00
int wcsncasecmp ( const wchar_t * a , const wchar_t * b , size_t count ) ;
2006-02-28 21:17:16 +08:00
/**
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 .
*/
2006-03-26 00:21:03 +08:00
# endif
# ifndef HAVE_WCSNDUP
/**
Fallback for wcsndup function . Returns a copy of \ c in , truncated
to a maximum length of \ c c .
*/
2012-11-19 08:30:30 +08:00
wchar_t * wcsndup ( const wchar_t * in , size_t c ) ;
2006-02-28 21:17:16 +08:00
2006-03-26 00:21:03 +08:00
# endif
2006-02-28 21:17:16 +08:00
/**
Converts from wide char to digit in the specified base . If d is not
2006-05-03 00:29:50 +08:00
a valid digit in the specified base , return - 1. This is a helper
function for wcstol , but it is useful itself , so it is exported .
2006-02-28 21:17:16 +08:00
*/
2012-11-19 08:30:30 +08:00
long convert_digit ( wchar_t d , int base ) ;
2006-02-28 21:17:16 +08:00
2006-03-26 00:21:03 +08:00
# ifndef HAVE_WCSTOL
2006-02-28 21:17:16 +08:00
/**
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 ,
2012-11-19 08:30:30 +08:00
wchar_t * * endptr ,
int base ) ;
2006-02-28 21:17:16 +08:00
2006-04-19 17:56:28 +08:00
# endif
# ifndef HAVE_WCSLCAT
/**
Appends src to string dst of size siz ( unlike wcsncat , siz is the
full size of dst , not space left ) . At most siz - 1 characters will be
copied . Always NUL terminates ( unless siz < = wcslen ( dst ) ) . Returns
wcslen ( src ) + MIN ( siz , wcslen ( initial dst ) ) . If retval > = siz ,
truncation occurred .
This is the OpenBSD strlcat function , modified for wide characters ,
and renamed to reflect this change .
*/
2012-11-19 08:30:30 +08:00
size_t wcslcat ( wchar_t * dst , const wchar_t * src , size_t siz ) ;
2006-04-19 17:56:28 +08:00
# endif
# ifndef HAVE_WCSLCPY
/**
Copy src to string dst of size siz . At most siz - 1 characters will
be copied . Always NUL terminates ( unless siz = = 0 ) . Returns
wcslen ( src ) ; if retval > = siz , truncation occurred .
This is the OpenBSD strlcpy function , modified for wide characters ,
2012-11-18 18:23:22 +08:00
and renamed to reflect this change .
2006-04-19 17:56:28 +08:00
*/
2012-11-19 08:30:30 +08:00
size_t wcslcpy ( wchar_t * dst , const wchar_t * src , size_t siz ) ;
2006-04-19 17:56:28 +08:00
2006-03-26 00:21:03 +08:00
# endif
2006-02-28 21:17:16 +08:00
2006-06-15 18:53:15 +08:00
# ifndef HAVE_LRAND48_R
/**
Datastructure for the lrand48_r fallback implementation .
*/
struct drand48_data
{
2012-11-19 08:30:30 +08:00
/**
Seed value
*/
unsigned int seed ;
2006-06-15 18:53:15 +08:00
}
2007-10-15 21:21:25 +08:00
;
2006-06-15 18:53:15 +08:00
/**
Fallback implementation of lrand48_r . Internally uses rand_r , so it is pretty weak .
*/
2012-11-19 08:30:30 +08:00
int lrand48_r ( struct drand48_data * buffer , long int * result ) ;
2006-06-20 08:50:10 +08:00
2006-06-15 18:53:15 +08:00
/**
2006-06-20 08:50:10 +08:00
Fallback implementation of srand48_r , the seed function for lrand48_r .
2006-06-15 18:53:15 +08:00
*/
2012-11-19 08:30:30 +08:00
int srand48_r ( long int seedval , struct drand48_data * buffer ) ;
2006-06-15 18:53:15 +08:00
2006-02-28 21:17:16 +08:00
# endif
2006-06-15 18:53:15 +08:00
2006-06-21 22:15:44 +08:00
# ifndef HAVE_FUTIMES
2012-11-19 08:30:30 +08:00
int futimes ( int fd , const struct timeval * times ) ;
2006-06-21 22:15:44 +08:00
# endif
2013-04-09 01:20:56 +08:00
/* autoconf may fail to detect gettext (645), so don't define a function call gettext or we'll get build errors */
2006-07-20 06:55:49 +08:00
2013-04-09 03:02:43 +08:00
/** Cover for gettext() */
2013-04-09 01:20:56 +08:00
char * fish_gettext ( const char * msgid ) ;
2006-07-20 07:11:49 +08:00
2013-04-09 03:02:43 +08:00
/** Cover for bindtextdomain() */
2013-04-09 01:20:56 +08:00
char * fish_bindtextdomain ( const char * domainname , const char * dirname ) ;
2006-07-20 06:55:49 +08:00
2013-04-09 03:02:43 +08:00
/** Cover for textdomain() */
2013-04-09 01:20:56 +08:00
char * fish_textdomain ( const char * domainname ) ;
2006-07-20 06:55:49 +08:00
2013-04-09 03:02:43 +08:00
/* Cover for dcgettext */
char * fish_dcgettext ( const char * domainname , const char * msgid , int category ) ;
2006-07-20 07:11:49 +08:00
# ifndef HAVE__NL_MSG_CAT_CNTR
/**
Some gettext implementation use have this variable , and by
increasing it , one can tell the system that the translations need
to be reloaded .
*/
extern int _nl_msg_cat_cntr ;
# endif
2006-07-20 06:55:49 +08:00
2006-07-31 04:59:41 +08:00
# ifndef HAVE_KILLPG
2008-01-14 00:47:47 +08:00
/**
Send specified signal to specified process group .
*/
2012-11-19 08:30:30 +08:00
int killpg ( int pgr , int sig ) ;
2006-07-31 04:59:41 +08:00
# endif
2006-08-28 19:43:05 +08:00
# ifndef HAVE_WORKING_GETOPT_LONG
2008-01-14 00:47:47 +08:00
/**
Struct describing a long getopt option
*/
2012-11-18 18:23:22 +08:00
struct option
2006-08-28 19:43:05 +08:00
{
2012-11-19 08:30:30 +08:00
/**
Name of option
*/
const char * name ;
/**
Flag
*/
int has_arg ;
/**
Flag
*/
int * flag ;
/**
Return value
*/
int val ;
2006-08-28 19:43:05 +08:00
}
2007-10-15 21:21:25 +08:00
;
2006-08-28 19:43:05 +08:00
# ifndef no_argument
2012-11-18 18:23:22 +08:00
# define no_argument 0
2006-08-28 19:43:05 +08:00
# endif
# ifndef required_argument
2012-11-18 18:23:22 +08:00
# define required_argument 1
2006-08-28 19:43:05 +08:00
# endif
# ifndef optional_argument
2012-11-18 18:23:22 +08:00
# define optional_argument 2
2006-08-28 19:43:05 +08:00
# endif
2012-11-18 18:23:22 +08:00
int getopt_long ( int argc ,
2012-11-19 08:30:30 +08:00
char * const argv [ ] ,
const char * optstring ,
const struct option * longopts ,
int * longindex ) ;
2006-08-28 19:43:05 +08:00
# endif
2007-10-15 19:39:36 +08:00
# ifndef HAVE_SYSCONF
# define _SC_ARG_MAX 1
long sysconf ( int name ) ;
# endif
2009-02-03 07:20:49 +08:00
# ifndef HAVE_NAN
double nan ( char * tagp ) ;
2009-02-03 06:46:45 +08:00
# endif
2009-02-03 07:20:49 +08:00
2006-06-15 18:53:15 +08:00
# endif