#! @TCL@ -f
#
# file: dec_quit_0.tcl
#

# this procedure exits the program cleanly
#
proc quit_proc {} {

    # import globals
    #
    global decoder_pipe
    global pipe_flag
    global tmp_outfile
    global tmp_infile
    global tmp_latfile
    global tmp_lmfile
    global debug_file

    # close the process if running
    #
    if {$pipe_flag == 1} {

        puts $debug_file "before close pipe : $pipe_flag"
        flush $debug_file
 
	catch {
	    puts $decoder_pipe "-1\n"
	    flush $decoder_pipe
	    close $decoder_pipe
	}

	set pipe_flag 0
    }

    # delete the temporary files
    #
    if {[file exists $tmp_outfile] == 1} {
	exec rm $tmp_outfile
	exec rm $tmp_infile
	exec rm $tmp_latfile
#	exec rm $tmp_lmfile
    }

    # exit the program
    #
    exit
}

# procedure to display a required message
#
proc message_proc {msg} {

    # declare globals
    #
    global p

    # set the message string
    #
    set msg [string trim $msg]

    # display the text in the message area
    #
    $p.message configure -text $msg
}

# create brief on-line help for each button
#
bind $p.reset <ButtonPress-2> {
    message_proc "Reset the decoder to the start point."
    after 1000 {message_proc ""}
}
bind $p.config <ButtonPress-2> {
    message_proc "Configure the decoder to with the appropriate filenames \
	    for parameters, lattices, input mfcc and output."
    after 1000 {message_proc ""}
}
bind $p.run <ButtonPress-2> {
    message_proc "Run the decoder in continuous mode updating the \
	    display every \"Step size\" frames."
    after 1000 {message_proc ""}
}
bind $p.next <ButtonPress-2> {
    message_proc "Run the decoder for the next \"Step size\" frames \
	    and pause after updating the display."
    after 1000 {message_proc ""}
}
bind $p.stop <ButtonPress-2> {
    message_proc "Stop the continuous \"Run\" of the decoder. To resume \
	    the continuous mode, press \"Run\" again."
    after 1000 {message_proc ""}
}
bind $p.quit <ButtonPress-2> {
    message_proc "Quit the decoder and exit."
    after 1000 {message_proc ""}
}
