hardcode the built-in units. Dynamically constructing the constants using

2007-06-20  Sven Neumann  <sven@gimp.org>

	* plug-ins/script-fu/scheme-wrapper.c (init_constants): hardcode
	the built-in units. Dynamically constructing the constants using
	gimp_unit_get_singular() doesn't work because it returns a
	translated string.

svn path=/trunk/; revision=22804
This commit is contained in:
Sven Neumann
2007-06-20 10:54:28 +00:00
committed by Sven Neumann
parent c622b604d7
commit 1140960d35
2 changed files with 49 additions and 50 deletions

View File

@ -1,3 +1,10 @@
2007-06-20 Sven Neumann <sven@gimp.org>
* plug-ins/script-fu/scheme-wrapper.c (init_constants): hardcode
the built-in units. Dynamically constructing the constants using
gimp_unit_get_singular() doesn't work because it returns a
translated string.
2007-06-20 Sven Neumann <sven@gimp.org> 2007-06-20 Sven Neumann <sven@gimp.org>
* plug-ins/script-fu/script-fu-console.c (script_fu_cc_key_function): * plug-ins/script-fu/script-fu-console.c (script_fu_cc_key_function):

View File

@ -51,10 +51,10 @@ static int ts_console_mode;
#undef cons #undef cons
struct struct named_constant
named_constant { {
const char *name; const gchar *name;
int value; gint value;
}; };
struct named_constant const script_constants[] = struct named_constant const script_constants[] =
@ -69,6 +69,13 @@ struct named_constant const script_constants[] =
{ "TRUE", TRUE }, { "TRUE", TRUE },
{ "FALSE", FALSE }, { "FALSE", FALSE },
/* Builtin units */
{ "UNIT-PIXEL", GIMP_UNIT_PIXEL },
{ "UNIT-INCH", GIMP_UNIT_INCH },
{ "UNIT-MM", GIMP_UNIT_MM },
{ "UNIT-POINT", GIMP_UNIT_POINT },
{ "UNIT-PICA", GIMP_UNIT_PICA },
/* Script-Fu types */ /* Script-Fu types */
{ "SF-IMAGE", SF_IMAGE }, { "SF-IMAGE", SF_IMAGE },
{ "SF-DRAWABLE", SF_DRAWABLE }, { "SF-DRAWABLE", SF_DRAWABLE },
@ -220,15 +227,15 @@ ts_print_welcome (void)
void void
ts_interpret_stdin (void) ts_interpret_stdin (void)
{ {
scheme_load_file(&sc, stdin); scheme_load_file (&sc, stdin);
} }
gint gint
ts_interpret_string (const gchar *expr) ts_interpret_string (const gchar *expr)
{ {
port *pt=sc.outport->_object._port; port *pt = sc.outport->_object._port;
memset(sc.linebuff, '\0', LINESIZE); memset (sc.linebuff, '\0', LINESIZE);
pt->rep.string.curr = sc.linebuff; pt->rep.string.curr = sc.linebuff;
/* Somewhere 'past_the_end' gets altered so it needs to be reset ~~~~~ */ /* Somewhere 'past_the_end' gets altered so it needs to be reset ~~~~~ */
pt->rep.string.past_the_end = &sc.linebuff[LINESIZE-1]; pt->rep.string.past_the_end = &sc.linebuff[LINESIZE-1];
@ -372,32 +379,31 @@ init_constants (void)
const gchar **enum_type_names; const gchar **enum_type_names;
gint n_enum_type_names; gint n_enum_type_names;
gint i; gint i;
GimpUnit unit;
pointer symbol; pointer symbol;
symbol = sc.vptr->mk_symbol (&sc, "gimp-directory"); symbol = sc.vptr->mk_symbol (&sc, "gimp-directory");
sc.vptr->scheme_define (&sc, sc.global_env, symbol, sc.vptr->scheme_define (&sc, sc.global_env, symbol,
sc.vptr->mk_string (&sc, gimp_directory () )); sc.vptr->mk_string (&sc, gimp_directory ()));
sc.vptr->setimmutable(symbol); sc.vptr->setimmutable(symbol);
symbol = sc.vptr->mk_symbol (&sc, "gimp-data-directory"); symbol = sc.vptr->mk_symbol (&sc, "gimp-data-directory");
sc.vptr->scheme_define (&sc, sc.global_env, symbol, sc.vptr->scheme_define (&sc, sc.global_env, symbol,
sc.vptr->mk_string (&sc, gimp_data_directory () )); sc.vptr->mk_string (&sc, gimp_data_directory ()));
sc.vptr->setimmutable(symbol); sc.vptr->setimmutable(symbol);
symbol = sc.vptr->mk_symbol (&sc, "gimp-plug-in-directory"); symbol = sc.vptr->mk_symbol (&sc, "gimp-plug-in-directory");
sc.vptr->scheme_define (&sc, sc.global_env, symbol, sc.vptr->scheme_define (&sc, sc.global_env, symbol,
sc.vptr->mk_string (&sc, gimp_plug_in_directory () )); sc.vptr->mk_string (&sc, gimp_plug_in_directory ()));
sc.vptr->setimmutable(symbol); sc.vptr->setimmutable(symbol);
symbol = sc.vptr->mk_symbol (&sc, "gimp-locale-directory"); symbol = sc.vptr->mk_symbol (&sc, "gimp-locale-directory");
sc.vptr->scheme_define (&sc, sc.global_env, symbol, sc.vptr->scheme_define (&sc, sc.global_env, symbol,
sc.vptr->mk_string (&sc, gimp_locale_directory () )); sc.vptr->mk_string (&sc, gimp_locale_directory ()));
sc.vptr->setimmutable(symbol); sc.vptr->setimmutable(symbol);
symbol = sc.vptr->mk_symbol (&sc, "gimp-sysconf-directory"); symbol = sc.vptr->mk_symbol (&sc, "gimp-sysconf-directory");
sc.vptr->scheme_define (&sc, sc.global_env, symbol, sc.vptr->scheme_define (&sc, sc.global_env, symbol,
sc.vptr->mk_string (&sc, gimp_sysconf_directory () )); sc.vptr->mk_string (&sc, gimp_sysconf_directory ()));
sc.vptr->setimmutable(symbol); sc.vptr->setimmutable(symbol);
enum_type_names = gimp_enums_get_type_names (&n_enum_type_names); enum_type_names = gimp_enums_get_type_names (&n_enum_type_names);
@ -430,62 +436,44 @@ init_constants (void)
g_type_class_unref (enum_class); g_type_class_unref (enum_class);
} }
for (unit = GIMP_UNIT_PIXEL;
unit < gimp_unit_get_number_of_built_in_units ();
unit++)
{
gchar *tmp;
gchar *scheme_name;
/* FIXME: gimp_unit_get_singular() returns a translated string */
tmp = g_ascii_strup (gimp_unit_get_singular (unit), -1);
scheme_name = g_strconcat ("UNIT-", tmp, NULL);
g_free (tmp);
symbol = sc.vptr->mk_symbol (&sc, scheme_name);
sc.vptr->scheme_define (&sc, sc.global_env, symbol,
sc.vptr->mk_integer (&sc, unit));
sc.vptr->setimmutable(symbol);
g_free (scheme_name);
}
/* Constants used in the register block of scripts */ /* Constants used in the register block of scripts */
for (i = 0; script_constants[i].name != NULL; ++i) for (i = 0; script_constants[i].name != NULL; ++i)
{ {
symbol = sc.vptr->mk_symbol (&sc, script_constants[i].name); symbol = sc.vptr->mk_symbol (&sc, script_constants[i].name);
sc.vptr->scheme_define (&sc, sc.global_env, symbol, sc.vptr->scheme_define (&sc, sc.global_env, symbol,
sc.vptr->mk_integer (&sc, script_constants[i].value)); sc.vptr->mk_integer (&sc,
script_constants[i].value));
sc.vptr->setimmutable(symbol); sc.vptr->setimmutable(symbol);
} }
/* Define string constant for use in building paths to files/directories */ /* Define string constant for use in building paths to files/directories */
symbol = sc.vptr->mk_symbol (&sc, "DIR-SEPARATOR"); symbol = sc.vptr->mk_symbol (&sc, "DIR-SEPARATOR");
sc.vptr->scheme_define (&sc, sc.global_env, symbol, sc.vptr->scheme_define (&sc, sc.global_env, symbol,
sc.vptr->mk_string (&sc, G_DIR_SEPARATOR_S)); sc.vptr->mk_string (&sc, G_DIR_SEPARATOR_S));
sc.vptr->setimmutable(symbol); sc.vptr->setimmutable(symbol);
/* These constants are deprecated and will be removed at a later date. */ /* These constants are deprecated and will be removed at a later date. */
symbol = sc.vptr->mk_symbol (&sc, "gimp-dir"); symbol = sc.vptr->mk_symbol (&sc, "gimp-dir");
sc.vptr->scheme_define (&sc, sc.global_env, symbol, sc.vptr->scheme_define (&sc, sc.global_env, symbol,
sc.vptr->mk_string (&sc, gimp_directory () )); sc.vptr->mk_string (&sc, gimp_directory () ));
sc.vptr->setimmutable(symbol); sc.vptr->setimmutable(symbol);
symbol = sc.vptr->mk_symbol (&sc, "gimp-data-dir"); symbol = sc.vptr->mk_symbol (&sc, "gimp-data-dir");
sc.vptr->scheme_define (&sc, sc.global_env, symbol, sc.vptr->scheme_define (&sc, sc.global_env, symbol,
sc.vptr->mk_string (&sc, gimp_data_directory () )); sc.vptr->mk_string (&sc, gimp_data_directory () ));
sc.vptr->setimmutable(symbol); sc.vptr->setimmutable(symbol);
symbol = sc.vptr->mk_symbol (&sc, "gimp-plugin-dir"); symbol = sc.vptr->mk_symbol (&sc, "gimp-plugin-dir");
sc.vptr->scheme_define (&sc, sc.global_env, symbol, sc.vptr->scheme_define (&sc, sc.global_env, symbol,
sc.vptr->mk_string (&sc, gimp_plug_in_directory () )); sc.vptr->mk_string (&sc, gimp_plug_in_directory () ));
sc.vptr->setimmutable(symbol); sc.vptr->setimmutable(symbol);
for (i = 0; old_constants[i].name != NULL; ++i) for (i = 0; old_constants[i].name != NULL; ++i)
{ {
symbol = sc.vptr->mk_symbol (&sc, old_constants[i].name); symbol = sc.vptr->mk_symbol (&sc, old_constants[i].name);
sc.vptr->scheme_define (&sc, sc.global_env, symbol, sc.vptr->scheme_define (&sc, sc.global_env, symbol,
sc.vptr->mk_integer (&sc, old_constants[i].value)); sc.vptr->mk_integer (&sc,
old_constants[i].value));
sc.vptr->setimmutable(symbol); sc.vptr->setimmutable(symbol);
} }
} }
@ -512,29 +500,32 @@ init_procedures (void)
#if USE_DL #if USE_DL
symbol = sc.vptr->mk_symbol (&sc,"load-extension"); symbol = sc.vptr->mk_symbol (&sc,"load-extension");
sc.vptr->scheme_define (&sc, sc.global_env, symbol, sc.vptr->scheme_define (&sc, sc.global_env, symbol,
sc.vptr->mk_foreign_func (&sc, scm_load_ext)); sc.vptr->mk_foreign_func (&sc, scm_load_ext));
sc.vptr->setimmutable(symbol); sc.vptr->setimmutable(symbol);
#endif #endif
symbol = sc.vptr->mk_symbol (&sc, "script-fu-register"); symbol = sc.vptr->mk_symbol (&sc, "script-fu-register");
sc.vptr->scheme_define (&sc, sc.global_env, symbol, sc.vptr->scheme_define (&sc, sc.global_env, symbol,
sc.vptr->mk_foreign_func (&sc, script_fu_register_call)); sc.vptr->mk_foreign_func (&sc,
script_fu_register_call));
sc.vptr->setimmutable(symbol); sc.vptr->setimmutable(symbol);
symbol = sc.vptr->mk_symbol (&sc, "script-fu-menu-register"); symbol = sc.vptr->mk_symbol (&sc, "script-fu-menu-register");
sc.vptr->scheme_define (&sc, sc.global_env, symbol, sc.vptr->scheme_define (&sc, sc.global_env, symbol,
sc.vptr->mk_foreign_func (&sc, script_fu_menu_register_call)); sc.vptr->mk_foreign_func (&sc,
script_fu_menu_register_call));
sc.vptr->setimmutable(symbol); sc.vptr->setimmutable(symbol);
symbol = sc.vptr->mk_symbol (&sc, "script-fu-quit"); symbol = sc.vptr->mk_symbol (&sc, "script-fu-quit");
sc.vptr->scheme_define (&sc, sc.global_env, symbol, sc.vptr->scheme_define (&sc, sc.global_env, symbol,
sc.vptr->mk_foreign_func (&sc, script_fu_quit_call)); sc.vptr->mk_foreign_func (&sc, script_fu_quit_call));
sc.vptr->setimmutable(symbol); sc.vptr->setimmutable(symbol);
/* register the database execution procedure */ /* register the database execution procedure */
symbol = sc.vptr->mk_symbol (&sc, "gimp-proc-db-call"); symbol = sc.vptr->mk_symbol (&sc, "gimp-proc-db-call");
sc.vptr->scheme_define (&sc, sc.global_env, symbol, sc.vptr->scheme_define (&sc, sc.global_env, symbol,
sc.vptr->mk_foreign_func (&sc, marshall_proc_db_call)); sc.vptr->mk_foreign_func (&sc,
marshall_proc_db_call));
sc.vptr->setimmutable(symbol); sc.vptr->setimmutable(symbol);
gimp_procedural_db_query (".*", ".*", ".*", ".*", ".*", ".*", ".*", gimp_procedural_db_query (".*", ".*", ".*", ".*", ".*", ".*", ".*",
@ -558,15 +549,15 @@ init_procedures (void)
/* The Scheme statement was suggested by Simon Budig */ /* The Scheme statement was suggested by Simon Budig */
if (nparams == 0) if (nparams == 0)
{ {
buff = g_strdup_printf ( buff = g_strdup_printf (" (define (%s)"
" (define (%s) (gimp-proc-db-call \"%s\"))", " (gimp-proc-db-call \"%s\"))",
proc_list[i], proc_list[i]); proc_list[i], proc_list[i]);
} }
else else
{ {
buff = g_strdup_printf ( buff = g_strdup_printf (" (define %s (lambda x"
" (define %s (lambda x (apply gimp-proc-db-call (cons \"%s\" x))))", " (apply gimp-proc-db-call (cons \"%s\" x))))",
proc_list[i], proc_list[i]); proc_list[i], proc_list[i]);
} }
/* Execute the 'define' */ /* Execute the 'define' */
@ -580,6 +571,7 @@ init_procedures (void)
g_free (proc_author); g_free (proc_author);
g_free (proc_copyright); g_free (proc_copyright);
g_free (proc_date); g_free (proc_date);
gimp_destroy_paramdefs (params, nparams); gimp_destroy_paramdefs (params, nparams);
gimp_destroy_paramdefs (return_vals, nreturn_vals); gimp_destroy_paramdefs (return_vals, nreturn_vals);
} }