Index: /trunk/glueforge/glueforge.in
===================================================================
--- /trunk/glueforge/glueforge.in	(revision 5954)
+++ /trunk/glueforge/glueforge.in	(revision 5955)
@@ -3,5 +3,5 @@
 # Copyright (C) 2005  Joshua Hoblitt
 #
-# $Id: glueforge.in,v 1.38 2006-01-07 04:46:56 jhoblitt Exp $
+# $Id: glueforge.in,v 1.39 2006-01-10 00:38:15 jhoblitt Exp $
 
 use strict;
@@ -36,65 +36,27 @@
 die "file doesn't not contain a valid config" unless defined $config->[0];
 
-my %data;
-
-# find table name
-my $table_name;
-for (my $i = 0; $i < @{$config}; $i++) {
-    my $elem = $config->[$i];
-
-    if ( $elem->{name} eq "table" ) {
-        $table_name = $elem->{value};
-
-        # delete element from array
-        splice @$config, $i, 1;
-
-        last;
-    }
-}
-
-# global data
-$data{pkg_name}         = $table_name . "db";
-$data{pkg_namespace}    = $table_name;
-
-# per table data
-my %table;
-$table{name}        = $table_name;
-$table{namespace}   = $table_name;
-$table{object_name} = $table{namespace} . "Row";
-
-my @items;
-
-# setup items
-for (my $i = 0; $i < @{$config}; $i++) {
-    my $elem = $config->[$i];
-
-    my $mdtypes = lookup_type( $elem->{type} );
-    next if ! defined $mdtypes;
-
-    push @items, {
-        name    => $elem->{name},
-        type    => $elem->{type},
-        ctype   => $mdtypes->{ctype},
-        mtype   => $mdtypes->{mtype},
-        test    => $mdtypes->{test},
-        comment => $elem->{comment},
-        value   => $elem->{value},
-    };
-}
-
-$table{columns} = \@items;
-$data{tables} = [ \%table ];
-
-$output = $data{pkg_name} unless defined $output;
+# if the first hash has a class of "metadata" then this is a complex config.
+# Otherwise it is a simple config.
+my $complex = ($config->[0]->{class} eq "metadata") ? 1 : 0;
+
+my $data; # hashref
+if ($complex) {
+#    $data = complex_config($config);
+} else {
+    $data = simple_config($config);
+}
+
+# determine output path
+$output = $data->{pkg_name} unless defined $output;
 
 my %tt = (
     'autogen_sh.tt'         => "$output/autogen.sh",
     'configure_ac.tt'       => "$output/configure.ac",
-    'pkgconfig_pc_in.tt'    => "$output/$data{pkg_name}.pc.in",
+    'pkgconfig_pc_in.tt'    => "$output/$data->{pkg_name}.pc.in",
     'doxyfile_in.tt'        => "$output/Doxyfile.in",
     'top_makefile_am.tt'    => "$output/Makefile.am",
     'src_makefile_am.tt'    => "$output/src/Makefile.am",
-    'header.tt'             => "$output/src/$data{pkg_name}.h",
-    'code.tt'               => "$output/src/$data{pkg_name}.c",
+    'header.tt'             => "$output/src/$data->{pkg_name}.h",
+    'code.tt'               => "$output/src/$data->{pkg_name}.c",
     'tests_makefile_am.tt'  => "$output/tests/Makefile.am",
     'testsuite_at.tt'       => "$output/tests/testsuite.at",
@@ -120,5 +82,5 @@
 
 foreach my $t ( keys %tt ) {
-    $mangler->process( $t, \%data, $tt{$t})
+    $mangler->process( $t, $data, $tt{$t})
         or die $mangler->error;
 }
@@ -187,4 +149,60 @@
 }
 
+sub simple_config {
+    my $config = shift;
+
+    # find table name
+    my $table_name;
+    for (my $i = 0; $i < @{$config}; $i++) {
+        my $elem = $config->[$i];
+
+        if ( $elem->{name} eq "table" ) {
+            $table_name = $elem->{value};
+
+            # delete element from array
+            splice @$config, $i, 1;
+
+            last;
+        }
+    }
+
+    my %data;
+
+    # global data
+    $data{pkg_name}         = $table_name . "db";
+    $data{pkg_namespace}    = $table_name;
+
+    # per table data
+    my %table;
+    $table{name}        = $table_name;
+    $table{namespace}   = $table_name;
+    $table{object_name} = $table{namespace} . "Row";
+
+    my @items;
+
+    # setup items
+    for (my $i = 0; $i < @{$config}; $i++) {
+        my $elem = $config->[$i];
+
+        my $mdtypes = lookup_type( $elem->{type} );
+        next if ! defined $mdtypes;
+
+        push @items, {
+            name    => $elem->{name},
+            type    => $elem->{type},
+            ctype   => $mdtypes->{ctype},
+            mtype   => $mdtypes->{mtype},
+            test    => $mdtypes->{test},
+            comment => $elem->{comment},
+            value   => $elem->{value},
+        };
+    }
+
+    $table{columns} = \@items;
+    $data{tables} = [ \%table ];
+
+    return \%data;
+}
+
 __END__
 
