#!/usr/bin/perl
# ISDK - Information System Development Kit
# Copyright (C) 1998-1999 Szilard Hajba, Peter Vazsonyi
#
# 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
# Library General Public License for more details.
#
# You should have received a copy of the GNU Library General Public
# License along with this library; if not, write to the Free
# Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

# Variables:
#	$fml_obj{form}{name}=tag
#	$fml_tbl{form}=table
#	$sql_obj{table}{name}=type

sub parse_sql {
    my ($file)=@_;
    my ($lnum, $ln)=(0);
    open FILE, $file;
    $file =~ /(\/)?([a-zA-Z0-9_.]+)$/;
    push @index, "File: '$2'\n";
    while ($ln=<FILE>) {
	if ($ln =~ /^\s*CREATE\s*(TABLE|VIEW|FUNCTION)\s*(\w+)\s*/) {
	    push @tags, "$2\t$file\t/^ \\*CREATE \\*$1 \\*$2 \\*(\\.\\*\$/;\"\tf\n";
	    push @index, "    $1 $2\n";
#	} elsif ($ln =~ /^\s*CREATE\s*/) {
#	    $tbl="";
#	} elsif ($ln =~ /^\s+(\w+)\s*(\@?\w+).*$/) {
#	    $sql_obj{$tbl}{$1}=$2 if ($tbl);
	}
	$lnum++;
    }
    close FILE;
}

while ($ARGV[0]) {
    parse_sql($ARGV[0]);
    shift;
}

open FILE, ">tags";
print FILE "!_TAG_FILE_FORMAT\t2\t/extended format; --format=1 will not append ;\"\n";
print FILE "!_TAG_FILE_SORTED\t1\t/0=unsorted, 1=sorted/\n";
print FILE "!_TAG_PROGRAM_AUTHOR\tSzilard Hajba  /szilu\@revai.hu/\n";
print FILE "!_TAG_PROGRAM_NAME\tsqltags\t//\n";
print FILE "!_TAG_PROGRAM_VERSION\t1.99.0\n";
print FILE (sort @tags);
close FILE;

open FILE, ">index.tables";
print FILE (@index);
#foreach $k (keys %tags) {
#    print FILE "$k\n";
#}
close FILE;
