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

#define  BYTE      unsigned char
#define  WORD      unsigned int
#define  CHOFILL   0x0084
#define  JUNGFILL  0x4000
#define  JongFill  0x0100
#define  ChoBul    21
#define  JungBul   3
#define  JongBul   14
#define  AGROUP    1
#define  BGROUP    2
#define  CHONUM   19
#define  JUNGNUM  42
#define  JONGNUM  27
#define  TMPNUM   13
#define  ASECTION  4
#define  BSECTION  4
#define  CSECTION  4
#define  DSECTION  5
#define  ESECTION  2
#define  FSECTION  1
#define  GSECTION  1

#define  SUCCESS            1
#define  FAIL               0
#define  CODE_FILE_ERROR  200
WORD ChoCode,JungCode,JongCode ;
WORD ChoFile,JungFile,JongFile ;
WORD RetChoCode,RetJungCode,RetJongCode ;
char ChoReadFile[80],JungReadFile[80],JongReadFile[80] ;
/*----------------------------------------------------------------------*/
/*                    JoHab Hangul Code Generate  Main                  */
/*----------------------------------------------------------------------*/
MoonJohab(int ReadCode)
{ WORD TmpCode    ;

  TmpCode  = ReadCode        ;
  ChoCode  = TmpCode >> 10   ;
  ChoCode  = ChoCode << 2    ;
  TmpCode  = ReadCode        ;
  TmpCode  = TmpCode >> 5    ;
  JungCode = TmpCode << 11   ;
  TmpCode  = ReadCode        ;
  TmpCode  = TmpCode << 11   ;
  JongCode = TmpCode >> 3    ;
  JoHabProcess()             ;

}

/*---------------------------------------------------------------------*/
/*                                JoHab Process                        */
/*---------------------------------------------------------------------*/
int JoHabProcess()
{int ans ;

     if(JongCode == JongFill)
         ans = NoJongProcess()        ;
     else
        {  ans = JongBokFind()        ;
           if(ans == SUCCESS)
             ans = JongBokProcess()   ;
           else
             ans = JongDanProcess()   ;
        }
   if(ans == CODE_FILE_ERROR)
        ans = FAIL ;
   else
     ans = PsfFileMerge() ;
   if(ans == SUCCESS)
      return(SUCCESS)     ;
   else
      return(FAIL)        ;
}

/*--------------------------------------------------------------------*/
/*                              Psf File Merge                        */
/*--------------------------------------------------------------------*/
int PsfFileMerge()
{int ans ;
 int i   ;

      if(ChoFile != 0)
          ans = PsfFileLoad(ChoFile,ChoReadFile,&RetChoCode)     ;
      else
          { strcpy(ChoReadFile," ") ;
            strpcy(JungReadFile," ") ;
            strcpy(JongReadFile," ") ;
            RetChoCode  = CHOFILL  ;
            RetJungCode = JUNGFILL ;
            RetJongCode = JongFill ;
          }
      if(ans != SUCCESS)
         return(CODE_FILE_ERROR)       ;

      if(JungFile != 0)
         ans = PsfFileLoad(JungFile,JungReadFile,&RetJungCode)    ;
      else
           { strcpy(JungReadFile," ") ;
             strcpy(JongReadFile," ") ;
             RetJungCode = JUNGFILL   ;
             RetJongCode = JongFill   ;
            }
      if(ans != SUCCESS)
         return(CODE_FILE_ERROR)       ;
      if(JongFile != 0)
           ans = PsfFileLoad(JongFile,JongReadFile,&RetJongCode) ;
      else
          {  strcpy(JongReadFile," ") ;
             RetJongCode = JongFill ;
           }
      if(ans != SUCCESS)
         return(CODE_FILE_ERROR) ;
    return(SUCCESS) ;
}

/*--------------------------------------------------------------------*/
/*                               Psf File Load                        */
/*--------------------------------------------------------------------*/
int PsfFileLoad(Code,File,RetCode)
int Code ;
char File[] ;
int *RetCode ;
{int FileCode   ;
 int FileNum    ;

  Code     = Code - 1       ;
  FileNum  = Code / 200 + 1 ;
  FileCode = Code % 200     ;
  if(FileNum < 10)
     sprintf(File,"jaso00%d",FileNum) ;
  else if(FileNum <100)
     sprintf(File,"jaso0%d",FileNum)  ;
  else
     sprintf(File,"jaso%d",FileNum)   ;
  (*RetCode) = FileCode ;
  return(SUCCESS) ;

}

