1 /* Copyright (C) 2011 Edward Der-Hua Liu, Hsin-Chu, Taiwan
2  *
3  * This library is free software; you can redistribute it and/or
4  * modify it under the terms of the GNU Lesser General Public
5  * License as published by the Free Software Foundation version 2.1
6  * of the License.
7  *
8  * This library is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11  * Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public
14  * License along with this library; if not, write to the Free Software
15  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
16  */
17 
18 #include "hime.h"
19 
20 #include "gtab.h"
21 #include "hime-conf.h"
22 #include "hime-endian.h"
23 #include "pho.h"
24 #include "tsin.h"
25 
init_tsin_table_fname(INMD * p,char * fname)26 gboolean init_tsin_table_fname (INMD *p, char *fname) {
27     char fname_idx[256], gtab_phrase_src[256], gtabfname[256];
28     if (p->filename_append) {
29         //    dbg("filename_append %s\n",p->filename_append);
30         strcpy (fname, p->filename_append);
31         strcpy (gtabfname, fname);
32     } else if (p->filename) {
33         get_hime_user_fname (p->filename, fname);
34         get_hime_user_or_sys_fname (p->filename, gtabfname);
35     } else {
36         dbg ("no file name\n");
37         return FALSE;
38     }
39 
40     strcat (fname, ".tsin-db");
41     strcat (strcpy (fname_idx, fname), ".idx");
42     strcat (strcpy (gtab_phrase_src, fname), ".src");
43     //  dbg("init_tsin_table %s\n", fname);
44 
45     setenv ("HIME_NO_RELOAD", "", TRUE);
46 
47     if (access (fname, W_OK) < 0 || access (fname_idx, W_OK) < 0) {
48         unix_exec (HIME_BIN_DIR "/hime-tsin2gtab-phrase %s %s", gtabfname, gtab_phrase_src);
49         unix_exec (HIME_BIN_DIR "/hime-tsa2d32 %s %s", gtab_phrase_src, fname);
50     }
51 
52     return TRUE;
53 }
54