BSD 4_4_Lite2 development
authorCSRG <csrg@ucbvax.Berkeley.EDU>
Sat, 17 Apr 1993 13:19:44 +0000 (05:19 -0800)
committerCSRG <csrg@ucbvax.Berkeley.EDU>
Sat, 17 Apr 1993 13:19:44 +0000 (05:19 -0800)
Work on file usr/src/contrib/X11R5-lib/lib/X/Xsi/XmbTextPrp.c
Work on file usr/src/contrib/X11R5-lib/lib/X/Xsi/XCnvCTToWC.c
Work on file usr/src/contrib/X11R5-lib/lib/X/Xsi/XwcPrpText.c
Work on file usr/src/contrib/X11R5-lib/lib/X/Xsi/XwcTextPrp.c
Work on file usr/src/contrib/X11R5-lib/lib/X/Xsi/XmbPrpText.c
Work on file usr/src/contrib/X11R5-lib/lib/X/Xsi/XGetIMVal.c
Work on file usr/src/contrib/X11R5-lib/lib/X/Xsi/XICGetVal.c

Synthesized-from: CSRG/cd3/4.4BSD-Lite2

usr/src/contrib/X11R5-lib/lib/X/Xsi/XCnvCTToWC.c [new file with mode: 0644]
usr/src/contrib/X11R5-lib/lib/X/Xsi/XGetIMVal.c [new file with mode: 0644]
usr/src/contrib/X11R5-lib/lib/X/Xsi/XICGetVal.c [new file with mode: 0644]
usr/src/contrib/X11R5-lib/lib/X/Xsi/XmbPrpText.c [new file with mode: 0644]
usr/src/contrib/X11R5-lib/lib/X/Xsi/XmbTextPrp.c [new file with mode: 0644]
usr/src/contrib/X11R5-lib/lib/X/Xsi/XwcPrpText.c [new file with mode: 0644]
usr/src/contrib/X11R5-lib/lib/X/Xsi/XwcTextPrp.c [new file with mode: 0644]

