[MPlayer-cvslog] r37080 - in trunk/gui: ui/render.c util/string.c util/string.h win32/widgetrender.c

ib subversion at mplayerhq.hu
Thu Mar 27 02:49:01 CET 2014


Author: ib
Date: Thu Mar 27 02:49:01 2014
New Revision: 37080

Log:
Move most of TranslateFilename() back to the renderer files.

Although it would be nice to share the code (which was the reason
for r34263), most of it really doesn't belong to string.c.

Modified:
   trunk/gui/ui/render.c
   trunk/gui/util/string.c
   trunk/gui/util/string.h
   trunk/gui/win32/widgetrender.c

Modified: trunk/gui/ui/render.c
==============================================================================
--- trunk/gui/ui/render.c	Thu Mar 27 00:19:13 2014	(r37079)
+++ trunk/gui/ui/render.c	Thu Mar 27 02:49:01 2014	(r37080)
@@ -26,6 +26,8 @@
 #include "gui/skin/font.h"
 #include "gui/util/string.h"
 
+#include "access_mpcontext.h"
+#include "help_mp.h"
 #include "libavutil/avstring.h"
 #include "osdep/timer.h"
 #include "stream/stream.h"
@@ -36,6 +38,108 @@ static char *image_buffer;
 static int image_width;
 
 /**
+ * @brief Convert #guiInfo member Filename.
+ *
+ * @param how 0 (cut file path and extension),
+ *            1 (additionally, convert lower case) or
+ *            2 (additionally, convert upper case)
+ * @param fname pointer to a buffer to receive the converted Filename
+ * @param maxlen size of @a fname buffer
+ *
+ * @return pointer to @a fname buffer
+ */
+static char *TranslateFilename(int how, char *fname, size_t maxlen)
+{
+    char *p;
+    size_t len;
+    stream_t *stream;
+
+    switch (guiInfo.StreamType) {
+    case STREAMTYPE_FILE:
+
+        if (guiInfo.Filename && *guiInfo.Filename) {
+            p = strrchr(guiInfo.Filename, '/');
+
+            if (p)
+                av_strlcpy(fname, p + 1, maxlen);
+            else
+                av_strlcpy(fname, guiInfo.Filename, maxlen);
+
+            len = strlen(fname);
+
+            if (len > 3 && fname[len - 3] == '.')
+                fname[len - 3] = 0;
+            else if (len > 4 && fname[len - 4] == '.')
+                fname[len - 4] = 0;
+            else if (len > 5 && fname[len - 5] == '.')
+                fname[len - 5] = 0;
+        } else
+            av_strlcpy(fname, MSGTR_GUI_MSG_NoFileLoaded, maxlen);
+
+        break;
+
+    case STREAMTYPE_STREAM:
+
+        av_strlcpy(fname, guiInfo.Filename, maxlen);
+        break;
+
+    case STREAMTYPE_CDDA:
+
+        snprintf(fname, maxlen, MSGTR_GUI_TitleN, guiInfo.Track);
+        break;
+
+    case STREAMTYPE_VCD:
+
+        snprintf(fname, maxlen, MSGTR_GUI_TitleN, guiInfo.Track - 1);
+        break;
+
+    case STREAMTYPE_DVD:
+
+        if (guiInfo.Chapter)
+            snprintf(fname, maxlen, MSGTR_GUI_ChapterN, guiInfo.Chapter);
+        else
+            av_strlcpy(fname, MSGTR_GUI_NoChapter, maxlen);
+
+        break;
+
+    case STREAMTYPE_TV:
+    case STREAMTYPE_DVB:
+
+        p      = MSGTR_GUI_NoChannelName;
+        stream = mpctx_get_stream(guiInfo.mpcontext);
+
+        if (stream)
+            stream_control(stream, STREAM_CTRL_GET_CURRENT_CHANNEL, &p);
+
+        av_strlcpy(fname, p, maxlen);
+        break;
+
+    default:
+
+        av_strlcpy(fname, MSGTR_GUI_MSG_NoMediaOpened, maxlen);
+        break;
+    }
+
+    if (how) {
+        p = fname;
+
+        while (*p) {
+            char t = 0;
+
+            if (how == 1 && *p >= 'A' && *p <= 'Z')
+                t = 32;
+            if (how == 2 && *p >= 'a' && *p <= 'z')
+                t = -32;
+
+            *p = *p + t;
+            p++;
+        }
+    }
+
+    return fname;
+}
+
+/**
  * @brief Translate all variables in the @a text.
  *
  * @param text text containing variables

Modified: trunk/gui/util/string.c
==============================================================================
--- trunk/gui/util/string.c	Thu Mar 27 00:19:13 2014	(r37079)
+++ trunk/gui/util/string.c	Thu Mar 27 02:49:01 2014	(r37080)
@@ -25,15 +25,8 @@
 #include <string.h>
 
 #include "string.h"
-#include "gui/interface.h"
 #include "gui/app/gui.h"
 
-#include "access_mpcontext.h"
-#include "config.h"
-#include "help_mp.h"
-#include "libavutil/avstring.h"
-#include "stream/stream.h"
-
 /**
  * @brief Convert a string to lower case.
  *
@@ -258,113 +251,6 @@ void setddup(char **old, const char *dir
 }
 
 /**
- * @brief Convert #guiInfo member Filename.
- *
- * @param how 0 (cut file path and extension),
- *            1 (additionally, convert lower case) or
- *            2 (additionally, convert upper case)
- * @param fname pointer to a buffer to receive the converted Filename
- * @param maxlen size of @a fname buffer
- *
- * @return pointer to @a fname buffer
- */
-char *TranslateFilename(int how, char *fname, size_t maxlen)
-{
-    char *p;
-    size_t len;
-    stream_t *stream;
-
-    switch (guiInfo.StreamType) {
-    case STREAMTYPE_FILE:
-
-        if (guiInfo.Filename && *guiInfo.Filename) {
-            p = strrchr(guiInfo.Filename,
-#if HAVE_DOS_PATHS
-                        '\\');
-#else
-                        '/');
-#endif
-
-            if (p)
-                av_strlcpy(fname, p + 1, maxlen);
-            else
-                av_strlcpy(fname, guiInfo.Filename, maxlen);
-
-            len = strlen(fname);
-
-            if (len > 3 && fname[len - 3] == '.')
-                fname[len - 3] = 0;
-            else if (len > 4 && fname[len - 4] == '.')
-                fname[len - 4] = 0;
-            else if (len > 5 && fname[len - 5] == '.')
-                fname[len - 5] = 0;
-        } else
-            av_strlcpy(fname, MSGTR_GUI_MSG_NoFileLoaded, maxlen);
-
-        break;
-
-    case STREAMTYPE_STREAM:
-
-        av_strlcpy(fname, guiInfo.Filename, maxlen);
-        break;
-
-    case STREAMTYPE_CDDA:
-
-        snprintf(fname, maxlen, MSGTR_GUI_TitleN, guiInfo.Track);
-        break;
-
-    case STREAMTYPE_VCD:
-
-        snprintf(fname, maxlen, MSGTR_GUI_TitleN, guiInfo.Track - 1);
-        break;
-
-    case STREAMTYPE_DVD:
-
-        if (guiInfo.Chapter)
-            snprintf(fname, maxlen, MSGTR_GUI_ChapterN, guiInfo.Chapter);
-        else
-            av_strlcpy(fname, MSGTR_GUI_NoChapter, maxlen);
-
-        break;
-
-    case STREAMTYPE_TV:
-    case STREAMTYPE_DVB:
-
-        p      = MSGTR_GUI_NoChannelName;
-        stream = mpctx_get_stream(guiInfo.mpcontext);
-
-        if (stream)
-            stream_control(stream, STREAM_CTRL_GET_CURRENT_CHANNEL, &p);
-
-        av_strlcpy(fname, p, maxlen);
-        break;
-
-    default:
-
-        av_strlcpy(fname, MSGTR_GUI_MSG_NoMediaOpened, maxlen);
-        break;
-    }
-
-    if (how) {
-        p = fname;
-
-        while (*p) {
-            char t = 0;
-
-            if (how == 1 && *p >= 'A' && *p <= 'Z')
-                t = 32;
-            if (how == 2 && *p >= 'a' && *p <= 'z')
-                t = -32;
-
-            *p = *p + t;
-            p++;
-        }
-    }
-
-    return fname;
-}
-
-/**
  * @brief Read characters from @a file.
  *
  * @param str pointer to a buffer to receive the read characters

Modified: trunk/gui/util/string.h
==============================================================================
--- trunk/gui/util/string.h	Thu Mar 27 00:19:13 2014	(r37079)
+++ trunk/gui/util/string.h	Thu Mar 27 02:49:01 2014	(r37080)
@@ -31,7 +31,6 @@ void setddup(char **old, const char *dir
 void setdup(char **old, const char *str);
 char *strlower(char *in);
 char *strswap(char *in, char from, char to);
-char *TranslateFilename(int how, char *fname, size_t maxlen);
 char *trim(char *in);
 
 #endif /* MPLAYER_GUI_STRING_H */

