[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: перекодировка



 Здравствуйте,

 На мой взгляд вот такая вот программка весьма удобна (см. attachment).
 К сожалению имя автора и происхождение оной канули в лету... :(

 Желаю успехов!

nefedov@nusun.jinr.ru

-----------------------------------------------------------------------------
Hi! I'm a .signature virus! Copy me into your ~/.signature to help me spread!
-----------------------------------------------------------------------------

On Mon, 10 Jul 2000, Konstantin Kubatkin wrote:

> 
>  а кто чем пользуется для перекодировки текстов из различных кодировок?
> например из CP866 в KOI8-R? у меня есть alt2koi8 и koi82alt, но они
> требуют libc5, а с recode из поставки Debian я не смог разобраться 
> 
> -- 
> Konstantin Kubatkin
> KK4501-RIPE, Kherson, TriLogiC Group
> Fido: 2:468/0@FidoNet
> 
/**  recode.c  **/

#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>

typedef unsigned char uchar;
/* +yo */
uchar ai[] = {176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,
              192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,
              208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,
              136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,
              152,153,154,129,156,157,158,159,160,130,162,163,164,165,166,167,
              168,169,170,171,172,173,174,175,240,132,242,243,244,245,246,247,
              224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,
              161,241,135,134,128,133,131,155,248,249,250,251,252,253,254,255};
/* +yo */
uchar ak[] = {225,226,247,231,228,229,246,250,233,234,235,236,237,238,239,240,
              242,243,244,245,230,232,227,254,251,253,255,249,248,252,224,241,
              193,194,215,199,196,197,214,218,201,202,203,204,205,206,207,208,
              136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,
              152,153,154,129,156,157,158,159,160,161,162,132,164,165,166,167,
              168,169,170,171,172,173,174,175,176,177,178,130,180,181,182,183,
              210,211,212,213,198,200,195,222,219,221,223,217,216,220,192,209,
              179,163,135,134,128,133,131,155,184,185,186,187,188,189,190,191};
/* +yo */
uchar aw[] = {192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,
              208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,
              224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,
              136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,
              152,153,154,129,156,157,158,159,160,161,162,163,164,165,166,167,
              130,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,
              240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255,
              168,184,135,134,128,133,131,155,132,185,186,187,188,189,190,191};
/* +yo */
uchar ia[] = {244,195,201,246,217,245,243,242,176,177,178,179,180,181,182,183,
              184,185,186,187,188,189,190,191,192,193,194,247,196,197,198,199,
              200,240,202,203,204,205,206,207,208,209,210,211,212,213,214,215,
              128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,
              144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,
              160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,
              224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,
              216,241,218,219,220,221,222,223,248,249,250,251,252,253,254,255};
/* +yo */
uchar ik[] = {128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,
              144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,
              160,179,162,177,164,165,166,167,168,169,170,171,172,173,174,175,
              225,226,247,231,228,229,246,250,233,234,235,236,237,238,239,240,
              242,243,244,245,230,232,227,254,251,253,255,249,248,252,224,241,
              193,194,215,199,196,197,214,218,201,202,203,204,205,206,207,208,
              210,211,212,213,198,200,195,222,219,221,223,217,216,220,192,209,
              176,163,178,161,180,181,182,183,184,185,186,187,188,189,190,191};
/* +yo */
uchar iw[] = {128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,
              144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,
              160,168,162,163,164,165,166,167,161,169,170,171,172,173,174,175,
              192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,
              208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,
              224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,
              240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255,
              176,184,178,179,180,181,182,183,177,185,186,187,188,189,190,191};
/* +yo */
uchar ka[] = {244,195,219,246,203,245,243,242,176,177,178,179,180,181,182,183,
              184,185,186,187,188,189,190,191,192,193,194,247,196,197,198,199,
              200,201,202,241,204,205,206,207,208,209,210,211,212,213,214,215,
              216,217,218,240,220,221,222,223,248,249,250,251,252,253,254,255,
              238,160,161,230,164,165,228,163,229,168,169,170,171,172,173,174,
              175,239,224,225,226,227,166,162,236,235,167,232,237,233,231,234,
              158,128,129,150,132,133,148,131,149,136,137,138,139,140,141,142,
              143,159,144,145,146,147,134,130,156,155,135,152,157,153,151,154};
/* +yo */
uchar ki[] = {128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,
              144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,
              160,243,162,241,164,165,166,167,168,169,170,171,172,173,174,175,
              240,163,242,161,244,245,246,247,248,249,250,251,252,253,254,255,
              238,208,209,230,212,213,228,211,229,216,217,218,219,220,221,222,
              223,239,224,225,226,227,214,210,236,235,215,232,237,233,231,234,
              206,176,177,198,180,181,196,179,197,184,185,186,187,188,189,190,
              191,207,192,193,194,195,182,178,204,203,183,200,205,201,199,202};
/* +yo */
uchar kw[] = {128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,
              144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,
              160,161,162,184,164,165,166,167,179,169,170,171,172,173,174,175,
              176,177,178,168,180,181,182,183,163,185,186,187,188,189,190,191,
              254,224,225,246,228,229,244,227,245,232,233,234,235,236,237,238,
              239,255,240,241,242,243,230,226,252,251,231,248,253,249,247,250,
              222,192,193,214,196,197,212,195,213,200,201,202,203,204,205,206,
              207,223,208,209,210,211,198,194,220,219,199,216,221,217,215,218};
/* +yo */
uchar wa[] = {244,195,208,246,248,245,243,242,176,177,178,179,180,181,182,183,
              184,185,186,187,188,189,190,191,192,193,194,247,196,197,198,199,
              200,201,202,203,204,205,206,207,240,209,210,211,212,213,214,215,
              216,217,218,219,220,221,222,223,241,249,250,251,252,253,254,255,
              128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,
              144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,
              160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,
              224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239};
/* +yo */
uchar wi[] = {128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,
              144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,
              160,168,162,163,164,165,166,167,161,169,170,171,172,173,174,175,
              240,248,242,243,244,245,246,247,241,249,250,251,252,253,254,255,
              176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,
              192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,
              208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,
              224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239};
/* +yo */
uchar wk[] = {128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,
              144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,
              160,161,162,184,164,165,166,167,179,169,170,171,172,173,174,175,
              176,177,178,168,180,181,182,183,163,185,186,187,188,189,190,191,
              225,226,247,231,228,229,246,250,233,234,235,236,237,238,239,240,
              242,243,244,245,230,232,227,254,251,253,255,249,248,252,224,241,
              193,194,215,199,196,197,214,218,201,202,203,204,205,206,207,208,
              210,211,212,213,198,200,195,222,219,221,223,217,216,220,192,209};

/**********************************************************/
main(argc, argv)
char **argv;
int argc;
{
FILE *in, *out;
struct stat buf;
uchar *table, c;
char temp[1024];
int i;
if(argc < 2 || argc > 4)
   usage(argv[0]);
if(!strcmp(argv[1], "-ai"))
   table = ai;
else if(!strcmp(argv[1], "-ak"))
   table = ak;
else if(!strcmp(argv[1], "-aw"))
   table = aw;
else if(!strcmp(argv[1], "-ia"))
   table = ia;
else if(!strcmp(argv[1], "-ik"))
   table = ik;
else if(!strcmp(argv[1], "-iw"))
   table = iw;
else if(!strcmp(argv[1], "-ka"))
   table = ka;
else if(!strcmp(argv[1], "-ki"))
   table = ki;
else if(!strcmp(argv[1], "-kw"))
   table = kw;
else if(!strcmp(argv[1], "-wa"))
   table = wa;
else if(!strcmp(argv[1], "-wi"))
   table = wi;
else if(!strcmp(argv[1], "-wk"))
   table = wk;
else
   usage(argv[0]);
in = 0;
out = 0;
if(argc == 2 || (argc == 3 && !strcmp(argv[2], "-")))
   {
   in = stdin;
   out = stdout;
   }
else if(argc == 4)
   {
   if(!strcmp(argv[2], "-"))
      in = stdin;
   if(!strcmp(argv[3], "-"))
      out = stdout;
   }
if(argc > 2)
   {
   if(!in)
      {
      if(stat(argv[2], &buf) < 0)
         {
         printf("%s: cannot open input file '%s'.\n", argv[0], argv[2]);
         exit(1);
         }
      in = fopen(argv[2], "r");
      if(!in)
         {
         printf("%s: cannot open input file '%s'.\n", argv[0], argv[2]);
         exit(1);
         }
      }
   if(!out)
      {
      if(argc == 3)
         sprintf(temp, "%s.%d", argv[0], getpid());
      else
         strcpy(temp, argv[3]);
      out = fopen(temp, "w");
      if(!out)
         {
         printf("%s: cannot open %s file '%s'.\n", argv[0],
                ((argc == 3) ? "temporary" : "output"), temp);
         fclose(in);
         exit(1);
         }
      }
   }
if(!in)
   {
   printf("%s: cannot open standard input.\n", argv[0]);
   exit(1);
   }
if(!out)
   {
   printf("%s: cannot open standard output.\n", argv[0]);
   fclose(in);
   exit(1);
   }
while((i = getc(in)) != -1)
   {
   i &= 0377;
   if(i & 0200)
      i = table[i & 0177];
   putc(i, out);
   }
fclose(in);
fclose(out);
if(argc == 3 && strcmp(argv[2], "-"))
   {
   unlink(argv[2]);
   link(temp, argv[2]);
   unlink(temp);
   }
}

/**********************************************************/
usage(name)
char *name;
{
fprintf(stderr, "Usage: %s -{ai|ak|aw|ia|ik|iw|ka|ki|kw|wa|wi|wk} ", name);
fprintf(stderr, "[input_file [output_file]]\n       Parameters are:\n");
fprintf(stderr, "       -ai         - from Alternative to ISO,\n");
fprintf(stderr, "       -ak         - from Alternative to Koi8,\n");
fprintf(stderr, "       -aw         - from Alternative to Windows,\n");
fprintf(stderr, "       -ia         - from ISO to Alternative,\n");
fprintf(stderr, "       -ik         - from ISO to Koi8,\n");
fprintf(stderr, "       -iw         - from ISO to Windows,\n");
fprintf(stderr, "       -ka         - from Koi8 to Alternative,\n");
fprintf(stderr, "       -ki         - from Koi8 to ISO,\n");
fprintf(stderr, "       -kw         - from Koi8 to Windows,\n");
fprintf(stderr, "       -wa         - from Windows to Alternative,\n");
fprintf(stderr, "       -wi         - from Windows to ISO;\n");
fprintf(stderr, "       -wk         - from Windows to Koi8;\n");
fprintf(stderr, "       input_file  - name of input file, ");
fprintf(stderr, "may be \"-\" as standard input;\n");
fprintf(stderr, "       output_file - name of output file, ");
fprintf(stderr, "may be \"-\" as standard output.\n");
exit(1);
}

Reply to: