232
109
foreach (@inargs) {
233
110
my($pdbtype, @typeinfo) = &arg_parse($_->{type});
234
111
my $arg = $arg_types{$pdbtype};
235
my $var = &arg_vname($_);
236
my $value = &arg_value($arg, $argc++);
238
if (exists $arg->{id_func} && !exists $_->{no_id_lookup}) {
239
my $id_func = $arg->{id_func};
240
$id_func = $_->{id_func} if exists $_->{id_func};
242
$result .= " $var = $id_func (gimp, $value);\n";
244
if (exists $arg->{check_func}) {
245
my $check_func = eval qq/"$arg->{check_func}"/;
247
$result .= &make_arg_test($_, sub { ${$_[0]} =~ s/==/!=/ },
250
$result .= &make_arg_test($_, sub { ${$_[0]} =~ s/==/!=/ },
255
$result .= ' ' x 2 . "$var = $value";
256
$result .= ' ? TRUE : FALSE' if $pdbtype eq 'boolean';
259
if ($pdbtype eq 'string' || $pdbtype eq 'parasite') {
260
my ($reverse, $test, $utf8, $utf8testvar);
262
$test = "$var == NULL";
265
if ($pdbtype eq 'parasite') {
266
$test .= " || $var->name == NULL";
267
$utf8testvar = "$var->name";
270
$utf8 = !exists $_->{no_validate};
271
$utf8testvar = "$var";
274
if (exists $_->{null_ok}) {
275
$reverse = sub { ${$_[0]} =~ s/!//; };
276
$test = "$var && !g_utf8_validate ($var, -1, NULL)";
279
$reverse = sub { ${$_[0]} =~ s/!//;
280
${$_[0]} =~ s/||/&&/g;
281
${$_[0]} =~ s/==/!=/g };
282
$test .= " || !g_utf8_validate ($utf8testvar, -1, NULL)";
285
$reverse = sub { ${$_[0]} =~ s/||/&&/g;
286
${$_[0]} =~ s/==/!=/g };
289
$result .= &make_arg_test($_, $reverse, $test);
291
elsif ($pdbtype eq 'tattoo') {
292
$result .= &make_arg_test($_, sub { ${$_[0]} =~ s/==/!=/ },
295
elsif ($pdbtype eq 'unit') {
296
$typeinfo[0] = 'GIMP_UNIT_PIXEL' unless defined $typeinfo[0];
297
$result .= &make_arg_test($_, sub { ${$_[0]} = "!(${$_[0]})" },
298
"$var < $typeinfo[0] || $var >= " .
299
'_gimp_unit_get_number_of_units (gimp)');
301
elsif ($pdbtype eq 'enum' && !$enums{$typeinfo[0]}->{contig}) {
302
if (!exists $_->{no_success} || exists $_->{on_success} ||
303
exists $_->{on_fail}) {
304
my %vals; my $symbols = $enums{pop @typeinfo}->{symbols};
305
@vals{@$symbols}++; delete @vals{@typeinfo};
307
my $okvals = ""; my $failvals = "";
310
foreach (@$symbols) {
311
if (exists $vals{$_}) {
312
$okvals .= ' ' x 4 if $once++;
313
$okvals .= "case $_:\n";
317
sub format_switch_frag {
318
my ($arg, $key) = @_;
320
if (exists $arg->{$key}) {
321
$frag = &format_code_frag($arg->{$key}, 1);
322
$frag =~ s/\t/' ' x 8/eg;
323
$frag =~ s/^/' ' x 2/meg;
328
$okvals .= &format_switch_frag($_, 'on_success');
331
$failvals .= "default:\n";
332
if (!exists $_->{no_success}) {
334
$failvals .= ' ' x 6 . "success = FALSE;\n"
336
$failvals .= &format_switch_frag($_, 'on_fail');
351
elsif (defined $typeinfo[0] || defined $typeinfo[2]) {
352
my $code = ""; my $tests = 0; my $extra = "";
354
if ($pdbtype eq 'enum') {
355
my $symbols = $enums{shift @typeinfo}->{symbols};
357
my ($start, $end) = (0, $#$symbols);
359
my $syms = "@$symbols "; my $test = $syms;
360
foreach (@typeinfo) { $test =~ s/$_ // }
362
if ($syms =~ /$test/g) {
363
if (pos $syms == length $syms) {
371
foreach (@typeinfo) {
372
$extra .= " || $var == $_";
376
$typeinfo[0] = $symbols->[$start];
377
if ($start != $end) {
379
$typeinfo[2] = $symbols->[$end];
384
undef @typeinf[2..3];
387
elsif ($pdbtype eq 'float') {
388
foreach (@typeinfo[0, 2]) {
389
$_ .= '.0' if defined $_ && !/\./
393
if (defined $typeinfo[0]) {
394
$code .= "$var $typeinfo[1] $typeinfo[0]";
395
$code .= '.0' if $pdbtype eq 'float' && $typeinfo[0] !~ /\./;
399
if (defined $typeinfo[2]) {
400
$code .= ' || ' if $tests;
401
$code .= "$var $typeinfo[3] $typeinfo[2]";
406
$result .= &make_arg_test($_, sub { ${$_[0]} = "!(${$_[0]})" },
414
$result = "\n" . $result if $result;
112
my $var = $_->{name};
115
$value = "&args->values[$argc]";
116
$result .= eval qq/" $arg->{get_value_func};\n"/;
120
if (!exists $_->{no_success}) {
125
$result = "\n" . $result . "\n" if $result;
459
172
$result .= ' ' x 4 . "{\n" if $success && $argc > 1;
460
173
$result .= $outargs;
461
174
$result .= ' ' x 4 . "}\n" if $success && $argc > 1;
462
$result .= "\n" . ' ' x 2 . "return return_args;\n";
175
$result .= "\n" . ' ' x 2 . "return return_vals;\n";
465
$result =~ s/_args =//;
178
$result =~ s/_vals =//;
468
181
$result =~ s/, success\);$/, TRUE);/m unless $success;
187
my ($pdbtype, @typeinfo) = &arg_parse($arg->{type});
188
my $name = $arg->{canonical_name};
189
my $nick = $arg->{canonical_name};
190
my $blurb = exists $arg->{desc} ? $arg->{desc} : "";
194
my $flags = 'GIMP_PARAM_READWRITE';
200
if (exists $arg->{no_success}) {
201
$flags .= ' | GIMP_PARAM_NO_VALIDATE';
204
if ($pdbtype eq 'image') {
205
$none_ok = exists $arg->{none_ok} ? 'TRUE' : 'FALSE';
207
gimp_param_spec_image_id ("$name",
211
GIMP_PARAM_READWRITE)
214
elsif ($pdbtype eq 'drawable') {
215
$none_ok = exists $arg->{none_ok} ? 'TRUE' : 'FALSE';
217
gimp_param_spec_drawable_id ("$name",
224
elsif ($pdbtype eq 'layer') {
225
$none_ok = exists $arg->{none_ok} ? 'TRUE' : 'FALSE';
227
gimp_param_spec_layer_id ("$name",
234
elsif ($pdbtype eq 'channel') {
235
$none_ok = exists $arg->{none_ok} ? 'TRUE' : 'FALSE';
237
gimp_param_spec_channel_id ("$name",
244
elsif ($pdbtype eq 'layer_mask') {
245
$none_ok = exists $arg->{none_ok} ? 'TRUE' : 'FALSE';
247
gimp_param_spec_layer_mask_id ("$name",
254
elsif ($pdbtype eq 'selection') {
255
$none_ok = exists $arg->{none_ok} ? 'TRUE' : 'FALSE';
257
gimp_param_spec_selection_id ("$name",
264
elsif ($pdbtype eq 'vectors') {
265
$none_ok = exists $arg->{none_ok} ? 'TRUE' : 'FALSE';
267
gimp_param_spec_vectors_id ("$name",
274
elsif ($pdbtype eq 'display') {
275
$none_ok = exists $arg->{none_ok} ? 'TRUE' : 'FALSE';
277
gimp_param_spec_display_id ("$name",
284
elsif ($pdbtype eq 'tattoo') {
286
g_param_spec_uint ("$name",
293
elsif ($pdbtype eq 'guide') {
295
g_param_spec_uint ("$name",
302
elsif ($pdbtype eq 'float') {
303
$min = defined $typeinfo[0] ? $typeinfo[0] : -G_MAXDOUBLE;
304
$max = defined $typeinfo[2] ? $typeinfo[2] : G_MAXDOUBLE;
305
$default = exists $arg->{default} ? $arg->{default} : defined $typeinfo[0] ? $typeinfo[0] : 0.0;
307
g_param_spec_double ("$name",
310
$min, $max, $default,
314
elsif ($pdbtype eq 'int32') {
315
$min = defined $typeinfo[0] ? $typeinfo[0] : G_MININT32;
316
$max = defined $typeinfo[2] ? $typeinfo[2] : G_MAXINT32;
317
$default = exists $arg->{default} ? $arg->{default} : defined $typeinfo[0] ? $typeinfo[0] : 0;
319
gimp_param_spec_int32 ("$name",
322
$min, $max, $default,
326
elsif ($pdbtype eq 'int16') {
327
$min = defined $typeinfo[0] ? $typeinfo[0] : G_MININT16;
328
$max = defined $typeinfo[2] ? $typeinfo[2] : G_MAXINT16;
329
$default = exists $arg->{default} ? $arg->{default} : defined $typeinfo[0] ? $typeinfo[0] : 0;
331
gimp_param_spec_int16 ("$name",
334
$min, $max, $default,
338
elsif ($pdbtype eq 'int8') {
339
$min = defined $typeinfo[0] ? $typeinfo[0] : 0;
340
$max = defined $typeinfo[2] ? $typeinfo[2] : G_MAXUINT8;
341
$default = exists $arg->{default} ? $arg->{default} : defined $typeinfo[0] ? $typeinfo[0] : 0;
343
gimp_param_spec_int8 ("$name",
346
$min, $max, $default,
350
elsif ($pdbtype eq 'boolean') {
351
$default = exists $arg->{default} ? $arg->{default} : FALSE;
353
g_param_spec_boolean ("$name",
360
elsif ($pdbtype eq 'string') {
361
$no_validate = exists $arg->{no_validate} ? 'TRUE' : 'FALSE';
362
$null_ok = exists $arg->{null_ok} ? 'TRUE' : 'FALSE';
363
$default = exists $arg->{default} ? $arg->{default} : NULL;
365
gimp_param_spec_string ("$name",
368
$no_validate, $null_ok,
373
elsif ($pdbtype eq 'enum') {
374
$enum_type = $typeinfo[0];
375
$enum_type =~ s/([a-z])([A-Z])/$1_$2/g;
376
$enum_type =~ s/([A-Z]+)([A-Z])/$1_$2/g;
377
$enum_type =~ tr/[a-z]/[A-Z]/;
378
$enum_type =~ s/^GIMP/GIMP_TYPE/;
379
$default = exists $arg->{default} ? $arg->{default} : $enums{$typeinfo[0]}->{symbols}[0];
381
my ($foo, $bar, @remove) = &arg_parse($arg->{type});
384
$postproc .= 'gimp_param_spec_enum_exclude_value (GIMP_PARAM_SPEC_ENUM ($pspec),';
385
$postproc .= "\n $_);\n";
388
if ($postproc eq '') {
390
g_param_spec_enum ("$name",
400
gimp_param_spec_enum ("$name",
409
elsif ($pdbtype eq 'unit') {
410
$typeinfo[0] = 'GIMP_UNIT_PIXEL' unless defined $typeinfo[0];
411
$allow_pixels = $typeinfo[0] eq 'GIMP_UNIT_PIXEL' ? TRUE : FALSE;
412
$allow_percent = exists $arg->{allow_percent} ? TRUE : FALSE;
413
$default = exists $arg->{default} ? $arg->{default} : $typeinfo[0];
415
gimp_param_spec_unit ("$name",
424
elsif ($pdbtype eq 'color') {
425
$has_alpha = exists $arg->{has_alpha} ? TRUE : FALSE;
426
$default = exists $arg->{default} ? $arg->{default} : NULL;
428
gimp_param_spec_rgb ("$name",
436
elsif ($pdbtype eq 'parasite') {
438
gimp_param_spec_parasite ("$name",
444
elsif ($pdbtype eq 'int32array') {
446
gimp_param_spec_int32_array ("$name",
452
elsif ($pdbtype eq 'int16array') {
454
gimp_param_spec_int16_array ("$name",
460
elsif ($pdbtype eq 'int8array') {
462
gimp_param_spec_int8_array ("$name",
468
elsif ($pdbtype eq 'floatarray') {
470
gimp_param_spec_float_array ("$name",
476
elsif ($pdbtype eq 'stringarray') {
478
gimp_param_spec_string_array ("$name",
485
warn "Unsupported PDB type: $arg->{name} ($arg->{type})";
491
return ($pspec, $postproc);
495
$_ = shift; s/_/-/g; return $_;
473
499
my @procs = @{(shift)};
477
504
foreach $name (@procs) {
478
505
my $proc = $main::pdb{$name};
481
508
my @inargs = @{$proc->{inargs}} if exists $proc->{inargs};
482
509
my @outargs = @{$proc->{outargs}} if exists $proc->{outargs};
511
my $help = $proc->{help};
484
513
local $success = 0;
515
$help =~ s/gimp(\w+)\(\s*\)/"'gimp".canonicalize($1)."'"/ge;
486
517
$out->{pcount}++; $total++;
488
$out->{procs} .= "static ProcRecord ${name}_proc;\n";
490
$out->{register} .= <<CODE;
491
procedural_db_register (gimp, \&${name}_proc);
519
$out->{register} .= <<CODE;
522
* gimp-$proc->{canonical_name}
524
procedure = gimp_procedure_new (${name}_invoker);
525
gimp_object_set_static_name (GIMP_OBJECT (procedure), "gimp-$proc->{canonical_name}");
526
gimp_procedure_set_static_strings (procedure,
527
"gimp-$proc->{canonical_name}",
528
@{[ "ewrap($proc->{blurb}, 2) ]},
529
@{[ "ewrap($help, 2) ]},
531
"$proc->{copyright}",
533
@{[$proc->{deprecated} ? "\"$proc->{deprecated}\"" : 'NULL']});
538
foreach $arg (@inargs) {
539
my ($pspec, $postproc) = &generate_pspec($arg);
541
$pspec =~ s/^/' ' x length(" gimp_procedure_add_argument (")/meg;
543
$out->{register} .= <<CODE;
544
gimp_procedure_add_argument (procedure,
548
if ($postproc ne '') {
549
$pspec = "procedure->args[$argc]";
550
$postproc =~ s/^/' '/meg;
551
$out->{register} .= eval qq/"$postproc"/;
559
foreach $arg (@outargs) {
560
my ($pspec, $postproc) = &generate_pspec($arg);
563
$pspec =~ s/^/' ' x length(" gimp_procedure_add_return_value (")/meg;
565
$out->{register} .= <<CODE;
566
gimp_procedure_add_return_value (procedure,
570
if ($postproc ne '') {
571
$pspec = "procedure->values[$argc]";
572
$postproc =~ s/^/' '/meg;
573
$out->{register} .= eval qq/"$postproc"/;
579
$out->{register} .= <<CODE;
580
gimp_pdb_register_procedure (pdb, procedure);
581
g_object_unref (procedure);
494
584
if (exists $proc->{invoke}->{headers}) {
500
$out->{code} .= "\nstatic Argument *\n";
501
$out->{code} .= "${name}_invoker (Gimp *gimp,\n";
502
$out->{code} .= ' ' x length($name) . " GimpContext *context,\n";
503
$out->{code} .= ' ' x length($name) . " GimpProgress *progress,\n";
504
$out->{code} .= ' ' x length($name) . " Argument *args)\n{\n";
590
$out->{code} .= "\nstatic GValueArray *\n";
591
$out->{code} .= "${name}_invoker (GimpProcedure *procedure,\n";
592
$out->{code} .= ' ' x length($name) . " Gimp *gimp,\n";
593
$out->{code} .= ' ' x length($name) . " GimpContext *context,\n";
594
$out->{code} .= ' ' x length($name) . " GimpProgress *progress,\n";
595
$out->{code} .= ' ' x length($name) . " const GValueArray *args)\n{\n";
508
if (exists $proc->{invoke}->{proc}) {
509
my ($procname, $args) = @{$proc->{invoke}->{proc}};
510
my ($exec, $fail, $argtype);
511
my $custom = $proc->{invoke}->{code};
513
$exec = "procedural_db_execute (gimp, context, progress, $procname, $args)";
514
$fail = "procedural_db_return_args (\&${name}_proc, FALSE)";
516
$argtype = 'Argument';
517
if (exists $proc->{invoke}->{args}) {
518
foreach (@{$proc->{invoke}->{args}}) {
519
$code .= " $argtype *$_;\n";
523
foreach (qw(exec fail argtype)) { $custom =~ s/%%$_%%/"\$$_"/eeg }
526
foreach (@{$proc->{inargs}}) {
527
my $arg = $arg_types{(&arg_parse($_->{type}))[0]};
528
my $var = &arg_vname($_);
529
$custom =~ s/%%$var%%/&arg_value($arg, $pos)/e;
533
$code .= &declare_vars($proc);
534
$code .= "\n" if length($code);
535
$code .= &format_code_frag($custom, 0) . "}\n";
537
elsif (exists $proc->{invoke}->{pass_through}) {
538
my $invoke = $proc->{invoke};
541
$argc += @{$invoke->{pass_args}} if exists $invoke->{pass_args};
542
$argc += @{$invoke->{make_args}} if exists $invoke->{make_args};
544
my %pass; my @passgroup;
545
my $before = 0; my $contig = 0; my $pos = -1;
546
if (exists $invoke->{pass_args}) {
547
foreach (@{$invoke->{pass_args}}) {
549
$_ - 1 == $before ? $contig = 1 : $pos++;
550
push @{$passgroup[$pos]}, $_;
554
$code .= ' ' x 2 . "int i;\n" if $contig;
556
$code .= ' ' x 2 . "Argument argv[$argc];\n";
558
my $tempproc; $pos = 0;
559
foreach (@{$proc->{inargs}}) {
560
$_->{argpos} = $pos++;
561
push @{$tempproc->{inargs}}, $_ if !exists $pass{$_->{argpos}};
564
$code .= &declare_args($tempproc, $out, qw(inargs)) . "\n";
565
$code .= &declare_vars($proc);
568
foreach (@{$tempproc->{inargs}}) {
569
my $argproc; $argproc->{inargs} = [ $_ ];
570
$marshal .= &marshal_inargs($argproc, $_->{argpos});
573
$marshal .= "\n" if $marshal;
578
return procedural_db_return_args (\&${name}_proc, FALSE);
583
$marshal = substr($marshal, 1) if $marshal;
586
foreach (@passgroup) {
587
$code .= ($#$_ ? <<LOOP : <<CODE) . "\n";
588
for (i = $_->[0]; i < @{[ $_->[$#$_] + 1 ]}; i++)
591
argv[$_->[0]] = args[$_->[0]];
595
if (exists $invoke->{make_args}) {
597
foreach (@{$invoke->{make_args}}) {
598
while (exists $pass{$pos}) { $pos++ }
600
my $arg = $arg_types{(&arg_parse($_->{type}))[0]};
601
my $type = &arg_ptype($arg);
604
argv[$pos].arg_type = GIMP_PDB_$arg->{name};
607
my $frag = $_->{code};
608
$frag =~ s/%%arg%%/"argv[$pos].value.pdb_$type"/e;
609
$code .= &format_code_frag($frag, 0);
617
return $invoke->{pass_through}_invoker (gimp, context, progress, argv);
599
if (exists $proc->{invoke}->{no_marshalling}) {
600
$code .= &format_code_frag($proc->{invoke}->{code}, 0) . "}\n";
622
603
my $invoker = "";
624
$invoker .= ' ' x 2 . "Argument *return_args;\n" if scalar @outargs;
625
$invoker .= &declare_args($proc, $out, qw(inargs outargs));
626
$invoker .= &declare_vars($proc);
605
$invoker .= ' ' x 2 . "GValueArray *return_vals;\n" if scalar @outargs;
606
$invoker .= &declare_args($proc, $out, 0, qw(inargs));
607
$invoker .= &declare_args($proc, $out, 1, qw(outargs));
628
609
$invoker .= &marshal_inargs($proc, 0);
629
610
$invoker .= "\n" if $invoker && $invoker !~ /\n\n/s;