pax_global_header00006660000000000000000000000064117516314320014515gustar00rootroot0000000000000052 comment=e8d34024a6b185a759733915f116cc5588550261 ittner-lua-iconv-466b58d/000077500000000000000000000000001175163143200152615ustar00rootroot00000000000000ittner-lua-iconv-466b58d/.gitignore000066400000000000000000000000271175163143200172500ustar00rootroot00000000000000*.lo *.o *.so *.tar.gz ittner-lua-iconv-466b58d/COPYING000066400000000000000000000027351175163143200163230ustar00rootroot00000000000000Lua-iconv is (c) 2005-10 Alexandre Erwin Ittner Lua-iconv is copyrighted free software: it can be used for both academic and commercial purposes at absolutely no cost. There are no royalties or GNU-like "copyleft" restrictions. The legal details are below: Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHOR OR COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. If you use this package in a product, an acknowledgment in the product documentation would be greatly appreciated (but it is not required). ittner-lua-iconv-466b58d/Makefile000066400000000000000000000050731175163143200167260ustar00rootroot00000000000000# luaiconv - Performs character set conversions in Lua # (c) 2005-10 Alexandre Erwin Ittner # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the # "Software"), to deal in the Software without restriction, including # without limitation the rights to use, copy, modify, merge, publish, # distribute, sublicense, and/or sell copies of the Software, and to # permit persons to whom the Software is furnished to do so, subject to # the following conditions: # # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. # IN NO EVENT SHALL THE AUTHOR OR COPYRIGHT HOLDER BE LIABLE FOR ANY # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # # If you use this package in a product, an acknowledgment in the product # documentation would be greatly appreciated (but it is not required). #CC = gcc #RM = rm # Gives a nice speedup, but also spoils debugging on x86. Comment out this # line when debugging. OMIT_FRAME_PTR = -fomit-frame-pointer LUABIN = lua LUAPKG = lua5.2 CFLAGS = `pkg-config $(LUAPKG) --cflags` -fPIC -O3 -Wall $(OMIT_FRAME_PTR) LFLAGS = -shared INSTALL_PATH = `$(LUABIN) -e' \ for dir in package.cpath:gmatch("(/[^?;]+)?") do \ io.write(dir) \ os.exit(0) \ end \ os.exit(1) \ '` ## If your system doesn't have pkg-config or if you do not want to get the ## install path from Lua, comment out the previous lines and uncomment and ## change the following ones according to your building environment. #CFLAGS = -I/usr/local/include/ -fPIC -O3 -Wall $(OMIT_FRAME_PTR) #LFLAGS = -shared #INSTALL_PATH = /usr/local/lib/lua/5.2/ all: iconv.so iconv.lo: luaiconv.c $(CC) -o iconv.lo -c $(CFLAGS) luaiconv.c iconv.so: iconv.lo $(CC) -o iconv.so $(LFLAGS) $(LIBS) iconv.lo install: iconv.so make test install -D -s iconv.so $(DESTDIR)/$(INSTALL_PATH)/iconv.so clean: $(RM) iconv.so iconv.lo test: iconv.so test_iconv.lua lua test_iconv.lua ittner-lua-iconv-466b58d/README000066400000000000000000000112231175163143200161400ustar00rootroot00000000000000Lua-iconv: performs character set conversions in Lua (c) 2005-11 Alexandre Erwin Ittner Project page: http://ittner.github.com/lua-iconv/ === Introduction === Lua-iconv is POSIX 'iconv' binding for the Lua Programming Language. The iconv library converts a sequence of characters from one codeset into a sequence of corresponding characters in another codeset. The codesets are those specified in the iconv.new() call that returned the conversion descriptor, cd. Lua-iconv 7 *requires* Lua 5.1 or Lua 5.2. For Lua 5.0, use the first release (lua-iconv-r1). Details on iconv may be obtained in the Open Group's interface definition (http://www.opengroup.org/onlinepubs/007908799/xsh/iconv.h.html). === Download and installation === Lua-iconv can be obtained from its GitHub project page (https://github.com/ittner/lua-iconv/downloads), from a LuaRocks server or from some Linux distributions which already provide it (eg. Debian). Unless you downloaded a compiled package, you must build the library for your system. If you have LuaRocks installed, all the process is automatic; just fire up your favourite shell and type, as root: luarocks install lua-iconv and the package will be downloaded from a rock server, installed and configured. Otherwise, you must compile and install the package. In a system with pkg-config (as many Linux distributions and Unix flavors) open a shell, untar the distribution package and, within the program directory, type: make install as root. The library will be compiled and installed on the in the correct path (which is defined in lua5.x.pc). Compiling on systems without pkg-config requires manual changes in the Makefile (this includes Windows). === Loading and initialization === Lua-iconv is a shared library that must be loaded in the Lua interpreter before use. You can simply do a local iconv = require("iconv") call to load up the library (that, of course, must be installed in a directory from package.cpath). === API documentation === cd = iconv.new(to, from) cd = iconv.open(to, from) Opens a new conversion descriptor, from the 'from' charset to the 'to' charset. Concatenating "//TRANSLIT" to the first argument will enable character transliteration and concatenating "//IGNORE" to the first argument will cause iconv to ignore any invalid characters found in the input string. This function returns a new converter or nil on error. nstr, err = cd:iconv(str) Converts the 'str' string to the desired charset. This method always returns two arguments: the converted string and an error code, which may have any of the following values: nil No error. Conversion was successful. iconv.ERROR_NO_MEMORY Failed to allocate enough memory in the conversion process. iconv.ERROR_INVALID An invalid character was found in the input sequence. iconv.ERROR_INCOMPLETE An incomplete character was found in the input sequence. iconv.ERROR_FINALIZED Trying to use an already-finalized converter. This usually means that the user was tweaking the garbage collector private methods. iconv.ERROR_UNKNOWN There was an unknown error. === License === Lua-iconv is copyrighted free software: it can be used for both academic and commercial purposes at absolutely no cost. There are no royalties or GNU-like "copyleft" restrictions. The legal details are below: Lua-iconv is (c) 2005-11 Alexandre Erwin Ittner Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHOR OR COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. If you use this package in a product, an acknowledgment in the product documentation would be greatly appreciated (but it is not required). ittner-lua-iconv-466b58d/debian/000077500000000000000000000000001175163143200165035ustar00rootroot00000000000000ittner-lua-iconv-466b58d/debian/changelog000066400000000000000000000015611175163143200203600ustar00rootroot00000000000000lua-iconv (7-1) unstable; urgency=low * Update package for lua-iconv 7 + Lua-5.2 -- Alexandre Erwin Ittner Sun, 06 May 2012 22:35:22 -0300 lua-iconv (6-3) unstable; urgency=low * debian/control: Conflicts, Provides, and Replaces lua-iconv (Closes: #557052) -- Jon Bernard Fri, 20 Nov 2009 18:58:12 -0600 lua-iconv (6-2) unstable; urgency=low * debian/control: update package name to conform to lua standard (Closes: #544958) * debian/control: add Vcs fields * debian/control: update package description * debian/watch: look for new upstream releases on luaforge (Closes: #544960) -- Jon Bernard Wed, 28 Oct 2009 11:58:00 -0400 lua-iconv (6-1) unstable; urgency=low * Initial release (Closes: #540298) -- Jon Bernard Sun, 02 Aug 2009 13:50:50 -0400 ittner-lua-iconv-466b58d/debian/compat000066400000000000000000000000021175163143200177010ustar00rootroot000000000000007 ittner-lua-iconv-466b58d/debian/control000066400000000000000000000014071175163143200201100ustar00rootroot00000000000000Source: lua-iconv Section: interpreters Priority: optional Maintainer: Jon Bernard Build-Depends: debhelper (>= 7), liblua5.2-dev, lua5.2, pkg-config Standards-Version: 3.8.2 Vcs-Git: https://github.com/ittner/lua-iconv.git Vcs-Browser: https://github.com/ittner/lua-iconv.git Homepage: http://ittner.github.com/lua-iconv/ Package: liblua5.2-iconv0 Architecture: any Depends: ${shlibs:Depends}, ${misc:Depends} Recommends: lua5.2 Conflicts: lua-iconv Provides: lua-iconv Replaces: lua-iconv Description: iconv bindings for the Lua programming language This package provides POSIX 'iconv' bindings for the Lua programming language. It converts a sequence of characters from one codeset into a sequence of corresponding characters in another codeset. ittner-lua-iconv-466b58d/debian/copyright000066400000000000000000000032671175163143200204460ustar00rootroot00000000000000This package was debianized by Jon Bernard on Sun, 02 Aug 2009 13:50:50 -0400. It was downloaded from http://luaforge.net/frs/?group_id=131&release_id=1440 Upstream Author: Alexandre Erwin Ittner Copyright: Copyright (C) 2005-09 Alexandre Erwin Ittner License: Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHOR OR COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. If you use this package in a product, an acknowledgment in the product documentation would be greatly appreciated (but it is not required). The Debian packaging is: Copyright (C) 2009 Jon Bernard and is licensed under the GPL version 3, see `/usr/share/common-licenses/GPL-3'. ittner-lua-iconv-466b58d/debian/docs000066400000000000000000000000071175163143200173530ustar00rootroot00000000000000README ittner-lua-iconv-466b58d/debian/examples000066400000000000000000000000171175163143200202420ustar00rootroot00000000000000test_iconv.lua ittner-lua-iconv-466b58d/debian/rules000066400000000000000000000000351175163143200175560ustar00rootroot00000000000000#!/usr/bin/make -f %: dh $@ ittner-lua-iconv-466b58d/fp.utf16.txt000066400000000000000000000010301175163143200173650ustar00rootroot00000000000000ÿþAo longe, ao luar No rio uma vela Serena a passar, Que é que me revela Não sei, mas mue ser Tornou-se-me estranho, E eu sonho sem ver Os sonhos que tenho. Que angústia me enlaça? Que amor não se explica? É a vela que passa Na noite que fica -- Fernando Pessoa ittner-lua-iconv-466b58d/fp.utf32.txt000066400000000000000000000020601175163143200173670ustar00rootroot00000000000000ÿþAo longe, ao luar No rio uma vela Serena a passar, Que é que me revela Não sei, mas mue ser Tornou-se-me estranho, E eu sonho sem ver Os sonhos que tenho. Que angústia me enlaça? Que amor não se explica? É a vela que passa Na noite que fica -- Fernando Pessoa ittner-lua-iconv-466b58d/fp.utf8.txt000066400000000000000000000004211175163143200173110ustar00rootroot00000000000000Ao longe, ao luar No rio uma vela Serena a passar, Que é que me revela Não sei, mas mue ser Tornou-se-me estranho, E eu sonho sem ver Os sonhos que tenho. Que angústia me enlaça? Que amor não se explica? É a vela que passa Na noite que fica -- Fernando Pessoa ittner-lua-iconv-466b58d/lua-iconv-7.rockspec000066400000000000000000000020671175163143200210620ustar00rootroot00000000000000 -- Packs lua-iconv into a LuaRock -- rockspec based uppon the file provided by DarkGod package = "lua-iconv" version = "7" source = { url = "https://github.com/downloads/ittner/lua-iconv/lua-iconv-7.tar.gz", md5 = "8a38b4e6ac8a9290093898793d16fe4b" } description = { summary = "Lua binding to the iconv", detailed = [[ Lua binding to the POSIX 'iconv' library, which converts a sequence of characters from one codeset into a sequence of corresponding characters in another codeset. ]], license = "MIT/X11", homepage = "http://ittner.github.com/lua-iconv/" } dependencies = { "lua >= 5.1", } external_dependencies = { ICONV = { header = "iconv.h" } } build = { type = "builtin", modules = { iconv = { sources = {"luaiconv.c"}, incdirs = {"$(ICONV_INCDIR)"}, libdirs = {"$(ICONV_LIBDIR)"} } }, platforms = { cygwin = { modules = { iconv = { libraries = {"iconv"} } } } } } ittner-lua-iconv-466b58d/lua-iconv-logo.ps000066400000000000000000000113451175163143200204640ustar00rootroot00000000000000%!PS-Adobe-2.0 EPSF-2.0 %%Title: Lua logo %%Creator: lua@tecgraf.puc-rio.br %%CreationDate: Wed Nov 29 19:04:04 EDT 2000 %%BoundingBox: -45 0 1035 1080 %%Pages: 1 %%EndComments %%EndProlog %------------------------------------------------------------------------------ % % Copyright (C) 1998-2000. All rights reserved. % Graphic design by Alexandre Nakonechnyj (nako@openlink.com.br). % PostScript programming by the Lua team (lua@tecgraf.puc-rio.br). % % Permission is hereby granted, without written agreement and without license % or royalty fees, to use, copy, and distribute this logo for any purpose, % including commercial applications, subject to the following conditions: % % * The origin of this logo must not be misrepresented; you must not % claim that you drew the original logo. We recommend that you give credit % to the graphics designer in all printed matter that includes the logo. % % * The only modification you can make is to adapt the orbiting text to % your product name. % % * The logo can be used in any scale as long as the relative proportions % of its elements are maintained. % %------------------------------------------------------------------------------ /LABEL (iconv) def %-- DO NOT CHANGE ANYTHING BELOW THIS LINE ------------------------------------ /PLANETCOLOR {0 0 0.5 setrgbcolor} bind def /HOLECOLOR {1.0 setgray} bind def /ORBITCOLOR {0.5 setgray} bind def /LOGOFONT {/Helvetica 0.90} def /LABELFONT {/Helvetica 0.36} def %------------------------------------------------------------------------------ /MOONCOLOR {PLANETCOLOR} bind def /LOGOCOLOR {HOLECOLOR} bind def /LABELCOLOR {ORBITCOLOR} bind def /LABELANGLE 125 def /LOGO (Lua) def /DASHANGLE 10 def /HALFDASHANGLE DASHANGLE 2 div def % moon radius. planet radius is 1. /r 1 2 sqrt 2 div sub def /D {0 360 arc fill} bind def /F {exch findfont exch scalefont setfont} bind def % place it nicely on the paper /RESOLUTION 1024 def RESOLUTION 2 div dup translate RESOLUTION 2 div 2 sqrt div dup scale %-------------------------------------------------------------------- planet -- PLANETCOLOR 0 0 1 D %---------------------------------------------------------------------- hole -- HOLECOLOR 1 2 r mul sub dup r D %---------------------------------------------------------------------- moon -- MOONCOLOR 1 1 r D %---------------------------------------------------------------------- logo -- LOGOCOLOR LOGOFONT F LOGO stringwidth pop 2 div neg -0.5 moveto LOGO show %------------------------------------------------------------------------------ % based on code from Blue Book Program 10, on pages 167--169 % available at ftp://ftp.adobe.com/pub/adobe/displaypostscript/bluebook.shar % str ptsize centerangle radius outsidecircletext -- /outsidecircletext { circtextdict begin /radius exch def /centerangle exch def /ptsize exch def /str exch def gsave str radius ptsize findhalfangle centerangle add rotate str { /charcode exch def ( ) dup 0 charcode put outsideplacechar } forall grestore end } def % string radius ptsize findhalfangle halfangle /findhalfangle { 4 div add exch stringwidth pop 2 div exch 2 mul 3.1415926535 mul div 360 mul } def /circtextdict 16 dict def circtextdict begin /outsideplacechar { /char exch def /halfangle char radius ptsize findhalfangle def gsave halfangle neg rotate radius 0 translate -90 rotate char stringwidth pop 2 div neg 0 moveto char show grestore halfangle 2 mul neg rotate } def end %--------------------------------------------------------------------- label -- LABELFONT F /LABELSIZE LABELFONT exch pop def /LABELRADIUS LABELSIZE 3 div 1 r add sub neg 1.02 mul def /HALFANGLE LABEL LABELRADIUS LABELSIZE findhalfangle HALFDASHANGLE div ceiling HALFDASHANGLE mul def /LABELANGLE 60 LABELANGLE HALFANGLE sub lt { HALFANGLE HALFANGLE DASHANGLE div floor DASHANGLE mul eq {LABELANGLE DASHANGLE div ceiling DASHANGLE mul} {LABELANGLE HALFDASHANGLE sub DASHANGLE div round DASHANGLE mul HALFDASHANGLE add} ifelse } {HALFANGLE 60 add} ifelse def LABELCOLOR LABEL LABELSIZE LABELANGLE LABELRADIUS outsidecircletext %--------------------------------------------------------------------- orbit -- ORBITCOLOR 0.03 setlinewidth [1 r add 3.1415926535 180 div HALFDASHANGLE mul mul] 0 setdash newpath 0 0 1 r add 3 copy 30 LABELANGLE HALFANGLE add arcn stroke 60 LABELANGLE HALFANGLE sub 2 copy lt {arc stroke} {4 {pop} repeat} ifelse %------------------------------------------------------------------ copyright -- /COPYRIGHT (Graphic design by A. Nakonechnyj. Copyright (c) 1998, All rights reserved.) def LABELCOLOR LOGOFONT 32 div F 2 sqrt 0.99 mul dup neg moveto COPYRIGHT 90 rotate %show %---------------------------------------------------------------------- done -- showpage %%Trailer %%EOF ittner-lua-iconv-466b58d/luaiconv.c000066400000000000000000000155001175163143200172460ustar00rootroot00000000000000/* * luaiconv - Performs character set conversions in Lua * (c) 2005-11 Alexandre Erwin Ittner * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the * "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, * distribute, sublicense, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so, subject to * the following conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN NO EVENT SHALL THE AUTHOR OR COPYRIGHT HOLDER BE LIABLE FOR ANY * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * * If you use this package in a product, an acknowledgment in the product * documentation would be greatly appreciated (but it is not required). * * */ #include #include #include #include #include #define LIB_NAME "iconv" #define LIB_VERSION LIB_NAME " 7" #define ICONV_TYPENAME "iconv_t" #if LUA_VERSION_NUM < 501 #error "Unsuported Lua version. You must use Lua >= 5.1" #endif #if LUA_VERSION_NUM < 502 #define luaL_newlib(L, f) { lua_newtable(L); luaL_register(L, NULL, f); } #define lua_rawlen(L, i) lua_objlen(L, i) #endif #define BOXPTR(L, p) (*(void**)(lua_newuserdata(L, sizeof(void*))) = (p)) #define UNBOXPTR(L, i) (*(void**)(lua_touserdata(L, i))) /* Set a integer constant. Assumes a table in the top of the stack */ #define TBL_SET_INT_CONST(L, c) { \ lua_pushliteral(L, #c); \ lua_pushnumber(L, c); \ lua_settable(L, -3); \ } #define ERROR_NO_MEMORY 1 #define ERROR_INVALID 2 #define ERROR_INCOMPLETE 3 #define ERROR_UNKNOWN 4 #define ERROR_FINALIZED 5 static void push_iconv_t(lua_State *L, iconv_t cd) { BOXPTR(L, cd); luaL_getmetatable(L, ICONV_TYPENAME); lua_setmetatable(L, -2); } static iconv_t get_iconv_t(lua_State *L, int i) { if (luaL_checkudata(L, i, ICONV_TYPENAME) != NULL) { iconv_t cd = UNBOXPTR(L, i); return cd; /* May be NULL. This must be checked by the caller. */ } luaL_argerror(L, i, lua_pushfstring(L, ICONV_TYPENAME " expected, got %s", luaL_typename(L, i))); return NULL; } static int Liconv_open(lua_State *L) { const char *tocode = luaL_checkstring(L, 1); const char *fromcode = luaL_checkstring(L, 2); iconv_t cd = iconv_open(tocode, fromcode); if (cd != (iconv_t)(-1)) push_iconv_t(L, cd); /* ok */ else lua_pushnil(L); /* error */ return 1; } #define CONV_BUF_SIZE 256 static int Liconv(lua_State *L) { iconv_t cd = get_iconv_t(L, 1); size_t ibleft = lua_rawlen(L, 2); char *inbuf = (char*) luaL_checkstring(L, 2); char *outbuf; char *outbufs; size_t obsize = (ibleft > CONV_BUF_SIZE) ? ibleft : CONV_BUF_SIZE; size_t obleft = obsize; size_t ret = -1; int hasone = 0; if (cd == NULL) { lua_pushstring(L, ""); lua_pushnumber(L, ERROR_FINALIZED); return 2; } outbuf = (char*) malloc(obsize * sizeof(char)); if (outbuf == NULL) { lua_pushstring(L, ""); lua_pushnumber(L, ERROR_NO_MEMORY); return 2; } outbufs = outbuf; do { ret = iconv(cd, &inbuf, &ibleft, &outbuf, &obleft); if (ret == (size_t)(-1)) { lua_pushlstring(L, outbufs, obsize - obleft); if (hasone == 1) lua_concat(L, 2); hasone = 1; if (errno == EILSEQ) { lua_pushnumber(L, ERROR_INVALID); free(outbufs); return 2; /* Invalid character sequence */ } else if (errno == EINVAL) { lua_pushnumber(L, ERROR_INCOMPLETE); free(outbufs); return 2; /* Incomplete character sequence */ } else if (errno == E2BIG) { obleft = obsize; outbuf = outbufs; } else { lua_pushnumber(L, ERROR_UNKNOWN); free(outbufs); return 2; /* Unknown error */ } } } while (ret != (size_t) 0); lua_pushlstring(L, outbufs, obsize - obleft); if (hasone == 1) lua_concat(L, 2); free(outbufs); return 1; /* Done */ } #ifdef HAS_ICONVLIST /* a GNU extension? */ static int push_one(unsigned int cnt, char *names[], void *data) { lua_State *L = (lua_State*) data; int n = (int) lua_tonumber(L, -1); int i; /* Stack: n */ lua_remove(L, -1); for (i = 0; i < cnt; i++) { /* Stack> */ lua_pushnumber(L, n++); lua_pushstring(L, names[i]); /* Stack: n */ lua_settable(L, -3); } lua_pushnumber(L, n); /* Stack: n */ return 0; } static int Liconvlist(lua_State *L) { lua_newtable(L); lua_pushnumber(L, 1); /* Stack: 1 */ iconvlist(push_one, (void*) L); /* Stack: n */ lua_remove(L, -1); return 1; } #endif static int Liconv_close(lua_State *L) { iconv_t cd = get_iconv_t(L, 1); if (cd != NULL && iconv_close(cd) == 0) { /* Mark the pointer as freed, preventing interpreter crashes if the user forces __gc to be called twice. */ void **ptr = lua_touserdata(L, 1); *ptr = NULL; lua_pushboolean(L, 1); /* ok */ } else lua_pushnil(L); /* error */ return 1; } static const luaL_Reg iconv_funcs[] = { { "open", Liconv_open }, { "new", Liconv_open }, { "iconv", Liconv }, #ifdef HAS_ICONVLIST { "list", Liconvlist }, #endif { NULL, NULL } }; int luaopen_iconv(lua_State *L) { luaL_newlib(L, iconv_funcs); TBL_SET_INT_CONST(L, ERROR_NO_MEMORY); TBL_SET_INT_CONST(L, ERROR_INVALID); TBL_SET_INT_CONST(L, ERROR_INCOMPLETE); TBL_SET_INT_CONST(L, ERROR_FINALIZED); TBL_SET_INT_CONST(L, ERROR_UNKNOWN); lua_pushliteral(L, "VERSION"); lua_pushstring(L, LIB_VERSION); lua_settable(L, -3); luaL_newmetatable(L, ICONV_TYPENAME); lua_pushliteral(L, "__index"); lua_pushvalue(L, -3); lua_settable(L, -3); lua_pushliteral(L, "__gc"); lua_pushcfunction(L, Liconv_close); lua_settable(L, -3); lua_pop(L, 1); return 1; } ittner-lua-iconv-466b58d/makestr.lua000066400000000000000000000005431175163143200174340ustar00rootroot00000000000000 local fp = assert(io.open(arg[1], "rb")) local str = assert(fp:read("*a")) fp:close() local i local c = 0 local ostr = "local xxxxxxxxxxx = \"" for i = 1, string.len(str) do ostr = ostr .. "\\" .. string.byte(string.sub(str, i, i+1)) if string.len(ostr) > 72 then io.write(ostr .. "\"\n") ostr = ".. \"" end end io.write(ostr .. "\"\n") ittner-lua-iconv-466b58d/maketargz.sh000077500000000000000000000005411175163143200176050ustar00rootroot00000000000000#!/bin/sh PACKAGE=lua-iconv VERSION=7 DIRNAME=$PACKAGE-$VERSION TGZNAME=$DIRNAME.tar.gz rm -f $TGZNAME mkdir $DIRNAME cp -r debian $DIRNAME/ #rm -rf $DIRNAME/debian/.svn cp -r COPYING Makefile README luaiconv.c test_iconv.lua $DIRNAME tar -czf $TGZNAME $DIRNAME #cd $DIRNAME dpkg-buildpackage -rfakeroot #cd .. rm -rf $DIRNAME tar -tzf $TGZNAME ittner-lua-iconv-466b58d/test_iconv.lua000066400000000000000000000140351175163143200201440ustar00rootroot00000000000000local iconv = require("iconv") -- Set your terminal encoding here -- local termcs = "iso-8859-1" local termcs = "utf-8" local iso88591 = "\65\111\32\108\111\110\103\101\44\32\97\111\32\108\117" .. "\97\114\10\78\111\32\114\105\111\32\117\109\97\32\118\101\108\97\10\83" .. "\101\114\101\110\97\32\97\32\112\97\115\115\97\114\44\10\81\117\101\32" .. "\233\32\113\117\101\32\109\101\32\114\101\118\101\108\97\10\10\78\227" .. "\111\32\115\101\105\44\32\109\97\115\32\109\117\101\32\115\101\114\10" .. "\84\111\114\110\111\117\45\115\101\45\109\101\32\101\115\116\114\97\110" .. "\104\111\44\10\69\32\101\117\32\115\111\110\104\111\32\115\101\109\32" .. "\118\101\114\10\79\115\32\115\111\110\104\111\115\32\113\117\101\32\116" .. "\101\110\104\111\46\10\10\81\117\101\32\97\110\103\250\115\116\105\97" .. "\32\109\101\32\101\110\108\97\231\97\63\10\81\117\101\32\97\109\111\114" .. "\32\110\227\111\32\115\101\32\101\120\112\108\105\99\97\63\10\201\32\97" .. "\32\118\101\108\97\32\113\117\101\32\112\97\115\115\97\10\78\97\32\110" .. "\111\105\116\101\32\113\117\101\32\102\105\99\97\10\10\32\32\32\32\45" .. "\45\32\70\101\114\110\97\110\100\111\32\80\101\115\115\111\97\10" local utf8 = "\65\111\32\108\111\110\103\101\44\32\97\111\32\108\117\97\114" .. "\10\78\111\32\114\105\111\32\117\109\97\32\118\101\108\97\10\83\101\114" .. "\101\110\97\32\97\32\112\97\115\115\97\114\44\10\81\117\101\32\195\169\32" .. "\113\117\101\32\109\101\32\114\101\118\101\108\97\10\10\78\195\163\111\32" .. "\115\101\105\44\32\109\97\115\32\109\117\101\32\115\101\114\10\84\111\114" .. "\110\111\117\45\115\101\45\109\101\32\101\115\116\114\97\110\104\111\44" .. "\10\69\32\101\117\32\115\111\110\104\111\32\115\101\109\32\118\101\114\10" .. "\79\115\32\115\111\110\104\111\115\32\113\117\101\32\116\101\110\104\111" .. "\46\10\10\81\117\101\32\97\110\103\195\186\115\116\105\97\32\109\101\32" .. "\101\110\108\97\195\167\97\63\10\81\117\101\32\97\109\111\114\32\110\195" .. "\163\111\32\115\101\32\101\120\112\108\105\99\97\63\10\195\137\32\97\32" .. "\118\101\108\97\32\113\117\101\32\112\97\115\115\97\10\78\97\32\110\111" .. "\105\116\101\32\113\117\101\32\102\105\99\97\10\10\32\32\32\32\45\45\32" .. "\70\101\114\110\97\110\100\111\32\80\101\115\115\111\97\10" local utf16 = "\255\254\65\0\111\0\32\0\108\0\111\0\110\0\103\0\101\0\44\0\32" .. "\0\97\0\111\0\32\0\108\0\117\0\97\0\114\0\10\0\78\0\111\0\32\0\114\0\105" .. "\0\111\0\32\0\117\0\109\0\97\0\32\0\118\0\101\0\108\0\97\0\10\0\83\0\101" .. "\0\114\0\101\0\110\0\97\0\32\0\97\0\32\0\112\0\97\0\115\0\115\0\97\0\114" .. "\0\44\0\10\0\81\0\117\0\101\0\32\0\233\0\32\0\113\0\117\0\101\0\32\0\109" .. "\0\101\0\32\0\114\0\101\0\118\0\101\0\108\0\97\0\10\0\10\0\78\0\227\0\111" .. "\0\32\0\115\0\101\0\105\0\44\0\32\0\109\0\97\0\115\0\32\0\109\0\117\0\101" .. "\0\32\0\115\0\101\0\114\0\10\0\84\0\111\0\114\0\110\0\111\0\117\0\45\0\115" .. "\0\101\0\45\0\109\0\101\0\32\0\101\0\115\0\116\0\114\0\97\0\110\0\104\0" .. "\111\0\44\0\10\0\69\0\32\0\101\0\117\0\32\0\115\0\111\0\110\0\104\0\111" .. "\0\32\0\115\0\101\0\109\0\32\0\118\0\101\0\114\0\10\0\79\0\115\0\32\0\115" .. "\0\111\0\110\0\104\0\111\0\115\0\32\0\113\0\117\0\101\0\32\0\116\0\101\0" .. "\110\0\104\0\111\0\46\0\10\0\10\0\81\0\117\0\101\0\32\0\97\0\110\0\103\0" .. "\250\0\115\0\116\0\105\0\97\0\32\0\109\0\101\0\32\0\101\0\110\0\108\0\97" .. "\0\231\0\97\0\63\0\10\0\81\0\117\0\101\0\32\0\97\0\109\0\111\0\114\0\32" .. "\0\110\0\227\0\111\0\32\0\115\0\101\0\32\0\101\0\120\0\112\0\108\0\105\0" .. "\99\0\97\0\63\0\10\0\201\0\32\0\97\0\32\0\118\0\101\0\108\0\97\0\32\0\113" .. "\0\117\0\101\0\32\0\112\0\97\0\115\0\115\0\97\0\10\0\78\0\97\0\32\0\110" .. "\0\111\0\105\0\116\0\101\0\32\0\113\0\117\0\101\0\32\0\102\0\105\0\99\0" .. "\97\0\10\0\10\0\32\0\32\0\32\0\32\0\45\0\45\0\32\0\70\0\101\0\114\0\110" .. "\0\97\0\110\0\100\0\111\0\32\0\80\0\101\0\115\0\115\0\111\0\97\0\10\0" -- Bizarre EBCDIC-CP-ES encoding. local ebcdic = "\193\150\64\147\150\149\135\133\107\64\129\150\64\147\164\129" .. "\153\37\213\150\64\153\137\150\64\164\148\129\64\165\133\147\129\37\226" .. "\133\153\133\149\129\64\129\64\151\129\162\162\129\153\107\37\216\164\133" .. "\64\81\64\152\164\133\64\148\133\64\153\133\165\133\147\129\37\37\213\70" .. "\150\64\162\133\137\107\64\148\129\162\64\148\164\133\64\162\133\153\37" .. "\227\150\153\149\150\164\96\162\133\96\148\133\64\133\162\163\153\129\149" .. "\136\150\107\37\197\64\133\164\64\162\150\149\136\150\64\162\133\148\64" .. "\165\133\153\37\214\162\64\162\150\149\136\150\162\64\152\164\133\64\163" .. "\133\149\136\150\75\37\37\216\164\133\64\129\149\135\222\162\163\137\129" .. "\64\148\133\64\133\149\147\129\72\129\111\37\216\164\133\64\129\148\150" .. "\153\64\149\70\150\64\162\133\64\133\167\151\147\137\131\129\111\37\113" .. "\64\129\64\165\133\147\129\64\152\164\133\64\151\129\162\162\129\37\213" .. "\129\64\149\150\137\163\133\64\152\164\133\64\134\137\131\129\37\37\64\64" .. "\64\64\96\96\64\198\133\153\149\129\149\132\150\64\215\133\162\162\150\129" .. "\37" function check_one(to, from, text) print("\n-- Testing conversion from " .. from .. " to " .. to) local cd = iconv.new(to .. "//TRANSLIT", from) assert(cd, "Failed to create a converter object.") local ostr, err = cd:iconv(text) if err == iconv.ERROR_INCOMPLETE then print("ERROR: Incomplete input.") elseif err == iconv.ERROR_INVALID then print("ERROR: Invalid input.") elseif err == iconv.ERROR_NO_MEMORY then print("ERROR: Failed to allocate memory.") elseif err == iconv.ERROR_UNKNOWN then print("ERROR: There was an unknown error.") end print(ostr) end check_one(termcs, "iso-8859-1", iso88591) check_one(termcs, "utf8", utf8) check_one(termcs, "utf16", utf16) check_one(termcs, "EBCDIC-CP-ES", ebcdic) -- The library must never crash the interpreter, even if the user tweaks -- with the garbage collector methods. local cd = iconv.new("iso-8859-1", "utf-8") local _, e = cd:iconv("atenção") assert(e == nil, "Unexpected conversion error") local gc = getmetatable(cd).__gc gc(cd) local _, e = cd:iconv("atenção") assert(e == iconv.ERROR_FINALIZED, "Failed to detect double-freed objects") gc(cd) ittner-lua-iconv-466b58d/uniopen.lua000066400000000000000000000014421175163143200174420ustar00rootroot00000000000000 -- Simple (and incomplete) Unicode I/O layer. local iconv = require("iconv") local m = { } local mti = { } local mt = { __index = mti } function m.open(fname, mode, tocharset, fromcharset) assert(mode == "r" or mode == "rb", "Only read modes are supported yet") local cd = assert(iconv.new(tocharset, fromcharset), "Bad charset") local fp = io.open(fname, mode) if not fp then return nil end local o = { fp = fp, cd = cd } setmetatable(o, mt) return o; end function mti.read(fp, mod) assert(fp and fp.fp and fp.cd, "Bad file descriptor") local ret = fp.fp:read(mod) if ret then return fp.cd:iconv(ret) -- returns: string, error code else return nil end end function mti.close(fp) assert(fp and fp.fp, "Bad file descriptor") fp.fp:close() end return m