1998-10-30 18:21:33 +08:00
|
|
|
/* 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 <glib.h>
|
1999-04-09 14:00:11 +08:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
1998-10-30 18:21:33 +08:00
|
|
|
#include "parasitelist.h"
|
|
|
|
#include "gimpparasite.h"
|
1999-04-12 06:28:51 +08:00
|
|
|
#include "gimprc.h"
|
1999-04-09 14:00:11 +08:00
|
|
|
#include "libgimp/parasite.h"
|
|
|
|
#include "libgimp/gimpenv.h"
|
1999-04-12 06:28:51 +08:00
|
|
|
#include "libgimp/gimpintl.h"
|
1998-10-30 18:21:33 +08:00
|
|
|
|
|
|
|
static ParasiteList *parasites = NULL;
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_init_parasites()
|
|
|
|
{
|
|
|
|
g_return_if_fail(parasites == NULL);
|
|
|
|
parasites = parasite_list_new();
|
1999-04-09 14:00:11 +08:00
|
|
|
gimp_parasiterc_load();
|
1998-10-30 18:21:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_attach_parasite (Parasite *p)
|
|
|
|
{
|
|
|
|
parasite_list_add(parasites, p);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1999-04-23 14:07:09 +08:00
|
|
|
gimp_detach_parasite (const char *name)
|
1998-10-30 18:21:33 +08:00
|
|
|
{
|
|
|
|
parasite_list_remove(parasites, name);
|
|
|
|
}
|
|
|
|
|
|
|
|
Parasite *
|
1999-04-23 14:07:09 +08:00
|
|
|
gimp_find_parasite (const char *name)
|
1998-10-30 18:21:33 +08:00
|
|
|
{
|
|
|
|
return parasite_list_find(parasites, name);
|
|
|
|
}
|
|
|
|
|
1999-02-14 02:19:44 +08:00
|
|
|
static void list_func(char *key, Parasite *p, char ***cur)
|
|
|
|
{
|
|
|
|
*(*cur)++ = (char *) g_strdup (key);
|
|
|
|
}
|
|
|
|
|
|
|
|
char **
|
|
|
|
gimp_parasite_list (gint *count)
|
|
|
|
{
|
|
|
|
char **list, **cur;
|
|
|
|
|
|
|
|
*count = parasite_list_length (parasites);
|
|
|
|
cur = list = (char **) g_malloc (sizeof (char *) * *count);
|
|
|
|
|
|
|
|
parasite_list_foreach (parasites, (GHFunc)list_func, &cur);
|
|
|
|
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
1999-04-12 06:28:51 +08:00
|
|
|
static void save_func(char *key, Parasite *p, FILE *fp)
|
|
|
|
{
|
|
|
|
if (parasite_is_persistent (p))
|
|
|
|
{
|
|
|
|
gchar *s;
|
|
|
|
guint32 l;
|
|
|
|
|
|
|
|
fprintf (fp, "(parasite \"%s\" %lu \"", parasite_name (p), parasite_flags (p));
|
|
|
|
|
|
|
|
for (s = (gchar *)parasite_data (p), l = parasite_data_size (p);
|
|
|
|
l;
|
|
|
|
l--, s++)
|
|
|
|
{
|
|
|
|
switch (*s)
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-04-09 14:00:11 +08:00
|
|
|
void
|
|
|
|
gimp_parasiterc_save()
|
|
|
|
{
|
1999-04-12 06:28:51 +08:00
|
|
|
int i;
|
|
|
|
char *filename;
|
1999-04-09 14:00:11 +08:00
|
|
|
FILE *fp;
|
1999-04-12 06:28:51 +08:00
|
|
|
|
|
|
|
filename = gimp_personal_rc_file ("#parasiterc.tmp~");
|
|
|
|
|
|
|
|
fp = fopen (filename, "w");
|
|
|
|
g_free (filename);
|
|
|
|
if (!fp)
|
1999-04-09 14:00:11 +08:00
|
|
|
return;
|
1998-10-30 18:21:33 +08:00
|
|
|
|
1999-04-12 06:28:51 +08:00
|
|
|
fprintf (fp, _("# GIMP parasiterc\n"));
|
|
|
|
fprintf (fp, _("# This file will be entirely rewritten every time you quit the gimp.\n\n"));
|
|
|
|
|
|
|
|
parasite_list_foreach (parasites, (GHFunc)save_func, fp);
|
1998-10-30 18:21:33 +08:00
|
|
|
|
1999-04-12 06:28:51 +08:00
|
|
|
fclose (fp);
|
|
|
|
|
|
|
|
if (rename(gimp_personal_rc_file ("#parasiterc.tmp~"),
|
1999-04-09 14:00:11 +08:00
|
|
|
gimp_personal_rc_file("parasiterc")) != 0)
|
1999-04-12 06:28:51 +08:00
|
|
|
unlink(gimp_personal_rc_file ("#parasiterc.tmp~"));
|
1999-04-09 14:00:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_parasiterc_load()
|
|
|
|
{
|
1999-04-12 06:28:51 +08:00
|
|
|
char *filename;
|
1999-04-09 14:00:11 +08:00
|
|
|
|
1999-04-12 06:28:51 +08:00
|
|
|
filename = gimp_personal_rc_file ("parasiterc");
|
|
|
|
app_init_update_status(NULL, filename, -1);
|
|
|
|
parse_gimprc_file (filename);
|
|
|
|
g_free (filename);
|
1999-04-09 14:00:11 +08:00
|
|
|
}
|