From 593042c06a0aee709ce945d01df42fb5a135c055 Mon Sep 17 00:00:00 2001 From: Andrew Pamment Date: Fri, 31 Mar 2017 07:39:04 +1000 Subject: [PATCH] attempt to use libiconv to convert cp437 to utf8 --- Makefile.freebsd.WWW | 2 +- Makefile.linux.WWW | 2 +- Makefile.netbsd.WWW | 2 +- Makefile.osx.WWW | 2 +- www_msgs.c | 16 ++++++++++++---- 5 files changed, 16 insertions(+), 8 deletions(-) diff --git a/Makefile.freebsd.WWW b/Makefile.freebsd.WWW index ed0409d..ec57509 100644 --- a/Makefile.freebsd.WWW +++ b/Makefile.freebsd.WWW @@ -5,7 +5,7 @@ JAMLIB = deps/jamlib/jamlib.a ZMODEM = deps/Xmodem/libzmodem.a LUA = deps/lua/liblua.a B64 = deps/libb64-1.2/src/libb64.a -MICROHTTPD=-lmicrohttpd +MICROHTTPD=-lmicrohttpd -liconv ODOORS = deps/odoors/libs-`uname -s`/libODoors.a JSMN = deps/jsmn/libjsmn.a CDK = deps/cdk-5-20161210/libcdk.a diff --git a/Makefile.linux.WWW b/Makefile.linux.WWW index fe2ade6..40edcbb 100644 --- a/Makefile.linux.WWW +++ b/Makefile.linux.WWW @@ -5,7 +5,7 @@ JAMLIB = deps/jamlib/jamlib.a ZMODEM = deps/Xmodem/libzmodem.a LUA = deps/lua/liblua.a B64 = deps/libb64-1.2/src/libb64.a -MICROHTTPD=-lmicrohttpd +MICROHTTPD=-lmicrohttpd -liconv ODOORS = deps/odoors/libs-`uname -s`/libODoors.a JSMN = deps/jsmn/libjsmn.a CDK = deps/cdk-5-20161210/libcdk.a diff --git a/Makefile.netbsd.WWW b/Makefile.netbsd.WWW index 82b9a7f..639ef8d 100644 --- a/Makefile.netbsd.WWW +++ b/Makefile.netbsd.WWW @@ -5,7 +5,7 @@ JAMLIB = deps/jamlib/jamlib.a ZMODEM = deps/Xmodem/libzmodem.a LUA = deps/lua/liblua.a B64 = deps/libb64-1.2/src/libb64.a -MICROHTTPD=-lmicrohttpd +MICROHTTPD=-lmicrohttpd -liconv ODOORS = deps/odoors/libs-`uname -s`/libODoors.a JSMN = deps/jsmn/libjsmn.a CDK = deps/cdk-5-20161210/libcdk.a diff --git a/Makefile.osx.WWW b/Makefile.osx.WWW index 94e2924..296907f 100644 --- a/Makefile.osx.WWW +++ b/Makefile.osx.WWW @@ -5,7 +5,7 @@ JAMLIB = deps/jamlib/jamlib.a ZMODEM = deps/Xmodem/libzmodem.a LUA = deps/lua/liblua.a B64 = deps/libb64-1.2/src/libb64.a -MICROHTTPD=-lmicrohttpd +MICROHTTPD=-lmicrohttpd -liconv ODOORS = deps/odoors/libs-`uname -s`/libODoors.a JSMN = deps/jsmn/libjsmn.a CDK = deps/cdk-5-20161210/libcdk.a diff --git a/www_msgs.c b/www_msgs.c index d44cc8d..a9682c0 100644 --- a/www_msgs.c +++ b/www_msgs.c @@ -7,6 +7,7 @@ #ifdef __FreeBSD__ #include #endif +#include #include "bbs.h" #include "jamlib/jam.h" @@ -269,9 +270,10 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i char buffer[4096]; int chars; int i; - + iconv_t ic; char *aha_text; char *aha_out; + char *aha_cp437; if (conference < 0 || conference >= conf.mail_conference_count || area < 0 || area >= conf.mail_conferences[conference]->mail_area_count) { return NULL; @@ -465,10 +467,16 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i len += strlen(buffer); - aha_text = (char *)malloc(jmh.TxtLen + 1); - memcpy(aha_text, body, jmh.TxtLen); - aha_text[jmh.TxtLen] = '\0'; + aha_text = (char *)malloc(jmh.TxtLen + 1); + aha_cp437 = (char *)malloc(jmh.TxtLen + 1); + memcpy(aha_cp437, body, jmh.TxtLen); + aha_cp437[jmh.TxtLen] = '\0'; + + + ic = iconv_open("UTF-8//TRANSLIT", "CP437"); + iconv(ic, &aha_cp437, jmh.TxtLen, &aha_text, jmh.TxtLen); + iconv_close(ic); aha_out = aha(aha_text); while (len + strlen(aha_out) > max_len - 1) { max_len += 4096;