Logo Search packages:      
Sourcecode: xcingb version File versions  Download package

tran.c

/*
      Copyright (C) 1995      Edward Der-Hua Liu, Hsin-Chu, Taiwan
*/

#include <sys/types.h>

extern int printf( const char *format, ...);

void ser_b5(u_char *ch, u_char *tt)
{
      u_short q,r,ofs, oofs;

      tt[2]=0;
      oofs=ofs=((u_short)*ch<<8)|*(ch+1);

      if (ofs==0) {
            *tt=*(tt+1)=0;
            return;
      }
      if (ch[0]==' ' && ch[1]==' ') {
            *tt=*(tt+1)=' ';
            return;
      }

      if (ofs < 0x8800) {
            ofs-=0x8400;
            if (ofs>=5401) ofs+=408; /* useless */ 
            q=ofs/157; r=ofs%157;
            if (r<63)
                  *(tt+1)=r+0x40;
            else
                  *(tt+1)=(r-63)+0xa1;

            if (q<94)
                  *tt=q+0xa1;
            else
                  printf("&error ofs:%x\n",oofs);
            return;
      }

      if (ofs > 0xe000) {
            ofs-=0xe000;
            q=ofs/157; r=ofs%157;
            if (r<63)
                  *(tt+1)=r+0x40;
            else
                  *(tt+1)=(r-63)+0xa1;

            if (q<94)
                  *tt=q+0xc6;
            else
                  printf("#error ofs:%x\n",oofs);
            return;
      }

      ofs-=0x8800;
      if (ofs>=5401) ofs+=408;
      q=ofs/157; r=ofs%157;
      if (r<63)
            *(tt+1)=r+0x40;
      else
            *(tt+1)=(r-63)+0xa1;

      if (q<94)
            *tt=q+0xa4;
      else
            printf("!error ofs:%x\n",oofs);
}

void b5_ser(u_char *s, u_char *t)
{
u_char lb,hb, tt=0;
u_short ser, b5;

if (s[0]==' ' && s[1]==' ') {
      *t=*(t+1)=' ';
      return;
}
hb=s[0];
lb=s[1];
b5=((u_short)hb<<8)|lb;

if (b5 < (u_short)0xa440) {
      if (lb>=0xa1 && lb<=0xfe) tt=(lb-0xa1)+63;
      else
      if (lb>=0x40 && lb<=0x7e) tt=lb-0x40;
      else printf("err %x\n", b5);
      ser=(u_short)(hb-0xa1)*157+ tt;
      ser+=0x8400;
      t[0]=ser>>8;
      t[1]=ser&255;
      if (t[0]==0x21 && t[1]==0x84)
            printf("#%2x%2x %c%c\n", s[0],s[1], s[0],s[1]);
      return;
}

if (b5 >= 0xc6a1 && b5 <= 0xc8fe) {
      if (lb>=0xa1 && lb<=0xfe) tt=(lb-0xa1)+63;
      else
      if (lb>=0x40 && lb<=0x7e) tt=lb-0x40;
      else printf("err %x\n", b5);
      ser=(u_short)(hb-0xc6)*157+ tt;
      ser+=0xe000;
      t[0]=ser>>8;
      t[1]=ser&255;
      if (t[0]==0x21 && t[1]==0x84)
            printf("$%2x%2x %c%c\n", s[0],s[1], s[0],s[1]);
      return;
}

if (lb>=0xa1 && lb<=0xfe) tt=(lb-0xa1)+63;
else
if (lb>=0x40 && lb<=0x7e) tt=lb-0x40;
else printf("err %x\n", b5);
ser=(u_short)(hb-0xa4)*157+ tt;
if (ser>=5401) ser+=0x8800-408;
else ser+=0x8800;
t[0]=ser>>8;
t[1]=ser&255;
      if (t[0]==0x21 && t[1]==0x84)
            printf("*%2x%2x %c%c\n", s[0],s[1], s[0],s[1]);
}

Generated by  Doxygen 1.6.0   Back to index