Commit 840a9700 authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer
Browse files

app/file-open.c app/file-utils.c app/gimprc.c app/plug_in.c

2001-10-24  Michael Natterer  <mitch@gimp.org>

	* app/file-open.c
	* app/file-utils.c
	* app/gimprc.c
	* app/plug_in.c
	* app/user_install.c
	* app/base/base.c
	* app/base/temp-buf.c
	* app/core/gimpdata.c
	* app/core/gimpdatafiles.c
	* app/core/gimpimagefile.c
	* app/gui/about-dialog.c
	* app/gui/file-open-dialog.c
	* app/gui/file-save-dialog.c
	* app/gui/gui.c
	* app/gui/menus.c
	* app/gui/splash.c
	* app/gui/tips-dialog.c
	* app/tools/gimpcurvestool.c
	* app/tools/gimplevelstool.c
	* libgimpbase/gimpenv.c
	* plug-ins/FractalExplorer/FractalExplorer.c
	* plug-ins/gfig/gfig.c
	* plug-ins/gflare/gflare.c
	* tools/pdbgen/pdb/fileops.pdb: use g_build_filename() all over
	the place instead of g_strconcat() and friends together with
	G_DIR_SEPARATOR_S. Also removed all attempts to manually detect
	double dir separators. LibGimpBase's searchpath utility functions
	don't append a G_DIR_SEPARATOR_S to all paths any more.

	* app/pdb/fileops_cmds.c: regenerated.
