diff options
author | Klaus Schmidinger <kls (at) cadsoft (dot) de> | 2007-06-10 18:00:00 +0200 |
---|---|---|
committer | Klaus Schmidinger <kls (at) cadsoft (dot) de> | 2007-06-10 18:00:00 +0200 |
commit | b9b9ace9a8d2d1c0beda1dc0a2ebc6be9b47c305 (patch) | |
tree | be6d179a3d48dc4323b55a9efc0acb03e767847b /tools.h | |
parent | a5921252942f73601b159f20b560477ec45b4ece (diff) | |
download | vdr-patch-lnbsharing-b9b9ace9a8d2d1c0beda1dc0a2ebc6be9b47c305.tar.gz vdr-patch-lnbsharing-b9b9ace9a8d2d1c0beda1dc0a2ebc6be9b47c305.tar.bz2 |
Version 1.5.3vdr-1.5.3
- Fixed some spelling errors in 'newplugin' (thanks to Ville Skyttä).
- Fixed a busy loop in fast forward if the next video data file is missing
(thanks to Reinhard Nissl).
- Fixed handling frequencies in NitFilter::Process() (thanks to Anssi Hannula).
- Fixed a race condition with signal handlers at program exit (thanks to Udo
Richter).
- Non-primary devices in Transfer mode are now also used for recording (thanks
to Anssi Hannula).
- Fixed handling ChannelUp/Down keys if there is currently a replay running
(thanks to Marco Schlüßler).
- The new SVDRP command REMO can be used to turn VDR's remote control off and
on in case other programs need to be controlled (based on patches from Krzysztof
Parma and Helmut Auer).
- Increased the maximum number of CA system ids to cope with the AlphaCrypt
CAM's version 3.11 firmware.
- Fixed getting the code setting from the locale (thanks to Matthias Schwarzott).
- Implemented support for Freetype fonts (based on a patch from Alexander Riedel).
The font names and sizes can be adjusted in the "Setup/OSD" menu.
Note that VDR now requires freetype fonts to be installed in
/usr/share/fonts/truetype.
- If the OSD device in use has at least 8bpp bitmap depth and this is also
used by the current skin, Freetype fonts are displayed "anti-aliased".
The new setup parameter "OSD/Anti-alias" can be used to turn this off.
- The new function cOsd::SetAntiAliasGranularity() can be used to help the OSD
in managing the available color palette entries when doing anti-aliasing.
Skins that use 8bpp bitmaps can call this function with the maximum number
of colors used, and the maximum number of color combinations. The OSD will
then evenly split the available palette entries between the various colors
combinations, so that fonts can be "anti-aliased". By default a total of
10 colors and 10 combinations is assumed.
- The pixel fonts have been completely removed from the VDR source.
- VDR is now "UTF-8 aware". It handles strings according to the character
encoding used on the user's system. All internationalization strings and
incoming SI data are converted to the system encoding.
- Plugins that handle strings need to be aware that on systems with UTF-8
encoding a "character symbol" may consist of more than a single byte in
memory. The functions and macros named Utf8...() can be used to handle
strings without needing to care about the underlying character encoding
(see tools.h for details).
- Even though the weekdays of repeating timers are presented to the user as UTF-8
characters in the OSD, the timers.conf file and the SVDRP timer commands still
use single byte characters ("MTWTFSS") to make sure this information is handled
correctly between systems with different character encodings.
- Added a missing i18n string for "CAM" in the Turkish OSD texts.
- Improved editing strings that are too long to fit into the editable area.
- Changes to the OSD settings in the "Setup/OSD" menu now immediately take effect
when the "Ok" key is pressed.
Diffstat (limited to 'tools.h')
-rw-r--r-- | tools.h | 126 |
1 files changed, 125 insertions, 1 deletions
@@ -4,7 +4,7 @@ * See the main source file 'vdr.c' for copyright information and * how to reach the author. * - * $Id: tools.h 1.97 2007/01/05 10:45:11 kls Exp $ + * $Id: tools.h 1.98 2007/06/10 08:46:23 kls Exp $ */ #ifndef __TOOLS_H @@ -13,10 +13,12 @@ #include <dirent.h> #include <errno.h> #include <fcntl.h> +#include <iconv.h> #include <poll.h> #include <stddef.h> #include <stdint.h> #include <stdio.h> +#include <stdlib.h> #include <string.h> #include <syslog.h> #include <sys/stat.h> @@ -72,6 +74,73 @@ template<class T> inline void put_unaligned(unsigned int v, T* p) ((s *)p)->v = v; } +// 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 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 { +private: + iconv_t cd; + char *result; + size_t length; + static char *systemCharacterTable; +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. + ///< 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 cosntructor). + ///< 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); + }; + class cString { private: char *s; @@ -320,6 +389,61 @@ public: T *Next(const T *object) const { return (T *)object->cListObject::Next(); } // avoid ambiguities in case of a "list of lists" }; +template<class T> class cVector { +private: + mutable int allocated; + mutable int size; + mutable T *data; + void Realloc(int NewAllocated) const { data = (T *)realloc(data, (allocated = NewAllocated) * sizeof(T)); } +public: + cVector(int Allocated = 10) + { + allocated = 0; + size = 0; + data = NULL; + Realloc(Allocated); + } + virtual ~cVector() { free(data); } + T& At(int Index) const + { + if (Index >= size) + Realloc(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 Append(T Data) + { + if (size >= allocated) + Realloc(allocated * 4 / 2); // increase size by 50% + data[size++] = Data; + } + void Sort(__compar_fn_t Compare) + { + qsort(data, size, sizeof(T), Compare); + } + }; + +inline int CompareStrings(const void *a, const void *b) +{ + return strcmp(*(const char **)a, *(const char **)b); +} + +class cFileNameList : public cVector<char *> { +public: + cFileNameList(const char *Directory = NULL); + virtual ~cFileNameList(); + bool Load(const char *Directory); + int Find(const char *FileName); + }; + class cHashObject : public cListObject { friend class cHashBase; private: |