2 * wmmenugen - Window Maker PropList menu generator
4 * miscellaneous functions
6 * Copyright (c) 2010. Tamas Tevesz <ice@extreme.hu>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 #include <WINGs/WUtil.h>
30 static const char *const terminals
[] = {
31 "x-terminal-emulator", /* Debian wrapper to launch user's prefered X terminal */
32 "aterm", /* AfterStep's X terminal, which provides "transparency" */
33 "eterm", /* Enlightenment's terminal, designed for eye-candyness (and efficiency) */
34 "gnome-terminal", /* GNOME project's terminal */
35 "konsole", /* KDE project's terminals */
36 "kterm", /* a Multi-Lingual Terminal based on xterm, originally by Katsuya Sano */
37 "mlterm", /* a Multi-Lingual Terminal emulator written from scratch */
38 "rxvt", /* a slimmed-down xterm */
39 "mrxvt", /* rxvt with support for tabs amongst other things */
40 "pterm", /* terminal based on PuTTY, a popular SSH client for Windows */
41 "xterm", /* the standard terminal provided by the X Window System */
42 "dtterm" /* provided by CDE, a frequent Desktop Environment in proprietary UNIXs */
45 /* pick a terminal emulator by finding the first existing entry of `terminals'
46 * in $PATH. the returned pointer should be wfreed later.
47 * if $WMMENU_TERMINAL exists in the environment, it's value overrides this
50 char *find_terminal_emulator(void)
55 t
= getenv("WMMENU_TERMINAL");
59 path
= getenv("PATH");
63 for (i
= 0; i
< wlengthof(terminals
); i
++) {
64 t
= wfindfile(path
, terminals
[i
]);
67 return wstrdup(terminals
[i
]);
74 /* tokenize `what' (LC_MESSAGES or LANG if `what' is NULL) in the form of
75 * `language[_territory][.codeset][@modifier]' into separate language, country,
76 * encoding, modifier components, which are allocated on demand and should be
77 * wfreed later. components that do not exist in `what' are set to NULL.
79 void parse_locale(const char *what
, char **language
, char **country
, char **encoding
, char **modifier
)
83 *language
= *country
= *encoding
= *modifier
= NULL
;
86 e
= getenv("LC_MESSAGES");
88 e
= getenv("LANG"); /* this violates the spec */
98 strcmp(e
, "POSIX") == 0 ||
104 *modifier
= wstrdup(p
+ 1);
110 *encoding
= wstrdup(p
+ 1);
116 *country
= wstrdup(p
+ 1);
121 *language
= wstrdup(e
);
129 /* determine whether (first token of) given file is in $PATH
131 Bool
fileInPath(const char *file
)
134 static char *path
= NULL
;
139 /* if it's an absolute path spec, don't override the user.
140 * s/he might just know better.
145 /* if it has a directory separator at random places,
146 * we might know better.
148 p
= strchr(file
, '/');
153 path
= getenv("PATH");
159 t
= strpbrk(p
, " \t");
163 t
= wfindfile(path
, p
);