#!/proj/tcl/install/5.x-sparc/bin/tcl

# This is a script to build the mapping from Sun Attachment types
# to mime types.  Its output is included into the mimeSun.tcl module.

exec ce_db_build network -to_ascii /tmp/ce.network
catch {exec egrep {TYPE_(NAME|OPEN|PRINT),} /tmp/ce.network > /tmp/ce.summary}
set in [open /tmp/ce.summary]
set ok 0
while {[gets $in line] >= 0} {
    if [regexp {TYPE_NAME.*<(.+)>} $line match type] {
	set ok 1
    }
    if [regexp {TYPE_OPEN.*<(.+)>} $line match cmd] {
	if {$ok} {
	    switch -regexp -- $cmd {
		\$FILE {
		    puts [list set mimeSunMap($type) application/x-sun-prog]
		}
		textedit.* {
		    puts [list set mimeSunMap($type) text/plain]
		}
		imagetool.* {
		    regsub -- -file $type {} image
		    puts [list set mimeSunMap($type) image/x-$image]
		}
		iconedit.* {
		    regsub -- -(file|image) $type {} image
		    puts [list set mimeSunMap($type) image/x-$image]
		}
		^dos {
		    puts [list set mimeSunMap($type) application/x-dos]
		}
		^fmclient {
		    puts [list set mimeSunMap($type) application/x-frame]
		}
		.*fontedit {
		    puts [list set mimeSunMap($type) application/x-fontedit]
		}
		{.*draw \$FILE} {
		    if [regexp {([^ ]*)\$FILE} $cmd match prog] {
			puts [list set mimeSunMap($type) application/x-$prog]
		    }
		}
		guide.* {
		    puts [list set mimeSunMap($type) application/x-guide]
		}
		make.* {
		    puts [list set mimeSunMap($type) application/x-makefile]
		}
		navigator.* {
		    puts [list set mimeSunMap($type) application/x-answerbook]
		}
		default {
		    puts [list set mimeSunMap($type) application/x-$type]
		}
	    }
	}
	set ok 0
    }
}