/*--------------------------------------------------------------------*/
/*                       Jong Dan Ja Uem Process                      */
/*--------------------------------------------------------------------*/
int JongDanProcess()
{int Code ;
 int ans  ;


     Code    = JungSeongFind(JungCode)    ;
     ans     = ChoSeongCodeFind(&ChoCode) ;
     JungSeongCodeFind(&JungCode)         ;
     JongSeongCodeFind(&JongCode)         ;
     if( (ChoCode == 0) && (JungCode == 0) && (JongCode == 0) )
         return(CODE_FILE_ERROR) ;
     switch(Code)
       {  case 1   :
                       ChoFile  = (7*CHONUM) + ChoCode  ;
                       if(ans == AGROUP)
                           {JungFile = (ChoBul*CHONUM) + JUNGNUM + JungCode ;
                            JongFile = (ChoBul*CHONUM) + (JUNGNUM*JungBul) + JongCode ;
                           }
                       else
                           { JungFile = (ChoBul*CHONUM) + JUNGNUM + ASECTION + JungCode ;
                             JongFile = (ChoBul*CHONUM) + (JUNGNUM*JungBul) +
                                        JongBul + JongCode ;
                           }
                       break ;
          case 2 :
                       ChoFile  = (8 * CHONUM) + ChoCode  ;
                       if(ans == AGROUP)
                          {  JungFile = (ChoBul*CHONUM) + JUNGNUM + (ASECTION * 2)  +
                                        JungCode ;
                             JongFile = (ChoBul*CHONUM) + (JUNGNUM*JungBul) + (JongBul*2) +
                                        JongCode ;
                          }
                       else
                          { JungFile = (ChoBul*CHONUM) + (ASECTION*2) + JUNGNUM +
                                       BSECTION + JungCode ;
                            JongFile = (ChoBul*CHONUM) + (JUNGNUM*JungBul) +
                                       (JongBul*3) + JongCode ;
                          }
                       break ;
          case 3 :
                       ChoFile  = ChoCode + (CHONUM*9) ;
                       if(ans == AGROUP)
                          { JungFile = (ChoBul*CHONUM) + (ASECTION*2) + (BSECTION*2) + JUNGNUM +
                                       JungCode ;
                            JongFile = (ChoBul*CHONUM) + (JUNGNUM*JungBul) + (JongBul*4) +
                                       JongCode ;
                         }
                       else
                         { JungFile = (ChoBul*CHONUM) + (ASECTION*2) + (BSECTION*2) + JUNGNUM +
                                      CSECTION + JungCode ;
                           JongFile = (ChoBul*CHONUM) + (JUNGNUM*JungBul) +
                                       (JongBul*5) + JongCode ;
                         }
                       break ;
          case 4 :
                       ChoFile  =  ChoCode + (CHONUM*10)  ;
                       if(ans == AGROUP)
                          {  JungFile = (ChoBul*CHONUM) + (ASECTION*2) + (BSECTION*2) + JUNGNUM +
                                        (CSECTION*2)    + JungCode ;
                             JongFile = (ChoBul*CHONUM) + (JUNGNUM*JungBul) + (JongBul*6) +
                                       JongCode ;
                           }
                       else
                          {  JungFile = (ChoBul*CHONUM) + (ASECTION*2) + (BSECTION*2) + JUNGNUM +
                                        (CSECTION*2) + DSECTION + JungCode ;
                             JongFile = (ChoBul*CHONUM) + (JUNGNUM*JungBul) +
                                        (JongBul*7) + JongCode ;
                           }
                       break ;
          case 5 :
                       ChoFile  =  ChoCode + (CHONUM*11)  ;
                       if(ans == AGROUP)
                           {  JungFile = (ChoBul*CHONUM) + (ASECTION*2) + (BSECTION*2) + JUNGNUM +
                                         (CSECTION*2) + (DSECTION*2)  + JungCode ;
                              JongFile = (ChoBul*CHONUM) + (JUNGNUM*JungBul) + (JongBul*8) +
                                         JongCode ;
                            }

                       else
                           {  JungFile = (ChoBul*CHONUM) + (ASECTION*2) + (BSECTION*2) + JUNGNUM +
                                         (CSECTION*2) + (DSECTION*2) + ESECTION + JungCode ;
                              JongFile = (ChoBul*CHONUM) + (JUNGNUM*JungBul) +
                                         (JongBul*9) + JongCode ;
                           }
                       break ;
         case 6 :
                       ChoFile  =  ChoCode + (CHONUM*12)  ;
                       if(ans == AGROUP)
                           {  JungFile = (ChoBul*CHONUM) + (ASECTION*2) + (BSECTION*2) + JUNGNUM +
                                         (CSECTION*2) + (DSECTION*2) + (ESECTION *2) + JungCode ;
                              JongFile = (ChoBul*CHONUM) + (JUNGNUM*JungBul) + (JongBul*10) +
                                         JongCode ;
                           }
                       else
                          {  JungFile = (ChoBul*CHONUM) + (ASECTION*2) + (BSECTION*2) + JUNGNUM +
                                        (CSECTION*2) + (DSECTION*2) + (ESECTION * 2) +
                                         FSECTION + JungCode ;
                             JongFile = (ChoBul*CHONUM) + (JUNGNUM*JungBul) + (JongBul*11) + JongCode ;
                          }
                       break ;
          case 7 :
                       ChoFile  =  ChoCode + (CHONUM*13) ;
                       if(ans == AGROUP)
                          {  JungFile = (ChoBul*CHONUM) + (ASECTION*2) + (BSECTION*2) + JUNGNUM +
                                        (CSECTION*2) + (DSECTION*2) + (ESECTION *2) +
                                        (FSECTION*2)  + JungCode ;
                             JongFile = (ChoBul*CHONUM) + (JUNGNUM*JungBul) + (JongBul*12) +
                                         JongCode ;
                           }
                       else
                          {  JungFile = (ChoBul*CHONUM) + (ASECTION*2) + (BSECTION*2) + JUNGNUM +
                                        (CSECTION*2) + (DSECTION*2) + (ESECTION*2) +
                                        (FSECTION*3) + JungCode ;
                             JongFile = (ChoBul*CHONUM) + (JUNGNUM*JungBul) +
                                        (JongBul*13) + JongCode ;
                          }
                       break ;
          case -1 : ChoFile = JungFile = JongFile = 0 ;
                     break ;
     }
    if( (ChoFile == 0) && (JungFile == 0) && (JongFile == 0) )
        return(CODE_FILE_ERROR) ;
   return(SUCCESS) ;
}


