1
/* Copyright (C) 2010 Edward Der-Hua Liu, Hsin-Chu, Taiwan
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; either
6
* version 2.1 of the License, or (at your option) any later version.
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.
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
20
#include <X11/Xatom.h>
23
char *TableDir=HIME_TABLE_DIR;
28
if ((dname=getenv("HIME_TABLE_DIR"))) {
35
void get_hime_dir(char *tt)
37
strcpy(tt,(char *)getenv("HOME"));
38
strcat(tt,"/.config/hime");
42
gboolean get_hime_user_fname(char *name, char fname[])
45
strcat(strcat(fname,"/"),name);
46
return !access(fname, R_OK);
47
// dbg("get_hime_user_fname %s %s\n", name, fname);
50
void get_hime_conf_fname(char *name, char fname[])
53
strcat(strcat(fname,"/config/"),name);
56
void get_hime_user_or_sys_fname(char *name, char fname[])
58
if (!getenv("HIME_TABLE_DIR")) {
59
if (get_hime_user_fname(name, fname))
63
get_sys_table_file_name(name, fname);
66
void get_hime_conf_str(char *name, char **rstr, char *default_str)
68
char fname[MAX_HIME_STR];
74
get_hime_conf_fname(name, fname);
78
if ((fp=fopen(fname, "rb")) == NULL) {
79
*rstr = strdup(default_str);
83
myfgets(out, sizeof(out), fp);
84
int len = strlen(out);
85
if (len && out[len-1]=='\n')
93
void get_hime_conf_fstr(char *name, char rstr[], char *default_str)
96
get_hime_conf_str(name, &tt, default_str);
101
int get_hime_conf_int(char *name, int default_value)
104
char default_value_str[MAX_HIME_STR];
106
sprintf(default_value_str, "%d", default_value);
107
get_hime_conf_fstr(name, tt, default_value_str);
113
void save_hime_conf_str(char *name, char *str)
118
get_hime_conf_fname(name, fname);
120
if ((fp=fopen(fname,"wb"))==NULL) {
121
p_err("cannot create %s", fname);
124
fprintf(fp, "%s", str);
129
void save_hime_conf_int(char *name, int val)
133
sprintf(tt, "%d", val);
134
save_hime_conf_str(name, tt);
137
void get_sys_table_file_name(char *name, char *fname)
139
sprintf(fname, "%s/%s", TableDir, name);
141
#endif /* !CLIENT_LIB */
143
char *get_hime_xim_name()
147
if ((xim_name=getenv("XMODIFIERS"))) {
148
static char find[] = "@im=";
149
static char sstr[32];
150
char *p = strstr(xim_name, find);
152
if (p==NULL) return "hime";
155
strncpy(sstr, p, sizeof(sstr));
156
sstr[sizeof(sstr) - 1]=0;
158
if ((p=strchr(sstr, '.')))
161
// dbg("Try to use name from XMODIFIERS=@im=%s\n", sstr);
168
Atom get_hime_atom(Display *dpy)
170
char *xim_name = get_hime_xim_name();
173
snprintf(tt, sizeof(tt), "HIME_ATOM_%s", xim_name);
175
Atom atom = XInternAtom(dpy, tt, False);