1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
4 # include "../config.h"
5 #endif // HAVE_CONFIG_H
20 #endif // HAVE_UNISTD_H
22 #if defined(HAVE_PROCESS_H) && defined(__EMX__)
24 #endif // HAVE_PROCESS_H __EMX__
37 string expandTilde(const string& s) {
38 if (s[0] != '~') return s;
40 const char* const home = getenv("HOME");
41 if (home == NULL) return s;
43 return string(home + s.substr(s.find('/')));
47 void bexec(const string& command, const string& displaystring) {
51 int ret = putenv(const_cast<char *>(displaystring.c_str()));
53 ret = execl("/bin/sh", "/bin/sh", "-c", command.c_str(), NULL);
57 spawnlp(P_NOWAIT, "cmd.exe", "cmd.exe", "/c", command.c_str(), NULL);
62 string textPropertyToString(Display *display, XTextProperty& text_prop) {
65 if (text_prop.value && text_prop.nitems > 0) {
66 if (text_prop.encoding == XA_STRING) {
67 ret = (char *) text_prop.value;
69 text_prop.nitems = strlen((char *) text_prop.value);
73 if (XmbTextPropertyToTextList(display, &text_prop,
74 &list, &num) == Success &&
77 XFreeStringList(list);
86 string itostring(unsigned long i) {
91 for (; i > 0; i /= 10)
92 tmp.insert(tmp.begin(), "0123456789"[i%10]);
97 string itostring(long i) {
98 std::string tmp = itostring( (unsigned long) std::abs(i));
100 tmp.insert(tmp.begin(), '-');
104 string basename (const string& path) {
105 string::size_type slash = path.rfind('/');
106 if (slash == string::npos)
108 return path.substr(slash+1);