/*--------------------------------------------------------------------*/
/*                       Jong Bok Ja Uem Process                      */
/*--------------------------------------------------------------------*/
int JongBokProcess()
{int Code ;
 int ans  ;

     Code = JungSeongFind(JungCode)    ;
     ans  = ChoSeongCodeFind(&ChoCode) ;
     JungSeongCodeFind(&JungCode)      ;
     JongSeongCodeFind(&JongCode)      ;
     if( (ChoCode == 0) && (JungCode == 0) && (JongCode == 0) )
       return(CODE_FILE_ERROR) ;
     switch(Code)
       {  case 1 :
                    ChoFile  = (14*CHONUM) + ChoCode  ;
                    if(ans == AGROUP)
                      { JungFile = (ChoBul*CHONUM) + (JUNGNUM*2) + JungCode ;
                        JongFile = (ChoBul*CHONUM) + (JUNGNUM*JungBul) + (JongBul*14) +
                                   JongCode ;
                      }
                     else
                      { JungFile = (ChoBul*CHONUM) + (JUNGNUM*2) + ASECTION + JungCode ;
                        JongFile = (ChoBul*CHONUM) + (JUNGNUM*JungBul) + (JongBul*14) +
                                   TMPNUM + JongCode ;
                      }
                       break ;
          case 2 :
                       ChoFile  = (15 * CHONUM) + ChoCode  ;
                       if(ans == AGROUP)
                          {  JungFile = (ChoBul*CHONUM) + (ASECTION*2) + (JUNGNUM*2) +
                                        JungCode + BSECTION ;
                             JongFile = (ChoBul*CHONUM) + (JUNGNUM*JungBul) + (JongBul*14) + (TMPNUM*2) +
                                        JongCode ;
                          }
                       else
                          { JungFile = (ChoBul*CHONUM) + (ASECTION*2) + (JUNGNUM*2) + BSECTION +
                                       JungCode ;
                            JongFile = (ChoBul*CHONUM) + (JUNGNUM*JungBul) + (JongBul*14) +
                                       (TMPNUM*3) + JongCode ;
                          }
                       break ;
          case 3 :
                       ChoFile  = ChoCode + (CHONUM*16)  ;
                       if(ans == AGROUP)
                          { JungFile = (ChoBul*CHONUM) + (ASECTION*2) + (BSECTION*2) + (JUNGNUM*2) +
                                       JungCode ;
                            JongFile = (ChoBul*CHONUM) + (JUNGNUM*JungBul) + (JongBul*14) + (TMPNUM*4) +
                                       JongCode ;
                         }
                       else
                         { JungFile = (ChoBul*CHONUM) + (ASECTION*2) + (BSECTION*2) + (JUNGNUM*2) +
                                      CSECTION +  JungCode ;
                           JongFile = (ChoBul*CHONUM) + (JUNGNUM*JungBul) + (JongBul*14) + (TMPNUM*5) +
                                       JongCode ;
                         }
                       break ;
          case 4 :
                       ChoFile  =  ChoCode + (CHONUM*17)  ;
                       if(ans == AGROUP)
                          {  JungFile = (ChoBul*CHONUM) + (ASECTION*2) + (BSECTION*2) + (JUNGNUM*2) +
                                        (CSECTION*2) + JungCode ;
                             JongFile = (ChoBul*CHONUM) + (JUNGNUM*JungBul) + (JongBul*14) + (TMPNUM*6) +
                                        JongCode ;
                           }
                       else
                          {  JungFile = (ChoBul*CHONUM) + (ASECTION*2) + (BSECTION*2) + (JUNGNUM*2) +
                                        (CSECTION*2) + DSECTION + JungCode ;
                             JongFile = (ChoBul*CHONUM) + (JUNGNUM*JungBul) + (JongBul*14) + (TMPNUM*7) +
                                        JongCode ;
                           }
                       break ;
          case 5 :
                       ChoFile  =  ChoCode + (CHONUM*18)  ;
                       if(ans == AGROUP)
                           {  JungFile = (ChoBul*CHONUM) + (ASECTION*2) + (BSECTION*2) + (JUNGNUM*2) +
                                         (CSECTION*2) + (DSECTION*2)  + JungCode ;
                              JongFile = (ChoBul*CHONUM) + (JUNGNUM*JungBul) + (JongBul*14) + (TMPNUM*8) +
                                         JongCode ;
                            }
                       else
                           { JungFile = (ChoBul*CHONUM) + (ASECTION*2) + (BSECTION*2) + (JUNGNUM*2) +
                                         (CSECTION*2) + (DSECTION*2) + ESECTION + JungCode ;
                             JongFile = (ChoBul*CHONUM) + (JUNGNUM*JungBul) + (JongBul*14) + (TMPNUM*9) +
                                           JongCode ;
                           }
                       break ;
         case 6 :
                       ChoFile  =  ChoCode + (CHONUM*19)  ;
                       if(ans == AGROUP)
                           {  JungFile = (ChoBul*CHONUM) + (ASECTION*2) + (BSECTION*2) + (JUNGNUM*2) +
                                         (CSECTION*2) + (DSECTION*2) + (ESECTION *2) +
                                         JungCode ;
                              JongFile = (ChoBul*CHONUM) + (JUNGNUM*JungBul) + (JongBul*14) + (TMPNUM*10) +
                                         JongCode ;
                            }
                       else
                          {  JungFile = (ChoBul*CHONUM) + (ASECTION*2) + (BSECTION*2) + (JUNGNUM*2) +
                                        (CSECTION*2) + (DSECTION*2) + (ESECTION *2) +
                                        FSECTION +JungCode ;
                             JongFile = (ChoBul*CHONUM) + (JUNGNUM*JungBul) + (JongBul*14) + (TMPNUM*11) +
                                        JongCode ;
                           }
                       break ;
          case 7 :
                       ChoFile  =  ChoCode + (CHONUM*20) ;
                       if(ans == AGROUP)
                          {  JungFile = (ChoBul*CHONUM) + (ASECTION*2) + (BSECTION*2) + (JUNGNUM*2) +
                                        (CSECTION*2) + (DSECTION*2) + (ESECTION*2) +
                                        (FSECTION*2) +  JungCode ;
                             JongFile = (ChoBul*CHONUM) + (JUNGNUM*JungBul) + (JongBul*14) + (TMPNUM*12) +
                                         JongCode ;
                           }
                       else
                          {  JungFile = (ChoBul*CHONUM) + (ASECTION*2) + (BSECTION*2) + (JUNGNUM*2) +
                                        (CSECTION*2) + (DSECTION*2) + (ESECTION *2) +
                                        (FSECTION*3) + JungCode ;
                             JongFile = (ChoBul*CHONUM) + (JUNGNUM*JungBul) + (JongBul*14) + (TMPNUM*13) +
                                        JongCode ;
                          }
                       break ;
          case -1   : ChoFile = JungFile = JongFile = 0 ;
                     break ;
     }
    if( (ChoFile == 0) && (JungFile == 0) && (JongFile == 0) )
        return(CODE_FILE_ERROR) ;
   return(SUCCESS) ;
}

