rus_conv.c
上传用户:ai20ln
上传日期:2007-01-05
资源大小:79k
文件大小:3k
源码类别:

ICQ/即时通讯

开发平台:

Unix_Linux

  1. /**  rus_conv.c  **/
  2. #include "micq.h"
  3. #ifdef _WIN32
  4.  #include <winuser.h>
  5.  /* OemToChar and CharToOemis here...*/
  6. #endif
  7. #include <stdio.h>
  8. #include <sys/types.h>
  9. #include <sys/stat.h>
  10. typedef unsigned char uchar;
  11. uchar kw[] = {128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,
  12.               144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,
  13.               160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,
  14.               176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,
  15.               254,224,225,246,228,229,244,227,245,232,233,234,235,236,237,238,
  16.               239,255,240,241,242,243,230,226,252,251,231,248,253,249,247,250,
  17.               222,192,193,214,196,197,212,195,213,200,201,202,203,204,205,206,
  18.               207,223,208,209,210,211,198,194,220,219,199,216,221,217,215,218};
  19. uchar wk[] = {128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,
  20.               144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,
  21.               160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,
  22.               176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,
  23.               225,226,247,231,228,229,246,250,233,234,235,236,237,238,239,240,
  24.               242,243,244,245,230,232,227,254,251,253,255,249,248,252,224,241,
  25.               193,194,215,199,196,197,214,218,201,202,203,204,205,206,207,208,
  26.               210,211,212,213,198,200,195,222,219,221,223,217,216,220,192,209};
  27. /********************************************************
  28. Russian language ICQ fix.
  29. Usual Windows ICQ users do use Windows 1251 encoding but
  30. unix users do use koi8 encoding, so we need to convert it.
  31. This function will convert string from windows 1251 to koi8
  32. or from koi8 to windows 1251.
  33. Andrew Frolov dron@ilm.net
  34. *********************************************************/
  35. void rus_conv( char to[4], char *t_in )
  36. {
  37.    uchar *table;
  38.    int i;
  39. #ifdef _WIN32
  40.    /* Jerom's code %) */
  41.    char tempbuff[10000]; /* What happens if we use t_in twice??? */
  42.    /* Does windows barf? it shouldn't but it shouldn't crash either */
  43.    if ( Russian )
  44.    {
  45.       assert( strlen( t_in ) < 9999 );
  46.       if(strcmp(to, "kw") == 0)
  47.          OemToChar(t_in, tempbuff);
  48.       /* If you have errors here try to change this function to
  49.       // OemToAnsi() */
  50.       else
  51.          CharToOem(t_in, tempbuff);
  52.       /*  If you have errors here try to change this function to
  53.       // AnsiToOem() */
  54.       strcpy(t_in, tempbuff);
  55.    }
  56. #else
  57. /* 6-17-1998 by Linux_Dude
  58.  * Moved initialization of table out front of 'if' block to prevent compiler
  59.  * warning. Improved error message, and now return without performing string
  60.  * conversion to prevent addressing memory out of range (table pointer would
  61.  * previously have remained uninitialized ( = bad)).
  62. */
  63.    table = wk;
  64.    if(strcmp(to, "kw") == 0)
  65.       table = kw;
  66.    else if(strcmp(to, "wk") != 0)
  67.    {
  68.       fprintf(stderr, "nError - "to" in call to rus_conv() is "%s", must " 
  69.                       "be "wk" or "kw".nWarning - Sending message " 
  70.                       "without converting string.n", to);
  71.       return;
  72.    }
  73.       
  74. /* End Linux_Dude's changes ;)
  75. */
  76.    if ( Russian )
  77.    {
  78.       for (i=0;t_in[i]!=0;i++)
  79.       {
  80.          t_in[i] &= 0377;
  81.          if(t_in[i] & 0200)
  82.             t_in[i] = table[t_in[i] & 0177];
  83.       }
  84.    }
  85. #endif
  86. }