summaryrefslogtreecommitdiffstats
path: root/libass/ass_utils.c
diff options
context:
space:
mode:
authorGrigori Goronzy <greg@blackbox>2009-07-11 02:18:51 +0200
committerGrigori Goronzy <greg@blackbox>2009-07-11 02:22:18 +0200
commit2c412cdab94a7bb27c5a1e04ab902295215de888 (patch)
treec1372ebf5e6473b287e152a40c88587f3470d237 /libass/ass_utils.c
parent613a22ab9b96453c10de6d75b43067652ad6d7db (diff)
downloadlibass-2c412cdab94a7bb27c5a1e04ab902295215de888.tar.bz2
libass-2c412cdab94a7bb27c5a1e04ab902295215de888.tar.xz
Message callback funtionality
Introduce functionality for providing a message callback that is used for passing messages to the controlling application instead of simply printing them to standard output. The function pointer to the callback is stored in the ass_library_t instance. ass_msg needs access to it, so in many places the library instance needs to be passed around now. The default behavior is the old one: messages of MSGL_INFO or lower are printed to the standard output, prefixed with "[ass]".
Diffstat (limited to 'libass/ass_utils.c')
-rw-r--r--libass/ass_utils.c31
1 files changed, 15 insertions, 16 deletions
diff --git a/libass/ass_utils.c b/libass/ass_utils.c
index 6e45b02..0592d33 100644
--- a/libass/ass_utils.c
+++ b/libass/ass_utils.c
@@ -21,10 +21,13 @@
#include "config.h"
#include <stdlib.h>
+#include <stdio.h>
#include <inttypes.h>
#include <ft2build.h>
#include FT_GLYPH_H
+#include "ass_library.h"
+#include "ass.h"
#include "ass_utils.h"
int mystrtoi(char **p, int *res)
@@ -71,7 +74,7 @@ int mystrtod(char **p, double *res)
return 0;
}
-int strtocolor(char **q, uint32_t *res)
+int strtocolor(ass_library_t *library, char **q, uint32_t *res)
{
uint32_t color = 0;
int result;
@@ -80,7 +83,7 @@ int strtocolor(char **q, uint32_t *res)
if (*p == '&')
++p;
else
- ass_msg(MSGL_DBG2, "suspicious color format: \"%s\"\n", p);
+ ass_msg(library, MSGL_DBG2, "suspicious color format: \"%s\"\n", p);
if (*p == 'H' || *p == 'h') {
++p;
@@ -119,15 +122,11 @@ char parse_bool(char *str)
return 0;
}
-void ass_msg(int lvl, char *fmt, ...)
+void ass_msg(ass_library_t *priv, int lvl, char *fmt, ...)
{
va_list va;
- if (lvl > MSGL_INFO)
- return;
va_start(va, fmt);
- printf("[ass] ");
- vprintf(fmt, va);
- printf("\n");
+ priv->msg_callback(lvl, fmt, &va);
va_end(va);
}
@@ -162,8 +161,9 @@ unsigned ass_utf8_get_char(char **str)
}
#ifdef CONFIG_ENCA
-void *ass_guess_buffer_cp(unsigned char *buffer, int buflen,
- char *preferred_language, char *fallback)
+void *ass_guess_buffer_cp(ass_library_t *library, unsigned char *buffer,
+ int buflen, char *preferred_language,
+ char *fallback)
{
const char **languages;
size_t langcnt;
@@ -173,11 +173,10 @@ void *ass_guess_buffer_cp(unsigned char *buffer, int buflen,
int i;
languages = enca_get_languages(&langcnt);
- ass_msg(MSGL_V, "ENCA supported languages: ");
+ ass_msg(library, MSGL_V, "ENCA supported languages");
for (i = 0; i < langcnt; i++) {
- ass_msg(MSGL_V, "%s ", languages[i]);
+ ass_msg(library, MSGL_V, "lang %s", languages[i]);
}
- ass_msg(MSGL_V, "\n");
for (i = 0; i < langcnt; i++) {
const char *tmp;
@@ -189,7 +188,7 @@ void *ass_guess_buffer_cp(unsigned char *buffer, int buflen,
tmp = enca_charset_name(encoding.charset, ENCA_NAME_STYLE_ICONV);
if (tmp && encoding.charset != ENCA_CS_UNKNOWN) {
detected_sub_cp = strdup(tmp);
- ass_msg(MSGL_INFO, "ENCA detected charset: %s\n", tmp);
+ ass_msg(library, MSGL_INFO, "ENCA detected charset: %s", tmp);
}
enca_analyser_free(analyser);
}
@@ -198,8 +197,8 @@ void *ass_guess_buffer_cp(unsigned char *buffer, int buflen,
if (!detected_sub_cp) {
detected_sub_cp = strdup(fallback);
- ass_msg(MSGL_INFO,
- "ENCA detection failed: fallback to %s\n", fallback);
+ ass_msg(library, MSGL_INFO,
+ "ENCA detection failed: fallback to %s", fallback);
}
return detected_sub_cp;