/*--------------------------------------------------------------------*/
/*                      No JongSeong Code (Fill Code)                 */
/*--------------------------------------------------------------------*/
int NoJongProcess()
{int Code,ans  ;

     Code = JungSeongFind(JungCode)    ;
     ans  = ChoSeongCodeFind(&ChoCode) ;
     JungSeongCodeFind(&JungCode)      ;
     if( (ChoCode == 0) && (JungCode == 0) && (JongCode == 0) )
        return(CODE_FILE_ERROR) ;
     switch(Code)
       {  case 1 :
                     ChoFile  = ChoCode  ;
                     if(ans == AGROUP)
                         JungFile = (ChoBul*CHONUM) + JungCode ;
                     else
                         JungFile = (ChoBul*CHONUM) + ASECTION + JungCode ;
                     JongFile = 0 ;
                     break        ;
          case 2 :
                       ChoFile  =  CHONUM  + ChoCode  ;
                       if(ans == AGROUP)
                          JungFile = (ChoBul*CHONUM) + (ASECTION*2) + JungCode ;
                       else
                         JungFile = (ChoBul*CHONUM)  + (ASECTION*2) + BSECTION + JungCode ;
                       JongFile = 0 ;
                       break ;
          case 3 :
                       ChoFile = ChoCode + (CHONUM*2)    ;
                       if(ans == AGROUP)
                           JungFile = (ChoBul*CHONUM) + (ASECTION*2) + (BSECTION*2)  +
                                      JungCode ;
                       else
                           JungFile = (ChoBul*CHONUM) + (ASECTION*2) + (BSECTION*2)  +
                                      CSECTION +  JungCode ;
                       JongFile = 0 ;
                       break ;
          case 4 :
                       ChoFile  =  ChoCode + (CHONUM*3)  ;
                       if(ans == AGROUP)
                          JungFile = (ChoBul*CHONUM) + (ASECTION*2) + (BSECTION*2) +
                                     (CSECTION*2)  + JungCode ;
                       else
                         JungFile = (ChoBul*CHONUM) + (ASECTION*2) + (BSECTION*2) +
                                    (CSECTION*2) + DSECTION + JungCode ;
                       JongFile = 0 ;
                       break ;
          case 5 :
                       ChoFile  =  ChoCode + ( CHONUM * 4 )  ;
                       if(ans == AGROUP)
                           JungFile = (ChoBul*CHONUM) + (ASECTION*2) + (BSECTION*2) +
                                  (CSECTION*2) + (DSECTION*2) + JungCode ;
                       else
                           JungFile = (ChoBul*CHONUM) + (ASECTION*2) + (BSECTION*2) +
                                  (CSECTION*2) + (DSECTION*2) + ESECTION + JungCode ;
                       JongFile = 0 ;
                       break ;
         case 6 :
                       ChoFile  =  ChoCode + (CHONUM*5)  ;
                       if(ans == AGROUP)
                           JungFile = (ChoBul*CHONUM) + (ASECTION*2) + (BSECTION*2) +
                                      (CSECTION*2) + (DSECTION*2) + (ESECTION *2) +
                                      JungCode ;
                       else
                          JungFile = (ChoBul*CHONUM) + (ASECTION*2) + (BSECTION*2) +
                                     (CSECTION*2) + (DSECTION*2) + (ESECTION *2) +
                                      FSECTION + JungCode ;
                       JongFile = 0 ;
                       break ;
          case 7 :
                       ChoFile  =  ChoCode + (CHONUM*6) ;
                       if(ans == AGROUP)
                          JungFile = (ChoBul*CHONUM) + (ASECTION*2) + (BSECTION*2) +
                                     (CSECTION*2) + (DSECTION*2) + (ESECTION *2) +
                                     (FSECTION*2) +  JungCode ;
                       else
                          JungFile = (ChoBul*CHONUM) + (ASECTION*2) + (BSECTION*2) +
                                     (CSECTION*2) + (DSECTION*2) + (ESECTION *2) +
                                     (FSECTION*3) +  JungCode ;
                       JongFile = 0 ;
                       break ;
        case -1 : ChoFile = JungFile = JongFile = 0 ;
                     break   ;
     }
    if( (ChoFile == 0) && (JungFile == 0) && (JongFile == 0) )
        return(CODE_FILE_ERROR) ;
   return(SUCCESS) ;
}

