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

📄 xinitct.c

📁 早期freebsd实现
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * $XConsortium: XInitCT.c,v 1.18 92/04/14 15:55:19 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. * *	Authors: Li Yuhong		OMRON Corporation *		 Hiroshi Kuribayashi	OMRON Corporation *    *//*  * This module provides functions operating on the CT(ISO 2022) encoding to * support such conversion functions. * All approved standard CT encodings are stored here, i.e., allocated * to client's memory.  I don't know whether it is suitable or not, because * X server does not provide any propertis for the CT encodings registered * by X consortium. * * by Li Yuhong, Nov. 7, 1990 * */#include "Xlibint.h"#include <X11/Xos.h>#include <X11/Xresource.h>#include "Xlocaleint.h"/* * Font CharSet Name Registered by X Consortium.  * The order is same in page 5 of document, "Compound Text Encoding"*/#define NISO8859_1      "iso8859-1"#define NISO8859_2      "iso8859-2"#define NISO8859_3      "iso8859-3"#define NISO8859_4      "iso8859-4"#define NISO8859_5      "iso8859-5"#define NISO8859_6      "iso8859-6"#define NISO8859_7      "iso8859-7"#define NISO8859_8      "iso8859-8"#define NISO8859_9      "iso8859-9"#define NJISX0201_0     "jisx0201.1976-0"#define NGB2312_0       "gb2312.1980-0"#define NGB2312_1       "gb2312.1980-1"#define NJISX0208_0     "jisx0208.1983-0"#define NJISX0208_1     "jisx0208.1983-1"#define NKSC5601_0      "ksc5601.1987-0"#define NKSC5601_1      "ksc5601.1987-1"#define NISO646_0       "iso646-0"#ifndef OLDJISX0208ONLY#define NNJISX0208_0    "jisx0208.1990-0"#define NNJISX0208_1    "jisx0208.1990-1"#define NNJISX0212_0    "jisx0212.1990-0"#define NNJISX0212_1    "jisx0212.1990-1"#endif/* * Approved Standard Encodings*/#define EISO8859_1L     "\033(B"        /* GL 94 character set */#define EJISX0201_L     "\033(J"        /* GR 94 character set */#define EJISX0201_R     "\033)I"        /* GR 94 character set */#define EISO8859_1R     "\033-A"        /* GR 96 character set */#define EISO8859_2R     "\033-B"#define EISO8859_3R     "\033-C"#define EISO8859_4R     "\033-D"#define EISO8859_7R     "\033-F"#define EISO8859_6R     "\033-G"#define EISO8859_8R     "\033-H"#define EISO8859_5R     "\033-L"#define EISO8859_9R     "\033-M"#define EGB2312_0       "\033$(A"       /* GL 94N character set */#define EGB2312_1       "\033$)A"       /* GR 94N character set */#define EJISX0208_0     "\033$(B"#define EJISX0208_1     "\033$)B"#define EKSC5601_0      "\033$(C"#define EKSC5601_1      "\033$)C"#ifndef OLDJISX0208ONLY#define EJISX0212_0     "\033$(D"#define EJISX0212_1     "\033$)D"#endif#define EISO646_0       EISO8859_1L/* * Add one more for Taiwan. * It would be better to invoke final characters for Taiwan into 03/01 * and 03/02 in accordance with ISO 2022 because it has not registered yet. * However strict CT definition contains the following statements: * *    [Final characters for private encodings (in the range 03/00 to 03/15), *    are not permitted here in Compound Text.]   * * Ooh,Ooh! * So the final characters for Taiwan is defined to 05/01 and 05/02. * * By Li Yuhong, Nov. 20, 1990*/#ifdef	nodef#define NTW2312_1       "tw2312-1.1980-0"#define NTW2312_2       "tw2312-2.1980-0"#define ETW2312_1       "\033$(Y"       /* Taiwan Font1, not registered yet.*/#define ETW2312_2       "\033$(Z"       /* Taiwan Font2, not registered yet.*/#define WTW2312_1       PrivatePlaneLastI11#define WTW2312_2       PrivatePlaneLastI10#endif/* * Offset in 4-byte wchar encoding, referred to 	ISO/IEC DIS 10646 	Infomation technology - Universal Coded Character Set (UCS)*/#define WISO8859_1      0x20202000#define WISO8859_1R     0x20202080/* We use Right half of JISX0201 (Katakana) in   Last rows of Private Use Zone */#define WJISX0201_L     PrivateZoneLast-0x100#define WJISX0201_R     PrivateZoneLast#define WISO8859_2R     0x20202180	/* Row33:Latin Alphabet No.2 */#define WISO8859_3R     0x20202280      /*? not found in DIS 10646 */#define WISO8859_4R     0x20202380      /*? not found in DIS 10646 */#define WISO8859_9R     0x20202480      /*? not found in DIS 10646 */#define WISO8859_5R     0x20202880	/* Row40:Cyrillic*/#define WISO8859_7R     0x20202A80	/* Row42:Greek(little bit diffrent)*/#define WISO8859_6R     0x20202C80	/* Row44:Araabic(little bit diffrent)*/#define WISO8859_8R     0x20202D80	/* Row45:Hebrew(little bit diffrent)*/#define WGB2312		HANZISCRIPT#define WJISX0208	KANJISCRIPT#define WKSC5601	HANJASCRIPT#ifndef OLDJISX0208ONLY#define WJISX0212	0x20408000#endif#define WISO646_0       WISO8859_1/*  * table for registered states, i.e., CT encodings.*/#define MAXISOSTATE     127             /* for 127 countries, enough? */typedef struct {    char     *nstate_name;              /* standard name registered by X */    char     *nstate_encoding;          /* control sequence of CT encoding */    XrmQuark state_name;                /* same as nstate_name, but quark */    XrmQuark state_encoding;            /* same as nstate_encoding, but quark*/    wchar    state_woffset;             /* offset in 4-byte wchar encoding */    int      state_length;              /* number of bytes of encoding */    _CSID     GLorGR;    _CSID     C94orC96;} ISORegisterState;static ISORegisterState *ISOStateTable;static _CSID ISOStateTableNum = 0;#ifndef lintstatic int lock;#endif/* *   Function Name: _XInitCTEncoding() *    Arguments IN: none. *             OUT: none. *          Return: none. *     Description: The function builds the internal table for CT encoding *                  registered by X Consortium.  It will convert string *                  names to quark names, and hire the resource memory *                  to store strings. *                  */void_XInitCTEncoding(){    register ISORegisterState *ptr;    LockMutex(&lock);    if (ISOStateTableNum > 0) {	UnlockMutex(&lock);	return;    /* already initialized */    }    ptr = ISOStateTable = (ISORegisterState *)Xmalloc(MAXISOSTATE *                         sizeof(ISORegisterState));    if (ptr == NULL) {	UnlockMutex(&lock);	return;    }#define RegisterStandard(name, encoding, woffset)			\        ptr->state_name = XrmStringToQuark(name);                       \        ptr->state_encoding = XrmStringToQuark(encoding);               \        ptr->state_woffset = woffset;                                   \        /* hire the resource memory to store the string. */             \        ptr->nstate_name = XrmQuarkToString(ptr->state_name);           \        ptr->nstate_encoding = XrmQuarkToString(ptr->state_encoding);   \        /* only 2 or 1 bytes are supported in X. */                     \        ptr->state_length = (ptr->nstate_encoding[1] == '$')? 2 : 1;    \        ptr->GLorGR = ((_XctisGLdsg(ptr->nstate_encoding)) ? GL: GR);	\	ptr->C94orC96 = (ptr->nstate_encoding[1] == '-') ? C96 : C94;	\        ptr++; ISOStateTableNum++;                                           /*      * sort the table with woffset key, but not done yet.     * So do not change the following order, it decides the previlidge      * as that first match is first got.     */    /* Must Registerate ISO8859-1 GL first */    RegisterStandard(NISO8859_1, EISO8859_1L, WISO8859_1);    /* Must Registerate ISO8859-1 GR second */    RegisterStandard(NISO8859_1, EISO8859_1R, WISO8859_1R);    RegisterStandard(NJISX0208_0,EJISX0208_0, WJISX0208);    RegisterStandard(NJISX0201_0,EJISX0201_R, WJISX0201_R);    RegisterStandard(NJISX0201_0,EJISX0201_L, WJISX0201_L);    RegisterStandard(NGB2312_0,  EGB2312_0,   WGB2312);    RegisterStandard(NKSC5601_0, EKSC5601_0,  WKSC5601);    RegisterStandard(NISO646_0,  EISO646_0,   WISO646_0);    RegisterStandard(NISO8859_2, EISO8859_2R, WISO8859_2R);    RegisterStandard(NISO8859_3, EISO8859_3R, WISO8859_3R);    RegisterStandard(NISO8859_4, EISO8859_4R, WISO8859_4R);    RegisterStandard(NISO8859_9, EISO8859_9R, WISO8859_9R);    RegisterStandard(NISO8859_5, EISO8859_5R, WISO8859_5R);    RegisterStandard(NISO8859_7, EISO8859_7R, WISO8859_7R);    RegisterStandard(NISO8859_6, EISO8859_6R, WISO8859_6R);    RegisterStandard(NISO8859_8, EISO8859_8R, WISO8859_8R);    RegisterStandard(NGB2312_1,  EGB2312_1,   WGB2312);    RegisterStandard(NJISX0208_1,EJISX0208_1, WJISX0208);    RegisterStandard(NKSC5601_1, EKSC5601_1,  WKSC5601);/*    RegisterStandard(NTW2312_1,  ETW2312_1,   WTW2312_1);    RegisterStandard(NTW2312_2,  ETW2312_2,   WTW2312_2);*/#ifndef OLDJISX0208ONLY    RegisterStandard(NNJISX0208_0,EJISX0208_0, WJISX0208);    RegisterStandard(NNJISX0208_1,EJISX0208_1, WJISX0208);    RegisterStandard(NNJISX0212_0,EJISX0212_0, WJISX0212);    RegisterStandard(NNJISX0212_1,EJISX0212_1, WJISX0212);#endif    UnlockMutex(&lock);}/* *   Function Name: _XRegisterCharSet() *    Arguments IN: state_name - name of CharSet. *                  state_encoding - CT encoding, control sequence, *                                   provided by caller. null-terminated. *                  woffset - offset in wchar encoding. *             OUT: none *          Return: True - successful. *                  False -- can not registered state name. *     Description: The function registers a CharSet name into internal *                  table. *                  The control sequence and woffset should not conflict with *                  already registered state. */Bool_XRegisterCharSet(state_name, state_encoding, woffset, GLorGR, bytes)    char *state_name;    char *state_encoding;    wchar woffset;    int GLorGR;    int bytes;{    register ISORegisterState *ptr;    if (ISOStateTableNum >= MAXISOSTATE)        /* over maxinum, unacceptable fact!!! */        return(False);    /*     * Check Correctness. coding in later if this function is necessary.     */    ptr = ISOStateTable + ISOStateTableNum;    ptr->state_name = XrmStringToQuark(state_name);    ptr->state_encoding = XrmStringToQuark(state_encoding);    ptr->state_woffset = woffset;    ptr->nstate_name = XrmQuarkToString(ptr->state_name);    ptr->nstate_encoding = XrmQuarkToString(ptr->state_encoding);    ptr->state_length = bytes;    ptr->GLorGR = GLorGR;    ptr->C94orC96 = (ptr->nstate_encoding[1] == '-') ? C96 : C94;    ptr++; ISOStateTableNum++;    return True;}Bool_XctisGLdsg(dsg)    char *dsg;{    if (*(dsg+1) == '(' || *(dsg+2) == '(')	return (True);    else if (*(dsg+1) == ')' || *(dsg+2) == ')' || *(dsg+1) == '-')	return (False);    else if (*(dsg+1) == '$' &&    		(*(dsg+2) == '@' || *(dsg+2) == 'A' || *(dsg+2) == 'B'))	return (True);    return (False);}/* * The prefix of the following function names "_Xcw" means the functions * operating on the CT and wchar.*//* * _XcwNameGetALL() *   get all items of RegisterTable with the index state_name.*/_CSID_XcwNameGetGLorGRId(state_name, GLorGR)    char       *state_name;    _CSID	GLorGR;{    register XrmQuark		 name;    register ISORegisterState 	*ptr;    register _CSID		 id;    name = XrmStringToQuark(state_name);        for (id = 0, ptr = ISOStateTable; id < ISOStateTableNum; id++, ptr++)        if (name == ptr->state_name) {	    if (ptr->GLorGR != GLorGR)		continue;            return(id);        }    return(ND);}Bool_XcwNameGetAll(state_name, state_encoding, woffset, GLorGR)    char       *state_name;    char      **state_encoding;    wchar      *woffset;    _CSID	GLorGR;{    _CSID	id;    if((id = _XcwNameGetGLorGRId(state_name, GLorGR)) == ND)	return(False);    *woffset = ISOStateTable[id].state_woffset;    *state_encoding = ISOStateTable[id].nstate_encoding;    return(True);}#ifdef not_useBool_XcwNameGetId(xlocale, state_name)    XLocale	 xlocale;    char	*state_name;{    _CSID	 GLorGR;    _CSID	 id;    GLorGR = ctGetGLorGR(xlocale);    if((id = _XcwNameGetGLorGRId(state_name, GLorGR)) == ND)	return(False);    ctSetid(xlocale, id);    return(True);}int_XcwNameGetLength(state_name, GLorGR)    char       *state_name;    _CSID	GLorGR;{    _CSID	id;    if((id = _XcwNameGetGLorGRId(state_name, GLorGR)) == ND)	return (0);    return ISOStateTable[id].state_length;        }Bool_XcwNameGetEncoding(state_name, state_encoding, GLorGR)    char       *state_name;    char      **state_encoding;    _CSID	GLorGR;{    _CSID	id;    if((id = _XcwNameGetGLorGRId(state_name, GLorGR)) == ND)	return(False);    *state_encoding = ISOStateTable[id].nstate_encoding;    return(True);}Bool_XcwNameGetWoffset(state_name, woffset, GLorGR)    char       *state_name;    wchar      *woffset;    _CSID	GLorGR;{    _CSID	id;    if((id = _XcwNameGetGLorGRId(state_name, GLorGR)) == ND)	return(False);    *woffset = ISOStateTable[id].state_woffset;    return(True);}#endif/* * _XcwEscGetAll() *   get all items of ISOStateTable with the index state_encoding.*/static _CSID_XcwEscGetId(state_encoding)    char	*state_encoding;{

⌨️ 快捷键说明

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