#	parse_template.pl

%list_data = (
	"LIST_TITLE",   "Current Versions Of Software",
	"MAIN_KEY",	"p package",
	"DATA_FIELD 1",	"c contact",
	"DATA_FIELD 2",	"l location",
	"GLOBAL_SEARCH","g globally",
	"DYNAMIC_REF",  "dynamic",
	"DESCRIPTION",	"d description",
	"LOCAL_VAR 1",	"\$show_description = 0",
);


#	here's where we decide how to parse the different %list_data entries
%parse_routines = (
	"MAIN_KEY", 		"&parse_primary",
	"DATA_FIELD",		"&parse_data_field",
	"GLOBAL_SEARCH",	"&parse_global_search",
	"DYNAMIC_REF",		"&parse_dref",
	"DESCRIPTION",		"&parse_description",
	"LOCAL_VAR",		"&parse_local_var",

        "LIST_TITLE",           0,
	"CORE_ADD_ROUTINES",	0,
	"CORE_SEARCH_ROUTINES",	0,
	"CORE_HELP_ROUTINES",	0,

	"INPUT_SPOOL_ROUTINES",	0,
	"INPUT_SPOOL_FILES",	0,
	"INPUT_SPOOL_DIRS",	0,
);




sub parse_definition {
    $num_data_fields = 0;
    %check_key = ();
    $list_syms{"RESET_LIST"} = ();
    $list_syms{"LIST_TITLE"} = $list_data{"LIST_TITLE"};
    foreach $ld_item (keys %list_data) {
	($routine_item, $ignore) = split(' ', $ld_item);
	$fstr = "$parse_routines{$routine_item}(\"$list_data{$ld_item}\")";
	eval $fstr;
    }
    $list_syms{"ADD_MENU_STRS"} = ();
    $list_syms{"SEARCH_MENU_STRS"} = ();
    &init_add_menu_strs;
    1;
}

sub parse_primary {
    local($key_str) = @_;
    
    ($keystroke, $key_str) = split(' ', $key_str);
    &make_data_input_routine($keystroke, $key_str, "MAIN_VAL");
    $list_syms{"MAIN"} = $key_str;
    $list_syms{"MAIN_KS"} = $keystroke;
    $list_syms{"MAIN_VAL"} = '';
    &parse_check_key($keystroke, "MAIN_KEY ($key_str)");
    1;
}

sub parse_data_field {
    local($key_str) = @_;
    
    $num_data_fields++;
    ($keystroke, $key_str) = split(/[ \t]+/, $key_str);

    &make_data_input_routine($keystroke, $key_str,
			     "DATA_VAL" . $num_data_fields);
    &make_data_search_routine($keystroke, $key_str);

    $list_syms{"DATA_" . $num_data_fields} = $key_str;
    $list_syms{"DATA_KS" . $num_data_fields} = $keystroke;
    $list_syms{"DATA_VAL" . $num_data_fields} = '';
    &parse_check_key($keystroke, "DATA_FIELD $num_data_fields ($key_str)");
    1;
}

sub parse_global_search { 
    1;
}

sub parse_dref {
    local($dref_str) = @_;
    $list_syms{"DYNAMIC_REF"} = $dref_str;
    1;
}

sub parse_description {
    local($desc_str) = @_;
    
    ($keystroke, $desc_str) = split(' ', $desc_str);
    
    $list_syms{"DESCRIPTION"} = $desc_str;
    $list_syms{"DESCRIPTION_KS"} = $keystroke;
    $list_syms{"DESCRIPTION_STAT"} = "not edited";
    &make_description_input_routine($keystroke);
    &parse_check_key($keystroke, "DESCRIPTION ($desc_str)");
    1;
}

sub parse_local_var {

    1;
}


sub parse_check_key {
    local($keystroke, $desc_str) = @_;

    if (defined($check_key{$keystroke})) {
	print TTYOUT <<EOS;

	hey! "$keystroke" for "$desc_str" interferes with
             "$keystroke" for "$check_key{$keystroke}"!

        This is something that should be corrected in the template, or
your list will not behave properly.

EOS
        print TTYOUT "\tpress any key..."; &flush;
	read (TTYIN, $ans, 1);
    } else {
	$check_key{$keystroke} = $desc_str;
    }
    1;
}

1;