/*--------------------------------------------------------------------*/
/*                            JungSeong Find                          */
/*--------------------------------------------------------------------*/
int JungSeongFind(Code)
int Code ;
{

   if( (Code == 0x1800) || (Code == 0x2800) ||
       (Code == 0x3800) || (Code == 0x5800) )
     return(1) ;
  else if( (Code == 0x2000) || (Code == 0x3000) ||
           (Code == 0x5000) || (Code == 0x6000) )
     return(2) ;
  else if( (Code == 0x6800) || (Code == 0x9800) ||
           (Code == 0xA000) || (Code == 0xD000) )
     return(3) ;
  else if( (Code == 0x7000) || (Code == 0x9000) ||
           (Code == 0xA800) || (Code == 0xB800) ||
           (Code == 0xE000))
    return(4) ;
 else if( (Code == 0x7800) || (Code == 0xB000))
    return(5) ;
 else if(Code == 0xD800)
    return(6) ;
 else if(Code == 0xE800)
    return(7) ;
 else
    return(-1) ;
}

/*---------------------------------------------------------------------*/
/*                      Cho Seong Code Index Find                      */
/*---------------------------------------------------------------------*/
int ChoSeongCodeFind(Code)
WORD *Code ;
{ int i ;
  WORD TmpCode ;

    TmpCode = *Code ;
    switch(TmpCode)
      { case 0x0088 : *Code = 1 ;
                      break     ;
        case 0x0090 : *Code = 2 ;
                      break     ;
        case 0x0094 : *Code = 3 ;
                      break     ;
        case 0x009C : *Code = 4 ;
                      break     ;
        case 0x00A0 : *Code = 5 ;
                      break     ;
        case 0x00A4 : *Code = 6 ;
                      break     ;
        case 0x00AC : *Code = 7 ;
                      break     ;
        case 0x00B4 : *Code = 8 ;
                      break     ;
        case 0x00B8 : *Code = 9 ;
                      break     ;
        case 0x00C0 : *Code = 10;
                      break     ;
        case 0x00C4 : *Code = 11;
                      break     ;
        case 0x00C8 : *Code = 12;
                      break     ;
        case 0x00CC : *Code = 13;
                      break     ;
        case 0x00D0 : *Code = 14;
                      break     ;
        case 0x008C : *Code = 15;
                      break     ;
        case 0x0098 : *Code = 16;
                      break     ;
        case 0x00A8 : *Code = 17;
                      break     ;
        case 0x00B0 : *Code = 18;
                      break     ;
        case 0x00BC : *Code = 19;
                      break     ;
     }

   if( (TmpCode == 0x008C) || (TmpCode == 0x0098) ||
       (TmpCode == 0x00A8) || (TmpCode == 0x00B0) ||
       (TmpCode == 0x00BC) )
     return(BGROUP) ;
   else
     return(AGROUP) ;
}

