#!/usr/bin/perl -w

use warnings;
use strict;

# Location of master GUI file
my $guipath = "Master.gui.test";
open GUIFILE, $guipath or die $!;

my $desc = 0;

# Current file name
my $currfile = "";

# Variables used in loop
my $screen;
my $screenname;
my $fldname;

while (<GUIFILE>) {
    chomp;

    if (!$desc and /^(\w+):$/) {
        print "Screen name: $1\n";
    } elsif (/^\{$/) {
        print "Start of block\n";
        $desc = 1;
    } elsif (/^\}$/) {
        # End of a description block
        print "End of block\n";
        $desc = 0;
    } elsif (!$desc and /^"?$screen"?\.(.+):/) {
        print "Field name: $1\n";
        # Strip quotes from field name
        ($fldname = $1) =~ tr/"//d;
    } elsif ($desc and /^\s*id:\s*(\d+)$/) {
        print "ID for field $fldname: $1\n";
    } else {
        print "(ignored)\n";
    }
} # end while <GUIFILE>
close GUIFILE;
