#!/usr/bin/tclsh 

#*** Main Program

    if {$argc != 2} {   
        puts stdout "\nConvHelp \nGenerate Index File for Help System\nUsage: conv infile outfile\n"
        return; 
    }

    set inname  [lindex $argv 0]
    set outname [lindex $argv 1]        

    set infile  [open $inname  "r"] 
    set outfile [open $outname "w"]

#*** Skip file Header and read the x- and y-length

    puts stdout "Converting..."

#*** Write Header for new file

    set rowcount 0      
    set entry    0

    while {[eof $infile] == 0} {
        set filepos [tell $infile]
        gets $infile inbuf 
        if {$entry == 0} {                      # *** Start of entry was not found so far..
           if {[string first ":entry" $inbuf] >= 0} {
              set entry 1                       
              set commandlist {}
              if {![expr $rowcount%10]} {       # *** Inform User
                 puts -nonewline stdout "\[$rowcount\] "
                 flush stdout
              }
              incr rowcount
           }
        } else {                                # *** Ok, we are processing an entry
           if {[string first ":" $inbuf] < 0} { # *** Another entry
               foreach word "$inbuf" {
                   lappend commandlist "$word"  
               }
           } else {
               foreach command "$commandlist" { # *** End of entries reached
                   puts $outfile "$command $inname $filepos" 
               }
               set entry 0
           } 
        }               
    }                   

    close $outfile
    close $infile
    puts stdout "\[$rowcount\] "