/*---------------------------------------------------------------------*/
/*                      Jung Seong Code Index Find                     */
/*---------------------------------------------------------------------*/
int JungSeongCodeFind(Code)
WORD *Code ;
{ int i ;

    switch(*Code)
      { case 0x1800 : *Code = 1 ;
                      break     ;
        case 0x2800 : *Code = 2 ;
                      break     ;
        case 0x3800 : *Code = 3 ;
                      break     ;
        case 0x5800 : *Code = 4 ;
                      break     ;
        case 0x2000 : *Code = 1 ;
                      break     ;
        case 0x3000 : *Code = 2 ;
                      break     ;
        case 0x5000 : *Code = 3 ;
                      break     ;
        case 0x6000 : *Code = 4 ;
                      break     ;
        case 0x6800 : *Code = 1 ;
                      break     ;
        case 0x9800 : *Code = 2 ;
                      break     ;
        case 0xA000 : *Code = 3 ;
                      break     ;
        case 0xD000 : *Code = 4 ;
                      break     ;
        case 0x7000 : *Code = 1 ;
                      break     ;
        case 0x9000 : *Code = 2 ;
                      break     ;
        case 0xA800 : *Code = 3 ;
                      break     ;
        case 0xB800 : *Code = 4 ;
                      break     ;
        case 0xE000 : *Code = 5 ;
                      break     ;
        case 0x7800 : *Code = 1 ;
                      break     ;
        case 0xB000 : *Code = 2 ;
                      break     ;
        case 0xD800 : *Code = 1 ;
                      break     ;
        case 0xE800 : *Code = 1 ;
                      break     ;
     }
}

