From 3c75b863a628adc020062e773d7edf5bac0649fb Mon Sep 17 00:00:00 2001 From: erdgeist <> Date: Sat, 15 Nov 2003 19:03:54 +0000 Subject: UTF-8 autodetection, some gcc warnings --- vchat-client.c | 40 +++++++++++++++++++++++++--------------- vchat-config.h | 48 ++++++++++++++++++++++++------------------------ vchat-messages.h | 7 ++++++- vchat-protocol.c | 15 +++++++++++++++ vchat-ui.c | 6 +++--- vchat.h | 5 ++++- 6 files changed, 77 insertions(+), 44 deletions(-) diff --git a/vchat-client.c b/vchat-client.c index 2fc1ea9..a3e7fd2 100755 --- a/vchat-client.c +++ b/vchat-client.c @@ -26,6 +26,10 @@ #include #include #include +#ifndef NO_LOCALE +#include +#include +#endif #include "vchat.h" /* version of this module */ @@ -278,8 +282,8 @@ setstroption (confopt option, unsigned char *string) configoptions[i].value = strdup(string); else configoptions[i].value = NULL; - if (configoptions[i].localvar) - *configoptions[i].localvar = configoptions[i].value; + if (configoptions[i].localvar.pstr) + *configoptions[i].localvar.pstr = configoptions[i].value; } } @@ -294,17 +298,19 @@ setnoption (unsigned char *name, unsigned char *string) for (i = 0; configoptions[i].type != CO_NIL; i++) if (!strcmp(configoptions[i].varname,name)) { if (configoptions[i].type == CO_STR) { - if (configoptions[i].value) - free(configoptions[i].value); - if (string) - configoptions[i].value = strdup(string); - else - configoptions[i].value = NULL; - } else if (configoptions[i].type == CO_INT) { - configoptions[i].value = (char *) atoi(string); - } - if (configoptions[i].localvar) - *configoptions[i].localvar = configoptions[i].value; + if (configoptions[i].value) + free(configoptions[i].value); + if (string) + configoptions[i].value = strdup(string); + else + configoptions[i].value = NULL; + if (configoptions[i].localvar.pstr) + *configoptions[i].localvar.pstr = configoptions[i].value; + } else if (configoptions[i].type == CO_INT) { + configoptions[i].value = (char *) atoi(string); + if (configoptions[i].localvar.pint) + *configoptions[i].localvar.pint = (int)configoptions[i].value; + } } } @@ -337,8 +343,8 @@ setintoption (confopt option, int value) for (i = 0; configoptions[i].type != CO_NIL; i++) if ((configoptions[i].id == option) && (configoptions[i].type == CO_INT)) { configoptions[i].value = (char *) value; - if (configoptions[i].localvar) - *configoptions[i].localvar = configoptions[i].value; + if (configoptions[i].localvar.pint) + *configoptions[i].localvar.pint = (int)configoptions[i].value; } } @@ -472,6 +478,10 @@ main (int argc, char **argv) int pchar; int cmdsunparsed = 1; +#ifndef NO_LOCALE + setlocale(LC_ALL,""); +#endif + loadconfig (GLOBAL_CONFIG_FILE); loadconfig (getstroption (CF_CONFIGFILE)); diff --git a/vchat-config.h b/vchat-config.h index beb4579..856b00c 100755 --- a/vchat-config.h +++ b/vchat-config.h @@ -29,30 +29,30 @@ extern unsigned int hscroll; static volatile configoption configoptions[] = { /* config-option type name in file default value value localvar */ - {CF_NICK, CO_STR, "nick", NULL, NULL, &nick }, - {CF_FROM, CO_STR, "from", "vc-alpha-0.16", NULL, NULL }, - {CF_SERVERHOST, CO_STR, "host", "pulse.flatline.de",NULL, NULL }, - {CF_SERVERPORT, CO_INT, "port", (char *) 2325, (char *)-1, NULL }, - {CF_CIPHERSUITE, CO_STR, "ciphers", "HIGH:MEDIUM", NULL, NULL }, - {CF_CONFIGFILE, CO_STR, "conffile", "~/.vchat/config", NULL, NULL }, - {CF_CERTFILE, CO_STR, "certfile", "~/.vchat/cert", NULL, NULL }, - {CF_KEYFILE, CO_STR, "keyfile", "~/.vchat/key", NULL, NULL }, - {CF_FORMFILE, CO_STR, "formatfile", "~/.vchat/formats", NULL, NULL }, - {CF_LOGFILE, CO_STR, "logfile", "~/.vchat/log", NULL, NULL, }, - {CF_ENCODING, CO_STR, "encoding", NULL, NULL, &encoding }, - {CF_USESSL, CO_INT, "usessl", (char *) 1, (char *)-1, (unsigned char **)&usessl }, - {CF_USECERT, CO_INT, "usecert", (char *) 1, (char *)-1, NULL }, - {CF_USETIME, CO_INT, "usetime", (char *) 1, (char *)-1, (unsigned char **)&usetime }, - {CF_USETOPIC, CO_INT, "usetopicbar",(char *) 1, (char *)-1, NULL }, - {CF_PRIVHEIGHT, CO_INT, "messages", (char *) 0, (char *)-1, NULL }, - {CF_HSCROLL, CO_INT, "hscroll", (char *) 5, (char *)-1, (unsigned char **)&hscroll }, - {CF_CHANNEL, CO_INT, "channel", (char *) 0, (char *)-1, NULL }, - {CF_SCROLLBPRIV, CO_INT, "privscrollb",(char *) 2048, (char *)-1, NULL }, - {CF_SCROLLBACK, CO_INT, "scrollback", (char *) 8192, (char *)-1, NULL }, - {CF_SCROLLBPRIVT,CO_INT, "privscrollt",(char *) 0, (char *)-1, NULL }, - {CF_SCROLLBACKT, CO_INT, "scrolltime", (char *) 86400, (char *)-1, NULL }, - {CF_KEEPLOG, CO_INT, "keeplog", (char *) 0, (char *)-1, NULL }, - {CF_NIL, CO_NIL, NULL, NULL, NULL, NULL }, + {CF_NICK, CO_STR, "nick", NULL, NULL, { .pstr = &nick } }, + {CF_FROM, CO_STR, "from", "vc-alpha-0.16", NULL, { NULL } }, + {CF_SERVERHOST, CO_STR, "host", "pulse.flatline.de",NULL, { NULL } }, + {CF_SERVERPORT, CO_INT, "port", (char *) 2325, (char *)-1, { NULL } }, + {CF_CIPHERSUITE, CO_STR, "ciphers", "HIGH:MEDIUM", NULL, { NULL } }, + {CF_CONFIGFILE, CO_STR, "conffile", "~/.vchat/config", NULL, { NULL } }, + {CF_CERTFILE, CO_STR, "certfile", "~/.vchat/cert", NULL, { NULL } }, + {CF_KEYFILE, CO_STR, "keyfile", "~/.vchat/key", NULL, { NULL } }, + {CF_FORMFILE, CO_STR, "formatfile", "~/.vchat/formats", NULL, { NULL } }, + {CF_LOGFILE, CO_STR, "logfile", "~/.vchat/log", NULL, { NULL } }, + {CF_ENCODING, CO_STR, "encoding", NULL, NULL, { .pstr = &encoding }}, + {CF_USESSL, CO_INT, "usessl", (char *) 1, (char *)-1, { .pint = &usessl } }, + {CF_USECERT, CO_INT, "usecert", (char *) 1, (char *)-1, { NULL } }, + {CF_USETIME, CO_INT, "usetime", (char *) 1, (char *)-1, { .pint = &usetime } }, + {CF_USETOPIC, CO_INT, "usetopicbar",(char *) 1, (char *)-1, { NULL } }, + {CF_PRIVHEIGHT, CO_INT, "messages", (char *) 0, (char *)-1, { NULL } }, + {CF_HSCROLL, CO_INT, "hscroll", (char *) 5, (char *)-1, { .pint = &hscroll } }, + {CF_CHANNEL, CO_INT, "channel", (char *) 0, (char *)-1, { NULL } }, + {CF_SCROLLBPRIV, CO_INT, "privscrollb",(char *) 2048, (char *)-1, { NULL } }, + {CF_SCROLLBACK, CO_INT, "scrollback", (char *) 8192, (char *)-1, { NULL } }, + {CF_SCROLLBPRIVT,CO_INT, "privscrollt",(char *) 0, (char *)-1, { NULL } }, + {CF_SCROLLBACKT, CO_INT, "scrolltime", (char *) 86400, (char *)-1, { NULL } }, + {CF_KEEPLOG, CO_INT, "keeplog", (char *) 0, (char *)-1, { NULL } }, + {CF_NIL, CO_NIL, NULL, NULL, NULL, { NULL } }, }; /* diff --git a/vchat-messages.h b/vchat-messages.h index 477d791..0902e88 100755 --- a/vchat-messages.h +++ b/vchat-messages.h @@ -64,7 +64,7 @@ servermessage servermessages[] = { {"169", SM_INFO, NULL, NULL}, /* 201 Server signon */ - {"201", SM_IGNORE, NULL, NULL}, + {"201", SM_IGNORE, serverlogin, NULL}, /* 211 User signon */ {"211", SM_USERINFO, usersignon, NULL}, @@ -83,6 +83,9 @@ servermessage servermessages[] = { /* 241 Nickname change */ {"241", SM_USERINFO, usernickchange, NULL}, +/* 269 Encoding set to + answer to .e */ + {"269", SM_INFO, NULL, NULL}, /* 120 */ {"120", SM_INFO, login, NULL}, /* 121 You're not logged in */ @@ -117,6 +120,8 @@ servermessage servermessages[] = { {"414", SM_ERROR, NULL, NULL}, /* 415 Nickname reserved */ {"415", SM_ERROR, nickerr, NULL}, +/* 469 I'm very sorry, FNORD is not know to this system, try .E for a * list */ + {"469", SM_ERROR, NULL, NULL}, /* 501 Disconnected by own request */ {"501", SM_INFO, NULL, NULL}, /* 502 Disconnected by operator */ diff --git a/vchat-protocol.c b/vchat-protocol.c index 5113365..f1e8b5c 100755 --- a/vchat-protocol.c +++ b/vchat-protocol.c @@ -26,6 +26,10 @@ #include #include #include +#ifndef NO_LOCALE +#include +#include +#endif /* local includes */ #include "vchat.h" @@ -62,6 +66,7 @@ static void anonlogin (unsigned char *message); static void topicinfo (unsigned char *message); static void pubaction (unsigned char *message); static void pubthoughts (unsigned char *message); +static void serverlogin (unsigned char *message); static void idleprompt (unsigned char *message); static void topicchange (unsigned char *message); static void pmnotsent (unsigned char *message); @@ -408,6 +413,16 @@ pubthoughts (unsigned char *message) writechan (tmpstr); } +/* parse and handle server logon */ +static void +serverlogin (unsigned char *message) +{ +#ifndef NO_LOCALE + int utf8=!strcmp(nl_langinfo(CODESET), "UTF-8"); + if (utf8) + networkoutput(".e utf8"); +#endif +} /* parse and handle an idle message * format: 305 * vars: %s message */ diff --git a/vchat-ui.c b/vchat-ui.c index e2b68d1..ef6561e 100755 --- a/vchat-ui.c +++ b/vchat-ui.c @@ -1539,14 +1539,14 @@ clearfilters( char colour ) { void removefilter( unsigned char *tail ) { int rmv = 0, val; - unsigned char* end; + char* end; flushout( ); rmv = removefromfilterlist( test_simplerm, (void *)tail, 0 ); if(!rmv) { - val = strtol((char*)tail, (char **)&end, 10); - if( (tail != end) && (!*end) ) + val = strtol((char*)tail, &end, 10); + if( (tail != (unsigned char*)end) && (!*end) ) rmv = removefromfilterlist( test_numericrm, (void *)val, 0); } diff --git a/vchat.h b/vchat.h index 64788b9..ec5da02 100755 --- a/vchat.h +++ b/vchat.h @@ -59,7 +59,10 @@ struct configoption unsigned char *varname; unsigned char *defaultvalue; unsigned char *value; - unsigned char **localvar; + union { + unsigned char **pstr; + int *pint; + } localvar; }; typedef struct configoption configoption; -- cgit v1.2.3