Mercurial > mplayer.hg
diff gui/util/string.c @ 34175:a345e7162d0a
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.
| author | ib |
|---|---|
| date | Wed, 26 Oct 2011 15:14:06 +0000 |
| parents | d7527ee45784 |
| children | d52b0ad317d5 |
line wrap: on
line diff
--- 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 <string.h> #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; +}