parent f766956e
2001-10-24 Michael Natterer <mitch@gimp.org>
* app/file-open.c
* app/file-utils.c
* app/gimprc.c
* app/plug_in.c
* app/user_install.c
* app/base/base.c
* app/base/temp-buf.c
* app/core/gimpdata.c
* app/core/gimpdatafiles.c
* app/core/gimpimagefile.c
* app/gui/about-dialog.c
* app/gui/file-open-dialog.c
* app/gui/file-save-dialog.c
* app/gui/gui.c
* app/gui/menus.c
* app/gui/splash.c
* app/gui/tips-dialog.c
* app/tools/gimpcurvestool.c
* app/tools/gimplevelstool.c
* libgimpbase/gimpenv.c
* plug-ins/FractalExplorer/FractalExplorer.c
* plug-ins/gfig/gfig.c
* plug-ins/gflare/gflare.c
* tools/pdbgen/pdb/fileops.pdb: use g_build_filename() all over
the place instead of g_strconcat() and friends together with
G_DIR_SEPARATOR_S. Also removed all attempts to manually detect
double dir separators. LibGimpBase's searchpath utility functions
don't append a G_DIR_SEPARATOR_S to all paths any more.
* app/pdb/fileops_cmds.c: regenerated.
2001-10-24 Michael Natterer <mitch@gimp.org>
* libgimpwidgets/gimpbutton.[ch]: added
......
......@@ -341,9 +341,9 @@ plug_in_init (Gimp *gimp,
if (g_path_is_absolute (the_gimp->config->pluginrc_path))
filename = g_strdup (the_gimp->config->pluginrc_path);
else
filename = g_strdup_printf ("%s" G_DIR_SEPARATOR_S "%s",
gimp_directory (),
the_gimp->config->pluginrc_path);
filename = g_build_filename (gimp_directory (),
the_gimp->config->pluginrc_path,
NULL);
}
else
filename = gimp_personal_rc_file ("pluginrc");
......@@ -3638,12 +3638,12 @@ static gchar *
plug_in_search_in_path (gchar *search_path,
gchar *filename)
{
static gchar path[256];
gchar *local_path;
gchar *token;
gchar *next_token;
struct stat buf;
gint err;
gchar *local_path;
gchar *token;
gchar *next_token;
gchar *path;
struct stat buf;
gint err;
local_path = g_strdup (search_path);
next_token = local_path;
......@@ -3651,11 +3651,7 @@ plug_in_search_in_path (gchar *search_path,
while (token)
{
sprintf (path, "%s", token);
if (token[strlen (token) - 1] != G_DIR_SEPARATOR)
strcat (path, G_DIR_SEPARATOR_S);
strcat (path, filename);
path = g_build_filename (token, filename, NULL);
err = stat (path, &buf);
if (!err && S_ISREG (buf.st_mode))
......@@ -3664,6 +3660,8 @@ plug_in_search_in_path (gchar *search_path,
break;
}
g_free (path);
token = strtok (NULL, G_SEARCHPATH_SEPARATOR_S);
}
......
......@@ -55,6 +55,7 @@ static void toast_old_temp_files (void);
void
base_init (void)
{
gchar *swapfile;
gchar *path;
#ifdef HAVE_ASM_MMX
......@@ -68,10 +69,14 @@ base_init (void)
if (base_config->swap_path == NULL)
base_config->swap_path = g_strdup (g_get_tmp_dir ());
path = g_strdup_printf ("%s" G_DIR_SEPARATOR_S "gimpswap.%lu",
base_config->swap_path,
(unsigned long) getpid ());
swapfile = g_strdup_printf ("gimpswap.%lu", (unsigned long) getpid ());
path = g_build_filename (base_config->swap_path, swapfile, NULL);
g_free (swapfile);
tile_swap_add (path, NULL, NULL);
g_free (path);
paint_funcs_setup ();
......@@ -93,7 +98,6 @@ toast_old_temp_files (void)
{
DIR *dir;
struct dirent *entry;
GString *filename = g_string_new ("");
dir = opendir (base_config->swap_path);
......@@ -101,7 +105,7 @@ toast_old_temp_files (void)
return;
while ((entry = readdir (dir)) != NULL)
if (!strncmp (entry->d_name, "gimpswap.", 9))
if (! strncmp (entry->d_name, "gimpswap.", 9))
{
/* don't try to kill swap files of running processes
* yes, I know they might not all be gimp processes, and when you
......@@ -112,20 +116,24 @@ toast_old_temp_files (void)
*/
gint pid = atoi (entry->d_name + 9);
/* On Windows, you can't remove open files anyhow,
* so no harm trying.
*/
#ifndef G_OS_WIN32
if (kill (pid, 0))
#endif
{
/* On Windows, you can't remove open files anyhow,
* so no harm trying.
*/
g_string_printf (filename, "%s" G_DIR_SEPARATOR_S "%s",
base_config->swap_path, entry->d_name);
unlink (filename->str);
gchar *filename;
filename = g_build_filename (base_config->swap_path, entry->d_name,
NULL);
unlink (filename);
g_free (filename);
}
}
closedir (dir);
g_string_free (filename, TRUE);
}
......@@ -1772,8 +1772,7 @@ file_dialog_create (GtkWidget *parent)
G_CALLBACK (file_dialog_cancel_callback),
NULL);
temp = g_strdup_printf ("%s" G_DIR_SEPARATOR_S "curves" G_DIR_SEPARATOR_S,
gimp_directory ());
temp = g_build_filename (gimp_directory (), "curves", NULL);
gtk_file_selection_set_filename (GTK_FILE_SELECTION (file_dlg), temp);
g_free (temp);
......
......@@ -568,13 +568,21 @@ static TempBuf * cached_in_memory = NULL;
static gchar *
generate_unique_filename (void)
{
pid_t pid;
pid_t pid;
gchar *swapfile;
gchar *path;
pid = getpid ();
return g_strdup_printf ("%s" G_DIR_SEPARATOR_S "gimp%d.%d",
base_config->temp_path,
(gint) pid,
swap_index++);
swapfile = g_strdup_printf ("gimp%d.%d",
(gint) pid,
swap_index++);
path = g_build_filename (base_config->temp_path, swapfile, NULL);
g_free (swapfile);
return path;
}
void
......@@ -593,7 +601,9 @@ temp_buf_swap (TempBuf *buf)
buf->swapped = TRUE;
if (base_config->stingy_memory_use)
swap = buf;
{
swap = buf;
}
else
{
swap = cached_in_memory;
......
......@@ -267,6 +267,7 @@ gimp_data_create_filename (GimpData *data,
GList *path;
gchar *dir;
gchar *filename;
gchar *fullpath;
gchar *safe_name;
gint i;
gint unum = 1;
......@@ -290,27 +291,38 @@ gimp_data_create_filename (GimpData *data,
if (safe_name[i] == G_DIR_SEPARATOR || isspace (safe_name[i]))
safe_name[i] = '_';
filename = g_strdup_printf ("%s%s%s",
dir, safe_name,
filename = g_strdup_printf ("%s%s",
safe_name,
gimp_data_get_extension (data));
while ((file = fopen (filename, "r")))
fullpath = g_build_filename (dir, filename, NULL);
g_free (filename);
while ((file = fopen (fullpath, "r")))
{
fclose (file);
g_free (filename);
filename = g_strdup_printf ("%s%s_%d%s",
dir, safe_name, unum,
g_free (fullpath);
filename = g_strdup_printf ("%s_%d%s",
safe_name,
unum,
gimp_data_get_extension (data));
fullpath = g_build_filename (dir, filename, NULL);
g_free (filename);
unum++;
}
g_free (dir);
g_free (safe_name);
gimp_data_set_filename (data, filename);
gimp_data_set_filename (data, fullpath);
g_free (filename);
g_free (fullpath);
}
GimpData *
......
......@@ -171,9 +171,8 @@ gimp_datafiles_read_directories (const gchar *path_str,
continue;
}
filename = g_strdup_printf ("%s%s",
(gchar *) list->data,
dir_ent->d_name);
filename = g_build_filename ((gchar *) list->data,
dir_ent->d_name, NULL);
/* Check the file and see that it is not a sub-directory */
err = stat (filename, &filestat);
......
......@@ -160,9 +160,7 @@ gimp_imagefile_get_new_preview (GimpViewable *viewable,
dirname = g_path_get_dirname (GIMP_OBJECT (imagefile)->name);
basename = g_path_get_basename (GIMP_OBJECT (imagefile)->name);
thumbname = g_strconcat (dirname, G_DIR_SEPARATOR_S,
".xvpics", G_DIR_SEPARATOR_S,
basename, NULL);
thumbname = g_build_filename (dirname, ".xvpics", basename, NULL);
g_free (dirname);
g_free (basename);
......
......@@ -316,10 +316,7 @@ about_dialog_load_logo (GtkWidget *window)
if (logo_pixmap)
return TRUE;
filename = g_strconcat (gimp_data_directory (),
G_DIR_SEPARATOR_S,
"gimp_logo.ppm",
NULL);
filename = g_build_filename (gimp_data_directory (), "gimp_logo.ppm", NULL);
fp = fopen (filename, "rb");
g_free (filename);
......
......@@ -464,12 +464,10 @@ set_preview (const gchar *fullfname,
gboolean thumb_may_be_outdated = FALSE;
gboolean show_generate_label = TRUE;
dirname = g_path_get_dirname (fullfname);
dirname = g_path_get_dirname (fullfname);
basename = g_path_get_basename (fullfname);
tname = g_strconcat (dirname, G_DIR_SEPARATOR_S,
".xvpics", G_DIR_SEPARATOR_S,
basename, NULL);
tname = g_build_filename (dirname, ".xvpics", basename, NULL);
/* If the file is newer than its thumbnail, the thumbnail may
* be out of date.
......@@ -644,13 +642,11 @@ file_open_genbutton_callback (GtkWidget *widget,
gtk_file_selection_set_filename (fs, "");
filedirname = g_strdup (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,
(gchar *) list->data, NULL);
full_filename = g_build_filename (filedirname,
(gchar *) list->data,
NULL);
err = stat (full_filename, &buf);
......@@ -700,8 +696,8 @@ file_open_genbutton_callback (GtkWidget *widget,
{
if (! g_slist_next (list))
{
full_filename = g_strconcat (filedirname, G_DIR_SEPARATOR_S,
(gchar *) list->data, NULL);
full_filename = g_build_filename (filedirname,
(gchar *) list->data, NULL);
gtk_file_selection_set_filename (fs, full_filename);
g_free (full_filename);
}
......@@ -752,7 +748,9 @@ file_open_ok_callback (GtkWidget *widget,
g_free (s);
}
else
gtk_file_selection_set_filename (fs, full_filename);
{
gtk_file_selection_set_filename (fs, full_filename);
}
return;
}
......@@ -798,8 +796,8 @@ file_open_ok_callback (GtkWidget *widget,
{
g_free (full_filename);
full_filename = g_strconcat (filedirname, G_DIR_SEPARATOR_S,
(gchar *) list->data, NULL);
full_filename = g_build_filename (filedirname,
(gchar *) list->data, NULL);
if (strcmp (list->data, raw_filename))
{ /* don't load current selection twice */
......
......@@ -98,6 +98,7 @@ file_save_dialog_menu_init (void)
for (list = save_procs; list; list = g_slist_next (list))
{
gchar *basename;
gchar *filename;
gchar *page;
gchar *lowercase_page;
......@@ -105,12 +106,14 @@ file_save_dialog_menu_init (void)
basename = g_path_get_basename (file_proc->prog);
page = g_strconcat ("filters", G_DIR_SEPARATOR_S,
basename, ".html",
NULL);
filename = g_strconcat (basename, ".html", NULL);
g_free (basename);
page = g_build_filename ("filters", filename, NULL);
g_free (filename);
lowercase_page = g_ascii_strdown (page, -1);
g_free (page);
......@@ -393,7 +396,9 @@ file_save_ok_callback (GtkWidget *widget,
g_free (s);
}
else
gtk_file_selection_set_filename (fs, filename);
{
gtk_file_selection_set_filename (fs, filename);
}
}
else
{
......
......@@ -75,10 +75,8 @@ tips_dialog_create (void)
{
gchar *temp;
temp = g_strdup_printf ("%s" G_DIR_SEPARATOR_S TIPS_DIR_NAME
G_DIR_SEPARATOR_S "%s",
gimp_data_directory (),
_("gimp_tips.txt"));
temp = g_build_filename (gimp_data_directory (), TIPS_DIR_NAME,
_("gimp_tips.txt"), NULL);
read_tips_file (temp);
g_free (temp);
}
......
......@@ -906,19 +906,19 @@ static gboolean
user_install_run (void)
{
FILE *pfp;
gchar buffer[2048];
gchar *filename = NULL;
gchar *command = NULL;
struct stat stat_buf;
gint err;
gboolean executable = TRUE;
/* Generate output */
g_snprintf (buffer, sizeof (buffer), "%s" G_DIR_SEPARATOR_S USER_INSTALL,
gimp_data_directory ());
if ((err = stat (buffer, &stat_buf)) != 0)
filename = g_build_filename (gimp_data_directory (), USER_INSTALL, NULL);
if ((err = stat (filename, &stat_buf)) != 0)
{
gchar *str;
str = g_strdup_printf ("%s\n%s", buffer,
str = g_strdup_printf ("%s\n%s", filename,
_("does not exist. Cannot install."));
add_label (GTK_BOX (log_page), str);
g_free (str);
......@@ -929,8 +929,8 @@ user_install_run (void)
else if (! (S_IXUSR & stat_buf.st_mode) || ! (S_IRUSR & stat_buf.st_mode))
{
gchar *str;
str = g_strdup_printf ("%s\n%s", buffer,
str = g_strdup_printf ("%s\n%s", filename,
_("has invalid permissions. Cannot install."));
add_label (GTK_BOX (log_page), str);
g_free (str);
......@@ -942,13 +942,13 @@ user_install_run (void)
if (executable)
{
#ifdef G_OS_WIN32
char *quoted_data_dir, *quoted_user_dir, *quoted_sysconf_dir;
gchar *quoted_data_dir, *quoted_user_dir, *quoted_sysconf_dir;
/* On Windows, it is common for the GIMP data directory
* to have spaces in it ("c:\Program Files\GIMP"). Put spaces in quotes.
*/
quoted_data_dir = quote_spaces (gimp_data_directory ());
quoted_user_dir = quote_spaces (gimp_directory ());
quoted_data_dir = quote_spaces (gimp_data_directory ());
quoted_user_dir = quote_spaces (gimp_directory ());
quoted_sysconf_dir = quote_spaces (gimp_sysconf_directory ());
/* The Microsoft _popen doesn't work in Windows applications, sigh.
......@@ -959,49 +959,64 @@ user_install_run (void)
*/
AllocConsole ();
g_snprintf (buffer, sizeof(buffer), "%s" G_DIR_SEPARATOR_S USER_INSTALL " %s %s %s",
quoted_data_dir, quoted_data_dir,
quoted_user_dir, quoted_sysconf_dir);
if (system (buffer) == -1)
executable = FALSE;
g_free (filename);
filename = g_build_filename (quoted_data_dir, USER_INSTALL, NULL);
command = g_strdup_printf ("%s %s %s %s",
fn,
quoted_data_dir,
quoted_user_dir,
quoted_sysconf_dir);
g_free (quoted_data_dir);
g_free (quoted_user_dir);
g_free (quoted_sysconf_dir);
if (system (command) == -1)
executable = FALSE;
if (executable)
add_label (GTK_BOX (log_page),
_("Did you notice any error messages in the console window?\n"
"If not, installation was successful!\n"
"Otherwise, quit and investigate the possible reason..."));
#else
#ifndef __EMX__
g_snprintf (buffer, sizeof(buffer), "%s" G_DIR_SEPARATOR_S USER_INSTALL " %s %s %s %s",
gimp_data_directory (),
"2>&1",
gimp_data_directory(), gimp_directory (), gimp_sysconf_directory());
#else
g_snprintf (buffer, sizeof(buffer), "cmd.exe /c %s" G_DIR_SEPARATOR_S USER_INSTALL " %s %s %s",
gimp_data_directory (), gimp_data_directory(),
gimp_directory (), gimp_sysconf_directory());
#ifdef __EMX__
command = g_strdup_printf ("cmd.exe /c %s %s %s %s",
filename,
gimp_data_directory (),
gimp_directory (),
gimp_sysconf_directory());
{
char *s = buffer + 10;
gchar *s = buffer + 11;
while (*s)
{
if (*s == '/') *s = '\\';
s++;
}
}
#else
command = g_strdup_printf ("%s 2>&1 %s %s %s",
filename,
gimp_data_directory (),
gimp_directory (),
gimp_sysconf_directory ());
#endif
g_free (filename);
/* urk - should really use something better than popen(), since
* we can't tell if the installation script failed --austin
*/
if ((pfp = popen (buffer, "r")) != NULL)
if ((pfp = popen (command, "r")) != NULL)
{
GtkWidget *scrolled_window;
GtkWidget *log_view;
GtkTextBuffer *log_buffer;
static gchar buffer[2048];
scrolled_window = gtk_scrolled_window_new (NULL, NULL);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
......@@ -1031,10 +1046,14 @@ user_install_run (void)
"Otherwise, quit and investigate the possible reason..."));
}
else
executable = FALSE;
{
executable = FALSE;
}
#endif /* !G_OS_WIN32 */
}
g_free (command);
if (executable)
{
g_object_set_data (G_OBJECT (log_page), "footer",
......
......@@ -203,7 +203,7 @@ file_open_absolute_filename (const gchar *name)
return g_strdup (name);
current = g_get_current_dir ();
absolute = g_strconcat (current, G_DIR_SEPARATOR_S, name, NULL);
absolute = g_build_filename (current, name, NULL);
g_free (current);
return absolute;
......
......@@ -551,12 +551,8 @@ file_save_thumbnail (GimpImage *gimage,
pathname = g_path_get_dirname (full_source_filename);
filename = g_path_get_basename (full_source_filename);
xvpathname = g_strconcat (pathname, G_DIR_SEPARATOR_S, ".xvpics",
NULL);
thumbnailname = g_strconcat (xvpathname, G_DIR_SEPARATOR_S,
filename,
NULL);
xvpathname = g_build_filename (pathname, ".xvpics", NULL);
thumbnailname = g_build_filename (xvpathname, filename, NULL);
tbd = temp_buf_data (tempbuf);
......
......@@ -203,7 +203,7 @@ file_open_absolute_filename (const gchar *name)
return g_strdup (name);
current = g_get_current_dir ();
absolute = g_strconcat (current, G_DIR_SEPARATOR_S, name, NULL);
absolute = g_build_filename (current, name, NULL);
g_free (current);
return absolute;
......
......@@ -551,12 +551,8 @@ file_save_thumbnail (GimpImage *gimage,
pathname = g_path_get_dirname (full_source_filename);
filename = g_path_get_basename (full_source_filename);
xvpathname = g_strconcat (pathname, G_DIR_SEPARATOR_S, ".xvpics",
NULL);
thumbnailname = g_strconcat (xvpathname, G_DIR_SEPARATOR_S,