Commit add9089f authored by Marc Lehmann's avatar Marc Lehmann

*** empty log message ***

parent 7c946f47
Sun Apr 11 23:35:31 CEST 1999 Marc Lehmann <pcg@goof.com>
* app/general.c: save string token length into "token_int".
Fixed parsing of escape sequences, added '\0' and '"' sequences.
* app/gimprc.c: implement new type "parasite".
* app/gimpparasite.c: load and save parasiterc in "semi-ascii".
* libgimp/parasite.[ch]: new function parasite_flags.
Sat Apr 10 23:33:26 PDT 1999 Manish Singh <yosh@gimp.org>
* app/color_picker.c: added a sample average feature (requested
......
......@@ -20,8 +20,10 @@
#include <unistd.h>
#include "parasitelist.h"
#include "gimpparasite.h"
#include "gimprc.h"
#include "libgimp/parasite.h"
#include "libgimp/gimpenv.h"
#include "libgimp/gimpintl.h"
static ParasiteList *parasites = NULL;
......@@ -69,40 +71,68 @@ gimp_parasite_list (gint *count)
return list;
}
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);
}
}
void
gimp_parasiterc_save()
{
int i;
char *filename;
FILE *fp;
guint32 version = 1;
if (!(fp = fopen(gimp_personal_rc_file ("#parasiterc.tmp"), "w")))
filename = gimp_personal_rc_file ("#parasiterc.tmp~");
fp = fopen (filename, "w");
g_free (filename);
if (!fp)
return;
version = GINT32_TO_BE(version);
fwrite(&version, 4, 1, fp);
parasite_list_save(parasites, fp);
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);
fclose(fp);
if (rename(gimp_personal_rc_file ("#parasiterc.tmp"),
fclose (fp);
if (rename(gimp_personal_rc_file ("#parasiterc.tmp~"),
gimp_personal_rc_file("parasiterc")) != 0)
unlink(gimp_personal_rc_file ("#parasiterc.tmp"));
unlink(gimp_personal_rc_file ("#parasiterc.tmp~"));
}
void
gimp_parasiterc_load()
{
FILE *fp;
guint32 version;
if (!(fp = fopen(gimp_personal_rc_file ("parasiterc"), "r")))
return;
fread(&version, 4, 1, fp);
version = GINT32_FROM_BE(version);
if (version != 1)
{
fclose(fp);
return;
}
parasite_list_load(parasites, fp);
char *filename;
fclose(fp);
filename = gimp_personal_rc_file ("parasiterc");
app_init_update_status(NULL, filename, -1);
parse_gimprc_file (filename);
g_free (filename);
}
......@@ -20,8 +20,10 @@
#include <unistd.h>
#include "parasitelist.h"
#include "gimpparasite.h"
#include "gimprc.h"
#include "libgimp/parasite.h"
#include "libgimp/gimpenv.h"
#include "libgimp/gimpintl.h"
static ParasiteList *parasites = NULL;
......@@ -69,40 +71,68 @@ gimp_parasite_list (gint *count)
return list;
}
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);
}
}
void
gimp_parasiterc_save()
{
int i;
char *filename;
FILE *fp;
guint32 version = 1;
if (!(fp = fopen(gimp_personal_rc_file ("#parasiterc.tmp"), "w")))
filename = gimp_personal_rc_file ("#parasiterc.tmp~");
fp = fopen (filename, "w");
g_free (filename);
if (!fp)
return;
version = GINT32_TO_BE(version);
fwrite(&version, 4, 1, fp);
parasite_list_save(parasites, fp);
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);
fclose(fp);
if (rename(gimp_personal_rc_file ("#parasiterc.tmp"),
fclose (fp);
if (rename(gimp_personal_rc_file ("#parasiterc.tmp~"),
gimp_personal_rc_file("parasiterc")) != 0)
unlink(gimp_personal_rc_file ("#parasiterc.tmp"));
unlink(gimp_personal_rc_file ("#parasiterc.tmp~"));
}
void
gimp_parasiterc_load()
{
FILE *fp;
guint32 version;
if (!(fp = fopen(gimp_personal_rc_file ("parasiterc"), "r")))
return;
fread(&version, 4, 1, fp);
version = GINT32_FROM_BE(version);
if (version != 1)
{
fclose(fp);
return;
}
parasite_list_load(parasites, fp);
char *filename;
fclose(fp);
filename = gimp_personal_rc_file ("parasiterc");
app_init_update_status(NULL, filename, -1);
parse_gimprc_file (filename);
g_free (filename);
}
......@@ -197,15 +197,19 @@ get_token (ParseInfo *info)
}
else if (slashed || (buffer[info->position] != '"'))
{
slashed = FALSE;
if (slashed && buffer[info->position] == 'n')
tokenbuf[tokenpos++] = '\n';
else if (slashed && buffer[info->position] == 'r')
tokenbuf[tokenpos++] = '\r';
else if (slashed && buffer[info->position] == 'z') /* ^Z */
tokenbuf[tokenpos++] = '\032';
else if (slashed && buffer[info->position] == '0') /* \0 */
tokenbuf[tokenpos++] = '\0';
else if (slashed && buffer[info->position] == '"')
tokenbuf[tokenpos++] = '"';
else
tokenbuf[tokenpos++] = buffer[info->position];
tokenbuf[tokenpos++] = buffer[info->position];
slashed = FALSE;
info->position += 1;
}
else
......@@ -213,6 +217,7 @@ get_token (ParseInfo *info)
tokenbuf[tokenpos] = '\0';
token_str = tokenbuf;
token_sym = tokenbuf;
token_int = tokenpos;
info->position += 1;
return TOKEN_STRING;
}
......
......@@ -20,8 +20,10 @@
#include <unistd.h>
#include "parasitelist.h"
#include "gimpparasite.h"
#include "gimprc.h"
#include "libgimp/parasite.h"
#include "libgimp/gimpenv.h"
#include "libgimp/gimpintl.h"
static ParasiteList *parasites = NULL;
......@@ -69,40 +71,68 @@ gimp_parasite_list (gint *count)
return list;
}
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);
}
}
void
gimp_parasiterc_save()
{
int i;
char *filename;
FILE *fp;
guint32 version = 1;
if (!(fp = fopen(gimp_personal_rc_file ("#parasiterc.tmp"), "w")))
filename = gimp_personal_rc_file ("#parasiterc.tmp~");
fp = fopen (filename, "w");
g_free (filename);
if (!fp)
return;
version = GINT32_TO_BE(version);
fwrite(&version, 4, 1, fp);
parasite_list_save(parasites, fp);
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);
fclose(fp);
if (rename(gimp_personal_rc_file ("#parasiterc.tmp"),
fclose (fp);
if (rename(gimp_personal_rc_file ("#parasiterc.tmp~"),
gimp_personal_rc_file("parasiterc")) != 0)
unlink(gimp_personal_rc_file ("#parasiterc.tmp"));
unlink(gimp_personal_rc_file ("#parasiterc.tmp~"));
}
void
gimp_parasiterc_load()
{
FILE *fp;
guint32 version;
if (!(fp = fopen(gimp_personal_rc_file ("parasiterc"), "r")))
return;
fread(&version, 4, 1, fp);
version = GINT32_FROM_BE(version);
if (version != 1)
{
fclose(fp);
return;
}
parasite_list_load(parasites, fp);
char *filename;
fclose(fp);
filename = gimp_personal_rc_file ("parasiterc");
app_init_update_status(NULL, filename, -1);
parse_gimprc_file (filename);
g_free (filename);
}
......@@ -44,7 +44,9 @@
#include "gimage.h"
#include "session.h"
#include "tools.h"
#include "gimpparasite.h"
#include "libgimp/parasite.h"
#include "libgimp/gimpintl.h"
#include "libgimp/gimpenv.h"
......@@ -70,7 +72,8 @@ typedef enum {
TT_XMENUPATH,
TT_XDEVICE,
TT_XSESSIONINFO,
TT_XUNITINFO
TT_XUNITINFO,
TT_XPARASITE
} TokenType;
typedef struct _ParseFunc ParseFunc;
......@@ -167,6 +170,7 @@ static int parse_device (gpointer val1p, gpointer val2p);
static int parse_menu_path (gpointer val1p, gpointer val2p);
static int parse_session_info (gpointer val1p, gpointer val2p);
static int parse_unit_info (gpointer val1p, gpointer val2p);
static int parse_parasite (gpointer val1p, gpointer val2p);
static int parse_proc_def (PlugInProcDef **proc_def);
static int parse_proc_arg (ProcArg *arg);
......@@ -275,6 +279,7 @@ static ParseFunc funcs[] =
{ "monitor-yresolution", TT_FLOAT, &monitor_yres, NULL },
{ "num-processors", TT_INT, &num_processors, NULL },
{ "image-title-format", TT_STRING, &image_title_format, NULL },
{ "parasite", TT_XPARASITE, NULL, NULL },
};
static int nfuncs = sizeof (funcs) / sizeof (funcs[0]);
......@@ -619,6 +624,8 @@ parse_statement ()
return parse_session_info (funcs[i].val1p, funcs[i].val2p);
case TT_XUNITINFO:
return parse_unit_info (funcs[i].val1p, funcs[i].val2p);
case TT_XPARASITE:
return parse_parasite (funcs[i].val1p, funcs[i].val2p);
}
return parse_unknown (token_sym);
......@@ -2010,6 +2017,44 @@ parse_unit_info (gpointer val1p,
return ERROR;
}
static int
parse_parasite (gpointer val1p,
gpointer val2p)
{
int token;
int res = ERROR;
gchar *identifier = NULL;
gulong flags = 0;
token = get_next_token ();
if (token != TOKEN_STRING)
goto error;
identifier = g_strdup (token_str);
token = get_next_token ();
/* possible future extension: allow flags as symbolic strings. */
if (token == TOKEN_NUMBER)
flags |= token_int;
token = get_next_token ();
if (token != TOKEN_STRING)
goto error;
gimp_attach_parasite (parasite_new (identifier, flags, token_int, token_str));
token = get_next_token ();
if (token != TOKEN_RIGHT_PAREN)
goto error;
res = OK;
error:
g_free (identifier);
return res;
}
static int
parse_unknown (char *token_sym)
{
......@@ -2102,6 +2147,7 @@ value_to_str (char *name)
case TT_XDEVICE:
case TT_XSESSIONINFO:
case TT_XUNITINFO:
case TT_XPARASITE:
return NULL;
}
return NULL;
......
......@@ -177,6 +177,14 @@ parasite_compare (const Parasite *a, const Parasite *b)
return FALSE;
}
gulong
parasite_flags(const Parasite *p)
{
if (p == NULL)
return 0;
return p->flags;
}
int
parasite_is_persistent(const Parasite *p)
{
......
......@@ -50,6 +50,7 @@ int parasite_is_type (const Parasite *parasite,
const char *name);
int parasite_is_persistent (const Parasite *p);
int parasite_has_flag (const Parasite *p, gulong flag);
gulong parasite_flags (const Parasite *p);
const char *parasite_name (const Parasite *p);
void *parasite_data (const Parasite *p);
long parasite_data_size (const Parasite *p);
......
......@@ -177,6 +177,14 @@ parasite_compare (const Parasite *a, const Parasite *b)
return FALSE;
}
gulong
parasite_flags(const Parasite *p)
{
if (p == NULL)
return 0;
return p->flags;
}
int
parasite_is_persistent(const Parasite *p)
{
......
......@@ -50,6 +50,7 @@ int parasite_is_type (const Parasite *parasite,
const char *name);
int parasite_is_persistent (const Parasite *p);
int parasite_has_flag (const Parasite *p, gulong flag);
gulong parasite_flags (const Parasite *p);
const char *parasite_name (const Parasite *p);
void *parasite_data (const Parasite *p);
long parasite_data_size (const Parasite *p);
......
......@@ -177,6 +177,14 @@ parasite_compare (const Parasite *a, const Parasite *b)
return FALSE;
}
gulong
parasite_flags(const Parasite *p)
{
if (p == NULL)
return 0;
return p->flags;
}
int
parasite_is_persistent(const Parasite *p)
{
......
......@@ -50,6 +50,7 @@ int parasite_is_type (const Parasite *parasite,
const char *name);
int parasite_is_persistent (const Parasite *p);
int parasite_has_flag (const Parasite *p, gulong flag);
gulong parasite_flags (const Parasite *p);
const char *parasite_name (const Parasite *p);
void *parasite_data (const Parasite *p);
long parasite_data_size (const Parasite *p);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment