Commit 9435e618 authored by Manish Singh's avatar Manish Singh

Lossa stuff

-Yosh
parent 323fa245
......@@ -3,7 +3,9 @@ enum_headers = \
../../app/channel_ops.h \
../../app/text_tool.h \
../../app/gimpdrawable.h \
../../app/gimpimage.h
../../app/gimpimage.h \
../../app/procedural_db.h \
../../app/paint_funcs.h
enums.pl: enumgen.pl $(enum_headers)
cd $(srcdir) \
......
......@@ -60,6 +60,37 @@ sub format_code_frag {
$code;
}
sub make_arg_test {
my ($arg, $reverse, $test) = @_;
my $result = "";
my $yes = exists $arg->{on_success};
my $no = !exists $arg->{no_success} || exists $arg->{on_fail};
if ($yes || $no) {
&$reverse(\$test) if $yes;
$result = ' ' x 2 . "if ($test)\n";
$result .= &format_code_frag($arg->{on_success}, 1) if $yes;
if ($no) {
$result .= ' ' x 2 . "else\n" if $yes;
if (!exists $arg->{no_success}) {
$success = 1;
$result .= ' ' x 4 . "success = FALSE;\n";
}
if (exists $arg->{on_fail}) {
$result .= &format_code_frag($_->{on_fail}, 1);
}
}
}
$result;
}
sub declare_args {
my $proc = shift;
my $out = shift;
......@@ -116,10 +147,18 @@ sub make_arg_recs {
/array/ && do { last };
/boolean/ && do { $info = 'TRUE or FALSE'; last };
/int|float/ && do { $info =~ s/$type/$arg->{name}/e; last };
/enum/ && do { $info = $enums{$name}->{info};
/enum/ && do { my $enum = $enums{$name};
$info = $enum->{info};
foreach (@remove) {
$info =~ s/$_ \(.*?\)(, )?//
} last };
if (exists $enum->{nicks}->{$_}) {
$nick = $enum->{nicks}->{$_};
}
else {
$nick = $_;
}
$info =~ s/$nick \(.*?\)(, )?//
}
$info =~ s/, $//; last };
}
$desc =~ s/%%desc%%/$info/eg;
......@@ -159,123 +198,113 @@ sub marshal_inargs {
$result .= <<CODE;
$var = $arg->{id_func} (args[$argc].value.pdb_$type);
CODE
if (!exists $_->{no_success}) {
$result .= ' ' x 2 . "if ($var ";
$result .= exists $_->{on_success} ? '!=' : '==';
$result .= " NULL)\n";
if (exists $_->{on_success}) {
$result .= &format_code_frag($_->{on_success}, 1);
$result .= ' ' x 2 . "else\n";
}
$result .= ' ' x 4 . "success = FALSE;\n";
if (exists $_->{on_fail}) {
$result .= &format_code_frag($_->{on_fail}, 1);
}
$success = 1;
}
$result .= &make_arg_test($_, sub { ${$_[0]} =~ s/==/!=/ },
"$var == NULL");
}
else {
my $code = ' ' x 2 . "$var =";
$result .= ' ' x 2 . "$var =";
my $cast = "";
if ($type eq 'pointer' || $arg->{type} =~ /int(16|8)$/) {
$cast = " ($arg->{type})";
}
$code .= "$cast args[$argc].value.pdb_$type";
$code .= ' ? TRUE : FALSE' if $pdbtype eq 'boolean';
$code .= ";\n";
$result .= "$cast args[$argc].value.pdb_$type";
$result .= ' ? TRUE : FALSE' if $pdbtype eq 'boolean';
$result .= ";\n";
if (!exists $_->{no_success}) {
if ($pdbtype eq 'string') {
$code .= ' ' x 2 . "success = $var != NULL;\n";
}
elsif ($pdbtype eq 'enum' && !$enums{$typeinfo[0]}->{contig}) {
if ($pdbtype eq 'string') {
$result .= &make_arg_test($_, sub { ${$_[0]} =~ s/==/!=/ },
"$var == NULL");
}
elsif ($pdbtype eq 'unit') {
$result .= &make_arg_test($_, sub { ${$_[0]} = "!(${$_[0]})" },
'unit < UNIT_PIXEL || unit >= ' .
'gimp_unit_get_number_of_units ()');
}
elsif ($pdbtype eq 'enum' && !$enums{$typeinfo[0]}->{contig}) {
if (!exists $_->{no_success} || exists $_->{on_success} ||
exists $_->{on_fail}) {
my %vals; my $symbols = $enums{pop @typeinfo}->{symbols};
@vals{@$symbols}++; delete @vals{@typeinfo};
$code .= <<CODE;
switch ($var)
{
CODE
my $okvals = ""; my $failvals = "";
my $once = 0;
foreach (@$symbols) {
$code .= ' ' x 4 . "case $_:\n" if exists $vals{$_};
if (exists $vals{$_}) {
$okvals .= ' ' x 4 if $once++;
$okvals .= "case $_:\n";
}
}
$code .= <<CODE;
sub format_switch_frag {
my ($arg, $key) = @_;
my $frag = "";
if (exists $arg->{$key}) {
$frag = &format_code_frag($arg->{$key}, 1);
$frag =~ s/\t/' ' x 8/eg;
$frag =~ s/^/' ' x 2/meg;
$frag =~ s/^ {8}/\t/mg;
}
$frag;
}
$okvals .= &format_switch_frag($_, 'on_success');
$failvals .= "default:\n";
if (!exists $_->{no_success}) {
$success = 1;
$failvals .= ' ' x 6 . "success = FALSE\n"
}
$failvals .= &format_switch_frag($_, 'on_fail');
$result .= <<CODE;
switch ($var)
{
$okvals
break;
default:
success = FALSE;
$failvals
break;
}
CODE
}
elsif (defined $typeinfo[0] || defined $typeinfo[2]) {
my $tests = 0; my $extra = "";
if ($pdbtype eq 'enum') {
my $symbols = $enums{pop @typeinfo}->{symbols};
foreach (@typeinfo) { $extra .= " && $var != $_" }
$typeinfo[0] = $symbols->[0];
$typeinfo[1] = '>=';
$typeinfo[2] = $symbols->[$#$symbols];
$typeinfo[3] = '<=';
}
}
elsif (defined $typeinfo[0] || defined $typeinfo[2]) {
my $code = ""; my $tests = 0; my $extra = "";
$code .= ' ' x 2 . "success = ";
if ($pdbtype eq 'enum') {
my $symbols = $enums{shift @typeinfo}->{symbols};
if (defined $typeinfo[0]) {
$code .= "$var $typeinfo[1] $typeinfo[0]";
$tests++;
}
if (defined $typeinfo[2]) {
$code .= ' && ' if $tests;
$code .= "$var $typeinfo[3] $typeinfo[2]";
}
foreach (@typeinfo) { $extra .= " || $var == $_" }
$code .= "$extra;\n";
$typeinfo[0] = $symbols->[0];
$typeinfo[1] = '<';
$typeinfo[2] = $symbols->[$#$symbols];
$typeinfo[3] = '>';
}
if ($code =~ /success/) {
my $tests = 0;
if (exists $_->{on_success}) {
$code .= ' ' x 2 . "if (success)\n";
$code .= &format_code_frag($_->{on_success}, 1);
$tests++;
elsif ($pdbtype eq 'float') {
foreach (@typeinfo[0, 2]) {
$_ .= '.0' if defined $_ && !/\./
}
}
if (exists $_->{on_fail}) {
$code .= ' ' x 2;
$code .= $tests ? "else\n" : "if (success)\n";
$code .= &format_code_frag($_->{on_fail}, 1);
}
if (defined $typeinfo[0]) {
$code .= "$var $typeinfo[1] $typeinfo[0]";
$code .= '.0' if $pdbtype eq 'float' && $typeinfo[0] !~ /\./;
$tests++;
}
if ($success) {
$code =~ s/^/' ' x 4/meg;
$code =~ s/^ {8}/\t/mg;
if (defined $typeinfo[2]) {
$code .= ' || ' if $tests;
$code .= "$var $typeinfo[3] $typeinfo[2]";
}
$code .= ' ' x 4 . "}\n";
$result .= ' ' x 2 . "if (success)\n" . ' ' x 4 . "{\n";
}
else {
$success_init = 0;
}
$code .= $extra;
$success = 1;
}
$result .= &make_arg_test($_, sub { ${$_[0]} = "!(${$_[0]})" },
$code);
}
$result .= $code;
}
$argc++; $result .= "\n";
......@@ -344,7 +373,6 @@ sub generate {
my @outargs = @{$proc->{outargs}} if exists $proc->{outargs};
local $success = 0;
local $success_init = 1;
$out->{pcount}++; $total++;
......@@ -476,13 +504,11 @@ CODE
}
if ($success) {
$success_init = 0 if $proc->{invoke}->{success} eq 'NONE';
my $header = ' ' x 2 . "gboolean success";
$header .= " = $proc->{invoke}->{success}" if $success_init;
$header .= ";\n";
$out->{code} .= $header;
$out->{code} .= ' ' x 2 . "gboolean success";
unless ($proc->{invoke}->{success} eq 'NONE') {
$out->{code} .= " = $proc->{invoke}->{success}";
}
$out->{code} .= ";\n";
}
$out->{code} .= $code;
......@@ -500,15 +526,13 @@ static ProcRecord ${name}_proc =
"$proc->{copyright}",
"$proc->{date}",
PDB_INTERNAL,
@{[scalar @inargs or '0']},
@{[scalar @inargs]},
@{[scalar @inargs ? "${name}_inargs" : 'NULL']},
@{[scalar @outargs or '0']},
@{[scalar @outargs]},
@{[scalar @outargs ? "${name}_outargs" : 'NULL']},
{ { ${name}_invoker } }
};
CODE
delete $out->{headers}->{q/"procedural_db.h"/};
}
my $gpl = <<'GPL';
......@@ -554,20 +578,27 @@ HEADER
foreach $group (@main::groups) {
my $out = $out{$group};
foreach (@{$main::grp{$group}->{headers}}) { $out->{headers}->{$_}++ }
delete $out->{headers}->{q/"procedural_db.h"/};
my $headers = "";
foreach (sort keys %{$out->{headers}}) { $headers .= "#include $_\n" }
my $extra = {};
if (exists $main::grp{$group}->{extra}->{app}) {
$extra = $main::grp{$group}->{extra}->{app}
}
my $cfile = "$destdir/${group}_cmds.c$FILE_EXT";
open CFILE, "> $cfile" or die "Can't open $cmdfile: $!\n";
print CFILE $gpl;
print CFILE qq/#include "procedural_db.h"\n\n/;
foreach $header (sort keys %{$out->{headers}}) {
print CFILE "#include $header\n";
}
print CFILE "\n";
if (exists $main::grp{$group}->{code}) {
print CFILE "$main::grp{$group}->{code}\n";
}
print CFILE $headers, "\n";
print CFILE $extra->{decls}, "\n" if exists $extra->{decls};
print CFILE $out->{procs};
print CFILE "\nvoid\nregister_${group}_procs (void)\n";
print CFILE "{\n$out->{register}}\n";
print CFILE "\n", $extra->{code} if exists $extra->{code};
print CFILE $out->{code};
close CFILE;
&write_file($cfile);
......@@ -577,9 +608,9 @@ HEADER
$longest = length $decl if $longest < length $decl;
$group_procs .= ' ' x 2 . "app_init_update_status (";
$group_procs .= q/"Internal Procedures"/ unless $once;
$group_procs .= q/_("Internal Procedures")/ unless $once;
$group_procs .= 'NULL' if $once++;
$group_procs .= qq/, "$main::grp{$group}->{desc}", /;
$group_procs .= qq/, _("$main::grp{$group}->{desc}"), /;
($group_procs .= sprintf "%.3f", $pcount / $total) =~ s/\.?0*$//s;
$group_procs .= ($group_procs !~ /\.\d+$/s ? ".0" : "") . ");\n";
$group_procs .= ' ' x 2 . "register_${group}_procs ();\n\n";
......@@ -589,7 +620,8 @@ HEADER
$internal = "$destdir/internal_procs.c$FILE_EXT";
open INTERNAL, "> $internal" or die "Can't open $cmdfile: $!\n";
print INTERNAL $gpl;
print INTERNAL qq/#include "app_procs.h"\n\n/;
print INTERNAL qq@#include "app_procs.h"\n\n@;
print INTERNAL qq@#include "libgimp/gimpintl.h"\n\n@;
print INTERNAL "/* Forward declarations for registering PDB procs */\n\n";
foreach (@group_decls) {
print INTERNAL "void $_" . ' ' x ($longest - length $_) . " (void);\n";
......
......@@ -25,16 +25,12 @@ BEGIN {
use lib $srcdir;
use Text::Wrap qw(wrap $columns);
$columns = 79;
$columns = 77;
require 'util.pl';
BEGIN { require 'util.pl' }
eval <<'CODE';
*write_file = \&Gimp::CodeGen::util::write_file;
*FILE_EXT = \$Gimp::CodeGen::util::FILE_EXT;
CODE
$FILE_EXT = $FILE_EXT;
my $header = <<'HEADER';
:# The GIMP -- an image manipulation program
......@@ -66,7 +62,10 @@ my $footer = <<'FOOTER';
:
:foreach $e (values %enums) {
: $e->{info} = "";
: foreach (@{$e->{symbols}}) { $e->{info} .= "$_ ($e->{mapping}->{$_}), " }
: foreach (@{$e->{symbols}}) {
: my $nick = exists $e->{nicks}->{$_} ? $e->{nicks}->{$_} : $_;
: $e->{info} .= "$nick ($e->{mapping}->{$_}), "
: }
: $e->{info} =~ s/, $//;
:}
:
......@@ -76,9 +75,21 @@ FOOTER
$header =~ s/^://mg;
$footer =~ s/^://mg;
my ($enumname, $contig, $symbols, @mapping, $before);
my ($enumname, $contig, $symbols, @nicks, @mapping, $before, $chop);
# Most of this enum parsing stuff was swiped from makeenums.pl in GTK+
sub parse_options {
my $opts = shift;
my @opts;
for $opt (split /\s*,\s*/, $opts) {
my ($key,$val) = $opt =~ /\s*(\w+)(?:=(\S+))?/;
defined $val or $val = 1;
push @opts, $key, $val;
}
@opts;
}
sub parse_entries {
my $file = shift;
......@@ -127,7 +138,20 @@ sub parse_entries {
>\*/)?
\s*$
@x) {
my ($name, $value) = ($1, $2);
my ($name, $value, $options) = ($1, $2, $3);
if (defined $options) {
my %options = parse_options($options);
next if defined $options{skip};
if (defined $options{nick}) {
push @nicks, $name, $options{nick};
}
}
elsif (defined $chop) {
my $nick = $name;
$nick =~ s/$chop//;
push @nicks, $name, $nick;
}
$symbols .= $name . ' ';
......@@ -163,7 +187,18 @@ while (<>) {
close (ARGV); # reset line numbering
}
if (/^\s*typedef\s+enum\s*({)?/) {
if (m@^\s*typedef\s+enum\s*
({)?\s*
(?:/\*<
(([^*]|\*(?!/))*)
>\*/)?
@x) {
if (defined $2) {
my %options = parse_options($2);
$chop = $options{"chop"};
} else {
$chop = undef;
}
# Didn't have trailing '{' look on next lines
if (!defined $1) {
while (<>) {
......@@ -173,7 +208,7 @@ while (<>) {
}
}
$symbols = ""; $contig = 1; $before = -1; @mapping = ();
$symbols = ""; $contig = 1; $before = -1; @mapping = (); @nicks = ();
# Now parse the entries
&parse_entries (\*ARGV);
......@@ -188,11 +223,20 @@ while (<>) {
}
$mapping =~ s/,\n\s*$//s;
my $nicks = ""; $pos = 1;
foreach (@nicks) {
$nicks .= $pos++ % 2 ? "$_ => " : "'$_',\n\t\t ";
}
if ($nicks) {
$nicks =~ s/,\n\s*$//s;
$nicks = ",\n\t nicks => { " . $nicks . " }";
}
$code .= <<ENTRY;
$enumname =>
{ contig => $contig,
symbols => [ qw($symbols) ],
mapping => { $mapping }
mapping => { $mapping }$nicks
},
ENTRY
}
......
......@@ -22,8 +22,8 @@ package Gimp::CodeGen::enums;
%enums = (
ConvertPaletteType =>
{ contig => 1,
symbols => [ qw(MAKE_PALETTE REUSE_PALETTE WEB_PALETTE MONO_PALETTE
CUSTOM_PALETTE) ],
symbols => [ qw(MAKE_PALETTE REUSE_PALETTE WEB_PALETTE
MONO_PALETTE CUSTOM_PALETTE) ],
mapping => { MAKE_PALETTE => '0',
REUSE_PALETTE => '1',
WEB_PALETTE => '2',
......@@ -61,7 +61,13 @@ package Gimp::CodeGen::enums;
GRAY_GIMAGE => '2',
GRAYA_GIMAGE => '3',
INDEXED_GIMAGE => '4',
INDEXEDA_GIMAGE => '5' }
INDEXEDA_GIMAGE => '5' },
nicks => { RGB_GIMAGE => 'RGB',
RGBA_GIMAGE => 'RGBA',
GRAY_GIMAGE => 'GRAY',
GRAYA_GIMAGE => 'GRAYA',
INDEXED_GIMAGE => 'INDEXED',
INDEXEDA_GIMAGE => 'INDEXEDA' }
},
GimpImageBaseType =>
{ contig => 1,
......@@ -88,12 +94,111 @@ package Gimp::CodeGen::enums;
ClipToImage => '1',
ClipToBottomLayer => '2',
FlattenImage => '3' }
},
PDBArgType =>
{ contig => 1,
symbols => [ qw(PDB_INT32 PDB_INT16 PDB_INT8 PDB_FLOAT PDB_STRING
PDB_INT32ARRAY PDB_INT16ARRAY PDB_INT8ARRAY
PDB_FLOATARRAY PDB_STRINGARRAY PDB_COLOR
PDB_REGION PDB_DISPLAY PDB_IMAGE PDB_LAYER
PDB_CHANNEL PDB_DRAWABLE PDB_SELECTION
PDB_BOUNDARY PDB_PATH PDB_PARASITE PDB_STATUS
PDB_END) ],
mapping => { PDB_INT32 => '0',
PDB_INT16 => '1',
PDB_INT8 => '2',
PDB_FLOAT => '3',
PDB_STRING => '4',
PDB_INT32ARRAY => '5',
PDB_INT16ARRAY => '6',
PDB_INT8ARRAY => '7',
PDB_FLOATARRAY => '8',
PDB_STRINGARRAY => '9',
PDB_COLOR => '10',
PDB_REGION => '11',
PDB_DISPLAY => '12',
PDB_IMAGE => '13',
PDB_LAYER => '14',
PDB_CHANNEL => '15',
PDB_DRAWABLE => '16',
PDB_SELECTION => '17',
PDB_BOUNDARY => '18',
PDB_PATH => '19',
PDB_PARASITE => '20',
PDB_STATUS => '21',
PDB_END => '22' }
},
PDBStatusType =>
{ contig => 1,
symbols => [ qw(PDB_EXECUTION_ERROR PDB_CALLING_ERROR
PDB_PASS_THROUGH PDB_SUCCESS) ],
mapping => { PDB_EXECUTION_ERROR => '0',
PDB_CALLING_ERROR => '1',
PDB_PASS_THROUGH => '2',
PDB_SUCCESS => '3' }
},
PDBProcType =>
{ contig => 1,
symbols => [ qw(PDB_INTERNAL PDB_PLUGIN PDB_EXTENSION
PDB_TEMPORARY) ],
mapping => { PDB_INTERNAL => '0',
PDB_PLUGIN => '1',
PDB_EXTENSION => '2',
PDB_TEMPORARY => '3' }
},
LayerModeEffects =>
{ contig => 1,
symbols => [ qw(NORMAL_MODE DISSOLVE_MODE BEHIND_MODE
MULTIPLY_MODE SCREEN_MODE OVERLAY_MODE
DIFFERENCE_MODE ADDITION_MODE SUBTRACT_MODE
DARKEN_ONLY_MODE LIGHTEN_ONLY_MODE HUE_MODE
SATURATION_MODE COLOR_MODE VALUE_MODE DIVIDE_MODE
ERASE_MODE REPLACE_MODE) ],
mapping => { NORMAL_MODE => '0',
DISSOLVE_MODE => '1',
BEHIND_MODE => '2',
MULTIPLY_MODE => '3',
SCREEN_MODE => '4',
OVERLAY_MODE => '5',
DIFFERENCE_MODE => '6',
ADDITION_MODE => '7',
SUBTRACT_MODE => '8',
DARKEN_ONLY_MODE => '9',
LIGHTEN_ONLY_MODE => '10',
HUE_MODE => '11',
SATURATION_MODE => '12',
COLOR_MODE => '13',
VALUE_MODE => '14',
DIVIDE_MODE => '15',
ERASE_MODE => '16',
REPLACE_MODE => '17' },
nicks => { NORMAL_MODE => 'NORMAL',
DISSOLVE_MODE => 'DISSOLVE',
BEHIND_MODE => 'BEHIND',
MULTIPLY_MODE => 'MULTIPLY/BURN',
SCREEN_MODE => 'SCREEN',
OVERLAY_MODE => 'OVERLAY',
DIFFERENCE_MODE => 'DIFFERENCE',
ADDITION_MODE => 'ADDITION',
SUBTRACT_MODE => 'SUBTRACT',
DARKEN_ONLY_MODE => 'DARKEN-ONLY',
LIGHTEN_ONLY_MODE => 'LIGHTEN-ONLY',
HUE_MODE => 'HUE',
SATURATION_MODE => 'SATURATION',
COLOR_MODE => 'COLOR',
VALUE_MODE => 'VALUE',
DIVIDE_MODE => 'DIVIDE/DODGE',
ERASE_MODE => 'ERASE',
REPLACE_MODE => 'REPLACE' }
}
);
foreach $e (values %enums) {
$e->{info} = "";
foreach (@{$e->{symbols}}) { $e->{info} .= "$_ ($e->{mapping}->{$_}), " }
foreach (@{$e->{symbols}}) {
my $nick = exists $e->{nicks}->{$_} ? $e->{nicks}->{$_} : $_;
$e->{info} .= "$nick ($e->{mapping}->{$_}), "
}
$e->{info} =~ s/, $//;
}
......
......@@ -17,4 +17,5 @@
# Modify this list for the groups to parse in the pdb directory
@groups = qw(gdisplay edit floating_sel undo palette gradient convert
channel_ops text gimprc drawable parasite paths);
channel_ops gimprc drawable parasite paths gradient_select
unit procedural_db brushes);
......@@ -308,9 +308,16 @@ LGPL
my $hfile = "$destdir/gimp${group}.h$FILE_EXT";
my $cfile = "$destdir/gimp${group}.c$FILE_EXT";
my $protos;
foreach (@{$out->{proto}}) { $protos .= $_ }
chop $protos;
my $extra = {};
if (exists $main::grp{$group}->{extra}->{lib}) {
$extra = $main::grp{$group}->{extra}->{lib}
}
my $body;
$body = $extra->{decls} if exists $extra->{decls};
foreach (@{$out->{proto}}) { $body .= $_ }
$body .= $extra->{protos} if exists $extra->{protos};
chomp $body;
open HFILE, "> $hfile" or die "Can't open $cfile: $!\n";
print HFILE $lgpl;
......@@ -329,7 +336,7 @@ extern "C" {
#endif /* __cplusplus */
$protos
$body
#ifdef __cplusplus
......@@ -345,6 +352,7 @@ HEADER
open CFILE, "> $cfile" or die "Can't open $cfile: $!\n";
print CFILE $lgpl;
print CFILE qq/#include "gimp${group}.h"\n/;
print CFILE "\n", $extra->{code} if exists $extra->{code};
print CFILE $out->{code};
close CFILE;
&write_file($cfile);
......