home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / lib / libi18n / autokr.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  2.6 KB  |  81 lines

  1. /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18. /*    autokr.c    */
  19.  
  20. #include "intlpriv.h"
  21. #include "xp.h"
  22. #include "libi18n.h"
  23.  
  24. MODULE_PRIVATE int16 intl_detect_KCSID( uint16 defaultCSID, const unsigned char *buf, int32 len )
  25. {
  26.     register const unsigned char    *cp = buf;
  27.     /* CS_2022_KR is 7bit. Scan to end of 7bit data or legitimate KOREAN ESC sequence. */
  28.     while( len && !( *cp & 0x80 ) ){
  29.         /* CS_2022_KR  ESC $ ) C */
  30.         if(( cp[0] == ESC && len > 3 && ( cp[1] == '$' && cp[2] == ')' && cp[3] == 'C' ) ) ||
  31.             (SI == *cp) || (SO == *cp) )
  32.             return CS_2022_KR;
  33.         cp++, len--;
  34.     }
  35.  
  36.     if( len > 0 )   return CS_KSC_8BIT;        /* it is not Roman */
  37.  
  38.     return CS_ASCII;                        /* Could be any of the 3... */
  39. }
  40.  
  41.  
  42.  
  43. /* Auto Detect Korean Char Code Conversion    : jliu */
  44. MODULE_PRIVATE unsigned char *
  45. autoKCCC (CCCDataObject obj, const unsigned char *s, int32 l)
  46. {
  47.     int16 doc_csid = 0;
  48.  
  49.     /* Use 1st stream data block to guess doc Korean CSID.    */
  50.     doc_csid = intl_detect_KCSID (INTL_GetCCCDefaultCSID(obj),(const unsigned char *) s, l);
  51.  
  52.     if( doc_csid == CS_ASCII ){    /* return s unconverted and                */
  53.         INTL_SetCCCLen(obj, l);
  54.         return (unsigned char *)s;                /* autodetect next block of stream data    */
  55.     }
  56.  
  57.         /* Setup converter function for success streams data blocks    */
  58.     
  59.     (void)INTL_GetCharCodeConverter( doc_csid, INTL_GetCCCToCSID(obj), obj );
  60.     INTL_CallCCCReportAutoDetect(obj, doc_csid);
  61.     
  62.     
  63.     /* If no conversion needed, change put_block module for successive
  64.      * data blocks.  For current data block, return unmodified buffer.
  65.      */
  66.     if (INTL_GetCCCCvtfunc(obj) == NULL) {
  67.         INTL_SetCCCLen(obj, l);
  68.         return((unsigned char *) s);
  69.     }
  70.     /* For initial block, must call converter directly.  Success calls
  71.      * to the converter will be called directly from net_CharCodeConv()
  72.      */
  73.     return (unsigned char *)(INTL_GetCCCCvtfunc(obj)) (obj, (const unsigned char*)s, l);
  74. }
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81.