From c25eeebeae274fd671300c88a04fc052f46a804e Mon Sep 17 00:00:00 2001 From: woro Date: Mon, 11 Feb 2008 00:24:13 +0000 Subject: next try at msprintf, and really enable utf8 git-svn-id: https://vdr-muggle.svn.sourceforge.net/svnroot/vdr-muggle/trunk/muggle-plugin@1017 e10066b5-e1e2-0310-b819-94efdf66514b --- mg_db.c | 4 +++- mg_setup.c | 1 - mg_tools.c | 15 +++++++++++++++ mg_tools.h | 1 + 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/mg_db.c b/mg_db.c index f511d9e..8a227d2 100644 --- a/mg_db.c +++ b/mg_db.c @@ -1018,7 +1018,9 @@ mgSQLString mgDb::Build_cddbid(const mgSQLString& artist) const { char *s; - asprintf(&s,"%ld-%.9s",random(),artist.original()); + msprintf(&s,"%ld-%.9s",random(),artist.original()); + if (!s) + msprintf(&s,"%ld-X",random()); mgSQLString result = mgSQLString(s); free(s); return result; diff --git a/mg_setup.c b/mg_setup.c index c71a3ca..01c22b2 100644 --- a/mg_setup.c +++ b/mg_setup.c @@ -55,7 +55,6 @@ mgSetup::mgSetup () if (dot) utf8 = strcmp(dot+1,"UTF-8")==0; } -utf8=false; if (utf8) mgWarning("muggle running in UTF-8 mode"); diff --git a/mg_tools.c b/mg_tools.c index 266dee2..20595c5 100644 --- a/mg_tools.c +++ b/mg_tools.c @@ -31,6 +31,21 @@ mgSetDebugLevel (int new_level) DEBUG_LEVEL = new_level; } +int +msprintf(char **strp, const char *fmt, ...) +{ + va_list ap; + int res; + va_start (ap, fmt); + res=vasprintf (strp, fmt, ap); + if (res<0) + { + *strp=0; + mgError("asprintf() returns %d. This probably means illformed UTF-8 characters." + " Please convert your file names to UTF-8",fmt,res); + } + va_end (ap); +} void mgDebug (int level, const char *fmt, ...) diff --git a/mg_tools.h b/mg_tools.h index be2bf93..12cf432 100644 --- a/mg_tools.h +++ b/mg_tools.h @@ -31,6 +31,7 @@ void mgDebug (int level, const char *fmt, ...); void mgDebug (const char *fmt, ...); void mgWarning (const char *fmt, ...); void mgError (const char *fmt, ...); +int msprintf(char **strp, const char *fmt, ...); //@} #ifdef DEBUG -- cgit v1.2.3