fjstrnse.c
来自「开放源码的编译器open watcom 1.6.0版的源代码」· C语言 代码 · 共 130 行
C
130 行
/****************************************************************************
*
* 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 <string.h>
#include <jstring.h>
#include <jctype.h>
/**
*
* Name: _fjstrnset 暥帤楍偵暥帤傪杽傔傞
*
* Synopsis: p = _fjstrnset( str, c, n );
*
* FJSTRING p; str偲摨偠億僀儞僞
* FJSTRING str; 暥帤傪杽傔傞暥帤楍
* JMOJI c; 杽傔傞暥帤偺抣
* unsigned int n; 暥帤傪杽傔傞挿偝
*
* Description: _fjstrnset娭悢偼暥帤楍str傪堷悢 c 偺抣偱杽傔傑偡丅c 偑娍帤偺
* 応崌丄崅埵俉價僢僩偑丄娍帤偺戞侾僶僀僩偱丄掅埵俉價僢僩偑娍帤偺
* 戞俀僶僀僩偱偡丅戞俀僶僀僩偑 NULL偺応崌丄戞侾僶僀僩傕 NULL
* 偲偟偰埖偄傑偡丅傕偟丄 c 偵侾僶僀僩暥帤傪巜掕偡傞応崌偵偼丄
* 忋埵僶僀僩偼丄侽偵偡傞昁梫偑偁傝傑偡丅n 偺抣偑暥帤楍偺挿偝傛傝
* 戝偒偔丄偐偮丄暥帤楍偺挿偝偑婏悢偺応崌偵偼丄c 偑娍帤偺帪偵偼丄
* 暥帤楍偺嵟屻偺僶僀僩偼0x20偵側傝傑偡丅n 暥帤栚偑娍帤偺戞侾
* 僶僀僩偺応崌丄戞俀僶僀僩傪0x20偵曄峏偟傑偡丅
*
* Returns: _fjstrnset娭悢偼 str 偲摨偠抣傪曉偟傑偡丅
*
*
* Name: _fjstrnset fill the string with a letter
*
* Synopsis: p = _fjstrnset( str, c, n );
*
* FJSTRING p; return value same as "str"
* FJSTRING str; pointer to the string to be filled
* JMOJI c; value of letter
* unsigned int n; length to fill letter
*
* Description: The _fjstrnset function fills the string "str" with the value
* of the argument "c". If you specify "c" with KANJI letter,
* JMOJI consist with 16 bit and its' high byte consist with
* first byte code of KANJI letter, and low byte consist with
* second byte code of KANJI letter.
* If second byte code is NULL then also consider the first byte
* code to NULL. If you specify the 1 byte character code, it must
* be into low byte of JMOJI, and high byte has to consist with
* NULL code.
* If the value of "n" is greater than the length of the string
* then, and if also length of the string is odd number then,
* and if you have specified "c" with KANJI letter then, the last
* byte of string is changed to 0x20.
* Also When the value which "n" points to is the first byte code
* of KANJI letter in the "str" string, the second byte code is
* changed to 0x20. This function is a data independent form that
* accept far pointer argunments. It is most useful in mix memory
* model applications.
*
* Returns: The jstrnset function returns the same value of "str". *
**/
_WCRTLINK FJSTRING _WCI86FAR _fjstrnset( JCHAR _WCFAR *str, JMOJI c, size_t n )
{
JCHAR _WCFAR *dest, _WCFAR *keep = str;
JMOJI c2;
size_t byte, count, len;
if( !n ) return str;
byte = n * ( jiszen( c )?2:1 );
len = _fstrlen( str );
if( len <= byte ) {
if( jiszen( c ) ) {
for( count = 0; count < len/2; count++ ) {
str = _fjputmoji( str, c );
}
if( len & 1 )
*str = ' ';
}
else {
_fmemset( str, c, len );
}
} else {
for( dest = str; dest - str < byte - 1; ) {
dest = _fjgetmoji( dest, (JMOJI _WCFAR *)&c2 );
}
_fjgetmoji( dest, (JMOJI _WCFAR *)&c2 );
if( dest - str != byte && jiszen( c2 ) ) {
*( dest+1 ) = ' ';
}
if( jiszen( c ) ) {
for( count = 0; count < n; count++ ) {
str = _fjputmoji( str, c );
}
} else {
_fmemset( str, c, n );
}
}
return keep;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?