Modified: trunk/gui/win32/widgetrender.c
==============================================================================
--- trunk/gui/win32/widgetrender.c	Thu Mar 27 00:19:13 2014	(r37079)
+++ trunk/gui/win32/widgetrender.c	Thu Mar 27 02:49:01 2014	(r37080)
@@ -22,6 +22,7 @@
  */
 
 #include <stdio.h>
+#include <string.h>
 #include <ctype.h>
 #include <windows.h>
 
@@ -30,6 +31,11 @@
 #include "gui/interface.h"
 #include "gui.h"
 
+#include "access_mpcontext.h"
+#include "help_mp.h"
+#include "libavutil/avstring.h"
+#include "stream/stream.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)
@@ -115,6 +121,102 @@ static void stringreplace(char *dest, co
     }
 }
 
+/**
+ * @brief Convert #guiInfo member Filename.
+ *
+ * @param how 0 (cut file path and extension),
+ *            1 (additionally, convert lower case) or
+ *            2 (additionally, convert upper case)
+ * @param fname pointer to a buffer to receive the converted Filename
+ * @param maxlen size of @a fname buffer
+ *
+ * @return pointer to @a fname buffer
+ */
+char *TranslateFilename (int how, char *fname, size_t maxlen)
+{
+    char *p;
+    size_t len;
+    stream_t *stream;
+
+    switch (guiInfo.StreamType)
+    {
+        case STREAMTYPE_FILE:
+
+            if (guiInfo.Filename && *guiInfo.Filename)
+            {
+                p = strrchr(guiInfo.Filename, '\\');
+
+                if (p) av_strlcpy(fname, p + 1, maxlen);
+                else av_strlcpy(fname, guiInfo.Filename, maxlen);
+
+                len = strlen(fname);
+
+                if (len > 3 && fname[len - 3] == '.') fname[len - 3] = 0;
+                else if (len > 4 && fname[len - 4] == '.') fname[len - 4] = 0;
+                else if (len > 5 && fname[len - 5] == '.') fname[len - 5] = 0;
+            }
+            else av_strlcpy(fname, MSGTR_GUI_MSG_NoFileLoaded, maxlen);
+
+            break;
+
+        case STREAMTYPE_STREAM:
+
+            av_strlcpy(fname, guiInfo.Filename, maxlen);
+            break;
+
+        case STREAMTYPE_CDDA:
+
+            snprintf(fname, maxlen, MSGTR_GUI_TitleN, guiInfo.Track);
+            break;
+
+        case STREAMTYPE_VCD:
+
+            snprintf(fname, maxlen, MSGTR_GUI_TitleN, guiInfo.Track - 1);
+            break;
+
+        case STREAMTYPE_DVD:
+
+            if (guiInfo.Chapter) snprintf(fname, maxlen, MSGTR_GUI_ChapterN, guiInfo.Chapter);
+            else av_strlcpy(fname, MSGTR_GUI_NoChapter, maxlen);
+
+            break;
+
+        case STREAMTYPE_TV:
+        case STREAMTYPE_DVB:
+
+            p = MSGTR_GUI_NoChannelName;
+            stream = mpctx_get_stream(guiInfo.mpcontext);
+
+            if (stream) stream_control(stream, STREAM_CTRL_GET_CURRENT_CHANNEL, &p);
+
+            av_strlcpy(fname, p, maxlen);
+            break;
+
+        default:
+
+            av_strlcpy(fname, MSGTR_GUI_MSG_NoMediaOpened, maxlen);
+            break;
+    }
+
+    if (how)
+    {
+        p = fname;
+
+        while (*p)
+        {
+            char t = 0;
+
+            if (how == 1 && *p >= 'A' && *p <= 'Z') t = 32;
+            if (how == 2 && *p >= 'a' && *p <= 'z') t = -32;
+
+            *p = *p + t;
+            p++;
+        }
+    }
+
+    return fname;
+}
+
 /* replaces the chars with special meaning with the associated data from the player info struct */
 static char *generatetextfromlabel(widget *item)
 {


More information about the MPlayer-cvslog mailing list