diff -ruN ./src/Makefile.am ../libicq-0.33/src/Makefile.am --- ./src/Makefile.am Thu Apr 1 19:02:42 1999 +++ ../libicq-0.33/src/Makefile.am Thu Apr 1 19:03:15 1999 @@ -11,7 +11,9 @@ send.h \ tcp.h \ config.h \ - util.h + util.h \ + japanese.h \ + japanese.c libicq_la_LDFLAGS = -version-info 0:3:0 include_HEADERS = libicq.h diff -ruN ./src/Makefile.in ../libicq-0.33/src/Makefile.in --- ./src/Makefile.in Thu Apr 1 19:02:42 1999 +++ ../libicq-0.33/src/Makefile.in Thu Apr 1 19:03:15 1999 @@ -86,7 +86,9 @@ send.h \ tcp.h \ config.h \ - util.h + util.h \ + japanese.h \ + japanese.c libicq_la_LDFLAGS = -version-info 0:3:0 include_HEADERS = libicq.h @@ -101,7 +103,7 @@ LIBS = @LIBS@ libicq_la_LIBADD = libicq_la_OBJECTS = libicq.lo receive.lo send.lo tcp.lo config.lo \ -util.lo +util.lo japanese.lo COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) LTCOMPILE = $(LIBTOOL) --mode=compile $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) LINK = $(LIBTOOL) --mode=link $(CC) $(AM_CFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ @@ -253,6 +255,7 @@ send.lo send.o: send.c icq.h libicq.h send.h tcp.h util.h tcp.lo tcp.o: tcp.c icq.h libicq.h receive.h tcp.h util.lo util.o: util.c icq.h libicq.h +japanese.lo japanese.o: japanese.c japanese.h info: dvi: diff -ruN ./src/japanese.c ../libicq-0.33/src/japanese.c --- ./src/japanese.c Thu Jan 1 09:00:00 1970 +++ ../libicq-0.33/src/japanese.c Thu Apr 1 19:03:15 1999 @@ -0,0 +1,215 @@ +/* + * japanese.c + * (C) Kuramitsu Kimio, Tokyo Univ. 1996-97 + * (C) Taku Kudoh, Kyoto Univ. 1998-99 + */ + +#include +#include +#include +#include "japanese.h" + +#define ESC 6 +#define LF 10 +#define CR 13 + +#define CHAROUT(ch) *str2 = (unsigned char)(ch); str2++; +#define HANKATA(a) (a >= 161 && a <= 223) +#define ISMARU(a) (a >= 202 && a <= 206) +#define ISNIGORI(a) ((a >= 182 && a <= 196) || (a >= 202 && a <= 206) || (a == 179)) +#define SJIS1(A) ((A >= 129 && A <= 159) || (A >= 224 && A <= 239)) +#define SJIS2(A) (A >= 64 && A <= 252) +#define ISEUC(A) (A >= 161 && A <= 254) +#define ISLF(A) (A == LF) +#define ISCR(A) (A == CR) + +static int stable[][2] = { + {129,66},{129,117},{129,118},{129,65},{129,69},{131,146},{131,64}, + {131,66},{131,68},{131,70},{131,72},{131,131},{131,133},{131,135}, + {131,98},{129,91},{131,65},{131,67},{131,69},{131,71},{131,73}, + {131,74},{131,76},{131,78},{131,80},{131,82},{131,84},{131,86}, + {131,88},{131,90},{131,92},{131,94},{131,96},{131,99},{131,101}, + {131,103},{131,105},{131,106},{131,107},{131,108},{131,109}, + {131,110},{131,113},{131,116},{131,119},{131,122},{131,125}, + {131,126},{131,128},{131,129},{131,130},{131,132},{131,134}, + {131,136},{131,137},{131,138},{131,139},{131,140},{131,141}, + {131,143},{131,147},{129,74},{129,75}}; + +unsigned char *_to_jis(unsigned char *str) +{ + *str = (unsigned char)ESC; str++; + *str = (unsigned char)'$'; str++; + *str = (unsigned char)'B'; str++; + return str; +} + +void _jis_shift(int *p1, int *p2) +{ + unsigned char c1 = *p1; + unsigned char c2 = *p2; + int rowOffset = c1 < 95 ? 112 : 176; + int cellOffset = c1 % 2 ? (c2 > 95 ? 32 : 31) : 126; + + *p1 = ((c1 + 1) >> 1) + rowOffset; + *p2 += cellOffset; +} + +void _sjis_shift(int *p1, int *p2) +{ + unsigned char c1 = *p1; + unsigned char c2 = *p2; + int adjust = c2 < 159; + int rowOffset = c1 < 160 ? 112 : 176; + int cellOffset = adjust ? (c2 > 127 ? 32 : 31) : 126; + + *p1 = ((c1 - rowOffset) << 1) - adjust; + *p2 -= cellOffset; +} + +unsigned char *_sjis_han2zen(unsigned char *str, int *p1, int *p2) +{ + register int c1, c2; + + c1 = (int)*str; str++; + *p1 = stable[c1 - 161][0]; + *p2 = stable[c1 - 161][1]; + + c2 = (int)*str; + if (c2 == 222 && ISNIGORI(c1)) { + if ((*p2 >= 74 && *p2 <= 103) || (*p2 >= 110 && *p2 <= 122)) + (*p2)++; + else if (*p1 == 131 && *p2 == 69) + *p2 = 148; + str++; + } + + if (c2 == 223 && ISMARU(c1) && (*p2 >= 110 && *p2 <= 122) ) { + *p2 += 2; + str++; + } + return str++; +} + +void _shift2euc(unsigned char *str, unsigned char *str2) +{ + int p1,p2; + + while ((p1 = (int)*str) != '\0') { + if (SJIS1(p1)) { + if((p2 = (int)*(++str)) == '\0') break; + if (SJIS2(p2)) { + _sjis_shift(&p1,&p2); + p1 += 128; + p2 += 128; + } + CHAROUT(p1); + CHAROUT(p2); + str++; + continue; + } + +#ifdef NO_HANKAKU_SJIS + if (HANKATA(p1)) { + str = _sjis_han2zen(str,&p1,&p2); + _sjis_shift(&p1,&p2); + p1 += 128; + p2 += 128; + CHAROUT(p1); + CHAROUT(p2); + continue; + } +#endif + +#ifdef CONV_RETURN_CODE + if (ISCR(p1)) { + if((p2 = (int)*(++str)) == '\0') { + CHAROUT(p1); + break; + } + if (ISLF(p2)) { + CHAROUT(LF); + } else { + CHAROUT(p1); + CHAROUT(p2); + } + str++; + continue; + } +#endif + + CHAROUT(p1); + str++; + } + *str2='\0'; +} + +void _euc2shift(unsigned char *str, unsigned char *str2) +{ + int p1,p2; + + while ((p1 = (int)*str) != '\0') { + if (ISEUC(p1)) { + if((p2 = (int)*(++str)) == '\0') break; + if (ISEUC(p2)) { + p1 -= 128; + p2 -= 128; + _jis_shift(&p1,&p2); + } + CHAROUT(p1); + CHAROUT(p2); + str++; + continue; + } + +#ifdef CONV_RETURN_CODE + if (ISLF(p1)) { + CHAROUT(CR); + CHAROUT(LF); + str++; + continue; + } +#endif + + CHAROUT(p1); + str++; + } + *str2='\0'; +} + +unsigned char *_set_buffer(char *str) +{ + static unsigned char *buf; + if((buf = (unsigned char *)malloc((strlen(str) + 1) * 4)) == NULL) { + fprintf(stderr, "Can't malloc buffer\n"); + exit(2); + } + return buf; +} + +char *_replace_buffer(unsigned char *buf) +{ + char *str; + + if ((str = strdup(buf)) == NULL) { + fprintf(stderr, "Can't malloc string buffer\n"); + exit(2); + } + free(buf); + return str; +} + +char *toStringEUC(char *str) +{ + unsigned char *buf; + buf = _set_buffer(str); + _shift2euc((unsigned char *)str, buf); + return (char *)_replace_buffer(buf); +} + +char *toStringSJIS(char *str) +{ + unsigned char *buf; + buf = _set_buffer(str); + _euc2shift((unsigned char *)str, buf); + return _replace_buffer(buf); +} diff -ruN ./src/japanese.h ../libicq-0.33/src/japanese.h --- ./src/japanese.h Thu Jan 1 09:00:00 1970 +++ ../libicq-0.33/src/japanese.h Thu Apr 1 19:03:15 1999 @@ -0,0 +1,11 @@ +/* + * japanese.h + * (C) Kuramitsu Kimio, Tokyo Univ. 1996-97 + * (C) Taku Kudoh, Kyoto Univ. 1998-99 + */ + +#define CONV_RETURN_CODE +#define NO_HANKAKU_SJIS + +extern char *toStringEUC(char *str); +extern char *toStringSJIS(char *str); diff -ruN ./src/libicq.c ../libicq-0.33/src/libicq.c --- ./src/libicq.c Thu Apr 1 19:02:42 1999 +++ ../libicq-0.33/src/libicq.c Thu Apr 1 19:01:14 1999 @@ -32,6 +32,7 @@ #include "tcp.h" #include "util.h" #include "config.h" +#include "japanese.h" void TCP_SendMessages(int i); @@ -249,12 +250,12 @@ if(Contacts[i].connected == 1) { - if(!TCP_SendMessage(uin, text)) - Send_Message(uin, text); /* fall back on UDP send */ + if(!TCP_SendMessage(uin, toStringSJIS(text))) + Send_Message(uin, toStringSJIS(text)); } else if(Contacts[i].connected < 0 || Contacts[i].status == STATUS_OFFLINE) { - Send_Message(uin, text); + Send_Message(uin, toStringSJIS(text)); } else { @@ -289,12 +290,12 @@ if(Contacts[i].connected == 1) { - if(!TCP_SendURL(uin, url, text)) - Send_URL(uin, url, text); + if(!TCP_SendURL(uin, url, toStringSJIS(text))) + Send_URL(uin, url, toStringSJIS(text)); } else if(Contacts[i].connected < 0 || Contacts[i].status == STATUS_OFFLINE) { - Send_URL(uin, url, text); + Send_URL(uin, url, toStringSJIS(text)); } else { @@ -477,17 +478,17 @@ GList* msg; MESSAGE_DATA_PTR curr_msg; - #ifdef DEBUG +#ifdef DEBUG fprintf(stderr, "\n LIBICQ> TCP_SendMessages"); - #endif +#endif while(msg = g_list_first(Contacts[i].messages)) { curr_msg = ((MESSAGE_DATA_PTR)(msg->data)); if(curr_msg->type == MSG_MESS) - TCP_SendMessage(Contacts[i].uin, curr_msg->text); + TCP_SendMessage(Contacts[i].uin, toStringSJIS(curr_msg->text)); else if(curr_msg->type == URL_MESS) - TCP_SendURL(Contacts[i].uin, curr_msg->url, curr_msg->text); + TCP_SendURL(Contacts[i].uin, curr_msg->url, toStringSJIS(curr_msg->text)); else if(curr_msg->type == AWAY_MESS) TCP_GetAwayMessage(Contacts[i].uin); @@ -514,9 +515,9 @@ curr_msg = ((MESSAGE_DATA_PTR)(msg->data)); if(curr_msg->type == MSG_MESS) - Send_Message(Contacts[i].uin, curr_msg->text); + Send_Message(Contacts[i].uin, toStringSJIS(curr_msg->text)); else if(curr_msg->type == URL_MESS) - Send_URL(Contacts[i].uin, curr_msg->url, curr_msg->text); + Send_URL(Contacts[i].uin, curr_msg->url, toStringSJIS(curr_msg->text)); g_free(curr_msg->text); g_free(curr_msg->url); diff -ruN ./src/receive.c ../libicq-0.33/src/receive.c --- ./src/receive.c Thu Apr 1 19:02:42 1999 +++ ../libicq-0.33/src/receive.c Thu Apr 1 19:01:14 1999 @@ -25,6 +25,7 @@ #include "receive.h" #include "send.h" #include "util.h" +#include "japanese.h" extern gint Verbose; extern gint sok; @@ -269,14 +270,14 @@ tmp = strchr(data, '\xFE'); if(!tmp) return; *tmp = 0; - c_mesg.msg = data; + c_mesg.msg = toStringEUC(data); data = ++tmp; c_mesg.url = data; } else { - c_mesg.msg = data; + c_mesg.msg = toStringEUC(data); } last_recv_uin = Chars_2_DW(r_mesg->uin); @@ -340,14 +341,14 @@ tmp = strchr(data, '\xFE'); if(!tmp) return; *tmp = 0; - c_mesg.msg = data; + c_mesg.msg = toStringEUC(data); data = ++tmp; c_mesg.url = data; } else { - c_mesg.msg = data; + c_mesg.msg = toStringEUC(data); } if(event[EVENT_MESSAGE] != NULL) @@ -479,7 +480,6 @@ close(Contacts[cindex].sok); Contacts[cindex].sok = -1L; strcpy(user_update.nick, Contacts[cindex].nick); - } user_update.status = STATUS_OFFLINE; @@ -700,8 +700,4 @@ if(event[EVENT_SEARCH_RESULTS] != NULL) (*event[EVENT_SEARCH_RESULTS])((void*)Search_Results); } - - - -