18
18
# "Perlized" from C source by Manish Singh <yosh@gimp.org>
20
sub proc_name_arg () {{
23
desc => 'The procedure name',
27
sub data_ident_arg () {{
30
desc => 'The identifier associated with data'
33
sub data_bytes_arg () {{
36
desc => 'The number of bytes in the data',
42
desc => 'A byte array containing data',
43
array => &data_bytes_arg
47
my ($type, $long_type, $real_type) = @_;
50
Queries the procedural database for information on the specified procedure's
55
This procedure returns information on the specified procedure's $long_type. The
56
$long_type type, name, and a description are retrieved.
64
{ name => "${type}_num", type => 'int32',
65
desc => "The $long_type number" }
69
{ name => "${type}_type", type => 'enum GimpPDBArgType (no GIMP_PDB_END)',
70
desc => "The type of $long_type { %%desc%% }", void_ret => 1,
71
alias => "${type}->arg_type", no_declare => 1 },
72
{ name => "${type}_name", type => 'string',
73
desc => "The name of the $long_type",
74
alias => "g_strdup (${type}->name)", no_declare => 1 },
75
{ name => "${type}_desc", type => 'string',
76
desc => "A description of the $long_type",
77
alias => "g_strdup (${type}->description)", no_declare => 1 }
81
vars => [ 'ProcRecord *proc', "ProcArg *$type = NULL" ],
84
proc = procedural_db_lookup (gimp, proc_name);
88
const gchar *compat_name;
90
compat_name = g_hash_table_lookup (gimp->procedural_compat_ht, proc_name);
93
proc = procedural_db_lookup (gimp, compat_name);
96
if (proc && (${type}_num >= 0 && ${type}_num < proc->num_$real_type))
97
$type = \&proc->${real_type}\[${type}_num];
107
20
sub procedural_db_temp_name {
108
21
$blurb = 'Generates a unique temporary PDB name.';
111
24
This procedure generates a temporary PDB entry name that is guaranteed to be
112
unique. It is many used by the interactive popup dialogs to generate a PDB
116
$author = $copyright = 'Andy Thomas';
28
&andy_pdb_misc('1998');
120
31
{ name => 'temp_name', type => 'string',
190
my $regcomp = ""; $once = 0;
191
foreach (qw(name blurb help author copyright date proc_type)) {
192
push @inargs, { name => $_, type => 'string', no_validate => 1,
193
desc => "The regex for procedure $_" };
195
$regcomp .= ' ' x 2 if $once++;
196
$regcomp .= "if (regcomp (&pdb_query.${_}_regex, $_, 0))\n";
197
$regcomp .= " goto free_${_};\n";
200
my $free = ""; $once = 0;
201
foreach (qw(proc_type date copyright author help blurb name)) {
202
$free .= ' ' x 2 if $once++;
203
$free .= "free_${_}:\n";
204
$free .= " regfree (&pdb_query.${_}_regex);\n";
208
$inargs[$#inargs]->{desc} =~
210
<type: { 'Internal GIMP procedure', 'GIMP Plug-in',
96
{ name => 'name', type => 'string', no_validate => 1,
97
desc => 'The regex for procedure name' },
98
{ name => 'blurb', type => 'string', no_validate => 1,
99
desc => 'The regex for procedure blurb' },
100
{ name => 'help', type => 'string', no_validate => 1,
101
desc => 'The regex for procedure help' },
102
{ name => 'author', type => 'string', no_validate => 1,
103
desc => 'The regex for procedure author' },
104
{ name => 'copyright', type => 'string', no_validate => 1,
105
desc => 'The regex for procedure copyright' },
106
{ name => 'date', type => 'string', no_validate => 1,
107
desc => 'The regex for procedure date' },
108
{ name => 'proc_type', type => 'string', no_validate => 1,
109
desc => 'The regex for procedure type: { \'Internal GIMP procedure\',
110
\'GIMP Plug-In\', \'GIMP Extension\',
111
\'Temporary Procedure\' }' }
214
115
{ name => 'procedure_names', type => 'stringarray', void_ret => 1,
215
116
desc => 'The list of procedure names',
216
alias => 'pdb_query.list_of_procs', no_declare => 1,
217
117
array => { name => 'num_matches',
218
desc => 'The number of matching procedures',
219
alias => 'pdb_query.num_procs', no_declare => 1 }
118
desc => 'The number of matching procedures' } }
224
headers => [ qw(<stdlib.h> "regexrepl/regex.h") ],
225
vars => [ 'PDBQuery pdb_query' ],
234
pdb_query.gimp = gimp;
235
pdb_query.list_of_procs = NULL;
236
pdb_query.num_procs = 0;
237
pdb_query.querying_compat = FALSE;
239
g_hash_table_foreach (gimp->procedural_ht,
240
procedural_db_query_entry, \&pdb_query);
242
pdb_query.querying_compat = TRUE;
244
g_hash_table_foreach (gimp->procedural_compat_ht,
245
procedural_db_query_entry, \&pdb_query);
124
success = gimp_pdb_query (gimp->pdb,
125
name, blurb, help, author,
126
copyright, date, proc_type,
127
&num_matches, &procedure_names);
258
138
$help = <<'HELP';
259
This procedure returns information on the specified procedure. A short blurb,
260
detailed help, author(s), copyright information, procedure type, number of
261
input, and number of return values are returned. For specific information on
262
each input argument and return value, use the
263
'gimp_procedural_db_proc_arg' and
264
'gimp_procedural_db_proc_val' procedures.
139
This procedure returns information on the specified procedure. A short
140
blurb, detailed help, author(s), copyright information, procedure
141
type, number of input, and number of return values are returned. For
142
specific information on each input argument and return value, use the
143
gimp_procedural_db_proc_arg() and gimp_procedural_db_proc_val()
270
@inargs = ( &proc_name_arg );
151
{ name => 'procedure_name', type => 'string',
152
desc => 'The procedure name' }
273
156
{ name => 'blurb', type => 'string', void_ret => 1, wrap => 1,
281
164
{ name => 'date', type => 'string',
282
165
desc => 'Copyright date' },
283
166
{ name => 'proc_type', type => 'enum GimpPDBProcType',
284
desc => 'The procedure type: { %%desc%% }' },
167
desc => 'The procedure type' },
285
168
{ name => 'num_args', type => 'int32',
286
169
desc => 'The number of input arguments' },
287
170
{ name => 'num_values', type => 'int32',
288
171
desc => 'The number of return values' }
292
if ($_->{type} eq 'string') {
293
$_->{alias} = "strings.compat ? strings.$_->{name} : g_strdup (strings.$_->{name})";
295
$_->{alias} = "proc->$_->{name}";
298
$_->{no_declare} = 1;
302
vars => [ 'PDBStrings strings', 'ProcRecord *proc = NULL' ],
305
proc = procedural_db_lookup (gimp, proc_name);
309
get_pdb_strings (&strings, proc, FALSE);
313
const gchar *compat_name;
315
compat_name = g_hash_table_lookup (gimp->procedural_compat_ht, proc_name);
319
proc = procedural_db_lookup (gimp, compat_name);
322
get_pdb_strings (&strings, proc, TRUE);
326
success = (proc != NULL);
177
GimpPDBProcType ptype;
180
canonical = gimp_canonicalize_identifier (procedure_name);
182
success = gimp_pdb_proc_info (gimp->pdb, canonical,
183
&blurb, &help, &author,
184
©right, &date, &ptype,
185
&num_args, &num_values);
332
194
sub procedural_db_proc_arg {
333
&arg_info_proc('arg', 'argument', 'args');
196
Queries the procedural database for information on the specified procedure's
201
This procedure returns information on the specified procedure's argument. The
202
argument type, name, and a description are retrieved.
209
{ name => 'procedure_name', type => 'string',
210
desc => 'The procedure name' },
211
{ name => 'arg_num', type => 'int32',
212
desc => 'The argument number' }
216
{ name => 'arg_type', type => 'enum GimpPDBArgType (no GIMP_PDB_END)',
217
desc => "The type of argument", void_ret => 1 },
218
{ name => 'arg_name', type => 'string',
219
desc => 'The name of the argument' },
220
{ name => 'arg_desc', type => 'string',
221
desc => 'A description of the argument' }
230
canonical = gimp_canonicalize_identifier (procedure_name);
232
proc = gimp_pdb_lookup_procedure (gimp->pdb, canonical);
236
const gchar *compat_name;
238
compat_name = gimp_pdb_lookup_compat_proc_name (gimp->pdb, canonical);
241
proc = gimp_pdb_lookup_procedure (gimp->pdb, compat_name);
246
if (proc && (arg_num >= 0 && arg_num < proc->num_args))
248
GParamSpec *pspec = proc->args[arg_num];
250
arg_type = gimp_pdb_compat_arg_type_from_gtype (G_PARAM_SPEC_VALUE_TYPE (pspec));
251
arg_name = g_strdup (g_param_spec_get_name (pspec));
252
arg_desc = gimp_param_spec_get_desc (pspec);
336
261
sub procedural_db_proc_val {
337
&arg_info_proc('val', 'return value', 'values');
263
Queries the procedural database for information on the specified procedure's
268
This procedure returns information on the specified procedure's return value.
269
The return value type, name, and a description are retrieved.
276
{ name => 'procedure_name', type => 'string',
277
desc => 'The procedure name' },
278
{ name => 'val_num', type => 'int32',
279
desc => 'The return value number' }
283
{ name => 'val_type', type => 'enum GimpPDBArgType (no GIMP_PDB_END)',
284
desc => "The type of return value", void_ret => 1 },
285
{ name => 'val_name', type => 'string',
286
desc => 'The name of the return value' },
287
{ name => 'val_desc', type => 'string',
288
desc => 'A description of the return value' }
297
canonical = gimp_canonicalize_identifier (procedure_name);
299
proc = gimp_pdb_lookup_procedure (gimp->pdb, canonical);
303
const gchar *compat_name;
305
compat_name = gimp_pdb_lookup_compat_proc_name (gimp->pdb, canonical);
308
proc = gimp_pdb_lookup_procedure (gimp->pdb, compat_name);
313
if (proc && (val_num >= 0 && val_num < proc->num_values))
315
GParamSpec *pspec = proc->values[val_num];
317
val_type = gimp_pdb_compat_arg_type_from_gtype (G_PARAM_SPEC_VALUE_TYPE (pspec));
318
val_name = g_strdup (g_param_spec_get_name (pspec));
319
val_desc = gimp_param_spec_get_desc (pspec);
340
328
sub procedural_db_get_data {
341
$alias{lib} = 'get_data';
343
329
$blurb = 'Returns data associated with the specified identifier.';
345
331
$help = <<'HELP';
354
@inargs = ( &data_ident_arg );
341
{ name => 'identifier', type => 'string',
342
desc => 'The identifier associated with data' }
356
@outargs = ( &data_arg );
357
$outargs[0]->{alias} = 'data_copy';
358
$outargs[0]->{init} = 1;
359
$outargs[0]->{wrap} = 1;
360
$outargs[0]->{void_ret} = 1;
346
{ name => 'data', type => 'int8array',
347
desc => 'A byte array containing data', wrap => 1,
349
array => { name => 'bytes', type => '1 <= int32',
350
desc => 'The number of bytes in the data' } }
363
vars => [ 'const guint8 *data' ],
366
data = procedural_db_get_data (gimp, identifier, &bytes);
367
success = (data != NULL);
370
data_copy = g_memdup (data, bytes);
356
gchar *canonical = gimp_canonicalize_identifier (identifier);
357
const guint8 *orig_data;
359
orig_data = gimp_plug_in_manager_get_data (gimp->plug_in_manager,
365
data = g_memdup (orig_data, bytes);
416
@inargs = ( &data_ident_arg, &data_arg );
417
$inargs[1]->{wrap} = 1;
418
delete @{$inargs[1]->{array}}{qw(alias no_declare)};
421
{ name => 'identifier', type => 'string',
422
desc => 'The identifier associated with data' },
423
{ name => 'data', type => 'int8array',
424
desc => 'A byte array containing data', wrap => 1,
425
array => { name => 'bytes', type => '1 <= int32',
426
desc => 'The number of bytes in the data' } }
421
code => 'procedural_db_set_data (gimp, identifier, bytes, data);'
432
gchar *canonical = gimp_canonicalize_identifier (identifier);
434
gimp_plug_in_manager_set_data (gimp->plug_in_manager,
435
canonical, bytes, data);
425
@headers = qw(<string.h> "gimp-intl.h");
427
$extra{app}->{decls} = <<'CODE';
428
#define COMPAT_BLURB "This procedure is deprecated! Use '%s' instead."
431
/* Query structure */
432
typedef struct _PDBQuery PDBQuery;
441
regex_t author_regex;
442
regex_t copyright_regex;
444
regex_t proc_type_regex;
446
gchar **list_of_procs;
448
gboolean querying_compat;
452
typedef struct _PDBStrings PDBStrings;
465
static gchar *proc_type_str[] =
467
N_("Internal GIMP procedure"),
469
N_("GIMP Extension"),
470
N_("Temporary Procedure")
473
static const gchar * const type_str[] =
477
foreach (@{$Gimp::CodeGen::enums::enums{GimpPDBArgType}->{symbols}}) {
478
$extra{app}->{decls} .= qq/ "$_",\n/;
481
$extra{app}->{decls} =~ s/,\n$/\n};\n/;
483
$extra{app}->{code} = <<'CODE';
485
match_strings (regex_t *preg,
491
return regexec (preg, a, 0, NULL, 0);
495
get_pdb_strings (PDBStrings *strings,
499
strings->compat = compat;
503
strings->blurb = g_strdup_printf (COMPAT_BLURB, proc->name);
504
strings->help = g_strdup (strings->blurb);
505
strings->author = NULL;
506
strings->copyright = NULL;
507
strings->date = NULL;
511
strings->blurb = proc->blurb;
512
strings->help = proc->help;
513
strings->author = proc->author;
514
strings->copyright = proc->copyright;
515
strings->date = proc->date;
520
procedural_db_query_entry (gpointer key,
524
PDBQuery *pdb_query = user_data;
527
const gchar *proc_name;
532
if (pdb_query->querying_compat)
533
list = g_hash_table_lookup (pdb_query->gimp->procedural_ht, value);
540
proc = (ProcRecord *) list->data;
542
get_pdb_strings (&strings, proc, pdb_query->querying_compat);
544
if (! match_strings (&pdb_query->name_regex, proc_name) &&
545
! match_strings (&pdb_query->blurb_regex, strings.blurb) &&
546
! match_strings (&pdb_query->help_regex, strings.help) &&
547
! match_strings (&pdb_query->author_regex, strings.author) &&
548
! match_strings (&pdb_query->copyright_regex, strings.copyright) &&
549
! match_strings (&pdb_query->date_regex, strings.date) &&
550
! match_strings (&pdb_query->proc_type_regex,
551
proc_type_str[(gint) proc->proc_type]))
553
pdb_query->num_procs++;
554
pdb_query->list_of_procs = g_renew (gchar *, pdb_query->list_of_procs,
555
pdb_query->num_procs);
556
pdb_query->list_of_procs[pdb_query->num_procs - 1] = g_strdup (proc_name);
561
g_free (strings.blurb);
562
g_free (strings.help);
567
output_string (FILE *file,
570
if (fprintf (file, "\"") < 0)
578
case '\\' : if (fprintf (file, "\\\\") < 0) return FALSE; break;
579
case '\"' : if (fprintf (file, "\\\"") < 0) return FALSE; break;
580
case '{' : if (fprintf (file, "@{") < 0) return FALSE; break;
581
case '@' : if (fprintf (file, "@@") < 0) return FALSE; break;
582
case '}' : if (fprintf (file, "@}") < 0) return FALSE; break;
585
if (fprintf (file, "%c", *string) < 0)
591
if (fprintf (file, "\"\n") < 0)
598
procedural_db_print_entry (gpointer key,
602
ProcRecord *procedure;
609
list = (GList *) value;
610
file = (FILE *) user_data;
612
buf = g_string_new ("");
617
procedure = (ProcRecord*) list->data;
620
fprintf (file, "\n(register-procedure ");
622
if (list || num != 1)
624
g_string_printf (buf, "%s <%d>", procedure->name, num);
625
output_string (file, buf->str);
628
output_string (file, procedure->name);
630
output_string (file, procedure->blurb);
631
output_string (file, procedure->help);
632
output_string (file, procedure->author);
633
output_string (file, procedure->copyright);
634
output_string (file, procedure->date);
635
output_string (file, proc_type_str[(int) procedure->proc_type]);
637
fprintf (file, "( ");
638
for (i = 0; i < procedure->num_args; i++)
640
fprintf (file, "( ");
642
output_string (file, procedure->args[i].name );
643
output_string (file, type_str[procedure->args[i].arg_type]);
644
output_string (file, procedure->args[i].description);
646
fprintf (file, " ) ");
648
fprintf (file, " ) ");
650
fprintf (file, "( ");
651
for (i = 0; i < procedure->num_values; i++)
653
fprintf (file, "( ");
654
output_string (file, procedure->values[i].name );
655
output_string (file, type_str[procedure->values[i].arg_type]);
656
output_string (file, procedure->values[i].description);
658
fprintf (file, " ) ");
660
fprintf (file, " ) ");
661
fprintf (file, " ) ");
664
g_string_free (buf, TRUE);
667
/* This really doesn't belong here, but it depends on our generated type_str
671
pdb_type_name (gint type)
673
if (type >= 0 && type <= GIMP_PDB_END)
674
return type_str[type];
676
return g_strdup_printf ("(PDB type %d unknown)", type);
677
/* Yeah, we leak the memory. But then you shouldn't try and
678
* get the name of a PDB type that doesn't exist, should you.
444
@headers = qw("libgimpbase/gimpbase.h"
446
"core/gimpparamspecs-desc.h"
449
"plug-in/gimppluginmanager-data.h");
683
451
@procs = qw(procedural_db_temp_name procedural_db_dump
684
452
procedural_db_query procedural_db_proc_info
685
453
procedural_db_proc_arg procedural_db_proc_val
686
454
procedural_db_get_data procedural_db_get_data_size
687
455
procedural_db_set_data);
688
457
%exports = (app => [@procs], lib => [@procs]);
690
459
$desc = 'Procedural database';