⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 kanji.c

📁 MC Linux/Unix 终端下文件管理器
💻 C
📖 第 1 页 / 共 3 页
字号:
/*    Unix SMB/Netbios implementation.   Version 1.9.   Kanji Extensions   Copyright (C) Andrew Tridgell 1992-1998      This program is free software; you can redistribute it and/or modify   it under the terms of the GNU General Public License as published by   the Free Software Foundation; either version 2 of the License, or   (at your option) any later version.      This program is distributed in the hope that it will be useful,   but WITHOUT ANY WARRANTY; without even the implied warranty of   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the   GNU General Public License for more details.      You should have received a copy of the GNU General Public License   along with this program; if not, write to the Free Software   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.   Adding for Japanese language by <fujita@ainix.isac.co.jp> 1994.9.5     and extend coding system to EUC/SJIS/JIS/HEX at 1994.10.11     and add all jis codes sequence type at 1995.8.16     Notes: Hexadecimal code by <ohki@gssm.otuka.tsukuba.ac.jp>*/#define _KANJI_C_#include "includes.h"/* * Function pointers that get overridden when multi-byte code pages * are loaded. */const char *(*multibyte_strchr)(const char *, int ) = (const char *(*)(const char *, int )) strchr;const char *(*multibyte_strrchr)(const char *, int ) = (const char *(*)(const char *, int )) strrchr;const char *(*multibyte_strstr)(const char *, const char *) = (const char *(*)(const char *, const char *)) strstr;char *(*multibyte_strtok)(char *, const char *) = (char *(*)(char *, const char *)) strtok;/* * Kanji is treated differently here due to historical accident of * it being the first non-English codepage added to Samba. * The define 'KANJI' is being overloaded to mean 'use kanji codepage * by default' and also 'this is the filename-to-disk conversion  * method to use'. This really should be removed and all control * over this left in the smb.conf parameters 'client codepage' * and 'coding system'. */#ifndef KANJI/* * Set the default conversion to be the functions in * charcnv.c. */static size_t skip_non_multibyte_char(char);static BOOL not_multibyte_char_1(char);char *(*_dos_to_unix)(char *, BOOL) = dos2unix_format;char *(*_unix_to_dos)(char *, BOOL) = unix2dos_format;size_t (*_skip_multibyte_char)(char) = skip_non_multibyte_char;BOOL (*is_multibyte_char_1)(char) = not_multibyte_char_1;#else /* KANJI *//* * Set the default conversion to be the function * sj_to_sj in this file. */static char *sj_to_sj(char *from, BOOL overwrite);static size_t skip_kanji_multibyte_char(char);static BOOL is_kanji_multibyte_char_1(char);char *(*_dos_to_unix)(char *, BOOL) = sj_to_sj;char *(*_unix_to_dos)(char *, BOOL) = sj_to_sj;size_t (*_skip_multibyte_char)(char) = skip_kanji_multibyte_char;int (*is_multibyte_char_1)(char) = is_kanji_multibyte_char_1;#endif /* KANJI *//* jis si/so sequence */static char jis_kso = JIS_KSO;static char jis_ksi = JIS_KSI;static char hex_tag = HEXTAG;/*******************************************************************  SHIFT JIS functions********************************************************************//******************************************************************* search token from S1 separated any char of S2 S1 contains SHIFT JIS chars.********************************************************************/static char *sj_strtok(char *s1, const char *s2){  static char *s = NULL;  char *q;  if (!s1) {    if (!s) {      return NULL;    }    s1 = s;  }  for (q = s1; *s1; ) {    if (is_shift_jis (*s1)) {      s1 += 2;    } else if (is_kana (*s1)) {      s1++;    } else {      char *p = strchr (s2, *s1);      if (p) {        if (s1 != q) {          s = s1 + 1;          *s1 = '\0';          return q;        }        q = s1 + 1;      }      s1++;    }  }  s = NULL;  if (*q) {    return q;  }  return NULL;}/******************************************************************* search string S2 from S1 S1 contains SHIFT JIS chars.********************************************************************/static const char *sj_strstr(const char *s1, const char *s2){  size_t len = strlen (s2);  if (!*s2)     return (const char *) s1;  for (;*s1;) {    if (*s1 == *s2) {      if (strncmp (s1, s2, len) == 0)        return (const char *) s1;    }    if (is_shift_jis (*s1)) {      s1 += 2;    } else {      s1++;    }  }  return NULL;}/******************************************************************* Search char C from beginning of S. S contains SHIFT JIS chars.********************************************************************/static const char *sj_strchr (const char *s, int c){  for (; *s; ) {    if (*s == c)      return (const char *) s;    if (is_shift_jis (*s)) {      s += 2;    } else {      s++;    }  }  return NULL;}/******************************************************************* Search char C end of S. S contains SHIFT JIS chars.********************************************************************/static const char *sj_strrchr(const char *s, int c){  const char *q;  for (q = 0; *s; ) {    if (*s == c) {      q = (const char *) s;    }    if (is_shift_jis (*s)) {      s += 2;    } else {      s++;    }  }  return q;}/******************************************************************* Kanji multibyte char skip function.*******************************************************************/   static size_t skip_kanji_multibyte_char(char c){  if(is_shift_jis(c)) {    return 2;  } else if (is_kana(c)) {    return 1;  }  return 0;}/******************************************************************* Kanji multibyte char identification.*******************************************************************/   static BOOL is_kanji_multibyte_char_1(char c){  return is_shift_jis(c);}/******************************************************************* The following functions are the only ones needed to do multibyte support for Hangul, Big5 and Simplified Chinese. Most of the real work for these codepages is done in the generic multibyte functions. The only reason these functions are needed at all is that the is_xxx(c) calls are really preprocessor macros.********************************************************************//*******************************************************************  Hangul (Korean - code page 949) function.********************************************************************/static BOOL hangul_is_multibyte_char_1(char c){  return is_hangul(c);}/*******************************************************************  Big5 Traditional Chinese (code page 950) function.********************************************************************/static BOOL big5_is_multibyte_char_1(char c){  return is_big5_c1(c);}/*******************************************************************  Simplified Chinese (code page 936) function.********************************************************************/static BOOL simpch_is_multibyte_char_1(char c){  return is_simpch_c1(c);}/*******************************************************************  Generic multibyte functions - used by Hangul, Big5 and Simplified  Chinese codepages.********************************************************************//******************************************************************* search token from S1 separated any char of S2 S1 contains generic multibyte chars.********************************************************************/static char *generic_multibyte_strtok(char *s1, const char *s2){  static char *s = NULL;  char *q;  if (!s1) {    if (!s) {      return NULL;    }    s1 = s;  }  for (q = s1; *s1; ) {    if ((*is_multibyte_char_1)(*s1)) {        s1 += 2;    } else {      char *p = strchr (s2, *s1);      if (p) {        if (s1 != q) {          s = s1 + 1;          *s1 = '\0';          return q;        }        q = s1 + 1;      }    s1++;    }  }  s = NULL;  if (*q) {    return q;  }  return NULL;}/******************************************************************* search string S2 from S1 S1 contains generic multibyte chars.********************************************************************/static const char *generic_multibyte_strstr(const char *s1, const char *s2){  size_t len = strlen (s2);  if (!*s2)    return (const char *) s1;  for (;*s1;) {    if (*s1 == *s2) {      if (strncmp (s1, s2, len) == 0)        return (const char *) s1;    }    if ((*is_multibyte_char_1)(*s1)) {      s1 += 2;    } else {      s1++;    }  }  return NULL;}/******************************************************************* Search char C from beginning of S. S contains generic multibyte chars.********************************************************************/static const char *generic_multibyte_strchr(const char *s, int c){  for (; *s; ) {    if (*s == c)      return (const char *) s;    if ((*is_multibyte_char_1)(*s)) {      s += 2;    } else {      s++;    }  }  return NULL;}/******************************************************************* Search char C end of S. S contains generic multibyte chars.********************************************************************/static const char *generic_multibyte_strrchr(const char *s, int c){  const char *q;   for (q = 0; *s; ) {    if (*s == c) {      q = (const char *) s;    }    if ((*is_multibyte_char_1)(*s)) {      s += 2;    } else {      s++;    }  }  return q;}/******************************************************************* Generic multibyte char skip function.*******************************************************************/static size_t skip_generic_multibyte_char(char c){  if( (*is_multibyte_char_1)(c)) {    return 2;  }  return 0;}/*******************************************************************  Code conversion********************************************************************//* convesion buffer */static char cvtbuf[1024];/*******************************************************************  EUC <-> SJIS********************************************************************/static int euc2sjis (int hi, int lo){  if (hi & 1)    return ((hi / 2 + (hi < 0xdf ? 0x31 : 0x71)) << 8) |            (lo - (lo >= 0xe0 ? 0x60 : 0x61));  else    return ((hi / 2 + (hi < 0xdf ? 0x30 : 0x70)) << 8) | (lo - 2);}static int sjis2euc (int hi, int lo){  if (lo >= 0x9f)    return ((hi * 2 - (hi >= 0xe0 ? 0xe0 : 0x60)) << 8) | (lo + 2);  else    return ((hi * 2 - (hi >= 0xe0 ? 0xe1 : 0x61)) << 8) |            (lo + (lo >= 0x7f ? 0x60 : 0x61));}/******************************************************************* Convert FROM contain SHIFT JIS codes to EUC codes return converted buffer********************************************************************/static char *sj_to_euc(char *from, BOOL overwrite){  char *out;  char *save;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -