~ubuntu-branches/ubuntu/precise/hime/precise

« back to all changes in this revision

Viewing changes to src/IMdkit/lib/IMConn.c

  • Committer: Package Import Robot
  • Author(s): Yao Wei (魏銘廷)
  • Date: 2012-01-14 00:24:08 UTC
  • Revision ID: package-import@ubuntu.com-20120114002408-e79gagbeg1rt8npv
Tags: upstream-0.9.9
Import upstream version 0.9.9

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/******************************************************************
 
2
 
 
3
         Copyright 1994, 1995 by Sun Microsystems, Inc.
 
4
         Copyright 1993, 1994 by Hewlett-Packard Company
 
5
 
 
6
Permission to use, copy, modify, distribute, and sell this software
 
7
and its documentation for any purpose is hereby granted without fee,
 
8
provided that the above copyright notice appear in all copies and
 
9
that both that copyright notice and this permission notice appear
 
10
in supporting documentation, and that the name of Sun Microsystems, Inc.
 
11
and Hewlett-Packard not be used in advertising or publicity pertaining to
 
12
distribution of the software without specific, written prior permission.
 
13
Sun Microsystems, Inc. and Hewlett-Packard make no representations about
 
14
the suitability of this software for any purpose.  It is provided "as is"
 
15
without express or implied warranty.
 
16
 
 
17
SUN MICROSYSTEMS INC. AND HEWLETT-PACKARD COMPANY DISCLAIMS ALL
 
18
WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED
 
19
WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
 
20
SUN MICROSYSTEMS, INC. AND HEWLETT-PACKARD COMPANY BE LIABLE FOR ANY
 
21
SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
 
22
RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
 
23
CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
 
24
IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 
25
 
 
26
  Author: Hidetoshi Tajima(tajima@Eng.Sun.COM) Sun Microsystems, Inc.
 
27
 
 
28
    This version tidied and debugged by Steve Underwood May 1999
 
29
 
 
30
******************************************************************/
 
31
 
 
32
#include <X11/Xlib.h>
 
33
#include <stdlib.h>
 
34
#include <string.h>
 
35
#include "IMdkit.h"
 
36
#include <stdarg.h>
 
37
 
 
38
#define Va_start(a,b) va_start(a,b)
 
39
 
 
40
static void _IMCountVaList(va_list var, int *total_count)
 
41
{
 
42
    char *attr;
 
43
 
 
44
    *total_count = 0;
 
45
 
 
46
    for (attr = va_arg (var, char*);  attr;  attr = va_arg (var, char*))
 
47
    {
 
48
        (void)va_arg (var, XIMArg *);
 
49
        ++(*total_count);
 
50
    }
 
51
    /*endfor*/
 
52
}
 
53
 
 
54
static void _IMVaToNestedList(va_list var, int max_count, XIMArg **args_return)
 
55
{
 
56
    XIMArg *args;
 
57
    char   *attr;
 
58
 
 
59
    if (max_count <= 0)
 
60
    {
 
61
        *args_return = (XIMArg *) NULL;
 
62
        return;
 
63
    }
 
64
    /*endif*/
 
65
 
 
66
    args = (XIMArg *) malloc ((unsigned) (max_count + 1)*sizeof (XIMArg));
 
67
    *args_return = args;
 
68
    if (!args)
 
69
        return;
 
70
    /*endif*/
 
71
 
 
72
    for (attr = va_arg (var, char*);  attr;  attr = va_arg (var, char *))
 
73
    {
 
74
        args->name = attr;
 
75
        args->value = va_arg (var, XPointer);
 
76
        args++;
 
77
    }
 
78
    /*endfor*/
 
79
    args->name = (char*)NULL;
 
80
}
 
81
 
 
82
static char *_FindModifiers (XIMArg *args)
 
83
{
 
84
    char *modifiers;
 
85
 
 
86
    while (args->name)
 
87
    {
 
88
        if (strcmp (args->name, IMModifiers) == 0)
 
89
        {
 
90
            modifiers = args->value;
 
91
            return modifiers;
 
92
        }
 
93
        else
 
94
        {
 
95
            args++;
 
96
        }
 
97
        /*endif*/
 
98
    }
 
99
    /*endwhile*/
 
100
    return NULL;
 
101
}
 
102
 
 
103
XIMS _GetIMS (char *modifiers)
 
104
{
 
105
    XIMS ims;
 
106
    extern IMMethodsRec Xi18n_im_methods;
 
107
 
 
108
    if ((ims = (XIMS) malloc (sizeof (XIMProtocolRec))) == (XIMS) NULL)
 
109
        return ((XIMS) NULL);
 
110
    /*endif*/
 
111
    memset ((void *) ims, 0, sizeof (XIMProtocolRec));
 
112
 
 
113
    if (modifiers == NULL
 
114
        ||
 
115
        modifiers[0] == '\0'
 
116
        ||
 
117
        strcmp (modifiers, "Xi18n") == 0)
 
118
    {
 
119
        ims->methods = &Xi18n_im_methods;
 
120
        return ims;
 
121
    }
 
122
    /*endif*/
 
123
    XFree (ims);
 
124
    return (XIMS) NULL;
 
125
}
 
126
 
 
127
XIMS IMOpenIM (Display *display, ...)
 
128
{
 
129
    va_list var;
 
130
    int total_count;
 
131
    XIMArg *args;
 
132
    XIMS ims;
 
133
    char *modifiers;
 
134
    Status ret;
 
135
 
 
136
    Va_start (var, display);
 
137
    _IMCountVaList (var, &total_count);
 
138
    va_end (var);
 
139
 
 
140
    Va_start (var, display);
 
141
    _IMVaToNestedList (var, total_count, &args);
 
142
    va_end (var);
 
143
 
 
144
    modifiers = _FindModifiers (args);
 
145
 
 
146
    ims = _GetIMS (modifiers);
 
147
    if (ims == (XIMS) NULL)
 
148
        return (XIMS) NULL;
 
149
    /*endif*/
 
150
    
 
151
    ims->core.display = display;
 
152
 
 
153
    ims->protocol = (*ims->methods->setup) (display, args);
 
154
    XFree (args);
 
155
    if (ims->protocol == (void *) NULL)
 
156
    {
 
157
        XFree (ims);
 
158
        return (XIMS) NULL;
 
159
    }
 
160
    /*endif*/
 
161
    ret = (ims->methods->openIM) (ims);
 
162
    if (ret == False)
 
163
    {
 
164
        XFree (ims);
 
165
        return (XIMS) NULL;
 
166
    }
 
167
    /*endif*/
 
168
    return (XIMS) ims;
 
169
}
 
170
 
 
171
Status IMCloseIM (XIMS ims)
 
172
{
 
173
    (ims->methods->closeIM) (ims);
 
174
    XFree (ims);
 
175
    return True;
 
176
}