]> Dogcows Code - chaz/openbox/blobdiff - otk/util.cc
use otk objects in the ob scripts by importing otk
[chaz/openbox] / otk / util.cc
index 91d6f13a5471f98b69c71744216a03f3c638c571..a2b784e7b5a01427ed1bc2b8d32ed48ad0f83207 100644 (file)
@@ -7,6 +7,10 @@
 extern "C" {
 #include <X11/Xatom.h>
 
+#ifdef HAVE_STDIO_H
+#include <stdio.h>
+#endif
+
 #ifdef HAVE_STRING_H
 #include <string.h>
 #endif
@@ -23,6 +27,9 @@ extern "C" {
 #  include <process.h>
 #endif //   HAVE_PROCESS_H             __EMX__
 
+#include "gettext.h"
+#define _(str) gettext(str)
+
 #include <assert.h>
 }
 
@@ -48,9 +55,8 @@ void bexec(const string& command, const string& displaystring) {
 #ifndef    __EMX__
   if (! fork()) {
     setsid();
-    int ret = putenv(const_cast<char *>(displaystring.c_str()));
-    assert(ret != -1);
-    ret = execl("/bin/sh", "/bin/sh", "-c", command.c_str(), NULL);
+    putenv(displaystring);
+    int ret = execl("/bin/sh", "/bin/sh", "-c", command.c_str(), NULL);
     exit(ret);
   }
 #else //   __EMX__
@@ -59,30 +65,6 @@ void bexec(const string& command, const string& displaystring) {
 }
 
 
-string textPropertyToString(Display *display, XTextProperty& text_prop) {
-  string ret;
-
-  if (text_prop.value && text_prop.nitems > 0) {
-    if (text_prop.encoding == XA_STRING) {
-      ret = (char *) text_prop.value;
-    } else {
-      text_prop.nitems = strlen((char *) text_prop.value);
-
-      char **list;
-      int num;
-      if (XmbTextPropertyToTextList(display, &text_prop,
-                                    &list, &num) == Success &&
-          num > 0 && *list) {
-        ret = *list;
-        XFreeStringList(list);
-      }
-    }
-  }
-
-  return ret;
-}
-
-
 string itostring(unsigned long i) {
   if (i == 0)
     return string("0");
@@ -101,14 +83,25 @@ string itostring(long i) {
   return tmp;
 }
 
+void putenv(const std::string &data)
+{
+  char *c = new char[data.size() + 1];
+  std::string::size_type i, max;
+  for (i = 0, max = data.size(); i < max; ++i)
+    c[i] = data[i];
+  c[i] = 0;
+  if (::putenv(c)) {
+    printf(_("warning: couldn't set environment variable\n"));
+    perror("putenv()");
+  }
 }
 
-#ifndef   HAVE_BASENAME
 string basename (const string& path) {
   string::size_type slash = path.rfind('/');
   if (slash == string::npos)
     return path;
   return path.substr(slash+1);
 }
-#endif // HAVE_BASENAME
+
+}
 
This page took 0.02191 seconds and 4 git commands to generate.