~ubuntu-branches/ubuntu/vivid/sunpinyin/vivid

« back to all changes in this revision

Viewing changes to wrapper/xim/IMdkit/IMValues.c

  • Committer: Package Import Robot
  • Author(s): YunQiang Su
  • Date: 2012-04-11 03:06:40 UTC
  • mfrom: (1.1.3)
  • Revision ID: package-import@ubuntu.com-20120411030640-wl9yw5no4n4lcf82
Tags: 2.0.3+git20120404-1
* Medium urgency for fixing RC bug.
* New upstream commit: fix FTBFS with gcc-4.7 (Closes: #667385).
* Add Multi-Arch: same to libsunpinyin3, -dev and -dbg.
* Add YunQiang Su to uploaders.

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 <stdlib.h>
33
 
#include <X11/Xlib.h>
34
 
#include "IMdkit.h"
35
 
#include <stdarg.h>
36
 
 
37
 
#define Va_start(a,b) va_start(a,b)
38
 
 
39
 
static void _IMCountVaList (va_list var, int *total_count)
40
 
{
41
 
    char *attr;
42
 
 
43
 
    *total_count = 0;
44
 
 
45
 
    for (attr = va_arg (var, char *);  attr;  attr = va_arg (var, char *))
46
 
    {
47
 
        (void)va_arg (var, XIMArg *);
48
 
        ++(*total_count);
49
 
    }
50
 
    /*endfor*/
51
 
}
52
 
 
53
 
static void _IMVaToNestedList (va_list var, int max_count, XIMArg **args_return)
54
 
{
55
 
    XIMArg *args;
56
 
    char   *attr;
57
 
 
58
 
    if (max_count <= 0)
59
 
    {
60
 
        *args_return = (XIMArg *) NULL;
61
 
        return;
62
 
    }
63
 
    /*endif*/
64
 
 
65
 
    args = (XIMArg *) malloc ((unsigned) (max_count + 1)*sizeof (XIMArg));
66
 
    *args_return = args;
67
 
    if (!args)
68
 
        return;
69
 
    /*endif*/
70
 
    for (attr = va_arg (var, char *);  attr;  attr = va_arg (var, char *))
71
 
    {
72
 
        args->name = attr;
73
 
        args->value = va_arg (var, XPointer);
74
 
        args++;
75
 
    }
76
 
    /*endfor*/
77
 
    args->name = (char *) NULL;
78
 
}
79
 
 
80
 
char *IMGetIMValues (XIMS ims, ...)
81
 
{
82
 
    va_list var;
83
 
    int total_count;
84
 
    XIMArg *args;
85
 
    char *ret;
86
 
 
87
 
    Va_start (var, ims);
88
 
    _IMCountVaList (var, &total_count);
89
 
    va_end (var);
90
 
 
91
 
    Va_start (var, ims);
92
 
    _IMVaToNestedList (var, total_count, &args);
93
 
    va_end (var);
94
 
 
95
 
    ret = (*ims->methods->getIMValues) (ims, args);
96
 
 
97
 
    if (args)
98
 
        XFree ((char *) args);
99
 
    /*endif*/
100
 
    return ret;
101
 
}
102
 
 
103
 
char *IMSetIMValues (XIMS ims, ...)
104
 
{
105
 
    va_list var;
106
 
    int total_count;
107
 
    XIMArg *args;
108
 
    char *ret;  
109
 
 
110
 
    Va_start (var, ims);
111
 
    _IMCountVaList (var, &total_count);
112
 
    va_end (var);
113
 
 
114
 
    Va_start (var, ims);
115
 
    _IMVaToNestedList (var, total_count, &args);
116
 
    va_end (var);
117
 
 
118
 
    ret = (*ims->methods->setIMValues) (ims, args);
119
 
 
120
 
    if (args)
121
 
        XFree ((char *) args);
122
 
    /*endif*/
123
 
    return ret;
124
 
}