From f9e170dd72c69b18eb6fa1e822f0ada93b6db28a Mon Sep 17 00:00:00 2001 From: Michiel Broek Date: Sun, 3 Apr 2005 14:12:12 +0000 Subject: [PATCH] More Chinese characters support --- ChangeLog | 7 +++++++ lib/charset.c | 32 ++++++++++++++++++++++++++++++++ lib/mbselib.h | 3 +++ mbsebbs/change.c | 2 ++ mbsebbs/mbsebbs.c | 4 +--- mbsebbs/msgutil.c | 7 ++++++- mbsebbs/user.c | 4 ++++ 7 files changed, 55 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3e3b099b..b250d2e3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -19,6 +19,13 @@ v0.71.2 16-Jan-2005 that host aka's (node /0) were not presented to the remote. (thanks Przemyslaw Kwiatkowski). + mbsebbs: + When a message is posted by a user, the CHRS kludge of the user + is used in the message, not the area setting. + When a user logs in, the users locale (guessed value from his + characterset) is set. Experimental to see if libc functions will + support Chinese characters. + mbfido: Empty *.msg netmails for our own system are dropped with and logged (just like received empty netmails). Empty netmails to diff --git a/lib/charset.c b/lib/charset.c index b026136c..7439a670 100644 --- a/lib/charset.c +++ b/lib/charset.c @@ -127,6 +127,38 @@ char *getchrs(int val) } + +/* + * Experimental table that should translate from the user selected + * charset to a locale. This is not the right way to do, the best + * thing is to store each bbs users locale instead and then lookup + * his characterset using standard library calls. + * + * This is one of the things the bbs world never saw coming, in the + * "good" old days bbses were almost allways called local. Thanks + * to the internet bbs users are now all over the world. + */ +char *getlocale(int val) +{ + switch (val) { + case FTNC_NONE: return (char *)"C"; + case FTNC_CP437: return (char *)"en_US"; + case FTNC_CP850: return (char *)"en_US"; + case FTNC_CP865: return (char *)"sv_SE"; + case FTNC_CP866: return (char *)"ru_RU"; + case FTNC_CP852: return (char *)"cs_CZ"; + case FTNC_CP895: return (char *)"cs_CZ"; + case FTNC_LATIN_1: return (char *)"en_US"; + case FTNC_LATIN_2: return (char *)"cs_CZ"; + case FTNC_MAC: return (char *)"en_US"; + case FTNC_KOI8_R: return (char *)"ru_RU.koi8r"; + case FTNC_CP936: return (char *)"zh_CN.gbk"; + default: return (char *)"C"; + } +} + + + char *getchrsdesc(int val) { switch (val) { diff --git a/lib/mbselib.h b/lib/mbselib.h index 0611d1b5..eb7cd5b4 100644 --- a/lib/mbselib.h +++ b/lib/mbselib.h @@ -93,6 +93,8 @@ #if !defined(__ppc__) #include #endif +#include +#include /* used to use #elif, but native braindead hpux 9.00 c compiler didn't * * understand it */ @@ -2538,6 +2540,7 @@ typedef struct st_charset_table { char *getchrs(int); /* Return characterset name */ +char *getlocale(int); /* Return locale name */ char *getchrsdesc(int); /* Return characterset description */ CharsetTable *charset_table_new(void); /* Add table to linked list */ CharsetAlias *charset_alias_new(void); /* Add alias to linked list */ diff --git a/mbsebbs/change.c b/mbsebbs/change.c index 815895f0..71d597c8 100644 --- a/mbsebbs/change.c +++ b/mbsebbs/change.c @@ -1052,6 +1052,8 @@ void Chg_Charset() exitinfo.Charset = i; Syslog('+', "New character set %s", getchrs(exitinfo.Charset)); WriteExitinfo(); + setlocale(LC_CTYPE, getlocale(exitinfo.Charset)); + Syslog('b', "setlocale(LC_CTYPE, NULL) returns \"%s\"", printable(setlocale(LC_CTYPE, NULL), 0)); Enter(2); colour(LIGHTGREEN, BLACK); /* Character set now set to: */ diff --git a/mbsebbs/mbsebbs.c b/mbsebbs/mbsebbs.c index f4c769b3..a6b90d82 100644 --- a/mbsebbs/mbsebbs.c +++ b/mbsebbs/mbsebbs.c @@ -46,8 +46,6 @@ #include "ttyio.h" #include "openport.h" -#include -#include extern int do_quiet; /* Logging quiet flag */ @@ -228,7 +226,7 @@ int main(int argc, char **argv) /* * Some debugging for me */ - Syslog('b', "setlocale() returns \"%s\"", printable(setlocale(LC_ALL, NULL), 0)); + Syslog('b', "setlocale(LC_ALL, NULL) returns \"%s\"", printable(setlocale(LC_ALL, NULL), 0)); /* Next is not usefull */ Syslog('b', "nl_langinfo(LC_CTYPE) returns \"%s\"", printable(nl_langinfo(LC_CTYPE), 0)); diff --git a/mbsebbs/msgutil.c b/mbsebbs/msgutil.c index 428d7e57..1f7a4020 100644 --- a/mbsebbs/msgutil.c +++ b/mbsebbs/msgutil.c @@ -219,7 +219,12 @@ void Add_Headkludges(faddr *dest, int IsReply) break; } - if (msgs.Charset != FTNC_NONE) { + /* + * Set the right charset kludge + */ + if (exitinfo.Charset != FTNC_NONE) { + sprintf(temp, "\001CHRS: %s", getchrs(exitinfo.Charset)); + } else if (msgs.Charset != FTNC_NONE) { sprintf(temp, "\001CHRS: %s", getchrs(msgs.Charset)); } else { sprintf(temp, "\001CHRS: %s", getchrs(FTNC_LATIN_1)); diff --git a/mbsebbs/user.c b/mbsebbs/user.c index bc4a1960..f015ad7d 100644 --- a/mbsebbs/user.c +++ b/mbsebbs/user.c @@ -53,6 +53,7 @@ #include "ttyio.h" + extern int sock; extern pid_t mypid; char *StartTime = NULL; @@ -463,6 +464,9 @@ void user() Chg_Charset(); } + setlocale(LC_CTYPE, getlocale(exitinfo.Charset)); + Syslog('b', "setlocale(LC_CTYPE, NULL) returns \"%s\"", printable(setlocale(LC_CTYPE, NULL), 0)); + GetLastUser(); StartTime = xstrcpy(GetLocalHM()); ChangeHomeDir(exitinfo.Name, exitinfo.Email);