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

« back to all changes in this revision

Viewing changes to uim/look.c

  • Committer: Bazaar Package Importer
  • Author(s): Masahito Omote
  • Date: 2008-06-25 19:56:33 UTC
  • mfrom: (3.1.18 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080625195633-8jljph4rfq00l8o7
Tags: 1:1.5.1-2
* uim-tcode: provide tutcode-custom.scm, tutcode-bushudic.scm
  and tutcode-rule.scm (Closes: #482659)
* Fix FTBFS: segv during compile (Closes: #483078).
  I personally think this bug is not specific for uim but is a optimization
  problem on gcc-4.3.1. (https://bugs.freedesktop.org/show_bug.cgi?id=16477)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* 
 
2
  Copyright (c) 2003-2008 uim Project http://code.google.com/p/uim/
 
3
 
 
4
  All rights reserved.
 
5
 
 
6
  Redistribution and use in source and binary forms, with or without
 
7
  modification, are permitted provided that the following conditions
 
8
  are met:
 
9
 
 
10
  1. Redistributions of source code must retain the above copyright
 
11
     notice, this list of conditions and the following disclaimer.
 
12
  2. Redistributions in binary form must reproduce the above copyright
 
13
     notice, this list of conditions and the following disclaimer in the
 
14
     documentation and/or other materials provided with the distribution.
 
15
  3. Neither the name of authors nor the names of its contributors
 
16
     may be used to endorse or promote products derived from this software
 
17
     without specific prior written permission.
 
18
 
 
19
  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND
 
20
  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 
21
  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 
22
  ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE
 
23
  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 
24
  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 
25
  OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 
26
  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 
27
  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 
28
  OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 
29
  SUCH DAMAGE.
 
30
 
 
31
*/
 
32
 
 
33
#include <stdlib.h>
 
34
#include <string.h>
 
35
 
 
36
#include "uim.h"
 
37
#include "uim-scm.h"
 
38
#include "uim-scm-abbrev.h"
 
39
#include "uim-helper.h"
 
40
#include "plugin.h"
 
41
 
 
42
#include "bsdlook.h"
 
43
 
 
44
static uim_lisp
 
45
uim_look_look(uim_lisp dict_, uim_lisp str_)
 
46
{
 
47
  const char *dict = REFER_C_STR(dict_);
 
48
  const char *str = REFER_C_STR(str_);
 
49
  uim_look_ctx *ctx;
 
50
  char buf[1024];
 
51
  char *dict_str;
 
52
  size_t len;
 
53
  uim_lisp ret_ = uim_scm_f();
 
54
 
 
55
  ctx = uim_look_init();
 
56
  if (!ctx)
 
57
    uim_fatal_error("uim_look_init() failed");
 
58
 
 
59
  if (!uim_look_open_dict(dict, ctx))
 
60
    return ret_;
 
61
 
 
62
  dict_str = uim_strdup(str);
 
63
  len = strlen(str);
 
64
 
 
65
  ret_ = uim_scm_null();
 
66
  if (uim_look(dict_str, ctx) != 0) {
 
67
    uim_look_set(ctx);
 
68
    while (uim_look_get(dict_str, buf, sizeof(buf), ctx) != 0) {
 
69
      /* don't use the word itself */
 
70
      if (strcasecmp(buf, dict_str) == 0)
 
71
        continue;
 
72
      if (len < strlen(buf))
 
73
        ret_ = CONS(MAKE_STR(buf + len), ret_);
 
74
    }
 
75
  }
 
76
 
 
77
  uim_look_finish(ctx);
 
78
  free(dict_str);
 
79
 
 
80
  return uim_scm_callf("reverse", "o", ret_);
 
81
}
 
82
 
 
83
void
 
84
uim_plugin_instance_init(void)
 
85
{
 
86
  uim_scm_init_proc2("look-lib-look", uim_look_look);
 
87
}
 
88
 
 
89
void
 
90
uim_plugin_instance_quit(void)
 
91
{
 
92
}