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;
42 printf("tilde: getenv(DISPLAY)=%s\n", getenv("DISPLAY"));
44 return string(home + s.substr(s.find('/')));
48 void bexec(const string& command, const string& displaystring) {
52 int ret = putenv(const_cast<char *>(displaystring.c_str()));
54 ret = execl("/bin/sh", "/bin/sh", "-c", command.c_str(), NULL);
58 spawnlp(P_NOWAIT, "cmd.exe", "cmd.exe", "/c", command.c_str(), NULL);
63 string textPropertyToString(Display *display, XTextProperty& text_prop) {
66 if (text_prop.value && text_prop.nitems > 0) {
67 if (text_prop.encoding == XA_STRING) {
68 ret = (char *) text_prop.value;
70 text_prop.nitems = strlen((char *) text_prop.value);
74 if (XmbTextPropertyToTextList(display, &text_prop,
75 &list, &num) == Success &&
78 XFreeStringList(list);
87 string itostring(unsigned long i) {
92 for (; i > 0; i /= 10)
93 tmp.insert(tmp.begin(), "0123456789"[i%10]);
98 string itostring(long i) {
99 std::string tmp = itostring( (unsigned long) std::abs(i));
101 tmp.insert(tmp.begin(), '-');
105 string basename (const string& path) {
106 string::size_type slash = path.rfind('/');
107 if (slash == string::npos)
109 return path.substr(slash+1);