From 164fca39bdacc36b7d9f2d1b28ab5abe03ce4004 Mon Sep 17 00:00:00 2001 From: Bram Moolenaar Date: Wed, 14 Jul 2010 13:58:07 +0200 Subject: Add clipboard support in Mac console. (Bjorn Winckler) --- Filelist | 2 +- runtime/doc/debug.txt | 10 +- runtime/doc/todo.txt | 6 +- src/Make_cyg.mak | 3 +- src/Makefile | 4 +- src/auto/configure | 34 +-- src/configure.in | 33 +-- src/os_mac.h | 2 +- src/os_mac_conv.c | 5 + src/os_macosx.c | 611 --------------------------------------- src/os_macosx.m | 783 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/vim.h | 3 + 12 files changed, 841 insertions(+), 655 deletions(-) delete mode 100644 src/os_macosx.c create mode 100644 src/os_macosx.m diff --git a/Filelist b/Filelist index 8e80e4473..d41af0a22 100644 --- a/Filelist +++ b/Filelist @@ -373,7 +373,7 @@ SRC_MAC = \ src/os_mac.h \ src/os_mac.rsr.hqx \ src/os_mac_conv.c \ - src/os_macosx.c \ + src/os_macosx.m \ src/proto/gui_mac.pro \ src/proto/os_mac_conv.pro \ diff --git a/runtime/doc/debug.txt b/runtime/doc/debug.txt index 55939022b..eb5a30593 100644 --- a/runtime/doc/debug.txt +++ b/runtime/doc/debug.txt @@ -39,7 +39,7 @@ This also applies when using the MingW tools. ============================================================================== -2. Locating memory leaks *debug-leaks* +2. Locating memory leaks *debug-leaks* *valgrind* If you suspect Vim is leaking memory and you are using Linux, the valgrind tool is very useful to pinpoint memory leaks. @@ -47,14 +47,18 @@ tool is very useful to pinpoint memory leaks. First of all, build Vim with EXITFREE defined. Search for this in MAKEFILE and uncomment the line. -Use this command to start Vim: *valgrind* +Use this command to start Vim: > - valgrind --log-file=valgrind.log ./vim + valgrind --log-file=valgrind.log --leak-check=full ./vim Note: Vim will run much slower. If your .vimrc is big or you have several plugins you need to be patient for startup, or run with the "-u NONE" argument. +There are often a few leaks from libraries, such as getpwuid() and +XtVaAppCreateShell(). Those are unavoidable. The number of bytes should be +very small a Kbyte or less. + ============================================================================== 3. Windows Bug Reporting *debug-win32* diff --git a/runtime/doc/todo.txt b/runtime/doc/todo.txt index 6077c2cc5..6a7d9ad66 100644 --- a/runtime/doc/todo.txt +++ b/runtime/doc/todo.txt @@ -1098,7 +1098,7 @@ Vim 7.3: - Conceal feature: no update when moving to another window. (Dominique Pelle, 2010 Jul 5) Vince will look into it. Patches to possibly include: -- Mac: console clipboard support. (Bjoren Winckler, 2010 Jul 12) +- Mac: console clipboard support. (Bjorn Winckler, 2010 Jul 12) - Win32: patch for better font scaling. (George Reilly, 2009 Mar 26) - Patch for completion of ":find" arguments. (Nazri Ramliy, 2009 Feb 22, 26) 8 For ":find" and ":sfind" expand files found in 'path'. @@ -1106,8 +1106,9 @@ Patches to possibly include: - Patch for vertical line at certain column position, 'guidecolumn' option. (Pankaj Garg, 2009 Apr 14, aka Lone, Apr 15) Update 2009 May 2, 'margincolumn' - Alternative patch. (2010 Feb 2, Gregor Uhlenheuer, update Apr 18 2010) + Alternative patch. (2010 Feb 2, Gregor Uhlenheuer, update 2010 Jul 12) Fix by Lech Lorens, Apr 19 + When there are multiple columns it makes sense to call it 'guidecolumn' - Another patch for Javascript indenting. (Hari Kumar, 2010 Jul 11) Needs a few tests. - Add different highlighting for a fold line depending on the fold level. @@ -1124,7 +1125,6 @@ Patches to possibly include: Docs patch by Dominique Pelle, Mar 25 Update 2009 Mar 28. Fix for invalid memory access. (Lech Lorens, 2009 Apr 17) -- Fix for test29. (Milan Vancura, 2010 May 16) - Disable setting 'encoding' from a modeline? It usually causes problems, can't do any good. (Patch from Patrick Texier, 2008 Dec 9) - Redraw problem when appending digraph causes line to wrap. (James Vega, 2007 diff --git a/src/Make_cyg.mak b/src/Make_cyg.mak index b80c258e3..9091d0946 100644 --- a/src/Make_cyg.mak +++ b/src/Make_cyg.mak @@ -37,7 +37,8 @@ # USEDLL no or yes: set to yes to use the Runtime library DLL (no) # For USEDLL=yes the cygwin1.dll is required to run Vim. # "no" does not work with latest version of Cygwin, use -# Make_ming.mak instead. Or set CC to gcc-3. +# Make_ming.mak instead. Or set CC to gcc-3 and add +# -L/lib/w32api to EXTRA_LIBS. # POSTSCRIPT no or yes: set to yes for PostScript printing (no) # FEATURES TINY, SMALL, NORMAL, BIG or HUGE (BIG) # WINVER Lowest Win32 version to support. (0x0400) diff --git a/src/Makefile b/src/Makefile index 0b86b46c8..592162557 100644 --- a/src/Makefile +++ b/src/Makefile @@ -2511,8 +2511,8 @@ objects/os_beos.o: os_beos.c objects/os_qnx.o: os_qnx.c $(CCC) -o $@ os_qnx.c -objects/os_macosx.o: os_macosx.c - $(CCC) -o $@ os_macosx.c +objects/os_macosx.o: os_macosx.m + $(CCC) -o $@ os_macosx.m objects/os_mac_conv.o: os_mac_conv.c $(CCC) -o $@ os_mac_conv.c diff --git a/src/auto/configure b/src/auto/configure index 20f723b9b..380491f36 100755 --- a/src/auto/configure +++ b/src/auto/configure @@ -4004,7 +4004,7 @@ fi $as_echo "no" >&6; } { $as_echo "$as_me:${as_lineno-$LINENO}: checking if Darwin files are there" >&5 $as_echo_n "checking if Darwin files are there... " >&6; } - if test -f os_macosx.c; then + if test -f os_macosx.m; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 $as_echo "yes" >&6; } else @@ -4160,14 +4160,9 @@ rm -f core conftest.err conftest.$ac_objext \ if test "$enable_darwin" = "yes"; then MACOSX=yes - OS_EXTRA_SRC="os_macosx.c os_mac_conv.c"; + OS_EXTRA_SRC="os_macosx.m os_mac_conv.c"; OS_EXTRA_OBJ="objects/os_macosx.o objects/os_mac_conv.o" CPPFLAGS="$CPPFLAGS -DMACOS_X_UNIX -no-cpp-precomp" - if test "x$MACARCH" = "xboth"; then - CPPFLAGS="$CPPFLAGS -I$DEVELOPER_DIR/SDKs/MacOSX10.4u.sdk/Developer/Headers/FlatCarbon" - else - CPPFLAGS="$CPPFLAGS -I$DEVELOPER_DIR/Headers/FlatCarbon" - fi # On IRIX 5.3, sys/types and inttypes.h are conflicting. for ac_header in sys/types.h sys/stat.h stdlib.h string.h memory.h strings.h \ @@ -7025,8 +7020,9 @@ $as_echo "no GUI support" >&6; } SKIP_CARBON=YES ;; yes|"") { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes - automatic GUI support" >&5 $as_echo "yes - automatic GUI support" >&6; } ;; - auto) { $as_echo "$as_me:${as_lineno-$LINENO}: result: auto - automatic GUI support" >&5 -$as_echo "auto - automatic GUI support" >&6; } ;; + auto) { $as_echo "$as_me:${as_lineno-$LINENO}: result: auto - Carbon GUI is outdated - disable GUI support" >&5 +$as_echo "auto - Carbon GUI is outdated - disable GUI support" >&6; } + SKIP_CARBON=YES ;; carbon) { $as_echo "$as_me:${as_lineno-$LINENO}: result: Carbon GUI support" >&5 $as_echo "Carbon GUI support" >&6; } ;; *) { $as_echo "$as_me:${as_lineno-$LINENO}: result: Sorry, $enable_gui GUI is not supported" >&5 @@ -7184,6 +7180,12 @@ $as_echo "yes" >&6; }; VIMNAME=Vim fi + if test "x$MACARCH" = "xboth"; then + CPPFLAGS="$CPPFLAGS -I$DEVELOPER_DIR/SDKs/MacOSX10.4u.sdk/Developer/Headers/FlatCarbon" + else + CPPFLAGS="$CPPFLAGS -I$DEVELOPER_DIR/Headers/FlatCarbon" + fi + if test x$prefix = xNONE; then prefix=/Applications fi @@ -11774,13 +11776,11 @@ if test "x$MACOSX" = "xyes" -a -n "$PERL"; then fi fi -if test "x$MACOSX" = "xyes" && test "x$CARBON" = "xyes" \ - && test "x$GUITYPE" != "xCARBONGUI"; then - { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we need -framework Carbon" >&5 -$as_echo_n "checking whether we need -framework Carbon... " >&6; } - if test "x$enable_multibyte" = "xyes" || test "x$features" = "xbig" \ - || test "x$features" = "xhuge"; then - LIBS="$LIBS -framework Carbon" +if test "x$MACOSX" = "xyes"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we need -framework Cocoa" >&5 +$as_echo_n "checking whether we need -framework Cocoa... " >&6; } + if test "x$features" != "xtiny" || test "x$enable_multibyte" = "xyes"; then + LIBS=$"$LIBS -framework Cocoa" { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 $as_echo "yes" >&6; } else @@ -11788,7 +11788,7 @@ $as_echo "yes" >&6; } $as_echo "no" >&6; } fi fi -if test "x$MACARCH" = "xboth"; then +if test "x$MACARCH" = "xboth" && test "x$GUITYPE" = "xCARBONGUI"; then LDFLAGS="$LDFLAGS -isysroot $DEVELOPER_DIR/SDKs/MacOSX10.4u.sdk -arch i386 -arch ppc" fi diff --git a/src/configure.in b/src/configure.in index 567c7a218..0e0e6469b 100644 --- a/src/configure.in +++ b/src/configure.in @@ -101,7 +101,7 @@ if test "`(uname) 2>/dev/null`" = Darwin; then if test "$enable_darwin" = "yes"; then AC_MSG_RESULT(no) AC_MSG_CHECKING(if Darwin files are there) - if test -f os_macosx.c; then + if test -f os_macosx.m; then AC_MSG_RESULT(yes) else AC_MSG_RESULT([no, Darwin support disabled]) @@ -168,15 +168,10 @@ if test "`(uname) 2>/dev/null`" = Darwin; then if test "$enable_darwin" = "yes"; then MACOSX=yes - OS_EXTRA_SRC="os_macosx.c os_mac_conv.c"; + OS_EXTRA_SRC="os_macosx.m os_mac_conv.c"; OS_EXTRA_OBJ="objects/os_macosx.o objects/os_mac_conv.o" dnl TODO: use -arch i386 on Intel machines CPPFLAGS="$CPPFLAGS -DMACOS_X_UNIX -no-cpp-precomp" - if test "x$MACARCH" = "xboth"; then - CPPFLAGS="$CPPFLAGS -I$DEVELOPER_DIR/SDKs/MacOSX10.4u.sdk/Developer/Headers/FlatCarbon" - else - CPPFLAGS="$CPPFLAGS -I$DEVELOPER_DIR/Headers/FlatCarbon" - fi dnl If Carbon is found, assume we don't want X11 dnl unless it was specifically asked for (--with-x) @@ -1325,7 +1320,8 @@ elif test "x$MACOSX" = "xyes" -a "x$with_x" = "xno" ; then no) AC_MSG_RESULT(no GUI support) SKIP_CARBON=YES ;; yes|"") AC_MSG_RESULT(yes - automatic GUI support) ;; - auto) AC_MSG_RESULT(auto - automatic GUI support) ;; + auto) AC_MSG_RESULT(auto - Carbon GUI is outdated - disable GUI support) + SKIP_CARBON=YES ;; carbon) AC_MSG_RESULT(Carbon GUI support) ;; *) AC_MSG_RESULT([Sorry, $enable_gui GUI is not supported]) SKIP_CARBON=YES ;; @@ -1436,6 +1432,12 @@ if test "x$MACOSX" = "xyes" -a -z "$SKIP_CARBON" -a "x$CARBON" = "xyes"; then VIMNAME=Vim fi + if test "x$MACARCH" = "xboth"; then + CPPFLAGS="$CPPFLAGS -I$DEVELOPER_DIR/SDKs/MacOSX10.4u.sdk/Developer/Headers/FlatCarbon" + else + CPPFLAGS="$CPPFLAGS -I$DEVELOPER_DIR/Headers/FlatCarbon" + fi + dnl Default install directory is not /usr/local if test x$prefix = xNONE; then prefix=/Applications @@ -3109,19 +3111,18 @@ if test "x$MACOSX" = "xyes" -a -n "$PERL"; then fi fi -if test "x$MACOSX" = "xyes" && test "x$CARBON" = "xyes" \ - && test "x$GUITYPE" != "xCARBONGUI"; then - AC_MSG_CHECKING(whether we need -framework Carbon) - dnl check for MACOSX without Carbon GUI, but with FEAT_MBYTE - if test "x$enable_multibyte" = "xyes" || test "x$features" = "xbig" \ - || test "x$features" = "xhuge"; then - LIBS="$LIBS -framework Carbon" +if test "x$MACOSX" = "xyes"; then + AC_MSG_CHECKING(whether we need -framework Cocoa) + dnl Cocoa is needed with FEAT_CLIPBOARD or FEAT_MBYTE (the former is + dnl disabled during tiny build) + if test "x$features" != "xtiny" || test "x$enable_multibyte" = "xyes"; then + LIBS=$"$LIBS -framework Cocoa" AC_MSG_RESULT(yes) else AC_MSG_RESULT(no) fi fi -if test "x$MACARCH" = "xboth"; then +if test "x$MACARCH" = "xboth" && test "x$GUITYPE" = "xCARBONGUI"; then LDFLAGS="$LDFLAGS -isysroot $DEVELOPER_DIR/SDKs/MacOSX10.4u.sdk -arch i386 -arch ppc" fi diff --git a/src/os_mac.h b/src/os_mac.h index f1ed96541..05b572dea 100644 --- a/src/os_mac.h +++ b/src/os_mac.h @@ -22,7 +22,7 @@ * Include the Mac header files, unless also compiling with X11 (the header * files have many conflicts). */ -#ifndef FEAT_X11 +#ifdef FEAT_GUI_MAC # include /* Apple calls it QuickDraw.h... */ # include # include diff --git a/src/os_mac_conv.c b/src/os_mac_conv.c index 793018998..3ede6480d 100644 --- a/src/os_mac_conv.c +++ b/src/os_mac_conv.c @@ -15,8 +15,13 @@ #define NO_X11_INCLUDES #include "vim.h" +#ifndef FEAT_GUI_MAC +# include +#endif + #if defined(MACOS_CONVERT) || defined(PROTO) + # ifdef PROTO /* A few dummy types to be able to generate function prototypes. */ typedef int UniChar; diff --git a/src/os_macosx.c b/src/os_macosx.c deleted file mode 100644 index 0868ef047..000000000 --- a/src/os_macosx.c +++ /dev/null @@ -1,611 +0,0 @@ -/* vi:set ts=8 sts=4 sw=4: - * - * VIM - Vi IMproved by Bram Moolenaar - * - * Do ":help uganda" in Vim to read copying and usage conditions. - * Do ":help credits" in Vim to see a list of people who contributed. - * See README.txt for an overview of the Vim source code. - */ - -/* - * os_macosx.c -- Mac specific things for Mac OS/X. - */ - -#ifdef MACOS_X_UNIX -# ifdef HAVE_CONFIG_H /* Using Makefile. */ -# include "vim.h" -# else -# include "os_unix.c" /* Using Project Builder */ -# endif -#else - Error: MACOS 9 is no longer supported in Vim 7 -#endif - -#ifdef _DEBUG - void -Trace(char* fmt, ...) -{ - char buf[2048]; - va_list args; - - va_start(args, fmt); - /* vsnprintf(buf, sizeof(buf), fmt, args);*/ - fprintf(stderr, "%s", buf); - va_end(args); -} -#endif - -#ifdef MACOS_X_ICONVEMU -/* - * Libiconv emulation layer - */ - -struct _iconv_t -{ - TECObjectRef tec; - TECObjectRef tecReverse; - TECSnifferObjectRef sniff; - TextEncoding from; - TextEncoding to; -}; -/* typedef struct _iconv_t *iconv_t; */ - - -static int last_errno = 0; - -/* - * Get TextEncoding from iconv's encoding name - */ - static TextEncoding -get_textencoding(const char* encodename) -{ - static struct { - const char* name; - TextEncoding encode; - } encodetable[] = { - /* ISO-8859 encodings family */ - {"latin1", kTextEncodingISOLatin1}, - {"latin2", kTextEncodingISOLatin2}, - {"latin3", kTextEncodingISOLatin3}, - {"latin4", kTextEncodingISOLatin4}, - {"latin5", kTextEncodingISOLatin5}, - {"latin6", kTextEncodingISOLatin6}, - {"latin7", kTextEncodingISOLatin7}, - {"latin8", kTextEncodingISOLatin8}, - {"latin9", kTextEncodingISOLatin9}, - {"iso-8859-1", kTextEncodingISOLatin1}, - {"iso-8859-2", kTextEncodingISOLatin2}, - {"iso-8859-3", kTextEncodingISOLatin3}, - {"iso-8859-4", kTextEncodingISOLatin4}, - {"iso-8859-5", kTextEncodingISOLatinCyrillic}, - {"iso-8859-6", kTextEncodingISOLatinArabic}, - {"iso-8859-7", kTextEncodingISOLatinGreek}, - {"iso-8859-8", kTextEncodingISOLatinHebrew}, - {"iso-8859-9", kTextEncodingISOLatin5}, - {"iso-8859-10", kTextEncodingISOLatin6}, - {"iso-8859-15", kTextEncodingISOLatin9}, - - /* Unicode encodings. */ - /* TODO: Add other type of unicode */ - {"ucs-2", kTextEncodingMacUnicode}, - - /* Japanese encoding aliases */ - {"cp932", kTextEncodingShiftJIS}, - {"shift-jis", kTextEncodingShiftJIS}, - {"euc-jp", kTextEncodingEUC_JP}, - {"iso-2022-jp", kTextEncodingISO_2022_JP}, - {"iso-2022-jp-1", kTextEncodingISO_2022_JP_1}, - {"iso-2022-jp-2", kTextEncodingISO_2022_JP_2}, - {"iso-2022-jp-3", kTextEncodingISO_2022_JP_3}, - - /* Other aliases. These aliases in this block are just guessed. */ - /* TODO: Must be verified. */ - {"gb2312", kTextEncodingGB_2312_80}, - {"cp936", kTextEncodingMacChineseSimp}, - {"euc-cn", kTextEncodingEUC_CN}, - {"cp950", kTextEncodingMacChineseTrad}, - {"euc-tw", kTextEncodingEUC_TW}, - {"cp949", kTextEncodingMacKorean}, - {"euc-kr", kTextEncodingEUC_KR}, - - /* - * All encodings supported by Macintosh. You can find these values - * in a file: - * /System/Library/Frameworks/CoreServices.framework/Versions/A/ - * Frameworks/CarbonCore.framework/Versions/A/Headers/TextCommon.h - */ - {"MacRoman", kTextEncodingMacRoman}, - {"MacJapanese", kTextEncodingMacJapanese}, - {"MacChineseTrad", kTextEncodingMacChineseTrad}, - {"MacKorean", kTextEncodingMacKorean}, - {"MacArabic", kTextEncodingMacArabic}, - {"MacHebrew", kTextEncodingMacHebrew}, - {"MacGreek", kTextEncodingMacGreek}, - {"MacCyrillic", kTextEncodingMacCyrillic}, - {"MacDevanagari", kTextEncodingMacDevanagari}, - {"MacGurmukhi", kTextEncodingMacGurmukhi}, - {"MacGujarati", kTextEncodingMacGujarati}, - {"MacOriya", kTextEncodingMacOriya}, - {"MacBengali", kTextEncodingMacBengali}, - {"MacTamil", kTextEncodingMacTamil}, - {"MacTelugu", kTextEncodingMacTelugu}, - {"MacKannada", kTextEncodingMacKannada}, - {"MacMalayalam", kTextEncodingMacMalayalam}, - {"MacSinhalese", kTextEncodingMacSinhalese}, - {"MacBurmese", kTextEncodingMacBurmese}, - {"MacKhmer", kTextEncodingMacKhmer}, - {"MacThai", kTextEncodingMacThai}, - {"MacLaotian", kTextEncodingMacLaotian}, - {"MacGeorgian", kTextEncodingMacGeorgian}, - {"MacArmenian", kTextEncodingMacArmenian}, - {"MacChineseSimp", kTextEncodingMacChineseSimp}, - {"MacTibetan", kTextEncodingMacTibetan}, - {"MacMongolian", kTextEncodingMacMongolian}, - {"MacEthiopic", kTextEncodingMacEthiopic}, - {"MacCentralEurRoman", kTextEncodingMacCentralEurRoman}, - {"MacVietnamese", kTextEncodingMacVietnamese}, - {"MacExtArabic", kTextEncodingMacExtArabic}, - {"MacSymbol", kTextEncodingMacSymbol}, - {"MacDingbats", kTextEncodingMacDingbats}, - {"MacTurkish", kTextEncodingMacTurkish}, - {"MacCroatian", kTextEncodingMacCroatian}, - {"MacIcelandic", kTextEncodingMacIcelandic}, - {"MacRomanian", kTextEncodingMacRomanian}, - {"MacCeltic", kTextEncodingMacCeltic}, - {"MacGaelic", kTextEncodingMacGaelic}, - {"MacKeyboardGlyphs", kTextEncodingMacKeyboardGlyphs}, - {"MacTradChinese", kTextEncodingMacTradChinese}, - {"MacRSymbol", kTextEncodingMacRSymbol}, - {"MacSimpChinese", kTextEncodingMacSimpChinese}, - {"MacGeez", kTextEncodingMacGeez}, - {"MacEastEurRoman", kTextEncodingMacEastEurRoman}, - {"MacUninterp", kTextEncodingMacUninterp}, - {"MacUnicode", kTextEncodingMacUnicode}, - {"MacFarsi", kTextEncodingMacFarsi}, - {"MacUkrainian", kTextEncodingMacUkrainian}, - {"MacInuit", kTextEncodingMacInuit}, - {"MacVT100", kTextEncodingMacVT100}, - {"MacHFS", kTextEncodingMacHFS}, - {"UnicodeDefault", kTextEncodingUnicodeDefault}, - {"UnicodeV1_1", kTextEncodingUnicodeV1_1}, - {"ISO10646_1993", kTextEncodingISO10646_1993}, - {"UnicodeV2_0", kTextEncodingUnicodeV2_0}, - {"UnicodeV2_1", kTextEncodingUnicodeV2_1}, - {"UnicodeV3_0", kTextEncodingUnicodeV3_0}, - {"UnicodeV3_1", kTextEncodingUnicodeV3_1}, - {"UnicodeV3_2", kTextEncodingUnicodeV3_2}, - {"ISOLatin1", kTextEncodingISOLatin1}, - {"ISOLatin2", kTextEncodingISOLatin2}, - {"ISOLatin3", kTextEncodingISOLatin3}, - {"ISOLatin4", kTextEncodingISOLatin4}, - {"ISOLatinCyrillic", kTextEncodingISOLatinCyrillic}, - {"ISOLatinArabic", kTextEncodingISOLatinArabic}, - {"ISOLatinGreek", kTextEncodingISOLatinGreek}, - {"ISOLatinHebrew", kTextEncodingISOLatinHebrew}, - {"ISOLatin5", kTextEncodingISOLatin5}, - {"ISOLatin6", kTextEncodingISOLatin6}, - {"ISOLatin7", kTextEncodingISOLatin7}, - {"ISOLatin8", kTextEncodingISOLatin8}, - {"ISOLatin9", kTextEncodingISOLatin9}, - {"DOSLatinUS", kTextEncodingDOSLatinUS}, - {"DOSGreek", kTextEncodingDOSGreek}, - {"DOSBalticRim", kTextEncodingDOSBalticRim}, - {"DOSLatin1", kTextEncodingDOSLatin1}, - {"DOSGreek1", kTextEncodingDOSGreek1}, - {"DOSLatin2", kTextEncodingDOSLatin2}, - {"DOSCyrillic", kTextEncodingDOSCyrillic}, - {"DOSTurkish", kTextEncodingDOSTurkish}, - {"DOSPortuguese", kTextEncodingDOSPortuguese}, - {"DOSIcelandic", kTextEncodingDOSIcelandic}, - {"DOSHebrew", kTextEncodingDOSHebrew}, - {"DOSCanadianFrench", kTextEncodingDOSCanadianFrench}, - {"DOSArabic", kTextEncodingDOSArabic}, - {"DOSNordic", kTextEncodingDOSNordic}, - {"DOSRussian", kTextEncodingDOSRussian}, - {"DOSGreek2", kTextEncodingDOSGreek2}, - {"DOSThai", kTextEncodingDOSThai}, - {"DOSJapanese", kTextEncodingDOSJapanese}, - {"DOSChineseSimplif", kTextEncodingDOSChineseSimplif}, - {"DOSKorean", kTextEncodingDOSKorean}, - {"DOSChineseTrad", kTextEncodingDOSChineseTrad}, - {"WindowsLatin1", kTextEncodingWindowsLatin1}, - {"WindowsANSI", kTextEncodingWindowsANSI}, - {"WindowsLatin2", kTextEncodingWindowsLatin2}, - {"WindowsCyrillic", kTextEncodingWindowsCyrillic}, - {"WindowsGreek", kTextEncodingWindowsGreek}, - {"WindowsLatin5", kTextEncodingWindowsLatin5}, - {"WindowsHebrew", kTextEncodingWindowsHebrew}, - {"WindowsArabic", kTextEncodingWindowsArabic}, - {"WindowsBalticRim", kTextEncodingWindowsBalticRim}, - {"WindowsVietnamese", kTextEncodingWindowsVietnamese}, - {"WindowsKoreanJohab", kTextEncodingWindowsKoreanJohab}, - {"US_ASCII", kTextEncodingUS_ASCII}, - {"JIS_X0201_76", kTextEncodingJIS_X0201_76}, - {"JIS_X0208_83", kTextEncodingJIS_X0208_83}, - {"JIS_X0208_90", kTextEncodingJIS_X0208_90}, - {"JIS_X0212_90", kTextEncodingJIS_X0212_90}, - {"JIS_C6226_78", kTextEncodingJIS_C6226_78}, - {"ShiftJIS_X0213_00", kTextEncodingShiftJIS_X0213_00}, - {"GB_2312_80", kTextEncodingGB_2312_80}, - {"GBK_95", kTextEncodingGBK_95}, - {"GB_18030_2000", kTextEncodingGB_18030_2000}, - {"KSC_5601_87", kTextEncodingKSC_5601_87}, - {"KSC_5601_92_Johab", kTextEncodingKSC_5601_92_Johab}, - {"CNS_11643_92_P1", kTextEncodingCNS_11643_92_P1}, - {"CNS_11643_92_P2", kTextEncodingCNS_11643_92_P2}, - {"CNS_11643_92_P3", kTextEncodingCNS_11643_92_P3}, - {"ISO_2022_JP", kTextEncodingISO_2022_JP}, - {"ISO_2022_JP_2", kTextEncodingISO_2022_JP_2}, - {"ISO_2022_JP_1", kTextEncodingISO_2022_JP_1}, - {"ISO_2022_JP_3", kTextEncodingISO_2022_JP_3}, - {"ISO_2022_CN", kTextEncodingISO_2022_CN}, - {"ISO_2022_CN_EXT", kTextEncodingISO_2022_CN_EXT}, - {"ISO_2022_KR", kTextEncodingISO_2022_KR}, - {"EUC_JP", kTextEncodingEUC_JP}, - {"EUC_CN", kTextEncodingEUC_CN}, - {"EUC_TW", kTextEncodingEUC_TW}, - {"EUC_KR", kTextEncodingEUC_KR}, - {"ShiftJIS", kTextEncodingShiftJIS}, - {"KOI8_R", kTextEncodingKOI8_R}, - {"Big5", kTextEncodingBig5}, - {"MacRomanLatin1", kTextEncodingMacRomanLatin1}, - {"HZ_GB_2312", kTextEncodingHZ_GB_2312}, - {"Big5_HKSCS_1999", kTextEncodingBig5_HKSCS_1999}, - {"NextStepLatin", kTextEncodingNextStepLatin}, - {"EBCDIC_US", kTextEncodingEBCDIC_US}, - {"EBCDIC_CP037", kTextEncodingEBCDIC_CP037}, - {"MultiRun", kTextEncodingMultiRun}, - - /* Terminator */ - {NULL, -1}, - }; - int i; - - i = 0; - for (i = 0; encodetable[i].name != NULL; ++i) - { - if (STRICMP(encodename, encodetable[i].name) == 0) - break; - } - return encodetable[i].encode; -} - -/* - * iconv interfaces - */ - - iconv_t -iconv_open(const char* tocode, const char* fromcode) -{ - TextEncoding toEnc, fromEnc; - iconv_t cd = NULL; - OSStatus st; - - /* Verify to/from encoding name */ - toEnc = get_textencoding(tocode); - fromEnc = get_textencoding(fromcode); - if (toEnc < 0 || fromEnc < 0) - goto ICONV_OPEN_ERR; - - /* Allocate memory to object */ - cd = (iconv_t)alloc(sizeof(struct _iconv_t)); - if (!cd) - goto ICONV_OPEN_ERR; - vim_memset(cd, 0, sizeof(struct _iconv_t)); - - /* Create converter */ - if (fromEnc != toEnc) - { - TRACE("*** fromEnc=%d toEnc=%d\n", (int)fromEnc, (int)toEnc); - st = TECCreateConverter(&cd->tec, fromEnc, toEnc); - if (st != 0) - { - TRACE("*** TECCreateConverter()=%d\n", (int)st); - goto ICONV_OPEN_ERR; - } - /* Create reverse converter */ - st = TECCreateConverter(&cd->tecReverse, toEnc, fromEnc); - if (st != 0) - { - TRACE("*** TECCreateConverter()=%d (reverse)\n", (int)st); - goto ICONV_OPEN_ERR; - } - /* Create Sniffer */ - st = TECCreateSniffer(&cd->sniff, &fromEnc, 1); - if (st != 0) - { - TRACE("*** TECCreateSniffer()=%d\n", (int)st); - goto ICONV_OPEN_ERR; - } - } - - cd->from = fromEnc; - cd->to = toEnc; - last_errno = 0; - return cd; - -ICONV_OPEN_ERR: - if (cd) - iconv_close(cd); - last_errno = EINVAL; - return (iconv_t)-1; -} - -/* - * Used when there are same value in 'from encoding' and 'to encoding'. - * TEC doesn't support conversion between same encodings, and - * TECCreateConverter() failed. - */ - static size_t -null_conv(iconv_t cd, const char **inbuf, size_t *inbytesleft, - char **outbuf, size_t *outbytesleft) -{ - const char* buf_in = inbuf && *inbuf ? *inbuf : NULL; - char* buf_out = outbuf && *outbuf ? *outbuf : NULL; - - if (buf_in) - { - int in_len = inbytesleft ? *inbytesleft : 0; - int out_len = outbytesleft ? *outbytesleft : 0; - - if (!buf_out || out_len <= 0) - { - last_errno = E2BIG; - return -1; - } - else if (in_len > 0) - { - int len = in_len < out_len ? in_len : out_len; - - memcpy (buf_out, buf_in, len); - *inbuf += len; - *outbuf += len; - *inbytesleft -= len; - *outbytesleft -= len; - if (*outbytesleft <= 0) - { - last_errno = E2BIG; - return -1; - } - } - } - last_errno = 0; - return 0; -} - - size_t -iconv(iconv_t cd, const char **inbuf, size_t *inbytesleft, - char **outbuf, size_t *outbytesleft) -{ - ConstTextPtr buf_in; - TextPtr buf_out; - ByteCount out_len, out_true; - ByteCount in_len, in_true; - OSStatus st; - - if (!cd) - { - last_errno = ENOENT; /* TODO: Another error code should be set */ - return -1; - } - if (cd->from == cd->to) - return null_conv(cd, inbuf, inbytesleft, outbuf, outbytesleft) ; - - buf_in = (TextPtr) inbuf ; - buf_out = (TextPtr) outbuf ; - out_len = out_true = -1; - in_len = in_true = -1; - - if (buf_in && buf_out) - { - ItemCount error, feature; - - /* Normal convert mode */ - if (!inbytesleft || !outbytesleft) - { - last_errno = EFAULT; - return -1; - } - in_len = *inbytesleft; - out_len = *outbytesleft; - - /* Check stream is form in expected encoding or not */ - st = TECSniffTextEncoding(cd->sniff, (TextPtr)buf_in, in_len, - &cd->from, 1, &error, 1, &feature, 1); - TRACE("TECSniffTextEncoding()=%d error=%d feature=%d\n", - (int)st, (int)error, (int)feature); - if ((error != 0 || feature == 0) - && !(error == 0xffffffff && feature == 0xffffffff)) - /* Not expected encoding */ - st = kTECUnmappableElementErr; - else - { - /* Do convert */ - st = TECConvertText(cd->tec, - buf_in, in_len, &in_true, - buf_out, out_len, &out_true); - /* Verify converted text. Compare original text with reverse - * converted text. If not match, there is some problem on - * converting. */ - if (st == 0 && in_true > 0) - { - ByteCount rev_in, rev_out; - TextPtr buf_rev = (TextPtr)alloc(in_true); - - if (buf_rev) - { - st = TECConvertText(cd->tecReverse, - buf_out, out_true, &rev_in, - buf_rev, in_true, &rev_out); - if (st != 0 || rev_in != out_true || rev_out != in_true - || memcmp(buf_rev, buf_in, rev_out) != 0) - { -#ifdef ICONVOSX_DEBUG - fprintf(stderr, " reverse conversion failed.\n"); -#endif - st = kTECUnmappableElementErr; - } - vim_free(buf_rev); - } - else - st = kTECUnmappableElementErr; - } - } - } - else if (!buf_in && buf_out) - { - /* Flush all buffered strings to buffer, and reset status */ - if (!outbytesleft) - { - last_errno = EFAULT; - return -1; - } - out_len = *outbytesleft; - st = TECFlushText(cd->tec, - buf_out, out_len, &out_true); - } - else if (!buf_in && !buf_out) - { - /* Reset cd's status and cancel buffered strings */ - unsigned char tmp_out[256]; - - buf_out = tmp_out; - out_len = sizeof(tmp_out); - st = TECFlushText(cd->tec, - buf_out, out_len, &out_true); - } - else - { - last_errno = EFAULT; - return -1; - } - TRACE("st=%d, buf_in=%p, in_len=%d, in_true=%d\n" - " buf_out=%p, out_len=%d, out_true=%d\n", (int)st, - buf_in, (int)in_len, (int)in_true, - buf_out, (int)out_len, (int)out_true); - - switch (st) - { - case 0: - /* No error */ - if (inbytesleft) - *inbytesleft -= in_true; - if (outbytesleft) - *outbytesleft -= out_true; - if (inbuf && *inbuf) - *inbuf += in_true; - if (outbuf && *outbuf) - *outbuf += out_true; - last_errno = 0; - return 0; /* No error */ - case kTECUnmappableElementErr: - last_errno = EILSEQ; - case kTECIncompleteElementErr: - last_errno = EINVAL; - case kTECOutputBufferFullStatus: - last_errno = E2BIG; - return -1; - default: - TRACE("iconv(%p, %p, %p, %p, %p) failed. (%d)\n", - cd, inbuf, inbytesleft, outbuf, outbytesleft, (int)st); - last_errno = EFAULT; - return -1; - } -} - - int -iconv_close(iconv_t cd) -{ - if (cd) - { - /* Free all elements of iconv_t */ - if (cd->tec) - TECDisposeConverter(cd->tec); - if (cd->tecReverse) - TECDisposeConverter(cd->tecReverse); - if (cd->sniff) - TECDisposeSniffer(cd->sniff); - vim_free(cd); - last_errno = 0; - return 0; - } - else - { - last_errno = EINVAL; - return -1; - } -} - - int * -iconv_errno() -{ - return &last_errno; -} -#endif /* MACOS_X_ICONVEMU */ - -#ifdef USE_MCH_GETTEXT - -#define GETTEXT_BUFNUM 64 -#define GETTEXT_BUFSIZE 256 - - char * -mch_gettext(const char *msgid) -{ - static char buf[GETTEXT_BUFNUM][GETTEXT_BUFSIZE]; - static int bufnum = 0; - const char *msg = NULL; - CFStringRef strkey = NULL, strmsg = NULL; - CFStringEncoding enc; - - if (!msgid) - goto MCH_GETTEXT_FINISH; - enc = CFStringGetSystemEncoding(); - TRACE("mch_gettext(%s)\n", msgid); - - strkey = CFStringCreateWithCString(NULL, msgid, enc); - if (!strkey) - { - TRACE(" Can't create a CFString for msgid.\n"); - goto MCH_GETTEXT_FINISH; - } - - strmsg = CFCopyLocalizedString(strkey, NULL); - if (!strmsg) - { - TRACE(" No localized strings for msgid.\n"); - goto MCH_GETTEXT_FINISH; - } - - msg = CFStringGetCStringPtr(strmsg, enc); - if (!msg) - { - /* This is as backup when CFStringGetCStringPtr was failed */ - CFStringGetCString(strmsg, buf[bufnum], GETTEXT_BUFSIZE, enc); - msg = buf[bufnum]; - if (++bufnum >= GETTEXT_BUFNUM) - bufnum = 0; - } - TRACE(" Localized to: %s\n", msg); - -MCH_GETTEXT_FINISH: - if (strkey) - CFRelease(strkey); - if (strmsg) - CFRelease(strmsg); - return (char *)(msg ? msg : msgid); -} - - char * -mch_bindtextdomain(const char *domain, const char *dirname) -{ - TRACE("mch_bindtextdomain(%s, %s)\n", domain, dirname); - return (char*)dirname; -} - - char * -mch_textdomain(const char *domain) -{ - TRACE("mch_textdomain(%s)\n", domain); - return (char*)domain; -} -#endif diff --git a/src/os_macosx.m b/src/os_macosx.m new file mode 100644 index 000000000..7067df4b7 --- /dev/null +++ b/src/os_macosx.m @@ -0,0 +1,783 @@ +/* vi:set ts=8 sts=4 sw=4: + * + * VIM - Vi IMproved by Bram Moolenaar + * + * Do ":help uganda" in Vim to read copying and usage conditions. + * Do ":help credits" in Vim to see a list of people who contributed. + * See README.txt for an overview of the Vim source code. + */ + +/* + * os_macosx.m -- Mac specific things for Mac OS/X. + */ + +#ifndef MACOS_X_UNIX + Error: MACOS 9 is no longer supported in Vim 7 +#endif + +#include "vim.h" +#import + + +NSString *VimPboardType = @"VimPboardType"; + + +#ifdef _DEBUG + void +Trace(char* fmt, ...) +{ + char buf[2048]; + va_list args; + + va_start(args, fmt); + /* vsnprintf(buf, sizeof(buf), fmt, args);*/ + fprintf(stderr, "%s", buf); + va_end(args); +} +#endif + +#ifdef MACOS_X_ICONVEMU +/* + * Libiconv emulation layer + */ + +struct _iconv_t +{ + TECObjectRef tec; + TECObjectRef tecReverse; + TECSnifferObjectRef sniff; + TextEncoding from; + TextEncoding to; +}; +/* typedef struct _iconv_t *iconv_t; */ + + +static int last_errno = 0; + +/* + * Get TextEncoding from iconv's encoding name + */ + static TextEncoding +get_textencoding(const char* encodename) +{ + static struct { + const char* name; + TextEncoding encode; + } encodetable[] = { + /* ISO-8859 encodings family */ + {"latin1", kTextEncodingISOLatin1}, + {"latin2", kTextEncodingISOLatin2}, + {"latin3", kTextEncodingISOLatin3}, + {"latin4", kTextEncodingISOLatin4}, + {"latin5", kTextEncodingISOLatin5}, + {"latin6", kTextEncodingISOLatin6}, + {"latin7", kTextEncodingISOLatin7}, + {"latin8", kTextEncodingISOLatin8}, + {"latin9", kTextEncodingISOLatin9}, + {"iso-8859-1", kTextEncodingISOLatin1}, + {"iso-8859-2", kTextEncodingISOLatin2}, + {"iso-8859-3", kTextEncodingISOLatin3}, + {"iso-8859-4", kTextEncodingISOLatin4}, + {"iso-8859-5", kTextEncodingISOLatinCyrillic}, + {"iso-8859-6", kTextEncodingISOLatinArabic}, + {"iso-8859-7", kTextEncodingISOLatinGreek}, + {"iso-8859-8", kTextEncodingISOLatinHebrew}, + {"iso-8859-9", kTextEncodingISOLatin5}, + {"iso-8859-10", kTextEncodingISOLatin6}, + {"iso-8859-15", kTextEncodingISOLatin9}, + + /* Unicode encodings. */ + /* TODO: Add other type of unicode */ + {"ucs-2", kTextEncodingMacUnicode}, + + /* Japanese encoding aliases */ + {"cp932", kTextEncodingShiftJIS}, + {"shift-jis", kTextEncodingShiftJIS}, + {"euc-jp", kTextEncodingEUC_JP}, + {"iso-2022-jp", kTextEncodingISO_2022_JP}, + {"iso-2022-jp-1", kTextEncodingISO_2022_JP_1}, + {"iso-2022-jp-2", kTextEncodingISO_2022_JP_2}, + {"iso-2022-jp-3", kTextEncodingISO_2022_JP_3}, + + /* Other aliases. These aliases in this block are just guessed. */ + /* TODO: Must be verified. */ + {"gb2312", kTextEncodingGB_2312_80}, + {"cp936", kTextEncodingMacChineseSimp}, + {"euc-cn", kTextEncodingEUC_CN}, + {"cp950", kTextEncodingMacChineseTrad}, + {"euc-tw", kTextEncodingEUC_TW}, + {"cp949", kTextEncodingMacKorean}, + {"euc-kr", kTextEncodingEUC_KR}, + + /* + * All encodings supported by Macintosh. You can find these values + * in a file: + * /System/Library/Frameworks/CoreServices.framework/Versions/A/ + * Frameworks/CarbonCore.framework/Versions/A/Headers/TextCommon.h + */ + {"MacRoman", kTextEncodingMacRoman}, + {"MacJapanese", kTextEncodingMacJapanese}, + {"MacChineseTrad", kTextEncodingMacChineseTrad}, + {"MacKorean", kTextEncodingMacKorean}, + {"MacArabic", kTextEncodingMacArabic}, + {"MacHebrew", kTextEncodingMacHebrew}, + {"MacGreek", kTextEncodingMacGreek}, + {"MacCyrillic", kTextEncodingMacCyrillic}, + {"MacDevanagari", kTextEncodingMacDevanagari}, + {"MacGurmukhi", kTextEncodingMacGurmukhi}, + {"MacGujarati", kTextEncodingMacGujarati}, + {"MacOriya", kTextEncodingMacOriya}, + {"MacBengali", kTextEncodingMacBengali}, + {"MacTamil", kTextEncodingMacTamil}, + {"MacTelugu", kTextEncodingMacTelugu}, + {"MacKannada", kTextEncodingMacKannada}, + {"MacMalayalam", kTextEncodingMacMalayalam}, + {"MacSinhalese", kTextEncodingMacSinhalese}, + {"MacBurmese", kTextEncodingMacBurmese}, + {"MacKhmer", kTextEncodingMacKhmer}, + {"MacThai", kTextEncodingMacThai}, + {"MacLaotian", kTextEncodingMacLaotian}, + {"MacGeorgian", kTextEncodingMacGeorgian}, + {"MacArmenian", kTextEncodingMacArmenian}, + {"MacChineseSimp", kTextEncodingMacChineseSimp}, + {"MacTibetan", kTextEncodingMacTibetan}, + {"MacMongolian", kTextEncodingMacMongolian}, + {"MacEthiopic", kTextEncodingMacEthiopic}, + {"MacCentralEurRoman", kTextEncodingMacCentralEurRoman}, + {"MacVietnamese", kTextEncodingMacVietnamese}, + {"MacExtArabic", kTextEncodingMacExtArabic}, + {"MacSymbol", kTextEncodingMacSymbol}, + {"MacDingbats", kTextEncodingMacDingbats}, + {"MacTurkish", kTextEncodingMacTurkish}, + {"MacCroatian", kTextEncodingMacCroatian}, + {"MacIcelandic", kTextEncodingMacIcelandic}, + {"MacRomanian", kTextEncodingMacRomanian}, + {"MacCeltic", kTextEncodingMacCeltic}, + {"MacGaelic", kTextEncodingMacGaelic}, + {"MacKeyboardGlyphs", kTextEncodingMacKeyboardGlyphs}, + {"MacTradChinese", kTextEncodingMacTradChinese}, + {"MacRSymbol", kTextEncodingMacRSymbol}, + {"MacSimpChinese", kTextEncodingMacSimpChinese}, + {"MacGeez", kTextEncodingMacGeez}, + {"MacEastEurRoman", kTextEncodingMacEastEurRoman}, + {"MacUninterp", kTextEncodingMacUninterp}, + {"MacUnicode", kTextEncodingMacUnicode}, + {"MacFarsi", kTextEncodingMacFarsi}, + {"MacUkrainian", kTextEncodingMacUkrainian}, + {"MacInuit", kTextEncodingMacInuit}, + {"MacVT100", kTextEncodingMacVT100}, + {"MacHFS", kTextEncodingMacHFS}, + {"UnicodeDefault", kTextEncodingUnicodeDefault}, + {"UnicodeV1_1", kTextEncodingUnicodeV1_1}, + {"ISO10646_1993", kTextEncodingISO10646_1993}, + {"UnicodeV2_0", kTextEncodingUnicodeV2_0}, + {"UnicodeV2_1", kTextEncodingUnicodeV2_1}, + {"UnicodeV3_0", kTextEncodingUnicodeV3_0}, + {"UnicodeV3_1", kTextEncodingUnicodeV3_1}, + {"UnicodeV3_2", kTextEncodingUnicodeV3_2}, + {"ISOLatin1", kTextEncodingISOLatin1}, + {"ISOLatin2", kTextEncodingISOLatin2}, + {"ISOLatin3", kTextEncodingISOLatin3}, + {"ISOLatin4", kTextEncodingISOLatin4}, + {"ISOLatinCyrillic", kTextEncodingISOLatinCyrillic}, + {"ISOLatinArabic", kTextEncodingISOLatinArabic}, + {"ISOLatinGreek", kTextEncodingISOLatinGreek}, + {"ISOLatinHebrew", kTextEncodingISOLatinHebrew}, + {"ISOLatin5", kTextEncodingISOLatin5}, + {"ISOLatin6", kTextEncodingISOLatin6}, + {"ISOLatin7", kTextEncodingISOLatin7}, + {"ISOLatin8", kTextEncodingISOLatin8}, + {"ISOLatin9", kTextEncodingISOLatin9}, + {"DOSLatinUS", kTextEncodingDOSLatinUS}, + {"DOSGreek", kTextEncodingDOSGreek}, + {"DOSBalticRim", kTextEncodingDOSBalticRim}, + {"DOSLatin1", kTextEncodingDOSLatin1}, + {"DOSGreek1", kTextEncodingDOSGreek1}, + {"DOSLatin2", kTextEncodingDOSLatin2}, + {"DOSCyrillic", kTextEncodingDOSCyrillic}, + {"DOSTurkish", kTextEncodingDOSTurkish}, + {"DOSPortuguese", kTextEncodingDOSPortuguese}, + {"DOSIcelandic", kTextEncodingDOSIcelandic}, + {"DOSHebrew", kTextEncodingDOSHebrew}, + {"DOSCanadianFrench", kTextEncodingDOSCanadianFrench}, + {"DOSArabic", kTextEncodingDOSArabic}, + {"DOSNordic", kTextEncodingDOSNordic}, + {"DOSRussian", kTextEncodingDOSRussian}, + {"DOSGreek2", kTextEncodingDOSGreek2}, + {"DOSThai", kTextEncodingDOSThai}, + {"DOSJapanese", kTextEncodingDOSJapanese}, + {"DOSChineseSimplif", kTextEncodingDOSChineseSimplif}, + {"DOSKorean", kTextEncodingDOSKorean}, + {"DOSChineseTrad", kTextEncodingDOSChineseTrad}, + {"WindowsLatin1", kTextEncodingWindowsLatin1}, + {"WindowsANSI", kTextEncodingWindowsANSI}, + {"WindowsLatin2", kTextEncodingWindowsLatin2}, + {"WindowsCyrillic", kTextEncodingWindowsCyrillic}, + {"WindowsGreek", kTextEncodingWindowsGreek}, + {"WindowsLatin5", kTextEncodingWindowsLatin5}, + {"WindowsHebrew", kTextEncodingWindowsHebrew}, + {"WindowsArabic", kTextEncodingWindowsArabic}, + {"WindowsBalticRim", kTextEncodingWindowsBalticRim}, + {"WindowsVietnamese", kTextEncodingWindowsVietnamese}, + {"WindowsKoreanJohab", kTextEncodingWindowsKoreanJohab}, + {"US_ASCII", kTextEncodingUS_ASCII}, + {"JIS_X0201_76", kTextEncodingJIS_X0201_76}, + {"JIS_X0208_83", kTextEncodingJIS_X0208_83}, + {"JIS_X0208_90", kTextEncodingJIS_X0208_90}, + {"JIS_X0212_90", kTextEncodingJIS_X0212_90}, + {"JIS_C6226_78", kTextEncodingJIS_C6226_78}, + {"ShiftJIS_X0213_00", kTextEncodingShiftJIS_X0213_00}, + {"GB_2312_80", kTextEncodingGB_2312_80}, + {"GBK_95", kTextEncodingGBK_95}, + {"GB_18030_2000", kTextEncodingGB_18030_2000}, + {"KSC_5601_87", kTextEncodingKSC_5601_87}, + {"KSC_5601_92_Johab", kTextEncodingKSC_5601_92_Johab}, + {"CNS_11643_92_P1", kTextEncodingCNS_11643_92_P1}, + {"CNS_11643_92_P2", kTextEncodingCNS_11643_92_P2}, + {"CNS_11643_92_P3", kTextEncodingCNS_11643_92_P3}, + {"ISO_2022_JP", kTextEncodingISO_2022_JP}, + {"ISO_2022_JP_2", kTextEncodingISO_2022_JP_2}, + {"ISO_2022_JP_1", kTextEncodingISO_2022_JP_1}, + {"ISO_2022_JP_3", kTextEncodingISO_2022_JP_3}, + {"ISO_2022_CN", kTextEncodingISO_2022_CN}, + {"ISO_2022_CN_EXT", kTextEncodingISO_2022_CN_EXT}, + {"ISO_2022_KR", kTextEncodingISO_2022_KR}, + {"EUC_JP", kTextEncodingEUC_JP}, + {"EUC_CN", kTextEncodingEUC_CN}, + {"EUC_TW", kTextEncodingEUC_TW}, + {"EUC_KR", kTextEncodingEUC_KR}, + {"ShiftJIS", kTextEncodingShiftJIS}, + {"KOI8_R", kTextEncodingKOI8_R}, + {"Big5", kTextEncodingBig5}, + {"MacRomanLatin1", kTextEncodingMacRomanLatin1}, + {"HZ_GB_2312", kTextEncodingHZ_GB_2312}, + {"Big5_HKSCS_1999", kTextEncodingBig5_HKSCS_1999}, + {"NextStepLatin", kTextEncodingNextStepLatin}, + {"EBCDIC_US", kTextEncodingEBCDIC_US}, + {"EBCDIC_CP037", kTextEncodingEBCDIC_CP037}, + {"MultiRun", kTextEncodingMultiRun}, + + /* Terminator */ + {NULL, -1}, + }; + int i; + + i = 0; + for (i = 0; encodetable[i].name != NULL; ++i) + { + if (STRICMP(encodename, encodetable[i].name) == 0) + break; + } + return encodetable[i].encode; +} + +/* + * iconv interfaces + */ + + iconv_t +iconv_open(const char* tocode, const char* fromcode) +{ + TextEncoding toEnc, fromEnc; + iconv_t cd = NULL; + OSStatus st; + + /* Verify to/from encoding name */ + toEnc = get_textencoding(tocode); + fromEnc = get_textencoding(fromcode); + if (toEnc < 0 || fromEnc < 0) + goto ICONV_OPEN_ERR; + + /* Allocate memory to object */ + cd = (iconv_t)alloc(sizeof(struct _iconv_t)); + if (!cd) + goto ICONV_OPEN_ERR; + vim_memset(cd, 0, sizeof(struct _iconv_t)); + + /* Create converter */ + if (fromEnc != toEnc) + { + TRACE("*** fromEnc=%d toEnc=%d\n", (int)fromEnc, (int)toEnc); + st = TECCreateConverter(&cd->tec, fromEnc, toEnc); + if (st != 0) + { + TRACE("*** TECCreateConverter()=%d\n", (int)st); + goto ICONV_OPEN_ERR; + } + /* Create reverse converter */ + st = TECCreateConverter(&cd->tecReverse, toEnc, fromEnc); + if (st != 0) + { + TRACE("*** TECCreateConverter()=%d (reverse)\n", (int)st); + goto ICONV_OPEN_ERR; + } + /* Create Sniffer */ + st = TECCreateSniffer(&cd->sniff, &fromEnc, 1); + if (st != 0) + { + TRACE("*** TECCreateSniffer()=%d\n", (int)st); + goto ICONV_OPEN_ERR; + } + } + + cd->from = fromEnc; + cd->to = toEnc; + last_errno = 0; + return cd; + +ICONV_OPEN_ERR: + if (cd) + iconv_close(cd); + last_errno = EINVAL; + return (iconv_t)-1; +} + +/* + * Used when there are same value in 'from encoding' and 'to encoding'. + * TEC doesn't support conversion between same encodings, and + * TECCreateConverter() failed. + */ + static size_t +null_conv(iconv_t cd, const char **inbuf, size_t *inbytesleft, + char **outbuf, size_t *outbytesleft) +{ + const char* buf_in = inbuf && *inbuf ? *inbuf : NULL; + char* buf_out = outbuf && *outbuf ? *outbuf : NULL; + + if (buf_in) + { + int in_len = inbytesleft ? *inbytesleft : 0; + int out_len = outbytesleft ? *outbytesleft : 0; + + if (!buf_out || out_len <= 0) + { + last_errno = E2BIG; + return -1; + } + else if (in_len > 0) + { + int len = in_len < out_len ? in_len : out_len; + + memcpy (buf_out, buf_in, len); + *inbuf += len; + *outbuf += len; + *inbytesleft -= len; + *outbytesleft -= len; + if (*outbytesleft <= 0) + { + last_errno = E2BIG; + return -1; + } + } + } + last_errno = 0; + return 0; +} + + size_t +iconv(iconv_t cd, const char **inbuf, size_t *inbytesleft, + char **outbuf, size_t *outbytesleft) +{ + ConstTextPtr buf_in; + TextPtr buf_out; + ByteCount out_len, out_true; + ByteCount in_len, in_true; + OSStatus st; + + if (!cd) + { + last_errno = ENOENT; /* TODO: Another error code should be set */ + return -1; + } + if (cd->from == cd->to) + return null_conv(cd, inbuf, inbytesleft, outbuf, outbytesleft) ; + + buf_in = (TextPtr) inbuf ; + buf_out = (TextPtr) outbuf ; + out_len = out_true = -1; + in_len = in_true = -1; + + if (buf_in && buf_out) + { + ItemCount error, feature; + + /* Normal convert mode */ + if (!inbytesleft || !outbytesleft) + { + last_errno = EFAULT; + return -1; + } + in_len = *inbytesleft; + out_len = *outbytesleft; + + /* Check stream is form in expected encoding or not */ + st = TECSniffTextEncoding(cd->sniff, (TextPtr)buf_in, in_len, + &cd->from, 1, &error, 1, &feature, 1); + TRACE("TECSniffTextEncoding()=%d error=%d feature=%d\n", + (int)st, (int)error, (int)feature); + if ((error != 0 || feature == 0) + && !(error == 0xffffffff && feature == 0xffffffff)) + /* Not expected encoding */ + st = kTECUnmappableElementErr; + else + { + /* Do convert */ + st = TECConvertText(cd->tec, + buf_in, in_len, &in_true, + buf_out, out_len, &out_true); + /* Verify converted text. Compare original text with reverse + * converted text. If not match, there is some problem on + * converting. */ + if (st == 0 && in_true > 0) + { + ByteCount rev_in, rev_out; + TextPtr buf_rev = (TextPtr)alloc(in_true); + + if (buf_rev) + { + st = TECConvertText(cd->tecReverse, + buf_out, out_true, &rev_in, + buf_rev, in_true, &rev_out); + if (st != 0 || rev_in != out_true || rev_out != in_true + || memcmp(buf_rev, buf_in, rev_out) != 0) + { +#ifdef ICONVOSX_DEBUG + fprintf(stderr, " reverse conversion failed.\n"); +#endif + st = kTECUnmappableElementErr; + } + vim_free(buf_rev); + } + else + st = kTECUnmappableElementErr; + } + } + } + else if (!buf_in && buf_out) + { + /* Flush all buffered strings to buffer, and reset status */ + if (!outbytesleft) + { + last_errno = EFAULT; + return -1; + } + out_len = *outbytesleft; + st = TECFlushText(cd->tec, + buf_out, out_len, &out_true); + } + else if (!buf_in && !buf_out) + { + /* Reset cd's status and cancel buffered strings */ + unsigned char tmp_out[256]; + + buf_out = tmp_out; + out_len = sizeof(tmp_out); + st = TECFlushText(cd->tec, + buf_out, out_len, &out_true); + } + else + { + last_errno = EFAULT; + return -1; + } + TRACE("st=%d, buf_in=%p, in_len=%d, in_true=%d\n" + " buf_out=%p, out_len=%d, out_true=%d\n", (int)st, + buf_in, (int)in_len, (int)in_true, + buf_out, (int)out_len, (int)out_true); + + switch (st) + { + case 0: + /* No error */ + if (inbytesleft) + *inbytesleft -= in_true; + if (outbytesleft) + *outbytesleft -= out_true; + if (inbuf && *inbuf) + *inbuf += in_true; + if (outbuf && *outbuf) + *outbuf += out_true; + last_errno = 0; + return 0; /* No error */ + case kTECUnmappableElementErr: + last_errno = EILSEQ; + case kTECIncompleteElementErr: + last_errno = EINVAL; + case kTECOutputBufferFullStatus: + last_errno = E2BIG; + return -1; + default: + TRACE("iconv(%p, %p, %p, %p, %p) failed. (%d)\n", + cd, inbuf, inbytesleft, outbuf, outbytesleft, (int)st); + last_errno = EFAULT; + return -1; + } +} + + int +iconv_close(iconv_t cd) +{ + if (cd) + { + /* Free all elements of iconv_t */ + if (cd->tec) + TECDisposeConverter(cd->tec); + if (cd->tecReverse) + TECDisposeConverter(cd->tecReverse); + if (cd->sniff) + TECDisposeSniffer(cd->sniff); + vim_free(cd); + last_errno = 0; + return 0; + } + else + { + last_errno = EINVAL; + return -1; + } +} + + int * +iconv_errno() +{ + return &last_errno; +} +#endif /* MACOS_X_ICONVEMU */ + +#ifdef USE_MCH_GETTEXT + +#define GETTEXT_BUFNUM 64 +#define GETTEXT_BUFSIZE 256 + + char * +mch_gettext(const char *msgid) +{ + static char buf[GETTEXT_BUFNUM][GETTEXT_BUFSIZE]; + static int bufnum = 0; + const char *msg = NULL; + CFStringRef strkey = NULL, strmsg = NULL; + CFStringEncoding enc; + + if (!msgid) + goto MCH_GETTEXT_FINISH; + enc = CFStringGetSystemEncoding(); + TRACE("mch_gettext(%s)\n", msgid); + + strkey = CFStringCreateWithCString(NULL, msgid, enc); + if (!strkey) + { + TRACE(" Can't create a CFString for msgid.\n"); + goto MCH_GETTEXT_FINISH; + } + + strmsg = CFCopyLocalizedString(strkey, NULL); + if (!strmsg) + { + TRACE(" No localized strings for msgid.\n"); + goto MCH_GETTEXT_FINISH; + } + + msg = CFStringGetCStringPtr(strmsg, enc); + if (!msg) + { + /* This is as backup when CFStringGetCStringPtr was failed */ + CFStringGetCString(strmsg, buf[bufnum], GETTEXT_BUFSIZE, enc); + msg = buf[bufnum]; + if (++bufnum >= GETTEXT_BUFNUM) + bufnum = 0; + } + TRACE(" Localized to: %s\n", msg); + +MCH_GETTEXT_FINISH: + if (strkey) + CFRelease(strkey); + if (strmsg) + CFRelease(strmsg); + return (char *)(msg ? msg : msgid); +} + + char * +mch_bindtextdomain(const char *domain, const char *dirname) +{ + TRACE("mch_bindtextdomain(%s, %s)\n", domain, dirname); + return (char*)dirname; +} + + char * +mch_textdomain(const char *domain) +{ + TRACE("mch_textdomain(%s)\n", domain); + return (char*)domain; +} +#endif + + + +#ifdef FEAT_CLIPBOARD + + void +clip_mch_lose_selection(VimClipboard *cbd) +{ +} + + + int +clip_mch_own_selection(VimClipboard *cbd) +{ + /* This is called whenever there is a new selection and 'guioptions' + * contains the "a" flag (automatically copy selection). Return TRUE, else + * the "a" flag does nothing. Note that there is no concept of "ownership" + * of the clipboard in Mac OS X. + */ + return TRUE; +} + + + void +clip_mch_request_selection(VimClipboard *cbd) +{ + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + + NSPasteboard *pb = [NSPasteboard generalPasteboard]; + NSArray *supportedTypes = [NSArray arrayWithObjects:VimPboardType, + NSStringPboardType, nil]; + NSString *bestType = [pb availableTypeFromArray:supportedTypes]; + if (!bestType) goto releasepool; + + int motion_type = MCHAR; + NSString *string = nil; + + if ([bestType isEqual:VimPboardType]) + { + /* This type should consist of an array with two objects: + * 1. motion type (NSNumber) + * 2. text (NSString) + * If this is not the case we fall back on using NSStringPboardType. + */ + id plist = [pb propertyListForType:VimPboardType]; + if ([plist isKindOfClass:[NSArray class]] && [plist count] == 2) + { + id obj = [plist objectAtIndex:1]; + if ([obj isKindOfClass:[NSString class]]) + { + motion_type = [[plist objectAtIndex:0] intValue]; + string = obj; + } + } + } + + if (!string) + { + /* Use NSStringPboardType. The motion type is set to line-wise if the + * string contains at least one EOL character, otherwise it is set to + * character-wise (block-wise is never used). + */ + NSMutableString *mstring = + [[pb stringForType:NSStringPboardType] mutableCopy]; + if (!mstring) goto releasepool; + + /* Replace unrecognized end-of-line sequences with \x0a (line feed). */ + NSRange range = { 0, [mstring length] }; + unsigned n = [mstring replaceOccurrencesOfString:@"\x0d\x0a" + withString:@"\x0a" options:0 + range:range]; + if (0 == n) + { + n = [mstring replaceOccurrencesOfString:@"\x0d" withString:@"\x0a" + options:0 range:range]; + } + + /* Scan for newline character to decide whether the string should be + * pasted line-wise or character-wise. + */ + motion_type = MCHAR; + if (0 < n || NSNotFound != [mstring rangeOfString:@"\n"].location) + motion_type = MLINE; + + string = mstring; + } + + if (!(MCHAR == motion_type || MLINE == motion_type || MBLOCK == motion_type + || MAUTO == motion_type)) + motion_type = MCHAR; + + char_u *str = (char_u*)[string UTF8String]; + int len = [string lengthOfBytesUsingEncoding:NSUTF8StringEncoding]; + +#ifdef FEAT_MBYTE + if (input_conv.vc_type != CONV_NONE) + str = string_convert(&input_conv, str, &len); +#endif + + if (str) + clip_yank_selection(motion_type, str, len, cbd); + +#ifdef FEAT_MBYTE + if (input_conv.vc_type != CONV_NONE) + vim_free(str); +#endif + +releasepool: + [pool release]; +} + + +/* + * Send the current selection to the clipboard. + */ + void +clip_mch_set_selection(VimClipboard *cbd) +{ + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + + /* If the '*' register isn't already filled in, fill it in now. */ + cbd->owned = TRUE; + clip_get_selection(cbd); + cbd->owned = FALSE; + + /* Get the text to put on the pasteboard. */ + long_u llen = 0; char_u *str = 0; + int motion_type = clip_convert_selection(&str, &llen, cbd); + if (motion_type < 0) + goto releasepool; + + /* TODO: Avoid overflow. */ + int len = (int)llen; +#ifdef FEAT_MBYTE + if (output_conv.vc_type != CONV_NONE) + { + char_u *conv_str = string_convert(&output_conv, str, &len); + if (conv_str) + { + vim_free(str); + str = conv_str; + } + } +#endif + + if (len > 0) + { + NSString *string = [[NSString alloc] + initWithBytes:str length:len encoding:NSUTF8StringEncoding]; + + /* See clip_mch_request_selection() for info on pasteboard types. */ + NSPasteboard *pb = [NSPasteboard generalPasteboard]; + NSArray *supportedTypes = [NSArray arrayWithObjects:VimPboardType, + NSStringPboardType, nil]; + [pb declareTypes:supportedTypes owner:nil]; + + NSNumber *motion = [NSNumber numberWithInt:motion_type]; + NSArray *plist = [NSArray arrayWithObjects:motion, string, nil]; + [pb setPropertyList:plist forType:VimPboardType]; + + [pb setString:string forType:NSStringPboardType]; + + [string release]; + } + + vim_free(str); +releasepool: + [pool release]; +} + +#endif /* FEAT_CLIPBOARD */ diff --git a/src/vim.h b/src/vim.h index cb2bc7da1..b231f1987 100644 --- a/src/vim.h +++ b/src/vim.h @@ -93,6 +93,9 @@ # ifndef HAVE_CONFIG_H # define UNIX # endif +# ifndef FEAT_CLIPBOARD +# define FEAT_CLIPBOARD +# endif #endif #if defined(MACOS_X) || defined(MACOS_CLASSIC) # define MACOS -- cgit v1.2.1