gimp/app/gimpparasite.c
Michael Natterer 7d1375e949 Makefile.am configure.in added new directory libgimpbase/
2001-05-21  Michael Natterer  <mitch@gimp.org>

	* Makefile.am
	* configure.in
	* gimptool-1.4.in: added new directory libgimpbase/

	* app/Makefile.am: link against the new lib.

	* app/appenums.h: removed the PDB enums which are in
	libgimpbase/gimpbasetypes.h now. They are all "Gimp" prefixed.

	* app/apptypes.h: #include "libgimpbase/gimpbasetypes.h"

	* app/[lots]
	* app/core/[of]
	* app/gui/[files]
	* app/tools/: changed includes and all PDB types.

	* app/pdb/*: regenerated.

	* libgimp/Makefile.am: don't build libgimpi.a uglyness any more.

	* libgimp/gimpenv.[ch]
	* libgimp/gimplimits.[hh]
	* libgimp/gimpparasite.[ch]
	* libgimp/gimpparasiteio.[ch]
	* libgimp/gimpprotocol.[ch]
	* libgimp/gimpsignal.[ch]
	* libgimp/gimpunit.h
	* libgimp/gimputils.[ch]
	* libgimp/gimpwire.[ch]: removed...

	* libgimpbase/*: ...and added here as new library.

	* libgimp/gimp.[ch]
	* libgimp/gimpdrawable.[ch]
	* libgimp/gimpenums.h
	* libgimp/gimpimage.[ch]
	* libgimp/gimptile.c
	* libgimp/gimptypes.h
	* libgimp/gimpunit.c: changed accordingly. Added the
	gimp_*_add_new_parasite to gimp.[ch], gimpdrawable.[ch] and
	gimpimage.[ch].

	* libgimpwidgets/gimppatheditor.c
	* libgimpwidgets/gimpquerybox.c
	* libgimpwidgets/gimpsizeentry.c
	* libgimpwidgets/gimpunitmenu.c
	* libgimpwidgets/gimpwidgets.c
	* libgimpwidgets/gimpwidgetstypes.h: changed includes accordingly.

	* plug-ins/*/Makefile.am
	* plug-ins/common/mkgen.pl: link against libgimpbase.

	* tools/pdbgen/Makefile.am: scan libgimpbase/gimpbasetypes.h, so
	the enums are known to pdbgen...

	* tools/pdbgen/enumcode.pl: ...but don't write them out to
	libgimp/gimpenums.h

	* tools/pdbgen/app.pl: include libgimp/gimpbase.h in all *_cmds.c
	files. Added GIMP_ to the type names ganerated in app/.

	* tools/pdbgen/enums.pl: regenerated.

	* tools/pdbgen/pdb.pl
	* tools/pdbgen/pdb/fileops.pdb
	* tools/pdbgen/pdb/procedural_db.pdb
	* tools/pdbgen/pdb/unit.pdb: changed includes.
2001-05-21 13:58:46 +00:00

185 lines
4.3 KiB
C

/* gimpparasite.c: Copyright 1998 Jay Cox <jaycox@earthlink.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "config.h"
#include <gtk/gtk.h>
#include <stdio.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#include "libgimpbase/gimpbase.h"
#include "core/core-types.h"
#include "app_procs.h"
#include "parasitelist.h"
#include "gimpparasite.h"
#include "gimprc.h"
static ParasiteList *parasites = NULL;
void
gimp_init_parasites (void)
{
g_return_if_fail (parasites == NULL);
parasites = parasite_list_new ();
gimp_parasiterc_load ();
}
void
gimp_parasite_attach (GimpParasite *p)
{
parasite_list_add (parasites, p);
}
void
gimp_parasite_detach (const gchar *name)
{
parasite_list_remove (parasites, name);
}
GimpParasite *
gimp_parasite_find (const gchar *name)
{
return parasite_list_find (parasites, name);
}
static void
list_func (gchar *key,
GimpParasite *p,
gchar ***cur)
{
*(*cur)++ = (char *) g_strdup (key);
}
gchar **
gimp_parasite_list (gint *count)
{
gchar **list;
gchar **cur;
*count = parasite_list_length (parasites);
cur = list = g_new (gchar *, *count);
parasite_list_foreach (parasites, (GHFunc) list_func, &cur);
return list;
}
static void
save_func (gchar *key,
GimpParasite *p,
FILE *fp)
{
if (gimp_parasite_is_persistent (p))
{
gchar *s;
guint32 l;
fprintf (fp, "(parasite \"%s\" %lu \"",
gimp_parasite_name (p), gimp_parasite_flags (p));
/*
* the current methodology is: never move the parasiterc from one
* system to another. If you want to do this you should probably
* write out parasites which contain any non-alphanumeric(+some)
* characters as \xHH sequences altogether.
*/
for (s = (gchar *) gimp_parasite_data (p), l = gimp_parasite_data_size (p);
l;
l--, s++)
{
switch (*s)
{
case '\\': fputs ("\\\\", fp); break;
case '\0': fputs ("\\0", fp); break;
case '"' : fputs ("\\\"", fp); break;
/* disabled, not portable! */
/* case '\n': fputs ("\\n", fp); break;*/
/* case '\r': fputs ("\\r", fp); break;*/
case 26 : fputs ("\\z", fp); break;
default : fputc (*s, fp); break;
}
}
fputs ("\")\n\n", fp);
}
}
void
gimp_parasiterc_save (void)
{
gchar *tmp_filename = NULL;
gchar *bak_filename = NULL;
gchar *rc_filename = NULL;
FILE *fp;
tmp_filename = gimp_personal_rc_file ("#parasiterc.tmp~");
bak_filename = gimp_personal_rc_file ("parasiterc.bak");
rc_filename = gimp_personal_rc_file ("parasiterc");
fp = fopen (tmp_filename, "w");
if (!fp)
goto cleanup;
fprintf (fp,
"# GIMP parasiterc\n"
"# This file will be entirely rewritten every time you "
"quit the gimp.\n\n");
parasite_list_foreach (parasites, (GHFunc)save_func, fp);
fclose (fp);
#if defined(G_OS_WIN32) || defined(__EMX__)
/* First rename the old parasiterc out of the way */
unlink (bak_filename);
rename (rc_filename, bak_filename);
#endif
if (rename (tmp_filename, rc_filename) != 0)
{
#if defined(G_OS_WIN32) || defined(__EMX__)
/* Rename the old parasiterc back */
rename (bak_filename, rc_filename);
#endif
unlink (tmp_filename);
}
cleanup:
g_free (tmp_filename);
g_free (bak_filename);
g_free (rc_filename);
}
void
gimp_parasiterc_load (void)
{
gchar *filename;
filename = gimp_personal_rc_file ("parasiterc");
app_init_update_status (NULL, filename, -1);
parse_gimprc_file (filename);
g_free (filename);
}