we used to g_free memory returned by strdup() here! Also we used to append

2000-11-15  Sven Neumann  <sven@gimp.org>

	* app/fileops.c: we used to g_free memory returned by strdup() here!
	Also we used to append DIR_SEPARATORs to the filename shown in the
	file_selector even if it already ended in one. Fixed all this, closed
	a memleak and cleaned up the code.
This commit is contained in:
Sven Neumann 2000-11-15 17:48:43 +00:00 committed by Sven Neumann
parent 353f6a72ac
commit c84c286b87
7 changed files with 156 additions and 116 deletions

View File

@ -1,3 +1,10 @@
2000-11-15 Sven Neumann <sven@gimp.org>
* app/fileops.c: we used to g_free memory returned by strdup() here!
Also we used to append DIR_SEPARATORs to the filename shown in the
file_selector even if it already ended in one. Fixed all this, closed
a memleak and cleaned up the code.
Mon Nov 13 01:28:24 PST 2000 Manish Singh <yosh@gimp.org>
* plug-ins/common/url.c: set all the locale variables we can, to

View File

@ -66,6 +66,7 @@
#include "gdisplay.h"
#include "gimage.h"
#include "gimpcontext.h"
#include "gimpdrawableP.h"
#include "gimpui.h"
#include "fileops.h"
#include "fileopsP.h"
@ -110,7 +111,7 @@ static GimpImage * file_open_image (gchar *filename,
RunModeType run_mode,
gint *status);
static gint file_save (GimpImage *gimage,
static gint file_save (GimpImage *gimage,
gchar *filename,
gchar *raw_filename,
RunModeType run_mode);
@ -159,7 +160,8 @@ static gint file_check_magic_list (GSList *magics_list,
static void file_update_menus (GSList *procs,
gint image_type);
static GSList* clist_to_slist (GtkCList *file_list);
static GSList* clist_to_slist (GtkCList *file_list);
static GtkWidget *fileload = NULL;
@ -300,7 +302,7 @@ file_open_callback (GtkWidget *widget,
if (GTK_WIDGET_VISIBLE (fileload))
return;
gtk_file_selection_set_filename (GTK_FILE_SELECTION(fileload),
gtk_file_selection_set_filename (GTK_FILE_SELECTION (fileload),
"." G_DIR_SEPARATOR_S);
gtk_window_set_title (GTK_WINDOW (fileload), _("Load Image"));
}
@ -1063,6 +1065,7 @@ file_save_thumbnail (GimpImage *gimage,
}
}
break;
case GRAY:
for (i=0; i<h; i++)
{
@ -1092,10 +1095,13 @@ file_save_thumbnail (GimpImage *gimage,
}
}
break;
default:
g_warning("UNKNOWN GIMAGE TYPE IN THUMBNAIL SAVE");
break;
}
fclose(fp);
fclose (fp);
}
else /* Error writing thumbnail */
{
@ -1364,10 +1370,7 @@ set_preview (const gchar *fullfname,
gtk_frame_set_label (GTK_FRAME (open_options_frame), fname);
if (preview_fullname)
{
g_free (preview_fullname);
}
g_free (preview_fullname);
preview_fullname = g_strdup (fullfname);
if (RGB_source)
@ -1435,6 +1438,7 @@ set_preview (const gchar *fullfname,
_("(Thumbnail file not written)"));
}
}
gtk_widget_show (GTK_WIDGET (open_options_preview));
gtk_widget_queue_draw (GTK_WIDGET(open_options_preview));
@ -1517,11 +1521,13 @@ file_open_genbutton_callback (GtkWidget *widget,
gtk_file_selection_set_filename (fs, "");
filedirname= gtk_file_selection_get_filename (fs);
if (filedirname[strlen (filedirname) - 1] == G_DIR_SEPARATOR)
filedirname[strlen (filedirname) - 1] = '\0';
while(list)
{
full_filename = g_strconcat (filedirname, G_DIR_SEPARATOR_S,
(char *) list->data, NULL);
(gchar *) list->data, NULL);
err = stat (full_filename, &buf);
@ -1559,24 +1565,26 @@ file_open_genbutton_callback (GtkWidget *widget,
_("(could not make preview)"));
}
}
g_free(full_filename);
list= g_slist_next(list);
}
list = toplist;
while (list)
for (list = toplist; list; list = g_slist_next (list))
{
if (!(g_slist_next(list)))
if (!(g_slist_next (list)))
{
full_filename = g_strconcat (filedirname, G_DIR_SEPARATOR_S,
(char *) list->data, NULL);
(gchar *) list->data, NULL);
gtk_file_selection_set_filename (fs, full_filename);
g_free (full_filename);
}
g_free(list->data);
list= g_slist_next(list);
g_free (list->data);
}
g_slist_free(toplist);
toplist= NULL;
g_slist_free (toplist);
toplist = NULL;
}
gtk_widget_set_sensitive (GTK_WIDGET (fileload), TRUE);
@ -1607,13 +1615,15 @@ file_open_ok_callback (GtkWidget *widget,
if (err == 0 && (buf.st_mode & S_IFDIR))
{
GString *s = g_string_new (full_filename);
if (s->str[s->len - 1] != G_DIR_SEPARATOR)
if (full_filename[strlen (full_filename) - 1] != G_DIR_SEPARATOR)
{
g_string_append_c (s, G_DIR_SEPARATOR);
gchar *s = g_strconcat (full_filename, G_DIR_SEPARATOR_S, NULL);
gtk_file_selection_set_filename (fs, s);
g_free (s);
}
gtk_file_selection_set_filename (fs, s->str);
g_string_free (s, TRUE);
else
gtk_file_selection_set_filename (fs, full_filename);
return;
}
@ -1643,18 +1653,18 @@ file_open_ok_callback (GtkWidget *widget,
/* Have to read the clist before touching anything else */
list= clist_to_slist(GTK_CLIST(fs->file_list));
list = clist_to_slist (GTK_CLIST (fs->file_list));
/* Find a real base directory for the multiple selection */
raw_filename= g_strdup(raw_filename);
raw_filename = g_strdup(raw_filename);
gtk_file_selection_set_filename (fs, "");
filedirname= gtk_file_selection_get_filename (fs);
filedirname = gtk_file_selection_get_filename (fs);
while(list)
while (list)
{
full_filename = g_strconcat (filedirname, G_DIR_SEPARATOR_S,
(char *) list->data, NULL);
(gchar *) list->data, NULL);
if (strcmp (list->data, raw_filename))
{ /* don't load current selection twice */
@ -1677,16 +1687,17 @@ file_open_ok_callback (GtkWidget *widget,
}
}
g_free(full_filename);
g_free(list->data);
list= g_slist_next(list);
g_free (full_filename);
g_free (list->data);
list = g_slist_next (list);
}
g_slist_free(list);
list= NULL;
g_slist_free (list);
list = NULL;
}
gtk_file_selection_set_filename (fs, raw_filename);
g_free(raw_filename);
g_free (raw_filename);
gtk_widget_set_sensitive (GTK_WIDGET (fs), TRUE);
}
@ -1695,23 +1706,24 @@ static GSList *
clist_to_slist (GtkCList *file_list)
{
GSList *list = NULL;
GList *row = file_list->row_list;
gint rownum = 0;
gchar *temp;
GList *row;
gint rownum;
gchar *temp;
while (row)
for (row = file_list->row_list, rownum = 0;
row;
row = g_list_next (row), rownum++)
{
if (GTK_CLIST_ROW (row)->state == GTK_STATE_SELECTED)
{
if (gtk_clist_get_cell_type (file_list, rownum, 0) == GTK_CELL_TEXT)
{
gtk_clist_get_text (file_list, rownum, 0, &temp);
list = g_slist_prepend(list, strdup(temp));
list = g_slist_prepend (list, g_strdup (temp));
}
}
rownum++;
row = g_list_next (row);
}
return list;
}
@ -1729,7 +1741,7 @@ file_save_with_proc (GImage *gimage,
gint status = PDB_EXECUTION_ERROR;
if (gimage != NULL)
{
{
gimage_set_save_proc (gimage, save_proc);
status = file_save (gimage,
full_filename,
@ -1738,17 +1750,14 @@ file_save_with_proc (GImage *gimage,
/* hide the file save dialog on success */
if (status == PDB_SUCCESS)
file_dialog_hide (filesave);
}
file_dialog_hide (filesave);
}
/* If there was an error but file_save() didn't print an error
* message, then we'd better. */
if (status != PDB_SUCCESS &&
status != PDB_CANCEL)
{
g_message (_("Save failed.\n%s"), full_filename);
}
if (status != PDB_SUCCESS && status != PDB_CANCEL)
g_message (_("Save failed.\n%s"), full_filename);
/* always make file save dialog sensitive */
gtk_widget_set_sensitive (GTK_WIDGET (filesave), TRUE);
}
@ -1761,25 +1770,67 @@ file_save_ok_callback (GtkWidget *widget,
GtkFileSelection *fs;
gchar *filename;
gchar *raw_filename;
gchar *dot;
gint x;
struct stat buf;
gint err;
fs = GTK_FILE_SELECTION (data);
filename = gtk_file_selection_get_filename (fs);
raw_filename = gtk_entry_get_text (GTK_ENTRY(fs->selection_entry));
raw_filename = gtk_entry_get_text (GTK_ENTRY (fs->selection_entry));
g_assert (filename && raw_filename);
for (dot = strrchr (filename, '.'), x = 0; dot && *(++dot);)
{
if (*dot != 'e' || ++x < 0)
break;
else if (x > 3 && !strcmp (dot + 1, "k"))
{
ProcRecord *proc_rec;
Argument *args;
GimpDrawable *the_drawable;
the_drawable = gimp_image_active_drawable (the_gimage);
if (!the_drawable)
return;
proc_rec = procedural_db_lookup ("plug_in_the_egg");
if (!proc_rec)
break;
file_dialog_hide (filesave);
args = g_new (Argument, 3);
args[0].arg_type = PDB_INT32;
args[0].value.pdb_int = RUN_INTERACTIVE;
args[1].arg_type = PDB_IMAGE;
args[1].value.pdb_int = pdb_image_to_id (the_gimage);
args[2].arg_type = PDB_DRAWABLE;
args[2].value.pdb_int = the_drawable->ID;
plug_in_run (proc_rec, args, 3, FALSE, TRUE, 0);
g_free (args);
return;
}
}
err = stat (filename, &buf);
if (err == 0)
{
if (buf.st_mode & S_IFDIR)
{
GString *s = g_string_new (filename);
g_string_append_c (s, G_DIR_SEPARATOR);
gtk_file_selection_set_filename (fs, s->str);
g_string_free (s, TRUE);
if (filename[strlen (filename) - 1] != G_DIR_SEPARATOR)
{
gchar *s = g_strconcat (filename, G_DIR_SEPARATOR_S, NULL);
gtk_file_selection_set_filename (fs, s);
g_free (s);
}
else
gtk_file_selection_set_filename (fs, filename);
}
else
{

View File

@ -562,11 +562,6 @@ static GimpItemFactoryEntry image_entries[] =
NULL, NULL },
{ { N_("/Filters/Combine"), NULL, NULL, 0, "<Branch>" },
NULL, NULL },
{ { "/Filters/---", NULL, NULL, 0, "<Separator>" },
NULL, NULL },
{ { N_("/Filters/Toys"), NULL, NULL, 0, "<Branch>" },
NULL, NULL },
};
static guint n_image_entries = (sizeof (image_entries) /
sizeof (image_entries[0]));
@ -1128,7 +1123,7 @@ menus_reorder_plugins (void)
}
}
/* Move all submenus which registered after "<Image>/Filters/Toys"
/* Move all submenus which registered after "<Image>/Filters/Combine"
* before the separator after "<Image>/Filters/Web"
*/
menu_item = gtk_item_factory_get_widget (image_factory,
@ -1140,7 +1135,7 @@ menus_reorder_plugins (void)
pos = g_list_index (GTK_MENU_SHELL (menu)->children, menu_item);
menu_item = gtk_item_factory_get_widget (image_factory,
"/Filters/Toys");
"/Filters/Combine");
if (menu_item && GTK_IS_MENU (menu_item))
{

View File

@ -562,11 +562,6 @@ static GimpItemFactoryEntry image_entries[] =
NULL, NULL },
{ { N_("/Filters/Combine"), NULL, NULL, 0, "<Branch>" },
NULL, NULL },
{ { "/Filters/---", NULL, NULL, 0, "<Separator>" },
NULL, NULL },
{ { N_("/Filters/Toys"), NULL, NULL, 0, "<Branch>" },
NULL, NULL },
};
static guint n_image_entries = (sizeof (image_entries) /
sizeof (image_entries[0]));
@ -1128,7 +1123,7 @@ menus_reorder_plugins (void)
}
}
/* Move all submenus which registered after "<Image>/Filters/Toys"
/* Move all submenus which registered after "<Image>/Filters/Combine"
* before the separator after "<Image>/Filters/Web"
*/
menu_item = gtk_item_factory_get_widget (image_factory,
@ -1140,7 +1135,7 @@ menus_reorder_plugins (void)
pos = g_list_index (GTK_MENU_SHELL (menu)->children, menu_item);
menu_item = gtk_item_factory_get_widget (image_factory,
"/Filters/Toys");
"/Filters/Combine");
if (menu_item && GTK_IS_MENU (menu_item))
{

View File

@ -562,11 +562,6 @@ static GimpItemFactoryEntry image_entries[] =
NULL, NULL },
{ { N_("/Filters/Combine"), NULL, NULL, 0, "<Branch>" },
NULL, NULL },
{ { "/Filters/---", NULL, NULL, 0, "<Separator>" },
NULL, NULL },
{ { N_("/Filters/Toys"), NULL, NULL, 0, "<Branch>" },
NULL, NULL },
};
static guint n_image_entries = (sizeof (image_entries) /
sizeof (image_entries[0]));
@ -1128,7 +1123,7 @@ menus_reorder_plugins (void)
}
}
/* Move all submenus which registered after "<Image>/Filters/Toys"
/* Move all submenus which registered after "<Image>/Filters/Combine"
* before the separator after "<Image>/Filters/Web"
*/
menu_item = gtk_item_factory_get_widget (image_factory,
@ -1140,7 +1135,7 @@ menus_reorder_plugins (void)
pos = g_list_index (GTK_MENU_SHELL (menu)->children, menu_item);
menu_item = gtk_item_factory_get_widget (image_factory,
"/Filters/Toys");
"/Filters/Combine");
if (menu_item && GTK_IS_MENU (menu_item))
{

View File

@ -562,11 +562,6 @@ static GimpItemFactoryEntry image_entries[] =
NULL, NULL },
{ { N_("/Filters/Combine"), NULL, NULL, 0, "<Branch>" },
NULL, NULL },
{ { "/Filters/---", NULL, NULL, 0, "<Separator>" },
NULL, NULL },
{ { N_("/Filters/Toys"), NULL, NULL, 0, "<Branch>" },
NULL, NULL },
};
static guint n_image_entries = (sizeof (image_entries) /
sizeof (image_entries[0]));
@ -1128,7 +1123,7 @@ menus_reorder_plugins (void)
}
}
/* Move all submenus which registered after "<Image>/Filters/Toys"
/* Move all submenus which registered after "<Image>/Filters/Combine"
* before the separator after "<Image>/Filters/Web"
*/
menu_item = gtk_item_factory_get_widget (image_factory,
@ -1140,7 +1135,7 @@ menus_reorder_plugins (void)
pos = g_list_index (GTK_MENU_SHELL (menu)->children, menu_item);
menu_item = gtk_item_factory_get_widget (image_factory,
"/Filters/Toys");
"/Filters/Combine");
if (menu_item && GTK_IS_MENU (menu_item))
{

View File

@ -44,13 +44,13 @@
/* Declare local functions. */
static void query (void);
static void run (gchar *name,
gint nparams,
static void run (gchar *name,
gint nparams,
GimpParam *param,
gint *nreturn_vals,
gint *nreturn_vals,
GimpParam **return_vals);
static void do_playback (void);
static void do_playback (void);
static gint window_delete_callback (GtkWidget *widget,
GdkEvent *event,
@ -61,9 +61,9 @@ static gint step_callback (gpointer data);
static void toggle_feedbacktype (GtkWidget *widget,
gpointer data);
static void render_frame (void);
static void show_frame (void);
static void init_preview_misc (void);
static void render_frame (void);
static void show_frame (void);
static void init_preview_misc (void);
GimpPlugInInfo PLUG_IN_INFO =
@ -100,7 +100,7 @@ static GtkPreview *preview = NULL;
static gint32 image_id;
static gint32 total_frames;
static gint32 *layers;
static GimpDrawable *drawable;
static GimpDrawable *drawable;
static GimpImageBaseType imagetype;
static guchar *palette;
static gint ncolours;
@ -131,8 +131,7 @@ query (void)
"Adam D. Moss <adam@gimp.org>",
"Adam D. Moss <adam@gimp.org>",
"1998",
N_("<Image>/Filters/Toys/The Egg..."),
/*NULL,*/
NULL,
"RGB*, INDEXED*, GRAY*",
GIMP_PLUGIN,
nargs, 0,
@ -140,14 +139,14 @@ query (void)
}
static void
run (gchar *name,
gint n_params,
run (gchar *name,
gint n_params,
GimpParam *param,
gint *nreturn_vals,
gint *nreturn_vals,
GimpParam **return_vals)
{
static GimpParam values[1];
GimpRunModeType run_mode;
static GimpParam values[1];
GimpRunModeType run_mode;
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
*nreturn_vals = 1;
@ -181,10 +180,9 @@ run (gchar *name,
}
static void
build_dialog (GimpImageBaseType basetype,
char* imagename)
build_dialog (GimpImageBaseType basetype,
gchar *imagename)
{
GtkWidget *dlg;
GtkWidget *button;
@ -286,9 +284,10 @@ build_dialog (GimpImageBaseType basetype,
}
static void init_lut(void)
static void
init_lut (void)
{
int i;
gint i;
for (i=0; i<LUTSIZE; i++)
{
@ -299,7 +298,8 @@ static void init_lut(void)
}
static void do_playback(void)
static void
do_playback (void)
{
layers = gimp_image_get_layers (image_id, &total_frames);
imagetype = gimp_image_base_type(image_id);
@ -327,8 +327,9 @@ static void do_playback(void)
/* Rendering Functions */
/* Adam's silly algorithm. */
void domap1(unsigned char *src, unsigned char *dest,
int bx, int by, int cx, int cy)
static void
domap1 (unsigned char *src, unsigned char *dest,
int bx, int by, int cx, int cy)
{
unsigned int dy;
signed int bycxmcybx;
@ -400,8 +401,9 @@ void domap1(unsigned char *src, unsigned char *dest,
}
/* 3bypp variant */
void domap3(unsigned char *src, unsigned char *dest,
int bx, int by, int cx, int cy)
static void
domap3(unsigned char *src, unsigned char *dest,
int bx, int by, int cx, int cy)
{
unsigned int dy;
signed int bycxmcybx;
@ -481,7 +483,7 @@ void domap3(unsigned char *src, unsigned char *dest,
static void
render_frame(void)
render_frame (void)
{
int i;
static int frame = 0;
@ -652,7 +654,7 @@ render_frame(void)
static void
show_frame(void)
show_frame (void)
{
#ifdef RAPH_IS_HOME
#else
@ -663,10 +665,10 @@ show_frame(void)
static void
init_preview_misc(void)
init_preview_misc (void)
{
GimpPixelRgn pixel_rgn;
int i;
gint i;
gboolean has_alpha;
if ((imagetype == GIMP_RGB) || (imagetype == GIMP_INDEXED))
@ -814,11 +816,11 @@ init_preview_misc(void)
/* Util. */
static int
do_step(void)
do_step (void)
{
render_frame();
render_frame ();
return(1);
return 1;
}
@ -832,8 +834,8 @@ window_delete_callback (GtkWidget *widget,
{
gtk_idle_remove (idle_tag);
gdk_flush();
gtk_main_quit();
gdk_flush ();
gtk_main_quit ();
return FALSE;
}