[mw-devel] MW3 r1100 - trunk/src
psycodom at sucs.org
psycodom at sucs.org
Thu Nov 12 09:11:12 GMT 2009
Author: psycodom
Date: 2009-11-12 09:11:12 +0000 (Thu, 12 Nov 2009)
New Revision: 1100
Modified:
trunk/src/iconv.c
trunk/src/iconv.h
Log:
Deleted loads of obsolete unused code from iconv
Modified: trunk/src/iconv.c
===================================================================
--- trunk/src/iconv.c 2009-11-10 14:21:34 UTC (rev 1099)
+++ trunk/src/iconv.c 2009-11-12 09:11:12 UTC (rev 1100)
@@ -268,164 +268,13 @@
return conversion_result;
}
-
-/* convert string in given encoding to wide string */
-wchar_t * any2wcs(char * s, char * charset, int report_error)
-{
- char * local, * localcpy;
- char * wcs; /* needs to be char * for passing to iconv */
- wchar_t * wcscpy; /* the string as itself */
- size_t localbytesleft, wcsbytesleft;
- iconv_t conv;
- int errors = 0;
-
- if (!charset || !*charset) {
- fprintf(stderr, "any2wcs: No source character set specified!\n");
- return NULL;
- }
-
- conv = iconv_open("WCHAR_T", charset);
- if (conv == (iconv_t)-1) {
- if (errno == EINVAL)
- fprintf(stderr, "Conversion not supported\n");
- else perror("iconv");
- errno = 0;
- return NULL;
- }
-
- local = localcpy = strdup(s);
- localbytesleft = strlen(local) + 1;
- wcsbytesleft = localbytesleft * sizeof(wchar_t);
- wcscpy = malloc(wcsbytesleft);
- wcs = (char *)wcscpy;
- /* end of init code */
-
- while (localbytesleft > 0) {
- int nconv = iconv(conv,
- &local, &localbytesleft,
- &wcs, &wcsbytesleft);
- if (nconv == (size_t)-1) {
- /* iconv barfed, but why? */
- if (errno == EILSEQ || errno == EINVAL) {
- /* invalid input sequence, skip it */
- local++;
- localbytesleft--;
- errno = 0;
- errors++;
- continue;
- } else {
- /* some other error, recover what we can */
- *(wchar_t *)wcs = L'\0';
- perror("iconv");
- errno = 0;
- break;
- }
- }
- }
-
- iconv_close(conv);
- free(localcpy);
- if (report_error && errors>0)
- printf("warning: iconv found %d invalid bytes, discarding them\n", errors);
- return wcscpy;
-}
-
-/* convert wide string to string in given encoding */
-char *
-wcs2any(wchar_t * ws, char * charset, int report_error)
-{
- char * wcs; /* needs to be char * for passing to iconv */
- wchar_t * wcscpy; /* the string as itself */
- char * local, * localcpy;
- size_t localbytesleft, wcsbytesleft;
- iconv_t conv;
- int errors = 0;
-
- if (!charset || !*charset) {
- fprintf(stderr, "No target character set specified!\n");
- return NULL;
- }
-
- conv = iconv_open(charset, "WCHAR_T");
- if (conv == (iconv_t)-1) {
- if (errno == EINVAL)
- fprintf(stderr, "Conversion not supported\n");
- else perror("iconv");
- errno = 0;
- return NULL;
- }
-
- wcscpy = wcsdup(ws);
- wcs = (char *)wcscpy;
- localbytesleft = wcsbytesleft = (wcslen(ws) + 1) * sizeof(wchar_t);
- local = localcpy = malloc(localbytesleft);
- /* end of init code */
-
- while (wcsbytesleft > 0) {
- int nconv = iconv(conv,
- &wcs, &wcsbytesleft,
- &local, &localbytesleft);
- if (nconv == (size_t)-1) {
- /* iconv barfed, but why? */
- if (errno == EILSEQ || errno == EINVAL) {
- /* invalid or unconvertible input sequence, skip it */
- wcs+=sizeof(wchar_t);
- wcsbytesleft-=sizeof(wchar_t);
- errno = 0;
- errors++;
- continue;
- } else {
- /* some other error, recover what we can */
- *local = '\0';
- perror("iconv");
- errno = 0;
- break;
- }
- }
- }
-
- iconv_close(conv);
- free(wcscpy);
- if (report_error && errors>0)
- printf("warning: iconv found %d invalid bytes, discarding them\n", errors);
- return localcpy;
-}
-
-/* convert string in local encoding to wide string */
-wchar_t *
-local2wcs(char * s, int report_error)
-{
- return any2wcs(s, local_charset, report_error);
-}
-
-/* convert wide string to local encoding */
-char *
-wcs2local(wchar_t * ws, int report_error)
-{
- return wcs2any(ws, local_charset, report_error);
-}
-
-/* convert UTF-8 encoded string to wide string */
-wchar_t *
-utf82wcs(char * s, int report_error)
-{
- return any2wcs(s, "UTF-8", report_error);
-}
-
-/* convert wide string to UTF-8 encoded string */
-char *
-wcs2utf8(wchar_t * ws, int report_error)
-{
- return wcs2any(ws, "UTF-8", report_error);
-}
-
/* set local charset independently of locale */
int set_local_charset(char * set)
{
iconv_t conv;
/* check whether our environment supports this charset */
- conv = iconv_open("WCHAR_T", set);
+ conv = iconv_open("UTF-8", set);
if (conv == (iconv_t)-1) {
return 0;
} else {
@@ -503,7 +352,7 @@
exit(1);
} else {
/* check this environment supports UTF-8 */
- iconv_t conv = iconv_open("WCHAR_T", "UTF-8");
+ iconv_t conv = iconv_open("ASCII", "UTF-8");
if (conv == (iconv_t)-1) {
fprintf(stderr, "This environment doesn't seem to support UTF-8. Milliways requires UTF-8 support to work.\n");
exit(1);
@@ -511,37 +360,3 @@
iconv_close(conv);
}
}
-
-#ifdef TEST_ICONV
-void
-usage()
-{
- fprintf(stderr, "Usage: wchar sourcecharset targetcharset\n");
- exit(1);
-}
-
-int
-main(int argc, char ** argv)
-{
- char * in;
- wchar_t * mid;
- char * out;
-
- if (argc < 3) usage();
-
- init_locale();
- in = readline("Enter something to convert: ");
- set_local_charset(argv[1]);
-
- mid = local2wcs(in, 1);
- printf("Converted to wchar_t as %ls\n", mid);
-
- free(readline("Change terminal locale and press enter to continue"));
-
- set_local_charset(argv[2]);
- out = wcs2local(mid, 1);
- printf("Converted to target charset as %s\n", out);
-
- return 0;
-}
-#endif /* TEST_ICONV */
Modified: trunk/src/iconv.h
===================================================================
--- trunk/src/iconv.h 2009-11-10 14:21:34 UTC (rev 1099)
+++ trunk/src/iconv.h 2009-11-12 09:11:12 UTC (rev 1100)
@@ -7,24 +7,6 @@
int utf8_cleanup(char *buff);
-/* convert string in given encoding to wide string */
-//wchar_t * any2wcs(char * s, char * charset);
-
-/* convert wide string to string in given encoding */
-//char * wcs2any(wchar_t * ws, char * charset);
-
-/* convert string in local encoding to wide string */
-// wchar_t * local2wcs(char * s);
-
-/* convert wide string to local encoding */
-// char * wcs2local(wchar_t * ws);
-
-/* convert UTF-8 encoded string to wide string */
-//wchar_t * utf82wcs(char * s);
-
-/* convert wide string to UTF-8 encoded string */
-//char * wcs2utf8(wchar_t * ws);
-
/* set local charset independently of locale */
int set_local_charset(char * set);
More information about the mw-devel
mailing list