nthctype.c
来自「开放源码的编译器open watcom 1.6.0版的源代码」· C语言 代码 · 共 116 行
C
116 行
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
* DESCRIBE IT HERE!
*
****************************************************************************/
#include "variety.h"
#include <jstring.h>
/**
*
* Name: nthctype
*
* Synopsis: ret = nthctype( s, b );
*
* int ret; 僞僀僾
* JSTRING s; 暥帤楍
* int b; 埵抲
*
* Description: 僶僀僩扨埵偺僞僀僾傪挷傋傞丅們倛倠們倲倷倫倕偱偼
* 倣倧倓倕偵侾埲奜偺抣傪梌偊傞偲丄娍帤偺戞侾僶僀僩
* 偐偳偆偐傪挷傋丄戞侾僶僀僩側傜俠俿丵俲俰侾傪曉偟
* 偦傟埲奜側傜偽俠俿丵俙俶俲傪曉偡丅倣倧倓倕偵侾傪
* 梌偊傞偲娍帤偺戞俀僶僀僩偐偳偆偐傪挷傋丄戞俀僶僀
* 僩側傜偽俠俿丵俲俰俀傪曉偟偦傟埲奜側傜偽俠俿丵俬
* 俴俧俴傪曉偡丅
* 値倲倛們倲倷倫倕偼暥帤楍偺愭摢傪侽偲偡傞埵抲倐偵
* 偁傞僶僀僩偵偮偄偰僞僀僾傪挷傋傞丅
*
* Returns: 僰儖暥帤偺応崌偼俠俿丵俬俴俧俴傪曉偡丅
* 値倲倛們倲倷倫倕偱偼埵抲倐傑偱偺娫偵僰儖暥帤偑偁
* 偭偨応崌傕俠俿丵俬俴俧俴傪曉偡丅
* 栠傝抣 抣 堄枴
* CT_ANK 0 ANK乮娍帤埲奜乯
* CT_KJ1 1 娍帤偺戞侾僶僀僩
* CT_KJ2 2 娍帤偺戞俀僶僀僩
* CT_ILGL -1 晄惓
*
*
* Name: nthctype
*
* Synopsis: ret = nthctype( s, b );
*
* int ret; Type
* JSTRING s; String
* int b; Location (The b th byte from the head of s)
*
* Description: Check the type of the b th byte of string s.
* Nthctype uses chkctype which checks whether argument is the
* first byte of KANJI code if mode is except 1. If argument is
* the first byte of KANJI, chkctype returns CT_KJ1, otherwise
* it returns CT_ANK. If mode is 1, chkctype checks whether
* argument is the second byte of KANJI code. If it is the
* second byte, chkctype returns CT_KJ2, otherwise it returns
* CT_ILGL.
* Nthctype checks the b th byte of string.
*
* Returns: If checked character is NULL character, it returns CT_ILGL.
* If nthctype finds NULL character until the b th byte,
* it returns CT_ILGL, too.
* Retrun symbol Value Meanings
* CT_ANK 0 ANK(Except KANJI)
* CT_KJ1 1 The first byte of KANJI
* CT_KJ2 2 The second byte of KANJI
* CT_ILGL -1 Illegal
*
**/
_WCRTLINK int nthctype( const JCHAR *string, size_t nbyte )
{
int ctype;
ctype = CT_ILGL;
/*
// nbyte is now unsigned so following code does not work JBS 92/10/01
while( nbyte-- >= 0 ) {
if( *string == '\0' ) return( CT_ILGL );
ctype = chkctype( *string++, ctype );
}
// following is revised to preserve the sense of the above code
// (i.e., if nbyte==0 we go through the loop once)
*/
do {
if( *string == '\0' ) return( CT_ILGL );
ctype = chkctype( *string++, ctype );
} while( nbyte-- != 0 );
return( ctype );
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?