~ubuntu-branches/ubuntu/maverick/uim/maverick

« back to all changes in this revision

Viewing changes to emacs/im.c

  • Committer: Bazaar Package Importer
  • Author(s): Masahito Omote
  • Date: 2006-11-23 15:10:53 UTC
  • mfrom: (3.1.8 edgy)
  • Revision ID: james.westby@ubuntu.com-20061123151053-q42sk1lvks41xpfx
Tags: 1:1.2.1-9
uim-gtk2.0.postinst: Don't call update-gtk-immodules on purge.
(closes: Bug#398530)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
  Copyright (c) 2005-2006 uim Project http://uim.freedesktop.org/
 
3
 
 
4
  All rights reserved.
 
5
 
 
6
  Redistribution and use in source and binary forms, with or
 
7
  without modification, are permitted provided that the
 
8
  following conditions are met:
 
9
 
 
10
  1. Redistributions of source code must retain the above
 
11
     copyright notice, this list of conditions and the
 
12
     following disclaimer.
 
13
  2. Redistributions in binary form must reproduce the above
 
14
     copyright notice, this list of conditions and the
 
15
     following disclaimer in the documentation and/or other
 
16
     materials provided with the distribution.
 
17
  3. Neither the name of authors nor the names of its
 
18
     contributors may be used to endorse or promote products
 
19
     derived from this software without specific prior written
 
20
     permission.
 
21
 
 
22
  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
 
23
  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
 
24
  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 
25
  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 
26
  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
 
27
  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 
28
  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 
29
  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 
30
  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 
31
  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 
32
  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 
33
  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 
34
  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
35
*/
 
36
 
 
37
#include "im.h"
 
38
 
 
39
/* context's default value */
 
40
char *default_engine_name = NULL;
 
41
 
 
42
int default_engine_updated = 0;
 
43
 
 
44
 
 
45
void
 
46
update_default_engine(const char *engine_name)
 
47
{
 
48
  if (default_engine_name) free(default_engine_name);
 
49
  default_engine_name = strdup(engine_name);
 
50
 
 
51
  default_engine_updated = 1;
 
52
}
 
53
 
 
54
void
 
55
output_default_im_engine(void)
 
56
{
 
57
  if (default_engine_name)
 
58
        a_printf(" ( d \"%s\" ) ", default_engine_name);
 
59
  else
 
60
        a_printf(" ( d \"%s\" ) ", 
 
61
                         uim_get_default_im_name(setlocale(LC_ALL, NULL)));
 
62
}
 
63
 
 
64
 
 
65
int
 
66
check_im_name(const char *imname)
 
67
{
 
68
  int ret = 0, i;
 
69
  const char *name;
 
70
  uim_context context;
 
71
 
 
72
  context = uim_create_context(NULL, "UTF-8", NULL, NULL, NULL, NULL);
 
73
 
 
74
  for (i = 0; i < uim_get_nr_im(context); i++) {  
 
75
        name = uim_get_im_name(context, i);
 
76
        if (strcmp(name, imname) == 0) ret = 1;
 
77
  }
 
78
 
 
79
  uim_release_context(context);
 
80
 
 
81
  return ret;
 
82
}
 
83
 
 
84
 
 
85
int
 
86
show_im(const char *im)
 
87
{
 
88
  if (im == NULL) {
 
89
        a_printf(" ( e ) ");
 
90
        return 0;
 
91
  } else {
 
92
        a_printf(" ( i \"%s\" ) ", im); 
 
93
        return 1;
 
94
  }
 
95
}
 
96
 
 
97
/* show supported IM engines */
 
98
int
 
99
list_im_engine(void)
 
100
{
 
101
  int i;
 
102
 
 
103
  uim_context context;
 
104
 
 
105
  context = uim_create_context(NULL, "UTF-8", NULL, NULL, NULL, NULL);
 
106
 
 
107
  a_printf(" ( L ");
 
108
 
 
109
  for (i = 0 ; i < uim_get_nr_im(context); i++) {
 
110
        char dummy_str[] = "";
 
111
        const char *name, *lang, *language, *shortd, *encoding;
 
112
 
 
113
        if ((name = uim_get_im_name(context, i)) == NULL)
 
114
          name = dummy_str;
 
115
 
 
116
        if ((lang = uim_get_im_language(context, i)) == NULL)
 
117
          lang = dummy_str;
 
118
 
 
119
        if ((language = uim_get_language_name_from_locale(lang)) == NULL)
 
120
          language = dummy_str;
 
121
 
 
122
        if ((shortd = uim_get_im_short_desc(context, i)) == NULL)
 
123
          shortd = dummy_str;
 
124
        
 
125
        a_printf(" ( \"%s\" \"%s\" \"%s\" \"%s\" ",
 
126
                         name, lang, language, shortd);
 
127
 
 
128
        if ((encoding = uim_get_im_encoding(context, i)) == NULL)
 
129
          a_printf(" %s ) ", encoding);
 
130
        else
 
131
          a_printf(" UTF-8 ) "); /* or nil? */
 
132
  }
 
133
 
 
134
  a_printf(" ) ");
 
135
 
 
136
  uim_release_context(context);
 
137
 
 
138
  return i;
 
139
}
 
140
 
 
141