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

📄 xcnvtostr.c

📁 早期freebsd实现
💻 C
字号:
/* * $XConsortium: XCnvToStr.c,v 1.14 91/05/31 18:57:15 rws Exp $ *//* * Copyright 1990, 1991 by OMRON Corporation, NTT Software Corporation, *                      and Nippon Telegraph and Telephone Corporation * Copyright 1991 by the Massachusetts Institute of Technology * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided that * the above copyright notice appear in all copies and that both that * copyright notice and this permission notice appear in supporting * documentation, and that the names of OMRON, NTT Software, NTT, and M.I.T. * not be used in advertising or publicity pertaining to distribution of the * software without specific, written prior permission. OMRON, NTT Software, * NTT, and M.I.T. make no representations about the suitability of this * software for any purpose.  It is provided "as is" without express or * implied warranty. * * OMRON, NTT SOFTWARE, NTT, AND M.I.T. DISCLAIM ALL WARRANTIES WITH REGARD * TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY * AND FITNESS, IN NO EVENT SHALL OMRON, NTT SOFTWARE, NTT, OR M.I.T. BE * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * *	Author:		 Hiroshi Kuribayashi	OMRON Corporation *    *//* * This files includes 3 functions: *  *      _XConvertWCToString() *      _XConvertMBToString() *	DefaultString() * */#include "Xlibint.h"#include "Xlocaleint.h"#include <X11/Xos.h>/* * Constant Definitions*/#define HT                  0x09        /* horizontal tab */#define NL                  0x0A        /* new line */char *XDefaultString(){    return("");}/* partial conversion from WC to Xstring */int_XConvertWCToString(wc_str, wc_len, string, str_len, scanned_len)    wchar	       *wc_str;    int			wc_len;    unsigned char      *string;    int		       *str_len;    int		       *scanned_len;{    int			limit;    wchar		wc;    unsigned char	group;    limit = *str_len;    (*scanned_len) = (*str_len) = 0;    while (wc_len > 0 && (wc = *wc_str) != WNULL) {	if ((*str_len) >= limit) {            return(BadBuffer);	}	if (((wc) & SCRIPT1) == LATINSCRIPT ||	    ((wc) & CONTROLSCRIPT) == CLPADPADPAD &&		((group = wgetgroup(wc)) == HT ||		group == NL)) {	    *string++ = _Xwctoa(wc);	    (*str_len)++;	}        wc_str++, wc_len--, (*scanned_len)++;    }    if ((*str_len) < limit)	*string = 0;    return(Success);}#define Return(result)  {                                               \	*ct_bytes = ctcnt;                                              \	*scanned_bytes = mbcnt;                                         \	if (ctcnt < limit)                                              \	    *ct_str = 0;        /* additional service */                \	return (result);                                                \    }#define SaveStore(c) {                                                  \	if (ctcnt >= limit) Return(BadBuffer);                          \	*ct_str++ = c;                                                  \	ctcnt++;                                                        \    }int_XConvertMBToString(mb_str, mb_bytes, ct_str, ct_bytes, scanned_bytes)    unsigned char   *mb_str;    int              mb_bytes;    unsigned char   *ct_str;    int             *ct_bytes;    int             *scanned_bytes;{    XLocale	xlocale;    _CSID	ctid, csid;    int         mbcnt, ctcnt;    int         limit, len;    unsigned char       c;    int		code;    xlocale = _XFallBackConvert();    _Xmbinit(xlocale);    _Xctinit(xlocale);    limit = *ct_bytes;    mbcnt = ctcnt = 0;    while (mb_bytes > 0 && (c = *mb_str) != 0) {	if ((csid = _Xmbcsid(xlocale, mb_str)) == ND)	    Return(BadEncoding);	if (_Xmbtype(xlocale) == CDS_STATEFUL &&	    (len = _Xmbdlen(xlocale, mb_str)) > 0) {	    /* skip designation sequence */	    mbcnt += len; mb_str += len, mb_bytes -= len;	    continue;	}	ctid = _Xmbctid(xlocale, csid);	if (ctid == CODESET0 || ctid == CODESET1) {	    if (_Xmbctocsc(xlocale, mb_str, &code) < 0) {		mbcnt++; mb_str++; mb_bytes--;		Return (BadEncoding);	    }	    SaveStore(code);	    mbcnt++; mb_str++; mb_bytes--;	    continue;	} else if (csid == C0) {	    if (c == HT || c == NL) {		SaveStore(c);	    }	    mbcnt++; mb_str++, mb_bytes--;	    continue;	} else {	    len = _Xmblen(xlocale);	    mbcnt += len; mb_str += len; mb_bytes -= len;	}    }    Return(Success);}

⌨️ 快捷键说明

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