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.c | |
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.c')
-rw-r--r-- | tools.c | 264 |
1 files changed, 260 insertions, 4 deletions
@@ -4,7 +4,7 @@ * See the main source file 'vdr.c' for copyright information and * how to reach the author. * - * $Id: tools.c 1.122 2007/01/05 10:44:57 kls Exp $ + * $Id: tools.c 1.123 2007/06/09 14:21:21 kls Exp $ */ #include "tools.h" @@ -570,6 +570,221 @@ uint64_t cTimeMs::Elapsed(void) return Now() - begin; } +// --- UTF-8 support --------------------------------------------------------- + +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) << 4) | ((*(s + 1) & 0x3F) << 6) | (*(s + 2) & 0x3F); + case 4: return ((*s & 0x07) << 2) | ((*(s + 1) & 0x3F) << 4) | ((*(s + 2) & 0x3F) << 6) | (*(s + 3) & 0x3F); + } + 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 Utf8ToArray(const char *s, uint *a, int Size) +{ + int n = 0; + while (*s && --Size > 0) { + if (cCharSetConv::SystemCharacterTable()) + *a++ = *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; + if (!ToCode) + ToCode = "UTF-8"; + cd = (FromCode && ToCode) ? iconv_open(ToCode, FromCode) : (iconv_t)-1; + 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")) { + // 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[129] = 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) { + char *FromPtr = (char *)From; + size_t FromLength = strlen(From); + char *ToPtr = To; + if (!ToPtr) { + length = max(length, FromLength * 2); // some reserve to avoid later reallocations + result = (char *)realloc(result, length); + 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; + length += r; + result = (char *)realloc(result, length); + 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; +} + // --- cString --------------------------------------------------------------- cString::cString(const char *S, bool TakePointer) @@ -607,12 +822,12 @@ cString cString::sprintf(const char *fmt, ...) cString WeekDayName(int WeekDay) { - char buffer[4]; + char buffer[16]; WeekDay = WeekDay == 0 ? 6 : WeekDay - 1; // we start with Monday==0! if (0 <= WeekDay && WeekDay <= 6) { const char *day = tr("MonTueWedThuFriSatSun"); - day += WeekDay * 3; - strn0cpy(buffer, day, sizeof(buffer)); + day += Utf8SymChars(day, WeekDay * 3); + strn0cpy(buffer, day, min(Utf8SymChars(day, 3) + 1, int(sizeof(buffer)))); return buffer; } else @@ -890,6 +1105,47 @@ struct dirent *cReadDir::Next(void) return directory && readdir_r(directory, &u.d, &result) == 0 ? result : NULL; } +// --- cFileNameList --------------------------------------------------------- + +cFileNameList::cFileNameList(const char *Directory) +{ + Load(Directory); +} + +cFileNameList::~cFileNameList() +{ + for (int i = 0; i < Size(); i++) + free(At(i)); +} + +bool cFileNameList::Load(const char *Directory) +{ + if (Directory) { + cReadDir d(Directory); + struct dirent *e; + if (d.Ok()) { + while ((e = d.Next()) != NULL) { + if (strcmp(e->d_name, ".") && strcmp(e->d_name, "..")) + Append(strdup(e->d_name)); + } + Sort(CompareStrings); + return true; + } + else + LOG_ERROR_STR(Directory); + } + return false; +} + +int cFileNameList::Find(const char *FileName) +{ + for (int i = 0; i < Size(); i++) { + if (!strcmp(FileName, At(i))) + return i; + } + return -1; +} + // --- cFile ----------------------------------------------------------------- bool cFile::files[FD_SETSIZE] = { false }; |