[PATCH 1/2] sub/subreader: Avoid warning about guess_cp if libenca is not enabled
Move CONFIG_ENCA block above CONFIG_ICONV block to avoid the forward declaration in the CONFIG_ICONV block which might not be needed if libenca isn't enabled. Avoid this gcc warning: ``` sub/subreader.c:1216:20: warning: 'guess_cp' declared 'static' but never defined [-Wunused-function] 1216 | static const char* guess_cp(stream_t *st, const char *preferred_language, const char *fallback); | ^~~~~~~~ ``` --- sub/subreader.c | 124 ++++++++++++++++++++++++------------------------ 1 file changed, 61 insertions(+), 63 deletions(-) diff --git a/sub/subreader.c b/sub/subreader.c index 3c815d132..3386e1995 100644 --- a/sub/subreader.c +++ b/sub/subreader.c @@ -1210,11 +1210,70 @@ static int sub_autodetect (stream_t* st, int *uses_time, int utf16) { int sub_utf8_prev=0; +#ifdef CONFIG_ENCA +const char* guess_buffer_cp(unsigned char* buffer, int buflen, const char *preferred_language, const char *fallback) +{ + const char **languages; + size_t langcnt; + EncaAnalyser analyser; + EncaEncoding encoding; + const char *detected_sub_cp = NULL; + int i; + + languages = enca_get_languages(&langcnt); + mp_msg(MSGT_SUBREADER, MSGL_V, "ENCA supported languages: "); + for (i = 0; i < langcnt; i++) { + mp_msg(MSGT_SUBREADER, MSGL_V, "%s ", languages[i]); + } + mp_msg(MSGT_SUBREADER, MSGL_V, "\n"); + + for (i = 0; i < langcnt; i++) { + if (av_strcasecmp(languages[i], preferred_language) != 0) continue; + analyser = enca_analyser_alloc(languages[i]); + encoding = enca_analyse_const(analyser, buffer, buflen); + enca_analyser_free(analyser); + if (encoding.charset != ENCA_CS_UNKNOWN) { + detected_sub_cp = enca_charset_name(encoding.charset, ENCA_NAME_STYLE_ICONV); + break; + } + } + + free(languages); + + if (!detected_sub_cp) { + detected_sub_cp = fallback; + mp_msg(MSGT_SUBREADER, MSGL_INFO, "ENCA detection failed: fallback to %s\n", fallback); + }else{ + mp_msg(MSGT_SUBREADER, MSGL_INFO, "ENCA detected charset: %s\n", detected_sub_cp); + } + + return detected_sub_cp; +} + +#define MAX_GUESS_BUFFER_SIZE (256*1024) +static const char* guess_cp(stream_t *st, const char *preferred_language, const char *fallback) +{ + size_t buflen; + unsigned char *buffer; + const char *detected_sub_cp = NULL; + + buffer = malloc(MAX_GUESS_BUFFER_SIZE); + buflen = stream_read(st,buffer, MAX_GUESS_BUFFER_SIZE); + + detected_sub_cp = guess_buffer_cp(buffer, buflen, preferred_language, fallback); + + free(buffer); + stream_reset(st); + stream_seek(st,0); + + return detected_sub_cp; +} +#undef MAX_GUESS_BUFFER_SIZE +#endif + #ifdef CONFIG_ICONV static iconv_t icdsc = (iconv_t)(-1); -static const char* guess_cp(stream_t *st, const char *preferred_language, const char *fallback); - void subcp_open (stream_t *st) { char *tocp = "UTF-8"; @@ -1428,67 +1487,6 @@ struct subreader { const char *name; }; -#ifdef CONFIG_ENCA -const char* guess_buffer_cp(unsigned char* buffer, int buflen, const char *preferred_language, const char *fallback) -{ - const char **languages; - size_t langcnt; - EncaAnalyser analyser; - EncaEncoding encoding; - const char *detected_sub_cp = NULL; - int i; - - languages = enca_get_languages(&langcnt); - mp_msg(MSGT_SUBREADER, MSGL_V, "ENCA supported languages: "); - for (i = 0; i < langcnt; i++) { - mp_msg(MSGT_SUBREADER, MSGL_V, "%s ", languages[i]); - } - mp_msg(MSGT_SUBREADER, MSGL_V, "\n"); - - for (i = 0; i < langcnt; i++) { - if (av_strcasecmp(languages[i], preferred_language) != 0) continue; - analyser = enca_analyser_alloc(languages[i]); - encoding = enca_analyse_const(analyser, buffer, buflen); - enca_analyser_free(analyser); - if (encoding.charset != ENCA_CS_UNKNOWN) { - detected_sub_cp = enca_charset_name(encoding.charset, ENCA_NAME_STYLE_ICONV); - break; - } - } - - free(languages); - - if (!detected_sub_cp) { - detected_sub_cp = fallback; - mp_msg(MSGT_SUBREADER, MSGL_INFO, "ENCA detection failed: fallback to %s\n", fallback); - }else{ - mp_msg(MSGT_SUBREADER, MSGL_INFO, "ENCA detected charset: %s\n", detected_sub_cp); - } - - return detected_sub_cp; -} - -#define MAX_GUESS_BUFFER_SIZE (256*1024) -static const char* guess_cp(stream_t *st, const char *preferred_language, const char *fallback) -{ - size_t buflen; - unsigned char *buffer; - const char *detected_sub_cp = NULL; - - buffer = malloc(MAX_GUESS_BUFFER_SIZE); - buflen = stream_read(st,buffer, MAX_GUESS_BUFFER_SIZE); - - detected_sub_cp = guess_buffer_cp(buffer, buflen, preferred_language, fallback); - - free(buffer); - stream_reset(st); - stream_seek(st,0); - - return detected_sub_cp; -} -#undef MAX_GUESS_BUFFER_SIZE -#endif - sub_data* sub_read_file (const char *filename, float fps) { int utf16; stream_t* fd; --
The guess_cp function returns `const char *`, so we should use the same type for enca_sub_cp as well. Avoids this warning: ``` sub/subreader.c: In function 'subcp_open': sub/subreader.c:1287:33: warning: assignment discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers] 1287 | enca_sub_cp = guess_cp(st, enca_lang, enca_fallback); | ``` --- sub/subreader.c | 2 +- sub/subreader.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/sub/subreader.c b/sub/subreader.c index 3386e1995..35bc9eef5 100644 --- a/sub/subreader.c +++ b/sub/subreader.c @@ -55,7 +55,7 @@ #include <iconv.h> #endif char *sub_cp=NULL; -char *enca_sub_cp=NULL; +const char *enca_sub_cp=NULL; #ifdef CONFIG_FRIBIDI #include <fribidi/fribidi.h> char *fribidi_charset = NULL; ///character set that will be passed to FriBiDi diff --git a/sub/subreader.h b/sub/subreader.h index d499ad830..a4608cc4d 100644 --- a/sub/subreader.h +++ b/sub/subreader.h @@ -33,7 +33,7 @@ extern int sub_no_text_pp; // disable text post-processing extern int sub_match_fuzziness; extern int sub_format; extern char *sub_cp; -extern char *enca_sub_cp; +extern const char *enca_sub_cp; // subtitle formats #define SUB_INVALID -1 --
Hi! Both look fine to me.
On 26 Dec 2024, at 22:12, Alexander Strasser <eclipse7@gmx.net> wrote:
The guess_cp function returns `const char *`, so we should use the same type for enca_sub_cp as well.
Avoids this warning:
``` sub/subreader.c: In function 'subcp_open': sub/subreader.c:1287:33: warning: assignment discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers] 1287 | enca_sub_cp = guess_cp(st, enca_lang, enca_fallback); | ``` --- sub/subreader.c | 2 +- sub/subreader.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/sub/subreader.c b/sub/subreader.c index 3386e1995..35bc9eef5 100644 --- a/sub/subreader.c +++ b/sub/subreader.c @@ -55,7 +55,7 @@ #include <iconv.h> #endif char *sub_cp=NULL; -char *enca_sub_cp=NULL; +const char *enca_sub_cp=NULL; #ifdef CONFIG_FRIBIDI #include <fribidi/fribidi.h> char *fribidi_charset = NULL; ///character set that will be passed to FriBiDi diff --git a/sub/subreader.h b/sub/subreader.h index d499ad830..a4608cc4d 100644 --- a/sub/subreader.h +++ b/sub/subreader.h @@ -33,7 +33,7 @@ extern int sub_no_text_pp; // disable text post-processing extern int sub_match_fuzziness; extern int sub_format; extern char *sub_cp; -extern char *enca_sub_cp; +extern const char *enca_sub_cp;
// subtitle formats #define SUB_INVALID -1 -- _______________________________________________ MPlayer-dev-eng mailing list MPlayer-dev-eng@mplayerhq.hu https://lists.mplayerhq.hu/mailman/listinfo/mplayer-dev-eng
On 2024-12-27 19:33 +0100, Reimar Döffinger wrote:
Hi! Both look fine to me.
Thanks for the review! Both patches committed as SVN revision 38670 and 38671 . [...] Alexander P.S. I'm going too look into committing the partial patch from komh next. If you know anything else that fails to build with GCC14 on your os/arch please let me know.
participants (2)
-
Alexander Strasser -
Reimar Döffinger