diff options
Diffstat (limited to 'bin/csh')
-rw-r--r-- | bin/csh/Makefile | 151 | ||||
-rw-r--r-- | bin/csh/config.h | 277 | ||||
-rw-r--r-- | bin/csh/config_p.h | 111 | ||||
-rw-r--r-- | bin/csh/iconv_stub.c | 80 | ||||
-rw-r--r-- | bin/csh/iconv_stub.h | 44 |
5 files changed, 663 insertions, 0 deletions
diff --git a/bin/csh/Makefile b/bin/csh/Makefile new file mode 100644 index 0000000..1fa24a1 --- /dev/null +++ b/bin/csh/Makefile @@ -0,0 +1,151 @@ +# $FreeBSD$ +# @(#)Makefile 8.1 (Berkeley) 5/31/93 +# +# C Shell with process control; VM/UNIX VAX Makefile +# Bill Joy UC Berkeley; Jim Kulp IIASA, Austria +# +# To profile, put -DPROF in DEFS and -pg in CFLAGS, and recompile. + +.include <bsd.own.mk> + +TCSHDIR= ${.CURDIR}/../../contrib/tcsh +.PATH: ${TCSHDIR} + +PROG= csh +.if defined(RESCUE) +DFLAGS= -D_PATH_TCSHELL='"/rescue/${PROG}"' +.else +DFLAGS= -D_PATH_TCSHELL='"/bin/${PROG}"' +.endif +CFLAGS+= -I. -I${.CURDIR} -I${TCSHDIR} ${DFLAGS} +WARNS?= 1 +SRCS= sh.c sh.dir.c sh.dol.c sh.err.c sh.exec.c sh.char.c \ + sh.exp.c sh.file.c sh.func.c sh.glob.c sh.hist.c sh.init.c \ + sh.lex.c sh.misc.c sh.parse.c sh.print.c sh.proc.c sh.sem.c \ + sh.set.c sh.time.c sh.char.h sh.dir.h sh.proc.h sh.h +SRCS+= sh.decls.h glob.c glob.h mi.termios.c mi.wait.h mi.varargs.h +SRCS+= tw.decls.h tw.h tw.help.c tw.init.c tw.parse.c tw.spell.c \ + tw.comp.c tw.color.c +SRCS+= ed.chared.c ed.decls.h ed.defns.c ed.h ed.init.c ed.inputl.c \ + ed.refresh.c ed.screen.c ed.xmap.c ed.term.c ed.term.h +SRCS+= tc.alloc.c tc.bind.c tc.const.c tc.decls.h tc.disc.c \ + tc.func.c tc.nls.c tc.os.c tc.os.h tc.printf.c tc.prompt.c \ + tc.sched.c tc.sig.c tc.sig.h tc.str.c sh.types.h tc.vers.c tc.wait.h \ + tc.who.c tc.h +GENHDRS= ed.defns.h sh.err.h tc.const.h tc.defs.c +SRCS+= ${GENHDRS} + +MLINKS= csh.1 tcsh.1 +# MLINKS for Shell built in commands for which there are no userland +# utilities of the same name are handled with the associated manpage, +# builtin.1 in share/man/man1/. + +DPADD= ${LIBTERMCAP} ${LIBCRYPT} +LDADD= -ltermcap -lcrypt + +LINKS= ${BINDIR}/csh ${BINDIR}/tcsh + +CLEANFILES= ${GENHDRS} gethost csh.1 + +.if ${MK_EXAMPLES} != "no" +FILESDIR= ${SHAREDIR}/examples/tcsh +FILES= complete.tcsh csh-mode.el +.endif + +CATALOGS= et:et_EE.ISO8859-15 \ + finnish:fi_FI.ISO8859-1 \ + french:fr_FR.ISO8859-1 \ + german:de_DE.ISO8859-1 \ + greek:el_GR.ISO8859-7 \ + italian:it_IT.ISO8859-1 \ + ja:ja_JP.eucJP \ + russian:ru_RU.KOI8-R \ + spanish:es_ES.ISO8859-1 \ + ukrainian:uk_UA.KOI8-U + +NLSLINKS_fi_FI.ISO8859-1= fi_FI.ISO8859-15 +NLSLINKS_fr_FR.ISO8859-1= fr_BE.ISO8859-1 fr_BE.ISO8859-15 \ + fr_CA.ISO8859-1 fr_CA.ISO8859-15 fr_CH.ISO8859-1 \ + fr_CH.ISO8859-15 fr_FR.ISO8859-15 +NLSLINKS_de_DE.ISO8859-1= de_AT.ISO8859-1 de_AT.ISO8859-15 de_CH.ISO8859-1 \ + de_CH.ISO8859-15 de_DE.ISO8859-15 +NLSLINKS_it_IT.ISO8859-1= it_CH.ISO8859-1 it_CH.ISO8859-15 it_IT.ISO8859-15 +NLSLINKS_es_ES.ISO8859-1= es_ES.ISO8859-15 + +.if ${MK_NLS_CATALOGS} == "no" || defined(RESCUE) +CFLAGS+= -DNO_NLS_CATALOGS +.else +CFLAGS+= -DHAVE_ICONV +.if ${MK_ICONV} != "no" +NLSLINKS_de_DE.ISO8859-1 += de_AT.UTF-8 de_CH.UTF-8 de_DE.UTF-8 +NLSLINKS_el_GR.ISO8859-7 = el_GR.UTF-8 +NLSLINKS_es_ES.ISO8859-1 += es_ES.UTF-8 +NLSLINKS_et_EE.ISO8859-15 = et_EE.UTF-8 +NLSLINKS_fi_FI.ISO8859-1 += fi_FI.UTF-8 +NLSLINKS_fr_FR.ISO8859-1 += fr_BE.UTF-8 fr_CA.UTF-8 fr_CH.UTF-8 fr_FR.UTF-8 +NLSLINKS_it_IT.ISO8859-1 += it_CH.UTF-8 it_IT.UTF-8 +NLSLINKS_ja_JP.eucJP = ja_JP.SJIS ja_JP.UTF-8 +NLSLINKS_ru_RU.KOI8-R = ru_RU.CP1251 ru_RU.CP866 ru_RU.ISO8859-5 ru_RU.UTF-8 +NLSLINKS_uk_UA.KOI8-U = uk_UA.ISO8859-5 uk_UA.UTF-8 +.else +# Above links can be installed from ports/shells/tcsh_nls + +GENHDRS+= iconv.h +SRCS+= iconv_stub.c + +iconv.h: ${.CURDIR}/iconv_stub.h + cp ${.CURDIR}/iconv_stub.h ${.TARGET} +.endif +.endif + +NLSNAME= tcsh + +.for catalog in ${CATALOGS} +NLS+= ${catalog:C/.*://} +NLSSRCDIR_${catalog:C/.*://}= ${TCSHDIR}/nls/${catalog:C/:.*//} +NLSSRCFILES_${catalog:C/.*://}!= cd ${NLSSRCDIR_${catalog:C/.*://}}; echo charset set[0-9]* +.endfor + +csh.1: tcsh.man + cat ${.ALLSRC} > ${.TARGET} + +build-tools: gethost + +gethost: gethost.c sh.err.h tc.const.h sh.h + @rm -f ${.TARGET} + ${CC} -o gethost ${LDFLAGS} ${CFLAGS:C/-DHAVE_ICONV//} \ + ${TCSHDIR}/gethost.c + +tc.defs.c: gethost ${TCSHDIR}/host.defs + @rm -f ${.TARGET} + @echo "/* Do not edit this file, make creates it */" > ${.TARGET} + ./gethost ${TCSHDIR}/host.defs >> ${.TARGET} + +ed.defns.h: ed.defns.c + @rm -f ${.TARGET} + @echo '/* Do not edit this file, make creates it. */' > ${.TARGET} + @echo '#ifndef _h_ed_defns' >> ${.TARGET} + @echo '#define _h_ed_defns' >> ${.TARGET} + grep '[FV]_' ${TCSHDIR}/ed.defns.c | grep '^#define' >> ${.TARGET} + @echo '#endif /* _h_ed_defns */' >> ${.TARGET} + +sh.err.h: sh.err.c + @rm -f ${.TARGET} + @echo '/* Do not edit this file, make creates it. */' > ${.TARGET} + @echo '#ifndef _h_sh_err' >> ${.TARGET} + @echo '#define _h_sh_err' >> ${.TARGET} + grep 'ERR_' ${.ALLSRC} | grep '^#define' >> ${.TARGET} + @echo '#endif /* _h_sh_err */' >> ${.TARGET} + +tc.const.h: tc.const.c sh.char.h config.h config_f.h sh.types.h sh.err.h + @rm -f ${.TARGET} + @echo '/* Do not edit this file, make creates it. */' > ${.TARGET} + @echo '#ifndef _h_tc_const' >> ${.TARGET} + @echo '#define _h_tc_const' >> ${.TARGET} + ${CC} -E ${CFLAGS:C/-DHAVE_ICONV//} ${.ALLSRC} -D_h_tc_const | \ + grep 'Char STR' | \ + sed -e 's/Char \([a-zA-Z0-9_]*\)\(.*\)/extern Char \1[];/' | \ + sort >> ${.TARGET} + @echo '#endif /* _h_tc_const */' >> ${.TARGET} + +.include <bsd.prog.mk> diff --git a/bin/csh/config.h b/bin/csh/config.h new file mode 100644 index 0000000..99f7d0b --- /dev/null +++ b/bin/csh/config.h @@ -0,0 +1,277 @@ +/* $FreeBSD$ */ +/* config.h. Generated from config.h.in by configure. */ +/* config.h.in. Generated from configure.in by autoheader. */ + +/* Define to the type of elements in the array set by `getgroups'. Usually + this is either `int' or `gid_t'. */ +#define GETGROUPS_T gid_t + +/* Define to 1 if the `getpgrp' function requires zero arguments. */ +#define GETPGRP_VOID 1 + +/* Define to 1 if you have the <auth.h> header file. */ +/* #undef HAVE_AUTH_H */ + +/* Define to 1 if you have the <crypt.h> header file. */ +/* #undef HAVE_CRYPT_H */ + +/* Define to 1 if you have the declaration of `crypt', and to 0 if you don't. + */ +#define HAVE_DECL_CRYPT 1 + +/* Define to 1 if you have the declaration of `environ', and to 0 if you + don't. */ +#define HAVE_DECL_ENVIRON 0 + +/* Define to 1 if you have the declaration of `gethostname', and to 0 if you + don't. */ +#define HAVE_DECL_GETHOSTNAME 1 + +/* Define to 1 if you have the declaration of `getpgrp', and to 0 if you + don't. */ +#define HAVE_DECL_GETPGRP 1 + +/* Define to 1 if you have the <dirent.h> header file, and it defines `DIR'. + */ +#define HAVE_DIRENT_H 1 + +/* Define to 1 if you have the `dup2' function. */ +#define HAVE_DUP2 1 + +/* Define to 1 if you have the <features.h> header file. */ +/* #undef HAVE_FEATURES_H */ + +/* Define to 1 if you have the `getauthid' function. */ +/* #undef HAVE_GETAUTHID */ + +/* Define to 1 if you have the `getcwd' function. */ +#define HAVE_GETCWD 1 + +/* Define to 1 if you have the `gethostname' function. */ +#define HAVE_GETHOSTNAME 1 + +/* Define to 1 if you have the `getpwent' function. */ +#define HAVE_GETPWENT 1 + +/* Define to 1 if you have the `getutent' function. */ +/* #undef HAVE_GETUTENT */ + +/* Define to 1 if you have the `getutxent' function. */ +#define HAVE_GETUTXENT 1 + +/* Define if you have the iconv() function and it works. */ +/* #undef HAVE_ICONV */ + +/* Define to 1 if you have the <inttypes.h> header file. */ +#define HAVE_INTTYPES_H 1 + +/* Define to 1 if the system has the type `long long'. */ +#define HAVE_LONG_LONG 1 + +/* Define to 1 if you have the `mallinfo' function. */ +/* #undef HAVE_MALLINFO */ + +/* Define to 1 if mbrtowc and mbstate_t are properly declared. */ +#define HAVE_MBRTOWC 1 + +/* Define to 1 if you have the `memmove' function. */ +#define HAVE_MEMMOVE 1 + +/* Define to 1 if you have the <memory.h> header file. */ +#define HAVE_MEMORY_H 1 + +/* Define to 1 if you have the `memset' function. */ +#define HAVE_MEMSET 1 + +/* Define to 1 if you have the `mkstemp' function. */ +#define HAVE_MKSTEMP 1 + +/* Define to 1 if you have the <ndir.h> header file, and it defines `DIR'. */ +/* #undef HAVE_NDIR_H */ + +/* Define to 1 if you have the `nice' function. */ +#define HAVE_NICE 1 + +/* Define to 1 if you have the `nl_langinfo' function. */ +#define HAVE_NL_LANGINFO 1 + +/* Define to 1 if you have the <paths.h> header file. */ +#define HAVE_PATHS_H 1 + +/* Define to 1 if you have the `sbrk' function. */ +#define HAVE_SBRK 1 + +/* Define to 1 if you have the `setpgid' function. */ +#define HAVE_SETPGID 1 + +/* Define to 1 if you have the `setpriority' function. */ +#define HAVE_SETPRIORITY 1 + +/* Define to 1 if you have the <shadow.h> header file. */ +/* #undef HAVE_SHADOW_H */ + +/* Define to 1 if you have the <stdint.h> header file. */ +#define HAVE_STDINT_H 1 + +/* Define to 1 if you have the <stdlib.h> header file. */ +#define HAVE_STDLIB_H 1 + +/* Define to 1 if you have the `strcoll' function and it is properly defined. + */ +#define HAVE_STRCOLL 1 + +/* Define to 1 if you have the `strerror' function. */ +#define HAVE_STRERROR 1 + +/* Define to 1 if you have the <strings.h> header file. */ +#define HAVE_STRINGS_H 1 + +/* Define to 1 if you have the <string.h> header file. */ +#define HAVE_STRING_H 1 + +/* Define to 1 if you have the `strstr' function. */ +#define HAVE_STRSTR 1 + +/* Define to 1 if `d_ino' is a member of `struct dirent'. */ +#define HAVE_STRUCT_DIRENT_D_INO 1 + +/* Define to 1 if `ss_family' is a member of `struct sockaddr_storage'. */ +#define HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY 1 + +/* Define to 1 if `ut_host' is a member of `struct utmpx'. */ +#define HAVE_STRUCT_UTMPX_UT_HOST 1 + +/* Define to 1 if `ut_tv' is a member of `struct utmpx'. */ +#define HAVE_STRUCT_UTMPX_UT_TV 1 + +/* Define to 1 if `ut_user' is a member of `struct utmpx'. */ +#define HAVE_STRUCT_UTMPX_UT_USER 1 + +/* Define to 1 if `ut_xtime' is a member of `struct utmpx'. */ +/* #undef HAVE_STRUCT_UTMPX_UT_XTIME */ + +/* Define to 1 if `ut_host' is a member of `struct utmp'. */ +#define HAVE_STRUCT_UTMP_UT_HOST 1 + +/* Define to 1 if `ut_tv' is a member of `struct utmp'. */ +#define HAVE_STRUCT_UTMP_UT_TV 1 + +/* Define to 1 if `ut_user' is a member of `struct utmp'. */ +#define HAVE_STRUCT_UTMP_UT_USER 1 + +/* Define to 1 if `ut_xtime' is a member of `struct utmp'. */ +/* #undef HAVE_STRUCT_UTMP_UT_XTIME */ + +/* Define to 1 if you have the `sysconf' function. */ +#define HAVE_SYSCONF 1 + +/* Define to 1 if you have the <sys/dir.h> header file, and it defines `DIR'. + */ +/* #undef HAVE_SYS_DIR_H */ + +/* Define to 1 if you have the <sys/ndir.h> header file, and it defines `DIR'. + */ +/* #undef HAVE_SYS_NDIR_H */ + +/* Define to 1 if you have the <sys/stat.h> header file. */ +#define HAVE_SYS_STAT_H 1 + +/* Define to 1 if you have the <sys/types.h> header file. */ +#define HAVE_SYS_TYPES_H 1 + +/* Define to 1 if you have the <unistd.h> header file. */ +#define HAVE_UNISTD_H 1 + +/* Define to 1 if you have the <utmpx.h> header file. */ +#define HAVE_UTMPX_H 1 + +/* Define to 1 if you have the <utmp.h> header file. */ +/* #undef HAVE_UTMP_H */ + +/* Define to 1 if you have the <wchar.h> header file. */ +#define HAVE_WCHAR_H 1 + +/* Define to 1 if you have the <wctype.h> header file. */ +#define HAVE_WCTYPE_H 1 + +/* Define to 1 if you have the `wcwidth' function. */ +#define HAVE_WCWIDTH 1 + +/* Define as const if the declaration of iconv() needs const. */ +#define ICONV_CONST const + +/* Support NLS. */ +#define NLS 1 + +/* Support NLS catalogs. */ +#define NLS_CATALOGS 1 + +/* Define to the address where bug reports for this package should be sent. */ +#define PACKAGE_BUGREPORT "http://bugs.gw.com/" + +/* Define to the full name of this package. */ +#define PACKAGE_NAME "tcsh" + +/* Define to the full name and version of this package. */ +#define PACKAGE_STRING "tcsh 6.18.01" + +/* Define to the one symbol short name of this package. */ +#define PACKAGE_TARNAME "tcsh" + +/* Define to the home page for this package. */ +#define PACKAGE_URL "" + +/* Define to the version of this package. */ +#define PACKAGE_VERSION "6.18.01" + +/* Define to 1 if the `setpgrp' function takes no argument. */ +/* #undef SETPGRP_VOID */ + +/* The size of `wchar_t', as computed by sizeof. */ +#define SIZEOF_WCHAR_T 4 + +/* Define to 1 if the `S_IS*' macros in <sys/stat.h> do not work properly. */ +/* #undef STAT_MACROS_BROKEN */ + +/* Define to 1 if you have the ANSI C header files. */ +#define STDC_HEADERS 1 + +/* Define for Solaris 2.5.1 so the uint32_t typedef from <sys/synch.h>, + <pthread.h>, or <semaphore.h> is not used. If the typedef were allowed, the + #define below would cause a syntax error. */ +/* #undef _UINT32_T */ + +/* Define to empty if `const' does not conform to ANSI C. */ +/* #undef const */ + +/* Define to `int' if <sys/types.h> doesn't define. */ +/* #undef gid_t */ + +/* Define to `int' if <sys/types.h> does not define. */ +/* #undef mode_t */ + +/* Define to `unsigned int' if <sys/types.h> does not define. */ +/* #undef size_t */ + +/* Define to `int' if neither <sys/types.h> nor <sys/socket.h> define. */ +/* #undef socklen_t */ + +/* Define to `int' not defined in <sys/types.h>. */ +/* #undef ssize_t */ + +/* Define to `int' if <sys/types.h> doesn't define. */ +/* #undef uid_t */ + +/* Define to the type of an unsigned integer type of width exactly 32 bits if + such a type exists and the standard includes do not define it. */ +/* #undef uint32_t */ + +/* Define to empty if the keyword `volatile' does not work. Warning: valid + code using `volatile' can become incorrect without. Disable with care. */ +/* #undef volatile */ + +#include "config_p.h" +#include "config_f.h" + +/* Work around a vendor issue where config_f.h is #undef'ing this setting */ +#define SYSMALLOC diff --git a/bin/csh/config_p.h b/bin/csh/config_p.h new file mode 100644 index 0000000..a1bbea6 --- /dev/null +++ b/bin/csh/config_p.h @@ -0,0 +1,111 @@ +/* $FreeBSD$ */ +/* + * config.h -- configure various defines for tcsh + * + * All source files should #include this FIRST. + * + * Edit this to match your system type. + */ + +#ifndef _h_config +#define _h_config +/****************** System dependant compilation flags ****************/ +/* + * POSIX This system supports IEEE Std 1003.1-1988 (POSIX). + */ +#define POSIX + +/* + * POSIXJOBS This system supports the optional IEEE Std 1003.1-1988 (POSIX) + * job control facilities. + */ +#define POSIXJOBS + +/* + * VFORK This machine has a vfork(). + * It used to be that for job control to work, this define + * was mandatory. This is not the case any more. + * If you think you still need it, but you don't have vfork, + * define this anyway and then do #define vfork fork. + * I do this anyway on a Sun because of yellow pages brain damage, + * [should not be needed under 4.1] + * and on the iris4d cause SGI's fork is sufficiently "virtual" + * that vfork isn't necessary. (Besides, SGI's vfork is weird). + * Note that some machines eg. rs6000 have a vfork, but not + * with the berkeley semantics, so we cannot use it there either. + */ +#define VFORK + +/* + * BSDJOBS You have BSD-style job control (both process groups and + * a tty that deals correctly + */ +#define BSDJOBS + +/* + * BSDTIMES You have BSD-style process time stuff (like rusage) + * This may or may not be true. For example, Apple Unix + * (OREO) has BSDJOBS but not BSDTIMES. + */ +#define BSDTIMES + +/* + * BSDLIMIT You have BSD-style resource limit stuff (getrlimit/setrlimit) + */ +#define BSDLIMIT + +/* + * TERMIO You have struct termio instead of struct sgttyb. + * This is usually the case for SYSV systems, where + * BSD uses sgttyb. POSIX systems should define this + * anyway, even though they use struct termios. + */ +#define TERMIO + +/* + * SYSVREL Your machine is SYSV based (HPUX, A/UX) + * NOTE: don't do this if you are on a Pyramid -- tcsh is + * built in a BSD universe. + * Set SYSVREL to 1, 2, 3, or 4, depending the version of System V + * you are running. Or set it to 0 if you are not SYSV based + */ +#define SYSVREL 0 + +/* + * YPBUGS Work around Sun YP bugs that cause expansion of ~username + * to send command output to /dev/null + */ +#undef YPBUGS + +/****************** local defines *********************/ + +#if defined(__FreeBSD__) +#define NLS_BUGS +#define BSD_STYLE_COLORLS +/* Use LC_MESSAGES locale category to open the message catalog */ +#define MCLoadBySet NL_CAT_LOCALE +#define BUFSIZE 8192 +#define UTMPX_FILE "/var/run/utx.active" +#endif + +#if defined(__bsdi__) +/* + * _PATH_TCSHELL if you've change the installation location (vix) + */ +#include <sys/param.h> +# ifdef _BSDI_VERSION >= 199701 +# define _PATH_TCSHELL "/bin/tcsh" +# undef SYSMALLOC +# define SYSMALLOC +# else +# define _PATH_TCSHELL "/usr/contrib/bin/tcsh" +# endif + +# undef NLS +# undef NLS_CATALOGS + +#elif defined(__APPLE__) +# define SYSMALLOC +#endif + +#endif /* _h_config */ diff --git a/bin/csh/iconv_stub.c b/bin/csh/iconv_stub.c new file mode 100644 index 0000000..d1a9e47 --- /dev/null +++ b/bin/csh/iconv_stub.c @@ -0,0 +1,80 @@ +/*- + * Copyright (c) 2006 Hajimu UMEMOTO <ume@FreeBSD.org> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#include <dlfcn.h> +#include <stddef.h> + +#include "iconv.h" + +#undef iconv_open +#undef iconv +#undef iconv_close + +#define ICONVLIB "libiconv.so" +#define ICONV_ENGINE "iconv" +#define ICONV_OPEN "iconv_open" +#define ICONV_CLOSE "iconv_close" + +typedef iconv_t iconv_open_t(const char *, const char *); + +dl_iconv_t *dl_iconv; +dl_iconv_close_t *dl_iconv_close; + +static int initialized; +static void *iconvlib; +static iconv_open_t *iconv_open; + +iconv_t +dl_iconv_open(const char *tocode, const char *fromcode) +{ + if (initialized) { + if (iconvlib == NULL) + return (iconv_t)-1; + } else { + initialized = 1; + iconvlib = dlopen(ICONVLIB, RTLD_LAZY | RTLD_GLOBAL); + if (iconvlib == NULL) + return (iconv_t)-1; + iconv_open = (iconv_open_t *)dlfunc(iconvlib, ICONV_OPEN); + if (iconv_open == NULL) + goto dlfunc_err; + dl_iconv = (dl_iconv_t *)dlfunc(iconvlib, ICONV_ENGINE); + if (dl_iconv == NULL) + goto dlfunc_err; + dl_iconv_close = (dl_iconv_close_t *)dlfunc(iconvlib, + ICONV_CLOSE); + if (dl_iconv_close == NULL) + goto dlfunc_err; + } + return iconv_open(tocode, fromcode); + +dlfunc_err: + dlclose(iconvlib); + iconvlib = NULL; + return (iconv_t)-1; +} diff --git a/bin/csh/iconv_stub.h b/bin/csh/iconv_stub.h new file mode 100644 index 0000000..89e9d0d --- /dev/null +++ b/bin/csh/iconv_stub.h @@ -0,0 +1,44 @@ +/*- + * Copyright (c) 2006 Hajimu UMEMOTO <ume@FreeBSD.org> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _ICONV_H_ +#define _ICONV_H_ + +typedef void *iconv_t; +typedef size_t dl_iconv_t(iconv_t, const char **, size_t *, char **, size_t *); +typedef int dl_iconv_close_t(iconv_t); + +extern iconv_t dl_iconv_open(const char *, const char *); +extern dl_iconv_t *dl_iconv; +extern dl_iconv_close_t *dl_iconv_close; + +#define iconv_open dl_iconv_open +#define iconv dl_iconv +#define iconv_close dl_iconv_close + +#endif /* !_ICONV_H_ */ |