[MPlayer-cvslog] r33828 - in trunk/gui: interface.c interface.h ui/actions.c ui/gtk/fileselect.c ui/gtk/playlist.c ui/gtk/preferences.c ui/gtk/url.c util/string.c util/string.h win32/interface.c
ib
subversion at mplayerhq.hu
Thu Jul 7 12:16:23 CEST 2011
Author: ib
Date: Thu Jul 7 12:16:22 2011
New Revision: 33828
Log:
Remove macros guiSetFilename() and guiSetDF() from interface.h.
Rename guiSetFilename() setdup() and guiSetDF() setddup()
and define them in string.c as functions.
Adjust malloc size to necessary size and check pointer returned
by malloc() to prevent segmentation fault.
Modified:
trunk/gui/interface.c
trunk/gui/interface.h
trunk/gui/ui/actions.c
trunk/gui/ui/gtk/fileselect.c
trunk/gui/ui/gtk/playlist.c
trunk/gui/ui/gtk/preferences.c
trunk/gui/ui/gtk/url.c
trunk/gui/util/string.c
trunk/gui/util/string.h
trunk/gui/win32/interface.c
Modified: trunk/gui/interface.c
==============================================================================
--- trunk/gui/interface.c Thu Jul 7 11:29:15 2011 (r33827)
+++ trunk/gui/interface.c Thu Jul 7 12:16:22 2011 (r33828)
@@ -329,7 +329,7 @@ void guiInit(void)
uiSetFileName(plCurrent->path, plCurrent->name, STREAMTYPE_FILE);
if (subdata)
- guiSetFilename(guiInfo.Subtitlename, subdata->filename);
+ setdup(&guiInfo.Subtitlename, subdata->filename);
guiLoadFont();
@@ -606,7 +606,7 @@ int gui(int what, void *arg)
char tmp[512];
sprintf(tmp, "vcd://%d", guiInfo.Track + 1);
- guiSetFilename(guiInfo.Filename, tmp);
+ setdup(&guiInfo.Filename, tmp);
}
break;
#endif
@@ -617,7 +617,7 @@ int gui(int what, void *arg)
char tmp[512];
sprintf(tmp, "dvd://%d", guiInfo.Title);
- guiSetFilename(guiInfo.Filename, tmp);
+ setdup(&guiInfo.Filename, tmp);
}
dvd_chapter = guiInfo.Chapter;
@@ -632,7 +632,7 @@ int gui(int what, void *arg)
if (guiInfo.Filename)
filename = gstrdup(guiInfo.Filename);
else if (filename)
- guiSetFilename(guiInfo.Filename, filename);
+ setdup(&guiInfo.Filename, filename);
}
// video opts
@@ -953,7 +953,7 @@ int gui(int what, void *arg)
if (guiInfo.Playing && (next = gtkSet(gtkGetNextPlItem, 0, NULL)) && (plLastPlayed != next)) {
plLastPlayed = next;
- guiSetDF(guiInfo.Filename, next->path, next->name);
+ setddup(&guiInfo.Filename, next->path, next->name);
guiInfo.StreamType = STREAMTYPE_FILE;
guiInfo.FilenameChanged = guiInfo.NewPlay = 1;
nfree(guiInfo.AudioFile);
Modified: trunk/gui/interface.h
==============================================================================
--- trunk/gui/interface.h Thu Jul 7 11:29:15 2011 (r33827)
+++ trunk/gui/interface.h Thu Jul 7 12:16:22 2011 (r33828)
@@ -89,19 +89,6 @@ extern int use_gui; // this
#define fsPersistant_MaxPos 5
-#define guiSetFilename(s, n) \
- { \
- free(s); \
- s = gstrdup(n); \
- }
-
-#define guiSetDF(s, d, n) \
- { \
- free(s); \
- s = malloc(strlen(d) + strlen(n) + 5); \
- sprintf(s, "%s/%s", d, n); \
- }
-
typedef struct {
int x;
int y;
Modified: trunk/gui/ui/actions.c
==============================================================================
--- trunk/gui/ui/actions.c Thu Jul 7 11:29:15 2011 (r33827)
+++ trunk/gui/ui/actions.c Thu Jul 7 12:16:22 2011 (r33828)
@@ -257,9 +257,9 @@ void uiSetFileName(char *dir, char *name
return;
if (!dir)
- guiSetFilename(guiInfo.Filename, name)
+ setdup(&guiInfo.Filename, name);
else
- guiSetDF(guiInfo.Filename, dir, name)
+ setddup(&guiInfo.Filename, dir, name);
guiInfo.StreamType = type;
nfree(guiInfo.AudioFile);
Modified: trunk/gui/ui/gtk/fileselect.c
==============================================================================
--- trunk/gui/ui/gtk/fileselect.c Thu Jul 7 11:29:15 2011 (r33827)
+++ trunk/gui/ui/gtk/fileselect.c Thu Jul 7 12:16:22 2011 (r33828)
@@ -478,7 +478,7 @@ static void fs_Ok_released( GtkButton *
switch ( fsType )
{
case fsVideoSelector:
- guiSetDF( guiInfo.Filename,fsSelectedDirectory,fsSelectedFile );
+ setddup( &guiInfo.Filename,fsSelectedDirectory,fsSelectedFile );
guiInfo.StreamType=STREAMTYPE_FILE;
guiInfo.FilenameChanged=1; sub_fps=0;
nfree( guiInfo.AudioFile );
@@ -486,17 +486,17 @@ static void fs_Ok_released( GtkButton *
fs_PersistantHistory( get_current_dir_name_utf8() ); //totem, write into history
break;
case fsSubtitleSelector:
- guiSetDF( guiInfo.Subtitlename,fsSelectedDirectory,fsSelectedFile );
+ setddup( &guiInfo.Subtitlename,fsSelectedDirectory,fsSelectedFile );
guiLoadSubtitle( guiInfo.Subtitlename );
break;
case fsOtherSelector:
- guiSetDF( guiInfo.Othername,fsSelectedDirectory,fsSelectedFile );
+ setddup( &guiInfo.Othername,fsSelectedDirectory,fsSelectedFile );
break;
case fsAudioSelector:
- guiSetDF( guiInfo.AudioFile,fsSelectedDirectory,fsSelectedFile );
+ setddup( &guiInfo.AudioFile,fsSelectedDirectory,fsSelectedFile );
break;
case fsFontSelector:
- guiSetDF( font_name,fsSelectedDirectory,fsSelectedFile );
+ setddup( &font_name,fsSelectedDirectory,fsSelectedFile );
guiLoadFont();
if ( Preferences ) gtk_entry_set_text( GTK_ENTRY( prEFontName ),font_name );
break;
Modified: trunk/gui/ui/gtk/playlist.c
==============================================================================
--- trunk/gui/ui/gtk/playlist.c Thu Jul 7 11:29:15 2011 (r33827)
+++ trunk/gui/ui/gtk/playlist.c Thu Jul 7 12:16:22 2011 (r33828)
@@ -207,7 +207,7 @@ static void plButtonReleased( GtkButton
if ( plCurrent )
{
uiSetFileName( plCurrent->path,plCurrent->name,STREAMTYPE_FILE );
-// guiSetDF( guiInfo.Filename,plCurrent->path,plCurrent->name );
+// setddup( &guiInfo.Filename,plCurrent->path,plCurrent->name );
// guiInfo.FilenameChanged=1;
// guiInfo.StreamType=STREAMTYPE_FILE;
}
Modified: trunk/gui/ui/gtk/preferences.c
==============================================================================
--- trunk/gui/ui/gtk/preferences.c Thu Jul 7 11:29:15 2011 (r33827)
+++ trunk/gui/ui/gtk/preferences.c Thu Jul 7 12:16:22 2011 (r33828)
@@ -585,7 +585,7 @@ static void prButton( GtkButton * button
// --- 4. page
- guiSetFilename( font_name,gtk_entry_get_text( GTK_ENTRY( prEFontName ) ) );
+ setdup( &font_name,gtk_entry_get_text( GTK_ENTRY( prEFontName ) ) );
#ifndef CONFIG_FREETYPE
gtkSet( gtkSetFontFactor,HSFontFactoradj->value,NULL );
#else
@@ -636,8 +636,8 @@ static void prButton( GtkButton * button
if ( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( CBAutoSync ) ) ) { gtkAutoSync=(int)SBAutoSyncadj->value; gtkAutoSyncOn=1; }
else gtkAutoSyncOn=0;
- guiSetFilename( dvd_device,gtk_entry_get_text( GTK_ENTRY( prEDVDDevice ) ) );
- guiSetFilename( cdrom_device,gtk_entry_get_text( GTK_ENTRY( prECDRomDevice ) ) );
+ setdup( &dvd_device,gtk_entry_get_text( GTK_ENTRY( prEDVDDevice ) ) );
+ setdup( &cdrom_device,gtk_entry_get_text( GTK_ENTRY( prECDRomDevice ) ) );
case bCancel:
HidePreferences();
Modified: trunk/gui/ui/gtk/url.c
==============================================================================
--- trunk/gui/ui/gtk/url.c Thu Jul 7 11:29:15 2011 (r33827)
+++ trunk/gui/ui/gtk/url.c Thu Jul 7 12:16:22 2011 (r33828)
@@ -102,7 +102,7 @@ static void on_Button_pressed( GtkButton
item->url=gstrdup( str );
gtkSet( gtkAddURLItem,0,(void *)item );
- guiSetFilename( guiInfo.Filename,str ); guiInfo.FilenameChanged=1;
+ setdup( &guiInfo.Filename,str ); guiInfo.FilenameChanged=1;
uiEventHandling( evPlayNetwork,0 );
}
}
Modified: trunk/gui/util/string.c
==============================================================================
--- trunk/gui/util/string.c Thu Jul 7 11:29:15 2011 (r33827)
+++ trunk/gui/util/string.c Thu Jul 7 12:16:22 2011 (r33828)
@@ -16,6 +16,8 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
+#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
#include "string.h"
@@ -130,3 +132,17 @@ char *gstrdup(const char *str)
return strdup(str);
}
+
+void setdup(char **old, const char *str)
+{
+ free(*old);
+ *old = gstrdup(str);
+}
+
+void setddup(char **old, const char *dir, const char *name)
+{
+ free(*old);
+ *old = malloc(strlen(dir) + strlen(name) + 2);
+ if (*old)
+ sprintf(*old, "%s/%s", dir, name);
+}
Modified: trunk/gui/util/string.h
==============================================================================
--- trunk/gui/util/string.h Thu Jul 7 11:29:15 2011 (r33827)
+++ trunk/gui/util/string.h Thu Jul 7 12:16:22 2011 (r33828)
@@ -24,6 +24,8 @@ char *gstrchr(const char *str, int c);
int gstrcmp(const char *a, const char *b);
char *gstrdup(const char *str);
int gstrncmp(const char *a, const char *b, int n);
+void setddup(char **old, const char *dir, const char *name);
+void setdup(char **old, const char *str);
char *strlower(char *in);
char *strswap(char *in, char from, char to);
char *trim(char *in);
Modified: trunk/gui/win32/interface.c
==============================================================================
--- trunk/gui/win32/interface.c Thu Jul 7 11:29:15 2011 (r33827)
+++ trunk/gui/win32/interface.c Thu Jul 7 12:16:22 2011 (r33828)
@@ -96,6 +96,19 @@ char *gstrdup(const char *str)
return strdup(str);
}
+static void setdup (char **old, const char *str)
+{
+ free(*old);
+ *old = gstrdup(str);
+}
+
+static void setddup (char **old, const char *dir, const char *name)
+{
+ free(*old);
+ *old = malloc(strlen(dir) + strlen(name) + 2);
+ if (*old) sprintf(*old, "%s/%s", dir, name);
+}
+
/**
* \brief this actually creates a new list containing only one element...
*/
@@ -388,9 +401,9 @@ void uiSetFileName(char *dir, char *name
{
if(!name) return;
if(!dir)
- guiSetFilename(guiInfo.Filename, name)
+ setdup(&guiInfo.Filename, name);
else
- guiSetDF(guiInfo.Filename, dir, name);
+ setddup(&guiInfo.Filename, dir, name);
guiInfo.StreamType = type;
free(guiInfo.AudioFile);
@@ -517,7 +530,7 @@ int gui(int what, void *arg)
dvd_chapter = guiInfo.DVD.current_chapter;
dvd_angle = guiInfo.DVD.current_angle;
sprintf(tmp,"dvd://%d", guiInfo.Title);
- guiSetFilename(guiInfo.Filename, tmp);
+ setdup(&guiInfo.Filename, tmp);
break;
}
#endif
More information about the MPlayer-cvslog
mailing list