IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 5955


Ignore:
Timestamp:
Jan 9, 2006, 2:38:15 PM (21 years ago)
Author:
jhoblitt
Message:

determine if the config file is in simple or complex format
move current config logic into simple_config()

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/glueforge/glueforge.in

    r5951 r5955  
    33# Copyright (C) 2005  Joshua Hoblitt
    44#
    5 # $Id: glueforge.in,v 1.38 2006-01-07 04:46:56 jhoblitt Exp $
     5# $Id: glueforge.in,v 1.39 2006-01-10 00:38:15 jhoblitt Exp $
    66
    77use strict;
     
    3636die "file doesn't not contain a valid config" unless defined $config->[0];
    3737
    38 my %data;
    39 
    40 # find table name
    41 my $table_name;
    42 for (my $i = 0; $i < @{$config}; $i++) {
    43     my $elem = $config->[$i];
    44 
    45     if ( $elem->{name} eq "table" ) {
    46         $table_name = $elem->{value};
    47 
    48         # delete element from array
    49         splice @$config, $i, 1;
    50 
    51         last;
    52     }
    53 }
    54 
    55 # global data
    56 $data{pkg_name}         = $table_name . "db";
    57 $data{pkg_namespace}    = $table_name;
    58 
    59 # per table data
    60 my %table;
    61 $table{name}        = $table_name;
    62 $table{namespace}   = $table_name;
    63 $table{object_name} = $table{namespace} . "Row";
    64 
    65 my @items;
    66 
    67 # setup items
    68 for (my $i = 0; $i < @{$config}; $i++) {
    69     my $elem = $config->[$i];
    70 
    71     my $mdtypes = lookup_type( $elem->{type} );
    72     next if ! defined $mdtypes;
    73 
    74     push @items, {
    75         name    => $elem->{name},
    76         type    => $elem->{type},
    77         ctype   => $mdtypes->{ctype},
    78         mtype   => $mdtypes->{mtype},
    79         test    => $mdtypes->{test},
    80         comment => $elem->{comment},
    81         value   => $elem->{value},
    82     };
    83 }
    84 
    85 $table{columns} = \@items;
    86 $data{tables} = [ \%table ];
    87 
    88 $output = $data{pkg_name} unless defined $output;
     38# if the first hash has a class of "metadata" then this is a complex config.
     39# Otherwise it is a simple config.
     40my $complex = ($config->[0]->{class} eq "metadata") ? 1 : 0;
     41
     42my $data; # hashref
     43if ($complex) {
     44#    $data = complex_config($config);
     45} else {
     46    $data = simple_config($config);
     47}
     48
     49# determine output path
     50$output = $data->{pkg_name} unless defined $output;
    8951
    9052my %tt = (
    9153    'autogen_sh.tt'         => "$output/autogen.sh",
    9254    'configure_ac.tt'       => "$output/configure.ac",
    93     'pkgconfig_pc_in.tt'    => "$output/$data{pkg_name}.pc.in",
     55    'pkgconfig_pc_in.tt'    => "$output/$data->{pkg_name}.pc.in",
    9456    'doxyfile_in.tt'        => "$output/Doxyfile.in",
    9557    'top_makefile_am.tt'    => "$output/Makefile.am",
    9658    'src_makefile_am.tt'    => "$output/src/Makefile.am",
    97     'header.tt'             => "$output/src/$data{pkg_name}.h",
    98     'code.tt'               => "$output/src/$data{pkg_name}.c",
     59    'header.tt'             => "$output/src/$data->{pkg_name}.h",
     60    'code.tt'               => "$output/src/$data->{pkg_name}.c",
    9961    'tests_makefile_am.tt'  => "$output/tests/Makefile.am",
    10062    'testsuite_at.tt'       => "$output/tests/testsuite.at",
     
    12082
    12183foreach my $t ( keys %tt ) {
    122     $mangler->process( $t, \%data, $tt{$t})
     84    $mangler->process( $t, $data, $tt{$t})
    12385        or die $mangler->error;
    12486}
     
    187149}
    188150
     151sub simple_config {
     152    my $config = shift;
     153
     154    # find table name
     155    my $table_name;
     156    for (my $i = 0; $i < @{$config}; $i++) {
     157        my $elem = $config->[$i];
     158
     159        if ( $elem->{name} eq "table" ) {
     160            $table_name = $elem->{value};
     161
     162            # delete element from array
     163            splice @$config, $i, 1;
     164
     165            last;
     166        }
     167    }
     168
     169    my %data;
     170
     171    # global data
     172    $data{pkg_name}         = $table_name . "db";
     173    $data{pkg_namespace}    = $table_name;
     174
     175    # per table data
     176    my %table;
     177    $table{name}        = $table_name;
     178    $table{namespace}   = $table_name;
     179    $table{object_name} = $table{namespace} . "Row";
     180
     181    my @items;
     182
     183    # setup items
     184    for (my $i = 0; $i < @{$config}; $i++) {
     185        my $elem = $config->[$i];
     186
     187        my $mdtypes = lookup_type( $elem->{type} );
     188        next if ! defined $mdtypes;
     189
     190        push @items, {
     191            name    => $elem->{name},
     192            type    => $elem->{type},
     193            ctype   => $mdtypes->{ctype},
     194            mtype   => $mdtypes->{mtype},
     195            test    => $mdtypes->{test},
     196            comment => $elem->{comment},
     197            value   => $elem->{value},
     198        };
     199    }
     200
     201    $table{columns} = \@items;
     202    $data{tables} = [ \%table ];
     203
     204    return \%data;
     205}
     206
    189207__END__
    190208
Note: See TracChangeset for help on using the changeset viewer.