diff --git a/usr/src/contrib/X11R5-lib/lib/X/Xsi/XCnvCTToWC.c b/usr/src/contrib/X11R5-lib/lib/X/Xsi/XCnvCTToWC.c
new file mode 100644 (file)
index 0000000..f8f8c08
--- /dev/null
@@ -0,0 +1,472 @@
+/*
+ * $XConsortium: XCnvCTToWC.c,v 1.22 91/11/17 16:15:29 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 files includes 2 functions:
+ * 
+ *      _XConvertCTToWC()
+ *      _XConvertWCToCT()
+ * 
+*/
+#include "Xlibint.h"
+#include "Xlocaleint.h"
+#include <X11/Xos.h>
+#include <X11/Xutil.h>
+
+static int _XConvertCTextToWC();
+extern int _XParseISOEncoding();
+extern Bool _XcwEscSetStatus();
+extern void _XwcSetCsid();
+
+/*
+ *          Function Name: _XConvertCTToWC
+ *
+*/
+
+/*
+ * Constant Definitions
+*/
+#define HT                  0x09        /* horizontal tab */
+#define NL                  0x0A        /* new line */
+#define ESC                 0x1B        /* escape */
+#define CSI                 0x9B        /* control sequence introducer. */
+#define SPACE               0x20        /* space */
+#define GL94MIN             0x21        /* manimun of code of GL 94 charset */  
+#define GL94MAX             0x7E        /* maximun of code of GL 94 charset */
+
+/* 
+ * Macro Procedure Definitions
+*/
+/* 
+ * Return():
+ *   set result values before funciton returns.
+ *   If there is more room for output buffer wc_str, provide additional
+ *    service, i.e., append WNULL at tail.
+*/
+#define Return(result) {                                                \
+        *wc_len = wcnt;                                                 \
+        *scanned_bytes = ctcnt;                                         \
+        if (wcnt < limit) *wc_str = WNULL;                              \
+       if (state) *state = xlocale->ct_state;                          \
+        if (error > 0) return(error);                                   \
+        return(result);                                                 \
+    }
+
+/*
+ * SaveStore():
+ *   store converted wchar code to buffer, and make sure no overflow.
+*/
+#define SaveStore(wc) {                                                 \
+        if (wcnt >= limit)                                              \
+            Return(BadBuffer);                                         \
+        *wc_str++ = wc;                                                 \
+        wcnt++;                                                         \
+    }
+
+/*
+ * CombineCode():
+ *   concatenate the byte with code if the byte is valid.
+*/
+#define CombineCode(code) {                                             \
+        if (byte < stateinfo.code_min || byte > stateinfo.code_max) {   \
+            error++;                                                    \
+            byte = stateinfo.code_min;                                  \
+        }                                                               \
+        code = (code << 8) | byte;                                      \
+        ct_str++, ct_bytes--;                                           \
+        if (ct_bytes < 1)                                               \
+            Return(BadTerminate);                                       \
+        byte = *ct_str;                                                 \
+    }
+
+int
+_XConvertCTToWC(xlocale, ct_str, ct_bytes, wc_str, wc_len, scanned_bytes, state)
+    XLocale            xlocale;
+    unsigned char      *ct_str;
+    int                        ct_bytes;
+    wchar             *wc_str;
+    int                       *wc_len;
+    int                       *scanned_bytes;
+    _State            *state;
+{
+    register unsigned char     byte;
+    register unsigned int      code;
+    wchar                      woffset;
+    int                                wcnt, ctcnt, limit, len;
+    ISOStateInfo               stateinfo;
+    char                       seq[MAXSEQUENCELENGTH];
+    int                                error = 0;
+
+    if (!xlocale)
+       xlocale = _XFallBackConvert();
+    if (state && *state != XDEFAULT_STATE) {
+       xlocale->ct_state = *state;
+       if (_XcwIdCheck(xlocale) == False)
+           _Xctinit(xlocale);
+    } else
+       _Xctinit(xlocale);
+
+    limit = *wc_len;
+    wcnt = ctcnt = 0;
+    while (ct_bytes > 0 && (byte = *ct_str) != 0) {
+        switch (byte) {
+          case HT:
+          case NL:
+          case SPACE:
+            SaveStore(_Xatowc(byte));
+            ct_str++, ct_bytes--, ctcnt++;
+            continue;
+          case CSI:
+            /* not supported yet */
+          case ESC:
+            /* parse the control escape sequence of CT encoding. */
+            switch (_XParseISOEncoding(ct_str, ct_bytes, &len, &stateinfo)) {
+              case Success:
+               if (*(ct_str+1) == 0x25) {
+                   /* Extend segmant */
+                   int tmplen = limit - wcnt;
+                   int ret;
+                   if((ret = _XConvertCTextToWC(xlocale, ct_str, ct_bytes,
+                                           wc_str, &tmplen, &len)) < 0)
+                       Return(ret);
+                   wc_str += tmplen;
+                   wcnt +=tmplen;
+                   ct_str += len, ct_bytes -= len, ctcnt += len;
+                   continue;
+               }
+                /*
+                 * In mose case the control sequence is new one, so we 
+                 * set it to current state directly, enhance little speed
+                 * without no comparision. 
+                 * 
+                */
+               (void) strncpy(seq, (char *)ct_str, len);
+                seq[len] = '\0';
+                if (_XcwEscSetStatus(xlocale, seq) == True) {
+                    ct_str += len, ct_bytes -= len;
+                    ctcnt += len;
+                    continue;
+                }
+                /*
+                 * Actually, it is not registered encoding, can not be
+                 * recognized by this convertor. go to next step.
+                */
+              case BadEncoding:
+                /*
+                 * wrong escape sequence, the function can not recover
+                 * this error, return it.   
+                */
+                Return(BadEncoding);
+              case BadTerminate:
+                Return(BadTerminate);
+              default:  /* never go to here */
+                Return(BadEncoding);
+                ;
+            }   
+          default:
+            /* get codepoint of character. */
+           ctSetGLorGR(xlocale, byte&0x80);
+           _XcwIdGetAll(xlocale, &woffset, &stateinfo);
+            code = 0; 
+            switch (stateinfo.code_bytes) {
+              case 4:
+                    CombineCode(code);
+              case 3:
+                    CombineCode(code);
+              case 2:
+                    CombineCode(code);
+              case 1:
+                   if (byte < stateinfo.code_min ||
+                       byte > stateinfo.code_max) {
+                       error++;
+                       byte = stateinfo.code_min;
+                   }
+                   code = (code << 8) | byte;
+                    ct_str++, ct_bytes--;
+                   code &= 0x7f7f7f7f; /* MSB off */
+                    break;
+            }
+            SaveStore(woffset | code);
+            /*
+             * after no any error, then advance scanned_bytes 
+             * "ctcnt".
+            */
+            ctcnt += stateinfo.code_bytes;
+            continue;
+        }
+    } 
+    Return(Success);
+}
+
+/*
+ *          Function Name: _XConvertWCToCT
+ *
+*/
+#undef Return
+#undef SaveStore
+
+#define Return(result) {                                                \
+        *ct_bytes = ctcnt;                                              \
+        *scanned_len = wcnt;                                            \
+       if (ctcnt < limit)                                              \
+           *ct_str = 0;                                                \
+        if (error > 0) return(error);                                   \
+        return(result);                                                 \
+    }
+
+#define SaveStore(c)   {                                                \
+       if (ctcnt >= limit) Return(BadBuffer);                           \
+       *ct_str++ = c;                                                   \
+       ctcnt++;                                                         \
+    }
+
+#define AppendDesignation(state) {                                      \
+        int len = strlen(state);                                        \
+        if ((ctcnt + len) > limit)                                      \
+           Return(BadBuffer);                                           \
+        (void) strcpy((char *)ct_str, state);                           \
+        ct_str += len;                                                  \
+        ctcnt += len;                                                   \
+    }
+     
+
+int
+_XConvertWCToCT(xlocale, wc_str, wc_len, ct_str, ct_bytes, scanned_len)
+    XLocale            xlocale;
+    wchar             *wc_str;
+    int                        wc_len;
+    unsigned char      *ct_str;
+    int                       *ct_bytes;
+    int                       *scanned_len;
+{
+    char              *esc, seq[MAXSEQUENCELENGTH];
+    wchar              woffset, wc;
+    int                        wcnt, ctcnt, crwcnt, crctcnt, limit;
+    int                        ret, error = 0;
+    ISOStateInfo       stateinfo;
+    _State             state_sv, state_ext;
+    unsigned char      *ct_str_sv = NULL;
+    int len_sv;
+    char *defstr = XDefaultString();
+
+    if (!xlocale)
+       xlocale = _XFallBackConvert();
+
+    _Xctinit(xlocale);
+    state_sv = xlocale->ct_state;
+    limit = *ct_bytes;
+    wcnt = ctcnt = 0;
+    while ((wc_len > 0) && ((wc = *wc_str) != WNULL)) {
+       _CSID   ctGLorGR;
+        /*
+         * filter control characters. 
+        */
+        if (_Xiswcntrl(wc)) {
+            SaveStore(_Xwctoa(wc));
+            wc_str++, wc_len--, wcnt++;
+            continue;
+        }
+        _XcwGetAll(xlocale, wc, &esc, &woffset, &stateinfo);
+       if (woffset == 0) {
+           int i;
+           /* XXX BUG: need to check/add designate sequence of default string.
+              But current default string is NULL, so OK. :-) */
+           for (i = 0; *(defstr + i) != 0; i++) {
+               SaveStore(*(defstr + i))
+           }
+           error++;
+           wc_str++, wc_len--, wcnt++;
+            continue;
+       }
+        if ((ctGLorGR = ctGetGLorGR(xlocale)) == GL &&
+               ctGetGLid(xlocale) != (state_sv & 0xff) ||
+           ctGLorGR == GR &&
+               ctGetGRid(xlocale) != ((state_sv >> 8) & 0xff)) {
+           state_ext = state_sv;
+           state_sv = xlocale->ct_state;
+            /*
+             * append designation of control sequence.
+            */
+           if (*(esc+1) == 0x25) {
+               ct_str_sv = ct_str + 4;
+               len_sv = strlen(esc) - 6;
+           }
+            AppendDesignation(esc);
+        }
+        /* 
+         * remainning buffer length of ct_str.
+        */
+        crctcnt = limit - ctcnt;
+        if ((ret = _XwcDecomposeGlyphCharset(xlocale, wc_str, wc_len, ct_str,
+               &crctcnt, &crwcnt, (int *)NULL)) < 0)
+            Return(ret);
+       if (ct_str_sv) {
+           *ct_str_sv++ = (crctcnt + len_sv) / 128 + 128;
+           *ct_str_sv = (crctcnt + len_sv) % 128 +128;
+           ct_str_sv = NULL;
+           xlocale->ct_state = state_ext;
+           state_sv = state_ext;
+       }
+        error += ret;
+        wc_str += crwcnt, wc_len -= crwcnt, wcnt += crwcnt;
+        ct_str += crctcnt, ctcnt += crctcnt;
+    }
+    if (!_XcwCheckDefaultState(xlocale)) {
+        (void) _XcwGetDefaultEncoding(xlocale, seq);
+        AppendDesignation(seq);
+       _Xctinit(xlocale);
+    }
+    Return(Success);
+}
+
+int
+_XctIsExtendSegment(xlocale, ct_str, textlen, bytes)
+XLocale xlocale;
+unsigned char *ct_str;
+int *textlen;
+int *bytes;
+{
+    unsigned char *text;
+    int seqlen;
+    unsigned char name[128];
+    _CSID csid;
+    int m, l;
+
+    if(*(ct_str+1) != 0x25 || *(ct_str+2) != 0x2f)
+       return (0);     /* Not CT Extend Segment */
+    *bytes = *(ct_str+3) -'0';
+    if (*bytes < 0 || *bytes > 4)
+       return (0);     /* Not CT Extend Segment */
+    else if (*bytes == 0)
+       /* I'm not sure. Valiable octes pre char cannot convert */
+       *bytes = 1;
+
+
+    text = (unsigned char *)index((char *)ct_str+6, 0x02) + 1;
+    m = *(ct_str+4);
+    l = *(ct_str+5);
+    seqlen = text - ct_str;
+
+    strncpy((char *)name, (char *)ct_str+6, seqlen - 6);
+    name[seqlen - 7] =0;
+    csid = _XcwNameGetGLorGRId(name, *(text+1) & 0x80);
+    ctSetGLorGR(xlocale, *(text+1) & 0x80);
+    ctSetid(xlocale, csid);
+
+    *textlen = (m-128)*128+(l-128) + 5 - seqlen + 1;   /* !!!!! */
+    return(seqlen);
+}
+
+#undef Return
+#undef SaveStore
+#undef CombineCode
+
+#define Return(result) {                                                \
+        *wc_bytes = wccnt;                                              \
+        *scanned_bytes = ctcnt;                                         \
+       if (wccnt < limit)                                              \
+           *wc_str = 0;                                                \
+        if (error > 0) return (error);                                  \
+        return (result);                                                \
+    }
+
+#define SaveStore(wc) {                                                 \
+        if (wccnt >= limit) Return(BadBuffer);                          \
+        *wc_str++ = wc;                                                 \
+        wccnt++;                                                        \
+    }
+
+/*
+ * CombineCode():
+ *   concatenate the byte with code if the byte is valid.
+*/
+#define CombineCode(code) {                                             \
+        code = (code << 8) | byte;                                      \
+        ct_str++; ct_bytes--;                                          \
+        if (ct_bytes < 1)                                               \
+            Return(BadTerminate);                                       \
+        byte = *ct_str;                                                 \
+    }
+
+static int
+_XConvertCTextToWC(xlocale, ct_str, ct_bytes, wc_str, wc_bytes, scanned_bytes)
+    XLocale xlocale;
+    unsigned char   *ct_str;
+    int              ct_bytes;
+    wchar          *wc_str;
+    int             *wc_bytes;
+    int             *scanned_bytes;
+{
+    register unsigned char byte;
+    int         wccnt, ctcnt;
+    int         code, len, limit, error;
+    int textlen;
+    int bytes;
+    _State state_sv;
+    wchar woffset;
+
+    state_sv = xlocale->ct_state;
+    limit = *wc_bytes;
+    wccnt = ctcnt = error = 0;
+
+    if((len = _XctIsExtendSegment(xlocale, ct_str, &textlen, &bytes)) < 0)
+       /* not register encoding by X. */
+       Return(BadEncoding);
+    ct_str += len; ctcnt += len; ct_bytes -=len;
+
+    if (ct_bytes < textlen)
+       Return(BadTerminate); /* Nor enough data. What should do? */
+
+    _XcwIdGetWoffset(xlocale, &woffset);
+
+    while (textlen > 0) {
+       /* get codepoint of character. */
+       code = 0;
+       byte = *ct_str;
+       switch (bytes) {
+         case 4: CombineCode(code);
+         case 3: CombineCode(code);
+         case 2: CombineCode(code);
+         case 1:
+               code = (code << 8) | byte;
+               ct_str++, ct_bytes--;
+               code &= 0x7f7f7f7f; /* MSB off */
+               break;
+       }
+       SaveStore(woffset | code);
+       textlen -= bytes;
+       ctcnt += bytes;
+    }
+    xlocale->ct_state = state_sv;
+    Return(Success);
+}
diff --git a/usr/src/contrib/X11R5-lib/lib/X/Xsi/XGetIMVal.c b/usr/src/contrib/X11R5-lib/lib/X/Xsi/XGetIMVal.c
new file mode 100644 (file)
index 0000000..aa8f9b8
--- /dev/null
@@ -0,0 +1,195 @@
+/*
+ * $XConsortium: XGetIMVal.c,v 1.16 91/12/02 16:31:34 rws Exp $
+ */
+
+/*
+ * Copyright 1990, 1991 by OMRON 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 and MIT not be used in
+ * advertising or publicity pertaining to distribution of the software without
+ * specific, written prior permission.  OMRON and MIT make no representations
+ * about the suitability of this software for any purpose.  It is provided
+ * "as is" without express or implied warranty.
+ *
+ * OMRON AND MIT DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL OMRON OR MIT 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
+ * TORTUOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE. 
+ *
+ *     Author: Seiji Kuwari    OMRON Corporation
+ *                             kuwa@omron.co.jp
+ *                             kuwa%omron.co.jp@uunet.uu.net
+ */                            
+
+#include "Xlibint.h"
+#include "Xi18nint.h"
+#include "XIMlibint.h"
+#if NeedVarargsPrototypes
+# include <stdarg.h>
+# define Va_start(a,b) va_start(a,b)
+#else
+# include <varargs.h>
+# define Va_start(a,b) va_start(a)
+#endif
+
+/*
+ * Query Input Method.
+ */
+static char *
+_IMGetValues(im, args, pmask)
+    register XipIM im;
+    register XIMArg *args;
+    unsigned long *pmask;
+{
+    register XIMArg            *arg;
+    register int               i;
+    register XrmName           Name;
+    register XIMrmResourceList xrmres;
+    unsigned int               num_resources = im->num_resources;
+    unsigned long              mask = 0L;
+    XrmQuark                   query_input =
+                                    XrmPermStringToQuark(XNQueryInputStyle);
+
+    for (arg = args; arg->name && *(arg->name); arg++) {
+       Name = XrmStringToName(arg->name);
+       for (xrmres = im->resources, i = 0;
+            i < num_resources; i++, xrmres++) {
+           if (Name == xrmres->xrm_name) {
+               if (!pmask) {
+                   if (Name == query_input) {
+                       char *p;
+                       XIMStyles *styles;
+                       int size = sizeof(XIMStyle)
+                                  * im->values.input_styles.count_styles;
+                       int all_size = sizeof(XIMStyles) + size;
+                       if ((p = Xmalloc((unsigned)all_size)) == NULL) {
+                           continue;
+                       }
+                       styles = (XIMStyles *)p;
+                       styles->count_styles =
+                                       im->values.input_styles.count_styles;
+                       styles->supported_styles =
+                                       (XIMStyle *)(p + sizeof(XIMStyles));
+                       bcopy((char *)im->values.input_styles.supported_styles,
+                             (char *)styles->supported_styles, size);
+                       bcopy((char *)&styles, (char *)arg->value,
+                             sizeof(XIMStyles *));
+                   } else {
+                       (void) _XCopyToArg((char *)im - xrmres->xrm_offset - 1,
+                                          &arg->value,
+                                          (unsigned int)xrmres->xrm_size);
+                   }
+               }
+               mask |= (1L << (xrmres->mask));
+               break;
+           }
+       }
+       if (i >= num_resources) return(arg->name);
+    }
+    if (pmask)
+       *pmask = mask;
+    return NULL;
+}
+
+static Status
+_ReceiveIMValues(im, mask)
+    register XipIM im;
+    unsigned long mask;
+{
+    register char      *p = NULL;
+    ximGetIMReq                req;
+    ximGetIMReply      reply;
+    XIMStyle           *supported_styles = NULL;
+    char               dummy_buf[512];
+
+    req.reqType = XIM_GetIM;
+    req.length = sz_ximGetIMReq;
+    req.mask = mask;
+    if ((_XipWriteToIM(im, (char *)&req, sz_ximGetIMReq) < 0) ||
+       (_XipFlushToIM(im) < 0)) {
+       return(-1);
+    }
+
+    if (_XipReadFromIM(im, (char *)&reply, sz_ximGetIMReply) < 0) {
+       return(-1);
+    }
+    if (reply.state != 0) {
+       return(-1);
+    }
+    if (reply.num_styles > 0) {
+       if ((supported_styles =
+            (XIMStyle *)Xmalloc((unsigned)(sizeof(XIMStyle) *
+                                           reply.num_styles))) == NULL){
+           if (_XipReadFromIM(im, dummy_buf, sizeof(XIMStyle) * reply.num_styles)
+               < 0) {
+           }
+           return(-1);
+       }
+       if (_XipReadFromIM(im, (char *)supported_styles,
+                          sizeof(XIMStyle) * reply.num_styles) < 0) {
+           return(-1);
+       }
+    }
+    if (reply.nbytes > 0) {
+       if ((p = Xmalloc((unsigned)(reply.nbytes + 1))) == NULL) {
+           if (_XipReadFromIM(im, dummy_buf, reply.nbytes) < 0) {
+           }
+           return(-1);
+       }
+       if (_XipReadFromIM(im, p, reply.nbytes) < 0) {
+           return(-1);
+       }
+       p[reply.nbytes] = '\0';
+    }
+    if (mask & (1L << IMQueryInputStyle)) {
+       if ((im->values.input_styles.count_styles > 0)
+           && (im->values.input_styles.supported_styles)) {
+           Xfree(im->values.input_styles.supported_styles);
+       }
+       im->values.input_styles.supported_styles = supported_styles;
+       im->values.input_styles.count_styles = reply.num_styles;
+    }
+#ifdef XML
+    if ((mask & (1L << IMQueryLanguage)) && (p != NULL)) {
+       if (im->values.supported_language) {
+           Xfree(im->values.supported_language);
+       }
+       im->values.supported_language = p;
+    }
+#else  /* XML */
+    if (reply.nbytes > 0) Xfree(p);
+#endif /* XML */
+    return 0;
+}
+    
+
+char *
+_XipGetIMValues(supim, args)
+    XIM supim;
+    XIMArg *args;
+{
+    XipIM im = (XipIM)supim;
+    unsigned long mask;
+    char *err;
+
+    if (im->fd < 0) return(NULL);
+
+    err = _IMGetValues(im, args, &mask);
+    if (err) return err;
+
+    if (!_ReceiveIMValues(im, mask)) {
+       return(_IMGetValues(im, args, (unsigned long *)NULL));
+    } else if (args) {
+       return(args->name);
+    } else {
+       return((char *)"SomethingErrorOccured");
+    }
+}
diff --git a/usr/src/contrib/X11R5-lib/lib/X/Xsi/XICGetVal.c b/usr/src/contrib/X11R5-lib/lib/X/Xsi/XICGetVal.c
new file mode 100644 (file)
index 0000000..73b723d
--- /dev/null
@@ -0,0 +1,315 @@
+/*
+ * $XConsortium: XICGetVal.c,v 1.16 91/12/02 17:29:37 rws Exp $
+ */
+
+/*
+ * Copyright 1990, 1991 by OMRON 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 and MIT not be used in
+ * advertising or publicity pertaining to distribution of the software without
+ * specific, written prior permission.  OMRON and MIT make no representations
+ * about the suitability of this software for any purpose.  It is provided
+ * "as is" without express or implied warranty.
+ *
+ * OMRON AND MIT DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL OMRON OR MIT 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
+ * TORTUOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE. 
+ *
+ *     Author: Seiji Kuwari    OMRON Corporation
+ *                             kuwa@omron.co.jp
+ *                             kuwa%omron.co.jp@uunet.uu.net
+ */                            
+
+#include "Xlibint.h"
+#include "Xi18nint.h"
+#include "XIMlibint.h"
+#if NeedVarargsPrototypes
+# include <stdarg.h>
+# define Va_start(a,b) va_start(a,b)
+#else
+# include <varargs.h>
+# define Va_start(a,b) va_start(a)
+#endif
+
+/*
+ * Get a attributes of input context depended on the nested argument list.
+ */
+static char *
+_ICGetAttrValues(im, args, attr, mask, offset, mask_only)
+    register XipIM im;
+    register XIMArg *args;
+    ICAttributes *attr;
+    unsigned long *mask;
+    int offset;
+    char mask_only;
+{
+    register                   XIMArg *arg;
+    register int               i;
+    register XrmName           Name;
+    register XIMrmResourceList xrmres;
+    XPointer                   *location;
+    register unsigned int      num_resources = im->core.ic_num_attr_resources;
+    XrmQuark                   spot_name =
+                                   XrmPermStringToQuark(XNSpotLocation);
+    XrmQuark                   area_needed_name =
+                                   XrmPermStringToQuark(XNAreaNeeded);
+    XrmQuark                   area_name =
+                                   XrmPermStringToQuark(XNArea);
+
+    for (arg = args; arg && arg->name && *(arg->name) ; arg++) {
+       Name = XrmStringToName(arg->name);
+       for (xrmres = im->core.ic_attr_resources, i = 0;
+            i < num_resources; i++, xrmres++) {
+           if (Name == xrmres->xrm_name) {
+               if (!(xrmres->mode & IMResourceRead)) {
+                   return(arg->name);
+               }
+               if (!mask_only) {
+                   if (Name == area_needed_name || Name == area_name ||
+                                                   Name == spot_name) {
+                       location = (XPointer*)arg->value;
+                       *location = (XPointer)Xmalloc(xrmres->xrm_size);
+                   } else {
+                       location = (XPointer *)&arg->value;
+                   }
+                   (void)_XCopyToArg((char *)attr - xrmres->xrm_offset - 1,
+                                      location,
+                                      (unsigned int)xrmres->xrm_size);
+               }
+               if (xrmres->mask >= 0) {
+                   *mask |= (1L << (xrmres->mask + offset));
+               }
+               break;
+           }
+       }
+       if (i >= num_resources) return(arg->name);
+    }
+    return(NULL);
+}
+
+/*
+ * Get input context specified by the nested argument list.
+ */
+char *
+_XipICGetValues(ic, args, mask, mask_only)
+    register XipIC ic;
+    register XIMArg *args;
+    unsigned long *mask;
+    char mask_only;
+{
+    XipIM                      im = ipIMofIC(ic);
+    register XIMArg            *arg;
+    register int               i;
+    register XrmName           Name;
+    register XIMrmResourceList xrmres;
+    register unsigned int      num_resources = im->core.ic_num_resources;
+    char                       *err;
+    XrmQuark                   preedit_name =
+                                   XrmPermStringToQuark(XNPreeditAttributes);
+    XrmQuark                   status_name =
+                                   XrmPermStringToQuark(XNStatusAttributes);
+
+    for (arg = args; arg && arg->name && *(arg->name); arg++) {
+       Name = XrmStringToName(arg->name);
+       for (xrmres = im->core.ic_resources, i = 0;
+            i < num_resources; i++, xrmres++) {
+           if (Name == xrmres->xrm_name) {
+               if (Name == preedit_name) {
+                   if ((err = _ICGetAttrValues(im, (XIMArg *)arg->value,
+                                               &ic->core.preedit_attr,
+                                               mask, 0, mask_only)) != NULL) {
+                       return(err);
+                   }
+               } else if (Name == status_name) {
+                   if ((err = _ICGetAttrValues(im, (XIMArg *)arg->value,
+                                               &ic->core.status_attr,
+                                               mask, StatusOffset,
+                                               mask_only)) != NULL) {
+                       return(err);
+                   }
+               } else {
+                   if (!(xrmres->mode & IMResourceRead)) {
+                       return(arg->name);
+                   }
+                   if (!mask_only) {
+                       (void) _XCopyToArg((char *)ic - xrmres->xrm_offset - 1,
+                                          &arg->value,
+                                          (unsigned int)xrmres->xrm_size);
+                   }
+                   if (xrmres->mask >= 0) {
+                       *mask |= (1L << (xrmres->mask));
+                   }
+               }
+               break;
+           }
+       }
+       if (i >= num_resources) return(arg->name);
+    }
+    return(NULL);
+}
+
+static int
+_ReceiveICAttrValues(im, attr, mask, offset)
+    XipIM im;
+    register ICAttributes *attr;
+    unsigned long mask;
+    int offset;
+{
+    ximICAttributesReq reply;
+
+    if (_XipReadFromIM(im, (char *)&reply, sz_ximICAttributesReq) < 0)
+       return(-1);
+    
+    if (mask & (1L << (ICArea + offset))) {
+       attr->area.x = reply.area_x;
+       attr->area.y = reply.area_y;
+       attr->area.width = reply.area_width;
+       attr->area.height = reply.area_height;
+    }
+    if (mask & (1L << (ICAreaNeeded + offset))) {
+       attr->area_needed.width = reply.areaneeded_width;
+       attr->area_needed.height = reply.areaneeded_height;
+    }
+    if (mask & (1L << ICSpotLocation + offset)) {
+       attr->spot_location.x = reply.spot_x;
+       attr->spot_location.y = reply.spot_y;
+    }
+    if (mask & (1L << (ICColormap + offset))) {
+       attr->colormap = reply.colormap;
+    }
+    if (mask & (1L << (ICStdColormap + offset))) {
+       attr->std_colormap = reply.std_colormap;
+    }
+    if (mask & (1L << (ICForeground + offset))) {
+       attr->foreground = reply.foreground;
+    }
+    if (mask & (1L << (ICBackground + offset))) {
+       attr->background = reply.background;
+    }
+    if (mask & (1L << (ICBackgroundPixmap + offset))) {
+       attr->background_pixmap = reply.pixmap;
+    }
+    if (mask & (1L << (ICLineSpace + offset))) {
+       attr->line_space = reply.line_space;
+    }
+    if (mask & (1L << (ICCursor + offset))) {
+       attr->cursor = reply.cursor;
+    }
+    return(0);
+}
+
+Status
+_XipReceiveICValues(ic, mask)
+    register XipIC ic;
+    unsigned long mask;
+{
+    XipIM im = ipIMofIC(ic);
+    register char *p = NULL, *p2 = NULL;
+    ximGetICReq req;
+    ximGetICReply reply;
+    ximICValuesReq ic_req;
+
+    req.reqType = XIM_GetIC;
+    req.length = sz_ximGetICReq;
+    req.xic = ic->icid;
+    req.mask = mask;
+    if ((_XipWriteToIM(im, (char *)&req, sz_ximGetICReq) < 0) ||
+       (_XipFlushToIM(im) < 0)) {
+       return(-1);
+    }
+
+    if (_XipReadFromIM(im, (char *)&reply, sz_ximGetICReply) < 0) {
+       return(-1);
+    }
+    if (reply.state != 0) {
+       return(-1);
+    }
+    if (_XipReadFromIM(im, (char *)&ic_req, sz_ximICValuesReq) < 0) {
+       return(-1);
+    }
+    if (ic_req.nbytes > 0) {
+       if ((p = Xmalloc((unsigned)(ic_req.nbytes + 1))) == NULL) return(-1);
+       if (_XipReadFromIM(im, p, ic_req.nbytes) < 0) {
+           return(-1);
+       }
+       p[ic_req.nbytes] = '\0';
+    }
+    if (ic_req.nbytes2 > 0) {
+       if ((p2 = Xmalloc((unsigned)(ic_req.nbytes2 + 1))) == NULL) return(-1);
+       if (_XipReadFromIM(im, p2, ic_req.nbytes2) < 0) {
+           return(-1);
+       }
+       p2[ic_req.nbytes2] = '\0';
+    }
+
+    if (mask & (1L << ICInputStyle)) {
+       ic->core.input_style = ic_req.input_style;
+    }
+    if (mask & (1L << ICClientWindow)) {
+       ic->core.client_window = ic_req.c_window;
+    }
+    if (mask & (1L << ICFocusWindow)) {
+       ic->core.focus_window = ic_req.focus_window;
+    }
+    if (mask & (1L << ICFilterEvents)) {
+       ic->core.filter_events = ic_req.filter_events;
+    }
+#ifdef XML
+    if (mask & (1L << ICUsingLanguage)) {
+       if (ic->values.using_language) Xfree(ic->values.using_language);
+       if (p == NULL) {
+           ic->values.using_language = NULL;
+       } else {
+           ic->values.using_language = p;
+       }
+    }
+    if (mask & (1L << ICCurrentLanguage)) {
+       if (ic->values.current_language) Xfree(ic->values.current_language);
+       if (p2 == NULL) {
+           ic->values.current_language = NULL;
+       } else {
+           ic->values.current_language = p2;
+       }
+    }
+#else  /* XML */
+    if (ic_req.nbytes > 0) Xfree(p);
+    if (ic_req.nbytes2 > 0) Xfree(p2);
+#endif /* XML */
+    if ((_ReceiveICAttrValues(im, &ic->core.preedit_attr, mask, 0) < 0) ||
+       (_ReceiveICAttrValues(im, &ic->core.status_attr, mask, StatusOffset) < 0)) {
+       return(-1);
+    }
+    return(0);
+}
+
+char*
+_XipGetICValues(supic, args)
+    XIC supic;
+    XIMArg *args;
+{
+    XipIC              ic = (XipIC)supic;
+    XipIM              im = ipIMofIC(ic);
+    unsigned long      mask = 0L;
+    char               *err;
+
+    if (im->fd < 0) return(NULL);
+
+    err = _XipICGetValues(ic, args, &mask, 1);
+    if (err)
+       return err;
+    /*
+     * Attempt to receive current IC data from the input manager.
+     */
+    if (!_XipReceiveICValues(ic, mask))
+       (void)_XipICGetValues(ic, args, &mask, 0);
+    return NULL;
+}
diff --git a/usr/src/contrib/X11R5-lib/lib/X/Xsi/XmbPrpText.c b/usr/src/contrib/X11R5-lib/lib/X/Xsi/XmbPrpText.c
new file mode 100644 (file)
index 0000000..877b3fa
--- /dev/null
@@ -0,0 +1,127 @@
+/* $XConsortium: XmbPrpText.c,v 1.8 91/11/17 15:31:41 rws Exp $ */
+/*
+ * Copyright 1991 by OMRON 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 and MIT not be used in
+ * advertising or publicity pertaining to distribution of the software without
+ * specific, written prior permission.  OMRON and MIT make no representations
+ * about the suitability of this software for any purpose.  It is provided
+ * "as is" without express or implied warranty.
+ *
+ * OMRON AND MIT DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL OMRON OR MIT 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
+ * TORTUOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Author: Hiroshi Kuribayashi    OMRON Corporation
+ *
+ */
+
+#include <X11/Xlibint.h>
+#include <X11/Xatom.h>
+#include <X11/Xutil.h>
+#include "Xlocaleint.h"
+
+#define XA_COMPOUND_TEXT(d) XInternAtom(d, "COMPOUND_TEXT", False)
+
+#if NeedFunctionPrototypes
+int
+XmbTextPropertyToTextList(
+    Display *dpy,
+    XTextProperty *tp,
+    char ***list_return,
+    int *count_return
+)
+#else
+int
+XmbTextPropertyToTextList(dpy, tp, list_return, count_return)
+    Display *dpy;
+    XTextProperty *tp;
+    char ***list_return;
+    int *count_return;
+#endif
+{
+    unsigned char **list;
+    unsigned int nelements;
+    unsigned char *cp;
+    unsigned char *start;
+    int i, j;
+    int len, scand;
+    unsigned int datalen = (int) tp->nitems;
+    XsiLCd lcd = (XsiLCd)_XlcCurrentLC();
+    int ret, error = 0;
+
+    if (tp->format != 8 ||
+       (tp->encoding != XA_STRING &&
+        tp->encoding != XA_COMPOUND_TEXT(dpy) &&
+        !(lcd &&
+          tp->encoding == XInternAtom(dpy, lcd->xlc->xlc_db->lc_encoding,
+                                      False))))
+       return XConverterNotFound;
+
+    if (datalen == 0) {
+       *list_return = (char **)Xmalloc(sizeof(char *));
+       **list_return = 0;
+       *count_return = 0;
+       return Success;
+    }
+
+    nelements = 1;
+    for (cp = tp->value, i = datalen; i > 0; cp++, i--) {
+       if (*cp == '\0') nelements++;
+    }
+
+    list = (unsigned char **) Xmalloc (nelements * sizeof (unsigned char *));
+    if (!list) return XNoMemory;
+
+    start = (unsigned char *)Xmalloc ((datalen + 1) * sizeof (unsigned char));
+    if (!start) {
+       Xfree ((char *) list);
+       return XNoMemory;
+    }
+
+    if (tp->encoding == XA_STRING ||
+       tp->encoding == XA_COMPOUND_TEXT(dpy)) {
+       cp = (unsigned char *)tp->value;
+       for (i = j = 0; i < nelements; i++, j++) {
+           list[j] = start;
+           len = datalen + 1;
+           if (i == nelements - 1)
+               scand = datalen;
+           else
+               scand = strlen((char *)cp);
+           if ((ret = _XConvertCTToMB(0, cp, scand, start,
+                               &len, &scand, 0)) < 0) {
+               XFreeStringList((char **)list);
+               return (XConverterNotFound);
+           }
+           error += ret;
+           start += len + 1;
+           datalen -= len + 1;
+           cp += scand + 1;
+       }
+    } else {
+       (void)bcopy ((char *) tp->value, (char *)start, (unsigned)tp->nitems);
+       start[datalen] = '\0';
+        
+       for (cp = start, i = datalen + 1, j = 0; i > 0; cp++, i--) {
+           if (*cp == '\0') {
+               list[j] = start;
+               start = (cp + 1);
+               j++;
+           }
+       }
+    }
+
+    *list_return = (char **)list;
+    *count_return = nelements;
+    return error;
+}
diff --git a/usr/src/contrib/X11R5-lib/lib/X/Xsi/XmbTextPrp.c b/usr/src/contrib/X11R5-lib/lib/X/Xsi/XmbTextPrp.c
new file mode 100644 (file)
index 0000000..ceaa9bc
--- /dev/null
@@ -0,0 +1,177 @@
+/* $XConsortium: XmbTextPrp.c,v 1.6 91/11/17 15:31:30 rws Exp $ */
+/*
+ * Copyright 1991 by OMRON 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 and MIT not be used in
+ * advertising or publicity pertaining to distribution of the software without
+ * specific, written prior permission.  OMRON and MIT make no representations
+ * about the suitability of this software for any purpose.  It is provided
+ * "as is" without express or implied warranty.
+ *
+ * OMRON AND MIT DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL OMRON OR MIT 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
+ * TORTUOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Author: Hiroshi Kuribayashi    OMRON Corporation
+ *
+ */
+
+#include <X11/Xlibint.h>
+#include <X11/Xatom.h>
+#include <X11/Xutil.h>
+#include "Xlocaleint.h"
+
+#define XA_COMPOUND_TEXT(d) XInternAtom(d, "COMPOUND_TEXT", False)
+
+#if NeedFunctionPrototypes
+int
+XmbTextListToTextProperty(
+    Display          *dpy,
+    char             **list,
+    int                       count,
+    XICCEncodingStyle  style,
+    XTextProperty     *text_prop
+)
+#else
+int
+XmbTextListToTextProperty(dpy, list, count, style, text_prop)
+    Display          *dpy;
+    char             **list;
+    int                       count;
+    XICCEncodingStyle  style;
+    XTextProperty     *text_prop;
+#endif
+{
+    int len, datalen;
+    unsigned char *buf, *buf_sv;
+    int i, scand;
+    register unsigned int nbytes;
+    XTextProperty proto;
+    int ret, error = 0;
+
+    for (i = 0, nbytes = 0; i < count; i++) {
+       nbytes += (unsigned) ((list[i] ? strlen (list[i]) : 0) + 1);
+    }
+    proto.format = 8;
+    proto.nitems = 0;
+
+    if (nbytes) {
+       datalen = len = nbytes * 6 + 6; /* Is it correct/enough ? */
+       buf_sv = buf = (unsigned char *)Xmalloc((unsigned)len);
+       if (!buf) return (XNoMemory);
+       proto.value = (unsigned char *) buf;
+
+       if (style == XStringStyle) {
+           proto.encoding = XA_STRING;
+           for (i = 0; i < count; i++, list++) {
+               if (*list) {
+                   len = datalen;
+                   if ((ret = _XConvertMBToString((unsigned char *)(*list),
+                                           strlen(*list), buf,
+                                           &len, &scand)) < 0) {
+                       Xfree((char *)buf_sv);
+                       return (XConverterNotFound);
+                   }
+                   error += ret;
+                   buf += len + 1;
+                   datalen -= len + 1;
+                   proto.nitems += len + 1;
+               } else {
+                   *buf++ = '\0';
+                   datalen--;
+                   proto.nitems++;
+               }
+           }
+           proto.nitems--;
+       } else if (style == XCompoundTextStyle) {
+           proto.encoding = XA_COMPOUND_TEXT(dpy);
+           for (i = 0; i < count; i++, list++) {
+               if (*list) {
+                   len = datalen;
+                   if ((ret = _XConvertMBToCT(0, (unsigned char *)(*list),
+                                       strlen(*list), buf,
+                                       &len, &scand, 0)) < 0) {
+                       Xfree((char *)buf_sv);
+                       return (XConverterNotFound);
+                   }
+                   error += ret;
+                   buf += len + 1;
+                   datalen -= len + 1;
+                   proto.nitems += len + 1;
+               } else {
+                   *buf++ = '\0';
+                   datalen--;
+                   proto.nitems++;
+               }
+           }
+           proto.nitems--;
+       } else if (style == XTextStyle) { /* MB: need not to convert */
+           XsiLCd lcd = (XsiLCd)_XlcCurrentLC();
+           proto.nitems = nbytes - 1;
+           if (lcd)
+               proto.encoding = XInternAtom(dpy,
+                                            lcd->xlc->xlc_db->lc_encoding,
+                                            False);
+           else
+               proto.encoding = XA_STRING;
+           for (i = 0; i < count; i++, list++) {
+               if (*list) {
+                   (void) strcpy((char *)buf, *list);
+                   buf += (strlen(*list) + 1);
+               } else {
+                   *buf++ = '\0';
+               }
+           }
+       } else if (style == XStdICCTextStyle) {
+           int is_xstring = 1; /* Yes */
+           for (i = 0; i < count; i++, list++) {
+               if (*list) {
+                   len = datalen;
+                   if ((ret = _XConvertMBToCT(0, (unsigned char *)*list,
+                                       strlen(*list),
+                                       buf, &len, &scand, 0)) < 0) {
+                       Xfree((char *)buf_sv);
+                       return (XConverterNotFound);
+                   }
+                   error += ret;
+                   if (is_xstring)
+                       for (i = 0; *(buf+i); i++) {
+                           if (!_isXString(*(buf+i))) {
+                               is_xstring = 0; /* Not XString */
+                               break;
+                           }
+                       }
+                   buf += len + 1;
+                   datalen -= len + 1;
+                   proto.nitems += len + 1;
+               } else {
+                   *buf++ = '\0';
+                   datalen--;
+                   proto.nitems++;
+               }
+           }
+           proto.nitems--;
+           if (is_xstring)
+               proto.encoding = XA_STRING;
+           else
+               proto.encoding = XA_COMPOUND_TEXT(dpy);
+       } else {
+           /* I don't know such a encoding */
+           return (XConverterNotFound);
+       }
+    } else {
+       proto.nitems = 0;
+       proto.value = 0;
+    }
+    *text_prop = proto;
+    return (error);
+}
diff --git a/usr/src/contrib/X11R5-lib/lib/X/Xsi/XwcPrpText.c b/usr/src/contrib/X11R5-lib/lib/X/Xsi/XwcPrpText.c
new file mode 100644 (file)
index 0000000..f2d72c8
--- /dev/null
@@ -0,0 +1,178 @@
+/* $XConsortium: XwcPrpText.c,v 1.12 91/11/17 15:31:34 rws Exp $ */
+/*
+ * Copyright 1991 by OMRON 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 and MIT not be used in
+ * advertising or publicity pertaining to distribution of the software without
+ * specific, written prior permission.  OMRON and MIT make no representations
+ * about the suitability of this software for any purpose.  It is provided
+ * "as is" without express or implied warranty.
+ *
+ * OMRON AND MIT DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL OMRON OR MIT 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
+ * TORTUOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Author: Hiroshi Kuribayashi    OMRON Corporation
+ *
+ */
+
+#include <X11/Xlibint.h>
+#include <X11/Xatom.h>
+#include <X11/Xutil.h>
+#include "Xlocaleint.h"
+
+#define XA_COMPOUND_TEXT(d) XInternAtom(d, "COMPOUND_TEXT", False)
+
+#if NeedFunctionPrototypes
+int
+XwcTextPropertyToTextList(
+    Display *dpy,
+    XTextProperty *tp,
+    wchar_t ***list_return,
+    int *count_return
+)
+#else
+int
+XwcTextPropertyToTextList(dpy, tp, list_return, count_return)
+    Display *dpy;
+    XTextProperty *tp;
+    wchar_t ***list_return;
+    int *count_return;
+#endif
+{
+    wchar_t **list;
+    unsigned int nelements;
+    unsigned char *cp;
+    wchar_t *start;
+    int i, j;
+    int len, scand;
+    unsigned int datalen = (int) tp->nitems;
+    int ret, error = 0;
+#ifndef X_WCHAR
+    char *mbuf;
+#endif
+    XsiLCd lcd = (XsiLCd)_XlcCurrentLC();
+
+    if (tp->format != 8 ||
+       (tp->encoding != XA_STRING &&
+        tp->encoding != XA_COMPOUND_TEXT(dpy) &&
+        !(lcd &&
+          tp->encoding == XInternAtom(dpy, lcd->xlc->xlc_db->lc_encoding,
+                                      False))))
+       return XConverterNotFound;
+
+    if (datalen == 0) {
+       *list_return = (wchar_t **) Xmalloc(sizeof (wchar_t *));
+       **list_return = 0;
+       *count_return = 0;
+       return Success;
+    }
+
+    nelements = 1;
+    for (cp = tp->value, i = datalen; i > 0; cp++, i--) {
+       if (*cp == '\0') nelements++;
+    }
+
+    list = (wchar_t **) Xmalloc (nelements * sizeof (wchar_t *));
+    if (!list) return XNoMemory;
+
+    start = (wchar_t *) Xmalloc ((datalen + 1) * sizeof (wchar_t));
+    if (!start) {
+       Xfree ((char *) list);
+       return XNoMemory;
+    }
+
+    if (tp->encoding == XA_STRING ||
+       tp->encoding == XA_COMPOUND_TEXT(dpy)) {
+       cp = tp->value;
+       for (i = j = 0; i < nelements; i++, j++) {
+           list[j] = start;
+           if (i == nelements - 1)
+               scand = datalen;
+           else
+               scand = strlen((char *)cp);
+#ifdef X_WCHAR
+           len = datalen + 1;
+           if ((ret = _XConvertCTToWC(0, cp,  scand, start,
+                               &len, &scand, 0)) < 0) {
+               XwcFreeStringList(list);
+               return (XConverterNotFound);
+           }
+#else
+#ifdef macII
+           len = 0; ret = 0;
+#else
+           len = scand * 2;
+           mbuf = _XAllocScratch(dpy, len);
+           if ((ret = _XConvertCTToMB(0, cp, scand, mbuf,
+                               &len, &scand, 0)) < 0) {
+               XwcFreeStringList(list);
+               return (XConverterNotFound);
+           }
+           len = mbstowcs(start, mbuf, datalen + 1);
+           if (len == datalen) {
+               XwcFreeStringList(list);
+               return (XConverterNotFound);
+           }
+#endif
+#endif
+           error += ret;
+           start += len + 1;
+           datalen -= len + 1;
+           cp += scand + 1;
+       }
+    } else {
+       cp = tp->value;
+       for (i = j = 0; i < nelements; i++, j++) {
+           list[j] = start;
+#ifdef X_WCHAR
+           len = datalen + 1;
+           if (i == nelements - 1)
+               scand = datalen;
+           else
+               scand = strlen((char *)cp);
+           if ((ret = _XConvertMBToWC(0, cp, scand, start,
+                               &len, &scand, 0)) < 0) {
+               XwcFreeStringList(list);
+               return (XConverterNotFound);
+           }
+           error += ret;
+#else
+#ifdef macII
+           len = 0;
+#else
+           len = mbstowcs(start, (char *)cp, datalen);
+           if (len == datalen) {
+               XwcFreeStringList(list);
+               return (XConverterNotFound);
+           }
+#endif
+#endif
+           start += len + 1;
+           datalen -= len + 1;
+           cp += scand + 1;
+       }
+    }
+
+    *list_return = list;
+    *count_return = nelements;
+    return error;
+}
+
+void XwcFreeStringList (list)
+    wchar_t **list;
+{
+    if (list) {
+       if (list[0]) Xfree ((char *)(list[0]));
+       Xfree ((char *) list);
+    }
+}
diff --git a/usr/src/contrib/X11R5-lib/lib/X/Xsi/XwcTextPrp.c b/usr/src/contrib/X11R5-lib/lib/X/Xsi/XwcTextPrp.c
new file mode 100644 (file)
index 0000000..2f279f8
--- /dev/null
@@ -0,0 +1,241 @@
+/* $XConsortium: XwcTextPrp.c,v 1.7 91/11/17 15:31:47 rws Exp $ */
+/*
+ * Copyright 1991 by OMRON 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 and MIT not be used in
+ * advertising or publicity pertaining to distribution of the software without
+ * specific, written prior permission.  OMRON and MIT make no representations
+ * about the suitability of this software for any purpose.  It is provided
+ * "as is" without express or implied warranty.
+ *
+ * OMRON AND MIT DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL OMRON OR MIT 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
+ * TORTUOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Author: Hiroshi Kuribayashi    OMRON Corporation
+ *
+ */
+
+#include <X11/Xlibint.h>
+#include <X11/Xatom.h>
+#include <X11/Xutil.h>
+#include "Xlocaleint.h"
+
+static int
+_Xwcslen(ws)
+wchar_t *ws;
+{
+    register n;
+    n = 0;
+    while (*ws++ != WNULL)
+       n++;
+    return(n);
+}
+
+#define XA_COMPOUND_TEXT(d) XInternAtom(d, "COMPOUND_TEXT", False)
+
+#if NeedFunctionPrototypes
+int
+XwcTextListToTextProperty(
+    Display          *dpy,
+    wchar_t         **list,
+    int                       count,
+    XICCEncodingStyle  style,
+    XTextProperty     *text_prop
+)
+#else
+int
+XwcTextListToTextProperty(dpy, list, count, style, text_prop)
+    Display          *dpy;
+    wchar_t         **list;
+    int                       count;
+    XICCEncodingStyle  style;
+    XTextProperty     *text_prop;
+#endif
+{
+    int len, datalen;
+    unsigned char *buf, *buf_sv;
+    int i, scand;
+    register unsigned int nbytes;
+    XTextProperty proto;
+    int ret, error = 0;
+#ifndef X_WCHAR
+    char *mbuf;
+    int mlen;
+#endif
+
+    for (i = 0, nbytes = 0; i < count; i++) {
+       nbytes += (unsigned) ((list[i] ? _Xwcslen (list[i]) : 0) + 1);
+    }
+
+    proto.format = 8;
+    proto.nitems = 0;
+
+    if (nbytes) {
+       datalen = len = nbytes * 6 + 6; /* Is it correct? */
+       buf_sv = buf = (unsigned char *)Xmalloc((unsigned)len);
+       if (!buf) return (XNoMemory);
+       proto.value = (unsigned char *) buf;
+
+       if (style == XStringStyle) {
+           proto.encoding = XA_STRING;
+           for (i = 0; i < count; i++, list++) {
+               if (*list) {
+                   len = datalen;
+#ifdef X_WCHAR
+                   if ((ret = _XConvertWCToString(*list, _Xwcslen(*list), buf,
+                                           &len, &scand)) < 0) {
+                       Xfree((char *)buf_sv);
+                       return (XConverterNotFound);
+                   }
+#else
+                   mlen = _Xsiwcstombs(dpy, (XLCd)NULL,
+                                       *list, _Xwcslen(*list), True, &mbuf);
+                   if ((ret = _XConvertMBToString(mbuf, mlen, buf,
+                                           &len, &scand)) < 0) {
+                       Xfree((char *)buf_sv);
+                       return (XConverterNotFound);
+                   }
+#endif
+                   error += ret;
+                   buf += len + 1;
+                   datalen -= len + 1;
+                   proto.nitems += len + 1;
+               } else {
+                   *buf++ = '\0';
+                   datalen--;
+                   proto.nitems++;
+               }
+           }
+           proto.nitems--;
+       } else if (style == XCompoundTextStyle) {
+           proto.encoding = XA_COMPOUND_TEXT(dpy);
+           for (i = 0; i < count; i++, list++) {
+               if (*list) {
+                   len = datalen;
+#ifdef X_WCHAR
+                   if ((ret = _XConvertWCToCT(0, *list, _Xwcslen(*list), buf,
+                                       &len, &scand, 0)) < 0) {
+                       Xfree((char *)buf_sv);
+                       return (XConverterNotFound);
+                   }
+#else
+                   mlen = _Xsiwcstombs(dpy, (XLCd)NULL,
+                                       *list, _Xwcslen(*list), True, &mbuf);
+                   if ((ret = _XConvertMBToCT(0, mbuf, mlen, buf,
+                                       &len, &scand, 0)) < 0) {
+                       Xfree((char *)buf_sv);
+                       return (XConverterNotFound);
+                   }
+#endif
+                   error += ret;
+                   buf += len + 1;
+                   datalen -= len + 1;
+                   proto.nitems += len + 1;
+               } else {
+                   *buf++ = '\0';
+                   datalen--;
+                   proto.nitems++;
+               }
+           }
+           proto.nitems--;
+       } else if (style == XTextStyle) { /* MB */
+           XsiLCd lcd = (XsiLCd)_XlcCurrentLC();
+           if (lcd)
+               proto.encoding = XInternAtom(dpy,
+                                            lcd->xlc->xlc_db->lc_encoding,
+                                            False);
+           else
+               proto.encoding = XA_STRING;
+           for (i = 0; i < count; i++, list++) {
+               if (*list) {
+                   len = datalen;
+#ifdef X_WCHAR
+                   if ((ret = _XConvertWCToMB(0, *list, _Xwcslen(*list), buf,
+                                       &len, &scand, 0)) < 0) {
+                       Xfree((char *)buf_sv);
+                       return (XConverterNotFound);
+                   }
+                   error += ret;
+#else
+#ifdef macII
+                   len = 0;
+#else
+                   len = wcstombs((char *)buf, *list, len);
+                   if (len == datalen) {
+                       Xfree((char *)buf_sv);
+                       return (XConverterNotFound);
+                   }
+#endif
+#endif
+                   buf += len + 1;
+                   datalen -= len + 1;
+                   proto.nitems += len + 1;
+               } else {
+                   *buf++ = '\0';
+                   datalen--;
+                   proto.nitems++;
+               }
+           }
+           proto.nitems--;
+       } else if (style == XStdICCTextStyle) {
+           int is_xstring = 1; /* Yes */
+           for (i = 0; i < count; i++, list++) {
+               if (*list) {
+                   len = datalen;
+#ifdef X_WCHAR
+                   if ((ret = _XConvertWCToCT(0, *list, _Xwcslen(*list), buf,
+                                       &len, &scand, 0)) < 0) {
+                       Xfree((char *)buf_sv);
+                       return (XConverterNotFound);
+                   }
+#else
+                   mlen = _Xsiwcstombs(dpy, (XLCd)NULL,
+                                       *list, _Xwcslen(*list), True, &mbuf);
+                   if ((ret = _XConvertMBToCT(0, mbuf, mlen, buf,
+                                       &len, &scand, 0)) < 0) {
+                       Xfree((char *)buf_sv);
+                       return (XConverterNotFound);
+                   }
+#endif
+                   error += ret;
+                   if (is_xstring)
+                       for (i = 0; *(buf+i); i++) {
+                           if(!_isXString(*(buf+i))) {
+                               is_xstring = 0; /* Not XString */
+                               break;
+                           }
+                       }
+                   buf += len + 1;
+                   datalen -= len + 1;
+                   proto.nitems += len + 1;
+               } else {
+                   *buf++ = '\0';
+                   datalen--;
+                   proto.nitems++;
+               }
+           }
+           proto.nitems--;
+           if (is_xstring)
+               proto.encoding = XA_STRING;
+           else
+               proto.encoding = XA_COMPOUND_TEXT(dpy);
+       } else {
+           return (XConverterNotFound);
+       }
+    } else {
+       proto.nitems = 0;
+       proto.value = 0;
+    }
+    *text_prop = proto;
+    return (error);
+}