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>
29 static char *terminals
[] = {
30 "x-terminal-emulator", "aterm","eterm", "gnome-terminal", "konsole",
31 "kterm", "mlterm", "rxvt", "mrxvt", "pterm", "xterm", "dtterm",
35 /* pick a terminal emulator by finding the first existing entry of `terminals'
36 * in $PATH. the returned pointer should be wfreed later.
37 * if $WMMENU_TERMINAL exists in the environment, it's value overrides this
40 char *find_terminal_emulator(void)
45 path
= t
= ret
= NULL
;
47 t
= getenv("WMMENU_TERMINAL");
53 path
= getenv("PATH");
57 for (i
= 0; terminals
[i
]; i
++) {
58 t
= wfindfile(path
, terminals
[i
]);
64 ret
= wstrdup(basename(t
));
73 /* tokenize `what' (LC_MESSAGES or LANG if `what' is NULL) in the form of
74 * `language[_territory][.codeset][@modifier]' into separate language, country,
75 * encoding, modifier components, which are allocated on demand and should be
76 * wfreed later. components that do not exist in `what' are set to NULL.
78 void parse_locale(const char *what
, char **language
, char **country
, char **encoding
, char **modifier
)
82 *language
= *country
= *encoding
= *modifier
= NULL
;
85 e
= getenv("LC_MESSAGES");
87 e
= getenv("LANG"); /* this violates the spec */
97 strcmp(e
, "POSIX") == 0 ||
103 *modifier
= wstrdup(p
+ 1);
109 *encoding
= wstrdup(p
+ 1);
115 *country
= wstrdup(p
+ 1);
120 *language
= wstrdup(e
);
128 /* determine whether (first token of) given file is in $PATH
130 Bool
fileInPath(const char *file
)
133 static char *path
= NULL
;
138 /* if it's an absolute path spec, don't override the user.
139 * s/he might just know better.
144 /* if it has a directory separator at random places,
145 * we might know better.
147 p
= strchr(file
, '/');
152 path
= getenv("PATH");
158 t
= strpbrk(p
, " \t");
162 t
= wfindfile(path
, p
);