Commit 6f55271a authored by Manish Singh's avatar Manish Singh
Browse files

Bunch more stuff

-Yosh
parent 98e1bdca
......@@ -24,21 +24,16 @@ $destdir = "$main::destdir/app";
*arg_ptype = \&Gimp::CodeGen::pdb::arg_ptype;
*arg_vname = \&Gimp::CodeGen::pdb::arg_vname;
*enums = \%Gimp::CodeGen::enums::enums;
*write_file = \&Gimp::CodeGen::util::write_file;
*FILE_EXT = \$Gimp::CodeGen::util::FILE_EXT;
%testmap = (
'<' => '>',
'>' => '<',
'<=' => '>=',
'>=' => '<='
);
sub declare_args {
my $proc = shift;
my $out = shift;
my $result = "";
local $result = "";
foreach (@_) {
my @args = @{$proc->{$_}} if exists $proc->{$_};
......@@ -51,9 +46,10 @@ sub declare_args {
}
unless (exists $_->{no_declare}) {
my $type = $arg->{type};
$result .= ' ' x 2 . $type . &arg_vname($_);
$result .= ' = NULL' if exists $_->{init} && $type =~ /\*$/;
$result .= ' ' x 2 . $arg->{type} . &arg_vname($_);
if (!exists $_->{no_init} && exists $_->{init}) {
$result .= $arg->{type} =~ /\*$/ ? ' = NULL' : '0'
}
$result .= ";\n";
if (exists $arg->{id_headers}) {
......@@ -61,13 +57,6 @@ sub declare_args {
$out->{headers}->{$_}++;
}
}
if (exists $_->{get}) {
my $type = $arg_types{$_->{get}->{type}}->{type};
$result .= ' ' x 2 . $type . &arg_vname($_->{get});
$result .= ' = NULL' if $type =~ /\*$/;
$result .= ";\n";
}
}
}
}
......@@ -88,17 +77,28 @@ sub make_args {
$result .= "\nstatic ProcArg $proc->{name}_${_}[] =";
$result .= "\n{\n";
foreach my $arg (@{$proc->{$_}}) {
my ($type) = &arg_parse($arg->{type});
local ($desc) = "";
$desc = 'TRUE or FALSE' if $type eq 'boolean';
foreach $arg (@{$proc->{$_}}) {
my ($type, $name, @remove) = &arg_parse($arg->{type});
my $desc = $arg->{desc};
my $info = $arg->{type};
for ($type) {
/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};
foreach (@remove) {
$info =~ s/$_ \(.*?\)(, )?//
} last };
}
$desc =~ s/%%desc%%/$info/eg;
$result .= <<CODE;
{
PDB_$arg_types{$type}->{name},
"$arg->{name}",
"@{[ eval qq/"$arg->{desc}"/ ]}"
"$desc"
},
CODE
}
......@@ -125,61 +125,81 @@ sub marshal_inargs {
my $arg = $arg_types{$pdbtype};
my $type = &arg_ptype($arg);
my $var = &arg_vname($_);
if (exists $arg->{id_func}) {
my $test = exists $_->{on_success} ? '!=' : '==';
$result .= <<CODE;
if (($var = $arg->{id_func} (args[$argc].value.pdb_$type)) == NULL)
success = FALSE;
if (($var = $arg->{id_func} (args[$argc].value.pdb_$type)) $test NULL)
CODE
$result .= <<CODE if exists $_->{get};
$result .= <<CODE if exists $_->{on_success};
$_->{on_success}
else
@{[ &arg_vname($_->{get}) ]} = @{[ eval qq/"$arg->{$_->{get}->{type}}"/ ]};
CODE
$result .= ' ' x 4 . "success = FALSE;\n";
$success = 1;
}
else {
if ($pdbtype eq 'enum') {
# FIXME: implement this
my $code = ' ' x 2 . "$var =";
my $cast = "";
if ($type eq 'pointer' || $arg->{type} =~ /int(16|8)$/) {
$cast = " ($arg->{type})";
}
elsif ($pdbtype eq 'boolean') {
$result .= ' ' x 2 . "$var = ";
$result .= "args[$argc].value.pdb_$type ? TRUE : FALSE;\n";
$code .= "$cast args[$argc].value.pdb_$type";
$code .= ' ? TRUE : FALSE' if $pdbtype eq 'boolean';
$code .= ";\n";
if ($pdbtype eq 'string') {
$code .= ' ' x 2 . "success = $var != NULL;\n";
}
else {
my $cast = "";
elsif (defined $typeinfo[0] || defined $typeinfo[2]) {
my $tests = 0; my $extra = "";
$cast = " ($arg->{type})" if $type eq "pointer";
$cast = " ($arg->{type})" if $arg->{type} =~ /int(16|8)$/;
if ($pdbtype eq 'enum') {
my $name = pop @typeinfo;
$result .= ' ' x 2 . "$var =";
$result .= "$cast args[$argc].value.pdb_$type;\n";
foreach (@typeinfo) { $extra .= " && $var != $_" }
if ($pdbtype eq 'string') {
$result .= ' ' x 2 . "success = $var != NULL;\n";
$success = 1;
$typeinfo[0] = $enums{$name}->{start};
$typeinfo[1] = '>=';
$typeinfo[2] = $enums{$name}->{end};
$typeinfo[3] = '<=';
}
elsif (defined $typeinfo[0] || defined $typeinfo[2]) {
my $tests = 0;
$result .= ' ' x 2 . "success = ";
$code .= ' ' x 2 . "success = ";
if (defined $typeinfo[0]) {
$result .= "$var $testmap{$typeinfo[1]} $typeinfo[0]";
$tests++;
}
if (defined $typeinfo[0]) {
$code .= "$var $typeinfo[1] $typeinfo[0]";
$tests++;
}
if (defined $typeinfo[2]) {
$result .= '|| ' if $tests;
$result .= "$var $testmap{$typeinfo[2]} $typeinfo[3]";
}
if (defined $typeinfo[2]) {
$code .= ' && ' if $tests;
$code .= "$var $typeinfo[3] $typeinfo[2]";
}
$result .= ";\n";
$code .= "$extra;\n";
}
$success = 1;
if ($code =~ /success/) {
if ($success) {
$code =~ s/^/' ' x 4/meg;
$code =~ s/^ {8}/\t/mg;
$code .= ' ' x 4 . "}\n";
$result .= ' ' x 2 . "if (success)\n" . ' ' x 4 . "{\n";
}
else {
$success_init = 0;
}
$success = 1;
}
$result .= $code;
}
$argc++; $result .= "\n";
......@@ -240,7 +260,7 @@ sub generate {
my %out;
my $total = 0.0;
foreach my $name (@procs) {
foreach $name (@procs) {
my $proc = $main::pdb{$name};
my $out = \%{$out{$proc->{group}}};
......@@ -248,6 +268,7 @@ sub generate {
my @outargs = @{$proc->{outargs}} if exists $proc->{outargs};
local $success = 0;
local $success_init = 1;
$out->{pcount}++; $total++;
......@@ -258,7 +279,7 @@ sub generate {
CODE
if (exists $proc->{invoke}->{headers}) {
foreach my $header (@{$proc->{invoke}->{headers}}) {
foreach $header (@{$proc->{invoke}->{headers}}) {
$out->{headers}->{$header}++;
}
}
......@@ -300,8 +321,11 @@ CODE
$success = ($code =~ /success =/) unless $success;
if ($success) {
$out->{code} .= ' ' x 2;
$out->{code} .= "int success = $proc->{invoke}->{success};\n";
$success_init = 0 if $proc->{invoke}->{success} eq 'NONE';
$out->{code} .= ' ' x 2 . "gboolean success";
$out->{code} .= " = $proc->{invoke}->{success}" if $success_init;
$out->{code} .= ";\n";
}
$out->{code} .= $invoker . $code . "\n";
......@@ -376,7 +400,7 @@ HEADER
my $cfile = "$destdir/${group}_cmds.c$FILE_EXT";
open CFILE, "> $cfile" or die "Can't open $cmdfile: $!\n";
print CFILE $gpl;
foreach my $header (sort keys %{$out->{headers}}) {
foreach $header (sort keys %{$out->{headers}}) {
print CFILE "#include $header\n";
}
print CFILE "\n";
......
# The GIMP -- an image manipulation program
# Copyright (C) 1998 Manish Singh <yosh@gimp.org>
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
package Gimp::CodeGen::enums;
%enums = (
ConvertPaletteType =>
{ name => 'ConvertPaletteType', base => 0,
symbols => [ qw(MAKE_PALETTE REUSE_PALETTE WEB_PALETTE MONO_PALETTE
CUSTOM_PALETTE) ] }
);
foreach $enum (values %enums) {
$enum->{start} = $enum->{symbols}->[0];
$enum->{end} = $enum->{symbols}->[$#{$enum->{symbols}}];
my $pos = 0; $enum->{info} = "";
foreach (@{$enum->{symbols}}) { $enum->{info} .= "$_ ($pos), "; $pos++ }
$enum->{info} =~ s/, $//;
}
1;
......@@ -36,7 +36,7 @@ sub generate {
$type;
}
foreach my $name (@procs) {
foreach $name (@procs) {
my $proc = $main::pdb{$name};
my $out = \%{$out{$proc->{group}}};
......
......@@ -33,49 +33,36 @@ package Gimp::CodeGen::pdb;
color => { name => 'COLOR' , type => 'guchar *' },
display => {
name => 'DISPLAY',
type => 'GDisplay *',
id_func => 'gdisplay_get_ID',
id_ret_func => '$var->ID',
id_headers => [ qw("gdisplay.h") ]
},
image => {
name => 'IMAGE',
type => 'GimpImage *',
id_func => 'pdb_id_to_image',
id_ret_func => 'pdb_image_to_id ($var)',
id_headers => [ qw("procedural_db.h") ]
},
layer => {
name => 'LAYER',
type => 'GimpLayer *',
id_func => 'layer_get_ID',
id_ret_func => 'drawable_ID (GIMP_DRAWABLE ($var))',
id_headers => [ qw("drawable.h" "layer.h") ]
},
channel => {
name => 'CHANNEL',
type => 'Channel *',
id_func => 'channel_get_ID',
id_ret_func => 'drawable_ID (GIMP_DRAWABLE ($var))',
id_headers => [ qw("drawable.h" "channel.h") ]
},
drawable => {
name => 'DRAWABLE',
type => 'GimpDrawable *',
id_func => 'gimp_drawable_get_ID',
id_ret_func => 'drawable_ID (GIMP_DRAWABLE ($var))',
id_headers => [ qw("drawable.h") ],
image => 'drawable_gimage (GIMP_DRAWABLE ($var))'
},
selection => {
name => 'SELECTION',
type => 'Channel *',
id_func => 'channel_get_ID',
id_ret_func => 'drawable_ID (GIMP_DRAWABLE ($var))',
id_headers => [ qw("drawable.h" "channel.h") ]
},
display => { name => 'DISPLAY',
type => 'GDisplay *',
id_func => 'gdisplay_get_ID',
id_ret_func => '$var->ID',
id_headers => [ qw("gdisplay.h") ] },
image => { name => 'IMAGE',
type => 'GimpImage *',
id_func => 'pdb_id_to_image',
id_ret_func => 'pdb_image_to_id ($var)',
id_headers => [ qw("procedural_db.h") ] },
layer => { name => 'LAYER',
type => 'GimpLayer *',
id_func => 'layer_get_ID',
id_ret_func => 'drawable_ID (GIMP_DRAWABLE ($var))',
id_headers => [ qw("drawable.h" "layer.h") ] },
channel => { name => 'CHANNEL',
type => 'Channel *',
id_func => 'channel_get_ID',
id_ret_func => 'drawable_ID (GIMP_DRAWABLE ($var))',
id_headers => [ qw("drawable.h" "channel.h") ] },
drawable => { name => 'DRAWABLE',
type => 'GimpDrawable *',
id_func => 'gimp_drawable_get_ID',
id_ret_func => 'drawable_ID (GIMP_DRAWABLE ($var))',
id_headers => [ qw("drawable.h") ] },
selection => { name => 'SELECTION',
type => 'Channel *',
id_func => 'channel_get_ID',
id_ret_func => 'drawable_ID (GIMP_DRAWABLE ($var))',
id_headers => [ qw("drawable.h" "channel.h") ] },
boundary => { name => 'BOUNDARY', type => 'gpointer ' }, # ??? FIXME
path => { name => 'PATH' , type => 'gpointer ' }, # ??? FIXME
......@@ -90,12 +77,28 @@ package Gimp::CodeGen::pdb;
# Split out the parts of an arg constraint
sub arg_parse {
my %testmap = (
'<' => '>',
'>' => '<',
'<=' => '>=',
'>=' => '<='
);
my $arg = shift;
if ($arg =~ /^enum (\w+)/) {
return ('enum', $1);
if ($arg =~ /^enum (\w+)(.*)/) {
my ($name, $remove) = ($1, $2);
my @retvals = ('enum', $name);
if ($remove && $remove =~ / \(no /) {
$remove =~ s/ \(no (.*?)\)$/$1/;
push @retvals, split(/,\s*/, $remove);
}
return @retvals;
}
if ($arg =~ /^([\d\.-].*?)? *(<=|<)? *(\w+) *(<=|<)? *([\d\.-].*?)?/) {
return ($3, $1, $2, $5, $4);
elsif ($arg =~ /^([\d\.-].*?)? *(<=|<)? *(\w+) *(<=|<)? *([\d\.-].*?)?/) {
return ($3, $1, $2 ? $testmap{$2} : $2, $5, $4 ? $testmap{$4} : $4);
}
}
......
......@@ -35,12 +35,12 @@ HELP
@inargs = (
{ name => 'drawable', type => 'drawable',
desc => 'The drawable to offset', get => &std_image_arg },
desc => 'The drawable to offset' },
{ name => 'wrap_around', type => 'boolean',
desc => 'wrap image around or fill vacated regions' },
{ name => 'fill_type', type => 'enum GimpOffsetType',
desc => 'fill vacated regions of drawable with background or
transparent: $desc' },
transparent: %%desc%%' },
{ name => 'offset_x', type => 'int32',
desc => 'offset by this amount in X direction' },
{ name => 'offset_y', type => 'int32',
......@@ -49,8 +49,12 @@ HELP
%invoke = (
headers => [ qw(channel_ops.h) ],
vars => ['GimpImage *gimage'],
code => <<'CODE'
offset (gimage, drawable, wrap_around, fill_type, offset_x, offset_y);
{
gimage = drawable_gimage (GIMP_DRAWABLE (drawable));
offset (gimage, drawable, wrap_around, fill_type, offset_x, offset_y);
}
CODE
);
}
......
......@@ -115,14 +115,14 @@ HELP
&std_image_arg,
{ name => 'dither', type => 'boolean',
desc => 'Floyd-Steinberg dithering' },
{ name => 'palette_type', type => 'enum GimpDitherPaletteType',
desc => 'The type of palette to use: $desc' },
{ name => 'palette_type', type => 'enum ConvertPaletteType',
desc => 'The type of palette to use: %%desc%%' },
{ name => 'num_cols', type => 'int32',
desc => 'the number of colors to quantize to, ignored unless
(palette_type == 0)' },
(palette_type == MAKE_PALETTE)' },
{ name => 'palette', type => 'string',
desc => 'The name of the custom palette to use, ignored unless
(palette_type == 4)' }
(palette_type == CUSTOM_PALETTE)' }
);
%invoke = (
......
......@@ -64,7 +64,7 @@ HELP
@inargs = (
&drawable_arg,
{ name => 'fill_type', type => 'enum GimpFillType',
desc => 'The type of fill: $desc' }
desc => 'The type of fill: %%desc%%' }
);
%invoke = (
......
......@@ -21,8 +21,7 @@
sub inargs {
@inargs = (
{ name => 'drawable', type => 'drawable',
desc => "The drawable to @{[shift]}",
get => &std_image_arg }
desc => "The drawable to @{[shift]}" }
);
}
......@@ -30,7 +29,13 @@ sub inargs {
sub invoke {
%invoke = (
headers => [ qw("global_edit.h") ],
code => "success = @{[shift]};"
vars => ['GimpImage *gimage'],
code => <<CODE
{
gimage = drawable_gimage (GIMP_DRAWABLE (drawable));
success = @{[shift]};
}
CODE
);
}
......@@ -102,7 +107,7 @@ HELP
&invoke('layer != NULL');
$cmd = "layer = edit_paste (gimage, drawable, global_buf, paste_into);\n";
$invoke{code} = "{\n" . ' ' x 2 . $cmd . ' ' x 2 . $invoke{code} . "\n}\n";
$invoke{code} =~ s/(success.*$)/"$cmd $1"/me;
}
sub edit_clear {
......
......@@ -31,10 +31,10 @@ sub invoke {
headers => [ qw("layer.h" "floating_sel.h") ],
code => <<CODE
{
if (!layer_is_floating_sel (floating_sel))
success = FALSE;
else
if (layer_is_floating_sel (floating_sel))
$cmd (floating_sel);
else
success = FALSE;
}
CODE
);
......@@ -123,7 +123,7 @@ HELP
&std_pdb_misc;
&inargs;
push @inargs, { name => 'undo', type => 'boolean', desc => '$desc' };
push @inargs, { name => 'undo', type => 'boolean', desc => '%%desc%%' };
&invoke;
$invoke{code} =~ s/\(floating_sel\);/(floating_sel, undo);/;
......@@ -139,7 +139,7 @@ HELP
&std_pdb_misc;
&inargs;
push @inargs, { name => 'undo', type => 'boolean', desc => '$desc' };
push @inargs, { name => 'undo', type => 'boolean', desc => '%%desc%%' };
&invoke;
$invoke{code} =~ s/\(floating_sel\);/(floating_sel, undo);/;
......
......@@ -44,6 +44,7 @@ HELP
%invoke = (
headers => [ qw("gradient.h") ],
vars => ['gradient_t *grad', 'GSList *list', 'int i = 0'],
success => 'NONE',
code => <<'CODE'
{
gradients = g_new (gchar *, num_gradients);
......@@ -101,7 +102,6 @@ HELP
);
%invoke = (
success => 'FALSE',
headers => [ qw("gradient.h") ],
code => 'success = grad_set_grad_to_name (name);'
);
......
......@@ -40,7 +40,7 @@ HELP
{ name => 'sample_size', type => '0 < int32 < 10000',
desc => 'The size of the sample to return when the gradient is
changed $desc',
on_fail => 'G_SAMPLE' }
on_fail => 'sample_size = G_SAMPLE;' }
);
@outargs = (
......
......@@ -44,6 +44,7 @@ HELP
%invoke = (
headers => [ qw("gradient.h") ],
vars => ['gradient_t *grad', 'GSList *list', 'int i = 0'],
success => 'NONE',
code => <<'CODE'
{
gradients = g_new (gchar *, num_gradients);
......@@ -101,7 +102,6 @@ HELP
);
%invoke = (
success => 'FALSE',
headers => [ qw("gradient.h") ],
code => 'success = grad_set_grad_to_name (name);'
);
......
This diff is collapsed.
This diff is collapsed.
......@@ -67,7 +67,7 @@ HELP
@outargs = (
{ name => "${type}_type", type => 'enum PDBArgType',
desc => "The type of $long_type \$desc",
desc => "The type of $long_type %%desc%%",
alias => "${type}->arg_type" },
{ name => "${type}_name", type => 'string',
desc => "The name of the $long_type",
......@@ -205,7 +205,7 @@ HELP
{ name => 'date', type => 'string',
desc => 'Copyright date' },
{ name => 'proc_type', type => 'enum PDBProcType',
desc => 'The procedure type: $desc' },
desc => 'The procedure type: %%desc%%' },
{ name => 'num_args', type => 'int32',
desc => 'The number of input arguments' },
{ name => 'num_values', type => 'int32',
......
This diff is collapsed.
This diff is collapsed.
......@@ -65,7 +65,7 @@ $evalcode = <<'CODE';
$grp{$file}->{desc} = $desc if defined $desc;
$grp{$file}->{code} = $code if defined $code;
foreach my $proc (@procs) {
foreach $proc (@procs) {
# Reset all our PDB vars so previous defs don't interfere
foreach (@procvars) { eval "undef $_" }
......@@ -108,6 +108,7 @@ foreach $file (@groups) {
# Some important stuff
require 'pdb.pl';
require 'enums.pl';
require 'util.pl';
# Squash whitespace into just single spaces between words
......