diff options
| author | Andreas Oberritter <obi@opendreambox.org> | 2010-11-23 14:01:44 +0100 |
|---|---|---|
| committer | Andreas Oberritter <obi@opendreambox.org> | 2010-11-23 14:01:44 +0100 |
| commit | c4d7f98e70694e471409cda6de03d0f3b5816f27 (patch) | |
| tree | 8cae9b3d3b6ee59a5a11da6f8702fc1ee2b1861a /lib/base | |
| parent | 7b2960a205f3c3e3b421d1664cd38644b3ffb679 (diff) | |
| parent | ed472ea627a958bc8dfb375ca03329624f1aed9c (diff) | |
| download | enigma2-c4d7f98e70694e471409cda6de03d0f3b5816f27.tar.gz enigma2-c4d7f98e70694e471409cda6de03d0f3b5816f27.zip | |
Merge branch 'obi/master'
Diffstat (limited to 'lib/base')
| -rw-r--r-- | lib/base/.gitignore | 1 | ||||
| -rw-r--r-- | lib/base/Makefile.am | 58 | ||||
| -rw-r--r-- | lib/base/console.h | 1 | ||||
| -rw-r--r-- | lib/base/eenv.cpp.in | 117 | ||||
| -rw-r--r-- | lib/base/eenv.h | 16 | ||||
| -rw-r--r-- | lib/base/encoding.cpp | 7 |
6 files changed, 189 insertions, 11 deletions
diff --git a/lib/base/.gitignore b/lib/base/.gitignore new file mode 100644 index 00000000..aa9ae18f --- /dev/null +++ b/lib/base/.gitignore @@ -0,0 +1 @@ +eenv.cpp diff --git a/lib/base/Makefile.am b/lib/base/Makefile.am index 05085632..7f04abfa 100644 --- a/lib/base/Makefile.am +++ b/lib/base/Makefile.am @@ -1,12 +1,56 @@ -INCLUDES = \ - -I$(top_srcdir)/include +AM_CPPFLAGS = \ + -I$(top_srcdir) \ + -I$(top_srcdir)/include \ + -include Python.h \ + -include $(top_builddir)/enigma2_config.h noinst_LIBRARIES = libenigma_base.a libenigma_base_a_SOURCES = \ - buffer.cpp ebase.cpp eerror.cpp elock.cpp \ - init.cpp message.cpp thread.cpp \ - smartptr.cpp estring.cpp connection.cpp \ - filepush.cpp encoding.cpp console.cpp rawfile.cpp \ - nconfig.cpp ioprio.cpp etpm.cpp + buffer.cpp \ + connection.cpp \ + console.cpp \ + ebase.cpp \ + eenv.cpp \ + eerror.cpp \ + elock.cpp \ + encoding.cpp \ + estring.cpp \ + etpm.cpp \ + filepush.cpp \ + init.cpp \ + ioprio.cpp \ + message.cpp \ + nconfig.cpp \ + rawfile.cpp \ + smartptr.cpp \ + thread.cpp +EXTRA_DIST = \ + eenv.cpp.in + +baseincludedir = $(pkgincludedir)/lib/base +baseinclude_HEADERS = \ + buffer.h \ + console.h \ + ebase.h \ + eenv.h \ + eerror.h \ + elock.h \ + encoding.h \ + eptrlist.h \ + estring.h \ + etpm.h \ + filepush.h \ + i18n.h \ + idatasource.h \ + init.h \ + init_num.h \ + ioprio.h \ + message.h \ + nconfig.h \ + object.h \ + rawfile.h \ + ringbuffer.h \ + smartptr.h \ + thread.h diff --git a/lib/base/console.h b/lib/base/console.h index e730b40e..60540da0 100644 --- a/lib/base/console.h +++ b/lib/base/console.h @@ -1,7 +1,6 @@ #ifndef __LIB_BASE_CONSOLE_H__ #define __LIB_BASE_CONSOLE_H__ -#include "Python.h" #include <string> #include <lib/base/ebase.h> #include <lib/python/connections.h> diff --git a/lib/base/eenv.cpp.in b/lib/base/eenv.cpp.in new file mode 100644 index 00000000..52c42147 --- /dev/null +++ b/lib/base/eenv.cpp.in @@ -0,0 +1,117 @@ +#include <cstdio> +#include <cstdlib> +#include <cstring> +#include <wordexp.h> +#include <lib/base/eenv.h> +#include <lib/base/eerror.h> + +bool eEnv::initialized = false; + +void eEnv::initialize() +{ + static const struct { + std::string name; + std::string value; + } cfgenv[] = { + { "prefix", "@prefix@" }, + { "exec_prefix", "@exec_prefix@" }, + { "bindir", "@bindir@" }, + { "sbindir", "@sbindir@" }, + { "libexecdir", "@libexecdir@" }, + { "datarootdir", "@datarootdir@" }, + { "datadir", "@datadir@" }, + { "sysconfdir", "@sysconfdir@" }, + { "sharedstatedir", "@sharedstatedir@" }, + { "localstatedir", "@localstatedir@" }, + { "libdir", "@libdir@" }, + { "localedir", "@localedir@" }, + }; + size_t i; + + // 1st pass, as generated by configure. + // Variables set by the user will not be overwritten. + for (i = 0; i < (sizeof(cfgenv) / sizeof(*cfgenv)); i++) { + eDebug("setenv('%s', '%s', 0)", cfgenv[i].name.c_str(), cfgenv[i].value.c_str()); + setenv(cfgenv[i].name.c_str(), cfgenv[i].value.c_str(), 0); + } + + // 2nd pass: Resolve directories. + for (i = 0; i < (sizeof(cfgenv) / sizeof(*cfgenv)); i++) { + std::string dest; + eEnv::resolveVar(dest, "${" + cfgenv[i].name + "}"); + eDebug("setenv('%s', '%s', 1)", cfgenv[i].name.c_str(), dest.c_str()); + setenv(cfgenv[i].name.c_str(), dest.c_str(), 1); + } +} + +int eEnv::resolveVar(std::string &dest, const char *src) +{ + size_t i = 0; + int ret; + wordexp_t p; + + ret = wordexp(src, &p, WRDE_NOCMD | WRDE_UNDEF); + if (ret != 0) { + switch (ret) { + case WRDE_BADCHAR: + eDebug("%s: bad character", __func__); + break; + case WRDE_BADVAL: + eDebug("%s: bad value", __func__); + break; + case WRDE_CMDSUB: + eDebug("%s: invalid command substitution", __func__); + break; + case WRDE_NOSPACE: + eDebug("%s: out of memory", __func__); + break; + case WRDE_SYNTAX: + eDebug("%s: syntax error", __func__); + break; + default: + eDebug("%s: unknown error", __func__); + break; + } + + return -1; + } + + while (i < p.we_wordc) { + if (strchr(p.we_wordv[i], '$')) { + ret = eEnv::resolveVar(dest, p.we_wordv[i]); + if (ret < 0) + break; + } else { + dest.append(p.we_wordv[i]); + } + + if (++i < p.we_wordc) + dest.append(" "); + } + + wordfree(&p); + return ret; +} + +int eEnv::resolveVar(std::string &dest, const std::string &src) +{ + return eEnv::resolveVar(dest, src.c_str()); +} + +std::string eEnv::resolve(const std::string &src) +{ + std::string dest; + + if (!initialized) { + eEnv::initialize(); + initialized = true; + } + + eDebug("%s: resolve %s", __func__, src.c_str()); + + eEnv::resolveVar(dest, src); + + eDebug("%s: -> %s", __func__, dest.c_str()); + + return dest; +} diff --git a/lib/base/eenv.h b/lib/base/eenv.h new file mode 100644 index 00000000..3d149f5e --- /dev/null +++ b/lib/base/eenv.h @@ -0,0 +1,16 @@ +#ifndef __lib_base_paths_h +#define __lib_base_paths_h + +#include <string> + +class eEnv { +private: + static bool initialized; + static void initialize(); + static int resolveVar(std::string &dest, const char *src); + static int resolveVar(std::string &dest, const std::string &src); +public: + static std::string resolve(const std::string &path); +}; + +#endif diff --git a/lib/base/encoding.cpp b/lib/base/encoding.cpp index 8b4b592b..361acce5 100644 --- a/lib/base/encoding.cpp +++ b/lib/base/encoding.cpp @@ -2,6 +2,7 @@ #include <cstdlib> #include <lib/base/encoding.h> #include <lib/base/eerror.h> +#include <lib/base/eenv.h> eDVBTextEncodingHandler encodingHandler; // the one and only instance @@ -17,8 +18,8 @@ inline char toupper(char c) eDVBTextEncodingHandler::eDVBTextEncodingHandler() { - const char * file=DATADIR "/enigma2/encoding.conf"; - FILE *f = fopen(file, "rt"); + std::string file = eEnv::resolve("${datadir}/enigma2/encoding.conf"); + FILE *f = fopen(file.c_str(), "rt"); if (f) { char *line = (char*) malloc(256); @@ -61,7 +62,7 @@ eDVBTextEncodingHandler::eDVBTextEncodingHandler() free(line); } else - eDebug("[eDVBTextEncodingHandler] couldn't open %s !", file); + eDebug("[eDVBTextEncodingHandler] couldn't open %s !", file.c_str()); } void eDVBTextEncodingHandler::getTransponderDefaultMapping(int tsidonid, int &table) |
