forked from hime-ime/hime
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtable-update.c
66 lines (55 loc) · 1.86 KB
/
table-update.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*
* Copyright (C) 2020 The HIME team, Taiwan
* Copyright (C) 2009 Edward Der-Hua Liu, Hsin-Chu, Taiwan
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
@file table-update.c
@brief Update pho.tab2 when necessary
if (phonetic_char_dynamic_sequence) {
mv pho.tab2 pho.tab2.old
$(UPDATE) pho.tab2
$(CREATE) pho.tab2.version
}
*/
#include <sys/stat.h>
#include "hime.h"
void update_table_file (char *name, int version) {
if (!phonetic_char_dynamic_sequence)
return;
char fname_user[256];
char fname_version[256];
char fname_sys[256];
char version_name[256];
strcat (strcpy (version_name, name), ".version");
get_hime_user_fname (version_name, fname_version);
get_hime_user_fname (name, fname_user);
get_sys_table_file_name (name, fname_sys);
FILE *fp;
if ((fp = fopen (fname_version, "r"))) {
int ver = 0;
fscanf (fp, "%d", &ver);
fclose (fp);
if (ver >= version)
return;
}
char cmd[2048];
snprintf (cmd, sizeof (cmd), "mv -f %s %s.old && cp %s %s && echo %d > %s",
fname_user, fname_user,
fname_sys, fname_user, version, fname_version);
dbg ("exec %s\n", cmd);
system (cmd);
}