1 /*
2 * $Id:$
3 * Copyright (c) 2003,2004 Masahito Omote <omote@utyuuzin.net>
4 * 2005-2013 uim Project https://github.com/uim/uim
5 *
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. Neither the name of authors nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34 #include <config.h>
35
36 #include <stdlib.h>
37 #include <string.h>
38
39 #include "gettext.h"
40
41 #include "word.h"
42 #include "canna-cclass.h"
43
word_append(uim_word ** head,uim_word_type type,char * charset,char * phon,char * desc,const char * cclass_code,const char * cclass_native,int freq,int okuri,char * annotation)44 void word_append(uim_word **head, uim_word_type type,
45 char *charset,
46 char *phon, char *desc,
47 const char *cclass_code,
48 const char *cclass_native,
49 int freq,
50 int okuri, char *annotation)
51 {
52 uim_word *entry, *pos;
53 entry = malloc(sizeof(uim_word));
54 if (entry != NULL) {
55 /* If each arguments is NULL, allocate '\0' */
56 entry->type = type;
57
58 if (charset != NULL)
59 entry->charset = strdup(charset);
60 else
61 entry->charset = strdup("");
62
63 if (phon != NULL)
64 entry->phon = strdup(phon);
65 else
66 entry->phon = strdup("");
67
68 if (desc != NULL)
69 entry->desc = strdup(desc);
70 else
71 entry->desc = strdup("");
72
73 if (cclass_code != NULL) {
74 entry->cclass_code = strdup(cclass_code);
75 } else
76 entry->cclass_code = strdup("");
77
78 if (cclass_native != NULL) {
79 entry->cclass_native = strdup(cclass_native);
80 } else
81 entry->cclass_native = strdup("");
82
83 entry->freq = freq;
84
85 /* SKK specific */
86 entry->okuri = okuri;
87 if (annotation != NULL)
88 entry->annotation = strdup(annotation);
89 else
90 entry->annotation = strdup("");
91
92 entry->next = NULL;
93
94 if (*head == NULL) {
95 *head = entry;
96 } else {
97 pos = word_last(*head);
98 pos->next = entry;
99 }
100 }
101 }
102
word_free_list(uim_word * head)103 void word_free_list(uim_word *head) {
104 uim_word *pos, *pos_prev;
105 for (pos = head; pos != NULL; ) {
106 free(pos->charset);
107 free(pos->phon);
108 free(pos->desc);
109 free(pos->cclass_code);
110 free(pos->cclass_native);
111 free(pos->annotation);
112
113 pos_prev = pos;
114 pos = pos->next;
115 free(pos_prev);
116 }
117 }
118
word_last(uim_word * list)119 uim_word *word_last(uim_word *list) {
120 if (list != NULL) {
121 while (list->next) {
122 list = list->next;
123 }
124 }
125 return list;
126 }
127
128 uim_word_type
dict_identifier_to_word_type(char * identifier)129 dict_identifier_to_word_type(char *identifier)
130 {
131 uim_word_type type;
132
133 if (!strcmp(identifier, N_("Anthy private dictionary")))
134 type = WORD_TYPE_ANTHY;
135 else if (!strcmp(identifier, N_("Canna private dictionary")))
136 type = WORD_TYPE_CANNA;
137 else
138 type = WORD_TYPE_ANTHY; /* XXX */
139
140 return type;
141 }
142
143 int
dict_identifier_to_support_type(char * identifier)144 dict_identifier_to_support_type(char *identifier)
145 {
146 int type;
147
148 if (!strcmp(identifier, N_("Anthy private dictionary")))
149 type = SUPPORT_ANTHY;
150 else if (!strcmp(identifier, N_("Canna private dictionary")))
151 type = SUPPORT_CANNA;
152 else
153 type = SUPPORT_ANTHY; /* XXX */
154
155 return type;
156 }
157