2 /* This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 /* ---------------------------- included header files ---------------------- */
22 #include "safemalloc.h"
31 /* ---------------------------- local definitions -------------------------- */
33 /* ---------------------------- local macros ------------------------------- */
35 #define FGP_DOMAIN(l) ((FGettextPath *)l->object)->domain
36 #define FGP_DIR(l) ((FGettextPath *)l->object)->dir
38 /* ---------------------------- imports ------------------------------------ */
40 /* ---------------------------- included code files ------------------------ */
42 /* ---------------------------- local types -------------------------------- */
50 /* ---------------------------- forward declarations ----------------------- */
52 /* ---------------------------- local variables ---------------------------- */
54 static int FGettextInitOk
= 0;
55 static char *FGDefaultDir
= NULL
;
56 static char *FGDefaultDomain
= NULL
;
57 static const char *FGModuleName
= NULL
;
59 static flist
*FGPathList
= NULL
;
60 static FGettextPath
*FGLastPath
= NULL
;
62 /* ---------------------------- interface functions ------------------------ */
65 void fgettext_add_one_path(char *path
, int position
)
75 domain
= GetQuotedString(path
, &dir
, ";", NULL
, NULL
, NULL
);
76 if (!dir
|| dir
[0] == '\0' || dir
[0] != '/')
82 CopyString(&dir
, FGDefaultDir
);
84 if (!domain
|| domain
[0] == '\0')
86 domain
= FGDefaultDomain
;
89 tmp
= (FGettextPath
*)safemalloc(sizeof(FGettextPath
));
91 CopyString(&tmp
->domain
, domain
);
93 FGPathList
= flist_insert_obj(FGPathList
, tmp
, position
);
96 static void fgettext_free_fgpath_list(void)
98 flist
*l
= FGPathList
;
122 FGPathList
= flist_free_list(FGPathList
);
125 /* ---------------------------- interface functions ------------------------ */
127 void FGettextInit(const char *domain
, const char *dir
, const char *module
)
135 setlocale (LC_MESSAGES
, "");
137 btd
= bindtextdomain (domain
, dir
);
138 td
= textdomain (domain
);
142 stderr
,"[%s][FGettextInit]: <<ERROR>> "
143 "gettext initialisation fail!\n",
147 FGModuleName
= module
;
148 CopyString(&FGDefaultDir
, btd
);
149 CopyString(&FGDefaultDomain
, td
);
150 FGLastPath
= (FGettextPath
*)safemalloc(sizeof(FGettextPath
));
151 CopyString(&FGLastPath
->domain
, td
);
152 CopyString(&FGLastPath
->dir
, btd
);
153 FGPathList
= flist_append_obj(FGPathList
, FGLastPath
);
157 const char *FGettext(char *str
)
159 flist
*l
= FGPathList
;
160 const char *s
, *dummy
;
162 if (!HaveNLSSupport
|| !FGettextInitOk
|| FGPathList
== NULL
||
168 if (FGLastPath
!= l
->object
)
170 dummy
= bindtextdomain (FGP_DOMAIN(l
), FGP_DIR(l
));
171 dummy
= textdomain (FGP_DOMAIN(l
));
172 FGLastPath
= l
->object
;
182 dummy
= bindtextdomain (FGP_DOMAIN(l
), FGP_DIR(l
));
183 dummy
= textdomain (FGP_DOMAIN(l
));
184 FGLastPath
= l
->object
;
195 char *FGettextCopy(char *str
)
200 trans
= FGettext(str
);
203 CopyString(&r
, trans
);
208 void FGettextSetLocalePath(const char *path
)
210 char *exp_path
= NULL
;
212 char *after
, *p
, *str
;
215 if (!HaveNLSSupport
|| !FGettextInitOk
)
222 if (path
== NULL
|| path
[0] == '\0')
224 fgettext_free_fgpath_list();
225 FGLastPath
= (FGettextPath
*)safemalloc(sizeof(FGettextPath
));
226 CopyString(&FGLastPath
->domain
, FGDefaultDomain
);
227 CopyString(&FGLastPath
->dir
, FGDefaultDir
);
228 FGPathList
= flist_append_obj(FGPathList
, FGLastPath
);
233 exp_path
= envDupExpand(path
, 0);
235 if (StrEquals(exp_path
,"None"))
237 fgettext_free_fgpath_list();
241 after
= GetQuotedString(exp_path
, &before
, "+", NULL
, NULL
, NULL
);
242 if ((after
&& strchr(after
, '+')) || (before
&& strchr(before
, '+')))
245 stderr
,"[%s][SetLocalePath]: "
246 "To many '+' in locale path specification: %s\n",
250 if (!strchr(exp_path
, '+'))
252 fgettext_free_fgpath_list();
254 while(after
&& *after
)
256 after
= GetQuotedString(after
, &p
, ":", NULL
, NULL
, NULL
);
259 fgettext_add_one_path(p
,-1);
270 str
= GetQuotedString(str
, &p
, ":", NULL
, NULL
, NULL
);
273 fgettext_add_one_path(p
,count
);
293 void FGettextPrintLocalePath(int verbose
)
295 flist
*l
= FGPathList
;
297 if (!HaveNLSSupport
|| !FGettextInitOk
)
302 fprintf(stderr
,"fvwm NLS gettext path:\n");
306 stderr
," dir: %s, domain: %s\n",
307 FGP_DIR(l
), FGP_DOMAIN(l
));