/* $Id$ * $URL$ * * iconv charset conversion plugin * * Copyright (C) 2006 Ernst Bachmann * Copyright (C) 2006 The LCD4Linux Team * * This file is part of LCD4Linux. * * LCD4Linux is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * LCD4Linux is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * */ /* * exported functions: * * int plugin_init_iconv (void) * int plugin_exit_iconv (void) * */ #include "config.h" #include #include #include #include #include /* these should always be included */ #include "debug.h" #include "plugin.h" #ifdef WITH_DMALLOC #include #endif /* iconv function, convert charsets */ /* valid "to" and "from" charsets can be listed by running "iconv --list" from a shell */ /* utf16 & utf32 encodings won't work, as they contain null bytes, confusing strlen */ static void my_iconv(RESULT * result, RESULT * charset_from, RESULT * charset_to, RESULT * arg) { char *source; size_t source_left; char *dest; char *dest_pos; size_t dest_left; iconv_t cd; source = R2S(arg); source_left = strlen(source); /* use twice the memory needed in best case, but save lots of reallocs in worst case */ /* increase to 4 if most conversions are to utf32 (quite unlikely) */ /* also alloc a "safety byte" so we can always zero-terminate the string. */ dest_left = 2 * source_left; dest = malloc(dest_left + 1); dest_pos = dest; cd = iconv_open(R2S(charset_to), R2S(charset_from)); if (cd != (iconv_t) (-1)) { do { /* quite spammy: debug("plugin_iconv: calling iconv with %ld,[%s]/%ld,%ld", cd, source, source_left, dest_left); */ if (iconv(cd, &source, &source_left, &dest_pos, &dest_left) == (size_t) (-1)) { switch (errno) { case EILSEQ: /* illegal bytes in input sequence */ /* try to fix by skipping a byte */ info("plugin_iconv: illegal character in input string: %c", *source); source_left--; source++; break; case EINVAL: /* input string ends during a multibyte sequence */ /* try to fix by simply ignoring */ info("plugin_iconv: illegal character at end of input"); source_left = 0; break; case E2BIG: /* not enough bytes in outbuf. */ /* TODO: Realloc output buffer, probably doubling its size? */ /* for now, just bail out. For lcd4linux 99% of all conversions will go to ascii or latin1 anyways */ error ("plugin_iconv: out of memory in destination buffer. Seems like Ernst was too lazy, complain to him!"); source_left = 0; break; default: error("plugin_iconv: strange errno state (%d) occured", errno); source_left = 0; } } } while (source_left > 0); /* don't check for == 0, could be negative in EILSEQ case */ /* terminate the string, we're sure to have that byte left, see above */ *dest_pos = 0; dest_pos++; iconv_close(cd); } else { error("plugin_iconv: could not open conversion descriptor. Check if your charsets are supported!"); /* guaranteed to fit. */ strcpy(dest, source); } SetResult(&result, R_STRING, dest); free(dest); } /* plugin initialization */ int plugin_init_iconv(void) { AddFunction("iconv", 3, my_iconv); return 0; } void plugin_exit_iconv(void) { /* nothing to clean */ } .highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */ .highlight .cpf { color: #888888 } /* Comment.PreprocFile */ .highlight .c1 { color: #888888 } /* Comment.Single */ .highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */ .highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */ .highlight .ge { font-style: italic } /* Generic.Emph */ .highlight .gr { color: #aa0000 } /* Generic.Error */ .highlight .gh { color: #333333 } /* Generic.Heading */ .highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */ .highlight .go { color: #888888 } /* Generic.Output */ .highlight .gp { color: #555555 } /* Generic.Prompt */ .highlight .gs { font-weight: bold } /* Generic.Strong */ .highlight .gu { color: #666666 } /* Generic.Subheading */ .highlight .gt { color: #aa0000 } /* Generic.Traceback */ .highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */ .highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */ .highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */ .highlight .kp { color: #008800 } /* Keyword.Pseudo */ .highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */ .highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */ .highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */ .highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */ .highlight .na { color: #336699 } /* Name.Attribute */ .highlight .nb { color: #003388 } /* Name.Builtin */ .highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */ .highlight .no { color: #003366; font-weight: bold } /* Name.Constant */ .highlight .nd { color: #555555 } /* Name.Decorator */ .highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */ .highlight .nl { color: #336699; font-style: italic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
# KDE Config File
[KDE Desktop Entry]
Comment[C]=LCD4Linux
SwallowExec=lcd4linux -f /etc/lcd4kde.conf
SwallowTitle=XLCD4Linux
BinaryPattern=
Name=LCD4Linux
Name[C]=LCD4Linux
MimeType=
Comment=LCD4Linux
Exec=lcd4linux -f /etc/lcd4X11.conf
Icon=lcd4linux.xpm
Type=Application
Terminal=0