/*---------------------------------------------------------------------*/
/*                      Jong Seong Code Index Find                     */
/*---------------------------------------------------------------------*/
int JongSeongCodeFind(Code)
WORD *Code ;
{ int i ;

      switch(*Code)
      { case 0x0200 : *Code = 1 ;
                      break     ;
        case 0x0500 : *Code = 2 ;
                      break     ;
        case 0x0800 : *Code = 3 ;
                      break     ;
        case 0x0900 : *Code = 4 ;
                      break     ;
        case 0x1100 : *Code = 5 ;
                      break     ;
        case 0x1300 : *Code = 6 ;
                      break     ;
        case 0x1500 : *Code = 7 ;
                      break     ;
        case 0x1700 : *Code = 8 ;
                      break     ;
        case 0x1800 : *Code = 9 ;
                      break     ;
        case 0x1900 : *Code = 10;
                      break     ;
        case 0x1A00 : *Code = 11;
                      break     ;
        case 0x1B00 : *Code = 12;
                      break     ;
        case 0x1C00 : *Code = 13;
                      break     ;
        case 0x1D00 : *Code = 14;
                      break     ;
        case 0x0300 : *Code = 1 ;
                      break     ;
        case 0x0400 : *Code = 2 ;
                      break     ;
        case 0x0600 : *Code = 3 ;
                      break     ;
        case 0x0700 : *Code = 4 ;
                      break     ;
        case 0x0A00 : *Code = 5 ;
                      break     ;
        case 0x0B00 : *Code = 6 ;
                      break     ;
        case 0x0C00 : *Code = 7 ;
                      break     ;
        case 0x0D00 : *Code = 8 ;
                      break     ;
        case 0x0E00 : *Code = 9 ;
                      break     ;
        case 0x0F00 : *Code = 10;
                      break     ;
        case 0x1000 : *Code = 11;
                      break     ;
        case 0x1400 : *Code = 12;
                      break     ;
        case 0x1600 : *Code = 13;
                      break     ;
     }
}

/*-----------------------------------------------------------------*/
/*                           Jong Bok Find                         */
/*-----------------------------------------------------------------*/
int JongBokFind()
{

     if( (JongCode == 0x0300) || (JongCode == 0x0400) || (JongCode == 0x0600) ||
         (JongCode == 0x0700) || (JongCode == 0x0A00) || (JongCode == 0x0B00) ||
         (JongCode == 0x0C00) || (JongCode == 0x0D00) || (JongCode == 0x0E00) ||
         (JongCode == 0x0F00) || (JongCode == 0x1000) || (JongCode == 0x1400) ||
         (JongCode == 0x1600))
        return(SUCCESS) ;
     else
        return(FAIL)    ;

}

/*-------------------------------------------------------------------*/
/*                           file   create                           */
/*-------------------------------------------------------------------*/
int FileCreate(char *filename)
{int fh ;

  fh = open (filename, O_RDWR | O_CREAT | O_BINARY,S_IREAD | S_IWRITE );
  close(fh) ;
}

