#!/usr/bin/perl use warnings; use strict; use Getopt::Long; use Data::Dumper; use lib "$ENV{HOME}/public_perl/"; use zot; sub stringy { my $thing = shift; if (ref $thing) { return join ', ', @$thing; } elsif ($thing) { return $thing; } else { return 'Unspecified'; } } our (%opts); GetOptions(\%opts, 'table=s', 'zotfile=s', 'database=s', 'skeleton=s', 'opts=s%', 'help'); if (($opts{'help'}) || !( ($opts{'table'}) && ($opts{'zotfile'}) && ($opts{'database'}) && ($opts{'skeleton'}))) { print( "Usage: zot2gfd [options]\n", "writes out a GNUe Form Definition for a given table\n", "options are:\n", " --table table mandatory. The name of the table.\n", " --zotfile zot mandatory. The zotfile that holds the database schema.\n", " --database db mandatory. The name of the connection (from connections.conf).\n", " --skeleton skel mandatory. The name of the skeleton file.\n", " --opts opt=arg set additional options. May be specified many times.\n", " (defined in the skeleton)\n", " --help shows this message and exits.\n", "\nOptions may be abbreviated if inambiguous.\n"); exit 1; } open( ZOT, $opts{'zotfile'} ) or die( "Unable to open $opts{zotfile}" ); open( SKEL, $opts{'skeleton'} ) or die( "Unable to open $opts{skeleton}" ); $opts{$_} = $opts{'opts'}{$_} foreach (keys %{$opts{'opts'}} ); delete $opts{'opts'}; $opts{'historytables'} ||= []; $opts{'conditions'} ||= ''; $opts{'id'} ||= "$opts{table}.id"; $opts{'rid'} ||= $opts{'id'}; $opts{'name_field'} ||= "_$opts{table}_data.name"; $opts{'tables'} = [ delete $opts{'table'} ]; my %s = zot::parse(); my $table = $opts{'tables'}[0]; while ($s{$table}{'PARENT'}) { $table = $s{$table}{'PARENT'}; push @{ $opts{'tables'} }, $table; } die("multiple tables not supported yet :(") if (@{$opts{tables}} > 1); foreach $table (@{$opts{'tables'}}) { if ($s{$table}{'__HISTORY__'}) { push @{$opts{'tables'}}, "_${table}_data"; push @{$opts{'historytables'}}, "_${table}_data"; $opts{'conditions'} .= qq' \n '; $opts{'conditions'} .= qq' \n '; } } undef $/; my $skel = ; $skel =~ s/\@_(.+?)_\@/stringy($opts{lc $1})/ge; print $skel; #print Dumper \%opts;