First draft of chartran functions

This commit is contained in:
Michiel Broek 2007-02-20 22:11:36 +00:00
parent c142fa2c40
commit 789058e28f
3 changed files with 79 additions and 50 deletions

View File

@ -6,6 +6,9 @@ v0.91.5 18-Feb-2007
WARNING: do not configure with --enable-experiment this will break!
You own the pieces and the troubles, you have been warned.
Even BETTER: Do not use at all, currently there is unfinished code
and some things don't work right now.
FSP-1030 Unicode character set in FidoNet messages.

View File

@ -265,7 +265,7 @@ int chartran_init(char *fromset, char *toset)
if (strcmp(fromset, (char *)"UTF-8")) {
cd1 = iconv_open("UTF-8", fromset);
if (cd1 != (iconv_t)-1) {
if (cd1 == (iconv_t)-1) {
WriteError("$chartran_init(%s, %s): iconv_open(UTF-8, %s) error", fromset, toset, fromset);
return -1;
}
@ -313,12 +313,76 @@ void chartran_close(void)
char *chartran(char *input)
{
static char outbuf[1024];
static char temp[4096];
size_t rc, inSize, outSize;
char *in, *out;
memset(&outbuf, 0, sizeof(outbuf));
strncat(outbuf, input, sizeof(outbuf) -1);
/*
* Transparant
*/
if (!use_tran1 && !use_tran2) {
strncpy(outbuf, input, sizeof(outbuf) -1);
return outbuf;
}
/*
* Translate to UTF-8
*/
if (use_tran1 && !use_tran2) {
inSize = strlen(input);
outSize = sizeof(outbuf);
in = input;
out = outbuf;
rc = iconv(cd1, &in, &inSize, &out, &outSize);
if (rc == -1) {
WriteError("$iconv(%s) cd1", printable(input, 0));
strncpy(outbuf, input, sizeof(outbuf) -1);
}
return outbuf;
}
/*
* Translate from UTF-8
*/
if (!use_tran1 && use_tran2) {
inSize = strlen(input);
outSize = sizeof(outbuf);
in = input;
out = outbuf;
rc = iconv(cd2, &in, &inSize, &out, &outSize);
if (rc == -1) {
WriteError("$iconv(%s) cd2", printable(input, 0));
strncpy(outbuf, input, sizeof(outbuf) -1);
}
return outbuf;
}
/*
* Double translation via UTF-8
*/
inSize = strlen(input);
outSize = sizeof(temp);
in = input;
out = temp;
rc = iconv(cd1, &in, &inSize, &out, &outSize);
if (rc == -1) {
WriteError("$iconv(%s) cd1", printable(input, 0));
strncpy(outbuf, input, sizeof(outbuf) -1);
return outbuf;
}
inSize = strlen(temp);
outSize = sizeof(outbuf);
in = temp;
out = outbuf;
rc = iconv(cd2, &in, &inSize, &out, &outSize);
if (rc == -1) {
WriteError("$iconv(%s) cd2", printable(temp, 0));
strncpy(outbuf, input, sizeof(outbuf) -1);
}
return outbuf;
}

View File

@ -43,8 +43,6 @@
unsigned int article = 0L; /* Current article */
char currentgroup[81]; /* Current newsgroup */
int use_iconv; /* Use iconv translation */
iconv_t iconv_s; /* Struct for iconv */
extern unsigned int sentbytes;
@ -64,30 +62,14 @@ void send_xlat(char *);
void send_xlat(char *inp)
{
char temp[1024];
size_t rc, inSize, outSize;
if (use_iconv) {
inSize = strlen(inp);
outSize = sizeof(temp);
char* in = inp;
char* out = temp;
memset(&temp, 0, sizeof(temp));
rc = iconv(iconv_s, &in, &inSize, &out, &outSize);
if (rc == -1) {
WriteError("$iconv(%s)", printable(inp, 0));
strncpy(temp, inp, 1023);
}
if (strcmp(inp, temp))
Syslog('n', "i \"%s\"", printable(inp, 0));
Syslog('n', "> \"%s\"", printable(temp, 0));
PUTSTR(temp);
} else {
Syslog('n', "> \"%s\"", printable(inp, 0));
PUTSTR(inp);
}
memset(&temp, 0, sizeof(temp));
strncat(temp, chartran(inp), sizeof(temp) -1);
if (strcmp(inp, temp))
Syslog('n', "i \"%s\"", printable(inp, 0));
Syslog('n', "> \"%s\"", printable(temp, 0));
PUTSTR(temp);
PUTSTR((char *)"\r\n");
FLUSHOUT();
@ -126,7 +108,6 @@ void command_abhs(char *buf)
Syslog('+', "%s", buf);
cmd = strtok(buf, " \0");
opt = strtok(NULL, " \0");
use_iconv = FALSE;
IsDoing("Retrieve");
@ -217,16 +198,7 @@ void command_abhs(char *buf)
charindex = find_ftn_charset(charset);
if (charindex != FTNC_ERROR) {
Syslog('n', "iconv_open(UTF-8, %s)", charmap[charindex].ic_ftn);
// Syslog('n', "iconv_open(%s, %s)", charmap[charindex].ic_rfc, charmap[charindex].ic_ftn);
// Syslog('n', "setlocale() result %s", MBSE_SS(setlocale(LC_CTYPE, charmap[charindex].lang)));
iconv_s = iconv_open("UTF-8", charmap[charindex].ic_ftn);
// iconv_s = iconv_open(charmap[charindex].ic_rfc, charmap[charindex].ic_ftn);
if (iconv_s != (iconv_t)-1) {
use_iconv = TRUE;
} else {
WriteError("$iconv_open(UTF-8, %s)", charmap[charindex].ic_ftn);
}
chartran_init(charmap[charindex].ic_ftn, (char *)"UTF-8");
}
if ((strcasecmp(cmd, "ARTICLE") == 0) || (strcasecmp(cmd, "HEAD") == 0)) {
@ -250,12 +222,6 @@ void command_abhs(char *buf)
* 4. Default us-ascii.
*/
send_nntp("MIME-Version: 1.0");
// if (charindex != FTNC_ERROR) {
// send_nntp("Content-Type: text/plain; charset=%s", getrfcchrs(charindex));
// } else {
// send_nntp("Content-Type: text/plain; charset=us-ascii; format=fixed");
// }
// send_nntp("Content-Transfer-Encoding: 8bit");
send_nntp("Content-Type: text/plain; charset=utf-8");
send_nntp("X-FTN-From: %s <%s>", Msg.From, Msg.FromAddress);
@ -298,16 +264,12 @@ void command_abhs(char *buf)
}
}
send_nntp(".");
chartran_close();
return;
} else {
send_nntp("503 Could not retrieve message");
return;
}
if (use_iconv) {
iconv_close(iconv_s);
use_iconv = FALSE;
}
}