]>
Dogcows Code - chaz/openbox/blob - otk/util.cc
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__
27 #define _(str) gettext(str)
40 string
expandTilde(const string
& s
) {
41 if (s
[0] != '~') return s
;
43 const char* const home
= getenv("HOME");
44 if (home
== NULL
) return s
;
46 return string(home
+ s
.substr(s
.find('/')));
50 void bexec(const string
& command
, const string
& displaystring
) {
54 putenv(displaystring
);
55 int ret
= execl("/bin/sh", "/bin/sh", "-c", command
.c_str(), NULL
);
59 spawnlp(P_NOWAIT
, "cmd.exe", "cmd.exe", "/c", command
.c_str(), NULL
);
64 string
textPropertyToString(Display
*display
, XTextProperty
& text_prop
) {
67 if (text_prop
.value
&& text_prop
.nitems
> 0) {
68 if (text_prop
.encoding
== XA_STRING
) {
69 ret
= (char *) text_prop
.value
;
71 text_prop
.nitems
= strlen((char *) text_prop
.value
);
75 if (XmbTextPropertyToTextList(display
, &text_prop
,
76 &list
, &num
) == Success
&&
79 XFreeStringList(list
);
88 string
itostring(unsigned long i
) {
93 for (; i
> 0; i
/= 10)
94 tmp
.insert(tmp
.begin(), "0123456789"[i%10
]);
99 string
itostring(long i
) {
100 std::string tmp
= itostring( (unsigned long) std::abs(i
));
102 tmp
.insert(tmp
.begin(), '-');
106 void putenv(const std::string
&data
)
108 char *c
= new char[data
.size() + 1];
109 std::string::size_type i
, max
;
110 for (i
= 0, max
= data
.size(); i
< max
; ++i
)
114 printf(_("warning: couldn't set environment variable\n"));
119 string
basename (const string
& path
) {
120 string::size_type slash
= path
.rfind('/');
121 if (slash
== string::npos
)
123 return path
.substr(slash
+1);
This page took 0.039389 seconds and 4 git commands to generate.