* General Public License for more details.
*/
-#include <stdio.h>
#include <string.h>
-#include <errno.h>
-
-#if ENABLE_NLS
-#include <iconv.h>
-#endif
-
#include "text.h"
/*---------------------------------------------------------------------------*/
-#define MAXSTR 256
-
-/*---------------------------------------------------------------------------*/
-
-#if ENABLE_NLS
-static iconv_t conv_from_locale = 0;
-static iconv_t conv_to_locale = 0;
-#endif
-
-void text_init(void)
-{
-#if ENABLE_NLS
- if ((conv_from_locale = iconv_open("UTF-8", "")) == (iconv_t) -1)
- fprintf(stderr, "Error: %s\n", strerror(errno));
-
- if ((conv_to_locale = iconv_open("", "UTF-8")) == (iconv_t) -1)
- fprintf(stderr, "Error: %s\n", strerror(errno));
-#else
- return;
-#endif
-}
-
-void text_quit(void)
-{
-#if ENABLE_NLS
- if (conv_from_locale != (iconv_t) -1)
- iconv_close(conv_from_locale);
-
- if (conv_to_locale != (iconv_t) -1)
- iconv_close(conv_to_locale);
-#else
- return;
-#endif
-}
-
-/*---------------------------------------------------------------------------*/
-
-char *text_from_locale(char *str0)
-{
-#if ENABLE_NLS
- static char buffer[MAXSTR * 2];
-
- char *str0p = str0;
- char *str1p = buffer;
-
- size_t l0 = strlen(str0);
- size_t l1 = sizeof (buffer);
-
- if (conv_from_locale == (iconv_t) -1)
- return str0;
-
- if (iconv(conv_from_locale, &str0p, &l0, &str1p, &l1) == (size_t) -1)
- fprintf(stderr, "Error while converting to UTF-8: %s\n",
- strerror(errno));
-
- *str1p = '\0';
-
- return buffer;
-#else
- return str0;
-#endif
-}
-
-char *text_to_locale(char *str0)
-{
-#if ENABLE_NLS
- static char buffer[MAXSTR * 2];
-
- char *str0p = str0;
- char *str1p = buffer;
-
- size_t l0 = strlen(str0);
- size_t l1 = sizeof (buffer);
-
- if (conv_to_locale == (iconv_t) -1)
- return str0;
-
- if (iconv(conv_to_locale, &str0p, &l0, &str1p, &l1) == (size_t) -1)
- fprintf(stderr, "Error while converting from UTF-8: %s\n",
- strerror(errno));
-
- *str1p = '\0';
-
- return buffer;
-#else
- return str0;
-#endif
-}
-
-/*---------------------------------------------------------------------------*/
-
-int text_add_char(Uint32 unicode, char *string, int maxbytes, int maxchars)
+int text_add_char(Uint32 unicode, char *string, int maxbytes)
{
size_t pos = strlen(string);
int l;
else if (unicode < 0x10000) l = 3;
else l = 4;
- if ((pos + l >= maxbytes) || (text_length(string) + 1 >= maxchars))
+ if (pos + l >= maxbytes)
return 0;
if (unicode < 0x80)
int text_del_char(char *string)
{
- size_t pos = strlen(string) - 1;
+ int pos = (int) strlen(string) - 1;
while (pos >= 0 && ((string[pos] & 0xC0) == 0x80))
string[pos--] = 0;