# HG changeset patch # User ib # Date 1319642046 0 # Node ID a345e7162d0a9ad995e81989f2e16753377d42c5 # Parent a93891202051aa01f6d2e9d38c9e1198b8d392d4 Move TranslateFilename() to util/string.c. Now that the Win32 GUI uses symbolic constants for its messages, the code of TranslateFilename() both GUIs use is almost identical. So, share the code. diff -r a93891202051 -r a345e7162d0a gui/ui/render.c --- a/gui/ui/render.c Wed Oct 26 15:12:35 2011 +0000 +++ b/gui/ui/render.c Wed Oct 26 15:14:06 2011 +0000 @@ -24,11 +24,11 @@ #include "render.h" #include "gui/interface.h" #include "gui/skin/font.h" +#include "gui/util/string.h" #include "access_mpcontext.h" #include "codec-cfg.h" #include "config.h" -#include "help_mp.h" #include "libavutil/avstring.h" #include "libmpdemux/stheader.h" #include "mixer.h" @@ -40,75 +40,6 @@ static char *image_buffer; static int image_width; -static void TranslateFilename(int c, char *tmp, size_t tmplen) -{ - int i; - char *p; - size_t len; - - switch (guiInfo.StreamType) { - case STREAMTYPE_FILE: - if (guiInfo.Filename && guiInfo.Filename[0]) { - p = strrchr(guiInfo.Filename, '/'); - - if (p) - av_strlcpy(tmp, p + 1, tmplen); - else - av_strlcpy(tmp, guiInfo.Filename, tmplen); - - len = strlen(tmp); - - if (len > 3 && tmp[len - 3] == '.') - tmp[len - 3] = 0; - else if (len > 4 && tmp[len - 4] == '.') - tmp[len - 4] = 0; - else if (len > 5 && tmp[len - 5] == '.') - tmp[len - 5] = 0; - } else - av_strlcpy(tmp, MSGTR_NoFileLoaded, tmplen); - break; - - case STREAMTYPE_STREAM: - av_strlcpy(tmp, guiInfo.Filename, tmplen); - break; - -#ifdef CONFIG_VCD - case STREAMTYPE_VCD: - snprintf(tmp, tmplen, MSGTR_Title, guiInfo.Track - 1); - break; -#endif - -#ifdef CONFIG_DVDREAD - case STREAMTYPE_DVD: - if (guiInfo.Chapter) - snprintf(tmp, tmplen, MSGTR_Chapter, guiInfo.Chapter); - else - av_strlcat(tmp, MSGTR_NoChapter, tmplen); - break; -#endif - - default: - av_strlcpy(tmp, MSGTR_NoMediaOpened, tmplen); - break; - } - - if (c) { - for (i = 0; tmp[i]; i++) { - int t = 0; - - if (c == 1) - if (tmp[i] >= 'A' && tmp[i] <= 'Z') - t = 32; - - if (c == 2) - if (tmp[i] >= 'a' && tmp[i] <= 'z') - t = -32; - - tmp[i] = (char)(tmp[i] + t); - } - } -} - static char *Translate(char *str) { static char trbuf[512]; diff -r a93891202051 -r a345e7162d0a gui/util/string.c --- a/gui/util/string.c Wed Oct 26 15:12:35 2011 +0000 +++ b/gui/util/string.c Wed Oct 26 15:14:06 2011 +0000 @@ -21,6 +21,12 @@ #include #include "string.h" +#include "gui/interface.h" + +#include "config.h" +#include "help_mp.h" +#include "libavutil/avstring.h" +#include "stream/stream.h" /** * @brief Convert a string to lower case. @@ -229,3 +235,79 @@ if (*old) sprintf(*old, "%s/%s", dir, name); } + +char *TranslateFilename(int c, char *tmp, size_t tmplen) +{ + int i; + char *p; + size_t len; + + switch (guiInfo.StreamType) { + case STREAMTYPE_FILE: + if (guiInfo.Filename && guiInfo.Filename[0]) { + p = strrchr(guiInfo.Filename, +#if HAVE_DOS_PATHS + '\\'); +#else + '/'); +#endif + + if (p) + av_strlcpy(tmp, p + 1, tmplen); + else + av_strlcpy(tmp, guiInfo.Filename, tmplen); + + len = strlen(tmp); + + if (len > 3 && tmp[len - 3] == '.') + tmp[len - 3] = 0; + else if (len > 4 && tmp[len - 4] == '.') + tmp[len - 4] = 0; + else if (len > 5 && tmp[len - 5] == '.') + tmp[len - 5] = 0; + } else + av_strlcpy(tmp, MSGTR_NoFileLoaded, tmplen); + break; + + case STREAMTYPE_STREAM: + av_strlcpy(tmp, guiInfo.Filename, tmplen); + break; + +#ifdef CONFIG_VCD + case STREAMTYPE_VCD: + snprintf(tmp, tmplen, MSGTR_Title, guiInfo.Track - 1); + break; +#endif + +#ifdef CONFIG_DVDREAD + case STREAMTYPE_DVD: + if (guiInfo.Chapter) + snprintf(tmp, tmplen, MSGTR_Chapter, guiInfo.Chapter); + else + av_strlcat(tmp, MSGTR_NoChapter, tmplen); + break; +#endif + + default: + av_strlcpy(tmp, MSGTR_NoMediaOpened, tmplen); + break; + } + + if (c) { + for (i = 0; tmp[i]; i++) { + int t = 0; + + if (c == 1) + if (tmp[i] >= 'A' && tmp[i] <= 'Z') + t = 32; + + if (c == 2) + if (tmp[i] >= 'a' && tmp[i] <= 'z') + t = -32; + + tmp[i] = (char)(tmp[i] + t); + } + } + + return tmp; +} diff -r a93891202051 -r a345e7162d0a gui/util/string.h --- a/gui/util/string.h Wed Oct 26 15:12:35 2011 +0000 +++ b/gui/util/string.h Wed Oct 26 15:14:06 2011 +0000 @@ -29,6 +29,7 @@ void setdup(char **old, const char *str); char *strlower(char *in); char *strswap(char *in, char from, char to); +char *TranslateFilename(int c, char *tmp, size_t tmplen); char *trim(char *in); #endif /* MPLAYER_GUI_STRING_H */ diff -r a93891202051 -r a345e7162d0a gui/win32/widgetrender.c --- a/gui/win32/widgetrender.c Wed Oct 26 15:12:35 2011 +0000 +++ b/gui/win32/widgetrender.c Wed Oct 26 15:14:06 2011 +0000 @@ -26,12 +26,10 @@ #include #include "gui/util/bitmap.h" +#include "gui/util/string.h" #include "gui/interface.h" #include "gui.h" -#include "help_mp.h" -#include "libavutil/avstring.h" - #define MAX_LABELSIZE 250 static void render(int bitsperpixel, image *dst, image *src, int x, int y, int sx, int sy, int sw, int sh, int transparent) @@ -117,66 +115,6 @@ } } -static char *TranslateFilename (int c, char *tmp, size_t tmplen) -{ - int i; - char *p; - size_t len; - - switch (guiInfo.StreamType) - { - case STREAMTYPE_FILE: - if (guiInfo.Filename && guiInfo.Filename[0]) - { - p = strrchr(guiInfo.Filename, '\\'); - - if (p) av_strlcpy(tmp, p + 1, tmplen); - else av_strlcpy(tmp, guiInfo.Filename, tmplen); - - len = strlen(tmp); - - if (len > 3 && tmp[len - 3] == '.') tmp[len - 3] = 0; - else if (len > 4 && tmp[len - 4] == '.') tmp[len - 4] = 0; - else if (len > 5 && tmp[len - 5] == '.') tmp[len - 5] = 0; - } - else av_strlcpy(tmp, MSGTR_NoFileLoaded, tmplen); - break; - - case STREAMTYPE_STREAM: - av_strlcpy(tmp, guiInfo.Filename, tmplen); - break; - -#ifdef CONFIG_DVDREAD - case STREAMTYPE_DVD: - if (guiInfo.Chapter) snprintf(tmp, tmplen, MSGTR_Chapter, guiInfo.Chapter); - else av_strlcat(tmp, MSGTR_NoChapter, tmplen); - break; -#endif - - default: - av_strlcpy(tmp, MSGTR_NoMediaOpened, tmplen); - break; - } - - if (c) - { - for (i = 0; tmp[i]; i++) - { - int t = 0; - - if (c == 1) - if (tmp[i] >= 'A' && tmp[i] <= 'Z') t = 32; - - if (c == 2) - if (tmp[i] >= 'a' && tmp[i] <= 'z') t = -32; - - tmp[i] = (char) (tmp[i] + t); - } - } - - return tmp; -} - /* replaces the chars with special meaning with the associated data from the player info struct */ static char *generatetextfromlabel(widget *item) {