moved the new string escape function here and also it for the

2007-10-11  Sven Neumann  <sven@gimp.org>

	* plug-ins/script-fu/script-fu-scripts.[ch]: moved the new string
	escape function here and also it for the non-interactive case.

	* plug-ins/script-fu/script-fu-interface.c: changed accordingly.

svn path=/trunk/; revision=23802
This commit is contained in:
Sven Neumann 2007-10-11 11:59:55 +00:00 committed by Sven Neumann
parent 426eb27e7e
commit 66fecb60e6
4 changed files with 67 additions and 77 deletions

View file

@ -1,3 +1,10 @@
2007-10-11 Sven Neumann <sven@gimp.org>
* plug-ins/script-fu/script-fu-scripts.[ch]: moved the new string
escape function here and also it for the non-interactive case.
* plug-ins/script-fu/script-fu-interface.c: changed accordingly.
2007-10-11 Sven Neumann <sven@gimp.org>
* plug-ins/script-fu/script-fu-interface.c: don't use

View file

@ -103,8 +103,6 @@ static void script_fu_brush_callback (gpointer data,
const guchar *mask_data,
gboolean closing);
static gchar * script_fu_strescape (const gchar *source);
/*
* Local variables
@ -1012,67 +1010,3 @@ script_fu_reset (SFScript *script)
}
}
}
/*
* Escapes the special characters '\b', '\f', '\n', '\r', '\t', '\' and '"'
* in the string source by inserting a '\' before them.
*/
static gchar *
script_fu_strescape (const gchar *source)
{
const guchar *p;
gchar *dest;
gchar *q;
g_return_val_if_fail (source != NULL, NULL);
p = (const guchar *) source;
/* Each source byte needs maximally two destination chars */
q = dest = g_malloc (strlen (source) * 2 + 1);
while (*p)
{
switch (*p)
{
case '\b':
*q++ = '\\';
*q++ = 'b';
break;
case '\f':
*q++ = '\\';
*q++ = 'f';
break;
case '\n':
*q++ = '\\';
*q++ = 'n';
break;
case '\r':
*q++ = '\\';
*q++ = 'r';
break;
case '\t':
*q++ = '\\';
*q++ = 't';
break;
case '\\':
*q++ = '\\';
*q++ = '\\';
break;
case '"':
*q++ = '\\';
*q++ = '"';
break;
default:
*q++ = *p;
break;
}
p++;
}
*q = 0;
return dest;
}

View file

@ -668,8 +668,8 @@ script_fu_load_script (const GimpDatafileData *file_data,
{
if (gimp_datafiles_check_extension (file_data->filename, ".scm"))
{
gchar *command;
gchar *escaped = g_strescape (file_data->filename, NULL);
gchar *command;
gchar *escaped = script_fu_strescape (file_data->filename);
GString *output;
command = g_strdup_printf ("(load \"%s\")", escaped);
@ -968,8 +968,9 @@ script_fu_script_proc (const gchar *name,
case SF_FILENAME:
case SF_DIRNAME:
{
gchar *tmp = g_strescape (param->data.d_string, NULL);
gchar *tmp;
tmp = script_fu_strescape (param->data.d_string);
g_string_append_printf (s, "\"%s\"", tmp);
g_free (tmp);
}
@ -1067,8 +1068,9 @@ script_fu_script_proc (const gchar *name,
case SF_STRING:
case SF_TEXT:
{
gchar *tmp = g_strescape (arg_value->sfa_value, NULL);
gchar *tmp;
tmp = script_fu_strescape (arg_value->sfa_value);
g_string_append_printf (s, "\"%s\"", tmp);
g_free (tmp);
}
@ -1087,9 +1089,9 @@ script_fu_script_proc (const gchar *name,
case SF_FILENAME:
case SF_DIRNAME:
{
gchar *tmp = g_strescape (arg_value->sfa_file.filename,
NULL);
gchar *tmp;
tmp = script_fu_strescape (arg_value->sfa_file.filename);
g_string_append_printf (s, "\"%s\"", tmp);
g_free (tmp);
}
@ -1358,3 +1360,47 @@ script_fu_menu_compare (gconstpointer a,
return retval;
}
/*
* Escapes the special characters '\b', '\f', '\n', '\r', '\t', '\' and '"'
* in the string source by inserting a '\' before them.
*/
gchar *
script_fu_strescape (const gchar *source)
{
const guchar *p;
gchar *dest;
gchar *q;
g_return_val_if_fail (source != NULL, NULL);
p = (const guchar *) source;
/* Each source byte needs maximally two destination chars */
q = dest = g_malloc (strlen (source) * 2 + 1);
while (*p)
{
switch (*p)
{
case '\b':
case '\f':
case '\n':
case '\r':
case '\t':
case '\\':
case '"':
*q++ = '\\';
/* fallthrough */
default:
*q++ = *p;
break;
}
p++;
}
*q = 0;
return dest;
}

View file

@ -19,10 +19,13 @@
#ifndef __SCRIPT_FU_SCRIPTS_H__
#define __SCRIPT_FU_SCRIPTS_H__
void script_fu_find_scripts (const gchar *path);
pointer script_fu_add_script (scheme *sc, pointer a);
pointer script_fu_add_menu (scheme *sc, pointer a);
void script_fu_error_msg (const gchar *command,
const gchar *msg);
void script_fu_find_scripts (const gchar *path);
pointer script_fu_add_script (scheme *sc, pointer a);
pointer script_fu_add_menu (scheme *sc, pointer a);
void script_fu_error_msg (const gchar *command,
const gchar *msg);
gchar * script_fu_strescape (const gchar *source);
#endif /* __SCRIPT_FU_SCRIPTS__ */