#!/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_fml {
    my ($file)=@_;
    my ($lnum, $ln)=(0);
    undef $/;
    open FILE, $file;
    my($fml, $form)=(<FILE>);
    $fml =~ s/#[^\n]*\n//g;
    $fml =~ s/\n[ \t]*/ /g;
    while ($fml) {
	if ($fml =~ /^[^(]*\(\/?(\w+)[^)]*name=(\w+)[^)]*\)/) {
	    my ($tag, $name)=($1, $2);
	    if ($tag eq 'form') {
		$form=$name;
		push @tags, "$name\t$file\t/(form\\.\\*name=$name\\.\\*)/;\"\tf\n";
	    } elsif (grep(/ $tag /, ' form tlist alarm pixmap ')) {
		push @tags, "$name\t$file\t/($tag\\.\\*name=$name\\.\\*)/;\"\tf\n";
	    } else {
#		push @tags, "$form:$name\t$file\t/($tag\\.\\*name=$name\\.\\*)/;\"\tf\n";
#		push @tags, "\@\$$form:$name\t$file\t/($tag\\.\\*name=$name\\.\\*)/;\"\tf\n";
#		push @tags, "\@\*$form:$name\t$file\t/($tag\\.\\*name=$name\\.\\*)/;\"\tf\n";
	    }
	}
	$fml =~ s/^[^(]*\([^)]*\)[^(]*//;
    }
    close FILE;
}

if ($ARGV[0] eq '-a') {
    open FILE, "tags";
    @tags=grep {!/^!/} <FILE>;
    close FILE;
    shift;
}
while ($ARGV[0]) {
    parse_fml($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\tfmltags\t//\n";
print FILE "!_TAG_PROGRAM_VERSION\t1.99.0\n";
print FILE (sort @tags);
close FILE;
