diff options
Diffstat (limited to 'libs/vdr')
43 files changed, 3773 insertions, 0 deletions
diff --git a/libs/vdr/.dep.inc b/libs/vdr/.dep.inc new file mode 100644 index 0000000..4560e55 --- /dev/null +++ b/libs/vdr/.dep.inc @@ -0,0 +1,5 @@ +# This code depends on make tool being used +DEPFILES=$(wildcard $(addsuffix .d, ${OBJECTFILES})) +ifneq (${DEPFILES},) +include ${DEPFILES} +endif diff --git a/libs/vdr/Makefile b/libs/vdr/Makefile new file mode 100644 index 0000000..ec9de69 --- /dev/null +++ b/libs/vdr/Makefile @@ -0,0 +1,128 @@ +# +# There exist several targets which are by default empty and which can be +# used for execution of your targets. These targets are usually executed +# before and after some main targets. They are: +# +# .build-pre: called before 'build' target +# .build-post: called after 'build' target +# .clean-pre: called before 'clean' target +# .clean-post: called after 'clean' target +# .clobber-pre: called before 'clobber' target +# .clobber-post: called after 'clobber' target +# .all-pre: called before 'all' target +# .all-post: called after 'all' target +# .help-pre: called before 'help' target +# .help-post: called after 'help' target +# +# Targets beginning with '.' are not intended to be called on their own. +# +# Main targets can be executed directly, and they are: +# +# build build a specific configuration +# clean remove built files from a configuration +# clobber remove all built files +# all build all configurations +# help print help mesage +# +# Targets .build-impl, .clean-impl, .clobber-impl, .all-impl, and +# .help-impl are implemented in nbproject/makefile-impl.mk. +# +# Available make variables: +# +# CND_BASEDIR base directory for relative paths +# CND_DISTDIR default top distribution directory (build artifacts) +# CND_BUILDDIR default top build directory (object files, ...) +# CONF name of current configuration +# CND_PLATFORM_${CONF} platform name (current configuration) +# CND_ARTIFACT_DIR_${CONF} directory of build artifact (current configuration) +# CND_ARTIFACT_NAME_${CONF} name of build artifact (current configuration) +# CND_ARTIFACT_PATH_${CONF} path to build artifact (current configuration) +# CND_PACKAGE_DIR_${CONF} directory of package (current configuration) +# CND_PACKAGE_NAME_${CONF} name of package (current configuration) +# CND_PACKAGE_PATH_${CONF} path to package (current configuration) +# +# NOCDDL + + +# Environment +MKDIR=mkdir +CP=cp +CCADMIN=CCadmin + + +# build +build: .build-post + +.build-pre: +# Add your pre 'build' code here... + +.build-post: .build-impl +# Add your post 'build' code here... + + +# clean +clean: .clean-post + +.clean-pre: +# Add your pre 'clean' code here... + +.clean-post: .clean-impl +# Add your post 'clean' code here... + + +# clobber +clobber: .clobber-post + +.clobber-pre: +# Add your pre 'clobber' code here... + +.clobber-post: .clobber-impl +# Add your post 'clobber' code here... + + +# all +all: .all-post + +.all-pre: +# Add your pre 'all' code here... + +.all-post: .all-impl +# Add your post 'all' code here... + + +# build tests +build-tests: .build-tests-post + +.build-tests-pre: +# Add your pre 'build-tests' code here... + +.build-tests-post: .build-tests-impl +# Add your post 'build-tests' code here... + + +# run tests +test: .test-post + +.test-pre: +# Add your pre 'test' code here... + +.test-post: .test-impl +# Add your post 'test' code here... + + +# help +help: .help-post + +.help-pre: +# Add your pre 'help' code here... + +.help-post: .help-impl +# Add your post 'help' code here... + + + +# include project implementation makefile +include nbproject/Makefile-impl.mk + +# include project make variables +include nbproject/Makefile-variables.mk diff --git a/libs/vdr/doc/Legal.Note b/libs/vdr/doc/Legal.Note new file mode 100644 index 0000000..1a45581 --- /dev/null +++ b/libs/vdr/doc/Legal.Note @@ -0,0 +1,27 @@ +@@FileInfo@@ +@@AppInfo@@ + +from "Video Disk Recorder": + +Copyright (C) 2000, 2003, 2006, 2008 Klaus Schmidinger + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +Or, point your browser to http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + +The original author can be reached at kls@tvdr.de + +The vdr project's page is at http://www.tvdr.de + +@@Comment@@ diff --git a/libs/vdr/include/CharsetConv.h b/libs/vdr/include/CharsetConv.h new file mode 100644 index 0000000..3a05f56 --- /dev/null +++ b/libs/vdr/include/CharsetConv.h @@ -0,0 +1,115 @@ +/** + * File: CharsetConv.h + * Project: libvdr - classes taken from vdr-project + * + * from "Video Disk Recorder": + * + * Copyright (C) 2000, 2003, 2006, 2008 Klaus Schmidinger + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Or, point your browser to http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * + * The original author can be reached at kls@tvdr.de + * + * The vdr project's page is at http://www.tvdr.de + * + */ +#ifndef CHARSETCONV_H +#define CHARSETCONV_H + +#include <stddef.h> +#include <sys/types.h> +#include <iconv.h> +typedef unsigned char uchar; + +// When handling strings that might contain UTF-8 characters, it may be necessary +// to process a "symbol" that consists of several actual character bytes. The +// following functions allow transparently accessing a "char *" string without +// having to worry about what character set is actually used. + +int Utf8CharLen(const char *s); + ///< Returns the number of character bytes at the beginning of the given + ///< string that form a UTF-8 symbol. +uint Utf8CharGet(const char *s, int Length = 0); + ///< Returns the UTF-8 symbol at the beginning of the given string. + ///< Length can be given from a previous call to Utf8CharLen() to avoid calculating + ///< it again. If no Length is given, Utf8CharLen() will be called. +int Utf8CharSet(uint c, char *s = NULL); + ///< Converts the given UTF-8 symbol to a sequence of character bytes and copies + ///< them to the given string. Returns the number of bytes written. If no string + ///< is given, only the number of bytes is returned and nothing is copied. +int Utf8SymChars(const char *s, int Symbols); + ///< Returns the number of character bytes at the beginning of the given + ///< string that form at most the given number of UTF-8 symbols. +int Utf8StrLen(const char *s); + ///< Returns the number of UTF-8 symbols formed by the given string of + ///< character bytes. +char *Utf8Strn0Cpy(char *Dest, const char *Src, int n); + ///< Copies at most n character bytes from Src to Dest, making sure that the + ///< resulting copy ends with a complete UTF-8 symbol. The copy is guaranteed + ///< to be zero terminated. + ///< Returns a pointer to Dest. +int Utf8ToArray(const char *s, uint *a, int Size); + ///< Converts the given character bytes (including the terminating 0) into an + ///< array of UTF-8 symbols of the given Size. Returns the number of symbols + ///< in the array (without the terminating 0). +int Utf8FromArray(const uint *a, char *s, int Size, int Max = -1); + ///< Converts the given array of UTF-8 symbols (including the terminating 0) + ///< into a sequence of character bytes of at most Size length. Returns the + ///< number of character bytes written (without the terminating 0). + ///< If Max is given, only that many symbols will be converted. + ///< The resulting string is always zero-terminated if Size is big enough. + +// When allocating buffer space, make sure we reserve enough space to hold +// a string in UTF-8 representation: + +#define Utf8BufSize(s) ((s) * 4) + +// The following macros automatically use the correct versions of the character +// class functions: + +#define Utf8to(conv, c) (cCharSetConv::SystemCharacterTable() ? to##conv(c) : tow##conv(c)) +#define Utf8is(ccls, c) (cCharSetConv::SystemCharacterTable() ? is##ccls(c) : isw##ccls(c)) + +class cCharSetConv { +public: + cCharSetConv(const char *FromCode = NULL, const char *ToCode = NULL); + ///< Sets up a character set converter to convert from FromCode to ToCode. + ///< If FromCode is NULL, the previously set systemCharacterTable is used + ///< (or "UTF-8" if no systemCharacterTable has been set). + ///< If ToCode is NULL, "UTF-8" is used. + ~cCharSetConv(); + const char *Convert(const char *From, char *To = NULL, size_t ToLength = 0); + ///< Converts the given Text from FromCode to ToCode (as set in the constructor). + ///< If To is given, it is used to copy at most ToLength bytes of the result + ///< (including the terminating 0) into that buffer. If To is not given, + ///< the result is copied into a dynamically allocated buffer and is valid as + ///< long as this object lives, or until the next call to Convert(). The + ///< return value always points to the result if the conversion was successful + ///< (even if a fixed size To buffer was given and the result didn't fit into + ///< it). If the string could not be converted, the result points to the + ///< original From string. + static const char *SystemCharacterTable(void) { return systemCharacterTable; } + static void SetSystemCharacterTable(const char *CharacterTable); + +private: + iconv_t cd; + char *result; + size_t length; + static char *systemCharacterTable; + }; + +#endif /* CHARSETCONV_H */ + diff --git a/libs/vdr/include/CondWait.h b/libs/vdr/include/CondWait.h new file mode 100644 index 0000000..1e663df --- /dev/null +++ b/libs/vdr/include/CondWait.h @@ -0,0 +1,61 @@ +/** + * File: CondWait.h + * Project: libvdr - classes taken from vdr-project + * + * from "Video Disk Recorder": + * + * Copyright (C) 2000, 2003, 2006, 2008 Klaus Schmidinger + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Or, point your browser to http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * + * The original author can be reached at kls@tvdr.de + * + * The vdr project's page is at http://www.tvdr.de + * + */ +#ifndef CONDWAIT_H +#define CONDWAIT_H + +#include <pthread.h> + +class cCondWait { +public: + cCondWait(void); + ~cCondWait(); + + bool Wait(int TimeoutMs = 0); + ///< Waits at most TimeoutMs milliseconds for a call to Signal(), or + ///< forever if TimeoutMs is 0. + ///< \return Returns true if Signal() has been called, false it the given + ///< timeout has expired. + void Signal(void); + ///< Signals a caller of Wait() that the condition it is waiting for is met. + + static void SleepMs(int TimeoutMs); + ///< Creates a cCondWait object and uses it to sleep for TimeoutMs + ///< milliseconds, immediately giving up the calling thread's time + ///< slice and thus avoiding a "busy wait". + ///< In order to avoid a possible busy wait, TimeoutMs will be automatically + ///< limited to values >2. + +private: + pthread_mutex_t mutex; + pthread_cond_t cond; + bool signaled; + }; + +#endif /* CONDWAIT_H */ + diff --git a/libs/vdr/include/FileNameList.h b/libs/vdr/include/FileNameList.h new file mode 100644 index 0000000..c8bc6af --- /dev/null +++ b/libs/vdr/include/FileNameList.h @@ -0,0 +1,41 @@ +/** + * File: FileNameList.h + * Project: libvdr - classes taken from vdr-project + * + * from "Video Disk Recorder": + * + * Copyright (C) 2000, 2003, 2006, 2008 Klaus Schmidinger + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Or, point your browser to http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * + * The original author can be reached at kls@tvdr.de + * + * The vdr project's page is at http://www.tvdr.de + * + */ +#ifndef FILENAMELIST_H +#define FILENAMELIST_H + +#include <StringList.h> + +class cFileNameList : public cStringList { +public: + cFileNameList(const char *Directory = NULL, bool DirsOnly = false); + bool Load(const char *Directory, bool DirsOnly = false); + }; + +#endif /* FILENAMELIST_H */ + diff --git a/libs/vdr/include/Logging.h b/libs/vdr/include/Logging.h new file mode 100644 index 0000000..4dd1300 --- /dev/null +++ b/libs/vdr/include/Logging.h @@ -0,0 +1,45 @@ +/** + * File: Logging.h + * Project: libvdr - classes taken from vdr-project + * + * from "Video Disk Recorder": + * + * Copyright (C) 2000, 2003, 2006, 2008 Klaus Schmidinger + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Or, point your browser to http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * + * The original author can be reached at kls@tvdr.de + * + * The vdr project's page is at http://www.tvdr.de + * + */ +#ifndef LOGGING_H +#define LOGGING_H + +#include <sys/syslog.h> + +extern int SysLogLevel; +extern void syslog_with_tid(int priority, const char *format, ...); + +#define esyslog(a...) void( (SysLogLevel > 0) ? syslog_with_tid(LOG_ERR, a) : void() ) +#define isyslog(a...) void( (SysLogLevel > 1) ? syslog_with_tid(LOG_ERR, a) : void() ) +#define dsyslog(a...) void( (SysLogLevel > 2) ? syslog_with_tid(LOG_ERR, a) : void() ) + +#define LOG_ERROR esyslog("ERROR (%s,%d): %m", __FILE__, __LINE__) +#define LOG_ERROR_STR(s) esyslog("ERROR (%s,%d): %s: %m", __FILE__, __LINE__, s) + +#endif /* LOGGING_H */ + diff --git a/libs/vdr/include/Mutex.h b/libs/vdr/include/Mutex.h new file mode 100644 index 0000000..5ea6cf2 --- /dev/null +++ b/libs/vdr/include/Mutex.h @@ -0,0 +1,63 @@ +/** + * File: Mutex.h + * Project: libvdr - classes taken from vdr-project + * + * from "Video Disk Recorder": + * + * Copyright (C) 2000, 2003, 2006, 2008 Klaus Schmidinger + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Or, point your browser to http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * + * The original author can be reached at kls@tvdr.de + * + * The vdr project's page is at http://www.tvdr.de + * + */ +#ifndef MUTEX_H +#define MUTEX_H + +#include <pthread.h> + +class cMutex { +public: + cMutex(void); + ~cMutex(); + void Lock(void); + void Unlock(void); + +private: + pthread_mutex_t mutex; + int locked; + friend class cCondVar; + }; + +// cMutexLock can be used to easily set a lock on mutex and make absolutely +// sure that it will be unlocked when the block will be left. Several locks can +// be stacked, so a function that makes many calls to another function which uses +// cMutexLock may itself use a cMutexLock to make one longer lock instead of many +// short ones. +class cMutexLock { +private: + cMutex *mutex; + bool locked; +public: + cMutexLock(cMutex *Mutex = NULL); + ~cMutexLock(); + bool Lock(cMutex *Mutex); + }; + +#endif /* MUTEX_H */ + diff --git a/libs/vdr/include/ReadDir.h b/libs/vdr/include/ReadDir.h new file mode 100644 index 0000000..466976d --- /dev/null +++ b/libs/vdr/include/ReadDir.h @@ -0,0 +1,53 @@ +/** + * File: ReadDir.h + * Project: libvdr - classes taken from vdr-project + * + * from "Video Disk Recorder": + * + * Copyright (C) 2000, 2003, 2006, 2008 Klaus Schmidinger + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Or, point your browser to http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * + * The original author can be reached at kls@tvdr.de + * + * The vdr project's page is at http://www.tvdr.de + * + */ +#ifndef READDIR_H +#define READDIR_H + +#include <stddef.h> +#include <dirent.h> +#include <sys/types.h> + +class cReadDir { +public: + cReadDir(const char *Directory); + ~cReadDir(); + bool Ok(void) { return directory != NULL; } + struct dirent *Next(void); + +private: + DIR *directory; + struct dirent *result; + union { // according to "The GNU C Library Reference Manual" + struct dirent d; + char b[offsetof(struct dirent, d_name) + NAME_MAX + 1]; + } u; + }; + +#endif /* READDIR_H */ + diff --git a/libs/vdr/include/String.h b/libs/vdr/include/String.h new file mode 100644 index 0000000..ec03cc1 --- /dev/null +++ b/libs/vdr/include/String.h @@ -0,0 +1,85 @@ +/** + * File: String.h + * Project: libvdr - classes taken from vdr-project + * + * from "Video Disk Recorder": + * + * Copyright (C) 2000, 2003, 2006, 2008 Klaus Schmidinger + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Or, point your browser to http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * + * The original author can be reached at kls@tvdr.de + * + * The vdr project's page is at http://www.tvdr.de + * + */ +#ifndef STRING_H +#define STRING_H + +#include <CharsetConv.h> +#include <stddef.h> +#include <stdarg.h> + +class cString { +public: + cString(const char *S = NULL, bool TakePointer = false); + cString(const cString &String); + virtual ~cString(); + operator const void * () const { return s; } // to catch cases where operator*() should be used + operator const char * () const { return s; } // for use in (const char *) context + const char * operator*() const { return s; } // for use in (const void *) context (printf() etc.) + cString &operator=(const cString &String); + cString &operator=(const char *String); + cString &Truncate(int Index); ///< Truncate the string at the given Index (if Index is < 0 it is counted from the end of the string). + static cString sprintf(const char *fmt, ...) __attribute__ ((format (printf, 1, 2))); + static cString vsprintf(const char *fmt, va_list &ap); + +private: + char *s; + }; + +char *strcpyrealloc(char *dest, const char *src); +char *strn0cpy(char *dest, const char *src, size_t n); +char *strreplace(char *s, char c1, char c2); +char *strreplace(char *s, const char *s1, const char *s2); ///< re-allocates 's' and deletes the original string if necessary! +inline char *skipspace(const char *s) +{ + if ((uchar)*s > ' ') // most strings don't have any leading space, so handle this case as fast as possible + return (char *)s; + while (*s && (uchar)*s <= ' ') // avoiding isspace() here, because it is much slower + s++; + return (char *)s; +} +char *stripspace(char *s); +char *compactspace(char *s); +cString strescape(const char *s, const char *chars); +bool startswith(const char *s, const char *p); +bool endswith(const char *s, const char *p); +bool isempty(const char *s); +int numdigits(int n); +bool isnumber(const char *s); +int64_t StrToNum(const char *s); + ///< Converts the given string to a number. + ///< The numerical part of the string may be followed by one of the letters + ///< K, M, G or T to abbreviate Kilo-, Mega-, Giga- or Terabyte, respectively + ///< (based on 1024). Everything after the first non-numeric character is + ///< silently ignored, as are any characters other than the ones mentioned here. +cString itoa(int n); + + + +#endif /* STRING_H */ + diff --git a/libs/vdr/include/StringList.h b/libs/vdr/include/StringList.h new file mode 100644 index 0000000..fee534b --- /dev/null +++ b/libs/vdr/include/StringList.h @@ -0,0 +1,61 @@ +/** + * File: StringList.h + * Project: libvdr - classes taken from vdr-project + * + * from "Video Disk Recorder": + * + * Copyright (C) 2000, 2003, 2006, 2008 Klaus Schmidinger + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Or, point your browser to http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * + * The original author can be reached at kls@tvdr.de + * + * The vdr project's page is at http://www.tvdr.de + * + */ +#ifndef STRINGLIST_H +#define STRINGLIST_H + +#include <Vector.h> +#include <string.h> + +inline int CompareStrings(const void *a, const void *b) +{ + return strcmp(*(const char **)a, *(const char **)b); +} + +inline int CompareStringsIgnoreCase(const void *a, const void *b) +{ + return strcasecmp(*(const char **)a, *(const char **)b); +} + +class cStringList : public cVector<char *> { +public: + cStringList(int Allocated = 10): cVector<char *>(Allocated) {} + virtual ~cStringList(); + int Find(const char *s) const; + void Sort(bool IgnoreCase = false) + { + if (IgnoreCase) + cVector<char *>::Sort(CompareStringsIgnoreCase); + else + cVector<char *>::Sort(CompareStrings); + } + virtual void Clear(void); + }; + +#endif /* STRINGLIST_H */ + diff --git a/libs/vdr/include/Thread.h b/libs/vdr/include/Thread.h new file mode 100644 index 0000000..ce8c999 --- /dev/null +++ b/libs/vdr/include/Thread.h @@ -0,0 +1,101 @@ +/** + * File: Thread.h + * Project: libvdr - classes taken from vdr-project + * + * from "Video Disk Recorder": + * + * Copyright (C) 2000, 2003, 2006, 2008 Klaus Schmidinger + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Or, point your browser to http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * + * The original author can be reached at kls@tvdr.de + * + * The vdr project's page is at http://www.tvdr.de + * + * ++2012-07-04(rma): + * As I don't like the necessity to subclass what should work in a thread, + * I extended the original sources, so that an arbitrary function can be + * a thread kernel. + */ +#ifndef THREAD_H +#define THREAD_H + +#include <Mutex.h> +#include <stddef.h> +#include <pthread.h> +typedef pid_t tThreadId; + +class cThread { +public: + cThread(const char *Description = NULL); + ///< Creates a new thread. + ///< If Description is present, a log file entry will be made when + ///< the thread starts and stops. The Start() function must be called + ///< to actually start the thread. + cThread(int (*ThreadCallback)(void *opaque, cThread *instance), void *opaque, const char *Description = NULL); + virtual ~cThread(); + + void SetDescription(const char *Description, ...) __attribute__ ((format (printf, 2, 3))); + bool Start(void); + ///< Actually starts the thread. + ///< If the thread is already running, nothing happens. + virtual void Cancel(int WaitSeconds = 0); + ///< Cancels the thread by first setting 'running' to false, so that + ///< the Action() loop can finish in an orderly fashion and then waiting + ///< up to WaitSeconds seconds for the thread to actually end. If the + ///< thread doesn't end by itself, it is killed. + ///< If WaitSeconds is -1, only 'running' is set to false and Cancel() + ///< returns immediately, without killing the thread. + bool Active(void); + ///< used from outside to check whether the thread is still alive. + bool Running(void) { return running; } + ///< used from inside the thread to check whether it may keep on running. + ///< Returns false if a derived cThread object shall leave its Action() + ///< function. Should be public and so available for callback thread kernels + + static tThreadId ThreadId(void); + static tThreadId IsMainThread(void) { return ThreadId() == mainThreadId; } + static void SetMainThreadId(void); + +protected: + void SetPriority(int Priority); + void SetIOPriority(int Priority); + void Lock(void) { mutex.Lock(); } + void Unlock(void) { mutex.Unlock(); } + virtual void Action(void); + ///< A derived cThread class must implement the code it wants to + ///< execute as a separate thread in this function. If this is + ///< a loop, it must check Running() repeatedly to see whether + ///< it's time to stop. + ///< To support callbacks as thread kernels, default implementation now + ///< starts the callback + +private: + bool active; + bool running; + pthread_t childTid; + tThreadId childThreadId; + cMutex mutex; + char *description; + int (*threadCallback)(void *, cThread *); + void *opaque; + static tThreadId mainThreadId; + static void *StartThread(cThread *Thread); + friend class cThreadLock; + }; + +#endif /* THREAD_H */ + diff --git a/libs/vdr/include/TimeMs.h b/libs/vdr/include/TimeMs.h new file mode 100644 index 0000000..dca609f --- /dev/null +++ b/libs/vdr/include/TimeMs.h @@ -0,0 +1,50 @@ +/** + * File: TimeMs.h + * Project: libvdr - classes taken from vdr-project + * + * from "Video Disk Recorder": + * + * Copyright (C) 2000, 2003, 2006, 2008 Klaus Schmidinger + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Or, point your browser to http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * + * The original author can be reached at kls@tvdr.de + * + * The vdr project's page is at http://www.tvdr.de + * + */ +#ifndef TIMEMS_H +#define TIMEMS_H + +#include <inttypes.h> + +class cTimeMs { +public: + cTimeMs(int Ms = 0); + ///< Creates a timer with ms resolution and an initial timeout of Ms. + ///< If Ms is negative the timer is not initialized with the current + ///< time. + void Set(int Ms = 0); + bool TimedOut(void); + uint64_t Elapsed(void); + static uint64_t Now(void); + +private: + uint64_t begin; + }; + +#endif /* TIMEMS_H */ + diff --git a/libs/vdr/include/Vector.h b/libs/vdr/include/Vector.h new file mode 100644 index 0000000..65760ac --- /dev/null +++ b/libs/vdr/include/Vector.h @@ -0,0 +1,119 @@ +/** + * File: Vector.h + * Project: libvdr - classes taken from vdr-project + * + * from "Video Disk Recorder": + * + * Copyright (C) 2000, 2003, 2006, 2008 Klaus Schmidinger + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Or, point your browser to http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * + * The original author can be reached at kls@tvdr.de + * + * The vdr project's page is at http://www.tvdr.de + * + */ +#ifndef VECTOR_H +#define VECTOR_H + +#include <stddef.h> +#include <Logging.h> +#include <stdlib.h> + +template<class T> class cVector { + ///< cVector may only be used for *simple* types, like int or pointers - not for class objects that allocate additional memory! +public: + cVector(int Allocated = 10) + { + allocated = 0; + size = 0; + data = NULL; + Realloc(Allocated); + } + virtual ~cVector() { free(data); } + T& At(int Index) const + { + Realloc(Index); + if (Index >= size) + size = Index + 1; + return data[Index]; + } + const T& operator[](int Index) const + { + return At(Index); + } + T& operator[](int Index) + { + return At(Index); + } + int Size(void) const { return size; } + virtual void Insert(T Data, int Before = 0) + { + if (Before < size) { + Realloc(size); + memmove(&data[Before + 1], &data[Before], (size - Before) * sizeof(T)); + size++; + data[Before] = Data; + } + else + Append(Data); + } + virtual void Append(T Data) + { + if (size >= allocated) + Realloc(allocated * 3 / 2); // increase size by 50% + data[size++] = Data; + } + virtual void Remove(int Index) + { + if (Index < size - 1) + memmove(&data[Index], &data[Index + 1], (size - Index) * sizeof(T)); + size--; + } + virtual void Clear(void) + { + for (int i = 0; i < size; i++) + data[i] = T(0); + size = 0; + } + void Sort(__compar_fn_t Compare) + { + qsort(data, size, sizeof(T), Compare); + } + +private: + mutable int allocated; + mutable int size; + mutable T *data; + cVector(const cVector &Vector) {} // don't copy... + cVector &operator=(const cVector &Vector) { return *this; } // ...or assign this! + void Realloc(int Index) const + { + if (++Index > allocated) { + data = (T *)realloc(data, Index * sizeof(T)); + if (!data) { + esyslog("ERROR: out of memory - abort!"); + abort(); + } + for (int i = allocated; i < Index; i++) + data[i] = T(0); + allocated = Index; + } + } + }; + +#endif /* VECTOR_H */ + diff --git a/libs/vdr/include/i18n.h b/libs/vdr/include/i18n.h new file mode 100644 index 0000000..40185e4 --- /dev/null +++ b/libs/vdr/include/i18n.h @@ -0,0 +1,108 @@ +/** + * File: i18n.h + * Project: libvdr - classes taken from vdr-project + * + * from "Video Disk Recorder": + * + * Copyright (C) 2000, 2003, 2006, 2008 Klaus Schmidinger + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Or, point your browser to http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * + * The original author can be reached at kls@tvdr.de + * + * The vdr project's page is at http://www.tvdr.de + * + */ +#ifndef __I18N_H +#define __I18N_H + +#include <stdio.h> + +#define I18N_DEFAULT_LOCALE "en_US" +#define I18N_MAX_LOCALE_LEN 16 // for buffers that hold en_US etc. +#define I18N_MAX_LANGUAGES 256 // for buffers that hold all available languages +class cStringList; +void I18nInitialize(const char *LocaleDir = NULL); + ///< Detects all available locales and loads the language names and codes. + ///< If LocaleDir is given, it must point to a static string that lives + ///< for the entire lifetime of the program. +void I18nRegister(const char *Plugin); + ///< Registers the named plugin, so that it can use internationalized texts. +void I18nSetLocale(const char *Locale); + ///< Sets the current locale to Locale. The default locale is "en_US". + ///< If no such locale has been found in the call to I18nInitialize(), + ///< nothing happens. +int I18nCurrentLanguage(void); + ///< Returns the index of the current language. This number stays the + ///< same for any given language while the program is running, but may + ///< be different when the program is run again (for instance because + ///< a locale has been added or removed). The default locale ("en_US") + ///< always has a zero index. +void I18nSetLanguage(int Language); + ///< Sets the current language index to Language. If Language is outside + ///< the range of available languages, nothing happens. +int I18nNumLanguagesWithLocale(void); + ///< Returns the number of entries in the list returned by I18nLanguages() + ///< that actually have a locale. +const cStringList *I18nLanguages(void); + ///< Returns the list of available languages. Values returned by + ///< I18nCurrentLanguage() are indexes into this list. + ///< Only the first I18nNumLanguagesWithLocale() entries in this list + ///< have an actual locale installed. The rest are just dummy entries + ///< to allow having three letter language codes for other languages + ///< that have no actual locale on this system. +const char *I18nTranslate(const char *s, const char *Plugin = NULL) __attribute_format_arg__(1); + ///< Translates the given string (with optional Plugin context) into + ///< the current language. If no translation is available, the original + ///< string will be returned. +const char *I18nLocale(int Language); + ///< Returns the locale code of the given Language (which is an index as + ///< returned by I18nCurrentLanguage()). If Language is outside the range + ///< of available languages, NULL is returned. +const char *I18nLanguageCode(int Language); + ///< Returns the three letter language code of the given Language (which + ///< is an index as returned by I18nCurrentLanguage()). If Language is + ///< outside the range of available languages, NULL is returned. + ///< The returned string may consist of several alternative three letter + ///< language codes, separated by commas (as in "deu,ger"). +int I18nLanguageIndex(const char *Code); + ///< Returns the index of the language with the given three letter + ///< language Code. If no suitable language is found, -1 is returned. +const char *I18nNormalizeLanguageCode(const char *Code); + ///< Returns a 3 letter language code that may not be zero terminated. + ///< If no normalized language code can be found, the given Code is returned. + ///< Make sure at most 3 characters are copied when using it! +bool I18nIsPreferredLanguage(int *PreferredLanguages, const char *LanguageCode, int &OldPreference, int *Position = NULL); + ///< Checks the given LanguageCode (which may be something like "eng" or "eng+deu") + ///< against the PreferredLanguages and returns true if one is found that has an index + ///< smaller than OldPreference (which should be initialized to -1 before the first + ///< call to this function in a sequence of checks). If LanguageCode is not any of + ///< the PreferredLanguages, and OldPreference is less than zero, OldPreference will + ///< be set to a value higher than the highest language index. If Position is given, + ///< it will return 0 if this was a single language code (like "eng"), 1 if it was + ///< the first of two language codes (like "eng" out of "eng+deu") and 2 if it was + ///< the second one (like "deu" out of ""eng+deu"). + +#ifdef PLUGIN_NAME_I18N +#define tr(s) I18nTranslate(s, "vdr-" PLUGIN_NAME_I18N) +#define trVDR(s) I18nTranslate(s) // to use a text that's in the VDR core's translation file +#else +#define tr(s) I18nTranslate(s) +#endif + +#define trNOOP(s) (s) + +#endif //__I18N_H diff --git a/libs/vdr/include/tools.h b/libs/vdr/include/tools.h new file mode 100644 index 0000000..bb159aa --- /dev/null +++ b/libs/vdr/include/tools.h @@ -0,0 +1,49 @@ +/** + * File: tools.h + * Project: libvdr - classes taken from vdr-project + * + * from "Video Disk Recorder": + * + * Copyright (C) 2000, 2003, 2006, 2008 Klaus Schmidinger + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Or, point your browser to http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * + * The original author can be reached at kls@tvdr.de + * + * The vdr project's page is at http://www.tvdr.de + * + */ +#ifndef TOOLS_H +#define TOOLS_H + +#include <stddef.h> + +#define MALLOC(type, size) (type *)malloc(sizeof(type) * (size)) + +template<class T> inline void DELETENULL(T *&p) { T *q = p; p = NULL; delete q; } + +#define CHECK(s) { if ((s) < 0) LOG_ERROR; } // used for 'ioctl()' calls +#define FATALERRNO (errno && errno != EAGAIN && errno != EINTR) + +#ifndef __STL_CONFIG_H // in case some plugin needs to use the STL +template<class T> inline T min(T a, T b) { return a <= b ? a : b; } +template<class T> inline T max(T a, T b) { return a >= b ? a : b; } +template<class T> inline int sgn(T a) { return a < 0 ? -1 : a > 0 ? 1 : 0; } +template<class T> inline void swap(T &a, T &b) { T t = a; a = b; b = t; } +#endif + +#endif /* TOOLS_H */ + diff --git a/libs/vdr/nbproject/Makefile-Debug.mk b/libs/vdr/nbproject/Makefile-Debug.mk new file mode 100644 index 0000000..af3fe72 --- /dev/null +++ b/libs/vdr/nbproject/Makefile-Debug.mk @@ -0,0 +1,145 @@ +# +# Generated Makefile - do not edit! +# +# Edit the Makefile in the project folder instead (../Makefile). Each target +# has a -pre and a -post target defined where you can add customized code. +# +# This makefile implements configuration specific macros and targets. + + +# Environment +MKDIR=mkdir +CP=cp +GREP=grep +NM=nm +CCADMIN=CCadmin +RANLIB=ranlib +CC=gcc +CCC=g++ +CXX=g++ +FC=gfortran +AS=as + +# Macros +CND_PLATFORM=GNU-Linux-x86 +CND_CONF=Debug +CND_DISTDIR=dist +CND_BUILDDIR=build + +# Include project Makefile +include Makefile + +# Object Directory +OBJECTDIR=${CND_BUILDDIR}/${CND_CONF}/${CND_PLATFORM} + +# Object Files +OBJECTFILES= \ + ${OBJECTDIR}/src/StringList.o \ + ${OBJECTDIR}/src/TimeMs.o \ + ${OBJECTDIR}/src/Thread.o \ + ${OBJECTDIR}/src/String.o \ + ${OBJECTDIR}/src/i18n.o \ + ${OBJECTDIR}/src/Logging.o \ + ${OBJECTDIR}/src/ReadDir.o \ + ${OBJECTDIR}/src/CondWait.o \ + ${OBJECTDIR}/src/FileNameList.o \ + ${OBJECTDIR}/src/Mutex.o \ + ${OBJECTDIR}/src/CharsetConv.o + + +# C Compiler Flags +CFLAGS= + +# CC Compiler Flags +CCFLAGS=-std=gnu++0x -fomit-frame-pointer -fPIC -pthread -Wall -Wno-parentheses -Wno-switch -Wdisabled-optimization -Wpointer-arith -Wredundant-decls -Wwrite-strings -Wtype-limits -Wundef -fno-math-errno -fno-signed-zeros -fno-tree-vectorize -Werror=implicit-function-declaration -ansi +CXXFLAGS=-std=gnu++0x -fomit-frame-pointer -fPIC -pthread -Wall -Wno-parentheses -Wno-switch -Wdisabled-optimization -Wpointer-arith -Wredundant-decls -Wwrite-strings -Wtype-limits -Wundef -fno-math-errno -fno-signed-zeros -fno-tree-vectorize -Werror=implicit-function-declaration -ansi + +# Fortran Compiler Flags +FFLAGS= + +# Assembler Flags +ASFLAGS= + +# Link Libraries and Options +LDLIBSOPTIONS= + +# Build Targets +.build-conf: ${BUILD_SUBPROJECTS} + "${MAKE}" -f nbproject/Makefile-${CND_CONF}.mk ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/libvdr.a + +${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/libvdr.a: ${OBJECTFILES} + ${MKDIR} -p ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM} + ${RM} ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/libvdr.a + ${AR} -rv ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/libvdr.a ${OBJECTFILES} + $(RANLIB) ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/libvdr.a + +${OBJECTDIR}/src/StringList.o: nbproject/Makefile-${CND_CONF}.mk src/StringList.cc + ${MKDIR} -p ${OBJECTDIR}/src + ${RM} $@.d + $(COMPILE.cc) -g -Wall -DLOCDIR=/usr/share/locale -D_GNU_SOURCE=1 -D_REENTRANT -Iinclude -I/usr/include/freetype2 -I/usr/include/fribidi -MMD -MP -MF $@.d -o ${OBJECTDIR}/src/StringList.o src/StringList.cc + +${OBJECTDIR}/src/TimeMs.o: nbproject/Makefile-${CND_CONF}.mk src/TimeMs.cc + ${MKDIR} -p ${OBJECTDIR}/src + ${RM} $@.d + $(COMPILE.cc) -g -Wall -DLOCDIR=/usr/share/locale -D_GNU_SOURCE=1 -D_REENTRANT -Iinclude -I/usr/include/freetype2 -I/usr/include/fribidi -MMD -MP -MF $@.d -o ${OBJECTDIR}/src/TimeMs.o src/TimeMs.cc + +${OBJECTDIR}/src/Thread.o: nbproject/Makefile-${CND_CONF}.mk src/Thread.cc + ${MKDIR} -p ${OBJECTDIR}/src + ${RM} $@.d + $(COMPILE.cc) -g -Wall -DLOCDIR=/usr/share/locale -D_GNU_SOURCE=1 -D_REENTRANT -Iinclude -I/usr/include/freetype2 -I/usr/include/fribidi -MMD -MP -MF $@.d -o ${OBJECTDIR}/src/Thread.o src/Thread.cc + +${OBJECTDIR}/src/String.o: nbproject/Makefile-${CND_CONF}.mk src/String.cc + ${MKDIR} -p ${OBJECTDIR}/src + ${RM} $@.d + $(COMPILE.cc) -g -Wall -DLOCDIR=/usr/share/locale -D_GNU_SOURCE=1 -D_REENTRANT -Iinclude -I/usr/include/freetype2 -I/usr/include/fribidi -MMD -MP -MF $@.d -o ${OBJECTDIR}/src/String.o src/String.cc + +${OBJECTDIR}/src/i18n.o: nbproject/Makefile-${CND_CONF}.mk src/i18n.cc + ${MKDIR} -p ${OBJECTDIR}/src + ${RM} $@.d + $(COMPILE.cc) -g -Wall -DLOCDIR=/usr/share/locale -D_GNU_SOURCE=1 -D_REENTRANT -Iinclude -I/usr/include/freetype2 -I/usr/include/fribidi -MMD -MP -MF $@.d -o ${OBJECTDIR}/src/i18n.o src/i18n.cc + +${OBJECTDIR}/src/Logging.o: nbproject/Makefile-${CND_CONF}.mk src/Logging.cc + ${MKDIR} -p ${OBJECTDIR}/src + ${RM} $@.d + $(COMPILE.cc) -g -Wall -DLOCDIR=/usr/share/locale -D_GNU_SOURCE=1 -D_REENTRANT -Iinclude -I/usr/include/freetype2 -I/usr/include/fribidi -MMD -MP -MF $@.d -o ${OBJECTDIR}/src/Logging.o src/Logging.cc + +${OBJECTDIR}/src/ReadDir.o: nbproject/Makefile-${CND_CONF}.mk src/ReadDir.cc + ${MKDIR} -p ${OBJECTDIR}/src + ${RM} $@.d + $(COMPILE.cc) -g -Wall -DLOCDIR=/usr/share/locale -D_GNU_SOURCE=1 -D_REENTRANT -Iinclude -I/usr/include/freetype2 -I/usr/include/fribidi -MMD -MP -MF $@.d -o ${OBJECTDIR}/src/ReadDir.o src/ReadDir.cc + +${OBJECTDIR}/src/CondWait.o: nbproject/Makefile-${CND_CONF}.mk src/CondWait.cc + ${MKDIR} -p ${OBJECTDIR}/src + ${RM} $@.d + $(COMPILE.cc) -g -Wall -DLOCDIR=/usr/share/locale -D_GNU_SOURCE=1 -D_REENTRANT -Iinclude -I/usr/include/freetype2 -I/usr/include/fribidi -MMD -MP -MF $@.d -o ${OBJECTDIR}/src/CondWait.o src/CondWait.cc + +${OBJECTDIR}/src/FileNameList.o: nbproject/Makefile-${CND_CONF}.mk src/FileNameList.cc + ${MKDIR} -p ${OBJECTDIR}/src + ${RM} $@.d + $(COMPILE.cc) -g -Wall -DLOCDIR=/usr/share/locale -D_GNU_SOURCE=1 -D_REENTRANT -Iinclude -I/usr/include/freetype2 -I/usr/include/fribidi -MMD -MP -MF $@.d -o ${OBJECTDIR}/src/FileNameList.o src/FileNameList.cc + +${OBJECTDIR}/src/Mutex.o: nbproject/Makefile-${CND_CONF}.mk src/Mutex.cc + ${MKDIR} -p ${OBJECTDIR}/src + ${RM} $@.d + $(COMPILE.cc) -g -Wall -DLOCDIR=/usr/share/locale -D_GNU_SOURCE=1 -D_REENTRANT -Iinclude -I/usr/include/freetype2 -I/usr/include/fribidi -MMD -MP -MF $@.d -o ${OBJECTDIR}/src/Mutex.o src/Mutex.cc + +${OBJECTDIR}/src/CharsetConv.o: nbproject/Makefile-${CND_CONF}.mk src/CharsetConv.cc + ${MKDIR} -p ${OBJECTDIR}/src + ${RM} $@.d + $(COMPILE.cc) -g -Wall -DLOCDIR=/usr/share/locale -D_GNU_SOURCE=1 -D_REENTRANT -Iinclude -I/usr/include/freetype2 -I/usr/include/fribidi -MMD -MP -MF $@.d -o ${OBJECTDIR}/src/CharsetConv.o src/CharsetConv.cc + +# Subprojects +.build-subprojects: + +# Clean Targets +.clean-conf: ${CLEAN_SUBPROJECTS} + ${RM} -r ${CND_BUILDDIR}/${CND_CONF} + ${RM} ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/libvdr.a + +# Subprojects +.clean-subprojects: + +# Enable dependency checking +.dep.inc: .depcheck-impl + +include .dep.inc diff --git a/libs/vdr/nbproject/Makefile-Release.mk b/libs/vdr/nbproject/Makefile-Release.mk new file mode 100644 index 0000000..af83e45 --- /dev/null +++ b/libs/vdr/nbproject/Makefile-Release.mk @@ -0,0 +1,145 @@ +# +# Generated Makefile - do not edit! +# +# Edit the Makefile in the project folder instead (../Makefile). Each target +# has a -pre and a -post target defined where you can add customized code. +# +# This makefile implements configuration specific macros and targets. + + +# Environment +MKDIR=mkdir +CP=cp +GREP=grep +NM=nm +CCADMIN=CCadmin +RANLIB=ranlib +CC=gcc +CCC=g++ +CXX=g++ +FC=gfortran +AS=as + +# Macros +CND_PLATFORM=GNU-Linux-x86 +CND_CONF=Release +CND_DISTDIR=dist +CND_BUILDDIR=build + +# Include project Makefile +include Makefile + +# Object Directory +OBJECTDIR=${CND_BUILDDIR}/${CND_CONF}/${CND_PLATFORM} + +# Object Files +OBJECTFILES= \ + ${OBJECTDIR}/src/StringList.o \ + ${OBJECTDIR}/src/TimeMs.o \ + ${OBJECTDIR}/src/Thread.o \ + ${OBJECTDIR}/src/String.o \ + ${OBJECTDIR}/src/i18n.o \ + ${OBJECTDIR}/src/Logging.o \ + ${OBJECTDIR}/src/ReadDir.o \ + ${OBJECTDIR}/src/CondWait.o \ + ${OBJECTDIR}/src/FileNameList.o \ + ${OBJECTDIR}/src/Mutex.o \ + ${OBJECTDIR}/src/CharsetConv.o + + +# C Compiler Flags +CFLAGS= + +# CC Compiler Flags +CCFLAGS= +CXXFLAGS= + +# Fortran Compiler Flags +FFLAGS= + +# Assembler Flags +ASFLAGS= + +# Link Libraries and Options +LDLIBSOPTIONS= + +# Build Targets +.build-conf: ${BUILD_SUBPROJECTS} + "${MAKE}" -f nbproject/Makefile-${CND_CONF}.mk ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/libvdr.a + +${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/libvdr.a: ${OBJECTFILES} + ${MKDIR} -p ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM} + ${RM} ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/libvdr.a + ${AR} -rv ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/libvdr.a ${OBJECTFILES} + $(RANLIB) ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/libvdr.a + +${OBJECTDIR}/src/StringList.o: nbproject/Makefile-${CND_CONF}.mk src/StringList.cc + ${MKDIR} -p ${OBJECTDIR}/src + ${RM} $@.d + $(COMPILE.cc) -O2 -MMD -MP -MF $@.d -o ${OBJECTDIR}/src/StringList.o src/StringList.cc + +${OBJECTDIR}/src/TimeMs.o: nbproject/Makefile-${CND_CONF}.mk src/TimeMs.cc + ${MKDIR} -p ${OBJECTDIR}/src + ${RM} $@.d + $(COMPILE.cc) -O2 -MMD -MP -MF $@.d -o ${OBJECTDIR}/src/TimeMs.o src/TimeMs.cc + +${OBJECTDIR}/src/Thread.o: nbproject/Makefile-${CND_CONF}.mk src/Thread.cc + ${MKDIR} -p ${OBJECTDIR}/src + ${RM} $@.d + $(COMPILE.cc) -O2 -MMD -MP -MF $@.d -o ${OBJECTDIR}/src/Thread.o src/Thread.cc + +${OBJECTDIR}/src/String.o: nbproject/Makefile-${CND_CONF}.mk src/String.cc + ${MKDIR} -p ${OBJECTDIR}/src + ${RM} $@.d + $(COMPILE.cc) -O2 -MMD -MP -MF $@.d -o ${OBJECTDIR}/src/String.o src/String.cc + +${OBJECTDIR}/src/i18n.o: nbproject/Makefile-${CND_CONF}.mk src/i18n.cc + ${MKDIR} -p ${OBJECTDIR}/src + ${RM} $@.d + $(COMPILE.cc) -O2 -MMD -MP -MF $@.d -o ${OBJECTDIR}/src/i18n.o src/i18n.cc + +${OBJECTDIR}/src/Logging.o: nbproject/Makefile-${CND_CONF}.mk src/Logging.cc + ${MKDIR} -p ${OBJECTDIR}/src + ${RM} $@.d + $(COMPILE.cc) -O2 -MMD -MP -MF $@.d -o ${OBJECTDIR}/src/Logging.o src/Logging.cc + +${OBJECTDIR}/src/ReadDir.o: nbproject/Makefile-${CND_CONF}.mk src/ReadDir.cc + ${MKDIR} -p ${OBJECTDIR}/src + ${RM} $@.d + $(COMPILE.cc) -O2 -MMD -MP -MF $@.d -o ${OBJECTDIR}/src/ReadDir.o src/ReadDir.cc + +${OBJECTDIR}/src/CondWait.o: nbproject/Makefile-${CND_CONF}.mk src/CondWait.cc + ${MKDIR} -p ${OBJECTDIR}/src + ${RM} $@.d + $(COMPILE.cc) -O2 -MMD -MP -MF $@.d -o ${OBJECTDIR}/src/CondWait.o src/CondWait.cc + +${OBJECTDIR}/src/FileNameList.o: nbproject/Makefile-${CND_CONF}.mk src/FileNameList.cc + ${MKDIR} -p ${OBJECTDIR}/src + ${RM} $@.d + $(COMPILE.cc) -O2 -MMD -MP -MF $@.d -o ${OBJECTDIR}/src/FileNameList.o src/FileNameList.cc + +${OBJECTDIR}/src/Mutex.o: nbproject/Makefile-${CND_CONF}.mk src/Mutex.cc + ${MKDIR} -p ${OBJECTDIR}/src + ${RM} $@.d + $(COMPILE.cc) -O2 -MMD -MP -MF $@.d -o ${OBJECTDIR}/src/Mutex.o src/Mutex.cc + +${OBJECTDIR}/src/CharsetConv.o: nbproject/Makefile-${CND_CONF}.mk src/CharsetConv.cc + ${MKDIR} -p ${OBJECTDIR}/src + ${RM} $@.d + $(COMPILE.cc) -O2 -MMD -MP -MF $@.d -o ${OBJECTDIR}/src/CharsetConv.o src/CharsetConv.cc + +# Subprojects +.build-subprojects: + +# Clean Targets +.clean-conf: ${CLEAN_SUBPROJECTS} + ${RM} -r ${CND_BUILDDIR}/${CND_CONF} + ${RM} ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/libvdr.a + +# Subprojects +.clean-subprojects: + +# Enable dependency checking +.dep.inc: .depcheck-impl + +include .dep.inc diff --git a/libs/vdr/nbproject/Makefile-impl.mk b/libs/vdr/nbproject/Makefile-impl.mk new file mode 100644 index 0000000..4112c2c --- /dev/null +++ b/libs/vdr/nbproject/Makefile-impl.mk @@ -0,0 +1,133 @@ +# +# Generated Makefile - do not edit! +# +# Edit the Makefile in the project folder instead (../Makefile). Each target +# has a pre- and a post- target defined where you can add customization code. +# +# This makefile implements macros and targets common to all configurations. +# +# NOCDDL + + +# Building and Cleaning subprojects are done by default, but can be controlled with the SUB +# macro. If SUB=no, subprojects will not be built or cleaned. The following macro +# statements set BUILD_SUB-CONF and CLEAN_SUB-CONF to .build-reqprojects-conf +# and .clean-reqprojects-conf unless SUB has the value 'no' +SUB_no=NO +SUBPROJECTS=${SUB_${SUB}} +BUILD_SUBPROJECTS_=.build-subprojects +BUILD_SUBPROJECTS_NO= +BUILD_SUBPROJECTS=${BUILD_SUBPROJECTS_${SUBPROJECTS}} +CLEAN_SUBPROJECTS_=.clean-subprojects +CLEAN_SUBPROJECTS_NO= +CLEAN_SUBPROJECTS=${CLEAN_SUBPROJECTS_${SUBPROJECTS}} + + +# Project Name +PROJECTNAME=vdr + +# Active Configuration +DEFAULTCONF=Debug +CONF=${DEFAULTCONF} + +# All Configurations +ALLCONFS=Debug Release + + +# build +.build-impl: .build-pre .validate-impl .depcheck-impl + @#echo "=> Running $@... Configuration=$(CONF)" + "${MAKE}" -f nbproject/Makefile-${CONF}.mk QMAKE=${QMAKE} SUBPROJECTS=${SUBPROJECTS} .build-conf + + +# clean +.clean-impl: .clean-pre .validate-impl .depcheck-impl + @#echo "=> Running $@... Configuration=$(CONF)" + "${MAKE}" -f nbproject/Makefile-${CONF}.mk QMAKE=${QMAKE} SUBPROJECTS=${SUBPROJECTS} .clean-conf + + +# clobber +.clobber-impl: .clobber-pre .depcheck-impl + @#echo "=> Running $@..." + for CONF in ${ALLCONFS}; \ + do \ + "${MAKE}" -f nbproject/Makefile-$${CONF}.mk QMAKE=${QMAKE} SUBPROJECTS=${SUBPROJECTS} .clean-conf; \ + done + +# all +.all-impl: .all-pre .depcheck-impl + @#echo "=> Running $@..." + for CONF in ${ALLCONFS}; \ + do \ + "${MAKE}" -f nbproject/Makefile-$${CONF}.mk QMAKE=${QMAKE} SUBPROJECTS=${SUBPROJECTS} .build-conf; \ + done + +# build tests +.build-tests-impl: .build-impl .build-tests-pre + @#echo "=> Running $@... Configuration=$(CONF)" + "${MAKE}" -f nbproject/Makefile-${CONF}.mk SUBPROJECTS=${SUBPROJECTS} .build-tests-conf + +# run tests +.test-impl: .build-tests-impl .test-pre + @#echo "=> Running $@... Configuration=$(CONF)" + "${MAKE}" -f nbproject/Makefile-${CONF}.mk SUBPROJECTS=${SUBPROJECTS} .test-conf + +# dependency checking support +.depcheck-impl: + @echo "# This code depends on make tool being used" >.dep.inc + @if [ -n "${MAKE_VERSION}" ]; then \ + echo "DEPFILES=\$$(wildcard \$$(addsuffix .d, \$${OBJECTFILES}))" >>.dep.inc; \ + echo "ifneq (\$${DEPFILES},)" >>.dep.inc; \ + echo "include \$${DEPFILES}" >>.dep.inc; \ + echo "endif" >>.dep.inc; \ + else \ + echo ".KEEP_STATE:" >>.dep.inc; \ + echo ".KEEP_STATE_FILE:.make.state.\$${CONF}" >>.dep.inc; \ + fi + +# configuration validation +.validate-impl: + @if [ ! -f nbproject/Makefile-${CONF}.mk ]; \ + then \ + echo ""; \ + echo "Error: can not find the makefile for configuration '${CONF}' in project ${PROJECTNAME}"; \ + echo "See 'make help' for details."; \ + echo "Current directory: " `pwd`; \ + echo ""; \ + fi + @if [ ! -f nbproject/Makefile-${CONF}.mk ]; \ + then \ + exit 1; \ + fi + + +# help +.help-impl: .help-pre + @echo "This makefile supports the following configurations:" + @echo " ${ALLCONFS}" + @echo "" + @echo "and the following targets:" + @echo " build (default target)" + @echo " clean" + @echo " clobber" + @echo " all" + @echo " help" + @echo "" + @echo "Makefile Usage:" + @echo " make [CONF=<CONFIGURATION>] [SUB=no] build" + @echo " make [CONF=<CONFIGURATION>] [SUB=no] clean" + @echo " make [SUB=no] clobber" + @echo " make [SUB=no] all" + @echo " make help" + @echo "" + @echo "Target 'build' will build a specific configuration and, unless 'SUB=no'," + @echo " also build subprojects." + @echo "Target 'clean' will clean a specific configuration and, unless 'SUB=no'," + @echo " also clean subprojects." + @echo "Target 'clobber' will remove all built files from all configurations and," + @echo " unless 'SUB=no', also from subprojects." + @echo "Target 'all' will will build all configurations and, unless 'SUB=no'," + @echo " also build subprojects." + @echo "Target 'help' prints this message." + @echo "" + diff --git a/libs/vdr/nbproject/Makefile-variables.mk b/libs/vdr/nbproject/Makefile-variables.mk new file mode 100644 index 0000000..7b6323c --- /dev/null +++ b/libs/vdr/nbproject/Makefile-variables.mk @@ -0,0 +1,35 @@ +# +# Generated - do not edit! +# +# NOCDDL +# +CND_BASEDIR=`pwd` +CND_BUILDDIR=build +CND_DISTDIR=dist +# Debug configuration +CND_PLATFORM_Debug=GNU-Linux-x86 +CND_ARTIFACT_DIR_Debug=dist/Debug/GNU-Linux-x86 +CND_ARTIFACT_NAME_Debug=libvdr.a +CND_ARTIFACT_PATH_Debug=dist/Debug/GNU-Linux-x86/libvdr.a +CND_PACKAGE_DIR_Debug=dist/Debug/GNU-Linux-x86/package +CND_PACKAGE_NAME_Debug=vdr.tar +CND_PACKAGE_PATH_Debug=dist/Debug/GNU-Linux-x86/package/vdr.tar +# Release configuration +CND_PLATFORM_Release=GNU-Linux-x86 +CND_ARTIFACT_DIR_Release=dist/Release/GNU-Linux-x86 +CND_ARTIFACT_NAME_Release=libvdr.a +CND_ARTIFACT_PATH_Release=dist/Release/GNU-Linux-x86/libvdr.a +CND_PACKAGE_DIR_Release=dist/Release/GNU-Linux-x86/package +CND_PACKAGE_NAME_Release=vdr.tar +CND_PACKAGE_PATH_Release=dist/Release/GNU-Linux-x86/package/vdr.tar +# +# include compiler specific variables +# +# dmake command +ROOT:sh = test -f nbproject/private/Makefile-variables.mk || \ + (mkdir -p nbproject/private && touch nbproject/private/Makefile-variables.mk) +# +# gmake command +.PHONY: $(shell test -f nbproject/private/Makefile-variables.mk || (mkdir -p nbproject/private && touch nbproject/private/Makefile-variables.mk)) +# +include nbproject/private/Makefile-variables.mk diff --git a/libs/vdr/nbproject/Package-Debug.bash b/libs/vdr/nbproject/Package-Debug.bash new file mode 100644 index 0000000..f1d82e6 --- /dev/null +++ b/libs/vdr/nbproject/Package-Debug.bash @@ -0,0 +1,75 @@ +#!/bin/bash -x + +# +# Generated - do not edit! +# + +# Macros +TOP=`pwd` +CND_PLATFORM=GNU-Linux-x86 +CND_CONF=Debug +CND_DISTDIR=dist +CND_BUILDDIR=build +NBTMPDIR=${CND_BUILDDIR}/${CND_CONF}/${CND_PLATFORM}/tmp-packaging +TMPDIRNAME=tmp-packaging +OUTPUT_PATH=${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/libvdr.a +OUTPUT_BASENAME=libvdr.a +PACKAGE_TOP_DIR=vdr/ + +# Functions +function checkReturnCode +{ + rc=$? + if [ $rc != 0 ] + then + exit $rc + fi +} +function makeDirectory +# $1 directory path +# $2 permission (optional) +{ + mkdir -p "$1" + checkReturnCode + if [ "$2" != "" ] + then + chmod $2 "$1" + checkReturnCode + fi +} +function copyFileToTmpDir +# $1 from-file path +# $2 to-file path +# $3 permission +{ + cp "$1" "$2" + checkReturnCode + if [ "$3" != "" ] + then + chmod $3 "$2" + checkReturnCode + fi +} + +# Setup +cd "${TOP}" +mkdir -p ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/package +rm -rf ${NBTMPDIR} +mkdir -p ${NBTMPDIR} + +# Copy files and create directories and links +cd "${TOP}" +makeDirectory "${NBTMPDIR}/vdr/lib" +copyFileToTmpDir "${OUTPUT_PATH}" "${NBTMPDIR}/${PACKAGE_TOP_DIR}lib/${OUTPUT_BASENAME}" 0644 + + +# Generate tar file +cd "${TOP}" +rm -f ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/package/vdr.tar +cd ${NBTMPDIR} +tar -vcf ../../../../${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/package/vdr.tar * +checkReturnCode + +# Cleanup +cd "${TOP}" +rm -rf ${NBTMPDIR} diff --git a/libs/vdr/nbproject/Package-Release.bash b/libs/vdr/nbproject/Package-Release.bash new file mode 100644 index 0000000..146443a --- /dev/null +++ b/libs/vdr/nbproject/Package-Release.bash @@ -0,0 +1,75 @@ +#!/bin/bash -x + +# +# Generated - do not edit! +# + +# Macros +TOP=`pwd` +CND_PLATFORM=GNU-Linux-x86 +CND_CONF=Release +CND_DISTDIR=dist +CND_BUILDDIR=build +NBTMPDIR=${CND_BUILDDIR}/${CND_CONF}/${CND_PLATFORM}/tmp-packaging +TMPDIRNAME=tmp-packaging +OUTPUT_PATH=${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/libvdr.a +OUTPUT_BASENAME=libvdr.a +PACKAGE_TOP_DIR=vdr/ + +# Functions +function checkReturnCode +{ + rc=$? + if [ $rc != 0 ] + then + exit $rc + fi +} +function makeDirectory +# $1 directory path +# $2 permission (optional) +{ + mkdir -p "$1" + checkReturnCode + if [ "$2" != "" ] + then + chmod $2 "$1" + checkReturnCode + fi +} +function copyFileToTmpDir +# $1 from-file path +# $2 to-file path +# $3 permission +{ + cp "$1" "$2" + checkReturnCode + if [ "$3" != "" ] + then + chmod $3 "$2" + checkReturnCode + fi +} + +# Setup +cd "${TOP}" +mkdir -p ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/package +rm -rf ${NBTMPDIR} +mkdir -p ${NBTMPDIR} + +# Copy files and create directories and links +cd "${TOP}" +makeDirectory "${NBTMPDIR}/vdr/lib" +copyFileToTmpDir "${OUTPUT_PATH}" "${NBTMPDIR}/${PACKAGE_TOP_DIR}lib/${OUTPUT_BASENAME}" 0644 + + +# Generate tar file +cd "${TOP}" +rm -f ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/package/vdr.tar +cd ${NBTMPDIR} +tar -vcf ../../../../${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/package/vdr.tar * +checkReturnCode + +# Cleanup +cd "${TOP}" +rm -rf ${NBTMPDIR} diff --git a/libs/vdr/nbproject/configurations.xml b/libs/vdr/nbproject/configurations.xml new file mode 100644 index 0000000..90cd3e0 --- /dev/null +++ b/libs/vdr/nbproject/configurations.xml @@ -0,0 +1,101 @@ +<?xml version="1.0" encoding="UTF-8"?> +<configurationDescriptor version="80"> + <logicalFolder name="root" displayName="root" projectFiles="true" kind="ROOT"> + <logicalFolder name="HeaderFiles" + displayName="Header Files" + projectFiles="true"> + <itemPath>include/CharsetConv.h</itemPath> + <itemPath>include/CondWait.h</itemPath> + <itemPath>include/FileNameList.h</itemPath> + <itemPath>include/Logging.h</itemPath> + <itemPath>include/Mutex.h</itemPath> + <itemPath>include/ReadDir.h</itemPath> + <itemPath>include/String.h</itemPath> + <itemPath>include/StringList.h</itemPath> + <itemPath>include/Thread.h</itemPath> + <itemPath>include/TimeMs.h</itemPath> + <itemPath>include/Vector.h</itemPath> + <itemPath>include/i18n.h</itemPath> + <itemPath>include/tools.h</itemPath> + </logicalFolder> + <logicalFolder name="ResourceFiles" + displayName="Resource Files" + projectFiles="true"> + </logicalFolder> + <logicalFolder name="SourceFiles" + displayName="Source Files" + projectFiles="true"> + <itemPath>src/CharsetConv.cc</itemPath> + <itemPath>src/CondWait.cc</itemPath> + <itemPath>src/FileNameList.cc</itemPath> + <itemPath>src/Logging.cc</itemPath> + <itemPath>src/Mutex.cc</itemPath> + <itemPath>src/ReadDir.cc</itemPath> + <itemPath>src/String.cc</itemPath> + <itemPath>src/StringList.cc</itemPath> + <itemPath>src/Thread.cc</itemPath> + <itemPath>src/TimeMs.cc</itemPath> + <itemPath>src/i18n.cc</itemPath> + </logicalFolder> + <logicalFolder name="TestFiles" + displayName="Test Files" + projectFiles="false" + kind="TEST_LOGICAL_FOLDER"> + </logicalFolder> + <logicalFolder name="ExternalFiles" + displayName="Important Files" + projectFiles="false" + kind="IMPORTANT_FILES_FOLDER"> + <itemPath>Makefile</itemPath> + </logicalFolder> + </logicalFolder> + <projectmakefile>Makefile</projectmakefile> + <confs> + <conf name="Debug" type="3"> + <toolsSet> + <remote-sources-mode>LOCAL_SOURCES</remote-sources-mode> + <compilerSet>default</compilerSet> + </toolsSet> + <compileType> + <ccTool> + <incDir> + <pElem>include</pElem> + <pElem>/usr/include/freetype2</pElem> + <pElem>/usr/include/fribidi</pElem> + </incDir> + <commandLine>-std=gnu++0x -fomit-frame-pointer -fPIC -pthread -Wall -Wno-parentheses -Wno-switch -Wdisabled-optimization -Wpointer-arith -Wredundant-decls -Wwrite-strings -Wtype-limits -Wundef -fno-math-errno -fno-signed-zeros -fno-tree-vectorize -Werror=implicit-function-declaration -ansi</commandLine> + <preprocessorList> + <Elem>LOCDIR=/usr/share/locale</Elem> + <Elem>_GNU_SOURCE=1</Elem> + <Elem>_REENTRANT</Elem> + </preprocessorList> + <warningLevel>2</warningLevel> + </ccTool> + <archiverTool> + </archiverTool> + </compileType> + </conf> + <conf name="Release" type="3"> + <toolsSet> + <remote-sources-mode>LOCAL_SOURCES</remote-sources-mode> + <compilerSet>default</compilerSet> + </toolsSet> + <compileType> + <cTool> + <developmentMode>5</developmentMode> + </cTool> + <ccTool> + <developmentMode>5</developmentMode> + </ccTool> + <fortranCompilerTool> + <developmentMode>5</developmentMode> + </fortranCompilerTool> + <asmTool> + <developmentMode>5</developmentMode> + </asmTool> + <archiverTool> + </archiverTool> + </compileType> + </conf> + </confs> +</configurationDescriptor> diff --git a/libs/vdr/nbproject/private/Makefile-variables.mk b/libs/vdr/nbproject/private/Makefile-variables.mk new file mode 100644 index 0000000..a64183e --- /dev/null +++ b/libs/vdr/nbproject/private/Makefile-variables.mk @@ -0,0 +1,7 @@ +# +# Generated - do not edit! +# +# NOCDDL +# +# Debug configuration +# Release configuration diff --git a/libs/vdr/nbproject/private/configurations.xml b/libs/vdr/nbproject/private/configurations.xml new file mode 100644 index 0000000..fa15dc7 --- /dev/null +++ b/libs/vdr/nbproject/private/configurations.xml @@ -0,0 +1,72 @@ +<?xml version="1.0" encoding="UTF-8"?> +<configurationDescriptor version="80"> + <projectmakefile>Makefile</projectmakefile> + <confs> + <conf name="Debug" type="3"> + <toolsSet> + <developmentServer>localhost</developmentServer> + <platform>2</platform> + </toolsSet> + <dbx_gdbdebugger version="1"> + <gdb_pathmaps> + </gdb_pathmaps> + <gdb_interceptlist> + <gdbinterceptoptions gdb_all="false" gdb_unhandled="true" gdb_unexpected="true"/> + </gdb_interceptlist> + <gdb_options> + <DebugOptions> + </DebugOptions> + </gdb_options> + <gdb_buildfirst gdb_buildfirst_overriden="false" gdb_buildfirst_old="false"/> + </dbx_gdbdebugger> + <nativedebugger version="1"> + <engine>gdb</engine> + </nativedebugger> + <runprofile version="9"> + <runcommandpicklist> + <runcommandpicklistitem>"${OUTPUT_PATH}"</runcommandpicklistitem> + </runcommandpicklist> + <runcommand>"${OUTPUT_PATH}"</runcommand> + <rundir></rundir> + <buildfirst>true</buildfirst> + <terminal-type>0</terminal-type> + <remove-instrumentation>0</remove-instrumentation> + <environment> + </environment> + </runprofile> + </conf> + <conf name="Release" type="3"> + <toolsSet> + <developmentServer>localhost</developmentServer> + <platform>2</platform> + </toolsSet> + <dbx_gdbdebugger version="1"> + <gdb_pathmaps> + </gdb_pathmaps> + <gdb_interceptlist> + <gdbinterceptoptions gdb_all="false" gdb_unhandled="true" gdb_unexpected="true"/> + </gdb_interceptlist> + <gdb_options> + <DebugOptions> + </DebugOptions> + </gdb_options> + <gdb_buildfirst gdb_buildfirst_overriden="false" gdb_buildfirst_old="false"/> + </dbx_gdbdebugger> + <nativedebugger version="1"> + <engine>gdb</engine> + </nativedebugger> + <runprofile version="9"> + <runcommandpicklist> + <runcommandpicklistitem>"${OUTPUT_PATH}"</runcommandpicklistitem> + </runcommandpicklist> + <runcommand>"${OUTPUT_PATH}"</runcommand> + <rundir></rundir> + <buildfirst>true</buildfirst> + <terminal-type>0</terminal-type> + <remove-instrumentation>0</remove-instrumentation> + <environment> + </environment> + </runprofile> + </conf> + </confs> +</configurationDescriptor> diff --git a/libs/vdr/nbproject/private/private.xml b/libs/vdr/nbproject/private/private.xml new file mode 100644 index 0000000..5ee2703 --- /dev/null +++ b/libs/vdr/nbproject/private/private.xml @@ -0,0 +1,8 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project-private xmlns="http://www.netbeans.org/ns/project-private/1"> + <data xmlns="http://www.netbeans.org/ns/make-project-private/1"> + <activeConfTypeElem>3</activeConfTypeElem> + <activeConfIndexElem>0</activeConfIndexElem> + </data> + <editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/1"/> +</project-private> diff --git a/libs/vdr/nbproject/project.xml b/libs/vdr/nbproject/project.xml new file mode 100644 index 0000000..c87a53a --- /dev/null +++ b/libs/vdr/nbproject/project.xml @@ -0,0 +1,25 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://www.netbeans.org/ns/project/1"> + <type>org.netbeans.modules.cnd.makeproject</type> + <configuration> + <data xmlns="http://www.netbeans.org/ns/make-project/1"> + <name>vdr</name> + <c-extensions/> + <cpp-extensions>cc</cpp-extensions> + <header-extensions>h</header-extensions> + <sourceEncoding>UTF-8</sourceEncoding> + <make-dep-projects/> + <sourceRootList/> + <confList> + <confElem> + <name>Debug</name> + <type>3</type> + </confElem> + <confElem> + <name>Release</name> + <type>3</type> + </confElem> + </confList> + </data> + </configuration> +</project> diff --git a/libs/vdr/src/CharsetConv.cc b/libs/vdr/src/CharsetConv.cc new file mode 100644 index 0000000..ed50dee --- /dev/null +++ b/libs/vdr/src/CharsetConv.cc @@ -0,0 +1,294 @@ +/** + * File: CharsetConv.cc + * Project: libvdr - classes taken from vdr-project + * + * from "Video Disk Recorder": + * + * Copyright (C) 2000, 2003, 2006, 2008 Klaus Schmidinger + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Or, point your browser to http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * + * The original author can be reached at kls@tvdr.de + * + * The vdr project's page is at http://www.tvdr.de + * + */ +#include <CharsetConv.h> +#include <Logging.h> +#include <errno.h> +#include <string.h> +#include <stdlib.h> +#include <tools.h> + +static uint SystemToUtf8[128] = { 0 }; + +int Utf8CharLen(const char *s) +{ + if (cCharSetConv::SystemCharacterTable()) + return 1; +#define MT(s, m, v) ((*(s) & (m)) == (v)) // Mask Test + if (MT(s, 0xE0, 0xC0) && MT(s + 1, 0xC0, 0x80)) + return 2; + if (MT(s, 0xF0, 0xE0) && MT(s + 1, 0xC0, 0x80) && MT(s + 2, 0xC0, 0x80)) + return 3; + if (MT(s, 0xF8, 0xF0) && MT(s + 1, 0xC0, 0x80) && MT(s + 2, 0xC0, 0x80) && MT(s + 3, 0xC0, 0x80)) + return 4; + return 1; +} + +uint Utf8CharGet(const char *s, int Length) +{ + if (cCharSetConv::SystemCharacterTable()) + return (uchar)*s < 128 ? *s : SystemToUtf8[(uchar)*s - 128]; + if (!Length) + Length = Utf8CharLen(s); + switch (Length) { + case 2: return ((*s & 0x1F) << 6) | (*(s + 1) & 0x3F); + case 3: return ((*s & 0x0F) << 12) | ((*(s + 1) & 0x3F) << 6) | (*(s + 2) & 0x3F); + case 4: return ((*s & 0x07) << 18) | ((*(s + 1) & 0x3F) << 12) | ((*(s + 2) & 0x3F) << 6) | (*(s + 3) & 0x3F); + default: break; + } + return *s; +} + +int Utf8CharSet(uint c, char *s) +{ + if (c < 0x80 || cCharSetConv::SystemCharacterTable()) { + if (s) + *s = c; + return 1; + } + if (c < 0x800) { + if (s) { + *s++ = ((c >> 6) & 0x1F) | 0xC0; + *s = (c & 0x3F) | 0x80; + } + return 2; + } + if (c < 0x10000) { + if (s) { + *s++ = ((c >> 12) & 0x0F) | 0xE0; + *s++ = ((c >> 6) & 0x3F) | 0x80; + *s = (c & 0x3F) | 0x80; + } + return 3; + } + if (c < 0x110000) { + if (s) { + *s++ = ((c >> 18) & 0x07) | 0xF0; + *s++ = ((c >> 12) & 0x3F) | 0x80; + *s++ = ((c >> 6) & 0x3F) | 0x80; + *s = (c & 0x3F) | 0x80; + } + return 4; + } + return 0; // can't convert to UTF-8 +} + +int Utf8SymChars(const char *s, int Symbols) +{ + if (cCharSetConv::SystemCharacterTable()) + return Symbols; + int n = 0; + while (*s && Symbols--) { + int sl = Utf8CharLen(s); + s += sl; + n += sl; + } + return n; +} + +int Utf8StrLen(const char *s) +{ + if (cCharSetConv::SystemCharacterTable()) + return strlen(s); + int n = 0; + while (*s) { + s += Utf8CharLen(s); + n++; + } + return n; +} + +extern char *strn0cpy(char *dest, const char *src, size_t n); + +char *Utf8Strn0Cpy(char *Dest, const char *Src, int n) +{ + if (cCharSetConv::SystemCharacterTable()) + return strn0cpy(Dest, Src, n); + char *d = Dest; + while (*Src) { + int sl = Utf8CharLen(Src); + n -= sl; + if (n > 0) { + while (sl--) + *d++ = *Src++; + } + else + break; + } + *d = 0; + return Dest; +} + +int Utf8ToArray(const char *s, uint *a, int Size) +{ + int n = 0; + while (*s && --Size > 0) { + if (cCharSetConv::SystemCharacterTable()) + *a++ = (uchar)(*s++); + else { + int sl = Utf8CharLen(s); + *a++ = Utf8CharGet(s, sl); + s += sl; + } + n++; + } + if (Size > 0) + *a = 0; + return n; +} + +int Utf8FromArray(const uint *a, char *s, int Size, int Max) +{ + int NumChars = 0; + int NumSyms = 0; + while (*a && NumChars < Size) { + if (Max >= 0 && NumSyms++ >= Max) + break; + if (cCharSetConv::SystemCharacterTable()) { + *s++ = *a++; + NumChars++; + } + else { + int sl = Utf8CharSet(*a); + if (NumChars + sl <= Size) { + Utf8CharSet(*a, s); + a++; + s += sl; + NumChars += sl; + } + else + break; + } + } + if (NumChars < Size) + *s = 0; + return NumChars; +} + +// --- cCharSetConv ---------------------------------------------------------- + +char *cCharSetConv::systemCharacterTable = NULL; + +cCharSetConv::cCharSetConv(const char *FromCode, const char *ToCode) +{ + if (!FromCode) + FromCode = systemCharacterTable ? systemCharacterTable : "UTF-8"; + if (!ToCode) + ToCode = "UTF-8"; + cd = iconv_open(ToCode, FromCode); + result = NULL; + length = 0; +} + +cCharSetConv::~cCharSetConv() +{ + free(result); + iconv_close(cd); +} + +void cCharSetConv::SetSystemCharacterTable(const char *CharacterTable) +{ + free(systemCharacterTable); + systemCharacterTable = NULL; + if (!strcasestr(CharacterTable, "UTF-8")) { + // Set up a map for the character values 128...255: + char buf[129]; + for (int i = 0; i < 128; i++) + buf[i] = i + 128; + buf[128] = 0; + cCharSetConv csc(CharacterTable); + const char *s = csc.Convert(buf); + int i = 0; + while (*s) { + int sl = Utf8CharLen(s); + SystemToUtf8[i] = Utf8CharGet(s, sl); + s += sl; + i++; + } + systemCharacterTable = strdup(CharacterTable); + } +} + +const char *cCharSetConv::Convert(const char *From, char *To, size_t ToLength) +{ + if (cd != (iconv_t)-1 && From && *From) { + char *FromPtr = (char *)From; + size_t FromLength = strlen(From); + char *ToPtr = To; + if (!ToPtr) { + int NewLength = max(length, FromLength * 2); // some reserve to avoid later reallocations + if (char *NewBuffer = (char *)realloc(result, NewLength)) { + length = NewLength; + result = NewBuffer; + } + else { + esyslog("ERROR: out of memory"); + return From; + } + ToPtr = result; + ToLength = length; + } + else if (!ToLength) + return From; // can't convert into a zero sized buffer + ToLength--; // save space for terminating 0 + char *Converted = ToPtr; + while (FromLength > 0) { + if (iconv(cd, &FromPtr, &FromLength, &ToPtr, &ToLength) == size_t(-1)) { + if (errno == E2BIG || ((errno == EILSEQ) && (ToLength < 1))) { + if (To) break; // caller provided a fixed size buffer, but it was too small + // The result buffer is too small, so increase it: + size_t d = ToPtr - result; + size_t r = length / 2; + int NewLength = length + r; + if (char *NewBuffer = (char *)realloc(result, NewLength)) { + length = NewLength; + Converted = result = NewBuffer; + } + else { + esyslog("ERROR: out of memory"); + return From; + } + ToLength += r; + ToPtr = result + d; + } + if (errno == EILSEQ) { + // A character can't be converted, so mark it with '?' and proceed: + FromPtr++; + FromLength--; + *ToPtr++ = '?'; + ToLength--; + } + else if (errno != E2BIG) + return From; // unknown error, return original string + } + } + *ToPtr = 0; + return Converted; + } + return From; +} diff --git a/libs/vdr/src/CondWait.cc b/libs/vdr/src/CondWait.cc new file mode 100644 index 0000000..efa4803 --- /dev/null +++ b/libs/vdr/src/CondWait.cc @@ -0,0 +1,101 @@ +/** + * File: CondWait.cc + * Project: libvdr - classes taken from vdr-project + * + * from "Video Disk Recorder": + * + * Copyright (C) 2000, 2003, 2006, 2008 Klaus Schmidinger + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Or, point your browser to http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * + * The original author can be reached at kls@tvdr.de + * + * The vdr project's page is at http://www.tvdr.de + * + */ +#include <CondWait.h> +#include <sys/time.h> +#include <sys/wait.h> +#include <sys/prctl.h> +#include <errno.h> +#include <tools.h> + +static bool GetAbsTime(struct timespec *Abstime, int MillisecondsFromNow) +{ + struct timeval now; + if (gettimeofday(&now, NULL) == 0) { // get current time + now.tv_sec += MillisecondsFromNow / 1000; // add full seconds + now.tv_usec += (MillisecondsFromNow % 1000) * 1000; // add microseconds + if (now.tv_usec >= 1000000) { // take care of an overflow + now.tv_sec++; + now.tv_usec -= 1000000; + } + Abstime->tv_sec = now.tv_sec; // seconds + Abstime->tv_nsec = now.tv_usec * 1000; // nano seconds + return true; + } + return false; +} + +cCondWait::cCondWait(void) +{ + signaled = false; + pthread_mutex_init(&mutex, NULL); + pthread_cond_init(&cond, NULL); +} + +cCondWait::~cCondWait() +{ + pthread_cond_broadcast(&cond); // wake up any sleepers + pthread_cond_destroy(&cond); + pthread_mutex_destroy(&mutex); +} + +void cCondWait::SleepMs(int TimeoutMs) +{ + cCondWait w; + w.Wait(max(TimeoutMs, 3)); // making sure the time is >2ms to avoid a possible busy wait +} + +bool cCondWait::Wait(int TimeoutMs) +{ + pthread_mutex_lock(&mutex); + if (!signaled) { + if (TimeoutMs) { + struct timespec abstime; + if (GetAbsTime(&abstime, TimeoutMs)) { + while (!signaled) { + if (pthread_cond_timedwait(&cond, &mutex, &abstime) == ETIMEDOUT) + break; + } + } + } + else + pthread_cond_wait(&cond, &mutex); + } + bool r = signaled; + signaled = false; + pthread_mutex_unlock(&mutex); + return r; +} + +void cCondWait::Signal(void) +{ + pthread_mutex_lock(&mutex); + signaled = true; + pthread_cond_broadcast(&cond); + pthread_mutex_unlock(&mutex); +} diff --git a/libs/vdr/src/FileNameList.cc b/libs/vdr/src/FileNameList.cc new file mode 100644 index 0000000..74dc4f2 --- /dev/null +++ b/libs/vdr/src/FileNameList.cc @@ -0,0 +1,70 @@ +/** + * File: FileNameList.cc + * Project: libvdr - classes taken from vdr-project + * + * from "Video Disk Recorder": + * + * Copyright (C) 2000, 2003, 2006, 2008 Klaus Schmidinger + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Or, point your browser to http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * + * The original author can be reached at kls@tvdr.de + * + * The vdr project's page is at http://www.tvdr.de + * + */ +#include <FileNameList.h> +#include <ReadDir.h> +#include <String.h> +#include <sys/stat.h> + + +cString AddDirectory(const char *DirName, const char *FileName) +{ + return cString::sprintf("%s/%s", DirName && *DirName ? DirName : ".", FileName); +} + +// TODO better GetFileNames(const char *Directory, cStringList *List)? +cFileNameList::cFileNameList(const char *Directory, bool DirsOnly) +{ + Load(Directory, DirsOnly); +} + +bool cFileNameList::Load(const char *Directory, bool DirsOnly) +{ + Clear(); + if (Directory) { + cReadDir d(Directory); + struct dirent *e; + if (d.Ok()) { + while ((e = d.Next()) != NULL) { + if (DirsOnly) { + struct stat ds; + if (stat(AddDirectory(Directory, e->d_name), &ds) == 0) { + if (!S_ISDIR(ds.st_mode)) + continue; + } + } + Append(strdup(e->d_name)); + } + Sort(); + return true; + } + else + LOG_ERROR_STR(Directory); + } + return false; +} diff --git a/libs/vdr/src/Logging.cc b/libs/vdr/src/Logging.cc new file mode 100644 index 0000000..4db516b --- /dev/null +++ b/libs/vdr/src/Logging.cc @@ -0,0 +1,46 @@ +/** + * File: Logging.cc + * Project: libvdr - classes taken from vdr-project + * + * from "Video Disk Recorder": + * + * Copyright (C) 2000, 2003, 2006, 2008 Klaus Schmidinger + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Or, point your browser to http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * + * The original author can be reached at kls@tvdr.de + * + * The vdr project's page is at http://www.tvdr.de + * + */ +#include <Logging.h> +#include <Thread.h> +#include <stdarg.h> +#include <stdio.h> + +int SysLogLevel = 3; + +#define MAXSYSLOGBUF 256 + +void syslog_with_tid(int priority, const char *format, ...) +{ + va_list ap; + char fmt[MAXSYSLOGBUF]; + snprintf(fmt, sizeof(fmt), "[%d] %s", cThread::ThreadId(), format); + va_start(ap, format); + vsyslog(priority, fmt, ap); + va_end(ap); +} diff --git a/libs/vdr/src/Mutex.cc b/libs/vdr/src/Mutex.cc new file mode 100644 index 0000000..cb100c7 --- /dev/null +++ b/libs/vdr/src/Mutex.cc @@ -0,0 +1,81 @@ +/** + * File: Mutex.cc + * Project: libvdr - classes taken from vdr-project + * + * from "Video Disk Recorder": + * + * Copyright (C) 2000, 2003, 2006, 2008 Klaus Schmidinger + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Or, point your browser to http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * + * The original author can be reached at kls@tvdr.de + * + * The vdr project's page is at http://www.tvdr.de + * + */ +#include <Mutex.h> + +cMutex::cMutex(void) +{ + locked = 0; + pthread_mutexattr_t attr; + pthread_mutexattr_init(&attr); + pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK_NP); + pthread_mutex_init(&mutex, &attr); +} + +cMutex::~cMutex() +{ + pthread_mutex_destroy(&mutex); +} + +void cMutex::Lock(void) +{ + pthread_mutex_lock(&mutex); + locked++; +} + +void cMutex::Unlock(void) +{ + if (!--locked) + pthread_mutex_unlock(&mutex); +} + +// --- cMutexLock ------------------------------------------------------------ + +cMutexLock::cMutexLock(cMutex *Mutex) +{ + mutex = NULL; + locked = false; + Lock(Mutex); +} + +cMutexLock::~cMutexLock() +{ + if (mutex && locked) + mutex->Unlock(); +} + +bool cMutexLock::Lock(cMutex *Mutex) +{ + if (Mutex && !mutex) { + mutex = Mutex; + Mutex->Lock(); + locked = true; + return true; + } + return false; +} diff --git a/libs/vdr/src/ReadDir.cc b/libs/vdr/src/ReadDir.cc new file mode 100644 index 0000000..a837f35 --- /dev/null +++ b/libs/vdr/src/ReadDir.cc @@ -0,0 +1,53 @@ +/** + * File: ReadDir.cc + * Project: libvdr - classes taken from vdr-project + * + * from "Video Disk Recorder": + * + * Copyright (C) 2000, 2003, 2006, 2008 Klaus Schmidinger + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Or, point your browser to http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * + * The original author can be reached at kls@tvdr.de + * + * The vdr project's page is at http://www.tvdr.de + * + */ +#include <ReadDir.h> +#include <stddef.h> +#include <string.h> + +cReadDir::cReadDir(const char *Directory) +{ + directory = opendir(Directory); +} + +cReadDir::~cReadDir() +{ + if (directory) + closedir(directory); +} + +struct dirent *cReadDir::Next(void) +{ + if (directory) { + while (readdir_r(directory, &u.d, &result) == 0 && result) { + if (strcmp(result->d_name, ".") && strcmp(result->d_name, "..")) + return result; + } + } + return NULL; +} diff --git a/libs/vdr/src/String.cc b/libs/vdr/src/String.cc new file mode 100644 index 0000000..0729c77 --- /dev/null +++ b/libs/vdr/src/String.cc @@ -0,0 +1,379 @@ +/** + * File: String.cc + * Project: libvdr - classes taken from vdr-project + * + * from "Video Disk Recorder": + * + * Copyright (C) 2000, 2003, 2006, 2008 Klaus Schmidinger + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Or, point your browser to http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * + * The original author can be reached at kls@tvdr.de + * + * The vdr project's page is at http://www.tvdr.de + * + */ +#include <String.h> +#include <Logging.h> +#include <i18n.h> +#include <tools.h> +#include <string.h> +#include <stdlib.h> +#include <stdio.h> +#include <time.h> +#include <sys/time.h> +#include <ctype.h> + +char *strcpyrealloc(char *dest, const char *src) +{ + if (src) { + int l = max(dest ? strlen(dest) : 0, strlen(src)) + 1; // don't let the block get smaller! + dest = (char *)realloc(dest, l); + if (dest) + strcpy(dest, src); + else + esyslog("ERROR: out of memory"); + } + else { + free(dest); + dest = NULL; + } + return dest; +} + +char *strn0cpy(char *dest, const char *src, size_t n) +{ + char *s = dest; + for ( ; --n && (*dest = *src) != 0; dest++, src++) ; + *dest = 0; + return s; +} + +char *strreplace(char *s, char c1, char c2) +{ + if (s) { + char *p = s; + while (*p) { + if (*p == c1) + *p = c2; + p++; + } + } + return s; +} + +char *strreplace(char *s, const char *s1, const char *s2) +{ + char *p = strstr(s, s1); + if (p) { + int of = p - s; + int l = strlen(s); + int l1 = strlen(s1); + int l2 = strlen(s2); + if (l2 > l1) { + if (char *NewBuffer = (char *)realloc(s, l + l2 - l1 + 1)) + s = NewBuffer; + else { + esyslog("ERROR: out of memory"); + return s; + } + } + char *sof = s + of; + if (l2 != l1) + memmove(sof + l2, sof + l1, l - of - l1 + 1); + strncpy(sof, s2, l2); + } + return s; +} + +char *stripspace(char *s) +{ + if (s && *s) { + for (char *p = s + strlen(s) - 1; p >= s; p--) { + if (!isspace(*p)) + break; + *p = 0; + } + } + return s; +} + +char *compactspace(char *s) +{ + if (s && *s) { + char *t = stripspace(skipspace(s)); + char *p = t; + while (p && *p) { + char *q = skipspace(p); + if (q - p > 1) + memmove(p + 1, q, strlen(q) + 1); + p++; + } + if (t != s) + memmove(s, t, strlen(t) + 1); + } + return s; +} + +cString strescape(const char *s, const char *chars) +{ + char *buffer; + const char *p = s; + char *t = NULL; + while (*p) { + if (strchr(chars, *p)) { + if (!t) { + buffer = MALLOC(char, 2 * strlen(s) + 1); + t = buffer + (p - s); + s = strcpy(buffer, s); + } + *t++ = '\\'; + } + if (t) + *t++ = *p; + p++; + } + if (t) + *t = 0; + return cString(s, t != NULL); +} + +bool startswith(const char *s, const char *p) +{ + while (*p) { + if (*p++ != *s++) + return false; + } + return true; +} + +bool endswith(const char *s, const char *p) +{ + const char *se = s + strlen(s) - 1; + const char *pe = p + strlen(p) - 1; + while (pe >= p) { + if (*pe-- != *se-- || (se < s && pe >= p)) + return false; + } + return true; +} + +bool isempty(const char *s) +{ + return !(s && *skipspace(s)); +} + +int numdigits(int n) +{ + int res = 1; + while (n >= 10) { + n /= 10; + res++; + } + return res; +} + +bool isnumber(const char *s) +{ + if (!s || !*s) + return false; + do { + if (!isdigit(*s)) + return false; + } while (*++s); + return true; +} + +int64_t StrToNum(const char *s) +{ + char *t = NULL; + int64_t n = strtoll(s, &t, 10); + if (t) { + switch (*t) { + case 'T': n *= 1024; + case 'G': n *= 1024; + case 'M': n *= 1024; + case 'K': n *= 1024; + } + } + return n; +} + +cString itoa(int n) +{ + char buf[16]; + snprintf(buf, sizeof(buf), "%d", n); + return buf; +} + +// --- cString --------------------------------------------------------------- + +cString::cString(const char *S, bool TakePointer) +{ + s = TakePointer ? (char *)S : S ? strdup(S) : NULL; +} + +cString::cString(const cString &String) +{ + s = String.s ? strdup(String.s) : NULL; +} + +cString::~cString() +{ + free(s); +} + +cString &cString::operator=(const cString &String) +{ + if (this == &String) + return *this; + free(s); + s = String.s ? strdup(String.s) : NULL; + return *this; +} + +cString &cString::operator=(const char *String) +{ + if (s == String) + return *this; + free(s); + s = String ? strdup(String) : NULL; + return *this; +} + +cString &cString::Truncate(int Index) +{ + int l = strlen(s); + if (Index < 0) + Index = l + Index; + if (Index >= 0 && Index < l) + s[Index] = 0; + return *this; +} + +cString cString::sprintf(const char *fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + char *buffer; + if (!fmt || vasprintf(&buffer, fmt, ap) < 0) { + esyslog("error in vasprintf('%s', ...)", fmt); + buffer = strdup("???"); + } + va_end(ap); + return cString(buffer, true); +} + +cString cString::vsprintf(const char *fmt, va_list &ap) +{ + char *buffer; + if (!fmt || vasprintf(&buffer, fmt, ap) < 0) { + esyslog("error in vasprintf('%s', ...)", fmt); + buffer = strdup("???"); + } + return cString(buffer, true); +} + +cString WeekDayName(int WeekDay) +{ + char buffer[16]; + WeekDay = WeekDay == 0 ? 6 : WeekDay - 1; // we start with Monday==0! + if (0 <= WeekDay && WeekDay <= 6) { + // TRANSLATORS: abbreviated weekdays, beginning with monday (must all be 3 letters!) + const char *day = tr("MonTueWedThuFriSatSun"); + day += Utf8SymChars(day, WeekDay * 3); + strn0cpy(buffer, day, min(Utf8SymChars(day, 3) + 1, int(sizeof(buffer)))); + return buffer; + } + else + return "???"; +} + +cString WeekDayName(time_t t) +{ + struct tm tm_r; + return WeekDayName(localtime_r(&t, &tm_r)->tm_wday); +} + +cString WeekDayNameFull(int WeekDay) +{ + WeekDay = WeekDay == 0 ? 6 : WeekDay - 1; // we start with Monday==0! + switch (WeekDay) { + case 0: return tr("Monday"); + case 1: return tr("Tuesday"); + case 2: return tr("Wednesday"); + case 3: return tr("Thursday"); + case 4: return tr("Friday"); + case 5: return tr("Saturday"); + case 6: return tr("Sunday"); + default: return "???"; + } +} + +cString WeekDayNameFull(time_t t) +{ + struct tm tm_r; + return WeekDayNameFull(localtime_r(&t, &tm_r)->tm_wday); +} + +cString DayDateTime(time_t t) +{ + char buffer[32]; + if (t == 0) + time(&t); + struct tm tm_r; + tm *tm = localtime_r(&t, &tm_r); + snprintf(buffer, sizeof(buffer), "%s %02d.%02d. %02d:%02d", *WeekDayName(tm->tm_wday), tm->tm_mday, tm->tm_mon + 1, tm->tm_hour, tm->tm_min); + return buffer; +} + +cString TimeToString(time_t t) +{ + char buffer[32]; + if (ctime_r(&t, buffer)) { + buffer[strlen(buffer) - 1] = 0; // strip trailing newline + return buffer; + } + return "???"; +} + +cString DateString(time_t t) +{ + char buf[32]; + struct tm tm_r; + tm *tm = localtime_r(&t, &tm_r); + char *p = stpcpy(buf, WeekDayName(tm->tm_wday)); + *p++ = ' '; + strftime(p, sizeof(buf) - (p - buf), "%d.%m.%Y", tm); + return buf; +} + +cString ShortDateString(time_t t) +{ + char buf[32]; + struct tm tm_r; + tm *tm = localtime_r(&t, &tm_r); + strftime(buf, sizeof(buf), "%d.%m.%y", tm); + return buf; +} + +cString TimeString(time_t t) +{ + char buf[25]; + struct tm tm_r; + strftime(buf, sizeof(buf), "%R", localtime_r(&t, &tm_r)); + return buf; +} diff --git a/libs/vdr/src/StringList.cc b/libs/vdr/src/StringList.cc new file mode 100644 index 0000000..5b3adf5 --- /dev/null +++ b/libs/vdr/src/StringList.cc @@ -0,0 +1,50 @@ +/** + * File: StringList.cc + * Project: libvdr - classes taken from vdr-project + * + * from "Video Disk Recorder": + * + * Copyright (C) 2000, 2003, 2006, 2008 Klaus Schmidinger + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Or, point your browser to http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * + * The original author can be reached at kls@tvdr.de + * + * The vdr project's page is at http://www.tvdr.de + * + */ +#include <StringList.h> + +cStringList::~cStringList() +{ + Clear(); +} + +int cStringList::Find(const char *s) const +{ + for (int i = 0; i < Size(); i++) { + if (!strcmp(s, At(i))) + return i; + } + return -1; +} + +void cStringList::Clear(void) +{ + for (int i = 0; i < Size(); i++) + free(At(i)); + cVector<char *>::Clear(); +} diff --git a/libs/vdr/src/Thread.cc b/libs/vdr/src/Thread.cc new file mode 100644 index 0000000..25d23e3 --- /dev/null +++ b/libs/vdr/src/Thread.cc @@ -0,0 +1,209 @@ +/** + * File: Thread.cc + * Project: libvdr - classes taken from vdr-project + * + * from "Video Disk Recorder": + * + * Copyright (C) 2000, 2003, 2006, 2008 Klaus Schmidinger + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Or, point your browser to http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * + * The original author can be reached at kls@tvdr.de + * + * The vdr project's page is at http://www.tvdr.de + * + */ +#include <Thread.h> +#include <TimeMs.h> +#include <CondWait.h> +#include <Logging.h> +#include <stdarg.h> +#include <errno.h> +#include <unistd.h> +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <signal.h> +#include <sys/types.h> +#include <sys/syscall.h> +#include <sys/resource.h> +tThreadId cThread::mainThreadId = 0; + +cThread::cThread(const char *Description) + : active(false) + , running(false) + , childTid(0) + , childThreadId(0) + , description(NULL) + , threadCallback(NULL) + , opaque(NULL) +{ + if (Description) SetDescription("%s", Description); +} + +cThread::cThread(int (*ThreadCallback)(void *, cThread *), void *Opaque, const char *Description) + : active(false) + , running(false) + , childTid(0) + , childThreadId(0) + , description(NULL) + , threadCallback(ThreadCallback) + , opaque(Opaque) +{ + if (Description) SetDescription("%s", Description); +} + +cThread::~cThread() +{ + Cancel(); // just in case the derived class didn't call it + free(description); +} + +void cThread::SetPriority(int Priority) +{ + if (setpriority(PRIO_PROCESS, 0, Priority) < 0) + LOG_ERROR; +} + +void cThread::SetIOPriority(int Priority) +{ + if (syscall(SYS_ioprio_set, 1, 0, (Priority & 0xff) | (2 << 13)) < 0) // best effort class + LOG_ERROR; +} + +void cThread::SetDescription(const char *Description, ...) +{ + free(description); + description = NULL; + if (Description) { + va_list ap; + va_start(ap, Description); + vasprintf(&description, Description, ap); + va_end(ap); + } +} + +void *cThread::StartThread(cThread *Thread) +{ + Thread->childThreadId = ThreadId(); + if (Thread->description) { + dsyslog("%s thread started (pid=%d, tid=%d)", Thread->description, getpid(), Thread->childThreadId); +#ifdef PR_SET_NAME + if (prctl(PR_SET_NAME, Thread->description, 0, 0, 0) < 0) + esyslog("%s thread naming failed (pid=%d, tid=%d)", Thread->description, getpid(), Thread->childThreadId); +#endif + } + Thread->Action(); + if (Thread->description) + dsyslog("%s thread ended (pid=%d, tid=%d)", Thread->description, getpid(), Thread->childThreadId); + Thread->running = false; + Thread->active = false; + + return NULL; +} + +#define THREAD_STOP_TIMEOUT 3000 // ms to wait for a thread to stop before newly starting it +#define THREAD_STOP_SLEEP 30 // ms to sleep while waiting for a thread to stop + +bool cThread::Start(void) +{ + if (!running) { + if (active) { + // Wait until the previous incarnation of this thread has completely ended + // before starting it newly: + cTimeMs RestartTimeout; + while (!running && active && RestartTimeout.Elapsed() < THREAD_STOP_TIMEOUT) + cCondWait::SleepMs(THREAD_STOP_SLEEP); + } + if (!active) { + active = running = true; + if (pthread_create(&childTid, NULL, (void *(*) (void *))&StartThread, (void *)this) == 0) { + pthread_detach(childTid); // auto-reap + } + else { + LOG_ERROR; + active = running = false; + return false; + } + } + } + return true; +} + +void cThread::Action() +{ + if (!threadCallback) *((char *)0) = 0; + ///< if not used the callback constructor, cThread must be subclassed, so stop application here! + + threadCallback(opaque, this); // passing this as parameter allows the callback + // use the public interface of this instance. +} + +bool cThread::Active(void) +{ + if (active) { + // + // Single UNIX Spec v2 says: + // + // The pthread_kill() function is used to request + // that a signal be delivered to the specified thread. + // + // As in kill(), if sig is zero, error checking is + // performed but no signal is actually sent. + // + int err; + if ((err = pthread_kill(childTid, 0)) != 0) { + if (err != ESRCH) + LOG_ERROR; + childTid = 0; + active = running = false; + } + else + return true; + } + return false; +} + +void cThread::Cancel(int WaitSeconds) +{ + running = false; + if (active && WaitSeconds > -1) { + if (WaitSeconds > 0) { + for (time_t t0 = time(NULL) + WaitSeconds; time(NULL) < t0; ) { + if (!Active()) + return; + cCondWait::SleepMs(10); + } + esyslog("ERROR: %s thread %d won't end (waited %d seconds) - canceling it...", description ? description : "", childThreadId, WaitSeconds); + } + pthread_cancel(childTid); + childTid = 0; + active = false; + } +} + +tThreadId cThread::ThreadId(void) +{ + return syscall(__NR_gettid); +} + +void cThread::SetMainThreadId(void) +{ + if (mainThreadId == 0) + mainThreadId = ThreadId(); + else + esyslog("ERROR: attempt to set main thread id to %d while it already is %d", ThreadId(), mainThreadId); +} diff --git a/libs/vdr/src/TimeMs.cc b/libs/vdr/src/TimeMs.cc new file mode 100644 index 0000000..620481e --- /dev/null +++ b/libs/vdr/src/TimeMs.cc @@ -0,0 +1,101 @@ +/** + * File: TimeMs.cc + * Project: libvdr - classes taken from vdr-project + * + * from "Video Disk Recorder": + * + * Copyright (C) 2000, 2003, 2006, 2008 Klaus Schmidinger + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Or, point your browser to http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * + * The original author can be reached at kls@tvdr.de + * + * The vdr project's page is at http://www.tvdr.de + * + */ +#include <TimeMs.h> +#include <Logging.h> +#include <stddef.h> +#include <sys/time.h> +#include <time.h> +#include <unistd.h> +#include <utime.h> + +cTimeMs::cTimeMs(int Ms) +{ + if (Ms >= 0) + Set(Ms); + else + begin = 0; +} + +uint64_t cTimeMs::Now(void) +{ +#if _POSIX_TIMERS > 0 && defined(_POSIX_MONOTONIC_CLOCK) +#define MIN_RESOLUTION 5 // ms + static bool initialized = false; + static bool monotonic = false; + struct timespec tp; + if (!initialized) { + // check if monotonic timer is available and provides enough accurate resolution: + if (clock_getres(CLOCK_MONOTONIC, &tp) == 0) { + long Resolution = tp.tv_nsec; + // require a minimum resolution: + if (tp.tv_sec == 0 && tp.tv_nsec <= MIN_RESOLUTION * 1000000) { + if (clock_gettime(CLOCK_MONOTONIC, &tp) == 0) { + dsyslog("cTimeMs: using monotonic clock (resolution is %ld ns)", Resolution); + monotonic = true; + } + else + esyslog("cTimeMs: clock_gettime(CLOCK_MONOTONIC) failed"); + } + else + dsyslog("cTimeMs: not using monotonic clock - resolution is too bad (%ld s %ld ns)", tp.tv_sec, tp.tv_nsec); + } + else + esyslog("cTimeMs: clock_getres(CLOCK_MONOTONIC) failed"); + initialized = true; + } + if (monotonic) { + if (clock_gettime(CLOCK_MONOTONIC, &tp) == 0) + return (uint64_t(tp.tv_sec)) * 1000 + tp.tv_nsec / 1000000; + esyslog("cTimeMs: clock_gettime(CLOCK_MONOTONIC) failed"); + monotonic = false; + // fall back to gettimeofday() + } +#else +# warning Posix monotonic clock not available +#endif + struct timeval t; + if (gettimeofday(&t, NULL) == 0) + return (uint64_t(t.tv_sec)) * 1000 + t.tv_usec / 1000; + return 0; +} + +void cTimeMs::Set(int Ms) +{ + begin = Now() + Ms; +} + +bool cTimeMs::TimedOut(void) +{ + return Now() >= begin; +} + +uint64_t cTimeMs::Elapsed(void) +{ + return Now() - begin; +} diff --git a/libs/vdr/src/i18n.cc b/libs/vdr/src/i18n.cc new file mode 100644 index 0000000..a6d8d65 --- /dev/null +++ b/libs/vdr/src/i18n.cc @@ -0,0 +1,324 @@ +/** + * File: i18n.cc + * Project: libvdr - classes taken from vdr-project + * + * from "Video Disk Recorder": + * + * Copyright (C) 2000, 2003, 2006, 2008 Klaus Schmidinger + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Or, point your browser to http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * + * The original author can be reached at kls@tvdr.de + * + * The vdr project's page is at http://www.tvdr.de + * + * In case an English phrase is used in more than one context (and might need + * different translations in other languages) it can be preceded with an + * arbitrary string to describe its context, separated from the actual phrase + * by a '$' character (see for instance "Button$Stop" vs. "Stop"). + * Of course this means that no English phrase may contain the '$' character! + * If this should ever become necessary, the existing '$' would have to be + * replaced with something different... + */ +#include <i18n.h> +#include <String.h> +#include <StringList.h> +#include <FileNameList.h> +#include <Logging.h> +#include <string.h> +#include <stdlib.h> +#include <ctype.h> +#include <libintl.h> +#include <locale.h> +#include <unistd.h> + +// TRANSLATORS: The name of the language, as written natively +const char *LanguageName = trNOOP("LanguageName$English"); +// TRANSLATORS: The 3-letter code of the language +const char *LanguageCode = trNOOP("LanguageCode$eng"); + +#define AsString(s) #s + +// List of known language codes with aliases. +// Actually we could list all codes from http://www.loc.gov/standards/iso639-2 +// here, but that would be several hundreds - and for most of them it's unlikely +// they're ever going to be used... + +const char *LanguageCodeList[] = { + "eng,dos", + "deu,ger", + "slv,slo", + "ita", + "dut,nla,nld", + "prt", + "fra,fre", + "nor", + "fin,suo", + "pol", + "esl,spa", + "ell,gre", + "sve,swe", + "rom,rum", + "hun", + "cat,cln", + "rus", + "srb,srp,scr,scc", + "hrv", + "est", + "dan", + "cze,ces", + "tur", + "ukr", + "ara", + NULL + }; + +static const char *I18nLocaleDir = AsString(LOCDIR); + +static cStringList LanguageLocales; +static cStringList LanguageNames; +static cStringList LanguageCodes; + +static int NumLocales = 1; +static int CurrentLanguage = 0; + +static bool ContainsCode(const char *Codes, const char *Code) +{ + while (*Codes) { + int l = 0; + for ( ; l < 3 && Code[l]; l++) { + if (Codes[l] != tolower(Code[l])) + break; + } + if (l == 3) + return true; + Codes++; + } + return false; +} + +static const char *SkipContext(const char *s) +{ + const char *p = strchr(s, '$'); + return p ? p + 1 : s; +} + +static void SetEnvLanguage(const char *Locale) +{ + setenv("LANGUAGE", Locale, 1); + extern int _nl_msg_cat_cntr; + ++_nl_msg_cat_cntr; +} + +void I18nInitialize(const char *LocaleDir) +{ + if (LocaleDir) + I18nLocaleDir = LocaleDir; + LanguageLocales.Append(strdup(I18N_DEFAULT_LOCALE)); + LanguageNames.Append(strdup(SkipContext(LanguageName))); + LanguageCodes.Append(strdup(LanguageCodeList[0])); + textdomain("vdr"); + bindtextdomain("vdr", I18nLocaleDir); + cFileNameList Locales(I18nLocaleDir, true); + if (Locales.Size() > 0) { + char *OldLocale = strdup(setlocale(LC_MESSAGES, NULL)); + for (int i = 0; i < Locales.Size(); i++) { + cString FileName = cString::sprintf("%s/%s/LC_MESSAGES/vdr.mo", I18nLocaleDir, Locales[i]); + if (access(FileName, F_OK) == 0) { // found a locale with VDR texts + if (NumLocales < I18N_MAX_LANGUAGES - 1) { + SetEnvLanguage(Locales[i]); + const char *TranslatedLanguageName = gettext(LanguageName); + if (TranslatedLanguageName != LanguageName) { + NumLocales++; + if (strstr(OldLocale, Locales[i]) == OldLocale) + CurrentLanguage = LanguageLocales.Size(); + LanguageLocales.Append(strdup(Locales[i])); + LanguageNames.Append(strdup(TranslatedLanguageName)); + const char *Code = gettext(LanguageCode); + for (const char **lc = LanguageCodeList; *lc; lc++) { + if (ContainsCode(*lc, Code)) { + Code = *lc; + break; + } + } + LanguageCodes.Append(strdup(Code)); + } + } + else { + esyslog("ERROR: too many locales - increase I18N_MAX_LANGUAGES!"); + break; + } + } + } + SetEnvLanguage(LanguageLocales[CurrentLanguage]); + free(OldLocale); + dsyslog("found %d locales in %s", NumLocales - 1, I18nLocaleDir); + } + // Prepare any known language codes for which there was no locale: + for (const char **lc = LanguageCodeList; *lc; lc++) { + bool Found = false; + for (int i = 0; i < LanguageCodes.Size(); i++) { + if (strcmp(*lc, LanguageCodes[i]) == 0) { + Found = true; + break; + } + } + if (!Found) { + dsyslog("no locale for language code '%s'", *lc); + LanguageLocales.Append(strdup(I18N_DEFAULT_LOCALE)); + LanguageNames.Append(strdup(*lc)); + LanguageCodes.Append(strdup(*lc)); + } + } +} + +void I18nRegister(const char *Plugin) +{ + cString Domain = cString::sprintf("vdr-%s", Plugin); + bindtextdomain(Domain, I18nLocaleDir); +} + +void I18nSetLocale(const char *Locale) +{ + if (Locale && *Locale) { + int i = LanguageLocales.Find(Locale); + if (i >= 0) { + CurrentLanguage = i; + SetEnvLanguage(Locale); + } + else + dsyslog("unknown locale: '%s'", Locale); + } +} + +int I18nCurrentLanguage(void) +{ + return CurrentLanguage; +} + +void I18nSetLanguage(int Language) +{ + if (Language < LanguageNames.Size()) { + CurrentLanguage = Language; + I18nSetLocale(I18nLocale(CurrentLanguage)); + } +} + +int I18nNumLanguagesWithLocale(void) +{ + return NumLocales; +} + +const cStringList *I18nLanguages(void) +{ + return &LanguageNames; +} + +const char *I18nTranslate(const char *s, const char *Plugin) +{ + if (!s) + return s; + if (CurrentLanguage) { + const char *t = Plugin ? dgettext(Plugin, s) : gettext(s); + if (t != s) + return t; + } + return SkipContext(s); +} + +const char *I18nLocale(int Language) +{ + return 0 <= Language && Language < LanguageLocales.Size() ? LanguageLocales[Language] : NULL; +} + +const char *I18nLanguageCode(int Language) +{ + return 0 <= Language && Language < LanguageCodes.Size() ? LanguageCodes[Language] : NULL; +} + +int I18nLanguageIndex(const char *Code) +{ + for (int i = 0; i < LanguageCodes.Size(); i++) { + if (ContainsCode(LanguageCodes[i], Code)) + return i; + } + //dsyslog("unknown language code: '%s'", Code); + return -1; +} + +const char *I18nNormalizeLanguageCode(const char *Code) +{ + for (int i = 0; i < 3; i++) { + if (Code[i]) { + // ETSI EN 300 468 defines language codes as consisting of three letters + // according to ISO 639-2. This means that they are supposed to always consist + // of exactly three letters in the range a-z - no digits, UTF-8 or other + // funny characters. However, some broadcasters apparently don't have a + // copy of the DVB standard (or they do, but are perhaps unable to read it), + // so they put all sorts of non-standard stuff into the language codes, + // like nonsense as "2ch" or "A 1" (yes, they even go as far as using + // blanks!). Such things should go into the description of the EPG event's + // ComponentDescriptor. + // So, as a workaround for this broadcaster stupidity, let's ignore + // language codes with unprintable characters... + if (!isprint(Code[i])) { + //dsyslog("invalid language code: '%s'", Code); + return "???"; + } + // ...and replace blanks with underlines (ok, this breaks the 'const' + // of the Code parameter - but hey, it's them who started this): + if (Code[i] == ' ') + *((char *)&Code[i]) = '_'; + } + else + break; + } + int n = I18nLanguageIndex(Code); + return n >= 0 ? I18nLanguageCode(n) : Code; +} + +bool I18nIsPreferredLanguage(int *PreferredLanguages, const char *LanguageCode, int &OldPreference, int *Position) +{ + int pos = 1; + bool found = false; + while (LanguageCode) { + int LanguageIndex = I18nLanguageIndex(LanguageCode); + for (int i = 0; i < LanguageCodes.Size(); i++) { + if (PreferredLanguages[i] < 0) + break; // the language is not a preferred one + if (PreferredLanguages[i] == LanguageIndex) { + if (OldPreference < 0 || i < OldPreference) { + OldPreference = i; + if (Position) + *Position = pos; + found = true; + break; + } + } + } + if ((LanguageCode = strchr(LanguageCode, '+')) != NULL) { + LanguageCode++; + pos++; + } + else if (pos == 1 && Position) + *Position = 0; + } + if (OldPreference < 0) { + OldPreference = LanguageCodes.Size(); // higher than the maximum possible value + return true; // if we don't find a preferred one, we take the first one + } + return found; +} diff --git a/libs/vdr/summary.txt b/libs/vdr/summary.txt new file mode 100644 index 0000000..a2a3582 --- /dev/null +++ b/libs/vdr/summary.txt @@ -0,0 +1 @@ +libvdr - classes taken from vdr-project diff --git a/libs/vdr/vdr.cbp b/libs/vdr/vdr.cbp new file mode 100644 index 0000000..82be645 --- /dev/null +++ b/libs/vdr/vdr.cbp @@ -0,0 +1,83 @@ +<?xml version="1.0" encoding="UTF-8" standalone="yes" ?> +<CodeBlocks_project_file> + <FileVersion major="1" minor="6" /> + <Project> + <Option title="CMP.libs.vdr" /> + <Option pch_mode="2" /> + <Option compiler="gcc" /> + <Build> + <Target title="Debug"> + <Option output="libvdr" prefix_auto="1" extension_auto="1" /> + <Option working_dir="" /> + <Option object_output="obj/Debug/" /> + <Option type="2" /> + <Option compiler="gcc" /> + <Option createDefFile="1" /> + <Compiler> + <Add option="-fomit-frame-pointer" /> + <Add option="-Winit-self" /> + <Add option="-Wredundant-decls" /> + <Add option="-std=c++0x" /> + <Add option="-Wall" /> + <Add option="-g" /> + </Compiler> + </Target> + <Target title="Release"> + <Option output="libvdr" prefix_auto="1" extension_auto="1" /> + <Option working_dir="" /> + <Option object_output="obj/Release/" /> + <Option type="2" /> + <Option compiler="gcc" /> + <Option createDefFile="1" /> + <Compiler> + <Add option="-Winit-self" /> + <Add option="-Wredundant-decls" /> + <Add option="-Wmissing-declarations" /> + <Add option="-Wmissing-include-dirs" /> + <Add option="-std=c++0x" /> + <Add option="-Wextra" /> + <Add option="-Wall" /> + </Compiler> + </Target> + </Build> + <Compiler> + <Add option="-fomit-frame-pointer -fPIC -pthread -Wall -Wno-parentheses -Wno-switch -Wdisabled-optimization -Wpointer-arith -Wredundant-decls -Wwrite-strings -Wtype-limits -Wundef -fno-math-errno -fno-signed-zeros -fno-tree-vectorize -Werror=implicit-function-declaration -ansi" /> + <Add option="-D_REENTRANT" /> + <Add option="-D_GNU_SOURCE=1" /> + <Add option="-DLOCDIR=/usr/share/locale" /> + <Add directory="include" /> + <Add directory="/usr/include/freetype2" /> + <Add directory="/usr/include/fribidi" /> + </Compiler> + <Unit filename="include/CharsetConv.h" /> + <Unit filename="include/CondWait.h" /> + <Unit filename="include/FileNameList.h" /> + <Unit filename="include/Logging.h" /> + <Unit filename="include/Mutex.h" /> + <Unit filename="include/ReadDir.h" /> + <Unit filename="include/String.h" /> + <Unit filename="include/StringList.h" /> + <Unit filename="include/Thread.h" /> + <Unit filename="include/TimeMs.h" /> + <Unit filename="include/Vector.h" /> + <Unit filename="include/i18n.h" /> + <Unit filename="include/tools.h" /> + <Unit filename="src/CharsetConv.cc" /> + <Unit filename="src/CondWait.cc" /> + <Unit filename="src/FileNameList.cc" /> + <Unit filename="src/Logging.cc" /> + <Unit filename="src/Mutex.cc" /> + <Unit filename="src/ReadDir.cc" /> + <Unit filename="src/String.cc" /> + <Unit filename="src/StringList.cc" /> + <Unit filename="src/Thread.cc" /> + <Unit filename="src/TimeMs.cc" /> + <Unit filename="src/i18n.cc" /> + <Extensions> + <code_completion /> + <envvars /> + <lib_finder disable_auto="1" /> + <debugger /> + </Extensions> + </Project> +</CodeBlocks_project_file> diff --git a/libs/vdr/vdr.depend b/libs/vdr/vdr.depend new file mode 100644 index 0000000..c4ac310 --- /dev/null +++ b/libs/vdr/vdr.depend @@ -0,0 +1 @@ +# depslib dependency file v1.0 diff --git a/libs/vdr/vdr.layout b/libs/vdr/vdr.layout new file mode 100644 index 0000000..43b8191 --- /dev/null +++ b/libs/vdr/vdr.layout @@ -0,0 +1,24 @@ +<?xml version="1.0" encoding="UTF-8" standalone="yes" ?> +<CodeBlocks_layout_file> + <ActiveTarget name="Debug" /> + <File name="src/i18n.cc" open="0" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> + <Cursor> + <Cursor1 position="0" topLine="0" /> + </Cursor> + </File> + <File name="src/Thread.cc" open="0" top="0" tabpos="7" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> + <Cursor> + <Cursor1 position="0" topLine="0" /> + </Cursor> + </File> + <File name="src/CharsetConv.cc" open="0" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> + <Cursor> + <Cursor1 position="0" topLine="0" /> + </Cursor> + </File> + <File name="include/Thread.h" open="0" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> + <Cursor> + <Cursor1 position="0" topLine="0" /> + </Cursor> + </File> +</CodeBlocks_layout_file> diff --git a/libs/vdr/vdr.layout.save b/libs/vdr/vdr.layout.save new file mode 100644 index 0000000..52982d9 --- /dev/null +++ b/libs/vdr/vdr.layout.save @@ -0,0 +1,24 @@ +<?xml version="1.0" encoding="UTF-8" standalone="yes" ?> +<CodeBlocks_layout_file> + <ActiveTarget name="Debug" /> + <File name="src/i18n.cc" open="0" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> + <Cursor> + <Cursor1 position="0" topLine="0" /> + </Cursor> + </File> + <File name="include/Thread.h" open="0" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> + <Cursor> + <Cursor1 position="0" topLine="0" /> + </Cursor> + </File> + <File name="src/Thread.cc" open="0" top="0" tabpos="7" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> + <Cursor> + <Cursor1 position="0" topLine="0" /> + </Cursor> + </File> + <File name="src/CharsetConv.cc" open="0" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> + <Cursor> + <Cursor1 position="0" topLine="0" /> + </Cursor> + </File> +</CodeBlocks_layout_file> |